if (! CVUtility.isModuleVisible("Tasks", userId, this.dataSource))
{
throw new AuthorizationFailedException("User does not have access to Tasks");
}
InitialContext ic = CVUtility.getInitialContext();
ActivityHelperLocalHome home = (ActivityHelperLocalHome)ic.lookup("local/ActivityHelper");
ActivityHelperLocal remote = (ActivityHelperLocal) home.create();
remote.setDataSource(dataSource);
ActivityVO actVo = new ActivityVO();
actVo.setEntityID(0);
actVo.setIndividualID(tvo.getIndividualID());
actVo.setActivityType(8);
actVo.setOwner(userId);
actVo.setTitle(tvo.getTitle());
actVo.setActivityDetails(tvo.getActivityDetails());
actVo.setActivityStartDate(tvo.getStart());
actVo.setActivityDueDate(tvo.getEnd());
actVo.setVisibility("PUBLIC");
activityId = remote.addActivity(actVo,userId);
int taskCount = 1;
dl.setSql("projecttask.selecttaskcount");
dl.setInt(1, tvo.getProjectID());
Collection countCol = dl.executeQuery();
Iterator itCount = countCol.iterator();
if (itCount.hasNext())
{
HashMap hm = (HashMap)itCount.next();
if (hm.get("count(projecttaskcount)") != null)
{
taskCount = ((Integer)hm.get("count(projecttaskcount)")).intValue();
}else{
taskCount = 0;
}
}
dl.clearParameters();
dl.setSql("projecttask.addtask");
dl.setInt(1, activityId);
dl.setInt(2, tvo.getProjectID());
dl.setInt(3, tvo.getParentID());
dl.setString(4, tvo.getIsMileStone());
dl.setInt(5, ++taskCount);
dl.executeUpdate();
HashMap assigned = (HashMap)tvo.getAssignedTo();
Iterator ite = null;
if (assigned != null)
{
ite = assigned.keySet().iterator();
while (ite.hasNext())
{
int assignedTo = ((Integer)ite.next()).intValue();
dl.setSql("projecttask.addtaskassigned");
dl.setInt(1, activityId);
dl.setInt(2, assignedTo);
dl.executeUpdate();
dl.clearParameters();
}
}
Collection actions = tvo.getActivityAction();
if (actions != null)
{
ite = actions.iterator();
while (ite.hasNext())
{
ActivityActionVO action = (ActivityActionVO)ite.next();
dl.setSql("projecttask.addtaskalertaction");
dl.setString(1, action.getActionType());
dl.setString(2, tvo.getMessage());
dl.executeUpdate();
int actionId = dl.getAutoGeneratedKey();
dl.clearParameters();
ArrayList recipients = action.getRecipient();
if (recipients != null)
{
Iterator it1 = recipients.iterator();
while (it1.hasNext())
{
dl.setSql("projecttask.addtaskalert");
dl.setInt(1, activityId);
dl.setInt(2, actionId);
dl.setInt(3, ((Integer)it1.next()).intValue());
dl.executeUpdate();
}
} // end if (recipients != null)
} // end while (ite.hasNext())
} // end if (actions != null)
Vector customField = tvo.getCustomField();
if (customField != null && customField.size() != 0)
{
for (int i = 0; i < customField.size(); i++)
{
CustomFieldVO cvo = (CustomFieldVO)customField.get(i);
if (cvo.getFieldID() != 0)
{
dl.setSql("project.addcustomfieldscalar");
dl.setInt(1, cvo.getFieldID());
dl.setInt(2, activityId);
dl.setString(3, cvo.getValue());
dl.executeUpdate();
}
}
}
// TODO: we may not need to do this as tasks are activites and activites don't seem to use recordauth.
AuthorizationLocalHome authorizationHome = (AuthorizationLocalHome)ic.lookup("local/Authorization");
AuthorizationLocal authorizationLocal = authorizationHome.create();
authorizationLocal.setDataSource(dataSource);
authorizationLocal.saveCurrentDefaultPermission("Tasks", activityId, userId);
}catch (Exception e){
System.out.println("[Exception][TaskEJB.addTask] Exception Thrown: " + e);