Search in sources :

Example 16 with DocumentType

use of org.kuali.kfs.kew.doctype.bo.DocumentType in project cu-kfs by CU-CommunityApps.

the class DocumentTypeServiceImpl method versionAndSave.

@CacheEvict(value = { DocumentType.CACHE_NAME, Permission.CACHE_NAME }, allEntries = true)
public void versionAndSave(DocumentType documentType) {
    // is going to be an update and not a create just throw and exception to be on the safe side
    if (documentType.getDocumentTypeId() != null && documentType.getVersionNumber() != null) {
        throw new RuntimeException("DocumentType configured for update and not versioning which we support");
    }
    // grab the old document. Don't Use Cached Version!
    DocumentType oldDocumentType = findByName(documentType.getName());
    // reset the children on the oldDocumentType
    // oldDocumentType.resetChildren();
    String existingDocTypeId = null;
    if (oldDocumentType != null) {
        existingDocTypeId = oldDocumentType.getDocumentTypeId();
        // set version number on the new doc type using the max version from the database
        Integer maxVersionNumber = documentTypeDAO.getMaxVersionNumber(documentType.getName());
        documentType.setVersion(maxVersionNumber != null ? Integer.valueOf(maxVersionNumber + 1) : Integer.valueOf(0));
        oldDocumentType.setCurrentInd(Boolean.FALSE);
        if (LOG.isInfoEnabled()) {
            LOG.info("Saving old document type Id " + oldDocumentType.getDocumentTypeId() + " name '" + oldDocumentType.getName() + "' (current = " + oldDocumentType.getCurrentInd() + ")");
        }
        save(oldDocumentType);
    }
    // check to see that no current documents exist in database
    if (!CollectionUtils.isEmpty(documentTypeDAO.findAllCurrentByName(documentType.getName()))) {
        String errorMsg = "Found invalid 'current' document with name '" + documentType.getName() + "'.  None should exist.";
        LOG.error(errorMsg);
        throw new RuntimeException(errorMsg);
    }
    // set up the previous current doc type on the new doc type
    documentType.setPreviousVersionId(existingDocTypeId);
    documentType.setCurrentInd(Boolean.TRUE);
    save(documentType);
    if (LOG.isInfoEnabled()) {
        LOG.info("Saved current document type Id " + documentType.getDocumentTypeId() + " name '" + documentType.getName() + "' (current = " + documentType.getCurrentInd() + ")");
    }
    // attach the children to this new parent.  cloning the children would probably be a better way to go here...
    if (ObjectUtils.isNotNull(existingDocTypeId)) {
        // documentType.getPreviousVersion() should not be null at this point
        for (DocumentType child : getChildDocumentTypes(existingDocTypeId)) {
            child.setDocTypeParentId(documentType.getDocumentTypeId());
            save(child);
            if (LOG.isInfoEnabled()) {
                LOG.info("Saved child document type Id " + child.getDocumentTypeId() + " name '" + child.getName() + "' (parent = " + child.getDocTypeParentId() + ", current = " + child.getCurrentInd() + ")");
            }
        }
    }
    // the db and not from the cache
    if (documentType.getDocTypeParentId() != null) {
        DocumentType parent = getDocumentTypeDAO().findById(documentType.getDocTypeParentId());
        save(parent);
        if (LOG.isInfoEnabled()) {
            LOG.info("Saved parent document type Id " + parent.getDocumentTypeId() + " name '" + parent.getName() + "' (current = " + parent.getCurrentInd() + ")");
        }
    }
}
Also used : DocumentType(org.kuali.kfs.kew.doctype.bo.DocumentType) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 17 with DocumentType

use of org.kuali.kfs.kew.doctype.bo.DocumentType in project cu-kfs by CU-CommunityApps.

the class MenuService method canInitiateDocument.

private boolean canInitiateDocument(String documentTypeName, Person person) {
    DocumentAuthorizer documentAuthorizer = documentDictionaryService.getDocumentAuthorizer(documentTypeName);
    DocumentType documentType = documentTypeService.getDocumentTypeByName(documentTypeName);
    return documentType != null && documentType.isActive() && documentAuthorizer.canInitiate(documentTypeName, person);
}
Also used : DocumentAuthorizer(org.kuali.kfs.krad.document.DocumentAuthorizer) DocumentType(org.kuali.kfs.kew.doctype.bo.DocumentType)

Example 18 with DocumentType

use of org.kuali.kfs.kew.doctype.bo.DocumentType in project cu-kfs by CU-CommunityApps.

the class CuAutoDisapproveDocumentsServiceImplTest method testCheckIffParentDocumentTypeParameterExists.

public final void testCheckIffParentDocumentTypeParameterExists() {
    boolean isExist = autoDisapproveDocumentsService.checkIfParentDocumentTypeParameterExists();
    boolean parameterExists = false;
    if (parameterService.parameterExists(AutoDisapproveDocumentsStep.class, KFSParameterKeyConstants.YearEndAutoDisapprovalConstants.YEAR_END_AUTO_DISAPPROVE_PARENT_DOCUMENT_TYPE)) {
        List<DocumentType> parentDocumentTypes = autoDisapproveDocumentsService.getYearEndAutoDisapproveParentDocumentTypes();
        for (DocumentType parentDocumentType : parentDocumentTypes) {
            if (ObjectUtils.isNotNull(documentTypeService.getDocumentTypeByName(parentDocumentType.getName()))) {
                parameterExists = true;
                break;
            }
        }
    }
    assertTrue("YEAR_END_AUTO_DISAPPROVE_PARENT_DOCUMENT_TYPE System parameter does not exist.", (parameterExists && isExist) || (!parameterExists && !isExist));
}
Also used : DocumentType(org.kuali.kfs.kew.doctype.bo.DocumentType)

Aggregations

DocumentType (org.kuali.kfs.kew.doctype.bo.DocumentType)18 ArrayList (java.util.ArrayList)3 RouteNodeInstance (org.kuali.kfs.kew.engine.node.RouteNodeInstance)3 Timestamp (java.sql.Timestamp)2 Criteria (org.apache.ojb.broker.query.Criteria)2 QueryByCriteria (org.apache.ojb.broker.query.QueryByCriteria)2 RouteNode (org.kuali.kfs.kew.engine.node.RouteNode)2 AutoCancelBatchStep (edu.cornell.kfs.sys.batch.AutoCancelBatchStep)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Account (org.kuali.kfs.coa.businessobject.Account)1 Chart (org.kuali.kfs.coa.businessobject.Chart)1 ObjectCode (org.kuali.kfs.coa.businessobject.ObjectCode)1 ProjectCode (org.kuali.kfs.coa.businessobject.ProjectCode)1 SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)1 SubObjectCode (org.kuali.kfs.coa.businessobject.SubObjectCode)1 DocumentAttributeIndexingQueue (org.kuali.kfs.kew.api.document.attribute.DocumentAttributeIndexingQueue)1 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)1 DocumentAuthorizer (org.kuali.kfs.krad.document.DocumentAuthorizer)1