Java Code Examples for org.apache.olingo.commons.api.data.Entity#getNavigationLinks()

The following examples show how to use org.apache.olingo.commons.api.data.Entity#getNavigationLinks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity copyEntityRecursively(final EdmEntitySet edmEntitySet, final Entity entity) {
  // Check if entity is already copied
  if(containsEntityInCopyMap(edmEntitySet.getName(), entity)) {
    return getEntityFromCopyMap(edmEntitySet.getName(), entity);
  } else {
    final Entity newEntity = copyEntity(entity);
    addEntityToCopyMap(edmEntitySet.getName(), entity, newEntity);
    
    // Create nested entities recursively
    for(final Link link : entity.getNavigationLinks()) {
      newEntity.getNavigationLinks().add(copyLink(edmEntitySet, link));
    }
    
    return newEntity;
  }
}
 
Example 2
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity copyEntityRecursively(final EdmEntitySet edmEntitySet, final Entity entity) {
  // Check if entity is already copied
  if(containsEntityInCopyMap(edmEntitySet.getName(), entity)) {
    return getEntityFromCopyMap(edmEntitySet.getName(), entity);
  } else {
    final Entity newEntity = copyEntity(entity);
    addEntityToCopyMap(edmEntitySet.getName(), entity, newEntity);
    
    // Create nested entities recursively
    for(final Link link : entity.getNavigationLinks()) {
      newEntity.getNavigationLinks().add(copyLink(edmEntitySet, link));
    }
    
    return newEntity;
  }
}
 
Example 3
Source File: TransactionalEntityManager.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity copyEntityRecursively(final EdmEntitySet edmEntitySet, final Entity entity) {
  // Check if entity is already copied
  if(containsEntityInCopyMap(edmEntitySet.getName(), entity)) {
    return getEntityFromCopyMap(edmEntitySet.getName(), entity);
  } else {
    final Entity newEntity = copyEntity(entity);
    addEntityToCopyMap(edmEntitySet.getName(), entity, newEntity);
    
    // Create nested entities recursively
    for(final Link link : entity.getNavigationLinks()) {
      newEntity.getNavigationLinks().add(copyLink(edmEntitySet, link));
    }
    
    return newEntity;
  }
}
 
Example 4
Source File: ExpandSystemQueryOptionHandler.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity transformEntityGraphToTree(final Entity entity, final EdmBindingTarget edmEntitySet,
    final ExpandOption expand, final ExpandItem parentExpandItem) throws ODataApplicationException {
  final Entity newEntity = newEntity(entity);
  if (hasExpandItems(expand)) {
    final boolean expandAll = expandAll(expand);
    final Set<String> expanded = expandAll ? null : getExpandedPropertyNames(expand.getExpandItems());
    final EdmEntityType edmType = edmEntitySet.getEntityType();

    for (final Link link : entity.getNavigationLinks()) {
      final String propertyName = link.getTitle();

      if (expandAll || expanded.contains(propertyName)) {
        final EdmNavigationProperty edmNavigationProperty = edmType.getNavigationProperty(propertyName);
        final EdmBindingTarget edmBindingTarget = edmEntitySet.getRelatedBindingTarget(propertyName);
        final Link newLink = newLink(link);
        newEntity.getNavigationLinks().add(newLink);
        final ExpandItem expandItem = getInnerExpandItem(expand, propertyName);

        if (edmNavigationProperty.isCollection()) {
          newLink.setInlineEntitySet(transformEntitySetGraphToTree(link.getInlineEntitySet(),
              edmBindingTarget, expandItem.getExpandOption(), expandItem));
        } else {
          newLink.setInlineEntity(transformEntityGraphToTree(link.getInlineEntity(),
              edmBindingTarget,expandItem.getExpandOption(), expandItem));
        }
      }
    }

  }
  return newEntity;
}
 
Example 5
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void deriveEntityESAllPrimDeepInsert() throws Exception {
  final String entityString =  "{\"PropertyInt16\": 32767,"
      + "\"PropertyString\": \"First Resource - positive values\","
      + "\"PropertyBoolean\": true,"
      + "\"PropertyByte\": 255,"
      + "\"PropertySByte\": 127,"
      + "\"PropertyInt32\": 2147483647,"
      + "\"PropertyInt64\": 9223372036854775807,"
      + "\"PropertyDecimal\": 34,"
      + "\"PropertyBinary\": \"ASNFZ4mrze8=\","
      + "\"PropertyDate\": \"2012-12-03\","
      + "\"PropertyDateTimeOffset\": \"2012-12-03T07:16:23Z\","
      + "\"PropertyDuration\": \"PT6S\","
      + "\"PropertyGuid\": \"01234567-89ab-cdef-0123-456789abcdef\","
      + "\"PropertyTimeOfDay\": \"03:26:05\","
      + "\"NavPropertyETTwoPrimMany\": [{\"@odata.type\": \"#olingo.odata.test1.ETBase\","
      + "\"PropertyInt16\": -365,\"PropertyString\": \"Test String2\","
      + "\"AdditionalPropertyString_5\": \"Test String2\"},"
      + "{\"PropertyInt16\": -365,\"PropertyString\": \"Test String2\"}],"
      + "\"NavPropertyETTwoPrimOne\":"
      + "{\"@odata.type\": \"#olingo.odata.test1.ETBase\",\"PropertyInt16\": 32767,"
      + "\"PropertyString\": \"Test String4\","
      + "\"AdditionalPropertyString_5\": \"Test String2\"}}";
  final Entity entity = deserialize(entityString, "ETAllPrim");
  assertNotNull(entity);
  List<Property> properties = entity.getProperties();
  assertNotNull(properties);
  assertEquals(14, properties.size());
  List<Link> navProperties = entity.getNavigationLinks();
  assertNotNull(navProperties);
  assertEquals(2, navProperties.size());
  assertNotNull(navProperties.get(1).getInlineEntitySet()
      .getEntities().get(0).getProperty("AdditionalPropertyString_5"));
  assertNotNull(navProperties.get(0).getInlineEntity().getProperty("AdditionalPropertyString_5"));
}
 
Example 6
Source File: Services.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private Response patchEntityInternal(final UriInfo uriInfo,
    final String accept, final String contentType, final String prefer, final String ifMatch,
    final String entitySetName, final String entityId, final String changes) {

  try {
    final Accept acceptType = Accept.parse(accept);

    if (acceptType == Accept.XML || acceptType == Accept.TEXT) {
      throw new UnsupportedMediaTypeException("Unsupported media type");
    }

    final Map.Entry<String, InputStream> entityInfo = xml.readEntity(entitySetName, entityId, Accept.ATOM);

    final String etag = Commons.getETag(entityInfo.getKey());
    if (StringUtils.isNotBlank(ifMatch) && !ifMatch.equals(etag)) {
      throw new ConcurrentModificationException("Concurrent modification");
    }

    final Accept contentTypeValue = Accept.parse(contentType);

    final Entity entryChanges;

    if (contentTypeValue == Accept.XML || contentTypeValue == Accept.TEXT) {
      throw new UnsupportedMediaTypeException("Unsupported media type");
    } else if (contentTypeValue == Accept.ATOM) {
      entryChanges = atomDeserializer.toEntity(
          IOUtils.toInputStream(changes, Constants.ENCODING)).getPayload();
    } else {
      final ResWrap<Entity> jcont = jsonDeserializer.toEntity(IOUtils.toInputStream(changes, Constants.ENCODING));
      entryChanges = jcont.getPayload();
    }

    final ResWrap<Entity> container = atomDeserializer.toEntity(entityInfo.getValue());

    for (Property property : entryChanges.getProperties()) {
      final Property _property = container.getPayload().getProperty(property.getName());
      if (_property == null) {
        container.getPayload().getProperties().add(property);
      } else {
        _property.setValue(property.getValueType(), property.getValue());
      }
    }

    for (Link link : entryChanges.getNavigationLinks()) {
      container.getPayload().getNavigationLinks().add(link);
    }

    final ByteArrayOutputStream content = new ByteArrayOutputStream();
    final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
    atomSerializer.write(writer, container);
    writer.flush();
    writer.close();

    final InputStream res = xml.addOrReplaceEntity(
        entityId, entitySetName, new ByteArrayInputStream(content.toByteArray()), container.getPayload());

    final ResWrap<Entity> cres = atomDeserializer.toEntity(res);

    normalizeAtomEntry(cres.getPayload(), entitySetName, entityId);

    final String path = Commons.getEntityBasePath(entitySetName, entityId);
    FSManager.instance().putInMemory(
        cres, path + File.separatorChar + Constants.get(ConstantKey.ENTITY));

    final Response response;
    if ("return-content".equalsIgnoreCase(prefer)) {
      response = xml.createResponse(
          uriInfo.getRequestUri().toASCIIString(),
          xml.readEntity(entitySetName, entityId, acceptType).getValue(),
          null, acceptType, Response.Status.OK);
    } else {
      res.close();
      response = xml.createResponse(
          uriInfo.getRequestUri().toASCIIString(),
          null,
          null,
          acceptType, Response.Status.NO_CONTENT);
    }

    if (StringUtils.isNotBlank(prefer)) {
      response.getHeaders().put("Preference-Applied", Collections.<Object> singletonList(prefer));
    }

    return response;
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}