use of org.orcid.jaxb.model.v3.dev1.common.Month in project ORCID-Source by ORCID.
the class ActivityValidator method validateWork.
public void validateWork(Work work, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
WorkTitle title = work.getWorkTitle();
if (title == null || title.getTitle() == null || PojoUtil.isEmpty(title.getTitle().getContent())) {
throw new ActivityTitleValidationException();
}
if (work.getCountry() != null) {
if (work.getCountry().getValue() == null) {
Map<String, String> params = new HashMap<String, String>();
String values = Arrays.stream(Iso3166Country.values()).map(element -> element.value()).collect(Collectors.joining(", "));
params.put("type", "country");
params.put("values", values);
throw new ActivityTypeValidationException(params);
}
}
// translated title language code
if (title != null && title.getTranslatedTitle() != null) {
String translatedTitle = title.getTranslatedTitle().getContent();
String languageCode = title.getTranslatedTitle().getLanguageCode();
if (PojoUtil.isEmpty(translatedTitle) && !PojoUtil.isEmpty(languageCode)) {
throw new OrcidValidationException("Please specify a translated title or remove the language code");
}
// If translated title language code is null or invalid
if (!PojoUtil.isEmpty(translatedTitle) && (PojoUtil.isEmpty(title.getTranslatedTitle().getLanguageCode()) || !Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(title.getTranslatedTitle().getLanguageCode()::equals))) {
Map<String, String> params = new HashMap<String, String>();
String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
params.put("type", "translated title -> language code");
params.put("values", values);
throw new ActivityTypeValidationException(params);
}
}
if (work.getWorkType() == null) {
Map<String, String> params = new HashMap<String, String>();
String values = Arrays.stream(WorkType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
params.put("type", "work type");
params.put("values", values);
throw new ActivityTypeValidationException(params);
}
if (!PojoUtil.isEmpty(work.getLanguageCode())) {
if (!Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(work.getLanguageCode()::equals)) {
Map<String, String> params = new HashMap<String, String>();
String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
params.put("type", "language code");
params.put("values", values);
throw new ActivityTypeValidationException(params);
}
}
// publication date
if (work.getPublicationDate() != null) {
PublicationDate pd = work.getPublicationDate();
Year year = pd.getYear();
Month month = pd.getMonth();
Day day = pd.getDay();
if (year != null) {
try {
Integer.valueOf(year.getValue());
} catch (NumberFormatException n) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "publication date -> year");
params.put("values", "integers");
throw new ActivityTypeValidationException(params);
}
if (year.getValue().length() != 4) {
throw new OrcidValidationException("Invalid year " + year.getValue() + " please specify a four digits value");
}
}
if (month != null) {
try {
Integer.valueOf(month.getValue());
} catch (NumberFormatException n) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "publication date -> month");
params.put("values", "integers");
throw new ActivityTypeValidationException(params);
}
if (month.getValue().length() != 2) {
throw new OrcidValidationException("Invalid month " + month.getValue() + " please specify a two digits value");
}
}
if (day != null) {
try {
Integer.valueOf(day.getValue());
} catch (NumberFormatException n) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "publication date -> day");
params.put("values", "integers");
throw new ActivityTypeValidationException(params);
}
if (day.getValue().length() != 2) {
throw new OrcidValidationException("Invalid day " + day.getValue() + " please specify a two digits value");
}
}
// Check the date is valid
boolean isYearEmpty = (year == null || year.getValue() == null) ? true : false;
boolean isMonthEmpty = (month == null || month.getValue() == null) ? true : false;
boolean isDayEmpty = (day == null || day.getValue() == null) ? true : false;
if (isYearEmpty && (!isMonthEmpty || !isDayEmpty)) {
throw new OrcidValidationException("Invalid date, please specify a year element");
} else if (!isYearEmpty && isMonthEmpty && !isDayEmpty) {
throw new OrcidValidationException("Invalid date, please specify a month element");
} else if (isYearEmpty && isMonthEmpty && !isDayEmpty) {
throw new OrcidValidationException("Invalid date, please specify a year and month elements");
}
}
// citation
if (work.getWorkCitation() != null) {
String citation = work.getWorkCitation().getCitation();
CitationType type = work.getWorkCitation().getWorkCitationType();
if (type == null) {
Map<String, String> params = new HashMap<String, String>();
String values = Arrays.stream(CitationType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
params.put("type", "citation type");
params.put("values", values);
throw new ActivityTypeValidationException(params);
}
if (PojoUtil.isEmpty(citation)) {
throw new OrcidValidationException("Please specify a citation or remove the parent tag");
}
}
if (work.getWorkExternalIdentifiers() == null || work.getWorkExternalIdentifiers().getExternalIdentifier() == null || work.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
throw new ActivityIdentifierValidationException();
}
if (work.getWorkContributors() != null) {
WorkContributors contributors = work.getWorkContributors();
if (!contributors.getContributor().isEmpty()) {
for (Contributor contributor : contributors.getContributor()) {
if (contributor.getContributorOrcid() != null) {
ContributorOrcid contributorOrcid = contributor.getContributorOrcid();
if (!PojoUtil.isEmpty(contributorOrcid.getUri())) {
if (!OrcidStringUtils.isValidOrcid2_1Uri(contributorOrcid.getUri())) {
throw new OrcidValidationException("Invalid contributor URI");
}
}
if (!PojoUtil.isEmpty(contributorOrcid.getPath())) {
if (!OrcidStringUtils.isValidOrcid(contributorOrcid.getPath())) {
throw new OrcidValidationException("Invalid contributor ORCID");
}
}
}
if (contributor.getCreditName() != null) {
if (PojoUtil.isEmpty(contributor.getCreditName().getContent())) {
throw new OrcidValidationException("Please specify a contributor credit name or remove the empty tag");
}
}
if (contributor.getContributorEmail() != null) {
if (PojoUtil.isEmpty(contributor.getContributorEmail().getValue())) {
throw new OrcidValidationException("Please specify a contributor email or remove the empty tag");
}
}
}
}
}
if (work.getPutCode() != null && createFlag) {
Map<String, String> params = new HashMap<String, String>();
if (sourceEntity != null) {
params.put("clientName", sourceEntity.getSourceName());
}
throw new InvalidPutCodeException(params);
}
// Check that we are not changing the visibility
if (isApiRequest && !createFlag) {
Visibility updatedVisibility = work.getVisibility();
validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
}
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
use of org.orcid.jaxb.model.v3.dev1.common.Month in project ORCID-Source by ORCID.
the class PojoUtilTest method affiliationsCreateDateSortString_StartDateOnlyTest.
@Test
public void affiliationsCreateDateSortString_StartDateOnlyTest() {
Affiliation aff = new Employment();
FuzzyDate start = new FuzzyDate();
start.setDay(new Day(1));
start.setMonth(new Month(2));
start.setYear(new Year(3));
aff.setStartDate(start);
String dateSortString = PojoUtil.createDateSortString(aff);
assertEquals("Y-3-02-01", dateSortString);
}
use of org.orcid.jaxb.model.v3.dev1.common.Month in project ORCID-Source by ORCID.
the class PojoUtilTest method affiliationsCreateDateSortString_EndDateOnlyTest.
@Test
public void affiliationsCreateDateSortString_EndDateOnlyTest() {
Affiliation aff = new Employment();
FuzzyDate end = new FuzzyDate();
end.setDay(new Day(1));
end.setMonth(new Month(2));
end.setYear(new Year(3));
aff.setEndDate(end);
String dateSortString = PojoUtil.createDateSortString(aff);
assertEquals("X-3-02-01", dateSortString);
}
use of org.orcid.jaxb.model.v3.dev1.common.Month 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.common.Month in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getFundingMapperFacade.
public MapperFacade getFundingMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("fundingExternalIdentifiersConverterId", new JSONFundingExternalIdentifiersConverterV3());
converterFactory.registerConverter("fundingContributorsConverterId", new JsonOrikaConverter<FundingContributors>());
ClassMapBuilder<Funding, ProfileFundingEntity> fundingClassMap = mapperFactory.classMap(Funding.class, ProfileFundingEntity.class);
addV3CommonFields(fundingClassMap);
registerSourceConverters(mapperFactory, fundingClassMap);
fundingClassMap.field("type", "type");
fundingClassMap.field("organizationDefinedType.content", "organizationDefinedType");
fundingClassMap.field("title.title.content", "title");
fundingClassMap.field("title.translatedTitle.content", "translatedTitle");
fundingClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
fundingClassMap.field("description", "description");
fundingClassMap.field("amount.content", "numericAmount");
fundingClassMap.field("amount.currencyCode", "currencyCode");
fundingClassMap.field("url.value", "url");
fundingClassMap.fieldBToA("org.name", "organization.name");
fundingClassMap.fieldBToA("org.city", "organization.address.city");
fundingClassMap.fieldBToA("org.region", "organization.address.region");
fundingClassMap.fieldBToA("org.country", "organization.address.country");
fundingClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
fundingClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
fundingClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
fundingClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
fundingClassMap.fieldMap("contributors", "contributorsJson").converter("fundingContributorsConverterId").add();
fundingClassMap.register();
ClassMapBuilder<FundingSummary, ProfileFundingEntity> fundingSummaryClassMap = mapperFactory.classMap(FundingSummary.class, ProfileFundingEntity.class);
addV3CommonFields(fundingSummaryClassMap);
registerSourceConverters(mapperFactory, fundingSummaryClassMap);
fundingSummaryClassMap.field("type", "type");
fundingSummaryClassMap.field("title.title.content", "title");
fundingSummaryClassMap.field("title.translatedTitle.content", "translatedTitle");
fundingSummaryClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
fundingSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
fundingSummaryClassMap.fieldBToA("org.name", "organization.name");
fundingSummaryClassMap.fieldBToA("org.city", "organization.address.city");
fundingSummaryClassMap.fieldBToA("org.region", "organization.address.region");
fundingSummaryClassMap.fieldBToA("org.country", "organization.address.country");
fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
fundingSummaryClassMap.register();
mapperFactory.classMap(FuzzyDate.class, StartDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
mapperFactory.classMap(FuzzyDate.class, EndDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
return mapperFactory.getMapperFacade();
}
Aggregations