Search in sources :

Example 16 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(top);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry)

Example 17 with RegistryEntry

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

the class RegistryEntryService method createDocumentDescriptionAssociatedWithRegistryEntry.

/*
TODO: Temp disabled!
    private void associateCorrespondencePartTypeWithCorrespondencePart(@NotNull CorrespondencePart correspondencePart) {
        CorrespondencePartType incomingCorrespondencePartType = correspondencePart.getCorrespondencePartType();
        // It should never get this far with a null value
        // It should be rejected at controller level
        // The incoming CorrespondencePartType will not have @id field set. Therefore, we have to look it up
        // in the database and make sure the proper CorrespondencePartType is associated with the CorrespondencePart
        if (incomingCorrespondencePartType != null && incomingCorrespondencePartType.getCode() != null) {
            CorrespondencePartType actualCorrespondencePartType =
                    correspondencePartTypeRepository.findByCode(incomingCorrespondencePartType.getCode());
            if (actualCorrespondencePartType != null) {
                correspondencePart.setCorrespondencePartType(actualCorrespondencePartType);
            }
        }
    }


    TODO: Temp disabled!
    @Override
    public List<CorrespondencePartPerson> getCorrespondencePartPersonAssociatedWithRegistryEntry(String systemID) {
        RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
        return registryEntry.getReferenceCorrespondencePartPerson();
    }

    @Override
    public List<CorrespondencePartInternal> getCorrespondencePartInternalAssociatedWithRegistryEntry(String systemID) {
        RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
        return registryEntry.getReferenceCorrespondencePartInternal();
    }

    @Override
    public List<CorrespondencePartUnit> getCorrespondencePartUnitAssociatedWithRegistryEntry(String systemID) {
        RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
        return registryEntry.getReferenceCorrespondencePartUnit();
    }
    */
/* @Override
     public CorrespondencePartPerson createCorrespondencePartPersonAssociatedWithRegistryEntry(
             String systemID, CorrespondencePartPerson correspondencePart) {
         RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);

 TODO: Temp disabled!
         associateCorrespondencePartTypeWithCorrespondencePart(correspondencePart);

         ContactInformation contactInformation = correspondencePart.getContactInformation();
         if (null != contactInformation) {
             NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(contactInformation);
             NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(contactInformation);
         }

         SimpleAddress postalAddress = correspondencePart.getPostalAddress();
         if (null != postalAddress) {
             NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(postalAddress);
             NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(postalAddress);
         }

         SimpleAddress residingAddress = correspondencePart.getResidingAddress();
         if (null != residingAddress) {
             NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(residingAddress);
             NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(residingAddress);
         }

         NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
         NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
         // bidirectional relationship @ManyToMany, set both sides of relationship
         registryEntry.getReferenceCorrespondencePartPerson().add(correspondencePart);
         correspondencePart.getReferenceRegistryEntry().add(registryEntry);
         return correspondencePartService.createNewCorrespondencePartPerson(correspondencePart);

         return null;
     }
 */
/*
  TODO: Temp disabled!
    @Override
    public CorrespondencePartInternal createCorrespondencePartInternalAssociatedWithRegistryEntry(
            String systemID, CorrespondencePartInternal correspondencePart) {
        RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);

        NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
        NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
        // bidirectional relationship @ManyToMany, set both sides of relationship
        registryEntry.getReferenceCorrespondencePartInternal().add(correspondencePart);
        correspondencePart.getReferenceRegistryEntry().add(registryEntry);
        return correspondencePartService.createNewCorrespondencePartInternal(correspondencePart);
    }

    @Override
    public CorrespondencePartUnit createCorrespondencePartUnitAssociatedWithRegistryEntry(
            String systemID, CorrespondencePartUnit correspondencePart) {
        RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);

        associateCorrespondencePartTypeWithCorrespondencePart(correspondencePart);

        ContactInformation contactInformation = correspondencePart.getContactInformation();
        if (null != contactInformation) {
            NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(contactInformation);
            NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(contactInformation);
        }

        SimpleAddress postalAddress = correspondencePart.getPostalAddress();
        if (null != postalAddress) {
            NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(postalAddress);
            NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(postalAddress);
        }

        SimpleAddress businessAddress = correspondencePart.getBusinessAddress();
        if (null != businessAddress) {
            NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(businessAddress);
            NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(businessAddress);
        }

        NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
        NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
        // bidirectional relationship @ManyToMany, set both sides of relationship
        registryEntry.getReferenceCorrespondencePartUnit().add(correspondencePart);
        correspondencePart.getReferenceRegistryEntry().add(registryEntry);
        return correspondencePartService.createNewCorrespondencePartUnit(correspondencePart);
    }

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

Example 18 with RegistryEntry

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

the class RegistryEntryService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String registryEntrySystemId) {
    RegistryEntry registryEntry = getRegistryEntryOrThrow(registryEntrySystemId);
    registryEntryRepository.delete(registryEntry);
}
Also used : RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry)

Example 19 with RegistryEntry

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

the class RegistryEntryService method getRegistryEntryOrThrow.

/**
 * 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 RegistryEntry back. If there is no valid
 * RegistryEntry, an exception is thrown
 *
 * @param registryEntrySystemId
 * @return
 */
protected RegistryEntry getRegistryEntryOrThrow(@NotNull String registryEntrySystemId) {
    RegistryEntry registryEntry = registryEntryRepository.findBySystemId(registryEntrySystemId);
    if (registryEntry == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " RegistryEntry, using systemId " + registryEntrySystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return registryEntry;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) RegistryEntry(nikita.common.model.noark5.v4.casehandling.RegistryEntry)

Example 20 with RegistryEntry

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

the class RegistryEntryService method handleUpdate.

// All UPDATE operations
@Override
public RegistryEntry handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull RegistryEntry incomingRegistryEntry) {
    RegistryEntry existingRegistryEntry = getRegistryEntryOrThrow(systemId);
    // Copy all the values you are allowed to copy ....
    if (null != incomingRegistryEntry.getDescription()) {
        existingRegistryEntry.setDescription(incomingRegistryEntry.getDescription());
    }
    if (null != incomingRegistryEntry.getTitle()) {
        existingRegistryEntry.setTitle(incomingRegistryEntry.getTitle());
    }
    if (null != incomingRegistryEntry.getDocumentMedium()) {
        existingRegistryEntry.setDocumentMedium(incomingRegistryEntry.getDocumentMedium());
    }
    if (null != incomingRegistryEntry.getDocumentDate()) {
        existingRegistryEntry.setDocumentDate(incomingRegistryEntry.getDocumentDate());
    }
    if (null != incomingRegistryEntry.getDueDate()) {
        existingRegistryEntry.setDueDate(incomingRegistryEntry.getDueDate());
    }
    if (null != incomingRegistryEntry.getFreedomAssessmentDate()) {
        existingRegistryEntry.setFreedomAssessmentDate(incomingRegistryEntry.getFreedomAssessmentDate());
    }
    if (null != incomingRegistryEntry.getLoanedDate()) {
        existingRegistryEntry.setLoanedDate(incomingRegistryEntry.getLoanedDate());
    }
    if (null != incomingRegistryEntry.getLoanedTo()) {
        existingRegistryEntry.setLoanedTo(incomingRegistryEntry.getLoanedTo());
    }
    existingRegistryEntry.setVersion(version);
    registryEntryRepository.save(existingRegistryEntry);
    return existingRegistryEntry;
}
Also used : RegistryEntry(nikita.common.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