Search in sources :

Example 26 with RegistryEntry

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

the class RegistryEntryHateoasController method deleteRecordBySystemId.

// Delete a Record identified by systemID
// DELETE [contextPath][api]/casehandling/journalpost/{systemId}/
@ApiOperation(value = "Deletes a single RegistryEntry entity identified by systemID", response = String.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) returned", response = String.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.DELETE)
public ResponseEntity<String> deleteRecordBySystemId(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemID of the record to delete", required = true) @PathVariable("systemID") final String systemID) {
    RegistryEntry registryEntry = registryEntryService.findBySystemId(systemID);
    registryEntryService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, registryEntry));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(CommonUtils.WebUtils.getSuccessStatusStringForDelete());
}
Also used : RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 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 {
    RegistryEntry registryEntry = new RegistryEntry();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        registryEntry.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());
            registryEntry.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost object 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) {
        registryEntry.setRecordId(currentNode.textValue());
        objectNode.remove(BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(TITLE);
    if (null != currentNode) {
        registryEntry.setTitle(currentNode.textValue());
        objectNode.remove(TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        registryEntry.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(DESCRIPTION);
    if (null != currentNode) {
        registryEntry.setDescription(currentNode.textValue());
        objectNode.remove(DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode);
    // Deserialize general registryEntry properties
    // Deserialize recordYear
    currentNode = objectNode.get(REGISTRY_ENTRY_YEAR);
    if (null != currentNode) {
        registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_YEAR);
    }
    // Deserialize recordSequenceNumber
    currentNode = objectNode.get(REGISTRY_ENTRY_SEQUENCE_NUMBER);
    if (null != currentNode) {
        registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_SEQUENCE_NUMBER);
    }
    // Deserialize registryEntryNumber
    currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER);
    if (null != currentNode) {
        registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_NUMBER);
    }
    // Deserialize registryEntryType
    currentNode = objectNode.get(REGISTRY_ENTRY_TYPE);
    if (null != currentNode) {
        registryEntry.setRegistryEntryType(currentNode.textValue());
        objectNode.remove(REGISTRY_ENTRY_TYPE);
    }
    // Deserialize recordStatus
    currentNode = objectNode.get(REGISTRY_ENTRY_STATUS);
    if (null != currentNode) {
        registryEntry.setRecordStatus(currentNode.textValue());
        objectNode.remove(REGISTRY_ENTRY_STATUS);
    }
    // Deserialize recordDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setRecordDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed journaldato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize documentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DOCUMENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setDocumentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DOCUMENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed dokumentetsDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize receivedDate
    currentNode = objectNode.get(REGISTRY_ENTRY_RECEIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setReceivedDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_RECEIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed mottattDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize sentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_SENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setSentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_SENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed sendtDate. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize dueDate
    currentNode = objectNode.get(REGISTRY_ENTRY_DUE_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setDueDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_DUE_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed forfallsdato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize freedomAssessmentDate
    currentNode = objectNode.get(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setFreedomAssessmentDate(parsedDate);
            objectNode.remove(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed offentlighetsvurdertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize numberOfAttachments
    currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    if (null != currentNode) {
        registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
    }
    // Deserialize loanedDate
    currentNode = objectNode.get(CASE_LOANED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
            registryEntry.setLoanedDate(parsedDate);
            objectNode.remove(CASE_LOANED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The journalpost 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) {
        registryEntry.setLoanedTo(currentNode.textValue());
        objectNode.remove(CASE_LOANED_TO);
    }
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return registryEntry;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 28 with RegistryEntry

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

the class RegistryEntryService method findRegistryEntryByOwnerPaginated.

// All READ operations
public List<RegistryEntry> findRegistryEntryByOwnerPaginated(Integer top, Integer skip) {
    if (top == null || top > maxPageSize) {
        top = maxPageSize;
    }
    if (skip == null) {
        skip = 0;
    }
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<RegistryEntry> criteriaQuery = criteriaBuilder.createQuery(RegistryEntry.class);
    Root<RegistryEntry> from = criteriaQuery.from(RegistryEntry.class);
    CriteriaQuery<RegistryEntry> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<RegistryEntry> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(maxPageSize);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

Example 29 with RegistryEntry

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

the class RegistryEntryService method createPrecedenceAssociatedWithRecord.

@Override
public Precedence createPrecedenceAssociatedWithRecord(String registryEntrySystemID, Precedence precedence) {
    RegistryEntry registryEntry = getRegistryEntryOrThrow(registryEntrySystemID);
    NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(precedence);
    NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(precedence);
    // bidirectional relationship @ManyToMany, set both sides of relationship
    registryEntry.getReferencePrecedence().add(precedence);
    precedence.getReferenceRegistryEntry().add(registryEntry);
    return precedenceService.createNewPrecedence(precedence);
}
Also used : RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

Example 30 with RegistryEntry

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

the class RegistryEntryService method createDocumentDescriptionAssociatedWithRegistryEntry.

@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRegistryEntry(String systemID, DocumentDescription documentDescription) {
    RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
    TreeSet<Record> records = (TreeSet<Record>) documentDescription.getReferenceRecord();
    // It should always be instaniated ... check this ...
    if (records == null) {
        records = new TreeSet<>();
        documentDescription.setReferenceRecord(records);
    }
    records.add(registryEntry);
    return documentDescriptionService.save(documentDescription);
}
Also used : TreeSet(java.util.TreeSet) Record(nikita.model.noark5.v4.Record) RegistryEntry(nikita.model.noark5.v4.casehandling.RegistryEntry)

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