public static Result transitionToCompleted( TaskArtifact taskArt, double estimatedHours, double additionalHours, IAtsChangeSet changes) { if (taskArt.isInState(TeamState.Completed)) { return Result.TrueResult; } // Assign current user if unassigned try { if (taskArt.getStateMgr().isUnAssigned()) { taskArt.getStateMgr().setAssignee(AtsClientService.get().getUserService().getCurrentUser()); } taskArt .getStateMgr() .updateMetrics( taskArt.getStateDefinition(), additionalHours, 100, true, AtsClientService.get().getUserService().getCurrentUser()); if (estimatedHours > 0.0) { taskArt.setSoleAttributeValue(AtsAttributeTypes.EstimatedHours, estimatedHours); } TransitionHelper helper = new TransitionHelper( "Transition to Completed", Arrays.asList(taskArt), TaskStates.Completed.getName(), null, null, changes, AtsClientService.get().getServices()); IAtsTransitionManager transitionMgr = TransitionFactory.getTransitionManager(helper); TransitionResults results = transitionMgr.handleAll(); if (results.isEmpty()) { return Result.TrueResult; } return new Result("Transition Error %s", results.toString()); } catch (Exception ex) { OseeLog.log(Activator.class, Level.SEVERE, ex); return new Result( "Exception occurred while transitioning to completed (see error log) " + ex.getLocalizedMessage()); } }
public static Result transitionToInWork( TaskArtifact taskArt, IAtsUser toUser, int percentComplete, double additionalHours, IAtsChangeSet changes) throws OseeCoreException { if (taskArt.isInState(TaskStates.InWork)) { return Result.TrueResult; } TransitionHelper helper = new TransitionHelper( "Transition to InWork", Arrays.asList(taskArt), TaskStates.InWork.getName(), Arrays.asList(toUser), null, changes, AtsClientService.get().getServices(), TransitionOption.OverrideAssigneeCheck); IAtsTransitionManager transitionMgr = TransitionFactory.getTransitionManager(helper); TransitionResults results = transitionMgr.handleAll(); if (!results.isEmpty()) { return new Result("Transition Error %s", results.toString()); } if (taskArt.getStateMgr().getPercentComplete(taskArt.getCurrentStateName()) != percentComplete || additionalHours > 0) { taskArt .getStateMgr() .updateMetrics( taskArt.getStateDefinition(), additionalHours, percentComplete, true, AtsClientService.get().getUserService().getCurrentUser()); } if (changes != null) { taskArt.saveSMA(changes); } return Result.TrueResult; }