Search in sources :

Example 31 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
@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);
}
Also used : DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) DocumentObject(nikita.model.noark5.v4.DocumentObject) 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 32 with DocumentObject

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;
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 33 with DocumentObject

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;
}
Also used : DocumentObject(nikita.common.model.noark5.v4.DocumentObject)

Example 34 with DocumentObject

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;
}
Also used : DocumentObject(nikita.common.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 35 with 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();
}
Also used : DocumentObject(nikita.common.model.noark5.v4.DocumentObject)

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