use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.
the class PojoUtilTest method affiliationsCreateDateSortString_EndDate_NullMonthNullDayTest.
@Test
public void affiliationsCreateDateSortString_EndDate_NullMonthNullDayTest() {
Affiliation aff = new Employment();
FuzzyDate end = new FuzzyDate();
end.setYear(new Year(2017));
aff.setEndDate(end);
String dateSortString = PojoUtil.createDateSortString(aff);
assertEquals("X-2017-00-00", dateSortString);
}
use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.
the class GetMyDataControllerTest method before.
@Before
public void before() {
MockitoAnnotations.initMocks(this);
TargetProxyHelper.injectIntoProxy(getMyDataController, "batchSize", 50);
TargetProxyHelper.injectIntoProxy(getMyDataController, "personDetailsManager", mockPersonDetailsManager);
TargetProxyHelper.injectIntoProxy(getMyDataController, "workEntityCacheManager", mockWorkEntityCacheManager);
TargetProxyHelper.injectIntoProxy(getMyDataController, "affiliationManagerReadOnly", mockAffiliationManagerReadOnly);
TargetProxyHelper.injectIntoProxy(getMyDataController, "profileFundingManagerReadOnly", mockProfileFundingManagerReadOnly);
TargetProxyHelper.injectIntoProxy(getMyDataController, "peerReviewManagerReadOnly", mockPeerReviewManagerReadOnly);
TargetProxyHelper.injectIntoProxy(getMyDataController, "workManagerReadOnly", mockWorkManagerReadOnly);
when(mockPersonDetailsManager.getPersonDetails(anyString())).thenAnswer(new Answer<Person>() {
@Override
public Person answer(InvocationOnMock invocation) throws Throwable {
Person p = new Person();
p.setBiography(new Biography("Biography", Visibility.LIMITED));
Name name = new Name();
name.setVisibility(Visibility.LIMITED);
name.setFamilyName(new FamilyName("Family Name"));
name.setGivenNames(new GivenNames("Given Names"));
name.setCreditName(new CreditName("Credit Name"));
p.setName(name);
return p;
}
});
when(mockAffiliationManagerReadOnly.getAffiliations(anyString())).thenAnswer(new Answer<List<Affiliation>>() {
@Override
public List<Affiliation> answer(InvocationOnMock invocation) throws Throwable {
List<Affiliation> affs = new ArrayList<Affiliation>();
FuzzyDate startDate = new FuzzyDate(new Year(2018), new Month(1), new Day(1));
FuzzyDate endDate = new FuzzyDate(new Year(2018), new Month(12), new Day(31));
Distinction d = new Distinction();
d.setDepartmentName("distinction");
d.setEndDate(endDate);
d.setStartDate(startDate);
d.setPutCode(1L);
setOrg(d);
affs.add(d);
Education e = new Education();
e.setDepartmentName("education");
e.setEndDate(endDate);
e.setStartDate(startDate);
e.setPutCode(2L);
setOrg(e);
affs.add(e);
Employment emp = new Employment();
emp.setDepartmentName("employment");
emp.setEndDate(endDate);
emp.setStartDate(startDate);
emp.setPutCode(3L);
setOrg(emp);
affs.add(emp);
InvitedPosition i = new InvitedPosition();
i.setDepartmentName("invited position");
i.setEndDate(endDate);
i.setStartDate(startDate);
i.setPutCode(4L);
setOrg(i);
affs.add(i);
Membership m = new Membership();
m.setDepartmentName("membership");
m.setEndDate(endDate);
m.setStartDate(startDate);
m.setPutCode(5L);
setOrg(m);
affs.add(m);
Qualification q = new Qualification();
q.setDepartmentName("qualification");
q.setEndDate(endDate);
q.setStartDate(startDate);
q.setPutCode(6L);
setOrg(q);
affs.add(q);
Service s = new Service();
s.setDepartmentName("service");
s.setEndDate(endDate);
s.setStartDate(startDate);
s.setPutCode(7L);
setOrg(s);
affs.add(s);
return affs;
}
});
when(mockProfileFundingManagerReadOnly.getFundingList(anyString())).thenAnswer(new Answer<List<Funding>>() {
@Override
public List<Funding> answer(InvocationOnMock invocation) throws Throwable {
List<Funding> fundings = new ArrayList<Funding>();
Funding f = new Funding();
Amount a = new Amount();
a.setContent("1000");
a.setCurrencyCode("$");
f.setAmount(a);
FundingTitle t = new FundingTitle();
t.setTitle(new Title("title"));
f.setTitle(t);
setOrg(f);
f.setPutCode(1L);
fundings.add(f);
return fundings;
}
});
when(mockPeerReviewManagerReadOnly.findPeerReviews(anyString())).thenAnswer(new Answer<List<PeerReview>>() {
@Override
public List<PeerReview> answer(InvocationOnMock invocation) throws Throwable {
List<PeerReview> peerReviews = new ArrayList<PeerReview>();
PeerReview p = new PeerReview();
setOrg(p);
p.setPutCode(1L);
peerReviews.add(p);
return peerReviews;
}
});
when(mockWorkManagerReadOnly.findWorks(anyString(), any())).thenAnswer(new Answer<List<Work>>() {
@Override
public List<Work> answer(InvocationOnMock invocation) throws Throwable {
List<Work> works = new ArrayList<Work>();
Work w = new Work();
WorkTitle t = new WorkTitle();
t.setTitle(new Title("title"));
w.setPutCode(1L);
works.add(w);
return works;
}
});
when(mockWorkManagerReadOnly.getLastModified(anyString())).thenReturn(0L);
when(mockWorkEntityCacheManager.retrieveWorkLastModifiedList(anyString(), anyLong())).thenAnswer(new Answer<List<WorkLastModifiedEntity>>() {
@Override
public List<WorkLastModifiedEntity> answer(InvocationOnMock invocation) throws Throwable {
List<WorkLastModifiedEntity> works = new ArrayList<WorkLastModifiedEntity>();
WorkLastModifiedEntity w = new WorkLastModifiedEntity();
w.setId(1L);
w.setOrcid(ORCID);
w.setLastModified(new Date());
works.add(w);
return works;
}
});
}
use of org.orcid.jaxb.model.v3.dev1.record.Employment 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.Employment in project ORCID-Source by ORCID.
the class GetMyDataController method generateAffiliationsData.
private void generateAffiliationsData(String orcid, ZipOutputStream zip) throws JAXBException, IOException {
List<Affiliation> affiliations = affiliationManagerReadOnly.getAffiliations(orcid);
for (Affiliation affiliation : affiliations) {
String elementName = null;
if (affiliation instanceof Distinction) {
elementName = DISTINCTIONS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof Education) {
elementName = EDUCATIONS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof Employment) {
elementName = EMPLOYMENTS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof InvitedPosition) {
elementName = INVITED_POSITIONS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof Membership) {
elementName = MEMBERSHIPS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof Qualification) {
elementName = QUALIFICATIONS_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else if (affiliation instanceof Service) {
elementName = SERVICES_DIR_NAME + '/' + affiliation.getPutCode() + ".xml";
} else {
throw new IllegalArgumentException("Invalid affiliation type: " + affiliation.getClass().getName());
}
writeElement(toByteArray(affiliation), elementName, zip);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getEmploymentMapperFacade.
public MapperFacade getEmploymentMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ClassMapBuilder<Employment, OrgAffiliationRelationEntity> classMap = mapperFactory.classMap(Employment.class, OrgAffiliationRelationEntity.class);
ClassMapBuilder<EmploymentSummary, OrgAffiliationRelationEntity> summaryClassMap = mapperFactory.classMap(EmploymentSummary.class, OrgAffiliationRelationEntity.class);
return generateMapperFacadeForAffiliation(mapperFactory, classMap, summaryClassMap);
}
Aggregations