| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.service.impl; |
| 17 | |
|
| 18 | |
import java.util.List; |
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.log4j.Logger; |
| 22 | |
import org.kuali.rice.core.framework.persistence.jta.TransactionalNoValidationExceptionRollback; |
| 23 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 24 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 25 | |
import org.kuali.rice.kns.dao.MaintenanceDocumentDao; |
| 26 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
| 27 | |
import org.kuali.rice.kns.document.MaintenanceLock; |
| 28 | |
import org.kuali.rice.kns.exception.DocumentTypeAuthorizationException; |
| 29 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
| 30 | |
import org.kuali.rice.kns.service.BusinessObjectAuthorizationService; |
| 31 | |
import org.kuali.rice.kns.service.DocumentService; |
| 32 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
| 33 | |
import org.kuali.rice.kns.service.MaintenanceDocumentService; |
| 34 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 35 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
@TransactionalNoValidationExceptionRollback |
| 42 | 0 | public class MaintenanceDocumentServiceImpl implements MaintenanceDocumentService { |
| 43 | 0 | protected static final Logger LOG = Logger.getLogger(MaintenanceDocumentServiceImpl.class); |
| 44 | |
|
| 45 | |
private MaintenanceDocumentDao maintenanceDocumentDao; |
| 46 | |
private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
| 47 | |
private BusinessObjectAuthorizationService businessObjectAuthorizationService; |
| 48 | |
private DocumentService documentService; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@SuppressWarnings("unchecked") |
| 55 | |
public MaintenanceDocument setupNewMaintenanceDocument(String objectClassName, String documentTypeName, |
| 56 | |
String maintenanceAction) { |
| 57 | 0 | if (StringUtils.isEmpty(objectClassName) && StringUtils.isEmpty(documentTypeName)) { |
| 58 | 0 | throw new IllegalArgumentException("Document type name or bo class not given!"); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | 0 | if (StringUtils.isEmpty(documentTypeName)) { |
| 63 | |
try { |
| 64 | 0 | documentTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(Class |
| 65 | |
.forName(objectClassName)); |
| 66 | |
} |
| 67 | 0 | catch (ClassNotFoundException e) { |
| 68 | 0 | throw new RuntimeException(e); |
| 69 | 0 | } |
| 70 | |
|
| 71 | 0 | if (StringUtils.isEmpty(documentTypeName)) { |
| 72 | 0 | throw new RuntimeException( |
| 73 | |
"documentTypeName is empty; does this Business Object have a maintenance document definition? " |
| 74 | |
+ objectClassName); |
| 75 | |
} |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | 0 | if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) |
| 80 | |
|| KNSConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) { |
| 81 | 0 | Class<? extends BusinessObject> boClass = maintenanceDocumentDictionaryService |
| 82 | |
.getBusinessObjectClass(documentTypeName); |
| 83 | 0 | boolean allowsNewOrCopy = getBusinessObjectAuthorizationService().canCreate(boClass, |
| 84 | |
GlobalVariables.getUserSession().getPerson(), documentTypeName); |
| 85 | 0 | if (!allowsNewOrCopy) { |
| 86 | 0 | LOG.error("Document type " + documentTypeName + " does not allow new or copy actions."); |
| 87 | 0 | throw new DocumentTypeAuthorizationException(GlobalVariables.getUserSession().getPerson() |
| 88 | |
.getPrincipalId(), "newOrCopy", documentTypeName); |
| 89 | |
} |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
try { |
| 94 | 0 | return (MaintenanceDocument) getDocumentService().getNewDocument(documentTypeName); |
| 95 | |
} |
| 96 | 0 | catch (WorkflowException e) { |
| 97 | 0 | LOG.error("Cannot get new maintenance document instance for doc type: " + documentTypeName, e); |
| 98 | 0 | throw new RuntimeException( |
| 99 | |
"Cannot get new maintenance document instance for doc type: " + documentTypeName, e); |
| 100 | |
} |
| 101 | |
} |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
public String getLockingDocumentId(MaintenanceDocument document) { |
| 107 | 0 | return getLockingDocumentId(document.getNewMaintainableObject(), document.getDocumentNumber()); |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
public String getLockingDocumentId(Maintainable maintainable, String documentNumber) { |
| 115 | 0 | String lockingDocId = null; |
| 116 | 0 | List<MaintenanceLock> maintenanceLocks = maintainable.generateMaintenanceLocks(); |
| 117 | 0 | for (MaintenanceLock maintenanceLock : maintenanceLocks) { |
| 118 | 0 | lockingDocId = maintenanceDocumentDao.getLockingDocumentNumber(maintenanceLock.getLockingRepresentation(), |
| 119 | |
documentNumber); |
| 120 | 0 | if (StringUtils.isNotBlank(lockingDocId)) { |
| 121 | 0 | break; |
| 122 | |
} |
| 123 | |
} |
| 124 | 0 | return lockingDocId; |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public void deleteLocks(String documentNumber) { |
| 131 | 0 | maintenanceDocumentDao.deleteLocks(documentNumber); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public void storeLocks(List<MaintenanceLock> maintenanceLocks) { |
| 138 | 0 | maintenanceDocumentDao.storeLocks(maintenanceLocks); |
| 139 | 0 | } |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
public MaintenanceDocumentDao getMaintenanceDocumentDao() { |
| 145 | 0 | return maintenanceDocumentDao; |
| 146 | |
} |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public void setMaintenanceDocumentDao(MaintenanceDocumentDao maintenanceDocumentDao) { |
| 153 | 0 | this.maintenanceDocumentDao = maintenanceDocumentDao; |
| 154 | 0 | } |
| 155 | |
|
| 156 | |
protected MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
| 157 | 0 | return this.maintenanceDocumentDictionaryService; |
| 158 | |
} |
| 159 | |
|
| 160 | |
public void setMaintenanceDocumentDictionaryService( |
| 161 | |
MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService) { |
| 162 | 0 | this.maintenanceDocumentDictionaryService = maintenanceDocumentDictionaryService; |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
protected BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
| 166 | 0 | return this.businessObjectAuthorizationService; |
| 167 | |
} |
| 168 | |
|
| 169 | |
public void setBusinessObjectAuthorizationService( |
| 170 | |
BusinessObjectAuthorizationService businessObjectAuthorizationService) { |
| 171 | 0 | this.businessObjectAuthorizationService = businessObjectAuthorizationService; |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
protected DocumentService getDocumentService() { |
| 175 | 0 | return this.documentService; |
| 176 | |
} |
| 177 | |
|
| 178 | |
public void setDocumentService(DocumentService documentService) { |
| 179 | 0 | this.documentService = documentService; |
| 180 | 0 | } |
| 181 | |
|
| 182 | |
} |