use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectDeserializer method deserialize.
@Override
public DocumentObject deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
DocumentObject documentObject = new DocumentObject();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general DocumentObject properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentObject, objectNode);
// Deserialize versionNumber
JsonNode currentNode = objectNode.get(DOCUMENT_OBJECT_VERSION_NUMBER);
if (null != currentNode) {
documentObject.setVersionNumber(new Integer(currentNode.intValue()));
objectNode.remove(DOCUMENT_OBJECT_VERSION_NUMBER);
}
// Deserialize variantFormat
currentNode = objectNode.get(DOCUMENT_OBJECT_VARIANT_FORMAT);
if (null != currentNode) {
documentObject.setVariantFormat(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_VARIANT_FORMAT);
}
// Deserialize format
currentNode = objectNode.get(DOCUMENT_OBJECT_FORMAT);
if (null != currentNode) {
documentObject.setFormat(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_FORMAT);
}
// Deserialize formatDetails
currentNode = objectNode.get(DOCUMENT_OBJECT_FORMAT_DETAILS);
if (null != currentNode) {
documentObject.setFormatDetails(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_FORMAT_DETAILS);
}
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentObject, objectNode);
// Deserialize referenceDocumentFile
currentNode = objectNode.get(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
if (null != currentNode) {
documentObject.setReferenceDocumentFile(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
}
// Deserialize checksum
currentNode = objectNode.get(DOCUMENT_OBJECT_CHECKSUM);
if (null != currentNode) {
documentObject.setChecksum(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_CHECKSUM);
}
// Deserialize checksumAlgorithm
currentNode = objectNode.get(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
if (null != currentNode) {
documentObject.setChecksumAlgorithm(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
}
// Deserialize fileSize
currentNode = objectNode.get(DOCUMENT_OBJECT_FILE_SIZE);
if (null != currentNode) {
documentObject.setFileSize(currentNode.asLong());
objectNode.remove(DOCUMENT_OBJECT_FILE_SIZE);
}
// Deserialize filename
currentNode = objectNode.get(DOCUMENT_OBJECT_FILE_NAME);
if (null != currentNode) {
documentObject.setOriginalFilename(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_FILE_NAME);
}
// Deserialize mimeType
currentNode = objectNode.get(DOCUMENT_OBJECT_MIME_TYPE);
if (null != currentNode) {
documentObject.setMimeType(currentNode.textValue());
objectNode.remove(DOCUMENT_OBJECT_MIME_TYPE);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The dokumentobjekt you tried to create is malformed. The " + "following fields are not recognised as dokumentobjekt fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
return documentObject;
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method createDefaultDocumentObject.
// Create a DocumentObject with default values
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/ny-dokumentobjekt
@ApiOperation(value = "Create a DocumentObject with default values", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", 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(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> createDefaultDocumentObject(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
DocumentObject defaultDocumentObject = new DocumentObject();
// This is just temporary code as this will have to be replaced if this ever goes into production
defaultDocumentObject.setMimeType(MediaType.APPLICATION_XML.toString());
defaultDocumentObject.setVariantFormat(PRODUCTION_VERSION);
defaultDocumentObject.setFormat("XML");
defaultDocumentObject.setVersionNumber(1);
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(defaultDocumentObject);
documentObjectHateoasHandler.addLinksOnNew(documentObjectHateoas, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method createDocumentObjectAssociatedWithDocumentDescription.
// API - All POST Requests (CRUD - CREATE)
@ApiOperation(value = "Persists a DocumentObject object associated with the given DocumentDescription systemId", notes = "Returns the newly created documentObject after it was associated with a DocumentDescription" + " object and persisted to the database", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentDescriptionHateoas.class), @ApiResponse(code = 201, message = "DocumentObject " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentDescriptionHateoas.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
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_DOCUMENT_OBJECT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<DocumentObjectHateoas> createDocumentObjectAssociatedWithDocumentDescription(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of documentDescription to associate the documentObject with.", required = true) @PathVariable String systemID, @ApiParam(name = "documentObject", value = "Incoming documentObject object", required = true) @RequestBody DocumentObject documentObject) throws NikitaException {
DocumentObject createdDocumentObject = documentDescriptionService.createDocumentObjectAssociatedWithDocumentDescription(systemID, documentObject);
DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(documentObject);
documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdDocumentObject));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdDocumentObject.getVersion().toString()).body(documentObjectHateoas);
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method findDocumentObjectByAnyColumn.
// All READ operations
@Override
public List<DocumentObject> findDocumentObjectByAnyColumn(String column, String value) {
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<DocumentObject> criteriaQuery = criteriaBuilder.createQuery(DocumentObject.class);
Root<DocumentObject> from = criteriaQuery.from(DocumentObject.class);
CriteriaQuery<DocumentObject> select = criteriaQuery.select(from);
if (column.equalsIgnoreCase(DOCUMENT_OBJECT_FILE_NAME)) {
column = "originalFilename";
}
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
criteriaQuery.where(criteriaBuilder.equal(from.get(column), value));
TypedQuery<DocumentObject> typedQuery = entityManager.createQuery(select);
return typedQuery.getResultList();
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method deleteEntity.
// All DELETE operations
@Override
public void deleteEntity(@NotNull String documentObjectSystemId) {
DocumentObject documentObject = getDocumentObjectOrThrow(documentObjectSystemId);
documentObjectRepository.delete(documentObject);
}
Aggregations