use of org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ResearcherUrlsTest method testReadPublicScope_ResearcherUrls.
@Test
public void testReadPublicScope_ResearcherUrls() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
// Public works
Response r = serviceDelegator.viewResearcherUrls(ORCID);
assertNotNull(r);
ResearcherUrls ru = (ResearcherUrls) r.getEntity();
assertNotNull(ru);
assertEquals("/0000-0000-0000-0003/researcher-urls", ru.getPath());
Utils.verifyLastModified(ru.getLastModifiedDate());
assertEquals(3, ru.getResearcherUrls().size());
boolean found13 = false, found14 = false, found15 = false;
for (ResearcherUrl element : ru.getResearcherUrls()) {
if (element.getPutCode() == 13) {
found13 = true;
} else if (element.getPutCode() == 14) {
found14 = true;
} else if (element.getPutCode() == 15) {
found15 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found13);
assertTrue(found14);
assertTrue(found15);
r = serviceDelegator.viewResearcherUrl(ORCID, 13L);
assertNotNull(r);
assertEquals(ResearcherUrl.class.getName(), r.getEntity().getClass().getName());
// Limited am the source of should work
serviceDelegator.viewResearcherUrl(ORCID, 14L);
// Limited am not the source of should fail
try {
serviceDelegator.viewResearcherUrl(ORCID, 16L);
fail();
} catch (OrcidAccessControlException e) {
} catch (Exception e) {
fail();
}
// Private am the source of should work
serviceDelegator.viewResearcherUrl(ORCID, 15L);
// Private am not the source of should fail
try {
serviceDelegator.viewResearcherUrl(ORCID, 17L);
fail();
} catch (OrcidAccessControlException e) {
} catch (Exception e) {
fail();
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl in project ORCID-Source by ORCID.
the class WebsitesForm method toResearcherUrls.
public ResearcherUrls toResearcherUrls() {
ResearcherUrls researcherUrls = new ResearcherUrls();
List<ResearcherUrl> ruList = new ArrayList<ResearcherUrl>();
for (WebsiteForm website : websites) {
ruList.add(website.toResearcherUrl());
}
researcherUrls.setResearcherUrls(ruList);
return researcherUrls;
}
use of org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl in project ORCID-Source by ORCID.
the class Api3_0_Dev1LastModifiedDatesHelper method calculateLastModified.
public static void calculateLastModified(ResearcherUrls researcherUrls) {
if (researcherUrls != null && researcherUrls.getResearcherUrls() != null && !researcherUrls.getResearcherUrls().isEmpty()) {
LastModifiedDate latest = null;
for (ResearcherUrl researcherUrl : researcherUrls.getResearcherUrls()) {
if (researcherUrl.getLastModifiedDate() != null && researcherUrl.getLastModifiedDate().after(latest)) {
latest = researcherUrl.getLastModifiedDate();
}
}
researcherUrls.setLastModifiedDate(latest);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl 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.jaxb.model.v3.dev1.record.ResearcherUrl in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method updateResearcherUrl.
@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = updatedResearcherUrlEntity.getSourceId();
String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
// Validate the researcher url
PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
for (ResearcherUrlEntity existing : existingResearcherUrls) {
if (isDuplicated(existing, researcherUrl, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "researcher-url");
params.put("value", researcherUrl.getUrlName());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
updatedResearcherUrlEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedResearcherUrlEntity.setSourceId(existingSourceId);
updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
researcherUrlDao.merge(updatedResearcherUrlEntity);
return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
Aggregations