/**
  *
  * @param PMSERequest $request
  * @return \PMSERequest
  */
 public function validateRequest(PMSERequest $request)
 {
     $this->logger->info("Validate Request " . get_class($this));
     $this->logger->debug(array("Request data:", $request));
     $request->validate();
     return $request;
 }
 /**
  *
  * @param type $element
  * @param type $createThread
  * @param type $bean
  * @param type $externalAction
  * @param type $args
  * @return type
  */
 public function executeRequest($args = array(), $createThread = false, $bean = null, $externalAction = '')
 {
     $this->logger->info('Processing a direct request.');
     $this->logger->debug('Direct request params: ' . print_r($args));
     $this->request->setCreateThread($createThread);
     $this->request->setExternalAction($externalAction);
     $this->request->setBean($bean);
     $this->request->setArguments($args);
     $preProcessor = $this->preProcessor->getInstance();
     $response = $preProcessor->processRequest($this->request);
     return $response;
 }
 /**
  * Validates that if a second request from the same event and bean record
  * is received, the second request should be invalidated and thus ignored.
  * @param PMSERequest $request
  * @return \PMSERequest
  */
 public function validateRequest(PMSERequest $request)
 {
     $this->logger->info("Validate Request " . get_class($this));
     $this->logger->debug(array("Request data:", $request));
     $args = $request->getArguments();
     $flowId = isset($args['idFlow']) ? $args['idFlow'] : (isset($args['flow_id']) ? $args['flow_id'] : '0');
     if (!isset($_SESSION['locked_flows']) || !in_array($flowId, $_SESSION['locked_flows'])) {
         $request->validate();
     } else {
         $request->invalidate();
     }
     return $request;
 }
 /**
  * That method process the event related dependencies, here process criterias too.
  * @param object event
  */
 public function processRelatedDependencies($eventData)
 {
     $this->logger->info("Processing related Dependencies");
     $relatedArray = $this->processEventCriteria($eventData['evn_criteria'], $eventData);
     $this->removeRelatedDependencies($eventData);
     $this->createRelatedDependencies($relatedArray);
 }
示例#5
0
 /**
  *
  * @param PMSERequest $request
  * @return type
  */
 public function validateRequest(PMSERequest $request)
 {
     $this->logger->info("Start validation process.");
     $this->logger->debug(array("Request Data to be validated: ", $request));
     // A default request is always valid, if fails to validate in any validator
     // the status is set to invalid and no further validation is required
     if (!isset($this->validators[$request->getType()])) {
         $this->logger->info("Invalid Request");
         return false;
     }
     foreach ($this->validators[$request->getType()] as $validatorName => $validatorLevel) {
         if ($validatorLevel != PMSEValidationLevel::NoValidation) {
             $validator = $this->retrieveValidator($validatorName, $validatorLevel);
             $request = $validator->validateRequest($request);
             if (!$request->isValid()) {
                 $this->logger->info(get_class($validator) . " validator invalidated request.");
                 return $request;
             } else {
                 $this->logger->info(get_class($validator) . " validator validated request.");
             }
         }
     }
     $this->logger->info("Request validated successfully");
     $request->setStatus('PROCESSED');
     return $request;
 }
 /**
  *
  * @param PMSERequest $request
  * @return \PMSERequest
  */
 public function validateRequest(PMSERequest $request)
 {
     $this->logger->info("Validate Request " . get_class($this));
     $this->logger->debug(array("Request data:", $request));
     $flowData = $request->getFlowData();
     $bean = $request->getBean();
     if ($flowData['evn_id'] == 'TERMINATE') {
         $paramsRelated = $this->validateParamsRelated($bean, $flowData);
         $this->validateExpression($bean, $flowData, $request, $paramsRelated);
     }
     return $request;
 }
示例#7
0
 /**
  * Execute all the flows marked as SLEEPING
  */
 private function wakeUpSleepingFlows()
 {
     $this->logger->info("Checking flows with status sleeping");
     $today = TimeDate::getInstance()->nowDb();
     //get all records with status = sleeping
     $flowBean = BeanFactory::getBean('pmse_BpmFlow');
     //new BpmFlow();
     //$flows = $flowBean->getSelectRows('', "bpmn_type = 'bpmnEvent' and cas_flow_status = 'SLEEPING' and cas_due_date <= '$today' ");
     $flows = $flowBean->get_full_list('', "bpmn_type = 'bpmnEvent' and cas_flow_status = 'SLEEPING' and cas_due_date <= '{$today}' ");
     $n = 0;
     foreach ($flows as $flow) {
         $this->newFollowFlow($flow->fetched_row, false, null, 'WAKE_UP');
         $n++;
     }
     if ($n == 0) {
         $this->logger->info("No flows processed with status sleeping");
     } else {
         $this->logger->info("Processed {$n} flows with status sleeping");
     }
 }
示例#8
0
 /**
  *
  * @param type $request
  * @param type $createThread
  * @param type $bean
  * @param type $externalAction
  * @return type
  */
 public function processRequest(PMSERequest $request)
 {
     if ($request->getExternalAction() == 'TERMINATE_CASE') {
         $this->terminateCaseByBeanAndProcess($request->getBean());
     } else {
         if (!isset($_SESSION['triggeredFlows'])) {
             $_SESSION['triggeredFlows'] = array();
         }
         $flowDataList = $this->getFlowDataList($request);
         foreach ($flowDataList as $flowData) {
             // Process the flow data and also the bean object data
             $request->setFlowData($this->processFlowData($flowData));
             $request->setBean($this->processBean($request->getBean(), $request->getFlowData()));
             $request->getBean()->load_relationships();
             // is essential that the request should be initialized as valid for the next flow
             $request->validate();
             // validatind the request with the initial Data
             $validatedRequest = $this->validator->validateRequest($request);
             if ($validatedRequest->isValid()) {
                 $data = $validatedRequest->getFlowData();
                 if (!(isset($data['evn_type']) && $data['evn_type'] == 'GLOBAL_TERMINATE')) {
                     $this->logger->info('Request validated for element: ' . $data['bpmn_type'] . ' with id: ' . $data['bpmn_id']);
                     $_SESSION['pmse_start_time'] = microtime(true);
                     $result = $this->executer->runEngine($validatedRequest->getFlowData(), $validatedRequest->getCreateThread(), $validatedRequest->getBean(), $validatedRequest->getExternalAction(), $validatedRequest->getArguments());
                     $this->logger->info('Execution of case: #' . $data['cas_id'] . ' completed');
                 }
             } else {
                 $data = $request->getFlowData();
                 $this->logger->info('Request not validated for element: ' . $data['bpmn_type'] . ' with id: ' . $data['bpmn_id']);
             }
             if ($request->getResult() == 'TERMINATE_CASE') {
                 $this->terminateCaseByBeanAndProcess($request->getBean(), $data);
             }
         }
     }
 }
 /**
  *
  * @param type $flowData
  * @return type
  */
 public function taskAssignment($flowData)
 {
     $activityBean = $this->retrieveBean('pmse_BpmnActivity');
     //new BpmnActivity();
     $activityDefinitionBean = $this->retrieveBean('pmse_BpmActivityDefinition');
     //new BpmActivityDefinition();
     $actId = $flowData['bpmn_id'];
     $activities = $activityBean->get_list('pmse_bpmn_activity.id', "pmse_bpmn_activity.id = '{$actId}'");
     $activityRow = get_object_vars($activities['list'][0]);
     $currentUserId = $flowData['cas_user_id'];
     $currentSugarId = $flowData['cas_sugar_object_id'];
     $currentSugarModule = $flowData['cas_sugar_module'];
     $today = TimeDate::getInstance()->nowDb();
     $activitiesDef = $activityDefinitionBean->get_list('pmse_bpm_activity_definition.id', "pmse_bpm_activity_definition.id = '{$actId}' ", 0, -1, -1, array());
     if (!isset($activitiesDef['list'][0])) {
         //$this->bpmLog('ERROR', "[$flowData['cas_id']][$flowData['cas_index']] Activity Definition not found using act_id: $actId");
         $this->logger->error("[{$flowData['cas_id']}][{$flowData['cas_index']}] Activity Definition not found using act_id: {$actId}");
         $activityDefRow = array();
     } else {
         $activityDefRow = get_object_vars($activitiesDef['list'][0]);
     }
     $bpmnElement = array_merge($activityRow, $activityDefRow);
     //todo: throw an error if something was wrong
     //$expectedTimeObject = json_decode(base64_decode($activityDefRow['act_expected_time']));
     $caseData = new stdClass();
     $caseData->cas_start_date = '';
     $caseData->cas_delegate_date = $today;
     //$expectedTime = PMSEEngineUtils::processExpectedTime($expectedTimeObject, $caseData);
     //$dueDate = (!empty($expectedTime)) ? date('Y-m-d H:i:s', $expectedTime) : null;
     $activityType = $bpmnElement['act_task_type'];
     if ($activityType == 'SCRIPTTASK') {
         $cas_flow_status = 'SCRIPT';
         $cas_sugar_action = $activityType;
         //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] next flow is a script");
         $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] next flow is a script");
     } else {
         $cas_flow_status = 'FORM';
         $cas_sugar_action = $bpmnElement['act_type'];
         //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] next flow is an activity");
         $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] next flow is an activity");
         //check assignment rules
         $assignUser = isset($bpmnElement['act_assign_user']) == true ? $bpmnElement['act_assign_user'] : '******';
         $assign_method = isset($bpmnElement['act_assignment_method']) == true ? strtolower($bpmnElement['act_assignment_method']) : 'unknown';
         $assign_team = isset($bpmnElement['act_assign_team']) == true ? $bpmnElement['act_assign_team'] : 'unknown';
         //$last_assigned = $bpmnElement['act_last_user_assigned'];
         if ($assign_method == 'static') {
             switch ($assignUser) {
                 case 'owner':
                     $currentUserId = $this->getRecordOwnerId($currentSugarId, $currentSugarModule);
                     break;
                 case 'supervisor':
                     $currentUserId = $this->getSupervisorId($currentUserId);
                     break;
                 case 'currentuser':
                     $currentUserId = $currentUserId;
                     //$this->getCurrentUserId();
                     break;
                 default:
                     $currentUserId = $assignUser;
                     break;
             }
             //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] form assigned to user '$currentUserId'");
             $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] form assigned to user '{$currentUserId}'");
         } elseif ($assign_method == 'selfservice') {
             $currentUserId = $assign_team;
             //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] form assigned to team $currentUserId (Selfservice)");
             $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] form assigned to team {$currentUserId} (Selfservice)");
         } elseif ($assign_method == 'balanced') {
             $currentUserId = $this->getNextUserUsingRoundRobin($actId);
             //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] form assigned to user $currentUserId (Round Robin)");
             $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] form assigned to user {$currentUserId} (Round Robin)");
         } else {
             //$this->bpmLog('INFO', "[$flowData['cas_id']][$flowData['cas_index']] 'unknown' assigned to user $currentUserId");
             $this->logger->info("[{$flowData['cas_id']}][{$flowData['cas_index']}] 'unknown' assigned to user {$currentUserId}");
         }
         //parent::execute($flowData, $bean);
     }
     return $currentUserId;
 }
示例#10
0
 /**
  * Merge determined bean data into an determined text template, this could be
  * an email template, expression template, or another type of text with
  * bean variables in it.
  *
  * @global type $beanList
  * @param type $bean
  * @param type $template
  * @param type $component_array
  * @param type $evaluate
  * @return type
  */
 public function mergeTemplate($bean, $template, $component_array, $evaluate = false)
 {
     global $beanList;
     $replace_array = array();
     $replace_type_array = array();
     foreach ($component_array as $module_name => $module_array) {
         //base module
         if ($module_name == $bean->module_dir) {
             foreach ($module_array as $field => $field_array) {
                 if ($field_array['value_type'] == 'href_link') {
                     //Create href link to target record
                     $replacement_value = $this->get_href_link($bean);
                 }
                 if ($field_array['value_type'] == 'future') {
                     if ($evaluate) {
                         $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, false, array());
                     } else {
                         $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, false, array());
                     }
                 }
                 if ($field_array['value_type'] == 'past') {
                     $replacement_value = bpminbox_check_special_fields($field_array['name'], $bean, true, array());
                 }
                 $replace_type_array[$field_array['original']] = get_bean_field_type($field_array['name'], $bean);
                 $replace_array[$field_array['original']] = implode(', ', unencodeMultienum($replacement_value));
             }
         } else {
             //Confirm this is an actual module in the beanlist
             if (isset($beanList[$module_name]) || isset($bean->field_defs[$module_name])) {
                 ///Build the relationship information using the Relationship handler
                 $rel_handler = $bean->call_relationship_handler("module_dir", true);
                 if (isset($bean->field_defs[$module_name])) {
                     $rel_handler->rel1_relationship_name = $bean->field_defs[$module_name]['relationship'];
                     $rel_module = get_rel_module_name($bean->module_dir, $rel_handler->rel1_relationship_name, $bean->db);
                     $rel_handler->rel1_module = $rel_module;
                     $rel_handler->rel1_bean = get_module_info($rel_module);
                 } else {
                     $rel_handler->process_by_rel_bean($module_name);
                 }
                 foreach ($bean->field_defs as $field => $attribute_array) {
                     if (!empty($attribute_array['relationship']) && $attribute_array['relationship'] == $rel_handler->rel1_relationship_name) {
                         $rel_handler->base_vardef_field = $field;
                         break;
                     }
                 }
                 //obtain the rel_module object
                 $rel_list = $rel_handler->build_related_list("base");
                 if (!empty($rel_list[0])) {
                     $rel_object = $rel_list[0];
                     $rel_module_present = true;
                 } else {
                     $rel_module_present = false;
                 }
                 foreach ($module_array as $field => $field_array) {
                     if ($rel_module_present == true) {
                         if ($field_array['value_type'] == 'href_link') {
                             //Create href link to target record
                             $replacement_value = $this->get_href_link($rel_object);
                         } else {
                             //use future always for rel because fetched should always be the same
                             $replacement_value = bpminbox_check_special_fields($field_array['name'], $rel_object, false, array());
                         }
                     } else {
                         $replacement_value = "Invalid Value";
                     }
                     $replace_array[$field_array['original']] = implode(', ', unencodeMultienum($replacement_value));
                 }
             }
         }
     }
     foreach ($replace_array as $name => $replacement_value) {
         if ($evaluate) {
             $replacement_value = str_replace("\n", ' ', $replacement_value);
             $type = $replace_type_array[$name]['type'];
             $dbtype = $replace_type_array[$name]['db_type'];
             //TODO evaluate more types even Ids perhaps
             $this->logger->info("Field : {$name} , type: '{$type}',  DBtype: '{$dbtype}'");
             if (($dbtype == 'double' || $dbtype == 'int') && $type != 'currency') {
                 $replacement_value = trim($replacement_value);
             } elseif ($type == 'currency') {
                 //TODO hardcoded . , should use system currency format
                 $replacement_value = str_replace(",", '', $replacement_value);
                 $replacement_value = str_replace(".", ',', $replacement_value);
                 $replacement_value = floatval($replacement_value);
             } else {
                 //here $replacement_value must be datatime, time, string datatype values
                 $replacement_value = "'" . $replacement_value . "'";
             }
         } else {
             $replacement_value = nl2br($replacement_value);
         }
         $template = str_replace($name, $replacement_value, $template);
     }
     return $template;
 }
示例#11
0
 /**
  * Send the email based in an email template and with the email data parsed.
  * @param type $moduleName
  * @param type $beanId
  * @param type $addresses
  * @param type $templateId
  * @return type
  */
 public function sendTemplateEmail($moduleName, $beanId, $addresses, $templateId)
 {
     $msgError = '';
     $bean = $this->retrieveBean($moduleName, $beanId);
     $mailObject = $this->retrieveSugarPHPMailer();
     $this->setupMailObject($mailObject);
     $OBCharset = $this->locale->getPrecedentPreference('default_email_charset');
     if (isset($addresses->to)) {
         foreach ($addresses->to as $key => $email) {
             $mailObject->AddAddress($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset));
         }
     } else {
         $msgError = 'addresses field \'TO\' is not defined';
     }
     if (isset($addresses->cc)) {
         foreach ($addresses->cc as $key => $email) {
             $mailObject->AddCC($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset));
         }
     } else {
         $this->logger->info('addresses field \'CC\' is not defined');
     }
     if (isset($addresses->bcc)) {
         foreach ($addresses->bcc as $key => $email) {
             $mailObject->AddBCC($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset));
         }
     } else {
         $this->logger->info('addresses field \'BCC\' is not defined');
     }
     //    $email = trim($this->mergeBeanInTemplate($bean, $addressArray['to'][0][1], false));
     $templateObject = $this->retrieveBean('pmse_Emails_Templates');
     $templateObject->disable_row_level_security = true;
     if (isset($templateId) && $templateId != "") {
         $templateObject->retrieve($templateId);
     } else {
         $msgError = 'template_id is not defined';
     }
     if (isset($templateObject->from_name) && $templateObject->from_name != '') {
         $mailObject->FromName = $templateObject->from_name;
     }
     if (isset($templateObject->from_address) && $templateObject->from_address != '') {
         $mailObject->From = $templateObject->from_address;
     }
     if (isset($templateObject->body) && empty($templateObject->body)) {
         $templateObject->body = strip_tags(from_html($templateObject->body_html));
     } else {
         $this->logger->warning('template body is not defined');
     }
     if (isset($templateObject->body) && isset($templateObject->body_html)) {
         if (!empty($templateObject->body_html)) {
             $mailObject->IsHTML(true);
             $mailObject->Body = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body_html));
             $mailObject->AltBody = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body));
         } else {
             $mailObject->AltBody = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body));
         }
     } else {
         $this->logger->warning('template body_html is not defined');
     }
     if (isset($templateObject->subject)) {
         $mailObject->Subject = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->subject));
     } else {
         $this->logger->warning('template subject is not defined');
     }
     $mailObject->prepForOutbound();
     $result = $mailObject->Send();
     //if (isset($mailObject->ErrorInfo)) {
     //$this->bpmLog('ERROR', "mail error: " . $mailObject->ErrorInfo);
     //}
     return array('result' => $result, 'ErrorMessage' => $msgError, 'ErrorInfo' => $mailObject->ErrorInfo);
 }