Search in sources :

Example 26 with Class

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

the class ClassHateoasController method deleteClassBySystemId.

// Delete a Class identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single Class 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<HateoasNoarkObject> deleteClassBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the class to delete", required = true) @PathVariable("systemID") final String systemID) {
    Class klass = classService.findBySystemIdOrderBySystemId(systemID);
    NoarkEntity parentEntity = klass.chooseParent();
    classService.deleteEntity(systemID);
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else if (parentEntity instanceof ClassificationSystem) {
        hateoasNoarkObject = new ClassificationSystemHateoas(parentEntity);
        classificationSystemHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could process" + request.getRequestURI());
    }
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, klass));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) ClassificationSystem(nikita.model.noark5.v4.ClassificationSystem) ClassificationSystemHateoas(nikita.model.noark5.v4.hateoas.ClassificationSystemHateoas) NoarkEntity(nikita.model.noark5.v4.NoarkEntity) ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) HateoasNoarkObject(nikita.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) 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)

Example 27 with Class

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

the class ClassHateoasController method updateClass.

// API - All PUT Requests (CRUD - UPDATE)
// Update a Class
// PUT [contextPath][api]/arkivstruktur/basisregistrering/{systemID}
@ApiOperation(value = "Updates a Class object", notes = "Returns the newly" + " update Class object after it is persisted to the database", response = ClassHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Class " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = ClassHateoas.class), @ApiResponse(code = 201, message = "Class " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = ClassHateoas.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 Class"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<ClassHateoas> updateClass(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of class to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "class", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    validateForUpdate(klass);
    Class updatedClass = classService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), klass);
    ClassHateoas classHateoas = new ClassHateoas(updatedClass);
    classHateoasHandler.addLinks(classHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedClass));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedClass.getVersion().toString()).body(classHateoas);
}
Also used : ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) 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 28 with Class

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

the class ClassificationSystemHateoasController method createClassAssociatedWithClassificationSystem.

@ApiOperation(value = "Persists a Class object associated with the given ClassificationSystem systemId", notes = "Returns the newly created class object after it was associated with a classificationSystem " + "object and persisted to the database", response = ClassHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Class " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = Class.class), @ApiResponse(code = 201, message = "Class " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = Class.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 Class"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.POST, value = CLASSIFICATION_SYSTEM + SLASH + LEFT_PARENTHESIS + "classificationSystemSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_RECORD, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<ClassHateoas> createClassAssociatedWithClassificationSystem(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "classificationSystemSystemId", value = "systemId of classificationSystem to associate the klass with.", required = true) @PathVariable String classificationSystemSystemId, @ApiParam(name = "klass", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    Class createdClass = classificationSystemService.createClassAssociatedWithClassificationSystem(classificationSystemSystemId, klass);
    ClassHateoas classHateoas = new ClassHateoas(createdClass);
    classHateoasHandler.addLinks(classHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdClass));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdClass.getVersion().toString()).body(classHateoas);
}
Also used : ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) AfterNoarkEntityCreatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 29 with Class

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

the class FileHateoasController method deleteFileBySystemId.

// Delete a File identified by systemID
// DELETE [contextPath][api]/arkivstruktur/mappe/{systemId}/
@ApiOperation(value = "Deletes a single File entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or File) 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> deleteFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to delete", required = true) @PathVariable("systemID") final String systemID) {
    File file = fileService.findBySystemIdOrderBySystemId(systemID);
    NoarkEntity parentEntity = file.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 NikitaException("Internal error. Could not process" + request.getRequestURI());
    }
    fileService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, file));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) CaseFileHateoas(nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) 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 30 with Class

use of nikita.common.model.noark5.v4.Class 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)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)18 ApiOperation (io.swagger.annotations.ApiOperation)18 ApiResponses (io.swagger.annotations.ApiResponses)18 Class (nikita.model.noark5.v4.Class)17 Class (nikita.common.model.noark5.v4.Class)16 Timed (com.codahale.metrics.annotation.Timed)9 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)7 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)7 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NikitaException (nikita.common.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)4 NikitaException (nikita.util.exceptions.NikitaException)4 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)4 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2