Search in sources :

Example 1 with Format

use of nikita.common.model.noark5.v4.metadata.Format in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordDeserializer method deserialize.

@Override
public BasicRecord deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    BasicRecord basicRecord = new BasicRecord();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(basicRecord, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        basicRecord.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            basicRecord.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The basisregistrering you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(BASIC_RECORD_ID);
    if (null != currentNode) {
        basicRecord.setRecordId(currentNode.textValue());
        objectNode.remove(BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(TITLE);
    if (null != currentNode) {
        basicRecord.setTitle(currentNode.textValue());
        objectNode.remove(TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        basicRecord.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(DESCRIPTION);
    if (null != currentNode) {
        basicRecord.setDescription(currentNode.textValue());
        objectNode.remove(DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseAuthor(basicRecord, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The basisregistrering you tried to create is malformed. The " + "following fields are not recognised as basisregistrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return basicRecord;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BasicRecord(nikita.model.noark5.v4.BasicRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 2 with Format

use of nikita.common.model.noark5.v4.metadata.Format in project nikita-noark5-core by HiOA-ABI.

the class DocumentDescriptionDeserializer method deserialize.

@Override
public DocumentDescription deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    DocumentDescription documentDescription = new DocumentDescription();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode);
    // Deserialize documentType
    JsonNode currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    if (null != currentNode) {
        documentDescription.setDocumentType(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    }
    // Deserialize documentStatus
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_STATUS);
    if (null != currentNode) {
        documentDescription.setDocumentStatus(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_STATUS);
    }
    // Deserialize associatedWithRecordAs
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    if (null != currentNode) {
        documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    }
    // Deserialize documentNumber
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    if (null != currentNode) {
        documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    }
    // Deserialize associationDate
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            documentDescription.setAssociationDate(parsedDate);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create " + "has a malformed tilknyttetDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    }
    // Deserialize associatedBy
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    if (null != currentNode) {
        documentDescription.setAssociatedBy(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    }
    // Deserialize storageLocation
    currentNode = objectNode.get(STORAGE_LOCATION);
    if (null != currentNode) {
        documentDescription.setStorageLocation(currentNode.textValue());
        objectNode.remove(STORAGE_LOCATION);
    }
    // Deserialize general documentDescription properties
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return documentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) 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)

Example 3 with Format

use of nikita.common.model.noark5.v4.metadata.Format in project nikita-noark5-core by HiOA-ABI.

the class DocumentObjectDeserializer method deserialize.

@Override
public DocumentObject deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    DocumentObject documentObject = new DocumentObject();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general DocumentObject properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentObject, objectNode);
    // Deserialize versionNumber
    JsonNode currentNode = objectNode.get(DOCUMENT_OBJECT_VERSION_NUMBER);
    if (null != currentNode) {
        documentObject.setVersionNumber(new Integer(currentNode.intValue()));
        objectNode.remove(DOCUMENT_OBJECT_VERSION_NUMBER);
    }
    // Deserialize variantFormat
    currentNode = objectNode.get(DOCUMENT_OBJECT_VARIANT_FORMAT);
    if (null != currentNode) {
        documentObject.setVariantFormat(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_VARIANT_FORMAT);
    }
    // Deserialize format
    currentNode = objectNode.get(DOCUMENT_OBJECT_FORMAT);
    if (null != currentNode) {
        documentObject.setFormat(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_FORMAT);
    }
    // Deserialize formatDetails
    currentNode = objectNode.get(DOCUMENT_OBJECT_FORMAT_DETAILS);
    if (null != currentNode) {
        documentObject.setFormatDetails(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_FORMAT_DETAILS);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentObject, objectNode);
    // Deserialize referenceDocumentFile
    currentNode = objectNode.get(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    if (null != currentNode) {
        documentObject.setReferenceDocumentFile(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE);
    }
    // Deserialize checksum
    currentNode = objectNode.get(DOCUMENT_OBJECT_CHECKSUM);
    if (null != currentNode) {
        documentObject.setChecksum(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_CHECKSUM);
    }
    // Deserialize checksumAlgorithm
    currentNode = objectNode.get(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    if (null != currentNode) {
        documentObject.setChecksumAlgorithm(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM);
    }
    // Deserialize fileSize
    currentNode = objectNode.get(DOCUMENT_OBJECT_FILE_SIZE);
    if (null != currentNode) {
        documentObject.setFileSize(currentNode.asLong());
        objectNode.remove(DOCUMENT_OBJECT_FILE_SIZE);
    }
    // Deserialize filename
    currentNode = objectNode.get(DOCUMENT_OBJECT_FILE_NAME);
    if (null != currentNode) {
        documentObject.setOriginalFilename(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_FILE_NAME);
    }
    // Deserialize mimeType
    currentNode = objectNode.get(DOCUMENT_OBJECT_MIME_TYPE);
    if (null != currentNode) {
        documentObject.setMimeType(currentNode.textValue());
        objectNode.remove(DOCUMENT_OBJECT_MIME_TYPE);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The dokumentobjekt you tried to create is malformed. The " + "following fields are not recognised as dokumentobjekt fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return documentObject;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DocumentObject(nikita.model.noark5.v4.DocumentObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 4 with Format

use of nikita.common.model.noark5.v4.metadata.Format 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 5 with Format

use of nikita.common.model.noark5.v4.metadata.Format in project nikita-noark5-core by HiOA-ABI.

the class FormatService method handleUpdate.

/**
 * Update a Format identified by its systemId
 * <p>
 * Copy the values you are allowed to change, code and description
 *
 * @param systemId The systemId of the format object you wish to update
 * @param format   The updated format object. Note the values you are
 *                 allowed to change are copied from this object. This
 *                 object is not persisted.
 * @return the updated format
 */
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, Format format) {
    Format existingFormat = getFormatOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != existingFormat.getCode()) {
        existingFormat.setCode(existingFormat.getCode());
    }
    if (null != existingFormat.getDescription()) {
        existingFormat.setDescription(existingFormat.getDescription());
    }
    // Note this can potentially result in a NoarkConcurrencyException
    // exception
    existingFormat.setVersion(version);
    MetadataHateoas formatHateoas = new MetadataHateoas(formatRepository.save(existingFormat));
    metadataHateoasHandler.addLinks(formatHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFormat));
    return formatHateoas;
}
Also used : Format(nikita.common.model.noark5.v4.metadata.Format) Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)7 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)7 Authorisation (nikita.webapp.security.Authorisation)7 ParseException (java.text.ParseException)6 Date (java.util.Date)6 List (java.util.List)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 Format (nikita.common.model.noark5.v4.metadata.Format)3 RegistryEntryType (nikita.common.model.noark5.v4.metadata.RegistryEntryType)3 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)2 Series (nikita.model.noark5.v4.Series)2 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)2 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)1 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)1 BasicRecord (nikita.model.noark5.v4.BasicRecord)1 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 Record (nikita.model.noark5.v4.Record)1