org.apache.olingo.commons.api.data.EntityCollection Java Examples

The following examples show how to use org.apache.olingo.commons.api.data.EntityCollection. 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: TripPinDataModel.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity getFlightFrom(int flighID) {
  Map<String, Object> map = this.flightLinks.get(flighID);
  if (map == null) {
    return null;
  }

  String from = (String) map.get("From");
  EntityCollection set = getEntitySet("Airports");

  if (from != null) {
    for (Entity e : set.getEntities()) {
      if (e.getProperty("IataCode").getValue().equals(from)) {
        return e;
      }
    }
  }
  return null;
}
 
Example #2
Source File: JsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException {
  final T obj = container == null ? null : container.getPayload();
  try (final JsonGenerator json = new JsonFactory().createGenerator(writer)) {
    if (obj instanceof EntityCollection) {
      new JsonEntitySetSerializer(serverMode, contentType).doContainerSerialize(
          (ResWrap<EntityCollection>) container, json);
    } else if (obj instanceof Entity) {
      new JsonEntitySerializer(serverMode, contentType).doContainerSerialize((ResWrap<Entity>) container, json);
    } else if (obj instanceof Property) {
      new JsonPropertySerializer(serverMode, contentType).doContainerSerialize((ResWrap<Property>) container, json);
    } else if (obj instanceof Link) {
      link((Link) obj, json);
    } else if (obj instanceof URI) {
      reference((ResWrap<URI>) container, json);
    }
    json.flush();
  } catch (final IOException | EdmPrimitiveTypeException e) {
    throw new ODataSerializerException(e);
  }
}
 
Example #3
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityCollectionReferenceEmpty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
  final EntityCollection entityCollection = new EntityCollection();

  ReferenceCollectionSerializerOptions options = ReferenceCollectionSerializerOptions.with()
      .contextURL(ContextURL.with().asCollection().suffix(Suffix.REFERENCE).build()).build();

  final SerializerResult serializerResult = serializer.referenceCollection(metadata,
      edmEntitySet,
      entityCollection, options);

  final String resultString = IOUtils.toString(serializerResult.getContent());

  String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
      "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
      "  xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
      "  m:context=\"../$metadata#Collection($ref)\">\n" +
      "</a:feed>";
  checkXMLEqual(expected, resultString);
}
 
Example #4
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityCollectionWithComplexPropertyMetadataNone() throws Exception {
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
  ComplexValue complexValue = new ComplexValue();
  complexValue.getValue().add(new Property(null, "Inner1", ValueType.PRIMITIVE,
      BigDecimal.TEN.scaleByPowerOfTen(-5)));
  Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  time.clear();
  time.set(Calendar.HOUR_OF_DAY, 13);
  time.set(Calendar.SECOND, 59);
  time.set(Calendar.MILLISECOND, 999);
  complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
  entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{"
      + "\"value\":[{"
      + "\"Property1\":1,"
      + "\"Property2\":{"
      + "\"Inner1\":0.00010,"
      + "\"Inner2\":\"13:00:59.999\"}}]}",
      serialize(serializerNone, metadata, null, entityCollection, null));
}
 
Example #5
Source File: TechnicalEntityProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public void countEntityCollection(final ODataRequest request, final ODataResponse response,
    final UriInfo uriInfo) throws ODataApplicationException, ODataLibraryException {
  validateOptions(uriInfo.asUriInfoResource());
  getEdmEntitySet(uriInfo); // including checks
  final EntityCollection entitySetInitial = readEntityCollection(uriInfo);
  EntityCollection entitySet = new EntityCollection();
  entitySet.getEntities().addAll(entitySetInitial.getEntities());
  FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, uriInfo, serviceMetadata.getEdm());
  SearchHandler.applySearchSystemQueryOption(uriInfo.getSearchOption(), entitySet);
  int count =  entitySet.getEntities().size();
  for (SystemQueryOption systemQueryOption : uriInfo.getSystemQueryOptions()) {
    if (systemQueryOption.getName().contains(DELTATOKEN)) {
      count = count + getDeltaCount(uriInfo);
      break;
    }
  }
  response.setContent(odata.createFixedFormatSerializer().count(count));
  response.setStatusCode(HttpStatusCode.OK.getStatusCode());
  response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
}
 
Example #6
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createESDelta(final Edm edm, final OData odata) {
 EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
      .addProperty(createPrimitive("PropertyString", "Number:" + Short.MAX_VALUE)));
  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", Short.MIN_VALUE))
      .addProperty(createPrimitive("PropertyString", "Number:" + Short.MIN_VALUE)));
  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", 0))
      .addProperty(createPrimitive("PropertyString", "Number:" + 0)));
  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", 100))
      .addProperty(createPrimitive("PropertyString", "Number:" + 100)));
  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", -1))
      .addProperty(createPrimitive("PropertyString", "Number:" + -1)));


  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETDelta));
  createEntityId(edm, odata, "ESDelta", entityCollection);
  createOperations("ESDelta", entityCollection, EntityTypeProvider.nameETDelta);
  return entityCollection;
}
 
Example #7
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity getEntity(EdmEntityType edmEntityType, List<UriParameter> keyParams, List<Entity> entityList) 
    throws ODataApplicationException {
  
  // the list of entities at runtime
  EntityCollection entitySet = getEntityCollection(entityList);

  /* generic approach to find the requested entity */
  Entity requestedEntity = Util.findEntity(edmEntityType, entitySet, keyParams);

  if (requestedEntity == null) {
    // this variable is null if our data doesn't contain an entity for the requested key
    // Throw suitable exception
    throw new ODataApplicationException("Entity for requested key doesn't exist",
        HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH);
  }

  return requestedEntity;
}
 
Example #8
Source File: EdmAssistedJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandMetadataMin() throws Exception {
  final Entity relatedEntity1 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 1.5));
  final Entity relatedEntity2 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 2.75));
  EntityCollection target = new EntityCollection();
  target.getEntities().add(relatedEntity1);
  target.getEntities().add(relatedEntity2);
  Link link = new Link();
  link.setTitle("NavigationProperty");
  link.setInlineEntitySet(target);
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, (short) 1));
  entity.getNavigationLinks().add(link);
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,NavigationProperty(Related1))\","
      + "\"value\":[{"
      + "\"Property1\":1,"
      + "\"NavigationProperty\":["
      + "{\"Related1\":1.5},"
      + "{\"Related1\":2.75}]}]}",
      serialize(serializerMin, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)"));
}
 
Example #9
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createESPeople(final Edm edm, final OData odata) {
    EntityCollection entityCollection = new EntityCollection();

    entityCollection.getEntities().add(new Entity()
        .addProperty(createPrimitive("id", 0))
        .addProperty(createPrimitive("name", "A")));

    entityCollection.getEntities().add(new Entity()
        .addProperty(createPrimitive("id", 1))
        .addProperty(createPrimitive("name", "B")));

    entityCollection.getEntities().add(new Entity()
        .addProperty(createPrimitive("id", 2))
        .addProperty(createPrimitive("name", "C")));

    entityCollection.getEntities().add(new Entity()
        .addProperty(createPrimitive("id", 3))
        .addProperty(createPrimitive("name", "D")));

    setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETPeople));
    createEntityId(edm, odata, "ESPeople", entityCollection);
    return entityCollection;
}
 
Example #10
Source File: TripPinDataModel.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EntityCollection getEntitySet(String name, int skip, int pageSize) {
  EntityCollection set = this.entitySetMap.get(name);
  if (set == null) {
    return null;
  }

  EntityCollection modifiedES = new EntityCollection();
  int i = 0;
  for (Entity e : set.getEntities()) {
    if (skip >= 0 && i >= skip && modifiedES.getEntities().size() < pageSize) {
      modifiedES.getEntities().add(e);
    }
    i++;
  }
  modifiedES.setCount(i);
  set.setCount(i);

  if (skip == -1 && pageSize == -1) {
    return set;
  }
  return modifiedES;
}
 
Example #11
Source File: ODataEntitySetRequestImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public ES getBody() {
  if (entitySet == null) {
    try {
      final ResWrap<EntityCollection> resource =
          odataClient.getDeserializer(ContentType.parse(getContentType())).
              toEntitySet(getRawResponse());

      entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
    } catch (final ODataDeserializerException e) {
      throw new IllegalArgumentException(e);
    } finally {
      this.close();
    }
  }
  return entitySet;
}
 
Example #12
Source File: Storage.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private Entity getProduct(EdmEntityType edmEntityType, List<UriParameter> keyParams) throws ODataApplicationException {

        // the list of entities at runtime
        EntityCollection entitySet = getProducts();

        /*  generic approach  to find the requested entity */
        Entity requestedEntity = Util.findEntity(edmEntityType, entitySet, keyParams);

        if (requestedEntity == null) {
            // this variable is null if our data doesn't contain an entity for the requested key
            // Throw suitable exception
            throw new ODataApplicationException("Entity for requested key doesn't exist",
                                                HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH);
        }

        return requestedEntity;
    }
 
Example #13
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Entity getEntity(EdmEntityType edmEntityType, List<UriParameter> keyParams, List<Entity> entityList) 
    throws ODataApplicationException {
  
  // the list of entities at runtime
  EntityCollection entitySet = getEntityCollection(entityList);

  /* generic approach to find the requested entity */
  Entity requestedEntity = Util.findEntity(edmEntityType, entitySet, keyParams);

  if (requestedEntity == null) {
    // this variable is null if our data doesn't contain an entity for the requested key
    // Throw suitable exception
    throw new ODataApplicationException("Entity for requested key doesn't exist",
        HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH);
  }

  return requestedEntity;
}
 
Example #14
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createESTwoPrim(final Edm edm, final OData odata) {
  EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 32766))
      .addProperty(createPrimitive("PropertyString", "Test String1")));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -365))
      .addProperty(createPrimitive("PropertyString", "Test String2")));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -32766))
      .addProperty(createPrimitive("PropertyString", null)));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
      .addProperty(createPrimitive("PropertyString", "Test String4")));

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoPrim));
  createEntityId(edm, odata, "ESTwoPrim", entityCollection);
  createOperations("ESTwoPrim", entityCollection, EntityTypeProvider.nameETTwoPrim);
  return entityCollection;
}
 
Example #15
Source File: JsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void write(final Writer writer, final T obj) throws ODataSerializerException {
  try (final JsonGenerator json = new JsonFactory().createGenerator(writer)) {
    if (obj instanceof EntityCollection) {
      new JsonEntitySetSerializer(serverMode, contentType).doSerialize((EntityCollection) obj, json);
    } else if (obj instanceof Entity) {
      new JsonEntitySerializer(serverMode, contentType).doSerialize((Entity) obj, json);
    } else if (obj instanceof Property) {
      new JsonPropertySerializer(serverMode, contentType).doSerialize((Property) obj, json);
    } else if (obj instanceof Link) {
      link((Link) obj, json);
    }
    json.flush();
  } catch (final IOException | EdmPrimitiveTypeException e) {
    throw new ODataSerializerException(e);
  }
}
 
Example #16
Source File: TechnicalEntityProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
    entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
    final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
    final CountOption countOption, String id, final boolean isContNav) throws ODataLibraryException {

  return odata.createSerializer(requestedFormat, request.getHeaders(HttpHeader.ODATA_VERSION))
      .entityCollection(
      serviceMetadata,
      edmEntityType,
      entityCollection,
      EntityCollectionSerializerOptions.with()
          .contextURL(isODataMetadataNone(requestedFormat) ? null :
              getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select, isContNav))
          .count(countOption)
          .expand(expand).select(select)
          .id(id)
          .build());
}
 
Example #17
Source File: Util.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public static Entity findEntity(EdmEntityType edmEntityType, EntityCollection entitySet,
    List<UriParameter> keyParams) {

  List<Entity> entityList = entitySet.getEntities();

  // loop over all entities in order to find that one that matches
  // all keys in request e.g. contacts(ContactID=1, CompanyID=1)
  for (Entity entity : entityList) {
    boolean foundEntity = entityMatchesAllKeys(edmEntityType, entity, keyParams);
    if (foundEntity) {
      return entity;
    }
  }

  return null;
}
 
Example #18
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void setLinks(final Entity entity, final String navigationPropertyName, final Entity... targets) {
  if(targets.length == 0) {
    return;
  }
  
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(entity.getId().toASCIIString() + "/" + navigationPropertyName);

    EntityCollection target = new EntityCollection();
    target.getEntities().addAll(Arrays.asList(targets));
    link.setInlineEntitySet(target);
    
    entity.getNavigationLinks().add(link);
  } else {
    link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets));
  }
}
 
Example #19
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void linkPropMixPrimCompInESCompMixPrimCollCompToCollETTwoKeyNav(
    Map<String, EntityCollection> data) {
  EntityCollection collection = data.get("ESCompMixPrimCollComp");
  Entity entity = collection.getEntities().get(0);
  ComplexValue complexValue = entity.getProperties().get(1).asComplex();
  final List<Entity> esTwoKeyNavTargets = data.get("ESTwoKeyNav").getEntities();
  Link link = new Link();
  link.setRel(Constants.NS_NAVIGATION_LINK_REL + "NavPropertyETTwoKeyNavMany");
  link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
  link.setTitle("NavPropertyETTwoKeyNavMany");
  EntityCollection target = new EntityCollection();
  target.setCount(2);
  target.getEntities().addAll(Arrays.asList(esTwoKeyNavTargets.get(0), esTwoKeyNavTargets.get(2)));
  link.setInlineEntitySet(target);
  link.setHref(entity.getId().toASCIIString() + "/" + 
  entity.getProperties().get(1).getName() + "/"
      + "NavPropertyETTwoKeyNavMany");
  complexValue.getNavigationLinks().add(link);
}
 
Example #20
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void setLinks(final Entity entity, final String navigationPropertyName, final Entity... targets) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(entity.getId().toASCIIString() + "/" + navigationPropertyName);

    EntityCollection target = new EntityCollection();
    target.getEntities().addAll(Arrays.asList(targets));
    link.setInlineEntitySet(target);
    
    entity.getNavigationLinks().add(link);
  } else {
    link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets));
  }
}
 
Example #21
Source File: Util.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public static Entity findEntity(EdmEntityType edmEntityType, EntityCollection entitySet,
    List<UriParameter> keyParams) throws ODataApplicationException {

  List<Entity> entityList = entitySet.getEntities();

  // loop over all entities in order to find that one that matches all keys in request
  // e.g. contacts(ContactID=1, CompanyID=1)
  for (Entity entity: entityList) {
    boolean foundEntity = entityMatchesAllKeys(edmEntityType, entity, keyParams);
    if (foundEntity) {
      return entity;
    }
  }

  return null;
}
 
Example #22
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Entity getCategory(EdmEntityType edmEntityType, List<UriParameter> keyParams) {

    // the list of entities at runtime
    EntityCollection entitySet = getCategories();

    /* generic approach to find the requested entity */
    return Util.findEntity(edmEntityType, entitySet, keyParams);
  }
 
Example #23
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void selectExtendedComplexType() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final EntityCollection entitySet = data.readAll(edmEntitySet);
  InputStream result = serializer
      .entityCollection(metadata, entityType, entitySet,
          EntityCollectionSerializerOptions.with()
              .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
              .build()).getContent();
  final String resultString = IOUtils.toString(result);

  final String expected = "{"
      + "\"@odata.context\":\"$metadata#ESFourKeyAlias\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"value\":[{"
      + "\"PropertyInt16\":1,"
      + "\"PropertyComp\":{"
      + "\"PropertyInt16\":11,"
      + "\"PropertyString\":\"Num11\""
      + "},"
      + "\"PropertyCompComp\":{"
      + "\"PropertyComp\":{"
      + "\"@odata.type\":\"#olingo.odata.test1.CTBase\","
      + "\"PropertyInt16\":111,"
      + "\"PropertyString\":\"Num111\","
      + "\"AdditionalPropString\":\"Test123\""
      + "}}}]}";

  Assert.assertEquals(expected, resultString);
}
 
Example #24
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public EntityCollection readFunctionImportCollection(final UriResourceFunction uriResourceFunction,
    final ServiceMetadata serviceMetadata) throws ODataApplicationException {

  if (DemoEdmProvider.FUNCTION_COUNT_CATEGORIES.equals(uriResourceFunction.getFunctionImport().getName())) {
    // Get the parameter of the function
    final UriParameter parameterAmount = uriResourceFunction.getParameters().get(0);
    // Try to convert the parameter to an Integer.
    // We have to take care, that the type of parameter fits to its EDM declaration
    int amount;
    try {
      amount = Integer.parseInt(parameterAmount.getText());
    } catch (NumberFormatException e) {
      throw new ODataApplicationException("Type of parameter Amount must be Edm.Int32", HttpStatusCode.BAD_REQUEST
          .getStatusCode(), Locale.ENGLISH);
    }

    final List<Entity> resultEntityList = new ArrayList<Entity>();

    // Loop over all categories and check how many products are linked
    for (final Entity category : manager.getEntityCollection(DemoEdmProvider.ES_CATEGORIES_NAME)) {
      final EntityCollection products = getRelatedEntityCollection(category, DemoEdmProvider.NAV_TO_PRODUCTS);
      if (products.getEntities().size() == amount) {
        resultEntityList.add(category);
      }
    }

    final EntityCollection resultCollection = new EntityCollection();
    resultCollection.getEntities().addAll(resultEntityList);
    return resultCollection;
  } else {
    throw new ODataApplicationException("Function not implemented", HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(),
        Locale.ROOT);
  }
}
 
Example #25
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityWithStreamMetadataFull() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream");
  final EntityCollection collection = data.readAll(edmEntitySet);
  InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), collection,
      EntityCollectionSerializerOptions.with()
      .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
      .build()).getContent();
  final String resultString = IOUtils.toString(result);
  final String expectedResult = "{\"@odata.context\":\"$metadata#ESWithStream\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"value\":[{"
      + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\","
      + "\"@odata.id\":\"ESWithStream(32767)\","
      + "\"[email protected]\":\"#Int16\","
      + "\"PropertyInt16\":32767,"
      + "\"[email protected]\":\"#Stream\","
      + "\"[email protected]\":\"readLink\"},"
      + "{"
      + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\","
      + "\"@odata.id\":\"ESWithStream(7)\","
      + "\"[email protected]\":\"#Int16\","
      + "\"PropertyInt16\":7,"
      + "\"[email protected]\":\"#Stream\","
      + "\"[email protected]\":\"eTag\","
      + "\"[email protected]\":\"image/jpeg\","
      + "\"[email protected]\":\"http://mediaserver:1234/editLink\""
      + "}]}";
  Assert.assertEquals(expectedResult, resultString);
}
 
Example #26
Source File: AtomDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public ResWrap<EntityCollection> toEntitySet(final InputStream input) throws ODataDeserializerException {
  try {
    final XMLEventReader reader = getReader(input);
    final StartElement start = skipBeforeFirstStartElement(reader);
    return getContainer(start, entitySet(reader, start));
  } catch (XMLStreamException | EdmPrimitiveTypeException e) {
    throw new ODataDeserializerException(e);
  }
}
 
Example #27
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EntityCollection createESMixEnumDefCollComp(Edm edm, OData odata) {
  final EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(createETMixEnumDefCollComp("key1", (short) 1));
  entityCollection.getEntities().add(createETMixEnumDefCollComp("key1", (short) 3));
  entityCollection.getEntities().add(createETMixEnumDefCollComp("key1", (short) 4));

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixEnumDefCollComp));
  createEntityId(edm, odata, "ESMixEnumDefCollComp", entityCollection);
  createOperations("ESMixEnumDefCollComp", entityCollection, EntityTypeProvider.nameETMixEnumDefCollComp);
  return entityCollection;
}
 
Example #28
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private List<Entity> createInlineEntities(final String rawBaseUri, final EdmEntitySet targetEntitySet,
    final EntityCollection changedEntitySet) throws DataProviderException {
  List<Entity> entities = new ArrayList<Entity>();

  for (final Entity newEntity : changedEntitySet.getEntities()) {
    entities.add(createInlineEntity(rawBaseUri, targetEntitySet, newEntity));
  }

  return entities;
}
 
Example #29
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private Link createLink(final ExpandTreeBuilder expandBuilder, final String navigationPropertyName,
    final JsonNode jsonNode,
    final EdmNavigationProperty edmNavigationProperty) throws DeserializerException {
  Link link = new Link();
  link.setTitle(navigationPropertyName);
  final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ? expandBuilder.expand(edmNavigationProperty)
      : null;
  EdmEntityType derivedEdmEntityType = (EdmEntityType) getDerivedType(
      edmNavigationProperty.getType(), jsonNode);
  if (jsonNode.isArray() && edmNavigationProperty.isCollection()) {
    link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
    EntityCollection inlineEntitySet = new EntityCollection();
    inlineEntitySet.getEntities().addAll(
        consumeEntitySetArray(derivedEdmEntityType, jsonNode, childExpandBuilder));
    link.setInlineEntitySet(inlineEntitySet);
  } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
      && !edmNavigationProperty.isCollection()) {
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    if (!jsonNode.isNull()) {
      Entity inlineEntity = consumeEntityNode(derivedEdmEntityType, (ObjectNode) jsonNode, childExpandBuilder);
      link.setInlineEntity(inlineEntity);
    }
  } else {
    throw new DeserializerException("Invalid value: " + jsonNode.getNodeType()
        + " for expanded navigation property: " + navigationPropertyName,
        MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, navigationPropertyName);
  }
  return link;
}
 
Example #30
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void entitySetCompAllPrim() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
  EntityCollection entitySet = data.readAll(edmEntitySet);
  entitySet.setCount(entitySet.getEntities().size());
  entitySet.setNext(URI.create("/next"));
  CountOption countOption = Mockito.mock(CountOption.class);
  Mockito.when(countOption.getValue()).thenReturn(true);
  InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
      EntityCollectionSerializerOptions.with()
          .contextURL(ContextURL.with().serviceRoot(new URI("http://host:port"))
              .entitySet(edmEntitySet).build())
          .id("http://host/svc/ESCompAllPrim")
          .count(countOption)
          .build()).getContent();
  final String resultString = IOUtils.toString(result);
  String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
      + "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\" "
      + "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
      + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
      + "m:context=\"http://host:port$metadata#ESCompAllPrim\" "
      + "m:metadata-etag=\"metadataETag\">"
      + "<a:id>http://host/svc/ESCompAllPrim</a:id>"
      + "<m:count>4</m:count>"
      + "<a:link rel=\"next\" href=\"/next\"></a:link>"
      + "<a:entry m:etag=\"W/&quot;32767&quot;\">"
      + "<a:id>ESCompAllPrim(32767)</a:id><a:title></a:title><a:summary></a:summary>";
  Assert.assertTrue(resultString.startsWith(prefix));
}