Search in sources :

Example 51 with File

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

the class FileHateoasController method findAllRecordsAssociatedWithFile.

// API - All GET Requests (CRUD - READ)
// Retrieve all Records associated with File identified by systemId
// GET [contextPath][api]/arkivstruktur/mappe/{systemId}/registrering
// REL http://rel.kxml.no/noark5/v4/api/arkivstruktur/registrering/
@ApiOperation(value = "Retrieve all Record associated with a File identified by systemId", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Record returned", response = RecordHateoas.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + REGISTRATION, method = RequestMethod.GET)
public ResponseEntity<RecordHateoas> findAllRecordsAssociatedWithFile(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) {
    File file = fileService.findBySystemId(systemID);
    if (file == null) {
        throw new NoarkEntityNotFoundException("Could not find File object with systemID " + systemID);
    }
    RecordHateoas recordHateoas = new RecordHateoas((List<INikitaEntity>) (List) file.getReferenceRecord());
    recordHateoasHandler.addLinks(recordHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) List(java.util.List) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 52 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
@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, 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(nikita.webapp.security.Authorisation) CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 53 with File

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

the class RecordHateoasController method deleteRecordBySystemId.

// Delete a Record identified by systemID
// DELETE [contextPath][api]/arkivstruktur/registrering/{systemId}/
@ApiOperation(value = "Deletes a single Record entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) returned", response = HateoasNoarkObject.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<String> deleteRecordBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the record to delete", required = true) @PathVariable("systemID") final String systemID) {
    Record record = recordService.findBySystemId(systemID);
    /*  NoarkEntity parentEntity = record.chooseParent();
        HateoasNoarkObject hateoasNoarkObject;
        if (parentEntity instanceof Series) {
            hateoasNoarkObject = new SeriesHateoas(parentEntity);
            seriesHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
        }
        else if (parentEntity instanceof File) {
            hateoasNoarkObject = new FileHateoas(parentEntity);
            fileHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
        }
        else if (parentEntity instanceof Class) {
            hateoasNoarkObject = new ClassHateoas(parentEntity);
            classHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
        }
        else {
            throw new nikita.webapp.util.exceptions.NikitaException("Internal error. Could not process"
                    + request.getRequestURI());
        } */
    recordService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, record));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("{\"status\": \"deleted\"}");
}
Also used : Record(nikita.common.model.noark5.v4.Record) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 54 with File

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

the class SeriesHateoasController method createCaseFileAssociatedWithSeries.

// Create a new casefile
// POST [contextPath][api]/arkivstruktur/arkivdel/{systemId}/ny-saksmappe/
// This currently is not supported in the standard, but probably will be later
@ApiOperation(value = "Persists a CaseFile object associated with the given Series systemId", notes = "Returns " + "the newly created caseFile object after it was associated with a Series object and persisted to " + "the database", response = CaseFileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CaseFileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = CaseFileHateoas.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 CaseFile"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CASE_FILE, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<CaseFileHateoas> createCaseFileAssociatedWithSeries(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of series to associate the caseFile with", required = true) @PathVariable String systemID, @ApiParam(name = "caseFile", value = "Incoming caseFile object", required = true) @RequestBody CaseFile caseFile) throws NikitaException {
    validateForCreate(caseFile);
    CaseFile createdCaseFile = seriesService.createCaseFileAssociatedWithSeries(systemID, caseFile);
    CaseFileHateoas caseFileHateoas = new CaseFileHateoas(createdCaseFile);
    caseFileHateoasHandler.addLinks(caseFileHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdCaseFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdCaseFile.getVersion().toString()).body(caseFileHateoas);
}
Also used : CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) Authorisation(nikita.webapp.security.Authorisation) Counted(com.codahale.metrics.annotation.Counted)

Example 55 with File

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

the class SeriesHateoasController method createDefaultFile.

// Create a File object with default values
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/ny-mappe/
@ApiOperation(value = "Create a File with default values", response = File.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File returned", response = File.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FILE, method = RequestMethod.GET)
public ResponseEntity<FileHateoas> createDefaultFile(HttpServletRequest request, final HttpServletResponse response) {
    File defaultFile = new File();
    defaultFile = setFileDefaults(defaultFile);
    FileHateoas fileHateoas = new FileHateoas(defaultFile);
    fileHateoasHandler.addLinksOnNew(fileHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(fileHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) Counted(com.codahale.metrics.annotation.Counted)

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