Search in sources :

Example 6 with NikitaMalformedInputDataException

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

the class AdministrativeUnitDeserializer method deserialize.

@Override
public AdministrativeUnit deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    AdministrativeUnit administrativeUnit = new AdministrativeUnit();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(administrativeUnit, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(administrativeUnit, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkFinaliseEntity(administrativeUnit, objectNode, errors);
    // Deserialize administrativeUnitStatus
    JsonNode currentNode = objectNode.get(N5ResourceMappings.ADMINISTRATIVE_UNIT_STATUS);
    if (currentNode != null) {
        administrativeUnit.setAdministrativeUnitStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.ADMINISTRATIVE_UNIT_STATUS);
    }
    // Deserialize administrativeUnitName
    currentNode = objectNode.get(N5ResourceMappings.ADMINISTRATIVE_UNIT_NAME);
    if (currentNode != null) {
        administrativeUnit.setAdministrativeUnitName(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.ADMINISTRATIVE_UNIT_NAME);
    }
    // Deserialize shortName
    currentNode = objectNode.get(N5ResourceMappings.SHORT_NAME);
    if (currentNode != null) {
        administrativeUnit.setShortName(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.SHORT_NAME);
    }
    // Deserialize referenceToParent
    currentNode = objectNode.get(N5ResourceMappings.ADMINISTRATIVE_UNIT_PARENT_REFERENCE);
    if (currentNode != null) {
        AdministrativeUnit parentAdministrativeUnit = administrativeUnit.getParentAdministrativeUnit();
        // Will it not always be null??
        if (parentAdministrativeUnit == null) {
            parentAdministrativeUnit = new AdministrativeUnit();
            parentAdministrativeUnit.setSystemId(currentNode.textValue());
            parentAdministrativeUnit.getReferenceChildAdministrativeUnit().add(administrativeUnit);
        }
        objectNode.remove(N5ResourceMappings.ADMINISTRATIVE_UNIT_PARENT_REFERENCE);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The administrativEnhet you tried to create is malformed. The " + "following fields are not recognised as administrativEnhet fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return administrativeUnit;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AdministrativeUnit(nikita.common.model.noark5.v4.admin.AdministrativeUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 7 with NikitaMalformedInputDataException

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

the class UserDeserializer 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 8 with NikitaMalformedInputDataException

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

the class CaseFileDeserializer method deserialize.

@Override
public CaseFile deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    CaseFile caseFile = new CaseFile();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise properties for File
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(caseFile, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(caseFile, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(caseFile, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseKeyword(caseFile, objectNode, errors);
    // Deserialize fileId
    JsonNode currentNode = objectNode.get(N5ResourceMappings.FILE_ID);
    if (null != currentNode) {
        caseFile.setFileId(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FILE_ID);
    }
    // Deserialize officialTitle
    currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        caseFile.setOfficialTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
    }
    caseFile.setReferenceCrossReference(CommonUtils.Hateoas.Deserialize.deserialiseCrossReferences(objectNode, errors));
    CommonUtils.Hateoas.Deserialize.deserialiseComments(caseFile, objectNode, errors);
    caseFile.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode, errors));
    caseFile.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode, errors));
    caseFile.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode, errors));
    // Deserialise general properties for CaseFile
    // Deserialize caseYear
    currentNode = objectNode.get(N5ResourceMappings.CASE_YEAR);
    if (null != currentNode) {
        caseFile.setCaseYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.CASE_YEAR);
    }
    // Deserialize caseSequenceNumber
    currentNode = objectNode.get(N5ResourceMappings.CASE_SEQUENCE_NUMBER);
    if (null != currentNode) {
        caseFile.setCaseSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.CASE_SEQUENCE_NUMBER);
    }
    // Deserialize caseDate
    caseFile.setCaseDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_DATE, objectNode, errors));
    // Deserialize administrativeUnit
    currentNode = objectNode.get(N5ResourceMappings.ADMINISTRATIVE_UNIT);
    if (null != currentNode) {
        caseFile.setAdministrativeUnit(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.ADMINISTRATIVE_UNIT);
    }
    // Deserialize caseResponsible
    currentNode = objectNode.get(N5ResourceMappings.CASE_RESPONSIBLE);
    if (null != currentNode) {
        caseFile.setCaseResponsible(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_RESPONSIBLE);
    }
    // Deserialize recordsManagementUnit
    currentNode = objectNode.get(N5ResourceMappings.CASE_RECORDS_MANAGEMENT_UNIT);
    if (null != currentNode) {
        caseFile.setRecordsManagementUnit(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_RECORDS_MANAGEMENT_UNIT);
    }
    // Deserialize caseStatus
    currentNode = objectNode.get(N5ResourceMappings.CASE_STATUS);
    if (null != currentNode) {
        caseFile.setCaseStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_STATUS);
    }
    // Deserialize loanedDate
    caseFile.setLoanedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_LOANED_DATE, objectNode, errors));
    // Deserialize loanedTo
    currentNode = objectNode.get(N5ResourceMappings.CASE_LOANED_TO);
    if (null != currentNode) {
        caseFile.setLoanedTo(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_LOANED_TO);
    }
    // Deserialize referenceSeries
    currentNode = objectNode.get(N5ResourceMappings.REFERENCE_SERIES);
    if (null != currentNode) {
        Series series = new Series();
        String systemID = currentNode.textValue();
        if (systemID != null) {
            series.setSystemId(systemID);
        }
        caseFile.setReferenceSeries(series);
        objectNode.remove(N5ResourceMappings.REFERENCE_SERIES);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The saksmappe object you tried to create is malformed. The " + "following fields are not recognised as saksmappe fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    caseFile.setReferenceCaseParty(CommonUtils.Hateoas.Deserialize.deserialiseCaseParties(objectNode, errors));
    caseFile.setReferencePrecedence(CommonUtils.Hateoas.Deserialize.deserialisePrecedences(objectNode, errors));
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return caseFile;
}
Also used : Series(nikita.common.model.noark5.v4.Series) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 9 with NikitaMalformedInputDataException

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

the class CorrespondencePartInternalDeserializer method deserialize.

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

Example 10 with NikitaMalformedInputDataException

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

the class CorrespondencePartPersonDeserializer method deserialize.

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