Search in sources :

Example 46 with NoarkEntityNotFoundException

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

the class DocumentObjectService method getDocumentObjectOrThrow.

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

Example 47 with NoarkEntityNotFoundException

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

the class RegistryEntryService method getRegistryEntryOrThrow.

/**
 * 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 RegistryEntry back. If there is no valid
 * RegistryEntry, an exception is thrown
 *
 * @param registryEntrySystemId
 * @return
 */
protected RegistryEntry getRegistryEntryOrThrow(@NotNull String registryEntrySystemId) {
    RegistryEntry registryEntry = registryEntryRepository.findBySystemId(registryEntrySystemId);
    if (registryEntry == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " RegistryEntry, using systemId " + registryEntrySystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return registryEntry;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry)

Example 48 with NoarkEntityNotFoundException

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

the class SeriesService method getSeriesOrThrow.

// Helper methods
/**
 * 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 Series back. If there is no valid
 * Series, an exception is thrown
 *
 * @param seriesSystemId
 * @return
 */
protected Series getSeriesOrThrow(@NotNull String seriesSystemId) {
    Series series = seriesRepository.findBySystemId(seriesSystemId);
    if (series == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Series, using systemId " + seriesSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return series;
}
Also used : Series(nikita.common.model.noark5.v4.Series) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 49 with NoarkEntityNotFoundException

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

the class SeriesService method createFileAssociatedWithSeries.

@Override
public File createFileAssociatedWithSeries(String seriesSystemId, File file) {
    File persistedFile = null;
    Series series = seriesRepository.findBySystemId(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 {
        file.setReferenceSeries(series);
        persistedFile = fileService.createFile(file);
    }
    return persistedFile;
}
Also used : Series(nikita.common.model.noark5.v4.Series) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) File(nikita.common.model.noark5.v4.File) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) NoarkEntityEditWhenClosedException(nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)

Example 50 with NoarkEntityNotFoundException

use of nikita.common.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.findBySystemId(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.common.model.noark5.v4.Series) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)

Aggregations

NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)55 Authorisation (nikita.webapp.security.Authorisation)13 Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 List (java.util.List)5 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)5 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)5 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 Class (nikita.common.model.noark5.v4.Class)4 File (nikita.common.model.noark5.v4.File)4 Record (nikita.common.model.noark5.v4.Record)4 BasicRecord (nikita.common.model.noark5.v4.BasicRecord)3 ClassificationSystem (nikita.common.model.noark5.v4.ClassificationSystem)3 Series (nikita.common.model.noark5.v4.Series)3 DocumentObjectHateoas (nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas)3 NoarkEntityEditWhenClosedException (nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2