Merge branch 'tags-set'
This commit is contained in:
commit
3eeea9b0fc
|
@ -7,6 +7,12 @@
|
|||
</properties>
|
||||
<body>
|
||||
<release version="0.7" date="TBD">
|
||||
<action type="add" issue="30">
|
||||
<![CDATA[<b>API CHANGE:</b>]]> The TagList class previously implemented ArrayList semantics,
|
||||
but this has been replaced with LinkedHashMap semantics. This means that the list of
|
||||
tags will no longer accept duplicate tags, but that tag order will still be
|
||||
preserved. Thanks to Bill de Beaubien for reporting!
|
||||
</action>
|
||||
<action type="add" dev="suranga">
|
||||
Documentation fixes
|
||||
</action>
|
||||
|
|
|
@ -59,12 +59,20 @@ public class Bundle extends BaseBundle /* implements IElement */{
|
|||
private IntegerDt myTotalResults;
|
||||
private InstantDt myUpdated;
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
|
||||
*/
|
||||
public Tag addCategory() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
|
|
@ -50,12 +50,19 @@ public class BundleEntry extends BaseBundle {
|
|||
private StringDt myTitle;
|
||||
private InstantDt myUpdated;
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
|
||||
*/
|
||||
public Tag addCategory() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
|
|
@ -28,38 +28,52 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* A single tag
|
||||
* <p>
|
||||
* Note on equality- When computing hashCode or equals values for this class, only the
|
||||
* {@link #getScheme() scheme} and
|
||||
* </p>
|
||||
*/
|
||||
public class Tag extends BaseElement implements IElement {
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag" scheme
|
||||
* value
|
||||
*/
|
||||
public static final String HL7_ORG_FHIR_TAG = "http://hl7.org/fhir/tag";
|
||||
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag/security" scheme
|
||||
* value
|
||||
*/
|
||||
public static final String HL7_ORG_SECURITY_TAG = "http://hl7.org/fhir/tag/security";
|
||||
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag/profile" scheme
|
||||
* value
|
||||
*/
|
||||
public static final String HL7_ORG_PROFILE_TAG = "http://hl7.org/fhir/tag/profile";
|
||||
|
||||
public static final String ATTR_TERM = "term";
|
||||
public static final String ATTR_LABEL = "label";
|
||||
public static final String ATTR_SCHEME = "scheme";
|
||||
public static final String ATTR_TERM = "term";
|
||||
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag" scheme value
|
||||
*/
|
||||
public static final String HL7_ORG_FHIR_TAG = "http://hl7.org/fhir/tag";
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag/profile" scheme value
|
||||
*/
|
||||
public static final String HL7_ORG_PROFILE_TAG = "http://hl7.org/fhir/tag/profile";
|
||||
/**
|
||||
* Convenience constant containing the "http://hl7.org/fhir/tag/security" scheme value
|
||||
*/
|
||||
public static final String HL7_ORG_SECURITY_TAG = "http://hl7.org/fhir/tag/security";
|
||||
|
||||
private String myLabel;
|
||||
private String myScheme;
|
||||
private String myTerm;
|
||||
|
||||
/**
|
||||
* @deprecated Tags will become immutable in a future release, so this constructor should not be used.
|
||||
*/
|
||||
public Tag() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated There is no reason to create a tag with a term and not a scheme, so this constructor will be removed
|
||||
*/
|
||||
public Tag(String theTerm) {
|
||||
this((String)null, theTerm, null);
|
||||
this((String) null, theTerm, null);
|
||||
}
|
||||
|
||||
public Tag(String theScheme, String theTerm) {
|
||||
myScheme = theScheme;
|
||||
myTerm = theTerm;
|
||||
}
|
||||
|
||||
public Tag(String theScheme, String theTerm, String theLabel) {
|
||||
|
@ -78,32 +92,6 @@ public class Tag extends BaseElement implements IElement {
|
|||
myLabel = theLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tag other = (Tag) obj;
|
||||
if (myLabel == null) {
|
||||
if (other.myLabel != null)
|
||||
return false;
|
||||
} else if (!myLabel.equals(other.myLabel))
|
||||
return false;
|
||||
if (myScheme == null) {
|
||||
if (other.myScheme != null)
|
||||
return false;
|
||||
} else if (!myScheme.equals(other.myScheme))
|
||||
return false;
|
||||
if (myTerm == null) {
|
||||
if (other.myTerm != null)
|
||||
return false;
|
||||
} else if (!myTerm.equals(other.myTerm))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return myLabel;
|
||||
|
@ -117,11 +105,32 @@ public class Tag extends BaseElement implements IElement {
|
|||
return myTerm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tag other = (Tag) obj;
|
||||
if (myScheme == null) {
|
||||
if (other.myScheme != null)
|
||||
return false;
|
||||
} else if (!myScheme.equals(other.myScheme))
|
||||
return false;
|
||||
if (myTerm == null) {
|
||||
if (other.myTerm != null)
|
||||
return false;
|
||||
} else if (!myTerm.equals(other.myTerm))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((myLabel == null) ? 0 : myLabel.hashCode());
|
||||
result = prime * result + ((myScheme == null) ? 0 : myScheme.hashCode());
|
||||
result = prime * result + ((myTerm == null) ? 0 : myTerm.hashCode());
|
||||
return result;
|
||||
|
@ -132,16 +141,31 @@ public class Tag extends BaseElement implements IElement {
|
|||
return StringUtils.isBlank(myLabel) && StringUtils.isBlank(myScheme) && StringUtils.isBlank(myTerm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||
* tag object
|
||||
*/
|
||||
public Tag setLabel(String theLabel) {
|
||||
myLabel = theLabel;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||
* tag object
|
||||
*/
|
||||
public Tag setScheme(String theScheme) {
|
||||
myScheme = theScheme;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Tags will become immutable in a future release of HAPI in order to facilitate
|
||||
* ensuring that the TagList acts as an unordered set. Use the constructor to set this field when creating a new
|
||||
* tag object
|
||||
*/
|
||||
public Tag setTerm(String theTerm) {
|
||||
myTerm = theTerm;
|
||||
return this;
|
||||
|
|
|
@ -20,24 +20,146 @@ package ca.uhn.fhir.model.api;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TagList extends ArrayList<Tag> {
|
||||
/**
|
||||
* A collection of tags present on a single resource. TagList is backed by a {@link LinkedHashSet}, so the order of added tags will be consistent, but duplicates will not be preserved.
|
||||
*
|
||||
* <p>
|
||||
* <b>Thread safety:</b> This class is not thread safe
|
||||
* </p>
|
||||
*/
|
||||
public class TagList implements Set<Tag>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String ATTR_CATEGORY = "category";
|
||||
public static final String ELEMENT_NAME = "TagList";
|
||||
public static final String ELEMENT_NAME_LC = ELEMENT_NAME.toLowerCase();
|
||||
|
||||
public Tag addTag(String theScheme, String theTerm, String theLabel) {
|
||||
Tag retVal = new Tag(theScheme, theTerm, theLabel);
|
||||
public static final String ELEMENT_NAME_LC = ELEMENT_NAME.toLowerCase();
|
||||
private static final long serialVersionUID = 1L;
|
||||
private transient List<Tag> myOrderedTags;
|
||||
private LinkedHashSet<Tag> myTagSet = new LinkedHashSet<Tag>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public TagList() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("TagList[").append(size()).append(" tag(s)]");
|
||||
for (Tag next : this) {
|
||||
b.append("\n * ").append(next.toString());
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Tag theE) {
|
||||
myOrderedTags = null;
|
||||
return myTagSet.add(theE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Tag> theC) {
|
||||
myOrderedTags = null;
|
||||
return myTagSet.addAll(theC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addTag(String, String, String)} should be used instead
|
||||
*/
|
||||
public Tag addTag() {
|
||||
myOrderedTags = null;
|
||||
return addTag(null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new tag instance
|
||||
*
|
||||
* @param theScheme
|
||||
* The tag scheme
|
||||
* @param theTerm
|
||||
* The tag term
|
||||
* @return Returns the newly created tag instance. Note that the tag is added to the list by this method, so you generally do not need to interact directly with the added tag.
|
||||
*/
|
||||
public Tag addTag(String theScheme, String theTerm) {
|
||||
Tag retVal = new Tag(theScheme, theTerm);
|
||||
add(retVal);
|
||||
myOrderedTags = null;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public Tag addTag() {
|
||||
return addTag(null, null, null);
|
||||
/**
|
||||
* Add a new tag instance
|
||||
*
|
||||
* @param theScheme
|
||||
* The tag scheme
|
||||
* @param theTerm
|
||||
* The tag term
|
||||
* @param theLabel
|
||||
* The tag label
|
||||
* @return Returns the newly created tag instance. Note that the tag is added to the list by this method, so you generally do not need to interact directly with the added tag.
|
||||
*/
|
||||
public Tag addTag(String theScheme, String theTerm, String theLabel) {
|
||||
Tag retVal = new Tag(theScheme, theTerm, theLabel);
|
||||
add(retVal);
|
||||
myOrderedTags = null;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
myOrderedTags = null;
|
||||
myTagSet.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object theO) {
|
||||
return myTagSet.contains(theO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> theC) {
|
||||
return myTagSet.containsAll(theC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TagList other = (TagList) obj;
|
||||
if (myTagSet == null) {
|
||||
if (other.myTagSet != null)
|
||||
return false;
|
||||
} else if (!myTagSet.equals(other.myTagSet))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tag at a given index - Note that the TagList is backed by a {@link LinkedHashSet}, so the order of added tags will be consistent, but duplicates will not be preserved.
|
||||
*/
|
||||
public Tag get(int theIndex) {
|
||||
if (myOrderedTags == null) {
|
||||
myOrderedTags = new ArrayList<Tag>();
|
||||
for (Tag next : myTagSet) {
|
||||
myOrderedTags.add(next);
|
||||
}
|
||||
}
|
||||
return myOrderedTags.get(theIndex);
|
||||
}
|
||||
|
||||
public Tag getTag(String theScheme, String theTerm) {
|
||||
|
@ -59,4 +181,52 @@ public class TagList extends ArrayList<Tag> {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myTagSet.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myTagSet.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Tag> iterator() {
|
||||
return myTagSet.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object theO) {
|
||||
myOrderedTags = null;
|
||||
return myTagSet.remove(theO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> theC) {
|
||||
myOrderedTags = null;
|
||||
return myTagSet.removeAll(theC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> theC) {
|
||||
myOrderedTags = null;
|
||||
return myTagSet.retainAll(theC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return myTagSet.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return myTagSet.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] theA) {
|
||||
return myTagSet.toArray(theA);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -158,8 +158,7 @@ class ParserState<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically
|
||||
* intended for embedded XHTML content
|
||||
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically intended for embedded XHTML content
|
||||
*/
|
||||
public void xmlEvent(XMLEvent theNextEvent) {
|
||||
myState.xmlEvent(theNextEvent);
|
||||
|
@ -222,35 +221,37 @@ class ParserState<T> {
|
|||
private static final int STATE_TERM = 1;
|
||||
|
||||
private int myCatState = STATE_NONE;
|
||||
private Tag myInstance;
|
||||
private TagList myTagList;
|
||||
private String myTerm;
|
||||
private String myLabel;
|
||||
private String myScheme;
|
||||
|
||||
public AtomCategoryState(Tag theEntry) {
|
||||
public AtomCategoryState(TagList theTagList) {
|
||||
super(null);
|
||||
myInstance = theEntry;
|
||||
myTagList = theTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
if ("term".equals(theName)) {
|
||||
myInstance.setTerm(theValue);
|
||||
myTerm = theValue;
|
||||
} else if ("label".equals(theName)) {
|
||||
myInstance.setLabel(theValue);
|
||||
myLabel = theValue;
|
||||
} else if ("scheme".equals(theName)) {
|
||||
myInstance.setScheme(theValue);
|
||||
myScheme = theValue;
|
||||
} else if ("value".equals(theName)) {
|
||||
/*
|
||||
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values
|
||||
* instead of one like everything else.
|
||||
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values instead of one like everything else.
|
||||
*/
|
||||
switch (myCatState) {
|
||||
case STATE_LABEL:
|
||||
myInstance.setLabel(theValue);
|
||||
myLabel = theValue;
|
||||
break;
|
||||
case STATE_TERM:
|
||||
myInstance.setTerm(theValue);
|
||||
myTerm = theValue;
|
||||
break;
|
||||
case STATE_SCHEME:
|
||||
myInstance.setScheme(theValue);
|
||||
myScheme = theValue;
|
||||
break;
|
||||
default:
|
||||
super.string(theValue);
|
||||
|
@ -265,6 +266,9 @@ class ParserState<T> {
|
|||
if (myCatState != STATE_NONE) {
|
||||
myCatState = STATE_NONE;
|
||||
} else {
|
||||
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
}
|
||||
|
@ -422,7 +426,7 @@ class ParserState<T> {
|
|||
} else if ("summary".equals(theLocalPart)) {
|
||||
push(new XhtmlState(getPreResourceState(), myEntry.getSummary(), false));
|
||||
} else if ("category".equals(theLocalPart)) {
|
||||
push(new AtomCategoryState(myEntry.addCategory()));
|
||||
push(new AtomCategoryState(myEntry.getCategories()));
|
||||
} else if ("deleted".equals(theLocalPart) && myJsonMode) {
|
||||
// JSON and XML deleted entries are completely different for some reason
|
||||
myDeleted = true;
|
||||
|
@ -629,7 +633,7 @@ class ParserState<T> {
|
|||
} else if ("author".equals(theLocalPart)) {
|
||||
push(new AtomAuthorState(myInstance));
|
||||
} else if ("category".equals(theLocalPart)) {
|
||||
push(new AtomCategoryState(myInstance.getCategories().addTag()));
|
||||
push(new AtomCategoryState(myInstance.getCategories()));
|
||||
} else if ("deleted-entry".equals(theLocalPart) && verifyNamespace(XmlParser.TOMBSTONES_NS, theNamespaceURI)) {
|
||||
push(new AtomDeletedEntryState(myInstance, myResourceType));
|
||||
} else {
|
||||
|
@ -707,7 +711,8 @@ class ParserState<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param theData The string value
|
||||
* @param theData
|
||||
* The string value
|
||||
*/
|
||||
public void string(String theData) {
|
||||
// ignore by default
|
||||
|
@ -718,7 +723,8 @@ class ParserState<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param theNextEvent The XML event
|
||||
* @param theNextEvent
|
||||
* The XML event
|
||||
*/
|
||||
public void xmlEvent(XMLEvent theNextEvent) {
|
||||
// ignore
|
||||
|
@ -1275,7 +1281,8 @@ class ParserState<T> {
|
|||
myContext.newTerser().visit(myInstance, new IModelVisitor() {
|
||||
|
||||
@Override
|
||||
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt) {
|
||||
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition,
|
||||
ExtensionDt theNextExt) {
|
||||
acceptElement(theNextExt.getValue(), null, null);
|
||||
}
|
||||
|
||||
|
@ -1508,7 +1515,7 @@ class ParserState<T> {
|
|||
@Override
|
||||
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
|
||||
if (TagList.ATTR_CATEGORY.equals(theLocalPart)) {
|
||||
push(new TagState(myTagList.addTag()));
|
||||
push(new TagState(myTagList));
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected element: " + theLocalPart);
|
||||
}
|
||||
|
@ -1524,11 +1531,14 @@ class ParserState<T> {
|
|||
private static final int SCHEME = 3;
|
||||
private static final int TERM = 1;
|
||||
private int mySubState = 0;
|
||||
private Tag myTag;
|
||||
private TagList myTagList;
|
||||
private String myTerm;
|
||||
private String myLabel;
|
||||
private String myScheme;
|
||||
|
||||
public TagState(Tag theTag) {
|
||||
public TagState(TagList theTagList) {
|
||||
super(null);
|
||||
myTag = theTag;
|
||||
myTagList = theTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1537,13 +1547,13 @@ class ParserState<T> {
|
|||
|
||||
switch (mySubState) {
|
||||
case TERM:
|
||||
myTag.setTerm(value);
|
||||
myTerm = (value);
|
||||
break;
|
||||
case LABEL:
|
||||
myTag.setLabel(value);
|
||||
myLabel = (value);
|
||||
break;
|
||||
case SCHEME:
|
||||
myTag.setScheme(value);
|
||||
myScheme = (value);
|
||||
break;
|
||||
case NONE:
|
||||
// This handles JSON encoding, which is a bit weird
|
||||
|
@ -1559,6 +1569,9 @@ class ParserState<T> {
|
|||
if (mySubState != NONE) {
|
||||
mySubState = NONE;
|
||||
} else {
|
||||
if (isNotEmpty(myScheme) || isNotBlank(myTerm) || isNotBlank(myLabel)) {
|
||||
myTagList.addTag(myScheme, myTerm, myLabel);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,10 +214,6 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((myVersionIdParamIndex != null) != (theRequest.getId() != null && theRequest.getId().hasVersionIdPart())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isDelete()) {
|
||||
if (Constants.PARAM_DELETE.equals(theRequest.getSecondaryOperation()) == false) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.method;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -66,7 +66,6 @@ import ca.uhn.fhir.rest.server.IBundleProvider;
|
|||
import ca.uhn.fhir.rest.server.IDynamicSearchResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.SearchParameterMap;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
|
||||
public class TagListTest {
|
||||
|
||||
private FhirContext myCtx = new FhirContext();
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
TagList tagList1 = new TagList();
|
||||
tagList1.addTag(null, "Dog", "Puppies");
|
||||
tagList1.addTag("http://foo", "Cat", "Kittens");
|
||||
|
||||
TagList tagList2 = new TagList();
|
||||
tagList2.addTag(null, "Dog", "Puppies");
|
||||
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||
|
||||
assertEquals(tagList1,tagList2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsIgnoresLabel() {
|
||||
TagList tagList1 = new TagList();
|
||||
tagList1.addTag(null, "Dog", "AAAA");
|
||||
tagList1.addTag("http://foo", "Cat", "BBBB");
|
||||
|
||||
TagList tagList2 = new TagList();
|
||||
tagList2.addTag(null, "Dog", "Puppies");
|
||||
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||
|
||||
assertEquals(tagList1,tagList2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEqualsIgnoresOrder() {
|
||||
TagList tagList1 = new TagList();
|
||||
tagList1.addTag(null, "Dog", "Puppies");
|
||||
tagList1.addTag("http://foo", "Cat", "Kittens");
|
||||
|
||||
TagList tagList2 = new TagList();
|
||||
tagList2.addTag("http://foo", "Cat", "Kittens");
|
||||
tagList2.addTag(null, "Dog", "Puppies");
|
||||
|
||||
assertEquals(tagList1,tagList2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreventDuplication() {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier("urn:system", "testTagsWithCreateAndReadAndSearch");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
TagList tagList = new TagList();
|
||||
tagList.addTag(null, "Dog", "Puppies");
|
||||
// Add this twice
|
||||
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||
|
||||
patient.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.addResource(patient, myCtx, "http://foo");
|
||||
|
||||
String encoded = myCtx.newXmlParser().encodeBundleToString(b);
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("Cat", "Kittens")));
|
||||
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("Cat", "Kittens", "Cat", "Kittens"))));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,6 @@ public class JsonParserTest {
|
|||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserTest.class);
|
||||
private static FhirContext ourCtx;
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeNarrativeBlockInBundle() {
|
||||
Patient p = new Patient();
|
||||
|
@ -87,7 +86,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodingNullExtension() {
|
||||
Patient p = new Patient();
|
||||
|
@ -164,13 +162,11 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInResourceElement() {
|
||||
|
||||
Conformance c = new Conformance();
|
||||
// c.addRest().getSecurity().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
// c.addRest().getSecurity().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
c.addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
|
@ -187,10 +183,10 @@ public class JsonParserTest {
|
|||
|
||||
Binary patient = new Binary();
|
||||
patient.setContentType("foo");
|
||||
patient.setContent(new byte[] {1,2,3,4});
|
||||
patient.setContent(new byte[] { 1, 2, 3, 4 });
|
||||
|
||||
String val = ourCtx.newJsonParser().encodeResourceToString(patient);
|
||||
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}",val);
|
||||
assertEquals("{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}", val);
|
||||
|
||||
}
|
||||
|
||||
|
@ -217,8 +213,6 @@ public class JsonParserTest {
|
|||
assertNull(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testNestedContainedResources() {
|
||||
|
||||
|
@ -240,39 +234,27 @@ public class JsonParserTest {
|
|||
|
||||
// Only one (outer) contained block
|
||||
int idx0 = str.indexOf("\"contained\"");
|
||||
int idx1 = str.indexOf("\"contained\"",idx0+1);
|
||||
int idx1 = str.indexOf("\"contained\"", idx0 + 1);
|
||||
|
||||
assertNotEquals(-1, idx0);
|
||||
assertEquals(-1, idx1);
|
||||
|
||||
Observation obs = ourCtx.newJsonParser().parseResource(Observation.class, str);
|
||||
assertEquals("A",obs.getName().getText().getValue());
|
||||
assertEquals("A", obs.getName().getText().getValue());
|
||||
|
||||
Observation obsB = (Observation) obs.getRelatedFirstRep().getTarget().getResource();
|
||||
assertEquals("B",obsB.getName().getText().getValue());
|
||||
assertEquals("B", obsB.getName().getText().getValue());
|
||||
|
||||
Observation obsC = (Observation) obsB.getRelatedFirstRep().getTarget().getResource();
|
||||
assertEquals("C",obsC.getName().getText().getValue());
|
||||
|
||||
assertEquals("C", obsC.getName().getText().getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseQuery() {
|
||||
String msg = "{\n" +
|
||||
" \"resourceType\": \"Query\",\n" +
|
||||
" \"text\": {\n" +
|
||||
" \"status\": \"generated\",\n" +
|
||||
" \"div\": \"<div>[Put rendering here]</div>\"\n" +
|
||||
" },\n" +
|
||||
" \"identifier\": \"urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376\",\n" +
|
||||
" \"parameter\": [\n" +
|
||||
" {\n" +
|
||||
" \"url\": \"http://hl7.org/fhir/query#_query\",\n" +
|
||||
" \"valueString\": \"example\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
String msg = "{\n" + " \"resourceType\": \"Query\",\n" + " \"text\": {\n" + " \"status\": \"generated\",\n" + " \"div\": \"<div>[Put rendering here]</div>\"\n" + " },\n"
|
||||
+ " \"identifier\": \"urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376\",\n" + " \"parameter\": [\n" + " {\n" + " \"url\": \"http://hl7.org/fhir/query#_query\",\n"
|
||||
+ " \"valueString\": \"example\"\n" + " }\n" + " ]\n" + "}";
|
||||
Query query = ourCtx.newJsonParser().parseResource(Query.class, msg);
|
||||
|
||||
assertEquals("urn:uuid:42b253f5-fa17-40d0-8da5-44aeb4230376", query.getIdentifier().getValueAsString());
|
||||
|
@ -287,7 +269,6 @@ public class JsonParserTest {
|
|||
ExtensionDt parameter = q.addParameter();
|
||||
parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example"));
|
||||
|
||||
|
||||
String val = new FhirContext().newJsonParser().encodeResourceToString(q);
|
||||
ourLog.info(val);
|
||||
|
||||
|
@ -315,7 +296,7 @@ public class JsonParserTest {
|
|||
|
||||
Binary val = ourCtx.newJsonParser().parseResource(Binary.class, "{\"resourceType\":\"Binary\",\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}");
|
||||
assertEquals("foo", val.getContentType());
|
||||
assertArrayEquals(new byte[] {1,2,3,4}, val.getContent());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, val.getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -382,7 +363,7 @@ public class JsonParserTest {
|
|||
//@formatter:on
|
||||
|
||||
String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList);
|
||||
assertEquals(expected,encoded);
|
||||
assertEquals(expected, encoded);
|
||||
|
||||
}
|
||||
|
||||
|
@ -392,7 +373,7 @@ public class JsonParserTest {
|
|||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
b.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
||||
b.addCategory("scheme", "term", "label");
|
||||
|
||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
ourLog.info(val);
|
||||
|
@ -400,8 +381,8 @@ public class JsonParserTest {
|
|||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1,b.getEntries().size());
|
||||
assertEquals(1,b.getCategories().size());
|
||||
assertEquals(1, b.getEntries().size());
|
||||
assertEquals(1, b.getCategories().size());
|
||||
assertEquals("term", b.getCategories().get(0).getTerm());
|
||||
assertEquals("label", b.getCategories().get(0).getLabel());
|
||||
assertEquals("scheme", b.getCategories().get(0).getScheme());
|
||||
|
@ -415,16 +396,16 @@ public class JsonParserTest {
|
|||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
e.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
||||
e.addCategory("scheme", "term", "label");
|
||||
|
||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
ourLog.info(val);
|
||||
|
||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1,b.getEntries().size());
|
||||
assertEquals(1,b.getEntries().get(0).getCategories().size());
|
||||
b = ourCtx.newJsonParser().parseBundle(val);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
assertEquals(1, b.getEntries().get(0).getCategories().size());
|
||||
assertEquals("term", b.getEntries().get(0).getCategories().get(0).getTerm());
|
||||
assertEquals("label", b.getEntries().get(0).getCategories().get(0).getLabel());
|
||||
assertEquals("scheme", b.getEntries().get(0).getCategories().get(0).getScheme());
|
||||
|
@ -450,7 +431,6 @@ public class JsonParserTest {
|
|||
parseAndEncode("/alert.profile.json");
|
||||
}
|
||||
|
||||
|
||||
private void parseAndEncode(String name) throws IOException {
|
||||
String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
|
||||
ourLog.info(msg);
|
||||
|
@ -465,7 +445,7 @@ public class JsonParserTest {
|
|||
JSON actual = JSONSerializer.toJSON(encoded.trim());
|
||||
|
||||
String exp = expected.toString().replace("\\r\\n", "\\n").replace("§", "§");
|
||||
String act = actual.toString().replace("\\r\\n","\\n");
|
||||
String act = actual.toString().replace("\\r\\n", "\\n");
|
||||
|
||||
ourLog.info("Expected: {}", exp);
|
||||
ourLog.info("Actual : {}", act);
|
||||
|
@ -473,8 +453,6 @@ public class JsonParserTest {
|
|||
assertEquals(exp, act);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeContainedResourcesMore() {
|
||||
|
||||
|
@ -518,7 +496,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeDeclaredExtensionWithResourceContent() {
|
||||
IParser parser = new FhirContext().newJsonParser();
|
||||
|
@ -549,8 +526,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExt() throws Exception {
|
||||
|
||||
|
@ -567,11 +542,12 @@ public class JsonParserTest {
|
|||
ourLog.info(encoded);
|
||||
|
||||
assertThat(encoded, not(containsString("123456")));
|
||||
assertEquals("{\"resourceType\":\"ValueSet\",\"define\":{\"concept\":[{\"extension\":[{\"url\":\"urn:alt\",\"valueString\":\"alt name\"}],\"code\":\"someCode\",\"display\":\"someDisplay\"}]}}", encoded);
|
||||
assertEquals(
|
||||
"{\"resourceType\":\"ValueSet\",\"define\":{\"concept\":[{\"extension\":[{\"url\":\"urn:alt\",\"valueString\":\"alt name\"}],\"code\":\"someCode\",\"display\":\"someDisplay\"}]}}",
|
||||
encoded);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionWithResourceContent() {
|
||||
IParser parser = new FhirContext().newJsonParser();
|
||||
|
@ -593,7 +569,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeInvalidChildGoodException() {
|
||||
Observation obs = new Observation();
|
||||
|
@ -793,7 +768,6 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This sample has extra elements in <searchParam> that are not actually a part of the spec any more..
|
||||
*/
|
||||
|
@ -864,13 +838,13 @@ public class JsonParserTest {
|
|||
|
||||
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
||||
String encoded = ourCtx.newJsonParser().encodeBundleToString(bundle);
|
||||
assertEquals(bundleString,encoded);
|
||||
assertEquals(bundleString, encoded);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBundle() throws InterruptedException {
|
||||
Bundle b= new Bundle();
|
||||
Bundle b = new Bundle();
|
||||
|
||||
InstantDt pub = InstantDt.withCurrentTime();
|
||||
b.setPublished(pub);
|
||||
|
@ -899,18 +873,17 @@ public class JsonParserTest {
|
|||
ourLog.info(bundleString);
|
||||
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.addAll(Arrays.asList("\"published\":\""+pub.getValueAsString()+"\""));
|
||||
strings.addAll(Arrays.asList("\"published\":\"" + pub.getValueAsString() + "\""));
|
||||
strings.addAll(Arrays.asList("\"id\":\"1\""));
|
||||
strings.addAll(Arrays.asList("this is the summary"));
|
||||
strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\""));
|
||||
strings.addAll(Arrays.asList("\"deleted\":\""+nowDt.getValueAsString()+"\"", "\"id\":\"Patient/3\""));
|
||||
strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\""));
|
||||
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
||||
|
||||
b.getEntries().remove(2);
|
||||
bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
assertThat(bundleString, not(containsString("deleted")));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -978,11 +951,10 @@ public class JsonParserTest {
|
|||
public void testParseWithIncorrectReference() throws IOException {
|
||||
String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"));
|
||||
jsonString = jsonString.replace("\"reference\"", "\"resource\"");
|
||||
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class,jsonString);
|
||||
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, jsonString);
|
||||
assertEquals("Organization/1", parsed.getManagingOrganization().getReference().getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleResourceEncodeWithCustomType() throws IOException {
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ public class XmlParserTest {
|
|||
Bundle b = new Bundle();
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
e.addCategory().setLabel("label").setTerm("term").setScheme("scheme");
|
||||
e.addCategory("scheme", "term", "label");
|
||||
|
||||
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(val);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
|
@ -33,7 +34,6 @@ import ca.uhn.fhir.rest.annotation.DeleteTags;
|
|||
import ca.uhn.fhir.rest.annotation.GetTags;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.TagListParam;
|
||||
import ca.uhn.fhir.rest.annotation.VersionIdParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
|
||||
/**
|
||||
|
@ -94,17 +94,6 @@ public class TagsServerTest {
|
|||
assertEquals(tagList, ourLastTagList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
TagList list1 = ourProvider.getAllTagsPatient();
|
||||
TagList list2 = ourProvider.getAllTagsPatient();
|
||||
assertEquals(list1, list2);
|
||||
|
||||
list1 = ourProvider.getAllTagsPatient();
|
||||
list2 = ourProvider.getAllTagsPatient();
|
||||
list2.get(0).setTerm("!!!!!");
|
||||
assertNotEquals(list1, list2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTags() throws Exception {
|
||||
|
@ -134,8 +123,10 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient");
|
||||
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -152,8 +143,10 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient111");
|
||||
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient111", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -170,8 +163,9 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient111222");
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient111222", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -188,8 +182,9 @@ public class TagsServerTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
TagList actual = ourCtx.newXmlParser().parseTagList(responseContent);
|
||||
TagList expected = ourProvider.getAllTags();
|
||||
expected.get(0).setTerm("Patient111222");
|
||||
TagList expected = new TagList();
|
||||
expected.addTag(null, "Patient111222", "DogLabel");
|
||||
expected.addTag("http://cats", "AllCat", "CatLabel");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
@ -261,15 +256,9 @@ public class TagsServerTest {
|
|||
|
||||
public static class DummyProvider {
|
||||
|
||||
@AddTags(type = Patient.class)
|
||||
public void addTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "add" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
|
||||
@AddTags(type = Patient.class)
|
||||
public void addTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "add" + theId.getIdPart();
|
||||
ourLastOutcome = "add" + theId.getIdPart() + StringUtils.defaultString(theId.getVersionIdPart());
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
|
||||
|
@ -297,13 +286,13 @@ public class TagsServerTest {
|
|||
return tagList;
|
||||
}
|
||||
|
||||
@GetTags(type = Patient.class)
|
||||
public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
||||
tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
||||
return tagList;
|
||||
}
|
||||
// @GetTags(type = Patient.class)
|
||||
// public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion) {
|
||||
// TagList tagList = new TagList();
|
||||
// tagList.add(new Tag((String) null, "Patient" + theId.getIdPart() + theVersion.getVersionIdPart(), "DogLabel"));
|
||||
// tagList.add(new Tag("http://cats", "AllCat", "CatLabel"));
|
||||
// return tagList;
|
||||
// }
|
||||
|
||||
@GetTags(type = Observation.class)
|
||||
public TagList getAllTagsObservationIdVersion(@IdParam IdDt theId) {
|
||||
|
@ -313,15 +302,15 @@ public class TagsServerTest {
|
|||
return tagList;
|
||||
}
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
// @DeleteTags(type = Patient.class)
|
||||
// public void RemoveTagsPatient(@IdParam IdDt theId, @VersionIdParam IdDt theVersion, @TagListParam TagList theTagList) {
|
||||
// ourLastOutcome = "Remove" + theId.getIdPart() + theVersion.getVersionIdPart();
|
||||
// ourLastTagList=theTagList;
|
||||
// }
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void RemoveTagsPatient(@IdParam IdDt theId, @TagListParam TagList theTagList) {
|
||||
ourLastOutcome = "Remove" + theId.getIdPart();
|
||||
ourLastOutcome = "Remove" + theId.getIdPart()+StringUtils.defaultString(theId.getVersionIdPart());
|
||||
ourLastTagList=theTagList;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,23 +142,25 @@ public class UpdateTest {
|
|||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||
|
||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||
httpPost.addHeader("Category", "Dog, Cat");
|
||||
httpPost.addHeader("Category", "Dog; scheme=\"urn:animals\", Cat; scheme=\"urn:animals\"");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
|
||||
assertEquals(new Tag("Cat"), ourReportProvider.getLastTags().get(1));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("urn:animals", "Dog"), ourReportProvider.getLastTags().get(0));
|
||||
assertEquals(new Tag("urn:animals", "Cat"), ourReportProvider.getLastTags().get(1));
|
||||
|
||||
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||
httpPost.addHeader("Category", "Dog; label=\"aa\", Cat; label=\"bb\"");
|
||||
httpPost.addHeader("Category", "Dog; label=\"aa\"; scheme=\"urn:animals\", Cat; label=\"bb\"; scheme=\"urn:animals\"");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
status = ourClient.execute(httpPost);
|
||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag((String) null, "Dog", "aa"), ourReportProvider.getLastTags().get(0));
|
||||
assertEquals(new Tag((String) null, "Cat", "bb"), ourReportProvider.getLastTags().get(1));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(2, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("urn:animals", "Dog", "aa"), ourReportProvider.getLastTags().get(0));
|
||||
assertEquals(new Tag("urn:animals", "Cat", "bb"), ourReportProvider.getLastTags().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,13 +170,14 @@ public class UpdateTest {
|
|||
dr.addCodedDiagnosis().addCoding().setCode("AAA");
|
||||
|
||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||
httpPost.addHeader("Category", "Dog");
|
||||
httpPost.addHeader("Category", "Dog; scheme=\"animals\"");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("Dog"), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("animals", "Dog"), ourReportProvider.getLastTags().get(0));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -187,17 +190,19 @@ public class UpdateTest {
|
|||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
|
||||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\";");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("http://foo", "Dog", null), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -219,9 +224,10 @@ public class UpdateTest {
|
|||
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"; ");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
status=ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(1, ourReportProvider.getLastTags().size());
|
||||
assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0));
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -236,6 +242,7 @@ public class UpdateTest {
|
|||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPut);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
// String responseContent =
|
||||
// IOUtils.toString(status.getEntity().getContent());
|
||||
|
@ -243,7 +250,6 @@ public class UpdateTest {
|
|||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals("http://localhost:" + ourPort + "/DiagnosticReport/001/_history/002", status.getFirstHeader("Location").getValue());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -258,11 +264,12 @@ public class UpdateTest {
|
|||
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
CloseableHttpResponse status = ourClient.execute(httpPut);
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
}
|
||||
|
||||
public void testUpdateWrongResourceType() throws Exception {
|
||||
|
@ -290,9 +297,11 @@ public class UpdateTest {
|
|||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Organization/001");
|
||||
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
CloseableHttpResponse response = ourClient.execute(httpPost);
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
response.close();
|
||||
CloseableHttpResponse status = ourClient.execute(httpPost);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
status.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -377,6 +386,7 @@ public class UpdateTest {
|
|||
return Observation.class;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Update()
|
||||
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) {
|
||||
/*
|
||||
|
|
|
@ -1189,14 +1189,17 @@ public class FhirResourceDaoTest {
|
|||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
TagList tagList = new TagList();
|
||||
tagList.addTag(null, "Dog", "Puppies");
|
||||
// Add this twice
|
||||
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||
tagList.addTag("http://foo", "Cat", "Kittens");
|
||||
patient.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
||||
|
||||
MethodOutcome outcome = ourPatientDao.create(patient);
|
||||
assertNotNull(outcome.getId());
|
||||
assertFalse(outcome.getId().isEmpty());
|
||||
IdDt patientId = outcome.getId();
|
||||
assertNotNull(patientId);
|
||||
assertFalse(patientId.isEmpty());
|
||||
|
||||
Patient retrieved = ourPatientDao.read(outcome.getId());
|
||||
Patient retrieved = ourPatientDao.read(patientId);
|
||||
TagList published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||
assertEquals(2, published.size());
|
||||
assertEquals("Dog", published.get(0).getTerm());
|
||||
|
@ -1217,6 +1220,23 @@ public class FhirResourceDaoTest {
|
|||
assertEquals("Kittens", published.get(1).getLabel());
|
||||
assertEquals("http://foo", published.get(1).getScheme());
|
||||
|
||||
ourPatientDao.addTag(patientId, "http://foo", "Cat", "Kittens");
|
||||
ourPatientDao.addTag(patientId, "http://foo", "Cow", "Calves");
|
||||
|
||||
retrieved = ourPatientDao.read(patientId);
|
||||
published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||
assertEquals(3, published.size());
|
||||
assertEquals("Dog", published.get(0).getTerm());
|
||||
assertEquals("Puppies", published.get(0).getLabel());
|
||||
assertEquals(null, published.get(0).getScheme());
|
||||
assertEquals("Cat", published.get(1).getTerm());
|
||||
assertEquals("Kittens", published.get(1).getLabel());
|
||||
assertEquals("http://foo", published.get(1).getScheme());
|
||||
assertEquals("Cow", published.get(2).getTerm());
|
||||
assertEquals("Calves", published.get(2).getLabel());
|
||||
assertEquals("http://foo", published.get(2).getScheme());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue