Search in sources :

Example 16 with NikitaMalformedInputDataException

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

the class CorrespondencePartUnitDeserializer method deserialize.

@Override
public CorrespondencePartUnit deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    CorrespondencePartUnit correspondencePartUnit = new CorrespondencePartUnit();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(correspondencePartUnit, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseCorrespondencePartUnitEntity(correspondencePartUnit, objectNode, errors);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The korrespondansepartenhet you tried to create is malformed. The " + "following fields are not recognised as korrespondansepartenhet fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return correspondencePartUnit;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CorrespondencePartUnit(nikita.common.model.noark5.v4.casehandling.secondary.CorrespondencePartUnit) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 17 with NikitaMalformedInputDataException

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

the class RegistryEntryDeserializer method deserialize.

@Override
public RegistryEntry deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    RegistryEntry registryEntry = new RegistryEntry();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode, errors);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        registryEntry.setArchivedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    registryEntry.setArchivedDate(CommonUtils.Hateoas.Deserialize.deserializeDateTime(N5ResourceMappings.RECORD_ARCHIVED_DATE, objectNode, errors));
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(N5ResourceMappings.BASIC_RECORD_ID);
    if (null != currentNode) {
        registryEntry.setRecordId(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(N5ResourceMappings.TITLE);
    if (null != currentNode) {
        registryEntry.setTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        registryEntry.setOfficialTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(N5ResourceMappings.DESCRIPTION);
    if (null != currentNode) {
        registryEntry.setDescription(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode, errors);
    // Deserialize general registryEntry properties
    // Deserialize recordYear
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
    if (null != currentNode) {
        registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
    }
    // Deserialize recordSequenceNumber
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
    if (null != currentNode) {
        registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
    }
    // Deserialize registryEntryNumber
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
    if (null != currentNode) {
        registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
    }
    // Deserialize registryEntryType
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
    if (null != currentNode) {
        registryEntry.setRegistryEntryType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
    } else {
        errors.append("The journalpost you tried to create is missing journalposttype. ");
    }
    // Deserialize recordStatus
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
    if (null != currentNode) {
        registryEntry.setRecordStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
    } else {
        errors.append("The journalpost you tried to create is missing journalstatus. ");
    }
    // Deserialize recordDate
    registryEntry.setRecordDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DATE, objectNode, errors, true));
    // Deserialize documentDate
    registryEntry.setDocumentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DOCUMENT_DATE, objectNode, errors));
    // Deserialize receivedDate
    registryEntry.setReceivedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECEIVED_DATE, objectNode, errors));
    // Deserialize sentDate
    registryEntry.setSentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_SENT_DATE, objectNode, errors));
    // Deserialize dueDate
    registryEntry.setDueDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DUE_DATE, objectNode, errors));
    // Deserialize freedomAssessmentDate
    registryEntry.setFreedomAssessmentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE, objectNode, errors));
    // Deserialize numberOfAttachments
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    if (null != currentNode) {
        registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    }
    // Deserialize loanedDate
    registryEntry.setLoanedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_LOANED_DATE, objectNode, errors));
    // Deserialize loanedTo
    currentNode = objectNode.get(N5ResourceMappings.CASE_LOANED_TO);
    if (null != currentNode) {
        registryEntry.setLoanedTo(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_LOANED_TO);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return registryEntry;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Aggregations

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