Search in sources :

Example 6 with AdministrativeUnit

use of nikita.model.noark5.v4.admin.AdministrativeUnit 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 7 with AdministrativeUnit

use of nikita.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.

the class AdministrativeUnitService method getAdministrativeUnitOrThrow.

// All HELPER operations
/**
 * Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
 * If you call this, be aware that you will only ever get a valid AdministrativeUnit back. If there is no valid
 * AdministrativeUnit, an exception is thrown
 *
 * @param administrativeUnitSystemId
 * @return
 */
protected AdministrativeUnit getAdministrativeUnitOrThrow(@NotNull String administrativeUnitSystemId) {
    AdministrativeUnit administrativeUnit = administrativeUnitRepository.findBySystemId(administrativeUnitSystemId);
    if (administrativeUnit == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " AdministrativeUnit, using systemId " + administrativeUnitSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return administrativeUnit;
}
Also used : AdministrativeUnit(nikita.common.model.noark5.v4.admin.AdministrativeUnit) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 8 with AdministrativeUnit

use of nikita.model.noark5.v4.admin.AdministrativeUnit in project nikita-noark5-core by HiOA-ABI.

the class AdministrativeUnitService method update.

/**
 * update a particular administrativeUnit. <br>
 *
 * @param incomingAdministrativeUnit
 * @return the updated administrativeUnit
 */
@Override
public AdministrativeUnit update(String systemId, Long version, AdministrativeUnit incomingAdministrativeUnit) {
    AdministrativeUnit existingAdministrativeUnit = getAdministrativeUnitOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    if (null != existingAdministrativeUnit.getAdministrativeUnitName()) {
        existingAdministrativeUnit.setAdministrativeUnitName(incomingAdministrativeUnit.getAdministrativeUnitName());
    }
    if (null != existingAdministrativeUnit.getShortName()) {
        existingAdministrativeUnit.setShortName(incomingAdministrativeUnit.getShortName());
    }
    existingAdministrativeUnit.setVersion(version);
    administrativeUnitRepository.save(existingAdministrativeUnit);
    return administrativeUnitRepository.save(incomingAdministrativeUnit);
}
Also used : AdministrativeUnit(nikita.common.model.noark5.v4.admin.AdministrativeUnit)

Example 9 with AdministrativeUnit

use of nikita.model.noark5.v4.admin.AdministrativeUnit 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 10 with AdministrativeUnit

use of nikita.model.noark5.v4.admin.AdministrativeUnit 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)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 AdministrativeUnit (nikita.model.noark5.v4.admin.AdministrativeUnit)7 Timed (com.codahale.metrics.annotation.Timed)6 AdministrativeUnit (nikita.common.model.noark5.v4.admin.AdministrativeUnit)6 AdministrativeUnitHateoas (nikita.common.model.noark5.v4.hateoas.admin.AdministrativeUnitHateoas)5 AdministrativeUnitHateoas (nikita.model.noark5.v4.hateoas.admin.AdministrativeUnitHateoas)5 Authorisation (nikita.webapp.security.Authorisation)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)2 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Series (nikita.common.model.noark5.v4.Series)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1