@Override public int compareTo(Keyword o) { if(o == null || o.getContent() == null) { return 1; } if(getContent() == null) { return -1; } return this.getContent().compareTo(o.getContent()); } }
public static void setPathToKeyword(Keyword keyword, String orcid) { if(keyword != null) { keyword.setPath(KEYWORDS.replace("{orcid}", orcid) + '/' + keyword.getPutCode()); } }
public static void calculateLastModified(Keywords keywords) { if (keywords != null && keywords.getKeywords() != null && !keywords.getKeywords().isEmpty()) { LastModifiedDate latest = null; for (Keyword keyword : keywords.getKeywords()) { if (keyword.getLastModifiedDate() != null && keyword.getLastModifiedDate().after(latest)) { latest = keyword.getLastModifiedDate(); } } keywords.setLastModifiedDate(latest); } }
if (keyword.getPutCode() != null) { form.setPutCode(String.valueOf(keyword.getPutCode())); if (!PojoUtil.isEmpty(keyword.getContent())) { form.setContent(keyword.getContent()); if (keyword.getVisibility() != null) { form.setVisibility(Visibility.valueOf(keyword.getVisibility())); } else { form.setVisibility(Visibility.valueOf(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.KEYWORD_DEFAULT.getVisibility().value()))); if (keyword.getCreatedDate() != null) { Date createdDate = new Date(); createdDate.setYear(String.valueOf(keyword.getCreatedDate().getValue().getYear())); createdDate.setMonth(String.valueOf(keyword.getCreatedDate().getValue().getMonth())); createdDate.setDay(String.valueOf(keyword.getCreatedDate().getValue().getDay())); form.setCreatedDate(createdDate); if (keyword.getLastModifiedDate() != null) { Date lastModifiedDate = new Date(); lastModifiedDate.setYear(String.valueOf(keyword.getLastModifiedDate().getValue().getYear())); lastModifiedDate.setMonth(String.valueOf(keyword.getLastModifiedDate().getValue().getMonth())); lastModifiedDate.setDay(String.valueOf(keyword.getLastModifiedDate().getValue().getDay())); form.setLastModified(lastModifiedDate); if (keyword.getSource() != null) { form.setSource(keyword.getSource().retrieveSourcePath()); if (keyword.getSource().getSourceName() != null) {
public Keyword toKeyword() { Keyword keyword = new Keyword(); if (!PojoUtil.isEmpty(putCode)) { keyword.setPutCode(Long.valueOf(putCode)); } if (!PojoUtil.isEmpty(content)) { keyword.setContent(content); } if (visibility != null && visibility.getVisibility() != null) { keyword.setVisibility(org.orcid.jaxb.model.v3.rc2.common.Visibility.fromValue(visibility.getVisibility().value())); } else { keyword.setVisibility(org.orcid.jaxb.model.v3.rc2.common.Visibility.fromValue(OrcidVisibilityDefaults.KEYWORD_DEFAULT.getVisibility().value())); } if (createdDate != null) { keyword.setCreatedDate(new CreatedDate(DateUtils.convertToXMLGregorianCalendar(createdDate.toCalendar()))); } if (lastModified != null) { keyword.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(lastModified.toCalendar()))); } if (displayIndex != null) { keyword.setDisplayIndex(displayIndex); } else { keyword.setDisplayIndex(0L); } keyword.setSource(new Source(source)); return keyword; }
if(keywords.getKeywords() != null) { for (Keyword updatedOrNew : keywords.getKeywords()) { if (existing.getId().equals(updatedOrNew.getPutCode())) { deleteMe = false; break; if (updatedOrNew.getPutCode() != null) { if (existingKeyword.getId().equals(updatedOrNew.getPutCode())) { existingKeyword.setLastModified(new Date()); existingKeyword.setVisibility(updatedOrNew.getVisibility().name()); existingKeyword.setKeywordName(updatedOrNew.getContent()); existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex()); profileKeywordDao.merge(existingKeyword); newKeyword.setVisibility(updatedOrNew.getVisibility().name()); newKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex()); profileKeywordDao.persist(newKeyword);
public static void validateKeyword(Keyword keyword, Source activeSource, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) { if(createFlag) { if(keyword.getPutCode() != null) { throw InvalidPutCodeException.forSource(activeSource); } } else { if(keyword.getPutCode() == null) { Map<String, String> params = new HashMap<String, String>(); throw new PutCodeRequiredException(params); } } if(PojoUtil.isEmpty(keyword.getContent())) { String message = "Keyword cannot be null"; LOGGER.error(message); throw new OrcidValidationException(message); } //Check that we are not changing the visibility validateAndFixVisibility(keyword, createFlag, isApiRequest, originalVisibility); }
private boolean isDuplicated(ProfileKeywordEntity existing, org.orcid.jaxb.model.v3.rc2.record.Keyword keyword, Source activeSource) { if (!existing.getId().equals(keyword.getPutCode())) { String existingSourceId = existing.getElementSourceId(); if (!PojoUtil.isEmpty(existingSourceId) && SourceEntityUtils.isTheSameForDuplicateChecking(activeSource,existing)) { if (existing.getKeywordName() != null && existing.getKeywordName().equals(keyword.getContent())) { return true; } } } return false; }
public static KeywordsForm valueOf(Keywords keywords) { KeywordsForm kf = new KeywordsForm(); if (keywords.getKeywords() != null) { for (Keyword keyword : keywords.getKeywords()) { if (keyword.getContent() != null) { kf.getKeywords().add(KeywordForm.valueOf(keyword)); } } } return kf; }
Map<String, String> params = new HashMap<String, String>(); params.put("type", "keyword"); params.put("value", keyword.getContent()); throw new OrcidDuplicatedElementException(params);
@Override public Keyword createKeyword(String orcid, Keyword keyword, boolean isApiRequest) { Source activeSource = sourceManager.retrieveActiveSource(); // Validate the keyword PersonValidator.validateKeyword(keyword, activeSource, true, isApiRequest, null); // Validate it is not duplicated List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywords(orcid, getLastModified(orcid)); for (ProfileKeywordEntity existing : existingKeywords) { if (isDuplicated(existing, keyword, activeSource)) { Map<String, String> params = new HashMap<String, String>(); params.put("type", "keyword"); params.put("value", keyword.getContent()); throw new OrcidDuplicatedElementException(params); } } ProfileKeywordEntity newEntity = adapter.toProfileKeywordEntity(keyword); ProfileEntity profile = profileEntityCacheManager.retrieve(orcid); newEntity.setProfile(profile); newEntity.setDateCreated(new Date()); //Set the source SourceEntityUtils.populateSourceAwareEntityFromSource(activeSource, newEntity); setIncomingPrivacy(newEntity, profile); DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest); profileKeywordDao.persist(newEntity); return adapter.toKeyword(newEntity); }