Search in sources :

Example 6 with FondsHateoas

use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsService method createFondsAssociatedWithFonds.

/**
 * Persists a new fonds object to the database, that is first associated
 * with a parent fonds object. Some values are set in the incoming
 * payload (e.g. title) and some are set by the core. owner, createdBy,
 * createdDate are automatically set by the core.
 * <p>
 * First we try to locate the parent. If the parent does not exist a
 * NoarkEntityNotFoundException exception is thrown
 *
 * @param childFonds          incoming fonds object with some values set
 * @param parentFondsSystemId The systemId of the parent fonds
 * @return the newly persisted fonds object
 */
@Override
public FondsHateoas createFondsAssociatedWithFonds(@NotNull String parentFondsSystemId, @NotNull Fonds childFonds) {
    Fonds parentFonds = getFondsOrThrow(parentFondsSystemId);
    checkFondsDoesNotContainSeries(parentFonds);
    childFonds.setReferenceParentFonds(parentFonds);
    return createNewFonds(childFonds);
}
Also used : Fonds(nikita.common.model.noark5.v4.Fonds)

Example 7 with FondsHateoas

use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsService method findSingleFonds.

/**
 * Retrieve a list of StorageLocation objects associated with a given Fonds
 * from the database. First we try to locate the Fonds object. If the
 * Fonds object does not exist a NoarkEntityNotFoundException exception
 * is thrown that the caller has to deal with.
 *
 * If any StorageLocation objects exist, they are wrapped in a
 * StorageLocationHateoas object and returned to the caller.
 *
 * @param fondsSystemId The systemId of the Fonds object that you want to
 *                      retrieve associated StorageLocation objects
 *
 * @return the newly persisted fondsCreator object wrapped as a
 * StorageLocationHateoas object
 */
/*@Override
    TODO: Finish implementing this.
    public StorageLocationHateoas findStorageLocationAssociatedWithFonds(
            @NotNull String fondsSystemId) {

        Fonds fonds = getFondsOrThrow(fondsSystemId);

        StorageLocationHateoas stroageLocationHateoas = new
                StorageLocationHateoas((List<INikitaEntity>)
                (List) fonds.getReferenceStorageLocation());
        fondsCreatorHateoasHandler.addLinks(stroageLocationHateoas,
                new Authorisation());
        return stroageLocationHateoas;
    } */
/**
 * Retrieve a single Fonds objects from the database.
 *
 * @param fondsSystemId The systemId of the Fonds object you wish to
 *                      retrieve
 * @return the Fonds object wrapped as a FondsHateoas object
 */
@Override
public FondsHateoas findSingleFonds(String fondsSystemId) {
    Fonds existingFonds = getFondsOrThrow(fondsSystemId);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(existingFonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFonds));
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 8 with FondsHateoas

use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsService method generateDefaultFonds.

/**
 * Generate a Default Fonds object that can be associated with the
 * identified Fonds. If fondsSystemId has a value, it is assumed you wish
 * to generate a sub-fonds.
 * <br>
 * Note. Ideally this method would be configurable based on the logged in
 * user and the business area they are working with. A generic Noark core
 * like this does not have scope for that kind of functionality.
 *
 * @param fondsSystemId The systemId of the Fonds object you wish to
 *                      generate a default sub-fonds. Null if the Fonds
 *                      is not a sub-fonds.
 * @return the Fonds object wrapped as a FondsHateoas object
 */
@Override
public FondsHateoas generateDefaultFonds(String fondsSystemId) {
    Fonds defaultFonds = new Fonds();
    defaultFonds.setTitle(TEST_TITLE);
    defaultFonds.setDescription(TEST_DESCRIPTION);
    defaultFonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
    FondsHateoas fondsHateoas = new FondsHateoas(defaultFonds);
    fondsHateoasHandler.addLinksOnNew(fondsHateoas, new Authorisation());
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds)

Example 9 with FondsHateoas

use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsService method handleUpdate.

// All UPDATE operations
/**
 * Updates a Fonds object in the database. First we try to locate the
 * Fonds object. If the Fonds object does not exist a
 * NoarkEntityNotFoundException exception is thrown that the caller has
 * to deal with.
 * <br>
 * After this the values you are allowed to update are copied from the
 * incomingFonds object to the existingFonds object and the existingFonds
 * object will be persisted to the database when the transaction boundary
 * is over.
 * <p>
 * Note, the version corresponds to the version number, when the object
 * was initially retrieved from the database. If this number is not the
 * same as the version number when re-retrieving the Fonds object from
 * the database a NoarkConcurrencyException is thrown. Note. This happens
 * when the call to Fonds.setVersion() occurs.
 *
 * @param fondsSystemId The systemId of the fonds object to retrieve
 * @param version       The last known version number (derived from an ETAG)
 * @param incomingFonds The incoming fonds object
 */
@Override
public FondsHateoas handleUpdate(@NotNull String fondsSystemId, @NotNull Long version, @NotNull Fonds incomingFonds) {
    Fonds existingFonds = getFondsOrThrow(fondsSystemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingFonds.getDescription()) {
        existingFonds.setDescription(incomingFonds.getDescription());
    }
    if (null != incomingFonds.getTitle()) {
        existingFonds.setTitle(incomingFonds.getTitle());
    }
    if (null != incomingFonds.getDocumentMedium()) {
        existingFonds.setDocumentMedium(existingFonds.getDocumentMedium());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingFonds.setVersion(version);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(existingFonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFonds));
    return fondsHateoas;
}
Also used : FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Example 10 with FondsHateoas

use of nikita.common.model.noark5.v4.hateoas.FondsHateoas in project nikita-noark5-core by HiOA-ABI.

the class FondsService method createNewFonds.

// All CREATE operations
/**
 * Persists a new fonds object to the database. Some values are set in the
 * incoming payload (e.g. title) and some are set by the core.
 * owner, createdBy, createdDate are automatically set by the core.
 *
 * @param fonds fonds object with some values set
 * @return the newly persisted fonds object wrapped as a fondsHateaos object
 */
@Override
public FondsHateoas createNewFonds(@NotNull Fonds fonds) {
    NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(fonds);
    NoarkUtils.NoarkEntity.Create.setNoarkEntityValues(fonds);
    fonds.setFondsStatus(STATUS_OPEN);
    NoarkUtils.NoarkEntity.Create.setFinaliseEntityValues(fonds);
    FondsHateoas fondsHateoas = new FondsHateoas(fondsRepository.save(fonds));
    fondsHateoasHandler.addLinks(fondsHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fonds));
    return fondsHateoas;
}
Also used : AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) FondsHateoas(nikita.common.model.noark5.v4.hateoas.FondsHateoas) Authorisation(nikita.webapp.security.Authorisation)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)15 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15 Timed (com.codahale.metrics.annotation.Timed)10 Fonds (nikita.model.noark5.v4.Fonds)10 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)8 Fonds (nikita.common.model.noark5.v4.Fonds)6 Authorisation (nikita.webapp.security.Authorisation)6 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)3 ArrayList (java.util.ArrayList)2 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)2 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)2 AfterNoarkEntityUpdatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)2 ResponseEntity (org.springframework.http.ResponseEntity)2 List (java.util.List)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)1 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)1