Search in sources :

Example 1 with DocumentType

use of nikita.common.model.noark5.v4.metadata.DocumentType 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 2 with DocumentType

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

the class DocumentTypeService method findByDescription.

/**
 * Retrieve all documentType that have a given description.
 * <br>
 * Note, this will be replaced by OData search.
 *
 * @param description
 * @return A list of documentType objects wrapped as a MetadataHateoas
 * object
 */
@Override
public MetadataHateoas findByDescription(String description) {
    MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) documentTypeRepository.findByDescription(description), DOCUMENT_TYPE);
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) List(java.util.List) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 3 with DocumentType

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

the class DocumentTypeService method generateDefaultDocumentType.

/**
 * Generate a default DocumentType object
 *
 * @return the DocumentType object wrapped as a DocumentTypeHateoas object
 */
@Override
public DocumentType generateDefaultDocumentType() {
    DocumentType documentType = new DocumentType();
    documentType.setCode(TEMPLATE_DOCUMENT_TYPE_CODE);
    documentType.setDescription(TEMPLATE_DOCUMENT_TYPE_DESCRIPTION);
    return documentType;
}
Also used : DocumentType(nikita.common.model.noark5.v4.metadata.DocumentType)

Example 4 with DocumentType

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

the class DocumentTypeService method getDocumentTypeOrThrow.

/**
 * 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 DocumentType object back. If there
 * is no DocumentType object, a NoarkEntityNotFoundException exception
 * is thrown
 *
 * @param systemId The systemId of the DocumentType object to retrieve
 * @return the DocumentType object
 */
private DocumentType getDocumentTypeOrThrow(@NotNull String systemId) {
    DocumentType documentType = documentTypeRepository.findBySystemId(systemId);
    if (documentType == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " DocumentType, using " + "systemId " + systemId;
        logger.error(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return documentType;
}
Also used : DocumentType(nikita.common.model.noark5.v4.metadata.DocumentType) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 5 with DocumentType

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

the class DocumentTypeService method find.

// find by systemId
/**
 * Retrieve a single documentType object identified by systemId
 *
 * @param systemId
 * @return single documentType object wrapped as a MetadataHateoas object
 */
@Override
public MetadataHateoas find(String systemId) {
    MetadataHateoas metadataHateoas = new MetadataHateoas(documentTypeRepository.save(documentTypeRepository.findBySystemId(systemId)));
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Aggregations

MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)6 Authorisation (nikita.webapp.security.Authorisation)6 List (java.util.List)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 DocumentType (nikita.common.model.noark5.v4.metadata.DocumentType)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)1 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)1 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)1 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1