Search in sources :

Example 11 with DocumentObject

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 {
    StringBuilder errors = new StringBuilder();
    DocumentObject documentObject = new DocumentObject();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general DocumentObject properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentObject, objectNode, errors);
    // Deserialize versionNumber
    JsonNode currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_VERSION_NUMBER);
    if (null != currentNode) {
        documentObject.setVersionNumber(new Integer(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_VERSION_NUMBER);
    }
    // Deserialize variantFormat
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_VARIANT_FORMAT);
    if (null != currentNode) {
        documentObject.setVariantFormat(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_VARIANT_FORMAT);
    }
    // Deserialize format
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT);
    if (null != currentNode) {
        documentObject.setFormat(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT);
    }
    // Deserialize formatDetails
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT_DETAILS);
    if (null != currentNode) {
        documentObject.setFormatDetails(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FORMAT_DETAILS);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentObject, objectNode, errors);
    // Deserialize referenceDocumentFile
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    if (null != currentNode) {
        documentObject.setReferenceDocumentFile(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    }
    // Deserialize checksum
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM);
    if (null != currentNode) {
        documentObject.setChecksum(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM);
    }
    // Deserialize checksumAlgorithm
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    if (null != currentNode) {
        documentObject.setChecksumAlgorithm(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    }
    // Deserialize fileSize
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FILE_SIZE);
    if (null != currentNode) {
        documentObject.setFileSize(currentNode.asLong());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FILE_SIZE);
    }
    // Deserialize filename
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_FILE_NAME);
    if (null != currentNode) {
        documentObject.setOriginalFilename(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_FILE_NAME);
    }
    // Deserialize mimeType
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_OBJECT_MIME_TYPE);
    if (null != currentNode) {
        documentObject.setMimeType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_OBJECT_MIME_TYPE);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The dokumentobjekt you tried to create is malformed. The " + "following fields are not recognised as dokumentobjekt fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return documentObject;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 12 with DocumentObject

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

the class DocumentDescriptionHateoasController method findAllDocumentDescriptionAssociatedWithRecord.

// Retrieve all DocumentObjects associated with a DocumentDescription identified by systemId
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/dokumentobjekt
@ApiOperation(value = "Retrieves a list of DocumentObjects associated with a DocumentDescription", 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 + DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> findAllDocumentDescriptionAssociatedWithRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to retrieve associated Record", required = true) @PathVariable("systemID") final String systemID) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
    if (documentDescription == null) {
        throw new NoarkEntityNotFoundException("Could not find DocumentDescription object with systemID " + systemID);
    }
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas((List<INikitaEntity>) (List) documentDescription.getReferenceDocumentObject());
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) DocumentObjectHateoas(nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas) INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with DocumentObject

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

the class DocumentObjectHateoasController method findOneDocumentObjectBySystemId.

// API - All GET Requests (CRUD - READ)
// Get a documentObject identified by systemID
// GET [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}
@ApiOperation(value = "Retrieves a single DocumentObject entity given a systemId", response = DocumentObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", response = DocumentObject.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.GET, produces = { NOARK5_V4_CONTENT_TYPE_JSON, NOARK5_V4_CONTENT_TYPE_JSON_XML })
public ResponseEntity<DocumentObjectHateoas> findOneDocumentObjectBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject to retrieve", required = true) @PathVariable("systemID") final String documentObjectSystemId) {
    DocumentObject createdDocumentObject = documentObjectService.findBySystemId(documentObjectSystemId);
    if (createdDocumentObject == null) {
        throw new NoarkEntityNotFoundException(documentObjectSystemId);
    }
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(createdDocumentObject);
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdDocumentObject.getVersion().toString()).body(documentObjectHateoas);
}
Also used : DocumentObjectHateoas(nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(nikita.webapp.security.Authorisation) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with DocumentObject

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

the class DocumentObjectHateoasController method deleteDocumentObjectBySystemId.

// Delete a DocumentObject identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single DocumentObject entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) returned", response = HateoasNoarkObject.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<HateoasNoarkObject> deleteDocumentObjectBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject to delete", required = true) @PathVariable("systemID") final String systemID) {
    DocumentObject documentObject = documentObjectService.findBySystemId(systemID);
    NoarkEntity parentEntity = documentObject.chooseParent();
    documentObjectService.deleteEntity(systemID);
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof DocumentDescription) {
        hateoasNoarkObject = new DocumentDescriptionHateoas(parentEntity);
        documentDescriptionHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else if (parentEntity instanceof Record) {
        hateoasNoarkObject = new RecordHateoas(parentEntity);
        recordHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could process" + request.getRequestURI());
    }
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, documentObject));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) HateoasNoarkObject(nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(nikita.webapp.security.Authorisation) DocumentDescriptionHateoas(nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas) RecordHateoas(nikita.common.model.noark5.v4.hateoas.RecordHateoas) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) 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 15 with DocumentObject

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
@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, 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);
}
Also used : DocumentObjectHateoas(nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(nikita.webapp.security.Authorisation) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)20 ApiOperation (io.swagger.annotations.ApiOperation)20 ApiResponses (io.swagger.annotations.ApiResponses)20 DocumentObject (nikita.model.noark5.v4.DocumentObject)16 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)15 Timed (com.codahale.metrics.annotation.Timed)10 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 DocumentObjectHateoas (nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas)7 DocumentObjectHateoas (nikita.model.noark5.v4.hateoas.DocumentObjectHateoas)7 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)6 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)3 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2