Search in sources :

Example 6 with NikitaMalformedInputDataException

use of nikita.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 {
    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);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 7 with NikitaMalformedInputDataException

use of nikita.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 {
    AdministrativeUnit administrativeUnit = new AdministrativeUnit();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(administrativeUnit, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(administrativeUnit, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkFinaliseEntity(administrativeUnit, objectNode);
    // Deserialize administrativeUnitStatus
    JsonNode currentNode = objectNode.get(ADMINISTRATIVE_UNIT_STATUS);
    if (currentNode != null) {
        administrativeUnit.setAdministrativeUnitStatus(currentNode.textValue());
        objectNode.remove(ADMINISTRATIVE_UNIT_STATUS);
    }
    // Deserialize administrativeUnitName
    currentNode = objectNode.get(ADMINISTRATIVE_UNIT_NAME);
    if (currentNode != null) {
        administrativeUnit.setAdministrativeUnitName(currentNode.textValue());
        objectNode.remove(ADMINISTRATIVE_UNIT_NAME);
    }
    // Deserialize shortName
    currentNode = objectNode.get(SHORT_NAME);
    if (currentNode != null) {
        administrativeUnit.setShortName(currentNode.textValue());
        objectNode.remove(SHORT_NAME);
    }
    // Deserialize referenceToParent
    currentNode = objectNode.get(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(ADMINISTRATIVE_UNIT_PARENT_REFERENCE);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The administrativEnhet you tried to create is malformed. The " + "following fields are not recognised as administrativEnhet fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return administrativeUnit;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AdministrativeUnit(nikita.model.noark5.v4.admin.AdministrativeUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 8 with NikitaMalformedInputDataException

use of nikita.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 {
    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);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(fonds, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(fonds, objectNode);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(FONDS_STATUS);
    if (currentNode != null) {
        fonds.setFondsStatus(currentNode.textValue());
        objectNode.remove(FONDS_STATUS);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkiv you tried to create is malformed. The " + "following fields are not recognised as arkiv fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return fonds;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Fonds(nikita.model.noark5.v4.Fonds) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 9 with NikitaMalformedInputDataException

use of nikita.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 {
    CaseFile caseFile = new CaseFile();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise properties for File
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(caseFile, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(caseFile, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(caseFile, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseKeyword(caseFile, objectNode);
    // Deserialize fileId
    JsonNode currentNode = objectNode.get(FILE_ID);
    if (null != currentNode) {
        caseFile.setFileId(currentNode.textValue());
        objectNode.remove(FILE_ID);
    }
    // Deserialize officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        caseFile.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    caseFile.setReferenceCrossReference(CommonUtils.Hateoas.Deserialize.deserialiseCrossReferences(objectNode));
    CommonUtils.Hateoas.Deserialize.deserialiseComments(caseFile, objectNode);
    caseFile.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
    caseFile.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
    caseFile.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
    // Deserialise general properties for CaseFile
    // Deserialize caseYear
    currentNode = objectNode.get(CASE_YEAR);
    if (null != currentNode) {
        caseFile.setCaseYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(CASE_YEAR);
    }
    // Deserialize caseSequenceNumber
    currentNode = objectNode.get(CASE_SEQUENCE_NUMBER);
    if (null != currentNode) {
        caseFile.setCaseSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(CASE_SEQUENCE_NUMBER);
    }
    // Deserialize caseDate
    currentNode = objectNode.get(CASE_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            caseFile.setCaseDate(parsedDate);
            objectNode.remove(CASE_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The saksmappe you tried to create " + "has a malformed saksDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize administrativeUnit
    currentNode = objectNode.get(ADMINISTRATIVE_UNIT);
    if (null != currentNode) {
        caseFile.setAdministrativeUnit(currentNode.textValue());
        objectNode.remove(ADMINISTRATIVE_UNIT);
    }
    // Deserialize caseResponsible
    currentNode = objectNode.get(CASE_RESPONSIBLE);
    if (null != currentNode) {
        caseFile.setCaseResponsible(currentNode.textValue());
        objectNode.remove(CASE_RESPONSIBLE);
    }
    // Deserialize recordsManagementUnit
    currentNode = objectNode.get(CASE_RECORDS_MANAGEMENT_UNIT);
    if (null != currentNode) {
        caseFile.setRecordsManagementUnit(currentNode.textValue());
        objectNode.remove(CASE_RECORDS_MANAGEMENT_UNIT);
    }
    // Deserialize caseStatus
    currentNode = objectNode.get(CASE_STATUS);
    if (null != currentNode) {
        caseFile.setCaseStatus(currentNode.textValue());
        objectNode.remove(CASE_STATUS);
    }
    // Deserialize loanedDate
    currentNode = objectNode.get(CASE_LOANED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            caseFile.setLoanedDate(parsedDate);
            objectNode.remove(CASE_LOANED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The saksmappe you tried to create " + "has a malformed utlaantDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize loanedTo
    currentNode = objectNode.get(CASE_LOANED_TO);
    if (null != currentNode) {
        caseFile.setLoanedTo(currentNode.textValue());
        objectNode.remove(CASE_LOANED_TO);
    }
    // Deserialize referenceSeries
    currentNode = objectNode.get(REFERENCE_SERIES);
    if (null != currentNode) {
        Series series = new Series();
        String systemID = currentNode.textValue();
        if (systemID != null) {
            series.setSystemId(systemID);
        }
        caseFile.setReferenceSeries(series);
        objectNode.remove(REFERENCE_SERIES);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("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));
    caseFile.setReferencePrecedence(CommonUtils.Hateoas.Deserialize.deserialisePrecedences(objectNode));
    return caseFile;
}
Also used : Series(nikita.model.noark5.v4.Series) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 10 with NikitaMalformedInputDataException

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