Search in sources :

Example 6 with PostalCode

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;
}
Also used : PostalCode(nikita.common.model.noark5.v4.metadata.PostalCode) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 7 with 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;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 8 with PostalCode

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;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) PostalCode(nikita.common.model.noark5.v4.metadata.PostalCode) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Aggregations

MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)6 Authorisation (nikita.webapp.security.Authorisation)6 List (java.util.List)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 PostalCode (nikita.common.model.noark5.v4.metadata.PostalCode)3 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1