Search in sources :

Example 1 with File

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

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

the class SeriesImportService 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 = fileImportService.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)

Example 3 with File

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

the class DocumentObjectHateoasController method handleFileUpload.

// API - All POST Requests (CRUD - CREATE)
// upload a file and associate it with a documentObject
// POST [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}/referanseFil
@ApiOperation(value = "Uploads a file and associates it with the documentObject identified by a systemId", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File uploaded successfully", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + REFERENCE_FILE, method = RequestMethod.POST, headers = "Accept=*/*", produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> handleFileUpload(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject you wish to associate a file with", required = true) @PathVariable("systemID") final String documentObjectSystemId) {
    try {
        DocumentObject documentObject = documentObjectService.findBySystemIdOrderBySystemId(documentObjectSystemId);
        if (documentObject == null) {
            throw new NoarkEntityNotFoundException(documentObjectSystemId);
        }
        InputStream inputStream;
        // Following will be needed for uploading file in chunks
        //String headerContentRange = request.getHeader("content-range");//Content-Range:bytes 737280-819199/845769
        // Check that content-length is set, > 0 and in agreement with the value set in documentObject
        Long contentLength = 0L;
        if (request.getHeader("content-length") == null) {
            throw new StorageException("Attempt to upload a document without content-length set. The document " + "was attempted to be associated with " + documentObject);
        }
        contentLength = (long) request.getIntHeader("content-length");
        if (contentLength < 1) {
            throw new StorageException("Attempt to upload a document with 0 or negative content-length set. " + "Actual value was (" + contentLength + "). The document  was attempted to be associated with " + documentObject);
        }
        if (null == documentObject.getFileSize()) {
            throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + "), but the value in documentObject has not been set (== null).  The " + "document was attempted to be associated with " + documentObject);
        }
        if (!contentLength.equals(documentObject.getFileSize())) {
            throw new StorageException("Attempt to upload a document with a content-length set in the header (" + contentLength + ") that is not the same as the value in documentObject (" + documentObject.getFileSize() + ").  The document was attempted to be associated with " + documentObject);
        }
        // Check that the content-type is set and in agreement with mimeType value in documentObject
        String headerContentType = request.getHeader("content-type");
        if (headerContentType == null) {
            throw new StorageException("Attempt to upload a document without content-type set. The document " + "was attempted to be associated with " + documentObject);
        }
        if (!headerContentType.equals(documentObject.getMimeType())) {
            throw new StorageException("Attempt to upload a document with a content-type set in the header (" + contentLength + ") that is not the same as the mimeType in documentObject (" + documentObject.getMimeType() + ").  The document was attempted to be associated with " + documentObject);
        }
        documentObjectService.storeAndCalculateChecksum(request.getInputStream(), documentObject);
        // We need to update the documentObject in the database as checksum and checksum algorithm are set after
        // the document has been uploaded
        documentObjectService.update(documentObject);
        DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(documentObject);
        documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
        return new ResponseEntity<>(documentObjectHateoas, HttpStatus.OK);
    } catch (IOException e) {
        throw new StorageException(e.toString());
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) InputStream(java.io.InputStream) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) DocumentObject(nikita.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) IOException(java.io.IOException) StorageException(nikita.util.exceptions.StorageException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with File

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

the class FileHateoasController method updateFile.

// API - All PUT Requests (CRUD - UPDATE)
// Update a File with given values
// PUT [contextPath][api]/arkivstruktur/mappe/{systemId}
@ApiOperation(value = "Updates a File identified by a given systemId", notes = "Returns the newly updated file", response = FileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FileHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type File"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FileHateoas> updateFile(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of file to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "File", value = "Incoming file object", required = true) @RequestBody File file) throws NikitaException {
    validateForUpdate(file);
    File updatedFile = fileService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), file);
    FileHateoas fileHateoas = new FileHateoas(updatedFile);
    fileHateoasHandler.addLinks(fileHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedFile.getVersion().toString()).body(fileHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) CaseFileHateoas(nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityUpdatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with File

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

the class RecordHateoasController method findAllDocumentDescriptionAssociatedWithRecord.

// Retrieve all DocumentDescriptions associated with a Record identified by systemId
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/dokumentbeskrivelse
@ApiOperation(value = "Retrieves a lit of DocumentDescriptions associated with a Record", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescriptionHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + DOCUMENT_DESCRIPTION, method = RequestMethod.GET)
public ResponseEntity<DocumentDescriptionHateoas> findAllDocumentDescriptionAssociatedWithRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to retrieve associated Record", required = true) @PathVariable("systemID") final String systemID) {
    Record record = recordService.findBySystemIdOrderBySystemId(systemID);
    if (record == null) {
        throw new NoarkEntityNotFoundException("Could not find File object with systemID " + systemID);
    }
    DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(new ArrayList<>(record.getReferenceDocumentDescription()));
    documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentDescriptionHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Record(nikita.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)31 ApiOperation (io.swagger.annotations.ApiOperation)23 ApiResponses (io.swagger.annotations.ApiResponses)23 Timed (com.codahale.metrics.annotation.Timed)15 File (nikita.model.noark5.v4.File)14 Authorisation (nikita.webapp.security.Authorisation)14 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)13 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)13 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)10 File (nikita.common.model.noark5.v4.File)8 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)8 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)8 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)7 List (java.util.List)5 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4