/**
  *
  * @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;
 }
 /**
  *
  * @param PMSEObservable $subject
  */
 public function update($subject)
 {
     if (method_exists($subject, 'getEventDefinition')) {
         $this->logger->debug("Trigger update of a Related Relationship for a Event Definition update");
         $event = $subject->getEvent();
         $eventData = $event->fetched_row;
         $eventDefinition = $subject->getEventDefinition();
         $eventDefinitionData = $eventDefinition->fetched_row;
         $processDefinition = $subject->getProcessDefinition();
         $processDefinitionData = $processDefinition->fetched_row ? $processDefinition->fetched_row : array();
         $completeData = $eventData + $eventDefinitionData + $processDefinitionData;
         $this->relatedDependency->processRelatedDependencies($completeData);
     }
 }
 public function __construct()
 {
     $this->request = new PMSERequest();
     $this->logger = PMSELogger::getInstance();
     $this->request->setType('engine');
     $this->preProcessor = PMSEPreProcessor::getInstance();
 }
示例#6
0
 /**
  * Update the email data in the REQUEST global object
  * @param type $bean
  * @param type $newEmailAddress
  */
 public function updateEmails($bean, $newEmailAddress)
 {
     //Note.- in the future will be an 'array' of change fields emails
     $moduleItem = '0';
     $addresses = $bean->emailAddress->getAddressesByGUID($bean->id, $bean->module_dir);
     if (sizeof($addresses) > 0) {
         $_REQUEST[$bean->module_dir . '_email_widget_id'] = 0;
         $_REQUEST['emailAddressWidget'] = 1;
         $_REQUEST['useEmailWidget'] = true;
     }
     foreach ($addresses as $item => $data) {
         if (!isset($data['email_address_id']) || !isset($data['primary_address'])) {
             $this->logger->error(' The Email address Id or the primary address flag does not exist in DB');
             continue;
         }
         $emailAddressId = $data['email_address_id'];
         $emailId = $bean->module_dir . $moduleItem . 'emailAddress';
         if (!empty($emailAddressId) && $data['primary_address'] == 1) {
             $_REQUEST[$emailId . 'PrimaryFlag'] = $emailId . $item;
             $_REQUEST[$emailId . $item] = $newEmailAddress;
         } else {
             $_REQUEST[$emailId . $item] = $data['email_address'];
         }
         $_REQUEST[$emailId . 'Id' . $item] = $emailAddressId;
         $_REQUEST[$emailId . 'VerifiedFlag' . $item] = true;
         $_REQUEST[$emailId . 'VerifiedValue' . $item] = $data['email_address'];
         //$upd_query = "UPDATE email_addresses SET email_address='" . $emailAddress . "', email_address_caps='" . mb_strtoupper($emailAddress) . "', date_modified=" . $db->now() . " WHERE id='" . $row['email_address_id'] . "'";
         //$upd_res = $db->Query($upd_query);
         //$this->bpmLog('INFO',  $upd_query . ' result :  ' . print_r($upd_res,true));
     }
 }
示例#7
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 PMSEObservable $subject
  * @return type
  */
 public function update($subject)
 {
     if (method_exists($subject, 'getProcessDefinition')) {
         $this->logger->debug("Trigger update of a Related Relationship for a Process Definitions update");
         $processDefinition = $subject->getProcessDefinition();
         $processDefinitionData = $processDefinition->fetched_row;
         $fields = array('id', 'rel_element_type');
         $relatedDependency = $this->getRelatedDependencyBean();
         $this->sugarQuery->select($fields);
         $this->sugarQuery->from($relatedDependency);
         $this->sugarQuery->where()->queryAnd()->addRaw("pro_id='{$processDefinitionData['id']}' AND prj_id='{$processDefinitionData['prj_id']}' AND deleted=0");
         $result = $this->sugarQuery->compileSql();
         $this->logger->debug("Retrieve dependencies query: {$result}");
         $rows = $this->sugarQuery->execute();
         foreach ($rows as $row) {
             $bean = $this->getRelatedDependencyBean($row['id']);
             $bean->pro_status = $processDefinitionData['pro_status'];
             $bean->pro_locked_variables = $processDefinitionData['pro_locked_variables'];
             $bean->pro_terminate_variables = $processDefinitionData['pro_terminate_variables'];
             if ($bean->pro_module !== $processDefinitionData['pro_module'] && $row['rel_element_type'] == 'TERMINATE') {
                 $bean->deleted = true;
             }
             $bean->save();
         }
         $this->processRelatedDependencies($processDefinitionData);
         $depNumber = count($rows);
         $this->logger->debug("Updating {$depNumber} dependencies");
     }
     return $result;
 }
 /**
  * Class Constructor
  * @global type $current_user
  * @codeCoverageIgnore
  */
 public function __construct()
 {
     global $current_user;
     $this->schedulersJob = new SchedulersJob();
     $this->sugarJobQueue = new SugarJobQueue();
     $this->logger = PMSELogger::getInstance();
     $this->currentUser = $current_user;
 }
示例#10
0
 /**
  * Retrieve unique instance of the PMSELogger singleton
  * @return type
  * @codeCoverageIgnore
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
 /**
  *
  * @param type $bean
  * @param type $flowData
  * @param type $externalAction
  * @return array
  */
 public function validateParamsRelated($bean, $flowData)
 {
     $paramsRelated = array();
     if ($bean->parent_type == $flowData['rel_process_module']) {
         $paramsRelated = array('replace_fields' => array($flowData['rel_element_relationship'] => $flowData['rel_element_module']));
     }
     $this->logger->debug("Parameters related returned :" . print_r($paramsRelated, true));
     return $paramsRelated;
 }
示例#12
0
 /**
  * Class constructor
  * @codeCoverageIgnore
  */
 public function __construct()
 {
     global $db;
     $this->executionMode = 'DEFAULT';
     $this->caseFlowHandler = new PMSECaseFlowHandler();
     $this->userAssignmentHandler = new PMSEUserAssignmentHandler();
     $this->beanHandler = new PMSEBeanHandler();
     $this->emailHandler = new PMSEEmailHandler();
     $this->dbHandler = $db;
     $this->logger = PMSELogger::getInstance();
 }
 /**
  * That method creates all dependencies related to this event and save them
  * @param array resultArray
  */
 public function createRelatedDependencies($resultArray)
 {
     foreach ($resultArray as $object) {
         $relatedDependency = $this->getBean('pmse_BpmRelatedDependency');
         foreach ($object as $attrib => $value) {
             $relatedDependency->{$attrib} = $value;
         }
         $relatedDependency->new_with_id = false;
         $relatedDependency->save();
     }
     $this->logger->debug("Creating " . count($resultArray) . " Related Dependencies.");
 }
示例#14
0
 /**
  *
  * @param type $data
  * @return type
  */
 public function getFlowsByCasId($casId)
 {
     $flow = $this->retrieveBean('pmse_BpmFlow');
     $q = $this->retrieveSugarQuery();
     $fields = array('id', 'deleted', 'assigned_user_id', 'cas_id', 'cas_index', 'pro_id', 'pcas_previous', 'cas_reassign_level', 'bpmn_id', 'bpmn_type', 'cas_user_id', 'cas_thread', 'cas_flow_status', 'cas_sugar_module', 'cas_sugar_object_id', 'cas_sugar_action', 'cas_adhoc_type', 'cas_task_start_date', 'cas_delegate_date', 'cas_start_date', 'cas_finish_date', 'cas_due_date', 'cas_queue_duration', 'cas_duration', 'cas_delay_duration', 'cas_started', 'cas_finished', 'cas_delayed');
     $q->select($fields);
     $q->from($flow);
     $q->where()->queryAnd()->addRaw("pmse_bpm_flow.cas_id={$casId} AND pmse_bpm_flow.cas_flow_status='ERROR'");
     $query = $q->compileSql();
     $start = microtime(true);
     $result = $q->execute();
     $time = (microtime(true) - $start) * 1000;
     $this->logger->debug('Query in order to retrieve all valid start and receive message events: ' . $query . ' \\n in ' . $time . ' milliseconds');
     return $result;
 }
 /**
  *
  * @param type $bean
  * @param type $flowData
  * @param type $request
  * @return array
  */
 public function validateParamsRelated($bean, $flowData, $request)
 {
     $paramsRelated = array();
     if ($request->getExternalAction() == 'EVALUATE_RELATED_MODULE') {
         if ($this->hasValidRelationship($bean, $flowData)) {
             $paramsRelated = array('replace_fields' => array($flowData['rel_element_relationship'] => $flowData['rel_element_module']));
         } else {
             $request->invalidate();
         }
     }
     if ($request->getExternalAction() == 'EVALUATE_MAIN_MODULE') {
         if ($bean->module_name != $flowData['cas_sugar_module'] || $bean->id != $flowData['cas_sugar_object_id']) {
             $request->invalidate();
         }
     }
     $this->logger->debug("Parameters related returned :" . print_r($paramsRelated, true));
     return $paramsRelated;
 }
示例#16
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");
     }
 }
 /**
  *
  * @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;
 }
示例#18
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;
 }
示例#19
0
 public function logErrorActivity($flowData, $bean)
 {
     $params = $this->processTags($flowData, $bean);
     $params['module_name'] = 'pmse_Inbox';
     $this->logger->activity('The task &0 of case &1 registered an execution error for the record &2 from module &3.', $params);
 }
示例#20
0
 /**
  * Flow Router Constructor
  * @codeCoverageIgnore
  */
 public function __construct()
 {
     $this->caseFlowHandler = new PMSECaseFlowHandler();
     $this->jobQueueHandler = new PMSEJobQueueHandler();
     $this->logger = PMSELogger::getInstance();
 }
示例#21
0
 public function __construct()
 {
     $this->logger = PMSELogger::getInstance();
     $this->relatedRecordApi = new RelateRecordApi();
 }
 /**
  *
  * @global type $db
  * @codeCoverageIgnore
  */
 public function __construct()
 {
     global $db;
     $this->dbHandler = $db;
     $this->logger = PMSELogger::getInstance();
 }
示例#23
0
 public function clearLog($api, $args)
 {
     $this->checkACL($api, $args);
     $logger = PMSELogger::getInstance();
     $pmse = PMSE::getInstance();
     global $current_user;
     if ($current_user->isDeveloperForModule('pmse_Inbox') || $current_user->isAdminForModule('pmse_Inbox')) {
         $pmse->clearLogFile($logger->getLogFileNameWithPath());
     } else {
         return false;
     }
     return true;
 }