use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateDuplicatedExtIds_duplicatesFoundTest.
@SuppressWarnings("deprecation")
@Test(expected = OrcidDuplicatedActivityException.class)
public void validateDuplicatedExtIds_duplicatesFoundTest() {
SourceEntity source1 = mock(SourceEntity.class);
when(source1.getSourceName()).thenReturn("source name");
when(source1.getSourceId()).thenReturn("APP-00000000000000");
SourceClientId sourceClientId = new SourceClientId();
sourceClientId.setPath("APP-00000000000000");
Source source2 = mock(Source.class);
when(source2.getSourceName()).thenReturn(new SourceName("source name"));
when(source2.getSourceClientId()).thenReturn(sourceClientId);
ExternalIDs extIds1 = getExternalIDs();
ExternalIDs extIds2 = getExternalIDs();
activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setExternalIdentifiers.
private void setExternalIdentifiers(ProfileEntity profileEntity, ExternalIdentifiers externalIdentifiers) {
String sourceId = getSourceId();
Set<ExternalIdentifierEntity> existingExternalIdentifierEntities = profileEntity.getExternalIdentifiers();
Iterator<ExternalIdentifierEntity> existingIt = null;
if (existingExternalIdentifierEntities != null) {
existingIt = existingExternalIdentifierEntities.iterator();
}
//Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
if (existingIt != null) {
while (existingIt.hasNext()) {
ExternalIdentifierEntity existing = existingIt.next();
String existingElementSource = existing.getElementSourceId();
if (sourceId != null && !sourceId.equals(existingElementSource)) {
//If am not the source of this element, do nothing
} else {
//If am the source, check if the element exists in the list of incoming elements
Triplet<String, String, String> existingTriplet = createTripletForExternalIdentifier(existing);
boolean found = false;
if (externalIdentifiers != null && externalIdentifiers.getExternalIdentifier() != null) {
for (ExternalIdentifier newExternalIdentifier : externalIdentifiers.getExternalIdentifier()) {
Triplet<String, String, String> newExternalIdentifierTriplet = createTripletForExternalIdentifier(newExternalIdentifier);
if (Objects.equals(existingTriplet, newExternalIdentifierTriplet)) {
found = true;
break;
}
}
}
//If it doesn't exists, remove it from the existing elements
if (!found) {
existingIt.remove();
}
}
}
}
//Iterate over the list of all new ones and add the ones that doesn't exists yet
if (externalIdentifiers != null && externalIdentifiers.getExternalIdentifier() != null) {
for (ExternalIdentifier newExternalIdentifier : externalIdentifiers.getExternalIdentifier()) {
boolean exists = false;
Triplet<String, String, String> newExternalIdentifierTriplet = createTripletForExternalIdentifier(newExternalIdentifier);
String sourceOfNewElement = newExternalIdentifier.getSource() == null ? null : newExternalIdentifier.getSource().retrieveSourcePath();
if (existingExternalIdentifierEntities != null) {
for (ExternalIdentifierEntity existingEntity : existingExternalIdentifierEntities) {
Triplet<String, String, String> existingTriplet = createTripletForExternalIdentifier(existingEntity);
String sourceOfExistingElement = existingEntity.getElementSourceId();
if (Objects.equals(sourceOfNewElement, sourceOfExistingElement) && Objects.equals(newExternalIdentifierTriplet, existingTriplet)) {
exists = true;
// visibility
if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
// Update the visibility of existing elements if
// the profile is not claimed
String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
String listVisibilityValue = externalIdentifiers.getVisibility() == null ? null : externalIdentifiers.getVisibility().value();
if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
}
}
break;
}
}
}
if (!exists) {
if (existingExternalIdentifierEntities == null) {
existingExternalIdentifierEntities = new TreeSet<ExternalIdentifierEntity>();
profileEntity.setExternalIdentifiers(existingExternalIdentifierEntities);
}
ExternalIdentifierEntity newEntity = new ExternalIdentifierEntity();
newEntity.setOwner(profileEntity);
//Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newEntity);
if (newExternalIdentifier.getExternalIdCommonName() != null) {
newEntity.setExternalIdCommonName(newExternalIdentifier.getExternalIdCommonName().getContent());
}
if (newExternalIdentifier.getExternalIdReference() != null) {
newEntity.setExternalIdReference(newExternalIdentifier.getExternalIdReference().getContent());
}
if (newExternalIdentifier.getExternalIdUrl() != null) {
newEntity.setExternalIdUrl(newExternalIdentifier.getExternalIdUrl().getValue());
}
newEntity.setVisibility(getDefaultVisibility(profileEntity, externalIdentifiers.getVisibility(), OrcidVisibilityDefaults.EXTERNAL_IDENTIFIER_DEFAULT));
newEntity.setDisplayIndex(0L);
for (ExternalIdentifierEntity tempEntity : existingExternalIdentifierEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
existingExternalIdentifierEntities.add(newEntity);
}
}
}
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setKeywords.
private void setKeywords(ProfileEntity profileEntity, Keywords keywords) {
String sourceId = getSourceId();
SortedSet<ProfileKeywordEntity> existingProfileKeywordEntities = profileEntity.getKeywords();
Iterator<ProfileKeywordEntity> existingIt = null;
if (existingProfileKeywordEntities != null) {
existingIt = existingProfileKeywordEntities.iterator();
}
//Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
if (existingIt != null) {
while (existingIt.hasNext()) {
ProfileKeywordEntity existing = existingIt.next();
String existingElementSource = existing.getElementSourceId();
if (sourceId != null && !sourceId.equals(existingElementSource)) {
//If am not the source of this element, do nothing
} else {
//If am the source, check if the element exists in the list of incoming elements
String value = existing.getKeywordName();
boolean found = false;
if (keywords != null && keywords.getKeyword() != null) {
for (Keyword newKeyword : keywords.getKeyword()) {
if (Objects.equals(value, newKeyword.getContent())) {
found = true;
break;
}
}
}
//If it doesn't exists, remove it from the existing elements
if (!found) {
existingIt.remove();
}
}
}
}
//Iterate over the list of all new ones and add the ones that doesn't exists yet
if (keywords != null && keywords.getKeyword() != null) {
for (Keyword newKeyword : keywords.getKeyword()) {
boolean exists = false;
if (existingProfileKeywordEntities != null) {
for (ProfileKeywordEntity existingEntity : existingProfileKeywordEntities) {
if (Objects.equals(newKeyword.getContent(), existingEntity.getKeywordName())) {
exists = true;
//If the profile is not claimed, you can update the visibility
if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
//Update the visibility of existing elements if the profile is not claimed
String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
String listVisibilityValue = keywords.getVisibility() == null ? null : keywords.getVisibility().value();
if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
}
}
break;
}
}
}
if (!exists) {
if (existingProfileKeywordEntities == null) {
existingProfileKeywordEntities = new TreeSet<ProfileKeywordEntity>();
profileEntity.setKeywords(existingProfileKeywordEntities);
}
ProfileKeywordEntity newEntity = new ProfileKeywordEntity();
newEntity.setProfile(profileEntity);
//Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newEntity);
newEntity.setKeywordName(newKeyword.getContent());
newEntity.setVisibility(getDefaultVisibility(profileEntity, keywords.getVisibility(), OrcidVisibilityDefaults.KEYWORD_DEFAULT));
newEntity.setDisplayIndex(0L);
for (ProfileKeywordEntity tempEntity : existingProfileKeywordEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
existingProfileKeywordEntities.add(newEntity);
}
}
}
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setOtherNames.
private void setOtherNames(ProfileEntity profileEntity, OtherNames otherNames) {
String sourceId = getSourceId();
SortedSet<OtherNameEntity> existingOtherNameEntities = profileEntity.getOtherNames();
Iterator<OtherNameEntity> existingIt = null;
if (existingOtherNameEntities != null) {
existingIt = existingOtherNameEntities.iterator();
}
//Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
if (existingIt != null) {
while (existingIt.hasNext()) {
OtherNameEntity existing = existingIt.next();
String existingElementSource = existing.getElementSourceId();
if (sourceId != null && !sourceId.equals(existingElementSource)) {
//If am not the source of this element, do nothing
} else {
//If am the source, check if the element exists in the list of incoming elements
String value = existing.getDisplayName();
boolean found = false;
if (otherNames != null && otherNames.getOtherName() != null) {
for (OtherName newOtherName : otherNames.getOtherName()) {
if (Objects.equals(value, newOtherName.getContent())) {
found = true;
break;
}
}
}
//If it doesn't exists, remove it from the existing elements
if (!found) {
existingIt.remove();
}
}
}
}
//Iterate over the list of all new ones and add the ones that doesn't exists yet
if (otherNames != null && otherNames.getOtherName() != null) {
for (OtherName newOtherName : otherNames.getOtherName()) {
boolean exists = false;
if (existingOtherNameEntities != null) {
for (OtherNameEntity existingEntity : existingOtherNameEntities) {
if (Objects.equals(newOtherName.getContent(), existingEntity.getDisplayName())) {
exists = true;
//If the profile is not claimed, you can update the visibility
if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
//Update the visibility of existing elements if the profile is not claimed
String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
String listVisibilityValue = otherNames.getVisibility() == null ? null : otherNames.getVisibility().value();
if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
}
}
break;
}
}
}
if (!exists) {
if (existingOtherNameEntities == null) {
existingOtherNameEntities = new TreeSet<OtherNameEntity>();
profileEntity.setOtherNames(existingOtherNameEntities);
}
OtherNameEntity newEntity = new OtherNameEntity();
newEntity.setProfile(profileEntity);
//Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newEntity);
newEntity.setDisplayName(newOtherName.getContent());
newEntity.setVisibility(getDefaultVisibility(profileEntity, otherNames.getVisibility(), OrcidVisibilityDefaults.OTHER_NAMES_DEFAULT));
newEntity.setDisplayIndex(0L);
for (OtherNameEntity tempEntity : existingOtherNameEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
existingOtherNameEntities.add(newEntity);
}
}
}
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method getSponsor.
private Source getSponsor(ProfileEntity profileEntity) {
SourceEntity sourceEntity = profileEntity.getSource();
if (sourceEntity != null) {
Source sponsor = new Source();
SourceName sponsorName = new SourceName(sourceEntity.getSourceName());
sponsor.setSourceName(sponsorName);
ClientDetailsEntity sourceClient = sourceEntity.getSourceClient();
if (sourceClient != null && !OrcidStringUtils.isValidOrcid(sourceClient.getClientId())) {
SourceClientId sourceClientId = new SourceClientId(getOrcidIdBase(sourceClient.getId()));
sponsor.setSourceClientId(sourceClientId);
} else {
SourceOrcid sponsorOrcid = StringUtils.isNotBlank(sourceEntity.getSourceId()) ? new SourceOrcid(getOrcidIdBase(sourceEntity.getSourceId())) : null;
sponsor.setSourceOrcid(sponsorOrcid);
}
return sponsor;
}
return null;
}
Aggregations