use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOff.
@Test
public void testValidExtIdsWorksFine_flagOff() {
ExternalIDs extIds = new ExternalIDs();
ExternalID id1 = new ExternalID();
id1.setRelationship(null);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
ExternalID id2 = new ExternalID();
id2.setRelationship(null);
id2.setType("doi");
id2.setValue("value1");
id2.setUrl(new Url("http://value1.com"));
ExternalID id3 = new ExternalID();
id3.setRelationship(null);
id3.setType("doi");
id3.setValue("value1");
id3.setUrl(new Url("http://value1.com"));
extIds.getExternalIdentifier().add(id1);
extIds.getExternalIdentifier().add(id2);
extIds.getExternalIdentifier().add(id3);
validator.validateWorkOrPeerReview(extIds);
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOn.
@Test
public void testValidExtIdsWorksFine_flagOn() {
validator.setRequireRelationshipOnExternalIdentifier(true);
ExternalIDs extIds = new ExternalIDs();
ExternalID id1 = new ExternalID();
id1.setRelationship(Relationship.SELF);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
ExternalID id2 = new ExternalID();
id2.setRelationship(Relationship.SELF);
id2.setType("doi");
id2.setValue("value1");
id2.setUrl(new Url("http://value1.com"));
ExternalID id3 = new ExternalID();
id3.setRelationship(Relationship.SELF);
id3.setType("doi");
id3.setValue("value1");
id3.setUrl(new Url("http://value1.com"));
extIds.getExternalIdentifier().add(id1);
extIds.getExternalIdentifier().add(id2);
extIds.getExternalIdentifier().add(id3);
validator.validateWorkOrPeerReview(extIds);
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testValidateWorkOrPeerReview.
@Test
public void testValidateWorkOrPeerReview() {
// call for ExternalID and ExternalIDs
// ID valid
ExternalID id1 = new ExternalID();
id1.setRelationship(Relationship.SELF);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
validator.validateWorkOrPeerReview(id1);
// ID bad type
try {
id1.setType("invalid");
validator.validateWorkOrPeerReview(id1);
fail("no exception thrown for invalid type");
} catch (Exception e) {
if (!(e instanceof ActivityIdentifierValidationException))
throw e;
}
// id null
try {
id1.setType(null);
validator.validateWorkOrPeerReview(id1);
fail("no exception thrown for invalid type");
} catch (Exception e) {
if (!(e instanceof ActivityIdentifierValidationException))
throw e;
}
ExternalIDs ids = new ExternalIDs();
ids.getExternalIdentifier().add(id1);
// IDS one invalid
id1.setType("invalid");
try {
validator.validateWorkOrPeerReview(ids);
fail("no exception thrown for invalid type");
} catch (Exception e) {
if (!(e instanceof ActivityIdentifierValidationException))
throw e;
}
// IDS one valid (lowercase)
id1.setType("doi");
validator.validateWorkOrPeerReview(ids);
// IDS two valid
ExternalID id2 = new ExternalID();
id2.setRelationship(Relationship.SELF);
id2.setType("source-work-id");
id2.setValue("value2");
id2.setUrl(new Url("http://value1.com"));
ids.getExternalIdentifier().add(id2);
validator.validateWorkOrPeerReview(ids);
// IDS one invalid, one valid
id2.setType("not-a-type");
try {
validator.validateWorkOrPeerReview(ids);
fail("no exception thrown for invalid type");
} catch (Exception e) {
if (!(e instanceof ActivityIdentifierValidationException))
throw e;
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method filterExternalIdentifiers.
/**
* Filter the group external identifiers to match the external identifiers
* that belongs to the activities it have after filtering
*
* @param group
* The group we want to filter the external identifiers
*/
private void filterExternalIdentifiers(Group group) {
// Iterate over every external identifier and check if it is still
// present in the list of filtered elements
ExternalIDs extIds = group.getIdentifiers();
Iterator<ExternalID> extIdsIt = extIds.getExternalIdentifier().iterator();
while (extIdsIt.hasNext()) {
ExternalID extId = extIdsIt.next();
boolean found = false;
for (GroupableActivity summary : group.getActivities()) {
if (summary.getExternalIdentifiers() != null) {
if (summary.getExternalIdentifiers().getExternalIdentifier().contains(extId)) {
found = true;
break;
}
}
}
// If the ext id is not found, remove it from the list of ext ids
if (!found) {
extIdsIt.remove();
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalIDs in project ORCID-Source by ORCID.
the class WorkManagerImpl method createNewWorkGroup.
@Override
public void createNewWorkGroup(List<Long> workIds, String orcid) {
List<MinimizedWorkEntity> works = workEntityCacheManager.retrieveMinimizedWorks(orcid, workIds, getLastModified(orcid));
JSONWorkExternalIdentifiersConverterV3 externalIdConverter = new JSONWorkExternalIdentifiersConverterV3(norm, localeManager);
ExternalIDs allExternalIDs = new ExternalIDs();
MinimizedWorkEntity userVersion = null;
MinimizedWorkEntity userPreferred = null;
for (MinimizedWorkEntity work : works) {
if (orcid.equals(work.getSourceId())) {
userVersion = work;
}
if (userPreferred == null || userPreferred.getDisplayIndex() < work.getDisplayIndex()) {
userPreferred = work;
}
ExternalIDs externalIDs = externalIdConverter.convertFrom(work.getExternalIdentifiersJson(), null);
for (ExternalID externalID : externalIDs.getExternalIdentifier()) {
if (!allExternalIDs.getExternalIdentifier().contains(externalID)) {
allExternalIDs.getExternalIdentifier().add(externalID);
}
}
}
String externalIDsJson = externalIdConverter.convertTo(allExternalIDs, null);
if (userVersion != null) {
userVersion.setExternalIdentifiersJson(externalIDsJson);
} else {
WorkEntity allPreferredMetadata = createCopyOfUserPreferredWork(userPreferred);
allPreferredMetadata.setExternalIdentifiersJson(externalIDsJson);
workDao.persist(allPreferredMetadata);
}
}
Aggregations