private boolean hasLink(String theLinkType, Bundle theBundle) { for (Link next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
@Override public void addRootPropertiesToBundle(String theId, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) { myBase = theServerBase; if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); } if (myBundle.getId().isEmpty()) { myBundle.setId(UUID.randomUUID().toString()); } if (ResourceMetadataKeyEnum.UPDATED.get(myBundle) == null) { ResourceMetadataKeyEnum.UPDATED.put(myBundle, (InstantDt) theLastUpdated); } if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theLinkSelf)) { myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); } if (!hasLink(Constants.LINK_NEXT, myBundle) && isNotBlank(theLinkNext)) { myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); } if (!hasLink(Constants.LINK_PREVIOUS, myBundle) && isNotBlank(theLinkPrev)) { myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(theLinkPrev); } if (myBundle.getTypeElement().isEmpty() && theBundleType != null) { myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); } if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) { myBundle.getTotalElement().setValue(theTotalResults); } }
myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode());
/** * Returns the {@link #getLink() link} which matches a given {@link Link#getRelation() relation}. * If no link is found which matches the given relation, creates a new Link with the * given relation and adds it to this Bundle. If more than one * link is found which matches the given relation, returns the first matching Link. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching Link, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public Link getLinkOrCreate(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (Link next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } Link retVal = new Link(); retVal.setRelation(theRelation); getLink().add(retVal); return retVal; }
@Override public void addRootPropertiesToBundle(String theId, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) { ensureBundle(); myBase = theServerBase; if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); } if (myBundle.getId().isEmpty()) { myBundle.setId(UUID.randomUUID().toString()); } if (ResourceMetadataKeyEnum.UPDATED.get(myBundle) == null) { ResourceMetadataKeyEnum.UPDATED.put(myBundle, (InstantDt) theLastUpdated); } if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theLinkSelf)) { myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); } if (!hasLink(Constants.LINK_NEXT, myBundle) && isNotBlank(theLinkNext)) { myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); } if (!hasLink(Constants.LINK_PREVIOUS, myBundle) && isNotBlank(theLinkPrev)) { myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(theLinkPrev); } if (myBundle.getTypeElement().isEmpty() && theBundleType != null) { myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); } if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) { myBundle.getTotalElement().setValue(theTotalResults); } }
/** * Returns the {@link #getLink() link} which matches a given {@link Link#getRelation() relation}. * If no link is found which matches the given relation, returns <code>null</code>. If more than one * link is found which matches the given relation, returns the first matching Link. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching Link, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public Link getLink(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (Link next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } return null; }
/** * Gets the value(s) for <b>relation</b> (). * creating it if it does * not exist. This method may return <code>null</code>. * * <p> * <b>Definition:</b> * A name which details the functional use for this link - see [[http://www.iana.org/assignments/link-relations/link-relations.xhtml]] * </p> */ public String getRelation() { return getRelationElement().getValue(); }
/** * Gets the value(s) for <b>url</b> (). * creating it if it does * not exist. This method may return <code>null</code>. * * <p> * <b>Definition:</b> * The reference details for the link * </p> */ public String getUrl() { return getUrlElement().getValue(); }
/** * Adds and returns a new value for <b>link</b> () * * <p> * <b>Definition:</b> * A series of links that provide context to this bundle * </p> */ public Link addLink() { Link newType = new Link(); getLink().add(newType); return newType; }
/** * Adds and returns a new value for <b>link</b> () * * <p> * <b>Definition:</b> * A series of links that provide context to this entry * </p> */ public Link addLink() { Link newType = new Link(); getLink().add(newType); return newType; }
private boolean hasLink(String theLinkType, Bundle theBundle) { for (Link next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode());