Search in sources :

Example 11 with NikitaMalformedInputDataException

use of nikita.common.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 {
    StringBuilder errors = new StringBuilder();
    BasicRecord basicRecord = new BasicRecord();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(basicRecord, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(basicRecord, objectNode, errors);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        basicRecord.setArchivedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    basicRecord.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) {
        basicRecord.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) {
        basicRecord.setTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        basicRecord.setOfficialTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(N5ResourceMappings.DESCRIPTION);
    if (null != currentNode) {
        basicRecord.setDescription(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(basicRecord, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseAuthor(basicRecord, objectNode, errors);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The basisregistrering you tried to create is malformed. The " + "following fields are not recognised as basisregistrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return basicRecord;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BasicRecord(nikita.common.model.noark5.v4.BasicRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 12 with NikitaMalformedInputDataException

use of nikita.common.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 {
    StringBuilder errors = new StringBuilder();
    Class klass = new Class();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(klass, objectNode, errors);
    // Deserialize classId
    JsonNode currentNode = objectNode.get(N5ResourceMappings.CLASS_ID);
    if (null != currentNode) {
        klass.setClassId(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CLASS_ID);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The klasse you tried to create is malformed. The " + "following fields are not recognised as klasse fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return klass;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Class(nikita.common.model.noark5.v4.Class) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 13 with NikitaMalformedInputDataException

use of nikita.common.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 {
    StringBuilder errors = new StringBuilder();
    DocumentDescription documentDescription = new DocumentDescription();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode, errors);
    // Deserialize documentType
    JsonNode currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    if (null != currentNode) {
        documentDescription.setDocumentType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    }
    // Deserialize documentStatus
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_STATUS);
    if (null != currentNode) {
        documentDescription.setDocumentStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_STATUS);
    }
    // Deserialize associatedWithRecordAs
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    if (null != currentNode) {
        documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    }
    // Deserialize documentNumber
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    if (null != currentNode) {
        documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    }
    // Deserialize associationDate
    documentDescription.setAssociationDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, objectNode, errors));
    // Deserialize associatedBy
    currentNode = objectNode.get(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    if (null != currentNode) {
        documentDescription.setAssociatedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    }
    // Deserialize storageLocation
    currentNode = objectNode.get(N5ResourceMappings.STORAGE_LOCATION);
    if (null != currentNode) {
        documentDescription.setStorageLocation(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.STORAGE_LOCATION);
    }
    // Deserialize general documentDescription properties
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode, errors);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return documentDescription;
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 14 with NikitaMalformedInputDataException

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

the class FondsDeserializer method deserialize.

@Override
public Fonds deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    Fonds fonds = new Fonds();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // TODO : Are we deserialising parent? No, it's not done here or is it????
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(fonds, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode, errors);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(N5ResourceMappings.FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.common.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 15 with NikitaMalformedInputDataException

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

the class RecordDeserializer method deserialize.

@Override
public Record deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    Record record = new Record();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(record, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(record, objectNode, errors);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
    if (currentNode != null) {
        record.setArchivedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    record.setArchivedDate(CommonUtils.Hateoas.Deserialize.deserializeDateTime(N5ResourceMappings.RECORD_ARCHIVED_DATE, objectNode, errors));
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The registrering you tried to create is malformed. The " + "following fields are not recognised as registrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return record;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Record(nikita.common.model.noark5.v4.Record) JsonNode(com.fasterxml.jackson.databind.JsonNode) 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