Search in sources :

Example 1 with Series

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

the class FondsService method createFondsAssociatedWithFonds.

/**
     *
     ** Persists a new fonds object to the database, that is 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.
     *
     * 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 Fonds createFondsAssociatedWithFonds(String parentFondsSystemId, Fonds childFonds) {
    Fonds persistedChildFonds = null;
    Fonds parentFonds = fondsRepository.findBySystemIdOrderBySystemId(parentFondsSystemId);
    if (parentFonds == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Fonds, using fondsSystemId " + parentFondsSystemId + " when " + "trying to associate a child fonds with a parent fonds";
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (parentFonds.getReferenceSeries() != null) {
        String info = INFO_INVALID_STRUCTURE + " Cannot associate a new child fonds with a fonds that has " + "one or more series " + parentFondsSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        childFonds.setReferenceParentFonds(parentFonds);
        persistedChildFonds = this.createNewFonds(childFonds);
    }
    return persistedChildFonds;
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 2 with Series

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

the class FondsService method createSeriesAssociatedWithFonds.

/**
     *
     * Persists a new series 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.
     *
     * First we try to locate the parent fonds. If the parent fonds does not exist a NoarkEntityNotFoundException
     * exception is thrown. Next  we check that the fonds does not have children fonds. If it does an
     * exception is thrown.
     *
     * @param fondsSystemId
     * @param series
     * @return the newly persisted series object
     */
@Override
public Series createSeriesAssociatedWithFonds(String fondsSystemId, Series series) {
    Series persistedSeries = null;
    Fonds fonds = fondsRepository.findBySystemIdOrderBySystemId(fondsSystemId);
    if (fonds == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Fonds, using fondsSystemId " + fondsSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (fonds.getReferenceChildFonds() != null && fonds.getReferenceChildFonds().size() > 0) {
        String info = INFO_INVALID_STRUCTURE + " Cannot associate series with a fonds that has" + "children fonds " + fondsSystemId;
        logger.info(info);
        throw new NoarkInvalidStructureException(info, "Fonds", "Series");
    } else if (fonds.getFondsStatus() != null && fonds.getFondsStatus().equals(STATUS_CLOSED)) {
        String info = INFO_CANNOT_ASSOCIATE_WITH_CLOSED_OBJECT + ". Fonds with fondsSystemId " + fondsSystemId + "has status " + STATUS_CLOSED;
        logger.info(info);
        throw new NoarkEntityEditWhenClosedException(info);
    } else {
        series.setReferenceFonds(fonds);
        persistedSeries = seriesService.save(series);
    }
    return persistedSeries;
}
Also used : Series(nikita.model.noark5.v4.Series) NoarkInvalidStructureException(nikita.util.exceptions.NoarkInvalidStructureException) Fonds(nikita.model.noark5.v4.Fonds) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.util.exceptions.NoarkEntityEditWhenClosedException)

Example 3 with Series

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

the class SeriesService method createCaseFileAssociatedWithSeries.

// All CREATE operations
@Override
public CaseFile createCaseFileAssociatedWithSeries(String seriesSystemId, CaseFile caseFile) {
    CaseFile persistedFile = null;
    Series series = seriesRepository.findBySystemIdOrderBySystemId(seriesSystemId);
    if (series == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Series, using seriesSystemId " + seriesSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (series.getSeriesStatus() != null && series.getSeriesStatus().equals(STATUS_CLOSED)) {
        String info = INFO_CANNOT_ASSOCIATE_WITH_CLOSED_OBJECT + ". Series with seriesSystemId " + seriesSystemId + "has status " + STATUS_CLOSED;
        logger.info(info);
        throw new NoarkEntityEditWhenClosedException(info);
    } else {
        caseFile.setReferenceSeries(series);
        persistedFile = caseFileService.save(caseFile);
    }
    return persistedFile;
}
Also used : Series(nikita.model.noark5.v4.Series) CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.util.exceptions.NoarkEntityEditWhenClosedException)

Example 4 with Series

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

the class SeriesService method updateSeriesSetTitle.

public Series updateSeriesSetTitle(Long id, String newTitle) {
    Series series = seriesRepository.findById(id);
    if (series == null) {
    // TODO throw Object not find
    } else if (series.getSeriesStatus().equals(STATUS_CLOSED)) {
    // TODO throw Object finalises, cannot be edited
    }
    series.setTitle(newTitle);
    return seriesRepository.save(series);
}
Also used : Series(nikita.model.noark5.v4.Series)

Example 5 with Series

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

the class SeriesService method updateSeriesSetFinalized.

public Series updateSeriesSetFinalized(Long id) {
    Series series = seriesRepository.findById(id);
    if (series == null) {
    // TODO throw Object not find
    }
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    series.setSeriesStatus(STATUS_CLOSED);
    series.setFinalisedDate(new Date());
    series.setFinalisedBy(username);
    return seriesRepository.save(series);
}
Also used : Series(nikita.model.noark5.v4.Series) Date(java.util.Date)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)29 Series (nikita.model.noark5.v4.Series)20 ApiOperation (io.swagger.annotations.ApiOperation)18 ApiResponses (io.swagger.annotations.ApiResponses)18 Timed (com.codahale.metrics.annotation.Timed)16 Authorisation (nikita.webapp.security.Authorisation)13 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)13 Series (nikita.common.model.noark5.v4.Series)11 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)11 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)6 Fonds (nikita.model.noark5.v4.Fonds)6 NoarkEntityEditWhenClosedException (nikita.util.exceptions.NoarkEntityEditWhenClosedException)6 List (java.util.List)5 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)5 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 SeriesHateoas (nikita.model.noark5.v4.hateoas.SeriesHateoas)5