try{
RequestContainer reqCont = getRequestContainer();
SessionContainer sessCont = reqCont.getSessionContainer();
SessionContainer permSess = sessCont.getPermanentContainer();
IEngUserProfile profile = (IEngUserProfile)permSess.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
SchedulerServiceSupplier schedulerService=new SchedulerServiceSupplier();
TriggerInfo triggerInfo = (TriggerInfo)sessCont.getAttribute(SpagoBIConstants.TRIGGER_INFO);
JobInfo jobInfo = triggerInfo.getJobInfo();
String jobName = jobInfo.getJobName();
String jobGroupName = jobInfo.getJobGroupName();
String triggername = (String)request.getAttribute("triggername");
String triggerDescription = (String)request.getAttribute("triggerdescription");
String startdate = (String)request.getAttribute("startdate");
String starttime = (String)request.getAttribute("starttime");
String chronstr = (String)request.getAttribute("chronstring");
String enddate = (String)request.getAttribute("enddate");
String endtime = (String)request.getAttribute("endtime");
String repeatinterval = (String)request.getAttribute("repeatInterval");
triggerInfo.setEndDate(enddate);
triggerInfo.setEndTime(endtime);
triggerInfo.setRepeatInterval(repeatinterval);
triggerInfo.setStartDate(startdate);
triggerInfo.setStartTime(starttime);
triggerInfo.setChronString(chronstr);
triggerInfo.setTriggerDescription(triggerDescription);
triggerInfo.setTriggerName(triggername);
Map saveOptions = new HashMap();
List biobjIds = jobInfo.getBiobjectIds();
Iterator iterBiobjIds = biobjIds.iterator();
int index = 0;
while(iterBiobjIds.hasNext()){
index ++;
SaveInfo sInfo = new SaveInfo();
Integer biobId = (Integer)iterBiobjIds.next();
String saveassnap = (String)request.getAttribute("saveassnapshot_"+biobId+"__"+index);
if(saveassnap!=null) {
sInfo.setSaveAsSnapshot(true);
String snapname = (String)request.getAttribute("snapshotname_"+biobId+"__"+index);
sInfo.setSnapshotName(snapname);
String snapdescr = (String)request.getAttribute("snapshotdescription_"+biobId+"__"+index);
sInfo.setSnapshotDescription(snapdescr);
String snaphistlength = (String)request.getAttribute("snapshothistorylength_"+biobId+"__"+index);
sInfo.setSnapshotHistoryLength(snaphistlength);
}
String sendToJavaClass = (String)request.getAttribute("sendtojavaclass_"+biobId+"__"+index);
if(sendToJavaClass!=null) {
sInfo.setSendToJavaClass(true);
String javaClassPath = (String)request.getAttribute("javaclasspath_"+biobId+"__"+index);
JavaClassDestination tryClass=null;
try{
tryClass=(JavaClassDestination)Class.forName(javaClassPath).newInstance();
}
catch (ClassCastException e) {
logger.error("Error in istantiating class");
EMFValidationError emfError=new EMFValidationError(EMFErrorSeverity.ERROR, "sendtojavaclass_"+biobId+"__"+index, "12200");
errorHandler.addError(emfError);
}
catch (Exception e) {
logger.error("Error in istantiating class");
EMFValidationError emfError=new EMFValidationError(EMFErrorSeverity.ERROR, "sendtojavaclass_"+biobId+"__"+index, "12100");
errorHandler.addError(emfError);
}
sInfo.setJavaClassPath(javaClassPath);
}
String saveasdoc = (String)request.getAttribute("saveasdocument_"+biobId+"__"+index);
if(saveasdoc!=null) {
sInfo.setSaveAsDocument(true);
String docname = (String)request.getAttribute("documentname_"+biobId+"__"+index);
sInfo.setDocumentName(docname);
String docdescr = (String)request.getAttribute("documentdescription_"+biobId+"__"+index);
sInfo.setDocumentDescription(docdescr);
boolean useFixedFolder = "true".equalsIgnoreCase((String) request.getAttribute("useFixedFolder_"+biobId+"__"+index));
sInfo.setUseFixedFolder(useFixedFolder);
if (useFixedFolder) {
String functIdsConcat = "";
String tmpValReq = "tree_"+biobId+"__"+index+"_funct_id";
List functIds = request.getAttributeAsList(tmpValReq);
Iterator iterFunctIds = functIds.iterator();
while(iterFunctIds.hasNext()) {
String idFunct = (String)iterFunctIds.next();
functIdsConcat += idFunct;
if(iterFunctIds.hasNext()){
functIdsConcat += ",";
}
}
sInfo.setFunctionalityIds(functIdsConcat);
}
//gestire acquisizione folder
boolean useFolderDataset = "true".equalsIgnoreCase((String) request.getAttribute("useFolderDataset_"+biobId+"__"+index));
sInfo.setUseFolderDataSet(useFolderDataset);
if (useFolderDataset) {
String dsLabel = (String)request.getAttribute("datasetFolderLabel_"+biobId+"__"+index);
sInfo.setDataSetFolderLabel(dsLabel);
String datasetParameterLabel = (String)request.getAttribute("datasetFolderParameter_"+biobId+"__"+index);
sInfo.setDataSetFolderParameterLabel(datasetParameterLabel);
if (dsLabel == null || dsLabel.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingDataSet", params, "component_scheduler_messages"));
}
if (datasetParameterLabel == null || datasetParameterLabel.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingDataSetParameter", params, "component_scheduler_messages"));
}
// sInfo.setFunctionalityIds(functIdsConcat);
}
}
String sendmail = (String)request.getAttribute("sendmail_"+biobId+"__"+index);
if(sendmail!=null) {
sInfo.setSendMail(true);
boolean useFixedRecipients = "true".equalsIgnoreCase((String) request.getAttribute("useFixedRecipients_"+biobId+"__"+index));
sInfo.setUseFixedRecipients(useFixedRecipients);
if (useFixedRecipients) {
String mailtos = (String)request.getAttribute("mailtos_"+biobId+"__"+index);
sInfo.setMailTos(mailtos);
if (mailtos == null || mailtos.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingFixedRecipients", params, "component_scheduler_messages"));
}
}
boolean useDataset = "true".equalsIgnoreCase((String) request.getAttribute("useDataset_"+biobId+"__"+index));
sInfo.setUseDataSet(useDataset);
if (useDataset) {
String dsLabel = (String)request.getAttribute("datasetLabel_"+biobId+"__"+index);
sInfo.setDataSetLabel(dsLabel);
String datasetParameterLabel = (String)request.getAttribute("datasetParameter_"+biobId+"__"+index);
sInfo.setDataSetParameterLabel(datasetParameterLabel);
if (dsLabel == null || dsLabel.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingDataSet", params, "component_scheduler_messages"));
}
if (datasetParameterLabel == null || datasetParameterLabel.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingDataSetParameter", params, "component_scheduler_messages"));
}
}
boolean useExpression = "true".equalsIgnoreCase((String) request.getAttribute("useExpression_"+biobId+"__"+index));
sInfo.setUseExpression(useExpression);
if (useExpression) {
String expression = (String)request.getAttribute("expression_"+biobId+"__"+index);
sInfo.setExpression(expression);
if (expression == null || expression.trim().equals("")) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingExpression", params, "component_scheduler_messages"));
}
}
if (!useFixedRecipients && !useDataset && !useExpression) {
BIObject biobj = DAOFactory.getBIObjectDAO().loadBIObjectById(biobId);
List params = new ArrayList();
params.add(biobj.getName());
this.getErrorHandler().addError(new EMFValidationError(EMFErrorSeverity.ERROR, null, "errors.trigger.missingRecipients", params, "component_scheduler_messages"));
}
String mailsubj = (String)request.getAttribute("mailsubj_"+biobId+"__"+index);
sInfo.setMailSubj(mailsubj);
String mailtxt = (String)request.getAttribute("mailtxt_"+biobId+"__"+index);
sInfo.setMailTxt(mailtxt);
}
String sendtodl = (String)request.getAttribute("saveasdl_"+biobId+"__"+index);
if(sendtodl!=null) {
sInfo.setSendToDl(true);
sInfo.setBiobjId(biobId.intValue());
List dlist = DAOFactory.getDistributionListDAO().loadAllDistributionLists();
Iterator it = dlist.iterator();
while(it.hasNext()){
DistributionList dl = (DistributionList)it.next();
int dlId = dl.getId();
String listID = (String)request.getAttribute("sendtodl_"+dlId+"_"+biobId+"__"+index);
if(listID!=null){
sInfo.addDlId(new Integer(listID));
}
else{
DAOFactory.getDistributionListDAO().eraseDistributionListObjects(dl,biobId.intValue(),triggername);
}
}
}
saveOptions.put(biobId+"__"+index, sInfo);
}
triggerInfo.setSaveOptions(saveOptions);
// check for input validation errors
if(!this.getErrorHandler().isOKByCategory(EMFErrorCategory.VALIDATION_ERROR)) {
List functionalities = DAOFactory.getLowFunctionalityDAO().loadAllLowFunctionalities(false);
response.setAttribute(SpagoBIConstants.FUNCTIONALITIES_LIST, functionalities);
List allDatasets = DAOFactory.getDataSetDAO().loadAllActiveDataSets();
response.setAttribute(SpagoBIConstants.DATASETS_LIST, allDatasets);
response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, "TriggerDetail");
return;
}
StringBuffer message = createMessageSaveSchedulation(triggerInfo, false,profile);
// call the web service to create the schedule
String servoutStr = schedulerService.scheduleJob(message.toString());
SourceBean execOutSB = SchedulerUtilities.getSBFromWebServiceResponse(servoutStr);
if(execOutSB!=null) {
String outcome = (String)execOutSB.getAttribute("outcome");
if(outcome.equalsIgnoreCase("fault"))
throw new Exception("Trigger "+triggername+" not created by the web service");