Search in sources :

Example 6 with NoarkEntity

use of nikita.model.noark5.v4.NoarkEntity 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
@Timed
@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.findBySystemIdOrderBySystemId(systemID);
    /*  NoarkEntity parentEntity = record.chooseParent();
        HateoasNoarkObject hateoasNoarkObject;
        if (parentEntity instanceof Series) {
            hateoasNoarkObject = new SeriesHateoas(parentEntity);
            seriesHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
        }
        else if (parentEntity instanceof File) {
            hateoasNoarkObject = new FileHateoas(parentEntity);
            fileHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
        }
        else if (parentEntity instanceof Class) {
            hateoasNoarkObject = new ClassHateoas(parentEntity);
            classHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
        }
        else {
            throw new no.arkivlab.hioa.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.model.noark5.v4.Record) AfterNoarkEntityDeletedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with NoarkEntity

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

the class CaseFileHateoasController method deleteCaseFileBySystemId.

// Delete a CaseFile identified by systemID
// DELETE [contextPath][api]/casehandling/saksmappe/{systemId}/
@ApiOperation(value = "Deletes a single CaseFile entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or CaseFile) 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
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<HateoasNoarkObject> deleteCaseFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the caseFile to delete", required = true) @PathVariable("systemID") final String systemID) {
    CaseFile caseFile = caseFileService.findBySystemIdOrderBySystemId(systemID);
    NoarkEntity parentEntity = caseFile.chooseParent();
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Series) {
        hateoasNoarkObject = new SeriesHateoas(parentEntity);
        seriesHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else // TODO: Can a casefile have a Class as parent???
    if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could not process " + request.getRequestURI());
    }
    caseFileService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, caseFile));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Series(nikita.model.noark5.v4.Series) NoarkEntity(nikita.model.noark5.v4.NoarkEntity) ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) HateoasNoarkObject(nikita.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) SeriesHateoas(nikita.model.noark5.v4.hateoas.SeriesHateoas) Class(nikita.model.noark5.v4.Class) AfterNoarkEntityDeletedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) 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)6 Timed (com.codahale.metrics.annotation.Timed)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)6 NikitaException (nikita.util.exceptions.NikitaException)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 Class (nikita.model.noark5.v4.Class)4 NoarkEntity (nikita.model.noark5.v4.NoarkEntity)3 HateoasNoarkObject (nikita.model.noark5.v4.hateoas.HateoasNoarkObject)3 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)2 Record (nikita.model.noark5.v4.Record)2 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)2 ClassificationSystem (nikita.model.noark5.v4.ClassificationSystem)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 Series (nikita.model.noark5.v4.Series)1 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)1 ClassificationSystemHateoas (nikita.model.noark5.v4.hateoas.ClassificationSystemHateoas)1 DocumentDescriptionHateoas (nikita.model.noark5.v4.hateoas.DocumentDescriptionHateoas)1 RecordHateoas (nikita.model.noark5.v4.hateoas.RecordHateoas)1