use of nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasController method updateDocumentObject.
// API - All PUT Requests (CRUD - UPDATE)
// Update a DocumentObject
// PUT [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}
@ApiOperation(value = "Updates a DocumentObject object", notes = "Returns the newly" + " update DocumentObject object after it is persisted to the database", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentObjectHateoas.class), @ApiResponse(code = 201, message = "DocumentObject " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentObjectHateoas.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 DocumentObject"), @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<DocumentObjectHateoas> updateDocumentObject(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of documentObject to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "documentObject", value = "Incoming documentObject object", required = true) @RequestBody DocumentObject documentObject) throws NikitaException {
validateForUpdate(documentObject);
DocumentObject updatedDocumentObject = documentObjectService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), documentObject);
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(updatedDocumentObject);
documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedDocumentObject));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedDocumentObject.getVersion().toString()).body(documentObjectHateoas);
}
use of nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject documentObjectHateoas, JsonGenerator jgen) throws IOException {
DocumentObject documentObject = (DocumentObject) noarkSystemIdEntity;
jgen.writeStartObject();
// handle DocumentObject properties
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentObject);
if (documentObject.getVersionNumber() != null) {
jgen.writeNumberField(DOCUMENT_OBJECT_VERSION_NUMBER, documentObject.getVersionNumber().intValue());
}
if (documentObject.getVariantFormat() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_VARIANT_FORMAT, documentObject.getVariantFormat());
}
if (documentObject.getFormat() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_FORMAT, documentObject.getFormat());
}
if (documentObject.getFormatDetails() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_FORMAT_DETAILS, documentObject.getFormatDetails());
}
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentObject);
if (documentObject.getReferenceDocumentFile() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE, documentObject.getReferenceDocumentFile());
}
if (documentObject.getChecksum() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_CHECKSUM, documentObject.getChecksum());
}
if (documentObject.getChecksumAlgorithm() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM, documentObject.getChecksumAlgorithm());
}
if (documentObject.getFileSize() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_FILE_SIZE, Long.toString(documentObject.getFileSize()));
}
if (documentObject.getOriginalFilename() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_FILE_NAME, documentObject.getOriginalFilename());
}
if (documentObject.getMimeType() != null) {
jgen.writeStringField(DOCUMENT_OBJECT_MIME_TYPE, documentObject.getMimeType());
}
CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentObject);
CommonUtils.Hateoas.Serialize.printConversion(jgen, documentObject);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentObjectHateoas.getLinks(documentObject));
jgen.writeEndObject();
}
use of nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectHateoasController method findAllDocumentObject.
// Get all documentObject
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/
@ApiOperation(value = "Retrieves multiple DocumentObject entities limited by ownership rights", notes = "The field skip" + "tells how many DocumentObject 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 = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject list found", response = DocumentObjectHateoas.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(method = RequestMethod.GET, produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> findAllDocumentObject(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip, @RequestParam(name = "filter", required = false) String filter) {
String reg = " ";
String[] pieces;
DocumentObjectHateoas documentObjectHateoas = null;
if (filter != null) {
pieces = filter.split(reg);
if (pieces.length == 3 && pieces[1].equalsIgnoreCase("eq")) {
pieces[2] = pieces[2].replace("\'", "");
documentObjectHateoas = new DocumentObjectHateoas((List<INikitaEntity>) (List) documentObjectService.findDocumentObjectByAnyColumn(pieces[0], pieces[2]));
}
}
if (null == documentObjectHateoas) {
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
documentObjectHateoas = new DocumentObjectHateoas((List<INikitaEntity>) (List) documentObjectService.findByOwnedBy(loggedInUser));
}
documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Aggregations