@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 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; }
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 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); }
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); }
existingKeyword.setLastModified(new Date()); existingKeyword.setVisibility(updatedOrNew.getVisibility().name()); existingKeyword.setKeywordName(updatedOrNew.getContent()); existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex()); profileKeywordDao.merge(existingKeyword);
if (!PojoUtil.isEmpty(keyword.getContent())) { form.setContent(keyword.getContent());