kpisList.add(deserializeKpiNode((JSONObject)kpis.get(i), goalNodeId));
}
daoGoal.ereseGoalKpis(goalNodeId);
daoGoal.insertGoalKpis(kpisList, goalNodeId);
daoGoal.updateGoalNode(gn);
writeBackToClient(new JSONAcknowledge());
} catch (Exception e){
logger.debug("Error adding the details to the goal node");
throw new SpagoBIServiceException(SERVICE_NAME, "Error adding the details to the goal node",e);
}
logger.debug("Added the goal details");
}
if (serviceType != null && serviceType.equalsIgnoreCase(UPDATE_GOAL_NAME)) {
logger.debug("Updating the name of the goal with id:");
Integer goalNode = getAttributeAsInteger("goalId");
logger.debug("id:"+goalNode);
String goalName = getAttributeAsString("newName");
daoGoal.updateGoalName(goalNode, goalName);
try{
writeBackToClient(new JSONAcknowledge());
} catch (IOException e){
logger.debug("Error sending the response after the erese of the goal node");
throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal node",e);
}
logger.debug("Goal name updated");
}
if (serviceType != null && serviceType.equalsIgnoreCase(ERESE_GOAL_NODE)) {
logger.debug("Removing the goal node with id:");
Integer goalNode = getAttributeAsInteger("id");
logger.debug("id:"+goalNode);
daoGoal.ereseGoalNode(goalNode);
try{
writeBackToClient(new JSONAcknowledge());
} catch (IOException e){
logger.debug("Error sending the response after the erese of the goal node");
throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal node",e);
}
logger.debug("Goal removed");
}
if (serviceType != null && serviceType.equalsIgnoreCase(KPI_GOAL_ROOT_NODE)) {
logger.debug("Loading the kpi model instances linked to the goal: ");
Integer grantId = getAttributeAsInteger("grantId");
Integer goalNodeId = getAttributeAsInteger("goalNodeId");
Integer ouNodeId = getAttributeAsInteger("ouNodeId");
logger.debug("grantId: "+grantId+", goalNodeId"+goalNodeId);
OrganizationalUnitGrant grant = DAOFactory.getOrganizationalUnitDAO().getGrant(grantId);
ModelInstance mi = grant.getModelInstance();
List<OrganizationalUnitNodeWithGrant> ousWithGrants = DAOFactory.getOrganizationalUnitDAO().getGrantNodes(ouNodeId, grantId);
List<OrganizationalUnitGrantNode> grants = new ArrayList<OrganizationalUnitGrantNode>();
for(int i=0; i<ousWithGrants.size(); i++){
grants.addAll(ousWithGrants.get(i).getGrants());
}
List<Integer> modelInstances = new ArrayList<Integer>();
for(int i=0; i<grants.size(); i++){
modelInstances.add(grants.get(i).getModelInstanceNode().getModelInstanceNodeId());
}
if(modelInstances.contains(mi.getId())){
mi.setActive(true);
}
try {
JSONObject modelInstanceJSON = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( mi, null);
if(goalNodeId!=null){
List<GoalKpi> listGoalKpi = daoGoal.getGoalKpi(goalNodeId);
for(int i=0; i<listGoalKpi.size(); i++){
if(listGoalKpi.get(i).getModelInstanceId().equals( mi.getId())){
modelInstanceJSON.put("weight1", ""+listGoalKpi.get(i).getWeight1());
modelInstanceJSON.put("weight2", ""+listGoalKpi.get(i).getWeight2());
modelInstanceJSON.put("sign1", ""+listGoalKpi.get(i).getSign1());
if(listGoalKpi.get(i).getSign1()==110){
modelInstanceJSON.put("threshold1", "");
}else{
modelInstanceJSON.put("threshold1", ""+listGoalKpi.get(i).getThreshold1());
}
modelInstanceJSON.put("sign2", ""+listGoalKpi.get(i).getSign2());
if(listGoalKpi.get(i).getSign2()==110){
modelInstanceJSON.put("threshold2", "");
}else{
modelInstanceJSON.put("threshold2", ""+listGoalKpi.get(i).getThreshold2());
}
break;
}
}
}
writeBackToClient( new JSONSuccess( modelInstanceJSON ) );
} catch (Exception e) {
logger.debug("Impossible to serialize the responce to the client");
throw new SpagoBIServiceException(SERVICE_NAME, "Impossible to serialize the responce to the client", e);
}
logger.debug("kpi model instances loaded.");
}
if (serviceType != null && serviceType.equalsIgnoreCase(GOAL_ERESE)) {
logger.debug("Removing the goal with id:");
Integer goalId = getAttributeAsInteger("goalId");
logger.debug(goalId);
logger.debug(goalId);
daoGoal.eraseGoal(goalId);
try{
writeBackToClient( new JSONAcknowledge() );
} catch (IOException e){
logger.debug("Error sending the response after the erese of the goal");
throw new SpagoBIServiceException(SERVICE_NAME, "Error sending the response after the erese of the goal",e);
}
logger.debug("Goal removed");
}
if (serviceType != null && serviceType.equalsIgnoreCase(GOAL_INSERT)) {
logger.debug("Adding the goal: ");
JSONObject goalJSON = getAttributeAsJSONObject(GOAL);
logger.debug(goalJSON);
try{
Goal goal = deserializeGoal(goalJSON);
daoGoal.insertGoal(goal);
writeBackToClient( new JSONAcknowledge() );
} catch (Exception e){
logger.debug("Error inserting the goal");
throw new SpagoBIServiceException(SERVICE_NAME, "Error inserting the goal",e);
}
logger.debug("Goal added");