Processes incoming REQUEST messages.

This is message from an organizer, and is either a new event
invite, or an update to an existing one.


@param Message   $itipMessage
@param VCalendar $existingObject

@return VCalendar|null
963530
protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null)
    {
        if (!$existingObject) {
            // This is a new invite, and we're just going to copy over
            // all the components from the invite.
            $existingObject = new VCalendar();
            foreach ($itipMessage->message->getComponents() as $component) {
                $existingObject->add(clone $component);
            }
        } else {
            // We need to update an existing object with all the new
            // information. We can just remove all existing components
            // and create new ones.
            foreach ($existingObject->getComponents() as $component) {
                $existingObject->remove($component);
            }
            foreach ($itipMessage->message->getComponents() as $component) {
                $existingObject->add(clone $component);
            }
        }

        return $existingObject;
    }
1198675
public function startWorkflow(DataObject $object, $workflowID = null)
    {
        $existing = $this->getWorkflowFor($object);
        if ($existing) {
            throw new ExistingWorkflowException(_t(
                'WorkflowService.EXISTING_WORKFLOW_ERROR',
                "That object already has a workflow running"
            ));
        }

        $definition = null;
        if ($workflowID) {
            // Retrieve the workflow definition that has been triggered.

            $definition = $this->getDefinitionByID($object, $workflowID);
        }
        if (is_null($definition)) {
            // Fall back to the main workflow definition.

            $definition = $this->getDefinitionFor($object);
        }

        if ($definition) {
            $instance = new WorkflowInstance();
            $instance->beginWorkflow($definition, $object);
            $instance->execute();
        }
    }
256964
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String itemType = pRequestData.getParameter("itemType");
    if (InvItem.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, InvItem.class);
    } else if (ServiceToSale.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, ServiceToSale.class);
    } else {
      throw new Exception("NYI: " + itemType);
    }
  }
613131
private function processStack(\Iterator $iterator, $isObject)
    {
        if ($isObject) {
            if (!$this->processKey($iterator->key())) {
                return;
            }
        } elseif (!$this->first) {
            $this->outputLine(',', JsonToken::T_COMMA);
        }

        $this->first = false;
        $this->processValue($iterator->current());
    }
1048992
public function updateMessage(DataObject $object, $identifier)
    {
        $this->changeMessage(sprintf('Updating %s.%s', get_class($object), $identifier), 'changed');
    }
797450
protected function getExistingActiveOrInactiveProduct($existingProduct, $statusId, $locale)
    {
        if (($statusId == StatusEntity::ACTIVE || $statusId == StatusEntity::INACTIVE)
            && $existingProduct->getStatus()->getId() != $statusId
        ) {
            // Check if the same product already exists in IMPORTED state.
            $products = $this->productRepository->findByLocaleAndInternalItemNumber(
                $locale,
                $existingProduct->getInternalItemNumber()
            );
            foreach ($products as $product) {
                if ($product->isDeprecated() && $existingProduct->getId() != $product->getId()) {
                    $product->setIsDeprecated(false);

                    return $this->productFactory->createApiEntity($product, $locale);
                }
            }
        }

        return null;
    }
1032770
public void commitAddActiveMessage()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(this, tc, "commitAddActiveMessage");

    // Lock the active message counter lock
    synchronized(maxActiveMessageLock)
    {
      // Move the prepared add to the real count
      currentActiveMessages++;
      preparedActiveMessages--;
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        SibTr.debug(tc, "Active Messages: current: " + currentActiveMessages +
                          ", prepared: " + preparedActiveMessages +
                          ", maximum: " + maxActiveMessages +
                          " (suspended: " + consumerSetSuspended + ")");
      
      // We should never go negative, if we do something has gone wrong - FFDC
      if(preparedActiveMessages < 0)
      {
        SIErrorException e = new SIErrorException(
            nls.getFormattedMessage(
              "INTERNAL_MESSAGING_ERROR_CWSIP0001",
              new Object[] {
                "com.ibm.ws.sib.processor.impl.JSConsumerSet.commitAddActiveMessage",
                "1:499:1.16",
                Integer.valueOf(preparedActiveMessages),
                Integer.valueOf(currentActiveMessages),
                Integer.valueOf(maxActiveMessages),
                Boolean.valueOf(consumerSetSuspended)
                },
              null));

          FFDCFilter.processException(
            e,
            "com.ibm.ws.sib.processor.impl.JSConsumerSet.commitAddActiveMessage",
            "1:510:1.16",
            this);

          SibTr.exception(tc, e);
          SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0001",
            new Object[] {
              "com.ibm.ws.sib.processor.impl.JSConsumerSet.commitAddActiveMessage",
              "1:517:1.16" });
      }
      
      // If we currently hold the write lock (as we will always either hold
      // the read lock of the write lock we know this check will return the right
      // answer (i.e. it can't change under us)) we must have thought this add
      // would take us up to the limit and therefore require a suspend.
      if(maxActiveMessagePrepareLock.isWriteLockedByCurrentThread())
      {
        // If the limit has been reached, suspend the set
        if(currentActiveMessages == maxActiveMessages)
        {
          // All this does is mark the set as suspended. We leave it up to the members
          // of the set to notice that the set is suspended and suspend themselves.
          // This is more efficient than going round and suspending everyone, only to
          // have to resume then all again in a second. Hopefully the set will be
          // resumed before most of them notice it was suspended.
          consumerSetSuspended = true;

          if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.debug(tc, "JSConsumerSet suspended " + this);
        }
        
        // Release the write lock
        maxActiveMessagePrepareWriteLock.unlock();
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
          SibTr.debug(tc, "maxActiveMessagePrepareWriteLock.unlock(): " + maxActiveMessagePrepareLock);
      }
      else
      {
        // We only held a read lock, release it now
        maxActiveMessagePrepareReadLock.unlock();
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
          SibTr.debug(tc, "maxActiveMessagePrepareReadLock.unlock(): " + maxActiveMessagePrepareLock);
      }
    }

    if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(this, tc, "commitAddActiveMessage");
  }
1053345
public void updateMessage(final AVIMMessage oldMessage, final AVIMMessage newMessage, final AVIMMessageUpdatedCallback callback) {
    if (null == oldMessage || null == newMessage) {
      if (null != callback) {
        callback.internalDone(new AVException(new IllegalArgumentException("oldMessage/newMessage shouldn't be null")));
      }
      return;
    }
    final AVIMCommonJsonCallback tmpCallback = new AVIMCommonJsonCallback() {
      @Override
      public void done(Map<String, Object> result, AVIMException e) {
        if (null != e || null == result) {
          if (null != callback) {
            callback.internalDone(null, e);
          }
        } else {
          long patchTime = 0;
          if (result.containsKey(Conversation.PARAM_MESSAGE_PATCH_TIME)) {
            patchTime = (Long) result.get(Conversation.PARAM_MESSAGE_PATCH_TIME);
          }
          copyMessageWithoutContent(oldMessage, newMessage);
          newMessage.setUpdateAt(patchTime);
          updateLocalMessage(newMessage);
          if (null != callback) {
            callback.internalDone(newMessage, null);
          }
        }
      }
    };
    InternalConfiguration.getOperationTube().updateMessage(client.getClientId(), getType(), oldMessage, newMessage, tmpCallback);
  }
1053598
private function migrate_notification($notification, $isread) {
        global $DB;

        $tabledata = new \stdClass();
        $tabledata->useridfrom = $notification->useridfrom;
        $tabledata->useridto = $notification->useridto;
        $tabledata->subject = $notification->subject;
        $tabledata->fullmessage = $notification->fullmessage;
        $tabledata->fullmessageformat = $notification->fullmessageformat ?? FORMAT_MOODLE;
        $tabledata->fullmessagehtml = $notification->fullmessagehtml;
        $tabledata->smallmessage = $notification->smallmessage;
        $tabledata->component = $notification->component;
        $tabledata->eventtype = $notification->eventtype;
        $tabledata->contexturl = $notification->contexturl;
        $tabledata->contexturlname = $notification->contexturlname;
        $tabledata->timeread = $notification->timeread ?? null;
        $tabledata->timecreated = $notification->timecreated;

        $newid = $DB->insert_record('notifications', $tabledata);

        // Check if there is a record to move to the new 'message_popup_notifications' table.
        if ($mp = $DB->get_record('message_popup', ['messageid' => $notification->id, 'isread' => (int) $isread])) {
            $mpn = new \stdClass();
            $mpn->notificationid = $newid;
            $DB->insert_record('message_popup_notifications', $mpn);

            $DB->delete_records('message_popup', ['id' => $mp->id]);
        }
    }
1011963
public function push($topic, $idOrIdsOrResult = null, $result = null) {
        $this->checkPushService();
        $args = func_get_args();
        $argc = func_num_args();
        $id = null;
        $result = null;
        if (($argc < 2) || ($argc > 3)) {
            throw new Exception('Wrong number of arguments');
        }
        if ($argc === 2) {
            $result = $args[1];
        }
        else {
            $id = $args[1];
            $result = $args[2];
        }
        if ($id === null) {
            $topics = $this->getTopics($topic);
            $iterator = $topics->getIterator();
            while($iterator->valid()) {
                $id = $iterator->key();
                $this->internalPush($topic, $id, $result);
                $iterator->next();
            }
        }
        elseif (is_array($id)) {
            $ids = $id;
            foreach ($ids as $id) {
                $this->internalPush($topic, $id, $result);
            }
        }
        else {
            $this->internalPush($topic, $id, $result);
        }
    }
951851
public function handle(Project $project, $existingResult = null)
    {
        $resultFile = $this->shell->getTempFile('qa', 'json');
        $result = array(
            '3' => $this->countGitChangesPerFile($project, new \DateTime('-3 months')),
            '12' => $this->countGitChangesPerFile($project, new \DateTime('-1 year')),
            'all' => $this->countGitChangesPerFile($project),
        );
        file_put_contents($resultFile, json_encode($result));

        return $resultFile;
    }
151709
protected function handleParentProcess()
    {
        pcntl_wait($status);
        $result = $this->ipc->get();

        if ($result instanceof ExceptionDataHolder) {
            throw new IsolatedCallbackExecutionException($result);
        }

        return $result;
    }
1071953
final public function populateForm(ITypedObject $object)
    {
        $this->verifyObject($object);
        $this->typedObject = $object;
        $this->populateFormWithobject($object);
    }
828344
public function add(string $requestMessage = null) : void
    {
        if ($this->onlineIdParameter() === 'me') return;

        $data = ($requestMessage === null) ? new \stdClass() : [
            "requestMessage" => $requestMessage
        ];

        $this->postJson(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId()), $data);
    }
1199194
public void handleIv2InitiateTaskMessage(Iv2InitiateTaskMessage message)
    {
        final String procedureName = message.getStoredProcedureName();

        /*
         * If this is CL replay, use the txnid from the CL and use it to update the current txnid
         */
        long mpTxnId;
        //Timestamp is actually a pre-IV2ish style time based transaction id
        long timestamp = Long.MIN_VALUE;

        // Update UID if it's for replay
        if (message.isForReplay()) {
            timestamp = message.getUniqueId();
            m_uniqueIdGenerator.updateMostRecentlyGeneratedUniqueId(timestamp);
        } else  {
            timestamp = m_uniqueIdGenerator.getNextUniqueId();
        }

        TxnEgo ego = advanceTxnEgo();
        mpTxnId = ego.getTxnId();

        final String threadName = Thread.currentThread().getName(); // Thread name has to be materialized here
        final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.MPI);
        if (traceLog != null) {
            traceLog.add(() -> VoltTrace.meta("process_name", "name", CoreUtils.getHostnameOrAddress()))
                    .add(() -> VoltTrace.meta("thread_name", "name", threadName))
                    .add(() -> VoltTrace.meta("thread_sort_index", "sort_index", Integer.toString(100)))
                    .add(() -> VoltTrace.beginAsync("initmp", mpTxnId,
                                                    "txnId", TxnEgo.txnIdToString(mpTxnId),
                                                    "ciHandle", message.getClientInterfaceHandle(),
                                                    "name", procedureName,
                                                    "read", message.isReadOnly()));
        }

        // Don't have an SP HANDLE at the MPI, so fill in the unused value
        Iv2Trace.logIv2InitiateTaskMessage(message, m_mailbox.getHSId(), mpTxnId, Long.MIN_VALUE);

        // Handle every-site system procedures (at the MPI)
        final Config sysprocConfig = SystemProcedureCatalog.listing.get(procedureName);
        if (sysprocConfig != null &&  sysprocConfig.getEverysite()) {
            // Send an SP initiate task to all remote sites
            final Long localId = m_mailbox.getHSId();
            Iv2InitiateTaskMessage sp = new Iv2InitiateTaskMessage(
                    localId, // make the MPI the initiator.
                    message.getCoordinatorHSId(),
                    m_repairLogTruncationHandle,
                    mpTxnId,
                    timestamp,
                    message.isReadOnly(),
                    true, // isSinglePartition
                    null,
                    message.getStoredProcedureInvocation(),
                    message.getClientInterfaceHandle(),
                    message.getConnectionId(),
                    message.isForReplay());
            DuplicateCounter counter = new DuplicateCounter(
                    message.getInitiatorHSId(),
                    mpTxnId,
                    m_iv2Masters,
                    message);
            safeAddToDuplicateCounterMap(mpTxnId, counter);
            EveryPartitionTask eptask =
                new EveryPartitionTask(m_mailbox, m_pendingTasks, sp,
                        m_iv2Masters);
            m_pendingTasks.offer(eptask);
            return;
        }
        // Create a copy so we can overwrite the txnID so the InitiateResponse will be
        // correctly tracked.
        Iv2InitiateTaskMessage mp =
            new Iv2InitiateTaskMessage(
                    message.getInitiatorHSId(),
                    message.getCoordinatorHSId(),
                    m_repairLogTruncationHandle,
                    mpTxnId,
                    timestamp,
                    message.isReadOnly(),
                    message.isSinglePartition(),
                    null,
                    message.getStoredProcedureInvocation(),
                    message.getClientInterfaceHandle(),
                    message.getConnectionId(),
                    message.isForReplay());
        // Multi-partition initiation (at the MPI)
        MpProcedureTask task = null;
        if (isNpTxn(message) && NP_PROCEDURE_CLASS.hasProClass()) {
            Set<Integer> involvedPartitions = getBalancePartitions(message);
            if (involvedPartitions != null) {
                HashMap<Integer, Long> involvedPartitionMasters = Maps.newHashMap(m_partitionMasters);
                involvedPartitionMasters.keySet().retainAll(involvedPartitions);

                task = instantiateNpProcedureTask(m_mailbox, procedureName,
                        m_pendingTasks, mp, involvedPartitionMasters,
                        m_buddyHSIds.get(m_nextBuddy), false, m_hostId);
            }

            // if cannot figure out the involved partitions, run it as an MP txn
        }

        int[] nPartitionIds = message.getNParitionIds();
        if (nPartitionIds != null) {
            HashMap<Integer, Long> involvedPartitionMasters = new HashMap<>();
            for (int partitionId : nPartitionIds) {
                involvedPartitionMasters.put(partitionId, m_partitionMasters.get(partitionId));
            }

            task = instantiateNpProcedureTask(m_mailbox, procedureName,
                    m_pendingTasks, mp, involvedPartitionMasters,
                    m_buddyHSIds.get(m_nextBuddy), false, m_hostId);
        }


        if (task == null) {
            task = new MpProcedureTask(m_mailbox, procedureName,
                    m_pendingTasks, mp, m_iv2Masters, m_partitionMasters,
                    m_buddyHSIds.get(m_nextBuddy), false, m_hostId, false);
        }

        m_nextBuddy = (m_nextBuddy + 1) % m_buddyHSIds.size();
        m_outstandingTxns.put(task.m_txnState.txnId, task.m_txnState);
        m_pendingTasks.offer(task);
    }
1223350
public function preUpdate(LifecycleEventArgs $args): void
    {
        // Get the object and make sure it is what we need.
        $object = $args->getObject();
        if (!$object instanceof PublishableInterface) {
            return;
        }

        // Active unpublished objects should be published.
        if ($object->isActive() && !$object->isPublished()) {
            $object->setPublished(true);
        }
    }
1280309
protected function handleDefaults(ParsedMessage $parsedMessage)
    {
        if (!$parsedMessage->getFrom() && $this->defaults['from']['email']) {
            $parsedMessage->setFrom($this->defaults['from']['email'], $this->defaults['from']['name']);
        }

        if (!$parsedMessage->getTo() && $this->defaults['to']['email']) {
            $parsedMessage->addTo($this->defaults['to']['email'], $this->defaults['to']['name']);
        }

        if (!$parsedMessage->getCc() && $this->defaults['cc']['email']) {
            $parsedMessage->addCC($this->defaults['cc']['email'], $this->defaults['cc']['name']);
        }

        if (!$parsedMessage->getBcc() && $this->defaults['bcc']['email']) {
            $parsedMessage->addBcc($this->defaults['bcc']['email'], $this->defaults['bcc']['name']);
        }

        if (!$parsedMessage->getReplyTo() && $this->defaults['replyTo']) {
            $parsedMessage->setReplyTo($this->defaults['replyTo']);
        }

        if (!$parsedMessage->getSubject() && $this->defaults['subject']) {
            $parsedMessage->setSubject($this->defaults['subject']);
        }
    }