em.persist( group );
em.getTransaction().commit();
}
public void addTask(Task task, ContentData contentData) {
TaskData taskData = task.getTaskData();
// new tasks start off with status created
taskData.setStatus( Status.Created );
// execute "addTask" rules
if (ruleBases != null) {
RuleBase ruleBase = ruleBases.get("addTask");
if (ruleBase != null) {
StatefulSession session = ruleBase.newStatefulSession();
Map<String, Object> globals = this.globals.get("addTask");
if (globals != null) {
for (Map.Entry<String, Object> entry: globals.entrySet()) {
session.setGlobal(entry.getKey(), entry.getValue());
}
}
TaskServiceRequest request = new TaskServiceRequest("addTask", null, null);
session.setGlobal("request", request);
session.insert(task);
session.insert(contentData);
session.fireAllRules();
if (!request.isAllowed()) {
String error = "Cannot add Task:\n";
if (request.getReasons() != null) {
for (String reason: request.getReasons()) {
error += reason + "\n";
}
}
throw new RuntimeException(error);
}
}
}
if ( task.getPeopleAssignments() != null ) {
List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
if ( potentialOwners.size() == 1 ) {
// if there is a single potential owner, assign and set status to Reserved
OrganizationalEntity potentialOwner = potentialOwners.get( 0 );
// if there is a single potential user owner, assign and set status to Reserved
if(potentialOwner instanceof User){
taskData.setActualOwner( (User) potentialOwners.get( 0 ) );
taskData.setStatus( Status.Reserved );
}
//If there is a group set as potentialOwners, set the status to Ready ??
if(potentialOwner instanceof Group){
taskData.setStatus( Status.Ready );
}
} else if ( potentialOwners.size() > 1 ) {
// multiple potential owners, so set to Ready so one can claim.
taskData.setStatus( Status.Ready );
} else {
//@TODO we have no potential owners
}
} else {
//@TODO we have no potential owners
}
// set the CreatedOn date if it's not already set
if ( taskData.getCreatedOn() == null ) {
taskData.setCreatedOn( new Date() );
}
//@FIXME for now we activate on creation, unless date is supplied
if ( taskData.getActivationTime() == null ) {
taskData.setActivationTime( taskData.getCreatedOn() );
}
em.getTransaction().begin();
em.persist( task );
if (contentData != null) {
Content content = new Content();
content.setContent(contentData.getContent());
em.persist( content );
taskData.setDocumentAccessType( contentData.getAccessType() );
taskData.setDocumentType( contentData.getType() );
taskData.setDocumentContentId( content.getId() );
}
em.getTransaction().commit();
long now = System.currentTimeMillis();
// schedule after it's been persisted, otherwise the id's won't be assigned