Search in sources :

Example 26 with Fonds

use of nikita.common.model.noark5.v4.Fonds 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 27 with Fonds

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

the class FondsService method generateDefaultSeries.

/**
 * Generate a Default Fonds object that can be associated with the
 * identified 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 Series for
 * @return the Series object wrapped as a SeriesHateoas object
 */
@Override
public SeriesHateoas generateDefaultSeries(@NotNull String fondsSystemId) {
    Series defaultSeries = new Series();
    defaultSeries.setSeriesStatus(STATUS_OPEN);
    defaultSeries.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
    defaultSeries.setTitle("Default Series object generated by nikita " + "that can be associated with Fonds with systemID " + fondsSystemId);
    SeriesHateoas seriesHateoas = new SeriesHateoas(defaultSeries);
    seriesHateoasHandler.addLinksOnNew(seriesHateoas, new Authorisation());
    return seriesHateoas;
}
Also used : Series(nikita.common.model.noark5.v4.Series) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas)

Example 28 with Fonds

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

the class FondsService method getFondsOrThrow.

// All HELPER operations
/**
 * 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 Fonds back. If there is no valid
 * Fonds, a NoarkEntityNotFoundException exception is thrown
 *
 * @param fondsSystemId The systemId of the fonds object to retrieve
 * @return the fonds object
 */
private Fonds getFondsOrThrow(@NotNull String fondsSystemId) {
    Fonds fonds = fondsRepository.findBySystemId(fondsSystemId);
    if (fonds == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Fonds, using systemId " + fondsSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return fonds;
}
Also used : Fonds(nikita.common.model.noark5.v4.Fonds) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 29 with Fonds

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

the class FondsService method createFondsCreatorAssociatedWithFonds.

/**
 * Persists a new FondsCreator object to the database. Some values are set
 * in the incoming payload (e.g. fonds_creator_name) and some are set by
 * the core. owner,createdBy, createdDate are automatically set by the core.
 * <p>
 * First we try to locate the fonds to associate the FondsCreator with. If
 * the fonds does not exist a NoarkEntityNotFoundException exception is
 * thrown. After that we check that the Fonds object is not already closed.
 *
 * @param fondsSystemId The systemId of the fonds object you wish to
 *                      associate the fondsCreator object with
 * @param fondsCreator  incoming fondsCreator object with some values set
 * @return the newly persisted fondsCreator object wrapped as a
 * FondsCreatorHateoas object
 */
@Override
public FondsCreatorHateoas createFondsCreatorAssociatedWithFonds(@NotNull String fondsSystemId, @NotNull FondsCreator fondsCreator) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    checkFondsNotClosed(fonds);
    fondsCreatorService.createNewFondsCreator(fondsCreator);
    // add references to objects in both directions
    fondsCreator.addFonds(fonds);
    fonds.getReferenceFondsCreator().add(fondsCreator);
    // create the hateoas object with links
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, new Authorisation());
    return fondsCreatorHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) Fonds(nikita.common.model.noark5.v4.Fonds) FondsCreatorHateoas(nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)

Example 30 with Fonds

use of nikita.common.model.noark5.v4.Fonds 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)

Aggregations

Fonds (nikita.model.noark5.v4.Fonds)28 Counted (com.codahale.metrics.annotation.Counted)27 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 Timed (com.codahale.metrics.annotation.Timed)18 Fonds (nikita.common.model.noark5.v4.Fonds)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)14 Authorisation (nikita.webapp.security.Authorisation)13 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 ArrayList (java.util.ArrayList)5 Series (nikita.model.noark5.v4.Series)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 List (java.util.List)4 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)4 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)4 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)4 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)3