/**
  * Adds all roles found in the Policy to the role repository that are not yet
  * in persistent storage.
  *
  * @return void
  * @throws \TYPO3\Flow\Security\Exception\NoSuchRoleException
  */
 public function initializeRolesFromPolicy()
 {
     // for compile time the repository needs to be inject manually:
     if ($this->roleRepository === NULL) {
         $this->roleRepository = $this->objectManager->get('TYPO3\\Flow\\Security\\Policy\\RoleRepository');
     }
     if (!$this->objectManager->get('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface')->isConnected()) {
         // Skip synchronization if no connection on the persistence manager is available
         return;
     }
     if ($this->initializedRoles !== TRUE && !$this->cache->has('rolesFromPolicyUpToDate')) {
         if ($this->roleRepository->findByIdentifier('Anonymous') === NULL) {
             $this->roleRepository->add($this->systemRoles['Anonymous']);
         }
         if ($this->roleRepository->findByIdentifier('Everybody') === NULL) {
             $this->roleRepository->add($this->systemRoles['Everybody']);
         }
         if ($this->roleRepository->findByIdentifier('AuthenticatedUser') === NULL) {
             $this->roleRepository->add($this->systemRoles['AuthenticatedUser']);
         }
         if (isset($this->policy['roles']) && is_array($this->policy['roles'])) {
             foreach ($this->policy['roles'] as $roleIdentifier => $roleConfiguration) {
                 if ($this->roleRepository->findByIdentifier($roleIdentifier) === NULL) {
                     $this->roleRepository->add(new \TYPO3\Flow\Security\Policy\Role($roleIdentifier, Role::SOURCE_POLICY));
                 }
             }
             // Add parent roles
             foreach ($this->policy['roles'] as $roleIdentifier => $parentRoleIdentifiers) {
                 $parentRoles = array();
                 foreach ($parentRoleIdentifiers as $parentRoleIdentifier) {
                     if (($parentRole = $this->roleRepository->findByIdentifier($parentRoleIdentifier)) !== NULL) {
                         $parentRoles[] = $parentRole;
                     } else {
                         $hint = strpos($parentRoleIdentifier, '.') !== FALSE || strpos($parentRoleIdentifier, ':') !== FALSE ? ' Make sure that the package which might provide that role, is currently installed and defines that role in its policy.' : ' If you are referring to a role defined in a different package, make sure to specify the fully qualified role name.';
                         $message = sprintf('The role "%s" which was declared as a parent role for "%s" does not exist.%s Please adjust your Policy.yaml files to fix the problem.', $parentRoleIdentifier, $roleIdentifier, $hint);
                         throw new \TYPO3\Flow\Security\Exception\NoSuchRoleException($message, 1352971524);
                     }
                 }
                 if ($parentRoles !== array()) {
                     $this->roleRepository->findByIdentifier($roleIdentifier)->setParentRoles($parentRoles);
                 }
             }
         }
         $this->roleRepository->persistEntities();
         $this->cache->set('rolesFromPolicyUpToDate', 'Yes, Sir!');
     }
     $this->initializedRoles = TRUE;
 }
 /**
  * Return the options to fill the select fields in Kloster edit form
  * @FLOW\SkipCsrfProtection
  * @return array $response select options as JSON
  */
 public function getOptionsAction()
 {
     // Bearbeitungsstatus data
     $bearbeitungsstatusArr = [];
     $this->bearbeitungsstatusRepository->setDefaultOrderings(['name' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bearbeitungsstatuses = $this->bearbeitungsstatusRepository->findAll();
     foreach ($bearbeitungsstatuses as $bearbeitungsstatus) {
         $bearbeitungsstatusArr[$bearbeitungsstatus->getUUID()] = $bearbeitungsstatus->getName();
     }
     // Personallistenstatus data
     $personallistenstatusArr = [];
     $personallistenstatuses = $this->personallistenstatusRepository->findAll();
     foreach ($personallistenstatuses as $personallistenstatus) {
         $personallistenstatusArr[$personallistenstatus->getUUID()] = $personallistenstatus->getName();
     }
     // Band data
     $bandArr = [];
     $this->bandRepository->setDefaultOrderings(['sortierung' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bands = $this->bandRepository->findAll();
     foreach ($bands as $band) {
         $bandNummerTitel = $band->getNummer() . '-' . $band->getTitel();
         $bandArr[$band->getUUID()] = $bandNummerTitel;
     }
     // Literature data for select box
     $literaturArr = $this->getLiteraturAction();
     // Bistum data for select box
     $bistumArr = [];
     $this->bistumRepository->setDefaultOrderings(['bistum' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bistums = $this->bistumRepository->findAll();
     foreach ($bistums as $bistum) {
         if ($bistum->getBistum() != 'keine Angabe') {
             $bistumArr[$bistum->getUUID()] = $bistum->getBistum();
         } else {
             $bistumArr[$bistum->getUUID()] = '––';
         }
     }
     // Orden data for select box
     $ordenArr = [];
     $this->ordenRepository->setDefaultOrderings(['orden' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $ordens = $this->ordenRepository->findAll();
     foreach ($ordens as $orden) {
         $ordenArr[$orden->getUUID()] = $orden->getOrden();
     }
     // Ordenstyp data for select box
     $ordenstypArr = [];
     $this->ordenstypRepository->setDefaultOrderings(['ordenstyp' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $ordenstyps = $this->ordenstypRepository->findAll();
     foreach ($ordenstyps as $ordenstyp) {
         $ordenstypArr[$ordenstyp->getUUID()] = $ordenstyp->getOrdenstyp();
     }
     // Klosterstatus data for select box
     $klosterstatusArr = [];
     $this->klosterstatusRepository->setDefaultOrderings(['status' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $klosterstatuses = $this->klosterstatusRepository->findAll();
     foreach ($klosterstatuses as $klosterstatus) {
         if ($klosterstatus->getStatus() != 'keine Angabe') {
             $klosterstatusArr[$klosterstatus->getUUID()] = $klosterstatus->getStatus();
         } else {
             $klosterstatusArr[$klosterstatus->getUUID()] = '––';
         }
     }
     // Bearbeiter data for select box
     $bearbeiterArr = [];
     $this->bearbeiterRepository->setDefaultOrderings(['bearbeiter' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $bearbeiters = $this->bearbeiterRepository->findAll();
     foreach ($bearbeiters as $bearbeiter) {
         $bearbeiterArr[$bearbeiter->getUUID()] = $bearbeiter->getBearbeiter();
     }
     // URL-Typ data for select box
     $urltypArr = [];
     $this->urltypRepository->setDefaultOrderings(['name' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $urltyps = $this->urltypRepository->findAll();
     foreach ($urltyps as $urltyp) {
         if ($urltyp->getName() != 'GND' && $urltyp->getName() != 'Wikipedia') {
             $urltypArr[$urltyp->getUUID()] = $urltyp->getName();
         }
     }
     // Land data for select box
     $landArr = [];
     $this->landRepository->setDefaultOrderings(['land' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING]);
     $lands = $this->landRepository->findAll();
     foreach ($lands as $land) {
         $landArr[$land->getUUID()] = $land->getLand();
     }
     // Bearbeiter roles
     $roleArr = [];
     foreach ($this->roleRepository->findAll()->toArray() as $role) {
         if (stristr($role->getIdentifier(), 'Flow.Login')) {
             $roleValues = explode(':', $role->getIdentifier());
             $roleArr[$role->getIdentifier()] = $roleValues[1];
         }
     }
     $response = [];
     $response['bearbeitungsstatus'] = $bearbeitungsstatusArr;
     $response['personallistenstatus'] = $personallistenstatusArr;
     $response['band'] = $bandArr;
     $response['literatur'] = $literaturArr;
     $response['bistum'] = $bistumArr;
     $response['orden'] = $ordenArr;
     $response['ordenstyp'] = $ordenstypArr;
     $response['klosterstatus'] = $klosterstatusArr;
     $response['bearbeiter'] = $bearbeiterArr;
     $response['url_typ'] = $urltypArr;
     $response['land'] = $landArr;
     $response['role'] = $roleArr;
     $getOptions = json_encode($response);
     return $getOptions;
 }