Java Code Examples for org.apache.olingo.client.api.domain.ClientEntity#getProperties()

The following examples show how to use org.apache.olingo.client.api.domain.ClientEntity#getProperties() . 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: CMODataClientTransportMarshallingTest.java    From devops-cm-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllMembersMarshalled() {

    ClientEntity transportEnity = new ClientEntityImpl(new FullQualifiedName("AI_CRM_GW_CM_CI_SRV.Change"));
    List<ClientProperty> props = transportEnity.getProperties();
    props.add(new ClientPropertyImpl("TransportID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("8000038673").build()));
    props.add(new ClientPropertyImpl("DevelopmentSystemID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("J01~JAVA").build()));
    props.add(new ClientPropertyImpl("IsModifiable", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("true").build()));
    props.add(new ClientPropertyImpl("Owner", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("me").build()));
    props.add(new ClientPropertyImpl("Description", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("Lorem ipsum").build()));

    CMODataTransport transport = CMODataSolmanClient.toTransport("x", transportEnity);

    assertThat(transport.getTransportID(), is(equalTo("8000038673")));
    assertThat(transport.isModifiable(), is(equalTo(true)));
    assertThat(transport.getOwner(), is(equalTo("me")));
    assertThat(transport.getDescription(), is(equalTo("Lorem ipsum")));
}
 
Example 2
Source File: ClientEntitySerializer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ClientEntity entity, JsonGenerator generator, SerializerProvider provider) throws IOException {
    generator.writeStartObject();
    for (ClientProperty prop : entity.getProperties()) {
        generator.writeFieldName(prop.getName());
        generator.writeObject(prop.getValue());
    }
    generator.writeEndObject();
}
 
Example 3
Source File: CMODataClientTransportMarshallingTest.java    From devops-cm-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshallTransportWithoutDescriptionSucceeds() {

    ClientEntity transportEnity = new ClientEntityImpl(new FullQualifiedName("AI_CRM_GW_CM_CI_SRV.Change"));
    List<ClientProperty> props = transportEnity.getProperties();
    props.add(new ClientPropertyImpl("TransportID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("8000038673").build()));
    props.add(new ClientPropertyImpl("DevelopmentSystemID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("J01~JAVA").build()));
    props.add(new ClientPropertyImpl("IsModifiable", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("true").build()));
    CMODataTransport transport = CMODataSolmanClient.toTransport("x", transportEnity);
    assertThat(transport.getDescription(), is(nullValue()));
}
 
Example 4
Source File: CMODataClientTransportMarshallingTest.java    From devops-cm-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshallTransportWithoutOwnerSucceeds() {

    ClientEntity transportEnity = new ClientEntityImpl(new FullQualifiedName("AI_CRM_GW_CM_CI_SRV.Change"));
    List<ClientProperty> props = transportEnity.getProperties();
    props.add(new ClientPropertyImpl("TransportID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("8000038673").build()));
    props.add(new ClientPropertyImpl("DevelopmentSystemID", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("J01~JAVA").build()));
    props.add(new ClientPropertyImpl("IsModifiable", new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue("true").build()));
    CMODataTransport transport = CMODataSolmanClient.toTransport("x", transportEnity);
    assertThat(transport.getOwner(), is(nullValue()));
}
 
Example 5
Source File: AsyncTestITCase.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void withInlineEntry(final ContentType contentType) {
  final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
      appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");

  final ODataEntityRequest<ClientEntity> req =
      client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
  req.setFormat(contentType);

  final AsyncRequestWrapper<ODataRetrieveResponse<ClientEntity>> async =
      client.getAsyncRequestFactory().<ODataRetrieveResponse<ClientEntity>> getAsyncRequestWrapper(req);

  final AsyncResponseWrapper<ODataRetrieveResponse<ClientEntity>> responseWrapper = async.execute();

  assertFalse(responseWrapper.isPreferenceApplied());

  final ODataRetrieveResponse<ClientEntity> res = responseWrapper.getODataResponse();
  final ClientEntity entity = res.getBody();

  assertNotNull(entity);
  assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
  assertEquals(testStaticServiceRootURL + "/Customers(1)", entity.getEditLink().toASCIIString());

  assertEquals(3, entity.getNavigationLinks().size());

  if (ContentType.APPLICATION_ATOM_XML.equals(contentType)) {
    assertTrue(entity.getAssociationLinks().isEmpty());
    // In JSON, association links for each $ref link will exist.
  }

  boolean found = false;

  for (ClientLink link : entity.getNavigationLinks()) {
    if (link instanceof ClientInlineEntity) {
      final ClientEntity inline = ((ClientInlineEntity) link).getEntity();
      assertNotNull(inline);

      final List<? extends ClientProperty> properties = inline.getProperties();
      assertEquals(5, properties.size());

      assertTrue(properties.get(0).getName().equals("CompanyID")
          || properties.get(1).getName().equals("CompanyID")
          || properties.get(2).getName().equals("CompanyID")
          || properties.get(3).getName().equals("CompanyID")
          || properties.get(4).getName().equals("CompanyID"));
      assertTrue(properties.get(0).getValue().toString().equals("0")
          || properties.get(1).getValue().toString().equals("0")
          || properties.get(2).getValue().toString().equals("0")
          || properties.get(3).getValue().toString().equals("0")
          || properties.get(4).getValue().toString().equals("0"));

      found = true;
    }
  }

  assertTrue(found);
}
 
Example 6
Source File: ODataBinderImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public Entity getEntity(final ClientEntity odataEntity) {
  final Entity entity = new Entity();

  entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());

  // -------------------------------------------------------------
  // Add edit and self link
  // -------------------------------------------------------------
  final URI odataEditLink = odataEntity.getEditLink();
  if (odataEditLink != null) {
    final Link editLink = new Link();
    editLink.setTitle(entity.getType());
    editLink.setHref(odataEditLink.toASCIIString());
    editLink.setRel(Constants.EDIT_LINK_REL);
    entity.setEditLink(editLink);
  }

  if (odataEntity.isReadOnly()) {
    final Link selfLink = new Link();
    selfLink.setTitle(entity.getType());
    selfLink.setHref(odataEntity.getLink().toASCIIString());
    selfLink.setRel(Constants.SELF_LINK_REL);
    entity.setSelfLink(selfLink);
  }
  // -------------------------------------------------------------

  links(odataEntity, entity);

  // -------------------------------------------------------------
  // Append edit-media links
  // -------------------------------------------------------------
  for (ClientLink link : odataEntity.getMediaEditLinks()) {
    LOG.debug("Append edit-media link\n{}", link);
    entity.getMediaEditLinks().add(getLink(link));
  }
  // -------------------------------------------------------------

  if (odataEntity.isMediaEntity()) {
    entity.setMediaContentSource(odataEntity.getMediaContentSource());
    entity.setMediaContentType(odataEntity.getMediaContentType());
    entity.setMediaETag(odataEntity.getMediaETag());
  }

  for (ClientProperty property : odataEntity.getProperties()) {
    entity.getProperties().add(getProperty(property));
  }

  entity.setId(odataEntity.getId());
  annotations(odataEntity, entity);
  return entity;
}
 
Example 7
Source File: JSONTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void testOLINGO1114() throws Exception {
  ClientEntity entityIncNullValue = client.getObjectFactory()
          .newEntity(new FullQualifiedName("Microsoft.Dynamics.CRM", "account"));
  List<ClientProperty> properties = entityIncNullValue.getProperties();

  // Property "name"
  ClientPrimitiveValue.Builder valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.String);
  valueBuilder.setValue("testString");
  ClientProperty name = client.getObjectFactory().newPrimitiveProperty("name", valueBuilder.build());
  properties.add(name);

  // Property "testDecimal"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Decimal);
  valueBuilder.setValue(null);
  ClientProperty revenue = client.getObjectFactory().newPrimitiveProperty("testDecimal", valueBuilder.build());
  properties.add(revenue);

  // Property "testByte"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Byte);
  valueBuilder.setValue(null);
  ClientProperty testByte = client.getObjectFactory().newPrimitiveProperty("testByte", valueBuilder.build());
  properties.add(testByte);

  // Property "testDouble"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Double);
  valueBuilder.setValue(null);
  ClientProperty testDouble = client.getObjectFactory().newPrimitiveProperty("testDouble", valueBuilder.build());
  properties.add(testDouble);

  // Property "testInt64"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Int64);
  valueBuilder.setValue(null);
  ClientProperty testInt64 = client.getObjectFactory().newPrimitiveProperty("testInt64", valueBuilder.build());
  properties.add(testInt64);

  // Property "testInt32"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Int32);
  valueBuilder.setValue(null);
  ClientProperty testInt32 = client.getObjectFactory().newPrimitiveProperty("testInt32", valueBuilder.build());
  properties.add(testInt32);

  // Property "testInt16"
  valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
  valueBuilder.setType(EdmPrimitiveTypeKind.Int16);
  valueBuilder.setValue(null);
  ClientProperty testInt16 = client.getObjectFactory().newPrimitiveProperty("testInt16", valueBuilder.build());
  properties.add(testInt16);

  InputStream inputStream = client.getWriter().writeEntity(entityIncNullValue, ContentType.JSON_FULL_METADATA);
  HttpEntity httpEntity = URIUtils.buildInputStreamEntity(client, inputStream);

  final String actual = EntityUtils.toString(httpEntity);
  final JsonNode expected =
          OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("olingo1114.json")).
                  replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX));
  final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()));
  assertEquals(expected, actualNode);
}