use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.
@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
// Verify the email
boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
if (!emailVerified) {
throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
}
// Update the profile entity fields
ProfileEntity profile = profileDao.find(orcid);
profile.setLastModified(new Date());
profile.setIndexingStatus(IndexingStatus.REINDEX);
profile.setClaimed(true);
profile.setCompletedDate(new Date());
if (locale != null) {
profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
}
if (claim != null) {
profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
profile.setActivitiesVisibilityDefault(Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
}
// Update the visibility for every bio element to the visibility
// selected by the user
// Update the bio
org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
if (profile.getBiographyEntity() != null) {
profile.getBiographyEntity().setVisibility(defaultVisibility);
}
// Update address
if (profile.getAddresses() != null) {
for (AddressEntity a : profile.getAddresses()) {
a.setVisibility(defaultVisibility);
}
}
// Update the keywords
if (profile.getKeywords() != null) {
for (ProfileKeywordEntity k : profile.getKeywords()) {
k.setVisibility(defaultVisibility);
}
}
// Update the other names
if (profile.getOtherNames() != null) {
for (OtherNameEntity o : profile.getOtherNames()) {
o.setVisibility(defaultVisibility);
}
}
// Update the researcher urls
if (profile.getResearcherUrls() != null) {
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
r.setVisibility(defaultVisibility);
}
}
// Update the external identifiers
if (profile.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
e.setVisibility(defaultVisibility);
}
}
profileDao.merge(profile);
profileDao.flush();
return true;
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class ResearcherUrlDaoTest method testCannotAddDuplicatedResearcherUrl.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCannotAddDuplicatedResearcherUrl() {
try {
ResearcherUrlEntity newRUrl = new ResearcherUrlEntity();
newRUrl.setDateCreated(new Date());
newRUrl.setLastModified(new Date());
newRUrl.setClientSourceId("4444-4444-4444-4443");
newRUrl.setUrl("http://www.researcherurl2.com?id=1");
newRUrl.setUrlName("test");
newRUrl.setUser(new ProfileEntity("4444-4444-4444-4443"));
newRUrl.setVisibility(Visibility.PUBLIC);
newRUrl = dao.merge(newRUrl);
assertNotNull(newRUrl);
fail();
} catch (PersistenceException e) {
}
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class JpaJaxbResearcherUrlAdapterTest method fromResearcherUrlEntityToResearcherUrl.
@Test
public void fromResearcherUrlEntityToResearcherUrl() {
ResearcherUrlEntity entity = getResearcherUrlEntity();
ResearcherUrl r = jpaJaxbResearcherUrlAdapter.toResearcherUrl(entity);
// General info
assertNotNull(r);
assertEquals(Long.valueOf(13579), r.getPutCode());
assertEquals("http://orcid.org", r.getUrl().getValue());
assertEquals("Orcid URL", r.getUrlName());
assertEquals(Visibility.LIMITED, r.getVisibility());
// Source
assertEquals("APP-0001", r.getSource().retrieveSourcePath());
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class JpaJaxbResearcherUrlAdapterTest method testToResearcherUrlEntity.
@Test
public void testToResearcherUrlEntity() throws JAXBException {
ResearcherUrls rUrls = getResearcherUrls();
assertNotNull(rUrls);
assertNotNull(rUrls.getResearcherUrls());
assertEquals(1, rUrls.getResearcherUrls().size());
ResearcherUrlEntity entity = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(rUrls.getResearcherUrls().get(0));
assertNotNull(entity);
// General info
assertEquals(Long.valueOf(1248), entity.getId());
assertEquals(Visibility.PUBLIC.value(), entity.getVisibility().value());
assertEquals("http://site1.com/", entity.getUrl());
assertEquals("Site # 1", entity.getUrlName());
// Source
assertNull(entity.getSourceId());
assertNull(entity.getClientSourceId());
assertNull(entity.getElementSourceId());
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method deleteResearcherUrl.
@Override
public boolean deleteResearcherUrl(String orcid, Long id, boolean checkSource) {
boolean result = true;
ResearcherUrlEntity toDelete = researcherUrlDao.getResearcherUrl(orcid, id);
if (checkSource) {
orcidSecurityManager.checkSource(toDelete);
}
try {
researcherUrlDao.deleteResearcherUrl(orcid, id);
} catch (Exception e) {
LOGGER.error("Unable to delete researcherUrl with ID: " + id);
result = false;
}
return result;
}
Aggregations