diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ccfc0055..54fd1424d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ## 3.2.0 +### Added + +- Code generation for a Magento Entity in [#521](https://github.com/magento/magento2-phpstorm-plugin/pull/521) +- Code generation for email templates in [#350](https://github.com/magento/magento2-phpstorm-plugin/pull/350) +- Reference navigation for disabled observers in `events.xml` in [#439](https://github.com/magento/magento2-phpstorm-plugin/pull/439) +- Line markers for test fixtures in [#477](https://github.com/magento/magento2-phpstorm-plugin/pull/477) + +### Changed + +- Added ability to set the module sequence at generating new module [#266](https://github.com/magento/magento2-phpstorm-plugin/pull/266) + +### Fixed + +- ArrayIndexOutOfBoundsException in the New Module Action in [#519](https://github.com/magento/magento2-phpstorm-plugin/pull/519) + ## 3.1.3 ### Changed diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 633c25327..8e8420cb4 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -58,6 +58,7 @@ + @@ -229,6 +230,18 @@ + + + + + + + + + + + + diff --git a/resources/fileTemplates/code/Magento Entity Data Mapper.html.ft b/resources/fileTemplates/code/Magento Entity Data Mapper.html.ft new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/code/Magento Entity Data Mapper.html.ft @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft b/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft new file mode 100644 index 000000000..12644efb2 --- /dev/null +++ b/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft @@ -0,0 +1,52 @@ +entityDtoFactory = $entityDtoFactory; + } + + /** + * Map magento models to DTO array. + * + * @param ${ABSTRACT_COLLECTION} $collection + * + * @return array|${DTO_TYPE}[] + */ + public function map(${ABSTRACT_COLLECTION} $collection): array + { + $results = []; + /** @var ${MAGENTO_MODEL_TYPE} $item */ + foreach ($collection->getItems() as $item) { + /** @var ${DTO_TYPE}|${DATA_OBJECT} $entityDto */ + $entityDto = $this->entityDtoFactory->create(); + $entityDto->addData($item->getData()); + + #set($brackets = "[]") + $results$brackets = $entityDto; + } + + return $results; + } +} diff --git a/resources/fileTemplates/code/Magento Grid UI Component Column.xml.ft b/resources/fileTemplates/code/Magento Grid UI Component Column.xml.ft new file mode 100644 index 000000000..99a43eec6 --- /dev/null +++ b/resources/fileTemplates/code/Magento Grid UI Component Column.xml.ft @@ -0,0 +1,8 @@ + + +#if (${COLUMN_FILTER}) + ${COLUMN_FILTER} +#end + + + diff --git a/resources/fileTemplates/code/Magento Grid UI Component Column.xml.html b/resources/fileTemplates/code/Magento Grid UI Component Column.xml.html new file mode 100644 index 000000000..e69de29bb diff --git a/resources/fileTemplates/code/Magento Module UI Component Form Field Xml.xml.ft b/resources/fileTemplates/code/Magento Module UI Component Form Field Xml.xml.ft index b00a302f6..6075b7ec2 100644 --- a/resources/fileTemplates/code/Magento Module UI Component Form Field Xml.xml.ft +++ b/resources/fileTemplates/code/Magento Module UI Component Form Field Xml.xml.ft @@ -9,4 +9,17 @@ ${NAME} + #if(${FORM_ELEMENT} == 'checkbox') + + + + + 0 + 1 + + toggle + + + + #end diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.ft b/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.ft deleted file mode 100644 index d86f741cd..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.ft +++ /dev/null @@ -1,6 +0,0 @@ - return [ - 'label' => __('${BUTTON_LABEL}'), - 'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')), - 'class' => 'back', - 'sort_order' => ${BUTTON_SORT_ORDER} - ]; diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.html b/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.html deleted file mode 100644 index 8b1378917..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.ft b/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.ft deleted file mode 100644 index 48e12ec46..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.ft +++ /dev/null @@ -1,11 +0,0 @@ - return [ - 'label' => __('${BUTTON_LABEL}'), - 'class' => 'delete', - 'on_click' => 'deleteConfirm(\'' . __( - 'Are you sure you want to do this?' - ) . '\', \'' . - //TODO: adjust entity ID - $this->getUrl('*/*/${BUTTON_ROUTE}', ['entity_id' => '']) - . '\', {"data": {}})', - 'sort_order' => ${BUTTON_SORT_ORDER} - ]; diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.html b/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.html deleted file mode 100644 index 8b1378917..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.ft b/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.ft deleted file mode 100644 index 17e374d26..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.ft +++ /dev/null @@ -1,22 +0,0 @@ - return [ - 'label' => __('${BUTTON_LABEL}'), - 'class' => 'save primary', - 'on_click' => '', - 'data_attribute' => [ - 'mage-init' => [ - 'Magento_Ui/js/form/button-adapter' => [ - 'actions' => [ - [ - 'targetName' => '${FORM_NAME}.${FORM_NAME}', - 'actionName' => 'save', - 'params' => [ - true, - //TODO: adjust entity ID - ['entity_id' => ''], - ] - ] - ] - ] - ] - ] - ]; diff --git a/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.html b/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.html deleted file mode 100644 index 8b1378917..000000000 --- a/resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft new file mode 100644 index 000000000..ac18b5b21 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft @@ -0,0 +1,83 @@ +logger = $logger; + $this->modelFactory = $modelFactory; + $this->resource = $resource; + } + + /** + * Delete ${ENTITY_NAME}. + * + * @param int $entityId + * + * @return void + * @throws ${COULD_NOT_DELETE}|${NO_SUCH_ENTITY_EXCEPTION} + */ + public function execute(int $entityId) + { + try { + /** @var ${MODEL} $model */ + $model = $this->modelFactory->create(); + $this->resource->load($model, $entityId, '${ENTITY_ID}'); + + if (!$model->getData('${ENTITY_ID}')) { + throw new ${NO_SUCH_ENTITY_EXCEPTION}( + __('Could not find ${ENTITY_NAME} with id: `%id`', + [ + 'id' => $entityId + ] + ) + ); + } + + $this->resource->delete($model); + } catch (Exception $exception) { + $this->logger->error( + __('Could not delete ${ENTITY_NAME}. Original message: {message}'), + [ + 'message' => $exception->getMessage(), + 'exception' => $exception + ] + ); + throw new ${COULD_NOT_DELETE}(__('Could not delete ${ENTITY_NAME}.')); + } + } +} diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.ft new file mode 100644 index 000000000..432f096c4 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.ft @@ -0,0 +1,61 @@ +deleteByIdCommand = $deleteByIdCommand; + } + + /** + * Delete ${ENTITY_NAME} action. + * + * @return ${RESULT_INTERFACE} + */ + public function execute() + { + /** @var ${RESULT_INTERFACE} $resultRedirect */ + $resultRedirect = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_REDIRECT); + $resultRedirect->setPath('*/*/'); + $entityId = (int) $this->getRequest()->getParam('${ENTITY_ID}'); + + try { + $this->deleteByIdCommand->execute($entityId); + $this->messageManager->addSuccessMessage(__('You have successfully deleted ${ENTITY_NAME} entity')); + } catch (${COULD_NOT_DELETE} | ${NO_SUCH_ENTITY_EXCEPTION} $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); + } + + return $resultRedirect; + } +} diff --git a/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.html b/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.ft new file mode 100644 index 000000000..14bc769dd --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.ft @@ -0,0 +1,37 @@ +resultFactory->create(${RESULT_FACTORY}::TYPE_PAGE); + $resultPage->setActiveMenu('${MENU_IDENTIFIER}'); + $resultPage->getConfig()->getTitle()->prepend(__('Edit ${ENTITY_NAME}')); + + return $resultPage; + } +} diff --git a/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.html b/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.ft new file mode 100644 index 000000000..0573d9fa8 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.ft @@ -0,0 +1,37 @@ +resultFactory->create(${RESULT_FACTORY}::TYPE_PAGE); + + $resultPage->setActiveMenu('${MENU}'); + $resultPage->addBreadcrumb(__('${ENTITY_NAME}'), __('${ENTITY_NAME}')); + $resultPage->addBreadcrumb(__('Manage ${ENTITY_NAME}s'), __('Manage ${ENTITY_NAME}s')); + $resultPage->getConfig()->getTitle()->prepend(__('${ENTITY_NAME} List')); + + return $resultPage; + } +} diff --git a/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.html b/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft new file mode 100644 index 000000000..36989b2c2 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft @@ -0,0 +1,37 @@ +resultFactory->create(${RESULT_FACTORY}::TYPE_PAGE); + $resultPage->setActiveMenu('${MENU_IDENTIFIER}'); + $resultPage->getConfig()->getTitle()->prepend(__('New ${ENTITY_NAME}')); + + return $resultPage; + } +} diff --git a/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.html b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft new file mode 100644 index 000000000..552eac78c --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft @@ -0,0 +1,86 @@ +dataPersistor = $dataPersistor; + $this->saveCommand = $saveCommand; + $this->entityDataFactory = $entityDataFactory; + } + + /** + * Save ${ENTITY_NAME} Action. + * + * @return ResponseInterface|ResultInterface + */ + public function execute() + { + $resultRedirect = $this->resultRedirectFactory->create(); + $params = $this->getRequest()->getParams(); + + try { + /** @var ${ENTITY_DTO}|${DATA_OBJECT} $entityModel */ + $entityModel = $this->entityDataFactory->create(); + $entityModel->addData($params['general']); + $this->saveCommand->execute($entityModel); + $this->messageManager->addSuccessMessage( + __('The ${ENTITY_NAME} data was saved successfully') + ); + $this->dataPersistor->clear('entity'); + } catch (${COULD_NOT_SAVE} $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); + $this->dataPersistor->set('entity', $params); + + return $resultRedirect->setPath('*/*/edit', [ + '${ENTITY_ID}'=> $this->getRequest()->getParam('${ENTITY_ID}') + ]); + } + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.html b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft b/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft index e0620a3de..89897c75a 100644 --- a/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft +++ b/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft @@ -1,22 +1,31 @@ wrapButtonSettings( + '${LABEL}', + '${CLASS}', + ${ON_CLICK}, + ${DATA_ATTRS}, + ${SORT_ORDER} + ); } } diff --git a/resources/fileTemplates/internal/Magento Get List Query Model.php.ft b/resources/fileTemplates/internal/Magento Get List Query Model.php.ft new file mode 100644 index 000000000..bff40b0fd --- /dev/null +++ b/resources/fileTemplates/internal/Magento Get List Query Model.php.ft @@ -0,0 +1,90 @@ +collectionProcessor = $collectionProcessor; + $this->entityCollectionFactory = $entityCollectionFactory; + $this->entityDataMapper = $entityDataMapper; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->searchResultFactory = $searchResultFactory; + } + + /** + * Get ${ENTITY_NAME} list by search criteria. + * + * @param ${SEARCH_CRITERIA_TYPE}|null $searchCriteria + * + * @return ${SEARCH_RESULT_TYPE} + */ + public function execute(?${SEARCH_CRITERIA_TYPE} $searchCriteria = null): ${SEARCH_RESULT_TYPE} + { + /** @var ${ENTITY_COLLECTION_TYPE} $collection */ + $collection = $this->entityCollectionFactory->create(); + + if ($searchCriteria === null) { + $searchCriteria = $this->searchCriteriaBuilder->create(); + } else { + $this->collectionProcessor->process($searchCriteria, $collection); + } + + $entityDataObjects = $this->entityDataMapper->map($collection); + + /** @var ${SEARCH_RESULT_TYPE} $searchResult */ + $searchResult = $this->searchResultFactory->create(); + $searchResult->setItems($entityDataObjects); + $searchResult->setTotalCount($collection->getSize()); + $searchResult->setSearchCriteria($searchCriteria); + + return $searchResult; + } +} diff --git a/resources/fileTemplates/internal/Magento Get List Query Model.php.html b/resources/fileTemplates/internal/Magento Get List Query Model.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Get List Query Model.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft new file mode 100644 index 000000000..06a29a555 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft @@ -0,0 +1,122 @@ +urlBuilder = $urlBuilder; + } + + /** + * @inheritDoc + */ + public function prepareDataSource(array $dataSource): array + { + #set($entityIdAccessor = "['" + ${ENTITY_ID} + "']") + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as &$item) { + if (isset($item$entityIdAccessor)) { + $entityName = static::ENTITY_NAME; + $urlData = ['${ENTITY_ID}' => $item$entityIdAccessor]; + + $editUrl = $this->urlBuilder->getUrl(static::EDIT_URL_PATH, $urlData); + $deleteUrl = $this->urlBuilder->getUrl(static::DELETE_URL_PATH, $urlData); + + #set($columnNameAccessor = "[$this->getData('name')]") + $item$columnNameAccessor = [ + 'edit' => $this->getActionData($editUrl, (string) __('Edit')), + 'delete' => $this->getActionData( + $deleteUrl, + (string) __('Delete'), + (string) __('Delete %1', $entityName), + (string) __('Are you sure you want to delete a %1 record?', $entityName) + ) + ]; + } + } + } + + return $dataSource; + } + + /** + * Get action link data array. + * + * @param string $url + * @param string $label + * @param string|null $dialogTitle + * @param string|null $dialogMessage + * + * @return array + */ + private function getActionData( + string $url, + string $label, + ?string $dialogTitle = null, + ?string $dialogMessage = null + ): array { + $data = [ + 'href' => $url, + 'label' => $label, + 'post' => true, + '__disableTmpl' => true + ]; + + #set($confirmKeyAccessor = "['confirm']") + if ($dialogTitle && $dialogMessage) { + $data$confirmKeyAccessor = [ + 'title' => $dialogTitle, + 'message' => $dialogMessage + ]; + } + + return $data; + } +} diff --git a/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.html b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento New Entity Layout XML.xml.ft b/resources/fileTemplates/internal/Magento New Entity Layout XML.xml.ft new file mode 100644 index 000000000..0e2b03c76 --- /dev/null +++ b/resources/fileTemplates/internal/Magento New Entity Layout XML.xml.ft @@ -0,0 +1,4 @@ + + + diff --git a/resources/fileTemplates/internal/Magento New Entity Layout XML.xml.html b/resources/fileTemplates/internal/Magento New Entity Layout XML.xml.html new file mode 100644 index 000000000..e69de29bb diff --git a/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.ft b/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.ft new file mode 100644 index 000000000..998ebb28a --- /dev/null +++ b/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.ft @@ -0,0 +1,85 @@ +context = $context; + $this->urlBuilder = $context->getUrlBuilder(); + } + + /** + * Get ${ENTITY_NAME} entity id. + * + * @return int + */ + public function ${ENTITY_ID_GETTER}(): int + { + return (int) $this->context->getRequest()->getParam('${ENTITY_ID}'); + } + + /** + * Wrap button specific options to settings array. + * + * @param string $label + * @param string $class + * @param string $onclick + * @param array $dataAttribute + * @param int $sortOrder + * + * @return array + */ + protected function wrapButtonSettings( + string $label, + string $class, + string $onclick = '', + array $dataAttribute = [], + int $sortOrder = 0 + ): array { + return [ + 'label' => $label, + 'on_click' => $onclick, + 'data_attribute' => $dataAttribute, + 'class' => $class, + 'sort_order' => $sortOrder + ]; + } + + /** + * Get url. + * + * @param string $route + * @param array $params + * + * @return string + */ + protected function getUrl(string $route, array $params = []): string + { + return $this->urlBuilder->getUrl($route, $params); + } +} diff --git a/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.html b/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.html new file mode 100644 index 000000000..fcc119088 --- /dev/null +++ b/resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft index 701392df7..bb33568bb 100644 --- a/resources/fileTemplates/internal/Magento Resource Model Class.php.ft +++ b/resources/fileTemplates/internal/Magento Resource Model Class.php.ft @@ -22,5 +22,6 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen protected function _construct() { $this->_init('${DB_NAME}', '${ENTITY_ID_COLUMN}'); + $this->_useIsObjectNew = true; } } diff --git a/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft new file mode 100644 index 000000000..39bf47820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft @@ -0,0 +1,79 @@ +logger = $logger; + $this->modelFactory = $modelFactory; + $this->resource = $resource; + } + + /** + * Save ${ENTITY_NAME}. + * + * @param ${DTO}|${DATA_OBJECT} $${DTO_PROPERTY} + * + * @return int + * @throws ${COULD_NOT_SAVE} + */ + public function execute(${DTO} $${DTO_PROPERTY}): int + { + try { + /** @var ${MODEL} $model */ + $model = $this->modelFactory->create(); + $model->addData($${DTO_PROPERTY}->getData()); + $model->setHasDataChanges(true); + + if (!$model->getId()) { + $model->isObjectNew(true); + } + $this->resource->save($model); + } catch (${EXCEPTION} $exception) { + $this->logger->error( + __('Could not save ${ENTITY_NAME}. Original message: {message}'), + [ + 'message' => $exception->getMessage(), + 'exception' => $exception + ] + ); + throw new ${COULD_NOT_SAVE}(__('Could not save ${ENTITY_NAME}.')); + } + + return (int) $model->getEntityId(); + } +} diff --git a/resources/fileTemplates/internal/Magento Save Entity Command Model.php.html b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + diff --git a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft index 38c301727..610889926 100644 --- a/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft +++ b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft @@ -1,14 +1,123 @@ getListQuery = $getListQuery; + $this->searchResultFactory = $searchResultFactory; + } + + /** + * @inheritDoc + */ + public function getSearchResult() + { + $searchCriteria = $this->getSearchCriteria(); + $result = $this->getListQuery->execute($searchCriteria); + + return $this->searchResultFactory->create( + $result->getItems(), + $result->getTotalCount(), + $searchCriteria, + '#if(${ENTITY_ID})${ENTITY_ID}#{else}entity_id#end' + ); + } + + /** + * Get data. + * + * @return array + */ + public function getData(): array + { + if ($this->loadedData) { + return $this->loadedData; + } + $this->loadedData = parent::getData(); + $itemsById = []; + +#set($entityId = "#if(${ENTITY_ID})${ENTITY_ID}#{else}entity_id#end") +#set($entityIdAccessor = '[(int) $item[' + "'$entityId'" + ']]') +#set($getIdAccessor = "[(int) $id]") + foreach ($this->loadedData['items'] as $item) { + $itemsById$entityIdAccessor = $item; + } + + if ($id = $this->request->getParam('$entityId', null)) { + $this->loadedData['entity'] = $itemsById$getIdAccessor; + } + + return $this->loadedData; + } +#else /** * @inheritDoc */ @@ -19,4 +128,5 @@ class ${CLASS_NAME} extends DataProvider [] ]; } +#end } diff --git a/resources/fileTemplates/internal/Magento UI Component Form XML.xml.ft b/resources/fileTemplates/internal/Magento UI Component Form XML.xml.ft index d4fef52cc..6fe7739ac 100644 --- a/resources/fileTemplates/internal/Magento UI Component Form XML.xml.ft +++ b/resources/fileTemplates/internal/Magento UI Component Form XML.xml.ft @@ -9,6 +9,7 @@ ${NAME} + data.general ${NAME}.${NAME}_data_source diff --git a/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft b/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft index 70ca281cf..e502f3088 100644 --- a/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft +++ b/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft @@ -7,6 +7,13 @@ + + + ${NAME}_columns ${NAME}.${NAME}_data_source @@ -56,5 +63,18 @@ desc + #if (${COLUMNS}) + #set($columns = ${COLUMNS}) + #foreach ($column in $columns.split("\n")) + $column + #end + #end +#if (${ACTION_COLUMN}) + + + ${ID_FIELD_NAME} + + +#end diff --git a/resources/magento2/exception.properties b/resources/magento2/exception.properties new file mode 100644 index 000000000..14412aa7a --- /dev/null +++ b/resources/magento2/exception.properties @@ -0,0 +1,4 @@ +exception.common.title=Exception +exception.common.informUs=Please, inform us and we will fix that soon. Check logging console to get full exception stack trace. +exception.reflection.cannotInstantiate=Couldn't instantiate class: {0} +exception.NoSuchMethod=Method {0} not found for class {1}. diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index a413fc416..778209381 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -35,3 +35,5 @@ validator.magentoAclResourceIdInvalid=The ACL resource id is invalid validator.lowercaseCharacters={0} must contain lowercase characters only validator.db.invalidTableNameLength=Table name must contain up to 64 characters only (inclusive) validator.lowerSnakeCase=The {0} field must be of the lower snake case format +validator.menuIdentifierInvalid=The menu identifier is invalid +validator.someFieldsHaveErrors=Please, check the dialog. Some fields have errors diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewEntityAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewEntityAction.java new file mode 100644 index 000000000..7f798d919 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewEntityAction.java @@ -0,0 +1,56 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation; + +import com.intellij.ide.IdeView; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.magento.idea.magento2plugin.MagentoIcons; +import com.magento.idea.magento2plugin.actions.generation.dialog.NewEntityDialog; + +public class NewEntityAction extends AnAction { + public static final String ACTION_NAME = "Magento 2 Entity"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Entity"; + + /** + * Constructor. + */ + public NewEntityAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); + } + + @Override + public void actionPerformed(final AnActionEvent event) { + final DataContext dataContext = event.getDataContext(); + final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); + + if (view == null) { + return; + } + + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + if (project == null) { + return; + } + + final PsiDirectory directory = view.getOrChooseDirectory(); + if (directory == null) { + return; + } + + NewEntityDialog.open(project, directory); + } + + @Override + public boolean isDumbAware() { + return false; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/CollectionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/CollectionData.java index 0ada17e3f..35db5a415 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/CollectionData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/CollectionData.java @@ -5,18 +5,14 @@ package com.magento.idea.magento2plugin.actions.generation.data; -@SuppressWarnings({"PMD.ExcessiveParameterList"}) public class CollectionData { + private final String moduleName; private final String dbTableName; private final String modelName; private final String collectionName; - private final String collectionFqn; private final String collectionDirectory; - private final String collectionNamespace; private final String resourceModelName; - private final String resourceModelFqn; - private final String modelFqn; /** * Models Data. @@ -24,35 +20,24 @@ public class CollectionData { * @param moduleName String * @param dbTableName String * @param modelName String + * @param resourceModelName String * @param collectionName String - * @param collectionFqn String * @param collectionDirectory String - * @param resourceModelName String - * @param resourceModelFqn String - * @param modelFqn String */ public CollectionData( final String moduleName, final String dbTableName, final String modelName, - final String collectionName, - final String collectionFqn, - final String collectionDirectory, - final String collectionNamespace, final String resourceModelName, - final String resourceModelFqn, - final String modelFqn + final String collectionName, + final String collectionDirectory ) { this.moduleName = moduleName; this.dbTableName = dbTableName; this.modelName = modelName; this.collectionName = collectionName; - this.collectionFqn = collectionFqn; this.collectionDirectory = collectionDirectory; - this.collectionNamespace = collectionNamespace; this.resourceModelName = resourceModelName; - this.resourceModelFqn = resourceModelFqn; - this.modelFqn = modelFqn; } /** @@ -82,42 +67,6 @@ public String getModelName() { return modelName; } - /** - * Collection Name. - * - * @return String - */ - public String getCollectionName() { - return collectionName; - } - - /** - * Collection FQN. - * - * @return String - */ - public String getCollectionFqn() { - return collectionFqn; - } - - /** - * Collection Directory. - * - * @return String - */ - public String getCollectionDirectory() { - return collectionDirectory; - } - - /** - * Collection Namespace. - * - * @return String - */ - public String getCollectionNamespace() { - return collectionNamespace; - } - /** * Resource Model Name. * @@ -128,20 +77,20 @@ public String getResourceModelName() { } /** - * Resource Model FQN. + * Collection Name. * * @return String */ - public String getResourceModelFqn() { - return resourceModelFqn; + public String getCollectionName() { + return collectionName; } /** - * Model FQN. + * Collection Directory. * * @return String */ - public String getModelFqn() { - return modelFqn; + public String getCollectionDirectory() { + return collectionDirectory; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelData.java index 86ca4759c..98b7cafa3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelData.java @@ -6,52 +6,36 @@ package com.magento.idea.magento2plugin.actions.generation.data; public class DataModelData { - private final String namespace; + private final String name; + private final String interfaceName; private final String moduleName; - private final String fqn; - private final String interfaceFQN; private final String properties; private final boolean withInterface; /** * Constructor. * - * @param namespace String * @param name String + * @param interfaceName String * @param moduleName String - * @param fqn String - * @param interfaceFQN String * @param properties String * @param hasInterface boolean */ public DataModelData( - final String namespace, final String name, + final String interfaceName, final String moduleName, - final String fqn, - final String interfaceFQN, final String properties, final boolean hasInterface ) { - this.namespace = namespace; this.name = name; + this.interfaceName = interfaceName; this.moduleName = moduleName; - this.fqn = fqn; - this.interfaceFQN = interfaceFQN; this.properties = properties; this.withInterface = hasInterface; } - /** - * Get Namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - /** * Get Name. * @@ -62,30 +46,21 @@ public String getName() { } /** - * Get module name. + * Get interface name. * * @return String */ - public String getModuleName() { - return moduleName; + public String getInterfaceName() { + return interfaceName; } /** - * Get FQN. - * - * @return String - */ - public String getFQN() { - return fqn; - } - - /** - * Get Interface FQN. + * Get module name. * * @return String */ - public String getInterfaceFQN() { - return interfaceFQN; + public String getModuleName() { + return moduleName; } /** diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelInterfaceData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelInterfaceData.java index 8b7e269b5..0d2ea0a12 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelInterfaceData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DataModelInterfaceData.java @@ -5,46 +5,54 @@ package com.magento.idea.magento2plugin.actions.generation.data; +import org.jetbrains.annotations.NotNull; + public class DataModelInterfaceData { - private final String namespace; + private final String name; private final String moduleName; - private final String fqn; private final String properties; /** - * Constructor. + * Data model interface constructor. + * + * @param name String + * @param moduleName String + * @param properties String */ public DataModelInterfaceData( - final String namespace, - final String name, - final String moduleName, - final String fqn, - final String properties + final @NotNull String name, + final @NotNull String moduleName, + final @NotNull String properties ) { - this.namespace = namespace; this.name = name; this.moduleName = moduleName; - this.fqn = fqn; this.properties = properties; } - public String getNamespace() { - return namespace; - } - + /** + * Get data model interface name. + * + * @return String + */ public String getName() { return name; } + /** + * Get module name. + * + * @return String + */ public String getModuleName() { return moduleName; } - public String getFQN() { - return fqn; - } - + /** + * Get properties. + * + * @return String + */ public String getProperties() { return properties; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java new file mode 100644 index 000000000..446730e54 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java @@ -0,0 +1,85 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityByIdCommandData { + + private final String moduleName; + private final String entityName; + private final String entityId; + private final String modelName; + private final String resourceModelName; + + /** + * Delete Command DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param entityId String + * @param modelName String + * @param resourceModelName String + */ + public DeleteEntityByIdCommandData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String entityId, + final @NotNull String modelName, + final @NotNull String resourceModelName + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.entityId = entityId; + this.modelName = modelName; + this.resourceModelName = resourceModelName; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity Id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } + + /** + * Get model name. + * + * @return String + */ + public String getModelName() { + return modelName; + } + + /** + * Get resource model name. + * + * @return String + */ + public String getResourceModelName() { + return resourceModelName; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java new file mode 100644 index 000000000..f83516204 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java @@ -0,0 +1,72 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityControllerFileData { + + private final String entityName; + private final String moduleName; + private final String acl; + private final String entityId; + + /** + * Controller Delete file constructor. + * + * @param entityName String + * @param moduleName String + * @param acl String + * @param entityId String + */ + public DeleteEntityControllerFileData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String acl, + final @NotNull String entityId + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.acl = acl; + this.entityId = entityId; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get acl. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get entity Id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java new file mode 100644 index 000000000..6851b8faa --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java @@ -0,0 +1,72 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class EditEntityActionData { + + private final String entityName; + private final String moduleName; + private final String acl; + private final String menuIdentifier; + + /** + * Edit action data constructor. + * + * @param entityName String + * @param moduleName String + * @param acl String + * @param menuIdentifier String + */ + public EditEntityActionData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String acl, + final @NotNull String menuIdentifier + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.acl = acl; + this.menuIdentifier = menuIdentifier; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get acl. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get menu. + * + * @return String + */ + public String getMenu() { + return menuIdentifier; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java new file mode 100644 index 000000000..4a4e24c68 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java @@ -0,0 +1,99 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings({"PMD.ExcessiveParameterList", "PMD.TooManyFields"}) +public class EntityDataMapperData { + + private final String moduleName; + private final String entityName; + private final String modelName; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean dtoWithInterface; + + /** + * Magento entity data mapper data constructor. + * + * @param moduleName String + * @param entityName String + * @param modelName String + * @param dtoName String + * @param dtoInterfaceName String + * @param isDtoWithInterface boolean + */ + public EntityDataMapperData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String modelName, + final @NotNull String dtoName, + final @NotNull String dtoInterfaceName, + final boolean isDtoWithInterface + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.modelName = modelName; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.dtoWithInterface = isDtoWithInterface; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get model name. + * + * @return String + */ + public String getModelName() { + return modelName; + } + + /** + * Get DTO name. + * + * @return String + */ + public String getDtoName() { + return dtoName; + } + + /** + * Get DTO interface name. + * + * @return String + */ + public String getDtoInterfaceName() { + return dtoInterfaceName; + } + + /** + * Check if DTO has interface. + * + * @return boolean + */ + public boolean isDtoWithInterface() { + return dtoWithInterface; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java new file mode 100644 index 000000000..c31d20f91 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java @@ -0,0 +1,59 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class FormGenericButtonBlockData { + + private final String moduleName; + private final String entityName; + private final String entityId; + + /** + * Generic button DTO constructor. + * + * @param moduleName String + * @param entityName String + * @param entityId String + */ + public FormGenericButtonBlockData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String entityId + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.entityId = entityId; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java new file mode 100644 index 000000000..882f433aa --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java @@ -0,0 +1,72 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class GetListQueryModelData { + + private final String moduleName; + private final String entityName; + private final String modelName; + private final String collectionName; + + /** + * Query Model DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param modelName String + * @param collectionName String + */ + public GetListQueryModelData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String modelName, + final @NotNull String collectionName + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.modelName = modelName; + this.collectionName = collectionName; + } + + /** + * Get Query model module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get model name. + * + * @return String + */ + public String getModelName() { + return modelName; + } + + /** + * Get entity collection name. + * + * @return String + */ + public String getCollectionName() { + return collectionName; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/GridActionColumnData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/GridActionColumnData.java new file mode 100644 index 000000000..d99360105 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/GridActionColumnData.java @@ -0,0 +1,84 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class GridActionColumnData { + private final String moduleName; + private final String entityName; + private final String entityIdColumn; + private final String editUrlPath; + private final String deleteUrlPath; + + /** + * Grid UI Component action column data. + * + * @param moduleName String + * @param entityName String + * @param entityIdColumn String + * @param editUrlPath String + * @param deleteUrlPath String + */ + public GridActionColumnData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String entityIdColumn, + final @NotNull String editUrlPath, + final @NotNull String deleteUrlPath + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.entityIdColumn = entityIdColumn; + this.editUrlPath = editUrlPath; + this.deleteUrlPath = deleteUrlPath; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity id column name. + * + * @return String + */ + public String getEntityIdColumn() { + return entityIdColumn; + } + + /** + * Get edit url path. + * + * @return String + */ + public String getEditUrlPath() { + return editUrlPath; + } + + /** + * Get delete url path. + * + * @return String + */ + public String getDeleteUrlPath() { + return deleteUrlPath; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java new file mode 100644 index 000000000..33258c784 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java @@ -0,0 +1,72 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class IndexActionData { + + private final String moduleName; + private final String entityName; + private final String acl; + private final String menu; + + /** + * Magento entity index adminhtml controller data constructor. + * + * @param moduleName String + * @param entityName String + * @param acl String + * @param menu String + */ + public IndexActionData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String acl, + final @NotNull String menu + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.acl = acl; + this.menu = menu; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get ACL resource id. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get menu resource id. + * + * @return String + */ + public String getMenu() { + return menu; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ModelData.java index a20a2eb4d..f18295d09 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ModelData.java @@ -6,13 +6,11 @@ package com.magento.idea.magento2plugin.actions.generation.data; public class ModelData { + private final String moduleName; private final String dbTableName; private final String modelName; private final String resourceName; - private final String fqn; - private final String namespace; - private final String resourceModelFqn; /** * Model Data. @@ -21,26 +19,17 @@ public class ModelData { * @param dbTableName String * @param modelName String * @param resourceName String - * @param fqn String - * @param namespace String - * @param resourceModelFqn String */ public ModelData( final String moduleName, final String dbTableName, final String modelName, - final String resourceName, - final String fqn, - final String namespace, - final String resourceModelFqn + final String resourceName ) { this.moduleName = moduleName; this.dbTableName = dbTableName; this.modelName = modelName; this.resourceName = resourceName; - this.fqn = fqn; - this.namespace = namespace; - this.resourceModelFqn = resourceModelFqn; } /** @@ -78,31 +67,4 @@ public String getModelName() { public String getResourceName() { return resourceName; } - - /** - * Class FQN. - * - * @return String - */ - public String getFqn() { - return fqn; - } - - /** - * Class Namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - - /** - * Resource model FQN. - * - * @return String - */ - public String getResourceModelFqn() { - return resourceModelFqn; - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java new file mode 100644 index 000000000..ac88e84e6 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java @@ -0,0 +1,83 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class NewActionEntityControllerFileData { + + private final String entityName; + private final String moduleName; + private final String namespace; + private final String acl; + private final String menuIdentifier; + + /** + * Controller NewAction file constructor. + * + * @param entityName String + * @param moduleName String + * @param namespace String + */ + public NewActionEntityControllerFileData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String namespace, + final @NotNull String acl, + final @NotNull String menuIdentifier + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.namespace = namespace; + this.acl = acl; + this.menuIdentifier = menuIdentifier; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get acl. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get menu. + * + * @return String + */ + public String getMenu() { + return menuIdentifier; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/NewEntityLayoutData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/NewEntityLayoutData.java new file mode 100644 index 000000000..73b19fb2a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/NewEntityLayoutData.java @@ -0,0 +1,59 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class NewEntityLayoutData { + + private final String moduleName; + private final String newActionPath; + private final String editActionPath; + + /** + * New entity layout data. + * + * @param moduleName String + * @param newActionPath String + * @param editActionPath String + */ + public NewEntityLayoutData( + final @NotNull String moduleName, + final @NotNull String newActionPath, + final @NotNull String editActionPath + ) { + this.moduleName = moduleName; + this.newActionPath = newActionPath; + this.editActionPath = editActionPath; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get new action path. + * + * @return String + */ + public String getNewActionPath() { + return newActionPath; + } + + /** + * Get edit action path. + * + * @return String + */ + public String getEditActionPath() { + return editActionPath; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java index fefadceb7..6eefb0b8d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java @@ -2,47 +2,70 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.actions.generation.data; -import com.jetbrains.php.lang.psi.elements.PhpClass; +import org.jetbrains.annotations.NotNull; public class PreferenceDiXmFileData { - private String preferenceModule; - private PhpClass targetClass; - private String preferenceFqn; - private String namespace; - private String area; + private final String preferenceModule; + private final String preferenceFor; + private final String preferenceType; + private final String area; + + /** + * Preference DI XML file data. + * + * @param preferenceModule String + * @param preferenceFor String + * @param preferenceType String + * @param area String + */ public PreferenceDiXmFileData( - String preferenceModule, - PhpClass targetClass, - String preferenceFqn, - String namespace, - String area + final @NotNull String preferenceModule, + final @NotNull String preferenceFor, + final @NotNull String preferenceType, + final @NotNull String area ) { this.preferenceModule = preferenceModule; - this.targetClass = targetClass; - this.preferenceFqn = preferenceFqn; - this.namespace = namespace; + this.preferenceFor = preferenceFor; + this.preferenceType = preferenceType; this.area = area; } + /** + * Get preference module. + * + * @return String + */ public String getPreferenceModule() { return preferenceModule; } - public PhpClass getTargetClass() { - return targetClass; - } - - public String getPreferenceFqn() { - return preferenceFqn; + /** + * Get target class. + * + * @return String + */ + public String getPreferenceFor() { + return preferenceFor; } - public String getNamespace() { - return namespace; + /** + * Get preference FQN. + * + * @return String + */ + public String getPreferenceType() { + return preferenceType; } + /** + * Get area. + * + * @return String + */ public String getArea() { return area; } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/ResourceModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/ResourceModelData.java index 2d265fe32..fa6300947 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/ResourceModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/ResourceModelData.java @@ -6,12 +6,11 @@ package com.magento.idea.magento2plugin.actions.generation.data; public class ResourceModelData { + private final String moduleName; private final String dbTableName; private final String resourceModelName; private final String entityIdColumn; - private final String namespace; - private final String fqn; /** * Resource Model Data. @@ -20,23 +19,17 @@ public class ResourceModelData { * @param dbTableName String * @param resourceModelName String * @param entityIdColumn String - * @param namespace String - * @param fqn String */ public ResourceModelData( final String moduleName, final String dbTableName, final String resourceModelName, - final String entityIdColumn, - final String namespace, - final String fqn + final String entityIdColumn ) { this.moduleName = moduleName; this.dbTableName = dbTableName; this.resourceModelName = resourceModelName; this.entityIdColumn = entityIdColumn; - this.namespace = namespace; - this.fqn = fqn; } /** @@ -74,22 +67,4 @@ public String getEntityIdColumn() { public String getResourceModelName() { return resourceModelName; } - - /** - * Namespace getter. - * - * @return String. - */ - public String getNamespace() { - return namespace; - } - - /** - * FQN getter. - * - * @return String. - */ - public String getFqn() { - return fqn; - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java new file mode 100644 index 000000000..257b932ab --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java @@ -0,0 +1,111 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandData { + + private final String moduleName; + private final String entityName; + private final String modelName; + private final String resourceModelName; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean dtoWithInterface; + + /** + * Save Command DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param modelName String + * @param resourceModelName String + * @param dtoName String + * @param dtoInterfaceName String + * @param isDtoWithInterface boolean + */ + public SaveEntityCommandData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String modelName, + final @NotNull String resourceModelName, + final @NotNull String dtoName, + final @NotNull String dtoInterfaceName, + final boolean isDtoWithInterface + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.modelName = modelName; + this.resourceModelName = resourceModelName; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.dtoWithInterface = isDtoWithInterface; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get model name. + * + * @return String + */ + public String getModelName() { + return modelName; + } + + /** + * Get resource model name. + * + * @return String + */ + public String getResourceModelName() { + return resourceModelName; + } + + /** + * Get DTO name. + * + * @return String + */ + public String getDtoName() { + return dtoName; + } + + /** + * Get DTO interface name. + * + * @return String + */ + public String getDtoInterfaceName() { + return dtoInterfaceName; + } + + /** + * Check if DTO has an interface. + * + * @return boolean + */ + public boolean isDtoWithInterface() { + return dtoWithInterface; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java new file mode 100644 index 000000000..5508f1bc3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java @@ -0,0 +1,111 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data; + +import org.jetbrains.annotations.NotNull; + +public class SaveEntityControllerFileData { + + private final String entityName; + private final String moduleName; + private final String acl; + private final String entityId; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean dtoWithInterface; + + /** + * Controller save file constructor. + * + * @param entityName String + * @param moduleName String + * @param acl String + * @param entityId String + * @param dtoName String + * @param dtoInterfaceName String + * @param isDtoWithInterface boolean + */ + public SaveEntityControllerFileData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String acl, + final @NotNull String entityId, + final @NotNull String dtoName, + final @NotNull String dtoInterfaceName, + final boolean isDtoWithInterface + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.acl = acl; + this.entityId = entityId; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.dtoWithInterface = isDtoWithInterface; + } + + /** + * Get entity id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } + + /** + * Get acl. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get DTO name. + * + * @return String + */ + public String getDtoName() { + return dtoName; + } + + /** + * Get DTO interface name. + * + * @return String + */ + public String getDtoInterfaceName() { + return dtoInterfaceName; + } + + /** + * Check if DTO has interface. + * + * @return boolean + */ + public boolean isDtoWithInterface() { + return dtoWithInterface; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java index a8b518850..fe112761f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java @@ -5,27 +5,44 @@ package com.magento.idea.magento2plugin.actions.generation.data; -@SuppressWarnings({"PMD.DataClass"}) public class UiComponentDataProviderData { + private final String name; - private final String namespace; private final String path; + private final String entityName; + private final String entityIdFieldName; /** * UiComponentGridDataProviderData constructor. * * @param name String - * @param namespace String * @param path String */ public UiComponentDataProviderData( final String name, - final String namespace, final String path + ) { + this(name, path, null, null); + } + + /** + * UiComponentGridDataProviderData constructor. + * + * @param name String + * @param path String + * @param entityName String + * @param entityIdFieldName String + */ + public UiComponentDataProviderData( + final String name, + final String path, + final String entityName, + final String entityIdFieldName ) { this.name = name; - this.namespace = namespace; this.path = path; + this.entityName = entityName; + this.entityIdFieldName = entityIdFieldName; } /** @@ -38,20 +55,29 @@ public String getName() { } /** - * Get data provider class namespace. + * Get path. * * @return String */ - public String getNamespace() { - return namespace; + public String getPath() { + return path; } /** - * Get path. + * Get entity name. * * @return String */ - public String getPath() { - return path; + public String getEntityName() { + return entityName; + } + + /** + * Get entity id field name. + * + * @return String + */ + public String getEntityIdFieldName() { + return entityIdFieldName; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java index 6ebf32d83..3cca26561 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java @@ -8,6 +8,7 @@ import java.util.List; public class UiComponentFormFileData { + private final String formName; private final String formArea; private final String moduleName; @@ -18,7 +19,10 @@ public class UiComponentFormFileData { private final String route; private final String submitControllerName; private final String submitActionName; - private final String dataProviderFqn; + private final String dataProviderName; + private final String dataProviderPath; + private final String entityName; + private final String entityId; /** * UI Form data file constructor. @@ -32,7 +36,8 @@ public class UiComponentFormFileData { * @param route String * @param submitControllerName String * @param submitActionName String - * @param dataProviderFqn String + * @param dataProviderName String + * @param dataProviderPath String */ @SuppressWarnings({"PMD.ExcessiveParameterList"}) public UiComponentFormFileData( @@ -46,7 +51,60 @@ public UiComponentFormFileData( final String route, final String submitControllerName, final String submitActionName, - final String dataProviderFqn + final String dataProviderName, + final String dataProviderPath + ) { + this( + formName, + formArea, + moduleName, + label, + buttons, + fieldsets, + fields, + route, + submitControllerName, + submitActionName, + dataProviderName, + dataProviderPath, + "Entity", + "entity_id" + ); + } + + /** + * UI Form data file constructor. + * + * @param formName String + * @param formArea String + * @param moduleName String + * @param buttons List[UiComponentFormButtonData] + * @param fieldsets List[UiComponentFormFieldsetData] + * @param fields List[UiComponentFormFieldData] + * @param route String + * @param submitControllerName String + * @param submitActionName String + * @param dataProviderName String + * @param dataProviderPath String + * @param entityName String + * @param entityId String + */ + @SuppressWarnings({"PMD.ExcessiveParameterList"}) + public UiComponentFormFileData( + final String formName, + final String formArea, + final String moduleName, + final String label, + final List buttons, + final List fieldsets, + final List fields, + final String route, + final String submitControllerName, + final String submitActionName, + final String dataProviderName, + final String dataProviderPath, + final String entityName, + final String entityId ) { this.formName = formName; this.formArea = formArea; @@ -58,7 +116,10 @@ public UiComponentFormFileData( this.route = route; this.submitControllerName = submitControllerName; this.submitActionName = submitActionName; - this.dataProviderFqn = dataProviderFqn; + this.dataProviderName = dataProviderName; + this.dataProviderPath = dataProviderPath; + this.entityName = entityName; + this.entityId = entityId; } /** @@ -152,11 +213,38 @@ public String getSubmitActionName() { } /** - * Get data provider FQN. + * Get data provider name. + * + * @return String + */ + public String getDataProviderName() { + return dataProviderName; + } + + /** + * Get data provider path. + * + * @return String + */ + public String getDataProviderPath() { + return dataProviderPath; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity id. * * @return String */ - public String getDataProviderFqn() { - return dataProviderFqn; + public String getEntityId() { + return entityId; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java index 0d43834b4..99d0bc118 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java @@ -5,41 +5,96 @@ package com.magento.idea.magento2plugin.actions.generation.data; -@SuppressWarnings({"PMD.DataClass"}) +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@SuppressWarnings({"PMD.ExcessiveParameterList"}) public class UiComponentGridData { + private final String moduleName; private final String area; private final String name; - private final String providerClassName; private final String idFieldName; private final String acl; + private final String dataProviderName; + private final String dataProviderPath; + private final String entityName; private final UiComponentGridToolbarData gridToolbarData; + private final List> columns; /** * Ui component grid data constructor. * - * @param area Area - * @param name Name - * @param idFieldName Id field name - * @param acl ACL - * @param gridToolbarData Toolbar data + * @param moduleName String + * @param area String + * @param name String + * @param idFieldName String + * @param acl String + * @param dataProviderName String + * @param dataProviderPath String + * @param gridToolbarData UiComponentGridToolbarData */ public UiComponentGridData( final String moduleName, final String area, final String name, - final String providerClassName, final String idFieldName, final String acl, + final String dataProviderName, + final String dataProviderPath, final UiComponentGridToolbarData gridToolbarData + ) { + this( + moduleName, + area, + name, + idFieldName, + acl, + dataProviderName, + dataProviderPath, + null, + gridToolbarData, + new ArrayList<>() + ); + } + + /** + * Ui component grid data constructor. + * + * @param moduleName String + * @param area String + * @param name String + * @param idFieldName String + * @param acl String + * @param dataProviderName String + * @param dataProviderPath String + * @param entityName String + * @param gridToolbarData UiComponentGridToolbarData + * @param columns List + */ + public UiComponentGridData( + final String moduleName, + final String area, + final String name, + final String idFieldName, + final String acl, + final String dataProviderName, + final String dataProviderPath, + final String entityName, + final UiComponentGridToolbarData gridToolbarData, + final List> columns ) { this.moduleName = moduleName; this.area = area; this.name = name; - this.providerClassName = providerClassName; this.idFieldName = idFieldName; this.acl = acl; + this.dataProviderName = dataProviderName; + this.dataProviderPath = dataProviderPath; + this.entityName = entityName; this.gridToolbarData = gridToolbarData; + this.columns = columns; } /** @@ -87,6 +142,33 @@ public String getAcl() { return acl; } + /** + * Get data provider name. + * + * @return String + */ + public String getDataProviderName() { + return dataProviderName; + } + + /** + * Get data provider path. + * + * @return String + */ + public String getDataProviderPath() { + return dataProviderPath; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + /** * Get ID field name. * @@ -97,11 +179,11 @@ public String getIdFieldName() { } /** - * Get data provider class name. + * Get entity columns data. * - * @return String + * @return List of columns properties. */ - public String getProviderClassName() { - return providerClassName; + public List> getColumns() { + return columns; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/DataObjectConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/DataObjectConverter.java new file mode 100644 index 000000000..ef02db16d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/DataObjectConverter.java @@ -0,0 +1,12 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter; + +/** + * This interface used to map general DTO`s data to concrete dto. + */ +public interface DataObjectConverter { +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/AclXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/AclXmlDtoConverter.java new file mode 100644 index 000000000..a7127c8b9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/AclXmlDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class AclXmlDtoConverter extends AclXmlData implements DataObjectConverter { + + /** + * Acl XML DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public AclXmlDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getParentAclId(), + newEntityDialogData.getAclId(), + newEntityDialogData.getAclTitle() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.java new file mode 100644 index 000000000..c20fe1c3c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.java @@ -0,0 +1,35 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class CollectionModelDtoConverter extends CollectionData implements DataObjectConverter { + + /** + * Collection model DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public CollectionModelDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource"), + newEntityDialogData.getEntityName().concat("Collection"), + newEntityDialogData.getEntityName().concat("Model") + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelDtoConverter.java new file mode 100644 index 000000000..5d7107faf --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelDtoConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class DataModelDtoConverter extends DataModelData implements DataObjectConverter { + + /** + * DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DataModelDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName().concat("Data"), + newEntityDialogData.getEntityName().concat("Interface"), + generationContextData.getModuleName(), + newEntityDialogData.getProperties(), + newEntityDialogData.hasDtoInterface() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelInterfaceDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelInterfaceDtoConverter.java new file mode 100644 index 000000000..7e557ede1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelInterfaceDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class DataModelInterfaceDtoConverter extends DataModelInterfaceData + implements DataObjectConverter { + + /** + * DTO interface converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DataModelInterfaceDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName().concat("Interface"), + generationContextData.getModuleName(), + newEntityDialogData.getProperties() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataProviderDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataProviderDtoConverter.java new file mode 100644 index 000000000..ea11eb0d6 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataProviderDtoConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import org.jetbrains.annotations.NotNull; + +public class DataProviderDtoConverter extends UiComponentDataProviderData + implements DataObjectConverter { + + /** + * Data provider converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public DataProviderDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName().concat("DataProvider"), + UiComponentDataProviderFile.DIRECTORY, + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DbSchemaXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DbSchemaXmlDtoConverter.java new file mode 100644 index 000000000..5ae51978d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DbSchemaXmlDtoConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class DbSchemaXmlDtoConverter extends DbSchemaXmlData implements DataObjectConverter { + + /** + * Db Schema XML converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DbSchemaXmlDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getTableName(), + newEntityDialogData.getTableResource(), + newEntityDialogData.getTableEngine(), + newEntityDialogData.getEntityName(), + generationContextData.getEntityProps() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DeleteEntityByIdCommandDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DeleteEntityByIdCommandDtoConverter.java new file mode 100644 index 000000000..d0f9e457c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DeleteEntityByIdCommandDtoConverter.java @@ -0,0 +1,35 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityByIdCommandDtoConverter extends DeleteEntityByIdCommandData + implements DataObjectConverter { + + /** + * Delete entity by id command DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DeleteEntityByIdCommandDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource") + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityDataMapperDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityDataMapperDtoConverter.java new file mode 100644 index 000000000..43458c409 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityDataMapperDtoConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class EntityDataMapperDtoConverter extends EntityDataMapperData + implements DataObjectConverter { + + /** + * Entity data mapper converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public EntityDataMapperDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Data"), + newEntityDialogData.getEntityName().concat("Interface"), + newEntityDialogData.hasDtoInterface() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormDeleteControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormDeleteControllerDtoConverter.java new file mode 100644 index 000000000..c3a5f797d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormDeleteControllerDtoConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class FormDeleteControllerDtoConverter extends DeleteEntityControllerFileData + implements DataObjectConverter { + + /** + * Form delete controller converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormDeleteControllerDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + newEntityDialogData.getAclId(), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormEditControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormEditControllerDtoConverter.java new file mode 100644 index 000000000..ff48ea9b9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormEditControllerDtoConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class FormEditControllerDtoConverter extends EditEntityActionData + implements DataObjectConverter { + + /** + * Form edit controller converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormEditControllerDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + newEntityDialogData.getAclId(), + newEntityDialogData.getMenuId() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormGenericButtonBlockDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormGenericButtonBlockDtoConverter.java new file mode 100644 index 000000000..4eb3c9860 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormGenericButtonBlockDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class FormGenericButtonBlockDtoConverter extends FormGenericButtonBlockData + implements DataObjectConverter { + + /** + * Form generic button block converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormGenericButtonBlockDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormLayoutDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormLayoutDtoConverter.java new file mode 100644 index 000000000..e70ed644a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormLayoutDtoConverter.java @@ -0,0 +1,38 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class FormLayoutDtoConverter extends LayoutXmlData implements DataObjectConverter { + + private static final String VIEW_ACTION_NAME = "Edit"; + + /** + * Form layout converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormLayoutDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + Areas.adminhtml.toString(), + newEntityDialogData.getRoute(), + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + VIEW_ACTION_NAME, + newEntityDialogData.getFormName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormSaveControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormSaveControllerDtoConverter.java new file mode 100644 index 000000000..c80380378 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormSaveControllerDtoConverter.java @@ -0,0 +1,37 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class FormSaveControllerDtoConverter extends SaveEntityControllerFileData + implements DataObjectConverter { + + /** + * Form save controller converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormSaveControllerDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + newEntityDialogData.getAclId(), + newEntityDialogData.getIdFieldName(), + newEntityDialogData.getEntityName().concat("Data"), + newEntityDialogData.getEntityName().concat("Interface"), + newEntityDialogData.hasDtoInterface() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GetListQueryDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GetListQueryDtoConverter.java new file mode 100644 index 000000000..08acdfbc7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GetListQueryDtoConverter.java @@ -0,0 +1,34 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class GetListQueryDtoConverter extends GetListQueryModelData + implements DataObjectConverter { + + /** + * Get list query converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GetListQueryDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Collection") + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridActionColumnDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridActionColumnDtoConverter.java new file mode 100644 index 000000000..851d4e09b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridActionColumnDtoConverter.java @@ -0,0 +1,35 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class GridActionColumnDtoConverter extends GridActionColumnData + implements DataObjectConverter { + + /** + * Grid action column converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GridActionColumnDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName(), + generationContextData.getEditViewAction(), + generationContextData.getDeleteAction() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridLayoutXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridLayoutXmlDtoConverter.java new file mode 100644 index 000000000..63870167e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridLayoutXmlDtoConverter.java @@ -0,0 +1,37 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class GridLayoutXmlDtoConverter extends LayoutXmlData implements DataObjectConverter { + + /** + * Grid layout XML converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GridLayoutXmlDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + Areas.adminhtml.toString(), + newEntityDialogData.getRoute(), + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + IndexActionFile.CLASS_NAME, + newEntityDialogData.getGridName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java new file mode 100644 index 000000000..52efc63e9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.IndexActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class IndexActionDtoConverter extends IndexActionData implements DataObjectConverter { + + /** + * Entity list action converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public IndexActionDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getAclId(), + newEntityDialogData.getMenuId() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/MenuXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/MenuXmlDtoConverter.java new file mode 100644 index 000000000..6c585919f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/MenuXmlDtoConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class MenuXmlDtoConverter extends MenuXmlData implements DataObjectConverter { + + /** + * Menu XML DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public MenuXmlDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getParentMenuId(), + String.valueOf(newEntityDialogData.getMenuSortOrder()), + generationContextData.getModuleName(), + newEntityDialogData.getMenuId(), + newEntityDialogData.getMenuTitle(), + newEntityDialogData.getAclId(), + generationContextData.getIndexViewAction() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ModelDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ModelDtoConverter.java new file mode 100644 index 000000000..2d61484fc --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ModelDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class ModelDtoConverter extends ModelData implements DataObjectConverter { + + /** + * Model DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public ModelDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource") + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewControllerDtoConverter.java new file mode 100644 index 000000000..290327794 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewControllerDtoConverter.java @@ -0,0 +1,35 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class NewControllerDtoConverter extends NewActionEntityControllerFileData + implements DataObjectConverter { + + /** + * New controller DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public NewControllerDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + generationContextData.getNewControllerNamespaceBuilder().getNamespace(), + newEntityDialogData.getAclId(), + newEntityDialogData.getMenuId() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewEntityLayoutDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewEntityLayoutDtoConverter.java new file mode 100644 index 000000000..b30c59903 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewEntityLayoutDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class NewEntityLayoutDtoConverter extends NewEntityLayoutData + implements DataObjectConverter { + + /** + * New entity layout DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public NewEntityLayoutDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData //NOPMD + ) { + super( + generationContextData.getModuleName(), + generationContextData.getNewViewAction(), + generationContextData.getEditViewAction() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/PreferenceDiXmlFileDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/PreferenceDiXmlFileDtoConverter.java new file mode 100644 index 000000000..8fd7b3010 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/PreferenceDiXmlFileDtoConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class PreferenceDiXmlFileDtoConverter extends PreferenceDiXmFileData + implements DataObjectConverter { + + /** + * Preference DI XML file DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public PreferenceDiXmlFileDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), + generationContextData.getDtoModelNamespaceBuilder().getClassFqn(), + Areas.base.toString() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ResourceModelDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ResourceModelDtoConverter.java new file mode 100644 index 000000000..fa47a527b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ResourceModelDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class ResourceModelDtoConverter extends ResourceModelData implements DataObjectConverter { + + /** + * Resource model DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public ResourceModelDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Resource"), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/RoutesXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/RoutesXmlDtoConverter.java new file mode 100644 index 000000000..9c8e86460 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/RoutesXmlDtoConverter.java @@ -0,0 +1,33 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class RoutesXmlDtoConverter extends RoutesXmlData implements DataObjectConverter { + + /** + * Routes XML DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public RoutesXmlDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + Areas.adminhtml.toString(), + newEntityDialogData.getRoute(), + generationContextData.getModuleName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SaveEntityCommandDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SaveEntityCommandDtoConverter.java new file mode 100644 index 000000000..85d9182b7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SaveEntityCommandDtoConverter.java @@ -0,0 +1,37 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandDtoConverter extends SaveEntityCommandData + implements DataObjectConverter { + + /** + * Save entity command DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public SaveEntityCommandDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource"), + newEntityDialogData.getEntityName().concat("Data"), + newEntityDialogData.getEntityName().concat("Interface"), + newEntityDialogData.hasDtoInterface() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentFormLayoutDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentFormLayoutDtoConverter.java new file mode 100644 index 000000000..0313f8990 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentFormLayoutDtoConverter.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class UiComponentFormLayoutDtoConverter extends UiComponentFormFileData + implements DataObjectConverter { + + private static final String SUBMIT_ACTION_NAME = "Save"; + + /** + * Ui Component form layout DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public UiComponentFormLayoutDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getFormName(), + Areas.adminhtml.toString(), + generationContextData.getModuleName(), + newEntityDialogData.getFormLabel(), + generationContextData.getButtons(), + generationContextData.getFieldsetData(), + generationContextData.getFieldsData(), + newEntityDialogData.getRoute(), + newEntityDialogData.getEntityName(), + SUBMIT_ACTION_NAME, + newEntityDialogData.getEntityName().concat("DataProvider"), + UiComponentDataProviderFile.DIRECTORY, + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridDtoConverter.java new file mode 100644 index 000000000..05b845887 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridDtoConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import org.jetbrains.annotations.NotNull; + +public class UiComponentGridDtoConverter extends UiComponentGridData + implements DataObjectConverter { + + /** + * Ui component grid DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public UiComponentGridDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + Areas.adminhtml.toString(), + newEntityDialogData.getGridName(), + newEntityDialogData.getIdFieldName(), + newEntityDialogData.getAclId(), + newEntityDialogData.getEntityName().concat("DataProvider"), + UiComponentDataProviderFile.DIRECTORY, + newEntityDialogData.getEntityName(), + new UiComponentGridToolbarDtoConverter(generationContextData, newEntityDialogData), + generationContextData.getEntityProps() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridToolbarDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridToolbarDtoConverter.java new file mode 100644 index 000000000..e033a9247 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridToolbarDtoConverter.java @@ -0,0 +1,39 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class UiComponentGridToolbarDtoConverter extends UiComponentGridToolbarData + implements DataObjectConverter { + + /** + * Ui component grid toolbar DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public UiComponentGridToolbarDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.hasToolbar(), + newEntityDialogData.hasToolbarBookmarks(), + newEntityDialogData.hasToolbarColumnsControl(), + newEntityDialogData.hasToolbarFullTextSearch(), + newEntityDialogData.hasToolbarListingFilters(), + newEntityDialogData.hasToolbarListingPaging() + + + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/DialogData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/DialogData.java new file mode 100644 index 000000000..366f1eb3f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/DialogData.java @@ -0,0 +1,11 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.dialog; + +/** + * This interface used to provide dialogues DTOs to @GeneratorPoolHandler type. + */ +public interface DialogData {} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java new file mode 100644 index 000000000..63ac992b8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java @@ -0,0 +1,221 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.dialog; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldData; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldsetData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import java.util.List; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("PMD.TooManyFields") +public class EntityCreatorContextData implements GenerationContextData { + + private final Project project; + private final String moduleName; + private final String actionName; + private final boolean hasOpenFileFlag; + private final String indexViewAction; + private final String editViewAction; + private final String newViewAction; + private final String deleteAction; + private final NamespaceBuilder dtoModelNamespaceBuilder; + private final NamespaceBuilder dtoInterfaceNamespaceBuilder; + private final NamespaceBuilder formViewNamespaceBuilder; + private final NamespaceBuilder newControllerNamespaceBuilder; + private final List> entityProps; + private final List buttons; + private final List fieldsetData; + private final List fieldsData; + + /** + * Entity creator context data. + * + * @param project Project + * @param moduleName String + * @param actionName String + * @param hasOpenFileFlag boolean + * @param indexViewAction String + * @param editViewAction String + * @param newViewAction String + * @param deleteAction String + * @param dtoModelNamespaceBuilder NamespaceBuilder + * @param dtoInterfaceNamespaceBuilder NamespaceBuilder + * @param formViewNamespaceBuilder NamespaceBuilder + * @param newControllerNamespaceBuilder NamespaceBuilder + * @param entityProps List + * @param buttons List + * @param fieldsetData List + * @param fieldsData List + */ + @SuppressWarnings("PMD.ExcessiveParameterList") + public EntityCreatorContextData( + final @NotNull Project project, + final @NotNull String moduleName, + final @NotNull String actionName, + final boolean hasOpenFileFlag, + final @NotNull String indexViewAction, + final @NotNull String editViewAction, + final @NotNull String newViewAction, + final @NotNull String deleteAction, + final @NotNull NamespaceBuilder dtoModelNamespaceBuilder, + final @NotNull NamespaceBuilder dtoInterfaceNamespaceBuilder, + final @NotNull NamespaceBuilder formViewNamespaceBuilder, + final @NotNull NamespaceBuilder newControllerNamespaceBuilder, + final @NotNull List> entityProps, + final @NotNull List buttons, + final @NotNull List fieldsetData, + final @NotNull List fieldsData + ) { + this.project = project; + this.moduleName = moduleName; + this.actionName = actionName; + this.hasOpenFileFlag = hasOpenFileFlag; + this.indexViewAction = indexViewAction; + this.editViewAction = editViewAction; + this.newViewAction = newViewAction; + this.deleteAction = deleteAction; + this.dtoModelNamespaceBuilder = dtoModelNamespaceBuilder; + this.dtoInterfaceNamespaceBuilder = dtoInterfaceNamespaceBuilder; + this.formViewNamespaceBuilder = formViewNamespaceBuilder; + this.newControllerNamespaceBuilder = newControllerNamespaceBuilder; + this.entityProps = entityProps; + this.buttons = buttons; + this.fieldsetData = fieldsetData; + this.fieldsData = fieldsData; + } + + @Override + public Project getProject() { + return project; + } + + @Override + public String getModuleName() { + return moduleName; + } + + @Override + public String getActionName() { + return actionName; + } + + @Override + public boolean checkIfHasOpenFileFlag() { + return hasOpenFileFlag; + } + + /** + * Get index action. + * + * @return String + */ + public String getIndexViewAction() { + return indexViewAction; + } + + /** + * Get edit action. + * + * @return String + */ + public String getEditViewAction() { + return editViewAction; + } + + /** + * Get new action. + * + * @return String + */ + public String getNewViewAction() { + return newViewAction; + } + + /** + * Get delete action. + * + * @return String + */ + public String getDeleteAction() { + return deleteAction; + } + + /** + * Get DTO model namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getDtoModelNamespaceBuilder() { + return dtoModelNamespaceBuilder; + } + + /** + * Get DTO interface namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getDtoInterfaceNamespaceBuilder() { + return dtoInterfaceNamespaceBuilder; + } + + /** + * Get form view namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getFormViewNamespaceBuilder() { + return formViewNamespaceBuilder; + } + + /** + * Get new controller namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getNewControllerNamespaceBuilder() { + return newControllerNamespaceBuilder; + } + + /** + * Get entity properties. + * + * @return List + */ + public List> getEntityProps() { + return entityProps; + } + + /** + * Get buttons. + * + * @return List + */ + public List getButtons() { + return buttons; + } + + /** + * Get field sets data. + * + * @return List + */ + public List getFieldsetData() { + return fieldsetData; + } + + /** + * Get fields data. + * + * @return List + */ + public List getFieldsData() { + return fieldsData; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java new file mode 100644 index 000000000..924be84d8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java @@ -0,0 +1,42 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.dialog; + +import com.intellij.openapi.project.Project; + +/** + * This interface used to provide dialogues context DTOs to @GeneratorPoolHandler type. + */ +public interface GenerationContextData { + + /** + * Get project instance. + * + * @return Project + */ + Project getProject(); + + /** + * Get module name. + * + * @return String + */ + String getModuleName(); + + /** + * Get current action name. + * + * @return String + */ + String getActionName(); + + /** + * Check if files should be opened after generation. + * + * @return boolean + */ + boolean checkIfHasOpenFileFlag(); +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java new file mode 100644 index 000000000..ba6d6c2f3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java @@ -0,0 +1,355 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.data.dialog; + +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings({"PMD.ExcessiveParameterList", "PMD.TooManyFields"}) +public class NewEntityDialogData implements DialogData { + + // General tab data. + private final String entityName; + private final String tableName; + private final String idFieldName; + private final String tableEngine; + private final String tableResource; + private final boolean adminUiComponents; + private final boolean dtoInterface; + + // Admin UI Components tab data. + private final String route; + private final String formLabel; + private final String formName; + private final String gridName; + private final boolean toolbar; + private final boolean toolbarBookmarks; + private final boolean toolbarColumnsControl; + private final boolean toolbarListingFilters; + private final boolean toolbarListingPaging; + private final boolean toolbarFullTextSearch; + + // Acl tab data. + private final String parentAclId; + private final String aclId; + private final String aclTitle; + + // Menu tab data. + private final String parentMenuId; + private final int menuSortOrder; + private final String menuId; + private final String menuTitle; + + // Properties tab data. + private final String properties; + + /** + * New entity dialog data. + * + * @param entityName String + * @param tableName String + * @param idFieldName String + * @param tableEngine String + * @param tableResource String + * @param hasAdminUiComponents boolean + * @param hasDtoInterface boolean + * @param route String + * @param formLabel String + * @param formName String + * @param gridName String + * @param hasToolbar boolean + * @param hasToolbarBookmarks boolean + * @param hasToolbarColumnsControl boolean + * @param hasToolbarListingFilters boolean + * @param hasToolbarListingPaging boolean + * @param hasToolbarFullTextSearch boolean + * @param parentAclId String + * @param aclId String + * @param aclTitle String + * @param parentMenuId String + * @param menuSortOrder int + * @param menuId String + * @param menuTitle String + * @param properties String + */ + public NewEntityDialogData( + final @NotNull String entityName, + final @NotNull String tableName, + final @NotNull String idFieldName, + final @NotNull String tableEngine, + final @NotNull String tableResource, + final boolean hasAdminUiComponents, + final boolean hasDtoInterface, + final @NotNull String route, + final @NotNull String formLabel, + final @NotNull String formName, + final @NotNull String gridName, + final boolean hasToolbar, + final boolean hasToolbarBookmarks, + final boolean hasToolbarColumnsControl, + final boolean hasToolbarListingFilters, + final boolean hasToolbarListingPaging, + final boolean hasToolbarFullTextSearch, + final @NotNull String parentAclId, + final @NotNull String aclId, + final @NotNull String aclTitle, + final @NotNull String parentMenuId, + final int menuSortOrder, + final @NotNull String menuId, + final @NotNull String menuTitle, + final @NotNull String properties + ) { + this.entityName = entityName; + this.tableName = tableName; + this.idFieldName = idFieldName; + this.tableEngine = tableEngine; + this.tableResource = tableResource; + this.adminUiComponents = hasAdminUiComponents; + this.dtoInterface = hasDtoInterface; + this.route = route; + this.formLabel = formLabel; + this.formName = formName; + this.gridName = gridName; + this.toolbar = hasToolbar; + this.toolbarBookmarks = hasToolbarBookmarks; + this.toolbarColumnsControl = hasToolbarColumnsControl; + this.toolbarListingFilters = hasToolbarListingFilters; + this.toolbarListingPaging = hasToolbarListingPaging; + this.toolbarFullTextSearch = hasToolbarFullTextSearch; + this.parentAclId = parentAclId; + this.aclId = aclId; + this.aclTitle = aclTitle; + this.parentMenuId = parentMenuId; + this.menuSortOrder = menuSortOrder; + this.menuId = menuId; + this.menuTitle = menuTitle; + this.properties = properties; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get table name. + * + * @return String + */ + public String getTableName() { + return tableName; + } + + /** + * Get id field name. + * + * @return String + */ + public String getIdFieldName() { + return idFieldName; + } + + /** + * Get table engine. + * + * @return String + */ + public String getTableEngine() { + return tableEngine; + } + + /** + * Get table resource. + * + * @return String + */ + public String getTableResource() { + return tableResource; + } + + /** + * Check if has admin ui components. + * + * @return boolean + */ + public boolean hasAdminUiComponents() { + return adminUiComponents; + } + + /** + * Check if has dto interface. + * + * @return boolean + */ + public boolean hasDtoInterface() { + return dtoInterface; + } + + /** + * Get route. + * + * @return String + */ + public String getRoute() { + return route; + } + + /** + * Get form label. + * + * @return String + */ + public String getFormLabel() { + return formLabel; + } + + /** + * Get form name. + * + * @return String + */ + public String getFormName() { + return formName; + } + + /** + * Get grid name. + * + * @return String + */ + public String getGridName() { + return gridName; + } + + /** + * Check if has toolbar. + * + * @return boolean + */ + public boolean hasToolbar() { + return toolbar; + } + + /** + * Check if has toolbar bookmarks. + * + * @return boolean + */ + public boolean hasToolbarBookmarks() { + return toolbarBookmarks; + } + + /** + * Check if has toolbar columns control. + * + * @return boolean + */ + public boolean hasToolbarColumnsControl() { + return toolbarColumnsControl; + } + + /** + * Check if has toolbar listing filters. + * + * @return boolean + */ + public boolean hasToolbarListingFilters() { + return toolbarListingFilters; + } + + /** + * Check if has toolbar listing paging. + * + * @return boolean + */ + public boolean hasToolbarListingPaging() { + return toolbarListingPaging; + } + + /** + * Check if has toolbar fulltext search. + * + * @return boolean + */ + public boolean hasToolbarFullTextSearch() { + return toolbarFullTextSearch; + } + + /** + * Get parent acl id. + * + * @return String + */ + public String getParentAclId() { + return parentAclId; + } + + /** + * Get acl id. + * + * @return String + */ + public String getAclId() { + return aclId; + } + + /** + * Get acl title. + * + * @return String + */ + public String getAclTitle() { + return aclTitle; + } + + /** + * Get parent menu id. + * + * @return String + */ + public String getParentMenuId() { + return parentMenuId; + } + + /** + * Get menu sort order. + * + * @return int + */ + public int getMenuSortOrder() { + return menuSortOrder; + } + + /** + * Get menu id. + * + * @return String + */ + public String getMenuId() { + return menuId; + } + + /** + * Get menu title. + * + * @return String + */ + public String getMenuTitle() { + return menuTitle; + } + + /** + * Get properties. + * + * @return String + */ + public String getProperties() { + return properties; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index f340c83a7..66379034f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -5,40 +5,40 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; -import com.magento.idea.magento2plugin.actions.generation.dialog.util.HighlightDialogFieldOnErrorUtil; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; -import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidations; +import com.intellij.openapi.util.Pair; +import com.magento.idea.magento2plugin.actions.generation.dialog.reflection.ExtractComponentFromFieldUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.DialogFieldErrorUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.TypeFieldsRulesParser; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.data.FieldValidationData; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule; import com.magento.idea.magento2plugin.bundles.CommonBundle; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JOptionPane; +import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; +import org.jetbrains.annotations.NotNull; /** * All code generate dialog should extend this class. */ -@SuppressWarnings({"PMD.ShortVariable", "PMD.MissingSerialVersionUID"}) public abstract class AbstractDialog extends JDialog { + protected CommonBundle bundle; protected final ValidatorBundle validatorBundle = new ValidatorBundle(); + protected final List fieldsValidationsList; private final String errorTitle; - private final Map> textFieldValidationRuleMap; - private final Map> errorMessageFieldValidationRuleMap; + private JTabbedPane tabbedPane; + private boolean isValidationErrorShown; /** * Abstract Dialog Constructor. @@ -47,165 +47,192 @@ public AbstractDialog() { super(); bundle = new CommonBundle(); errorTitle = bundle.message("common.error"); - textFieldValidationRuleMap = new LinkedHashMap<>(); - errorMessageFieldValidationRuleMap = new HashMap<>(); + fieldsValidationsList = new TypeFieldsRulesParser(this).parseValidationRules(); } protected void centerDialog(final AbstractDialog dialog) { final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - final int x = screenSize.width / 2 - dialog.getSize().width / 2; - final int y = screenSize.height / 2 - dialog.getSize().height / 2; - dialog.setLocation(x, y); + final int coordinateX = screenSize.width / 2 - dialog.getSize().width / 2; + final int coordinateY = screenSize.height / 2 - dialog.getSize().height / 2; + dialog.setLocation(coordinateX, coordinateY); } protected void onCancel() { this.setVisible(false); } + /** + * Validate all form fields. + * + * @return boolean + */ + @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.AvoidDeeplyNestedIfStmts"}) protected boolean validateFormFields() { - addValidationRulesFromAnnotations(); - for (final Map.Entry> entry - : textFieldValidationRuleMap.entrySet()) { - final Object field = entry.getKey(); - final List rules = entry.getValue(); + boolean dialogHasErrors; + isValidationErrorShown = dialogHasErrors = false; + clearValidationHighlighting(); + + for (final FieldValidationData fieldValidationData : getFieldsToValidate()) { + final Field field = fieldValidationData.getField(); + final List> rules = fieldValidationData.getRules(); - for (final ValidationRule rule : rules) { + for (final Pair rulePair : rules) { + final ValidationRule rule = rulePair.getFirst(); + final String message = rulePair.getSecond(); final String value = resolveFieldValueByComponentType(field); if (value != null && !rule.check(value)) { - if (errorMessageFieldValidationRuleMap.containsKey(field) - && errorMessageFieldValidationRuleMap.get(field).containsKey(rule)) { - showErrorMessage(errorMessageFieldValidationRuleMap.get(field).get(rule)); - highlightFieldWithErrorStyle(field); + if (!dialogHasErrors) { + final JComponent component = + ExtractComponentFromFieldUtil.extract(field, this); + + if (component != null && tabbedPane != null) { + navigateToTabWithComponent(component); + } } - return false; + dialogHasErrors = true; + showErrorMessage(field, message); + break; } } } - return true; - } - protected void showErrorMessage(final String errorMessage) { - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - } - - private void addValidationRulesFromAnnotations() { - final Class type = this.getClass(); - final List validations = new LinkedList<>(); - - for (final Field field : type.getDeclaredFields()) { - field.setAccessible(true); - validations.clear(); - - if (field.isAnnotationPresent(FieldValidation.class)) { - validations.add(field.getAnnotation(FieldValidation.class)); - } - if (field.isAnnotationPresent(FieldValidations.class)) { - validations.addAll( - Arrays.asList(field.getAnnotation(FieldValidations.class).value()) - ); - } - - for (final FieldValidation validation : validations) { - try { - addValidationRuleToField( - field.get(this), - getRuleFromAnnotation(validation), - getMessageFromAnnotation(validation) - ); - } catch (Exception exception) { // NOPMD - // We don't need to cover this case. - } - } - field.setAccessible(false); + if (dialogHasErrors && !isValidationErrorShown) { + showErrorMessage(validatorBundle.message("validator.someFieldsHaveErrors")); } - } - private String getMessageFromAnnotation(final FieldValidation validation) { - String[] params; - final int minMessageArrayLength = 1; + return !dialogHasErrors; + } - if (validation.message().length > minMessageArrayLength) { - params = Arrays.copyOfRange(validation.message(), 1, validation.message().length); - } else { - params = new String[]{}; + /** + * Reset highlighting for fields. + */ + protected void clearValidationHighlighting() { + for (final FieldValidationData fieldValidationData : fieldsValidationsList) { + DialogFieldErrorUtil.resetFieldHighlighting(fieldValidationData.getField(), this); } - return validatorBundle.message(validation.message()[0], (Object[]) params); } - private ValidationRule getRuleFromAnnotation(final FieldValidation validation) - throws NoSuchMethodException, - IllegalAccessException, InvocationTargetException, InstantiationException { - final Class ruleType = validation.rule().getRule(); - - return (ValidationRule) ruleType.getConstructor().newInstance(); + /** + * Override this method to change which fields should or shouldn't be validated. + * + * @return List[FieldValidationData] + */ + protected List getFieldsToValidate() { + return new LinkedList<>(fieldsValidationsList); } - protected void addValidationRuleToField( - final Object field, - final ValidationRule rule, - final String message) { - if (!(field instanceof JComponent)) { - return; - } - List rules; - if (textFieldValidationRuleMap.containsKey(field)) { - rules = textFieldValidationRuleMap.get(field); - } else { - rules = new ArrayList<>(); - } + /** + * Tabbed pane should be registered to be possible navigate to the tab in which error occurred. + * + * @param tabbedPane JTabbedPane + */ + protected void registerTabbedPane(final @NotNull JTabbedPane tabbedPane) { + this.tabbedPane = tabbedPane; + } - if (!rules.contains(rule) && rule != null) { - addFieldValidationRuleMessageAssociation(field, rule, message); - rules.add(rule); - textFieldValidationRuleMap.put(field, rules); + /** + * Show error message for field. + * + * @param field Field + * @param errorMessage String + */ + protected void showErrorMessage( + final @NotNull Field field, + final @NotNull String errorMessage + ) { + final boolean isMessageShown = + DialogFieldErrorUtil.showErrorMessageForField(this, field, errorMessage); + + if (!isMessageShown) { + showErrorMessage(errorMessage); + DialogFieldErrorUtil.highlightField(this, field); } } - private void addFieldValidationRuleMessageAssociation( - final Object field, - final ValidationRule rule, - final String message) { - Map validationRuleErrorMessageMap; - if (errorMessageFieldValidationRuleMap.containsKey(field)) { - validationRuleErrorMessageMap = errorMessageFieldValidationRuleMap.get(field); - } else { - validationRuleErrorMessageMap = new HashMap<>(); + /** + * Show error message in dialog. + * + * @param errorMessage String + */ + protected void showErrorMessage(final String errorMessage) { + if (isValidationErrorShown) { + return; } - validationRuleErrorMessageMap.put(rule, message); - errorMessageFieldValidationRuleMap.put(field, validationRuleErrorMessageMap); + JOptionPane.showMessageDialog( + null, + errorMessage, + errorTitle, + JOptionPane.ERROR_MESSAGE + ); + isValidationErrorShown = true; } - private String resolveFieldValueByComponentType(final Object field) { - if (field instanceof JTextField) { - return ((JTextField) field).isEditable() ? ((JTextField) field).getText() : null; - } else if (field instanceof JComboBox) { - if (((JComboBox) field).getSelectedIndex() == -1) { + /** + * Resolve value of stored component by field. + * + * @param field Field + * + * @return String + */ + private String resolveFieldValueByComponentType(final Field field) { + final JComponent component = ExtractComponentFromFieldUtil.extract(field, this); + + if (component instanceof JTextField) { + return ((JTextField) component).isEditable() + ? ((JTextField) component).getText() : null; + } else if (component instanceof JComboBox) { + if (((JComboBox) component).getSelectedIndex() == -1) { return ""; } else { - return ((JComboBox) field).getSelectedItem().toString(); + return ((JComboBox) component).getSelectedItem().toString(); } - } else if (field instanceof JTextArea) { - return ((JTextArea) field).getText(); + } else if (component instanceof JTextArea) { + return ((JTextArea) component).getText(); } + return null; } /** - * Highlight field with error style. + * Navigate to tab with specified component. + * + * @param component JComponent + */ + private void navigateToTabWithComponent(final @NotNull JComponent component) { + if (tabbedPane == null) { + return; + } + + final int index = getParentTabPaneForComponent(component); + + if (index != -1) { + tabbedPane.setSelectedIndex(index); + } + } + + /** + * Get parent tab index for component. * - * @param field Object + * @param component Container + * + * @return int */ - private void highlightFieldWithErrorStyle(final Object field) { - if (field instanceof JTextField) { - HighlightDialogFieldOnErrorUtil.execute((JTextField) field); - } else if (field instanceof JComboBox) { - HighlightDialogFieldOnErrorUtil.execute((JComboBox) field); + private int getParentTabPaneForComponent(final @NotNull Container component) { + if (tabbedPane == null) { + return -1; } + final int parentTabIndex = tabbedPane.indexOfComponent(component); + + if (parentTabIndex != -1) { + return parentTabIndex; + } + final Container parent = component.getParent(); + + if (parent == null) { + return -1; + } + + return getParentTabPaneForComponent(parent); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 57288b2b1..30ac69f62 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.actions.generation.NewControllerAction; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; @@ -199,8 +198,11 @@ private void onOK() { this.setVisible(false); } - private PsiFile generateFile() { - return new ModuleControllerClassGenerator(new ControllerFileData( + /** + * Generate controller class file. + */ + private void generateFile() { + new ModuleControllerClassGenerator(new ControllerFileData( getActionDirectory(), getActionName(), getModuleName(), diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 844b0bf23..40d85a588 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -5,7 +5,6 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; -import com.google.common.base.CaseFormat; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; @@ -14,7 +13,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; -import com.magento.idea.magento2plugin.actions.generation.data.code.ClassPropertyData; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.ClassPropertyFormatterUtil; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; @@ -22,15 +21,14 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.bundles.CommonBundle; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.magento.files.DataModel; -import com.magento.idea.magento2plugin.magento.files.DataModelInterface; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor; import com.magento.idea.magento2plugin.ui.table.DeleteRowButton; import com.magento.idea.magento2plugin.ui.table.TableButton; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import com.magento.idea.magento2plugin.util.RegExUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; @@ -49,20 +47,17 @@ import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; -import org.apache.commons.lang.StringUtils; @SuppressWarnings({ - "PMD.ExcessiveImports", - "PMD.TooManyMethods", + "PMD.ExcessiveImports" }) public class NewDataModelDialog extends AbstractDialog { + private final Project project; private final String moduleName; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; private final List properties; - private NamespaceBuilder interfaceNamespace; - private NamespaceBuilder modelNamespace; private static final String MODEL_NAME = "Model Name"; private static final String PROPERTY_NAME = "Name"; @@ -70,8 +65,6 @@ public class NewDataModelDialog extends AbstractDialog { private static final String PROPERTY_ACTION = "Action"; private static final String PROPERTY_DELETE = "Delete"; - private static final String[] PROPERTY_TYPES = {"int", "float", "string", "bool"}; - private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; @@ -134,15 +127,17 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } + /** + * Proceed with generation. + */ private void onOK() { if (validateFormFields()) { - buildNamespaces(); formatProperties(); - generateModelFile(); + generateDataModelFile(); - if (isInterfaceShouldBeCreated()) { - generateModelInterfaceFile(); - generatePreference(); + if (createInterface.isSelected()) { + generateDataModelInterfaceFile(); + generatePreferenceForInterface(); } this.setVisible(false); } @@ -151,6 +146,7 @@ private void onOK() { @Override protected boolean validateFormFields() { boolean valid = false; + if (super.validateFormFields()) { valid = true; final String errorTitle = commonBundle.message("common.error"); @@ -193,111 +189,82 @@ public void onCancel() { dispose(); } - private void generateModelInterfaceFile() { - new DataModelInterfaceGenerator(project, new DataModelInterfaceData( - getInterfaceNamespace(), - getInterfaceName(), + /** + * Generate DTO interface file. + */ + private void generateDataModelInterfaceFile() { + new DataModelInterfaceGenerator(new DataModelInterfaceData( + getDtoInterfaceName(), getModuleName(), - getInterfaceFQN(), - getProperties() - )).generate(NewDataModelAction.ACTION_NAME, true); + ClassPropertyFormatterUtil.joinProperties(properties) + ), project).generate(NewDataModelAction.ACTION_NAME, true); } - private void generateModelFile() { + /** + * Generate DTO model file. + */ + private void generateDataModelFile() { new DataModelGenerator(project, new DataModelData( - getModelNamespace(), - getModelName(), + getDtoModelName(), + getDtoInterfaceName(), getModuleName(), - getModelFQN(), - getInterfaceFQN(), - getProperties(), - isInterfaceShouldBeCreated() + ClassPropertyFormatterUtil.joinProperties(properties), + createInterface.isSelected() )).generate(NewDataModelAction.ACTION_NAME, true); } - private void generatePreference() { + /** + * Generate preference for interface DTO. + */ + private void generatePreferenceForInterface() { new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getModuleName(), - GetPhpClassByFQN.getInstance(project).execute(getInterfaceFQN()), - getModelFQN(), - getModelNamespace(), + new DataModelInterfaceFile(getModuleName(), getDtoInterfaceName()).getClassFqn(), + new DataModelFile(getModuleName(), getDtoModelName()).getClassFqn(), "base" ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); } - private void buildNamespaces() { - interfaceNamespace = new NamespaceBuilder( - getModuleName(), getInterfaceName(), DataModelInterface.DIRECTORY - ); - modelNamespace = new NamespaceBuilder( - getModuleName(), getModelName(), DataModel.DIRECTORY - ); - } - /** - * Formats properties into an array of ClassPropertyData objects. + * Get module name. + * + * @return String */ - private void formatProperties() { - final DefaultTableModel propertiesTable = getPropertiesTable(); - final int rowCount = propertiesTable.getRowCount(); - String name; - String type; - - for (int index = 0; index < rowCount; index++) { - name = propertiesTable.getValueAt(index, 0).toString(); - type = propertiesTable.getValueAt(index, 1).toString(); - properties.add(new ClassPropertyData(// NOPMD - type, - CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name), - CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name), - name, - CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, name) - ).string()); - } - } - - private boolean isInterfaceShouldBeCreated() { - return createInterface.isSelected(); - } - private String getModuleName() { return moduleName; } - private String getInterfaceNamespace() { - return interfaceNamespace.getNamespace(); - } - - private String getInterfaceName() { - return modelName.getText().trim().concat("Interface"); - } - - private String getInterfaceFQN() { - return interfaceNamespace.getClassFqn(); - } - - private String getModelNamespace() { - return modelNamespace.getNamespace(); - } - - private String getModelName() { + /** + * Get DTO model name. + * + * @return String + */ + private String getDtoModelName() { return modelName.getText().trim(); } - private String getModelFQN() { - return modelNamespace.getClassFqn(); + /** + * Get DTO interface name. + * + * @return String + */ + private String getDtoInterfaceName() { + return modelName.getText().trim().concat("Interface"); } /** - * Gets properties as a string, ready for templating. - * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". + * Formats properties into an array of ClassPropertyData objects. */ - private String getProperties() { - return StringUtils.join(properties, ","); + private void formatProperties() { + properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); } + /** + * Initialize properties table. + */ private void initPropertiesTable() { final DefaultTableModel propertiesTable = getPropertiesTable(); + propertiesTable.setDataVector( new Object[][]{}, new Object[]{ @@ -314,7 +281,8 @@ private void initPropertiesTable() { addProperty.addActionListener(e -> { propertiesTable.addRow(new Object[]{ "", - PROPERTY_TYPES[0], + PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) + .getPropertyType(), PROPERTY_DELETE }); }); @@ -322,12 +290,24 @@ private void initPropertiesTable() { initPropertyTypeColumn(); } + /** + * Initialize property type column. + */ private void initPropertyTypeColumn() { final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE); - formElementTypeColumn.setCellEditor(new ComboBoxEditor(PROPERTY_TYPES)); - formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PROPERTY_TYPES)); + formElementTypeColumn.setCellEditor( + new ComboBoxEditor(PropertiesTypes.getPropertyTypes()) + ); + formElementTypeColumn.setCellRenderer( + new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes()) + ); } + /** + * Get properties table. + * + * @return DefaultTableModel + */ private DefaultTableModel getPropertiesTable() { return (DefaultTableModel) propertyTable.getModel(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index d8f9d2d61..f2dda4aa8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -18,7 +18,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.TableNameLength; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; -import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; import com.magento.idea.magento2plugin.magento.packages.database.TableEngines; import com.magento.idea.magento2plugin.magento.packages.database.TableResources; @@ -192,36 +192,36 @@ private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXm */ private void initializeColumnsUiComponentGroup() { final List columns = new LinkedList<>(Arrays.asList( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, - ModuleDbSchemaXml.XML_ATTR_COLUMN_PADDING, - ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, - ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, - ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, - ModuleDbSchemaXml.XML_ATTR_COLUMN_LENGTH, - ModuleDbSchemaXml.XML_ATTR_COLUMN_PRECISION, - ModuleDbSchemaXml.XML_ATTR_COLUMN_SCALE, - ModuleDbSchemaXml.XML_ATTR_COLUMN_ON_UPDATE, - ModuleDbSchemaXml.XML_ATTR_COLUMN_DEFAULT, - ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT + ColumnAttributes.TYPE.getName(), + ColumnAttributes.NAME.getName(), + ColumnAttributes.PADDING.getName(), + ColumnAttributes.UNSIGNED.getName(), + ColumnAttributes.NULLABLE.getName(), + ColumnAttributes.IDENTITY.getName(), + ColumnAttributes.LENGTH.getName(), + ColumnAttributes.PRECISION.getName(), + ColumnAttributes.SCALE.getName(), + ColumnAttributes.ON_UPDATE.getName(), + ColumnAttributes.DEFAULT.getName(), + ColumnAttributes.COMMENT.getName() )); // Set default values for columns final Map defaultValues = new HashMap<>(); - defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, "false"); - defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, "false"); + defaultValues.put(ColumnAttributes.NULLABLE.getName(), "false"); + defaultValues.put(ColumnAttributes.IDENTITY.getName(), "false"); // Set sources for columns final Map> sources = new HashMap<>(); final List booleanSource = Arrays.asList("true", "false"); final List columnTypes = TableColumnTypes.getTableColumnTypesList(); columnTypes.add(0, ""); sources.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), columnTypes ); - sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, booleanSource); - sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, booleanSource); - sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, booleanSource); - sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_ON_UPDATE, booleanSource); + sources.put(ColumnAttributes.UNSIGNED.getName(), booleanSource); + sources.put(ColumnAttributes.NULLABLE.getName(), booleanSource); + sources.put(ColumnAttributes.IDENTITY.getName(), booleanSource); + sources.put(ColumnAttributes.ON_UPDATE.getName(), booleanSource); // Initialize new Table Group columnsTableGroupWrapper = new TableGroupWrapper( columnsTable, diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form new file mode 100644 index 000000000..3f76f15e7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -0,0 +1,759 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java new file mode 100644 index 000000000..1b9c14d58 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -0,0 +1,800 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.ui.DocumentAdapter; +import com.intellij.util.indexing.FileBasedIndex; +import com.magento.idea.magento2plugin.actions.generation.NewEntityAction; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldData; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldsetData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.dialog.reflection.GetReflectionFieldUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.ClassPropertyFormatterUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.util.ProcessWorker; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.data.FieldValidationData; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AclResourceIdRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.MenuIdentifierRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.RouteIdRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.TableNameLength; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorPoolHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.provider.NewEntityGeneratorsProviderUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DbSchemaGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; +import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; +import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import com.magento.idea.magento2plugin.magento.packages.database.TableEngines; +import com.magento.idea.magento2plugin.magento.packages.database.TableResources; +import com.magento.idea.magento2plugin.magento.packages.uicomponent.FormElementType; +import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex; +import com.magento.idea.magento2plugin.ui.FilteredComboBox; +import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; +import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; +import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; +import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.awt.Cursor; +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.KeyStroke; +import javax.swing.event.DocumentEvent; +import javax.swing.table.DefaultTableModel; +import org.apache.commons.lang.StringUtils; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.UnusedPrivateField", + "PMD.ExcessiveImports" +}) +public class NewEntityDialog extends AbstractDialog { + + private final @NotNull Project project; + private final String moduleName; + private JPanel contentPane; + private JTabbedPane tabbedPane1; + private JPanel propertiesPanel; + private JTable propertyTable; + private JButton addProperty; + private JButton buttonOK; + private JButton buttonCancel; + private JPanel generalTable; + private JCheckBox createUiComponent; + private JLabel entityNameLabel; + private JLabel dbTableNameLabel; + private JLabel entityIdColumnNameLabel; + private JLabel routeLabel; + private JLabel aclLabel; + private JTextField aclTitle; + private FilteredComboBox parentAcl; + private JTextField formLabel; + private JLabel formLabelLabel; + private JLabel gridNameLabel; + private JLabel parentMenuItemLabel; + private JLabel sortOrderLabel; + private JLabel menuIdentifierLabel; + private JLabel menuTitleLabel; + private JTextField menuTitle; + private FilteredComboBox parentMenu; + private JCheckBox addToolBar; + private JCheckBox addBookmarksCheckBox; + private JCheckBox addColumnsControlCheckBox; + private JCheckBox addFullTextSearchCheckBox; + private JCheckBox addListingFiltersCheckBox; + private JCheckBox addListingPagingCheckBox; + private JComboBox tableEngine; + private JLabel tableEngineLabel; + private JComboBox tableResource; + private JLabel tableResourceLabel; + private JCheckBox createInterface; + private final List properties; + private TableGroupWrapper entityPropertiesTableGroupWrapper; + + private static final String ACTION_NAME = "Create Entity"; + private static final String PROPERTY_NAME = "Name"; + private static final String PROPERTY_TYPE = "Type"; + private static final String ACL_ID = "ACL ID"; + private static final String FORM_NAME = "Form Name"; + private static final String GRID_NAME = "Grid Name"; + private static final String IDENTIFIER = "Identifier"; + private static final String SORT_ORDER = "Sort Order"; + private static final String UI_COMPONENTS_TAB_NAME = "Admin UI Components"; + private static final String TABLE_NAME = "DB Table Name"; + private static final String ENTITY_NAME = "Entity Name"; + private static final String ROUTER = "Route"; + private static final String ENTITY_ID = "Entity ID Field Name"; + + private static final String MODEL_SUFFIX = "Model"; + private static final String RESOURCE_MODEL_SUFFIX = "Resource"; + private static final String COLLECTION_MODEL_SUFFIX = "Collection"; + private static final String DTO_MODEL_SUFFIX = "Data"; + private static final String DTO_INTERFACE_SUFFIX = "Interface"; + private static final String DATA_PROVIDER_SUFFIX = "DataProvider"; + + private static final boolean OPEN_FILES_FLAG = false; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ENTITY_ID}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, ENTITY_ID}) + private JTextField entityId; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ENTITY_NAME}) + @FieldValidation( + rule = RuleRegistry.ALPHANUMERIC, + message = {AlphanumericRule.MESSAGE, ENTITY_NAME} + ) + private JTextField entityName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, TABLE_NAME}) + @FieldValidation(rule = RuleRegistry.LOWERCASE, message = {Lowercase.MESSAGE, TABLE_NAME}) + @FieldValidation( + rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE, + message = {AlphanumericWithUnderscoreRule.MESSAGE, TABLE_NAME} + ) + @FieldValidation(rule = RuleRegistry.TABLE_NAME_LENGTH, message = {TableNameLength.MESSAGE}) + private JTextField dbTableName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ROUTER}) + @FieldValidation(rule = RuleRegistry.ROUTE_ID, message = {RouteIdRule.MESSAGE}) + private JTextField route; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, FORM_NAME}) + private JTextField formName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, GRID_NAME}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, FORM_NAME}) + private JTextField gridName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACL_ID}) + @FieldValidation(rule = RuleRegistry.ACL_RESOURCE_ID, message = {AclResourceIdRule.MESSAGE}) + private JTextField acl; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, SORT_ORDER}) + @FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE, SORT_ORDER}) + private JTextField sortOrder; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, IDENTIFIER}) + @FieldValidation(rule = RuleRegistry.MENU_IDENTIFIER, message = {MenuIdentifierRule.MESSAGE}) + private JTextField menuIdentifier; + private JLabel formNameLabel; + private JTextPane exampleIdentifier; + private JTextPane exampleAclId; + private JTextPane exampleFormName; + private JTextPane exampleGridName; + private JPanel uiComponentsPanel; + private JPanel formNamePanel; + private JPanel gridNamePanel; + private JPanel aclIdPanel; + private JPanel menuIdPanel; + private JLabel formNameErrorMessage; + private JLabel gridNameErrorMessage; + private JLabel aclErrorMessage; + private JLabel menuIdentifierErrorMessage; + private JLabel sortOrderErrorMessage; + private JLabel entityNameErrorMessage; + private JLabel dbTableNameErrorMessage; + private JLabel entityIdErrorMessage; + private JLabel routeErrorMessage; + private JTextField observerName; + private final ProcessWorker.InProgressFlag onOkActionFired; + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + */ + public NewEntityDialog(final @NotNull Project project, final PsiDirectory directory) { + super(); + + this.project = project; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.properties = new ArrayList<>(); + + setContentPane(contentPane); + setModal(true); + setTitle(NewEntityAction.ACTION_DESCRIPTION); + getRootPane().setDefaultButton(buttonOK); + + onOkActionFired = new ProcessWorker.InProgressFlag(false); + buttonOK.addActionListener(this::generateNewEntityFiles); + buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); + + // call onCancel() when cross is clicked + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent event) { + onCancel(); + } + + @SuppressWarnings("PMD.AccessorMethodGeneration") + @Override + public void windowOpened(final WindowEvent event) { + entityName.requestFocus(); + } + }); + + initializeComboboxSources(); + initPropertiesTable(); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction( + (final ActionEvent event) -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + + entityName.addKeyListener(new KeyAdapter() { + @SuppressWarnings("PMD.AccessorMethodGeneration") + @Override + public void keyReleased(final KeyEvent event) { + entityName.setText(StringUtils.capitalize(entityName.getText())); + } + }); + + entityName.getDocument().addDocumentListener(new DocumentAdapter() { + @SuppressWarnings("PMD.AccessorMethodGeneration") + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + autoCompleteIdentifiers(); + } + }); + + toggleUiComponentsPanel(); + + createUiComponent.addItemListener(event -> toggleUiComponentsPanel()); + registerTabbedPane(tabbedPane1); + } + + /** + * Open new controller dialog. + * + * @param project Project + * @param directory PsiDirectory + */ + public static void open(final Project project, final PsiDirectory directory) { + final NewEntityDialog dialog = new NewEntityDialog(project, directory); + dialog.pack(); + dialog.centerDialog(dialog); + dialog.setVisible(true); + } + + /** + * Filter fields to validate if createUiComponent checkbox isn't selected. + * + * @return List[FieldValidationData] + */ + @Override + protected List getFieldsToValidate() { + final List filteredFields = new LinkedList<>(); + + if (createUiComponent.isSelected()) { + filteredFields.addAll(super.getFieldsToValidate()); + } else { + final List fieldsToIgnore = new ArrayList<>(); + fieldsToIgnore.add(GetReflectionFieldUtil.getByName("route", this.getClass())); + fieldsToIgnore.add(GetReflectionFieldUtil.getByName("formName", this.getClass())); + fieldsToIgnore.add(GetReflectionFieldUtil.getByName("gridName", this.getClass())); + + for (final FieldValidationData fieldData : super.getFieldsToValidate()) { + if (fieldsToIgnore.contains(fieldData.getField())) { + continue; + } + filteredFields.add(fieldData); + } + } + + return filteredFields; + } + + /** + * Initialize combobox sources. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + private void initializeComboboxSources() { + for (final String engine : TableEngines.getTableEnginesList()) { + tableEngine.addItem(new ComboBoxItemData(engine, engine)); + } + for (final String resource : TableResources.getTableResourcesList()) { + tableResource.addItem(new ComboBoxItemData(resource, resource)); + } + } + + /** + * Initialize properties table. + */ + private void initPropertiesTable() { + final List columns = new LinkedList<>(Arrays.asList( + PROPERTY_NAME, + PROPERTY_TYPE + )); + final Map> sources = new HashMap<>(); + sources.put(PROPERTY_TYPE, PropertiesTypes.getPropertyTypesList()); + + // Initialize entity properties Table Group + entityPropertiesTableGroupWrapper = new TableGroupWrapper( + propertyTable, + addProperty, + columns, + new HashMap<>(), + sources + ); + entityPropertiesTableGroupWrapper.initTableGroup(); + } + + /** + * Generate new entity files. + * + * @param event ActionEvent + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + private void generateNewEntityFiles(final @NotNull ActionEvent event) { + if (!onOkActionFired.isInProgress()) { + buttonOK.setEnabled(false); + buttonCancel.setEnabled(false); + + if (propertyTable.isEditing()) { + propertyTable.getCellEditor().stopCellEditing(); + } + + new ProcessWorker( + this::onOK, + this::releaseDialogAfterGeneration, + onOkActionFired + ).execute(); + } + } + + /** + * Perform code generation using input data. + */ + private void onOK() { + if (!validateFormFields()) { + onOkActionFired.setInProgress(false); + return; + } + setCursor(new Cursor(Cursor.WAIT_CURSOR)); + + formatProperties(); + + final NewEntityDialogData dialogData = getNewEntityDialogData(); + final EntityCreatorContextData context = getEntityCreatorContextData(dialogData); + + final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(context); + + NewEntityGeneratorsProviderUtil.initializeGenerators( + generatorPoolHandler, + context, + dialogData + ); + + generatorPoolHandler.run(); + onOkActionFired.setFinished(true); + } + + /** + * Release dialog buttons and hide. + */ + private void releaseDialogAfterGeneration() { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + buttonCancel.setEnabled(true); + buttonOK.setEnabled(true); + + if (onOkActionFired.isFinished()) { + this.setVisible(false); + } + } + + /** + * Get entity creator context data. + * + * @param dialogData NewEntityDialogData + * + * @return EntityCreatorContextData + */ + private EntityCreatorContextData getEntityCreatorContextData( + final @NotNull NewEntityDialogData dialogData + ) { + final String entityName = dialogData.getEntityName(); + final String dtoClassName = entityName.concat(DTO_MODEL_SUFFIX); + final String dtoInterfaceClassName = entityName.concat(DTO_INTERFACE_SUFFIX); + + final String actionsPathPrefix = dialogData.getRoute() + File.separator + + FirstLetterToLowercaseUtil.convert(entityName) + File.separator; + final NamespaceBuilder dtoModelNamespace = + new DataModelFile(moduleName, dtoClassName).getNamespaceBuilder(); + final NamespaceBuilder dtoInterfaceNamespace = + new DataModelInterfaceFile(moduleName, dtoInterfaceClassName).getNamespaceBuilder(); + + final NamespaceBuilder formViewNamespaceBuilder = + new NamespaceBuilder( + moduleName, + "Edit", + ControllerBackendPhp.DEFAULT_DIR + File.separator + entityName + ); + + return new EntityCreatorContextData( + project, + moduleName, + ACTION_NAME, + OPEN_FILES_FLAG, + actionsPathPrefix.concat("index"), + actionsPathPrefix.concat("edit"), + actionsPathPrefix.concat("new"), + actionsPathPrefix.concat("delete"), + dtoModelNamespace, + dtoInterfaceNamespace, + formViewNamespaceBuilder, + new NewActionFile(moduleName, entityName).getNamespaceBuilder(), + getEntityProperties(), + getButtons(), + getFieldSets(), + getFields() + ); + } + + /** + * Formats properties into an array of ClassPropertyData objects. + */ + private void formatProperties() { + final String name = getEntityIdColumn(); + final String type = "int"; + + properties.add(ClassPropertyFormatterUtil.formatSingleProperty(name, type)); + properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); + } + + /** + * Get controller name. + * + * @return String + */ + private String getFormName() { + return formName.getText().trim(); + } + + /** + * Returns form fieldSets. + * + * @return List[UiComponentFormFieldsetData] + */ + private List getFieldSets() { + final ArrayList fieldSets = new ArrayList<>(); + final UiComponentFormFieldsetData fieldsetData = new UiComponentFormFieldsetData( + "general", + "General", + "10" + ); + fieldSets.add(fieldsetData); + + return fieldSets; + } + + /** + * Return form buttons list. + * + * @return List[UiComponentFormButtonData] + */ + private List getButtons() { + final List buttons = new ArrayList<>(); + final String directory = "Block/Form/" + entityName.getText().trim(); + + final NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( + moduleName, + "Save", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "Save", + moduleName, + "Save", + namespaceBuilderSave.getNamespace(), + "Save Entity", + "10", + getFormName(), + namespaceBuilderSave.getClassFqn() + )); + + final NamespaceBuilder namespaceBuilderBack = new NamespaceBuilder( + moduleName, + "Back", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "Back", + moduleName, + "Back", + namespaceBuilderBack.getNamespace(), + "Back To Grid", + "20", + getFormName(), + namespaceBuilderBack.getClassFqn() + )); + + final NamespaceBuilder namespaceBuilderDelete = new NamespaceBuilder( + moduleName, + "Delete", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "Delete", + moduleName, + "Delete", + namespaceBuilderDelete.getNamespace(), + "Delete Entity", + "30", + getFormName(), + namespaceBuilderDelete.getClassFqn() + )); + return buttons; + } + + /** + * Returns form fields list. + * + * @return List[UiComponentFormFieldData] + */ + private List getFields() { + final DefaultTableModel model = getPropertiesTable(); + final ArrayList fieldsets = new ArrayList<>(); + + fieldsets.add( + new UiComponentFormFieldData( + getEntityIdColumn(), + "Entity ID", + "0", + "general", + FormElementType.HIDDEN.getType(), + "text", + getEntityIdColumn() + ) + ); + + for (int count = 0; count < model.getRowCount(); count++) { + + final String name = model.getValueAt(count, 0).toString(); + final String dataType = model.getValueAt(count, 1).toString(); + + final String label = Arrays.stream(name.split("_")).map( + string -> string.substring(0, 1).toUpperCase(Locale.getDefault()) + + string.substring(1)).collect(Collectors.joining(" ") + ); + final String sortOrder = String.valueOf(count).concat("0"); + final String fieldset = "general"; + + final PropertiesTypes property = + PropertiesTypes.getByValue(model.getValueAt(count, 1).toString()); + final String formElementType = + FormElementType.getDefaultForProperty(property).getType(); + + final String source = model.getValueAt(count, 0).toString(); //todo: convert + + final UiComponentFormFieldData fieldsetData = new UiComponentFormFieldData(//NOPMD + name, + label, + sortOrder, + fieldset, + formElementType, + dataType, + source + ); + + fieldsets.add( + fieldsetData + ); + } + + return fieldsets; + } + + @SuppressWarnings({"PMD.UnusedPrivateMethod"}) + private void createUIComponents() { + final List aclResourcesList = GetAclResourcesListUtil.execute(project); + final Collection menuReferences = FileBasedIndex + .getInstance().getAllKeys(MenuIndex.KEY, project); + final ArrayList menuReferencesList = new ArrayList<>(menuReferences); + Collections.sort(menuReferencesList); + + this.parentAcl = new FilteredComboBox(aclResourcesList); + this.parentMenu = new FilteredComboBox(menuReferencesList); + + if (aclResourcesList.contains(ModuleMenuXml.defaultAcl)) { + parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); + } + } + + /** + * Get entity properties table columns data and format to suitable for generator. + * + * @return List of entity properties stored in HashMap. + */ + private List> getEntityProperties() { + final List> shortColumnsData = + entityPropertiesTableGroupWrapper.getColumnsData(); + + final List> columnsData = + DbSchemaGeneratorUtil.complementShortPropertiesByDefaults(shortColumnsData); + columnsData.add(0, DbSchemaGeneratorUtil.getTableIdentityColumnData(getEntityIdColumn())); + + return columnsData; + } + + /** + * Autocomplete entity name dependent fields. + */ + private void autoCompleteIdentifiers() { + final String entityNameValue = entityName.getText().trim(); + if (entityNameValue.isEmpty()) { + return; + } + final String entityName = CamelCaseToSnakeCase.getInstance().convert(entityNameValue); + final String entityNameLabel = Arrays.stream(entityName.split("_")).map( + string -> string.substring(0, 1).toUpperCase(Locale.getDefault()) + + string.substring(1) + ).collect(Collectors.joining(" ")); + + dbTableName.setText(entityName); + entityId.setText(entityName.concat("_id")); + route.setText(entityName); + formLabel.setText(entityNameLabel.concat(" Form")); + formName.setText(entityName.concat("_form")); + gridName.setText(entityName.concat("_listing")); + acl.setText(moduleName.concat("::management")); + aclTitle.setText(entityNameLabel.concat(" Management")); + menuIdentifier.setText(moduleName.concat("::management")); + menuTitle.setText(entityNameLabel.concat(" Management")); + } + + /** + * Resolve ui components panel state. + */ + private void toggleUiComponentsPanel() { + if (createUiComponent.isSelected()) { + tabbedPane1.add(uiComponentsPanel, 1); + tabbedPane1.setTitleAt(1, UI_COMPONENTS_TAB_NAME); + } else { + tabbedPane1.remove(1); + } + } + + /** + * Get new entity dialog data object. + * + * @return NewEntityDialogData + */ + private NewEntityDialogData getNewEntityDialogData() { + return new NewEntityDialogData( + entityName.getText().trim(), + dbTableName.getText().trim(), + entityId.getText().trim(), + getTableEngine(), + getTableResource(), + createUiComponent.isSelected(), + createInterface.isSelected(), + route.getText().trim(), + formLabel.getText().trim(), + formName.getText().trim(), + gridName.getText().trim(), + addToolBar.isSelected(), + addBookmarksCheckBox.isSelected(), + addColumnsControlCheckBox.isSelected(), + addListingFiltersCheckBox.isSelected(), + addListingPagingCheckBox.isSelected(), + addFullTextSearchCheckBox.isSelected(), + getParentAcl(), + acl.getText().trim(), + aclTitle.getText().trim(), + getParentMenu(), + Integer.parseInt(sortOrder.getText().trim()), + menuIdentifier.getText().trim(), + menuTitle.getText().trim(), + ClassPropertyFormatterUtil.joinProperties(properties) + ); + } + + /** + * Get properties table. + * + * @return DefaultTableModel + */ + private DefaultTableModel getPropertiesTable() { + return (DefaultTableModel) propertyTable.getModel(); + } + + /** + * Get entity id column name. + * + * @return String + */ + private String getEntityIdColumn() { + return entityId.getText().trim(); + } + + /** + * Get table engine. + * + * @return String + */ + private String getTableEngine() { + return tableEngine.getSelectedItem() == null ? "" + : tableEngine.getSelectedItem().toString().trim(); + } + + /** + * Get table resource. + * + * @return String + */ + private String getTableResource() { + return tableResource.getSelectedItem() == null ? "" + : tableResource.getSelectedItem().toString().trim(); + } + + /** + * Get parent acl resource id. + * + * @return String + */ + private String getParentAcl() { + return parentAcl.getSelectedItem() == null ? "" + : parentAcl.getSelectedItem().toString().trim(); + } + + /** + * Get parent menu id. + * + * @return String + */ + private String getParentMenu() { + return parentMenu.getSelectedItem() == null ? "" + : parentMenu.getSelectedItem().toString().trim(); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index e444c0574..522d2a4a9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -189,7 +189,7 @@ public void windowClosing(final WindowEvent event) { this.topicName.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(final @NotNull DocumentEvent event) { - updateIndefiersTextes(); + updateIdentifiersTexts(); } }); this.handlerClass.getDocument().addDocumentListener(new DocumentAdapter() { @@ -386,7 +386,7 @@ public String getModuleName() { /** * Update identifier texts. */ - public void updateIndefiersTextes() { + public void updateIdentifiersTexts() { final String topicNameText = this.topicName.getText(); this.handlerName.setText(topicNameText.concat(".handler")); this.consumerName.setText(topicNameText); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index 784f3b9b3..b2e970987 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.intellij.ui.DocumentAdapter; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; @@ -20,10 +19,6 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleResourceModelGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; -import com.magento.idea.magento2plugin.magento.files.ModelPhp; -import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; -import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -38,7 +33,7 @@ import javax.swing.event.DocumentEvent; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) +@SuppressWarnings("PMD.TooManyFields") public class NewModelsDialog extends AbstractDialog { private final String moduleName; private final Project project; @@ -53,9 +48,6 @@ public class NewModelsDialog extends AbstractDialog { private static final String ENTITY_ID_COLUMN_NAME = "Entity ID Column Name"; private static final String COLLECTION_NAME = "Collection Name"; private static final String COLLECTION_DIRECTORY = "Collection Directory"; - public static final String RESOURCE_MODEL = "ResourceModel"; - public static final String MODEL = "Model"; - public static final String FQN_ALIAS_KEYWORD = " as "; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MODEL_NAME}) @@ -150,68 +142,30 @@ public void updateText() { this.collectionDirectory.setText(modelName); } - private String getModuleName() { - return moduleName; - } - - private String getModelName() { - return modelName.getText().trim(); - } - - private String getCollectionName() { - return collectionName.getText().trim(); - } - - private String getResourceModelName() { - return resourceModelName.getText().trim(); - } - - private String getDbTableName() { - return dbTableName.getText().trim(); - } - - private String getEntityIdColumn() { - return entityIdColumn.getText().trim(); - } - - private String getCollectionDirectory() { - return ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + File.separator - + collectionDirectory.getText().trim(); - } - - private NamespaceBuilder getModelNamespace() { - return new NamespaceBuilder(getModuleName(), getModelName(), ModelPhp.MODEL_DIRECTORY); - } - - private NamespaceBuilder getResourceModelNamespace() { - return new NamespaceBuilder( - getModuleName(), - getResourceModelName(), - ResourceModelPhp.RESOURCE_MODEL_DIRECTORY - ); - } - - private NamespaceBuilder getCollectionNamespace() { - return new NamespaceBuilder( - getModuleName(), - getCollectionName(), - getCollectionDirectory() - ); - } - /** * Open new controller dialog. * * @param project Project * @param directory PsiDirectory */ - public static void open(final Project project, final PsiDirectory directory) { + public static void open( + final @NotNull Project project, + final @NotNull PsiDirectory directory + ) { final NewModelsDialog dialog = new NewModelsDialog(project, directory); dialog.pack(); dialog.centerDialog(dialog); dialog.setVisible(true); } + @Override + protected void onCancel() { + dispose(); + } + + /** + * Process generation. + */ private void onOK() { if (!validateFormFields()) { return; @@ -220,81 +174,108 @@ private void onOK() { generateModelFile(); generateResourceModelFile(); generateCollectionFile(); + this.setVisible(false); } - private PsiFile generateModelFile() { - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - final StringBuilder resourceModelFqn - = new StringBuilder(resourceModelNamespace.getClassFqn()); - String resourceModelName = getResourceModelName(); - - if (getModelName().equals(getResourceModelName())) { - resourceModelFqn.append(FQN_ALIAS_KEYWORD); - resourceModelFqn.append(RESOURCE_MODEL); - resourceModelName = RESOURCE_MODEL; - } - - return new ModuleModelGenerator(new ModelData( + /** + * Generate model file. + */ + private void generateModelFile() { + new ModuleModelGenerator(new ModelData( getModuleName(), getDbTableName(), getModelName(), - resourceModelName, - modelNamespace.getClassFqn(), - modelNamespace.getNamespace(), - resourceModelFqn.toString() + getResourceModelName() ), project).generate(NewModelsDialog.ACTION_NAME, true); } - private PsiFile generateResourceModelFile() { - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - return new ModuleResourceModelGenerator(new ResourceModelData( - getModuleName(), - getDbTableName(), - getResourceModelName(), - getEntityIdColumn(), - resourceModelNamespace.getNamespace(), - resourceModelNamespace.getClassFqn() + /** + * Generate resource model file. + */ + private void generateResourceModelFile() { + new ModuleResourceModelGenerator(new ResourceModelData( + getModuleName(), + getDbTableName(), + getResourceModelName(), + getEntityIdColumn() ), project).generate(NewModelsDialog.ACTION_NAME, true); } - private PsiFile generateCollectionFile() { - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder collectionNamespace = getCollectionNamespace(); - final StringBuilder modelFqn = new StringBuilder(modelNamespace.getClassFqn()); - String modelName = getModelName(); - final StringBuilder resourceModelFqn - = new StringBuilder(resourceModelNamespace.getClassFqn()); - String resourceModelName = getResourceModelName(); - - - if (getModelName().equals(getResourceModelName())) { - modelFqn.append(FQN_ALIAS_KEYWORD); - modelFqn.append(MODEL); - modelName = MODEL; - resourceModelFqn.append(FQN_ALIAS_KEYWORD); - resourceModelFqn.append(RESOURCE_MODEL); - resourceModelName = RESOURCE_MODEL; - } - - return new ModuleCollectionGenerator(new CollectionData( - getModuleName(), - getDbTableName(), - modelName, - getCollectionName(), - collectionNamespace.getClassFqn(), - getCollectionDirectory(), - collectionNamespace.getNamespace(), - resourceModelName, - resourceModelFqn.toString(), - modelFqn.toString() + /** + * Generate collection file. + */ + private void generateCollectionFile() { + new ModuleCollectionGenerator(new CollectionData( + getModuleName(), + getDbTableName(), + getModelName(), + getResourceModelName(), + getCollectionName(), + getCollectionDirectory() ), project).generate(NewModelsDialog.ACTION_NAME, true); } - @Override - protected void onCancel() { - dispose(); + /** + * Get module name. + * + * @return String + */ + private String getModuleName() { + return moduleName; + } + + /** + * Get model name. + * + * @return String + */ + private String getModelName() { + return modelName.getText().trim(); + } + + /** + * Get resource model name. + * + * @return String + */ + private String getResourceModelName() { + return resourceModelName.getText().trim(); + } + + /** + * Get collection name. + * + * @return String + */ + private String getCollectionName() { + return collectionName.getText().trim(); + } + + /** + * Get db table name. + * + * @return String + */ + private String getDbTableName() { + return dbTableName.getText().trim(); + } + + /** + * Get entity id column name. + * + * @return String + */ + private String getEntityIdColumn() { + return entityIdColumn.getText().trim(); + } + + /** + * Get collection directory. + * + * @return String + */ + private String getCollectionDirectory() { + return collectionDirectory.getText().trim(); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java index c293c3ec5..b1a4f0617 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -8,7 +8,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction; import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; @@ -42,11 +41,12 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp; -import com.magento.idea.magento2plugin.magento.files.FormButtonBlockPhp; +import com.magento.idea.magento2plugin.magento.files.FormButtonBlockFile; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.uicomponent.FormElementType; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor; import com.magento.idea.magento2plugin.ui.table.DeleteRowButton; @@ -71,7 +71,6 @@ import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; -import org.jetbrains.annotations.NotNull; @SuppressWarnings({ "PMD.TooManyFields", @@ -273,10 +272,10 @@ protected void initButtonsTable() { }); final String[] buttonTypes = { - FormButtonBlockPhp.TYPE_SAVE, - FormButtonBlockPhp.TYPE_BACK, - FormButtonBlockPhp.TYPE_DELETE, - FormButtonBlockPhp.TYPE_CUSTOM + FormButtonBlockFile.TYPE_SAVE, + FormButtonBlockFile.TYPE_BACK, + FormButtonBlockFile.TYPE_DELETE, + FormButtonBlockFile.TYPE_CUSTOM }; final TableColumn typeColumnObject = formButtons.getColumn(TYPE_COLUMN); @@ -346,25 +345,9 @@ protected void initFieldTable() { } private void initFormElementTypeColumn() { - final String[] formElementTypes = { - "hidden", - "file", - "input", - "date", - "boolean", - "checkbox", - "checkboxset", - "email", - "select", - "multiselect", - "text", - "textarea", - "price", - "radioset", - "wysiwyg" - }; - + final String[] formElementTypes = FormElementType.getTypeList().toArray(new String[0]); final TableColumn formElementTypeColumn = fields.getColumn(FORM_ELEMENT_TYPE_COLUMN); + formElementTypeColumn.setCellEditor(new ComboBoxEditor(formElementTypes)); formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(formElementTypes)); } @@ -433,26 +416,21 @@ private void onOK() { this.setVisible(false); } - private PsiFile generateDataProviderFile() { - final NamespaceBuilder namespace = getDataProviderNamespace(); - return new UiComponentDataProviderGenerator(new UiComponentDataProviderData( + /** + * Generate data provider file. + */ + private void generateDataProviderFile() { + new UiComponentDataProviderGenerator(new UiComponentDataProviderData( getDataProviderClassName(), - namespace.getNamespace(), getDataProviderDirectory() ), getModuleName(), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - @NotNull - private NamespaceBuilder getDataProviderNamespace() { - return new NamespaceBuilder( - getModuleName(), - getDataProviderClassName(), - getDataProviderDirectory() - ); - } - - private PsiFile generateFormFile() { - return new UiComponentFormGenerator(new UiComponentFormFileData( + /** + * Generate form file. + */ + private void generateFormFile() { + new UiComponentFormGenerator(new UiComponentFormFileData( getFormName(), getArea(), getModuleName(), @@ -463,25 +441,32 @@ private PsiFile generateFormFile() { getRoute(), getSubmitControllerName(), getSubmitActionName(), - getDataProviderNamespace().getClassFqn() + getDataProviderClassName(), + getDataProviderDirectory() ), project).generate(NewUiComponentFormAction.ACTION_NAME, true); } - private PsiFile generateRoutesXmlFile() { - return new RoutesXmlGenerator(new RoutesXmlData( + /** + * Generate route xml file. + */ + private void generateRoutesXmlFile() { + new RoutesXmlGenerator(new RoutesXmlData( getArea(), getRoute(), getModuleName() ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateViewControllerFile() { + /** + * Generate view controller file. + */ + private void generateViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), getViewActionName(), getViewControllerDirectory() ); - return new ModuleControllerClassGenerator(new ControllerFileData( + new ModuleControllerClassGenerator(new ControllerFileData( getViewControllerDirectory(), getViewActionName(), getModuleName(), @@ -493,13 +478,16 @@ private PsiFile generateViewControllerFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateSubmitControllerFile() { + /** + * Generate submit controller file. + */ + private void generateSubmitControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), getViewActionName(), getSubmitControllerDirectory() ); - return new ModuleControllerClassGenerator(new ControllerFileData( + new ModuleControllerClassGenerator(new ControllerFileData( getSubmitControllerDirectory(), getSubmitActionName(), getModuleName(), @@ -511,8 +499,11 @@ private PsiFile generateSubmitControllerFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( + /** + * Generate layout file. + */ + private void generateLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( getArea(), getRoute(), getModuleName(), @@ -522,8 +513,11 @@ private PsiFile generateLayoutFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateAclXmlFile() { - return new AclXmlGenerator(new AclXmlData( + /** + * Generate ACL XML file. + */ + private void generateAclXmlFile() { + new AclXmlGenerator(new AclXmlData( getParentAcl(), getAcl(), getAclTitle() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java index df1600789..21b5d2bc5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; import com.intellij.util.indexing.FileBasedIndex; import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction; @@ -44,7 +43,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; -import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; @@ -255,8 +254,7 @@ public static void open(final Project project, final PsiDirectory directory) { */ public UiComponentDataProviderData getGridDataProviderData() { return new UiComponentDataProviderData( - getDataProviderClass(), - getDataProviderNamespace(), + getDataProviderClassName(), getDataProviderDirectory() ); } @@ -287,9 +285,10 @@ public UiComponentGridData getUiComponentGridData() { getModuleName(), getArea(), getUiComponentName(), - getDataProviderClassFqn(), getEntityIdFieldName(), getAcl(), + getDataProviderClassName(), + getDataProviderDirectory(), getUiComponentGridToolbarData() ); } @@ -325,14 +324,20 @@ private void addActionListeners() { dataProviderType.addActionListener(event -> onDataProviderTypeChange()); } - private PsiFile generateRoutesXmlFile() { - return new RoutesXmlGenerator(new RoutesXmlData( + /** + * Generate routes file. + */ + private void generateRoutesXmlFile() { + new RoutesXmlGenerator(new RoutesXmlData( getArea(), getRoute(), getModuleName() ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } + /** + * Generate Ui Component class. + */ private void generateUiComponentFile() { final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( getUiComponentGridData(), @@ -341,8 +346,11 @@ private void generateUiComponentFile() { gridXmlGenerator.generate(NewUiComponentGridAction.ACTION_NAME, true); } + /** + * Generate data provider class. + */ private void generateDataProviderClass() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { + if (getDataProviderType().equals(UiComponentDataProviderFile.CUSTOM_TYPE)) { final UiComponentDataProviderGenerator dataProviderGenerator; dataProviderGenerator = new UiComponentDataProviderGenerator( getGridDataProviderData(), @@ -353,13 +361,16 @@ private void generateDataProviderClass() { } } + /** + * Generate data provider declaration. + */ private void generateDataProviderDeclaration() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.COLLECTION_TYPE)) { + if (getDataProviderType().equals(UiComponentDataProviderFile.COLLECTION_TYPE)) { final DataProviderDeclarationGenerator dataProviderGenerator; dataProviderGenerator = new DataProviderDeclarationGenerator( new DataProviderDeclarationData( getModuleName(), - getDataProviderClass(), + getDataProviderClassName(), getCollection(), getUiComponentName() + "_data_source", getTableName() @@ -368,13 +379,16 @@ private void generateDataProviderDeclaration() { } } - private PsiFile generateViewControllerFile() { + /** + * Generate view controller file. + */ + private void generateViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), getActionName(), getControllerDirectory() ); - return new ModuleControllerClassGenerator(new ControllerFileData( + new ModuleControllerClassGenerator(new ControllerFileData( getControllerDirectory(), getActionName(), getModuleName(), @@ -386,8 +400,11 @@ private PsiFile generateViewControllerFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( + /** + * Generate layout file. + */ + private void generateLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( getArea(), getRoute(), getModuleName(), @@ -397,8 +414,11 @@ private PsiFile generateLayoutFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateMenuFile() { - return new MenuXmlGenerator(new MenuXmlData( + /** + * Generate menu xml file. + */ + private void generateMenuFile() { + new MenuXmlGenerator(new MenuXmlData( getParentMenuItem(), getSortOrder(), getModuleName(), @@ -409,8 +429,11 @@ private PsiFile generateMenuFile() { ), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - private PsiFile generateAclXmlFile() { - return new AclXmlGenerator(new AclXmlData( + /** + * Generate ACL XML file. + */ + private void generateAclXmlFile() { + new AclXmlGenerator(new AclXmlData( getParentAcl(), getAcl(), getAclTitle() @@ -439,7 +462,7 @@ private void onAreaChange() { private void onDataProviderTypeChange() { final boolean visible = getDataProviderType().equals( - UiComponentDataProviderPhp.COLLECTION_TYPE + UiComponentDataProviderFile.COLLECTION_TYPE ); collection.setVisible(visible); @@ -492,8 +515,8 @@ private List getCollectionOptions() { private List getProviderTypeOptions() { return new ArrayList<>( Arrays.asList( - UiComponentDataProviderPhp.COLLECTION_TYPE, - UiComponentDataProviderPhp.CUSTOM_TYPE + UiComponentDataProviderFile.COLLECTION_TYPE, + UiComponentDataProviderFile.CUSTOM_TYPE ) ); } @@ -529,14 +552,14 @@ private String getDataProviderNamespace() { } private String getDataProviderClassFqn() { - if (!getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { - return UiComponentDataProviderPhp.DEFAULT_DATA_PROVIDER; + if (!getDataProviderType().equals(UiComponentDataProviderFile.CUSTOM_TYPE)) { + return UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER; } return String.format( "%s%s%s", getDataProviderNamespace(), Package.fqnSeparator, - getDataProviderClass() + getDataProviderClassName() ); } @@ -594,7 +617,12 @@ private String getCollection() { return collectionFqn.substring(1); } - private String getDataProviderClass() { + /** + * Get data provider class name. + * + * @return String + */ + private String getDataProviderClassName() { return providerClassName.getText().trim(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java index 4c0f7371d..9bc68139d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.dialog;//NOPMD +package com.magento.idea.magento2plugin.actions.generation.dialog; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; @@ -43,7 +43,10 @@ import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"}) +@SuppressWarnings({ + "PMD.UnusedPrivateMethod", + "PMD.ExcessiveImports" +}) public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD @NotNull private final Project project; @@ -165,9 +168,8 @@ protected void onOK() { } final PsiFile diXml = new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getPreferenceModule(), - targetClass, + targetClass.getPresentableFQN(), getPreferenceClassFqn(), - getNamespace(), getPreferenceArea() ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); if (diXml == null) { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/ExtractComponentFromFieldUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/ExtractComponentFromFieldUtil.java new file mode 100644 index 000000000..925cb13b3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/ExtractComponentFromFieldUtil.java @@ -0,0 +1,40 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.reflection; + +import java.lang.reflect.Field; +import javax.swing.JComponent; +import org.jetbrains.annotations.NotNull; + +public final class ExtractComponentFromFieldUtil { + + private ExtractComponentFromFieldUtil() {} + + /** + * Get JComponent value for field. + * + * @param field Field + * @param object Object + * + * @return JComponent + */ + public static JComponent extract(final @NotNull Field field, final @NotNull Object object) { + try { + field.setAccessible(true); + final Object component = field.get(object); + + if (component instanceof JComponent) { + return (JComponent) component; + } + } catch (IllegalAccessException exception) { + return null; + } finally { + field.setAccessible(false); + } + + return null; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/GetReflectionFieldUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/GetReflectionFieldUtil.java new file mode 100644 index 000000000..4880a3abc --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/reflection/GetReflectionFieldUtil.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.reflection; + +import java.lang.reflect.Field; +import org.jetbrains.annotations.NotNull; + +public final class GetReflectionFieldUtil { + + private GetReflectionFieldUtil() {} + + /** + * Get field by its name for specified type. + * + * @param name String + * @param type Class + * + * @return Field + */ + public static Field getByName(final @NotNull String name, final @NotNull Class type) { + try { + return type.getDeclaredField(name); + } catch (NoSuchFieldException | SecurityException exception) { + return null; + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ClassPropertyFormatterUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ClassPropertyFormatterUtil.java new file mode 100644 index 000000000..3c1a4363e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ClassPropertyFormatterUtil.java @@ -0,0 +1,64 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.util; + +import com.google.common.base.CaseFormat; +import com.magento.idea.magento2plugin.actions.generation.data.code.ClassPropertyData; +import java.util.ArrayList; +import java.util.List; +import javax.swing.table.DefaultTableModel; +import org.apache.commons.lang.StringUtils; + +public final class ClassPropertyFormatterUtil { + + private ClassPropertyFormatterUtil() {} + + /** + * Format table properties to ClassPropertyData list. + * + * @param table DefaultTableModel + * + * @return List + */ + public static List formatProperties(final DefaultTableModel table) { + final List properties = new ArrayList<>(); + + for (int index = 0; index < table.getRowCount(); index++) { + final String name = table.getValueAt(index, 0).toString(); + final String type = table.getValueAt(index, 1).toString(); + + properties.add(ClassPropertyFormatterUtil.formatSingleProperty(name, type)); + } + + return properties; + } + + /** + * Format single php class property. + * + * @param name String + * @param type String + * + * @return String + */ + public static String formatSingleProperty(final String name, final String type) { + return new ClassPropertyData( + type, + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name), + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name), + name, + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, name) + ).string(); + } + + /** + * Gets properties as a string, ready for templating. + * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". + */ + public static String joinProperties(final List properties) { + return StringUtils.join(properties, ","); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/DialogFieldErrorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/DialogFieldErrorUtil.java new file mode 100644 index 000000000..80c12d54a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/DialogFieldErrorUtil.java @@ -0,0 +1,196 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.util; + +import com.intellij.util.ui.UIUtil; +import com.magento.idea.magento2plugin.actions.generation.dialog.AbstractDialog; +import com.magento.idea.magento2plugin.actions.generation.dialog.reflection.ExtractComponentFromFieldUtil; +import java.awt.Color; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.lang.reflect.Field; +import javax.swing.BorderFactory; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.UIManager; +import javax.swing.border.Border; +import org.jetbrains.annotations.NotNull; + +public final class DialogFieldErrorUtil { + + private static final Color ERROR_COLOR = new Color(252, 119, 83); + private static final Color ERROR_BACKGROUND_COLOR = new Color(252, 119, 83, 15); + private static final String ERROR_HOLDER_NAME_SUFFIX = "ErrorMessage"; + + private DialogFieldErrorUtil() {} + + /** + * Add error highlighting for JComponent. + * + * @param dialog AbstractDialog + * @param field Field + */ + public static void highlightField( + final @NotNull AbstractDialog dialog, + final @NotNull Field field + ) { + final JComponent fieldComponent = ExtractComponentFromFieldUtil.extract(field, dialog); + + if (fieldComponent != null) { + highlightField(fieldComponent); + } + } + + /** + * Add error highlighting for JComponent. + * + * @param fieldComponent JComponent + */ + public static void highlightField(final @NotNull JComponent fieldComponent) { + fieldComponent.setBorder(BorderFactory.createLineBorder(ERROR_COLOR)); + fieldComponent.setBackground(ERROR_BACKGROUND_COLOR); + + fieldComponent.addFocusListener(new FocusListener() { + @Override + public void focusGained(final FocusEvent event) { + resetComponentHighlighting(fieldComponent); + } + + @Override + public void focusLost(final FocusEvent event) { + resetComponentHighlighting(fieldComponent); + } + }); + } + + /** + * Reset field highlighting. + * + * @param field Field + * @param dialog AbstractDialog + */ + public static void resetFieldHighlighting( + final @NotNull Field field, + final @NotNull AbstractDialog dialog + ) { + final JComponent fieldComponent = ExtractComponentFromFieldUtil.extract(field, dialog); + + if (fieldComponent == null) { + return; + } + + resetComponentHighlighting(fieldComponent); + final JLabel messageHolder = getMessageHolderForField(dialog, field); + + if (messageHolder == null) { + return; + } + + messageHolder.setVisible(false); + messageHolder.setText(""); + } + + /** + * Reset component highlighting. + * + * @param fieldComponent JComponent + */ + public static void resetComponentHighlighting( + final @NotNull JComponent fieldComponent + ) { + Color defaultBackgroundColor; + Border defaultBorder; + + if (fieldComponent instanceof JTextField) { + defaultBackgroundColor = UIManager.getColor("TextField.background"); + defaultBorder = UIManager.getBorder("TextField.border"); + } else if (fieldComponent instanceof JComboBox) { + defaultBackgroundColor = UIManager.getColor("ComboBox.background"); + defaultBorder = UIManager.getBorder("ComboBox.border"); + } else { + defaultBackgroundColor = UIManager.getColor("TextField.background"); + defaultBorder = UIManager.getBorder("TextField.border"); + } + + fieldComponent.setBackground(defaultBackgroundColor); + fieldComponent.setBorder(defaultBorder); + } + + /** + * Show error message for field. + * + * @param dialog AbstractDialog + * @param field Field + * @param message String + * + * @return boolean value that specify if error message was shown for field. + */ + public static boolean showErrorMessageForField( + final @NotNull AbstractDialog dialog, + final @NotNull Field field, + final @NotNull String message + ) { + final JLabel messageHolder = getMessageHolderForField(dialog, field); + final JComponent fieldComponent = ExtractComponentFromFieldUtil.extract(field, dialog); + + if (messageHolder == null || fieldComponent == null) { + return false; + } + highlightField(fieldComponent); + + messageHolder.setVisible(true); + messageHolder.setFont(UIUtil.getLabelFont(UIUtil.FontSize.MINI)); + messageHolder.setForeground(ERROR_COLOR); + messageHolder.setText(message); + + fieldComponent.addFocusListener(new FocusListener() { + @Override + public void focusGained(final FocusEvent event) { + messageHolder.setVisible(false); + messageHolder.setText(""); + } + + @Override + public void focusLost(final FocusEvent event) { + messageHolder.setVisible(false); + messageHolder.setText(""); + } + }); + + return true; + } + + /** + * Get message holder component for field. + * + * @param dialog AbstractDialog + * @param field Field + * + * @return JLabel + */ + private static JLabel getMessageHolderForField( + final @NotNull AbstractDialog dialog, + final @NotNull Field field + ) { + try { + final String errorHolderName = field.getName().concat(ERROR_HOLDER_NAME_SUFFIX); + final Field holderField = dialog.getClass().getDeclaredField(errorHolderName); + holderField.setAccessible(true); + final Object holderComponent = holderField.get(dialog); + holderField.setAccessible(false); + + if (holderComponent instanceof JLabel) { + return (JLabel) holderComponent; + } + } catch (NoSuchFieldException | IllegalAccessException exception) { + return null; + } + + return null; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/HighlightDialogFieldOnErrorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/HighlightDialogFieldOnErrorUtil.java deleted file mode 100644 index d894d51f6..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/HighlightDialogFieldOnErrorUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.dialog.util; - -import java.awt.Color; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import javax.swing.BorderFactory; -import javax.swing.JComponent; - -public final class HighlightDialogFieldOnErrorUtil { - private static final Color ERROR_BORDER_COLOR = new Color(252, 119, 83); - private static final Color ERROR_BACKGROUND_COLOR = new Color(252, 119, 83, 15); - - private HighlightDialogFieldOnErrorUtil() {} - - /** - * Add error highlighting for JComponent. - * - * @param field JComponent - */ - public static void execute(final JComponent field) { - final Color defaultBackgroundColor = field.getBackground(); - - field.setBorder(BorderFactory.createLineBorder(ERROR_BORDER_COLOR)); - field.setBackground(ERROR_BACKGROUND_COLOR); - - field.addFocusListener(new FocusListener() { - @Override - public void focusGained(final FocusEvent event) { - field.setBorder(null); - field.setBackground(defaultBackgroundColor); - } - - @Override - public void focusLost(FocusEvent e) {}//NOPMD - }); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java new file mode 100644 index 000000000..f8add1558 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java @@ -0,0 +1,118 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.util; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; +import javax.swing.SwingWorker; +import org.jetbrains.annotations.NotNull; + +/** + * This worker is used to allow button on click action to be performed in the separate thread. + * It releases UI to not be blocked. + */ +public final class ProcessWorker extends SwingWorker { + + private final Runnable processExecutorService; + private final Runnable processReleaserService; + private final InProgressFlag inProgressFlag; + + /** + * Process worker constructor. + * + * @param processExecutorService Runnable + * @param processReleaserService Runnable + * @param inProgressFlag InProgressFlag + */ + public ProcessWorker( + final @NotNull Runnable processExecutorService, + final @NotNull Runnable processReleaserService, + final InProgressFlag inProgressFlag + ) { + super(); + this.processExecutorService = processExecutorService; + this.processReleaserService = processReleaserService; + this.inProgressFlag = inProgressFlag; + } + + @Override + protected Boolean doInBackground() { + if (!inProgressFlag.isInProgress()) { + inProgressFlag.setInProgress(true); + // Run action event process + ApplicationManager.getApplication().invokeAndWait( + processExecutorService, + ModalityState.defaultModalityState() + ); + // Run release dialog action process + ApplicationManager.getApplication().invokeAndWait( + processReleaserService, + ModalityState.defaultModalityState() + ); + } + return null; + } + + /** + * Inner class used only to stop actionPerformed method executing. + */ + public static final class InProgressFlag { + + /** + * Is action in progress flag. + */ + private boolean inProgress; + + /** + * Is action finished flag. + */ + private boolean finished; + + /** + * In progress flag constructor. + * + * @param inProgress boolean + */ + public InProgressFlag(final boolean inProgress) { + this.inProgress = inProgress; + finished = false; + } + + /** + * Get is in progress value. + * + * @return boolean + */ + public boolean isInProgress() { + return inProgress; + } + + /** + * Set is in progress flag value. + * + * @param inProgress boolean + */ + public void setInProgress(final boolean inProgress) { + this.inProgress = inProgress; + } + + /** + * Get is progress finished flag value. + */ + public boolean isFinished() { + return finished; + } + + /** + * Set is progress finished flag value. + * + * @param finished boolean + */ + public void setFinished(final boolean finished) { + this.finished = finished; + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/FieldValidation.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/FieldValidation.java index 0303e35ce..b015a0b68 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/FieldValidation.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/FieldValidation.java @@ -26,7 +26,7 @@ /** * Get specified in the annotation message array. * The first element of array is a bundle message identifier, - * туче elements are the arguments for the bundle message. + * next elements are the arguments for the bundle message. * * @return String[] */ diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java index 4f1110374..15e94f928 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/RuleRegistry.java @@ -18,6 +18,7 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierWithColonRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.Lowercase; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.MenuIdentifierRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassFqnRule; @@ -50,7 +51,8 @@ public enum RuleRegistry { CONFIG_PATH(ConfigPathRule.class), CLI_COMMAND(CliCommandRule.class), NUMERIC(NumericRule.class), - TABLE_NAME_LENGTH(TableNameLength.class); + TABLE_NAME_LENGTH(TableNameLength.class), + MENU_IDENTIFIER(MenuIdentifierRule.class); private Class rule; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/TypeFieldsRulesParser.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/TypeFieldsRulesParser.java new file mode 100644 index 000000000..9436b44f3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/TypeFieldsRulesParser.java @@ -0,0 +1,75 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation; + +import com.intellij.openapi.util.Pair; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.data.FieldValidationData; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public final class TypeFieldsRulesParser { + + private final Class type; + private List fieldValidationList; + + /** + * Type fields rules parser. + * + * @param object Object + */ + public TypeFieldsRulesParser(final @NotNull Object object) { + type = object.getClass(); + } + + /** + * Parse validation rules for type. + * + * @return List[FieldValidationData] + */ + public List parseValidationRules() { + if (fieldValidationList == null) { + fieldValidationList = new LinkedList<>(); + final List annotations = new LinkedList<>(); + final List> rulePairList = new LinkedList<>(); + + for (final Field field : type.getDeclaredFields()) { + annotations.clear(); + field.setAccessible(true); + + if (field.isAnnotationPresent(FieldValidation.class)) { + annotations.add(field.getAnnotation(FieldValidation.class)); + } + + if (field.isAnnotationPresent(FieldValidations.class)) { + annotations.addAll( + Arrays.asList(field.getAnnotation(FieldValidations.class).value()) + ); + } + field.setAccessible(false); + rulePairList.clear(); + + for (final FieldValidation annotation : annotations) { + final ValidationRule rule = ValidationRuleExtractorUtil.extract(annotation); + final String message = ValidationMessageExtractorUtil.extract(annotation); + + if (rule != null) { + rulePairList.add(new Pair<>(rule, message)); //NOPMD + } + } + + if (!rulePairList.isEmpty()) { + fieldValidationList.add(new FieldValidationData(field, rulePairList)); //NOPMD + } + } + } + + return fieldValidationList; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationMessageExtractorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationMessageExtractorUtil.java new file mode 100644 index 000000000..8d66d46ae --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationMessageExtractorUtil.java @@ -0,0 +1,37 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation; + +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import java.util.Arrays; +import org.jetbrains.annotations.NotNull; + +public final class ValidationMessageExtractorUtil { + + private static final int MIN_MESSAGE_ARRAY_LENGTH = 1; + private static final ValidatorBundle VALIDATOR_BUNDLE = new ValidatorBundle(); + + private ValidationMessageExtractorUtil() {} + + /** + * Extract validation message from validation annotation. + * + * @param annotation FieldValidation + * + * @return String + */ + public static String extract(final @NotNull FieldValidation annotation) { + String[] params; + + if (annotation.message().length > MIN_MESSAGE_ARRAY_LENGTH) { + params = Arrays.copyOfRange(annotation.message(), 1, annotation.message().length); + } else { + params = new String[]{}; + } + + return VALIDATOR_BUNDLE.message(annotation.message()[0], (Object[]) params); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationRuleExtractorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationRuleExtractorUtil.java new file mode 100644 index 000000000..d6d15826c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/annotation/ValidationRuleExtractorUtil.java @@ -0,0 +1,39 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation; + +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule; +import java.lang.reflect.InvocationTargetException; +import org.jetbrains.annotations.NotNull; + +public final class ValidationRuleExtractorUtil { + + private ValidationRuleExtractorUtil() {} + + /** + * Extract validation rule from validation annotation. + * + * @param annotation FieldValidation + * + * @return ValidationRule + */ + public static ValidationRule extract(final @NotNull FieldValidation annotation) { + ValidationRule rule; + final Class ruleType = annotation.rule().getRule(); + + try { + rule = (ValidationRule) ruleType.getConstructor().newInstance(); + } catch (NoSuchMethodException + | IllegalAccessException + | InvocationTargetException + | InstantiationException exception + ) { + return null; + } + + return rule; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/data/FieldValidationData.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/data/FieldValidationData.java new file mode 100644 index 000000000..6a106ebbf --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/data/FieldValidationData.java @@ -0,0 +1,45 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.data; + +import com.intellij.openapi.util.Pair; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule; +import java.lang.reflect.Field; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class FieldValidationData { + + private final Field field; + private final List> rules; + + public FieldValidationData( + final @NotNull Field field, + final @NotNull List> rules + ) { + this.field = field; + this.rules = new LinkedList<>(rules); + } + + /** + * Get field. + * + * @return Field + */ + public Field getField() { + return field; + } + + /** + * Get validation rules. + * + * @return List + */ + public List> getRules() { + return new LinkedList<>(rules); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/AclResourceIdRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/AclResourceIdRule.java index 27b61b1f4..2ba81f24e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/AclResourceIdRule.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/AclResourceIdRule.java @@ -13,7 +13,7 @@ public class AclResourceIdRule implements ValidationRule { @Override public boolean check(final String value) { - return value.matches(RegExUtil.Magento.ACL_RESOURCE_ID); + return value.matches(RegExUtil.Magento.XML_IDENTIFIER); } public static ValidationRule getInstance() { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/MenuIdentifierRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/MenuIdentifierRule.java new file mode 100644 index 000000000..f11979b14 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/MenuIdentifierRule.java @@ -0,0 +1,17 @@ +package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule; + +import com.magento.idea.magento2plugin.util.RegExUtil; + +public class MenuIdentifierRule implements ValidationRule { + public static final String MESSAGE = "validator.menuIdentifierInvalid"; + private static final ValidationRule INSTANCE = new MenuIdentifierRule(); + + @Override + public boolean check(final String value) { + return value.matches(RegExUtil.Magento.XML_IDENTIFIER); + } + + public static ValidationRule getInstance() { + return INSTANCE; + } +} \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java index 87c3dccde..331ae6cb6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java @@ -5,141 +5,84 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.DataModel; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.LinkedList; -import java.util.List; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class DataModelGenerator extends FileGenerator { - private final Project project; - private final DataModelData modelData; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; - private final GetFirstClassOfFile getFirstClassOfFile; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; +public class DataModelGenerator extends PhpFileGenerator { + + private final DataModelData data; /** - * Constructor. + * Data model generator constructor. + * + * @param project Project + * @param data DataModelData */ - public DataModelGenerator(final Project project, final DataModelData modelData) { - super(project); - - this.project = project; - this.modelData = modelData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + public DataModelGenerator( + final @NotNull Project project, + final @NotNull DataModelData data + ) { + this(project, data, true); } - @Override - public PsiFile generate(final String actionName) { - final PsiFile[] files = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass model = GetPhpClassByFQN.getInstance(project).execute( - modelData.getFQN() - ); - - if (model == null) { - model = createModel(actionName); - - if (model == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "Data Model" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - } else { - files[0] = model.getContainingFile(); - } - } else { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "Data Model" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - } - }); - - return files[0]; + /** + * Data model generator constructor. + * + * @param project Project + * @param data DataModelData + * @param checkFileAlreadyExists boolean + */ + public DataModelGenerator( + final @NotNull Project project, + final @NotNull DataModelData data, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; } @Override - protected void fillAttributes(final Properties attributes) { - final List uses = getUses(); - attributes.setProperty("NAMESPACE", modelData.getNamespace()); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - attributes.setProperty("NAME", modelData.getName()); - attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(DataModel.DATA_OBJECT) - ); - attributes.setProperty( - "IMPLEMENTS", - PhpClassGeneratorUtil.getNameFromFqn(modelData.getInterfaceFQN()) - ); - attributes.setProperty("PROPERTIES", modelData.getProperties()); - attributes.setProperty("HASINTERFACE", Boolean.toString(modelData.hasInterface())); + protected AbstractPhpFile initFile() { + return new DataModelFile(data.getModuleName(), data.getName()); } - private List getUses() { - final List usesList = new LinkedList<>(); - usesList.add(DataModel.DATA_OBJECT); - - if (modelData.hasInterface()) { - usesList.add(modelData.getInterfaceFQN()); + /** + * Fill data model file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("NAME", data.getName()) + .appendProperty("PROPERTIES", data.getProperties()) + .appendProperty("HASINTERFACE", Boolean.toString(data.hasInterface())) + .append("EXTENDS", DataModelFile.DATA_OBJECT); + + if (data.hasInterface()) { + phpClassTypesBuilder.append( + "IMPLEMENTS", + new DataModelInterfaceFile( + data.getModuleName(), + data.getInterfaceName() + ).getClassFqn()); } - return usesList; - } - - private PhpClass createModel(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(modelData.getModuleName()); - final PsiFile interfaceFile; - final Properties attributes = getAttributes(); - for (final String directory: DataModel.DIRECTORY.split("/")) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } + phpClassTypesBuilder.mergeProperties(attributes); - interfaceFile = fileFromTemplateGenerator.generate( - new DataModel(modelData.getName()), - attributes, - parentDirectory, - actionName + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) ); - - return interfaceFile == null ? null : getFirstClassOfFile.execute((PhpFile) interfaceFile); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java index e9829199b..547b24408 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java @@ -5,120 +5,60 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.DataModelInterface; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class DataModelInterfaceGenerator extends FileGenerator { - private final Project project; - private final DataModelInterfaceData interfaceData; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; - private final GetFirstClassOfFile getFirstClassOfFile; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; +public class DataModelInterfaceGenerator extends PhpFileGenerator { + + private final DataModelInterfaceData data; /** - * Constructor. + * DTO interface generator constructor. + * + * @param data DataModelInterfaceData + * @param project Project */ public DataModelInterfaceGenerator( - final Project project, - final DataModelInterfaceData interfaceData + final @NotNull DataModelInterfaceData data, + final @NotNull Project project ) { - super(project); - - this.project = project; - this.interfaceData = interfaceData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + this(data, project, true); } - @Override - public PsiFile generate(final String actionName) { - final PsiFile[] files = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass modelInterface = GetPhpClassByFQN.getInstance(project).execute( - interfaceData.getFQN() - ); - - if (modelInterface == null) { - modelInterface = createInterface(actionName); - - if (modelInterface == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "Data Model Interface" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - } else { - files[0] = modelInterface.getContainingFile(); - } - } else { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "Data Model Interface" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - } - }); - - return files[0]; + /** + * DTO interface generator constructor. + * + * @param data DataModelInterfaceData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public DataModelInterfaceGenerator( + final @NotNull DataModelInterfaceData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; } @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", interfaceData.getName()); - attributes.setProperty("NAMESPACE", interfaceData.getNamespace()); - attributes.setProperty("PROPERTIES", interfaceData.getProperties()); + protected AbstractPhpFile initFile() { + return new DataModelInterfaceFile(data.getModuleName(), data.getName()); } - private PhpClass createInterface(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(interfaceData.getModuleName()); - final PsiFile interfaceFile; - final Properties attributes = getAttributes(); - - for (final String directory: DataModelInterface.DIRECTORY.split("/")) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } - - interfaceFile = fileFromTemplateGenerator.generate( - new DataModelInterface(interfaceData.getName()), - attributes, - parentDirectory, - actionName - ); - - return interfaceFile == null ? null : getFirstClassOfFile.execute((PhpFile) interfaceFile); + /** + * Fill DTO interface file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAME", data.getName()); + attributes.setProperty("NAMESPACE", file.getNamespace()); + attributes.setProperty("PROPERTIES", data.getProperties()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistJsonGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistJsonGenerator.java index 331a4e770..8268d2ab8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistJsonGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistJsonGenerator.java @@ -21,6 +21,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.FindOrCreateDbSchemaWhitelistJson; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaWhitelistJson; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import java.util.Arrays; import java.util.Map; import java.util.Properties; @@ -84,10 +85,10 @@ public PsiFile generate(final String actionName) { final JsonObject indexObject = jsonElementGenerator.createObject(""); for (final Map columnData : dbSchemaXmlData.getColumns()) { - final String columnName = columnData.get(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME); + final String columnName = columnData.get(ColumnAttributes.NAME.getName()); final boolean isIdentity = Boolean.parseBoolean( - columnData.get(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY) + columnData.get(ColumnAttributes.IDENTITY.getName()) ); if (isIdentity) { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGenerator.java index 5be58ad68..f394ebde5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGenerator.java @@ -16,6 +16,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; import com.magento.idea.magento2plugin.actions.generation.generator.util.FindOrCreateDbSchemaXmlUtil; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; import java.util.HashMap; import java.util.InputMismatchException; @@ -91,14 +92,14 @@ public PsiFile generate(final String actionName) { for (final Map columnData : dbSchemaXmlData.getColumns()) { final String identityAttrValue = - columnData.get(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY); + columnData.get(ColumnAttributes.IDENTITY.getName()); if (!hasPrimaryKey && Boolean.parseBoolean(identityAttrValue)) { hasPrimaryKey = true; primaryKeyData.putAll(columnData); } - final String columnTypeValue = columnData.get(ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE); + final String columnTypeValue = columnData.get(ColumnAttributes.TYPE.getName()); final TableColumnTypes columnType = TableColumnTypes.getByValue(columnTypeValue); if (columnType == null) { @@ -117,11 +118,11 @@ public PsiFile generate(final String actionName) { } } final String columnIdentityValue = - columnData.get(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME); + columnData.get(ColumnAttributes.NAME.getName()); findOrCreateTag( ModuleDbSchemaXml.XML_TAG_COLUMN, - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, + ColumnAttributes.NAME.getName(), tableTag, columnIdentityValue, attributes @@ -147,7 +148,7 @@ private void generatePrimaryKey( ) { final Map attributes = new LinkedHashMap<>(); attributes.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), ModuleDbSchemaXml.XML_ATTR_TYPE_PK ); attributes.put( @@ -164,13 +165,13 @@ private void generatePrimaryKey( ); final Map pkColumnAttributes = new HashMap<>(); final String columnIdentityValue = primaryKeyData.get( - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME + ColumnAttributes.NAME.getName() ); - pkColumnAttributes.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, columnIdentityValue); + pkColumnAttributes.put(ColumnAttributes.NAME.getName(), columnIdentityValue); findOrCreateTag( ModuleDbSchemaXml.XML_TAG_COLUMN, - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, + ColumnAttributes.NAME.getName(), pkTag, columnIdentityValue, pkColumnAttributes @@ -202,7 +203,7 @@ private void generatePrimaryKey( findOrCreateTag( ModuleDbSchemaXml.XML_TAG_COLUMN, - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, + ColumnAttributes.NAME.getName(), pkIndexTag, columnIdentityValue, pkColumnAttributes diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java new file mode 100644 index 000000000..bb9b80a9d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java @@ -0,0 +1,91 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; +import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; +import com.magento.idea.magento2plugin.magento.packages.code.ExceptionType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityByIdCommandGenerator extends PhpFileGenerator { + + private final DeleteEntityByIdCommandData data; + + /** + * Delete entity command generator constructor. + * + * @param data DeleteEntityCommandData + * @param project Project + */ + public DeleteEntityByIdCommandGenerator( + final @NotNull DeleteEntityByIdCommandData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Delete entity command generator constructor. + * + * @param data DeleteEntityCommandData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public DeleteEntityByIdCommandGenerator( + final @NotNull DeleteEntityByIdCommandData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new DeleteEntityByIdCommandFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill delete command file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName()); + final String modelType = modelFile.getClassFqn(); + final String modelFactoryType = modelType.concat("Factory"); + final ResourceModelFile resourceFile = + new ResourceModelFile(data.getModuleName(), data.getResourceModelName()); + + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("CLASS_NAME", DeleteEntityByIdCommandFile.CLASS_NAME) + .appendProperty("ENTITY_ID", data.getEntityId()) + .append("Exception", "Exception") + .append("COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType()) + .append("NO_SUCH_ENTITY_EXCEPTION", + ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()) + .append("LOGGER", FrameworkLibraryType.LOGGER.getType()) + .append("MODEL", modelType) + .append("MODEL_FACTORY", modelFactoryType) + .append("RESOURCE", resourceFile.getClassFqn()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java new file mode 100644 index 000000000..0832fc370 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java @@ -0,0 +1,95 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile; +import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.ExceptionType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityControllerFileGenerator extends PhpFileGenerator { + + private final DeleteEntityControllerFileData data; + + /** + * Delete Entity Controller File Generator. + * + * @param data DeleteEntityControllerFileData + * @param project Project + */ + public DeleteEntityControllerFileGenerator( + final @NotNull DeleteEntityControllerFileData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Delete Entity Controller File Generator. + * + * @param data DeleteEntityControllerFileData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public DeleteEntityControllerFileGenerator( + final @NotNull DeleteEntityControllerFileData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new DeleteActionFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill delete action file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", DeleteActionFile.CLASS_NAME) + .appendProperty("ADMIN_RESOURCE", data.getAcl()) + .appendProperty("ENTITY_ID", data.getEntityId()) + .append("DELETE_COMMAND", + new DeleteEntityByIdCommandFile( + data.getModuleName(), + data.getEntityName() + ).getClassFqn() + ) + .append("CONTEXT", BackendModuleType.CONTEXT.getType()) + .append("RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()) + .append("RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()) + .append("EXTENDS", BackendModuleType.EXTENDS.getType()) + .append("IMPLEMENTS_POST", HttpMethod.POST.getInterfaceFqn()) + .append("IMPLEMENTS_GET", HttpMethod.GET.getInterfaceFqn()) + .append("NO_SUCH_ENTITY_EXCEPTION", + ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()) + .append("COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java new file mode 100644 index 000000000..c6c5d4b78 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java @@ -0,0 +1,83 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class EditEntityActionGenerator extends PhpFileGenerator { + + private final EditEntityActionData data; + + /** + * Edit entity action/controller file generator constructor. + * + * @param data EditEntityActionData + * @param project Project + */ + public EditEntityActionGenerator( + final @NotNull EditEntityActionData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Edit entity action/controller file generator constructor. + * + * @param data EditEntityActionData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public EditEntityActionGenerator( + final @NotNull EditEntityActionData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new EditActionFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill edit action file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", file.getClassName()) + .appendProperty("ADMIN_RESOURCE", data.getAcl()) + .appendProperty("MENU_IDENTIFIER", data.getMenu()) + .append("EXTENDS", BackendModuleType.EXTENDS.getType()) + .append("IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()) + .append("RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()) + .append("RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()) + .append("RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java new file mode 100644 index 000000000..2149af4f4 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java @@ -0,0 +1,96 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; +import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class EntityDataMapperGenerator extends PhpFileGenerator { + + private final EntityDataMapperData data; + + /** + * Entity data mapper generator constructor. + * + * @param data EntityDataMapperData + * @param project Project + */ + public EntityDataMapperGenerator( + final @NotNull EntityDataMapperData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Entity data mapper generator constructor. + * + * @param data EntityDataMapperData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public EntityDataMapperGenerator( + final @NotNull EntityDataMapperData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new EntityDataMapperFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill entity data mapper file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName()); + final DataModelFile dtoFile = new DataModelFile(data.getDtoName(), data.getModuleName()); + final DataModelInterfaceFile dtoInterfaceFile = + new DataModelInterfaceFile(data.getModuleName(), data.getDtoInterfaceName()); + String dtoType; + + if (data.isDtoWithInterface()) { + dtoType = dtoInterfaceFile.getClassFqn(); + } else { + dtoType = dtoFile.getClassFqn(); + } + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", file.getClassName()) + .append("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()) + .append("DTO_TYPE", dtoType) + .append("MAGENTO_MODEL_TYPE", modelFile.getClassFqn()) + .append("DTO_FACTORY", dtoType.concat("Factory")) + .append("ABSTRACT_COLLECTION", FrameworkLibraryType.ABSTRACT_COLLECTION.getType()) + .mergeProperties(attributes); + + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/FileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/FileGenerator.java index eea775895..a1038ee4f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/FileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/FileGenerator.java @@ -2,6 +2,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + package com.magento.idea.magento2plugin.actions.generation.generator; import com.intellij.openapi.project.Project; @@ -10,30 +11,58 @@ import java.util.Properties; public abstract class FileGenerator { - private final Project project; - private final NavigateToCreatedFile navigateToCreatedFile; - public FileGenerator(Project project) - { + protected final Project project; + protected final NavigateToCreatedFile navigateToCreatedFile; + + public FileGenerator(final Project project) { this.project = project; this.navigateToCreatedFile = NavigateToCreatedFile.getInstance(); } - public abstract PsiFile generate(String actionName); + /** + * Generate target file. + * + * @param actionName String + * + * @return PsiFile + */ + public abstract PsiFile generate(final String actionName); + + /** + * Generate file. + * + * @param actionName String + * @param openFile boolean + * + * @return PsiFile + */ + public PsiFile generate(final String actionName, final boolean openFile) { + final PsiFile file = this.generate(actionName); - public PsiFile generate(String actionName, boolean openFile) { - PsiFile file = this.generate(actionName); - if (file != null) { + if (file != null && openFile) { navigateToCreatedFile.navigate(project, file); } + return file; } + /** + * Get file properties. + * + * @return Properties + */ protected Properties getAttributes() { - Properties attributes = new Properties(); + final Properties attributes = new Properties(); this.fillAttributes(attributes); + return attributes; } - protected abstract void fillAttributes(Properties attributes); + /** + * Fill attributes to be accessible from the file template. + * + * @param attributes Properties + */ + protected abstract void fillAttributes(final Properties attributes); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java new file mode 100644 index 000000000..cdef815c5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java @@ -0,0 +1,84 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Arrays; +import java.util.Locale; +import java.util.Properties; +import java.util.stream.Collectors; +import org.jetbrains.annotations.NotNull; + +public class FormGenericButtonBlockGenerator extends PhpFileGenerator { + + private final FormGenericButtonBlockData data; + + /** + * Generic Button Block generator constructor. + * + * @param data FormGenericButtonBlockData + * @param project Project + */ + public FormGenericButtonBlockGenerator( + final @NotNull FormGenericButtonBlockData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Generic Button Block generator constructor. + * + * @param data FormGenericButtonBlockData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public FormGenericButtonBlockGenerator( + final @NotNull FormGenericButtonBlockData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new FormGenericButtonBlockFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final String entityIdGetter = "get" + Arrays.stream(data.getEntityId().split("_")) + .map(s -> s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1)) + .collect(Collectors.joining()); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", FormGenericButtonBlockFile.CLASS_NAME) + .appendProperty("ENTITY_ID", data.getEntityId()) + .appendProperty("ENTITY_ID_GETTER", entityIdGetter) + .append("CONTEXT", FormGenericButtonBlockFile.CONTEXT) + .append("URL", FrameworkLibraryType.URL.getType()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java new file mode 100644 index 000000000..c91908286 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java @@ -0,0 +1,122 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.CollectionModelFile; +import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; +import com.magento.idea.magento2plugin.magento.files.queries.GetListQueryFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class GetListQueryModelGenerator extends PhpFileGenerator { + + private final GetListQueryModelData data; + + /** + * Query model generator Constructor. + * + * @param data QueryModelData + * @param project Project + */ + public GetListQueryModelGenerator( + final @NotNull GetListQueryModelData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Query model generator Constructor. + * + * @param data QueryModelData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public GetListQueryModelGenerator( + final @NotNull GetListQueryModelData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new GetListQueryFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final CollectionModelFile collectionModelFile = + new CollectionModelFile( + data.getModuleName(), + data.getCollectionName(), + data.getModelName() + ); + final NamespaceBuilder collectionNamespace = + collectionModelFile.getNamespaceBuilder(); + + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("CLASS_NAME", GetListQueryFile.CLASS_NAME) + .append( + "ENTITY_COLLECTION_TYPE", + collectionNamespace.getClassFqn() + ) + .append( + "ENTITY_COLLECTION_FACTORY_TYPE", + collectionNamespace.getClassFqn().concat("Factory") + ) + .append( + "ENTITY_DATA_MAPPER_TYPE", + new EntityDataMapperFile( + data.getModuleName(), + data.getEntityName() + ).getClassFqn() + ) + .append( + "COLLECTION_PROCESSOR_TYPE", + FrameworkLibraryType.COLLECTION_PROCESSOR.getType() + ) + .append( + "SEARCH_CRITERIA_BUILDER_TYPE", + FrameworkLibraryType.SEARCH_CRITERIA_BUILDER.getType() + ) + .append( + "SEARCH_CRITERIA_TYPE", + FrameworkLibraryType.SEARCH_CRITERIA.getType() + ) + .append( + "SEARCH_RESULT_TYPE", + FrameworkLibraryType.SEARCH_RESULT.getType() + ) + .append( + "SEARCH_RESULT_FACTORY_TYPE", + FrameworkLibraryType.SEARCH_RESULT.getFactory() + ) + .mergeProperties(attributes); + + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java new file mode 100644 index 000000000..386984ddd --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java @@ -0,0 +1,81 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class GridActionColumnFileGenerator extends PhpFileGenerator { + + private final GridActionColumnData data; + + /** + * Constructor for grid ui component action column class generator. + * + * @param data GridActionColumnData + * @param project Project + */ + public GridActionColumnFileGenerator( + final @NotNull GridActionColumnData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Constructor for grid ui component action column class generator. + * + * @param data GridActionColumnData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public GridActionColumnFileGenerator( + final @NotNull GridActionColumnData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new GridActionColumnFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill index controller file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("ENTITY_ID", data.getEntityIdColumn()) + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("CLASS_NAME", file.getClassName()) + .appendProperty("EDIT_URL_PATH", data.getEditUrlPath()) + .appendProperty("DELETE_URL_PATH", data.getDeleteUrlPath()) + .append("PARENT_CLASS", GridActionColumnFile.PARENT_CLASS) + .append("URL", FrameworkLibraryType.URL.getType()) + .append("CONTEXT", GridActionColumnFile.CONTEXT) + .append("UI_COMPONENT_FACTORY", GridActionColumnFile.UI_COMPONENT_FACTORY) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java new file mode 100644 index 000000000..300f3fcbc --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java @@ -0,0 +1,85 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.IndexActionData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class IndexActionGenerator extends PhpFileGenerator { + + private final IndexActionData data; + + /** + * Constructor for adminhtml index (list) controller generator. + * + * @param data EntityIndexAdminhtmlActionData + * @param project Project + */ + public IndexActionGenerator( + final @NotNull IndexActionData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Constructor for adminhtml index (list) controller generator. + * + * @param data EntityIndexAdminhtmlActionData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public IndexActionGenerator( + final @NotNull IndexActionData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new IndexActionFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill index controller file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", IndexActionFile.CLASS_NAME) + .appendProperty("ACL", data.getAcl()) + .appendProperty("MENU", data.getMenu()) + .appendProperty("NAMESPACE", file.getNamespace()) + .append("PARENT_CLASS_NAME", BackendModuleType.EXTENDS.getType()) + .append("HTTP_GET_METHOD", HttpMethod.GET.getInterfaceFqn()) + .append("RESULT", FrameworkLibraryType.RESULT_INTERFACE.getType()) + .append("RESPONSE", FrameworkLibraryType.RESPONSE_INTERFACE.getType()) + .append("RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()) + .mergeProperties(attributes); + + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java index 6b9c1770e..64c6c7eaf 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java @@ -5,178 +5,95 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.CollectionPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.CollectionModelFile; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class ModuleCollectionGenerator extends FileGenerator { - private final CollectionData collectionData; - private final Project project; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final GetFirstClassOfFile getFirstClassOfFile; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; +public class ModuleCollectionGenerator extends PhpFileGenerator { + + private final CollectionData data; /** * Generates new Collection PHP Class based on provided data. * - * @param collectionData CollectionData + * @param data CollectionData * @param project Project */ public ModuleCollectionGenerator( - final CollectionData collectionData, - final Project project + final @NotNull CollectionData data, + final @NotNull Project project ) { - super(project); - this.project = project; - this.collectionData = collectionData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + this(data, project, true); } /** - * Generates collection model class. + * Generates new Collection PHP Class based on provided data. * - * @param actionName Action name - * @return PsiFile + * @param data CollectionData + * @param project Project + * @param checkFileAlreadyExists boolean */ - public PsiFile generate(final String actionName) { - final PsiFile[] collectionFiles = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass collection = GetPhpClassByFQN.getInstance(project).execute( - getCollectionModelFqn() - ); - - if (collection != null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "Collection Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - collection = createClass(actionName); - - if (collection == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "Collection Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - collectionFiles[0] = collection.getContainingFile(); - }); + public ModuleCollectionGenerator( + final @NotNull CollectionData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } - return collectionFiles[0]; + @Override + protected AbstractPhpFile initFile() { + return new CollectionModelFile( + data.getModuleName(), + data.getCollectionName(), + data.getCollectionDirectory() + ); } /** - * Get controller module. + * Fill collection model file attributes. * - * @return String + * @param attributes Properties */ - public String getModuleName() { - return collectionData.getModuleName(); - } - - private String getCollectionModelFqn() { - return collectionData.getCollectionFqn(); - } - - private PhpClass createClass(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(getModuleName()); - final PsiFile modelFile; - - final String[] collectionDirectories = collectionData.getCollectionDirectory().split( - File.separator - ); - for (final String directory: collectionDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } - - final Properties attributes = getAttributes(); - modelFile = fileFromTemplateGenerator.generate( - new CollectionPhp(collectionData.getCollectionName()), - attributes, - parentDirectory, - actionName - ); - - if (modelFile == null) { - return null; - } - - return getFirstClassOfFile.execute((PhpFile) modelFile); - } - - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", collectionData.getCollectionName()); - attributes.setProperty("NAMESPACE", collectionData.getCollectionNamespace()); - - attributes.setProperty("DB_NAME", collectionData.getDbTableName()); - attributes.setProperty("MODEL", PhpClassGeneratorUtil.getNameFromFqn( - collectionData.getModelName()) - ); - attributes.setProperty("RESOURCE_MODEL", PhpClassGeneratorUtil.getNameFromFqn( - collectionData.getResourceModelName()) - ); - final List uses = getUses(); - uses.add(collectionData.getResourceModelFqn()); - uses.add(collectionData.getModelFqn()); + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + final ResourceModelFile resourceModelFile = + new ResourceModelFile(data.getModuleName(), data.getResourceModelName()); + final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName()); + + phpClassTypesBuilder.appendProperty("NAME", data.getCollectionName()) + .appendProperty("NAMESPACE", file.getNamespaceBuilder().getNamespace()) + .appendProperty("DB_NAME", data.getDbTableName()) + .appendProperty("MODEL", data.getModelName()) + .appendProperty("RESOURCE_MODEL", data.getResourceModelName()) + .append("EXTENDS", CollectionModelFile.ABSTRACT_COLLECTION) + .append( + "RESOURCE_MODEL", + resourceModelFile.getClassFqn(), + ResourceModelFile.ALIAS + ) + .append( + "MODEL", + modelFile.getClassFqn(), + ModelFile.ALIAS + ) + .mergeProperties(attributes); attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(CollectionPhp.ABSTRACT_COLLECTION) + "USES", + PhpClassGeneratorUtil.formatUses( + phpClassTypesBuilder.getUses() + ) ); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - - private List getUses() { - return new ArrayList<>(Arrays.asList( - CollectionPhp.ABSTRACT_COLLECTION - )); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleControllerClassGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleControllerClassGenerator.java index dcb2ebeec..a5142cb3d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleControllerClassGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleControllerClassGenerator.java @@ -33,9 +33,9 @@ import java.util.Properties; import javax.swing.JOptionPane; -@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.DataflowAnomalyAnalysis"}) public class ModuleControllerClassGenerator extends FileGenerator { - private final ControllerFileData controllerFileData; + + private final ControllerFileData data; private final Project project; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; @@ -46,16 +46,16 @@ public class ModuleControllerClassGenerator extends FileGenerator { /** * Generates new Controller PHP Class based on provided data. * - * @param controllerFileData ControllerFileData + * @param data ControllerFileData * @param project Project */ public ModuleControllerClassGenerator( - final ControllerFileData controllerFileData, + final ControllerFileData data, final Project project ) { super(project); this.project = project; - this.controllerFileData = controllerFileData; + this.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); @@ -67,8 +67,10 @@ public ModuleControllerClassGenerator( * Generate controller class. * * @param actionName Action name + * * @return PsiFile */ + @Override public PsiFile generate(final String actionName) { final PsiFile[] controllerFiles = new PsiFile[1]; @@ -121,7 +123,7 @@ public PsiFile generate(final String actionName) { * @return String */ public String getControllerModule() { - return controllerFileData.getControllerModule(); + return data.getControllerModule(); } /** @@ -137,9 +139,9 @@ public static String getHttpMethodInterfaceByMethod(final String method) { private String getControllerFqn() { return String.format( "%s%s%s", - controllerFileData.getNamespace(), + data.getNamespace(), Package.fqnSeparator, - controllerFileData.getActionClassName() + data.getActionClassName() ); } @@ -147,7 +149,7 @@ private PhpClass createControllerClass(final String actionName) { PsiDirectory parentDirectory = new ModuleIndex(project) .getModuleDirectoryByModuleName(getControllerModule()); final PsiFile controllerFile; - final String[] controllerDirectories = controllerFileData.getActionDirectory().split( + final String[] controllerDirectories = data.getActionDirectory().split( File.separator ); for (final String controllerDirectory: controllerDirectories) { @@ -159,16 +161,19 @@ private PhpClass createControllerClass(final String actionName) { final Properties attributes = getAttributes(); final String adminhtmlArea = Areas.adminhtml.toString(); - if (controllerFileData.getControllerArea().equals(adminhtmlArea)) { + if (data.getControllerArea().equals(adminhtmlArea)) { controllerFile = fileFromTemplateGenerator.generate( - ControllerBackendPhp.getInstance(controllerFileData.getActionClassName()), + new ControllerBackendPhp(data.getControllerModule(), data.getActionClassName()), attributes, parentDirectory, actionName ); } else { controllerFile = fileFromTemplateGenerator.generate( - ControllerFrontendPhp.getInstance(controllerFileData.getActionClassName()), + new ControllerFrontendPhp( + data.getControllerModule(), + data.getActionClassName() + ), attributes, parentDirectory, actionName @@ -182,12 +187,13 @@ private PhpClass createControllerClass(final String actionName) { return getFirstClassOfFile.execute((PhpFile) controllerFile); } + @Override protected void fillAttributes(final Properties attributes) { - final String actionClassName = controllerFileData.getActionClassName(); + final String actionClassName = data.getActionClassName(); attributes.setProperty("NAME", actionClassName); - attributes.setProperty("NAMESPACE", controllerFileData.getNamespace()); + attributes.setProperty("NAMESPACE", data.getNamespace()); final String httpMethodInterface = getHttpMethodInterfaceByMethod( - controllerFileData.getHttpMethodName() + data.getHttpMethodName() ); attributes.setProperty( "IMPLEMENTS", @@ -196,10 +202,10 @@ protected void fillAttributes(final Properties attributes) { final List uses = getUses(); uses.add(httpMethodInterface); - if (controllerFileData.getIsInheritClass()) { + if (data.getIsInheritClass()) { final String adminhtmlArea = Areas.adminhtml.toString(); - if (controllerFileData.getControllerArea().equals(adminhtmlArea)) { + if (data.getControllerArea().equals(adminhtmlArea)) { uses.add(Controller.ADMINHTML_CONTROLLER_FQN); attributes.setProperty( "EXTENDS", @@ -207,7 +213,7 @@ protected void fillAttributes(final Properties attributes) { ); attributes.setProperty( "ACL", - PhpClassGeneratorUtil.getNameFromFqn(controllerFileData.getAcl()) + PhpClassGeneratorUtil.getNameFromFqn(data.getAcl()) ); } else { uses.add(Controller.FRONTEND_CONTROLLER_FQN); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java index 6a7332fd4..e31252d08 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java @@ -5,166 +5,85 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.ModelPhp; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class ModuleModelGenerator extends FileGenerator { - private final ModelData modelData; - private final Project project; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final GetFirstClassOfFile getFirstClassOfFile; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; +public class ModuleModelGenerator extends PhpFileGenerator { + + private final ModelData data; /** * Generates new Model PHP Class based on provided data. * - * @param modelData ModelData + * @param data ModelData * @param project Project */ public ModuleModelGenerator( - final ModelData modelData, - final Project project + final @NotNull ModelData data, + final @NotNull Project project ) { - super(project); - this.project = project; - this.modelData = modelData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + this(data, project, true); } /** - * Generates model class. + * Generates new Model PHP Class based on provided data. * - * @param actionName Action name - * @return PsiFile + * @param data ModelData + * @param project Project + * @param checkFileAlreadyExists boolean */ - public PsiFile generate(final String actionName) { - final PsiFile[] modelFiles = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass model = GetPhpClassByFQN.getInstance(project).execute( - getModelFqn() - ); - - if (model != null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "Model Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - model = createModelClass(actionName); - - if (model == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "Model Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - modelFiles[0] = model.getContainingFile(); - }); + public ModuleModelGenerator( + final @NotNull ModelData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } - return modelFiles[0]; + @Override + protected AbstractPhpFile initFile() { + return new ModelFile(data.getModuleName(), data.getModelName()); } /** - * Get module. + * Fill model file attributes. * - * @return String + * @param attributes Properties */ - public String getModuleName() { - return modelData.getModuleName(); - } - - private String getModelFqn() { - return modelData.getFqn(); - } - - private PhpClass createModelClass(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(getModuleName()); - final PsiFile modelFile; - - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, ModelPhp.MODEL_DIRECTORY - ); - - final Properties attributes = getAttributes(); - modelFile = fileFromTemplateGenerator.generate( - new ModelPhp(modelData.getModelName()), - attributes, - parentDirectory, - actionName - ); - - if (modelFile == null) { - return null; - } - - return getFirstClassOfFile.execute((PhpFile) modelFile); - } - - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", modelData.getModelName()); - attributes.setProperty("NAMESPACE", modelData.getNamespace()); - - attributes.setProperty("DB_NAME", modelData.getDbTableName()); - attributes.setProperty("RESOURCE_MODEL", modelData.getResourceName()); - final List uses = getUses(); - - attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(ModelPhp.ABSTRACT_MODEL) - ); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - - private List getUses() { - return new ArrayList<>(Arrays.asList( - ModelPhp.ABSTRACT_MODEL, - modelData.getResourceModelFqn() - )); + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final ResourceModelFile resourceModelFile = + new ResourceModelFile(data.getModuleName(), data.getResourceName()); + + phpClassTypesBuilder + .appendProperty("NAME", data.getModelName()) + .appendProperty( + "NAMESPACE", + file.getNamespace() + ) + .appendProperty("DB_NAME", data.getDbTableName()) + .append( + "RESOURCE_MODEL", + resourceModelFile.getClassFqn(), + ResourceModelFile.ALIAS + ) + .appendProperty( + "EXTENDS", + PhpClassGeneratorUtil.getNameFromFqn(ModelFile.ABSTRACT_MODEL) + ) + .append("ABSTRACT_MODEL", ModelFile.ABSTRACT_MODEL) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java index fb892539f..b885508a2 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java @@ -5,173 +5,75 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.Arrays; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; import java.util.List; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -public class ModuleResourceModelGenerator extends FileGenerator { - private final ResourceModelData resourceModelData; - private final Project project; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final GetFirstClassOfFile getFirstClassOfFile; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; +public class ModuleResourceModelGenerator extends PhpFileGenerator { + + private final ResourceModelData data; /** * Generates new Resource Model PHP Class based on provided data. * - * @param resourceModelData ResourceModelData + * @param data ResourceModelData * @param project Project */ public ModuleResourceModelGenerator( - final ResourceModelData resourceModelData, + final ResourceModelData data, final Project project ) { - super(project); - this.project = project; - this.resourceModelData = resourceModelData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); + this(data, project, true); } /** - * Generates resource model class. + * Generates new Resource Model PHP Class based on provided data. * - * @param actionName Action name - * @return PsiFile + * @param data ResourceModelData + * @param project Project + * @param checkFileAlreadyExists boolean */ - public PsiFile generate(final String actionName) { - final PsiFile[] resourceModelFiles = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass resourceModel = GetPhpClassByFQN.getInstance(project).execute( - getResourceModelFqn() - ); - - if (resourceModel != null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "Resource Model Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - resourceModel = createClass(actionName); - - if (resourceModel == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "Resource Model Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - resourceModelFiles[0] = resourceModel.getContainingFile(); - }); + public ModuleResourceModelGenerator( + final ResourceModelData data, + final Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } - return resourceModelFiles[0]; + @Override + protected AbstractPhpFile initFile() { + return new ResourceModelFile(data.getModuleName(), data.getResourceModelName()); } /** - * Get module. + * Fill resource model file attributes. * - * @return String + * @param attributes Properties */ - public String getModuleName() { - return resourceModelData.getModuleName(); - } - - private String getResourceModelFqn() { - return resourceModelData.getFqn(); - } - - private PhpClass createClass(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(getModuleName()); - final PsiFile modelFile; - - final String[] resourceModelDirectories = ResourceModelPhp.RESOURCE_MODEL_DIRECTORY.split( - File.separator - ); - for (final String directory: resourceModelDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } - - final Properties attributes = getAttributes(); - modelFile = fileFromTemplateGenerator.generate( - new ResourceModelPhp(resourceModelData.getResourceModelName()), - attributes, - parentDirectory, - actionName - ); - - if (modelFile == null) { - return null; - } - - return getFirstClassOfFile.execute((PhpFile) modelFile); - } - - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", resourceModelData.getResourceModelName()); - attributes.setProperty("NAMESPACE", resourceModelData.getNamespace()); - - attributes.setProperty("DB_NAME", resourceModelData.getDbTableName()); - attributes.setProperty("ENTITY_ID_COLUMN", PhpClassGeneratorUtil.getNameFromFqn( - resourceModelData.getEntityIdColumn()) - ); - final List uses = getUses(); - - attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(ResourceModelPhp.ABSTRACT_DB) - ); - + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAME", data.getResourceModelName()) + .appendProperty( + "NAMESPACE", + file.getNamespace() + ) + .appendProperty("DB_NAME", data.getDbTableName()) + .appendProperty("ENTITY_ID_COLUMN", data.getEntityIdColumn()) + .append("EXTENDS", ResourceModelFile.ABSTRACT_DB) + .mergeProperties(attributes); + + final List uses = phpClassTypesBuilder.getUses(); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); } - - private List getUses() { - return new ArrayList<>(Arrays.asList( - ResourceModelPhp.ABSTRACT_DB - )); - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java new file mode 100644 index 000000000..21444054d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java @@ -0,0 +1,79 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class NewActionEntityControllerFileGenerator extends PhpFileGenerator { + + private final NewActionEntityControllerFileData data; + + /** + * NewAction Entity Controller File Generator. + * + * @param data NewActionEntityControllerFileData + * @param project Project + */ + public NewActionEntityControllerFileGenerator( + final NewActionEntityControllerFileData data, + final @NotNull Project project + ) { + super(project, true); + this.data = data; + } + + /** + * NewAction Entity Controller File Generator. + * + * @param data NewActionEntityControllerFileData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public NewActionEntityControllerFileGenerator( + final NewActionEntityControllerFileData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new NewActionFile(data.getModuleName(), data.getEntityName()); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", data.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", file.getClassName()) + .appendProperty("ADMIN_RESOURCE", data.getAcl()) + .appendProperty("MENU_IDENTIFIER", data.getMenu()) + .append("EXTENDS", BackendModuleType.EXTENDS.getType()) + .append("IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()) + .append("RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()) + .append("RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()) + .append("RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGenerator.java new file mode 100644 index 000000000..4587a05d2 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGenerator.java @@ -0,0 +1,116 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.NewEntityLayoutFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class NewEntityLayoutGenerator extends FileGenerator { + + private final Project project; + private final NewEntityLayoutData data; + private final NewEntityLayoutFile file; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + + /** + * New entity layout data constructor. + * + * @param data NewEntityLayoutData + * @param project Project + */ + public NewEntityLayoutGenerator( + final @NotNull NewEntityLayoutData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * New entity layout data constructor. + * + * @param data NewEntityLayoutData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public NewEntityLayoutGenerator( + final @NotNull NewEntityLayoutData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.data = data; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + file = new NewEntityLayoutFile(data.getNewActionPath().replace(File.separator, "_")); + fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = new ModuleIndex(project); + } + + /** + * Generate new entity layout. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PsiFile layout = FileBasedIndexUtil.findModuleViewFile( + file.getFileName(), + Areas.adminhtml, + data.getModuleName(), + project, + file.getParentDirectory() + ); + + if (this.checkFileAlreadyExists && layout != null) { + return layout; + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + data.getModuleName() + ); + final PsiDirectory layoutBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + file.getDirectory() + ); + + return fileFromTemplateGenerator.generate( + file, + getAttributes(), + layoutBaseDir, + actionName + ); + } + + /** + * Fill layout file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty( + "EDIT_ENTITY_LAYOUT", + data.getEditActionPath().replace(File.separator, "_") + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/PhpFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/PhpFileGenerator.java new file mode 100644 index 000000000..e3b81f08c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/PhpFileGenerator.java @@ -0,0 +1,146 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; + +public abstract class PhpFileGenerator extends FileGenerator { + + protected AbstractPhpFile file; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + + /** + * Php file generator constructor. + * + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public PhpFileGenerator( + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.checkFileAlreadyExists = checkFileAlreadyExists; + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = new ModuleIndex(project); + } + + /** + * Php file generation. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + file = getFile(); + + final PhpClass phpClass = GetPhpClassByFQN.getInstance(project).execute( + file.getClassFqn() + ); + + if (this.checkFileAlreadyExists && phpClass != null) { + onClassAlreadyExists(phpClass); + + return phpClass.getContainingFile(); + } + + final PsiDirectory fileBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleIndex.getModuleDirectoryByModuleName(file.getModuleName()), + file.getDirectory() + ); + + final PsiFile generatedFile = fileFromTemplateGenerator.generate( + file, + getAttributes(), + fileBaseDir, + actionName + ); + onFileGenerated(generatedFile); + + return generatedFile; + } + + /** + * Class already exists behaviour. + * + * @param phpClass PhpClass + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + protected void onClassAlreadyExists(final @NotNull PhpClass phpClass) { + JOptionPane.showMessageDialog( + null, + this.validatorBundle.message( + "validator.file.alreadyExists", + file.getHumanReadableName() == null + ? file.getClassName() : file.getHumanReadableName() + ), + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + } + + /** + * Implement this method to add on file has been generated behaviour. + * + * @param generatedFile PsiFile + */ + protected void onFileGenerated(final PsiFile generatedFile) { + if (generatedFile == null) { + JOptionPane.showMessageDialog( + null, + this.validatorBundle.message( + "validator.file.cantBeCreated", + file.getHumanReadableName() == null + ? file.getClassName() : file.getHumanReadableName() + ), + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + } + } + + /** + * Initialize corresponding php file. + * + * @return AbstractPhpFile + */ + protected abstract AbstractPhpFile initFile(); + + /** + * Get file object. + * + * @return AbstractPhpFile + */ + protected AbstractPhpFile getFile() { + if (file == null) { + file = initFile(); + } + + return file; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java index 330d2c67d..2c673558c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java @@ -29,22 +29,22 @@ public class PreferenceDiXmlGenerator extends FileGenerator { private final GetCodeTemplateUtil getCodeTemplateUtil; private final FindOrCreateDiXml findOrCreateDiXml; private final XmlFilePositionUtil positionUtil; - private final PreferenceDiXmFileData preferenceDiXmFileData; + private final PreferenceDiXmFileData data; private final Project project; /** * Constructor. * - * @param preferenceDiXmFileData PreferenceDiXmFileData + * @param data PreferenceDiXmFileData * @param project Project */ public PreferenceDiXmlGenerator( - final @NotNull PreferenceDiXmFileData preferenceDiXmFileData, + final @NotNull PreferenceDiXmFileData data, final Project project ) { super(project); - this.preferenceDiXmFileData = preferenceDiXmFileData; + this.data = data; this.project = project; this.getCodeTemplateUtil = new GetCodeTemplateUtil(project); this.findOrCreateDiXml = new FindOrCreateDiXml(project); @@ -52,19 +52,22 @@ public PreferenceDiXmlGenerator( } @Override - public PsiFile generate(final String actionName) { + public PsiFile generate(final @NotNull String actionName) { final PsiFile diXmlFile = findOrCreateDiXml.execute( actionName, - preferenceDiXmFileData.getPreferenceModule(), - preferenceDiXmFileData.getArea() + data.getPreferenceModule(), + data.getArea() ); - final boolean isPreferenceDeclared = getTypeAttributeValue((XmlFile) diXmlFile); + final boolean isPreferenceDeclared = hasTypeAttributeValue((XmlFile) diXmlFile); + if (isPreferenceDeclared) { return null; } + WriteCommandAction.runWriteCommandAction(project, () -> { final StringBuffer textBuf = new StringBuffer(); + try { textBuf.append(getCodeTemplateUtil.execute( ModuleDiXml.TEMPLATE_PREFERENCE, @@ -75,6 +78,7 @@ public PsiFile generate(final String actionName) { } final int insertPos = positionUtil.getRootInsertPosition((XmlFile) diXmlFile); + if (textBuf.length() > 0 && insertPos >= 0) { final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); @@ -89,14 +93,22 @@ public PsiFile generate(final String actionName) { return diXmlFile; } - private boolean getTypeAttributeValue(final XmlFile diXml) { + /** + * Check if type attribute has value. + * + * @param diXml XmlFile + * + * @return boolean + */ + private boolean hasTypeAttributeValue(final XmlFile diXml) { final Collection preferences = XmlPsiTreeUtil .findAttributeValueElements( diXml, ModuleDiXml.PREFERENCE_TAG_NAME, ModuleDiXml.PREFERENCE_ATTR_FOR ); - final String fqn = preferenceDiXmFileData.getTargetClass().getPresentableFQN(); + final String fqn = data.getPreferenceFor(); + for (final XmlAttributeValue preference: preferences) { if (PhpLangUtil.toPresentableFQN(preference.getValue()).equals(fqn)) { return true; @@ -106,10 +118,14 @@ private boolean getTypeAttributeValue(final XmlFile diXml) { return false; } + /** + * Fill preference xml attributes. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("FOR", preferenceDiXmFileData.getTargetClass() - .getPresentableFQN()); - attributes.setProperty("TYPE", preferenceDiXmFileData.getPreferenceFqn()); + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("FOR", data.getPreferenceFor()); + attributes.setProperty("TYPE", data.getPreferenceType()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java new file mode 100644 index 000000000..1fd09ef21 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java @@ -0,0 +1,147 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.Properties; +import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; + +public class QueryGenerator extends FileGenerator { + + private final UiComponentDataProviderData data; + private final Project project; + private final DirectoryGenerator directoryGenerator; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + private final String moduleName; + private final GetFirstClassOfFile getFirstClassOfFile; + private final UiComponentDataProviderFile file; + + /** + * Ui component grid data provider constructor. + * + * @param data UiComponentGridDataProviderData + * @param moduleName String + * @param project Project + */ + public QueryGenerator( + final UiComponentDataProviderData data, + final String moduleName, + final Project project + ) { + super(project); + this.data = data; + this.directoryGenerator = DirectoryGenerator.getInstance(); + this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); + this.project = project; + this.moduleName = moduleName; + file = new UiComponentDataProviderFile(moduleName, data.getName(), data.getPath()); + } + + @Override + public PsiFile generate(final @NotNull String actionName) { + final PsiFile[] dataProviderFiles = new PsiFile[1]; + + WriteCommandAction.runWriteCommandAction(project, () -> { + PhpClass dataProvider = GetPhpClassByFQN.getInstance(project).execute( + file.getClassFqn() + ); + + if (dataProvider != null) { + final String errorMessage = this.validatorBundle.message( + "validator.file.alreadyExists", + "DataProvider Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + + return; + } + + dataProvider = createDataProviderClass(actionName); + + if (dataProvider == null) { + final String errorMessage = this.validatorBundle.message( + "validator.file.cantBeCreated", + "DataProvider Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + + return; + } + + dataProviderFiles[0] = dataProvider.getContainingFile(); + }); + + return dataProviderFiles[0]; + } + + /** + * Create data provider file. + * + * @param actionName String + * + * @return PhpClass + */ + private PhpClass createDataProviderClass(final @NotNull String actionName) { + final PsiDirectory parentDirectory = new ModuleIndex(project) + .getModuleDirectoryByModuleName(this.moduleName); + final PsiDirectory dataProviderDirectory = + directoryGenerator.findOrCreateSubdirectories(parentDirectory, data.getPath()); + + final PsiFile dataProviderFile = fileFromTemplateGenerator.generate( + new UiComponentDataProviderFile(moduleName, data.getName(), data.getPath()), + getAttributes(), + dataProviderDirectory, + actionName + ); + + if (dataProviderFile == null) { + return null; + } + + return getFirstClassOfFile.execute((PhpFile) dataProviderFile); + } + + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", file.getNamespace()); + attributes.setProperty("CLASS_NAME", data.getName()); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java new file mode 100644 index 000000000..7cd7a0506 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -0,0 +1,117 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.google.common.base.CaseFormat; +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; +import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; +import com.magento.idea.magento2plugin.magento.packages.code.ExceptionType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandGenerator extends PhpFileGenerator { + + private final SaveEntityCommandData data; + + /** + * Save entity command generator constructor. + * + * @param data SaveEntityCommandData + * @param project Project + */ + public SaveEntityCommandGenerator( + final @NotNull SaveEntityCommandData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Save entity command generator constructor. + * + * @param data SaveEntityCommandData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SaveEntityCommandGenerator( + final @NotNull SaveEntityCommandData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new SaveEntityCommandFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill save command file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME) + .append("EXCEPTION", "Exception") + .append("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()) + .append("COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getType()) + .append("LOGGER", FrameworkLibraryType.LOGGER.getType()); + + final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName()); + final ResourceModelFile resourceModelFile = + new ResourceModelFile(data.getModuleName(), data.getResourceModelName()); + + final String modelType = modelFile.getClassFqn(); + final String modelFactoryType = modelType.concat("Factory"); + final String resourceType = resourceModelFile.getClassFqn(); + + if (data.isDtoWithInterface()) { + final DataModelInterfaceFile dataModelInterfaceFile = + new DataModelInterfaceFile(data.getModuleName(), data.getDtoInterfaceName()); + final String dtoType = dataModelInterfaceFile.getClassFqn(); + phpClassTypesBuilder.append("DTO", dtoType); + } else { + final DataModelFile dataModelFile = + new DataModelFile(data.getModuleName(), data.getDtoName()); + final String dtoType = dataModelFile.getClassFqn(); + phpClassTypesBuilder.append("DTO", dtoType); + } + + final String dtoProperty = CaseFormat.UPPER_CAMEL.to( + CaseFormat.LOWER_CAMEL, data.getEntityName() + ); + + phpClassTypesBuilder + .appendProperty("DTO_PROPERTY", dtoProperty) + .append("MODEL", modelType) + .append("MODEL_FACTORY", modelFactoryType) + .append("RESOURCE", resourceType); + + phpClassTypesBuilder.mergeProperties(attributes); + + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java new file mode 100644 index 000000000..5acd1477a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java @@ -0,0 +1,108 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; +import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; +import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityControllerFileGenerator extends PhpFileGenerator { + + private final SaveEntityControllerFileData data; + + /** + * Save Entity Controller File Generator. + * + * @param data SaveEntityControllerFileData + * @param project Project + */ + public SaveEntityControllerFileGenerator( + final @NotNull SaveEntityControllerFileData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Save Entity Controller File Generator. + * + * @param data SaveEntityControllerFileData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SaveEntityControllerFileGenerator( + final @NotNull SaveEntityControllerFileData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new SaveActionFile(data.getModuleName(), data.getEntityName()); + } + + /** + * Fill save action file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + String dtoType; + + if (data.isDtoWithInterface()) { + final DataModelInterfaceFile dataModelInterfaceFile = + new DataModelInterfaceFile(data.getModuleName(), data.getDtoInterfaceName()); + dtoType = dataModelInterfaceFile.getClassFqn(); + } else { + final DataModelFile dataModelFile = + new DataModelFile(data.getModuleName(), data.getDtoName()); + dtoType = dataModelFile.getClassFqn(); + } + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", SaveActionFile.CLASS_NAME) + .appendProperty("ENTITY_ID", data.getEntityId()) + .appendProperty("ADMIN_RESOURCE", data.getAcl()) + .append("IMPLEMENTS", HttpMethod.POST.getInterfaceFqn()) + .append("DATA_PERSISTOR", FrameworkLibraryType.DATA_PERSISTOR.getType()) + .append("EXTENDS", BackendModuleType.EXTENDS.getType()) + .append("ENTITY_DTO", dtoType) + .append("ENTITY_DTO_FACTORY", dtoType.concat("Factory")) + .append("SAVE_COMMAND", + new SaveEntityCommandFile( + data.getModuleName(), + data.getEntityName() + ).getClassFqn() + ) + .append("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()) + .append("COULD_NOT_SAVE", SaveActionFile.COULD_NOT_SAVE) + .append("CONTEXT", BackendModuleType.CONTEXT.getType()) + .append("RESPONSE_INTERFACE", FrameworkLibraryType.RESPONSE_INTERFACE.getType()) + .append("RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()) + .mergeProperties(attributes); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java index e7f46016c..d400439cb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java @@ -5,151 +5,96 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.queries.GetListQueryFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import java.util.Properties; -import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; -@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.DataflowAnomalyAnalysis"}) -public class UiComponentDataProviderGenerator extends FileGenerator { - private final UiComponentDataProviderData uiComponentGridDataProviderData; - private final Project project; - private final DirectoryGenerator directoryGenerator; - private final FileFromTemplateGenerator fileFromTemplateGenerator; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; +public class UiComponentDataProviderGenerator extends PhpFileGenerator { + + private final UiComponentDataProviderData data; private final String moduleName; - private final GetFirstClassOfFile getFirstClassOfFile; /** * Ui component grid data provider constructor. * - * @param uiComponentGridDataProviderData UiComponentGridDataProviderData + * @param data UiComponentGridDataProviderData * @param moduleName String * @param project Project */ public UiComponentDataProviderGenerator( - final UiComponentDataProviderData uiComponentGridDataProviderData, - final String moduleName, - final Project project + final @NotNull UiComponentDataProviderData data, + final @NotNull String moduleName, + final @NotNull Project project ) { - super(project); + this(data, moduleName, project, true); + } - this.uiComponentGridDataProviderData = uiComponentGridDataProviderData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - this.project = project; + /** + * Ui component grid data provider constructor. + * + * @param data UiComponentGridDataProviderData + * @param moduleName String + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public UiComponentDataProviderGenerator( + final @NotNull UiComponentDataProviderData data, + final @NotNull String moduleName, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; this.moduleName = moduleName; } @Override - public PsiFile generate(final String actionName) { - final PsiFile[] dataProviderFiles = new PsiFile[1]; - - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass dataProvider = GetPhpClassByFQN.getInstance(project).execute( - getDataProviderFqn() - ); - - if (dataProvider != null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.alreadyExists", - "DataProvider Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - dataProvider = createDataProviderClass(actionName); - - if (dataProvider == null) { - final String errorMessage = this.validatorBundle.message( - "validator.file.cantBeCreated", - "DataProvider Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - dataProviderFiles[0] = dataProvider.getContainingFile(); - }); - - return dataProviderFiles[0]; + protected AbstractPhpFile initFile() { + return new UiComponentDataProviderFile(moduleName, data.getName(), data.getPath()); } + /** + * Fill file property attributes. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAMESPACE", uiComponentGridDataProviderData.getNamespace()); - attributes.setProperty("CLASS_NAME", uiComponentGridDataProviderData.getName()); - } - - private PhpClass createDataProviderClass(final String actionName) { - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(this.moduleName); - final PsiFile dataProviderFile; - final String[] dataProviderDirectories = uiComponentGridDataProviderData.getPath().split( - File.separator - ); - for (final String dataProviderDirectory: dataProviderDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, dataProviderDirectory - ); + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace()) + .appendProperty("CLASS_NAME", data.getName()) + .appendProperty("HAS_GET_LIST_QUERY", "false") + .append("EXTENDS", UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER); + + if (data.getEntityIdFieldName() != null && data.getEntityName() != null) { + phpClassTypesBuilder.appendProperty("ENTITY_ID", data.getEntityIdFieldName()); + + phpClassTypesBuilder + .appendProperty("HAS_GET_LIST_QUERY", "true") + .append( + "GET_LIST_QUERY_TYPE", + new GetListQueryFile(moduleName, data.getEntityName()).getClassFqn() + ) + .append("REPORTING_TYPE", FrameworkLibraryType.REPORTING.getType()) + .append("SEARCH_CRITERIA_BUILDER", + FrameworkLibraryType.API_SEARCH_CRITERIA_BUILDER.getType()) + .append("REQUEST_TYPE", FrameworkLibraryType.REQUEST.getType()) + .append("FILTER_BUILDER", FrameworkLibraryType.FILTER_BUILDER.getType()) + .append("SEARCH_RESULT_FACTORY", + UiComponentDataProviderFile.SEARCH_RESULT_FACTORY); } + phpClassTypesBuilder.mergeProperties(attributes); - final Properties attributes = getAttributes(); - - dataProviderFile = fileFromTemplateGenerator.generate( - UiComponentDataProviderPhp.getInstance( - uiComponentGridDataProviderData.getName() - ), - attributes, - parentDirectory, - actionName - ); - - if (dataProviderFile == null) { - return null; - } - - return getFirstClassOfFile.execute((PhpFile) dataProviderFile); - } - - private String getDataProviderFqn() { - return String.format( - "%s%s%s", - uiComponentGridDataProviderData.getNamespace(), - Package.fqnSeparator, - uiComponentGridDataProviderData.getName() - ); + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java new file mode 100644 index 000000000..c525eef15 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java @@ -0,0 +1,192 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.FormButtonBlockFile; +import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; +import com.magento.idea.magento2plugin.magento.packages.UiFormButtonTypeSettings; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; +import org.bouncycastle.util.Strings; +import org.jetbrains.annotations.NotNull; + +public class UiComponentFormButtonBlockGenerator extends FileGenerator { + + private final UiComponentFormButtonData buttonData; + private final Project project; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + private final List uses; + private final String entityName; + private final String entityIdField; + + /** + * Ui Form button by its type generator constructor. + * + * @param buttonData UiComponentFormButtonData + * @param project Project + */ + public UiComponentFormButtonBlockGenerator( + final @NotNull UiComponentFormButtonData buttonData, + final @NotNull Project project + ) { + this(buttonData, project, "Entity", "entity_id", true); + } + + /** + * Ui Form button by its type generator constructor. + * + * @param buttonData UiComponentFormButtonData + * @param project Project + * @param entityName String + * @param entityIdField String + */ + public UiComponentFormButtonBlockGenerator( + final @NotNull UiComponentFormButtonData buttonData, + final @NotNull Project project, + final @NotNull String entityName, + final @NotNull String entityIdField + ) { + this(buttonData, project, entityName, entityIdField, true); + } + + /** + * Ui Form button by its type generator constructor. + * + * @param buttonData UiComponentFormButtonData + * @param project Project + * @param entityName String + * @param entityIdField String + * @param checkFileAlreadyExists boolean + */ + public UiComponentFormButtonBlockGenerator( + final @NotNull UiComponentFormButtonData buttonData, + final @NotNull Project project, + final @NotNull String entityName, + final @NotNull String entityIdField, + final boolean checkFileAlreadyExists + ) { + super(project); + this.buttonData = buttonData; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + this.entityName = entityName; + this.entityIdField = entityIdField; + fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = new ModuleIndex(project); + uses = new ArrayList<>(); + } + + /** + * Creates a module UI form button file. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass buttonClass = GetPhpClassByFQN.getInstance(project).execute( + buttonData.getFqn() + ); + + if (this.checkFileAlreadyExists && buttonClass != null) { + return buttonClass.getContainingFile(); + } + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + buttonData.getButtonModule() + ); + final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + buttonData.getButtonDirectory() + ); + + return fileFromTemplateGenerator.generate( + new FormButtonBlockFile( + buttonData.getButtonModule(), + buttonData.getButtonClassName(), + buttonData.getButtonDirectory() + ), + getAttributes(), + baseDirectory, + actionName + ); + } + + /** + * Fill save command file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAME", buttonData.getButtonClassName()); + attributes.setProperty("NAMESPACE", buttonData.getNamespace()); + attributes.setProperty("DATA_PROVIDER_TYPE", + PhpClassGeneratorUtil.getNameFromFqn(FormButtonBlockFile.DATA_PROVIDER_TYPE)); + uses.add(FormButtonBlockFile.DATA_PROVIDER_TYPE); + + final FormGenericButtonBlockFile genericButtonBlockFile = + new FormGenericButtonBlockFile(buttonData.getButtonModule(), entityName); + + final NamespaceBuilder genericBtnNamespace = new NamespaceBuilder( + buttonData.getButtonModule(), + FormGenericButtonBlockFile.CLASS_NAME, + genericButtonBlockFile.getDirectory() + ); + attributes.setProperty("GENERIC_BUTTON", + PhpClassGeneratorUtil.getNameFromFqn(genericBtnNamespace.getClassFqn())); + + if (!genericButtonBlockFile.getDirectory().equals(buttonData.getButtonDirectory())) { + uses.add(genericBtnNamespace.getClassFqn()); + } + + final UiFormButtonTypeSettings buttonTypeSettings = UiFormButtonTypeSettings.getByValue( + Strings.toUpperCase(buttonData.getButtonType()) + ); + attributes.setProperty("CLASS_ANNOTATION", buttonTypeSettings.getAnnotation()); + attributes.setProperty("TYPE", buttonTypeSettings.getLabel()); + attributes.setProperty("LABEL", buttonTypeSettings.getLabel()); + attributes.setProperty("CLASS", buttonTypeSettings.getClasses()); + + final String entityIdAccessor = "get" + Arrays.stream(entityIdField.split("_")) + .map(s -> s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1)) + .collect(Collectors.joining()) + "()"; + + final Map variables = new HashMap<>(); + variables.put("$varName", Strings.toLowerCase(entityName)); + variables.put("$varId", entityIdField); + variables.put("$varEntityIdAccessor", entityIdAccessor); + + attributes.setProperty("ON_CLICK", buttonTypeSettings.getOnClick(variables)); + attributes.setProperty("DATA_ATTRS", buttonTypeSettings.getDataAttrs(variables)); + attributes.setProperty("SORT_ORDER", String.valueOf(buttonTypeSettings.getSortOrder())); + attributes.setProperty("ENTITY_NAME", Strings.toLowerCase(entityName)); + attributes.setProperty("ENTITY_ID", entityIdField); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonPhpClassGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonPhpClassGenerator.java deleted file mode 100644 index 9fbc04109..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonPhpClassGenerator.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; -import com.magento.idea.magento2plugin.actions.generation.generator.code.ButtonMethodGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.FormButtonBlockPhp; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; -import java.util.Properties; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class UiComponentFormButtonPhpClassGenerator extends FileGenerator { - private final UiComponentFormButtonData buttonData; - private final Project project; - private final GetFirstClassOfFile getFirstClassOfFile; - - /** - * Constructor. - * - * @param buttonData UiComponentFormButtonData - * @param project Project - */ - public UiComponentFormButtonPhpClassGenerator( - final @NotNull UiComponentFormButtonData buttonData, - final Project project - ) { - super(project); - this.buttonData = buttonData; - this.project = project; - this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); - } - - /** - * Creates a module UI form file. - * - * @param actionName String - * @return PsiFile - */ - @Override - public PsiFile generate(final String actionName) { - final PsiFile[] buttonClassFile = {null}; - final PhpClass buttonClass = createButton(actionName); - new ButtonMethodGenerator(buttonData, project).generate(buttonClassFile, buttonClass); - - return buttonClass.getContainingFile(); - } - - /** - * Finds or Button PHP class. - * - * @param actionName String - * @return PhpClass - */ - protected PhpClass createButton( - final String actionName - ) { - final DirectoryGenerator directoryGenerator = DirectoryGenerator.getInstance(); - final FileFromTemplateGenerator fileFromTemplateGenerator = - new FileFromTemplateGenerator(project); - - final String moduleName = buttonData.getButtonModule(); - PsiDirectory parentDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(moduleName); - final String[] directories = buttonData.getButtonDirectory().split(File.separator); - for (final String pluginDirectory: directories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, - pluginDirectory - ); - } - - @Nullable final PsiFile buttonFile = fileFromTemplateGenerator.generate( - new FormButtonBlockPhp(buttonData.getButtonClassName()), - getAttributes(), - parentDirectory, - actionName - ); - return getFirstClassOfFile.execute((PhpFile) buttonFile); - } - - @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", buttonData.getButtonClassName()); - attributes.setProperty("NAMESPACE", buttonData.getNamespace()); - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java index 03c104c83..5a5d3e5cb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java @@ -14,32 +14,37 @@ import com.magento.idea.magento2plugin.actions.generation.generator.code.XmlDeclarationsGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.UiComponentFormXml; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentFormXmlFile; import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil; import java.util.ArrayList; import java.util.Locale; import java.util.Properties; +import java.util.stream.Collectors; import org.jetbrains.annotations.NotNull; public class UiComponentFormGenerator extends FileGenerator { - private final UiComponentFormFileData uiFormFileData; + + private final UiComponentFormFileData data; private final Project project; /** - * Constructor. + * Ui Component form generator constructor. * - * @param uiFormFileData UiFormFileData + * @param data UiFormFileData * @param project Project */ public UiComponentFormGenerator( - final @NotNull UiComponentFormFileData uiFormFileData, + final @NotNull UiComponentFormFileData data, final Project project ) { super(project); - this.uiFormFileData = uiFormFileData; + this.data = data; this.project = project; } @@ -47,6 +52,7 @@ public UiComponentFormGenerator( * Creates a module UI form file. * * @param actionName String + * * @return PsiFile */ @Override @@ -54,17 +60,24 @@ public PsiFile generate(final String actionName) { final PsiFile formFile = createForm( actionName ); - - createButtonClasses(actionName); + generateButtonClasses(actionName); return formFile; } - protected void createButtonClasses(final String actionName) { - for (final UiComponentFormButtonData buttonData: uiFormFileData.getButtons()) { - new UiComponentFormButtonPhpClassGenerator(//NOPMD - buttonData, - project + /** + * Generate buttons classes. + * + * @param actionName String + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + protected void generateButtonClasses(final @NotNull String actionName) { + for (final UiComponentFormButtonData buttonData : data.getButtons()) { + new UiComponentFormButtonBlockGenerator( + buttonData, + project, + data.getEntityName(), + data.getEntityId() ).generate(actionName); } } @@ -73,6 +86,7 @@ protected void createButtonClasses(final String actionName) { * Finds or creates form. * * @param actionName String + * * @return PsiFile */ protected PsiFile createForm( @@ -82,59 +96,85 @@ protected PsiFile createForm( final FileFromTemplateGenerator fileFromTemplateGenerator = new FileFromTemplateGenerator(project); - final String moduleName = uiFormFileData.getModuleName(); - PsiDirectory parentDirectory = new ModuleIndex(project) + final String moduleName = data.getModuleName(); + final PsiDirectory parentDirectory = new ModuleIndex(project) .getModuleDirectoryByModuleName(moduleName); + final ArrayList fileDirectories = new ArrayList<>(); fileDirectories.add(Package.moduleViewDir); - final String area = uiFormFileData.getFormArea(); + final String area = data.getFormArea(); fileDirectories.add(getArea(area).toString()); fileDirectories.add(Package.moduleViewUiComponentDir); - for (final String fileDirectory: fileDirectories) { - parentDirectory = directoryGenerator - .findOrCreateSubdirectory(parentDirectory, fileDirectory); - } - final String formName = uiFormFileData.getFormName(); - final UiComponentFormXml uiComponentFormXml = new UiComponentFormXml(formName); - XmlFile formFile = (XmlFile) FileBasedIndexUtil.findModuleConfigFile( + + final PsiDirectory formDirectory = + directoryGenerator.findOrCreateSubdirectories( + parentDirectory, + fileDirectories.stream().collect(Collectors.joining(File.separator)) + ); + + final String formName = data.getFormName(); + final UiComponentFormXmlFile uiComponentFormXml = new UiComponentFormXmlFile(formName); + XmlFile formFile = (XmlFile) FileBasedIndexUtil.findModuleViewFile( uiComponentFormXml.getFileName(), getArea(area), - formName, - project + moduleName, + project, + Package.moduleViewUiComponentDir ); + if (formFile == null) { formFile = (XmlFile) fileFromTemplateGenerator.generate( uiComponentFormXml, getAttributes(), - parentDirectory, + formDirectory, actionName ); } - new XmlDeclarationsGenerator(uiFormFileData, project).generate(formFile); + if (formFile != null) { + new XmlDeclarationsGenerator(data, project).generate(formFile); + } return formFile; } + /** + * Fill ui component form properties. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", uiFormFileData.getFormName()); - attributes.setProperty("LABEL", uiFormFileData.getLabel()); - attributes.setProperty("BUTTONS", uiFormFileData.getButtons().isEmpty() ? "" : "true"); - attributes.setProperty("ROUTE", uiFormFileData.getRoute()); - attributes.setProperty( - "SUBMIT_CONTROLLER", - uiFormFileData.getSubmitControllerName().toLowerCase(new Locale("en","EN")) - ); - attributes.setProperty( - "SUBMIT_ACTION", - uiFormFileData.getSubmitActionName().toLowerCase(new Locale("en","EN")) - ); - attributes.setProperty("DATA_PROVIDER", uiFormFileData.getDataProviderFqn()); - attributes.setProperty("PRIMARY_FIELD", uiFormFileData.getFields().get(0).getName()); + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAME", data.getFormName()) + .appendProperty("LABEL", data.getLabel()) + .appendProperty("BUTTONS", data.getButtons().isEmpty() ? "" : "true") + .appendProperty("ROUTE", data.getRoute()) + .appendProperty("SUBMIT_CONTROLLER", + data.getSubmitControllerName().toLowerCase(new Locale("en","EN"))) + .appendProperty("SUBMIT_ACTION", + data.getSubmitActionName().toLowerCase(new Locale("en","EN"))) + .appendProperty("DATA_PROVIDER", + new UiComponentDataProviderFile( + data.getModuleName(), + data.getDataProviderName(), + data.getDataProviderPath() + ).getClassFqn() + ) + .appendProperty("PRIMARY_FIELD", data.getFields().get(0).getName()) + .mergeProperties(attributes); } - private Areas getArea(final String area) { + /** + * Get Area Enum by its name. + * + * @param area String + * + * @return Areas + */ + private Areas getArea(final @NotNull String area) { return Areas.getAreaByString(area); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java index 5fb9b2bb9..ef457393d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java @@ -8,102 +8,259 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; +import com.intellij.psi.xml.XmlFile; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData; import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.GetCodeTemplateUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.UiComponentGridXml; -import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentGridXmlFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; +import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; +import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Properties; +import java.util.stream.Collectors; +import org.jetbrains.annotations.NotNull; public class UiComponentGridXmlGenerator extends FileGenerator { + public static final String TRUE = "true"; - private final UiComponentGridData uiComponentGridData; + private final UiComponentGridData data; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final GetCodeTemplateUtil getCodeTemplateUtil; /** * UI component grid XML generator constructor. * - * @param uiComponentGridData UiComponentGridData + * @param data UiComponentGridData * @param project Project */ public UiComponentGridXmlGenerator( - final UiComponentGridData uiComponentGridData, + final UiComponentGridData data, final Project project ) { super(project); - - this.uiComponentGridData = uiComponentGridData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.moduleIndex = new ModuleIndex(project); - this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + this.data = data; + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = new ModuleIndex(project); + fileFromTemplateGenerator = new FileFromTemplateGenerator(project); + getCodeTemplateUtil = new GetCodeTemplateUtil(project); } @Override public PsiFile generate(final String actionName) { - final String moduleName = this.uiComponentGridData.getModuleName(); - PsiDirectory uiComponentDirectory = this.moduleIndex.getModuleDirectoryByModuleName( + final String moduleName = data.getModuleName(); + final PsiDirectory parentDirectory = moduleIndex.getModuleDirectoryByModuleName( moduleName ); final String subdirectory = String.format( "%s/%s/%s", Package.moduleViewDir, - this.uiComponentGridData.getArea(), + this.data.getArea(), Package.moduleViewUiComponentDir ); + final PsiDirectory uiComponentDirectory = + directoryGenerator.findOrCreateSubdirectories(parentDirectory, subdirectory); - for (final String directory: subdirectory.split(File.separator)) { - uiComponentDirectory = directoryGenerator.findOrCreateSubdirectory( + final UiComponentGridXmlFile file = new UiComponentGridXmlFile(data.getName()); + + XmlFile gridXmlFile = (XmlFile) FileBasedIndexUtil.findModuleViewFile( + file.getFileName(), + Areas.getAreaByString(data.getArea()), + moduleName, + project, + Package.moduleViewUiComponentDir + ); + + if (gridXmlFile == null) { + gridXmlFile = (XmlFile) fileFromTemplateGenerator.generate( + new UiComponentGridXmlFile(data.getName()), + getAttributes(), uiComponentDirectory, - directory + actionName ); } - final UiComponentGridXml uiGridXml = new UiComponentGridXml(uiComponentGridData.getName()); - - return this.fileFromTemplateGenerator.generate( - uiGridXml, - getAttributes(), - uiComponentDirectory, - actionName - ); + return gridXmlFile; } + /** + * Fill UI Component grid xml file attributes. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", uiComponentGridData.getName()); - attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName()); - attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName()); - attributes.setProperty("PROVIDER_CLASS", uiComponentGridData.getProviderClassName()); - attributes.setProperty("ACL", uiComponentGridData.getAcl()); - final UiComponentGridToolbarData toolbarData = uiComponentGridData.getGridToolbarData(); + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final String dataProviderClassName = + new UiComponentDataProviderFile( + data.getModuleName(), + data.getDataProviderName(), + data.getDataProviderPath() + ).getClassFqn(); + + phpClassTypesBuilder + .appendProperty("NAME", data.getName()) + .appendProperty("ID_FIELD_NAME", data.getIdFieldName()) + .appendProperty("PROVIDER_CLASS", dataProviderClassName) + .appendProperty("ACL", data.getAcl()); + + final UiComponentGridToolbarData toolbarData = data.getGridToolbarData(); if (toolbarData.isAddToolbar()) { - attributes.setProperty("TOOLBAR", TRUE); + phpClassTypesBuilder.appendProperty("TOOLBAR", TRUE); if (toolbarData.isAddBookmarks()) { - attributes.setProperty("BOOKMARKS", TRUE); + phpClassTypesBuilder.appendProperty("BOOKMARKS", TRUE); } if (toolbarData.isAddColumnsControls()) { - attributes.setProperty("COLUMNS_CONTROLS", TRUE); + phpClassTypesBuilder.appendProperty("COLUMNS_CONTROLS", TRUE); } if (toolbarData.isAddFulltextSearch()) { - attributes.setProperty("FULLTEXT_SEARCH", TRUE); + phpClassTypesBuilder.appendProperty("FULLTEXT_SEARCH", TRUE); } if (toolbarData.isAddListingFilters()) { - attributes.setProperty("LISTING_FILTERS", TRUE); + phpClassTypesBuilder.appendProperty("LISTING_FILTERS", TRUE); } if (toolbarData.isAddListingPaging()) { - attributes.setProperty("LISTING_PAGING", TRUE); + phpClassTypesBuilder.appendProperty("LISTING_PAGING", TRUE); } } + phpClassTypesBuilder.mergeProperties(attributes); + + prepareColumnsProperties(attributes); + } + + /** + * Prepare columns properties. + * + * @param attributes Properties + */ + private void prepareColumnsProperties(final @NotNull Properties attributes) { + final List> columnsProperties = data.getColumns(); + final List columnsTextList = new LinkedList<>(); + + for (final Map columnProperties : columnsProperties) { + final String columnName = columnProperties.get(ColumnAttributes.NAME.getName()); + + if (columnName.equals(data.getIdFieldName())) { + continue; + } + + final String columnLabel = Arrays.stream( + columnName.replaceAll("_", " ").split(" ") + ).map( + s -> s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1) + ).collect(Collectors.joining(" ")); + + final TableColumnTypes columnType = + TableColumnTypes.getByValue( + columnProperties.get(ColumnAttributes.TYPE.getName()) + ); + + String columnFilter; + + if (columnType == null) { + columnFilter = "text"; + } else { + columnFilter = mapColumnTypeToFilterType(columnType); + } + + try { + columnsTextList.add( + getCodeTemplateUtil.execute( + UiComponentGridXmlFile.COLUMN_TEMPLATE, + fillColumnCodeTemplateAttributes( + columnName, + columnLabel, + columnFilter + ) + ).trim() + ); + } catch (IOException exception) { + return; + } + } + + if (!columnsTextList.isEmpty()) { + attributes.setProperty("COLUMNS", String.join("\n", columnsTextList)); + } + + if (data.getEntityName() != null) { + final GridActionColumnFile gridActionColumnFile = + new GridActionColumnFile(data.getModuleName(), data.getEntityName()); + attributes.setProperty("ACTION_COLUMN", gridActionColumnFile.getClassFqn()); + } + } + + /** + * Fill column code template attributes. + * + * @param name String + * @param label String + * @param filter String + * + * @return Properties + */ + private Properties fillColumnCodeTemplateAttributes( + final @NotNull String name, + final @NotNull String label, + final @NotNull String filter + + ) { + final Properties properties = new Properties(); + + properties.setProperty("COLUMN_NAME", name); + properties.setProperty("COLUMN_LABEL", label); + properties.setProperty("COLUMN_FILTER", filter); + + return properties; + } + + /** + * Map column type to filter UI Component type. + * + * @param type TableColumnTypes + * + * @return String + */ + @SuppressWarnings("PMD.CyclomaticComplexity") + private @NotNull String mapColumnTypeToFilterType(final @NotNull TableColumnTypes type) { + switch (type) { + case BOOLEAN: + return "select"; + case DATE: + return "dateRange"; + case DATETIME: + return "datetimeRange"; + case INT: + case BIGINT: + case TINYINT: + case SMALLINT: + case DECIMAL: + case DOUBLE: + case FLOAT: + return "textRange"; + default: + return "text"; + } } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/code/ButtonMethodGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/code/ButtonMethodGenerator.java deleted file mode 100644 index 8b06d7928..000000000 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/code/ButtonMethodGenerator.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.actions.generation.generator.code; - -import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.util.PsiTreeUtil; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.elements.GroupStatement; -import com.jetbrains.php.lang.psi.elements.Method; -import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; -import com.magento.idea.magento2plugin.actions.generation.generator.util.GetCodeTemplateUtil; -import com.magento.idea.magento2plugin.actions.generation.util.CodeStyleSettings; -import com.magento.idea.magento2plugin.bundles.CommonBundle; -import com.magento.idea.magento2plugin.bundles.ValidatorBundle; -import com.magento.idea.magento2plugin.magento.files.FormButtonBlockPhp; -import com.magento.idea.magento2plugin.magento.packages.MagentoPhpClass; -import com.magento.idea.magento2plugin.util.CamelCaseToHyphen; -import java.io.IOException; -import java.util.Properties; -import javax.swing.JOptionPane; -import org.jetbrains.annotations.NotNull; - -public class ButtonMethodGenerator { - - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; - private final GetCodeTemplateUtil getCodeTemplateUtil; - private final UiComponentFormButtonData buttonData; - private final Project project; - - /** - * Constructor. - * - * @param buttonData UiComponentFormButtonData - * @param project Project - */ - public ButtonMethodGenerator( - final @NotNull UiComponentFormButtonData buttonData, - final Project project - ) { - this.buttonData = buttonData; - this.project = project; - this.validatorBundle = new ValidatorBundle(); - this.commonBundle = new CommonBundle(); - this.getCodeTemplateUtil = new GetCodeTemplateUtil(project); - } - - /** - * Injects method to the button block class. - * - * @param buttonClassFile PsiFile[] - * @param buttonClass PhpClass - */ - public void generate(PsiFile[] buttonClassFile, final PhpClass buttonClass) { - final String template = getMethodTemplateByButtonType(buttonData.getButtonType()); - if (template.isEmpty()) { - return; - } - WriteCommandAction.runWriteCommandAction(project, () -> { - if (buttonClass == null) { - final String errorTitle = commonBundle.message("common.error"); - final String errorMessage = validatorBundle.message( - "validator.file.cantBeCreated", - "Plugin Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - errorTitle, - JOptionPane.ERROR_MESSAGE - ); - - return; - } - - final StringBuffer textBuf = new StringBuffer(); - try { - textBuf.append(getCodeTemplateUtil.execute( - template, - fillCodeTemplateAttributes() - ) - ); - } catch (IOException e) { - return; - } - - buttonClassFile[0] = buttonClass.getContainingFile(); - final CodeStyleSettings codeStyleSettings = new CodeStyleSettings( - (PhpFile) buttonClassFile[0] - ); - codeStyleSettings.adjustBeforeWrite(); - - final int insertPos = getInsertPos(buttonClass); - if (textBuf.length() > 0 && insertPos >= 0) { - final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance( - project - ); - final Document document = psiDocumentManager.getDocument(buttonClassFile[0]); - document.insertString(insertPos, textBuf); - final int endPos = insertPos + textBuf.length() + 1; - CodeStyleManager.getInstance(project).reformatText( - buttonClassFile[0], - insertPos, - endPos - ); - psiDocumentManager.commitDocument(document); - } - codeStyleSettings.restore(); - }); - } - - - protected Properties fillCodeTemplateAttributes() { - final Properties attributes = new Properties(); - attributes.setProperty("NAME", CamelCaseToHyphen.getInstance() - .convert(buttonData.getButtonClassName())); - attributes.setProperty("FQN", buttonData.getFqn()); - attributes.setProperty("BUTTON_SORT_ORDER", buttonData.getButtonSortOrder()); - attributes.setProperty("FORM_NAME", buttonData.getFormName()); - attributes.setProperty("BUTTON_LABEL", buttonData.getButtonLabel()); - return attributes; - } - - private int getInsertPos(final PhpClass phpClass) { - int insertPos = -1; - final Method[] phpMethods = PsiTreeUtil.getChildrenOfType(phpClass, Method.class); - for (final Method phpMethod: phpMethods) { - if (!phpMethod.getName().equals(FormButtonBlockPhp.DEFAULT_METHOD)) { - continue; - } - final GroupStatement[] groupStatements = PsiTreeUtil.getChildrenOfType( - phpMethod, - GroupStatement.class - ); - for (final GroupStatement groupStatement: groupStatements) { - final PsiElement[] elements = PsiTreeUtil.getChildrenOfType( - groupStatement, - PsiElement.class - ); - for (final PsiElement element: elements) { - if (!element.getText().equals(MagentoPhpClass.CLOSING_TAG)) { - continue; - } - insertPos = element.getTextOffset(); - } - } - } - - return insertPos; - } - - private String getMethodTemplateByButtonType(final String buttonType) { - String template; - switch (buttonType) { - case FormButtonBlockPhp.TYPE_SAVE: - template = FormButtonBlockPhp.saveMethodTemplate; - break; - case FormButtonBlockPhp.TYPE_BACK: - template = FormButtonBlockPhp.backMethodTemplate; - break; - case FormButtonBlockPhp.TYPE_DELETE: - template = FormButtonBlockPhp.deleteMethodTemplate; - break; - default: - template = ""; - break; - } - return template; - } -} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/code/XmlDeclarationsGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/code/XmlDeclarationsGenerator.java index 40854233d..b630f01eb 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/code/XmlDeclarationsGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/code/XmlDeclarationsGenerator.java @@ -11,7 +11,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldsetData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFileData; import com.magento.idea.magento2plugin.actions.generation.generator.util.GetCodeTemplateUtil; -import com.magento.idea.magento2plugin.magento.files.UiComponentFormXml; +import com.magento.idea.magento2plugin.magento.files.UiComponentFormXmlFile; import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; import java.io.IOException; import java.util.Properties; @@ -42,7 +42,7 @@ public XmlDeclarationsGenerator( * * @param formFile XmlFile */ - public void generate(final XmlFile formFile) { + public void generate(final @NotNull XmlFile formFile) { final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); final Document document = psiDocumentManager.getDocument(formFile); @@ -95,7 +95,7 @@ protected void renderFieldsets(final XmlTag rootTag) { } try { fieldsStringBuffer.append(getCodeTemplateUtil.execute( - UiComponentFormXml.FIELD_TEMPLATE, + UiComponentFormXmlFile.FIELD_TEMPLATE, fillAttributes(formFieldData) ) ); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java new file mode 100644 index 000000000..6004a57d5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java @@ -0,0 +1,114 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.FileGenerator; +import org.jetbrains.annotations.NotNull; + +public abstract class GeneratorHandler { + + private final GenerationContextData contextData; + private final DataObjectConverter dataObjectConverter; + private final GeneratorRunnerValidator runnerValidator; + private FileGenerator generator; + + /** + * Generator handler constructor. + * + * @param contextData Context + * @param dataObjectConverter DataObjectConverter + */ + public GeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Generator handler constructor. + * + * @param contextData Context + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public GeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + this.contextData = contextData; + this.dataObjectConverter = dataObjectConverter; + this.runnerValidator = runnerValidator; + } + + /** + * Override this method to add conditions for generation. + * + * @return boolean + */ + public boolean validate() { + if (runnerValidator != null) { + return runnerValidator.validate(); + } + return true; + } + + /** + * Instantiate and retrieve generator. + * Must be separated from generate method to test converter type casting. + */ + public abstract void instantiateGenerator(); + + /** + * Set generator. + * + * @param generator FileGenerator + */ + public void setGenerator(final FileGenerator generator) { + this.generator = generator; + } + + /** + * Run generator. + */ + public final void generate() { + generator.generate( + getContextData().getActionName(), + getContextData().checkIfHasOpenFileFlag() + ); + } + + /** + * Get project. + * + * @return Project + */ + protected Project getProject() { + return getContextData().getProject(); + } + + /** + * Get generation context DTO. + * + * @return GenerationContextData + */ + protected GenerationContextData getContextData() { + return contextData; + } + + /** + * Get data object converter. + * + * @return DataObjectConverter + */ + protected DataObjectConverter getDataObjectConverter() { + return dataObjectConverter; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java new file mode 100644 index 000000000..6bd0d6b4b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java @@ -0,0 +1,182 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool; + +import com.intellij.openapi.diagnostic.Logger; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.bundles.ExceptionBundle; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedList; +import java.util.List; +import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; + +public final class GeneratorPoolHandler { + + private static final Logger LOGGER = Logger.getInstance(GeneratorPoolHandler.class); + private final GenerationContextData contextData; + private final List pool; + private final ExceptionBundle exceptionBundle; + private final List errors; + + /** + * Generator pool handler constructor. + * + * @param contextData GenerationContextData + */ + public GeneratorPoolHandler(final @NotNull GenerationContextData contextData) { + this.contextData = contextData; + pool = new LinkedList<>(); + exceptionBundle = new ExceptionBundle(); + errors = new LinkedList<>(); + } + + /** + * Add next generation handler. + * + * @param next GeneratorHandler + * + * @return GeneratorPoolHandler + */ + public GeneratorPoolHandler addNext(final @NotNull GeneratorHandler next) { + pool.add(next); + return this; + } + + /** + * Add next generation handler by its type with provided data adapter. + * + * @param handlerClass Class + * @param dataObjectConverter DataObjectConverter + * + * @return GeneratorPoolHandler + */ + public GeneratorPoolHandler addNext( + final @NotNull Class handlerClass, + final @NotNull DataObjectConverter dataObjectConverter + ) { + return addNext(handlerClass, dataObjectConverter, null); + } + + /** + * Add next generation handler by its type with provided data adapter. + * + * @param handlerClass Class + * @param dataObjectConverter DataAdapter + * @param runnerValidator GeneratorRunnerValidator + * + * @return GeneratorPoolHandler + */ + public GeneratorPoolHandler addNext( + final @NotNull Class handlerClass, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + try { + if (runnerValidator == null) { + final Constructor handlerClassConstructor = handlerClass.getConstructor( + GenerationContextData.class, + DataObjectConverter.class + ); + pool.add(handlerClassConstructor + .newInstance(contextData, dataObjectConverter)); + } else { + final Constructor handlerClassConstructor = handlerClass.getConstructor( + GenerationContextData.class, + DataObjectConverter.class, + GeneratorRunnerValidator.class + ); + pool.add(handlerClassConstructor + .newInstance(contextData, dataObjectConverter, runnerValidator)); + } + } catch (InstantiationException | IllegalAccessException + | InvocationTargetException exception) { + LOGGER.error(exception.getMessage()); + errors.add(this.exceptionBundle.message( + "exception.reflection.cannotInstantiate", + handlerClass.getSimpleName() + )); + } catch (NoSuchMethodException noSuchMethodException) { + // This error can be caused if Handler class realization + // doesn't have constructor with all required arguments. + final String constructorDescWithTwoArgs = handlerClass.getSimpleName() + + " with arguments " + GenerationContextData.class.getSimpleName() + + ", " + DataObjectConverter.class.getSimpleName(); + final String constructorDescWithThreeArgs = handlerClass.getSimpleName() + + " with arguments " + GenerationContextData.class.getSimpleName() + ", " + + DataObjectConverter.class.getSimpleName() + ", " + + GeneratorRunnerValidator.class.getSimpleName(); + + LOGGER.error(noSuchMethodException.getMessage()); + errors.add(this.exceptionBundle.message( + "exception.NoSuchMethod", + runnerValidator == null ? constructorDescWithTwoArgs + : constructorDescWithThreeArgs, + handlerClass.getSimpleName() + )); + } + + return this; + } + + /** + * Trigger generation process. + */ + public void run() { + if (hasErrorMessages()) { + showErrorMessages(); + return; + } + for (final GeneratorHandler handler : pool) { + handler.instantiateGenerator(); + + if (handler.validate()) { + handler.generate(); + } + } + } + + /** + * Instantiate all generators. + */ + public void instantiateAllGenerators() { + for (final GeneratorHandler handler : pool) { + handler.instantiateGenerator(); + } + } + + /** + * Check if Generator Pool Handler has any error messages. + * + * @return boolean + */ + public boolean hasErrorMessages() { + return !errors.isEmpty(); + } + + /** + * Show error messages for the user. + */ + private void showErrorMessages() { + if (!errors.isEmpty()) { + final String title = this.exceptionBundle.message( + "exception.common.title" + ); + final String errorMessage = this.exceptionBundle.message( + "exception.common.informUs" + ); + + JOptionPane.showMessageDialog( + null, + errorMessage, + title, + JOptionPane.ERROR_MESSAGE + ); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorRunnerValidator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorRunnerValidator.java new file mode 100644 index 000000000..8fba4a3b1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorRunnerValidator.java @@ -0,0 +1,16 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool; + +public interface GeneratorRunnerValidator { + + /** + * Check if generator should be executed in the chain. + * + * @return boolean + */ + boolean validate(); +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/AclXmlGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/AclXmlGeneratorHandler.java new file mode 100644 index 000000000..65bc2ffea --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/AclXmlGeneratorHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class AclXmlGeneratorHandler extends GeneratorHandler { + + /** + * Acl XML file generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public AclXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Acl XML file generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public AclXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new AclXmlGenerator( + (AclXmlData) getDataObjectConverter(), + getContextData().getModuleName(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/CollectionModelGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/CollectionModelGeneratorHandler.java new file mode 100644 index 000000000..ecfbddbe0 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/CollectionModelGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class CollectionModelGeneratorHandler extends GeneratorHandler { + + /** + * Collection model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public CollectionModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Collection model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public CollectionModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new ModuleCollectionGenerator( + (CollectionData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelGeneratorHandler.java new file mode 100644 index 000000000..7ab55ff8f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DataModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DataModelGeneratorHandler extends GeneratorHandler { + + /** + * Data model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DataModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Data model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DataModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DataModelGenerator( + getProject(), + (DataModelData) getDataObjectConverter() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelInterfaceGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelInterfaceGeneratorHandler.java new file mode 100644 index 000000000..712a8a656 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelInterfaceGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DataModelInterfaceGeneratorHandler extends GeneratorHandler { + + /** + * Data model interface generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DataModelInterfaceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Data model interface generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DataModelInterfaceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DataModelInterfaceGenerator( + (DataModelInterfaceData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelPreferenceGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelPreferenceGeneratorHandler.java new file mode 100644 index 000000000..30ad3e70c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelPreferenceGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DataModelPreferenceGeneratorHandler extends GeneratorHandler { + + /** + * Data model preference generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DataModelPreferenceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Data model preference generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DataModelPreferenceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new PreferenceDiXmlGenerator( + (PreferenceDiXmFileData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataProviderGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataProviderGeneratorHandler.java new file mode 100644 index 000000000..66e0b04ba --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataProviderGeneratorHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DataProviderGeneratorHandler extends GeneratorHandler { + + /** + * Data provider generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DataProviderGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Data provider generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DataProviderGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new UiComponentDataProviderGenerator( + (UiComponentDataProviderData) getDataObjectConverter(), + getContextData().getModuleName(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaWhitelistGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaWhitelistGeneratorHandler.java new file mode 100644 index 000000000..b06f3300b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaWhitelistGeneratorHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DbSchemaWhitelistGeneratorHandler extends GeneratorHandler { + + /** + * Db schema whitelist generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DbSchemaWhitelistGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Db schema whitelist generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DbSchemaWhitelistGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DbSchemaWhitelistJsonGenerator( + getProject(), + (DbSchemaXmlData) getDataObjectConverter(), + getContextData().getModuleName() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaXmlGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaXmlGeneratorHandler.java new file mode 100644 index 000000000..25e9ec3c3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaXmlGeneratorHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DbSchemaXmlGeneratorHandler extends GeneratorHandler { + + /** + * Db schema XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DbSchemaXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Db schema XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DbSchemaXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DbSchemaXmlGenerator( + (DbSchemaXmlData) getDataObjectConverter(), + getProject(), + getContextData().getModuleName() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DeleteByIdCommandGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DeleteByIdCommandGeneratorHandler.java new file mode 100644 index 000000000..6c7c7ec30 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DeleteByIdCommandGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DeleteEntityByIdCommandGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class DeleteByIdCommandGeneratorHandler extends GeneratorHandler { + + /** + * Delete by id command generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public DeleteByIdCommandGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Delete by id command generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public DeleteByIdCommandGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DeleteEntityByIdCommandGenerator( + (DeleteEntityByIdCommandData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityDataMapperGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityDataMapperGeneratorHandler.java new file mode 100644 index 000000000..3e547dae9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityDataMapperGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class EntityDataMapperGeneratorHandler extends GeneratorHandler { + + /** + * Entity data mapper generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public EntityDataMapperGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Entity data mapper generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public EntityDataMapperGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new EntityDataMapperGenerator( + (EntityDataMapperData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormDeleteControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormDeleteControllerGeneratorHandler.java new file mode 100644 index 000000000..c14caddf7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormDeleteControllerGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.DeleteEntityControllerFileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class FormDeleteControllerGeneratorHandler extends GeneratorHandler { + + /** + * Form delete controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormDeleteControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Form delete controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public FormDeleteControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new DeleteEntityControllerFileGenerator( + (DeleteEntityControllerFileData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormEditControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormEditControllerGeneratorHandler.java new file mode 100644 index 000000000..5ec5f8c0d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormEditControllerGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.EditEntityActionGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class FormEditControllerGeneratorHandler extends GeneratorHandler { + + /** + * Form edit controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormEditControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Form edit controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public FormEditControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new EditEntityActionGenerator( + (EditEntityActionData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormGenericButtonBlockGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormGenericButtonBlockGeneratorHandler.java new file mode 100644 index 000000000..12f9d5fc9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormGenericButtonBlockGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class FormGenericButtonBlockGeneratorHandler extends GeneratorHandler { + + /** + * Form generic button block generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormGenericButtonBlockGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Form generic button block generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public FormGenericButtonBlockGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new FormGenericButtonBlockGenerator( + (FormGenericButtonBlockData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormLayoutGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormLayoutGeneratorHandler.java new file mode 100644 index 000000000..b3bf67721 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormLayoutGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class FormLayoutGeneratorHandler extends GeneratorHandler { + + /** + * Form layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + super(contextData, dataObjectConverter, null); + } + + /** + * Form layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param generatorRunnerValidator GeneratorRunnerValidator + */ + public FormLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator generatorRunnerValidator + ) { + super(contextData, dataObjectConverter, generatorRunnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new LayoutXmlGenerator( + (LayoutXmlData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormSaveControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormSaveControllerGeneratorHandler.java new file mode 100644 index 000000000..54ab4b099 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormSaveControllerGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityControllerFileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class FormSaveControllerGeneratorHandler extends GeneratorHandler { + + /** + * Form save controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormSaveControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Form save controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public FormSaveControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new SaveEntityControllerFileGenerator( + (SaveEntityControllerFileData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GetListQueryGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GetListQueryGeneratorHandler.java new file mode 100644 index 000000000..120c74943 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GetListQueryGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class GetListQueryGeneratorHandler extends GeneratorHandler { + + /** + * Get list query generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public GetListQueryGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Get list query generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public GetListQueryGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new GetListQueryModelGenerator( + (GetListQueryModelData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridActionColumnGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridActionColumnGeneratorHandler.java new file mode 100644 index 000000000..012e51dc5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridActionColumnGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.GridActionColumnDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class GridActionColumnGeneratorHandler extends GeneratorHandler { + + /** + * Grid actions column generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public GridActionColumnGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Grid actions column generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public GridActionColumnGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new GridActionColumnFileGenerator( + (GridActionColumnDtoConverter) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridLayoutXmlGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridLayoutXmlGeneratorHandler.java new file mode 100644 index 000000000..914180c53 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridLayoutXmlGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class GridLayoutXmlGeneratorHandler extends GeneratorHandler { + + /** + * Grid layout XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public GridLayoutXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Grid layout XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public GridLayoutXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new LayoutXmlGenerator( + (LayoutXmlData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java new file mode 100644 index 000000000..f9c2f82e1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.IndexActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.IndexActionGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class IndexActionGeneratorHandler extends GeneratorHandler { + + /** + * Entity index action generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public IndexActionGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Entity index action generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public IndexActionGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new IndexActionGenerator( + (IndexActionData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/MenuXmlGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/MenuXmlGeneratorHandler.java new file mode 100644 index 000000000..858507559 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/MenuXmlGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class MenuXmlGeneratorHandler extends GeneratorHandler { + + /** + * Menu XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public MenuXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Menu XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public MenuXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new MenuXmlGenerator( + (MenuXmlData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ModelGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ModelGeneratorHandler.java new file mode 100644 index 000000000..316aefe8d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ModelGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class ModelGeneratorHandler extends GeneratorHandler { + + /** + * Model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public ModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public ModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new ModuleModelGenerator( + (ModelData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewControllerGeneratorHandler.java new file mode 100644 index 000000000..a5fe02f07 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewControllerGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.NewActionEntityControllerFileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class NewControllerGeneratorHandler extends GeneratorHandler { + + /** + * New controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public NewControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * New controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public NewControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new NewActionEntityControllerFileGenerator( + (NewActionEntityControllerFileData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewEntityLayoutGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewEntityLayoutGeneratorHandler.java new file mode 100644 index 000000000..15728bade --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewEntityLayoutGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.NewEntityLayoutGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class NewEntityLayoutGeneratorHandler extends GeneratorHandler { + + /** + * New entity layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public NewEntityLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * New entity layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public NewEntityLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new NewEntityLayoutGenerator( + (NewEntityLayoutData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ResourceModelGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ResourceModelGeneratorHandler.java new file mode 100644 index 000000000..3eb28350b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ResourceModelGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleResourceModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class ResourceModelGeneratorHandler extends GeneratorHandler { + + /** + * Resource model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public ResourceModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Resource model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public ResourceModelGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new ModuleResourceModelGenerator( + (ResourceModelData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/RoutesXmlGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/RoutesXmlGeneratorHandler.java new file mode 100644 index 000000000..95e29db18 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/RoutesXmlGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class RoutesXmlGeneratorHandler extends GeneratorHandler { + + /** + * Routes XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public RoutesXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Routes XML generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public RoutesXmlGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new RoutesXmlGenerator( + (RoutesXmlData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SaveCommandGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SaveCommandGeneratorHandler.java new file mode 100644 index 000000000..cec5271b7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SaveCommandGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class SaveCommandGeneratorHandler extends GeneratorHandler { + + /** + * Save command generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public SaveCommandGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Save command generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public SaveCommandGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new SaveEntityCommandGenerator( + (SaveEntityCommandData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentFormLayoutGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentFormLayoutGeneratorHandler.java new file mode 100644 index 000000000..3bce7562c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentFormLayoutGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class UiComponentFormLayoutGeneratorHandler extends GeneratorHandler { + + /** + * Ui Component form layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public UiComponentFormLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Ui Component form layout generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public UiComponentFormLayoutGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new UiComponentFormGenerator( + (UiComponentFormFileData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentGridGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentGridGeneratorHandler.java new file mode 100644 index 000000000..992a61c5f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentGridGeneratorHandler.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; + +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorRunnerValidator; +import org.jetbrains.annotations.NotNull; + +public class UiComponentGridGeneratorHandler extends GeneratorHandler { + + /** + * Ui Component grid generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public UiComponentGridGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Ui Component grid generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public UiComponentGridGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new UiComponentGridXmlGenerator( + (UiComponentGridData) getDataObjectConverter(), + getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/provider/NewEntityGeneratorsProviderUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/provider/NewEntityGeneratorsProviderUtil.java new file mode 100644 index 000000000..8d6895f55 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/provider/NewEntityGeneratorsProviderUtil.java @@ -0,0 +1,223 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool.provider; + +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.AclXmlDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.CollectionModelDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.DataModelDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.DataModelInterfaceDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.DataProviderDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.DbSchemaXmlDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.DeleteEntityByIdCommandDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.EntityDataMapperDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.FormDeleteControllerDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.FormEditControllerDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.FormGenericButtonBlockDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.FormLayoutDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.FormSaveControllerDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.GetListQueryDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.GridActionColumnDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.GridLayoutXmlDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.IndexActionDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.MenuXmlDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.ModelDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.NewControllerDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.NewEntityLayoutDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.PreferenceDiXmlFileDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.ResourceModelDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.RoutesXmlDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.SaveEntityCommandDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.UiComponentFormLayoutDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.UiComponentGridDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.GeneratorPoolHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.AclXmlGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.CollectionModelGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DataModelGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DataModelInterfaceGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DataModelPreferenceGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DataProviderGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DbSchemaWhitelistGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DbSchemaXmlGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.DeleteByIdCommandGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.EntityDataMapperGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.FormDeleteControllerGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.FormEditControllerGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.FormGenericButtonBlockGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.FormLayoutGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.FormSaveControllerGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.GetListQueryGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.GridActionColumnGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.GridLayoutXmlGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.IndexActionGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.MenuXmlGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.ModelGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.NewControllerGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.NewEntityLayoutGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.ResourceModelGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.RoutesXmlGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.SaveCommandGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.UiComponentFormLayoutGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.UiComponentGridGeneratorHandler; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings({ + "PMD.CouplingBetweenObjects", + "PMD.ExcessiveImports" +}) +public final class NewEntityGeneratorsProviderUtil { + + private NewEntityGeneratorsProviderUtil() {} + + /** + * Generators initializing excluded from dialog to better test coverage. + * + * @param generatorPoolHandler GeneratorPoolHandler + * @param context EntityCreatorContextData + * @param dialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.ExcessiveMethodLength") + public static void initializeGenerators( + final @NotNull GeneratorPoolHandler generatorPoolHandler, + final @NotNull EntityCreatorContextData context, + final @NotNull NewEntityDialogData dialogData + ) { + generatorPoolHandler + .addNext( + ModelGeneratorHandler.class, + new ModelDtoConverter(context, dialogData) + ) + .addNext( + ResourceModelGeneratorHandler.class, + new ResourceModelDtoConverter(context, dialogData) + ) + .addNext( + CollectionModelGeneratorHandler.class, + new CollectionModelDtoConverter(context, dialogData) + ) + .addNext( + DataModelGeneratorHandler.class, + new DataModelDtoConverter(context, dialogData) + ) + .addNext( + DataModelInterfaceGeneratorHandler.class, + new DataModelInterfaceDtoConverter(context, dialogData), + dialogData::hasDtoInterface + ) + .addNext( + DataModelPreferenceGeneratorHandler.class, + new PreferenceDiXmlFileDtoConverter(context, dialogData), + dialogData::hasDtoInterface + ) + .addNext( + RoutesXmlGeneratorHandler.class, + new RoutesXmlDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + AclXmlGeneratorHandler.class, + new AclXmlDtoConverter(context, dialogData) + ) + .addNext( + MenuXmlGeneratorHandler.class, + new MenuXmlDtoConverter(context, dialogData) + ) + .addNext( + IndexActionGeneratorHandler.class, + new IndexActionDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + GridLayoutXmlGeneratorHandler.class, + new GridLayoutXmlDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + EntityDataMapperGeneratorHandler.class, + new EntityDataMapperDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + GetListQueryGeneratorHandler.class, + new GetListQueryDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + DataProviderGeneratorHandler.class, + new DataProviderDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + GridActionColumnGeneratorHandler.class, + new GridActionColumnDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + UiComponentGridGeneratorHandler.class, + new UiComponentGridDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + FormLayoutGeneratorHandler.class, + new FormLayoutDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + NewEntityLayoutGeneratorHandler.class, + new NewEntityLayoutDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + SaveCommandGeneratorHandler.class, + new SaveEntityCommandDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + DeleteByIdCommandGeneratorHandler.class, + new DeleteEntityByIdCommandDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + FormSaveControllerGeneratorHandler.class, + new FormSaveControllerDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + FormDeleteControllerGeneratorHandler.class, + new FormDeleteControllerDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + FormEditControllerGeneratorHandler.class, + new FormEditControllerDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + FormGenericButtonBlockGeneratorHandler.class, + new FormGenericButtonBlockDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + NewControllerGeneratorHandler.class, + new NewControllerDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + UiComponentFormLayoutGeneratorHandler.class, + new UiComponentFormLayoutDtoConverter(context, dialogData), + dialogData::hasAdminUiComponents + ) + .addNext( + DbSchemaXmlGeneratorHandler.class, + new DbSchemaXmlDtoConverter(context, dialogData) + ) + .addNext( + DbSchemaWhitelistGeneratorHandler.class, + new DbSchemaXmlDtoConverter(context, dialogData) + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorUtil.java new file mode 100644 index 000000000..d84f10318 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorUtil.java @@ -0,0 +1,111 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util; + +import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; +import com.magento.idea.magento2plugin.magento.packages.database.PropertyToDefaultTypeMapperUtil; +import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +public final class DbSchemaGeneratorUtil { + private static final String PROPERTY_NAME = "Name"; + private static final String PROPERTY_TYPE = "Type"; + + private DbSchemaGeneratorUtil() {} + + /** + * Complement short entity properties to expected in the db_schema.xml generator. + * + * @param shortProperties List + * + * @return List of expected in the DbSchemaXmlGenerator properties. + */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") + public static List> complementShortPropertiesByDefaults( + final List> shortProperties + ) { + final List> complemented = new LinkedList<>(); + + for (final Map property : shortProperties) { + final String name = property.get(PROPERTY_NAME); + final String type = property.get(PROPERTY_TYPE); + + final PropertiesTypes propType = PropertiesTypes.getByValue(type); + final TableColumnTypes tableColumnType = PropertyToDefaultTypeMapperUtil.map(propType); + + final List allowedAttributes = ModuleDbSchemaXml.getAllowedAttributes( + tableColumnType + ); + + final Map columnData = new LinkedHashMap<>(); + columnData.put(ColumnAttributes.TYPE.getName(), tableColumnType.getColumnType()); + columnData.put(ColumnAttributes.NAME.getName(), name); + + for (final String columnAttributeName : allowedAttributes) { + final ColumnAttributes attribute = ColumnAttributes.getByName(columnAttributeName); + + if (columnData.containsKey(columnAttributeName) || !attribute.hasDefault()) { + continue; + } + columnData.put(columnAttributeName, attribute.getDefault()); + } + columnData.put(ColumnAttributes.COMMENT.getName(), getColumnCommentByName(name)); + + complemented.add(columnData); + } + + return complemented; + } + + /** + * Get primary key default data for specified name. + * + * @param name String + * + * @return String + */ + public static Map getTableIdentityColumnData(final @NotNull String name) { + final Map columnData = new LinkedHashMap<>(); + + columnData.put(ColumnAttributes.TYPE.getName(), TableColumnTypes.INT.getColumnType()); + columnData.put(ColumnAttributes.NAME.getName(), name); + columnData.put(ColumnAttributes.PADDING.getName(), ColumnAttributes.PADDING.getDefault()); + columnData.put(ColumnAttributes.UNSIGNED.getName(), ColumnAttributes.UNSIGNED.getDefault()); + columnData.put(ColumnAttributes.NULLABLE.getName(), ColumnAttributes.NULLABLE.getDefault()); + columnData.put(ColumnAttributes.IDENTITY.getName(), "true"); + columnData.put(ColumnAttributes.COMMENT.getName(), getColumnCommentByName(name)); + + return columnData; + } + + /** + * Generate column comment by its name. + * + * @param name String + * + * @return String + */ + @SuppressWarnings("PMD.UseLocaleWithCaseConversions") + private static String getColumnCommentByName(final @NotNull String name) { + final StringBuilder commentStringBuilder = new StringBuilder(); + final String[] nameParts = name.split("_"); + + for (final String namePart : nameParts) { + commentStringBuilder + .append(namePart.substring(0, 1).toUpperCase()) + .append(namePart.substring(1)) + .append(' '); + } + + return commentStringBuilder.append("Column").toString(); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DirectoryGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DirectoryGenerator.java index 64f5a83d2..632782040 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DirectoryGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/DirectoryGenerator.java @@ -8,7 +8,9 @@ import com.intellij.openapi.application.WriteAction; import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.generator.data.ModuleDirectoriesData; +import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; +import java.util.Arrays; import org.jetbrains.annotations.NotNull; public class DirectoryGenerator { @@ -62,4 +64,44 @@ public PsiDirectory findOrCreateSubdirectory( final PsiDirectory sub = parent.findSubdirectory(subdirName); return sub == null ? WriteAction.compute(() -> parent.createSubdirectory(subdirName)) : sub; } + + /** + * Find or create subdirectories. + * + * @param parent PsiDirectory + * @param subdirPath String + * + * @return PsiDirectory + */ + public PsiDirectory findOrCreateSubdirectories( + final @NotNull PsiDirectory parent, + final @NotNull String subdirPath + ) { + PsiDirectory lastDirectory = null; + final String[] directories = subdirPath.split(File.separator); + + for (final String directory : Arrays.asList(directories)) { + if (lastDirectory == null) { + final PsiDirectory subDir = parent.findSubdirectory(directory); + + if (subDir == null) { + lastDirectory = WriteAction.compute(() -> parent.createSubdirectory(directory)); + } else { + lastDirectory = subDir; + } + } else { + final PsiDirectory subDir = lastDirectory.findSubdirectory(directory); + + if (subDir == null) { + final PsiDirectory finalLastDirectory = lastDirectory; + lastDirectory = WriteAction.compute(() -> + finalLastDirectory.createSubdirectory(directory)); + } else { + lastDirectory = subDir; + } + } + } + + return lastDirectory; + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassGeneratorUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassGeneratorUtil.java index 40677f142..c364dbb49 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassGeneratorUtil.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassGeneratorUtil.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.List; +import org.jetbrains.annotations.NotNull; public final class PhpClassGeneratorUtil { @@ -16,9 +17,10 @@ private PhpClassGeneratorUtil() {} * Formats PHP class uses. * * @param uses List + * * @return String */ - public static String formatUses(final List uses) { + public static String formatUses(final @NotNull List uses) { Collections.sort(uses); return String.join(",", uses); @@ -28,9 +30,10 @@ public static String formatUses(final List uses) { * Fetches the class name from a fully qualified name. * * @param fqn FQN + * * @return String */ - public static String getNameFromFqn(final String fqn) { + public static String getNameFromFqn(final @NotNull String fqn) { final String[] fqnArray = fqn.split("\\\\"); return fqnArray[fqnArray.length - 1]; diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassTypesBuilder.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassTypesBuilder.java new file mode 100644 index 000000000..d08ee95c3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassTypesBuilder.java @@ -0,0 +1,244 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import org.jetbrains.annotations.NotNull; + +public final class PhpClassTypesBuilder { + + private final List types; + private final Properties properties; + + /** + * Php class types builder. + */ + public PhpClassTypesBuilder() { + types = new ArrayList<>(); + properties = new Properties(); + } + + /** + * Append property. + * + * @param propertyName String + * @param propertyValue String + * + * @return PhpClassTypesBuilder + */ + public PhpClassTypesBuilder appendProperty( + final @NotNull String propertyName, + final @NotNull String propertyValue + ) { + properties.setProperty(propertyName, propertyValue); + return this; + } + + /** + * Append type. + * + * @param propertyName String + * @param typeFqn String + * + * @return PhpClassTypesBuilder + */ + public PhpClassTypesBuilder append( + final @NotNull String propertyName, + final @NotNull String typeFqn + ) { + return append(propertyName, typeFqn, null); + } + + /** + * Append type. + * + * @param propertyName String + * @param typeFqn String + * @param alias String + * + * @return PhpClassTypesBuilder + */ + public PhpClassTypesBuilder append( + final @NotNull String propertyName, + final @NotNull String typeFqn, + final String alias + ) { + final PhpClassTypeData type = new PhpClassTypeData( + typeFqn, + PhpClassGeneratorUtil.getNameFromFqn(typeFqn), + propertyName, + alias + ); + types.add(type); + + String propName; + + if (type.getAlias() == null) { + propName = type.getName(); + } else { + propName = hasDuplicatedName(type) ? type.getAlias() : type.getName(); + } + + properties.setProperty(type.getPropertyName(), propName); + return this; + } + + /** + * Merge properties. + * + * @param properties Properties + */ + public void mergeProperties(final @NotNull Properties properties) { + final Set> entrySet = this.properties.entrySet(); + + for (final Map.Entry map : entrySet) { + properties.setProperty(map.getKey().toString(), map.getValue().toString()); + } + } + + /** + * Get uses list for php class. + * + * @return List[String] + */ + public List getUses() { + final List uses = new ArrayList<>(); + + for (final PhpClassTypeData type : types) { + if (type.getFqnWithAlias() == null) { + uses.add(type.getFqn()); + } else { + uses.add(hasDuplicatedName(type) ? type.getFqnWithAlias() : type.getFqn()); + } + } + + return uses; + } + + /** + * Check if there is any duplicated type name. + * + * @param typeData PhpClassTypeData + * + * @return boolean + */ + private boolean hasDuplicatedName(final @NotNull PhpClassTypeData typeData) { + for (final PhpClassTypeData type : types) { + if (!typeData.equals(type) && typeData.getName().equals(type.getName())) { + return true; + } + } + + return hasDuplicatesInProps(typeData); + } + + /** + * Check if there is any duplicate in properties. + * + * @param typeData PhpClassTypeData + * + * @return boolean + */ + private boolean hasDuplicatesInProps(final @NotNull PhpClassTypeData typeData) { + final Set> propertiesEntrySet = this.properties.entrySet(); + + for (final Map.Entry propMapEntry : propertiesEntrySet) { + if (typeData.getPropertyName().equals(propMapEntry.getKey().toString())) { + continue; + } + if (typeData.getName().equals(propMapEntry.getValue().toString())) { + return true; + } + } + + return false; + } + + /** + * Php class type DTO. + */ + public static final class PhpClassTypeData { + + private static final String ALIAS_FORMAT = "%fqn as %alias"; + private final String fqn; + private final String name; + private final String propertyName; + private final String alias; + + /** + * Type data constructor. + * + * @param fqn String + * @param name String + * @param propertyName String + * @param alias String + */ + public PhpClassTypeData( + final @NotNull String fqn, + final @NotNull String name, + final @NotNull String propertyName, + final String alias + ) { + this.fqn = fqn; + this.name = name; + this.propertyName = propertyName; + this.alias = alias; + } + + /** + * Get type FQN. + * + * @return String + */ + public String getFqn() { + return fqn; + } + + /** + * Get type FQN. + * + * @return String + */ + public String getFqnWithAlias() { + if (getAlias() == null) { + return null; + } + + return ALIAS_FORMAT.replace("%fqn", getFqn()).replace("%alias", getAlias()); + } + + /** + * Get type name. + * + * @return String + */ + public String getName() { + return name; + } + + /** + * Get property name. + * + * @return String + */ + public String getPropertyName() { + return propertyName; + } + + /** + * Get type alias. + * + * @return String + */ + public String getAlias() { + return alias; + } + } +} diff --git a/src/com/magento/idea/magento2plugin/bundles/ExceptionBundle.java b/src/com/magento/idea/magento2plugin/bundles/ExceptionBundle.java new file mode 100644 index 000000000..8d15ab438 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/bundles/ExceptionBundle.java @@ -0,0 +1,18 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.bundles; + +public final class ExceptionBundle extends AbstractBundle { + + /** + * Retrieve exception bundle file name for plugin. + * + * @return String + */ + public String getBundleName() { + return "magento2.exception"; + } +} diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java index a687e7bbd..35d102fd9 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java @@ -135,6 +135,13 @@ public void visitFile(final PsiFile file) { ); } + if (observerDisabledAttribute != null + && observerDisabledAttribute.getValue() != null + && observerDisabledAttribute.getValue().equals("true") + ) { + continue; + } + for (final HashMap moduleEntry: modulesWithSameObserverName) { final Map.Entry module = moduleEntry diff --git a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java deleted file mode 100644 index bba99ba24..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; - -public abstract class AbstractPhpClass implements ModuleFileInterface { - private final String fileName; - - public AbstractPhpClass(final String className) { - fileName = className.concat(".php"); - } - - @Override - public String getFileName() { - return this.fileName; - } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java new file mode 100644 index 000000000..5de4b9341 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java @@ -0,0 +1,110 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import org.jetbrains.annotations.NotNull; + +public abstract class AbstractPhpFile implements ModuleFileInterface { + + public static final String FILE_EXTENSION = "php"; + private final String moduleName; + private final String className; + private NamespaceBuilder namespaceBuilder; + + /** + * Abstract php file constructor. + * + * @param moduleName String + * @param className String + */ + public AbstractPhpFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + this.moduleName = moduleName; + this.className = className; + } + + /** + * Get namespace. + * + * @return String + */ + public @NotNull String getNamespace() { + return getNamespaceBuilder().getNamespace(); + } + + /** + * Get class FQN. + * + * @return String + */ + public @NotNull String getClassFqn() { + return getNamespaceBuilder().getClassFqn(); + } + + /** + * Get namespace builder for file. + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder() { + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + className, + getDirectory() + ); + } + + return namespaceBuilder; + } + + /** + * Get directory for file. + * + * @return String + */ + public abstract String getDirectory(); + + /** + * Get file module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get class name. + * + * @return String + */ + public String getClassName() { + return className; + } + + /** + * Get readable name. Should be overridden to use. + * + * @return String + */ + public abstract String getHumanReadableName(); + + @Override + public String getFileName() { + return className.concat(".").concat(FILE_EXTENSION); + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java new file mode 100644 index 000000000..56159f74b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.magento.idea.magento2plugin.magento.packages.File; +import org.jetbrains.annotations.NotNull; + +public class CollectionModelFile extends AbstractPhpFile { + + public static final String TEMPLATE = "Magento Collection Class"; + public static final String HUMAN_READABLE_NAME = "Collection class"; + public static final String ABSTRACT_COLLECTION + = "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection"; + private final String directoryName; + + /** + * Collection model file constructor. + * + * @param moduleName String + * @param className String + * @param directoryName String + */ + public CollectionModelFile( + final @NotNull String moduleName, + final @NotNull String className, + final @NotNull String directoryName + ) { + super(moduleName, className); + this.directoryName = directoryName; + } + + @Override + public @NotNull String getDirectory() { + return ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + directoryName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/CollectionPhp.java b/src/com/magento/idea/magento2plugin/magento/files/CollectionPhp.java deleted file mode 100644 index bbc55b149..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/CollectionPhp.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -public class CollectionPhp extends AbstractPhpClass { - public static final String ABSTRACT_COLLECTION - = "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection"; - - public CollectionPhp(final String className) { - super(className); - } - - @Override - public String getTemplate() { - return "Magento Collection Class"; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java index 2c9a223d3..9c08500f0 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java @@ -5,43 +5,28 @@ package com.magento.idea.magento2plugin.magento.files; -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; +import org.jetbrains.annotations.NotNull; + +public class ControllerBackendPhp extends AbstractPhpFile { -@SuppressWarnings({ - "PMD.FieldNamingConventions", - "PMD.NonThreadSafeSingleton", - "PMD.RedundantFieldInitializer" -}) -public class ControllerBackendPhp implements ModuleFileInterface { public static final String TEMPLATE = "Magento Backend Controller Class"; public static final String DEFAULT_DIR = "Controller/Adminhtml"; - private static ControllerBackendPhp INSTANCE = null; - private String fileName; - - /** - * Returns a new instance of the class. - * - * @param className Controller class name - * @return ControllerBackendPhp - */ - public static ControllerBackendPhp getInstance(final String className) { - if (null == INSTANCE) { - INSTANCE = new ControllerBackendPhp(); - } - INSTANCE.setFileName(className.concat(".php")); + public ControllerBackendPhp( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } - return INSTANCE; + @Override + public String getDirectory() { + return DEFAULT_DIR; } - /** - * Get name of backend controller file. - * - * @return Name of the file. - */ - public String getFileName() { - return this.fileName; + @Override + public String getHumanReadableName() { + return null; } /** @@ -52,22 +37,4 @@ public String getFileName() { public String getTemplate() { return TEMPLATE; } - - /** - * Get return language. - * - * @return PHP language - */ - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } - - /** - * Get name of controller file. - * - * @param filename Name of backend controller file. - */ - private void setFileName(final String filename) { - this.fileName = filename; - } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java index f70c55347..93e966df0 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java @@ -5,43 +5,28 @@ package com.magento.idea.magento2plugin.magento.files; -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; +import org.jetbrains.annotations.NotNull; + +public class ControllerFrontendPhp extends AbstractPhpFile { -@SuppressWarnings({ - "PMD.FieldNamingConventions", - "PMD.NonThreadSafeSingleton", - "PMD.RedundantFieldInitializer" -}) -public class ControllerFrontendPhp implements ModuleFileInterface { public static final String TEMPLATE = "Magento Frontend Controller Class"; public static final String DEFAULT_DIR = "Controller"; - private static ControllerFrontendPhp INSTANCE = null; - private String fileName; - - /** - * Returns a new instance of the class. - * - * @param className Controller class name - * @return ControllerFrontendPhp - */ - public static ControllerFrontendPhp getInstance(final String className) { - if (null == INSTANCE) { - INSTANCE = new ControllerFrontendPhp(); - } - INSTANCE.setFileName(className.concat(".php")); + public ControllerFrontendPhp( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } - return INSTANCE; + @Override + public String getDirectory() { + return DEFAULT_DIR; } - /** - * Get name of frontend controller file. - * - * @return Name of the file. - */ - public String getFileName() { - return this.fileName; + @Override + public String getHumanReadableName() { + return null; } /** @@ -52,22 +37,4 @@ public String getFileName() { public String getTemplate() { return TEMPLATE; } - - /** - * Get return language. - * - * @return PHP language - */ - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } - - /** - * Get name of controller file. - * - * @param filename Name of frontend controller file. - */ - private void setFileName(final String filename) { - this.fileName = filename; - } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/DataModel.java b/src/com/magento/idea/magento2plugin/magento/files/DataModel.java deleted file mode 100644 index 5158f55f4..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/DataModel.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; - -public class DataModel implements ModuleFileInterface { - public static final String DIRECTORY = "Model/Data"; - public static final String DATA_OBJECT = "Magento\\Framework\\DataObject"; - private final String className; - - public DataModel(final String className) { - this.className = className.concat(".php"); - } - - @Override - public String getFileName() { - return className; - } - - @Override - public String getTemplate() { - return "Magento Data Model"; - } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java new file mode 100644 index 000000000..e6f299d90 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java @@ -0,0 +1,44 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class DataModelFile extends AbstractPhpFile { + + public static final String TEMPLATE = "Magento Data Model"; + public static final String HUMAN_READABLE_NAME = "Data transfer object model"; + public static final String DIRECTORY = "Model/Data"; + public static final String DATA_OBJECT = "Magento\\Framework\\DataObject"; + + /** + * Data model generator file constructor. + * + * @param moduleName String + * @param className String + */ + public DataModelFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/DataModelInterface.java b/src/com/magento/idea/magento2plugin/magento/files/DataModelInterface.java deleted file mode 100644 index 8b79cda6d..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/DataModelInterface.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; - -public class DataModelInterface implements ModuleFileInterface { - public static final String DIRECTORY = "Api/Data"; - private final String className; - - public DataModelInterface(final String className) { - this.className = className.concat(".php"); - } - - @Override - public String getFileName() { - return className; - } - - @Override - public String getTemplate() { - return "Magento Data Model Interface"; - } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/DataModelInterfaceFile.java b/src/com/magento/idea/magento2plugin/magento/files/DataModelInterfaceFile.java new file mode 100644 index 000000000..01937ff4c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/DataModelInterfaceFile.java @@ -0,0 +1,43 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class DataModelInterfaceFile extends AbstractPhpFile { + + public static final String TEMPLATE = "Magento Data Model Interface"; + public static final String HUMAN_READABLE_NAME = "Data transfer object interface"; + public static final String DIRECTORY = "Api/Data"; + + /** + * DTO interface file constructor. + * + * @param moduleName String + * @param className String + */ + public DataModelInterfaceFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java new file mode 100644 index 000000000..ca4e0e4c1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java @@ -0,0 +1,44 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class EntityDataMapperFile extends AbstractPhpFile { + + public static final String CLASS_NAME_SUFFIX = "DataMapper"; + public static final String HUMAN_READABLE_NAME = "Entity data mapper class"; + public static final String TEMPLATE = "Magento Entity Data Mapper"; + private static final String DIRECTORY = "Mapper"; + + /** + * Entity data mapper file constructor. + * + * @param moduleName String + * @param entityName String + */ + public EntityDataMapperFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, entityName.concat(CLASS_NAME_SUFFIX)); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public @NotNull String getDirectory() { + return DIRECTORY; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java b/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java new file mode 100644 index 000000000..38267b50f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java @@ -0,0 +1,51 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class FormButtonBlockFile extends AbstractPhpFile { + + public static final String TEMPLATE = "Magento Form Button Block Class"; + public static final String HUMAN_READABLE_NAME = "Form button block class"; + public static final String DATA_PROVIDER_TYPE = + "Magento\\Framework\\View\\Element\\UiComponent\\Control\\ButtonProviderInterface"; + public static final String TYPE_SAVE = "Save"; + public static final String TYPE_DELETE = "Delete"; + public static final String TYPE_BACK = "Back"; + public static final String TYPE_CUSTOM = "Custom"; + private final String directoryName; + + /** + * Form button block file constructor. + * + * @param moduleName String + * @param className String + */ + public FormButtonBlockFile( + final @NotNull String moduleName, + final @NotNull String className, + final @NotNull String directoryName + ) { + super(moduleName, className); + this.directoryName = directoryName; + } + + @Override + public String getDirectory() { + return directoryName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockPhp.java b/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockPhp.java deleted file mode 100644 index f88d51713..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockPhp.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -public class FormButtonBlockPhp extends AbstractPhpClass { - public static String template = "Magento Form Button Block Class"; - - public static String saveMethodTemplate = "Magento Php Form Button Block Type Save"; - public static String deleteMethodTemplate = "Magento Php Form Button Block Type Delete"; - public static String backMethodTemplate = "Magento Php Form Button Block Type Back"; - - public static final String TYPE_SAVE = "Save"; - public static final String TYPE_DELETE = "Delete"; - public static final String TYPE_BACK = "Back"; - public static final String TYPE_CUSTOM = "Custom"; - - public static final String DEFAULT_METHOD = "getButtonData"; - - public FormButtonBlockPhp(final String className) { - super(className); - } - - @Override - public String getTemplate() { - return template; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java new file mode 100644 index 000000000..1776ab125 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public final class FormGenericButtonBlockFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "GenericButton"; + public static final String HUMAN_READABLE_NAME = "Generic button block class"; + public static final String TEMPLATE = "Magento PHP Form Generic Button Block Class"; + public static final String CONTEXT = "Magento\\Backend\\Block\\Widget\\Context"; + private static final String DIRECTORY = "Block/Form"; + private final String entityName; + + /** + * Form generic button block file constructor. + * + * @param moduleName String + * @param entityName String + */ + public FormGenericButtonBlockFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java new file mode 100644 index 000000000..27538f96b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public final class GridActionColumnFile extends AbstractPhpFile { + + public static final String HUMAN_READABLE_NAME = "Grid Ui Component actions column class"; + public static final String TEMPLATE = "Magento Grid Ui Component Action Column Class"; + public static final String PARENT_CLASS = "Magento\\Ui\\Component\\Listing\\Columns\\Column"; + public static final String CONTEXT = + "Magento\\Framework\\View\\Element\\UiComponent\\ContextInterface"; + public static final String UI_COMPONENT_FACTORY = + "Magento\\Framework\\View\\Element\\UiComponentFactory"; + private static final String CLASS_NAME = "BlockActions"; + private static final String DIRECTORY = "Ui/Component/Listing/Column"; + + /** + * Grid actions column file constructor. + * + * @param moduleName String + * @param entityName String + */ + public GridActionColumnFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, entityName.concat(CLASS_NAME)); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java new file mode 100644 index 000000000..e7985fcba --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class ModelFile extends AbstractPhpFile { + + public static final String ABSTRACT_MODEL = + "Magento\\Framework\\Model\\AbstractModel"; + public static final String MODEL_DIRECTORY = "Model"; + public static final String TEMPLATE = "Magento Model Class"; + public static final String HUMAN_READABLE_NAME = "Model class"; + public static final String ALIAS = "Model"; + + /** + * Model file constructor. + * + * @param moduleName String + * @param className String + */ + public ModelFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } + + @Override + public String getDirectory() { + return MODEL_DIRECTORY; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModelPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ModelPhp.java deleted file mode 100644 index a2ffec498..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/ModelPhp.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -public class ModelPhp extends AbstractPhpClass { - public static final String ABSTRACT_MODEL = - "Magento\\Framework\\Model\\AbstractModel"; - public static final String MODEL_DIRECTORY = "Model"; - - public ModelPhp(final String className) { - super(className); - } - - @Override - public String getTemplate() { - return "Magento Model Class"; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java index 9b41ffcb8..7594e6f3a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java @@ -7,9 +7,11 @@ import com.intellij.lang.Language; import com.intellij.lang.xml.XMLLanguage; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.NotNull; public class ModuleDbSchemaXml implements ModuleFileInterface { private static final ModuleDbSchemaXml INSTANCE = new ModuleDbSchemaXml(); @@ -27,18 +29,6 @@ public class ModuleDbSchemaXml implements ModuleFileInterface { public static final String XML_ATTR_CONSTRAINT_REFERENCE_COLUMN_NAME = "referenceColumn"; public static final String XML_ATTR_CONSTRAINT_REFERENCE_ID_NAME = "referenceId"; public static final String XML_ATTR_INDEX_TYPE_NAME = "indexType"; - public static final String XML_ATTR_COLUMN_NAME = "name"; - public static final String XML_ATTR_COLUMN_TYPE = "xsi:type"; - public static final String XML_ATTR_COLUMN_PADDING = "padding"; - public static final String XML_ATTR_COLUMN_UNSIGNED = "unsigned"; - public static final String XML_ATTR_COLUMN_NULLABLE = "nullable"; - public static final String XML_ATTR_COLUMN_IDENTITY = "identity"; - public static final String XML_ATTR_COLUMN_COMMENT = "comment"; - public static final String XML_ATTR_COLUMN_DEFAULT = "default"; - public static final String XML_ATTR_COLUMN_LENGTH = "length"; - public static final String XML_ATTR_COLUMN_SCALE = "scale"; - public static final String XML_ATTR_COLUMN_PRECISION = "precision"; - public static final String XML_ATTR_COLUMN_ON_UPDATE = "on_update"; //constant attributes values public static final String XML_ATTR_TYPE_PK = "primary"; @@ -62,7 +52,7 @@ public class ModuleDbSchemaXml implements ModuleFileInterface { * @return List */ @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NcssCount"}) - public static List getAllowedAttributes(final TableColumnTypes columnType) { + public static List getAllowedAttributes(final @NotNull TableColumnTypes columnType) { final List allowedAttributes = new ArrayList<>(); switch (columnType) { @@ -70,68 +60,62 @@ public static List getAllowedAttributes(final TableColumnTypes columnTyp case MEDIUMBLOB: case LONGBLOB: case DATE: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); - break; - case VARBINARY: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_LENGTH); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; case TINYINT: case SMALLINT: case INT: case BIGINT: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_PADDING); - allowedAttributes.add(XML_ATTR_COLUMN_UNSIGNED); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_IDENTITY); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.PADDING.getName()); + allowedAttributes.add(ColumnAttributes.UNSIGNED.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.IDENTITY.getName()); + allowedAttributes.add(ColumnAttributes.DEFAULT.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; case DECIMAL: case DOUBLE: case FLOAT: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_SCALE); - allowedAttributes.add(XML_ATTR_COLUMN_PRECISION); - allowedAttributes.add(XML_ATTR_COLUMN_UNSIGNED); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.PRECISION.getName()); + allowedAttributes.add(ColumnAttributes.SCALE.getName()); + allowedAttributes.add(ColumnAttributes.UNSIGNED.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.DEFAULT.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; + case VARBINARY: case VARCHAR: case TEXT: case MEDIUMTEXT: case LONGTEXT: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_LENGTH); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.LENGTH.getName()); + allowedAttributes.add(ColumnAttributes.DEFAULT.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; case BOOLEAN: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.DEFAULT.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; case DATETIME: case TIMESTAMP: - allowedAttributes.add(XML_ATTR_COLUMN_NAME); - allowedAttributes.add(XML_ATTR_COLUMN_ON_UPDATE); - allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); - allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); - allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); + allowedAttributes.add(ColumnAttributes.NAME.getName()); + allowedAttributes.add(ColumnAttributes.ON_UPDATE.getName()); + allowedAttributes.add(ColumnAttributes.NULLABLE.getName()); + allowedAttributes.add(ColumnAttributes.DEFAULT.getName()); + allowedAttributes.add(ColumnAttributes.COMMENT.getName()); break; default: break; } - allowedAttributes.add(XML_ATTR_COLUMN_TYPE); + allowedAttributes.add(ColumnAttributes.TYPE.getName()); return allowedAttributes; } diff --git a/src/com/magento/idea/magento2plugin/magento/files/NewEntityLayoutFile.java b/src/com/magento/idea/magento2plugin/magento/files/NewEntityLayoutFile.java new file mode 100644 index 000000000..ba08c8b4d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/NewEntityLayoutFile.java @@ -0,0 +1,60 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.intellij.lang.xml.XMLLanguage; +import org.jetbrains.annotations.NotNull; + +public class NewEntityLayoutFile implements ModuleFileInterface { + + public static final String TEMPLATE = "Magento New Entity Layout XML"; + private static final String PARENT_DIRECTORY = "layout"; + private static final String DIRECTORY = "view/adminhtml/layout"; + private final String filename; + + /** + * New entity layout file constructor. + * + * @param filename String + */ + public NewEntityLayoutFile(final @NotNull String filename) { + this.filename = filename; + } + + /** + * Get parent directory for file. + * + * @return String + */ + public String getParentDirectory() { + return PARENT_DIRECTORY; + } + + /** + * Get directory for file. + * + * @return String + */ + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getFileName() { + return filename.concat(".xml"); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java new file mode 100644 index 000000000..6e22e1277 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class ResourceModelFile extends AbstractPhpFile { + + public static final String RESOURCE_MODEL_DIRECTORY = "Model/ResourceModel"; + public static final String TEMPLATE = "Magento Resource Model Class"; + public static final String HUMAN_READABLE_NAME = "Resource model class"; + public static final String ABSTRACT_DB + = "Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb"; + public static final String ALIAS = "ResourceModel"; + + /** + * Resource model file constructor. + * + * @param moduleName String + * @param className String + */ + public ResourceModelFile( + final @NotNull String moduleName, + final @NotNull String className + ) { + super(moduleName, className); + } + + @Override + public String getDirectory() { + return RESOURCE_MODEL_DIRECTORY; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ResourceModelPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelPhp.java deleted file mode 100644 index ee47b6c37..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/ResourceModelPhp.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -public class ResourceModelPhp extends AbstractPhpClass { - public static final String RESOURCE_MODEL_DIRECTORY = "Model/ResourceModel"; - public static final String ABSTRACT_DB - = "Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb"; - - public ResourceModelPhp(final String className) { - super(className); - } - - @Override - public String getTemplate() { - return "Magento Resource Model Class"; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java new file mode 100644 index 000000000..55e908b37 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import org.jetbrains.annotations.NotNull; + +public class UiComponentDataProviderFile extends AbstractPhpFile { + + public static final String TEMPLATE = "Magento UI Component Custom Data Provider Class"; + public static final String HUMAN_READABLE_NAME = "Data Provider Class"; + public static final String DIRECTORY = "Ui/DataProvider"; + public static final String CUSTOM_TYPE = "custom"; + public static final String COLLECTION_TYPE = "collection"; + public static final String DEFAULT_DATA_PROVIDER = + "Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProvider"; + public static final String SEARCH_RESULT_FACTORY = + "Magento\\Ui\\DataProvider\\SearchResultFactory"; + private final String directory; + + /** + * Ui Component data provider file constructor. + * + * @param moduleName String + * @param className String + * @param directory String + */ + public UiComponentDataProviderFile( + final @NotNull String moduleName, + final @NotNull String className, + final String directory + ) { + super(moduleName, className); + this.directory = directory; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return directory == null ? DIRECTORY : directory; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java deleted file mode 100644 index 24e72cec8..000000000 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.files; - -import com.intellij.lang.Language; -import com.jetbrains.php.lang.PhpLanguage; - -@SuppressWarnings({ - "PMD.FieldNamingConventions", - "PMD.NonThreadSafeSingleton", - "PMD.RedundantFieldInitializer" -}) -public class UiComponentDataProviderPhp implements ModuleFileInterface { - public static final String CUSTOM_TEMPLATE = "Magento UI Component Custom Data Provider Class"; - public static final String FILE_EXTENSION = "php"; - public static final String CUSTOM_TYPE = "custom"; - public static final String COLLECTION_TYPE = "collection"; - private static UiComponentDataProviderPhp INSTANCE = null; - private String className; - public static final String DEFAULT_DATA_PROVIDER = - "Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProvider"; - - /** - * Returns a new instance of the class. - * - * @param className DataProvider class name - * @return UiComponentGridDataProviderPhp - */ - public static UiComponentDataProviderPhp getInstance( - final String className - ) { - if (null == INSTANCE) { - INSTANCE = new UiComponentDataProviderPhp(); - } - - INSTANCE.setClassName(className); - - return INSTANCE; - } - - /** - * Set class name. - * - * @param className String - */ - public void setClassName(final String className) { - this.className = className; - } - - @Override - public String getFileName() { - return String.format("%s.%s", className, FILE_EXTENSION); - } - - @Override - public String getTemplate() { - return CUSTOM_TEMPLATE; - } - - @Override - public Language getLanguage() { - return PhpLanguage.INSTANCE; - } -} diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXml.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXmlFile.java similarity index 87% rename from src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXml.java rename to src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXmlFile.java index eebe72216..5f8be07f4 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentFormXmlFile.java @@ -8,7 +8,8 @@ import com.intellij.lang.Language; import com.intellij.lang.xml.XMLLanguage; -public class UiComponentFormXml implements ModuleFileInterface { +public class UiComponentFormXmlFile implements ModuleFileInterface { + public static final String FILE_EXTENSION = "xml"; public static final String TEMPLATE = "Magento UI Component Form XML"; public static final String FIELD_TEMPLATE = "Magento Module UI Component Form Field Xml"; @@ -19,7 +20,7 @@ public class UiComponentFormXml implements ModuleFileInterface { * * @param componentName component name */ - public UiComponentFormXml(final String componentName) { + public UiComponentFormXmlFile(final String componentName) { this.componentName = componentName; } diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXmlFile.java similarity index 80% rename from src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java rename to src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXmlFile.java index 96c7f449f..8e05d35f6 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXmlFile.java @@ -8,9 +8,11 @@ import com.intellij.lang.Language; import com.intellij.lang.xml.XMLLanguage; -public class UiComponentGridXml implements ModuleFileInterface { +public class UiComponentGridXmlFile implements ModuleFileInterface { + public static final String FILE_EXTENSION = "xml"; public static final String TEMPLATE = "Magento UI Component Grid XML"; + public static final String COLUMN_TEMPLATE = "Magento Grid UI Component Column"; private final String componentName; /** @@ -18,7 +20,7 @@ public class UiComponentGridXml implements ModuleFileInterface { * * @param componentName component name */ - public UiComponentGridXml(final String componentName) { + public UiComponentGridXmlFile(final String componentName) { this.componentName = componentName; } diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java new file mode 100644 index 000000000..7ad2adf59 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java @@ -0,0 +1,52 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public final class DeleteActionFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "Delete"; + public static final String HUMAN_READABLE_NAME = "Delete controller class"; + public static final String TEMPLATE = "Magento Entity Delete Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private final String entityName; + + /** + * Delete action file constructor. + * + * @param moduleName String + * @param entityName String + */ + public DeleteActionFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + /** + * Get Directory path from the module root. + * + * @return String + */ + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java new file mode 100644 index 000000000..b4cf8fbd0 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public final class EditActionFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "Edit"; + public static final String HUMAN_READABLE_NAME = "Entity edit controller class"; + public static final String TEMPLATE = "Magento Entity Edit Action Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private final String entityName; + + /** + * Edit action (adminhtml) file. + * + * @param moduleName String + * @param entityName String + */ + public EditActionFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java new file mode 100644 index 000000000..9b891b420 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public final class IndexActionFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "Index"; + public static final String HUMAN_READABLE_NAME = "Entity list controller class"; + public static final String TEMPLATE = "Magento Entity Index Adminhtml Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private final String entityName; + + /** + * Index adminhtml controller for an entity. + * + * @param entityName String + */ + public IndexActionFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java new file mode 100644 index 000000000..0cb03f398 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public final class NewActionFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "NewAction"; + public static final String HUMAN_READABLE_NAME = "New entity controller class"; + public static final String TEMPLATE = "Magento Entity New Action Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private final String entityName; + + /** + * New action file constructor. + * + * @param moduleName String + * @param entityName String + */ + public NewActionFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java new file mode 100644 index 000000000..0064c976d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public final class SaveActionFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "Save"; + public static final String HUMAN_READABLE_NAME = "Entity save controller class"; + public static final String TEMPLATE = "Magento Entity Save Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + public static final String COULD_NOT_SAVE = + "Magento\\Framework\\Exception\\CouldNotSaveException"; + private final String entityName; + + /** + * Save action file controller. + * + * @param moduleName String + * @param entityName String + */ + public SaveActionFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java new file mode 100644 index 000000000..2093e93f8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.commands; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityByIdCommandFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "DeleteByIdCommand"; + public static final String HUMAN_READABLE_NAME = "Delete entity by id command class"; + public static final String TEMPLATE = "Magento Delete Entity By Id Command"; + private static final String DIRECTORY = "Command"; + private final String entityName; + + /** + * Delete entity by id command file constructor. + * + * @param moduleName String + * @param entityName String + */ + public DeleteEntityByIdCommandFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java new file mode 100644 index 000000000..61573a503 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.commands; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandFile extends AbstractPhpFile implements ModuleFileInterface { + + public static final String CLASS_NAME = "SaveCommand"; + public static final String TEMPLATE = "Magento Save Entity Command Model"; + public static final String HUMAN_READABLE_NAME = "Save entity command model"; + private static final String DIRECTORY = "Command"; + private final String entityName; + + /** + * Save entity command file constructor. + * + * @param moduleName String + * @param entityName String + */ + public SaveEntityCommandFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + /** + * Get directory for save command file. + * + * @return String + */ + @Override + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java new file mode 100644 index 000000000..db4732721 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.queries; + +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.packages.File; +import org.jetbrains.annotations.NotNull; + +public final class GetListQueryFile extends AbstractPhpFile { + + public static final String CLASS_NAME = "GetListQuery"; + public static final String HUMAN_READABLE_NAME = "Get list query class"; + public static final String TEMPLATE = "Magento Get List Query Model"; + private static final String DIRECTORY = "Query"; + private final String entityName; + + /** + * Get list query file constructor. + * + * @param moduleName String + * @param entityName String + */ + public GetListQueryFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME); + this.entityName = entityName; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getDirectory() { + return DIRECTORY.concat(File.separator).concat(entityName); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/HttpMethod.java b/src/com/magento/idea/magento2plugin/magento/packages/HttpMethod.java index d8c0a8c43..327f84fce 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/HttpMethod.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/HttpMethod.java @@ -5,8 +5,10 @@ package com.magento.idea.magento2plugin.magento.packages; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.NotNull; public enum HttpMethod { GET("Magento\\Framework\\App\\Action\\HttpGetActionInterface"), @@ -58,4 +60,13 @@ public static List getHttpMethodList() { return methodNameList; } + + /** + * Get name from type FQN. + * + * @return String + */ + public @NotNull String getTypeName() { + return PhpClassGeneratorUtil.getNameFromFqn(getInterfaceFqn()); + } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java b/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java new file mode 100644 index 000000000..81c05aa7a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java @@ -0,0 +1,87 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages; + +import java.util.InputMismatchException; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public enum PropertiesTypes { + INT("int"), + FLOAT("float"), + STRING("string"), + BOOL("bool"); + + private final String propertyType; + + /** + * Entity property types ENUM constructor. + * + * @param propertyType String + */ + PropertiesTypes(final String propertyType) { + this.propertyType = propertyType; + } + + /** + * Get property type. + * + * @return String + */ + public String getPropertyType() { + return propertyType; + } + + /** + * Get ENUM by its string representation. + * + * @param value String + * + * @return PropertiesTypes + */ + public static PropertiesTypes getByValue(final @NotNull String value) { + for (final PropertiesTypes type : PropertiesTypes.values()) { + if (type.getPropertyType().equals(value)) { + return type; + } + } + + throw new InputMismatchException( + "Invalid property type value provided. Should be compatible with " + + PropertiesTypes.class + ); + } + + /** + * Get property types. + * + * @return String[] array of property types. + */ + public static String[] getPropertyTypes() { + return new String[]{ + valueOf(INT.toString()).getPropertyType(), + valueOf(FLOAT.toString()).getPropertyType(), + valueOf(STRING.toString()).getPropertyType(), + valueOf(BOOL.toString()).getPropertyType() + }; + } + + /** + * Get property types list. + * + * @return List of entity property types. + */ + public static List getPropertyTypesList() { + final List propertyList = new LinkedList<>(); + + for (final PropertiesTypes property : PropertiesTypes.values()) { + propertyList.add(property.getPropertyType()); + } + + return propertyList; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/UiFormButtonTypeSettings.java b/src/com/magento/idea/magento2plugin/magento/packages/UiFormButtonTypeSettings.java new file mode 100644 index 000000000..f0e23626e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/UiFormButtonTypeSettings.java @@ -0,0 +1,157 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages; + +import java.util.InputMismatchException; +import java.util.Map; +import org.jetbrains.annotations.NotNull; + +public enum UiFormButtonTypeSettings { + + SAVE("Save", "save primary", "''", "[\n" + + " 'mage-init' => ['button' => ['event' => 'save']],\n" + + " 'form-role' => 'save'\n" + + " ]", 10, "Save entity button."), + DELETE("Delete", "delete", "'deleteConfirm(\\''\n" + + " . __('Are you sure you want to delete this $varName?')\n" + + " . '\\', \\'' . $this->getUrl('*/*/delete', ['$varId' => " + + "$this->$varEntityIdAccessor]) . '\\')'", "[]", 20, "Delete entity button."), + BACK("Back To Grid", "back", + "sprintf(\"location.href = '%s';\", $this->getUrl('*/*/'))", + "[]", 30, "Back to list button."), + CUSTOM("Custom Button", "custom", "''", "[]", 0, "Custom button."); + + private final String label; + private final String classes; + private final String onClick; + private final String dataAttrs; + private final int sortOrder; + private final String annotation; + + /** + * Ui Form button settings Enum. + * + * @param label String + * @param classes String + * @param onClick String + * @param dataAttrs String + * @param sortOrder String + */ + UiFormButtonTypeSettings( + final @NotNull String label, + final @NotNull String classes, + final @NotNull String onClick, + final @NotNull String dataAttrs, + final int sortOrder, + final String annotation + ) { + this.label = label; + this.classes = classes; + this.onClick = onClick; + this.dataAttrs = dataAttrs; + this.sortOrder = sortOrder; + this.annotation = annotation; + } + + /** + * Get ENUM by its string representation. + * + * @param value String + * + * @return UiFormButtonTypeSettings + */ + public static UiFormButtonTypeSettings getByValue(final @NotNull String value) { + for (final UiFormButtonTypeSettings type : UiFormButtonTypeSettings.values()) { + if (type.toString().equals(value)) { + return type; + } + } + + throw new InputMismatchException( + "Invalid property type value provided. Should be compatible with " + + UiFormButtonTypeSettings.class + ); + } + + /** + * Get button label. + * + * @return String + */ + public String getLabel() { + return label; + } + + /** + * Get button classes. + * + * @return String + */ + public String getClasses() { + return classes; + } + + /** + * Get on click behavior. + * + * @param variables Map + * + * @return String + */ + public String getOnClick(final Map variables) { + return parseVariables(onClick, variables); + } + + /** + * Get button data attributes. + * + * @param variables Map + * + * @return String + */ + public String getDataAttrs(final Map variables) { + return parseVariables(dataAttrs, variables); + } + + /** + * Get button sort order. + * + * @return int + */ + public int getSortOrder() { + return sortOrder; + } + + /** + * Get button annotation. + * + * @return String + */ + public String getAnnotation() { + return annotation; + } + + /** + * Parse variables. + * + * @param string String + * @param variables Map + * + * @return String + */ + private String parseVariables(final String string, final Map variables) { + if (variables.isEmpty()) { + return string; + } + String parsed = string; + + for (final Map.Entry entry : variables.entrySet()) { + parsed = parsed.replace(entry.getKey(), entry.getValue()); + } + + return parsed; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java new file mode 100644 index 000000000..434ecf17f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.code; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import org.jetbrains.annotations.NotNull; + +public enum BackendModuleType { + CONTEXT("Magento\\Backend\\App\\Action\\Context"), + EXTENDS("Magento\\Backend\\App\\Action"), + RESULT_PAGE("Magento\\Backend\\Model\\View\\Result\\Page"); + + /** + * Backend module type. + */ + private final String type; + + /** + * Backend module type ENUM constructor. + * + * @param type String + */ + BackendModuleType(final @NotNull String type) { + this.type = type; + } + + /** + * Get type. + * + * @return String + */ + public @NotNull String getType() { + return type; + } + + /** + * Get name from type FQN. + * + * @return String + */ + public @NotNull String getTypeName() { + return PhpClassGeneratorUtil.getNameFromFqn(getType()); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java new file mode 100644 index 000000000..21cbb6a98 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java @@ -0,0 +1,47 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.code; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import org.jetbrains.annotations.NotNull; + +public enum ExceptionType { + COULD_NOT_SAVE("Magento\\Framework\\Exception\\CouldNotSaveException"), + COULD_NOT_DELETE("Magento\\Framework\\Exception\\CouldNotDeleteException"), + NO_SUCH_ENTITY_EXCEPTION("Magento\\Framework\\Exception\\NoSuchEntityException"); + + /** + * Magento Exception type. + */ + private final String type; + + /** + * Magento Exception type ENUM constructor. + * + * @param type String + */ + ExceptionType(final @NotNull String type) { + this.type = type; + } + + /** + * Get type. + * + * @return String + */ + public @NotNull String getType() { + return type; + } + + /** + * Get name from type FQN. + * + * @return String + */ + public @NotNull String getTypeName() { + return PhpClassGeneratorUtil.getNameFromFqn(getType()); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java new file mode 100644 index 000000000..bf2e7fab4 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -0,0 +1,85 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.code; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil; +import org.jetbrains.annotations.NotNull; + +public enum FrameworkLibraryType { + API_SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\Search\\SearchCriteriaBuilder"), + ABSTRACT_COLLECTION( + "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection" + ), + COLLECTION_PROCESSOR("Magento\\Framework\\Api\\SearchCriteria\\CollectionProcessorInterface"), + DATA_PERSISTOR("Magento\\Framework\\App\\Request\\DataPersistorInterface"), + DATA_OBJECT("Magento\\Framework\\DataObject"), + FILTER_BUILDER("Magento\\Framework\\Api\\FilterBuilder"), + RESULT_INTERFACE("Magento\\Framework\\Controller\\ResultInterface"), + RESULT_FACTORY("Magento\\Framework\\Controller\\ResultFactory"), + RESPONSE_INTERFACE("Magento\\Framework\\App\\ResponseInterface"), + LOGGER("Psr\\Log\\LoggerInterface"), + REPORTING("Magento\\Framework\\Api\\Search\\ReportingInterface"), + REQUEST("Magento\\Framework\\App\\RequestInterface"), + SEARCH_CRITERIA("Magento\\Framework\\Api\\SearchCriteriaInterface"), + SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\SearchCriteriaBuilder"), + SEARCH_RESULT("Magento\\Framework\\Api\\SearchResultsInterface"), + URL("Magento\\Framework\\UrlInterface"); + + /** + * Factory type suffix. + */ + private static final String FACTORY_SUFFIX = "Factory"; + + /** + * Framework Library type. + */ + private final String type; + + /** + * Framework Library type ENUM constructor. + * + * @param type String + */ + FrameworkLibraryType(final @NotNull String type) { + this.type = type; + } + + /** + * Get type. + * + * @return String + */ + public @NotNull String getType() { + return type; + } + + /** + * Get name from type FQN. + * + * @return String + */ + public @NotNull String getTypeName() { + return PhpClassGeneratorUtil.getNameFromFqn(getType()); + } + + /** + * Get factory type for type. + * + * @return String + */ + public @NotNull String getFactory() { + return type.concat(FACTORY_SUFFIX); + } + + /** + * Get factory type name from factory type FQN. + * + * @return String + */ + public @NotNull String getFactoryName() { + return PhpClassGeneratorUtil.getNameFromFqn(getFactory()); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/database/ColumnAttributes.java b/src/com/magento/idea/magento2plugin/magento/packages/database/ColumnAttributes.java new file mode 100644 index 000000000..21c787377 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/database/ColumnAttributes.java @@ -0,0 +1,85 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.database; + +import java.util.InputMismatchException; +import org.jetbrains.annotations.NotNull; + +public enum ColumnAttributes { + NAME("name", null), + TYPE("xsi:type", null), + PADDING("padding", "10"), + UNSIGNED("unsigned", "true"), + NULLABLE("nullable", "false"), + IDENTITY("identity", "false"), + LENGTH("length", "255"), + PRECISION("precision", "20"), + SCALE("scale", "2"), + ON_UPDATE("on_update", "false"), + DEFAULT("default", null), + COMMENT("comment", null); + + private final String name; + private final String defaultValue; + + /** + * Column Attribute ENUM Constructor. + * + * @param name String + * @param defaultValue String + */ + ColumnAttributes(final @NotNull String name, final String defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + } + + /** + * Get column attribute name. + * + * @return String + */ + public String getName() { + return name; + } + + /** + * Get column attribute default value. + * + * @return String + */ + public String getDefault() { + return defaultValue; + } + + /** + * Check if column attribute has default value. + * + * @return boolean + */ + public boolean hasDefault() { + return defaultValue != null; + } + + /** + * Get column attribute ENUM by its name string representation. + * + * @param name String + * + * @return ColumnAttributes + */ + public static @NotNull ColumnAttributes getByName(final @NotNull String name) { + for (final ColumnAttributes attribute : ColumnAttributes.values()) { + if (attribute.getName().equals(name)) { + return attribute; + } + } + + throw new InputMismatchException( + "Invalid column attribute name provided. Should be compatible with " + + ColumnAttributes.class + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/database/PropertyToDefaultTypeMapperUtil.java b/src/com/magento/idea/magento2plugin/magento/packages/database/PropertyToDefaultTypeMapperUtil.java new file mode 100644 index 000000000..29eba08ac --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/database/PropertyToDefaultTypeMapperUtil.java @@ -0,0 +1,39 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.database; + +import com.intellij.openapi.externalSystem.service.execution.NotSupportedException; +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import org.jetbrains.annotations.NotNull; + +public final class PropertyToDefaultTypeMapperUtil { + + private PropertyToDefaultTypeMapperUtil() {} + + /** + * Get default database type for specified entity property. + * + * @param propertyType PropertiesTypes + * + * @return TableColumnTypes + */ + public static TableColumnTypes map(final @NotNull PropertiesTypes propertyType) { + switch (propertyType) { + case INT: + return TableColumnTypes.INT; + case BOOL: + return TableColumnTypes.BOOLEAN; + case FLOAT: + return TableColumnTypes.DECIMAL; + case STRING: + return TableColumnTypes.VARCHAR; + default: + throw new NotSupportedException( + "ENUMs " + PropertiesTypes.class + " property is not supported." + ); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/FormElementType.java b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/FormElementType.java new file mode 100644 index 000000000..2dc043648 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/uicomponent/FormElementType.java @@ -0,0 +1,91 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.uicomponent; + +import com.intellij.openapi.externalSystem.service.execution.NotSupportedException; +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public enum FormElementType { + + HIDDEN("hidden"), + FILE("file"), + INPUT("input"), + DATE("date"), + BOOLEAN("boolean"), + CHECKBOX("checkbox"), + CHECKBOX_SET("checkboxset"), + EMAIL("email"), + SELECT("select"), + MULTISELECT("multiselect"), + TEXT("text"), + TEXTAREA("textarea"), + PRICE("price"), + RADIO_SET("radioset"), + WYSIWYG("wysiwyg"); + + /** + * UI Component form element type. + */ + private final String type; + + /** + * Form element type constructor. + * + * @param type String + */ + FormElementType(final @NotNull String type) { + this.type = type; + } + + /** + * Get form element type. + * + * @return String + */ + public @NotNull String getType() { + return type; + } + + /** + * Get list of available types. + * + * @return List[String] of available types. + */ + public static List getTypeList() { + final List availableTypes = new LinkedList<>(); + + for (final FormElementType type : FormElementType.values()) { + availableTypes.add(type.getType()); + } + + return availableTypes; + } + + /** + * Get default form element for specified property type. + * + * @param property PropertiesTypes + * + * @return FormElementType + */ + public static FormElementType getDefaultForProperty(final @NotNull PropertiesTypes property) { + switch (property) { + case INT: + case STRING: + case FLOAT: + return FormElementType.INPUT; + case BOOL: + return FormElementType.CHECKBOX; + default: + throw new NotSupportedException( + "ENUMs " + FormElementType.class + " property is not supported." + ); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/reference/provider/ObserverNameReferenceProvider.java b/src/com/magento/idea/magento2plugin/reference/provider/ObserverNameReferenceProvider.java index 94e34c555..f44b9de62 100644 --- a/src/com/magento/idea/magento2plugin/reference/provider/ObserverNameReferenceProvider.java +++ b/src/com/magento/idea/magento2plugin/reference/provider/ObserverNameReferenceProvider.java @@ -33,6 +33,7 @@ public class ObserverNameReferenceProvider extends PsiReferenceProvider { = new EventIndex(element.getProject()).getObservers( eventName, observerName, GlobalSearchScope.allScope(element.getProject()) ); + observers.removeIf(observer -> observer == element); if (!observers.isEmpty()) { psiReferences.add(new PolyVariantReferenceBase(element, observers)); diff --git a/src/com/magento/idea/magento2plugin/reference/provider/TableColumnNamesReferenceProvider.java b/src/com/magento/idea/magento2plugin/reference/provider/TableColumnNamesReferenceProvider.java index 47e1c1218..f28c6f7df 100644 --- a/src/com/magento/idea/magento2plugin/reference/provider/TableColumnNamesReferenceProvider.java +++ b/src/com/magento/idea/magento2plugin/reference/provider/TableColumnNamesReferenceProvider.java @@ -22,6 +22,7 @@ import com.intellij.util.ProcessingContext; import com.intellij.util.indexing.FileBasedIndex; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase; import com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex; import java.util.ArrayList; @@ -120,7 +121,7 @@ public PsiReference[] getReferencesByElement( for (final XmlTag columnTag : columnTags) { final String columnName = columnTag.getAttributeValue( - ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME + ColumnAttributes.NAME.getName() ); if (columnName != null && columnName.equals(columnIdentifier)) { diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 91ae8e30e..d815864b7 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -66,8 +66,8 @@ public static class Magento { public static final String ROUTE_ID = "^[A-Za-z0-9_]{3,}$"; - public static final String ACL_RESOURCE_ID - = "^([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}$"; + public static final String XML_IDENTIFIER = + "^([A-Z]+[a-zA-Z0-9]{1,}){1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}$"; } public class PhpRegex { diff --git a/testData/actions/generation/generator/DbSchemaWhitelistGenerator/generateDbSchemaWhitelistJsonFileForShortProperties/db_schema_whitelist.json b/testData/actions/generation/generator/DbSchemaWhitelistGenerator/generateDbSchemaWhitelistJsonFileForShortProperties/db_schema_whitelist.json new file mode 100644 index 000000000..172bbebfc --- /dev/null +++ b/testData/actions/generation/generator/DbSchemaWhitelistGenerator/generateDbSchemaWhitelistJsonFileForShortProperties/db_schema_whitelist.json @@ -0,0 +1,17 @@ +{ + "test_table": { + "column": { + "entity_id": true, + "name": true, + "age": true, + "salary": true, + "is_single": true + }, + "index": { + "TEST_TABLE_ENTITY_ID": true + }, + "constraint": { + "PRIMARY": true + } + } +} diff --git a/testData/actions/generation/generator/DbSchemaXmlGenerator/generateDbSchemaXmlFileForShortProperties/db_schema.xml b/testData/actions/generation/generator/DbSchemaXmlGenerator/generateDbSchemaXmlFileForShortProperties/db_schema.xml new file mode 100644 index 000000000..c3429b510 --- /dev/null +++ b/testData/actions/generation/generator/DbSchemaXmlGenerator/generateDbSchemaXmlFileForShortProperties/db_schema.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + +
+
diff --git a/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php b/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php new file mode 100644 index 000000000..014032232 --- /dev/null +++ b/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php @@ -0,0 +1,86 @@ +logger = $logger; + $this->modelFactory = $modelFactory; + $this->resource = $resource; + } + + /** + * Delete Book. + * + * @param int $entityId + * + * @return void + * @throws CouldNotDeleteException|NoSuchEntityException + */ + public function execute(int $entityId) + { + try { + /** @var BookModel $model */ + $model = $this->modelFactory->create(); + $this->resource->load($model, $entityId, 'book_id'); + + if (!$model->getData('book_id')) { + throw new NoSuchEntityException( + __('Could not find Book with id: `%id`', + [ + 'id' => $entityId + ] + ) + ); + } + + $this->resource->delete($model); + } catch (Exception $exception) { + $this->logger->error( + __('Could not delete Book. Original message: {message}'), + [ + 'message' => $exception->getMessage(), + 'exception' => $exception + ] + ); + throw new CouldNotDeleteException(__('Could not delete Book.')); + } + } +} diff --git a/testData/actions/generation/generator/DeleteEntityGenerator/generateDeleteEntityFile/Delete.php b/testData/actions/generation/generator/DeleteEntityGenerator/generateDeleteEntityFile/Delete.php new file mode 100644 index 000000000..279f1b597 --- /dev/null +++ b/testData/actions/generation/generator/DeleteEntityGenerator/generateDeleteEntityFile/Delete.php @@ -0,0 +1,66 @@ +deleteByIdCommand = $deleteByIdCommand; + } + + /** + * Delete Company action. + * + * @return ResultInterface + */ + public function execute() + { + /** @var ResultInterface $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('*/*/'); + $entityId = (int)$this->getRequest()->getParam('company_id'); + + try { + $this->deleteByIdCommand->execute($entityId); + $this->messageManager->addSuccessMessage(__('You have successfully deleted Company entity')); + } catch (CouldNotDeleteException | NoSuchEntityException $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); + } + + return $resultRedirect; + } +} diff --git a/testData/actions/generation/generator/EditEntityActionGenerator/generateEditEntityActionFile/Edit.php b/testData/actions/generation/generator/EditEntityActionGenerator/generateEditEntityActionFile/Edit.php new file mode 100644 index 000000000..68f3ef1c2 --- /dev/null +++ b/testData/actions/generation/generator/EditEntityActionGenerator/generateEditEntityActionFile/Edit.php @@ -0,0 +1,37 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Foo_Bar::management'); + $resultPage->getConfig()->getTitle()->prepend(__('Edit Book')); + + return $resultPage; + } +} diff --git a/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php b/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php new file mode 100644 index 000000000..28c6aeef0 --- /dev/null +++ b/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php @@ -0,0 +1,52 @@ +entityDtoFactory = $entityDtoFactory; + } + + /** + * Map magento models to DTO array. + * + * @param AbstractCollection $collection + * + * @return array|UnicornDataInterface[] + */ + public function map(AbstractCollection $collection): array + { + $results = []; + /** @var UnicornModel $item */ + foreach ($collection->getItems() as $item) { + /** @var UnicornDataInterface|DataObject $entityDto */ + $entityDto = $this->entityDtoFactory->create(); + $entityDto->addData($item->getData()); + + $results[] = $entityDto; + } + + return $results; + } +} diff --git a/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php index 83c14e26b..f49694409 100644 --- a/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php +++ b/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php @@ -1,20 +1,27 @@ __('Back Button'), 'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')), 'class' => 'back', 'sort_order' => 20]; + return $this->wrapButtonSettings( + 'Back To Grid', + 'back', + sprintf("location.href = '%s';", $this->getUrl('*/*/')), + [], + 30 + ); } } diff --git a/testData/actions/generation/generator/FormButtonBlockGenerator/generateCustomButtonBlock/MyCustom.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateCustomButtonBlock/MyCustom.php index dc93f9359..2e49feeea 100644 --- a/testData/actions/generation/generator/FormButtonBlockGenerator/generateCustomButtonBlock/MyCustom.php +++ b/testData/actions/generation/generator/FormButtonBlockGenerator/generateCustomButtonBlock/MyCustom.php @@ -1,19 +1,27 @@ wrapButtonSettings( + 'Custom Button', + 'custom', + '', + [], + 0 + ); } } diff --git a/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php index f117cdb5c..dc3814f81 100644 --- a/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php +++ b/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php @@ -1,21 +1,29 @@ __('Delete Entity'), 'class' => 'delete', 'on_click' => 'deleteConfirm(\'' . __('Are you sure you want to do this?') . '\', \'' . //TODO: adjust entity ID - $this->getUrl('*/*/${BUTTON_ROUTE}', ['entity_id' => '']) . '\', {"data": {}})', 'sort_order' => 30]; + return $this->wrapButtonSettings( + 'Delete', + 'delete', + 'deleteConfirm(\'' + . __('Are you sure you want to delete this book?') + . '\', \'' . $this->getUrl('*/*/delete', ['book_id' => $this->getBookId()]) . '\')', + [], + 20 + ); } } diff --git a/testData/actions/generation/generator/FormButtonBlockGenerator/generateSaveButtonBlock/SaveBlock.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateSaveButtonBlock/SaveBlock.php index b4a979786..e13cc0bfc 100644 --- a/testData/actions/generation/generator/FormButtonBlockGenerator/generateSaveButtonBlock/SaveBlock.php +++ b/testData/actions/generation/generator/FormButtonBlockGenerator/generateSaveButtonBlock/SaveBlock.php @@ -1,21 +1,30 @@ __('Save Entity'), 'class' => 'save primary', 'on_click' => '', 'data_attribute' => ['mage-init' => ['Magento_Ui/js/form/button-adapter' => ['actions' => [['targetName' => 'my_form.my_form', 'actionName' => 'save', 'params' => [true, //TODO: adjust entity ID - ['entity_id' => ''],]]]]]]]; + return $this->wrapButtonSettings( + 'Save', + 'save primary', + '', + [ + 'mage-init' => ['button' => ['event' => 'save']], + 'form-role' => 'save' + ], + 10 + ); } } diff --git a/testData/actions/generation/generator/FormGenericButtonBlockGenerator/generateFormGenericButtonBlockFile/GenericButton.php b/testData/actions/generation/generator/FormGenericButtonBlockGenerator/generateFormGenericButtonBlockFile/GenericButton.php new file mode 100644 index 000000000..00d30defb --- /dev/null +++ b/testData/actions/generation/generator/FormGenericButtonBlockGenerator/generateFormGenericButtonBlockFile/GenericButton.php @@ -0,0 +1,84 @@ +context = $context; + $this->urlBuilder = $context->getUrlBuilder(); + } + + /** + * Get Book entity id. + * + * @return int + */ + public function getBookId(): int + { + return (int)$this->context->getRequest()->getParam('book_id'); + } + + /** + * Wrap button specific options to settings array. + * + * @param string $label + * @param string $class + * @param string $onclick + * @param array $dataAttribute + * @param int $sortOrder + * + * @return array + */ + protected function wrapButtonSettings( + string $label, + string $class, + string $onclick = '', + array $dataAttribute = [], + int $sortOrder = 0 + ): array + { + return [ + 'label' => $label, + 'on_click' => $onclick, + 'data_attribute' => $dataAttribute, + 'class' => $class, + 'sort_order' => $sortOrder + ]; + } + + /** + * Get url. + * + * @param string $route + * @param array $params + * + * @return string + */ + protected function getUrl(string $route, array $params = []): string + { + return $this->urlBuilder->getUrl($route, $params); + } +} diff --git a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php new file mode 100644 index 000000000..5b7bb0c6f --- /dev/null +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BookBlockActions.php @@ -0,0 +1,120 @@ +urlBuilder = $urlBuilder; + } + + /** + * @inheritDoc + */ + public function prepareDataSource(array $dataSource): array + { + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as &$item) { + if (isset($item['book_id'])) { + $entityName = static::ENTITY_NAME; + $urlData = ['book_id' => $item['book_id']]; + + $editUrl = $this->urlBuilder->getUrl(static::EDIT_URL_PATH, $urlData); + $deleteUrl = $this->urlBuilder->getUrl(static::DELETE_URL_PATH, $urlData); + + $item[$this->getData('name')] = [ + 'edit' => $this->getActionData($editUrl, (string)__('Edit')), + 'delete' => $this->getActionData( + $deleteUrl, + (string)__('Delete'), + (string)__('Delete %1', $entityName), + (string)__('Are you sure you want to delete a %1 record?', $entityName) + ) + ]; + } + } + } + + return $dataSource; + } + + /** + * Get action link data array. + * + * @param string $url + * @param string $label + * @param string|null $dialogTitle + * @param string|null $dialogMessage + * + * @return array + */ + private function getActionData( + string $url, + string $label, + ?string $dialogTitle = null, + ?string $dialogMessage = null + ): array + { + $data = [ + 'href' => $url, + 'label' => $label, + 'post' => true, + '__disableTmpl' => true + ]; + + if ($dialogTitle && $dialogMessage) { + $data['confirm'] = [ + 'title' => $dialogTitle, + 'message' => $dialogMessage + ]; + } + + return $data; + } +} diff --git a/testData/actions/generation/generator/IndexControllerGenerator/generateIndexControllerFile/Index.php b/testData/actions/generation/generator/IndexControllerGenerator/generateIndexControllerFile/Index.php new file mode 100644 index 000000000..1cdce7b35 --- /dev/null +++ b/testData/actions/generation/generator/IndexControllerGenerator/generateIndexControllerFile/Index.php @@ -0,0 +1,37 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + + $resultPage->setActiveMenu('Foo_Bar::book_management_menu'); + $resultPage->addBreadcrumb(__('Book'), __('Book')); + $resultPage->addBreadcrumb(__('Manage Books'), __('Manage Books')); + $resultPage->getConfig()->getTitle()->prepend(__('Book List')); + + return $resultPage; + } +} diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php index 92dd1e212..e7d0fe07b 100644 --- a/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateFile/TestCollection.php @@ -2,7 +2,7 @@ namespace Foo\Bar\Model\ResourceModel\TestModel; -use Foo\Bar\Model\ResourceModel\TestModel\TestResource; +use Foo\Bar\Model\ResourceModel\TestResource; use Foo\Bar\Model\TestModel; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; diff --git a/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php new file mode 100644 index 000000000..71afdee70 --- /dev/null +++ b/testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php @@ -0,0 +1,23 @@ +_init(Model::class, ResourceModel::class); + } +} diff --git a/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php new file mode 100644 index 000000000..dfecb9f01 --- /dev/null +++ b/testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php @@ -0,0 +1,22 @@ +_init(ResourceModel::class); + } +} diff --git a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php index 170b61c18..2e16830fd 100644 --- a/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php +++ b/testData/actions/generation/generator/ModuleResourceModelGenerator/generateFile/TestResourceModel.php @@ -17,5 +17,6 @@ class TestResourceModel extends AbstractDb protected function _construct() { $this->_init('my_table', 'entity_id'); + $this->_useIsObjectNew = true; } } diff --git a/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php new file mode 100644 index 000000000..6140d1520 --- /dev/null +++ b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php @@ -0,0 +1,37 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Foo_Bar::menu_id'); + $resultPage->getConfig()->getTitle()->prepend(__('New Company')); + + return $resultPage; + } +} diff --git a/testData/actions/generation/generator/NewEntityLayoutGenerator/generateNewEntityLayoutFile/book_book_new.xml b/testData/actions/generation/generator/NewEntityLayoutGenerator/generateNewEntityLayoutFile/book_book_new.xml new file mode 100644 index 000000000..3277893bd --- /dev/null +++ b/testData/actions/generation/generator/NewEntityLayoutGenerator/generateNewEntityLayoutFile/book_book_new.xml @@ -0,0 +1,4 @@ + + + diff --git a/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php new file mode 100644 index 000000000..d1d2182e1 --- /dev/null +++ b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php @@ -0,0 +1,94 @@ +collectionProcessor = $collectionProcessor; + $this->entityCollectionFactory = $entityCollectionFactory; + $this->entityDataMapper = $entityDataMapper; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->searchResultFactory = $searchResultFactory; + } + + /** + * Get Book list by search criteria. + * + * @param SearchCriteriaInterface|null $searchCriteria + * + * @return SearchResultsInterface + */ + public function execute(?SearchCriteriaInterface $searchCriteria = null): SearchResultsInterface + { + /** @var Collection $collection */ + $collection = $this->entityCollectionFactory->create(); + + if ($searchCriteria === null) { + $searchCriteria = $this->searchCriteriaBuilder->create(); + } else { + $this->collectionProcessor->process($searchCriteria, $collection); + } + + $entityDataObjects = $this->entityDataMapper->map($collection); + + /** @var SearchResultsInterface $searchResult */ + $searchResult = $this->searchResultFactory->create(); + $searchResult->setItems($entityDataObjects); + $searchResult->setTotalCount($collection->getSize()); + $searchResult->setSearchCriteria($searchCriteria); + + return $searchResult; + } +} diff --git a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php new file mode 100644 index 000000000..dcff220fd --- /dev/null +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php @@ -0,0 +1,93 @@ +dataPersistor = $dataPersistor; + $this->saveCommand = $saveCommand; + $this->entityDataFactory = $entityDataFactory; + } + + /** + * Save Company Action. + * + * @return ResponseInterface|ResultInterface + */ + public function execute() + { + $resultRedirect = $this->resultRedirectFactory->create(); + $params = $this->getRequest()->getParams(); + + try { + /** @var CompanyInterface|DataObject $entityModel */ + $entityModel = $this->entityDataFactory->create(); + $entityModel->addData($params['general']); + $this->saveCommand->execute($entityModel); + $this->messageManager->addSuccessMessage( + __('The Company data was saved successfully') + ); + $this->dataPersistor->clear('entity'); + } catch (CouldNotSaveException $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); + $this->dataPersistor->set('entity', $params); + + return $resultRedirect->setPath('*/*/edit', [ + 'entity_id' => $this->getRequest()->getParam('entity_id') + ]); + } + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php new file mode 100644 index 000000000..2bac73502 --- /dev/null +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php @@ -0,0 +1,93 @@ +dataPersistor = $dataPersistor; + $this->saveCommand = $saveCommand; + $this->entityDataFactory = $entityDataFactory; + } + + /** + * Save Company Action. + * + * @return ResponseInterface|ResultInterface + */ + public function execute() + { + $resultRedirect = $this->resultRedirectFactory->create(); + $params = $this->getRequest()->getParams(); + + try { + /** @var CompanyData|DataObject $entityModel */ + $entityModel = $this->entityDataFactory->create(); + $entityModel->addData($params['general']); + $this->saveCommand->execute($entityModel); + $this->messageManager->addSuccessMessage( + __('The Company data was saved successfully') + ); + $this->dataPersistor->clear('entity'); + } catch (CouldNotSaveException $exception) { + $this->messageManager->addErrorMessage($exception->getMessage()); + $this->dataPersistor->set('entity', $params); + + return $resultRedirect->setPath('*/*/edit', [ + 'entity_id' => $this->getRequest()->getParam('entity_id') + ]); + } + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php new file mode 100644 index 000000000..533eb48e5 --- /dev/null +++ b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php @@ -0,0 +1,83 @@ +logger = $logger; + $this->modelFactory = $modelFactory; + $this->resource = $resource; + } + + /** + * Save Book. + * + * @param BookData|DataObject $book + * + * @return int + * @throws CouldNotSaveException + */ + public function execute(BookData $book): int + { + try { + /** @var BookModel $model */ + $model = $this->modelFactory->create(); + $model->addData($book->getData()); + $model->setHasDataChanges(true); + + if (!$model->getId()) { + $model->isObjectNew(true); + } + $this->resource->save($model); + } catch (Exception $exception) { + $this->logger->error( + __('Could not save Book. Original message: {message}'), + [ + 'message' => $exception->getMessage(), + 'exception' => $exception + ] + ); + throw new CouldNotSaveException(__('Could not save Book.')); + } + + return (int)$model->getEntityId(); + } +} diff --git a/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml index 6685de535..15b70e2b3 100644 --- a/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml +++ b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml @@ -10,21 +10,22 @@ my_form + data.general my_form.my_form_data_source - + custom_entity_grid_columns custom_entity_grid.custom_entity_grid_data_source diff --git a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseAreaWithActionsColumnColumn/custom_entity_grid.xml b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseAreaWithActionsColumnColumn/custom_entity_grid.xml new file mode 100644 index 000000000..5fde07dbd --- /dev/null +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseAreaWithActionsColumnColumn/custom_entity_grid.xml @@ -0,0 +1,52 @@ + ++ + + custom_entity_grid.custom_entity_grid_data_source + custom_entity_grid.custom_entity_grid_data_source + + + + + + + custom_entity_grid_columns + + custom_entity_grid.custom_entity_grid_data_source + + + + + + entity_id + + + + Foo_Bar::custom_entity + + + entity_id + entity_id + + + + + + + textRange + + desc + + + + + entity_id + + + + diff --git a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml index dea2e0d54..12c11dbc2 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml @@ -8,6 +8,13 @@ + + + custom_entity_grid_columns custom_entity_grid.custom_entity_grid_data_source diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGeneratorTest.java index aa6e9e248..87f81c8a2 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGeneratorTest.java @@ -11,17 +11,18 @@ import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; public class DataModelGeneratorTest extends BaseGeneratorTestCase { + + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Model/Data"; + /** * Tests for generation of a Magento 2 Data Model. */ public void testGenerateDataModel() { final Project project = myFixture.getProject(); final DataModelData modelData = new DataModelData( - "Foo\\Bar\\Model\\Data", "Sample", + "SampleInterface", "Foo_Bar", - "Foo\\Bar\\Model\\Data\\Sample", - "Foo\\Bar\\Api\\Data\\SampleInterface", "ID_PROPERTY;id_property;int;IdProperty;idProperty," + "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty", true @@ -35,7 +36,7 @@ public void testGenerateDataModel() { assertGeneratedFileIsCorrect( expectedFile, - "src/app/code/Foo/Bar/Model/Data", + EXPECTED_DIRECTORY, modelFile ); } @@ -46,11 +47,9 @@ public void testGenerateDataModel() { public void testGenerateDataModelWithoutInterface() { final Project project = myFixture.getProject(); final DataModelData modelData = new DataModelData( - "Foo\\Bar\\Model\\Data", "Sample", + "SampleInterface", "Foo_Bar", - "Foo\\Bar\\Model\\Data\\Sample", - "Foo\\Bar\\Api\\Data\\SampleInterface", "ID_PROPERTY;id_property;int;IdProperty;idProperty," + "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty", false @@ -64,7 +63,7 @@ public void testGenerateDataModelWithoutInterface() { assertGeneratedFileIsCorrect( expectedFile, - "src/app/code/Foo/Bar/Model/Data", + EXPECTED_DIRECTORY, modelFile ); } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGeneratorTest.java index 9acbd1eb6..6ad8b4076 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGeneratorTest.java @@ -5,36 +5,32 @@ package com.magento.idea.magento2plugin.actions.generation.generator; -import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction; import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; public class DataModelInterfaceGeneratorTest extends BaseGeneratorTestCase { + + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Api/Data"; + /** * Tests for generation of a Magento 2 Data Model Interface. */ public void testGenerateDataModelInterface() { - final Project project = myFixture.getProject(); - final DataModelInterfaceData interfaceData = new DataModelInterfaceData( - "Foo\\Bar\\Api\\Data", - "SampleInterface", - "Foo_Bar", - "Foo\\Bar\\Api\\Data\\SampleInterface", - "ID_PROPERTY;id_property;int;IdProperty;idProperty," - + "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" - ); final DataModelInterfaceGenerator generator = new DataModelInterfaceGenerator( - project, interfaceData + new DataModelInterfaceData( + "SampleInterface", + "Foo_Bar", + "ID_PROPERTY;id_property;int;IdProperty;idProperty," + + "SAMPLE_PROPERTY;sample_property;string;" + + "SampleProperty;sampleProperty" + ), + myFixture.getProject() ); final PsiFile interfaceFile = generator.generate(NewDataModelAction.ACTION_NAME); final PsiFile expectedFile = myFixture.configureByFile(this.getFixturePath("SampleInterface.php")); - assertGeneratedFileIsCorrect( - expectedFile, - "src/app/code/Foo/Bar/Api/Data", - interfaceFile - ); + assertGeneratedFileIsCorrect(expectedFile, EXPECTED_DIRECTORY, interfaceFile); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java index b7aed8c09..a8d747fa5 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java @@ -6,8 +6,10 @@ package com.magento.idea.magento2plugin.actions.generation.generator; import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DbSchemaGeneratorDataProviderUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DbSchemaGeneratorUtil; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaWhitelistJson; -import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -46,6 +48,41 @@ public void testGenerateDbSchemaWhitelistJsonFile() { ); } + /** + * Test whether db_schema_whitelist.json file generated correctly + * when columns provided as short entity properties. + */ + public void testGenerateDbSchemaWhitelistJsonFileForShortProperties() { + final List> properties = + DbSchemaGeneratorDataProviderUtil.generateEntityPropertiesForTest(); + + final List> columnsData = + DbSchemaGeneratorUtil.complementShortPropertiesByDefaults(properties); + columnsData.add(0, DbSchemaGeneratorUtil.getTableIdentityColumnData("entity_id")); + + final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( + TABLE_NAME, + "", + "", + "", + columnsData + ); + final DbSchemaWhitelistJsonGenerator dbSchemaWhitelistJsonGenerator = + new DbSchemaWhitelistJsonGenerator( + myFixture.getProject(), + dbSchemaXmlData, + MODULE_NAME + ); + + final String filePath = this.getFixturePath(ModuleDbSchemaWhitelistJson.FILE_NAME); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + dbSchemaWhitelistJsonGenerator.generate("test") + ); + } + /** * Generate columns for testcase. * @@ -55,53 +92,53 @@ private List> createColumnsForTest() { final List> columns = new LinkedList<>(); final Map entityIdColumnData = new LinkedHashMap<>(); entityIdColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.INT.getColumnType() ); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "entity_id"); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, "true"); + entityIdColumnData.put(ColumnAttributes.NAME.getName(), "entity_id"); + entityIdColumnData.put(ColumnAttributes.IDENTITY.getName(), "true"); columns.add(entityIdColumnData); final Map nameColumnData = new LinkedHashMap<>(); nameColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.VARCHAR.getColumnType() ); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "name"); + nameColumnData.put(ColumnAttributes.NAME.getName(), "name"); columns.add(nameColumnData); final Map ageColumnData = new LinkedHashMap<>(); ageColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.INT.getColumnType() ); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "age"); + ageColumnData.put(ColumnAttributes.NAME.getName(), "age"); columns.add(ageColumnData); final Map salaryColumnData = new LinkedHashMap<>(); salaryColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.DECIMAL.getColumnType() ); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "salary"); + salaryColumnData.put(ColumnAttributes.NAME.getName(), "salary"); columns.add(salaryColumnData); final Map dobColumnData = new LinkedHashMap<>(); dobColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.DATE.getColumnType() ); - dobColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "dob"); + dobColumnData.put(ColumnAttributes.NAME.getName(), "dob"); columns.add(dobColumnData); final Map createdAtColumnData = new LinkedHashMap<>(); createdAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.TIMESTAMP.getColumnType() ); - createdAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "created_at"); + createdAtColumnData.put(ColumnAttributes.NAME.getName(), "created_at"); columns.add(createdAtColumnData); final Map updatedAtColumnData = new LinkedHashMap<>(); updatedAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.TIMESTAMP.getColumnType() ); - updatedAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "updated_at"); + updatedAtColumnData.put(ColumnAttributes.NAME.getName(), "updated_at"); columns.add(updatedAtColumnData); return columns; diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java index b19d69f52..5e31071f1 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java @@ -6,7 +6,10 @@ package com.magento.idea.magento2plugin.actions.generation.generator; import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DbSchemaGeneratorDataProviderUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DbSchemaGeneratorUtil; import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; +import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; import com.magento.idea.magento2plugin.magento.packages.database.TableEngines; import com.magento.idea.magento2plugin.magento.packages.database.TableResources; @@ -52,6 +55,39 @@ public void testGenerateDbSchemaXmlFile() { ); } + /** + * Test db_schema.xml file generation when columns provided as short entity properties. + */ + public void testGenerateDbSchemaXmlFileForShortProperties() { + final List> properties = + DbSchemaGeneratorDataProviderUtil.generateEntityPropertiesForTest(); + + final List> columnsData = + DbSchemaGeneratorUtil.complementShortPropertiesByDefaults(properties); + columnsData.add(0, DbSchemaGeneratorUtil.getTableIdentityColumnData("entity_id")); + + final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( + TABLE_NAME, + TABLE_RESOURCE, + TABLE_ENGINE, + TABLE_COMMENT, + columnsData + ); + final DbSchemaXmlGenerator dbSchemaXmlGenerator = new DbSchemaXmlGenerator( + dbSchemaXmlData, + myFixture.getProject(), + MODULE_NAME + ); + + final String filePath = this.getFixturePath(ModuleDbSchemaXml.FILE_NAME); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + dbSchemaXmlGenerator.generate("test") + ); + } + /** * Generate columns for testcase. * @@ -62,89 +98,89 @@ private List> createColumnsForTest() { final List> columns = new LinkedList<>(); final Map entityIdColumnData = new LinkedHashMap<>(); entityIdColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.INT.getColumnType() ); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "entity_id"); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_PADDING, "11"); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, BOOLEAN_VALUE_TRUE); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_FALSE); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, BOOLEAN_VALUE_TRUE); - entityIdColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Entity Id Column"); + entityIdColumnData.put(ColumnAttributes.NAME.getName(), "entity_id"); + entityIdColumnData.put(ColumnAttributes.PADDING.getName(), "11"); + entityIdColumnData.put(ColumnAttributes.UNSIGNED.getName(), BOOLEAN_VALUE_TRUE); + entityIdColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_FALSE); + entityIdColumnData.put(ColumnAttributes.IDENTITY.getName(), BOOLEAN_VALUE_TRUE); + entityIdColumnData.put(ColumnAttributes.COMMENT.getName(), "Entity Id Column"); columns.add(entityIdColumnData); final Map nameColumnData = new LinkedHashMap<>(); nameColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.VARCHAR.getColumnType() ); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "name"); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_FALSE); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_LENGTH, "255"); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_DEFAULT, "John Smith"); - nameColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Name Column"); + nameColumnData.put(ColumnAttributes.NAME.getName(), "name"); + nameColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_FALSE); + nameColumnData.put(ColumnAttributes.LENGTH.getName(), "255"); + nameColumnData.put(ColumnAttributes.DEFAULT.getName(), "John Smith"); + nameColumnData.put(ColumnAttributes.COMMENT.getName(), "Name Column"); columns.add(nameColumnData); final Map ageColumnData = new LinkedHashMap<>(); ageColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.INT.getColumnType() ); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "age"); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_PADDING, "5"); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, BOOLEAN_VALUE_TRUE); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_TRUE); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, BOOLEAN_VALUE_FALSE); - ageColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Age Column"); + ageColumnData.put(ColumnAttributes.NAME.getName(), "age"); + ageColumnData.put(ColumnAttributes.PADDING.getName(), "5"); + ageColumnData.put(ColumnAttributes.UNSIGNED.getName(), BOOLEAN_VALUE_TRUE); + ageColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_TRUE); + ageColumnData.put(ColumnAttributes.IDENTITY.getName(), BOOLEAN_VALUE_FALSE); + ageColumnData.put(ColumnAttributes.COMMENT.getName(), "Age Column"); columns.add(ageColumnData); final Map salaryColumnData = new LinkedHashMap<>(); salaryColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.DECIMAL.getColumnType() ); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "salary"); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_PADDING, "5"); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, BOOLEAN_VALUE_TRUE); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_FALSE); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_PRECISION, "10"); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_SCALE, "2"); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_DEFAULT, "0.0"); - salaryColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Salary Column"); + salaryColumnData.put(ColumnAttributes.NAME.getName(), "salary"); + salaryColumnData.put(ColumnAttributes.PADDING.getName(), "5"); + salaryColumnData.put(ColumnAttributes.UNSIGNED.getName(), BOOLEAN_VALUE_TRUE); + salaryColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_FALSE); + salaryColumnData.put(ColumnAttributes.PRECISION.getName(), "10"); + salaryColumnData.put(ColumnAttributes.SCALE.getName(), "2"); + salaryColumnData.put(ColumnAttributes.DEFAULT.getName(), "0.0"); + salaryColumnData.put(ColumnAttributes.COMMENT.getName(), "Salary Column"); columns.add(salaryColumnData); final Map dobColumnData = new LinkedHashMap<>(); dobColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.DATE.getColumnType() ); - dobColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "dob"); - dobColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_TRUE); - dobColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Date Of The Birth Column"); + dobColumnData.put(ColumnAttributes.NAME.getName(), "dob"); + dobColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_TRUE); + dobColumnData.put(ColumnAttributes.COMMENT.getName(), "Date Of The Birth Column"); columns.add(dobColumnData); final Map createdAtColumnData = new LinkedHashMap<>(); createdAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.TIMESTAMP.getColumnType() ); - createdAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "created_at"); - createdAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_FALSE); - createdAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_ON_UPDATE, BOOLEAN_VALUE_FALSE); + createdAtColumnData.put(ColumnAttributes.NAME.getName(), "created_at"); + createdAtColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_FALSE); + createdAtColumnData.put(ColumnAttributes.ON_UPDATE.getName(), BOOLEAN_VALUE_FALSE); createdAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_DEFAULT, + ColumnAttributes.DEFAULT.getName(), CURRENT_TIMESTAMP_DEFAULT_VALUE ); - createdAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Created At Column"); + createdAtColumnData.put(ColumnAttributes.COMMENT.getName(), "Created At Column"); columns.add(createdAtColumnData); final Map updatedAtColumnData = new LinkedHashMap<>(); updatedAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + ColumnAttributes.TYPE.getName(), TableColumnTypes.TIMESTAMP.getColumnType() ); - updatedAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NAME, "updated_at"); - updatedAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, BOOLEAN_VALUE_FALSE); - updatedAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_ON_UPDATE, BOOLEAN_VALUE_TRUE); + updatedAtColumnData.put(ColumnAttributes.NAME.getName(), "updated_at"); + updatedAtColumnData.put(ColumnAttributes.NULLABLE.getName(), BOOLEAN_VALUE_FALSE); + updatedAtColumnData.put(ColumnAttributes.ON_UPDATE.getName(), BOOLEAN_VALUE_TRUE); updatedAtColumnData.put( - ModuleDbSchemaXml.XML_ATTR_COLUMN_DEFAULT, + ColumnAttributes.DEFAULT.getName(), CURRENT_TIMESTAMP_DEFAULT_VALUE ); - updatedAtColumnData.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT, "Updated At Column"); + updatedAtColumnData.put(ColumnAttributes.COMMENT.getName(), "Updated At Column"); columns.add(updatedAtColumnData); return columns; diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityCommandGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityCommandGeneratorTest.java new file mode 100644 index 000000000..bea393ebd --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityCommandGeneratorTest.java @@ -0,0 +1,51 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData; +import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; + +public class DeleteEntityCommandGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String MODEL_NAME = ENTITY_NAME + "Model"; + private static final String RESOURCE_MODEL_NAME = ENTITY_NAME + "Resource"; + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Command/" + ENTITY_NAME; + private static final String ENTITY_ID = "book_id"; + + /** + * Test generation of DeleteByIdCommand model for entity. + */ + public void testGenerateDeleteEntityByIdCommandFile() { + final DeleteEntityByIdCommandData deleteEntityByIdCommandData = + new DeleteEntityByIdCommandData( + MODULE_NAME, + ENTITY_NAME, + ENTITY_ID, + MODEL_NAME, + RESOURCE_MODEL_NAME + ); + final DeleteEntityByIdCommandGenerator deleteEntityByIdCommandGenerator = + new DeleteEntityByIdCommandGenerator( + deleteEntityByIdCommandData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + new DeleteEntityByIdCommandFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + final PsiFile deleteEntityCommandFile = deleteEntityByIdCommandGenerator.generate("test"); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + deleteEntityCommandFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java new file mode 100644 index 000000000..2533f44e5 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData; +import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile; + +public class DeleteEntityGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Company"; + private static final String ACL = "Foo_Bar::company_id"; + private static final String ENTITY_ID = "company_id"; + private static final String EXPECTED_DIRECTORY = + "/src/app/code/Foo/Bar/Controller/Adminhtml/" + ENTITY_NAME; + + /** + * Test generation of Delete controller. + */ + public void testGenerateDeleteEntityFile() { + final DeleteEntityControllerFileData deleteEntityControllerFileData = + new DeleteEntityControllerFileData( + ENTITY_NAME, + MODULE_NAME, + ACL, + ENTITY_ID + ); + final DeleteEntityControllerFileGenerator deleteEntityControllerFileGenerator = + new DeleteEntityControllerFileGenerator( + deleteEntityControllerFileData, + myFixture.getProject() + ); + final PsiFile deleteEntityActionFile = + deleteEntityControllerFileGenerator.generate("test"); + final String filePath = + this.getFixturePath(new DeleteActionFile(MODULE_NAME, ENTITY_NAME).getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + deleteEntityActionFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java new file mode 100644 index 000000000..5d3040662 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java @@ -0,0 +1,48 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; +import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile; + +public class EditEntityActionGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String EXPECTED_DIRECTORY = + "/src/app/code/Foo/Bar/Controller/Adminhtml/" + ENTITY_NAME; + private static final String ACL = "Foo_Bar::management"; + private static final String MENU = "Foo_Bar::management"; + + /** + * Test generation of edit entity controller file. + */ + public void testGenerateEditEntityActionFile() { + final EditActionFile file = new EditActionFile(MODULE_NAME, ENTITY_NAME); + final EditEntityActionGenerator generator = + new EditEntityActionGenerator( + new EditEntityActionData( + ENTITY_NAME, + MODULE_NAME, + ACL, + MENU + ), + myFixture.getProject(), + false + ); + + final PsiFile resultFile = generator.generate("test"); + final String filePath = this.getFixturePath(file.getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + resultFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java new file mode 100644 index 000000000..8654857c2 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; + +public class EntityDataMapperClassGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Mapper"; + private static final String ENTITY_NAME = "Unicorn"; + private static final String MODEL_NAME = "UnicornModel"; + private static final String DTO_NAME = "UnicornData"; + private static final String DTO_INTERFACE_NAME = "UnicornDataInterface"; + private static final boolean DTO_HAS_INTERFACE = true; + + /** + * Test generation of entity data mapper class. + */ + public void testGenerateEntityDataMapperFile() { + final EntityDataMapperData entityDataMapperData = new EntityDataMapperData( + MODULE_NAME, + ENTITY_NAME, + MODEL_NAME, + DTO_NAME, + DTO_INTERFACE_NAME, + DTO_HAS_INTERFACE + ); + final EntityDataMapperGenerator entityDataMapperGenerator = + new EntityDataMapperGenerator( + entityDataMapperData, + myFixture.getProject(), + false + ); + final EntityDataMapperFile entityDataMapperFile = + new EntityDataMapperFile(MODULE_NAME, ENTITY_NAME); + final String filePath = this.getFixturePath(entityDataMapperFile.getFileName()); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + entityDataMapperGenerator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java index b339741ad..7a94f1ded 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java @@ -11,11 +11,15 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; public class FormButtonBlockGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE_NAME = "Foo_Bar"; private static final String FORM_NAME = "my_form"; - private static final String BLOCK_DIRECTORY = "Block/Form"; + private static final String ENTITY_NAME = "Book"; + private static final String BLOCK_DIRECTORY = "Block/Form/" + ENTITY_NAME; private static final String ACTION_NAME = "test"; - public static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Block/Form"; + private static final String ENTITY_ID = "book_id"; + public static final String EXPECTED_DIRECTORY + = "src/app/code/Foo/Bar/Block/Form/" + ENTITY_NAME; /** * Test creation Block type Save. @@ -42,11 +46,14 @@ public void testGenerateSaveButtonBlock() { FORM_NAME, namespace.getClassFqn() ); - final UiComponentFormButtonPhpClassGenerator formButtonPhpClassGenerator = - new UiComponentFormButtonPhpClassGenerator( - uiComponentFormButtonData, - project - ); + final UiComponentFormButtonBlockGenerator formButtonPhpClassGenerator = + new UiComponentFormButtonBlockGenerator( + uiComponentFormButtonData, + project, + ENTITY_NAME, + ENTITY_ID, + false + ); final PsiFile file = formButtonPhpClassGenerator.generate(ACTION_NAME); assertGeneratedFileIsCorrect(expectedFile, EXPECTED_DIRECTORY, file); @@ -77,10 +84,13 @@ public void testGenerateBackButtonBlock() { FORM_NAME, namespace.getClassFqn() ); - final UiComponentFormButtonPhpClassGenerator formButtonPhpClassGenerator = - new UiComponentFormButtonPhpClassGenerator( + final UiComponentFormButtonBlockGenerator formButtonPhpClassGenerator = + new UiComponentFormButtonBlockGenerator( uiComponentFormButtonData, - project + project, + ENTITY_NAME, + ENTITY_ID, + false ); final PsiFile file = formButtonPhpClassGenerator.generate(ACTION_NAME); @@ -112,13 +122,16 @@ public void testGenerateDeleteButtonBlock() { FORM_NAME, namespace.getClassFqn() ); - final UiComponentFormButtonPhpClassGenerator formButtonPhpClassGenerator = - new UiComponentFormButtonPhpClassGenerator( - uiComponentFormButtonData, - project + final UiComponentFormButtonBlockGenerator generator = + new UiComponentFormButtonBlockGenerator( + uiComponentFormButtonData, + project, + ENTITY_NAME, + ENTITY_ID, + false ); - final PsiFile file = formButtonPhpClassGenerator.generate(ACTION_NAME); + final PsiFile file = generator.generate(ACTION_NAME); assertGeneratedFileIsCorrect(expectedFile, EXPECTED_DIRECTORY, file); } @@ -147,10 +160,13 @@ public void testGenerateCustomButtonBlock() { FORM_NAME, namespace.getClassFqn() ); - final UiComponentFormButtonPhpClassGenerator formButtonPhpClassGenerator = - new UiComponentFormButtonPhpClassGenerator( - uiComponentFormButtonData, - project + final UiComponentFormButtonBlockGenerator formButtonPhpClassGenerator = + new UiComponentFormButtonBlockGenerator( + uiComponentFormButtonData, + project, + ENTITY_NAME, + ENTITY_ID, + false ); final PsiFile file = formButtonPhpClassGenerator.generate(ACTION_NAME); diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java new file mode 100644 index 000000000..6df775add --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java @@ -0,0 +1,44 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; +import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; + +public class FormGenericButtonBlockGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String ENTITY_ID = "book_id"; + private static final String EXPECTED_DIRECTORY + = "src/app/code/Foo/Bar/Block/Form/" + ENTITY_NAME; + + /** + * Test generation of form ui component generic button block. + */ + public void testGenerateFormGenericButtonBlockFile() { + final FormGenericButtonBlockData data = new FormGenericButtonBlockData( + MODULE_NAME, + ENTITY_NAME, + ENTITY_ID + ); + final FormGenericButtonBlockGenerator generator = + new FormGenericButtonBlockGenerator( + data, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + new FormGenericButtonBlockFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + generator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java new file mode 100644 index 000000000..e5943a706 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java @@ -0,0 +1,41 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; +import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; + +public class GridActionColumnFileGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String ENTITY_ID_COLUMN = "book_id"; + private static final String EDIT_URL_PATH = "book_book_edit"; + private static final String DELETE_URL_PATH = "book_book_delete"; + + /** + * Test generation of grid actions column file. + */ + public void testGenerateGridActionColumnFile() { + final GridActionColumnFile file = new GridActionColumnFile(MODULE_NAME, ENTITY_NAME); + final GridActionColumnData data = new GridActionColumnData( + MODULE_NAME, + ENTITY_NAME, + ENTITY_ID_COLUMN, + EDIT_URL_PATH, + DELETE_URL_PATH + ); + final String filePath = this.getFixturePath(file.getFileName()); + final GridActionColumnFileGenerator generator = + new GridActionColumnFileGenerator(data, myFixture.getProject(), false); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + "src/app/code/Foo/Bar/".concat(file.getDirectory()), + generator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/IndexControllerGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/IndexControllerGeneratorTest.java new file mode 100644 index 000000000..68b821448 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/IndexControllerGeneratorTest.java @@ -0,0 +1,39 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.IndexActionData; +import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; + +public class IndexControllerGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String ACL = "Foo_Bar::book_management"; + private static final String MENU = "Foo_Bar::book_management_menu"; + + /** + * Test generation of list view entity controller (adminhtml). + */ + public void testGenerateIndexControllerFile() { + final IndexActionFile file = new IndexActionFile(MODULE_NAME, ENTITY_NAME); + final IndexActionData data = new IndexActionData( + MODULE_NAME, + ENTITY_NAME, + ACL, + MENU + ); + final String filePath = this.getFixturePath(file.getFileName()); + final IndexActionGenerator generator = + new IndexActionGenerator(data, myFixture.getProject(), false); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + "src/app/code/Foo/Bar/".concat(file.getDirectory()), + generator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGeneratorTest.java index 905539824..d3aac20ce 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGeneratorTest.java @@ -10,6 +10,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; public class ModuleCollectionGeneratorTest extends BaseGeneratorTestCase { + /** * Test generation of collection file. */ @@ -19,26 +20,45 @@ public void testGenerateFile() { "Foo_Bar", "my_table", "TestModel", - "TestCollection", - "Foo\\Bar\\Model\\ResourceModel\\TestModel\\TestCollection", - "Model/ResourceModel/TestModel", - "Foo\\Bar\\Model\\ResourceModel\\TestModel", "TestResource", - "Foo\\Bar\\Model\\ResourceModel\\TestModel\\TestResource", - "Foo\\Bar\\Model\\TestModel" + "TestCollection", + "TestModel" ); final ModuleCollectionGenerator generator = new ModuleCollectionGenerator( collectionFileData, project ); - final PsiFile controllerFile = generator.generate("test"); + final PsiFile collectionFile = generator.generate("test"); final String filePath = this.getFixturePath("TestCollection.php"); final PsiFile expectedFile = myFixture.configureByFile(filePath); assertGeneratedFileIsCorrect( expectedFile, "src/app/code/Foo/Bar/Model/ResourceModel/TestModel", - controllerFile + collectionFile + ); + } + + /** + * Test generation of collection file where resource model name equal to the model name. + */ + public void testGenerateWithTheSameNamesForResourceModelAndModel() { + final PsiFile collectionFile = new ModuleCollectionGenerator( + new CollectionData( + "Foo_Bar", + "my_table", + "Test", + "Test", + "Collection", + "Test" + ), + myFixture.getProject() + ).generate("test"); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(this.getFixturePath("Collection.php")), + "src/app/code/Foo/Bar/Model/ResourceModel/Test", + collectionFile ); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGeneratorTest.java index 8a51b9274..b673ced26 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGeneratorTest.java @@ -10,6 +10,9 @@ import com.magento.idea.magento2plugin.actions.generation.data.ModelData; public class ModuleModelGeneratorTest extends BaseGeneratorTestCase { + + private static final String EXPECTED_DIR = "src/app/code/Foo/Bar/Model"; + /** * Test generation of model file. */ @@ -19,23 +22,41 @@ public void testGenerateFile() { "Foo_Bar", "my_table", "TestModel", - "TestResource", - "Foo\\Bar\\Model\\TestModel", - "Foo\\Bar\\Model", - "Foo\\Bar\\Model\\ResourceModel\\TestResource" + "TestResource" ); final ModuleModelGenerator generator = new ModuleModelGenerator( modelData, project ); - final PsiFile controllerFile = generator.generate("test"); + final PsiFile modelFile = generator.generate("test"); final String filePath = this.getFixturePath("TestModel.php"); final PsiFile expectedFile = myFixture.configureByFile(filePath); assertGeneratedFileIsCorrect( expectedFile, - "src/app/code/Foo/Bar/Model", - controllerFile + EXPECTED_DIR, + modelFile + ); + } + + /** + * Test generation of model file where resource model name equal to the model name. + */ + public void testGenerateWithTheSameNameForResourceModel() { + final PsiFile modelFile = new ModuleModelGenerator( + new ModelData( + "Foo_Bar", + "my_table", + "Test", + "Test" + ), + myFixture.getProject() + ).generate("test"); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(this.getFixturePath("Test.php")), + EXPECTED_DIR, + modelFile ); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGeneratorTest.java index ebf707249..bbf36c78d 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGeneratorTest.java @@ -10,6 +10,9 @@ import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; public class ModuleResourceModelGeneratorTest extends BaseGeneratorTestCase { + + private static final String EXPECTED_DIR = "src/app/code/Foo/Bar/Model/ResourceModel"; + /** * Test generation of resource model file. */ @@ -19,22 +22,20 @@ public void testGenerateFile() { "Foo_Bar", "my_table", "TestResourceModel", - "entity_id", - "Foo\\Bar\\Model\\ResourceModel", - "Foo\\Bar\\Model\\ResourceModel\\TestModel" + "entity_id" ); final ModuleResourceModelGenerator generator = new ModuleResourceModelGenerator( resourceModelData, project ); - final PsiFile controllerFile = generator.generate("test"); + final PsiFile resourceModelFile = generator.generate("test"); final String filePath = this.getFixturePath("TestResourceModel.php"); final PsiFile expectedFile = myFixture.configureByFile(filePath); assertGeneratedFileIsCorrect( expectedFile, - "src/app/code/Foo/Bar/Model/ResourceModel", - controllerFile + EXPECTED_DIR, + resourceModelFile ); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java new file mode 100644 index 000000000..ee518d05a --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java @@ -0,0 +1,53 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; +import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; + +public class NewActionEntityGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Company"; + private static final String EXPECTED_DIRECTORY = + "/src/app/code/Foo/Bar/Controller/Adminhtml/" + ENTITY_NAME; + private static final String NAMESPACE = + "Foo\\Bar\\Controller\\Adminhtml\\" + ENTITY_NAME; + private static final String ACL = "Foo_Bar::company_id"; + private static final String MENU = "Foo_Bar::menu_id"; + + + /** + * Test generation of NewAction controller. + */ + public void testGenerateNewActionEntityFile() { + final NewActionEntityControllerFileData newActionEntityControllerFileData = + new NewActionEntityControllerFileData( + ENTITY_NAME, + MODULE_NAME, + NAMESPACE, + ACL, + MENU + ); + final NewActionEntityControllerFileGenerator newActionEntityControllerFileGenerator = + new NewActionEntityControllerFileGenerator( + newActionEntityControllerFileData, + myFixture.getProject() + ); + final PsiFile newActionEntityActionFile = + newActionEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath( + new NewActionFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + newActionEntityActionFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGeneratorTest.java new file mode 100644 index 000000000..a7f637c95 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGeneratorTest.java @@ -0,0 +1,46 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; +import com.magento.idea.magento2plugin.magento.files.NewEntityLayoutFile; +import com.magento.idea.magento2plugin.magento.packages.File; + +public class NewEntityLayoutGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String EDIT_ACTION = "book/book/edit"; + private static final String NEW_ACTION = "book/book/new"; + + /** + * Test new entity layout file generation. + */ + public void testGenerateNewEntityLayoutFile() { + final NewEntityLayoutData data = new NewEntityLayoutData( + MODULE_NAME, + NEW_ACTION, + EDIT_ACTION + ); + final NewEntityLayoutFile file = + new NewEntityLayoutFile(data.getNewActionPath().replace(File.separator, "_")); + + final NewEntityLayoutGenerator generator = new NewEntityLayoutGenerator( + data, + myFixture.getProject(), + false + ); + final PsiFile newActionLayoutFile = generator.generate("test"); + final String filePath = this.getFixturePath(file.getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + file.getDirectory(), + newActionLayoutFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGeneratorTest.java index a72a26176..ef04e5ec9 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGeneratorTest.java @@ -7,20 +7,18 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; -import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.magento.files.ModuleDiXml; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; -import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; public class PreferenceDiXmlGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE = "Foo_Bar"; private static final String MODULE_DIR = "src/app/code/Foo/Bar/"; private static final String TARGET_MODEL_ONE_CLASS_FQN = "Foo\\Bar\\Model\\SimpleModelOne"; private static final String TARGET_MODEL_TWO_CLASS_FQN = "Foo\\Bar\\Model\\SimpleModelTwo"; - private static final String NAMESPACE = "Foo\\Bar\\Model\\Override"; /** * Test preference DI XML file generation. @@ -96,6 +94,7 @@ public void testAddTwoPreferencesToOneDiXmlFile() { * @param targetClassFnq Target class FQN * @param preferenceFqn Preference FQN * @param area Area + * * @return PsiFile */ private PsiFile addPreferenceDiXml( @@ -104,12 +103,10 @@ private PsiFile addPreferenceDiXml( final String area ) { final Project project = myFixture.getProject(); - final PhpClass targetClass = GetPhpClassByFQN.getInstance(project).execute(targetClassFnq); final PreferenceDiXmFileData preferenceDiXmlFileData = new PreferenceDiXmFileData( MODULE, - targetClass, + targetClassFnq, preferenceFqn, - NAMESPACE, area ); final PreferenceDiXmlGenerator moduleXmlGenerator = new PreferenceDiXmlGenerator( @@ -124,6 +121,7 @@ private PsiFile addPreferenceDiXml( * Get expected directory based on provided area. * * @param area Area name + * * @return String */ private String getExpectedDirectory(final String area) { diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueryModelGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueryModelGeneratorTest.java new file mode 100644 index 000000000..5c6728351 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueryModelGeneratorTest.java @@ -0,0 +1,43 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; +import com.magento.idea.magento2plugin.magento.files.queries.GetListQueryFile; + +public class QueryModelGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String MODEL_NAME = "Book"; + private static final String COLLECTION_NAME = "Collection"; + + /** + * Test generation of GetListQuery model for entity. + */ + public void testGenerateGetListQueryModelFile() { + final GetListQueryFile file = new GetListQueryFile(MODULE_NAME, ENTITY_NAME); + final GetListQueryModelData getListQueryModelData = new GetListQueryModelData( + MODULE_NAME, + ENTITY_NAME, + MODEL_NAME, + COLLECTION_NAME + ); + final GetListQueryModelGenerator getListQueryModelGenerator = + new GetListQueryModelGenerator( + getListQueryModelData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath(file.getFileName()); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + file.getDirectory(), + getListQueryModelGenerator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java new file mode 100644 index 000000000..4ea056ff0 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java @@ -0,0 +1,88 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; +import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; + +public class SaveEntityActionGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Company"; + private static final String DTO_NAME = "CompanyData"; + private static final String DTO_TYPE_INTERFACE = "CompanyInterface"; + private static final String EXPECTED_DIRECTORY = + "/src/app/code/Foo/Bar/Controller/Adminhtml/" + ENTITY_NAME; + private static final String ACL = "Foo_Bar::company_id"; + private static final String ENTITY_ID = "entity_id"; + + /** + * Test generation of Save controller for entity without interface. + */ + public void testGenerateSaveEntityActionWithoutInterfaceFile() { + final SaveEntityControllerFileData saveEntityControllerFileData = + new SaveEntityControllerFileData( + ENTITY_NAME, + MODULE_NAME, + ACL, + ENTITY_ID, + DTO_NAME, + "", + false + ); + final SaveEntityControllerFileGenerator saveEntityControllerFileGenerator = + new SaveEntityControllerFileGenerator( + saveEntityControllerFileData, + myFixture.getProject(), + false + ); + final PsiFile saveEntityActionFile = saveEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath( + new SaveActionFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + saveEntityActionFile + ); + } + + /** + * Test generation of Save controller for entity with interface. + */ + public void testGenerateSaveEntityActionWithInterfaceFile() { + final SaveEntityControllerFileData saveEntityControllerFileData = + new SaveEntityControllerFileData( + ENTITY_NAME, + MODULE_NAME, + ACL, + ENTITY_ID, + DTO_NAME, + DTO_TYPE_INTERFACE, + true + ); + final SaveEntityControllerFileGenerator saveEntityControllerFileGenerator = + new SaveEntityControllerFileGenerator( + saveEntityControllerFileData, + myFixture.getProject(), + false + ); + final PsiFile saveEntityActionFile = saveEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath( + new SaveActionFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + saveEntityActionFile + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java new file mode 100644 index 000000000..2a677b6c8 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java @@ -0,0 +1,50 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; +import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; + +public class SaveEntityCommandGeneratorTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String MODEL_NAME = ENTITY_NAME + "Model"; + private static final String RESOURCE_MODEL_NAME = ENTITY_NAME + "Resource"; + private static final String DTO_NAME = ENTITY_NAME + "Data"; + private static final boolean IS_DTO_HAS_INTERFACE = false; + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Command/" + ENTITY_NAME; + + /** + * Test generation of SaveCommand model for entity. + */ + public void testGenerateSaveEntityCommandFile() { + final SaveEntityCommandData saveEntityCommandData = new SaveEntityCommandData( + MODULE_NAME, + ENTITY_NAME, + MODEL_NAME, + RESOURCE_MODEL_NAME, + DTO_NAME, + "", + IS_DTO_HAS_INTERFACE + ); + final SaveEntityCommandGenerator saveEntityCommandGenerator = + new SaveEntityCommandGenerator( + saveEntityCommandData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + new SaveEntityCommandFile(MODULE_NAME, ENTITY_NAME).getFileName() + ); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + saveEntityCommandGenerator.generate("test") + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGeneratorTest.java index 1d8c44acb..5aaf11a31 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGeneratorTest.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull; public class UiComponentFormGeneratorTest extends BaseGeneratorTestCase { + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/view/adminhtml/ui_component"; private static final String MODULE_NAME = "Foo_Bar"; @@ -33,9 +34,9 @@ public void testGenerateFormXmlFile() { final PsiFile expectedFile = myFixture.configureByFile(filePath); final Project project = myFixture.getProject(); - final List buttons = getButtons(); - final List fieldsets = getFieldsets(); - final List fields = getFields(); + final List buttons = getButtons(); + final List fieldsets = getFieldsets(); + final List fields = getFields(); final UiComponentFormFileData uiComponentFormData = new UiComponentFormFileData( FORM_NAME, @@ -48,7 +49,8 @@ public void testGenerateFormXmlFile() { ROUTE, "MyEntity", "Save", - "Foo/Bar/Ui/MyEntity/DataProvider" + "DataProvider", + "Ui/MyEntity" ); final UiComponentFormGenerator uiComponentFormGenerator = new UiComponentFormGenerator( uiComponentFormData, @@ -59,9 +61,14 @@ public void testGenerateFormXmlFile() { assertGeneratedFileIsCorrect(expectedFile, EXPECTED_DIRECTORY, file); } - @NotNull - protected List getFields() { - final List fields = new ArrayList(); + /** + * Get fields data. + * + * @return List + */ + protected @NotNull List getFields() { + final List fields = new ArrayList<>(); + fields.add(new UiComponentFormFieldData( "my_field", "My Field", @@ -80,12 +87,18 @@ protected List getFields() { "text", "entity" )); + return fields; } - @NotNull - protected List getFieldsets() { - final List fieldsets = new ArrayList(); + /** + * Get fieldSets data. + * + * @return List + */ + protected @NotNull List getFieldsets() { + final List fieldsets = new ArrayList<>(); + fieldsets.add(new UiComponentFormFieldsetData( "general", "General", @@ -96,14 +109,20 @@ protected List getFieldsets() { "Test Fieldset", "20" )); + return fieldsets; } - @NotNull - protected List getButtons() { - final List buttons = new ArrayList(); + /** + * Get buttons data. + * + * @return List + */ + protected @NotNull List getButtons() { + final List buttons = new ArrayList<>(); final String namespace = "Foo/Bar/Block/Form"; final String directory = "Block/Form"; + buttons.add(new UiComponentFormButtonData( directory, "SaveEntity", @@ -113,7 +132,7 @@ protected List getButtons() { "Save Entity", "10", FORM_NAME, - "Foo/Bar/Block/Form/Save" + "Foo\\Bar\\Block\\Form\\Save" )); buttons.add(new UiComponentFormButtonData( directory, @@ -124,7 +143,7 @@ protected List getButtons() { "Back To Grid", "20", FORM_NAME, - "Foo/Bar/Block/Form/Back" + "Foo\\Bar\\Block\\Form\\Back" )); buttons.add(new UiComponentFormButtonData( directory, @@ -135,7 +154,7 @@ protected List getButtons() { "Delete Entity", "30", FORM_NAME, - "Foo/Bar/Block/Form/Delete" + "Foo\\Bar\\Block\\Form\\Delete" )); buttons.add(new UiComponentFormButtonData( directory, @@ -146,8 +165,9 @@ protected List getButtons() { "Custom Button", "40", FORM_NAME, - "Foo/Bar/Block/Form/Custom" + "Foo\\Bar\\Block\\Form\\Custom" )); + return buttons; } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java index fa7e920b6..057782ca9 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java @@ -7,20 +7,28 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; public class UiComponentGridDataProviderGeneratorTest extends BaseGeneratorTestCase { + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Ui/Component/Listing"; private static final String MODULE_NAME = "Foo_Bar"; + private static final String ENTITY_NAME = "Book"; + private static final String ENTITY_ID_FIELD_NAME = "entity_id"; + private static final String MODEL_NAME = "Book"; private static final String PROVIDER_CLASS_NAME = "GridDataProvider"; - private static final String PROVIDER_NAMESPACE = "Foo\\Bar\\Ui\\Listing"; private static final String PROVIDER_PATH = "Ui/Component/Listing"; + private static final String COLLECTION_NAME = "Collection"; /** * Test data provider class file generation with custom type. */ public void testGenerateCustomDataProvider() { - final PsiFile dataProviderFile = generateDataProvider(); + final PsiFile dataProviderFile = generateDataProvider(new UiComponentDataProviderData( + PROVIDER_CLASS_NAME, + PROVIDER_PATH + )); final String filePath = this.getFixturePath("GridDataProvider.php"); final PsiFile expectedFile = myFixture.configureByFile(filePath); @@ -31,20 +39,53 @@ public void testGenerateCustomDataProvider() { ); } - private PsiFile generateDataProvider() { - final Project project = myFixture.getProject(); - final UiComponentDataProviderData providerData = new UiComponentDataProviderData( + /** + * Test data provider class file generation when get list query model exists. + */ + public void testGenerateDataProviderWithInjectedGetListQuery() { + generateGetListQuery(); + final PsiFile dataProviderFile = generateDataProvider(new UiComponentDataProviderData( PROVIDER_CLASS_NAME, - PROVIDER_NAMESPACE, - PROVIDER_PATH + PROVIDER_PATH, + ENTITY_NAME, + ENTITY_ID_FIELD_NAME + )); + final String filePath = this.getFixturePath("GridDataProvider.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + dataProviderFile ); - final UiComponentDataProviderGenerator generator; - generator = new UiComponentDataProviderGenerator( - providerData, + } + + /** + * Generate data provider file. + * + * @return PsiFile + */ + private PsiFile generateDataProvider(final UiComponentDataProviderData data) { + final Project project = myFixture.getProject(); + + return new UiComponentDataProviderGenerator( + data, MODULE_NAME, project - ); + ).generate("test"); + } - return generator.generate("test"); + /** + * Generate get list query model file. + */ + private void generateGetListQuery() { + final Project project = myFixture.getProject(); + final GetListQueryModelData getListData = new GetListQueryModelData( + MODULE_NAME, + ENTITY_NAME, + MODEL_NAME, + COLLECTION_NAME + ); + new GetListQueryModelGenerator(getListData, project, false).generate("test"); } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGeneratorTest.java index 7a7caf4b1..223544ee5 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGeneratorTest.java @@ -12,14 +12,18 @@ import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; +import java.util.ArrayList; public class UiComponentGridXmlGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE_DIRECTORY = "src/app/code/Foo/Bar/"; private static final String MODULE_NAME = "Foo_Bar"; private static final String COMPONENT_NAME = "custom_entity_grid"; + private static final String ENTITY_NAME = "Book"; private static final String ID_FIELD_NAME = "entity_id"; private static final String ACL = "Foo_Bar::custom_entity"; - private static final String PROVIDER_CLASS_NAME = "Foo\\Bar\\Ui\\Listing\\DataProvider"; + private static final String DATA_PROVIDER_NAME = "DataProvider"; + private static final String DATA_PROVIDER_PATH = "Ui/Listing"; /** * Test UI component listing file generation for specific area. @@ -51,6 +55,26 @@ public void testGenerateUiGridWithoutToolbar() { assertGeneratedFileIsCorrect(expectedFile, getExpectedDirectory(area), cronGroupsXmlFile); } + /** + * Test UI component listing file generation with actions column. + */ + public void testGenerateUiGridForBaseAreaWithActionsColumnColumn() { + final String area = Areas.base.toString(); + final PsiFile cronGroupsXmlFile = generateComponentGridXmlWithActionsColumn(area); + final String filePath = this.getFixturePath(String.format("%s.%s", COMPONENT_NAME, "xml")); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect(expectedFile, getExpectedDirectory(area), cronGroupsXmlFile); + } + + /** + * Generate UI Component Grid Xml file. + * + * @param area String + * @param addToolbar boolean + * + * @return PsiFile + */ private PsiFile generateComponentGridXml( final String area, final boolean addToolbar @@ -68,9 +92,10 @@ private PsiFile generateComponentGridXml( MODULE_NAME, area, COMPONENT_NAME, - PROVIDER_CLASS_NAME, ID_FIELD_NAME, ACL, + DATA_PROVIDER_NAME, + DATA_PROVIDER_PATH, uiGridToolbarData ); final UiComponentGridXmlGenerator uiGridXmlGenerator = new UiComponentGridXmlGenerator( @@ -81,6 +106,45 @@ private PsiFile generateComponentGridXml( return uiGridXmlGenerator.generate("test"); } + /** + * Generate UI Component Grid Xml file with actions column. + * + * @param area String + * + * @return PsiFile + */ + private PsiFile generateComponentGridXmlWithActionsColumn( + final String area + ) { + final Project project = myFixture.getProject(); + final UiComponentGridToolbarData uiGridToolbarData = new UiComponentGridToolbarData( + false, + true, + true, + true, + true, + true + ); + final UiComponentGridData uiGridData = new UiComponentGridData( + MODULE_NAME, + area, + COMPONENT_NAME, + ID_FIELD_NAME, + ACL, + DATA_PROVIDER_NAME, + DATA_PROVIDER_PATH, + ENTITY_NAME, + uiGridToolbarData, + new ArrayList<>() + ); + final UiComponentGridXmlGenerator uiGridXmlGenerator = new UiComponentGridXmlGenerator( + uiGridData, + project + ); + + return uiGridXmlGenerator.generate("test"); + } + /** * Get expected directory. * diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java new file mode 100644 index 000000000..34f06821d --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java @@ -0,0 +1,132 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.pool; + +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.actions.generation.generator.BaseGeneratorTestCase; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.provider.NewEntityGeneratorsProviderUtil; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import java.util.ArrayList; + +public class NewEntityGeneratorPoolTest extends BaseGeneratorTestCase { + + private static final String MODULE_NAME = "Foo_Bar"; + private static final String ACTION_NAME = "Test"; + private static final String INDEX_PATH = "index"; + private static final String EDIT_PATH = "edit"; + private static final String NEW_PATH = "new"; + private static final String DELETE_PATH = "delete"; + + /** + * Test if generator pool handler instantiated without any error. + */ + public void testGeneratorsInPoolInstantiating() { + final NewEntityDialogData dialogData = getMockNewEntityDialogData(); + final EntityCreatorContextData contextData = getMockContext(); + final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(contextData); + + NewEntityGeneratorsProviderUtil.initializeGenerators( + generatorPoolHandler, + contextData, + dialogData + ); + + assertFalse( + "There are errors during generators instantiating.", + generatorPoolHandler.hasErrorMessages() + ); + } + + /** + * Test if generators handlers doesn't have any DTO converter type errors. + */ + public void testGeneratorsInPoolOnCorrectDtoConverterTypes() { + final NewEntityDialogData dialogData = getMockNewEntityDialogData(); + final EntityCreatorContextData contextData = getMockContext(); + final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(contextData); + + NewEntityGeneratorsProviderUtil.initializeGenerators( + generatorPoolHandler, + contextData, + dialogData + ); + + try { + generatorPoolHandler.instantiateAllGenerators(); + } catch (ClassCastException exception) { + fail("Wrong type provided for generator: " + exception.getMessage()); + } + } + + /** + * Get mocked new entity dialog data. + * + * @return NewEntityDialogData + */ + @SuppressWarnings("PMD.AvoidDuplicateLiterals") + private NewEntityDialogData getMockNewEntityDialogData() { + return new NewEntityDialogData( + "test", + "test", + "test", + "test", + "test", + true, + true, + "test", + "test", + "test", + "test", + true, + true, + true, + true, + true, + true, + "test", + "test", + "test", + "test", + 10, + "test", + "test", + "test" + ); + } + + /** + * Get mocked entity creator context data. + * + * @return EntityCreatorContextData + */ + private EntityCreatorContextData getMockContext() { + final NamespaceBuilder mockNamespace = new NamespaceBuilder( + MODULE_NAME, + "MockClass", + "Mock/Directory" + ); + + return new EntityCreatorContextData( + this.myFixture.getProject(), + MODULE_NAME, + ACTION_NAME, + false, + INDEX_PATH, + EDIT_PATH, + NEW_PATH, + DELETE_PATH, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + new ArrayList<>(), + new ArrayList<>(), + new ArrayList<>(), + new ArrayList<>() + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorDataProviderUtil.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorDataProviderUtil.java new file mode 100644 index 000000000..99a058ea2 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorDataProviderUtil.java @@ -0,0 +1,51 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.util; + +import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public final class DbSchemaGeneratorDataProviderUtil { + + private static final String PROPERTY_NAME = "Name"; + private static final String PROPERTY_TYPE = "Type"; + + private DbSchemaGeneratorDataProviderUtil() {} + + /** + * Generate properties for testcases. + * + * @return List of prepared properties. + */ + public static List> generateEntityPropertiesForTest() { + final List> propertyList = new LinkedList<>(); + + final Map nameProperty = new HashMap<>(); + nameProperty.put(PROPERTY_NAME, "name"); + nameProperty.put(PROPERTY_TYPE, PropertiesTypes.STRING.getPropertyType()); + propertyList.add(nameProperty); + + final Map ageProperty = new HashMap<>(); + ageProperty.put(PROPERTY_NAME, "age"); + ageProperty.put(PROPERTY_TYPE, PropertiesTypes.INT.getPropertyType()); + propertyList.add(ageProperty); + + final Map salaryProperty = new HashMap<>(); + salaryProperty.put(PROPERTY_NAME, "salary"); + salaryProperty.put(PROPERTY_TYPE, PropertiesTypes.FLOAT.getPropertyType()); + propertyList.add(salaryProperty); + + final Map singleProperty = new HashMap<>(); + singleProperty.put(PROPERTY_NAME, "is_single"); + singleProperty.put(PROPERTY_TYPE, PropertiesTypes.BOOL.getPropertyType()); + propertyList.add(singleProperty); + + return propertyList; + } +}