/**
  * Handle the create step of object state migrations.
  *
  * @throws \Exception
  */
 protected function create()
 {
     foreach (array('object_state_group', 'names', 'identifier') as $key) {
         if (!isset($this->dsl[$key])) {
             throw new \Exception("The '{$key}' key is missing in a object state creation definition");
         }
     }
     if (!count($this->dsl['names'])) {
         throw new \Exception('No object state names have been defined. Need to specify at least one to create the state.');
     }
     $objectStateService = $this->repository->getObjectStateService();
     $objectStateGroupId = $this->dsl['object_state_group'];
     $objectStateGroupId = $this->referenceResolver->resolveReference($objectStateGroupId);
     $objectStateGroup = $this->objectStateGroupMatcher->matchOneByKey($objectStateGroupId);
     $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($this->dsl['identifier']);
     $objectStateCreateStruct->defaultLanguageCode = self::DEFAULT_LANGUAGE_CODE;
     foreach ($this->dsl['names'] as $languageCode => $name) {
         $objectStateCreateStruct->names[$languageCode] = $name;
     }
     if (isset($this->dsl['descriptions'])) {
         foreach ($this->dsl['descriptions'] as $languageCode => $description) {
             $objectStateCreateStruct->descriptions[$languageCode] = $description;
         }
     }
     $objectState = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);
     $this->setReferences($objectState);
     return $objectState;
 }
 /**
  * @param string $action
  * @return ObjectStateGroupCollection
  * @throws \Exception
  */
 protected function matchObjectStateGroups($action)
 {
     if (!isset($this->dsl['match'])) {
         throw new \Exception("A match condition is required to {$action} an ObjectStateGroup.");
     }
     $match = $this->dsl['match'];
     // convert the references passed in the match
     foreach ($match as $condition => $values) {
         if (is_array($values)) {
             foreach ($values as $position => $value) {
                 $match[$condition][$position] = $this->referenceResolver->resolveReference($value);
             }
         } else {
             $match[$condition] = $this->referenceResolver->resolveReference($values);
         }
     }
     return $this->objectStateGroupMatcher->match($match);
 }