Search in sources :

Example 21 with RegistryEntry

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

the class RegistryEntryDeserializer method deserialize.

@Override
public RegistryEntry deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    StringBuilder errors = new StringBuilder();
    RegistryEntry registryEntry = new RegistryEntry();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode, errors);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode, errors);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        registryEntry.setArchivedBy(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    registryEntry.setArchivedDate(CommonUtils.Hateoas.Deserialize.deserializeDateTime(N5ResourceMappings.RECORD_ARCHIVED_DATE, objectNode, errors));
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(N5ResourceMappings.BASIC_RECORD_ID);
    if (null != currentNode) {
        registryEntry.setRecordId(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(N5ResourceMappings.TITLE);
    if (null != currentNode) {
        registryEntry.setTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        registryEntry.setOfficialTitle(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(N5ResourceMappings.DESCRIPTION);
    if (null != currentNode) {
        registryEntry.setDescription(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode, errors);
    // Deserialize general registryEntry properties
    // Deserialize recordYear
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
    if (null != currentNode) {
        registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
    }
    // Deserialize recordSequenceNumber
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
    if (null != currentNode) {
        registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
    }
    // Deserialize registryEntryNumber
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
    if (null != currentNode) {
        registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
    }
    // Deserialize registryEntryType
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
    if (null != currentNode) {
        registryEntry.setRegistryEntryType(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
    } else {
        errors.append("The journalpost you tried to create is missing journalposttype. ");
    }
    // Deserialize recordStatus
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
    if (null != currentNode) {
        registryEntry.setRecordStatus(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
    } else {
        errors.append("The journalpost you tried to create is missing journalstatus. ");
    }
    // Deserialize recordDate
    registryEntry.setRecordDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DATE, objectNode, errors, true));
    // Deserialize documentDate
    registryEntry.setDocumentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DOCUMENT_DATE, objectNode, errors));
    // Deserialize receivedDate
    registryEntry.setReceivedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECEIVED_DATE, objectNode, errors));
    // Deserialize sentDate
    registryEntry.setSentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_SENT_DATE, objectNode, errors));
    // Deserialize dueDate
    registryEntry.setDueDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DUE_DATE, objectNode, errors));
    // Deserialize freedomAssessmentDate
    registryEntry.setFreedomAssessmentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE, objectNode, errors));
    // Deserialize numberOfAttachments
    currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    if (null != currentNode) {
        registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    }
    // Deserialize loanedDate
    registryEntry.setLoanedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_LOANED_DATE, objectNode, errors));
    // Deserialize loanedTo
    currentNode = objectNode.get(N5ResourceMappings.CASE_LOANED_TO);
    if (null != currentNode) {
        registryEntry.setLoanedTo(currentNode.textValue());
        objectNode.remove(N5ResourceMappings.CASE_LOANED_TO);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        errors.append("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
    }
    if (0 < errors.length())
        throw new NikitaMalformedInputDataException(errors.toString());
    return registryEntry;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) NikitaMalformedInputDataException(nikita.common.util.exceptions.NikitaMalformedInputDataException)

Example 22 with RegistryEntry

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

the class CaseFileHateoasController method createDefaultRegistryEntry.

// API - All GET Requests (CRUD - READ)
// Create a RegistryEntry object with default values
// GET [contextPath][api]/casehandling/mappe/SYSTEM_ID/ny-journalpost
@ApiOperation(value = "Create a RegistryEntry with default values", response = RegistryEntry.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry returned", response = RegistryEntry.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_REGISTRY_ENTRY, method = RequestMethod.GET)
public ResponseEntity<RegistryEntryHateoas> createDefaultRegistryEntry(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
    RegistryEntry defaultRegistryEntry = new RegistryEntry();
    // TODO consider using Calendar date = new GregorianCalendar()
    Date now = new Date();
    // TODO figure out good defaults to return
    defaultRegistryEntry.setRecordDate(now);
    defaultRegistryEntry.setDocumentDate(now);
    defaultRegistryEntry.setRecordStatus(TEST_RECORD_STATUS);
    defaultRegistryEntry.setRegistryEntryType(TEST_REGISTRY_ENTRY_TYPE);
    defaultRegistryEntry.setRecordYear(Calendar.getInstance().get(Calendar.YEAR));
    // TODO generate these
    // defaultRegistryEntry.setRecordSequenceNumber(201701011);
    // defaultRegistryEntry.setRegistryEntryNumber(201701);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(defaultRegistryEntry);
    registryEntryHateoasHandler.addLinksOnNew(registryEntryHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(registryEntryHateoas);
}
Also used : RegistryEntryHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas) Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Date(java.util.Date) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 23 with RegistryEntry

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

the class CaseFileHateoasController method createRegistryEntryAssociatedWithFile.

// API - All POST Requests (CRUD - CREATE)
// Create a RegistryEntry entity
// POST [contextPath][api]/casehandling/{systemId}/ny-journalpost
@ApiOperation(value = "Persists a RegistryEntry object associated with the given Series systemId", notes = "Returns the newly created record object after it was associated with a File object and " + "persisted to the database", response = RegistryEntryHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RegistryEntryHateoas.class), @ApiResponse(code = 201, message = "RegistryEntry " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RegistryEntryHateoas.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 RegistryEntry"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_REGISTRY_ENTRY, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<RegistryEntryHateoas> createRegistryEntryAssociatedWithFile(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of file to associate the record with", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "RegistryEntry", value = "Incoming registryEntry object", required = true) @RequestBody RegistryEntry registryEntry) throws NikitaException {
    RegistryEntry createdRegistryEntry = caseFileService.createRegistryEntryAssociatedWithCaseFile(systemID, registryEntry);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(createdRegistryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdRegistryEntry));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdRegistryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : RegistryEntryHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with RegistryEntry

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

the class RegistryEntryHateoasController method findOneRegistryEntrybySystemId.

// Retrieve a single registryEntry identified by systemId
// GET [contextPath][api]/casehandling/journalpost/{systemID}
@ApiOperation(value = "Retrieves a single RegistryEntry entity given a systemId", response = RegistryEntry.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry returned", response = RegistryEntry.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<RegistryEntryHateoas> findOneRegistryEntrybySystemId(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemID of the registryEntry to retrieve", required = true) @PathVariable("systemID") final String registryEntrySystemId) {
    RegistryEntry registryEntry = registryEntryService.findBySystemId(registryEntrySystemId);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(registryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(registryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with RegistryEntry

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

the class RegistryEntryHateoasController method updateRegistryEntry.

// Update a RegistryEntry with given values
// PUT [contextPath][api]/casehandling/journalpost/{systemId}
@ApiOperation(value = "Updates a RegistryEntry identified by a given systemId", notes = "Returns the newly updated registryEntry", response = RegistryEntryHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "RegistryEntry " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = RegistryEntryHateoas.class), @ApiResponse(code = 201, message = "RegistryEntry " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = RegistryEntryHateoas.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 RegistryEntry"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.PUT, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<RegistryEntryHateoas> updateRegistryEntry(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of registryEntry to update", required = true) @PathVariable("systemID") final String systemID, @ApiParam(name = "RegistryEntry", value = "Incoming registryEntry object", required = true) @RequestBody RegistryEntry registryEntry) throws NikitaException {
    validateForUpdate(registryEntry);
    RegistryEntry updatedRegistryEntry = registryEntryService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), registryEntry);
    RegistryEntryHateoas registryEntryHateoas = new RegistryEntryHateoas(updatedRegistryEntry);
    registryEntryHateoasHandler.addLinks(registryEntryHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedRegistryEntry));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedRegistryEntry.getVersion().toString()).body(registryEntryHateoas);
}
Also used : Authorisation(nikita.webapp.security.Authorisation) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RegistryEntry (nikita.model.noark5.v4.casehandling.RegistryEntry)18 Counted (com.codahale.metrics.annotation.Counted)14 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)14 RegistryEntry (nikita.common.model.noark5.v4.casehandling.RegistryEntry)13 Timed (com.codahale.metrics.annotation.Timed)7 Authorisation (nikita.webapp.security.Authorisation)6 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)6 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)4 Date (java.util.Date)3 RegistryEntryHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas)3 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)3 RegistryEntryHateoas (nikita.model.noark5.v4.hateoas.casehandling.RegistryEntryHateoas)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)2