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