Search in sources :

Example 6 with DocumentDescription

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

the class RecordHateoasController method createDefaultDocumentDescription.

// Create a DocumentDescription with default values
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/ny-dokumentbeskrivelse
@ApiOperation(value = "Create a DocumentDescription with default values", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescriptionHateoas.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
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_DOCUMENT_DESCRIPTION, method = RequestMethod.GET)
public ResponseEntity<DocumentDescriptionHateoas> createDefaultDocumentDescription(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
    DocumentDescription defaultDocumentDescription = new DocumentDescription();
    defaultDocumentDescription.setAssociatedWithRecordAs(MAIN_DOCUMENT);
    defaultDocumentDescription.setTitle(TEST_TITLE);
    defaultDocumentDescription.setDocumentType(LETTER);
    defaultDocumentDescription.setDocumentStatus(DOCUMENT_STATUS_FINALISED);
    defaultDocumentDescription.setDescription(TEST_DESCRIPTION);
    DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(defaultDocumentDescription);
    documentDescriptionHateoasHandler.addLinksOnNew(documentDescriptionHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentDescriptionHateoas);
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with DocumentDescription

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

the class RecordHateoasController method findAllDocumentDescriptionAssociatedWithRecord.

// Retrieve all DocumentDescriptions associated with a Record identified by systemId
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/dokumentbeskrivelse
@ApiOperation(value = "Retrieves a lit of DocumentDescriptions associated with a Record", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription returned", response = DocumentDescriptionHateoas.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
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + DOCUMENT_DESCRIPTION, method = RequestMethod.GET)
public ResponseEntity<DocumentDescriptionHateoas> 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) {
    Record record = recordService.findBySystemIdOrderBySystemId(systemID);
    if (record == null) {
        throw new NoarkEntityNotFoundException("Could not find File object with systemID " + systemID);
    }
    DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(new ArrayList<>(record.getReferenceDocumentDescription()));
    documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentDescriptionHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Record(nikita.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with DocumentDescription

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

the class DocumentDescriptionDeserializer method deserialize.

@Override
public DocumentDescription deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    DocumentDescription documentDescription = new DocumentDescription();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode);
    // Deserialize documentType
    JsonNode currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    if (null != currentNode) {
        documentDescription.setDocumentType(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    }
    // Deserialize documentStatus
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_STATUS);
    if (null != currentNode) {
        documentDescription.setDocumentStatus(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_STATUS);
    }
    // Deserialize associatedWithRecordAs
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    if (null != currentNode) {
        documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    }
    // Deserialize documentNumber
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    if (null != currentNode) {
        documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    }
    // Deserialize associationDate
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            documentDescription.setAssociationDate(parsedDate);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create " + "has a malformed tilknyttetDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    }
    // Deserialize associatedBy
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    if (null != currentNode) {
        documentDescription.setAssociatedBy(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    }
    // Deserialize storageLocation
    currentNode = objectNode.get(STORAGE_LOCATION);
    if (null != currentNode) {
        documentDescription.setStorageLocation(currentNode.textValue());
        objectNode.remove(STORAGE_LOCATION);
    }
    // Deserialize general documentDescription properties
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return documentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 9 with DocumentDescription

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

the class DocumentDescriptionHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkEntity, HateoasNoarkObject documentDescriptionHateoas, JsonGenerator jgen) throws IOException {
    DocumentDescription documentDescription = (DocumentDescription) noarkEntity;
    jgen.writeStartObject();
    // handle DocumentDescription properties
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentDescription);
    if (documentDescription.getDocumentType() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE, documentDescription.getDocumentType());
    }
    if (documentDescription.getDocumentStatus() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_STATUS, documentDescription.getDocumentStatus());
    }
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, documentDescription);
    if (documentDescription.getDocumentNumber() != null) {
        jgen.writeNumberField(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER, documentDescription.getDocumentNumber().intValue());
    }
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentDescription);
    if (documentDescription.getAssociationDate() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, Serialize.formatDate(documentDescription.getAssociationDate()));
    }
    if (documentDescription.getAssociatedWithRecordAs() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS, documentDescription.getAssociatedWithRecordAs());
    }
    CommonUtils.Hateoas.Serialize.printComment(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposalUndertaken(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDeletion(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, documentDescription);
    if (documentDescription.getStorageLocation() != null) {
        jgen.writeStringField(STORAGE_LOCATION, documentDescription.getStorageLocation());
    }
    CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentDescriptionHateoas.getLinks(documentDescription));
    jgen.writeEndObject();
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription)

Example 10 with DocumentDescription

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

the class DocumentDescriptionService method handleUpdate.

// All UPDATE operations
@Override
public DocumentDescription handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull DocumentDescription incomingDocumentDescription) {
    DocumentDescription existingDocumentDescription = getDocumentDescriptionOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingDocumentDescription.getDescription()) {
        existingDocumentDescription.setDescription(incomingDocumentDescription.getDescription());
    }
    if (null != incomingDocumentDescription.getTitle()) {
        existingDocumentDescription.setTitle(incomingDocumentDescription.getTitle());
    }
    if (null != incomingDocumentDescription.getDocumentMedium()) {
        existingDocumentDescription.setDocumentMedium(existingDocumentDescription.getDocumentMedium());
    }
    if (null != incomingDocumentDescription.getAssociatedWithRecordAs()) {
        existingDocumentDescription.setAssociatedWithRecordAs(incomingDocumentDescription.getAssociatedWithRecordAs());
    }
    if (null != incomingDocumentDescription.getDocumentNumber()) {
        existingDocumentDescription.setDocumentNumber(incomingDocumentDescription.getDocumentNumber());
    }
    existingDocumentDescription.setVersion(version);
    documentDescriptionRepository.save(existingDocumentDescription);
    return existingDocumentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)34 ApiOperation (io.swagger.annotations.ApiOperation)34 ApiResponses (io.swagger.annotations.ApiResponses)34 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)18 Timed (com.codahale.metrics.annotation.Timed)17 Authorisation (nikita.webapp.security.Authorisation)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)15 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)14 Record (nikita.model.noark5.v4.Record)8 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)8 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)7 ArrayList (java.util.ArrayList)6 Record (nikita.common.model.noark5.v4.Record)6 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)6 NikitaException (nikita.common.util.exceptions.NikitaException)5 NikitaException (nikita.util.exceptions.NikitaException)5 List (java.util.List)4 Class (nikita.common.model.noark5.v4.Class)4 DocumentDescriptionHateoas (nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas)4