Skip to content

change up equality checking for tag definitions #6910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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 <code>theTagDefToAdd</code> to <code>theEntity</code>. 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 <code>theTagDefToAdd</code> wrapped in a resourceTag if it was added to <code>theEntity</code> or <code>theEntity</code>'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<ResourceTag> getAllTagDefinitions(ResourceTable theEntity) {
HashSet<ResourceTag> retVal = Sets.newHashSet();
if (theEntity.isHasTags()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading