@param AggregateType $aggregateType
@param Iterator $historyEvents

@return object reconstructed AggregateRoot
352973
public function reconstituteAggregateFromHistory(AggregateType $aggregateType, Iterator $historyEvents)
    {
        if (null === $this->aggregateReconstructor) {
            $arId = $this->aggregateId;
            $eventApplyMap = $this->eventApplyMap;
            $flavour = $this->flavour;
            $this->aggregateReconstructor = function ($historyEvents) use ($arId, $aggregateType, $eventApplyMap, $flavour) {
                return static::reconstituteFromHistory($arId, $aggregateType, $eventApplyMap, $flavour, $historyEvents);
            };
        }

        return ($this->aggregateReconstructor->bindTo(null, GenericAggregateRoot::class))($historyEvents);
    }
511918
function assertHistoryType (history) {
  assertType("history", "object", history);
  assertType("history.listen", "function", history.listen);
  assertType("history.push", "function", history.push);
  assertType("history.replace", "function", history.replace);
  assertType("history.goBack", "function", history.goBack);
}
516789
AggregateIterable<BsonDocument> aggregate(
      final MongoNamespace namespace,
      final List<? extends Bson> pipeline) {
    return aggregate(namespace, pipeline, BsonDocument.class);
  }
1094007
@SuppressWarnings("unchecked")
    public static Set<Class<? extends AggregateRoot<?>>> includeSuperClasses(
            Collection<Class<? extends AggregateRoot>> aggregateClasses) {
        Set<Class<? extends AggregateRoot<?>>> results = new HashSet<>();
        for (Class<?> aggregateClass : aggregateClasses) {
            Class<?> classToAdd = aggregateClass;
            while (classToAdd != null) {
                if (AggregateRoot.class.isAssignableFrom(classToAdd) && !classToAdd.equals(
                        BaseAggregateRoot.class) && !classToAdd.equals(AggregateRoot.class)) {
                    results.add((Class<? extends AggregateRoot<?>>) classToAdd);
                    classToAdd = classToAdd.getSuperclass();
                } else {
                    break;
                }
            }
        }
        return results;
    }
921232
protected boolean isHistoryEventProduced(HistoryEventType eventType, Job job) {
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    HistoryLevel historyLevel = configuration.getHistoryLevel();
    return historyLevel.isHistoryEventProduced(eventType, job);
  }
548532
private function buildEventAggregate(array $rows, $returnType)
    {
        if ($returnType === self::RETURN_AS_ARRAY) {
            return $this->buildEventAggregateAsArray($rows);
        }

        return $this->buildEventAggregateAsObject($rows);
    }
86799
public function get(Identity $aggregateId)
    {
        if (!is_null($this->snapshotStore)) {
            if (!($snapshot = $this->loadSnapshot($aggregateId))) {
                $missing = $this->eventStore->getAggregateHistoryFor($aggregateId, $snapshot->getVersion());

                if ($missing->count() > 0) {
                    $snapshot->correctMissingHistory($missing);
                }

                return $snapshot->getAggregate();
            }
        }

        $aggregateHistory = $this->eventStore->getAggregateHistoryFor($aggregateId);
        $fqn = $this->getAggregateRootFqcn();

        return $fqn::reconstituteFrom($aggregateHistory);
    }
523720
protected void retrieveAggregateRoot(final Set<String> removedNodeIds, final Map<String, NodeData> map)
   {
      if (indexingConfig != null)
      {
         AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
         if (aggregateRules == null)
         {
            return;
         }
         long time = 0;
         if (log.isDebugEnabled())
         {
            time = System.currentTimeMillis();
         }
         int found = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Integer>()
         {
            public Integer run()
            {
               int found = 0;
               try
               {
                  CachingMultiIndexReader reader = indexRegister.getDefaultIndex().getIndexReader();
                  try
                  {
                     Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
                     TermDocs tDocs = reader.termDocs();
                     try
                     {
                        ItemDataConsumer ism = getContext().getItemStateManager();
                        for (Iterator<String> it = removedNodeIds.iterator(); it.hasNext();)
                        {
                           String id = it.next();
                           aggregateUUIDs = aggregateUUIDs.createTerm(id);
                           tDocs.seek(aggregateUUIDs);
                           while (tDocs.next())
                           {
                              Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
                              String uuid = doc.get(FieldNames.UUID);
                              ItemData itd = ism.getItemData(uuid);
                              if (itd == null)
                              {
                                 continue;
                              }
                              if (!itd.isNode())
                              {
                                 throw new RepositoryException("Item with id:" + uuid + " is not a node");
                              }
                              map.put(uuid, (NodeData)itd);
                              found++;
                           }
                        }
                     }
                     finally
                     {
                        tDocs.close();
                     }
                  }
                  finally
                  {
                     reader.release();
                  }
               }
               catch (Exception e)
               {
                  log.warn("Exception while retrieving aggregate roots", e);
               }
               return found;
            }
         });
         if (log.isDebugEnabled())
         {
            time = System.currentTimeMillis() - time;
            log.debug("Retrieved {} aggregate roots in {} ms.", new Integer(found), new Long(time));
         }
      }
   }
239979
public function byUuid(AggregateUuid $uuid, $returnType = self::RETURN_AS_ARRAY)
    {
        $uuid = (string) $uuid;
        $query = 'SELECT
                  `uuid`,
                  `version`,
                  `payload`,
                  `type`,
                  `body`,
                  `occurred_on`
                FROM `'.PdoDriver::EVENTSTORE_TABLE_NAME.'` 
                WHERE `uuid` = :uuid
                ORDER BY `occurred_on` ASC';
        $stmt = $this->pdo->prepare($query);
        $stmt->bindParam(':uuid', $uuid);
        $stmt->execute();

        $row = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        if (!empty($row)) {
            return $this->buildEventAggregate($row, $returnType);
        }

        return null;
    }
1027226
private function getTable(AggregateType $aggregateType)
    {
        if (isset($this->snapshotTableMap[$aggregateType->toString()])) {
            $tableName = $this->snapshotTableMap[$aggregateType->toString()];
        } else {
            $tableName = strtolower($this->getShortAggregateTypeName($aggregateType));
            if (strpos($tableName, "_snapshot") === false) {
                $tableName.= "_snapshot";
            }
        }
        return $tableName;
    }
624264
public function createSnapshot(AggregateId $aggregateId) : void
    {
        if (!$this->eventSourced($aggregateId)) {
            return;
        }
        /* @var $aggregateRoot EventSourcedAggregateRoot */
        $aggregateRoot = $this->loadSnapshot($aggregateId);
        $stateHash = $aggregateRoot === null ? null : $aggregateRoot->stateHash();
        $events = $this->getEventsFor($aggregateId, $stateHash);
        if ($events->count() == 0) {
            return;
        }
        if ($aggregateRoot === null) {
            $aggregateRoot = ObjectClass::forName($aggregateId->aggregateClass())->newInstanceWithoutConstructor();
        }
        $aggregateRoot->loadFromHistory($events);
        $this->doCreateSnapshot($aggregateRoot);
    }
985113
public function replayHistory(EventDispatcher $eventDispatcher): void
    {
        $allEvents = $this->storageFacility->loadAllEvents();
        foreach ($allEvents as $rawEvent) {
            $eventDispatcher->dispatch($this->restoreEvent($rawEvent));
        }
    }
504662
public function aggregateBy(
        string $filterName,
        string $field,
        int $applicationType,
        array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC,
        int $limit = Aggregation::NO_LIMIT
    ): self {
        $this->aggregations[$filterName] = Aggregation::create(
            $filterName,
            Item::getPathByField($field),
            $applicationType,
            Filter::TYPE_FIELD,
            [],
            $aggregationSort,
            $limit
        );

        return $this;
    }
707407
private function processAggregates($aggregates)
    {
        // Step 1. Calculate the aggregate group values.
        foreach ($this->collectionCursor as $model) {
            foreach ($aggregates as $aggregate) {
                $aggregate->calculateByIteration($model, $this->getGroupKeyForModel($model));
            }
        }

        $additionalData = [];

        // Step 2. Extract the group values and apply to models using augmentation data.
        foreach ($aggregates as $aggregate) {
            $groups = $aggregate->getGroups();

            foreach ($this->collectionCursor as $model) {
                $id = $model->UniqueIdentifier;
                $groupKey = $this->getGroupKeyForModel($model);

                if (!isset($additionalData[$id])) {
                    $additionalData[$id] = [];
                }

                if (isset($groups[$groupKey])) {
                    $additionalData[$id][$aggregate->getAlias()] = $groups[$groupKey];
                }
            }
        }

        // Give the cursor the augmentation data.
        $this->collectionCursor->setAugmentationData($additionalData);
    }
707002
public function read(Contract $aggregateRootType, AggregateRootIdentifier $aggregateRootIdentifier)
    {
        $statement = $this->selectQuery->prepare();

        $statement->bindValue(':aggregate_id', $aggregateRootIdentifier->toString());
        $statement->bindValue(':aggregate_type', $aggregateRootType->toString());

        $statement->execute();

        $records = $statement->fetchAll(\PDO::FETCH_ASSOC);
        $statement->closeCursor();

        return new PdoReadRecordEventStream(
            $aggregateRootIdentifier,
            $records,
            $this->eventSerializer
        );
    }
863007
public static function createAggregateCommandHandlerWith(string $inputChannelName, string $aggregateClassName, string $methodName): self
    {
        return new self($inputChannelName, $aggregateClassName, $methodName, true, "", true);
    }
685966
public static HistoryDTO transformToDto(History history) {
        if (history == null) {
            throw new WebApplicationException("Null entity object cannot be converted to Dto object.", Status.INTERNAL_SERVER_ERROR);
        }

        HistoryDTO historyDto = new HistoryDTO();

        try {
            BeanUtils.copyProperties(historyDto, history);
        } catch (Exception ex) {
            throw new WebApplicationException("DTO transformation failed.", Status.INTERNAL_SERVER_ERROR);
        }
        return historyDto;
    }