@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((type == null) ? 0 : type.hashCode()); if (this.getNormalized() != null && !StringUtils.isEmpty(this.getNormalized().getValue())) { result = prime * result + this.getNormalized().hashCode(); } else { result = prime * result + ((value == null) ? 0 : value.hashCode()); } //ignore normalizedError for equality checking/hash return result; }
public ExternalID clone() { ExternalID id = new ExternalID(); id.type = this.getType(); id.value = this.getValue(); if (this.getNormalized() != null) id.setNormalized(this.getNormalized()); if (this.getNormalizedError() != null) id.setNormalizedError(this.getNormalizedError()); if (this.getUrl() != null) id.url = new Url(this.getUrl().getValue()); if (this.getRelationship() != null) id.relationship = this.getRelationship(); if (this.getNormalizedUrl() != null) id.setNormalizedUrl(this.getNormalizedUrl()); if (this.getNormalizedUrlError() != null) id.setNormalizedUrlError(this.getNormalizedUrlError()); return id; }
public static ActivityExternalIdentifier valueOf(ExternalID externalIdentifier) { ActivityExternalIdentifier wi = new ActivityExternalIdentifier(); if (externalIdentifier != null) { if (externalIdentifier.getValue() != null) wi.setExternalIdentifierId(Text.valueOf(externalIdentifier.getValue())); if (externalIdentifier.getType() != null) wi.setExternalIdentifierType(Text.valueOf(externalIdentifier.getType())); if(externalIdentifier.getRelationship() != null) wi.setRelationship(Text.valueOf(externalIdentifier.getRelationship().value())); if(externalIdentifier.getUrl() != null) wi.setUrl(Text.valueOf(externalIdentifier.getUrl().getValue())); if(externalIdentifier.getNormalized() != null){ wi.setNormalized(Text.valueOf(externalIdentifier.getNormalized().getValue())); wi.getNormalized().setRequired(false); } if(externalIdentifier.getNormalizedUrl() != null){ wi.setNormalizedUrl(Text.valueOf(externalIdentifier.getNormalizedUrl().getValue())); wi.getNormalizedUrl().setRequired(false); } } return wi; }
if (StringUtils.isEmpty(id.getNormalized().getValue())){ id.setNormalizedError(new TransientError(localeManager.resolveMessage("transientError.normalization_failed.code"),localeManager.resolveMessage("transientError.normalization_failed.message",id.getType(),workExternalIdentifier.getWorkExternalIdentifierId().content )));
/** * If we have a normalized value, use that to generate Group ID; */ @Override @JsonIgnore public String getGroupId() { String workIdVal = null; if (this.getNormalized() != null && !StringUtils.isEmpty(this.getNormalized().getValue())) { workIdVal = this.getNormalized().getValue(); } else { workIdVal = this.value == null ? null : this.value; } String typeVal = this.type == null ? null : this.type; return workIdVal + typeVal; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ExternalID other = (ExternalID) obj; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; if (this.getNormalized() != null && !StringUtils.isEmpty(this.getNormalized().getValue())) { // if we have a normalized value, use that. if (!getNormalized().equals(other.getNormalized())) return false; } else { // otherwise check the provided value if (value == null) { if (other.value != null) return false; } else if (!value.equals(other.value)) return false; } //ignore normalizedError for equality checking/hash return true; }
public void checkExternalIdentifiersForDuplicates(ExternalIDs newExtIds, ExternalIDs existingExtIds, Source existingSource, Source activeSource) { if (existingExtIds != null && newExtIds != null) { for (ExternalID existingId : existingExtIds.getExternalIdentifier()) { for (ExternalID newId : newExtIds.getExternalIdentifier()) { // normalize the ids before checking equality newId.setNormalized(new TransientNonEmptyString(norm.normalise(newId.getType(), newId.getValue()))); if (existingId.getNormalized() == null) existingId.setNormalized(new TransientNonEmptyString(norm.normalise(existingId.getType(), existingId.getValue()))); if (areRelationshipsSameAndSelf(existingId.getRelationship(), newId.getRelationship()) && newId.equals(existingId) && SourceEntityUtils.isTheSameForDuplicateChecking(activeSource,existingSource)) { Map<String, String> params = new HashMap<String, String>(); params.put("clientName", SourceEntityUtils.getSourceName(activeSource)); throw new OrcidDuplicatedActivityException(params); } } } } }
@Override public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) { JSONExternalIdentifiers externalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONExternalIdentifiers.class); ExternalIDs externalIDs = new ExternalIDs(); for (JSONExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) { ExternalID id = new ExternalID(); if (externalIdentifier.getType() == null) { id.setType(FundingExternalIdentifierType.GRANT_NUMBER.value()); } else { id.setType(externalIdentifier.getType().toLowerCase()); } if (externalIdentifier.getUrl() != null && !PojoUtil.isEmpty(externalIdentifier.getUrl().getValue())) { Url url = new Url(externalIdentifier.getUrl().getValue()); id.setUrl(url); } if (!PojoUtil.isEmpty(externalIdentifier.getValue())) { id.setValue(externalIdentifier.getValue()); id.setNormalized(new TransientNonEmptyString(norm.normalise(id.getType(), externalIdentifier.getValue()))); if (StringUtils.isEmpty(id.getNormalized().getValue())){ id.setNormalizedError(new TransientError(localeManager.resolveMessage("transientError.normalization_failed.code"),localeManager.resolveMessage("transientError.normalization_failed.message", id.getType(), externalIdentifier.getValue()))); } } if (externalIdentifier.getRelationship() != null) { id.setRelationship(Relationship.fromValue(conv.convertFrom(externalIdentifier.getRelationship(), null))); } externalIDs.getExternalIdentifier().add(id); } return externalIDs; }