use of nikita.common.model.noark5.v4.DocumentObject 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.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionService method createDocumentObjectAssociatedWithDocumentDescription.
// All CREATE operations
@Override
public DocumentObject createDocumentObjectAssociatedWithDocumentDescription(String documentDescriptionSystemId, DocumentObject documentObject) {
DocumentObject persistedDocumentObject = null;
DocumentDescription documentDescription = documentDescriptionRepository.findBySystemId(documentDescriptionSystemId);
if (documentDescription == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentDescription, using documentDescriptionSystemId " + documentDescriptionSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
documentObject.setReferenceDocumentDescription(documentDescription);
List<DocumentObject> documentObjects = documentDescription.getReferenceDocumentObject();
documentObjects.add(documentObject);
persistedDocumentObject = documentObjectService.save(documentObject);
}
return persistedDocumentObject;
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method handleUpdate.
// All UPDATE operations
@Override
public DocumentObject handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull DocumentObject incomingDocumentObject) {
DocumentObject existingDocumentObject = getDocumentObjectOrThrow(systemId);
// Here copy all the values you are allowed to copy ....
if (null != incomingDocumentObject.getFormat()) {
existingDocumentObject.setFormat(incomingDocumentObject.getFormat());
}
if (null != incomingDocumentObject.getFormatDetails()) {
existingDocumentObject.setFormatDetails(incomingDocumentObject.getFormatDetails());
}
if (null != incomingDocumentObject.getOriginalFilename()) {
existingDocumentObject.setOriginalFilename(incomingDocumentObject.getOriginalFilename());
}
if (null != incomingDocumentObject.getVariantFormat()) {
existingDocumentObject.setVariantFormat(incomingDocumentObject.getVariantFormat());
}
if (null != incomingDocumentObject.getVersionNumber()) {
existingDocumentObject.setVersionNumber(incomingDocumentObject.getVersionNumber());
}
existingDocumentObject.setVersion(version);
documentObjectRepository.save(existingDocumentObject);
return existingDocumentObject;
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method getDocumentObjectOrThrow.
// All HELPER operations
/**
* Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
* If you call this, be aware that you will only ever get a valid DocumentObject back. If there is no valid
* DocumentObject, an exception is thrown
*
* @param documentObjectSystemId
* @return
*/
protected DocumentObject getDocumentObjectOrThrow(@NotNull String documentObjectSystemId) {
DocumentObject documentObject = documentObjectRepository.findBySystemId(documentObjectSystemId);
if (documentObject == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentObject, using systemId " + documentObjectSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return documentObject;
}
use of nikita.common.model.noark5.v4.DocumentObject 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();
}
Aggregations