Search in sources :

Example 16 with File

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

the class FileService method updateFileSetFinalized.

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

Example 17 with File

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

the class FileService method getFileOrThrow.

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

Example 18 with File

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

the class FileService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String fileSystemId) {
    File file = getFileOrThrow(fileSystemId);
    fileRepository.delete(file);
}
Also used : File(nikita.model.noark5.v4.File)

Example 19 with File

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

the class FileService method handleUpdate.

// All UPDATE operations
@Override
public File handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull File incomingFile) {
    File existingFile = getFileOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    if (null != existingFile.getDescription()) {
        existingFile.setDescription(incomingFile.getDescription());
    }
    if (null != existingFile.getTitle()) {
        existingFile.setTitle(incomingFile.getTitle());
    }
    if (null != existingFile.getDocumentMedium()) {
        existingFile.setDocumentMedium(existingFile.getDocumentMedium());
    }
    existingFile.setVersion(version);
    fileRepository.save(existingFile);
    return existingFile;
}
Also used : File(nikita.model.noark5.v4.File)

Example 20 with File

use of nikita.model.noark5.v4.File 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.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 {
        file.setReferenceSeries(series);
        persistedFile = fileService.createFile(file);
    }
    return persistedFile;
}
Also used : Series(nikita.model.noark5.v4.Series) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) File(nikita.model.noark5.v4.File) CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) NoarkEntityEditWhenClosedException(nikita.util.exceptions.NoarkEntityEditWhenClosedException)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)15 Timed (com.codahale.metrics.annotation.Timed)15 File (nikita.model.noark5.v4.File)14 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)13 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)13 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)8 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)7 BasicRecord (nikita.model.noark5.v4.BasicRecord)4 Record (nikita.model.noark5.v4.Record)4 Series (nikita.model.noark5.v4.Series)4 Date (java.util.Date)3 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)3 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Class (nikita.model.noark5.v4.Class)2