use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class WorksController method validateWork.
@RequestMapping(value = "/workValidate.json", method = RequestMethod.POST)
@ResponseBody
public WorkForm validateWork(@RequestBody WorkForm work) {
work.setErrors(new ArrayList<String>());
if (work.getCitation() != null) {
workCitationValidate(work);
copyErrors(work.getCitation().getCitationType(), work);
copyErrors(work.getCitation().getCitation(), work);
}
workTitleValidate(work);
copyErrors(work.getTitle(), work);
if (work.getSubtitle() != null) {
workSubtitleValidate(work);
copyErrors(work.getSubtitle(), work);
}
if (work.getTranslatedTitle() != null) {
workTranslatedTitleValidate(work);
copyErrors(work.getTranslatedTitle(), work);
}
// allowed to be null
if (work.getShortDescription() != null) {
workdescriptionValidate(work);
copyErrors(work.getShortDescription(), work);
}
if (work.getWorkCategory() != null)
workWorkCategoryValidate(work);
workWorkTypeValidate(work);
copyErrors(work.getWorkType(), work);
if (work.getWorkExternalIdentifiers() != null) {
workWorkExternalIdentifiersValidate(work);
for (WorkExternalIdentifier wId : work.getWorkExternalIdentifiers()) {
copyErrors(wId.getWorkExternalIdentifierId(), work);
copyErrors(wId.getWorkExternalIdentifierType(), work);
}
}
if (work.getUrl() != null) {
workUrlValidate(work);
copyErrors(work.getUrl(), work);
}
if (work.getJournalTitle() != null) {
workJournalTitleValidate(work);
copyErrors(work.getJournalTitle(), work);
}
if (work.getPublicationDate() != null) {
workPublicationDateValidate(work);
copyErrors(work.getPublicationDate(), work);
}
// allowed to be null
if (work.getLanguageCode() != null) {
workLanguageCodeValidate(work);
copyErrors(work.getLanguageCode(), work);
}
// null
if (work.getPutCode() != null) {
validateWorkId(work);
}
return work;
}
use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class WorksController method workWorkExternalIdentifiersValidate.
@RequestMapping(value = "/work/workExternalIdentifiersValidate.json", method = RequestMethod.POST)
@ResponseBody
public WorkForm workWorkExternalIdentifiersValidate(@RequestBody WorkForm work) {
for (WorkExternalIdentifier wId : work.getWorkExternalIdentifiers()) {
if (wId.getWorkExternalIdentifierId() == null)
wId.setWorkExternalIdentifierId(new Text());
if (wId.getWorkExternalIdentifierType() == null)
wId.setWorkExternalIdentifierType(new Text());
wId.getWorkExternalIdentifierId().setErrors(new ArrayList<String>());
wId.getWorkExternalIdentifierType().setErrors(new ArrayList<String>());
// if has id type must be specified
if (wId.getWorkExternalIdentifierId().getValue() != null && !wId.getWorkExternalIdentifierId().getValue().trim().equals("") && (wId.getWorkExternalIdentifierType().getValue() == null || wId.getWorkExternalIdentifierType().getValue().equals(""))) {
setError(wId.getWorkExternalIdentifierType(), "NotBlank.currentWorkExternalIds.idType");
} else if (wId.getWorkExternalIdentifierId().getValue() != null && wId.getWorkExternalIdentifierId().getValue().length() > 2084) {
setError(wId.getWorkExternalIdentifierId(), "manualWork.length_less_2084");
}
// if type is set a id must set
if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().equals("") && (wId.getWorkExternalIdentifierId().getValue() == null || wId.getWorkExternalIdentifierId().getValue().trim().equals(""))) {
setError(wId.getWorkExternalIdentifierId(), "NotBlank.currentWorkExternalIds.id");
}
Map<String, IdentifierType> types = identifierTypeManager.fetchIdentifierTypesByAPITypeName(getLocale());
if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().isEmpty() && !types.keySet().contains(wId.getWorkExternalIdentifierType().getValue())) {
setError(wId.getWorkExternalIdentifierType(), "manualWork.id_invalid");
}
}
return work;
}
use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class WorksController method initializeFields.
private void initializeFields(WorkForm w) {
if (w.getVisibility() == null) {
ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
Visibility v = profile.getActivitiesVisibilityDefault() == null ? Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault();
w.setVisibility(v);
}
if (w.getTitle() == null) {
w.setTitle(new Text());
}
if (w.getSubtitle() == null) {
w.setSubtitle(new Text());
}
if (w.getTranslatedTitle() == null) {
TranslatedTitleForm tt = new TranslatedTitleForm();
tt.setContent(new String());
tt.setLanguageCode(new String());
tt.setLanguageName(new String());
w.setTranslatedTitle(tt);
}
if (PojoUtil.isEmpty(w.getJournalTitle())) {
Text jt = new Text();
jt.setRequired(false);
w.setJournalTitle(jt);
}
if (PojoUtil.isEmpty(w.getWorkCategory())) {
Text wCategoryText = new Text();
wCategoryText.setValue(new String());
wCategoryText.setRequired(true);
w.setWorkCategory(wCategoryText);
}
if (PojoUtil.isEmpty(w.getWorkType())) {
Text wTypeText = new Text();
wTypeText.setValue(new String());
wTypeText.setRequired(true);
w.setWorkType(wTypeText);
}
initializePublicationDate(w);
if (w.getWorkExternalIdentifiers() == null || w.getWorkExternalIdentifiers().isEmpty()) {
WorkExternalIdentifier wei = new WorkExternalIdentifier();
Text wdiType = new Text();
wdiType.setValue(new String());
wei.setWorkExternalIdentifierId(new Text());
wei.setWorkExternalIdentifierType(wdiType);
wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
List<WorkExternalIdentifier> wdiL = new ArrayList<WorkExternalIdentifier>();
wdiL.add(wei);
w.setWorkExternalIdentifiers(wdiL);
}
if (PojoUtil.isEmpty(w.getUrl())) {
w.setUrl(new Text());
}
if (w.getContributors() == null || w.getContributors().isEmpty()) {
List<Contributor> contrList = new ArrayList<Contributor>();
w.setContributors(contrList);
}
if (PojoUtil.isEmpty(w.getShortDescription())) {
w.setShortDescription(new Text());
}
if (PojoUtil.isEmpty(w.getLanguageCode())) {
Text lc = new Text();
lc.setRequired(false);
w.setLanguageCode(lc);
}
if (PojoUtil.isEmpty(w.getLanguageName())) {
Text ln = new Text();
ln.setRequired(false);
w.setLanguageName(ln);
}
if (PojoUtil.isEmpty(w.getCountryCode())) {
w.setCountryCode(new Text());
}
if (PojoUtil.isEmpty(w.getCountryName())) {
w.setCountryName(new Text());
}
}
use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class WorksController method removeEmptyExternalIdentifiers.
private void removeEmptyExternalIdentifiers(WorkForm workForm) {
if (workForm != null) {
if (workForm.getWorkExternalIdentifiers() != null && !workForm.getWorkExternalIdentifiers().isEmpty()) {
List<WorkExternalIdentifier> cleanExtIds = new ArrayList<WorkExternalIdentifier>();
for (WorkExternalIdentifier wExtId : workForm.getWorkExternalIdentifiers()) {
if (!PojoUtil.isEmpty(wExtId.getWorkExternalIdentifierType())) {
if (!PojoUtil.isEmpty(wExtId.getWorkExternalIdentifierId())) {
cleanExtIds.add(wExtId);
}
}
}
workForm.setWorkExternalIdentifiers(cleanExtIds);
}
}
}
use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.
the class WorksControllerTest method testFieldValidators.
@Test
public void testFieldValidators() throws Exception {
Work work = WorkFormTest.getWork();
WorkForm workForm = WorkForm.valueOf(work);
worksController.workTitleValidate(workForm);
assertEquals(0, workForm.getTitle().getErrors().size());
worksController.workSubtitleValidate(workForm);
assertEquals(0, workForm.getSubtitle().getErrors().size());
worksController.workTranslatedTitleValidate(workForm);
assertEquals(0, workForm.getTranslatedTitle().getErrors().size());
worksController.workUrlValidate(workForm);
assertEquals(0, workForm.getUrl().getErrors().size());
worksController.workJournalTitleValidate(workForm);
assertEquals(0, workForm.getJournalTitle().getErrors().size());
worksController.workLanguageCodeValidate(workForm);
assertEquals(0, workForm.getLanguageCode().getErrors().size());
worksController.workdescriptionValidate(workForm);
assertEquals(0, workForm.getShortDescription().getErrors().size());
worksController.workWorkTypeValidate(workForm);
assertEquals(0, workForm.getWorkType().getErrors().size());
worksController.workWorkExternalIdentifiersValidate(workForm);
for (WorkExternalIdentifier wId : workForm.getWorkExternalIdentifiers()) {
assertEquals(0, wId.getWorkExternalIdentifierId().getErrors().size());
assertEquals(0, wId.getWorkExternalIdentifierType().getErrors().size());
}
worksController.workCitationValidate(workForm);
assertEquals(0, workForm.getCitation().getCitation().getErrors().size());
assertEquals(0, workForm.getCitation().getCitationType().getErrors().size());
assertNotNull(workForm.getCountryCode());
assertNotNull(workForm.getCountryCode().getValue());
assertEquals(Iso3166Country.US.value(), workForm.getCountryCode().getValue());
// Set wrong values to each field
workForm.setTitle(Text.valueOf(buildLongWord()));
workForm.setSubtitle(Text.valueOf(buildLongWord()));
workForm.getTranslatedTitle().setContent(buildLongWord());
workForm.getTranslatedTitle().setLanguageCode(buildLongWord());
workForm.getUrl().setValue(buildLongWord());
workForm.getJournalTitle().setValue(buildLongWord());
workForm.getLanguageCode().setValue(buildLongWord());
workForm.getShortDescription().setValue(buildLongWord());
workForm.getWorkType().setValue(new String());
worksController.workTitleValidate(workForm);
assertEquals(1, workForm.getTitle().getErrors().size());
worksController.workSubtitleValidate(workForm);
assertEquals(1, workForm.getSubtitle().getErrors().size());
worksController.workTranslatedTitleValidate(workForm);
assertEquals(2, workForm.getTranslatedTitle().getErrors().size());
worksController.workUrlValidate(workForm);
assertEquals(2, workForm.getUrl().getErrors().size());
worksController.workJournalTitleValidate(workForm);
assertEquals(1, workForm.getJournalTitle().getErrors().size());
worksController.workLanguageCodeValidate(workForm);
assertEquals(1, workForm.getLanguageCode().getErrors().size());
worksController.workdescriptionValidate(workForm);
assertEquals(1, workForm.getShortDescription().getErrors().size());
worksController.workWorkTypeValidate(workForm);
assertEquals(1, workForm.getWorkType().getErrors().size());
}
Aggregations