@Override public Link getLink(final ODataLink link, boolean isXML) { final Link linkResource = new LinkImpl(); linkResource.setRel(link.getRel()); linkResource.setTitle(link.getName()); linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString()); linkResource.setType(link.getType().toString()); linkResource.setMediaETag(link.getMediaETag()); if (link instanceof ODataInlineEntity) { // append inline entity final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity(); LOG.debug("Append in-line entity\n{}", inlineEntity); linkResource.setInlineEntry( getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML))); } else if (link instanceof ODataInlineEntitySet) { // append inline feed final ODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet(); LOG.debug("Append in-line feed\n{}", InlineFeed); linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForFormat(isXML))); } return linkResource; }
@Override public Feed getFeed(final ODataEntitySet feed, final Class<? extends Feed> reference) { final Feed feedResource = ResourceFactory.newFeed(reference); feedResource.setCount(feed.getCount()); final URI next = feed.getNext(); if (next != null) { feedResource.setNext(next); } for (ODataEntity entity : feed.getEntities()) { feedResource.getEntries().add(getEntry(entity, ResourceFactory.entryClassForFeed(reference))); } return feedResource; }
@Override public Property getProperty( final ODataProperty property, final Class<? extends Entry> reference, final boolean setType) { final Property propertyResource = ResourceFactory.newProperty(reference); propertyResource.setName(property.getName()); propertyResource.setValue(getValue(property.getValue(), reference, setType)); if (setType) { if (property.hasPrimitiveValue()) { propertyResource.setType(property.getPrimitiveValue().getType().toString()); } else if (property.hasComplexValue()) { propertyResource.setType(property.getComplexValue().getType()); } else if (property.hasCollectionValue()) { propertyResource.setType(property.getCollectionValue().getType()); } } return propertyResource; }
@Override public Entry getEntry( final ODataEntity entity, final Class<? extends Entry> reference, final boolean setType) { final Entry entry = ResourceFactory.newEntry(reference); entry.setType(entity.getName()); // ------------------------------------------------------------- // Add edit and self link // ------------------------------------------------------------- final URI editLink = entity.getEditLink(); if (editLink != null) { final LinkImpl entryEditLink = new LinkImpl(); entryEditLink.setTitle(entity.getName()); entryEditLink.setHref(editLink.toASCIIString()); entryEditLink.setRel(Constants.EDIT_LINK_REL); entry.setEditLink(entryEditLink); } if (entity.isReadOnly()) { final LinkImpl entrySelfLink = new LinkImpl(); entrySelfLink.setTitle(entity.getName()); entrySelfLink.setHref(entity.getLink().toASCIIString()); entrySelfLink.setRel(Constants.SELF_LINK_REL); entry.setSelfLink(entrySelfLink); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append navigation links (handling inline entry / feed as well) // ------------------------------------------------------------- // handle navigation links for (ODataLink link : entity.getNavigationLinks()) { // append link LOG.debug("Append navigation link\n{}", link); entry .getNavigationLinks() .add( getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- for (ODataLink link : entity.getEditMediaLinks()) { LOG.debug("Append edit-media link\n{}", link); entry .getMediaEditLinks() .add( getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append association links // ------------------------------------------------------------- for (ODataLink link : entity.getAssociationLinks()) { LOG.debug("Append association link\n{}", link); entry .getAssociationLinks() .add( getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- if (entity.isMediaEntity()) { entry.setMediaContentSource(entity.getMediaContentSource()); entry.setMediaContentType(entity.getMediaContentType()); } for (ODataProperty property : entity.getProperties()) { entry.getProperties().add(getProperty(property, reference, setType)); } return entry; }