Search in sources :

Example 11 with NoarkEntityNotFoundException

use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class RecordService method getRecordOrThrow.

// 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 Record back. If there is no valid
     * Record, an exception is thrown
     *
     * @param systemID
     * @return
     */
protected Record getRecordOrThrow(@NotNull String systemID) {
    Record record = recordRepository.findBySystemIdOrderBySystemId(systemID);
    if (record == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Record, using systemId " + systemID;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return record;
}
Also used : Record(nikita.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 12 with NoarkEntityNotFoundException

use of nikita.util.exceptions.NoarkEntityNotFoundException 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 13 with NoarkEntityNotFoundException

use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class AdministrativeUnitService method getAdministrativeUnitOrThrow.

// 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 AdministrativeUnit back. If there is no valid
     * AdministrativeUnit, an exception is thrown
     *
     * @param administrativeUnitSystemId
     * @return
     */
protected AdministrativeUnit getAdministrativeUnitOrThrow(@NotNull String administrativeUnitSystemId) {
    AdministrativeUnit administrativeUnit = administrativeUnitRepository.findBySystemIdOrderBySystemId(administrativeUnitSystemId);
    if (administrativeUnit == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " AdministrativeUnit, using systemId " + administrativeUnitSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return administrativeUnit;
}
Also used : AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 14 with NoarkEntityNotFoundException

use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class CaseFileImportService method createRegistryEntryAssociatedWithCaseFile.

@Override
public RegistryEntry createRegistryEntryAssociatedWithCaseFile(String fileSystemId, RegistryEntry registryEntry) {
    RegistryEntry persistedRecord = null;
    CaseFile file = caseFileRepository.findBySystemIdOrderBySystemId(fileSystemId);
    if (file == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " CaseFile, using fileSystemId " + fileSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        registryEntry.setReferenceFile(file);
        persistedRecord = registryEntryImportService.save(registryEntry);
    }
    return persistedRecord;
}
Also used : CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

Example 15 with NoarkEntityNotFoundException

use of nikita.util.exceptions.NoarkEntityNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class FondsImportService 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 = seriesImportService.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)

Aggregations

NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)51 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)15 Counted (com.codahale.metrics.annotation.Counted)14 Timed (com.codahale.metrics.annotation.Timed)14 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Fonds (nikita.model.noark5.v4.Fonds)8 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)8 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)7 File (nikita.model.noark5.v4.File)7 Record (nikita.model.noark5.v4.Record)7 Series (nikita.model.noark5.v4.Series)7 NoarkEntityEditWhenClosedException (nikita.util.exceptions.NoarkEntityEditWhenClosedException)7 BasicRecord (nikita.model.noark5.v4.BasicRecord)5 DocumentObject (nikita.model.noark5.v4.DocumentObject)5 Class (nikita.model.noark5.v4.Class)4 ClassificationSystem (nikita.model.noark5.v4.ClassificationSystem)3 RegistryEntry (nikita.model.noark5.v4.casehandling.RegistryEntry)3 DocumentObjectHateoas (nikita.model.noark5.v4.hateoas.DocumentObjectHateoas)3 IOException (java.io.IOException)2