| 1 | |
package org.kuali.student.r2.core.class1.process.service.impl; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Calendar; |
| 5 | |
import java.util.Collections; |
| 6 | |
import java.util.Comparator; |
| 7 | |
import java.util.Date; |
| 8 | |
import java.util.List; |
| 9 | |
|
| 10 | |
import javax.jws.WebParam; |
| 11 | |
|
| 12 | |
import org.apache.commons.lang.StringUtils; |
| 13 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
| 14 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 15 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
| 16 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 17 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
| 18 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
| 19 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 20 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 21 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 22 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 23 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 24 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
| 25 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
| 26 | |
import org.kuali.student.r2.common.util.constants.ProcessServiceConstants; |
| 27 | |
import org.kuali.student.r2.core.class1.process.dao.CheckDao; |
| 28 | |
import org.kuali.student.r2.core.class1.process.dao.InstructionDao; |
| 29 | |
import org.kuali.student.r2.core.class1.process.dao.ProcessDao; |
| 30 | |
import org.kuali.student.r2.core.process.dto.CheckInfo; |
| 31 | |
import org.kuali.student.r2.core.process.dto.InstructionInfo; |
| 32 | |
import org.kuali.student.r2.core.process.dto.ProcessCategoryInfo; |
| 33 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
| 34 | |
import org.kuali.student.r2.core.class1.process.model.CheckEntity; |
| 35 | |
import org.kuali.student.r2.core.class1.process.model.InstructionEntity; |
| 36 | |
import org.kuali.student.r2.core.class1.process.model.ProcessEntity; |
| 37 | |
import org.kuali.student.r2.core.process.service.ProcessService; |
| 38 | |
import org.kuali.student.r2.core.state.service.StateService; |
| 39 | |
import org.springframework.transaction.annotation.Transactional; |
| 40 | |
|
| 41 | 0 | public class ProcessServiceImpl implements ProcessService { |
| 42 | |
|
| 43 | |
private CheckDao checkDao; |
| 44 | |
private InstructionDao instructionDao; |
| 45 | |
private ProcessDao processDao; |
| 46 | |
private StateService stateService; |
| 47 | |
|
| 48 | |
public CheckDao getCheckDao() { |
| 49 | 0 | return checkDao; |
| 50 | |
} |
| 51 | |
|
| 52 | |
public void setCheckDao(CheckDao checkDao) { |
| 53 | 0 | this.checkDao = checkDao; |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public InstructionDao getInstructionDao() { |
| 57 | 0 | return instructionDao; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public void setInstructionDao(InstructionDao instructionDao) { |
| 61 | 0 | this.instructionDao = instructionDao; |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public ProcessDao getProcessDao() { |
| 65 | 0 | return processDao; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public void setProcessDao(ProcessDao processDao) { |
| 69 | 0 | this.processDao = processDao; |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public StateService getStateService() { |
| 73 | 0 | return stateService; |
| 74 | |
} |
| 75 | |
|
| 76 | |
public void setStateService(StateService stateService) { |
| 77 | 0 | this.stateService = stateService; |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public ProcessCategoryInfo getProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
| 82 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 83 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 84 | |
OperationFailedException, PermissionDeniedException { |
| 85 | 0 | throw new OperationFailedException("Method not implemented."); |
| 86 | |
|
| 87 | |
} |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
public List<ProcessCategoryInfo> getProcessCategoriesByIds( |
| 91 | |
@WebParam(name = "processCategoryIds") List<String> processCategoryIds, |
| 92 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 93 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 94 | |
OperationFailedException, PermissionDeniedException { |
| 95 | 0 | throw new OperationFailedException("Method not implemented."); |
| 96 | |
|
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public List<String> getProcessCategoryIdsByType(@WebParam(name = "processTypeKey") String processTypeKey, |
| 101 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 102 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 103 | |
PermissionDeniedException { |
| 104 | 0 | throw new OperationFailedException("Method not implemented."); |
| 105 | |
|
| 106 | |
} |
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public List<ProcessCategoryInfo> getProcessCategoriesForProcess(@WebParam(name = "processKey") String processKey, |
| 110 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 111 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 112 | |
PermissionDeniedException { |
| 113 | 0 | throw new OperationFailedException("Method not implemented."); |
| 114 | |
|
| 115 | |
} |
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public List<String> searchForProcessCategoryIds(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 119 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 120 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 121 | 0 | throw new OperationFailedException("Method not implemented."); |
| 122 | |
|
| 123 | |
} |
| 124 | |
|
| 125 | |
@Override |
| 126 | |
public List<ProcessCategoryInfo> searchForProcessCategories(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 127 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 128 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 129 | |
PermissionDeniedException { |
| 130 | 0 | throw new OperationFailedException("Method not implemented."); |
| 131 | |
|
| 132 | |
} |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public List<ValidationResultInfo> validateProcessCategory( |
| 136 | |
@WebParam(name = "validationTypeKey") String validationTypeKey, |
| 137 | |
@WebParam(name = "processCategoryInfo") ProcessCategoryInfo processCategoryInfo, |
| 138 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 139 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 140 | 0 | throw new OperationFailedException("Method not implemented."); |
| 141 | |
|
| 142 | |
} |
| 143 | |
|
| 144 | |
@Override |
| 145 | |
public ProcessCategoryInfo createProcessCategory(@WebParam(name = "processInfo") ProcessCategoryInfo processInfo, |
| 146 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 147 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, |
| 148 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 149 | 0 | throw new OperationFailedException("Method not implemented."); |
| 150 | |
|
| 151 | |
} |
| 152 | |
|
| 153 | |
@Override |
| 154 | |
public ProcessCategoryInfo updateProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
| 155 | |
@WebParam(name = "processInfo") ProcessCategoryInfo processInfo, |
| 156 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
| 157 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 158 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
| 159 | 0 | throw new OperationFailedException("Method not implemented."); |
| 160 | |
|
| 161 | |
} |
| 162 | |
|
| 163 | |
@Override |
| 164 | |
public StatusInfo deleteProcessCategory(@WebParam(name = "processCategoryId") String processCategoryId, |
| 165 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 166 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 167 | 0 | throw new OperationFailedException("Method not implemented."); |
| 168 | |
|
| 169 | |
} |
| 170 | |
|
| 171 | |
@Override |
| 172 | |
public StatusInfo addProcessToProcessCategory(@WebParam(name = "processKey") String processKey, |
| 173 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
| 174 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws AlreadyExistsException, |
| 175 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 176 | |
OperationFailedException, PermissionDeniedException { |
| 177 | 0 | throw new OperationFailedException("Method not implemented."); |
| 178 | |
|
| 179 | |
} |
| 180 | |
|
| 181 | |
@Override |
| 182 | |
public StatusInfo removeProcessFromProcessCategory(@WebParam(name = "processKey") String processKey, |
| 183 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
| 184 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws AlreadyExistsException, |
| 185 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 186 | |
OperationFailedException, PermissionDeniedException { |
| 187 | 0 | throw new OperationFailedException("Method not implemented."); |
| 188 | |
|
| 189 | |
} |
| 190 | |
|
| 191 | |
@Override |
| 192 | |
public ProcessInfo getProcess(@WebParam(name = "processKey") String processKey, |
| 193 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 194 | |
InvalidParameterException, |
| 195 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 196 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
| 197 | 0 | if (processEntity == null) { |
| 198 | 0 | throw new DoesNotExistException(processKey); |
| 199 | |
} |
| 200 | |
|
| 201 | 0 | return processEntity.toDto(); |
| 202 | |
} |
| 203 | |
|
| 204 | |
@Override |
| 205 | |
public List<ProcessInfo> getProcessesByKeys(@WebParam(name = "processKeys") List<String> processKeys, |
| 206 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 207 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 208 | 0 | List<ProcessEntity> processEntities = processDao.findByIds(processKeys); |
| 209 | 0 | if (processEntities == null || processEntities.isEmpty()) { |
| 210 | 0 | throw new DoesNotExistException("No records found"); |
| 211 | |
} |
| 212 | 0 | List<ProcessInfo> processInfoList = new ArrayList<ProcessInfo>(); |
| 213 | 0 | for (ProcessEntity processEntity : processEntities) { |
| 214 | 0 | if (processEntity == null) { |
| 215 | 0 | throw new DoesNotExistException(); |
| 216 | |
} |
| 217 | 0 | processInfoList.add(processEntity.toDto()); |
| 218 | |
} |
| 219 | 0 | return processInfoList; |
| 220 | |
} |
| 221 | |
|
| 222 | |
@Override |
| 223 | |
public List<String> getProcessKeysByType(@WebParam(name = "processTypeKey") String processTypeKey, |
| 224 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 225 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 226 | 0 | List<ProcessEntity> processEntities = processDao.getByProcessTypeId(processTypeKey); |
| 227 | |
|
| 228 | 0 | List<String> processIds = new ArrayList<String>(); |
| 229 | 0 | for (ProcessEntity processEntity : processEntities) { |
| 230 | 0 | processIds.add(processEntity.getId()); |
| 231 | |
} |
| 232 | |
|
| 233 | 0 | return processIds; |
| 234 | |
} |
| 235 | |
|
| 236 | |
@Override |
| 237 | |
public List<ProcessInfo> getProcessesForProcessCategory( |
| 238 | |
@WebParam(name = "processCategoryId") String processCategoryId, |
| 239 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 240 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 241 | |
PermissionDeniedException { |
| 242 | 0 | throw new OperationFailedException("Method not implemented."); |
| 243 | |
|
| 244 | |
} |
| 245 | |
|
| 246 | |
@Override |
| 247 | |
public List<String> searchForProcessKeys(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 248 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 249 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 250 | 0 | throw new OperationFailedException("Method not implemented."); |
| 251 | |
|
| 252 | |
} |
| 253 | |
|
| 254 | |
@Override |
| 255 | |
public List<ProcessInfo> searchForProcesss(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 256 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 257 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 258 | 0 | throw new OperationFailedException("Method not implemented."); |
| 259 | |
|
| 260 | |
} |
| 261 | |
|
| 262 | |
@Override |
| 263 | |
public List<ValidationResultInfo> validateProcess(@WebParam(name = "validationTypeKey") String validationTypeKey, |
| 264 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
| 265 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 266 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
| 267 | |
PermissionDeniedException { |
| 268 | 0 | throw new OperationFailedException("Method not implemented."); |
| 269 | |
|
| 270 | |
} |
| 271 | |
|
| 272 | |
@Override |
| 273 | |
@Transactional(readOnly = false) |
| 274 | |
public ProcessInfo createProcess(@WebParam(name = "processKey") String processKey, |
| 275 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
| 276 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 277 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, |
| 278 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 279 | |
|
| 280 | 0 | ProcessEntity existing = processDao.find(processKey); |
| 281 | 0 | if (existing != null) { |
| 282 | 0 | throw new AlreadyExistsException(processKey); |
| 283 | |
} |
| 284 | |
|
| 285 | 0 | ProcessEntity process = new ProcessEntity(processInfo); |
| 286 | |
|
| 287 | 0 | process.setId(processKey); |
| 288 | |
|
| 289 | 0 | processDao.persist(process); |
| 290 | |
|
| 291 | 0 | ProcessEntity retrieved = processDao.find(processKey); |
| 292 | |
|
| 293 | 0 | return retrieved.toDto(); |
| 294 | |
} |
| 295 | |
|
| 296 | |
@Override |
| 297 | |
@Transactional(readOnly = false) |
| 298 | |
public ProcessInfo updateProcess(@WebParam(name = "processKey") String processKey, |
| 299 | |
@WebParam(name = "processInfo") ProcessInfo processInfo, |
| 300 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 301 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
| 302 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, |
| 303 | |
VersionMismatchException { |
| 304 | |
|
| 305 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
| 306 | |
|
| 307 | 0 | if (processEntity == null) { |
| 308 | 0 | throw new DoesNotExistException(processKey); |
| 309 | |
} |
| 310 | |
|
| 311 | 0 | ProcessEntity toUpdate = new ProcessEntity(processInfo); |
| 312 | |
|
| 313 | 0 | toUpdate.setProcessState(ProcessServiceConstants.PROCESS_LIFECYCLE_KEY); |
| 314 | |
|
| 315 | 0 | toUpdate.setProcessType(processInfo.getTypeKey()); |
| 316 | |
|
| 317 | 0 | processDao.merge(toUpdate); |
| 318 | 0 | return processDao.find(toUpdate.getId()).toDto(); |
| 319 | |
|
| 320 | |
} |
| 321 | |
|
| 322 | |
@Override |
| 323 | |
@Transactional(readOnly = false) |
| 324 | |
public StatusInfo deleteProcess(@WebParam(name = "processKey") String processKey, |
| 325 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 326 | |
InvalidParameterException, |
| 327 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 328 | |
|
| 329 | 0 | ProcessEntity processEntity = processDao.find(processKey); |
| 330 | 0 | StatusInfo status = new StatusInfo(); |
| 331 | |
|
| 332 | 0 | if (processEntity == null) { |
| 333 | 0 | status.setSuccess(false); |
| 334 | 0 | return status; |
| 335 | |
} |
| 336 | |
|
| 337 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcess(processKey); |
| 338 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 339 | 0 | instructionDao.remove(instructionEntity); |
| 340 | |
} |
| 341 | |
|
| 342 | 0 | processDao.remove(processEntity); |
| 343 | |
|
| 344 | 0 | status.setSuccess(true); |
| 345 | 0 | return status; |
| 346 | |
|
| 347 | |
} |
| 348 | |
|
| 349 | |
@Override |
| 350 | |
public CheckInfo getCheck(@WebParam(name = "checkKey") String checkKey, |
| 351 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 352 | |
InvalidParameterException, |
| 353 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 354 | 0 | CheckEntity checkEntity = checkDao.find(checkKey); |
| 355 | 0 | if (checkEntity == null) { |
| 356 | 0 | throw new DoesNotExistException(checkKey); |
| 357 | |
} |
| 358 | 0 | return checkEntity.toDto(); |
| 359 | |
} |
| 360 | |
|
| 361 | |
@Override |
| 362 | |
public List<CheckInfo> getChecksByIds(@WebParam(name = "checkKeys") List<String> checkKeys, |
| 363 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 364 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 365 | 0 | List<CheckEntity> checkEntities = checkDao.findByIds(checkKeys); |
| 366 | 0 | if (checkEntities == null || checkEntities.isEmpty()) { |
| 367 | 0 | throw new DoesNotExistException("No records found"); |
| 368 | |
} |
| 369 | 0 | List<CheckInfo> checkInfoList = new ArrayList<CheckInfo>(); |
| 370 | 0 | for (CheckEntity checkEntity : checkEntities) { |
| 371 | 0 | if (checkEntity == null) { |
| 372 | 0 | throw new DoesNotExistException(); |
| 373 | |
} |
| 374 | 0 | checkInfoList.add(checkEntity.toDto()); |
| 375 | |
} |
| 376 | 0 | return checkInfoList; |
| 377 | |
} |
| 378 | |
|
| 379 | |
@Override |
| 380 | |
public List<String> getCheckKeysByType(@WebParam(name = "checkTypeKey") String checkTypeKey, |
| 381 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 382 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 383 | 0 | List<CheckEntity> checkEntities = checkDao.getByCheckTypeId(checkTypeKey); |
| 384 | |
|
| 385 | 0 | List<String> checkIds = new ArrayList<String>(); |
| 386 | 0 | for (CheckEntity processEntity : checkEntities) { |
| 387 | 0 | checkIds.add(processEntity.getId()); |
| 388 | |
} |
| 389 | |
|
| 390 | 0 | return checkIds; |
| 391 | |
} |
| 392 | |
|
| 393 | |
@Override |
| 394 | |
public List<String> searchForCheckKeys(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 395 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 396 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 397 | 0 | throw new OperationFailedException("Method not implemented."); |
| 398 | |
|
| 399 | |
} |
| 400 | |
|
| 401 | |
@Override |
| 402 | |
public List<CheckInfo> searchForChecks(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 403 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 404 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 405 | 0 | throw new OperationFailedException("Method not implemented."); |
| 406 | |
|
| 407 | |
} |
| 408 | |
|
| 409 | |
@Override |
| 410 | |
public List<ValidationResultInfo> validateCheck(@WebParam(name = "validationTypeKey") String validationTypeKey, |
| 411 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, |
| 412 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 413 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
| 414 | |
PermissionDeniedException { |
| 415 | 0 | throw new OperationFailedException("Method not implemented."); |
| 416 | |
|
| 417 | |
} |
| 418 | |
|
| 419 | |
@Override |
| 420 | |
@Transactional(readOnly = false) |
| 421 | |
public CheckInfo createCheck(@WebParam(name = "checkKey") String checkKey, |
| 422 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 423 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, |
| 424 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 425 | |
|
| 426 | 0 | if (checkDao.find(checkKey) != null) { |
| 427 | 0 | throw new AlreadyExistsException(checkInfo.getKey()); |
| 428 | |
} |
| 429 | |
|
| 430 | 0 | CheckEntity checkEntity = new CheckEntity(checkInfo); |
| 431 | 0 | checkEntity.setId(checkKey); |
| 432 | |
|
| 433 | 0 | checkEntity.setCheckType(checkInfo.getTypeKey()); |
| 434 | 0 | checkEntity.setCheckState(ProcessServiceConstants.CHECK_LIFECYCLE_KEY); |
| 435 | |
|
| 436 | 0 | if (StringUtils.isNotBlank(checkInfo.getProcessKey())) { |
| 437 | 0 | ProcessEntity process = processDao.find(checkInfo.getProcessKey()); |
| 438 | 0 | if (null == process) { |
| 439 | 0 | throw new InvalidParameterException("Check processKey not valid."); |
| 440 | |
} |
| 441 | 0 | checkEntity.setProcess(process); |
| 442 | 0 | } else { |
| 443 | 0 | checkEntity.setProcess(null); |
| 444 | |
} |
| 445 | |
|
| 446 | 0 | checkDao.persist(checkEntity); |
| 447 | |
|
| 448 | 0 | CheckEntity retrieved = checkDao.find(checkKey); |
| 449 | |
|
| 450 | 0 | return retrieved.toDto(); |
| 451 | |
|
| 452 | |
} |
| 453 | |
|
| 454 | |
@Override |
| 455 | |
@Transactional(readOnly = false) |
| 456 | |
public CheckInfo updateCheck(@WebParam(name = "checkKey") String checkKey, |
| 457 | |
@WebParam(name = "checkInfo") CheckInfo checkInfo, @WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 458 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
| 459 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, |
| 460 | |
VersionMismatchException { |
| 461 | |
|
| 462 | 0 | CheckEntity exists = checkDao.find(checkKey); |
| 463 | |
|
| 464 | 0 | if (exists == null) { |
| 465 | 0 | throw new DoesNotExistException(checkKey); |
| 466 | |
} |
| 467 | |
|
| 468 | 0 | CheckEntity toUpdate = new CheckEntity(checkInfo); |
| 469 | |
|
| 470 | 0 | toUpdate.setCheckType(checkInfo.getTypeKey()); |
| 471 | 0 | toUpdate.setCheckState(ProcessServiceConstants.CHECK_LIFECYCLE_KEY); |
| 472 | |
|
| 473 | 0 | if (StringUtils.isNotBlank(checkInfo.getProcessKey())) { |
| 474 | 0 | ProcessEntity process = processDao.find(checkInfo.getProcessKey()); |
| 475 | 0 | if (null == process) { |
| 476 | 0 | throw new InvalidParameterException("Check processKey not valid."); |
| 477 | |
} |
| 478 | 0 | toUpdate.setProcess(process); |
| 479 | 0 | } else { |
| 480 | 0 | toUpdate.setProcess(null); |
| 481 | |
} |
| 482 | |
|
| 483 | 0 | checkDao.merge(toUpdate); |
| 484 | |
|
| 485 | 0 | CheckEntity retrieved = checkDao.find(checkInfo.getKey()); |
| 486 | |
|
| 487 | 0 | return retrieved.toDto(); |
| 488 | |
|
| 489 | |
} |
| 490 | |
|
| 491 | |
@Override |
| 492 | |
@Transactional(readOnly = false) |
| 493 | |
public StatusInfo deleteCheck(@WebParam(name = "checkKey") String checkKey, |
| 494 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 495 | |
InvalidParameterException, |
| 496 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 497 | |
|
| 498 | 0 | CheckEntity exists = checkDao.find(checkKey); |
| 499 | 0 | StatusInfo status = new StatusInfo(); |
| 500 | |
|
| 501 | 0 | if (exists == null) { |
| 502 | 0 | status.setSuccess(false); |
| 503 | 0 | return status; |
| 504 | |
} |
| 505 | |
|
| 506 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByCheck(checkKey); |
| 507 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 508 | 0 | instructionDao.remove(instructionEntity); |
| 509 | |
} |
| 510 | |
|
| 511 | 0 | checkDao.remove(exists); |
| 512 | 0 | status.setSuccess(true); |
| 513 | 0 | return status; |
| 514 | |
} |
| 515 | |
|
| 516 | |
@Override |
| 517 | |
public InstructionInfo getInstruction(@WebParam(name = "instructionId") String instructionId, |
| 518 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 519 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 520 | 0 | InstructionEntity instructionEntity = instructionDao.find(instructionId); |
| 521 | 0 | if (instructionEntity == null) { |
| 522 | 0 | throw new DoesNotExistException(instructionId); |
| 523 | |
} |
| 524 | 0 | return instructionEntity.toDto(); |
| 525 | |
} |
| 526 | |
|
| 527 | |
@Override |
| 528 | |
public List<InstructionInfo> getInstructionsByIds(@WebParam(name = "instructionIds") List<String> instructionIds, |
| 529 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 530 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 531 | |
OperationFailedException, PermissionDeniedException { |
| 532 | 0 | List<InstructionEntity> instructionEntities = instructionDao.findByIds(instructionIds); |
| 533 | 0 | if (instructionEntities == null || instructionEntities.isEmpty()) { |
| 534 | 0 | throw new DoesNotExistException(); |
| 535 | |
} |
| 536 | 0 | List<InstructionInfo> instructionInfos = new ArrayList<InstructionInfo>(); |
| 537 | |
|
| 538 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 539 | 0 | if (instructionEntity == null) { |
| 540 | 0 | throw new DoesNotExistException(); |
| 541 | |
} |
| 542 | 0 | instructionInfos.add(instructionEntity.toDto()); |
| 543 | |
} |
| 544 | 0 | return instructionInfos; |
| 545 | |
} |
| 546 | |
|
| 547 | |
@Override |
| 548 | |
public List<String> getInstructionIdsByType(@WebParam(name = "instructionTypeKey") String instructionTypeKey, |
| 549 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 550 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 551 | |
PermissionDeniedException { |
| 552 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByInstructionTypeId(instructionTypeKey); |
| 553 | |
|
| 554 | 0 | List<String> instructionIds = new ArrayList<String>(); |
| 555 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 556 | 0 | instructionIds.add(instructionEntity.getId()); |
| 557 | |
} |
| 558 | |
|
| 559 | 0 | return instructionIds; |
| 560 | |
} |
| 561 | |
|
| 562 | |
@Override |
| 563 | |
public List<InstructionInfo> getInstructionsByProcess(@WebParam(name = "processKey") String processKey, |
| 564 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 565 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 566 | 0 | List<InstructionInfo> instructionInfos = new ArrayList<InstructionInfo>(); |
| 567 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcess(processKey); |
| 568 | 0 | if (null != instructionEntities) { |
| 569 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 570 | 0 | instructionInfos.add(instructionEntity.toDto()); |
| 571 | |
} |
| 572 | |
} |
| 573 | 0 | return instructionInfos; |
| 574 | |
} |
| 575 | |
|
| 576 | |
@Override |
| 577 | |
public List<InstructionInfo> getInstructionsByCheck(@WebParam(name = "checkKey") String checkKey, |
| 578 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 579 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 580 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByCheck(checkKey); |
| 581 | 0 | List<InstructionInfo> instructionInfoList = new ArrayList<InstructionInfo>(); |
| 582 | |
|
| 583 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 584 | 0 | instructionInfoList.add(instructionEntity.toDto()); |
| 585 | |
} |
| 586 | |
|
| 587 | 0 | return instructionInfoList; |
| 588 | |
} |
| 589 | |
|
| 590 | |
@Override |
| 591 | |
public List<InstructionInfo> getInstructionsByProcessAndCheck(@WebParam(name = "checkKey") String checkKey, |
| 592 | |
@WebParam(name = "processKey") String processKey, |
| 593 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 594 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
| 595 | |
PermissionDeniedException { |
| 596 | 0 | List<InstructionEntity> instructionEntities = instructionDao.getByProcessAndCheck(processKey, checkKey); |
| 597 | 0 | List<InstructionInfo> instructionInfoList = new ArrayList<InstructionInfo>(); |
| 598 | |
|
| 599 | 0 | for (InstructionEntity instructionEntity : instructionEntities) { |
| 600 | 0 | instructionInfoList.add(instructionEntity.toDto()); |
| 601 | |
} |
| 602 | |
|
| 603 | 0 | return instructionInfoList; |
| 604 | |
} |
| 605 | |
|
| 606 | |
@Override |
| 607 | |
public List<String> searchForInstructionIds(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 608 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws InvalidParameterException, |
| 609 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 610 | 0 | throw new OperationFailedException("Method not implemented."); |
| 611 | |
|
| 612 | |
} |
| 613 | |
|
| 614 | |
@Override |
| 615 | |
public List<InstructionInfo> searchForInstructions(@WebParam(name = "criteria") QueryByCriteria criteria, |
| 616 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 617 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 618 | |
PermissionDeniedException { |
| 619 | 0 | throw new OperationFailedException("Method not implemented."); |
| 620 | |
|
| 621 | |
} |
| 622 | |
|
| 623 | |
@Override |
| 624 | |
public List<ValidationResultInfo> validateInstruction( |
| 625 | |
@WebParam(name = "validationTypeKey") String validationTypeKey, |
| 626 | |
@WebParam(name = "processKey") String processKey, |
| 627 | |
@WebParam(name = "checkKey") String checkKey, |
| 628 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
| 629 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 630 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 631 | |
OperationFailedException, PermissionDeniedException { |
| 632 | 0 | throw new OperationFailedException("Method not implemented."); |
| 633 | |
|
| 634 | |
} |
| 635 | |
|
| 636 | |
@Override |
| 637 | |
@Transactional(readOnly = false) |
| 638 | |
public InstructionInfo createInstruction(@WebParam(name = "processKey") String processKey, |
| 639 | |
@WebParam(name = "checkKey") String checkKey, |
| 640 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
| 641 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
| 642 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, |
| 643 | |
ReadOnlyException { |
| 644 | 0 | InstructionEntity instruction = new InstructionEntity(instructionInfo); |
| 645 | 0 | instruction.setInstructionState(instructionInfo.getStateKey()); |
| 646 | 0 | instruction.setInstructionType(instructionInfo.getTypeKey()); |
| 647 | |
|
| 648 | 0 | List<String> appliedAtpTypes = instructionInfo.getAppliedAtpTypeKeys(); |
| 649 | 0 | if (appliedAtpTypes.contains(null)) { |
| 650 | 0 | throw new InvalidParameterException("Could not find all appliedAtpTypes: " |
| 651 | |
+ instructionInfo.getAppliedAtpTypeKeys()); |
| 652 | |
} |
| 653 | 0 | instruction.setAppliedAtpTypes(appliedAtpTypes); |
| 654 | |
|
| 655 | 0 | ProcessEntity process = processDao.find(processKey); |
| 656 | 0 | if (null == process) { |
| 657 | 0 | throw new InvalidParameterException("processKey"); |
| 658 | |
} |
| 659 | 0 | instruction.setProcess(process); |
| 660 | |
|
| 661 | 0 | CheckEntity check = checkDao.find(checkKey); |
| 662 | 0 | if (null == check) { |
| 663 | 0 | throw new InvalidParameterException("checkKey"); |
| 664 | |
} |
| 665 | 0 | instruction.setCheck(check); |
| 666 | |
|
| 667 | 0 | instructionDao.persist(instruction); |
| 668 | 0 | return instruction.toDto(); |
| 669 | |
} |
| 670 | |
|
| 671 | |
@Override |
| 672 | |
@Transactional(readOnly = false) |
| 673 | |
public InstructionInfo updateInstruction(@WebParam(name = "instructionId") String instructionId, |
| 674 | |
@WebParam(name = "instructionInfo") InstructionInfo instructionInfo, |
| 675 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DataValidationErrorException, |
| 676 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
| 677 | |
OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
| 678 | 0 | InstructionEntity exists = instructionDao.find(instructionId); |
| 679 | |
|
| 680 | 0 | if (exists == null) { |
| 681 | 0 | throw new DoesNotExistException(instructionId); |
| 682 | |
} |
| 683 | |
|
| 684 | 0 | InstructionEntity toUpdate = new InstructionEntity(instructionInfo); |
| 685 | 0 | toUpdate.setInstructionState( |
| 686 | |
instructionInfo.getStateKey()); |
| 687 | 0 | toUpdate.setInstructionType(instructionInfo.getTypeKey()); |
| 688 | |
|
| 689 | 0 | List<String> appliedAtpTypes = instructionInfo.getAppliedAtpTypeKeys(); |
| 690 | 0 | if (appliedAtpTypes.contains(null)) { |
| 691 | 0 | throw new InvalidParameterException("Could not find all appliedAtpTypes: " |
| 692 | |
+ instructionInfo.getAppliedAtpTypeKeys()); |
| 693 | |
} |
| 694 | 0 | toUpdate.setAppliedAtpTypes(appliedAtpTypes); |
| 695 | |
|
| 696 | 0 | ProcessEntity process = processDao.find(instructionInfo.getProcessKey()); |
| 697 | 0 | if (null == process) { |
| 698 | 0 | throw new InvalidParameterException("Instruction processKey"); |
| 699 | |
} |
| 700 | 0 | toUpdate.setProcess(process); |
| 701 | |
|
| 702 | 0 | CheckEntity check = checkDao.find(instructionInfo.getCheckKey()); |
| 703 | 0 | if (null == check) { |
| 704 | 0 | throw new InvalidParameterException("Instruction checkKey"); |
| 705 | |
} |
| 706 | 0 | toUpdate.setCheck(check); |
| 707 | |
|
| 708 | 0 | instructionDao.merge(toUpdate); |
| 709 | |
|
| 710 | 0 | return instructionDao.find(instructionId).toDto(); |
| 711 | |
|
| 712 | |
} |
| 713 | |
|
| 714 | |
@Override |
| 715 | |
@Transactional(readOnly = false) |
| 716 | |
public StatusInfo deleteInstruction(@WebParam(name = "instructionId") String instructionId, |
| 717 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, |
| 718 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 719 | |
|
| 720 | 0 | InstructionEntity exists = instructionDao.find(instructionId); |
| 721 | 0 | StatusInfo status = new StatusInfo(); |
| 722 | |
|
| 723 | 0 | if (exists == null) { |
| 724 | 0 | status.setSuccess(false); |
| 725 | 0 | return status; |
| 726 | |
} |
| 727 | |
|
| 728 | 0 | instructionDao.remove(exists); |
| 729 | |
|
| 730 | 0 | status.setSuccess(true); |
| 731 | 0 | return status; |
| 732 | |
} |
| 733 | |
|
| 734 | |
@Override |
| 735 | |
public List<InstructionInfo> getInstructionsForEvaluation(@WebParam(name = "processKey") String processKey, |
| 736 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) |
| 737 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, |
| 738 | |
PermissionDeniedException { |
| 739 | 0 | List<InstructionInfo> instructions = getInstructionsByProcess(processKey, contextInfo); |
| 740 | 0 | for (InstructionInfo instruction : instructions) { |
| 741 | 0 | if (!ProcessServiceConstants.PROCESS_ENABLED_STATE_KEY.equals(instruction.getStateKey())) { |
| 742 | |
|
| 743 | 0 | instructions.remove(instruction); |
| 744 | 0 | } else if (!isInstructionCurrent(instruction, contextInfo)) { |
| 745 | |
|
| 746 | 0 | instructions.remove(instruction); |
| 747 | |
} |
| 748 | |
} |
| 749 | |
|
| 750 | |
|
| 751 | 0 | Collections.sort(instructions, new Comparator<InstructionInfo>() { |
| 752 | |
@Override |
| 753 | |
public int compare(InstructionInfo instruction1, InstructionInfo instruction2) { |
| 754 | 0 | return instruction1.getPosition().compareTo(instruction2.getPosition()); |
| 755 | |
} |
| 756 | |
}); |
| 757 | |
|
| 758 | 0 | return instructions; |
| 759 | |
} |
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
|
| 777 | |
private boolean isInstructionCurrent(InstructionInfo instruction, ContextInfo contextInfo) |
| 778 | |
throws InvalidParameterException { |
| 779 | 0 | boolean result = false; |
| 780 | 0 | Date effectiveDate = instruction.getEffectiveDate(); |
| 781 | 0 | Date expirationDate = instruction.getExpirationDate(); |
| 782 | 0 | Date currentDate = Calendar.getInstance().getTime(); |
| 783 | |
|
| 784 | |
|
| 785 | 0 | if (null == effectiveDate) { |
| 786 | 0 | throw new InvalidParameterException("Instruction does not have an effective date."); |
| 787 | |
} |
| 788 | |
|
| 789 | 0 | if (!effectiveDate.after(currentDate)) { |
| 790 | 0 | if (null == expirationDate) { |
| 791 | 0 | result = true; |
| 792 | 0 | } else if (!expirationDate.before(currentDate)) { |
| 793 | 0 | result = true; |
| 794 | |
} |
| 795 | |
} |
| 796 | |
|
| 797 | 0 | return result; |
| 798 | |
} |
| 799 | |
|
| 800 | |
} |