Search in sources :

Example 1 with CaseStatus

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

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

the class CaseStatusService method createNewCaseStatus.

// All CREATE operations
/**
 * Persists a new CaseStatus object to the database.
 *
 * @param caseStatus CaseStatus object with values set
 * @return the newly persisted CaseStatus object wrapped as a
 * MetadataHateoas object
 */
@Override
public MetadataHateoas createNewCaseStatus(CaseStatus caseStatus) {
    caseStatus.setDeleted(false);
    caseStatus.setOwnedBy(SecurityContextHolder.getContext().getAuthentication().getName());
    MetadataHateoas metadataHateoas = new MetadataHateoas(caseStatusRepository.save(caseStatus));
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Example 3 with CaseStatus

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

the class CaseStatusService method handleUpdate.

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

Example 4 with CaseStatus

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

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

the class CaseStatusService method find.

// find by systemId
/**
 * Retrieve a single CaseStatus object identified by systemId
 *
 * @param systemId systemId of the CaseStatus you wish to retrieve
 * @return single CaseStatus object wrapped as a MetadataHateoas object
 */
@Override
public MetadataHateoas find(String systemId) {
    MetadataHateoas metadataHateoas = new MetadataHateoas(caseStatusRepository.findBySystemId(systemId));
    metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
    return metadataHateoas;
}
Also used : Authorisation(nikita.webapp.security.Authorisation) MetadataHateoas(nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)

Aggregations

MetadataHateoas (nikita.common.model.noark5.v4.hateoas.metadata.MetadataHateoas)6 Authorisation (nikita.webapp.security.Authorisation)6 List (java.util.List)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 CaseStatus (nikita.common.model.noark5.v4.metadata.CaseStatus)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Series (nikita.common.model.noark5.v4.Series)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)1 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)1 Series (nikita.model.noark5.v4.Series)1 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)1 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)1 AfterNoarkEntityUpdatedEvent (nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)1