// load bidocument
biobj = biobjdao.loadBIObjectByLabel(documentLabel);
// get the save options
String saveOptString = jobDataMap.getString("biobject_id_" + biobj.getId() + "__"+ (ind+1));
SaveInfo saveInfo = SchedulerUtilities.fromSaveInfoString(saveOptString);
// create the execution controller
executionController = new ExecutionController();
executionController.setBiObject(biobj);
// fill parameters
executionController.refreshParameters(biobj, inputParametersQueryString);
String iterativeParametersString = jobDataMap.getString(documentInstanceName + "_iterative");
logger.debug("Iterative parameter configuration for documet [" + documentLabel + "] is equal to [" + iterativeParametersString + "]");
setIterativeParameters(biobj, iterativeParametersString);
String loadAtRuntimeParametersString = jobDataMap.getString(documentInstanceName + "_loadAtRuntime");
logger.debug("Runtime parameter configuration for documet [" + documentLabel + "] is equal to [" + loadAtRuntimeParametersString + "]");
setLoadAtRuntimeParameters(biobj, loadAtRuntimeParametersString);
String useFormulaParametersString = jobDataMap.getString(documentInstanceName + "_useFormula");
logger.debug("Formuula based parameter configuration for documet [" + documentLabel + "] is equal to [" + useFormulaParametersString + "]");
setUseFormulaParameters(biobj, useFormulaParametersString);
retrieveParametersValues(biobj);
//gets the dataset data about the email address
IDataStore emailDispatchDataStore = null;
if (saveInfo.isUseDataSet()) {
IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(saveInfo.getDataSetLabel());
dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(profile));
dataSet.loadData();
emailDispatchDataStore = dataSet.getDataStore();
}
//gets the dataset data about the folder for the document save
IDataStore folderDispatchDataSotre = null;
if (saveInfo.isUseFolderDataSet()) {
IDataSet dataSet = DAOFactory.getDataSetDAO().loadActiveDataSetByLabel(saveInfo.getDataSetFolderLabel());
dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(profile));
dataSet.loadData();
folderDispatchDataSotre = dataSet.getDataStore();
}
eventManager = EventsManager.getInstance();
List roles = DAOFactory.getBIObjectDAO().getCorrectRolesForExecution(biobj.getId());
String startExecMsg = "${scheduler.startexecsched} " + biobj.getName();
Integer idEvent = eventManager.registerEvent("Scheduler", startExecMsg, "", roles);
Map tempParMap = new HashMap();
BIObjectParametersIterator objectParametersIterator = new BIObjectParametersIterator(biobj.getBiObjectParameters());
while (objectParametersIterator.hasNext()) {
List parameters = (List) objectParametersIterator.next();
biobj.setBiObjectParameters(parameters);
StringBuffer toBeAppendedToName = new StringBuffer();
StringBuffer toBeAppendedToDescription = new StringBuffer(" [");
Iterator parametersIt = parameters.iterator();
while (parametersIt.hasNext()) {
BIObjectParameter aParameter = (BIObjectParameter) parametersIt.next();
tempParMap.put(aParameter.getParameterUrlName(), aParameter.getParameterValuesAsString());
if (aParameter.isIterative()) {
toBeAppendedToName.append("_" + aParameter.getParameterValuesAsString());
toBeAppendedToDescription.append(aParameter.getLabel() + ":" + aParameter.getParameterValuesAsString() + "; ");
}
}
// if there are no iterative parameters, toBeAppendedToDescription is " [" and must be cleaned
if (toBeAppendedToDescription.length() == 2) {
toBeAppendedToDescription.delete(0, 2);
} else {
// toBeAppendedToDescription ends with "; " and must be cleaned
toBeAppendedToDescription.delete(toBeAppendedToDescription.length() - 2, toBeAppendedToDescription.length());
toBeAppendedToDescription.append("]");
}
// appending the current date
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("dd:MM:yyyy");
String dateStr = sdf.format(date);
toBeAppendedToName.append("_" + dateStr);
//check parameters value: if a parameter hasn't value but isn't mandatory the process
//must go on and so hasValidValue is set to true
List tmpBIObjectParameters = biobj.getBiObjectParameters();
Iterator it = tmpBIObjectParameters.iterator();
while (it.hasNext()){
boolean isMandatory = false;
BIObjectParameter aBIObjectParameter = (BIObjectParameter)it.next();
List checks = aBIObjectParameter.getParameter().getChecks();
if (checks != null && !checks.isEmpty()) {
Iterator checksIt = checks.iterator();
while (checksIt.hasNext()) {
Check check = (Check) checksIt.next();
if (check.getValueTypeCd().equalsIgnoreCase("MANDATORY")) {
isMandatory = true;
break;
}
}
}
if (!isMandatory &&
(aBIObjectParameter.getParameterValues() == null || aBIObjectParameter.getParameterValues().size() == 0)) {
aBIObjectParameter.setParameterValues(new ArrayList());
aBIObjectParameter.setHasValidValues(true);
}
}
// exec the document only if all its parameter are filled
if(executionController.directExecution()) {
logger.debug("Save as snapshot is eual to [" + saveInfo.isSaveAsSnapshot() + "]");
logger.debug("Dispatch to a distribution list is eual to [" + saveInfo.isSendToDl() + "]");
logger.debug("Dispatch to a java class is eual to [" + saveInfo.isSendToJavaClass() + "]");
logger.debug("Dispatch by mail-list is eual to [" + saveInfo.isSendMail() + "]");
logger.debug("Dispatch by folder-list is eual to [" + saveInfo.isSaveAsDocument() + "]");
if(!saveInfo.isSaveAsSnapshot() && !saveInfo.isSendToDl() && !saveInfo.isSendToJavaClass()) {
boolean noValidDispatchTarget = false;
if(saveInfo.isSendMail()) {
String[] recipients = findRecipients(saveInfo, biobj, emailDispatchDataStore);
if (recipients != null && recipients.length > 0) {
noValidDispatchTarget = false;
logger.debug("Found at least one target of type mail");
}else{
noValidDispatchTarget = true;
}
}
if(saveInfo.isSaveAsDocument()) {
List storeInFunctionalities = findFolders(saveInfo, biobj, folderDispatchDataSotre);
if(storeInFunctionalities != null && !storeInFunctionalities.isEmpty()) {
noValidDispatchTarget = false;
logger.debug("Found at least one target of type folder");
}else{
noValidDispatchTarget = true;
}
}
if(noValidDispatchTarget) {
logger.debug("No valid dispatch target for document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters [" + toBeAppendedToDescription +"]");
logger.info("Document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription + " not executed: no valid dispatch target");
continue;
} else if(!saveInfo.isSaveAsDocument() && !saveInfo.isSendMail()){
logger.debug("There are no dispatch targets for document with label [" + documentInstanceName + "] - if not an ETL, WEKA or KPI document a dispatch target should be added");
}else{
logger.debug("There is at list one dispatch target for document with label [" + documentInstanceName + "]");
}
}
executionProxy = new ExecutionProxy();
executionProxy.setBiObject(biobj);
logger.info("Executing document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription +" ...");
long start = System.currentTimeMillis();
byte[] response = executionProxy.exec(profile, "SCHEDULATION", null);
if (response == null || response.length == 0) {
logger.debug("Document executed without any response");
}
String retCT = executionProxy.getReturnedContentType();
String fileextension = executionProxy.getFileExtensionFromContType(retCT);
long end = System.currentTimeMillis();
long elapsed = (end - start)/1000;
logger.info("Document [" + (ind+1) + "] with label [" + documentInstanceName + "] and parameters " + toBeAppendedToDescription +" executed in [" + elapsed + "]");
if(saveInfo.isSaveAsSnapshot()) {
saveAsSnap(saveInfo, biobj, response, toBeAppendedToName.toString(), toBeAppendedToDescription.toString(),profile);
}
if(saveInfo.isSaveAsDocument()) {
saveAsDocument(saveInfo, biobj,jobExecutionContext, response, fileextension, folderDispatchDataSotre, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
}
if(saveInfo.isSendMail()) {
sendMail(saveInfo, biobj, tempParMap, response, retCT, fileextension, emailDispatchDataStore, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
}
if(saveInfo.isSendToDl()) {
sendToDl(saveInfo, biobj, response, retCT, fileextension, toBeAppendedToName.toString(), toBeAppendedToDescription.toString());
if(jobExecutionContext.getNextFireTime()== null){
String triggername = jobExecutionContext.getTrigger().getName();
List dlIds = saveInfo.getDlIds();
it = dlIds.iterator();
while(it.hasNext()){
Integer dlId = (Integer)it.next();
DistributionList dl = DAOFactory.getDistributionListDAO().loadDistributionListById(dlId);
DAOFactory.getDistributionListDAO().eraseDistributionListObjects(dl, (biobj.getId()).intValue(), triggername);
}
}
}
if(saveInfo.isSendToJavaClass()) {
sendToJavaClass(saveInfo, biobj, response);
}
} else {