private boolean isDuplicated(AddressEntity existing, Address address, Source activeSource) { if (!existing.getId().equals(address.getPutCode())) { //If they have the same source String existingSourceId = existing.getElementSourceId(); if (!PojoUtil.isEmpty(existingSourceId) && SourceEntityUtils.isTheSameForDuplicateChecking(activeSource,existing)) { //TODO: Not sure this works! String vs Iso3166Country enum if(existing.getIso2Country().equals(address.getCountry().getValue())) { return true; } } } return false; }
public static void validateAddress(Address address, Source activeSource, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) { if(createFlag) { if(address.getPutCode() != null) { throw InvalidPutCodeException.forSource(activeSource); } } else { if(address.getPutCode() == null) { Map<String, String> params = new HashMap<String, String>(); throw new PutCodeRequiredException(params); } } if(address.getCountry() == null || address.getCountry().getValue() == null) { String message = "Country cannot be null"; LOGGER.error(message); throw new OrcidValidationException(message); } //Check that we are not changing the visibility validateAndFixVisibility(address, createFlag, isApiRequest, originalVisibility); }
Map<String, String> params = new HashMap<String, String>(); params.put("type", "address"); params.put("value", address.getCountry().getValue().name()); throw new OrcidDuplicatedElementException(params);
@Override public Address createAddress(String orcid, Address address, boolean isApiRequest) { Source activeSource = sourceManager.retrieveActiveSource(); // Validate the address PersonValidator.validateAddress(address, activeSource, true, isApiRequest, null); // Validate it is not duplicated List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid)); for (AddressEntity existing : existingAddresses) { if (isDuplicated(existing, address, activeSource)) { Map<String, String> params = new HashMap<String, String>(); params.put("type", "address"); params.put("value", address.getCountry().getValue().name()); throw new OrcidDuplicatedElementException(params); } } AddressEntity newEntity = adapter.toAddressEntity(address); ProfileEntity profile = profileEntityCacheManager.retrieve(orcid); newEntity.setUser(profile); newEntity.setDateCreated(new Date()); SourceEntityUtils.populateSourceAwareEntityFromSource(activeSource, newEntity); DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest); setIncomingPrivacy(newEntity, profile); addressDao.persist(newEntity); return adapter.toAddress(newEntity); }
if (work.getCountry().getValue() == null) { Map<String, String> params = new HashMap<String, String>(); String values = Arrays.stream(Iso3166Country.values()).map(element -> element.name()).collect(Collectors.joining(", "));
existingAddress.setLastModified(new Date()); existingAddress.setVisibility(updatedOrNew.getVisibility().name()); existingAddress.setIso2Country(updatedOrNew.getCountry().getValue().name()); existingAddress.setDisplayIndex(updatedOrNew.getDisplayIndex()); addressDao.merge(existingAddress);