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() + ")");
}
}
}
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);
}
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));
}
Aggregations