org.apache.olingo.commons.api.Constants Java Examples
The following examples show how to use
org.apache.olingo.commons.api.Constants.
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: Storage.java From olingo-odata4 with Apache License 2.0 | 6 votes |
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 #2
Source File: ODataDeserializerDeepUpdateTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void esAllPrimExpandedToManyDelta() throws Exception { final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimManyDelta.json"); Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany"); assertNotNull(navigationLink); assertEquals("NavPropertyETTwoPrimMany", navigationLink.getTitle()); assertEquals(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE, navigationLink.getType()); assertNull(navigationLink.getInlineEntity()); assertNotNull(navigationLink.getInlineEntitySet()); assertEquals(3, navigationLink.getInlineEntitySet().getEntities().size()); assertEquals("ESAllPrim(5)",navigationLink.getInlineEntitySet().getEntities().get(0).getId().toString()); assertEquals("ESAllPrim(6)",navigationLink.getInlineEntitySet().getEntities().get(1).getId().toString()); assertNull(navigationLink.getInlineEntitySet().getEntities().get(2).getId()); Delta delta = ((Delta)navigationLink.getInlineEntitySet()); assertEquals(2, delta.getDeletedEntities().size()); assertNotNull(delta.getDeletedEntities().get(0).getId()); assertNotNull(delta.getDeletedEntities().get(1).getId()); assertEquals(Reason.deleted, delta.getDeletedEntities().get(0).getReason()); assertEquals(Reason.changed, delta.getDeletedEntities().get(1).getReason()); }
Example #3
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { json.writeStartArray(); for (Object value : property.asCollection()) { switch (property.getValueType()) { case COLLECTION_COMPLEX: json.writeStartObject(); if (isODataMetadataFull) { json.writeStringField(Constants.JSON_TYPE, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); } writeComplexValue(metadata, type, ((ComplexValue) value).getValue(), selectedPaths, json); json.writeEndObject(); break; default: throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); } } json.writeEndArray(); }
Example #4
Source File: AtomGeoValueDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private MultiPoint multipoint(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException { List<Point> points = Collections.<Point> emptyList(); boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POINTMEMBERS)) { points = points(reader, event.asStartElement(), type, null); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new MultiPoint(GeoUtils.getDimension(type), srid, points); }
Example #5
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType, final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select, final boolean onlyReference, String name, final JsonGenerator json, boolean isFullRepresentation) throws IOException, SerializerException { if (entitySet instanceof AbstractEntityCollection) { AbstractEntityCollection entities = (AbstractEntityCollection)entitySet; json.writeStartArray(); for (final Entity entity : entities) { if (onlyReference) { json.writeStartObject(); json.writeStringField(Constants.JSON_ID, getEntityId(entity, entityType, null)); json.writeEndObject(); } else { if (entity instanceof DeletedEntity) { writeDeletedEntity(entity, json); } else { writeAddedUpdatedEntity(metadata, entityType, entity, expand, select, null, false, name, json, isFullRepresentation); } } } json.writeEndArray(); } }
Example #6
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void writeAddedUpdatedEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ExpandOption expand, final SelectOption select, final ContextURL url, final boolean onlyReference, String name, final JsonGenerator json, boolean isFullRepresentation) throws IOException, SerializerException { json.writeStartObject(); if (entity.getId() != null && url != null) { name = url.getEntitySetOrSingletonOrType(); String entityId = entity.getId().toString(); if (!entityId.contains(name)) { String entityName = entityId.substring(0, entityId.indexOf("(")); if (!entityName.equals(name)) { json.writeStringField(Constants.AT + Constants.CONTEXT, Constants.HASH + entityName + Constants.ENTITY); } } } String id = getEntityId(entity, entityType, name); json.writeStringField(Constants.AT + Constants.ATOM_ATTR_ID, id); writeProperties(metadata, entityType, entity.getProperties(), select, json); writeNavigationProperties(metadata, entityType, entity, expand, id, json, isFullRepresentation); json.writeEndObject(); }
Example #7
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected static 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); EntityCollection target = new EntityCollection(); target.getEntities().addAll(Arrays.asList(targets)); link.setInlineEntitySet(target); link.setHref(entity.getId().toASCIIString() + "/" + navigationPropertyName); entity.getNavigationLinks().add(link); } else { link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets)); } }
Example #8
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private EntityCollection consumeEntityCollectionNode(final EdmEntityType edmEntityType, final ObjectNode tree, final ExpandTreeBuilder expandBuilder) throws DeserializerException { EntityCollection entitySet = new EntityCollection(); // Consume entities JsonNode jsonNode = tree.get(Constants.VALUE); if (jsonNode != null) { entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode, expandBuilder)); tree.remove(Constants.VALUE); } else { throw new DeserializerException("Could not find value array.", DeserializerException.MessageKeys.VALUE_ARRAY_NOT_PRESENT); } if (tree.isObject()) { removeAnnotations(tree); } assertJsonNodeIsEmpty(tree); return entitySet; }
Example #9
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void writeAddedUpdatedEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ExpandOption expand, final SelectOption select, final ContextURL url, final boolean onlyReference, String name, final JsonGenerator json) throws IOException, SerializerException { json.writeStartObject(); if (entity.getId() != null && url != null) { String entityId = entity.getId().toString(); name = url.getEntitySetOrSingletonOrType(); if (!entityId.contains(name)) { String entityName = entityId.substring(0, entityId.indexOf("(")); if (!entityName.equals(name)) { json.writeStringField(Constants.JSON_CONTEXT, HASH + entityName + ENTITY); } } } json.writeStringField(Constants.JSON_ID, getEntityId(entity, entityType, name)); writeProperties(metadata, entityType, entity.getProperties(), select, json); json.writeEndObject(); }
Example #10
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private <T> void addContextInfo( final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException { if (container.getContextURL() != null) { final ContextURL contextURL = ContextURLParser.parse(container.getContextURL()); final URI base = contextURL.getServiceRoot(); if (container.getPayload() instanceof EntityCollection) { ((EntityCollection) container.getPayload()).setBaseURI(base); } if (container.getPayload() instanceof Entity) { ((Entity) container.getPayload()).setBaseURI(base); } writer.writeAttribute(Constants.NS_METADATA, Constants.CONTEXT, container.getContextURL().toASCIIString()); } if (container.getMetadataETag() != null) { writer.writeAttribute(Constants.NS_METADATA, Constants.ATOM_ATTR_METADATAETAG, container.getMetadataETag()); } }
Example #11
Source File: EdmAssistedJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void complexValue(final JsonGenerator json, final EdmComplexType valueType, final String typeName, final ComplexValue value) throws IOException, SerializerException { json.writeStartObject(); if (typeName != null && isODataMetadataFull) { json.writeStringField(Constants.JSON_TYPE, typeName); } for (final Property property : value.getValue()) { final String name = property.getName(); final EdmProperty edmProperty = valueType == null || valueType.getStructuralProperty(name) == null ? null : valueType.getStructuralProperty(name); valuable(json, property, name, edmProperty == null ? null : edmProperty.getType(), edmProperty); } links(value, null, json); json.writeEndObject(); }
Example #12
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeComplexCollection(final ServiceMetadata metadata, final EdmComplexType type, final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json) throws IOException, SerializerException { json.writeStartArray(); for (Object value : property.asCollection()) { switch (property.getValueType()) { case COLLECTION_COMPLEX: json.writeStartObject(); if (isODataMetadataFull) { json.writeStringField(Constants.JSON_TYPE, "#" + type.getFullQualifiedName().getFullQualifiedNameAsString()); } writeComplexValue(metadata, type, ((ComplexValue) value).getValue(), selectedPaths, json); json.writeEndObject(); break; default: throw new SerializerException("Property type not yet supported!", SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); } } json.writeEndArray(); }
Example #13
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeLink(final XMLStreamWriter writer, final Link link, final ExtraContent content) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.ATOM_ELEM_LINK); if (link.getRel() != null) { writer.writeAttribute(Constants.ATTR_REL, link.getRel()); } if (link.getTitle() != null) { writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle()); } if (link.getHref() != null) { writer.writeAttribute(Constants.ATTR_HREF, link.getHref()); } if (link.getType() != null) { writer.writeAttribute(Constants.ATTR_TYPE, link.getType()); } content.write(writer, link); for (Annotation annotation : link.getAnnotations()) { annotation(writer, annotation, null); } writer.writeEndElement(); }
Example #14
Source File: AtomGeoValueDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException { final List<LineString> lineStrings = new ArrayList<>(); boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_LINESTRING)) { lineStrings.add(lineString(reader, event.asStartElement(), type, null)); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new MultiLineString(GeoUtils.getDimension(type), srid, lineStrings); }
Example #15
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void linkCollPropCompInESCompMixPrimCollCompToETTwoKeyNav(Map<String, EntityCollection> data2) { EntityCollection collection = data.get("ESCompMixPrimCollComp"); Entity entity = collection.getEntities().get(0); ComplexValue complexValue = entity.getProperties().get(1).asComplex(); List<ComplexValue> innerComplexValue = (List<ComplexValue>) complexValue.getValue().get(3).asCollection(); final List<Entity> esTwoKeyNavTargets = data.get("ESTwoKeyNav").getEntities(); for (ComplexValue innerValue : innerComplexValue) { Link link = new Link(); link.setRel(Constants.NS_NAVIGATION_LINK_REL + "NavPropertyETTwoKeyNavOne"); link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE); link.setTitle("NavPropertyETTwoKeyNavOne"); link.setHref(esTwoKeyNavTargets.get(1).getId().toASCIIString()); innerValue.getNavigationLinks().add(link); link.setInlineEntity(esTwoKeyNavTargets.get(1)); } }
Example #16
Source File: DataCreator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void linkETStreamOnComplexPropWithNavigationPropertyMany( Map<String, EntityCollection> data) { EntityCollection collection = data.get("ESStreamOnComplexProp"); Entity entity = collection.getEntities().get(1); ComplexValue complexValue = entity.getProperties().get(3).asComplex(); final List<Entity> esStreamTargets = data.get("ESWithStream").getEntities(); Link link = new Link(); link.setRel(Constants.NS_NAVIGATION_LINK_REL + "NavPropertyETStreamOnComplexPropMany"); link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE); link.setTitle("NavPropertyETStreamOnComplexPropMany"); EntityCollection target = new EntityCollection(); target.setCount(2); target.getEntities().addAll(Arrays.asList(esStreamTargets.get(0), esStreamTargets.get(1))); link.setInlineEntitySet(target); link.setHref(entity.getId().toASCIIString() + "/" + entity.getProperties().get(3).getName() + "/" + "NavPropertyETStreamOnComplexPropMany"); complexValue.getNavigationLinks().add(link); }
Example #17
Source File: AtomGeoValueSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void lineStrings(final XMLStreamWriter writer, final Iterator<LineString> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final LineString lineString = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRING, Constants.NS_GML); } points(writer, lineString.iterator(), false); if (wrap) { writer.writeEndElement(); } } }
Example #18
Source File: JsonODataErrorDetailDeserializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected ResWrap<ODataErrorDetail> doDeserialize(final JsonParser parser) throws IOException { final ODataErrorDetail error = new ODataErrorDetail(); final JsonNode errorNode = parser.getCodec().readTree(parser); if (errorNode.has(Constants.ERROR_CODE)) { error.setCode(errorNode.get(Constants.ERROR_CODE).textValue()); } if (errorNode.has(Constants.ERROR_MESSAGE)) { final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE); if (message.isValueNode()) { error.setMessage(message.textValue()); } else if (message.isObject()) { error.setMessage(message.get(Constants.VALUE).asText()); } } if (errorNode.has(Constants.ERROR_TARGET)) { error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue()); } return new ResWrap<>((URI) null, null, error); }
Example #19
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(NS_ATOM, Constants.ATTR_TITLE); if (title != null) { writer.writeCharacters(title); } writer.writeEndElement(); writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_SUMMARY); writer.writeEndElement(); writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_UPDATED); writer.writeCharacters(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") .format(new Date(System.currentTimeMillis()))); writer.writeEndElement(); writer.writeStartElement(NS_ATOM, "author"); writer.writeStartElement(NS_ATOM, "name"); writer.writeEndElement(); writer.writeEndElement(); }
Example #20
Source File: ClientEntitySetIterator.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) { final ByteArrayOutputStream attrs = new ByteArrayOutputStream(); String res; try { byte[] attrsDeclaration = null; final String key = "<" + name + " "; if (consume(input, key, os, true) >= 0 && consume(input, ">", attrs, false) >= 0) { attrsDeclaration = attrs.toByteArray(); os.write(attrsDeclaration); os.write('>'); } res = attrsDeclaration == null ? "" : new String(attrsDeclaration, Constants.UTF8).trim(); } catch (Exception e) { LOG.error("Error retrieving entities from EntitySet", e); res = ""; } return res.endsWith("/") ? res.substring(0, res.length() - 1) : res; }
Example #21
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
protected Link getOrCreateLink(final Linked linked, final String navigationPropertyName) throws XMLStreamException { Link link = linked.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); EntityCollection target = new EntityCollection(); link.setInlineEntitySet(target); if (linked.getId() != null) { link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName); } } return link; }
Example #22
Source File: ODataXmlSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writeMetadataETag(final ServiceMetadata metadata, final XMLStreamWriter writer) throws XMLStreamException { if (metadata != null && metadata.getServiceMetadataETagSupport() != null && metadata.getServiceMetadataETagSupport().getMetadataETag() != null) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG, metadata.getServiceMetadataETagSupport().getMetadataETag()); } }
Example #23
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void common(final XMLStreamWriter writer, final AbstractODataObject object) throws XMLStreamException { if (object.getTitle() != null) { writer.writeStartElement(Constants.ATOM_ELEM_TITLE); writer.writeAttribute(Constants.ATTR_TYPE, TYPE_TEXT); writer.writeCharacters(object.getTitle()); writer.writeEndElement(); } }
Example #24
Source File: AtomGeoValueSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final Point point = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML); } writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML); try { writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null) + " " + EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); } catch (EdmPrimitiveTypeException e) { throw new XMLStreamException("While serializing point coordinates as double", e); } writer.writeEndElement(); if (wrap) { writer.writeEndElement(); } } }
Example #25
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 5 votes |
boolean writeNextLink(final AbstractEntityCollection entitySet, final JsonGenerator json) throws IOException { if (entitySet.getNext() != null) { json.writeStringField(Constants.NEXTLINK, entitySet.getNext().toASCIIString()); return true; } else { return false; } }
Example #26
Source File: JSONTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected void assertSimilarWithFullMetadata(final String filename, final String actual, boolean isServerMode) throws Exception { String value = IOUtils.toString(getClass().getResourceAsStream(filename)); final JsonNode expected = isServerMode ? OBJECT_MAPPER.readTree(value. replace(Constants.JSON_MEDIA_EDIT_LINK, Constants.JSON_MEDIA_READ_LINK)) : OBJECT_MAPPER.readTree(value. replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX)); cleanupWithFullMetadata((ObjectNode) expected, isServerMode); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); cleanupWithFullMetadata(actualNode, isServerMode); assertEquals(expected, actualNode); }
Example #27
Source File: EdmAssistedJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected void doSerialize(final EdmEntityType entityType, final AbstractEntityCollection entityCollection, final String contextURLString, final String metadataETag, JsonGenerator json) throws IOException, SerializerException { json.writeStartObject(); metadata(contextURLString, metadataETag, null, null, entityCollection.getId(), false, json); if (entityCollection.getCount() != null) { if (isIEEE754Compatible) { json.writeStringField(Constants.JSON_COUNT, Integer.toString(entityCollection.getCount())); } else { json.writeNumberField(Constants.JSON_COUNT, entityCollection.getCount()); } } if (entityCollection.getDeltaLink() != null) { json.writeStringField(Constants.JSON_DELTA_LINK, entityCollection.getDeltaLink().toASCIIString()); } for (final Annotation annotation : entityCollection.getAnnotations()) { valuable(json, annotation, '@' + annotation.getTerm(), null, null); } json.writeArrayFieldStart(Constants.VALUE); for (final Entity entity : entityCollection) { doSerialize(entityType, entity, null, null, json); } json.writeEndArray(); if (entityCollection.getNext() != null) { json.writeStringField(Constants.JSON_NEXT_LINK, entityCollection.getNext().toASCIIString()); } json.writeEndObject(); }
Example #28
Source File: JsonDeltaSerializerWithNavigations.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void writeLink(DeltaLink link, EntityCollectionSerializerOptions options, JsonGenerator json, boolean isAdded) throws IOException, SerializerException { try { json.writeStartObject(); String entityId = options.getContextURL().getEntitySetOrSingletonOrType();// throw error if not set id String operation = isAdded ? Constants.LINK : Constants.DELETEDLINK; json.writeStringField(Constants.AT + Constants.CONTEXT, Constants.HASH + entityId + operation); if (link != null) { if (link.getSource() != null) { json.writeStringField(Constants.ATTR_SOURCE, link.getSource().toString()); } else { throw new SerializerException("DeltaLink source is null.", SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, "Source"); } if (link.getRelationship() != null) { json.writeStringField(Constants.ATTR_RELATIONSHIP, link.getRelationship().toString()); } else { throw new SerializerException("DeltaLink relationship is null.", SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, "Relationship"); } if (link.getTarget() != null) { json.writeStringField(Constants.ERROR_TARGET, link.getTarget().toString()); } else { throw new SerializerException("DeltaLink target is null.", SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, "Target"); } } else { throw new SerializerException("DeltaLink is null.", SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, "Delta Link"); } json.writeEndObject(); } catch (IOException e) { throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID); } }
Example #29
Source File: ODataErrorSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public void writeErrorDocument(final JsonGenerator json, final ODataError error) throws IOException, SerializerException { if (error == null) { throw new SerializerException("ODataError object MUST NOT be null!", SerializerException.MessageKeys.NULL_INPUT); } json.writeStartObject(); json.writeFieldName(Constants.JSON_ERROR); json.writeStartObject(); writeODataError(json, error.getCode(), error.getMessage(), error.getTarget()); writeODataAdditionalProperties(json, error.getAdditionalProperties()); if (error.getDetails() != null) { json.writeArrayFieldStart(Constants.ERROR_DETAILS); for (ODataErrorDetail detail : error.getDetails()) { json.writeStartObject(); writeODataError(json, detail.getCode(), detail.getMessage(), detail.getTarget()); writeODataAdditionalProperties(json, detail.getAdditionalProperties()); json.writeEndObject(); } json.writeEndArray(); } json.writeEndObject(); json.writeEndObject(); }
Example #30
Source File: JSONTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void assertJSONSimilar(final String filename, final String actual) throws Exception { final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) expected, false); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); cleanup(actualNode, false); assertEquals(expected, actualNode); }