当前位置: 首页>>代码示例>>Java>>正文


Java Entity.getProperty方法代码示例

本文整理汇总了Java中org.apache.olingo.commons.api.data.Entity.getProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getProperty方法的具体用法?Java Entity.getProperty怎么用?Java Entity.getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.olingo.commons.api.data.Entity的用法示例。


在下文中一共展示了Entity.getProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private Entity createEntity(EdmEntityType edmEntityType, Entity entity, List<Entity> entityList) {
  
  // the ID of the newly created entity is generated automatically
  int newId = 1;
  while (entityIdExists(newId, entityList)) {
    newId++;
  }

  Property idProperty = entity.getProperty("ID");
  if (idProperty != null) {
    idProperty.setValue(ValueType.PRIMITIVE, Integer.valueOf(newId));
  } else {
    // as of OData v4 spec, the key property can be omitted from the POST request body
    entity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
  }
  entity.setId(createId(entity, "ID"));
  entityList.add(entity);

  return entity;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:Storage.java

示例2: primitiveBoundAction

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
protected static Property primitiveBoundAction(final String name, final Map<String, Parameter> parameters, 
    final Map<String, EntityCollection> data, final EdmEntitySet edmEntitySet, final List<UriParameter> keyList)
    throws DataProviderException {
  List<Object> keyPropertyValues = new ArrayList<Object>();
  List<String> keyPropertyNames = new ArrayList<String>();
  if ("BAETTwoPrimRTString".equals(name)) {
    if (!keyList.isEmpty()) {
      setBindingPropertyKeyNameAndValue(keyList, edmEntitySet, keyPropertyValues, keyPropertyNames);
      EntityCollection entityCollection = data.get(edmEntitySet.getName());
      Entity entity = getSpecificEntity1(entityCollection, keyPropertyValues, keyPropertyNames);
      Property property = entity.getProperty("PropertyString");
      return property;
    }
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:18,代码来源:ActionData.java

示例3: writeExpandedStreamProperty

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void writeExpandedStreamProperty(ExpandOption expand, String propertyName, EdmProperty edmProperty, 
    Linked linked, ExpandItem expandAll, JsonGenerator json) throws SerializerException, 
    DecoderException, IOException {
  final ExpandItem innerOptions = ExpandSelectHelper.getExpandItem(expand.getExpandItems(), propertyName);
  if (innerOptions != null || expandAll != null) {
    if(constants instanceof Constantsv00){
      throw new SerializerException("Expand not supported for Stream Property Type!",
          SerializerException.MessageKeys.UNSUPPORTED_OPERATION_TYPE, "expand", edmProperty.getName());
    }
    Entity entity = (Entity) linked;
    final Property property = (Property) entity.getProperty(propertyName);
    if((property == null || property.isNull()) && edmProperty.isNullable() == Boolean.FALSE ){
      throw new SerializerException("Non-nullable property not present!",
          SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
    }
    Link link = (Link) property.getValue();
    Property stream = link.getInlineEntity().getProperty(propertyName);
    Base64 decoder = new Base64(true);
    byte[] decodedBytes = (byte[]) decoder.decode(stream.getValue());
    json.writeStringField(propertyName, new String(decodedBytes));     
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:ODataJsonSerializer.java

示例4: createProduct

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private Entity createProduct(EdmEntityType edmEntityType, Entity entity) {

    // the ID of the newly created product entity is generated automatically
    int newId = 1;
    while (productIdExists(newId)) {
      newId++;
    }

    Property idProperty = entity.getProperty("ID");
    if (idProperty != null) {
      idProperty.setValue(ValueType.PRIMITIVE, Integer.valueOf(newId));
    } else {
      // as of OData v4 spec, the key property can be omitted from the POST request body
      entity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
    }
    entity.setId(createId("Products", newId));
    this.productList.add(entity);

    return entity;

  }
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:Storage.java

示例5: getMatch

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * This method returns matched entity list, where it uses in getEntity method to get the matched entity.
 *
 * @param entityType EdmEntityType
 * @param param      UriParameter
 * @param entityList List of entities
 * @return list of entities
 * @throws ODataApplicationException
 * @throws ODataServiceFault
 */
private List<Entity> getMatch(EdmEntityType entityType, UriParameter param, List<Entity> entityList)
        throws ODataApplicationException, ODataServiceFault {
    ArrayList<Entity> list = new ArrayList<>();
    for (Entity entity : entityList) {
        EdmProperty property = (EdmProperty) entityType.getProperty(param.getName());
        EdmType type = property.getType();
        if (type.getKind() == EdmTypeKind.PRIMITIVE) {
            Object match = readPrimitiveValue(property, param.getText());
            Property entityValue = entity.getProperty(param.getName());
            if (match != null) {
                if (match.equals(entityValue.asPrimitive())) {
                    list.add(entity);
                }
            } else {
                if (null == entityValue.asPrimitive()) {
                    list.add(entity);
                }
            }
        } else {
            throw new ODataServiceFault("Complex elements are not supported, couldn't compare complex objects.");
        }
    }
    return list;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:35,代码来源:ODataAdapter.java

示例6: actionResetComputerDetailsSpecifications

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@POST
@Path("/ComputerDetail({entityId})/ResetComputerDetailsSpecifications")
public Response actionResetComputerDetailsSpecifications(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @PathParam("entityId") final String entityId,
    @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
    final String argument) {

  final Map.Entry<Accept, AbstractUtilities> utils = getUtilities(accept, format);

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

  try {
    final Map.Entry<String, InputStream> entityInfo = xml.readEntity("ComputerDetail", entityId, Accept.ATOM);

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

    final Entity param = xml.readEntity(utils.getKey(), IOUtils.toInputStream(argument, Constants.ENCODING));

    Property property = param.getProperty("specifications");
    container.getPayload().getProperty("SpecificationsBag").setValue(property.getValueType(), property.getValue());
    property = param.getProperty("purchaseTime");
    container.getPayload().getProperty("PurchaseDate").setValue(property.getValueType(), property.getValue());

    final FSManager fsManager = FSManager.instance();
    fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container),
        fsManager.getAbsolutePath(Commons.getEntityBasePath("ComputerDetail", entityId) + Constants.get(
            ConstantKey.ENTITY), Accept.ATOM));

    return utils.getValue().createResponse(null, null, null, utils.getKey(), Response.Status.NO_CONTENT);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:38,代码来源:Services.java

示例7: createId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if (navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:14,代码来源:Storage.java

示例8: createId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:14,代码来源:Storage.java

示例9: deriveEntityETMixPrimCollComp

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void deriveEntityETMixPrimCollComp() throws Exception {
  final String entityString = "{"
      + "\"PropertyInt16\":32767,"
      + "\"CollPropertyString\":"
      + "[\"[email protected]\",\"[email protected]\",\"[email protected]\"],"
      + "\"PropertyComp\":{\"@odata.type\": \"#olingo.odata.test1.CTBase\","
      + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\",\"AdditionalPropString\":\"Additional\"},"
      + "\"CollPropertyComp\":["
      + "{\"@odata.type\": \"#olingo.odata.test1.CTBase\",\n"
      + "\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\",\"AdditionalPropString\":\"Additional\"},"
      + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
      + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
  final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
  assertNotNull(entity);
  List<Property> properties = entity.getProperties();
  assertNotNull(properties);
  assertEquals(4, properties.size());
  Property prop = entity.getProperty("PropertyComp");
  ComplexValue asComp = prop.asComplex();
  assertEquals(3,asComp.getValue().size());
  assertEquals("olingo.odata.test1.CTBase",prop.getType());
  Property property = entity.getProperty("CollPropertyComp");
  assertEquals(ValueType.COLLECTION_COMPLEX, property.getValueType());

  assertTrue(property.getValue() instanceof List);
  List<? extends Object> asCollection = property.asCollection();
  assertEquals(3, asCollection.size());
  assertEquals(3,((ComplexValue)asCollection.get(0)).getValue().size());
  assertEquals(2,((ComplexValue)asCollection.get(1)).getValue().size());
  assertEquals(2,((ComplexValue)asCollection.get(2)).getValue().size());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:33,代码来源:ODataJsonDeserializerEntityTest.java

示例10: getNavigableEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * This method return the entity which is able to navigate from the parent entity (source) using uri navigation properties.
 * <p/>
 * In this method we check the parent entities foreign keys and return the entity according to the values.
 * we use ODataDataHandler, navigation properties to get particular foreign keys.
 *
 * @param metadata     Service Metadata
 * @param parentEntity Entity (Source)
 * @param navigation   UriResourceNavigation (Destination)
 * @return Entity (Destination)
 * @throws ODataApplicationException
 * @throws ODataServiceFault
 * @see ODataDataHandler#getNavigationProperties()
 */
private Entity getNavigableEntity(ServiceMetadata metadata, Entity parentEntity, UriResourceNavigation navigation,
                                  String baseUrl) throws ODataApplicationException, ODataServiceFault {
    EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType()));
    String linkName = navigation.getProperty().getName();
    List<Property> properties = new ArrayList<>();
    Map<String, EdmProperty> propertyMap = new HashMap<>();
    for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(linkName)
                                               .getNavigationKeys(type.getName())) {
        if (parentEntity.getProperty(keys.getForeignKey()) != null) {
            Property property = parentEntity.getProperty(keys.getForeignKey());
            propertyMap.put(keys.getPrimaryKey(), (EdmProperty) type.getProperty(property.getName()));
            property.setName(keys.getPrimaryKey());
            properties.add(property);
        }
    }
    EntityCollection results;
    results = createEntityCollectionFromDataEntryList(linkName, dataHandler
            .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), baseUrl);
    if (!results.getEntities().isEmpty()) {
        return results.getEntities().get(0);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Reference is not found.");
        }
        return null;
    }
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:42,代码来源:ODataAdapter.java

示例11: updateEntityWithETagMatched

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
   * This method updates the entity to the table by invoking ODataDataHandler updateEntityInTable method.
   *
   * @param edmEntityType  EdmEntityType
   * @param entity         entity with changes
   * @param existingEntity existing entity
   * @param merge          PUT/PATCH
   * @throws ODataApplicationException
   * @throws DataServiceFault
   * @see ODataDataHandler#updateEntityInTableTransactional(String, ODataEntry, ODataEntry)
   */
  private boolean updateEntityWithETagMatched(EdmEntityType edmEntityType, Entity entity, Entity existingEntity,
                                              boolean merge) throws ODataApplicationException, DataServiceFault {
/* loop over all properties and replace the values with the values of the given payload
   Note: ignoring ComplexType, as we don't have it in wso2dss oData model */
      List<Property> oldProperties = existingEntity.getProperties();
      ODataEntry newProperties = new ODataEntry();
      Map<String, EdmProperty> propertyMap = new HashMap<>();
      for (String property : edmEntityType.getPropertyNames()) {
          Property updateProperty = entity.getProperty(property);
          EdmProperty propertyType = (EdmProperty) edmEntityType.getProperty(property);
          if (isKey(edmEntityType, property)) {
              propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
              continue;
          }
          // the request payload might not consider ALL properties, so it can be null
          if (updateProperty == null) {
              // if a property has NOT been added to the request payload
              // depending on the HttpMethod, our behavior is different
              if (merge) {
                  // as of the OData spec, in case of PATCH, the existing property is not touched
                  propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
                  continue;
              } else {
                  // as of the OData spec, in case of PUT, the existing property is set to null (or to default value)
                  propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
                  newProperties.addValue(property, null);
                  continue;
              }
          }
          propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
          newProperties.addValue(property, readPrimitiveValueInString(propertyType, updateProperty.getValue()));
      }
      return this.dataHandler.updateEntityInTableTransactional(edmEntityType.getName(),
                                                               wrapPropertiesToDataEntry(edmEntityType, oldProperties,
                                                                                         propertyMap), newProperties);
  }
 
开发者ID:wso2,项目名称:carbon-data,代码行数:48,代码来源:ODataAdapter.java

示例12: readPrimitiveOrValue

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void readPrimitiveOrValue(ODataRequest request, ODataResponse response, UriInfo uriInfo,
		ContentType responseFormat, Boolean isValue) throws ODataApplicationException, SerializerException {
	// 1. Retrieve info from URI
	// 1.1. retrieve the info about the requested entity set
	List<UriResource> resourceParts = uriInfo.getUriResourceParts();
	UriResourceEntitySet uriEntityset = (UriResourceEntitySet) resourceParts.get(0);
	EdmEntitySet edmEntitySet = uriEntityset.getEntitySet();

	// 1.2. retrieve the requested (Edm) property
	// the second to last segment is the Property, if the last is $value
	UriResource lastResourcePart = resourceParts.get(resourceParts.size() - 1);
	int minSize = 1;
	if (lastResourcePart.getSegmentValue().equals("$value")) {
		minSize++;
	}
	UriResourceProperty uriProperty = (UriResourceProperty) resourceParts.get(resourceParts.size() - minSize);
	EdmProperty edmProperty = uriProperty.getProperty();
	String edmPropertyName = edmProperty.getName();
	EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) edmProperty.getType();

	// 2. retrieve data from backend
	// 2.1. retrieve the entity data, for which the property has to be read
	Entity entity = null;
	try {
		entity = SparqlBaseCommand.readEntity(rdfEdmProvider, uriInfo, UriType.URI5);
	} catch (EdmException | OData2SparqlException | ODataException e) {
		throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
				Locale.ENGLISH);
	}
	if (entity == null) {
		throw new ODataApplicationException("Property not found", HttpStatusCode.NOT_FOUND.getStatusCode(),
				Locale.ENGLISH);
	}
	// 2.2. retrieve the property data from the entity
	Property property = entity.getProperty(edmPropertyName);
	if (property == null) {
		throw new ODataApplicationException("Property not found", HttpStatusCode.NOT_FOUND.getStatusCode(),
				Locale.ENGLISH);
	}

	// 3. serialize
	if (isValue) {
		writePropertyValue(response, property);
	} else {
		writeProperty(request, response, responseFormat, edmEntitySet, edmPropertyName, edmPropertyType, property);
	}

}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:49,代码来源:SparqlPrimitiveValueProcessor.java

示例13: readPrimitive

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public void readPrimitive(ODataRequest request, ODataResponse response,
    UriInfo uriInfo, ContentType responseFormat)
    throws ODataApplicationException, SerializerException {

  // 1. Retrieve info from URI
  // 1.1. retrieve the info about the requested entity set
  List<UriResource> resourceParts = uriInfo.getUriResourceParts();
  // Note: only in our example we can rely that the first segment is the EntitySet
  UriResourceEntitySet uriEntityset = (UriResourceEntitySet) resourceParts.get(0);
  EdmEntitySet edmEntitySet = uriEntityset.getEntitySet();
  // the key for the entity
  List<UriParameter> keyPredicates = uriEntityset.getKeyPredicates();

  // 1.2. retrieve the requested (Edm) property
  // the last segment is the Property
  UriResourceProperty uriProperty = (UriResourceProperty) resourceParts.get(resourceParts.size() - 1);
  EdmProperty edmProperty = uriProperty.getProperty();
  String edmPropertyName = edmProperty.getName();
  // in our example, we know we have only primitive types in our model
  EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) edmProperty.getType();

  // 2. retrieve data from backend
  // 2.1. retrieve the entity data, for which the property has to be read
  Entity entity = storage.readEntityData(edmEntitySet, keyPredicates);
  if (entity == null) { // Bad request
    throw new ODataApplicationException("Entity not found",
        HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH);
  }

  // 2.2. retrieve the property data from the entity
  Property property = entity.getProperty(edmPropertyName);
  if (property == null) {
    throw new ODataApplicationException("Property not found",
        HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ENGLISH);
  }

  // 3. serialize
  Object value = property.getValue();
  if (value != null) {
    // 3.1. configure the serializer
    ODataSerializer serializer = odata.createSerializer(responseFormat);

    ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).navOrPropertyPath(edmPropertyName).build();
    PrimitiveSerializerOptions options = PrimitiveSerializerOptions.with().contextURL(contextUrl).build();
    // 3.2. serialize
    SerializerResult serializerResult = serializer.primitive(serviceMetadata, edmPropertyType, property, options);
    InputStream propertyStream = serializerResult.getContent();

    // 4. configure the response object
    response.setContent(propertyStream);
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
  } else {
    // in case there's no value for the property, we can skip the serialization
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:58,代码来源:DemoPrimitiveProcessor.java

示例14: extendedComplexProperty

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void extendedComplexProperty() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESFourKeyAlias");
  
  String payload = "<?xml version='1.0' encoding='UTF-8'?>"
      + "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" "
      + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
      + "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\">"
        + "<atom:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
        + "term=\"#olingo.odata.test1.ETFourKeyAlias\"/>"
        +  "<atom:content type=\"application/xml\">"
              +  "<metadata:properties>"
                  +  "<data:PropertyInt16 metadata:type=\"Int16\">1</data:PropertyInt16>"
                  +  "<data:PropertyComp metadata:type=\"#olingo.odata.test1.CTTwoPrim\">"
                      +  "<data:PropertyInt16 metadata:type=\"Int16\">11</data:PropertyInt16>"
                      +  "<data:PropertyString>Num11</data:PropertyString>"
                  +  "</data:PropertyComp>"
                  +  "<data:PropertyCompComp metadata:type=\"#olingo.odata.test1.CTCompComp\">"
                      +  "<data:PropertyComp metadata:type=\"#olingo.odata.test1.CTBase\">"
                          +  "<data:PropertyInt16 metadata:type=\"Int16\">111</data:PropertyInt16>"
                          +  "<data:PropertyString>Num111</data:PropertyString>"
                          +  "<data:AdditionalPropString>Test123</data:AdditionalPropString>"
                      +  "</data:PropertyComp>"
                  +  "</data:PropertyCompComp>"
              +  "</metadata:properties>"
            +  "</atom:content>"
        +  "</atom:entry>";
  
  EdmEntityType entityType = edmEntitySet.getEntityType();
  Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()), entityType)
          .getEntity();

  Assert.assertNotNull(result);
  Property propertyCompComp = result.getProperty("PropertyCompComp");
  Assert.assertEquals("PropertyCompComp", propertyCompComp.getName());   
  Assert.assertEquals("olingo.odata.test1.CTCompComp", propertyCompComp.getType());
  Assert.assertTrue(propertyCompComp.isComplex());
  
  ComplexValue complexValuePropComp = propertyCompComp.asComplex();    
  Property propertyComp = getCVProperty(complexValuePropComp, "PropertyComp");
  Assert.assertEquals("PropertyComp", propertyComp.getName()); 
  Assert.assertEquals("olingo.odata.test1.CTBase", propertyComp.getType());
  Assert.assertTrue(propertyComp.isComplex());  
  
  final ComplexValue cvAdditionalString = propertyComp.asComplex();
  Assert.assertEquals("Test123",getCVProperty(cvAdditionalString, "AdditionalPropString").asPrimitive());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:48,代码来源:ODataXmlDeserializerTest.java

示例15: derivedEntityESCompCollDerived

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void derivedEntityESCompCollDerived() throws Exception {
  final String payload = "{\n" +
      "   \"@odata.context\": \"$metadata#ESCompCollDerived/$entity\",\n" +
      "   \"@odata.metadataEtag\":\"W/metadataETag\",\n" +
      "   \"@odata.etag\":\"W/32767\",\n" +
      "   \"PropertyInt16\":32767,\n" +
      "   \"[email protected]\": \"#Collection(olingo.odata.test1.CTTwoPrimAno)\",\n" +
      "   \"CollPropertyCompAno\": [\n" +
      "      {\n" +
      "     \"@odata.type\": \"#olingo.odata.test1.CTBaseAno\",\n" +
      "            \"PropertyString\": \"TEST9876\",\n" +
      "            \"AdditionalPropString\": \"Additional9876\"\n" +
      "        },\n" +
      "        {\n" +
      "            \"@odata.type\": \"#olingo.odata.test1.CTTwoPrimAno\",\n" +
      "            \"PropertyString\": \"TEST1234\"\n" +
      "        }\n" +
      "    ]\n" +
      "   \n" +
      "}";
  final Entity entity = deserialize(payload, "ETDeriveCollComp");
  Assert.assertNotNull(entity);
  List<Property> properties = entity.getProperties();
  assertNotNull(properties);
  assertEquals(2, properties.size());
  assertEquals("PropertyInt16=32767", properties.get(0).toString());
  for (Property prop : properties) {
    assertNotNull(prop);
    if (prop.isCollection()) {
      Property property = entity.getProperty("CollPropertyCompAno");
      assertEquals(ValueType.COLLECTION_COMPLEX, property.getValueType());

      assertTrue(property.getValue() instanceof List);
      List<? extends Object> asCollection = property.asCollection();
      assertEquals(2, asCollection.size());

      for (Object arrayElement : asCollection) {
        assertTrue(arrayElement instanceof ComplexValue);
        List<Property> castedArrayElement = ((ComplexValue) arrayElement).getValue();
        if(castedArrayElement.size() == 1){
          assertEquals("PropertyString=TEST1234", castedArrayElement.get(0).toString());
          assertEquals("olingo.odata.test1.CTTwoPrimAno", ((ComplexValue) arrayElement).getTypeName());
        }else{
          assertEquals(2, castedArrayElement.size());
          assertEquals("AdditionalPropString=Additional9876", castedArrayElement.get(1).toString());
          assertEquals("olingo.odata.test1.CTBaseAno", ((ComplexValue) arrayElement).getTypeName());
        }
      }
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:53,代码来源:ODataJsonDeserializerEntityTest.java


注:本文中的org.apache.olingo.commons.api.data.Entity.getProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。