resource = $resource; $this->experimentalSchemeFactory = $experimentalSchemeFactory; $this->experimentalSchemeCollectionFactory = $experimentalSchemeCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->collectionProcessor = $collectionProcessor; } /** * @inheritDoc */ public function save( ExperimentalSchemeInterface $experimentalScheme ) { try { $this->resource->save($experimentalScheme); } catch (\Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the experimentalScheme: %1', $exception->getMessage() )); } return $experimentalScheme; } /** * @inheritDoc */ public function get($experimentalSchemeId) { $experimentalScheme = $this->experimentalSchemeFactory->create(); $this->resource->load($experimentalScheme, $experimentalSchemeId); if (!$experimentalScheme->getId()) { throw new NoSuchEntityException(__('ExperimentalScheme with id "%1" does not exist.', $experimentalSchemeId)); } return $experimentalScheme; } /** * @inheritDoc */ public function getList( \Magento\Framework\Api\SearchCriteriaInterface $criteria ) { $collection = $this->experimentalSchemeCollectionFactory->create(); $this->collectionProcessor->process($criteria, $collection); $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); $items = []; foreach ($collection as $model) { $items[] = $model; } $searchResults->setItems($items); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } /** * @inheritDoc */ public function delete( ExperimentalSchemeInterface $experimentalScheme ) { try { $experimentalSchemeModel = $this->experimentalSchemeFactory->create(); $this->resource->load($experimentalSchemeModel, $experimentalScheme->getExperimentalschemeId()); $this->resource->delete($experimentalSchemeModel); } catch (\Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the ExperimentalScheme: %1', $exception->getMessage() )); } return true; } /** * @inheritDoc */ public function deleteById($experimentalSchemeId) { return $this->delete($this->get($experimentalSchemeId)); } }