use of nikita.common.model.noark5.v4.metadata.PostalCode in project nikita-noark5-core by HiOA-ABI.
the class PostalCodeService method getPostalCodeOrThrow.
/**
* Internal helper method. Rather than having a find and try catch in
* multiple methods, we have it here once. If you call this, be aware
* that you will only ever get a valid PostalCode object back. If there
* is no PostalCode object, a NoarkEntityNotFoundException exception
* is thrown
*
* @param systemId The systemId of the PostalCode object to retrieve
* @return the PostalCode object
*/
private PostalCode getPostalCodeOrThrow(@NotNull String systemId) {
PostalCode postalCode = postalCodeRepository.findBySystemId(systemId);
if (postalCode == null) {
String info = INFO_CANNOT_FIND_OBJECT + " PostalCode, using " + "systemId " + systemId;
logger.error(info);
throw new NoarkEntityNotFoundException(info);
}
return postalCode;
}
use of nikita.common.model.noark5.v4.metadata.PostalCode in project nikita-noark5-core by HiOA-ABI.
the class PostalCodeService method createNewPostalCode.
// All CREATE operations
/**
* Persists a new PostalCode object to the database.
*
* @param postalCode PostalCode object with values set
* @return the newly persisted PostalCode object wrapped as a
* MetadataHateoas object
*/
@Override
public MetadataHateoas createNewPostalCode(PostalCode postalCode) {
postalCode.setDeleted(false);
postalCode.setOwnedBy(SecurityContextHolder.getContext().getAuthentication().getName());
MetadataHateoas metadataHateoas = new MetadataHateoas(postalCodeRepository.save(postalCode));
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
use of nikita.common.model.noark5.v4.metadata.PostalCode in project nikita-noark5-core by HiOA-ABI.
the class PostalCodeService method handleUpdate.
/**
* Update a PostalCode identified by its systemId
* <p>
* Copy the values you are allowed to change, code and description
*
* @param systemId The systemId of the postalCode object you wish to
* update
* @param postalCode The updated postalCode object. Note the values
* you are allowed to change are copied from this
* object. This object is not persisted.
* @return the updated postalCode
*/
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, PostalCode postalCode) {
PostalCode existingPostalCode = getPostalCodeOrThrow(systemId);
// Copy all the values you are allowed to copy ....
if (null != existingPostalCode.getCode()) {
existingPostalCode.setCode(existingPostalCode.getCode());
}
if (null != existingPostalCode.getDescription()) {
existingPostalCode.setDescription(existingPostalCode.getDescription());
}
// Note this can potentially result in a NoarkConcurrencyException
// exception
existingPostalCode.setVersion(version);
MetadataHateoas postalCodeHateoas = new MetadataHateoas(postalCodeRepository.save(existingPostalCode));
metadataHateoasHandler.addLinks(postalCodeHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingPostalCode));
return postalCodeHateoas;
}
Aggregations