Search in sources :

Example 11 with NikitaMalformedInputDataException

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

Example 12 with NikitaMalformedInputDataException

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

the class ClassifiactionSystemDeserializer method deserialize.

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

Example 13 with NikitaMalformedInputDataException

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

the class FileDeserializer method deserialize.

@Override
public File deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    File file = new File();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(file, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(file, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(file, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseKeyword(file, objectNode);
    // Deserialize fileId
    JsonNode currentNode = objectNode.get(FILE_ID);
    if (null != currentNode) {
        file.setFileId(currentNode.textValue());
        objectNode.remove(FILE_ID);
    }
    // Deserialize officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        file.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // TODO: FIX THIS CommonCommonUtils.Hateoas.Deserialize.deserialiseCrossReference(file, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseComments(file, objectNode);
    file.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
    file.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
    file.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
    // Deserialize referenceSeries
    currentNode = objectNode.get(REFERENCE_SERIES);
    if (null != currentNode) {
        Series series = new Series();
        String systemID = currentNode.textValue();
        if (systemID != null) {
            series.setSystemId(systemID);
        }
        file.setReferenceSeries(series);
        objectNode.remove(REFERENCE_SERIES);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The mappe you tried to create is malformed. The " + "following fields are not recognised as mappe fields  [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return file;
}
Also used : Series(nikita.model.noark5.v4.Series) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) File(nikita.model.noark5.v4.File) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 14 with NikitaMalformedInputDataException

use of nikita.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 {
    Record record = new Record();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(record, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(record, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (currentNode != null) {
        record.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (currentNode != null) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            record.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The registrering you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The registrering you tried to create is malformed. The " + "following fields are not recognised as registrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return record;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Record(nikita.model.noark5.v4.Record) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 15 with NikitaMalformedInputDataException

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

the class SeriesDeserializer method deserialize.

@Override
public Series deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    Series series = new Series();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(series, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(series, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(series, objectNode);
    // Deserialize seriesStatus
    JsonNode currentNode = objectNode.get(SERIES_STATUS);
    if (null != currentNode) {
        series.setSeriesStatus(currentNode.textValue());
        objectNode.remove(SERIES_STATUS);
    }
    // Deserialize seriesStartDate
    currentNode = objectNode.get(SERIES_START_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            series.setSeriesStartDate(parsedDate);
            objectNode.remove(SERIES_START_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The arkivdel you tried to create " + "has a malformed arkivperiodeStartDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize seriesEndDate
    currentNode = objectNode.get(SERIES_END_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            series.setSeriesEndDate(parsedDate);
            objectNode.remove(SERIES_END_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The arkivdel you tried to create " + "has a malformed arkivperiodeSluttDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize referencePrecursor
    currentNode = objectNode.get(SERIES_PRECURSOR);
    if (null != currentNode) {
        Series seriesPrecursor = new Series();
        seriesPrecursor.setSystemId(currentNode.textValue());
        series.setReferencePrecursor(seriesPrecursor);
        // TODO: Does this imply that the current arkivdel is the successor?
        // I would not set it here, as the service class has to check that
        // the seriesPrecursor object actually exists
        objectNode.remove(SERIES_PRECURSOR);
    }
    // Deserialize referenceSuccessor
    currentNode = objectNode.get(SERIES_SUCCESSOR);
    if (null != currentNode) {
        Series seriesSuccessor = new Series();
        seriesSuccessor.setSystemId(currentNode.textValue());
        series.setReferenceSuccessor(seriesSuccessor);
        // TODO: Does this imply that the current arkivdel is the precursor?
        // I would not set it here, as the service class should do this
        objectNode.remove(SERIES_SUCCESSOR);
    }
    series.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
    series.setReferenceDisposalUndertaken(CommonUtils.Hateoas.Deserialize.deserialiseDisposalUndertaken(objectNode));
    series.setReferenceDeletion(CommonUtils.Hateoas.Deserialize.deserialiseDeletion(objectNode));
    series.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
    series.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The arkivdel you tried to create is malformed. The " + "following fields are not recognised as arkivdel fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return series;
}
Also used : Series(nikita.model.noark5.v4.Series) 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)

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