Search in sources :

Example 6 with RecordHateoas

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

the class RecordHateoasController method updateRecord.

// API - All PUT Requests (CRUD - UPDATE)
// Update a Record with given values
// PUT [contextPath][api]/arkivstruktur/registrering/{systemId}
@ApiOperation(value = "Updates a Record identified by a given systemId", notes = "Returns the newly updated record", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Record " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RecordHateoas.class), @ApiResponse(code = 201, message = "Record " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RecordHateoas.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 Record"), @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<RecordHateoas> updateRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of record to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "Record", value = "Incoming record object", required = true) @RequestBody Record record) throws NikitaException {
    validateForUpdate(record);
    Record updatedRecord = recordService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), record);
    RecordHateoas recordHateoas = new RecordHateoas(updatedRecord);
    recordHateoasHandler.addLinks(recordHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedRecord));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedRecord.getVersion().toString()).body(recordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Record(nikita.model.noark5.v4.Record) 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)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)5 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Record (nikita.model.noark5.v4.Record)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 ArrayList (java.util.ArrayList)2 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)2 RecordHateoas (nikita.model.noark5.v4.hateoas.RecordHateoas)2 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)2 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)2 List (java.util.List)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 NoarkEntity (nikita.model.noark5.v4.NoarkEntity)1 DocumentDescriptionHateoas (nikita.model.noark5.v4.hateoas.DocumentDescriptionHateoas)1 HateoasNoarkObject (nikita.model.noark5.v4.hateoas.HateoasNoarkObject)1 NikitaException (nikita.util.exceptions.NikitaException)1 AfterNoarkEntityUpdatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1