Search in sources :

Example 6 with RecordHateoas

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

the class RecordHateoasController method findOneRecordbySystemId.

// API - All GET Requests (CRUD - READ)
// Retrieve a Record identified by a systemId
// GET [contextPath][api]/arkivstruktur/registrering/{systemId}
// http://rel.kxml.no/noark5/v4/api/arkivstruktur/registrering/
@ApiOperation(value = "Retrieves a single Record entity given a systemId", response = Record.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Record returned", response = Record.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<RecordHateoas> findOneRecordbySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the record to retrieve", required = true) @PathVariable("systemID") final String systemID) {
    Record record = recordService.findBySystemIdOrderBySystemId(systemID);
    RecordHateoas recordHateoas = new RecordHateoas(record);
    recordHateoasHandler.addLinks(recordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(record.getVersion().toString()).body(recordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Record(nikita.model.noark5.v4.Record) 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 RecordHateoas

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

the class RecordHateoasController method findAllRecord.

// Retrieve all Records
// GET [contextPath][api]/arkivstruktur/registrering
// http://rel.kxml.no/noark5/v4/api/arkivstruktur/registrering/
@ApiOperation(value = "Retrieves multiple Record entities limited by ownership rights", notes = "The field skip tells how many Record rows of the result set to ignore (starting at 0), " + "while top tells how many rows after skip to return. Note if the value of top is greater than " + "system value nikita-noark5-core.pagination.maxPageSize, then " + "nikita-noark5-core.pagination.maxPageSize is used.", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RecordHateoas found", 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
@Timed
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<RecordHateoas> findAllRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
    RecordHateoas recordHateoas = new RecordHateoas((ArrayList<INikitaEntity>) (ArrayList) recordService.findRecordByOwnerPaginated(top, skip));
    recordHateoasHandler.addLinks(recordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : INikitaEntity(nikita.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with RecordHateoas

use of nikita.common.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)

Example 9 with RecordHateoas

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

the class DocumentDescriptionHateoasController method deleteDocumentDescriptionBySystemId.

// Delete a DocumentDescription identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single DocumentDescription entity identified by systemID", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent Fonds 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, method = RequestMethod.DELETE)
public ResponseEntity<RecordHateoas> deleteDocumentDescriptionBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentDescription to delete", required = true) @PathVariable("systemID") final String systemID) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
    List<Record> record = new ArrayList<>();
    record.addAll(documentDescription.getReferenceRecord());
    documentDescriptionService.deleteEntity(systemID);
    RecordHateoas recordHateoas = new RecordHateoas((List) record);
    /*RecordHateoas recordHateoas = new RecordHateoas(
                (List<INikitaEntity>)
                        (List)record); */
    // RecordHateoas recordHateoas = new RecordHateoas(
    // (List<INikitaEntity>) (List)record);
    recordHateoasHandler.addLinks(recordHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, documentDescription));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Authorisation(nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) RecordHateoas(nikita.common.model.noark5.v4.hateoas.RecordHateoas) 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 10 with RecordHateoas

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

the class RecordHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject recordHateoas, JsonGenerator jgen) throws IOException {
    Record record = (Record) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, record);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, record);
    if (record.getArchivedDate() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_DATE, Serialize.formatDateTime(record.getArchivedDate()));
    }
    if (record.getArchivedBy() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_BY, record.getArchivedBy());
    }
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, record);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, record);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, record);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, recordHateoas.getLinks(record));
    jgen.writeEndObject();
}
Also used : Record(nikita.common.model.noark5.v4.Record)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 Authorisation (nikita.webapp.security.Authorisation)7 Timed (com.codahale.metrics.annotation.Timed)5 Record (nikita.common.model.noark5.v4.Record)5 Record (nikita.model.noark5.v4.Record)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 List (java.util.List)4 ArrayList (java.util.ArrayList)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)2 RecordHateoas (nikita.common.model.noark5.v4.hateoas.RecordHateoas)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 (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)2 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)2 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)1 NoarkEntity (nikita.common.model.noark5.v4.NoarkEntity)1