use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class GetMyDataControllerTest method testDownload.
@Test
public void testDownload() throws JAXBException, IOException {
SecurityContextHolder.getContext().setAuthentication(getAuthentication());
MockHttpServletResponse response = new MockHttpServletResponse();
getMyDataController.getMyData(response);
byte[] content = response.getContentAsByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(content);
ZipInputStream zip = new ZipInputStream(is);
ZipEntry zipEntry = zip.getNextEntry();
JAXBContext jaxbContext1 = JAXBContext.newInstance(Person.class, Distinction.class, Education.class, Employment.class, InvitedPosition.class, Membership.class, Qualification.class, Service.class, Funding.class, PeerReview.class, Work.class);
Unmarshaller u = jaxbContext1.createUnmarshaller();
boolean personFound = false;
boolean distinctionFound = false;
boolean educationFound = false;
boolean employmentFound = false;
boolean invitedPositionFound = false;
boolean membershipFound = false;
boolean qualificationFound = false;
boolean serviceFound = false;
boolean fundingFound = false;
boolean peerReviewFound = false;
boolean workFound = false;
while (zipEntry != null) {
String fileName = zipEntry.getName();
byte[] buffer = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
while ((len = zip.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
if (fileName.equals("person.xml")) {
Person x = (Person) u.unmarshal(in);
assertNotNull(x);
assertEquals("Biography", x.getBiography().getContent());
assertEquals(Visibility.LIMITED, x.getBiography().getVisibility());
personFound = true;
} else if (fileName.startsWith("affiliations/distinctions")) {
assertEquals("affiliations/distinctions/1.xml", fileName);
Distinction x = (Distinction) u.unmarshal(in);
assertNotNull(x);
assertEquals("distinction", x.getDepartmentName());
assertEquals(Long.valueOf(1), x.getPutCode());
validateOrg(x);
distinctionFound = true;
} else if (fileName.startsWith("affiliations/educations")) {
assertEquals("affiliations/educations/2.xml", fileName);
Education x = (Education) u.unmarshal(in);
assertNotNull(x);
assertEquals("education", x.getDepartmentName());
assertEquals(Long.valueOf(2), x.getPutCode());
validateOrg(x);
educationFound = true;
} else if (fileName.startsWith("affiliations/employments")) {
assertEquals("affiliations/employments/3.xml", fileName);
Employment x = (Employment) u.unmarshal(in);
assertNotNull(x);
assertEquals("employment", x.getDepartmentName());
assertEquals(Long.valueOf(3), x.getPutCode());
validateOrg(x);
employmentFound = true;
} else if (fileName.startsWith("affiliations/invited_positions")) {
assertEquals("affiliations/invited_positions/4.xml", fileName);
InvitedPosition x = (InvitedPosition) u.unmarshal(in);
assertNotNull(x);
assertEquals("invited position", x.getDepartmentName());
assertEquals(Long.valueOf(4), x.getPutCode());
validateOrg(x);
invitedPositionFound = true;
} else if (fileName.startsWith("affiliations/memberships")) {
assertEquals("affiliations/memberships/5.xml", fileName);
Membership x = (Membership) u.unmarshal(in);
assertNotNull(x);
assertEquals("membership", x.getDepartmentName());
assertEquals(Long.valueOf(5), x.getPutCode());
validateOrg(x);
membershipFound = true;
} else if (fileName.startsWith("affiliations/qualifications")) {
assertEquals("affiliations/qualifications/6.xml", fileName);
Qualification x = (Qualification) u.unmarshal(in);
assertNotNull(x);
assertEquals("qualification", x.getDepartmentName());
assertEquals(Long.valueOf(6), x.getPutCode());
validateOrg(x);
qualificationFound = true;
} else if (fileName.startsWith("affiliations/services")) {
assertEquals("affiliations/services/7.xml", fileName);
Service x = (Service) u.unmarshal(in);
assertNotNull(x);
assertEquals("service", x.getDepartmentName());
assertEquals(Long.valueOf(7), x.getPutCode());
validateOrg(x);
serviceFound = true;
} else if (fileName.startsWith("fundings")) {
assertEquals("fundings/1.xml", fileName);
Funding x = (Funding) u.unmarshal(in);
assertNotNull(x);
assertEquals("title", x.getTitle().getTitle().getContent());
assertEquals("1000", x.getAmount().getContent());
assertEquals("$", x.getAmount().getCurrencyCode());
assertEquals(Long.valueOf(1), x.getPutCode());
validateOrg(x);
fundingFound = true;
} else if (fileName.startsWith("peer_reviews")) {
assertEquals("peer_reviews/1.xml", fileName);
PeerReview x = (PeerReview) u.unmarshal(in);
assertNotNull(x);
validateOrg(x);
assertEquals(Long.valueOf(1), x.getPutCode());
peerReviewFound = true;
} else if (fileName.startsWith("works")) {
assertEquals("works/1.xml", fileName);
Work x = (Work) u.unmarshal(in);
assertNotNull(x);
assertEquals(Long.valueOf(1), x.getPutCode());
workFound = true;
}
zipEntry = zip.getNextEntry();
}
assertTrue(personFound);
assertTrue(distinctionFound);
assertTrue(educationFound);
assertTrue(employmentFound);
assertTrue(invitedPositionFound);
assertTrue(membershipFound);
assertTrue(qualificationFound);
assertTrue(serviceFound);
assertTrue(fundingFound);
assertTrue(peerReviewFound);
assertTrue(workFound);
zip.closeEntry();
zip.close();
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class PeerReviewsController method addPeerReview.
private PeerReviewForm addPeerReview(PeerReviewForm peerReviewForm) {
String userOrcid = getEffectiveUserOrcid();
PeerReview peerReview = peerReviewForm.toPeerReview();
peerReview = peerReviewManager.createPeerReview(userOrcid, peerReview, false);
peerReviewForm = PeerReviewForm.valueOf(peerReview);
return peerReviewForm;
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class OrcidInfo method getPeerReviewsJson.
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/peer-reviews.json")
@ResponseBody
public List<PeerReviewForm> getPeerReviewsJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "peerReviewIds") String peerReviewIdsStr) {
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
List<PeerReviewForm> peerReviews = new ArrayList<PeerReviewForm>();
Map<Long, PeerReview> peerReviewMap = activityManager.pubPeerReviewsMap(orcid);
String[] peerReviewIds = peerReviewIdsStr.split(",");
for (String id : peerReviewIds) {
PeerReview peerReview = peerReviewMap.get(Long.valueOf(id));
validateVisibility(peerReview.getVisibility());
sourceUtils.setSourceName(peerReview);
PeerReviewForm form = PeerReviewForm.valueOf(peerReview);
// Set language name
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, peerReview.getOrganization().getAddress().getCountry().name())));
if (!PojoUtil.isEmpty(form.getTranslatedSubjectName())) {
// Set translated title language name
if (!StringUtils.isEmpty(form.getTranslatedSubjectName().getLanguageCode())) {
String languageName = languages.get(form.getTranslatedSubjectName().getLanguageCode());
form.getTranslatedSubjectName().setLanguageName(languageName);
}
}
// the group id
if (form.getGroupId() != null && !PojoUtil.isEmpty(form.getGroupId().getValue())) {
GroupIdRecord groupId = groupIdRecordManager.findByGroupId(form.getGroupId().getValue()).get();
form.setGroupIdPutCode(Text.valueOf(groupId.getPutCode()));
}
peerReviews.add(form);
}
return peerReviews;
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getPeerReviewMapperFacade.
public MapperFacade getPeerReviewMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("workExternalIdentifiersConverterId", new JSONWorkExternalIdentifiersConverterV3(norm, localeManager));
converterFactory.registerConverter("workExternalIdentifierConverterId", new JSONPeerReviewWorkExternalIdentifierConverterV3());
// do same as work
ClassMapBuilder<PeerReview, PeerReviewEntity> classMap = mapperFactory.classMap(PeerReview.class, PeerReviewEntity.class);
addV3CommonFields(classMap);
registerSourceConverters(mapperFactory, classMap);
classMap.field("url.value", "url");
classMap.field("organization.name", "org.name");
classMap.field("organization.address.city", "org.city");
classMap.field("organization.address.region", "org.region");
classMap.field("organization.address.country", "org.country");
classMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
classMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
classMap.field("groupId", "groupId");
classMap.field("subjectType", "subjectType");
classMap.field("subjectUrl.value", "subjectUrl");
classMap.field("subjectName.title.content", "subjectName");
classMap.field("subjectName.translatedTitle.content", "subjectTranslatedName");
classMap.field("subjectName.translatedTitle.languageCode", "subjectTranslatedNameLanguageCode");
classMap.field("subjectContainerName.content", "subjectContainerName");
classMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
classMap.fieldMap("subjectExternalIdentifier", "subjectExternalIdentifiersJson").converter("workExternalIdentifierConverterId").add();
classMap.register();
ClassMapBuilder<PeerReviewSummary, PeerReviewEntity> peerReviewSummaryClassMap = mapperFactory.classMap(PeerReviewSummary.class, PeerReviewEntity.class);
addV3CommonFields(peerReviewSummaryClassMap);
registerSourceConverters(mapperFactory, peerReviewSummaryClassMap);
peerReviewSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
peerReviewSummaryClassMap.field("organization.name", "org.name");
peerReviewSummaryClassMap.field("organization.address.city", "org.city");
peerReviewSummaryClassMap.field("organization.address.region", "org.region");
peerReviewSummaryClassMap.field("organization.address.country", "org.country");
peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
peerReviewSummaryClassMap.register();
mapperFactory.classMap(FuzzyDate.class, CompletionDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validatePeerReviewWithoutDisambiguatedOrgId.
@Test(expected = InvalidDisambiguatedOrgException.class)
public void validatePeerReviewWithoutDisambiguatedOrgId() {
PeerReview pr = getPeerReview();
pr.getOrganization().getDisambiguatedOrganization().setDisambiguatedOrganizationIdentifier(null);
activityValidator.validatePeerReview(pr, null, false, true, Visibility.PUBLIC);
}
Aggregations