Search in sources :

Example 46 with NoarkEntityNotFoundException

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

the class DocumentDescriptionHateoasController method findAllDocumentDescriptionAssociatedWithRecord.

// Retrieve all DocumentObjects associated with a DocumentDescription identified by systemId
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/dokumentobjekt
@ApiOperation(value = "Retrieves a list of DocumentObjects associated with a DocumentDescription", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", 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 + DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> 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) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemIdOrderBySystemId(systemID);
    if (documentDescription == null) {
        throw new NoarkEntityNotFoundException("Could not find DocumentDescription object with systemID " + systemID);
    }
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(new ArrayList<>(documentDescription.getReferenceDocumentObject()));
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) 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)

Example 47 with NoarkEntityNotFoundException

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

the class DocumentObjectHateoasController method handleFileDownload.

// Get a file identified by systemID retrievable with referanseFile
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}/referanseFil
@ApiOperation(value = "Downloads a file associated 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.GET)
public void handleFileDownload(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject that has a file associated with it", required = true) @PathVariable("systemID") final String documentObjectSystemId) throws IOException {
    DocumentObject documentObject = documentObjectService.findBySystemIdOrderBySystemId(documentObjectSystemId);
    if (documentObject == null) {
        throw new NoarkEntityNotFoundException(documentObjectSystemId);
    }
    Resource fileResource = documentObjectService.loadAsResource(documentObject);
    String acceptType = request.getHeader(HttpHeaders.ACCEPT);
    if (acceptType != null && !acceptType.equalsIgnoreCase(documentObject.getMimeType())) {
        if (!acceptType.equals("*/*")) {
            throw new NoarkNotAcceptableException("The request [" + request.getRequestURI() + "] is not acceptable. " + "You have issued an Accept: " + acceptType + ", while the mimeType you are trying to retrieve " + "is [" + documentObject.getMimeType() + "].");
        }
    }
    response.setContentType(documentObject.getMimeType());
    response.setContentLength(documentObject.getFileSize().intValue());
    response.addHeader("Content-disposition", "inline; filename=" + documentObject.getOriginalFilename());
    response.addHeader("Content-Type", documentObject.getMimeType());
    InputStream filestream = fileResource.getInputStream();
    try {
        long bytesTotal = IOUtils.copyLarge(filestream, response.getOutputStream());
        filestream.close();
    } finally {
        try {
            // Try close without exceptions if copy() threw an
            // exception.  If close() is called twice, the second
            // close() should be ignored.
            filestream.close();
        } catch (IOException e) {
        // swallow any error to expose exceptions from
        // IOUtil.copy() if the second close() failed.
        }
    }
    response.flushBuffer();
}
Also used : InputStream(java.io.InputStream) NoarkNotAcceptableException(nikita.util.exceptions.NoarkNotAcceptableException) Resource(org.springframework.core.io.Resource) DocumentObject(nikita.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) IOException(java.io.IOException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 48 with NoarkEntityNotFoundException

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

the class FondsCreatorHateoasController method findOne.

// API - All GET Requests (CRUD - READ)
// Get a FondsCreator identified by a systemId
// GET [contextPath][api]/arkivstruktur/arkivskaper/{systemId}
@ApiOperation(value = "Retrieves a single FondsCreator entity given a systemId", response = FondsCreator.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator returned", response = FondsCreator.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 = FONDS_CREATOR + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<FondsCreatorHateoas> findOne(HttpServletRequest request, @ApiParam(name = "systemId", value = "systemId of FondsCreator to retrieve.", required = true) @PathVariable("systemID") final String fondsCreatorSystemId) {
    FondsCreator fondsCreator = fondsCreatorService.findBySystemIdOrderBySystemId(fondsCreatorSystemId);
    if (fondsCreator == null) {
        throw new NoarkEntityNotFoundException("Could not find FondsCreator object with systemID " + fondsCreatorSystemId);
    }
    FondsCreatorHateoas fondsCreatorHateoas = new FondsCreatorHateoas(fondsCreator);
    fondsCreatorHateoasHandler.addLinks(fondsCreatorHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreator.getVersion().toString()).body(fondsCreatorHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) FondsCreatorHateoas(nikita.model.noark5.v4.hateoas.FondsCreatorHateoas) FondsCreator(nikita.model.noark5.v4.FondsCreator) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 49 with NoarkEntityNotFoundException

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

the class FondsHateoasController method findOne.

// API - All GET Requests (CRUD - READ)
// Get single fonds identified by systemId
// GET [contextPath][api]/arkivstruktur/arkiv/{systemId}/
@ApiOperation(value = "Retrieves a single fonds entity given a systemId", response = Fonds.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fonds returned", response = Fonds.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 = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
@SuppressWarnings("unchecked")
public ResponseEntity<FondsHateoas> findOne(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of fonds to retrieve.", required = true) @PathVariable("systemID") final String systemID) {
    Fonds fonds = fondsService.findBySystemIdOrderBySystemId(systemID);
    if (fonds == null) {
        throw new NoarkEntityNotFoundException("Could not find fonds object with systemID " + systemID);
    }
    FondsHateoas fondsHateoas = new FondsHateoas(fonds);
    fondsHateoasHandler.addLinks(fondsHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fonds.getVersion().toString()).body(fondsHateoas);
}
Also used : FondsHateoas(nikita.model.noark5.v4.hateoas.FondsHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Fonds(nikita.model.noark5.v4.Fonds) 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)

Example 50 with NoarkEntityNotFoundException

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

the class SeriesHateoasController method findOneSeriesbySystemId.

// API - All GET Requests (CRUD - READ)
// Retrieve a Series given a systemId
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/
@ApiOperation(value = "Retrieves a single Series entity given a systemId", response = Series.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Series returned", response = Series.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, method = RequestMethod.GET)
public ResponseEntity<SeriesHateoas> findOneSeriesbySystemId(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemID of the series to retrieve", required = true) @PathVariable("systemID") final String systemID) {
    Series series = seriesService.findBySystemIdOrderBySystemId(systemID);
    if (series == null) {
        throw new NoarkEntityNotFoundException("Could not find series object with systemID " + systemID);
    }
    SeriesHateoas seriesHateoas = new SeriesHateoas(series);
    seriesHateoasHandler.addLinks(seriesHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(series.getVersion().toString()).body(seriesHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed)

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