Search in sources :

Example 1 with NikitaMalformedInputDataException

use of nikita.util.exceptions.NikitaMalformedInputDataException in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordDeserializer method deserialize.

@Override
public BasicRecord deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    BasicRecord basicRecord = new BasicRecord();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(basicRecord, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        basicRecord.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            basicRecord.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The basisregistrering you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(BASIC_RECORD_ID);
    if (null != currentNode) {
        basicRecord.setRecordId(currentNode.textValue());
        objectNode.remove(BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(TITLE);
    if (null != currentNode) {
        basicRecord.setTitle(currentNode.textValue());
        objectNode.remove(TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        basicRecord.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(DESCRIPTION);
    if (null != currentNode) {
        basicRecord.setDescription(currentNode.textValue());
        objectNode.remove(DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseAuthor(basicRecord, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The basisregistrering you tried to create is malformed. The " + "following fields are not recognised as basisregistrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return basicRecord;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BasicRecord(nikita.model.noark5.v4.BasicRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 2 with NikitaMalformedInputDataException

use of nikita.util.exceptions.NikitaMalformedInputDataException in project nikita-noark5-core by HiOA-ABI.

the class ClassDeserializer method deserialize.

@Override
public Class deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Class klass = new Class();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(klass, objectNode);
    // Deserialize classId
    JsonNode currentNode = objectNode.get(CLASS_ID);
    if (null != currentNode) {
        klass.setClassId(currentNode.textValue());
        objectNode.remove(CLASS_ID);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The klasse you tried to create is malformed. The " + "following fields are not recognised as klasse fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return klass;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Class(nikita.model.noark5.v4.Class) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 3 with NikitaMalformedInputDataException

use of nikita.util.exceptions.NikitaMalformedInputDataException 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 4 with NikitaMalformedInputDataException

use of nikita.util.exceptions.NikitaMalformedInputDataException 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DocumentObject(nikita.model.noark5.v4.DocumentObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 5 with NikitaMalformedInputDataException

use of nikita.util.exceptions.NikitaMalformedInputDataException in project nikita-noark5-core by HiOA-ABI.

the class FondsCreatorDeserializer method deserialize.

@Override
public FondsCreator deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    FondsCreator fondsCreator = new FondsCreator();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseFondsCreator(fondsCreator, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkivskaper you tried to create is malformed. The " + "following fields are not recognised as arkivskaper fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return fondsCreator;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FondsCreator(nikita.model.noark5.v4.FondsCreator) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Series (nikita.model.noark5.v4.Series)3 Fonds (nikita.model.noark5.v4.Fonds)2 BasicRecord (nikita.model.noark5.v4.BasicRecord)1 Class (nikita.model.noark5.v4.Class)1 ClassificationSystem (nikita.model.noark5.v4.ClassificationSystem)1 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 File (nikita.model.noark5.v4.File)1 FondsCreator (nikita.model.noark5.v4.FondsCreator)1 Record (nikita.model.noark5.v4.Record)1 AdministrativeUnit (nikita.model.noark5.v4.admin.AdministrativeUnit)1 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)1 RegistryEntry (nikita.model.noark5.v4.casehandling.RegistryEntry)1 CorrespondencePartInternal (nikita.model.noark5.v4.casehandling.secondary.CorrespondencePartInternal)1 CorrespondencePartPerson (nikita.model.noark5.v4.casehandling.secondary.CorrespondencePartPerson)1