use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getExternalIdentifierMapperFacade.
public MapperFacade getExternalIdentifierMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ClassMapBuilder<PersonExternalIdentifier, ExternalIdentifierEntity> externalIdentifierClassMap = mapperFactory.classMap(PersonExternalIdentifier.class, ExternalIdentifierEntity.class);
addV2DateFields(externalIdentifierClassMap);
externalIdentifierClassMap.field("putCode", "id");
externalIdentifierClassMap.field("type", "externalIdCommonName");
externalIdentifierClassMap.field("value", "externalIdReference");
externalIdentifierClassMap.field("url.value", "externalIdUrl");
externalIdentifierClassMap.fieldBToA("displayIndex", "displayIndex");
externalIdentifierClassMap.byDefault();
registerSourceConverters(mapperFactory, externalIdentifierClassMap);
//TODO: add relationship to database schema for people.
externalIdentifierClassMap.register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method updateExternalIdentifier.
@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
//Save the original source
String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
// Validate external identifier
PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, requireRelationshipOnExternalIdentifier);
// Validate it is not duplicated
List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "external-identifier");
params.put("value", externalIdentifier.getUrl().getValue());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
updatedExternalIdentifierEntity.setLastModified(new Date());
//Set source
updatedExternalIdentifierEntity.setSourceId(existingSourceId);
updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
externalIdentifierDao.merge(updatedExternalIdentifierEntity);
return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method updateExternalIdentifiers.
@Override
public PersonExternalIdentifiers updateExternalIdentifiers(String orcid, PersonExternalIdentifiers externalIdentifiers) {
List<ExternalIdentifierEntity> existingExternalIdentifiersList = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
// Delete the deleted ones
for (ExternalIdentifierEntity existing : existingExternalIdentifiersList) {
boolean deleteMe = true;
if (externalIdentifiers.getExternalIdentifiers() != null) {
for (PersonExternalIdentifier updatedOrNew : externalIdentifiers.getExternalIdentifiers()) {
if (existing.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
externalIdentifierDao.removeExternalIdentifier(orcid, existing.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete external identifier " + existing.getId(), e);
}
}
}
if (externalIdentifiers != null && externalIdentifiers.getExternalIdentifiers() != null) {
for (PersonExternalIdentifier updatedOrNew : externalIdentifiers.getExternalIdentifiers()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (ExternalIdentifierEntity existingExtId : existingExternalIdentifiersList) {
if (existingExtId.getId().equals(updatedOrNew.getPutCode())) {
existingExtId.setLastModified(new Date());
existingExtId.setVisibility(updatedOrNew.getVisibility());
existingExtId.setDisplayIndex(updatedOrNew.getDisplayIndex());
externalIdentifierDao.merge(existingExtId);
}
}
}
}
}
return externalIdentifiers;
}
use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.
the class JpaJaxbExternalIdentifierAdapterTest method testToExternalIdentifierEntity.
@Test
public void testToExternalIdentifierEntity() throws JAXBException {
ExternalIdentifierEntity entity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(getExternalIdentifier());
assertNotNull(entity);
assertEquals("A-0003", entity.getExternalIdCommonName());
assertEquals("A-0003", entity.getExternalIdReference());
assertEquals("http://ext-id/A-0003", entity.getExternalIdUrl());
assertEquals(Long.valueOf(1), entity.getId());
assertNotNull(entity.getDateCreated());
assertNotNull(entity.getLastModified());
// Source
assertNull(entity.getSourceId());
assertNull(entity.getClientSourceId());
assertNull(entity.getElementSourceId());
}
use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImplTest method testClaimChangingVisibility.
@Test
@Transactional
public void testClaimChangingVisibility() {
Claim claim = new Claim();
claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
claim.setPassword(Text.valueOf("passwordTest1"));
claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
Checkbox checked = new Checkbox();
checked.setValue(true);
claim.setSendChangeNotifications(checked);
claim.setSendOrcidNews(checked);
claim.setTermsOfUse(checked);
assertTrue(profileEntityManager.claimProfileAndUpdatePreferences("0000-0000-0000-0001", "public_0000-0000-0000-0001@test.orcid.org", Locale.EN, claim));
ProfileEntity profile = profileEntityManager.findByOrcid("0000-0000-0000-0001");
assertNotNull(profile);
assertNotNull(profile.getBiographyEntity());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, profile.getBiographyEntity().getVisibility());
assertNotNull(profile.getAddresses());
assertEquals(3, profile.getAddresses().size());
for (AddressEntity a : profile.getAddresses()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, a.getVisibility());
}
assertNotNull(profile.getExternalIdentifiers());
assertEquals(3, profile.getExternalIdentifiers().size());
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, e.getVisibility());
}
assertNotNull(profile.getKeywords());
assertEquals(3, profile.getKeywords().size());
for (ProfileKeywordEntity k : profile.getKeywords()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, k.getVisibility());
}
assertNotNull(profile.getOtherNames());
assertEquals(3, profile.getOtherNames().size());
for (OtherNameEntity o : profile.getOtherNames()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, o.getVisibility());
}
assertNotNull(profile.getResearcherUrls());
assertEquals(3, profile.getResearcherUrls().size());
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, r.getVisibility());
}
}
Aggregations