Search in sources :

Example 6 with CaseFile

use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.

the class CaseFileHateoasController method updateCaseFile.

// Update a CaseFile with given values
// PUT [contextPath][api]/casehandling/saksmappe/{systemId}
@ApiOperation(value = "Updates a CaseFile identified by a given systemId", notes = "Returns the newly updated caseFile", response = CaseFileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CaseFile " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CaseFileHateoas.class), @ApiResponse(code = 201, message = "CaseFile " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = CaseFileHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type CaseFile"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<CaseFileHateoas> updateCaseFile(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of caseFile to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "CaseFile", value = "Incoming caseFile object", required = true) @RequestBody CaseFile caseFile) throws NikitaException {
    validateForUpdate(caseFile);
    CaseFile updatedCaseFile = caseFileService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), caseFile);
    CaseFileHateoas caseFileHateoas = new CaseFileHateoas(updatedCaseFile);
    caseFileHateoasHandler.addLinks(caseFileHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedCaseFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedCaseFile.getVersion().toString()).body(caseFileHateoas);
}
Also used : CaseFileHateoas(nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) CaseFile(nikita.model.noark5.v4.casehandling.CaseFile) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) AfterNoarkEntityUpdatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with CaseFile

use of nikita.common.model.noark5.v4.casehandling.CaseFile 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 8 with CaseFile

use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.

the class CaseFileHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject caseFileHateoas, JsonGenerator jgen) throws IOException {
    CaseFile caseFile = (CaseFile) noarkSystemIdEntity;
    jgen.writeStartObject();
    if (caseFile.getSystemId() != null) {
        jgen.writeStringField(SYSTEM_ID, caseFile.getSystemId());
    }
    if (caseFile.getFileId() != null) {
        jgen.writeStringField(FILE_ID, caseFile.getFileId());
    }
    if (caseFile.getTitle() != null) {
        jgen.writeStringField(TITLE, caseFile.getTitle());
    }
    if (caseFile.getOfficialTitle() != null) {
        jgen.writeStringField(FILE_PUBLIC_TITLE, caseFile.getOfficialTitle());
    }
    if (caseFile.getDescription() != null) {
        jgen.writeStringField(DESCRIPTION, caseFile.getDescription());
    }
    CommonUtils.Hateoas.Serialize.printKeyword(jgen, caseFile);
    if (caseFile.getDocumentMedium() != null) {
        jgen.writeStringField(DOCUMENT_MEDIUM, caseFile.getDocumentMedium());
    }
    CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, caseFile);
    if (caseFile.getCreatedDate() != null) {
        jgen.writeStringField(CREATED_DATE, Serialize.formatDateTime(caseFile.getCreatedDate()));
    }
    if (caseFile.getCreatedBy() != null) {
        jgen.writeStringField(CREATED_BY, caseFile.getCreatedBy());
    }
    if (caseFile.getFinalisedDate() != null) {
        jgen.writeStringField(FINALISED_DATE, Serialize.formatDateTime(caseFile.getFinalisedDate()));
    }
    if (caseFile.getFinalisedBy() != null) {
        jgen.writeStringField(FINALISED_BY, caseFile.getFinalisedBy());
    }
    if (caseFile.getReferenceSeries() != null && caseFile.getReferenceSeries().getSystemId() != null) {
        jgen.writeStringField(REFERENCE_SERIES, caseFile.getReferenceSeries().getSystemId());
    }
    if (caseFile.getCaseYear() != null) {
        jgen.writeNumberField(CASE_YEAR, caseFile.getCaseYear().intValue());
    }
    if (caseFile.getCaseSequenceNumber() != null) {
        jgen.writeNumberField(CASE_SEQUENCE_NUMBER, caseFile.getCaseSequenceNumber().intValue());
    }
    if (caseFile.getCaseDate() != null) {
        jgen.writeStringField(CASE_DATE, Serialize.formatDate(caseFile.getCaseDate()));
    }
    if (caseFile.getAdministrativeUnit() != null) {
        jgen.writeStringField(ADMINISTRATIVE_UNIT, caseFile.getAdministrativeUnit());
    }
    if (caseFile.getCaseResponsible() != null) {
        jgen.writeStringField(CASE_RESPONSIBLE, caseFile.getCaseResponsible());
    }
    if (caseFile.getRecordsManagementUnit() != null) {
        jgen.writeStringField(CASE_RECORDS_MANAGEMENT_UNIT, caseFile.getRecordsManagementUnit());
    }
    if (caseFile.getCaseStatus() != null) {
        jgen.writeStringField(CASE_STATUS, caseFile.getCaseStatus());
    }
    if (caseFile.getLoanedDate() != null) {
        jgen.writeStringField(CASE_LOANED_DATE, Serialize.formatDate(caseFile.getLoanedDate()));
    }
    if (caseFile.getLoanedTo() != null) {
        jgen.writeStringField(CASE_LOANED_TO, caseFile.getLoanedTo());
    }
    // TODO: Implement M209 referanseSekundaerKlassifikasjon
    //CommonCommonUtils.Hateoas.Serialize.printSecondaryClassification(jgen, caseFile);
    CommonUtils.Hateoas.Serialize.printCaseParty(jgen, caseFile);
    //CommonUtils.Hateoas.Serialize.printPrecedence(jgen, caseFile);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, caseFileHateoas.getLinks(caseFile));
    jgen.writeEndObject();
}
Also used : CaseFile(nikita.model.noark5.v4.casehandling.CaseFile)

Example 9 with CaseFile

use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.

the class CaseFileService method createRegistryEntryAssociatedWithCaseFile.

@Override
public RegistryEntry createRegistryEntryAssociatedWithCaseFile(@NotNull String fileSystemId, @NotNull RegistryEntry registryEntry) {
    CaseFile caseFile = getCaseFileOrThrow(fileSystemId);
    // bidirectional relationship @OneToMany and @ManyToOne, set both sides of relationship
    registryEntry.setReferenceFile(caseFile);
    caseFile.getReferenceRecord().add(registryEntry);
    return registryEntryService.save(registryEntry);
}
Also used : CaseFile(nikita.model.noark5.v4.casehandling.CaseFile)

Example 10 with CaseFile

use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.

the class CaseFileService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String caseFileSystemId) {
    CaseFile caseFile = getCaseFileOrThrow(caseFileSystemId);
    caseFileRepository.delete(caseFile);
}
Also used : CaseFile(nikita.model.noark5.v4.casehandling.CaseFile)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)18 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)17 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)15 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Timed (com.codahale.metrics.annotation.Timed)9 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)7 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)7 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)6 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)4 Series (nikita.model.noark5.v4.Series)4 List (java.util.List)3 Series (nikita.common.model.noark5.v4.Series)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2