diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
index 185327502d1..838228019c3 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
@@ -109,7 +109,6 @@
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
-import org.apache.commons.lang3.builder.EqualsBuilder;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseCoding;
@@ -292,7 +291,7 @@ private void extractHapiTags(
next.getVersion(),
myCodingSpy.getBooleanObject(next));
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
allDefs.add(tag);
theEntity.setHasTags(true);
}
@@ -311,7 +310,7 @@ private void extractHapiTags(
next.getVersionElement().getValue(),
next.getUserSelectedElement().getValue());
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
allDefs.add(tag);
theEntity.setHasTags(true);
}
@@ -324,7 +323,7 @@ private void extractHapiTags(
TagDefinition def = cacheTagDefinitionDao.getTagOrNull(
theTransactionDetails, TagTypeEnum.PROFILE, NS_JPA_PROFILE, next.getValue(), null, null, null);
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
allDefs.add(tag);
theEntity.setHasTags(true);
}
@@ -349,7 +348,7 @@ private void extractRiTags(
next.getVersion(),
myCodingSpy.getBooleanObject(next));
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
theAllTags.add(tag);
theEntity.setHasTags(true);
}
@@ -368,7 +367,7 @@ private void extractRiTags(
next.getVersion(),
myCodingSpy.getBooleanObject(next));
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
theAllTags.add(tag);
theEntity.setHasTags(true);
}
@@ -381,7 +380,7 @@ private void extractRiTags(
TagDefinition def = cacheTagDefinitionDao.getTagOrNull(
theTransactionDetails, TagTypeEnum.PROFILE, NS_JPA_PROFILE, next.getValue(), null, null, null);
if (def != null) {
- ResourceTag tag = maybeAddTagToEntity(theEntity, def);
+ ResourceTag tag = theEntity.addTag(def);
theAllTags.add(tag);
theEntity.setHasTags(true);
}
@@ -401,42 +400,13 @@ private void extractProfileTags(
TagDefinition profileDef = cacheTagDefinitionDao.getTagOrNull(
theTransactionDetails, TagTypeEnum.PROFILE, NS_JPA_PROFILE, profile, null, null, null);
- ResourceTag tag = maybeAddTagToEntity(theEntity, profileDef);
+ ResourceTag tag = theEntity.addTag(profileDef);
theAllTags.add(tag);
theEntity.setHasTags(true);
}
}
}
- /**
- * Utility method adding theTagDefToAdd
to theEntity
. Since the database may contain
- * duplicate tagDefinitions, we perform a logical comparison, i.e. we don't care about the tagDefiniton.id, and add
- * the tag to the entity only if the entity does not already have that tag.
- *
- * @param theEntity receiving the tagDefinition
- * @param theTagDefToAdd to theEntity
- * @return theTagDefToAdd
wrapped in a resourceTag if it was added to theEntity
or theEntity
's
- * resourceTag encapsulating a tagDefinition that is logically equal to theTagDefToAdd.
- */
- private ResourceTag maybeAddTagToEntity(ResourceTable theEntity, TagDefinition theTagDefToAdd) {
- for (ResourceTag resourceTagFromEntity : theEntity.getTags()) {
- TagDefinition tag = resourceTagFromEntity.getTag();
- EqualsBuilder equalsBuilder = new EqualsBuilder();
- equalsBuilder.append(tag.getSystem(), theTagDefToAdd.getSystem());
- equalsBuilder.append(tag.getCode(), theTagDefToAdd.getCode());
- equalsBuilder.append(tag.getDisplay(), theTagDefToAdd.getDisplay());
- equalsBuilder.append(tag.getVersion(), theTagDefToAdd.getVersion());
- equalsBuilder.append(tag.getUserSelected(), theTagDefToAdd.getUserSelected());
- equalsBuilder.append(tag.getTagType(), theTagDefToAdd.getTagType());
-
- if (equalsBuilder.isEquals()) {
- return resourceTagFromEntity;
- }
- }
-
- return theEntity.addTag(theTagDefToAdd);
- }
-
private Set getAllTagDefinitions(ResourceTable theEntity) {
HashSet retVal = Sets.newHashSet();
if (theEntity.isHasTags()) {
diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/TagDefinition.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/TagDefinition.java
index 8f650e03bdd..f6066b7294a 100644
--- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/TagDefinition.java
+++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/TagDefinition.java
@@ -192,17 +192,11 @@ public boolean equals(Object obj) {
TagDefinition other = (TagDefinition) obj;
EqualsBuilder b = new EqualsBuilder();
-
- if (myId != null && other.myId != null) {
- b.append(myId, other.myId);
- } else {
- b.append(myTagType, other.myTagType);
- b.append(mySystem, other.mySystem);
- b.append(myCode, other.myCode);
- b.append(myVersion, other.myVersion);
- b.append(myUserSelected, other.myUserSelected);
- }
-
+ b.append(myTagType, other.myTagType);
+ b.append(mySystem, other.mySystem);
+ b.append(myCode, other.myCode);
+ b.append(myVersion, other.myVersion);
+ b.append(myUserSelected, other.myUserSelected);
return b.isEquals();
}