Java Code Examples for org.apache.olingo.commons.api.data.Property#setName()
The following examples show how to use
org.apache.olingo.commons.api.data.Property#setName() .
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: ODataAdapter.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * This method return the entity collection which are able to navigate from the parent entity (source) using uri navigation properties. * <p/> * In this method we check the parent entities primary 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 parentEntity * @param navigation UriResourceNavigation * @return EntityCollection * @throws ODataServiceFault */ private EntityCollection getNavigableEntitySet(ServiceMetadata metadata, Entity parentEntity, EdmNavigationProperty navigation, String url) throws ODataServiceFault, ODataApplicationException { EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType())); String linkName = navigation.getName(); List<Property> properties = new ArrayList<>(); Map<String, EdmProperty> propertyMap = new HashMap<>(); for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(type.getName()) .getNavigationKeys(linkName)) { Property property = parentEntity.getProperty(keys.getPrimaryKey()); if (property != null && !property.isNull()) { propertyMap.put(keys.getForeignKey(), (EdmProperty) type.getProperty(property.getName())); property.setName(keys.getForeignKey()); properties.add(property); } } if(!properties.isEmpty()) { return createEntityCollectionFromDataEntryList(linkName, dataHandler .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), url); } return null; }
Example 2
Source File: Services.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@GET @Path("/StoredPIs(1000)") public Response getStoredPI(@Context final UriInfo uriInfo) { final Entity entity = new Entity(); entity.setType("Microsoft.Test.OData.Services.ODataWCFService.StoredPI"); final Property id = new Property(); id.setType("Edm.Int32"); id.setName("StoredPIID"); id.setValue(ValueType.PRIMITIVE, 1000); entity.getProperties().add(id); final Link edit = new Link(); edit.setHref(uriInfo.getRequestUri().toASCIIString()); edit.setRel("edit"); edit.setTitle("StoredPI"); entity.setEditLink(edit); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); try { jsonSerializer.write(writer, new ResWrap<Entity>((URI) null, null, entity)); return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), null, Accept.JSON_FULLMETA); } catch (Exception e) { LOG.error("While creating StoredPI", e); return xml.createFaultResponse(Accept.JSON_FULLMETA.toString(), e); } }
Example 3
Source File: AtomTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
/** * @return */ private Entity createEntity() { Entity en = new Entity(); Property p1 = new Property(); p1.setName("Id"); p1.setType("Int64"); p1.setValue(ValueType.PRIMITIVE, Long.valueOf(123)); en.addProperty(p1); Property p2 = new Property(); p2.setName("Name"); p2.setType("String"); p2.setValue(ValueType.PRIMITIVE, "ABC"); en.addProperty(p2); return en; }
Example 4
Source File: JSONTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
/** * @return */ private Entity createEntity() { Entity en = new Entity(); Property p1 = new Property(); p1.setName("Id"); p1.setType("Int64"); p1.setValue(ValueType.PRIMITIVE, Long.valueOf(123)); en.addProperty(p1); Property p2 = new Property(); p2.setName("Name"); p2.setType("String"); p2.setValue(ValueType.PRIMITIVE, "ABC"); en.addProperty(p2); return en; }
Example 5
Source File: ODataAdapter.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * 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, EdmNavigationProperty navigation, String baseUrl) throws ODataApplicationException, ODataServiceFault { EdmEntityType type = metadata.getEdm().getEntityType(new FullQualifiedName(parentEntity.getType())); String linkName = navigation.getName(); List<Property> properties = new ArrayList<>(); Map<String, EdmProperty> propertyMap = new HashMap<>(); for (NavigationKeys keys : this.dataHandler.getNavigationProperties().get(linkName) .getNavigationKeys(type.getName())) { Property property = parentEntity.getProperty(keys.getForeignKey()); if (property != null && !property.isNull()) { propertyMap.put(keys.getPrimaryKey(), (EdmProperty) type.getProperty(property.getName())); property.setName(keys.getPrimaryKey()); properties.add(property); } } EntityCollection results = null; if (!properties.isEmpty()) { results = createEntityCollectionFromDataEntryList(linkName, dataHandler .readTableWithKeys(linkName, wrapPropertiesToDataEntry(type, properties, propertyMap)), baseUrl); } if (results != null && !results.getEntities().isEmpty()) { return results.getEntities().get(0); } else { if (log.isDebugEnabled()) { log.debug("Reference is not found."); } return null; } }
Example 6
Source File: JsonDeltaSerializerWithNavigationsTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void deletedEntityWithProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta"); Delta delta = new Delta(); List<DeletedEntity> deletedEntity = new ArrayList<DeletedEntity>(); DeletedEntity entity1 = new DeletedEntity(); entity1.setId(new URI("ESDelta(100)")); entity1.setReason(Reason.deleted); Property property = new Property(); property.setName("Property1"); property.setValue(ValueType.PRIMITIVE, "Value1"); entity1.getProperties().add(property); DeletedEntity entity2 = new DeletedEntity(); entity2.setId(new URI("ESDelta(-32768)")); entity2.setReason(Reason.changed); deletedEntity.add(entity1); deletedEntity.add(entity2); delta.getDeletedEntities().addAll(deletedEntity); InputStream stream = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); String jsonString = IOUtils.toString(stream); final String expectedResult = "{" +"\"@context\":\"$metadata#ESDelta/$delta\",\"value\":[{\"@context\":" + "\"#ESDelta(100)/$deletedEntity\",\"@removed\":{\"reason\":\"deleted\"}," + "\"Property1\":\"Value1\",\"@id\":\"ESDelta(100)\"},{\"@context\":\"#ESDelta(-32768)/$deletedEntity\"," + "\"@removed\":{\"reason\":\"changed\"},\"@id\":\"ESDelta(-32768)\"}]" + "}"; Assert.assertNotNull(jsonString); Assert.assertEquals(expectedResult, jsonString); }
Example 7
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private Property consumePropertyNode(final String name, final EdmType type, final boolean isCollection, final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException { Property property = new Property(); property.setName(name); property.setType(type.getFullQualifiedName().getFullQualifiedNameAsString()); if (isCollection) { consumePropertyCollectionNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode, property); } else { consumePropertySingleNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode, property); } return property; }
Example 8
Source File: ODataBinderImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public Property getProperty(final ClientProperty property) { final Property propertyResource = new Property(); propertyResource.setName(property.getName()); updateValuable(propertyResource, property); annotations(property, propertyResource); return propertyResource; }
Example 9
Source File: Services.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@GET @Path("/Products({entityId})/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails({param:.*})") public Response functionGetProductDetails( @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept, @PathParam("entityId") final String entityId, @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) { try { final Accept acceptType; if (StringUtils.isNotBlank(format)) { acceptType = Accept.valueOf(format.toUpperCase()); } else { acceptType = Accept.parse(accept); } final Entity entry = new Entity(); entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"); final Property productId = new Property(); productId.setName("ProductID"); productId.setType("Edm.Int32"); productId.setValue(ValueType.PRIMITIVE, Integer.valueOf(entityId)); entry.getProperties().add(productId); final Property productDetailId = new Property(); productDetailId.setName("ProductDetailID"); productDetailId.setType("Edm.Int32"); productDetailId.setValue(ValueType.PRIMITIVE, 2); entry.getProperties().add(productDetailId); final Link link = new Link(); link.setRel("edit"); link.setHref(URI.create( Constants.get(ConstantKey.DEFAULT_SERVICE_URL) + "ProductDetails(ProductID=6,ProductDetailID=1)").toASCIIString()); entry.setEditLink(link); final EntityCollection feed = new EntityCollection(); feed.getEntities().add(entry); final ResWrap<EntityCollection> container = new ResWrap<EntityCollection>( URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null, feed); return xml.createResponse( null, xml.writeEntitySet(acceptType, container), null, acceptType); } catch (Exception e) { return xml.createFaultResponse(accept, e); } }