From 20ef982d87cc1973a91bef2a9e5ac6825c5f4c13 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 15 Jan 2021 10:31:28 +0200 Subject: [PATCH 01/84] 309: Code refactoring --- .../generation/data/DbSchemaXmlData.java | 4 +- .../DbSchemaXmlSourceDataUtil.java} | 10 ++-- .../generation/dialog/NewDbSchemaDialog.java | 22 ++++---- .../magento/files/ModuleDbSchemaXml.java | 53 ++++++++++--------- .../ui/table/ComboBoxCellEditor.java | 50 ++++++++++------- .../ui/table/TableGroupWrapper.java | 18 +++---- 6 files changed, 87 insertions(+), 70 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/data/{DbSchemaXmlSourceData.java => util/DbSchemaXmlSourceDataUtil.java} (92%) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java index 1bb1ea0f5..271d0d209 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java @@ -77,7 +77,7 @@ public List> getColumns() { return new LinkedList<>(columns); } - public void setColumns(List> columns) { + public void setColumns(final List> columns) { this.columns = columns; } @@ -87,7 +87,7 @@ public void setColumns(List> columns) { * @return Map */ public Map getTableAttributesMap() { - final Map tableAttributesData = new LinkedHashMap<>(); + final Map tableAttributesData = new LinkedHashMap<>();//NOPMD tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName()); tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource()); tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine()); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlSourceData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java similarity index 92% rename from src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlSourceData.java rename to src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java index d321a5f22..85f3112aa 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlSourceData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java @@ -3,13 +3,13 @@ * See COPYING.txt for license details. */ -package com.magento.idea.magento2plugin.actions.generation.data; +package com.magento.idea.magento2plugin.actions.generation.data.util; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -public final class DbSchemaXmlSourceData { +public final class DbSchemaXmlSourceDataUtil { // currently available engines public static final String TABLE_ENGINE_INNODB = "innodb"; public static final String TABLE_ENGINE_MEMORY = "memory"; @@ -47,7 +47,7 @@ public final class DbSchemaXmlSourceData { /** * Denying the possibility to initialize this class. */ - private DbSchemaXmlSourceData() {} + private DbSchemaXmlSourceDataUtil() {} /** * Get source list for available table engines. @@ -56,8 +56,8 @@ private DbSchemaXmlSourceData() {} */ public static List getTableEngineSource() { return new LinkedList<>(Arrays.asList( - DbSchemaXmlSourceData.TABLE_ENGINE_INNODB, - DbSchemaXmlSourceData.TABLE_ENGINE_MEMORY) + DbSchemaXmlSourceDataUtil.TABLE_ENGINE_INNODB, + DbSchemaXmlSourceDataUtil.TABLE_ENGINE_MEMORY) ); } 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 27bb11f47..04e9127aa 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -9,8 +9,8 @@ import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction; import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlSourceData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +import com.magento.idea.magento2plugin.actions.generation.data.util.DbSchemaXmlSourceDataUtil; 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.AlphanumericWithUnderscoreRule; @@ -40,12 +40,12 @@ import javax.swing.KeyStroke; import org.jetbrains.annotations.NotNull; +@SuppressWarnings({"PMD.TooManyFields", "PMD.LoosePackageCoupling"}) public class NewDbSchemaDialog extends AbstractDialog { private static final String TABLE_NAME = "Table Name"; private final Project project; private final String moduleName; - private final PsiDirectory directory; private JPanel contentPanel; // Buttons @@ -94,7 +94,6 @@ public NewDbSchemaDialog( ) { super(); this.project = project; - this.directory = directory; moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); setTitle(NewDbSchemaAction.ACTION_DESCRIPTION); @@ -181,13 +180,16 @@ private void initializeColumnsUiComponentGroup() { ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT )); // Set default values for columns - final Map defaultValues = new HashMap<>(); + final Map defaultValues = new HashMap<>();//NOPMD defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, "false"); defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, "false"); // Set sources for columns - final Map> sources = new HashMap<>(); + final Map> sources = new HashMap<>();//NOPMD final List booleanSource = Arrays.asList("true", "false"); - sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, DbSchemaXmlSourceData.getColumnTypes()); + sources.put( + ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, + DbSchemaXmlSourceDataUtil.getColumnTypes() + ); sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, booleanSource); sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, booleanSource); sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, booleanSource); @@ -208,12 +210,12 @@ private void initializeColumnsUiComponentGroup() { */ private void fillComboBoxes() { // Table Engine ComboBox defaults. - for (final String engine : DbSchemaXmlSourceData.getTableEngineSource()) { - tableEngine.addItem(new ComboBoxItemData(engine, engine)); + for (final String engine : DbSchemaXmlSourceDataUtil.getTableEngineSource()) { + tableEngine.addItem(new ComboBoxItemData(engine, engine));//NOPMD } // Table Resource ComboBox defaults. - for (final String resource : DbSchemaXmlSourceData.getTableResourceSource()) { - tableResource.addItem(new ComboBoxItemData(resource, resource)); + for (final String resource : DbSchemaXmlSourceDataUtil.getTableResourceSource()) { + tableResource.addItem(new ComboBoxItemData(resource, resource));//NOPMD } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java index 368a8201d..1746c7585 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java @@ -7,7 +7,7 @@ import com.intellij.lang.Language; import com.intellij.lang.xml.XMLLanguage; -import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlSourceData; +import com.magento.idea.magento2plugin.actions.generation.data.util.DbSchemaXmlSourceDataUtil; import java.util.ArrayList; import java.util.List; @@ -44,8 +44,8 @@ public class ModuleDbSchemaXml implements ModuleFileInterface { public static final String XML_ATTR_TYPE_PK = "primary"; public static final String XML_ATTR_REFERENCE_ID_PK = "PRIMARY"; public static final String XML_ATTR_INDEX_TYPE_BTREE = "btree"; - public static final String XML_ATTR_INDEX_TYPE_FULLTEXT = "fulltext"; - public static final String XML_ATTR_INDEX_TYPE_HASH = "hash"; + public static final String XML_ATTR_INDEX_TYPE_FULLTEXT = "fulltext";//NOPMD + public static final String XML_ATTR_INDEX_TYPE_HASH = "hash";//NOPMD //tags public static final String XML_TAG_SCHEMA = "schema"; @@ -61,29 +61,30 @@ public class ModuleDbSchemaXml implements ModuleFileInterface { * * @return List */ + @SuppressWarnings("PMD") public static List getAllowedAttributes(final String columnType) { - List allowedAttributes = new ArrayList<>(); + final List allowedAttributes = new ArrayList<>(); switch (columnType) { - case DbSchemaXmlSourceData.COLUMN_TYPE_BLOB: - case DbSchemaXmlSourceData.COLUMN_TYPE_MEDIUMBLOB: - case DbSchemaXmlSourceData.COLUMN_TYPE_LONGBLOB: - case DbSchemaXmlSourceData.COLUMN_TYPE_DATE: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_BLOB: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_MEDIUMBLOB: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_LONGBLOB: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DATE: allowedAttributes.add(XML_ATTR_COLUMN_NAME); allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_VARBINARY: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_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); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_TINYINT: - case DbSchemaXmlSourceData.COLUMN_TYPE_SMALLINT: - case DbSchemaXmlSourceData.COLUMN_TYPE_INT: - case DbSchemaXmlSourceData.COLUMN_TYPE_BIGINT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TINYINT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_SMALLINT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_INT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_BIGINT: allowedAttributes.add(XML_ATTR_COLUMN_NAME); allowedAttributes.add(XML_ATTR_COLUMN_PADDING); allowedAttributes.add(XML_ATTR_COLUMN_UNSIGNED); @@ -92,9 +93,9 @@ public static List getAllowedAttributes(final String columnType) { allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_DECIMAL: - case DbSchemaXmlSourceData.COLUMN_TYPE_DOUBLE: - case DbSchemaXmlSourceData.COLUMN_TYPE_FLOAT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DECIMAL: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DOUBLE: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_FLOAT: allowedAttributes.add(XML_ATTR_COLUMN_NAME); allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT); allowedAttributes.add(XML_ATTR_COLUMN_SCALE); @@ -103,24 +104,24 @@ public static List getAllowedAttributes(final String columnType) { allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); allowedAttributes.add(XML_ATTR_COLUMN_COMMENT); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_VARCHAR: - case DbSchemaXmlSourceData.COLUMN_TYPE_TEXT: - case DbSchemaXmlSourceData.COLUMN_TYPE_MEDIUMTEXT: - case DbSchemaXmlSourceData.COLUMN_TYPE_LONGTEXT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_VARCHAR: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TEXT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_MEDIUMTEXT: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_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); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_BOOLEAN: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_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); break; - case DbSchemaXmlSourceData.COLUMN_TYPE_DATETIME: - case DbSchemaXmlSourceData.COLUMN_TYPE_TIMESTAMP: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DATETIME: + case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TIMESTAMP: allowedAttributes.add(XML_ATTR_COLUMN_NAME); allowedAttributes.add(XML_ATTR_COLUMN_ON_UPDATE); allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE); @@ -146,10 +147,10 @@ public static String generateIndexReferenceId( final String tableName, final List indexColumnsNames ) { - StringBuilder stringBuilder = new StringBuilder(tableName.toUpperCase()); + final StringBuilder stringBuilder = new StringBuilder(tableName.toUpperCase());//NOPMD - for (String indexName : indexColumnsNames) { - stringBuilder.append("_").append(indexName.toUpperCase()); + for (final String indexName : indexColumnsNames) { + stringBuilder.append("_").append(indexName.toUpperCase());//NOPMD } return stringBuilder.toString(); diff --git a/src/com/magento/idea/magento2plugin/ui/table/ComboBoxCellEditor.java b/src/com/magento/idea/magento2plugin/ui/table/ComboBoxCellEditor.java index 3fad5f75e..b69deebe7 100644 --- a/src/com/magento/idea/magento2plugin/ui/table/ComboBoxCellEditor.java +++ b/src/com/magento/idea/magento2plugin/ui/table/ComboBoxCellEditor.java @@ -5,40 +5,44 @@ package com.magento.idea.magento2plugin.ui.table; -import javax.swing.AbstractCellEditor; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.table.TableCellEditor; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Arrays; import java.util.List; -import java.util.Vector; +import javax.swing.AbstractCellEditor; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.table.TableCellEditor; public class ComboBoxCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { private T value; - private List options; - private JComboBox editorComponent; + private final List options;//NOPMD + private final JComboBox editorComponent; private ActionListener actionListener; - public ComboBoxCellEditor(List options) { + /** + * Constructor. + * + * @param options List + */ + public ComboBoxCellEditor(final List options) { + super(); this.options = options; editorComponent = new JComboBox(); - for (T option : options) { + for (final T option : this.options) { editorComponent.addItem(option); } } @Override public Component getTableCellEditorComponent( - JTable table, - Object value, - boolean isSelected, - int row, - int column + final JTable table, + final Object value, + final boolean isSelected, + final int row, + final int column ) { this.value = (T) value; @@ -60,8 +64,8 @@ public Object getCellEditorValue() { } @Override - public void actionPerformed(ActionEvent event) { - JComboBox comboBox = (JComboBox) event.getSource(); + public void actionPerformed(final ActionEvent event) { + final JComboBox comboBox = (JComboBox) event.getSource(); this.value = (T) comboBox.getSelectedItem(); if (actionListener != null) { @@ -70,11 +74,21 @@ public void actionPerformed(ActionEvent event) { editorComponent.setPopupVisible(false); } + /** + * Get component. + * + * @return Component + */ public Component getComponent() { return editorComponent; } - public void addAdditionalActionListener(ActionListener actionListener) { + /** + * Add additional action listener. + * + * @param actionListener ActionListener + */ + public void addAdditionalActionListener(final ActionListener actionListener) { this.actionListener = actionListener; } } diff --git a/src/com/magento/idea/magento2plugin/ui/table/TableGroupWrapper.java b/src/com/magento/idea/magento2plugin/ui/table/TableGroupWrapper.java index 38a5a3832..dd651497b 100644 --- a/src/com/magento/idea/magento2plugin/ui/table/TableGroupWrapper.java +++ b/src/com/magento/idea/magento2plugin/ui/table/TableGroupWrapper.java @@ -73,11 +73,11 @@ public DefaultTableModel getTableModel() { * @return List */ public List> getColumnsData() { - List> data = new LinkedList<>(); - DefaultTableModel tableModel = getTableModel(); + final List> data = new LinkedList<>(); + final DefaultTableModel tableModel = getTableModel(); for (int row = 0; row < tableModel.getRowCount(); row++) { - Map columnValues = new LinkedHashMap<>(); + final Map columnValues = new LinkedHashMap<>();//NOPMD for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) { columnValues.put( @@ -121,10 +121,10 @@ private String getTitleForColumn(final String column) { String title = column.replace("_", " "); if (title.contains(":")) { - title = title.substring(title.indexOf(":") + 1); + title = title.substring(title.indexOf(':') + 1); } - return title.substring(0, 1).toUpperCase() + title.substring(1); + return title.substring(0, 1).toUpperCase() + title.substring(1);//NOPMD } /** @@ -159,16 +159,16 @@ private void addNewRowRoutine( } if (sources != null && sources.containsKey(columns.get(index))) { final String column = columns.get(index); - final List source = new LinkedList<>(sources.get(column)); - final String[] sourceArray = new String[source.size()]; + final List source = new LinkedList<>(sources.get(column));//NOPMD + final String[] sourceArray = new String[source.size()];//NOPMD for (int sourceIndex = 0; sourceIndex < source.size(); sourceIndex++) { sourceArray[sourceIndex] = source.get(sourceIndex); } final TableColumn currentColumn = table.getColumn(getTitleForColumn(column)); - currentColumn.setCellRenderer(new ComboBoxRenderer(sourceArray)); + currentColumn.setCellRenderer(new ComboBoxRenderer(sourceArray));//NOPMD currentColumn.setCellEditor( - new ComboBoxCellEditor(Arrays.asList(sourceArray)) + new ComboBoxCellEditor(Arrays.asList(sourceArray))//NOPMD ); if (columnValuesObjectArray[index].toString().isEmpty() From c01e98c6e1089d675b3da8b42bf1f658af46d534 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 19 Jan 2021 15:10:24 +0200 Subject: [PATCH 02/84] Entity manager innitial --- resources/META-INF/plugin.xml | 1 + .../actions/generation/NewEntityAction.java | 56 ++ .../generation/dialog/NewDataModelDialog.java | 14 +- .../generation/dialog/NewEntityDialog.form | 491 ++++++++++ .../generation/dialog/NewEntityDialog.java | 873 ++++++++++++++++++ .../magento/packages/PropertiesTypes.java | 32 + 6 files changed, 1460 insertions(+), 7 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/NewEntityAction.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index c764c4986..329af85a3 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -58,6 +58,7 @@ + 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/dialog/NewDataModelDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 07296ae35..2d6d1ffba 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -27,6 +27,7 @@ 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.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; @@ -70,8 +71,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; @@ -304,9 +303,10 @@ private void initPropertiesTable() { addProperty.addActionListener(e -> { propertiesTable.addRow(new Object[]{ - "", - PROPERTY_TYPES[0], - PROPERTY_DELETE + "", + PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) + .getPropertyType(), + PROPERTY_DELETE }); }); @@ -315,8 +315,8 @@ private void initPropertiesTable() { 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())); } private DefaultTableModel getPropertiesTable() { 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..bdb3a51df --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -0,0 +1,491 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..afc3d4885 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -0,0 +1,873 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +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; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction; +import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ArrayList; +import java.util.List; +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; + +import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; +import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; +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.LayoutXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; +import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; +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.UiComponentFormFileData; +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.data.code.ClassPropertyData; +import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator; +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.LayoutXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; +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.RoutesXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; +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.DataModel; +import com.magento.idea.magento2plugin.magento.files.DataModelInterface; +import com.magento.idea.magento2plugin.magento.files.ModelPhp; +import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; +import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; +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.PropertiesTypes; +import com.magento.idea.magento2plugin.ui.FilteredComboBox; +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.FirstLetterToLowercaseUtil; +import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import org.apache.commons.lang.StringUtils; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings({ + "PMD.TooManyFields", + "PMD.MissingSerialVersionUID", + "PMD.DataClass", + "PMD.UnusedPrivateField", + "PMD.ExcessiveImports", +}) +public class NewEntityDialog extends AbstractDialog { + @NotNull + private final 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 createUiComponentsLabel; + private JTextField entityName; + private JLabel entityNameLabel; + private JLabel dbTableNameLabel; + private JTextField dbTableName; + private JTextField entityId; + private JLabel entityIdColumnNameLabel; + private JTextField route; + private JLabel routeLabel; + private JTextField acl; + private JLabel aclLabel; + private JTextField aclTitle; + private FilteredComboBox parentAcl; + private JLabel formNameLabel; + private JTextField formName; + private JTextField formLabel; + private JLabel formLabelLabel; + private JTextField gridName; + private JLabel gridNameLabel; + private JLabel parentMenuItemLabel; + private JLabel sortOrderLabel; + private JLabel menuIdentifierLabel; + private JTextField sortOrder; + private JTextField menuIdentifier; + private JLabel menuTitleLabel; + private JTextField menuTitle; + private FilteredComboBox parentMenu; + private JLabel formMenuLabel; + private JCheckBox addToolBar; + private JCheckBox addBookmarksCheckBox; + private JCheckBox addColumnsControlCheckBox; + private JCheckBox addFullTextSearchCheckBox; + private JCheckBox addListingFiltersCheckBox; + private JCheckBox addListingPagingCheckBox; + private final List properties; + + 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 PROPERTY_ACTION = "Action"; + private static final String PROPERTY_DELETE = "Delete"; + + private JTextField observerName; + + /** + * Constructor. + * + * @param project Project + * @param directory PsiDirectory + */ + public NewEntityDialog(final Project project, final PsiDirectory directory) { + super(); + + this.project = project; + this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); + this.properties = new ArrayList<>(); + + setContentPane(contentPane); + setModal(true); + setTitle(NewViewModelAction.ACTION_DESCRIPTION); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener((final ActionEvent event) -> onOK()); + 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(); + } + }); + + initPropertiesTable(); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction( + (final ActionEvent event) -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ); + } + + /** + * 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); + } + + private void initPropertiesTable() { + final DefaultTableModel propertiesTable = getPropertiesTable(); + propertiesTable.setDataVector( + new Object[][]{}, + new Object[]{ + PROPERTY_NAME, + PROPERTY_TYPE, + PROPERTY_ACTION + } + ); + + final TableColumn column = propertyTable.getColumn(PROPERTY_ACTION); + column.setCellRenderer(new TableButton(PROPERTY_DELETE)); + column.setCellEditor(new DeleteRowButton(new JCheckBox())); + + addProperty.addActionListener(e -> { + propertiesTable.addRow(new Object[]{ + "", + PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) + .getPropertyType(), + PROPERTY_DELETE + }); + }); + + initPropertyTypeColumn(); + } + + private void initPropertyTypeColumn() { + final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE); + formElementTypeColumn.setCellEditor(new ComboBoxEditor(PropertiesTypes.getPropertyTypes())); + formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes())); + } + + private DefaultTableModel getPropertiesTable() { + return (DefaultTableModel) propertyTable.getModel(); + } + + /** + * Perform code generation using input data. + */ + private void onOK() { + generateModelFile(); + generateResourceModelFile(); + generateCollectionFile(); + + formatProperties(); + generateDataModelFile(); + generateDataModelInterfaceFile(); + + generateRoutesXmlFile(); + generateViewControllerFile(); + generateSubmitControllerFile(); + generateDataProviderFile(); + generateLayoutFile(); + generateFormFile(); + generateAclXmlFile(); + + generateGridViewControllerFile(); + generateGridLayoutFile(); + generateMenuFile(); + generateUiComponentGridFile(); + } + + private PsiFile generateModelFile() { + final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); + String resourceModelName = getResourceModelName(); + + + return new ModuleModelGenerator(new ModelData( + getModuleName(), + getDbTableName(), + getModelName(), + resourceModelName, + modelNamespace.getClassFqn(), + modelNamespace.getNamespace(), + resourceModelNamespace.getClassFqn() + ), project).generate(ACTION_NAME, true); + } + + private NamespaceBuilder getModelNamespace() { + return new NamespaceBuilder(getModuleName(), getModelName(), ModelPhp.MODEL_DIRECTORY); + } + + private NamespaceBuilder getDataModelNamespace() { + return new NamespaceBuilder(getModuleName(), getDataModelName(), DataModel.DIRECTORY); + } + + private NamespaceBuilder getDataModelInterfaceNamespace() { + return new NamespaceBuilder(getModuleName(), getDataModelInterfaceName(), DataModelInterface.DIRECTORY); + } + + private NamespaceBuilder getResourceModelNamespace() { + return new NamespaceBuilder( + getModuleName(), + getResourceModelName(), + ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + ); + } + + private String getModuleName() { + return moduleName; + } + + private String getEntityName() { + return entityName.getText().trim(); + } + + private String getModelName() { + return getEntityName().concat("Model"); + } + + private String getDataModelName() { + return getEntityName().concat("Data"); + } + + private String getDataProviderClassName() { + return getEntityName().concat("DataProvider"); + } + + private String getDataModelInterfaceName() { + return getEntityName().concat("Interface"); + } + + private String getResourceModelName() { + return getEntityName().concat("Resource"); + } + + private String getCollectionName() { + return getEntityName().concat("Collection"); + } + + private String getDbTableName() { + return dbTableName.getText().trim(); + } + + private PsiFile generateResourceModelFile() { + final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); + return new ModuleResourceModelGenerator(new ResourceModelData( + getModuleName(), + getDbTableName(), + getResourceModelName(), + getEntityIdColumn(), + resourceModelNamespace.getNamespace(), + resourceModelNamespace.getClassFqn() + ), project).generate(ACTION_NAME, true); + } + + private String getEntityIdColumn() { + return entityId.getText().trim(); + } + + 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(); + + + return new ModuleCollectionGenerator(new CollectionData( + getModuleName(), + getDbTableName(), + modelName, + getCollectionName(), + collectionNamespace.getClassFqn(), + getCollectionDirectory(), + collectionNamespace.getNamespace(), + resourceModelName, + resourceModelFqn.toString(), + modelFqn.toString() + ), project).generate(ACTION_NAME, true); + } + + private void generateDataModelFile() { + NamespaceBuilder nameSpaceBuilder = getDataModelNamespace(); + new DataModelGenerator(project, new DataModelData( + getDataModelNamespace().getNamespace(), + getDataModelName(), + getModuleName(), + nameSpaceBuilder.getClassFqn(), + getDataModelInterfaceNamespace().getClassFqn(), + getProperties() + )).generate(ACTION_NAME, true); + } + + private void generateDataModelInterfaceFile() { + NamespaceBuilder nameSpaceBuilder = getDataModelInterfaceNamespace(); + new DataModelInterfaceGenerator(project, new DataModelInterfaceData( + nameSpaceBuilder.getNamespace(), + getDataModelInterfaceName(), + getModuleName(), + nameSpaceBuilder.getClassFqn(), + getProperties() + )).generate(ACTION_NAME, true); + } + + /** + * Gets properties as a string, ready for templating. + * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". + */ + private String getProperties() { + return StringUtils.join(properties, ","); + } + + /** + * Formats properties into an array of ClassPropertyData objects. + */ + private void formatProperties() { + final DefaultTableModel propertiesTable = getPropertiesTable(); + final int rowCount = propertiesTable.getRowCount(); + String name; + String type; + + name = getEntityIdColumn(); + type = "int"; + 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()); + + 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 NamespaceBuilder getCollectionNamespace() { + return new NamespaceBuilder( + getModuleName(), + getCollectionName(), + getCollectionDirectory() + ); + } + + private String getCollectionDirectory() { + return ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + File.separator + + getEntityName(); + } + + private PsiFile generateRoutesXmlFile() { + return new RoutesXmlGenerator(new RoutesXmlData( + Areas.adminhtml.toString(), + getRoute(), + getModuleName() + ), project).generate(ACTION_NAME, false); + } + + public String getRoute() { + return route.getText().trim(); + } + + private PsiFile generateViewControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + getViewActionName(), + getViewControllerDirectory() + ); + return new ModuleControllerClassGenerator(new ControllerFileData( + getViewControllerDirectory(), + getViewActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); + } + + private String getViewActionName() { + return "Edit"; + } + + private String getSubmitActionName() { + return "Save"; + } + + private String getViewControllerDirectory() { + return getControllerDirectory() + getModelName(); + } + + private String getControllerDirectory() { + return ControllerBackendPhp.DEFAULT_DIR + File.separator; + } + + private PsiFile generateSubmitControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + getSubmitActionName(), + getViewControllerDirectory() + ); + return new ModuleControllerClassGenerator(new ControllerFileData( + getViewControllerDirectory(), + getSubmitActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.POST.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); + } + + public String getAcl() { + return acl.getText().trim(); + } + + private PsiFile generateDataProviderFile() { + final NamespaceBuilder namespace = getDataProviderNamespace(); + return new UiComponentDataProviderGenerator(new UiComponentDataProviderData( + getDataProviderClassName(), + namespace.getNamespace(), + getDataProviderDirectory() + ), getModuleName(), project).generate(ACTION_NAME, false); + } + + @NotNull + private NamespaceBuilder getDataProviderNamespace() { + return new NamespaceBuilder( + getModuleName(), + getDataProviderClassName(), + getDataProviderDirectory() + ); + } + + public String getDataProviderDirectory() { + return "UI/DataProvider"; + } + + private PsiFile generateLayoutFile() { + return new LayoutXmlGenerator(new LayoutXmlData( + Areas.adminhtml.toString(), + getRoute(), + getModuleName(), + getEntityName(), + getViewActionName(), + getFormName() + ), project).generate(ACTION_NAME, false); + } + + /** + * Get controller name. + * + * @return String + */ + public String getFormName() { + return formName.getText().trim(); + } + + private PsiFile generateAclXmlFile() { + return new AclXmlGenerator(new AclXmlData( + getParentAcl(), + getAcl(), + getAclTitle() + ), getModuleName(), project).generate(ACTION_NAME, false); + } + + public String getParentAcl() { + return parentAcl.getSelectedItem().toString().trim(); + } + + public String getAclTitle() { + return aclTitle.getText().trim(); + } + + private PsiFile generateFormFile() { + return new UiComponentFormGenerator(new UiComponentFormFileData( + getFormName(), + Areas.adminhtml.toString(), + getModuleName(), + getFormLabel(), + getButtons(), + getFieldsets(), + getFields(), + getRoute(), + getEntityName(), + getSubmitActionName(), + getDataProviderNamespace().getClassFqn() + ), project).generate(ACTION_NAME, true); + } + + public String getFormLabel() { + return formLabel.getText().trim(); + } + + /** + * Returns form fieldsets. + * + * @return List[UiComponentFormFieldsetData] + */ + public 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] + */ + protected List getButtons() { + final List buttons = new ArrayList(); + final String directory = "Block/Form"; + + NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( + getModuleName(), + "Save", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "SaveEntity", + getModuleName(), + "Save", + namespaceBuilderSave.getNamespace(), + "Save Entity", + "10", + getFormName(), + namespaceBuilderSave.getClassFqn() + )); + + NamespaceBuilder namespaceBuilderBack = new NamespaceBuilder( + getModuleName(), + "Back", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "Back", + getModuleName(), + "Back", + namespaceBuilderBack.getNamespace(), + "Back To Grid", + "20", + getFormName(), + namespaceBuilderBack.getClassFqn() + )); + + NamespaceBuilder namespaceBuilderDelete = new NamespaceBuilder( + getModuleName(), + "Delete", + directory + ); + buttons.add(new UiComponentFormButtonData( + directory, + "Delete", + getModuleName(), + "Save", + namespaceBuilderDelete.getNamespace(), + "Delete Entity", + "30", + getFormName(), + namespaceBuilderDelete.getClassFqn() + )); + return buttons; + } + + /** + * Returns form fields list. + * + * @return List[UiComponentFormFieldData] + */ + public List getFields() { + final DefaultTableModel model = getPropertiesTable(); + final ArrayList fieldsets = new ArrayList<>(); + + fieldsets.add( + new UiComponentFormFieldData( + "entity_id", + "int", + "Entity ID", + "0", + "general", + "hidden", + "entity_id" + ) + ); + + 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 = model.getValueAt(count, 0).toString(); //todo: convert + final String sortOrder = String.valueOf(count).concat("0"); + final String fieldset = "general"; + final String formElementType = model.getValueAt(count, 1).toString(); + 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() { + this.parentAcl = new FilteredComboBox(getAclResourcesList()); + + if (getAclResourcesList().contains(ModuleMenuXml.defaultAcl)) { + parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); + } + } + + private List getAclResourcesList() { + return GetAclResourcesListUtil.execute(project); + } + + private PsiFile generateGridViewControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + "Listing", + getControllerDirectory() + ); + return new ModuleControllerClassGenerator(new ControllerFileData( + getControllerDirectory(), + "Listing", + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); + } + + private PsiFile generateGridLayoutFile() { + return new LayoutXmlGenerator(new LayoutXmlData( + Areas.adminhtml.toString(), + getRoute(), + getModuleName(), + getEntityName(), + "Listing", + getGridName() + ), project).generate(ACTION_NAME, false); + } + + private String getGridName() { + return gridName.getText().toString(); + } + + private PsiFile generateMenuFile() { + return new MenuXmlGenerator(new MenuXmlData( + getParentMenuItem(), + getSortOrder(), + getModuleName(), + getMenuIdentifier(), + getMenuTitle(), + getAcl(), + getMenuAction() + ), project).generate(ACTION_NAME, false); + } + + private String getParentMenuItem() { + return parentMenu.getSelectedItem().toString(); + } + + public String getSortOrder() { + return sortOrder.getText().trim(); + } + + public String getMenuIdentifier() { + return menuIdentifier.getText().trim(); + } + + private String getMenuAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "listing"; + } + + public String getMenuTitle() { + return menuTitle.getText().trim(); + } + + private void generateUiComponentGridFile() { + final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( + getUiComponentGridData(), + project + ); + gridXmlGenerator.generate(NewUiComponentGridAction.ACTION_NAME, true); + } + + /** + * Get grid UI component data. + * + * @return UiComponentGridData + */ + public UiComponentGridData getUiComponentGridData() { + return new UiComponentGridData( + getModuleName(), + Areas.adminhtml.toString(), + getGridName(), + getDataProviderNamespace().getClassFqn(), + getEntityIdColumn(), + getAcl(), + getUiComponentGridToolbarData() + ); + } + + /** + * Get grid toolbar data. + * + * @return UiComponentGridToolbarData + */ + public UiComponentGridToolbarData getUiComponentGridToolbarData() { + return new UiComponentGridToolbarData( + getAddToolBar(), + getAddBookmarksCheckBox(), + getAddColumnsControlCheckBox(), + getAddFullTextSearchCheckBox(), + getAddListingFiltersCheckBox(), + getAddListingPagingCheckBox() + ); + } + + private Boolean getAddToolBar() { + return addToolBar.isSelected(); + } + + private Boolean getAddColumnsControlCheckBox() { + return addColumnsControlCheckBox.isSelected(); + } + + private Boolean getAddFullTextSearchCheckBox() { + return addFullTextSearchCheckBox.isSelected(); + } + + private Boolean getAddListingFiltersCheckBox() { + return addListingFiltersCheckBox.isSelected(); + } + + private Boolean getAddListingPagingCheckBox() { + return addListingPagingCheckBox.isSelected(); + } + + private Boolean getAddBookmarksCheckBox() { + return addBookmarksCheckBox.isSelected(); + } +} 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..197566518 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java @@ -0,0 +1,32 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages; + +public enum PropertiesTypes { + INT("int"), + FLOAT("float"), + STRING("string"), + BOOL("bool"); + + private final String propertyType; + + PropertiesTypes(final String propertyType) { + this.propertyType = propertyType; + } + + public String getPropertyType() { + return propertyType; + } + + public static String[] getPropertyTypes() { + return new String[]{ + valueOf(INT.toString()).getPropertyType(), + valueOf(FLOAT.toString()).getPropertyType(), + valueOf(STRING.toString()).getPropertyType(), + valueOf(BOOL.toString()).getPropertyType() + }; + } +} From c473393d4f42f72e178cc747aaac75e64b741132 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 19 Jan 2021 16:34:23 +0200 Subject: [PATCH 03/84] New Entity DB --- .../generation/dialog/NewEntityDialog.form | 36 ++++++++++- .../generation/dialog/NewEntityDialog.java | 59 ++++++++++++++++++- 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index bdb3a51df..fe2ed32b8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -21,7 +21,7 @@ - + @@ -31,7 +31,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -95,6 +95,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index afc3d4885..6a2960c09 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -10,6 +10,7 @@ import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction; import com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction; import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; import java.awt.event.ActionEvent; @@ -18,6 +19,7 @@ import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.swing.*; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; @@ -27,6 +29,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; 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.DbSchemaXmlData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; @@ -43,6 +46,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator; 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.DbSchemaXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; @@ -68,6 +72,7 @@ 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.ui.table.TableGroupWrapper; import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; @@ -128,7 +133,13 @@ public class NewEntityDialog extends AbstractDialog { private JCheckBox addFullTextSearchCheckBox; private JCheckBox addListingFiltersCheckBox; private JCheckBox addListingPagingCheckBox; + private JComboBox tableEngine; + private JLabel tableEngineLabel; + private JComboBox tableResource; + private JLabel tableResourceLabel; private final List properties; + // Table Columns UI components group + private TableGroupWrapper columnsTableGroupWrapper; private static final String ACTION_NAME = "Create Entity"; private static final String PROPERTY_NAME = "Name"; @@ -252,6 +263,8 @@ private void onOK() { generateGridLayoutFile(); generateMenuFile(); generateUiComponentGridFile(); + + generateDbSchemaXmlFile(); } private PsiFile generateModelFile() { @@ -811,7 +824,7 @@ private void generateUiComponentGridFile() { getUiComponentGridData(), project ); - gridXmlGenerator.generate(NewUiComponentGridAction.ACTION_NAME, true); + gridXmlGenerator.generate(ACTION_NAME, true); } /** @@ -870,4 +883,48 @@ private Boolean getAddListingPagingCheckBox() { private Boolean getAddBookmarksCheckBox() { return addBookmarksCheckBox.isSelected(); } + + /** + * Run db_schema.xml file generator. + */ + private void generateDbSchemaXmlFile() { + new DbSchemaXmlGenerator( + new DbSchemaXmlData( + getDbTableName(), + getTableResource(), + getTableEngine(), + getEntityName(), + getColumns() + ), + project, + moduleName + ).generate(ACTION_NAME, false); + } + + /** + * Get tableResource field value. + * + * @return String + */ + private String getTableResource() { + return tableResource.getSelectedItem().toString().trim(); + } + + /** + * Get tableEngine field value. + * + * @return String + */ + private String getTableEngine() { + return tableEngine.getSelectedItem().toString().trim(); + } + + /** + * Get columnsTable values. + * + * @return List + */ + private List> getColumns() { + return columnsTableGroupWrapper.getColumnsData(); + } } From e4b19ea19b07930012bd8b247c5dfe7ef06b8632 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 20 Jan 2021 17:53:15 +0200 Subject: [PATCH 04/84] Fixed null pointer --- .../generation/dialog/NewEntityDialog.java | 14 ++ .../generation/generator/QueryGenerator.java | 155 ++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 6a2960c09..f566b05b6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -10,6 +10,7 @@ import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; +import com.intellij.util.indexing.FileBasedIndex; import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction; import com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction; import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; @@ -18,6 +19,8 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import javax.swing.*; @@ -68,6 +71,7 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; +import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex; import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor; import com.magento.idea.magento2plugin.ui.table.DeleteRowButton; @@ -740,6 +744,7 @@ public List getFields() { @SuppressWarnings({"PMD.UnusedPrivateMethod"}) private void createUIComponents() { this.parentAcl = new FilteredComboBox(getAclResourcesList()); + this.parentMenu = new FilteredComboBox(getMenuReferences()); if (getAclResourcesList().contains(ModuleMenuXml.defaultAcl)) { parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); @@ -927,4 +932,13 @@ private String getTableEngine() { private List> getColumns() { return columnsTableGroupWrapper.getColumnsData(); } + + @NotNull + private List getMenuReferences() { + final Collection menuReferences + = FileBasedIndex.getInstance().getAllKeys(MenuIndex.KEY, project); + final ArrayList menuReferencesList = new ArrayList<>(menuReferences); + Collections.sort(menuReferencesList); + return menuReferencesList; + } } 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..93ac918dc --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java @@ -0,0 +1,155 @@ +/* + * 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.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 javax.swing.*; +import java.util.Properties; + +public class QueryGenerator 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; + private final String moduleName; + private final GetFirstClassOfFile getFirstClassOfFile; + + /** + * Ui component grid data provider constructor. + * + * @param uiComponentGridDataProviderData UiComponentGridDataProviderData + * @param moduleName String + * @param project Project + */ + public QueryGenerator( + final UiComponentDataProviderData uiComponentGridDataProviderData, + final String moduleName, + final Project project + ) { + super(project); + + this.uiComponentGridDataProviderData = uiComponentGridDataProviderData; + this.directoryGenerator = DirectoryGenerator.getInstance(); + this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); + this.project = project; + 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]; + } + + @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 = ModuleIndex.getInstance(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 + ); + } + + 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() + ); + } +} From 70f703c5e9e9cff325b70fdfefa752e0d8afb7ab Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 22 Jan 2021 01:07:33 +0200 Subject: [PATCH 05/84] Added posibility to generate db_schema.xml and db_schema_whitelist.json from entity manager dialog --- .../generation/data/DbSchemaXmlData.java | 2 +- .../data/util/DbSchemaXmlSourceDataUtil.java | 0 .../generation/dialog/NewEntityDialog.java | 386 ++++++++++-------- .../generator/util/DbSchemaGeneratorUtil.java | 111 +++++ .../magento/files/ModuleDbSchemaXml.java | 75 ++-- .../magento/packages/PropertiesTypes.java | 55 +++ .../packages/database/ColumnAttributes.java | 85 ++++ .../PropertyToDefaultTypeMapperUtil.java | 39 ++ 8 files changed, 541 insertions(+), 212 deletions(-) delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorUtil.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/database/ColumnAttributes.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/database/PropertyToDefaultTypeMapperUtil.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java index 271d0d209..19ad86334 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java @@ -87,7 +87,7 @@ public void setColumns(final List> columns) { * @return Map */ public Map getTableAttributesMap() { - final Map tableAttributesData = new LinkedHashMap<>();//NOPMD + final Map tableAttributesData = new LinkedHashMap<>(); tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName()); tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource()); tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine()); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java b/src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index f566b05b6..883e1d9b6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -7,26 +7,10 @@ import com.google.common.base.CaseFormat; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.util.indexing.FileBasedIndex; -import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction; -import com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction; import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import javax.swing.*; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableColumn; - import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; @@ -46,9 +30,11 @@ 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.data.code.ClassPropertyData; +import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.actions.generation.generator.AclXmlGenerator; 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.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; @@ -60,6 +46,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; +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.DataModel; @@ -71,15 +58,37 @@ import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; 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.stubs.indexes.xml.MenuIndex; import com.magento.idea.magento2plugin.ui.FilteredComboBox; -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.ui.table.TableGroupWrapper; 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.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +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.Map; +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.KeyStroke; +import javax.swing.table.DefaultTableModel; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; @@ -89,6 +98,9 @@ "PMD.DataClass", "PMD.UnusedPrivateField", "PMD.ExcessiveImports", + "PMD.GodClass", + "PMD.TooManyMethods", + "PMD.CyclomaticComplexity" }) public class NewEntityDialog extends AbstractDialog { @NotNull @@ -142,14 +154,11 @@ public class NewEntityDialog extends AbstractDialog { private JComboBox tableResource; private JLabel tableResourceLabel; private final List properties; - // Table Columns UI components group - private TableGroupWrapper columnsTableGroupWrapper; + 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 PROPERTY_ACTION = "Action"; - private static final String PROPERTY_DELETE = "Delete"; private JTextField observerName; @@ -183,13 +192,14 @@ public void windowClosing(final WindowEvent event) { } }); + initializeComboboxSources(); initPropertiesTable(); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( - (final ActionEvent event) -> onCancel(), - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + (final ActionEvent event) -> onCancel(), + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); } @@ -206,37 +216,39 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } + /** + * 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 DefaultTableModel propertiesTable = getPropertiesTable(); - propertiesTable.setDataVector( - new Object[][]{}, - new Object[]{ + final List columns = new LinkedList<>(Arrays.asList( PROPERTY_NAME, - PROPERTY_TYPE, - PROPERTY_ACTION - } + 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 ); - - final TableColumn column = propertyTable.getColumn(PROPERTY_ACTION); - column.setCellRenderer(new TableButton(PROPERTY_DELETE)); - column.setCellEditor(new DeleteRowButton(new JCheckBox())); - - addProperty.addActionListener(e -> { - propertiesTable.addRow(new Object[]{ - "", - PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) - .getPropertyType(), - PROPERTY_DELETE - }); - }); - - initPropertyTypeColumn(); - } - - private void initPropertyTypeColumn() { - final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE); - formElementTypeColumn.setCellEditor(new ComboBoxEditor(PropertiesTypes.getPropertyTypes())); - formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes())); + entityPropertiesTableGroupWrapper.initTableGroup(); } private DefaultTableModel getPropertiesTable() { @@ -268,13 +280,22 @@ private void onOK() { generateMenuFile(); generateUiComponentGridFile(); - generateDbSchemaXmlFile(); + final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( + getDbTableName(), + getTableResource(), + getTableEngine(), + getEntityName(), + getEntityProperties() + ); + + generateDbSchemaXmlFile(dbSchemaXmlData); + generateWhitelistJsonFile(dbSchemaXmlData); } private PsiFile generateModelFile() { final NamespaceBuilder modelNamespace = getModelNamespace(); final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - String resourceModelName = getResourceModelName(); + final String resourceModelName = getResourceModelName(); return new ModuleModelGenerator(new ModelData( @@ -297,7 +318,11 @@ private NamespaceBuilder getDataModelNamespace() { } private NamespaceBuilder getDataModelInterfaceNamespace() { - return new NamespaceBuilder(getModuleName(), getDataModelInterfaceName(), DataModelInterface.DIRECTORY); + return new NamespaceBuilder( + getModuleName(), + getDataModelInterfaceName(), + DataModelInterface.DIRECTORY + ); } private NamespaceBuilder getResourceModelNamespace() { @@ -365,10 +390,10 @@ private PsiFile generateCollectionFile() { final NamespaceBuilder modelNamespace = getModelNamespace(); final NamespaceBuilder collectionNamespace = getCollectionNamespace(); final StringBuilder modelFqn = new StringBuilder(modelNamespace.getClassFqn()); - String modelName = getModelName(); + final String modelName = getModelName(); final StringBuilder resourceModelFqn = new StringBuilder(resourceModelNamespace.getClassFqn()); - String resourceModelName = getResourceModelName(); + final String resourceModelName = getResourceModelName(); return new ModuleCollectionGenerator(new CollectionData( @@ -386,7 +411,7 @@ private PsiFile generateCollectionFile() { } private void generateDataModelFile() { - NamespaceBuilder nameSpaceBuilder = getDataModelNamespace(); + final NamespaceBuilder nameSpaceBuilder = getDataModelNamespace(); new DataModelGenerator(project, new DataModelData( getDataModelNamespace().getNamespace(), getDataModelName(), @@ -398,7 +423,7 @@ private void generateDataModelFile() { } private void generateDataModelInterfaceFile() { - NamespaceBuilder nameSpaceBuilder = getDataModelInterfaceNamespace(); + final NamespaceBuilder nameSpaceBuilder = getDataModelInterfaceNamespace(); new DataModelInterfaceGenerator(project, new DataModelInterfaceData( nameSpaceBuilder.getNamespace(), getDataModelInterfaceName(), @@ -428,22 +453,22 @@ private void formatProperties() { name = getEntityIdColumn(); type = "int"; 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) + 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()); 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) + 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()); } } @@ -475,19 +500,19 @@ public String getRoute() { private PsiFile generateViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getViewActionName(), - getViewControllerDirectory() + getModuleName(), + getViewActionName(), + getViewControllerDirectory() ); return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getViewActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), - getAcl(), - true, - namespace.getNamespace() + getViewControllerDirectory(), + getViewActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() ), project).generate(ACTION_NAME, false); } @@ -496,7 +521,7 @@ private String getViewActionName() { } private String getSubmitActionName() { - return "Save"; + return "Save";//NOPMD } private String getViewControllerDirectory() { @@ -509,19 +534,19 @@ private String getControllerDirectory() { private PsiFile generateSubmitControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getSubmitActionName(), - getViewControllerDirectory() + getModuleName(), + getSubmitActionName(), + getViewControllerDirectory() ); return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getSubmitActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.POST.toString(), - getAcl(), - true, - namespace.getNamespace() + getViewControllerDirectory(), + getSubmitActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.POST.toString(), + getAcl(), + true, + namespace.getNamespace() ), project).generate(ACTION_NAME, false); } @@ -638,41 +663,41 @@ protected List getButtons() { final List buttons = new ArrayList(); final String directory = "Block/Form"; - NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( - getModuleName(), - "Save", - directory + final NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( + getModuleName(), + "Save", + directory ); buttons.add(new UiComponentFormButtonData( - directory, - "SaveEntity", - getModuleName(), - "Save", - namespaceBuilderSave.getNamespace(), - "Save Entity", - "10", - getFormName(), - namespaceBuilderSave.getClassFqn() + directory, + "SaveEntity", + getModuleName(), + "Save", + namespaceBuilderSave.getNamespace(), + "Save Entity", + "10", + getFormName(), + namespaceBuilderSave.getClassFqn() )); - NamespaceBuilder namespaceBuilderBack = new NamespaceBuilder( - getModuleName(), - "Back", - directory + final NamespaceBuilder namespaceBuilderBack = new NamespaceBuilder( + getModuleName(), + "Back", + directory ); buttons.add(new UiComponentFormButtonData( - directory, - "Back", - getModuleName(), - "Back", - namespaceBuilderBack.getNamespace(), - "Back To Grid", - "20", - getFormName(), - namespaceBuilderBack.getClassFqn() + directory, + "Back", + getModuleName(), + "Back", + namespaceBuilderBack.getNamespace(), + "Back To Grid", + "20", + getFormName(), + namespaceBuilderBack.getClassFqn() )); - NamespaceBuilder namespaceBuilderDelete = new NamespaceBuilder( + final NamespaceBuilder namespaceBuilderDelete = new NamespaceBuilder( getModuleName(), "Delete", directory @@ -701,15 +726,15 @@ public List getFields() { final ArrayList fieldsets = new ArrayList<>(); fieldsets.add( - new UiComponentFormFieldData( - "entity_id", - "int", - "Entity ID", - "0", - "general", - "hidden", - "entity_id" - ) + new UiComponentFormFieldData( + "entity_id", + "int", + "Entity ID", + "0", + "general", + "hidden", + "entity_id" + ) ); for (int count = 0; count < model.getRowCount(); count++) { @@ -724,17 +749,17 @@ public List getFields() { final String source = model.getValueAt(count, 0).toString(); //todo: convert final UiComponentFormFieldData fieldsetData = new UiComponentFormFieldData(//NOPMD - name, - label, - sortOrder, - fieldset, - formElementType, - dataType, - source + name, + label, + sortOrder, + fieldset, + formElementType, + dataType, + source ); fieldsets.add( - fieldsetData + fieldsetData ); } @@ -757,30 +782,30 @@ private List getAclResourcesList() { private PsiFile generateGridViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - "Listing", - getControllerDirectory() + getModuleName(), + "Listing", + getControllerDirectory() ); return new ModuleControllerClassGenerator(new ControllerFileData( - getControllerDirectory(), - "Listing", - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), - getAcl(), - true, - namespace.getNamespace() + getControllerDirectory(), + "Listing", + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() ), project).generate(ACTION_NAME, false); } private PsiFile generateGridLayoutFile() { return new LayoutXmlGenerator(new LayoutXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName(), - getEntityName(), - "Listing", - getGridName() + Areas.adminhtml.toString(), + getRoute(), + getModuleName(), + getEntityName(), + "Listing", + getGridName() ), project).generate(ACTION_NAME, false); } @@ -826,8 +851,8 @@ public String getMenuTitle() { private void generateUiComponentGridFile() { final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( - getUiComponentGridData(), - project + getUiComponentGridData(), + project ); gridXmlGenerator.generate(ACTION_NAME, true); } @@ -891,18 +916,27 @@ private Boolean getAddBookmarksCheckBox() { /** * Run db_schema.xml file generator. + * + * @param dbSchemaXmlData DbSchemaXmlData */ - private void generateDbSchemaXmlFile() { + private void generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { new DbSchemaXmlGenerator( - new DbSchemaXmlData( - getDbTableName(), - getTableResource(), - getTableEngine(), - getEntityName(), - getColumns() - ), - project, - moduleName + dbSchemaXmlData, + project, + moduleName + ).generate(ACTION_NAME, false); + } + + /** + * Run db_schema_whitelist.json generator. + * + * @param dbSchemaXmlData DbSchemaXmlData + */ + private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { + new DbSchemaWhitelistJsonGenerator( + project, + dbSchemaXmlData, + moduleName ).generate(ACTION_NAME, false); } @@ -925,20 +959,28 @@ private String getTableEngine() { } /** - * Get columnsTable values. + * Get entity properties table columns data and format to suitable for generator. * - * @return List + * @return List of entity properties stored in HashMap. */ - private List> getColumns() { - return columnsTableGroupWrapper.getColumnsData(); + private List> getEntityProperties() { + final List> shortColumnsData = + entityPropertiesTableGroupWrapper.getColumnsData(); + + final List> columnsData = + DbSchemaGeneratorUtil.complementShortPropertiesByDefaults(shortColumnsData); + columnsData.add(0, DbSchemaGeneratorUtil.getTableIdentityColumnData(getEntityIdColumn())); + + return columnsData; } @NotNull private List getMenuReferences() { final Collection menuReferences - = FileBasedIndex.getInstance().getAllKeys(MenuIndex.KEY, project); + = FileBasedIndex.getInstance().getAllKeys(MenuIndex.KEY, project); final ArrayList menuReferencesList = new ArrayList<>(menuReferences); Collections.sort(menuReferencesList); + return menuReferencesList; } } 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/magento/files/ModuleDbSchemaXml.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java index 9b41ffcb8..42a1e5b5a 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,6 +29,7 @@ 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"; @@ -62,7 +65,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,63 +73,57 @@ 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; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java b/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java index 197566518..81c05aa7a 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/PropertiesTypes.java @@ -5,6 +5,11 @@ 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"), @@ -13,14 +18,49 @@ public enum PropertiesTypes { 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(), @@ -29,4 +69,19 @@ public static String[] getPropertyTypes() { 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/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." + ); + } + } +} From 6483a70d295c36c76e6d9b31ff0eaa4a10ec095b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 22 Jan 2021 01:38:31 +0200 Subject: [PATCH 06/84] Code refactoring after ColumnAttributes enum type was added --- .../generation/dialog/NewDbSchemaDialog.java | 40 ++++---- .../DbSchemaWhitelistJsonGenerator.java | 5 +- .../generator/DbSchemaXmlGenerator.java | 19 ++-- .../magento/files/ModuleDbSchemaXml.java | 15 +-- .../TableColumnNamesReferenceProvider.java | 3 +- .../DbSchemaWhitelistGeneratorTest.java | 32 +++---- .../generator/DbSchemaXmlGeneratorTest.java | 91 ++++++++++--------- 7 files changed, 98 insertions(+), 107 deletions(-) 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/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/magento/files/ModuleDbSchemaXml.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java index 42a1e5b5a..7594e6f3a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java @@ -30,19 +30,6 @@ public class ModuleDbSchemaXml implements ModuleFileInterface { 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"; public static final String XML_ATTR_REFERENCE_ID_PK = "PRIMARY"; @@ -128,7 +115,7 @@ public static List getAllowedAttributes(final @NotNull TableColumnTypes default: break; } - allowedAttributes.add(XML_ATTR_COLUMN_TYPE); + allowedAttributes.add(ColumnAttributes.TYPE.getName()); return allowedAttributes; } 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/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java index b7aed8c09..ce08211f6 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java @@ -7,7 +7,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; 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; @@ -55,53 +55,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..fe75563be 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGeneratorTest.java @@ -7,6 +7,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; 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; @@ -62,89 +63,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; From a906b322601cc753423030fc19de8f77d0325fa7 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 22 Jan 2021 02:19:55 +0200 Subject: [PATCH 07/84] Added tests for db_schema.xml and db_schema_whitelist.json generation with provided entity properties instead of columns data --- .../db_schema_whitelist.json | 17 +++++++ .../db_schema.xml | 20 ++++++++ .../DbSchemaWhitelistGeneratorTest.java | 37 ++++++++++++++ .../generator/DbSchemaXmlGeneratorTest.java | 35 +++++++++++++ .../DbSchemaGeneratorDataProviderUtil.java | 51 +++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 testData/actions/generation/generator/DbSchemaWhitelistGenerator/generateDbSchemaWhitelistJsonFileForShortProperties/db_schema_whitelist.json create mode 100644 testData/actions/generation/generator/DbSchemaXmlGenerator/generateDbSchemaXmlFileForShortProperties/db_schema.xml create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/util/DbSchemaGeneratorDataProviderUtil.java 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/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaWhitelistGeneratorTest.java index ce08211f6..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,6 +6,8 @@ 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.packages.database.ColumnAttributes; import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes; @@ -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. * 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 fe75563be..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,6 +6,8 @@ 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; @@ -53,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. * 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; + } +} From 71ade4c809faef70606a1f606f4ffdae009512eb Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Fri, 22 Jan 2021 23:46:49 +0200 Subject: [PATCH 08/84] Improved data model generation integrated with the entity manager --- .../generation/dialog/NewEntityDialog.form | 21 ++++++++--- .../generation/dialog/NewEntityDialog.java | 37 +++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index fe2ed32b8..4c218161e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -21,7 +21,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -97,7 +97,7 @@ - + @@ -112,7 +112,7 @@ - + @@ -125,6 +125,15 @@ + + + + + + + + +
diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 883e1d9b6..807606b1f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -11,6 +11,7 @@ import com.intellij.psi.PsiFile; import com.intellij.util.indexing.FileBasedIndex; import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; +import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction; import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; @@ -20,6 +21,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; @@ -42,6 +44,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; @@ -64,6 +67,7 @@ import com.magento.idea.magento2plugin.ui.FilteredComboBox; import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper; import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; @@ -153,6 +157,7 @@ public class NewEntityDialog extends AbstractDialog { private JLabel tableEngineLabel; private JComboBox tableResource; private JLabel tableResourceLabel; + private JCheckBox createInterface; private final List properties; private TableGroupWrapper entityPropertiesTableGroupWrapper; @@ -262,10 +267,13 @@ private void onOK() { generateModelFile(); generateResourceModelFile(); generateCollectionFile(); - formatProperties(); generateDataModelFile(); - generateDataModelInterfaceFile(); + + if (createInterface.isSelected()) { + generateDataModelInterfaceFile(); + generateDataModelPreference(); + } generateRoutesXmlFile(); generateViewControllerFile(); @@ -274,7 +282,6 @@ private void onOK() { generateLayoutFile(); generateFormFile(); generateAclXmlFile(); - generateGridViewControllerFile(); generateGridLayoutFile(); generateMenuFile(); @@ -290,6 +297,7 @@ private void onOK() { generateDbSchemaXmlFile(dbSchemaXmlData); generateWhitelistJsonFile(dbSchemaXmlData); + this.setVisible(false); } private PsiFile generateModelFile() { @@ -333,6 +341,23 @@ private NamespaceBuilder getResourceModelNamespace() { ); } + /** + * Generate preference for data model. + */ + private void generateDataModelPreference() { + final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder modelInterfaceNamespace = getDataModelInterfaceNamespace(); + new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( + getModuleName(), + GetPhpClassByFQN.getInstance(project).execute( + modelInterfaceNamespace.getClassFqn() + ), + modelNamespace.getClassFqn(), + getModelName(), + Areas.base.toString() + ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); + } + private String getModuleName() { return moduleName; } @@ -410,6 +435,9 @@ private PsiFile generateCollectionFile() { ), project).generate(ACTION_NAME, true); } + /** + * Generate Data Model File. + */ private void generateDataModelFile() { final NamespaceBuilder nameSpaceBuilder = getDataModelNamespace(); new DataModelGenerator(project, new DataModelData( @@ -418,7 +446,8 @@ private void generateDataModelFile() { getModuleName(), nameSpaceBuilder.getClassFqn(), getDataModelInterfaceNamespace().getClassFqn(), - getProperties() + getProperties(), + createInterface.isSelected() )).generate(ACTION_NAME, true); } From b70044bb854716ce362f9a904fb69af62f5d56da Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Mon, 25 Jan 2021 10:42:29 +0200 Subject: [PATCH 09/84] Prettified form --- .../generation/dialog/NewEntityDialog.form | 190 +++++++++--------- .../generation/dialog/NewEntityDialog.java | 1 - 2 files changed, 91 insertions(+), 100 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index 4c218161e..e4e7aa74b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -1,6 +1,6 @@
- + @@ -29,14 +29,6 @@ - - - - - - - - @@ -45,14 +37,6 @@ - - - - - - - - @@ -125,18 +109,26 @@ + + + + + + + + - + - + - + @@ -210,6 +202,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -443,85 +514,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 807606b1f..546d76383 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -119,7 +119,6 @@ public class NewEntityDialog extends AbstractDialog { private JButton buttonCancel; private JPanel generalTable; private JCheckBox createUiComponent; - private JLabel createUiComponentsLabel; private JTextField entityName; private JLabel entityNameLabel; private JLabel dbTableNameLabel; From 61f3f000c2ec90bf298cb81e482bc7cea1a86e4d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 25 Jan 2021 14:46:27 +0200 Subject: [PATCH 10/84] Added get list query model and injected into data provider --- resources/META-INF/plugin.xml | 1 + .../Magento Get List Query Model.php.ft | 90 ++++++++++ .../Magento Get List Query Model.php.html | 18 ++ ...omponent Custom Data Provider Class.php.ft | 86 +++++++++- .../data/GetListQueryModelData.java | 82 +++++++++ .../data/UiComponentDataProviderData.java | 28 +++ .../generation/dialog/NewEntityDialog.java | 82 ++++++++- .../generator/GetListQueryModelGenerator.java | 159 ++++++++++++++++++ .../UiComponentDataProviderGenerator.java | 100 ++++++++++- .../files/UiComponentDataProviderPhp.java | 2 + .../magento/files/queries/GetListQuery.java | 67 ++++++++ .../packages/code/FrameworkLibraryType.java | 75 +++++++++ .../GetListQuery.php | 95 +++++++++++ .../GridDataProvider.php | 3 + .../GridDataProvider.php | 85 ++++++++++ .../generator/QueryModelGeneratorTest.java | 45 +++++ ...omponentGridDataProviderGeneratorTest.java | 41 +++++ 17 files changed, 1041 insertions(+), 18 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Get List Query Model.php.ft create mode 100644 resources/fileTemplates/internal/Magento Get List Query Model.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java create mode 100644 testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php create mode 100644 testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/QueryModelGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 48e5211a0..f2537aa10 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -228,6 +228,7 @@ + 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 UI Component Custom Data Provider Class.php.ft b/resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft index 38c301727..27151b44a 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,91 @@ 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' + ); + } +#else /** * @inheritDoc */ @@ -19,4 +96,5 @@ class ${CLASS_NAME} extends DataProvider [] ]; } +#end } 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..41178ecbb --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java @@ -0,0 +1,82 @@ +/* + * 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 collectionType; + private final String collectionTypeFactory; + private final String entityDataMapperType; + + /** + * Query Model DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param collectionType String + * @param entityDataMapperType String + */ + public GetListQueryModelData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String collectionType, + final @NotNull String entityDataMapperType + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.collectionType = collectionType; + this.collectionTypeFactory = collectionType.concat("Factory"); + this.entityDataMapperType = entityDataMapperType; + } + + /** + * Get Query model module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity collection type. + * + * @return String + */ + public String getCollectionType() { + return collectionType; + } + + /** + * Get entity collection type factory. + * + * @return String + */ + public String getCollectionTypeFactory() { + return collectionTypeFactory; + } + + /** + * Get entity data mapper type. + * + * @return String + */ + public String getEntityDataMapperType() { + return entityDataMapperType; + } +} 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..e82cafb20 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentDataProviderData.java @@ -10,6 +10,7 @@ public class UiComponentDataProviderData { private final String name; private final String namespace; private final String path; + private final String entityIdFieldName; /** * UiComponentGridDataProviderData constructor. @@ -22,10 +23,28 @@ public UiComponentDataProviderData( final String name, final String namespace, final String path + ) { + this(name, namespace, path, null); + } + + /** + * UiComponentGridDataProviderData constructor. + * + * @param name String + * @param namespace String + * @param path String + * @param entityIdFieldName String + */ + public UiComponentDataProviderData( + final String name, + final String namespace, + final String path, + final String entityIdFieldName ) { this.name = name; this.namespace = namespace; this.path = path; + this.entityIdFieldName = entityIdFieldName; } /** @@ -54,4 +73,13 @@ public String getNamespace() { public String getPath() { return path; } + + /** + * Get entity id field name. + * + * @return String + */ + public String getEntityIdFieldName() { + return entityIdFieldName; + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 883e1d9b6..d76a29c82 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -20,6 +20,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; @@ -42,6 +43,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; @@ -54,6 +56,7 @@ import com.magento.idea.magento2plugin.magento.files.ModelPhp; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; @@ -270,6 +273,7 @@ private void onOK() { generateRoutesXmlFile(); generateViewControllerFile(); generateSubmitControllerFile(); + generateModelGetListQueryFile(); generateDataProviderFile(); generateLayoutFile(); generateFormFile(); @@ -349,6 +353,11 @@ private String getDataModelName() { return getEntityName().concat("Data"); } + /** + * Get data provider class name. + * + * @return String + */ private String getDataProviderClassName() { return getEntityName().concat("DataProvider"); } @@ -381,6 +390,11 @@ private PsiFile generateResourceModelFile() { ), project).generate(ACTION_NAME, true); } + /** + * Get entity id column name. + * + * @return String + */ private String getEntityIdColumn() { return entityId.getText().trim(); } @@ -554,15 +568,26 @@ public String getAcl() { return acl.getText().trim(); } - private PsiFile generateDataProviderFile() { - final NamespaceBuilder namespace = getDataProviderNamespace(); - return new UiComponentDataProviderGenerator(new UiComponentDataProviderData( - getDataProviderClassName(), - namespace.getNamespace(), - getDataProviderDirectory() - ), getModuleName(), project).generate(ACTION_NAME, false); + /** + * Generate data provider file. + */ + private void generateDataProviderFile() { + if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { + final NamespaceBuilder namespaceBuilder = getDataProviderNamespace(); + new UiComponentDataProviderGenerator(new UiComponentDataProviderData( + getDataProviderClassName(), + namespaceBuilder.getNamespace(), + getDataProviderDirectory(), + getEntityIdColumn() + ), getModuleName(), project).generate(ACTION_NAME, false); + } } + /** + * Get data provider namespace builder. + * + * @return NamespaceBuilder + */ @NotNull private NamespaceBuilder getDataProviderNamespace() { return new NamespaceBuilder( @@ -572,10 +597,26 @@ private NamespaceBuilder getDataProviderNamespace() { ); } + /** + * Get data provider directory. + * + * @return String + */ public String getDataProviderDirectory() { + // TODO: add ui part with dynamic implementation. return "UI/DataProvider"; } + /** + * Get data provider type. + * + * @return String + */ + public String getDataProviderType() { + // TODO: add ui part with dynamic implementation. + return UiComponentDataProviderPhp.CUSTOM_TYPE; + } + private PsiFile generateLayoutFile() { return new LayoutXmlGenerator(new LayoutXmlData( Areas.adminhtml.toString(), @@ -940,6 +981,33 @@ private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXm ).generate(ACTION_NAME, false); } + /** + * Run GetListQuery.php file generator. + */ + private void generateModelGetListQueryFile() { + final String entityCollectionType = getCollectionNamespace().getClassFqn(); + + new GetListQueryModelGenerator( + new GetListQueryModelData( + getModuleName(), + getEntityName(), + entityCollectionType, + getEntityDataMapperType() + ), + project + ).generate(ACTION_NAME, true); + } + + /** + * Get entity data mapper type. + * + * @return String + */ + private String getEntityDataMapperType() { + // TODO: implement with entity data mapper generation. + return "Test\\Test\\Mapper\\" + getEntityName() + "DataMapper"; + } + /** * Get tableResource field value. * 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..ba7eb9f22 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java @@ -0,0 +1,159 @@ +/* + * 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.GetListQueryModelData; +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.queries.GetListQuery; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class GetListQueryModelGenerator extends FileGenerator { + + private final Project project; + private final GetListQueryModelData queryModelData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final NamespaceBuilder queryModelNamespaceBuilder; + private final boolean checkFileAlreadyExists; + + /** + * Query model generator Constructor. + * + * @param queryModelData QueryModelData + * @param project Project + */ + public GetListQueryModelGenerator( + final @NotNull GetListQueryModelData queryModelData, + final @NotNull Project project + ) { + this(queryModelData, project, true); + } + + /** + * Query model generator Constructor. + * + * @param queryModelData QueryModelData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public GetListQueryModelGenerator( + final @NotNull GetListQueryModelData queryModelData, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.project = project; + this.queryModelData = queryModelData; + this.checkFileAlreadyExists = checkFileAlreadyExists; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + queryModelNamespaceBuilder = new NamespaceBuilder( + queryModelData.getModuleName(), + GetListQuery.CLASS_NAME, + GetListQuery.DIRECTORY + ); + } + + /** + * Generate Get List Query model. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass getListQueryClass = GetPhpClassByFQN.getInstance(project).execute( + GetListQuery.getClassFqn(queryModelData.getModuleName()) + ); + + if (this.checkFileAlreadyExists && getListQueryClass != null) { + return getListQueryClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + queryModelData.getModuleName() + ); + final PsiDirectory queryModelBaseDir = directoryGenerator.findOrCreateSubdirectory( + moduleBaseDir, + GetListQuery.DIRECTORY + ); + + return fileFromTemplateGenerator.generate( + GetListQuery.getInstance(), + getAttributes(), + queryModelBaseDir, + actionName + ); + } + + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final List uses = new LinkedList<>(); + + uses.add(queryModelData.getCollectionTypeFactory()); + uses.add(queryModelData.getCollectionType()); + uses.add(queryModelData.getEntityDataMapperType()); + uses.add(FrameworkLibraryType.COLLECTION_PROCESSOR.getType()); + uses.add(FrameworkLibraryType.SEARCH_CRITERIA_BUILDER.getType()); + uses.add(FrameworkLibraryType.SEARCH_CRITERIA.getType()); + uses.add(FrameworkLibraryType.SEARCH_RESULT.getFactory()); + uses.add(FrameworkLibraryType.SEARCH_RESULT.getType()); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + attributes.setProperty("ENTITY_NAME", queryModelData.getEntityName()); + attributes.setProperty("NAMESPACE", queryModelNamespaceBuilder.getNamespace()); + attributes.setProperty("CLASS_NAME", GetListQuery.CLASS_NAME); + attributes.setProperty( + "ENTITY_COLLECTION_FACTORY_TYPE", + PhpClassGeneratorUtil.getNameFromFqn( + queryModelData.getCollectionTypeFactory() + ) + ); + attributes.setProperty( + "ENTITY_COLLECTION_TYPE", + PhpClassGeneratorUtil.getNameFromFqn( + queryModelData.getCollectionType() + ) + ); + attributes.setProperty( + "ENTITY_DATA_MAPPER_TYPE", + PhpClassGeneratorUtil.getNameFromFqn( + queryModelData.getEntityDataMapperType() + ) + ); + attributes.setProperty("COLLECTION_PROCESSOR_TYPE", + FrameworkLibraryType.COLLECTION_PROCESSOR.getTypeName()); + attributes.setProperty("SEARCH_CRITERIA_BUILDER_TYPE", + FrameworkLibraryType.SEARCH_CRITERIA_BUILDER.getTypeName()); + attributes.setProperty("SEARCH_CRITERIA_TYPE", + FrameworkLibraryType.SEARCH_CRITERIA.getTypeName()); + attributes.setProperty("SEARCH_RESULT_FACTORY_TYPE", + FrameworkLibraryType.SEARCH_RESULT.getFactoryName()); + attributes.setProperty("SEARCH_RESULT_TYPE", + FrameworkLibraryType.SEARCH_RESULT.getTypeName()); + } +} 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 6cdd90f5c..23832539b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java @@ -14,16 +14,22 @@ 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.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.UiComponentDataProviderPhp; +import com.magento.idea.magento2plugin.magento.files.queries.GetListQuery; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.LinkedList; +import java.util.List; import java.util.Properties; import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; @SuppressWarnings({"PMD.OnlyOneReturn", "PMD.DataflowAnomalyAnalysis"}) public class UiComponentDataProviderGenerator extends FileGenerator { @@ -44,12 +50,11 @@ public class UiComponentDataProviderGenerator extends FileGenerator { * @param project Project */ public UiComponentDataProviderGenerator( - final UiComponentDataProviderData uiComponentGridDataProviderData, - final String moduleName, - final Project project + final @NotNull UiComponentDataProviderData uiComponentGridDataProviderData, + final @NotNull String moduleName, + final @NotNull Project project ) { super(project); - this.uiComponentGridDataProviderData = uiComponentGridDataProviderData; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); @@ -60,8 +65,15 @@ public UiComponentDataProviderGenerator( this.moduleName = moduleName; } + /** + * Generate UiComponent data provider class. + * + * @param actionName String + * + * @return PsiFile + */ @Override - public PsiFile generate(final String actionName) { + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] dataProviderFiles = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { @@ -107,13 +119,82 @@ public PsiFile generate(final String actionName) { return dataProviderFiles[0]; } + /** + * Fill file property attributes. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { + protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("NAMESPACE", uiComponentGridDataProviderData.getNamespace()); attributes.setProperty("CLASS_NAME", uiComponentGridDataProviderData.getName()); + + if (uiComponentGridDataProviderData.getEntityIdFieldName() != null) { + attributes.setProperty( + "ENTITY_ID", + uiComponentGridDataProviderData.getEntityIdFieldName() + ); + } + attributes.setProperty("HAS_GET_LIST_QUERY", "false"); + + final List uses = new LinkedList<>(); + + uses.add(UiComponentDataProviderPhp.DEFAULT_DATA_PROVIDER); + attributes.setProperty( + "EXTENDS", + PhpClassGeneratorUtil.getNameFromFqn( + UiComponentDataProviderPhp.DEFAULT_DATA_PROVIDER + ) + ); + + final PhpClass getListQueryFile = GetPhpClassByFQN.getInstance(project).execute( + GetListQuery.getClassFqn(moduleName) + ); + + if (getListQueryFile == null) { + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + return; + } + attributes.setProperty("HAS_GET_LIST_QUERY", "true"); + + uses.add(FrameworkLibraryType.REPORTING.getType()); + attributes.setProperty("REPORTING_TYPE", FrameworkLibraryType.REPORTING.getTypeName()); + + uses.add(FrameworkLibraryType.API_SEARCH_CRITERIA_BUILDER.getType()); + attributes.setProperty("SEARCH_CRITERIA_BUILDER", + FrameworkLibraryType.API_SEARCH_CRITERIA_BUILDER.getTypeName()); + + uses.add(FrameworkLibraryType.REQUEST.getType()); + attributes.setProperty("REQUEST_TYPE", FrameworkLibraryType.REQUEST.getTypeName()); + + uses.add(FrameworkLibraryType.FILTER_BUILDER.getType()); + attributes.setProperty("FILTER_BUILDER", FrameworkLibraryType.FILTER_BUILDER.getTypeName()); + + uses.add(UiComponentDataProviderPhp.SEARCH_RESULT_FACTORY); + attributes.setProperty("SEARCH_RESULT_FACTORY", + PhpClassGeneratorUtil.getNameFromFqn( + UiComponentDataProviderPhp.SEARCH_RESULT_FACTORY + ) + ); + + final @NotNull String getListQueryFqn = getListQueryFile.getPresentableFQN(); + + uses.add(getListQueryFqn); + attributes.setProperty("GET_LIST_QUERY_TYPE", PhpClassGeneratorUtil.getNameFromFqn( + getListQueryFqn + )); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); } - private PhpClass createDataProviderClass(final String actionName) { + /** + * Generate data provider class. + * + * @param actionName String + * + * @return PhpClass + */ + private PhpClass createDataProviderClass(final @NotNull String actionName) { PsiDirectory parentDirectory = ModuleIndex.getInstance(project) .getModuleDirectoryByModuleName(this.moduleName); final PsiFile dataProviderFile; @@ -144,6 +225,11 @@ private PhpClass createDataProviderClass(final String actionName) { return getFirstClassOfFile.execute((PhpFile) dataProviderFile); } + /** + * Get data provider class FQN. + * + * @return String + */ private String getDataProviderFqn() { return String.format( "%s%s%s", diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java index 24e72cec8..1cb3f62bf 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java @@ -22,6 +22,8 @@ public class UiComponentDataProviderPhp implements ModuleFileInterface { private String className; 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"; /** * Returns a new instance of the class. diff --git a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java new file mode 100644 index 000000000..34f12c60b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java @@ -0,0 +1,67 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.queries; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import com.magento.idea.magento2plugin.magento.packages.Package; +import org.jetbrains.annotations.NotNull; + +public final class GetListQuery implements ModuleFileInterface { + public static final String DIRECTORY = "Query"; + public static final String CLASS_NAME = "GetListQuery"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Get List Query Model"; + private static final GetListQuery INSTANCE = new GetListQuery(); + + /** + * Get singleton instance of the class. + * + * @return GetListQuery + */ + public static GetListQuery getInstance() { + return INSTANCE; + } + + /** + * Get class FQN. + * + * @param moduleName String + * + * @return String + */ + public static String getClassFqn(final @NotNull String moduleName) { + final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( + moduleName, + GetListQuery.CLASS_NAME, + GetListQuery.DIRECTORY + ); + + return String.format( + "%s%s%s", + namespaceBuilder.getNamespace(), + Package.fqnSeparator, + CLASS_NAME + ); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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..924554396 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -0,0 +1,75 @@ +/* + * 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 { + COLLECTION_PROCESSOR("Magento\\Framework\\Api\\SearchCriteria\\CollectionProcessorInterface"), + FILTER_BUILDER("Magento\\Framework\\Api\\FilterBuilder"), + REPORTING("Magento\\Framework\\Api\\Search\\ReportingInterface"), + REQUEST("Magento\\Framework\\App\\RequestInterface"), + SEARCH_CRITERIA("Magento\\Framework\\Api\\SearchCriteriaInterface"), + SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\SearchCriteriaBuilder"), + API_SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\Search\\SearchCriteriaBuilder"), + SEARCH_RESULT("Magento\\Framework\\Api\\SearchResultsInterface"); + + /** + * 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/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php new file mode 100644 index 000000000..dbfb79255 --- /dev/null +++ b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php @@ -0,0 +1,95 @@ +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/UiComponentGridDataProviderGenerator/generateCustomDataProvider/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateCustomDataProvider/GridDataProvider.php index 9ac857ef1..9fa4fa30f 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateCustomDataProvider/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateCustomDataProvider/GridDataProvider.php @@ -4,6 +4,9 @@ use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; +/** + * DataProvider component. + */ class GridDataProvider extends DataProvider { /** diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php new file mode 100644 index 000000000..b5ba1faa2 --- /dev/null +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -0,0 +1,85 @@ +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, + 'entity_id' + ); + } +} 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..fb30875e2 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueryModelGeneratorTest.java @@ -0,0 +1,45 @@ +/* + * 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.GetListQuery; + +public class QueryModelGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE_NAME = "Foo_Bar"; + private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/" + + GetListQuery.DIRECTORY; + private static final String ENTITY_NAME = "Book"; + private static final String COLLECTION_TYPE = "Foo\\Bar\\Model\\ResourceModel\\" + + ENTITY_NAME + "\\Collection"; + private static final String ENTITY_DATA_MAPPER_TYPE = "Foo\\Bar\\Mapper\\" + + ENTITY_NAME + "DataMapper"; + + /** + * Test generation of GetListQuery model for entity. + */ + public void testGenerateGetListQueryModelFile() { + final GetListQueryModelData getListQueryModelData = new GetListQueryModelData( + MODULE_NAME, + ENTITY_NAME, + COLLECTION_TYPE, + ENTITY_DATA_MAPPER_TYPE + ); + final GetListQueryModelGenerator getListQueryModelGenerator = + new GetListQueryModelGenerator( + getListQueryModelData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath(GetListQuery.getInstance().getFileName()); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + getListQueryModelGenerator.generate("test") + ); + } +} 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..a1f119799 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGeneratorTest.java @@ -7,14 +7,20 @@ 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 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_TYPE = "Foo\\Bar\\Model\\ResourceModel\\" + + ENTITY_NAME + "\\Collection"; + private static final String ENTITY_DATA_MAPPER_TYPE = "Foo\\Bar\\Mapper\\" + + ENTITY_NAME + "DataMapper"; /** * Test data provider class file generation with custom type. @@ -31,6 +37,27 @@ public void testGenerateCustomDataProvider() { ); } + /** + * Test data provider class file generation when get list query model exists. + */ + public void testGenerateDataProviderWithInjectedGetListQuery() { + generateGetListQuery(); + final PsiFile dataProviderFile = generateDataProvider(); + final String filePath = this.getFixturePath("GridDataProvider.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + dataProviderFile + ); + } + + /** + * Generate data provider file. + * + * @return PsiFile + */ private PsiFile generateDataProvider() { final Project project = myFixture.getProject(); final UiComponentDataProviderData providerData = new UiComponentDataProviderData( @@ -47,4 +74,18 @@ private PsiFile generateDataProvider() { 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, + COLLECTION_TYPE, + ENTITY_DATA_MAPPER_TYPE + ); + new GetListQueryModelGenerator(getListData, project, false).generate("test"); + } } From fbb083d672d915c6364a3b78b86fad838c1f9845 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 25 Jan 2021 15:07:56 +0200 Subject: [PATCH 11/84] Fixed tests --- .../actions/generation/dialog/NewEntityDialog.java | 4 ++-- .../generateGetListQueryModelFile/GetListQuery.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 059867d0e..fd16ec207 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -10,7 +10,7 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.util.indexing.FileBasedIndex; -import com.magento.idea.magento2plugin.actions.generation.NewViewModelAction; +import com.magento.idea.magento2plugin.actions.generation.NewEntityAction; import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction; import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; @@ -184,7 +184,7 @@ public NewEntityDialog(final Project project, final PsiDirectory directory) { setContentPane(contentPane); setModal(true); - setTitle(NewViewModelAction.ACTION_DESCRIPTION); + setTitle(NewEntityAction.ACTION_DESCRIPTION); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener((final ActionEvent event) -> onOK()); diff --git a/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php index dbfb79255..4e23950a9 100644 --- a/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php +++ b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php @@ -1,5 +1,4 @@ Date: Wed, 27 Jan 2021 00:17:15 +0200 Subject: [PATCH 12/84] Added save entity command class generation --- resources/META-INF/plugin.xml | 1 + .../Magento Save Entity Command Model.php.ft | 74 +++++++++ ...Magento Save Entity Command Model.php.html | 18 +++ .../data/SaveEntityCommandData.java | 110 +++++++++++++ .../generation/dialog/NewEntityDialog.java | 63 ++++++++ .../generator/SaveEntityCommandGenerator.java | 151 ++++++++++++++++++ .../files/commands/SaveEntityCommandFile.java | 94 +++++++++++ .../magento/packages/code/ExceptionType.java | 45 ++++++ .../packages/code/FrameworkLibraryType.java | 2 + .../magento/packages/code/PhpCoreType.java | 35 ++++ .../SaveCommand.php | 78 +++++++++ .../SaveEntityCommandGeneratorTest.java | 51 ++++++ 12 files changed, 722 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft create mode 100644 resources/fileTemplates/internal/Magento Save Entity Command Model.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java create mode 100644 testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f2537aa10..b57bbc095 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -229,6 +229,7 @@ + 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..793c0a48b --- /dev/null +++ b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft @@ -0,0 +1,74 @@ +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()); + $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/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..747905b6d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java @@ -0,0 +1,110 @@ +/* + * 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 namespace; + private final String classFqn; + private final String modelClassFqn; + private final String resourceModelClassFqn; + private final String dataModelClassFqn; + + /** + * Save Command DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param namespace String + * @param classFqn String + * @param modelClassFqn String + * @param resourceModelClassFqn String + * @param dataModelClassFqn String + */ + public SaveEntityCommandData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String namespace, + final @NotNull String classFqn, + final @NotNull String modelClassFqn, + final @NotNull String resourceModelClassFqn, + final @NotNull String dataModelClassFqn + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.namespace = namespace; + this.classFqn = classFqn; + this.modelClassFqn = modelClassFqn; + this.resourceModelClassFqn = resourceModelClassFqn; + this.dataModelClassFqn = dataModelClassFqn; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get class FQN. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * Get entity model class FQN. + * + * @return String + */ + public String getModelClassFqn() { + return modelClassFqn; + } + + /** + * Get entity resource model class FQN. + * + * @return String + */ + public String getResourceModelClassFqn() { + return resourceModelClassFqn; + } + + /** + * Get entity DTO class FQN. + * + * @return String + */ + public String getDataModelClassFqn() { + return dataModelClassFqn; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index fd16ec207..922581691 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -25,6 +25,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldData; @@ -48,6 +49,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; @@ -60,6 +62,7 @@ import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; +import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; @@ -281,6 +284,7 @@ private void onOK() { generateViewControllerFile(); generateSubmitControllerFile(); generateModelGetListQueryFile(); + generateSaveEntityCommandFile(); generateDataProviderFile(); generateLayoutFile(); generateFormFile(); @@ -320,14 +324,29 @@ private PsiFile generateModelFile() { ), project).generate(ACTION_NAME, true); } + /** + * Get Magento 2 model namespace builder for the entity. + * + * @return NamespaceBuilder + */ private NamespaceBuilder getModelNamespace() { return new NamespaceBuilder(getModuleName(), getModelName(), ModelPhp.MODEL_DIRECTORY); } + /** + * Get DTO model namespace builder for the entity. + * + * @return NamespaceBuilder + */ private NamespaceBuilder getDataModelNamespace() { return new NamespaceBuilder(getModuleName(), getDataModelName(), DataModel.DIRECTORY); } + /** + * Get DTO model interface namespace builder for the entity. + * + * @return NamespaceBuilder + */ private NamespaceBuilder getDataModelInterfaceNamespace() { return new NamespaceBuilder( getModuleName(), @@ -336,6 +355,11 @@ private NamespaceBuilder getDataModelInterfaceNamespace() { ); } + /** + * Get Magento 2 Resource model namespace builder for the entity. + * + * @return NamespaceBuilder + */ private NamespaceBuilder getResourceModelNamespace() { return new NamespaceBuilder( getModuleName(), @@ -1036,6 +1060,45 @@ private String getEntityDataMapperType() { return "Test\\Test\\Mapper\\" + getEntityName() + "DataMapper"; } + /** + * Run SaveCommand.php file generator for an entity. + */ + private void generateSaveEntityCommandFile() { + final String classFqn = SaveEntityCommandFile.getClassFqn( + getModuleName(), + getEntityName() + ); + final String namespace = SaveEntityCommandFile.getNamespace( + getModuleName(), + getEntityName() + ); + final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); + final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); + final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); + + final String dtoType; + + if (createInterface.isSelected()) { + dtoType = dtoInterfaceModelNamespace.getClassFqn(); + } else { + dtoType = dtoModelNamespace.getClassFqn(); + } + + new SaveEntityCommandGenerator( + new SaveEntityCommandData( + getModuleName(), + getEntityName(), + namespace, + classFqn, + modelNamespace.getClassFqn(), + resourceModelNamespace.getClassFqn(), + dtoType + ), + project + ).generate(ACTION_NAME, true); + } + /** * Get tableResource field value. * 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..d273dbe26 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -0,0 +1,151 @@ +/* + * 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.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; +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.indexes.ModuleIndex; +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 com.magento.idea.magento2plugin.magento.packages.code.PhpCoreType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandGenerator extends FileGenerator { + + private final Project project; + private final SaveEntityCommandData saveEntityCommandData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + + /** + * Save entity command generator constructor. + * + * @param saveEntityCommandData SaveEntityCommandData + * @param project Project + */ + public SaveEntityCommandGenerator( + final @NotNull SaveEntityCommandData saveEntityCommandData, + final @NotNull Project project + ) { + this(saveEntityCommandData, project, true); + } + + /** + * Save entity command generator constructor. + * + * @param saveEntityCommandData SaveEntityCommandData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SaveEntityCommandGenerator( + final @NotNull SaveEntityCommandData saveEntityCommandData, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.saveEntityCommandData = saveEntityCommandData; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + } + + /** + * Generate save command for entity. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass saveEntityCommandClass = GetPhpClassByFQN.getInstance(project).execute( + saveEntityCommandData.getClassFqn() + ); + + if (this.checkFileAlreadyExists && saveEntityCommandClass != null) { + return saveEntityCommandClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + saveEntityCommandData.getModuleName() + ); + final PsiDirectory saveCommandFileBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + SaveEntityCommandFile.getDirectory(saveEntityCommandData.getEntityName()) + ); + + return fileFromTemplateGenerator.generate( + SaveEntityCommandFile.getInstance(), + getAttributes(), + saveCommandFileBaseDir, + actionName + ); + } + + /** + * Fill save command file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final List uses = new LinkedList<>(); + uses.add(PhpCoreType.EXCEPTION.getType()); + uses.add(FrameworkLibraryType.DATA_OBJECT.getType()); + uses.add(ExceptionType.COULD_NOT_SAVE.getType()); + uses.add(FrameworkLibraryType.LOGGER.getType()); + + final String dtoType = saveEntityCommandData.getDataModelClassFqn(); + uses.add(dtoType); + attributes.setProperty("DTO", PhpClassGeneratorUtil.getNameFromFqn(dtoType)); + + final String dtoProperty = CaseFormat.UPPER_CAMEL.to( + CaseFormat.LOWER_CAMEL, saveEntityCommandData.getEntityName() + ); + attributes.setProperty("DTO_PROPERTY", dtoProperty); + + final String modelType = saveEntityCommandData.getModelClassFqn(); + uses.add(modelType); + attributes.setProperty("MODEL", PhpClassGeneratorUtil.getNameFromFqn(modelType)); + + final String modelFactoryType = modelType.concat("Factory"); + uses.add(modelFactoryType); + attributes.setProperty("MODEL_FACTORY", + PhpClassGeneratorUtil.getNameFromFqn(modelFactoryType) + ); + + final String resourceType = saveEntityCommandData.getResourceModelClassFqn(); + uses.add(resourceType); + attributes.setProperty("RESOURCE", PhpClassGeneratorUtil.getNameFromFqn(resourceType)); + + attributes.setProperty("ENTITY_NAME", saveEntityCommandData.getEntityName()); + attributes.setProperty("NAMESPACE", saveEntityCommandData.getNamespace()); + attributes.setProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME); + + attributes.setProperty("EXCEPTION", PhpCoreType.EXCEPTION.getType()); + attributes.setProperty("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getTypeName()); + attributes.setProperty("COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getTypeName()); + attributes.setProperty("LOGGER", FrameworkLibraryType.LOGGER.getTypeName()); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } +} 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..8fdd87a31 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java @@ -0,0 +1,94 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.commands; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import com.magento.idea.magento2plugin.magento.packages.Package; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityCommandFile implements ModuleFileInterface { + public static final String CLASS_NAME = "SaveCommand"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Save Entity Command Model"; + private static final String DIRECTORY = "Command"; + private static final SaveEntityCommandFile INSTANCE = new SaveEntityCommandFile(); + + /** + * Get singleton object of save command file. + * + * @return SaveEntityCommandFile + */ + public static SaveEntityCommandFile getInstance() { + return INSTANCE; + } + + /** + * Get namespace. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull String getNamespace( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( + moduleName, + SaveEntityCommandFile.CLASS_NAME, + SaveEntityCommandFile.getDirectory(entityName) + ); + + return namespaceBuilder.getNamespace(); + } + + /** + * Get class FQN. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static String getClassFqn( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return getNamespace(moduleName, entityName) + .concat(Package.fqnSeparator) + .concat(CLASS_NAME); + } + + /** + * Get directory for save command file. + * + * @param entityName String + * + * @return String + */ + public static String getDirectory(final @NotNull String entityName) { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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..9e4d426c5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java @@ -0,0 +1,45 @@ +/* + * 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"); + + /** + * 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 index 924554396..4d0f97f05 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -10,7 +10,9 @@ public enum FrameworkLibraryType { COLLECTION_PROCESSOR("Magento\\Framework\\Api\\SearchCriteria\\CollectionProcessorInterface"), + DATA_OBJECT("Magento\\Framework\\DataObject"), FILTER_BUILDER("Magento\\Framework\\Api\\FilterBuilder"), + LOGGER("Psr\\Log\\LoggerInterface"), REPORTING("Magento\\Framework\\Api\\Search\\ReportingInterface"), REQUEST("Magento\\Framework\\App\\RequestInterface"), SEARCH_CRITERIA("Magento\\Framework\\Api\\SearchCriteriaInterface"), diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java new file mode 100644 index 000000000..694bfebdf --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java @@ -0,0 +1,35 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages.code; + +import org.jetbrains.annotations.NotNull; + +public enum PhpCoreType { + EXCEPTION("Exception"); + + /** + * PHP Core type. + */ + private final String type; + + /** + * PHP Core type ENUM constructor. + * + * @param type String + */ + PhpCoreType(final @NotNull String type) { + this.type = type; + } + + /** + * Get type. + * + * @return String + */ + public @NotNull String getType() { + return type; + } +} 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..c27c4045a --- /dev/null +++ b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php @@ -0,0 +1,78 @@ +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()); + $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/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..ec53cd3f0 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.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.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 EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Command/" + ENTITY_NAME; + private static final String NAMESPACE = "Foo\\Bar\\Command\\" + ENTITY_NAME; + private static final String CLASS_FQN = NAMESPACE + "\\" + SaveEntityCommandFile.CLASS_NAME; + private static final String DTO_CLASS_FQN = "Foo\\Bar\\Data\\" + ENTITY_NAME + "Data"; + private static final String MODEL_CLASS_FQN = "Foo\\Bar\\Model\\" + ENTITY_NAME + "Model"; + private static final String RESOURCE_CLASS_FQN = "Foo\\Bar\\Model\\ResourceModel\\" + + ENTITY_NAME + "Resource"; + + /** + * Test generation of SaveCommand model for entity. + */ + public void testGenerateSaveEntityCommandFile() { + final SaveEntityCommandData saveEntityCommandData = new SaveEntityCommandData( + MODULE_NAME, + ENTITY_NAME, + NAMESPACE, + CLASS_FQN, + MODEL_CLASS_FQN, + RESOURCE_CLASS_FQN, + DTO_CLASS_FQN + ); + final SaveEntityCommandGenerator saveEntityCommandGenerator = + new SaveEntityCommandGenerator( + saveEntityCommandData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + SaveEntityCommandFile.getInstance().getFileName() + ); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + saveEntityCommandGenerator.generate("test") + ); + } +} From cc662602bc5e2728be1cf2ba7ebd8d8f32f393f0 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Thu, 28 Jan 2021 21:02:10 +0200 Subject: [PATCH 13/84] added generator for save controller --- resources/META-INF/plugin.xml | 1 + ...agento Entity Save Controller Class.php.ft | 86 +++++++++++ ...ento Entity Save Controller Class.php.html | 18 +++ .../data/SaveEntityControllerFileData.java | 111 +++++++++++++ .../generation/dialog/NewEntityDialog.java | 78 +++++++--- .../SaveEntityControllerFileGenerator.java | 146 ++++++++++++++++++ .../generator/util/DirectoryGenerator.java | 42 +++++ .../magento/files/actions/SaveActionFile.java | 72 +++++++++ .../magento/packages/HttpMethod.java | 11 ++ .../packages/code/BackendModuleType.java | 46 ++++++ .../packages/code/FrameworkLibraryType.java | 6 +- .../Save.php | 93 +++++++++++ .../Save.php | 93 +++++++++++ .../SaveEntityActionGeneratorTest.java | 89 +++++++++++ 14 files changed, 869 insertions(+), 23 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Entity Save Controller Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java create mode 100644 testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php create mode 100644 testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f2537aa10..76e4e9329 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -229,6 +229,7 @@ + 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..64de350af --- /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); + $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/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..f43ad3da6 --- /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 namespace; + private final String saveCommandFqn; + private final String dtoType; + private final String acl; + private final String entityId; + + /** + * Controller save file constructor. + * + * @param entityName String + * @param moduleName String + * @param namespace String + * @param saveCommandFqn String + * @param acl String + * @param dtoType String + * @param entityId String + */ + public SaveEntityControllerFileData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String namespace, + final @NotNull String saveCommandFqn, + final @NotNull String dtoType, + final @NotNull String acl, + final @NotNull String entityId + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.namespace = namespace; + this.saveCommandFqn = saveCommandFqn; + this.dtoType = dtoType; + this.acl = acl; + this.entityId = entityId; + } + + /** + * Get entity id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } + + /** + * Get acl. + * + * @return String + */ + public String getAcl() { + return acl; + } + + /** + * Get dto type. + * + * @return String + */ + public String getDtoType() { + return dtoType; + } + + /** + * Get save command Fqn. + * + * @return String + */ + public String getSaveCommandFqn() { + return saveCommandFqn; + } + + /** + * 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; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index fd16ec207..d40a716be 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -18,13 +18,14 @@ 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.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; -import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormButtonData; import com.magento.idea.magento2plugin.actions.generation.data.UiComponentFormFieldData; @@ -39,15 +40,16 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityControllerFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; @@ -60,6 +62,7 @@ import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; +import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.HttpMethod; @@ -107,7 +110,8 @@ "PMD.ExcessiveImports", "PMD.GodClass", "PMD.TooManyMethods", - "PMD.CyclomaticComplexity" + "PMD.CyclomaticComplexity", + "PMD.ExcessiveClassLength" }) public class NewEntityDialog extends AbstractDialog { @NotNull @@ -279,7 +283,7 @@ private void onOK() { generateRoutesXmlFile(); generateViewControllerFile(); - generateSubmitControllerFile(); + generateSaveControllerFile(); generateModelGetListQueryFile(); generateDataProviderFile(); generateLayoutFile(); @@ -303,6 +307,49 @@ private void onOK() { this.setVisible(false); } + /** + * Generate Save Controller file. + */ + private void generateSaveControllerFile() { + final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); + final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + SaveActionFile.CLASS_NAME, + SaveActionFile.getDirectory(getEntityName()) + ); + final String dtoType; + + if (createInterface.isSelected()) { + dtoType = dtoInterfaceModelNamespace.getClassFqn(); + } else { + dtoType = dtoModelNamespace.getClassFqn(); + } + + new SaveEntityControllerFileGenerator(new SaveEntityControllerFileData( + getEntityName(), + getModuleName(), + namespace.getNamespace(), + getSaveEntityCommandClassFqn(), + dtoType, + getAcl(), + getEntityIdColumn() + ), project).generate(ACTION_NAME, false); + } + + /** + * Get save entity command class Fqn. + * + * @return String + */ + private String getSaveEntityCommandClassFqn() { + //TODO: change this stub after the save command generated will be implemented. + final NamespaceBuilder namespaceBuilder = + new NamespaceBuilder(getModuleName(), "SaveCommand", "Command/" + getEntityName()); + + return namespaceBuilder.getClassFqn(); + } + private PsiFile generateModelFile() { final NamespaceBuilder modelNamespace = getModelNamespace(); final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); @@ -574,24 +621,11 @@ private String getControllerDirectory() { return ControllerBackendPhp.DEFAULT_DIR + File.separator; } - private PsiFile generateSubmitControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getSubmitActionName(), - getViewControllerDirectory() - ); - return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getSubmitActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.POST.toString(), - getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); - } - + /** + * Get Acl id. + * + * @return String + */ public String getAcl() { return acl.getText().trim(); } 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..5bb8c710b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java @@ -0,0 +1,146 @@ +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.SaveEntityControllerFileData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; +import com.magento.idea.magento2plugin.magento.packages.HttpMethod; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SaveEntityControllerFileGenerator extends FileGenerator { + + private final SaveEntityControllerFileData fileData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final Project project; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * Save Entity Controller File Generator. + * + * @param fileData SaveEntityControllerFileData + * @param project Project + */ + public SaveEntityControllerFileGenerator( + final @NotNull SaveEntityControllerFileData fileData, + final @NotNull Project project + ) { + this(fileData, project, true); + } + + /** + * Save Entity Controller File Generator. + * + * @param fileData SaveEntityControllerFileData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SaveEntityControllerFileGenerator( + final @NotNull SaveEntityControllerFileData fileData, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.fileData = fileData; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + moduleIndex = ModuleIndex.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + uses = new ArrayList<>(); + } + + /** + * Generate Save action controller for entity. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass saveActionClass = GetPhpClassByFQN.getInstance(project).execute( + String.format( + "%s%s%s", + fileData.getNamespace(), + Package.fqnSeparator, + SaveActionFile.CLASS_NAME + ) + ); + + if (this.checkFileAlreadyExists && saveActionClass != null) { + return saveActionClass.getContainingFile(); + } + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + fileData.getModuleName() + ); + final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + SaveActionFile.getDirectory(fileData.getEntityName()) + ); + + return fileFromTemplateGenerator.generate( + SaveActionFile.getInstance(), + getAttributes(), + baseDirectory, + actionName + ); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + uses.add(BackendModuleType.CONTEXT.getType()); + uses.add(FrameworkLibraryType.RESPONSE_INTERFACE.getType()); + uses.add(FrameworkLibraryType.RESULT_INTERFACE.getType()); + attributes.setProperty("NAMESPACE", fileData.getNamespace()); + attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); + attributes.setProperty("CLASS_NAME", SaveActionFile.CLASS_NAME); + attributes.setProperty("ENTITY_ID", fileData.getEntityId()); + attributes.setProperty("ADMIN_RESOURCE", SaveActionFile.getAdminResource( + fileData.getModuleName(), + fileData.getAcl() + ) + ); + addProperty(attributes, "IMPLEMENTS", HttpMethod.POST.getInterfaceFqn()); + addProperty(attributes, "DATA_PERSISTOR", FrameworkLibraryType.DATA_PERSISTOR.getType()); + addProperty(attributes, "ENTITY_DTO", fileData.getDtoType()); + addProperty(attributes, "ENTITY_DTO_FACTORY", fileData.getDtoType().concat("Factory")); + addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); + addProperty(attributes, "SAVE_COMMAND", fileData.getSaveCommandFqn()); + addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); + addProperty(attributes, "COULD_NOT_SAVE", SaveActionFile.COULD_NOT_SAVE); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to properties. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..b59adb67d 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 @@ -9,6 +9,8 @@ import com.intellij.psi.PsiDirectory; import com.magento.idea.magento2plugin.actions.generation.generator.data.ModuleDirectoriesData; import com.magento.idea.magento2plugin.magento.packages.Package; +import java.io.File; +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/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java new file mode 100644 index 000000000..3f8eb4cf7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -0,0 +1,72 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + + +public final class SaveActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Save"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Entity Save Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private static final SaveActionFile INSTANCE = new SaveActionFile(); + public static final String COULD_NOT_SAVE = + "Magento\\Framework\\Exception\\CouldNotSaveException"; + + /** + * Get singleton instance of the class. + * + * @return SaveAction + */ + public static SaveActionFile getInstance() { + return INSTANCE; + } + + /** + * Get Directory path from the module root. + * + * @param entityName String + * + * @return String + */ + public static String getDirectory(final @NotNull String entityName) { + return DIRECTORY.concat("/" + entityName.concat("Model")); + } + + /** + * Get admin resource. + * + * @param moduleName String + * @param acl String + * + * @return String + */ + public static String getAdminResource( + final @NotNull String moduleName, + final @NotNull String acl + ) { + return moduleName + "::" + acl; + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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/code/BackendModuleType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java new file mode 100644 index 000000000..1036a4413 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java @@ -0,0 +1,46 @@ +/* + * 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"); + + /** + * 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/FrameworkLibraryType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java index 924554396..4e00a3d80 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -9,13 +9,17 @@ import org.jetbrains.annotations.NotNull; public enum FrameworkLibraryType { + API_SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\Search\\SearchCriteriaBuilder"), 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"), + RESPONSE_INTERFACE("Magento\\Framework\\App\\ResponseInterface"), REPORTING("Magento\\Framework\\Api\\Search\\ReportingInterface"), REQUEST("Magento\\Framework\\App\\RequestInterface"), SEARCH_CRITERIA("Magento\\Framework\\Api\\SearchCriteriaInterface"), SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\SearchCriteriaBuilder"), - API_SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\Search\\SearchCriteriaBuilder"), SEARCH_RESULT("Magento\\Framework\\Api\\SearchResultsInterface"); /** 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..7a6b9f49f --- /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); + $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..6bb2ad413 --- /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 CompanyModel|DataObject $entityModel */ + $entityModel = $this->entityDataFactory->create(); + $entityModel->addData($params); + $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/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..7b0b92484 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java @@ -0,0 +1,89 @@ +/* + * 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 EXPECTED_DIRECTORY = + "/src/app/code/Foo/Bar/Controller/Adminhtml/" + ENTITY_NAME + "Model"; + private static final String NAMESPACE = + "Foo\\Bar\\Controller\\Adminhtml\\" + ENTITY_NAME + "Model"; + private static final String SAVE_COMMAND = + "Foo\\Bar\\Command\\" + ENTITY_NAME + "\\SaveCommand"; + private static final String DTO_TYPE = + "Foo\\Bar\\Model\\" + ENTITY_NAME + "Model" + "\\CompanyModel"; + private static final String DTO_TYPE_INTERFACE = + "Foo\\Bar\\Api\\Data\\" + ENTITY_NAME + "Interface"; + private static final String ACL = "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, + NAMESPACE, + SAVE_COMMAND, + DTO_TYPE, + ACL, + ENTITY_ID + ); + final SaveEntityControllerFileGenerator saveEntityControllerFileGenerator = + new SaveEntityControllerFileGenerator( + saveEntityControllerFileData, + myFixture.getProject(), + false + ); + final PsiFile saveEntityActionFile = saveEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath(SaveActionFile.getInstance().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, + NAMESPACE, + SAVE_COMMAND, + DTO_TYPE_INTERFACE, + ACL, + ENTITY_ID + ); + final SaveEntityControllerFileGenerator saveEntityControllerFileGenerator = + new SaveEntityControllerFileGenerator( + saveEntityControllerFileData, + myFixture.getProject(), + true + ); + final PsiFile saveEntityActionFile = saveEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath(SaveActionFile.getInstance().getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + saveEntityActionFile + ); + } +} From f5da3829f8b40878699debe21e207bf566b9d5be Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 2 Feb 2021 16:33:04 +0200 Subject: [PATCH 14/84] Added entity data mapper generator and test for generation --- resources/META-INF/plugin.xml | 1 + .../code/Magento Entity Data Mapper.html.ft | 18 +++ .../code/Magento Entity Data Mapper.php.ft | 52 ++++++ .../generation/data/EntityDataMapperData.java | 96 ++++++++++++ .../generation/dialog/NewEntityDialog.java | 52 +++++- .../generator/EntityDataMapperGenerator.java | 148 ++++++++++++++++++ .../magento/files/EntityDataMapperFile.java | 118 ++++++++++++++ .../packages/code/FrameworkLibraryType.java | 4 + .../UnicornDataMapper.php | 52 ++++++ .../EntityDataMapperClassGeneratorTest.java | 49 ++++++ 10 files changed, 585 insertions(+), 5 deletions(-) create mode 100644 resources/fileTemplates/code/Magento Entity Data Mapper.html.ft create mode 100644 resources/fileTemplates/code/Magento Entity Data Mapper.php.ft create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java create mode 100644 testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f2537aa10..d302c43bc 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -229,6 +229,7 @@ + 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..8ae17d2e0 --- /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/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..197c29b18 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java @@ -0,0 +1,96 @@ +/* + * 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 EntityDataMapperData { + private final String moduleName; + private final String entityName; + private final String namespace; + private final String classFqn; + private final String modelClassFqn; + private final String dataModelClassFqn; + + /** + * Magento entity data mapper data constructor. + * + * @param moduleName String + * @param entityName String + * @param namespace String + * @param modelClassFqn String + * @param dataModelClassFqn String + */ + public EntityDataMapperData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String namespace, + final @NotNull String classFqn, + final @NotNull String modelClassFqn, + final @NotNull String dataModelClassFqn + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.namespace = namespace; + this.classFqn = classFqn; + this.modelClassFqn = modelClassFqn; + this.dataModelClassFqn = dataModelClassFqn; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get class fqn. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * Get model class fqn. + * + * @return String + */ + public String getModelClassFqn() { + return modelClassFqn; + } + + /** + * Get data model class fqn. + * + * @return String + */ + public String getDataModelClassFqn() { + return dataModelClassFqn; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index fd16ec207..75d7fa470 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -18,10 +18,11 @@ 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.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; -import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; @@ -39,13 +40,14 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; @@ -56,6 +58,7 @@ import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.files.DataModel; import com.magento.idea.magento2plugin.magento.files.DataModelInterface; +import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; import com.magento.idea.magento2plugin.magento.files.ModelPhp; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; @@ -107,7 +110,8 @@ "PMD.ExcessiveImports", "PMD.GodClass", "PMD.TooManyMethods", - "PMD.CyclomaticComplexity" + "PMD.CyclomaticComplexity", + "PMD.ExcessiveClassLength", }) public class NewEntityDialog extends AbstractDialog { @NotNull @@ -280,6 +284,7 @@ private void onOK() { generateRoutesXmlFile(); generateViewControllerFile(); generateSubmitControllerFile(); + generateEntityDataMapperFile(); generateModelGetListQueryFile(); generateDataProviderFile(); generateLayoutFile(); @@ -1009,6 +1014,41 @@ private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXm ).generate(ACTION_NAME, false); } + /** + * Generate entity data mapper type. + */ + private void generateEntityDataMapperFile() { + final EntityDataMapperFile entityDataMapperFile = + EntityDataMapperFile.getInstance(getEntityName()); + + final String namespace = entityDataMapperFile.getNamespace(getModuleName()); + final String classFqn = entityDataMapperFile.getClassFqn(getModuleName()); + + final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); + final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); + + final String dtoType; + + if (createInterface.isSelected()) { + dtoType = dtoInterfaceModelNamespace.getClassFqn(); + } else { + dtoType = dtoModelNamespace.getClassFqn(); + } + + new EntityDataMapperGenerator( + new EntityDataMapperData( + getModuleName(), + getEntityName(), + namespace, + classFqn, + modelNamespace.getClassFqn(), + dtoType + ), + project + ).generate(ACTION_NAME, false); + } + /** * Run GetListQuery.php file generator. */ @@ -1032,8 +1072,10 @@ private void generateModelGetListQueryFile() { * @return String */ private String getEntityDataMapperType() { - // TODO: implement with entity data mapper generation. - return "Test\\Test\\Mapper\\" + getEntityName() + "DataMapper"; + final EntityDataMapperFile entityDataMapperFile = + EntityDataMapperFile.getInstance(getEntityName()); + + return entityDataMapperFile.getClassFqn(getModuleName()); } /** 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..dd4640939 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java @@ -0,0 +1,148 @@ +/* + * 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.EntityDataMapperData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class EntityDataMapperGenerator extends FileGenerator { + + private final EntityDataMapperData entityDataMapperData; + private final Project project; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final EntityDataMapperFile entityDataMapperFile; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * Entity data mapper generator constructor. + * + * @param entityDataMapperData EntityDataMapperData + * @param project Project + */ + public EntityDataMapperGenerator( + final @NotNull EntityDataMapperData entityDataMapperData, + final @NotNull Project project + ) { + this(entityDataMapperData, project, true); + } + + /** + * Entity data mapper generator constructor. + * + * @param entityDataMapperData EntityDataMapperData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public EntityDataMapperGenerator( + final @NotNull EntityDataMapperData entityDataMapperData, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.entityDataMapperData = entityDataMapperData; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + entityDataMapperFile = EntityDataMapperFile + .getInstance(entityDataMapperData.getEntityName()); + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); + } + + /** + * Generate entity data mapper class. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass entityDataMapperClass = GetPhpClassByFQN.getInstance(project).execute( + entityDataMapperData.getClassFqn() + ); + if (this.checkFileAlreadyExists && entityDataMapperClass != null) { + return entityDataMapperClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + entityDataMapperData.getModuleName() + ); + final PsiDirectory entityDataMapperDir = directoryGenerator.findOrCreateSubdirectory( + moduleBaseDir, + entityDataMapperFile.getDirectory() + ); + + return fileFromTemplateGenerator.generate( + entityDataMapperFile, + getAttributes(), + entityDataMapperDir, + actionName + ); + } + + /** + * Fill entity data mapper file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", entityDataMapperData.getNamespace()); + attributes.setProperty("ENTITY_NAME", entityDataMapperData.getEntityName()); + attributes.setProperty("CLASS_NAME", entityDataMapperFile.getClassName()); + + addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); + addProperty(attributes, "DTO_TYPE", entityDataMapperData.getDataModelClassFqn()); + addProperty(attributes, "MAGENTO_MODEL_TYPE", entityDataMapperData.getModelClassFqn()); + addProperty( + attributes, + "DTO_FACTORY", + entityDataMapperData.getDataModelClassFqn().concat("Factory") + ); + addProperty( + attributes, + "ABSTRACT_COLLECTION", + FrameworkLibraryType.ABSTRACT_COLLECTION.getType() + ); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..a62b46d27 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java @@ -0,0 +1,118 @@ +/* + * 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 com.magento.idea.magento2plugin.magento.packages.Package; +import org.jetbrains.annotations.NotNull; + +public final class EntityDataMapperFile implements ModuleFileInterface { + + public static final String CLASS_NAME_SUFFIX = "DataMapper"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Entity Data Mapper"; + private static final String DIRECTORY = "Mapper"; + private static EntityDataMapperFile instance; + private String className; + private String namespaceFqn; + private String classFqn; + + private EntityDataMapperFile() {} + + /** + * Get singleton object of entity data mapper file. + * + * @param entityName String + * + * @return EntityDataMapperFile + */ + public static EntityDataMapperFile getInstance(final @NotNull String entityName) { + synchronized (EntityDataMapperFile.class) { + if (instance == null) { + instance = new EntityDataMapperFile(); + instance.className = entityName.concat(CLASS_NAME_SUFFIX); + } + } + + return instance; + } + + /** + * Get namespace. + * + * @param moduleName String + * + * @return String + */ + public @NotNull String getNamespace( + final @NotNull String moduleName + ) { + if (namespaceFqn == null) { + final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + namespaceFqn = namespaceBuilder.getNamespace(); + } + + return namespaceFqn; + } + + /** + * Get class FQN. + * + * @param moduleName String + * + * @return String + */ + public @NotNull String getClassFqn( + final @NotNull String moduleName + ) { + if (classFqn == null) { + classFqn = getNamespace(moduleName) + .concat(Package.fqnSeparator) + .concat(className); + } + + return classFqn; + } + + /** + * Get class name. + * + * @return String + */ + public @NotNull String getClassName() { + return className; + } + + /** + * Get directory for entity data mapper file. + * + * @return String + */ + public @NotNull String getDirectory() { + return DIRECTORY; + } + + @Override + public String getFileName() { + return className.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java index 924554396..5d0252aa0 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -9,7 +9,11 @@ import org.jetbrains.annotations.NotNull; public enum FrameworkLibraryType { + ABSTRACT_COLLECTION( + "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection" + ), COLLECTION_PROCESSOR("Magento\\Framework\\Api\\SearchCriteria\\CollectionProcessorInterface"), + DATA_OBJECT("Magento\\Framework\\DataObject"), FILTER_BUILDER("Magento\\Framework\\Api\\FilterBuilder"), REPORTING("Magento\\Framework\\Api\\Search\\ReportingInterface"), REQUEST("Magento\\Framework\\App\\RequestInterface"), 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..c23018769 --- /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/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..747c903cb --- /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 NAMESPACE = "Foo\\Bar\\Mapper"; + private static final String CLASS_FQN = NAMESPACE + "\\UnicornDataMapper"; + private static final String MODEL_CLASS_FQN = "Foo\\Bar\\Model\\UnicornModel"; + private static final String DATA_MODEL_CLASS_FQN = "Foo\\Bar\\Api\\Data\\UnicornDataInterface"; + + /** + * Test generation of entity data mapper class. + */ + public void testGenerateEntityDataMapperFile() { + final EntityDataMapperData entityDataMapperData = new EntityDataMapperData( + MODULE_NAME, + ENTITY_NAME, + NAMESPACE, + CLASS_FQN, + MODEL_CLASS_FQN, + DATA_MODEL_CLASS_FQN + ); + final EntityDataMapperGenerator entityDataMapperGenerator = + new EntityDataMapperGenerator( + entityDataMapperData, + myFixture.getProject(), + false + ); + final EntityDataMapperFile entityDataMapperFile = + EntityDataMapperFile.getInstance(ENTITY_NAME); + final String filePath = this.getFixturePath(entityDataMapperFile.getFileName()); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + entityDataMapperGenerator.generate("test") + ); + } +} From 42d1beb12382d85a2981a5db4c337facf2169027 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 12:47:03 +0200 Subject: [PATCH 15/84] Fixed few bugs with entity manager generation --- .../generation/dialog/NewEntityDialog.java | 336 ++++++++++-------- .../generator/util/NamespaceBuilder.java | 4 +- 2 files changed, 197 insertions(+), 143 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index fd16ec207..0bb977e1e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -278,17 +278,20 @@ private void onOK() { } generateRoutesXmlFile(); - generateViewControllerFile(); - generateSubmitControllerFile(); - generateModelGetListQueryFile(); - generateDataProviderFile(); - generateLayoutFile(); - generateFormFile(); generateAclXmlFile(); - generateGridViewControllerFile(); - generateGridLayoutFile(); generateMenuFile(); - generateUiComponentGridFile(); + + if (createUiComponent.isSelected()) { + generateGridViewControllerFile(); + generateGridLayoutFile(); + generateModelGetListQueryFile(); + generateDataProviderFile(); + generateUiComponentGridFile(); + generateFormLayoutFile(); + generateFormViewControllerFile(); + generateFormSubmitControllerFile(); + generateUiComponentFormFile(); + } final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( getDbTableName(), @@ -348,14 +351,14 @@ private NamespaceBuilder getResourceModelNamespace() { * Generate preference for data model. */ private void generateDataModelPreference() { - final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder dataModelNamespace = getDataModelNamespace(); final NamespaceBuilder modelInterfaceNamespace = getDataModelInterfaceNamespace(); new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getModuleName(), GetPhpClassByFQN.getInstance(project).execute( modelInterfaceNamespace.getClassFqn() ), - modelNamespace.getClassFqn(), + dataModelNamespace.getClassFqn(), getModelName(), Areas.base.toString() ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); @@ -540,60 +543,24 @@ public String getRoute() { return route.getText().trim(); } - private PsiFile generateViewControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getViewActionName(), - getViewControllerDirectory() - ); - return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getViewActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), - getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); - } - - private String getViewActionName() { - return "Edit"; - } - - private String getSubmitActionName() { - return "Save";//NOPMD - } - - private String getViewControllerDirectory() { - return getControllerDirectory() + getModelName(); + public String getAcl() { + return acl.getText().trim(); } - private String getControllerDirectory() { - return ControllerBackendPhp.DEFAULT_DIR + File.separator; + private PsiFile generateAclXmlFile() { + return new AclXmlGenerator(new AclXmlData( + getParentAcl(), + getAcl(), + getAclTitle() + ), getModuleName(), project).generate(ACTION_NAME, false); } - private PsiFile generateSubmitControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getSubmitActionName(), - getViewControllerDirectory() - ); - return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getSubmitActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.POST.toString(), - getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); + public String getParentAcl() { + return parentAcl.getSelectedItem().toString().trim(); } - public String getAcl() { - return acl.getText().trim(); + public String getAclTitle() { + return aclTitle.getText().trim(); } /** @@ -619,9 +586,9 @@ private void generateDataProviderFile() { @NotNull private NamespaceBuilder getDataProviderNamespace() { return new NamespaceBuilder( - getModuleName(), - getDataProviderClassName(), - getDataProviderDirectory() + getModuleName(), + getDataProviderClassName(), + getDataProviderDirectory() ); } @@ -645,14 +612,17 @@ public String getDataProviderType() { return UiComponentDataProviderPhp.CUSTOM_TYPE; } - private PsiFile generateLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName(), - getEntityName(), - getViewActionName(), - getFormName() + /** + * Generate Form UI Component layout file. + */ + private void generateFormLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( + Areas.adminhtml.toString(), + getRoute(), + getModuleName(), + getEntityName(), + getViewActionName(), + getFormName() ), project).generate(ACTION_NAME, false); } @@ -665,24 +635,32 @@ public String getFormName() { return formName.getText().trim(); } - private PsiFile generateAclXmlFile() { - return new AclXmlGenerator(new AclXmlData( - getParentAcl(), - getAcl(), - getAclTitle() - ), getModuleName(), project).generate(ACTION_NAME, false); - } - - public String getParentAcl() { - return parentAcl.getSelectedItem().toString().trim(); - } - - public String getAclTitle() { - return aclTitle.getText().trim(); + /** + * Generate Form UI Component post controller file. + */ + private void generateFormSubmitControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + getSubmitActionName(), + getViewControllerDirectory() + ); + new ModuleControllerClassGenerator(new ControllerFileData( + getViewControllerDirectory(), + getSubmitActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.POST.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); } - private PsiFile generateFormFile() { - return new UiComponentFormGenerator(new UiComponentFormFileData( + /** + * Generate UI component form file. + */ + private void generateUiComponentFormFile() { + new UiComponentFormGenerator(new UiComponentFormFileData( getFormName(), Areas.adminhtml.toString(), getModuleName(), @@ -697,6 +675,11 @@ private PsiFile generateFormFile() { ), project).generate(ACTION_NAME, true); } + /** + * Get UI Component form label. + * + * @return String + */ public String getFormLabel() { return formLabel.getText().trim(); } @@ -835,27 +818,60 @@ public List getFields() { return fieldsets; } - @SuppressWarnings({"PMD.UnusedPrivateMethod"}) - private void createUIComponents() { - this.parentAcl = new FilteredComboBox(getAclResourcesList()); - this.parentMenu = new FilteredComboBox(getMenuReferences()); + /** + * Generate UI Component grid file. + */ + private void generateUiComponentGridFile() { + final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( + getUiComponentGridData(), + project + ); + gridXmlGenerator.generate(ACTION_NAME, true); + } - if (getAclResourcesList().contains(ModuleMenuXml.defaultAcl)) { - parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); - } + /** + * Get grid UI component data. + * + * @return UiComponentGridData + */ + public UiComponentGridData getUiComponentGridData() { + return new UiComponentGridData( + getModuleName(), + Areas.adminhtml.toString(), + getGridName(), + getDataProviderNamespace().getClassFqn(), + getEntityIdColumn(), + getAcl(), + getUiComponentGridToolbarData() + ); } - private List getAclResourcesList() { - return GetAclResourcesListUtil.execute(project); + /** + * Get grid toolbar data. + * + * @return UiComponentGridToolbarData + */ + public UiComponentGridToolbarData getUiComponentGridToolbarData() { + return new UiComponentGridToolbarData( + getAddToolBar(), + getAddBookmarksCheckBox(), + getAddColumnsControlCheckBox(), + getAddFullTextSearchCheckBox(), + getAddListingFiltersCheckBox(), + getAddListingPagingCheckBox() + ); } - private PsiFile generateGridViewControllerFile() { + /** + * Generate Grid UI Component View Controller file. + */ + private void generateGridViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), "Listing", getControllerDirectory() ); - return new ModuleControllerClassGenerator(new ControllerFileData( + new ModuleControllerClassGenerator(new ControllerFileData( getControllerDirectory(), "Listing", getModuleName(), @@ -867,8 +883,11 @@ private PsiFile generateGridViewControllerFile() { ), project).generate(ACTION_NAME, false); } - private PsiFile generateGridLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( + /** + * Generate Grid UI Component layout file. + */ + private void generateGridLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( Areas.adminhtml.toString(), getRoute(), getModuleName(), @@ -878,8 +897,84 @@ private PsiFile generateGridLayoutFile() { ), project).generate(ACTION_NAME, false); } + /** + * Get Grid Name. + * + * @return String + */ private String getGridName() { - return gridName.getText().toString(); + return gridName.getText(); + } + + /** + * Generate Form UI Component View Controller file. + */ + private void generateFormViewControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + getViewActionName(), + getViewControllerDirectory() + ); + new ModuleControllerClassGenerator(new ControllerFileData( + getViewControllerDirectory(), + getViewActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); + } + + /** + * Get view action name. + * + * @return String + */ + private String getViewActionName() { + return "Edit"; + } + + /** + * Get submit action name. + * + * @return String + */ + private String getSubmitActionName() { + return "Save";//NOPMD + } + + /** + * Get view controller directory. + * + * @return String + */ + private String getViewControllerDirectory() { + return getControllerDirectory() + getModelName(); + } + + /** + * Get Adminhtml controller directory. + * + * @return String + */ + private String getControllerDirectory() { + return ControllerBackendPhp.DEFAULT_DIR + File.separator; + } + + @SuppressWarnings({"PMD.UnusedPrivateMethod"}) + private void createUIComponents() { + this.parentAcl = new FilteredComboBox(getAclResourcesList()); + this.parentMenu = new FilteredComboBox(getMenuReferences()); + + if (getAclResourcesList().contains(ModuleMenuXml.defaultAcl)) { + parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); + } + } + + private List getAclResourcesList() { + return GetAclResourcesListUtil.execute(project); } private PsiFile generateMenuFile() { @@ -918,47 +1013,6 @@ public String getMenuTitle() { return menuTitle.getText().trim(); } - private void generateUiComponentGridFile() { - final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( - getUiComponentGridData(), - project - ); - gridXmlGenerator.generate(ACTION_NAME, true); - } - - /** - * Get grid UI component data. - * - * @return UiComponentGridData - */ - public UiComponentGridData getUiComponentGridData() { - return new UiComponentGridData( - getModuleName(), - Areas.adminhtml.toString(), - getGridName(), - getDataProviderNamespace().getClassFqn(), - getEntityIdColumn(), - getAcl(), - getUiComponentGridToolbarData() - ); - } - - /** - * Get grid toolbar data. - * - * @return UiComponentGridToolbarData - */ - public UiComponentGridToolbarData getUiComponentGridToolbarData() { - return new UiComponentGridToolbarData( - getAddToolBar(), - getAddBookmarksCheckBox(), - getAddColumnsControlCheckBox(), - getAddFullTextSearchCheckBox(), - getAddListingFiltersCheckBox(), - getAddListingPagingCheckBox() - ); - } - private Boolean getAddToolBar() { return addToolBar.isSelected(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java index 2db65c630..6ba5668e4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java @@ -25,11 +25,11 @@ public class NamespaceBuilder { public NamespaceBuilder( final String moduleName, final String className, - final String classDirectory + String classDirectory ) { this.moduleName = moduleName; this.className = className; - this.classDirectory = classDirectory; + this.classDirectory = classDirectory.replaceAll(File.separator + "$", ""); } /** From 1c3c94d282d986a286f443128c98ea3054c71e8b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 14:34:19 +0200 Subject: [PATCH 16/84] fix for controller namespace --- .../actions/generation/dialog/NewEntityDialog.java | 2 +- .../actions/generation/generator/util/NamespaceBuilder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 0bb977e1e..9b652ace8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -869,7 +869,7 @@ private void generateGridViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), "Listing", - getControllerDirectory() + ControllerBackendPhp.DEFAULT_DIR ); new ModuleControllerClassGenerator(new ControllerFileData( getControllerDirectory(), diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java index 6ba5668e4..2db65c630 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java @@ -25,11 +25,11 @@ public class NamespaceBuilder { public NamespaceBuilder( final String moduleName, final String className, - String classDirectory + final String classDirectory ) { this.moduleName = moduleName; this.className = className; - this.classDirectory = classDirectory.replaceAll(File.separator + "$", ""); + this.classDirectory = classDirectory; } /** From 00971245ff6d8aefd75a90819f1c95018d91c78f Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 15:29:20 +0200 Subject: [PATCH 17/84] Code refactoring after CR --- .../code/Magento Entity Data Mapper.php.ft | 2 +- .../generation/dialog/NewEntityDialog.java | 4 ++-- .../generator/EntityDataMapperGenerator.java | 3 +-- .../magento/files/EntityDataMapperFile.java | 22 +++++-------------- .../UnicornDataMapper.php | 2 +- .../EntityDataMapperClassGeneratorTest.java | 3 +-- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft b/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft index 8ae17d2e0..12644efb2 100644 --- a/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft +++ b/resources/fileTemplates/code/Magento Entity Data Mapper.php.ft @@ -9,7 +9,7 @@ use $use; #end /** - * ${ENTITY_NAME} magento model collection to entity data transfer object array mapper. + * Converts a collection of ${ENTITY_NAME} entities to an array of data transfer objects. */ class ${CLASS_NAME} { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 75d7fa470..bc00d62ef 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -1019,7 +1019,7 @@ private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXm */ private void generateEntityDataMapperFile() { final EntityDataMapperFile entityDataMapperFile = - EntityDataMapperFile.getInstance(getEntityName()); + new EntityDataMapperFile(getEntityName()); final String namespace = entityDataMapperFile.getNamespace(getModuleName()); final String classFqn = entityDataMapperFile.getClassFqn(getModuleName()); @@ -1073,7 +1073,7 @@ private void generateModelGetListQueryFile() { */ private String getEntityDataMapperType() { final EntityDataMapperFile entityDataMapperFile = - EntityDataMapperFile.getInstance(getEntityName()); + new EntityDataMapperFile(getEntityName()); return entityDataMapperFile.getClassFqn(getModuleName()); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java index dd4640939..a477fe0ee 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java @@ -62,8 +62,7 @@ public EntityDataMapperGenerator( this.entityDataMapperData = entityDataMapperData; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; - entityDataMapperFile = EntityDataMapperFile - .getInstance(entityDataMapperData.getEntityName()); + entityDataMapperFile = new EntityDataMapperFile(entityDataMapperData.getEntityName()); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); diff --git a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java index a62b46d27..252bfff49 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java @@ -11,35 +11,23 @@ import com.magento.idea.magento2plugin.magento.packages.Package; import org.jetbrains.annotations.NotNull; -public final class EntityDataMapperFile implements ModuleFileInterface { +public class EntityDataMapperFile implements ModuleFileInterface { public static final String CLASS_NAME_SUFFIX = "DataMapper"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Data Mapper"; private static final String DIRECTORY = "Mapper"; - private static EntityDataMapperFile instance; - private String className; + private final String className; private String namespaceFqn; private String classFqn; - private EntityDataMapperFile() {} - /** - * Get singleton object of entity data mapper file. + * Entity data mapper file constructor. * * @param entityName String - * - * @return EntityDataMapperFile */ - public static EntityDataMapperFile getInstance(final @NotNull String entityName) { - synchronized (EntityDataMapperFile.class) { - if (instance == null) { - instance = new EntityDataMapperFile(); - instance.className = entityName.concat(CLASS_NAME_SUFFIX); - } - } - - return instance; + public EntityDataMapperFile(final @NotNull String entityName) { + this.className = entityName.concat(CLASS_NAME_SUFFIX); } /** diff --git a/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php b/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php index c23018769..28c6aeef0 100644 --- a/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php +++ b/testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php @@ -9,7 +9,7 @@ use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; /** - * Unicorn magento model collection to entity data transfer object array mapper. + * Converts a collection of Unicorn entities to an array of data transfer objects. */ class UnicornDataMapper { diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java index 747c903cb..c6f693cd7 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperClassGeneratorTest.java @@ -36,8 +36,7 @@ public void testGenerateEntityDataMapperFile() { myFixture.getProject(), false ); - final EntityDataMapperFile entityDataMapperFile = - EntityDataMapperFile.getInstance(ENTITY_NAME); + final EntityDataMapperFile entityDataMapperFile = new EntityDataMapperFile(ENTITY_NAME); final String filePath = this.getFixturePath(entityDataMapperFile.getFileName()); assertGeneratedFileIsCorrect( From 4e9cb66b46ee8b1b48f48218159e3ad2450f8ea6 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 15:36:24 +0200 Subject: [PATCH 18/84] fixed merging minor mistakes --- .../actions/generation/dialog/NewEntityDialog.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 5f4ad13cf..0ffa77f85 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -18,7 +18,6 @@ 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.DbSchemaXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; @@ -42,7 +41,6 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; From 31cf3a28518853dd700fdace8081cd642033ebca Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 15:49:49 +0200 Subject: [PATCH 19/84] Code refactoring after CR --- .../generator/SaveEntityCommandGenerator.java | 58 ++++++++++--------- .../files/commands/SaveEntityCommandFile.java | 10 ---- .../magento/packages/code/PhpCoreType.java | 35 ----------- .../SaveEntityCommandGeneratorTest.java | 2 +- 4 files changed, 33 insertions(+), 72 deletions(-) delete mode 100644 src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java index d273dbe26..aa74dfc5d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -18,8 +18,8 @@ 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 com.magento.idea.magento2plugin.magento.packages.code.PhpCoreType; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -33,6 +33,7 @@ public class SaveEntityCommandGenerator extends FileGenerator { private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; + private final List uses; /** * Save entity command generator constructor. @@ -66,6 +67,7 @@ public SaveEntityCommandGenerator( fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); } /** @@ -94,7 +96,7 @@ public PsiFile generate(final @NotNull String actionName) { ); return fileFromTemplateGenerator.generate( - SaveEntityCommandFile.getInstance(), + new SaveEntityCommandFile(), getAttributes(), saveCommandFileBaseDir, actionName @@ -108,15 +110,17 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - final List uses = new LinkedList<>(); - uses.add(PhpCoreType.EXCEPTION.getType()); - uses.add(FrameworkLibraryType.DATA_OBJECT.getType()); - uses.add(ExceptionType.COULD_NOT_SAVE.getType()); - uses.add(FrameworkLibraryType.LOGGER.getType()); + attributes.setProperty("ENTITY_NAME", saveEntityCommandData.getEntityName()); + attributes.setProperty("NAMESPACE", saveEntityCommandData.getNamespace()); + attributes.setProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME); + attributes.setProperty("EXCEPTION", "Exception"); + uses.add("Exception"); + addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); + addProperty(attributes, "COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getType()); + addProperty(attributes, "LOGGER", FrameworkLibraryType.LOGGER.getType()); final String dtoType = saveEntityCommandData.getDataModelClassFqn(); - uses.add(dtoType); - attributes.setProperty("DTO", PhpClassGeneratorUtil.getNameFromFqn(dtoType)); + addProperty(attributes, "DTO", dtoType); final String dtoProperty = CaseFormat.UPPER_CAMEL.to( CaseFormat.LOWER_CAMEL, saveEntityCommandData.getEntityName() @@ -124,28 +128,30 @@ protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("DTO_PROPERTY", dtoProperty); final String modelType = saveEntityCommandData.getModelClassFqn(); - uses.add(modelType); - attributes.setProperty("MODEL", PhpClassGeneratorUtil.getNameFromFqn(modelType)); + addProperty(attributes, "MODEL", modelType); final String modelFactoryType = modelType.concat("Factory"); - uses.add(modelFactoryType); - attributes.setProperty("MODEL_FACTORY", - PhpClassGeneratorUtil.getNameFromFqn(modelFactoryType) - ); + addProperty(attributes, "MODEL_FACTORY", modelFactoryType); final String resourceType = saveEntityCommandData.getResourceModelClassFqn(); - uses.add(resourceType); - attributes.setProperty("RESOURCE", PhpClassGeneratorUtil.getNameFromFqn(resourceType)); - - attributes.setProperty("ENTITY_NAME", saveEntityCommandData.getEntityName()); - attributes.setProperty("NAMESPACE", saveEntityCommandData.getNamespace()); - attributes.setProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME); - - attributes.setProperty("EXCEPTION", PhpCoreType.EXCEPTION.getType()); - attributes.setProperty("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getTypeName()); - attributes.setProperty("COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getTypeName()); - attributes.setProperty("LOGGER", FrameworkLibraryType.LOGGER.getTypeName()); + addProperty(attributes, "RESOURCE", resourceType); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java index 8fdd87a31..68b414338 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java @@ -17,16 +17,6 @@ public class SaveEntityCommandFile implements ModuleFileInterface { public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Save Entity Command Model"; private static final String DIRECTORY = "Command"; - private static final SaveEntityCommandFile INSTANCE = new SaveEntityCommandFile(); - - /** - * Get singleton object of save command file. - * - * @return SaveEntityCommandFile - */ - public static SaveEntityCommandFile getInstance() { - return INSTANCE; - } /** * Get namespace. diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java deleted file mode 100644 index 694bfebdf..000000000 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/PhpCoreType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.magento.packages.code; - -import org.jetbrains.annotations.NotNull; - -public enum PhpCoreType { - EXCEPTION("Exception"); - - /** - * PHP Core type. - */ - private final String type; - - /** - * PHP Core type ENUM constructor. - * - * @param type String - */ - PhpCoreType(final @NotNull String type) { - this.type = type; - } - - /** - * Get type. - * - * @return String - */ - public @NotNull String getType() { - return type; - } -} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java index ec53cd3f0..b897a5984 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGeneratorTest.java @@ -39,7 +39,7 @@ public void testGenerateSaveEntityCommandFile() { false ); final String filePath = this.getFixturePath( - SaveEntityCommandFile.getInstance().getFileName() + new SaveEntityCommandFile().getFileName() ); assertGeneratedFileIsCorrect( From d1dee19fdfb518cbf2082673abd7b9d2062cb6ea Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 15:57:29 +0200 Subject: [PATCH 20/84] fixed checkStyle issues --- .../actions/generation/dialog/NewEntityDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 48c4360fc..632749aa3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -50,8 +50,8 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleResourceModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityControllerFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityControllerFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; From 1e2bdff87a2842ddbf36f19b400afc9338383f25 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 16:09:03 +0200 Subject: [PATCH 21/84] getSaveEntityCommandClassFqn methods stub implemented --- .../actions/generation/dialog/NewEntityDialog.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index f1af6c4f5..79e47c0e8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -351,9 +351,12 @@ private void generateSaveControllerFile() { * @return String */ private String getSaveEntityCommandClassFqn() { - //TODO: change this stub after the save command generated will be implemented. final NamespaceBuilder namespaceBuilder = - new NamespaceBuilder(getModuleName(), "SaveCommand", "Command/" + getEntityName()); + new NamespaceBuilder( + getModuleName(), + SaveEntityCommandFile.CLASS_NAME, + SaveEntityCommandFile.getDirectory(getEntityName()) + ); return namespaceBuilder.getClassFqn(); } From 101c697d2f5c01f1b83c834a28039d69ccf3077a Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 3 Feb 2021 16:57:58 +0200 Subject: [PATCH 22/84] Code refactoring with actualization --- .../generation/dialog/NewEntityDialog.java | 594 +++++++++--------- 1 file changed, 310 insertions(+), 284 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 79e47c0e8..13e7eb372 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -288,19 +288,22 @@ private void onOK() { } generateRoutesXmlFile(); - generateViewControllerFile(); - generateSaveControllerFile(); - generateEntityDataMapperFile(); - generateModelGetListQueryFile(); - generateSaveEntityCommandFile(); - generateDataProviderFile(); - generateLayoutFile(); - generateFormFile(); generateAclXmlFile(); - generateGridViewControllerFile(); - generateGridLayoutFile(); generateMenuFile(); - generateUiComponentGridFile(); + + if (createUiComponent.isSelected()) { + generateGridViewControllerFile(); + generateGridLayoutFile(); + generateEntityDataMapperFile(); + generateModelGetListQueryFile(); + generateDataProviderFile(); + generateUiComponentGridFile(); + generateFormViewControllerFile(); + generateFormLayoutFile(); + generateSaveEntityCommandFile(); + generateFormSaveControllerFile(); + generateUiComponentFormFile(); + } final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( getDbTableName(), @@ -315,52 +318,6 @@ private void onOK() { this.setVisible(false); } - /** - * Generate Save Controller file. - */ - private void generateSaveControllerFile() { - final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); - final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - SaveActionFile.CLASS_NAME, - SaveActionFile.getDirectory(getEntityName()) - ); - final String dtoType; - - if (createInterface.isSelected()) { - dtoType = dtoInterfaceModelNamespace.getClassFqn(); - } else { - dtoType = dtoModelNamespace.getClassFqn(); - } - - new SaveEntityControllerFileGenerator(new SaveEntityControllerFileData( - getEntityName(), - getModuleName(), - namespace.getNamespace(), - getSaveEntityCommandClassFqn(), - dtoType, - getAcl(), - getEntityIdColumn() - ), project).generate(ACTION_NAME, false); - } - - /** - * Get save entity command class Fqn. - * - * @return String - */ - private String getSaveEntityCommandClassFqn() { - final NamespaceBuilder namespaceBuilder = - new NamespaceBuilder( - getModuleName(), - SaveEntityCommandFile.CLASS_NAME, - SaveEntityCommandFile.getDirectory(getEntityName()) - ); - - return namespaceBuilder.getClassFqn(); - } - private PsiFile generateModelFile() { final NamespaceBuilder modelNamespace = getModelNamespace(); final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); @@ -426,14 +383,14 @@ private NamespaceBuilder getResourceModelNamespace() { * Generate preference for data model. */ private void generateDataModelPreference() { - final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder dataModelNamespace = getDataModelNamespace(); final NamespaceBuilder modelInterfaceNamespace = getDataModelInterfaceNamespace(); new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getModuleName(), GetPhpClassByFQN.getInstance(project).execute( modelInterfaceNamespace.getClassFqn() ), - modelNamespace.getClassFqn(), + dataModelNamespace.getClassFqn(), getModelName(), Areas.base.toString() ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); @@ -618,24 +575,6 @@ public String getRoute() { return route.getText().trim(); } - private PsiFile generateViewControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getViewActionName(), - getViewControllerDirectory() - ); - return new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), - getViewActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), - getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); - } - private String getViewActionName() { return "Edit"; } @@ -661,66 +600,6 @@ public String getAcl() { return acl.getText().trim(); } - /** - * Generate data provider file. - */ - private void generateDataProviderFile() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { - final NamespaceBuilder namespaceBuilder = getDataProviderNamespace(); - new UiComponentDataProviderGenerator(new UiComponentDataProviderData( - getDataProviderClassName(), - namespaceBuilder.getNamespace(), - getDataProviderDirectory(), - getEntityIdColumn() - ), getModuleName(), project).generate(ACTION_NAME, false); - } - } - - /** - * Get data provider namespace builder. - * - * @return NamespaceBuilder - */ - @NotNull - private NamespaceBuilder getDataProviderNamespace() { - return new NamespaceBuilder( - getModuleName(), - getDataProviderClassName(), - getDataProviderDirectory() - ); - } - - /** - * Get data provider directory. - * - * @return String - */ - public String getDataProviderDirectory() { - // TODO: add ui part with dynamic implementation. - return "UI/DataProvider"; - } - - /** - * Get data provider type. - * - * @return String - */ - public String getDataProviderType() { - // TODO: add ui part with dynamic implementation. - return UiComponentDataProviderPhp.CUSTOM_TYPE; - } - - private PsiFile generateLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName(), - getEntityName(), - getViewActionName(), - getFormName() - ), project).generate(ACTION_NAME, false); - } - /** * Get controller name. * @@ -746,22 +625,6 @@ public String getAclTitle() { return aclTitle.getText().trim(); } - private PsiFile generateFormFile() { - return new UiComponentFormGenerator(new UiComponentFormFileData( - getFormName(), - Areas.adminhtml.toString(), - getModuleName(), - getFormLabel(), - getButtons(), - getFieldsets(), - getFields(), - getRoute(), - getEntityName(), - getSubmitActionName(), - getDataProviderNamespace().getClassFqn() - ), project).generate(ACTION_NAME, true); - } - public String getFormLabel() { return formLabel.getText().trim(); } @@ -914,13 +777,16 @@ private List getAclResourcesList() { return GetAclResourcesListUtil.execute(project); } - private PsiFile generateGridViewControllerFile() { + /** + * Generate Grid view controller file. + */ + private void generateGridViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), "Listing", - getControllerDirectory() + ControllerBackendPhp.DEFAULT_DIR ); - return new ModuleControllerClassGenerator(new ControllerFileData( + new ModuleControllerClassGenerator(new ControllerFileData( getControllerDirectory(), "Listing", getModuleName(), @@ -932,8 +798,11 @@ private PsiFile generateGridViewControllerFile() { ), project).generate(ACTION_NAME, false); } - private PsiFile generateGridLayoutFile() { - return new LayoutXmlGenerator(new LayoutXmlData( + /** + * Generate grid layout file. + */ + private void generateGridLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( Areas.adminhtml.toString(), getRoute(), getModuleName(), @@ -943,135 +812,13 @@ private PsiFile generateGridLayoutFile() { ), project).generate(ACTION_NAME, false); } - private String getGridName() { - return gridName.getText().toString(); - } - - private PsiFile generateMenuFile() { - return new MenuXmlGenerator(new MenuXmlData( - getParentMenuItem(), - getSortOrder(), - getModuleName(), - getMenuIdentifier(), - getMenuTitle(), - getAcl(), - getMenuAction() - ), project).generate(ACTION_NAME, false); - } - - private String getParentMenuItem() { - return parentMenu.getSelectedItem().toString(); - } - - public String getSortOrder() { - return sortOrder.getText().trim(); - } - - public String getMenuIdentifier() { - return menuIdentifier.getText().trim(); - } - - private String getMenuAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "listing"; - } - - public String getMenuTitle() { - return menuTitle.getText().trim(); - } - - private void generateUiComponentGridFile() { - final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( - getUiComponentGridData(), - project - ); - gridXmlGenerator.generate(ACTION_NAME, true); - } - /** - * Get grid UI component data. + * Get grid name. * - * @return UiComponentGridData - */ - public UiComponentGridData getUiComponentGridData() { - return new UiComponentGridData( - getModuleName(), - Areas.adminhtml.toString(), - getGridName(), - getDataProviderNamespace().getClassFqn(), - getEntityIdColumn(), - getAcl(), - getUiComponentGridToolbarData() - ); - } - - /** - * Get grid toolbar data. - * - * @return UiComponentGridToolbarData - */ - public UiComponentGridToolbarData getUiComponentGridToolbarData() { - return new UiComponentGridToolbarData( - getAddToolBar(), - getAddBookmarksCheckBox(), - getAddColumnsControlCheckBox(), - getAddFullTextSearchCheckBox(), - getAddListingFiltersCheckBox(), - getAddListingPagingCheckBox() - ); - } - - private Boolean getAddToolBar() { - return addToolBar.isSelected(); - } - - private Boolean getAddColumnsControlCheckBox() { - return addColumnsControlCheckBox.isSelected(); - } - - private Boolean getAddFullTextSearchCheckBox() { - return addFullTextSearchCheckBox.isSelected(); - } - - private Boolean getAddListingFiltersCheckBox() { - return addListingFiltersCheckBox.isSelected(); - } - - private Boolean getAddListingPagingCheckBox() { - return addListingPagingCheckBox.isSelected(); - } - - private Boolean getAddBookmarksCheckBox() { - return addBookmarksCheckBox.isSelected(); - } - - /** - * Run db_schema.xml file generator. - * - * @param dbSchemaXmlData DbSchemaXmlData - */ - private void generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { - new DbSchemaXmlGenerator( - dbSchemaXmlData, - project, - moduleName - ).generate(ACTION_NAME, false); - } - - /** - * Run db_schema_whitelist.json generator. - * - * @param dbSchemaXmlData DbSchemaXmlData + * @return String */ - private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { - new DbSchemaWhitelistJsonGenerator( - project, - dbSchemaXmlData, - moduleName - ).generate(ACTION_NAME, false); + private String getGridName() { + return gridName.getText(); } /** @@ -1138,6 +885,134 @@ private String getEntityDataMapperType() { return entityDataMapperFile.getClassFqn(getModuleName()); } + /** + * Generate data provider file. + */ + private void generateDataProviderFile() { + if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { + final NamespaceBuilder namespaceBuilder = getDataProviderNamespace(); + new UiComponentDataProviderGenerator(new UiComponentDataProviderData( + getDataProviderClassName(), + namespaceBuilder.getNamespace(), + getDataProviderDirectory(), + getEntityIdColumn() + ), getModuleName(), project).generate(ACTION_NAME, false); + } + } + + /** + * Get data provider namespace builder. + * + * @return NamespaceBuilder + */ + @NotNull + private NamespaceBuilder getDataProviderNamespace() { + return new NamespaceBuilder( + getModuleName(), + getDataProviderClassName(), + getDataProviderDirectory() + ); + } + + /** + * Get data provider directory. + * + * @return String + */ + public String getDataProviderDirectory() { + // TODO: add ui part with dynamic implementation. + return "UI/DataProvider"; + } + + /** + * Get data provider type. + * + * @return String + */ + public String getDataProviderType() { + // TODO: add ui part with dynamic implementation. + return UiComponentDataProviderPhp.CUSTOM_TYPE; + } + + /** + * Generate UI Component grid file. + */ + private void generateUiComponentGridFile() { + final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( + getUiComponentGridData(), + project + ); + gridXmlGenerator.generate(ACTION_NAME, true); + } + + /** + * Get grid UI component data. + * + * @return UiComponentGridData + */ + public UiComponentGridData getUiComponentGridData() { + return new UiComponentGridData( + getModuleName(), + Areas.adminhtml.toString(), + getGridName(), + getDataProviderNamespace().getClassFqn(), + getEntityIdColumn(), + getAcl(), + getUiComponentGridToolbarData() + ); + } + + /** + * Get grid toolbar data. + * + * @return UiComponentGridToolbarData + */ + public UiComponentGridToolbarData getUiComponentGridToolbarData() { + return new UiComponentGridToolbarData( + getAddToolBar(), + getAddBookmarksCheckBox(), + getAddColumnsControlCheckBox(), + getAddFullTextSearchCheckBox(), + getAddListingFiltersCheckBox(), + getAddListingPagingCheckBox() + ); + } + + /** + * Generate form view controller file. + */ + private void generateFormViewControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + getViewActionName(), + getViewControllerDirectory() + ); + new ModuleControllerClassGenerator(new ControllerFileData( + getViewControllerDirectory(), + getViewActionName(), + getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + getAcl(), + true, + namespace.getNamespace() + ), project).generate(ACTION_NAME, false); + } + + /** + * Generate UI Component form layout file. + */ + private void generateFormLayoutFile() { + new LayoutXmlGenerator(new LayoutXmlData( + Areas.adminhtml.toString(), + getRoute(), + getModuleName(), + getEntityName(), + getViewActionName(), + getFormName() + ), project).generate(ACTION_NAME, false); + } + /** * Run SaveCommand.php file generator for an entity. */ @@ -1177,6 +1052,157 @@ private void generateSaveEntityCommandFile() { ).generate(ACTION_NAME, true); } + /** + * Generate Save Controller file. + */ + private void generateFormSaveControllerFile() { + final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); + final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + SaveActionFile.CLASS_NAME, + SaveActionFile.getDirectory(getEntityName()) + ); + final String dtoType; + + if (createInterface.isSelected()) { + dtoType = dtoInterfaceModelNamespace.getClassFqn(); + } else { + dtoType = dtoModelNamespace.getClassFqn(); + } + + new SaveEntityControllerFileGenerator(new SaveEntityControllerFileData( + getEntityName(), + getModuleName(), + namespace.getNamespace(), + getSaveEntityCommandClassFqn(), + dtoType, + getAcl(), + getEntityIdColumn() + ), project).generate(ACTION_NAME, false); + } + + /** + * Get save entity command class Fqn. + * + * @return String + */ + private String getSaveEntityCommandClassFqn() { + final NamespaceBuilder namespaceBuilder = + new NamespaceBuilder( + getModuleName(), + SaveEntityCommandFile.CLASS_NAME, + SaveEntityCommandFile.getDirectory(getEntityName()) + ); + + return namespaceBuilder.getClassFqn(); + } + + /** + * Generate UI Component form file. + */ + private void generateUiComponentFormFile() { + new UiComponentFormGenerator(new UiComponentFormFileData( + getFormName(), + Areas.adminhtml.toString(), + getModuleName(), + getFormLabel(), + getButtons(), + getFieldsets(), + getFields(), + getRoute(), + getEntityName(), + getSubmitActionName(), + getDataProviderNamespace().getClassFqn() + ), project).generate(ACTION_NAME, true); + } + + private PsiFile generateMenuFile() { + return new MenuXmlGenerator(new MenuXmlData( + getParentMenuItem(), + getSortOrder(), + getModuleName(), + getMenuIdentifier(), + getMenuTitle(), + getAcl(), + getMenuAction() + ), project).generate(ACTION_NAME, false); + } + + private String getParentMenuItem() { + return parentMenu.getSelectedItem().toString(); + } + + public String getSortOrder() { + return sortOrder.getText().trim(); + } + + public String getMenuIdentifier() { + return menuIdentifier.getText().trim(); + } + + private String getMenuAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "listing"; + } + + public String getMenuTitle() { + return menuTitle.getText().trim(); + } + + private Boolean getAddToolBar() { + return addToolBar.isSelected(); + } + + private Boolean getAddColumnsControlCheckBox() { + return addColumnsControlCheckBox.isSelected(); + } + + private Boolean getAddFullTextSearchCheckBox() { + return addFullTextSearchCheckBox.isSelected(); + } + + private Boolean getAddListingFiltersCheckBox() { + return addListingFiltersCheckBox.isSelected(); + } + + private Boolean getAddListingPagingCheckBox() { + return addListingPagingCheckBox.isSelected(); + } + + private Boolean getAddBookmarksCheckBox() { + return addBookmarksCheckBox.isSelected(); + } + + /** + * Run db_schema.xml file generator. + * + * @param dbSchemaXmlData DbSchemaXmlData + */ + private void generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { + new DbSchemaXmlGenerator( + dbSchemaXmlData, + project, + moduleName + ).generate(ACTION_NAME, false); + } + + /** + * Run db_schema_whitelist.json generator. + * + * @param dbSchemaXmlData DbSchemaXmlData + */ + private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { + new DbSchemaWhitelistJsonGenerator( + project, + dbSchemaXmlData, + moduleName + ).generate(ACTION_NAME, false); + } + /** * Get tableResource field value. * From 3e61f96587315adac83c475352a4322bafe49360 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Thu, 4 Feb 2021 14:03:15 +0200 Subject: [PATCH 23/84] Fixed entity manager dialog UX --- resources/magento2/validation.properties | 1 + .../generation/dialog/NewEntityDialog.form | 383 +++++++++++------- .../generation/dialog/NewEntityDialog.java | 48 ++- .../validator/annotation/RuleRegistry.java | 4 +- .../validator/rule/MenuIdentifierRule.java | 17 + .../idea/magento2plugin/util/RegExUtil.java | 3 + 6 files changed, 304 insertions(+), 152 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/MenuIdentifierRule.java diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index a413fc416..bb61cd54a 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -35,3 +35,4 @@ 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 diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index e4e7aa74b..a1e2c007d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -6,23 +6,23 @@ - - + + - + - - + + @@ -81,7 +81,9 @@ - + + + @@ -96,7 +98,9 @@ - + + + @@ -126,15 +130,20 @@ + + + + +
- - + + - + @@ -152,27 +161,25 @@ - + - + - + - + - - - + - + - + - + @@ -180,141 +187,149 @@ - + - - - - - - - - - - - - - - - - - + - + - + - + + + - - + - + - + + + - - - + + + + + + + + + + + + + + + + + + + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - + - - - + - + + + + - + - + - + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -333,23 +348,81 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -357,7 +430,7 @@ - + @@ -365,7 +438,7 @@ - + @@ -373,15 +446,7 @@ - - - - - - - - - + @@ -389,7 +454,7 @@ - + @@ -397,7 +462,7 @@ - + @@ -405,19 +470,49 @@ - + + + - + + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 13e7eb372..ac6b75064 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -37,6 +37,13 @@ import com.magento.idea.magento2plugin.actions.generation.data.UiComponentGridToolbarData; import com.magento.idea.magento2plugin.actions.generation.data.code.ClassPropertyData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +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.AclResourceIdRule; +import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule; +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.generator.AclXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DataModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; @@ -103,6 +110,7 @@ import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; +import javax.swing.JTextPane; import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import org.apache.commons.lang.StringUtils; @@ -140,25 +148,18 @@ public class NewEntityDialog extends AbstractDialog { private JLabel entityIdColumnNameLabel; private JTextField route; private JLabel routeLabel; - private JTextField acl; private JLabel aclLabel; private JTextField aclTitle; private FilteredComboBox parentAcl; - private JLabel formNameLabel; - private JTextField formName; private JTextField formLabel; private JLabel formLabelLabel; - private JTextField gridName; private JLabel gridNameLabel; private JLabel parentMenuItemLabel; private JLabel sortOrderLabel; private JLabel menuIdentifierLabel; - private JTextField sortOrder; - private JTextField menuIdentifier; private JLabel menuTitleLabel; private JTextField menuTitle; private FilteredComboBox parentMenu; - private JLabel formMenuLabel; private JCheckBox addToolBar; private JCheckBox addBookmarksCheckBox; private JCheckBox addColumnsControlCheckBox; @@ -176,7 +177,36 @@ public class NewEntityDialog extends AbstractDialog { 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 = "Grit Name"; + private static final String IDENTIFIER = "Identifier"; + private static final String SORT_ORDER = "Sort Order"; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) + private JTextField formName; + + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, GRID_NAME}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) + 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}) + 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 JTextField observerName; /** @@ -276,6 +306,10 @@ private DefaultTableModel getPropertiesTable() { * Perform code generation using input data. */ private void onOK() { + if (!validateFormFields()) { + return; + } + generateModelFile(); generateResourceModelFile(); generateCollectionFile(); 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/rule/MenuIdentifierRule.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/rule/MenuIdentifierRule.java new file mode 100644 index 000000000..21b64fddb --- /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.MENU_IDENTIFIER); + } + + public static ValidationRule getInstance() { + return INSTANCE; + } +} \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 0f9ba046d..434ab781f 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -68,6 +68,9 @@ public static class Magento { 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 MENU_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 { From cdb963f348b770cd506f5ff9eb37c4ab7ae36675 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Thu, 4 Feb 2021 17:01:12 +0200 Subject: [PATCH 24/84] Fixed static-tests --- .../data/SaveEntityControllerFileData.java | 16 ++++++++-------- .../generation/dialog/NewDataModelDialog.java | 16 ++++++++++------ .../generation/generator/QueryGenerator.java | 3 +-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java index f43ad3da6..cfab60a1e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java @@ -36,14 +36,14 @@ public SaveEntityControllerFileData( final @NotNull String dtoType, final @NotNull String acl, final @NotNull String entityId - ) { - this.entityName = entityName; - this.moduleName = moduleName; - this.namespace = namespace; - this.saveCommandFqn = saveCommandFqn; - this.dtoType = dtoType; - this.acl = acl; - this.entityId = entityId; + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.namespace = namespace; + this.saveCommandFqn = saveCommandFqn; + this.dtoType = dtoType; + this.acl = acl; + this.entityId = entityId; } /** 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 f7d7ebd11..8bb0c189a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -312,10 +312,10 @@ private void initPropertiesTable() { addProperty.addActionListener(e -> { propertiesTable.addRow(new Object[]{ - "", - PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) - .getPropertyType(), - PROPERTY_DELETE + "", + PropertiesTypes.valueOf(PropertiesTypes.INT.toString()) + .getPropertyType(), + PROPERTY_DELETE }); }); @@ -324,8 +324,12 @@ private void initPropertiesTable() { private void initPropertyTypeColumn() { final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE); - formElementTypeColumn.setCellEditor(new ComboBoxEditor(PropertiesTypes.getPropertyTypes())); - formElementTypeColumn.setCellRenderer(new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes())); + formElementTypeColumn.setCellEditor( + new ComboBoxEditor(PropertiesTypes.getPropertyTypes()) + ); + formElementTypeColumn.setCellRenderer( + new ComboBoxTableRenderer<>(PropertiesTypes.getPropertyTypes()) + ); } private DefaultTableModel getPropertiesTable() { diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java index 93ac918dc..94c00245b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java @@ -22,9 +22,8 @@ import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; - -import javax.swing.*; import java.util.Properties; +import javax.swing.JOptionPane; public class QueryGenerator extends FileGenerator { private final UiComponentDataProviderData uiComponentGridDataProviderData; From dded030852332c843454571b134d980081b15f6a Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Thu, 4 Feb 2021 17:59:43 +0200 Subject: [PATCH 25/84] Fixed code by recomendation --- .../generation/dialog/validator/rule/AclResourceIdRule.java | 2 +- .../generation/dialog/validator/rule/MenuIdentifierRule.java | 2 +- src/com/magento/idea/magento2plugin/util/RegExUtil.java | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) 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 index 21b64fddb..f11979b14 100644 --- 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 @@ -8,7 +8,7 @@ public class MenuIdentifierRule implements ValidationRule { @Override public boolean check(final String value) { - return value.matches(RegExUtil.Magento.MENU_IDENTIFIER); + return value.matches(RegExUtil.Magento.XML_IDENTIFIER); } public static ValidationRule getInstance() { diff --git a/src/com/magento/idea/magento2plugin/util/RegExUtil.java b/src/com/magento/idea/magento2plugin/util/RegExUtil.java index 434ab781f..d4a66c3f3 100644 --- a/src/com/magento/idea/magento2plugin/util/RegExUtil.java +++ b/src/com/magento/idea/magento2plugin/util/RegExUtil.java @@ -66,10 +66,7 @@ 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 MENU_IDENTIFIER = + 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,}$"; } From cfb68fe3de0247246fa28e08c7d664b39ed0edf7 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 4 Feb 2021 18:37:30 +0200 Subject: [PATCH 26/84] Added entity columns to grid, recreated view controller, bug fixing, added actions column generation, test coverage --- resources/META-INF/plugin.xml | 2 + .../Magento Grid UI Component Column.xml.ft | 8 + .../Magento Grid UI Component Column.xml.html | 0 ...ty Index Adminhtml Controller Class.php.ft | 37 +++++ ... Index Adminhtml Controller Class.php.html | 18 +++ ...id Ui Component Action Column Class.php.ft | 122 +++++++++++++++ ... Ui Component Action Column Class.php.html | 18 +++ .../Magento UI Component Grid XML.xml.ft | 11 ++ .../data/AdminListViewEntityActionData.java | 96 ++++++++++++ .../generation/data/GridActionColumnData.java | 84 ++++++++++ .../generation/data/UiComponentGridData.java | 48 +++++- .../generation/dialog/NewEntityDialog.java | 119 ++++++++++---- .../AdminListViewEntityActionGenerator.java | 144 +++++++++++++++++ .../GridActionColumnFileGenerator.java | 148 ++++++++++++++++++ .../UiComponentGridXmlGenerator.java | 146 ++++++++++++++++- .../magento/files/GridActionColumnFile.java | 45 ++++++ .../magento/files/UiComponentGridXml.java | 1 + .../actions/AdminListViewActionFile.java | 54 +++++++ .../magento/files/actions/SaveActionFile.java | 3 +- .../packages/code/FrameworkLibraryType.java | 4 +- .../generateListViewControllerFile/Index.php | 37 +++++ .../BlockActions.php | 120 ++++++++++++++ .../Save.php | 2 +- .../Save.php | 2 +- ...ListViewEntityControllerGeneratorTest.java | 42 +++++ .../GridActionColumnFileGeneratorTest.java | 40 +++++ .../SaveEntityActionGeneratorTest.java | 4 +- 27 files changed, 1309 insertions(+), 46 deletions(-) create mode 100644 resources/fileTemplates/code/Magento Grid UI Component Column.xml.ft create mode 100644 resources/fileTemplates/code/Magento Grid UI Component Column.xml.html create mode 100644 resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Entity Index Adminhtml Controller Class.php.html create mode 100644 resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/GridActionColumnData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java create mode 100644 testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/Index.php create mode 100644 testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityControllerGeneratorTest.java create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index fbcc4239a..02aed878b 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -232,6 +232,8 @@ + + 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/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 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 UI Component Grid XML.xml.ft b/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft index 70ca281cf..4c765a560 100644 --- a/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft +++ b/resources/fileTemplates/internal/Magento UI Component Grid XML.xml.ft @@ -56,5 +56,16 @@ desc + #if (${COLUMNS}) + #set($columns = ${COLUMNS}) + #foreach ($column in $columns.split("\n")) + $column + #end + #end + + + ${ID_FIELD_NAME} + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java new file mode 100644 index 000000000..f52382111 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java @@ -0,0 +1,96 @@ +/* + * 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 AdminListViewEntityActionData { + private final String moduleName; + private final String entityName; + private final String namespace; + private final String classFqn; + private final String acl; + private final String menu; + + /** + * Magento entity index adminhtml controller data constructor. + * + * @param moduleName String + * @param entityName String + * @param namespace String + * @param acl String + * @param menu String + */ + public AdminListViewEntityActionData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String namespace, + final @NotNull String classFqn, + final @NotNull String acl, + final @NotNull String menu + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.namespace = namespace; + this.classFqn = classFqn; + 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 namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get class fqn. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * 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/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/UiComponentGridData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java index 0d43834b4..975af0f12 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java @@ -5,7 +5,10 @@ package com.magento.idea.magento2plugin.actions.generation.data; -@SuppressWarnings({"PMD.DataClass"}) +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + public class UiComponentGridData { private final String moduleName; private final String area; @@ -14,6 +17,7 @@ public class UiComponentGridData { private final String idFieldName; private final String acl; private final UiComponentGridToolbarData gridToolbarData; + private final List> columns; /** * Ui component grid data constructor. @@ -32,6 +36,38 @@ public UiComponentGridData( final String idFieldName, final String acl, final UiComponentGridToolbarData gridToolbarData + ) { + this( + moduleName, + area, + name, + providerClassName, + idFieldName, + acl, + gridToolbarData, + new ArrayList<>() + ); + } + + /** + * Ui component grid data constructor. + * + * @param area Area + * @param name Name + * @param idFieldName Id field name + * @param acl ACL + * @param gridToolbarData Toolbar data + * @param columns List + */ + public UiComponentGridData( + final String moduleName, + final String area, + final String name, + final String providerClassName, + final String idFieldName, + final String acl, + final UiComponentGridToolbarData gridToolbarData, + final List> columns ) { this.moduleName = moduleName; this.area = area; @@ -40,6 +76,7 @@ public UiComponentGridData( this.idFieldName = idFieldName; this.acl = acl; this.gridToolbarData = gridToolbarData; + this.columns = columns; } /** @@ -104,4 +141,13 @@ public String getIdFieldName() { public String getProviderClassName() { return providerClassName; } + + /** + * Get entity columns data. + * + * @return List of columns properties. + */ + public List> getColumns() { + return columns; + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 13e7eb372..ee129d0bd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -19,7 +19,9 @@ import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData; import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; +import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; +import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; @@ -43,7 +45,9 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; @@ -67,6 +71,7 @@ import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; +import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; 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.Areas; @@ -297,6 +302,7 @@ private void onOK() { generateEntityDataMapperFile(); generateModelGetListQueryFile(); generateDataProviderFile(); + generateUiComponentGridActionColumnFile(); generateUiComponentGridFile(); generateFormViewControllerFile(); generateFormLayoutFile(); @@ -583,10 +589,6 @@ private String getSubmitActionName() { return "Save";//NOPMD } - private String getViewControllerDirectory() { - return getControllerDirectory() + getModelName(); - } - private String getControllerDirectory() { return ControllerBackendPhp.DEFAULT_DIR + File.separator; } @@ -781,21 +783,21 @@ private List getAclResourcesList() { * Generate Grid view controller file. */ private void generateGridViewControllerFile() { + final AdminListViewActionFile indexFile = new AdminListViewActionFile(getEntityName()); final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), - "Listing", - ControllerBackendPhp.DEFAULT_DIR + AdminListViewActionFile.CLASS_NAME, + indexFile.getDirectory() ); - new ModuleControllerClassGenerator(new ControllerFileData( - getControllerDirectory(), - "Listing", + final AdminListViewEntityActionData data = new AdminListViewEntityActionData( getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), + getEntityName(), + namespace.getNamespace(), + namespace.getClassFqn(), getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); + getMenuIdentifier() + ); + new AdminListViewEntityActionGenerator(data, project).generate(ACTION_NAME, false); } /** @@ -934,6 +936,20 @@ public String getDataProviderType() { return UiComponentDataProviderPhp.CUSTOM_TYPE; } + /** + * Generate Grid UI Component action column file. + */ + private void generateUiComponentGridActionColumnFile() { + final GridActionColumnData data = new GridActionColumnData( + getModuleName(), + getEntityName(), + getEntityIdColumn(), + getEditViewAction(), + getDeleteAction() + ); + new GridActionColumnFileGenerator(data, project).generate(ACTION_NAME, true); + } + /** * Generate UI Component grid file. */ @@ -958,7 +974,8 @@ public UiComponentGridData getUiComponentGridData() { getDataProviderNamespace().getClassFqn(), getEntityIdColumn(), getAcl(), - getUiComponentGridToolbarData() + getUiComponentGridToolbarData(), + getEntityProperties() ); } @@ -978,6 +995,45 @@ public UiComponentGridToolbarData getUiComponentGridToolbarData() { ); } + /** + * Get index view action path. + * + * @return String + */ + private String getIndexViewAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "index"; + } + + /** + * Get edit view action path. + * + * @return String + */ + private String getEditViewAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "edit"; + } + + /** + * Get delete action path. + * + * @return String + */ + private String getDeleteAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "delete"; + } + /** * Generate form view controller file. */ @@ -985,10 +1041,10 @@ private void generateFormViewControllerFile() { final NamespaceBuilder namespace = new NamespaceBuilder( getModuleName(), getViewActionName(), - getViewControllerDirectory() + getControllerDirectory().concat(getEntityName()) ); new ModuleControllerClassGenerator(new ControllerFileData( - getViewControllerDirectory(), + getControllerDirectory().concat(getEntityName()), getViewActionName(), getModuleName(), Areas.adminhtml.toString(), @@ -1117,15 +1173,18 @@ private void generateUiComponentFormFile() { ), project).generate(ACTION_NAME, true); } - private PsiFile generateMenuFile() { - return new MenuXmlGenerator(new MenuXmlData( - getParentMenuItem(), - getSortOrder(), - getModuleName(), - getMenuIdentifier(), - getMenuTitle(), - getAcl(), - getMenuAction() + /** + * Generate menu file. + */ + private void generateMenuFile() { + new MenuXmlGenerator(new MenuXmlData( + getParentMenuItem(), + getSortOrder(), + getModuleName(), + getMenuIdentifier(), + getMenuTitle(), + getAcl(), + getIndexViewAction() ), project).generate(ACTION_NAME, false); } @@ -1141,14 +1200,6 @@ public String getMenuIdentifier() { return menuIdentifier.getText().trim(); } - private String getMenuAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "listing"; - } - public String getMenuTitle() { return menuTitle.getText().trim(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java new file mode 100644 index 000000000..db8fb408b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java @@ -0,0 +1,144 @@ +/* + * 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.AdminListViewEntityActionData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class AdminListViewEntityActionGenerator extends FileGenerator { + + private final Project project; + private final AdminListViewEntityActionData data; + private final AdminListViewActionFile file; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * Constructor for adminhtml index (list) controller generator. + * + * @param data EntityIndexAdminhtmlActionData + * @param project Project + */ + public AdminListViewEntityActionGenerator( + final @NotNull AdminListViewEntityActionData 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 AdminListViewEntityActionGenerator( + final @NotNull AdminListViewEntityActionData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.data = data; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + file = new AdminListViewActionFile(data.getEntityName()); + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); + } + + /** + * Generate Index controller for Adminhtml area. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass indexActionClass = GetPhpClassByFQN.getInstance(project).execute( + data.getClassFqn() + ); + + if (this.checkFileAlreadyExists && indexActionClass != null) { + return indexActionClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + data.getModuleName() + ); + final PsiDirectory indexActionFileBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + file.getDirectory() + ); + + return fileFromTemplateGenerator.generate( + file, + getAttributes(), + indexActionFileBaseDir, + actionName + ); + } + + /** + * Fill index controller file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("ENTITY_NAME", data.getEntityName()); + attributes.setProperty("NAMESPACE", data.getNamespace()); + attributes.setProperty("CLASS_NAME", AdminListViewActionFile.CLASS_NAME); + attributes.setProperty("ACL", data.getAcl()); + attributes.setProperty("MENU", data.getMenu()); + + addProperty(attributes, "PARENT_CLASS_NAME", BackendModuleType.EXTENDS.getType()); + addProperty(attributes, "HTTP_GET_METHOD", HttpMethod.GET.getInterfaceFqn()); + addProperty(attributes, "RESULT", FrameworkLibraryType.RESULT_INTERFACE.getType()); + addProperty(attributes, "RESPONSE", FrameworkLibraryType.RESPONSE_INTERFACE.getType()); + addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + private void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..a29d85764 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java @@ -0,0 +1,148 @@ +/* + * 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.GridActionColumnData; +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.GridActionColumnFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class GridActionColumnFileGenerator extends FileGenerator { + + private final Project project; + private final GridActionColumnData data; + private final GridActionColumnFile file; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final NamespaceBuilder classNamespaceBuilder; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * 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); + this.data = data; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + file = new GridActionColumnFile(); + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); + classNamespaceBuilder = new NamespaceBuilder( + data.getModuleName(), + GridActionColumnFile.CLASS_NAME, + GridActionColumnFile.DIRECTORY + ); + } + + /** + * Generate action column class. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass actionColumnClass = GetPhpClassByFQN.getInstance(project).execute( + classNamespaceBuilder.getClassFqn() + ); + + if (this.checkFileAlreadyExists && actionColumnClass != null) { + return actionColumnClass.getContainingFile(); + } + + final PsiDirectory actionColumnFileBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleIndex.getModuleDirectoryByModuleName( + data.getModuleName() + ), + file.getDirectory() + ); + + return fileFromTemplateGenerator.generate( + file, + getAttributes(), + actionColumnFileBaseDir, + actionName + ); + } + + /** + * Fill index controller file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("ENTITY_NAME", data.getEntityName()); + attributes.setProperty("ENTITY_ID", data.getEntityIdColumn()); + attributes.setProperty("NAMESPACE", classNamespaceBuilder.getNamespace()); + attributes.setProperty("CLASS_NAME", GridActionColumnFile.CLASS_NAME); + attributes.setProperty("EDIT_URL_PATH", data.getEditUrlPath()); + attributes.setProperty("DELETE_URL_PATH", data.getDeleteUrlPath()); + + addProperty(attributes, "PARENT_CLASS", GridActionColumnFile.PARENT_CLASS); + addProperty(attributes, "URL", FrameworkLibraryType.URL.getType()); + addProperty(attributes, "CONTEXT", GridActionColumnFile.CONTEXT); + addProperty(attributes, "UI_COMPONENT_FACTORY", GridActionColumnFile.UI_COMPONENT_FACTORY); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + private void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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 6a996edc6..082e1b92b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java @@ -12,11 +12,24 @@ 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.NamespaceBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; import com.magento.idea.magento2plugin.magento.files.UiComponentGridXml; import com.magento.idea.magento2plugin.magento.packages.File; 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 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"; @@ -24,6 +37,7 @@ public class UiComponentGridXmlGenerator extends FileGenerator { private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final GetCodeTemplateUtil getCodeTemplateUtil; /** * UI component grid XML generator constructor. @@ -38,9 +52,10 @@ public UiComponentGridXmlGenerator( super(project); this.uiComponentGridData = uiComponentGridData; - this.directoryGenerator = DirectoryGenerator.getInstance(); - this.moduleIndex = ModuleIndex.getInstance(project); - this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + getCodeTemplateUtil = new GetCodeTemplateUtil(project); } @Override @@ -73,8 +88,13 @@ public PsiFile generate(final String actionName) { ); } + /** + * Fill UI Component grid xml file attributes. + * + * @param attributes Properties + */ @Override - protected void fillAttributes(final Properties attributes) { + protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("NAME", uiComponentGridData.getName()); attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName()); attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName()); @@ -105,5 +125,123 @@ protected void fillAttributes(final Properties attributes) { attributes.setProperty("LISTING_PAGING", TRUE); } } + + prepareColumnsProperties(attributes); + } + + /** + * Prepare columns properties. + * + * @param attributes Properties + */ + private void prepareColumnsProperties(final @NotNull Properties attributes) { + final List> columnsProperties = uiComponentGridData.getColumns(); + final List columnsTextList = new LinkedList<>(); + + for (final Map columnProperties : columnsProperties) { + final String columnName = columnProperties.get(ColumnAttributes.NAME.getName()); + + if (columnName.equals(uiComponentGridData.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( + UiComponentGridXml.COLUMN_TEMPLATE, + fillColumnCodeTemplateAttributes( + columnName, + columnLabel, + columnFilter + ) + ).trim() + ); + } catch (IOException exception) { + return; + } + } + + if (!columnsTextList.isEmpty()) { + attributes.setProperty("COLUMNS", String.join("\n", columnsTextList)); + } + + final NamespaceBuilder actionColumnNamespace = new NamespaceBuilder( + uiComponentGridData.getModuleName(), + GridActionColumnFile.CLASS_NAME, + GridActionColumnFile.DIRECTORY + ); + attributes.setProperty("ACTION_COLUMN", actionColumnNamespace.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/magento/files/GridActionColumnFile.java b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java new file mode 100644 index 000000000..b127b6609 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java @@ -0,0 +1,45 @@ +/* + * 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 final class GridActionColumnFile implements ModuleFileInterface { + public static final String CLASS_NAME = "BlockActions"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Grid Ui Component Action Column Class"; + public static final String DIRECTORY = "UI/Component/Listing/Column"; + 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"; + + /** + * Get Directory path from the module root. + * + * @return String + */ + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java index 96c7f449f..468067cbb 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java @@ -11,6 +11,7 @@ public class UiComponentGridXml 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; /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java new file mode 100644 index 000000000..92ab92803 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + +public final class AdminListViewActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Index"; + public static final String FILE_EXTENSION = "php"; + 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 AdminListViewActionFile( + final @NotNull String entityName + ) { + this.entityName = entityName; + } + + /** + * Get Directory path from the module root. + * + * @return String + */ + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java index 3f8eb4cf7..7cb9ad184 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -10,7 +10,6 @@ import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; - public final class SaveActionFile implements ModuleFileInterface { public static final String CLASS_NAME = "Save"; public static final String FILE_EXTENSION = "php"; @@ -37,7 +36,7 @@ public static SaveActionFile getInstance() { * @return String */ public static String getDirectory(final @NotNull String entityName) { - return DIRECTORY.concat("/" + entityName.concat("Model")); + return DIRECTORY.concat("/" + entityName); } /** diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java index 2d2d31208..bf2e7fab4 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -18,13 +18,15 @@ public enum FrameworkLibraryType { 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"); + SEARCH_RESULT("Magento\\Framework\\Api\\SearchResultsInterface"), + URL("Magento\\Framework\\UrlInterface"); /** * Factory type suffix. diff --git a/testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/Index.php b/testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/Index.php new file mode 100644 index 000000000..1cdce7b35 --- /dev/null +++ b/testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/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/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php new file mode 100644 index 000000000..2922f23d8 --- /dev/null +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.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/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php index 7a6b9f49f..ea566a347 100644 --- a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php @@ -1,6 +1,6 @@ Date: Thu, 4 Feb 2021 23:52:47 +0200 Subject: [PATCH 27/84] Changed layout name according to the new controller name --- .../actions/generation/dialog/NewEntityDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index ee129d0bd..a236ac2dc 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -809,7 +809,7 @@ private void generateGridLayoutFile() { getRoute(), getModuleName(), getEntityName(), - "Listing", + AdminListViewActionFile.CLASS_NAME, getGridName() ), project).generate(ACTION_NAME, false); } From cb89409146280e731a9ef509175485a1589521e9 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 4 Feb 2021 23:57:39 +0200 Subject: [PATCH 28/84] Added field name to validation message --- .../actions/generation/dialog/NewEntityDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 32c0d4bb5..a650316f7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -201,7 +201,7 @@ public class NewEntityDialog extends AbstractDialog { private JTextField acl; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, SORT_ORDER}) - @FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE}) + @FieldValidation(rule = RuleRegistry.NUMERIC, message = {NumericRule.MESSAGE, SORT_ORDER}) private JTextField sortOrder; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, IDENTIFIER}) From 81c4b3c3d256aae60e1bc414a4bd1f9526d4ccf8 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 5 Feb 2021 22:05:50 +0200 Subject: [PATCH 29/84] UI Component form development --- .../generation/dialog/NewEntityDialog.form | 10 +-- .../generation/dialog/NewEntityDialog.java | 22 +++-- .../dialog/NewUiComponentFormDialog.java | 21 +---- .../packages/uiComponent/FormElementType.java | 90 +++++++++++++++++++ 4 files changed, 112 insertions(+), 31 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index a1e2c007d..8934c75a4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -22,7 +22,7 @@ - + @@ -138,7 +138,7 @@
- + @@ -323,7 +323,7 @@ - + @@ -413,7 +413,7 @@ - + @@ -516,7 +516,7 @@ - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index ac6b75064..bd8ec666c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -82,6 +82,7 @@ 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; @@ -690,8 +691,8 @@ public List getFieldsets() { * * @return List[UiComponentFormButtonData] */ - protected List getButtons() { - final List buttons = new ArrayList(); + protected List getButtons() { + final List buttons = new ArrayList<>(); final String directory = "Block/Form"; final NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( @@ -701,7 +702,7 @@ protected List getButtons() { ); buttons.add(new UiComponentFormButtonData( directory, - "SaveEntity", + "Save", getModuleName(), "Save", namespaceBuilderSave.getNamespace(), @@ -758,13 +759,13 @@ public List getFields() { fieldsets.add( new UiComponentFormFieldData( - "entity_id", - "int", + getEntityIdColumn(), "Entity ID", "0", "general", - "hidden", - "entity_id" + FormElementType.HIDDEN.getType(), + "text", + getEntityIdColumn() ) ); @@ -776,7 +777,12 @@ public List getFields() { final String label = model.getValueAt(count, 0).toString(); //todo: convert final String sortOrder = String.valueOf(count).concat("0"); final String fieldset = "general"; - final String formElementType = model.getValueAt(count, 1).toString(); + + 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 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..692698399 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -47,6 +47,7 @@ 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; @@ -346,25 +347,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)); } 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..992414e46 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java @@ -0,0 +1,90 @@ +/* + * 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: + return FormElementType.INPUT; + case BOOL: + return FormElementType.BOOLEAN; + case FLOAT: + return FormElementType.PRICE; + default: + throw new NotSupportedException( + "ENUMs " + FormElementType.class + " property is not supported." + ); + } + } +} From bf1d5d72a726b235d6828e22f7a9f24d023cdd84 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 10 Feb 2021 15:16:24 +0200 Subject: [PATCH 30/84] Form generic button development --- resources/META-INF/plugin.xml | 1 + ...PHP Form Generic Button Block Class.php.ft | 85 +++++++++++ ...P Form Generic Button Block Class.php.html | 18 +++ .../data/FormGenericButtonBlockData.java | 85 +++++++++++ .../generation/dialog/NewEntityDialog.java | 25 +++ .../FormGenericButtonBlockGenerator.java | 143 ++++++++++++++++++ .../files/FormGenericButtonBlockFile.java | 33 ++++ .../GenericButton.php | 84 ++++++++++ .../FormGenericButtonBlockGeneratorTest.java | 47 ++++++ 9 files changed, 521 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento PHP Form Generic Button Block Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java create mode 100644 testData/actions/generation/generator/FormGenericButtonBlockGenerator/generateFormGenericButtonBlockFile/GenericButton.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 02aed878b..6ea0203d6 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -234,6 +234,7 @@ + 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/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..076b07aa7 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.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 FormGenericButtonBlockData { + + private final String moduleName; + private final String entityName; + private final String entityId; + private final String classFqn; + private final String namespace; + + /** + * Generic button DTO constructor. + * + * @param moduleName String + * @param entityName String + * @param entityId String + * @param classFqn String + * @param namespace String + */ + public FormGenericButtonBlockData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String entityId, + final @NotNull String classFqn, + final @NotNull String namespace + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.entityId = entityId; + this.classFqn = classFqn; + this.namespace = namespace; + } + + /** + * 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 class FQN. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * Get namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index cfa17da0a..70d037a41 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -20,6 +20,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; @@ -53,6 +54,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; @@ -74,6 +76,7 @@ import com.magento.idea.magento2plugin.magento.files.DataModel; import com.magento.idea.magento2plugin.magento.files.DataModelInterface; import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; +import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; import com.magento.idea.magento2plugin.magento.files.ModelPhp; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; @@ -343,6 +346,7 @@ private void onOK() { generateFormLayoutFile(); generateSaveEntityCommandFile(); generateFormSaveControllerFile(); + generateFormUiComponentGenericButtonFile(); generateUiComponentFormFile(); } @@ -1194,6 +1198,27 @@ private String getSaveEntityCommandClassFqn() { return namespaceBuilder.getClassFqn(); } + /** + * Generate Form UI Component generic button block file. + */ + private void generateFormUiComponentGenericButtonFile() { + final NamespaceBuilder genericButtonBlockNamespace = new NamespaceBuilder( + getModuleName(), + FormGenericButtonBlockFile.CLASS_NAME, + FormGenericButtonBlockFile.DIRECTORY + ); + new FormGenericButtonBlockGenerator( + new FormGenericButtonBlockData( + getModuleName(), + getEntityName(), + getEntityIdColumn(), + genericButtonBlockNamespace.getClassFqn(), + genericButtonBlockNamespace.getNamespace() + ), + project + ).generate(ACTION_NAME, true); + } + /** * Generate UI Component form file. */ 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..0e8f7f44b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java @@ -0,0 +1,143 @@ +/* + * 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.FormGenericButtonBlockData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import java.util.stream.Collectors; +import org.jetbrains.annotations.NotNull; + +public class FormGenericButtonBlockGenerator extends FileGenerator { + + private final FormGenericButtonBlockData data; + private final Project project; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * 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); + this.data = data; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); + } + + /** + * Generate ui component form generic block. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass genericButtonClass = GetPhpClassByFQN.getInstance(project).execute( + data.getClassFqn() + ); + + if (this.checkFileAlreadyExists && genericButtonClass != null) { + return genericButtonClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + data.getModuleName() + ); + final PsiDirectory genericButtonBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + FormGenericButtonBlockFile.DIRECTORY + ); + + return fileFromTemplateGenerator.generate( + new FormGenericButtonBlockFile(), + getAttributes(), + genericButtonBaseDir, + actionName + ); + } + + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", data.getNamespace()); + attributes.setProperty("ENTITY_NAME", data.getEntityName()); + attributes.setProperty("CLASS_NAME", FormGenericButtonBlockFile.CLASS_NAME); + attributes.setProperty("ENTITY_ID", data.getEntityId()); + + final String entityIdGetter = "get" + Arrays.stream(data.getEntityId().split("_")) + .map(s -> s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1)) + .collect(Collectors.joining()); + + attributes.setProperty("ENTITY_ID_GETTER", entityIdGetter); + addProperty(attributes, "CONTEXT", FormGenericButtonBlockFile.CONTEXT); + addProperty(attributes, "URL", FrameworkLibraryType.URL.getType()); + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..eb2e33d55 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java @@ -0,0 +1,33 @@ +/* + * 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 FormGenericButtonBlockFile implements ModuleFileInterface { + + public static final String CLASS_NAME = "GenericButton"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento PHP Form Generic Button Block Class"; + public static final String DIRECTORY = "Block/Form"; + public static final String CONTEXT = "Magento\\Backend\\Block\\Widget\\Context"; + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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..57479a9bf --- /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/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..468fea28f --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java @@ -0,0 +1,47 @@ +/* + * 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"; + private static final String NAMESPACE = "Foo\\Bar\\Block\\Form"; + private static final String CLASS_FQN = NAMESPACE + "\\" + + FormGenericButtonBlockFile.CLASS_NAME; + + /** + * Test generation of form ui component generic button block. + */ + public void testGenerateFormGenericButtonBlockFile() { + final FormGenericButtonBlockData data = new FormGenericButtonBlockData( + MODULE_NAME, + ENTITY_NAME, + ENTITY_ID, + CLASS_FQN, + NAMESPACE + ); + final FormGenericButtonBlockGenerator generator = + new FormGenericButtonBlockGenerator( + data, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + new FormGenericButtonBlockFile().getFileName() + ); + + assertGeneratedFileIsCorrect( + myFixture.configureByFile(filePath), + EXPECTED_DIRECTORY, + generator.generate("test") + ); + } +} From c93644beaf7a485d66a20cfa3d7eade81bf315ce Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Wed, 10 Feb 2021 15:59:21 +0200 Subject: [PATCH 31/84] Added generator for NewAction Controller --- resources/META-INF/plugin.xml | 1 + ... Entity New Action Controller Class.php.ft | 36 +++++++ ...ntity New Action Controller Class.php.html | 18 ++++ .../NewActionEntityControllerFileData.java | 71 ++++++++++++ .../generation/dialog/NewEntityDialog.java | 26 ++++- ...ewActionEntityControllerFileGenerator.java | 101 ++++++++++++++++++ .../SaveEntityControllerFileGenerator.java | 6 +- .../magento/files/actions/NewActionFile.java | 54 ++++++++++ .../magento/files/actions/SaveActionFile.java | 15 --- .../packages/code/BackendModuleType.java | 3 +- .../generateNewActionEntityFile/NewAction.php | 36 +++++++ .../NewActionEntityGeneratorTest.java | 48 +++++++++ 12 files changed, 392 insertions(+), 23 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java create mode 100644 testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 02aed878b..eb2ded2c4 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -234,6 +234,7 @@ + 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..c7aa24380 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft @@ -0,0 +1,36 @@ +resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD); + $resultForward->forward('edit'); + + return $resultForward; + } +} 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/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..2f5dc4d13 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java @@ -0,0 +1,71 @@ +/* + * 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; + + /** + * 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 + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.namespace = namespace; + this.acl = acl; + } + + /** + * 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; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index a650316f7..2614a4d01 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -13,18 +13,19 @@ import com.magento.idea.magento2plugin.actions.generation.NewEntityAction; import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction; import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; 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.DbSchemaXmlData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; -import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; @@ -47,12 +48,12 @@ 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.generator.AclXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator; 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.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; @@ -61,6 +62,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.NewActionEntityControllerFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; @@ -79,6 +81,7 @@ import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; +import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; 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.Areas; @@ -342,6 +345,7 @@ private void onOK() { generateFormLayoutFile(); generateSaveEntityCommandFile(); generateFormSaveControllerFile(); + generateFormNewActionControllerFile(); generateUiComponentFormFile(); } @@ -1172,6 +1176,24 @@ private void generateFormSaveControllerFile() { ), project).generate(ACTION_NAME, false); } + /** + * Generate NewAction Controller file. + */ + private void generateFormNewActionControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + NewActionFile.CLASS_NAME, + NewActionFile.getDirectory(getEntityName()) + ); + + new NewActionEntityControllerFileGenerator(new NewActionEntityControllerFileData( + getEntityName(), + getModuleName(), + namespace.getNamespace(), + getAcl() + ), project).generate(ACTION_NAME, false); + } + /** * Get save entity command class Fqn. * 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..7f0adcc91 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java @@ -0,0 +1,101 @@ +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.NewActionEntityControllerFileData; +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.indexes.ModuleIndex; +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 org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class NewActionEntityControllerFileGenerator extends FileGenerator { + + private final NewActionEntityControllerFileData fileData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final List uses; + + /** + * NewAction Entity Controller File Generator. + * @param fileData NewActionEntityControllerFileData + * @param project Project + */ + public NewActionEntityControllerFileGenerator( + final NewActionEntityControllerFileData fileData, + final @NotNull Project project + ) { + super(project); + this.fileData = fileData; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + moduleIndex = ModuleIndex.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + uses = new ArrayList<>(); + } + + /** + * Generate NewAction controller for entity. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + fileData.getModuleName() + ); + final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + NewActionFile.getDirectory(fileData.getEntityName()) + ); + + return fileFromTemplateGenerator.generate( + NewActionFile.getInstance(), + getAttributes(), + baseDirectory, + actionName + ); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", fileData.getNamespace()); + attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); + attributes.setProperty("CLASS_NAME", NewActionFile.CLASS_NAME); + addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); + addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()); + attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); + addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()); + addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); + addProperty(attributes, "FORWARD", BackendModuleType.FORWARD.getType()); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to properties. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java index 5bb8c710b..de779b246 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java @@ -111,11 +111,7 @@ protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); attributes.setProperty("CLASS_NAME", SaveActionFile.CLASS_NAME); attributes.setProperty("ENTITY_ID", fileData.getEntityId()); - attributes.setProperty("ADMIN_RESOURCE", SaveActionFile.getAdminResource( - fileData.getModuleName(), - fileData.getAcl() - ) - ); + attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); addProperty(attributes, "IMPLEMENTS", HttpMethod.POST.getInterfaceFqn()); addProperty(attributes, "DATA_PERSISTOR", FrameworkLibraryType.DATA_PERSISTOR.getType()); addProperty(attributes, "ENTITY_DTO", fileData.getDtoType()); 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..2fe00e29c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + +public final class NewActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "NewAction"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Entity New Action Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private static final NewActionFile INSTANCE = new NewActionFile(); + + /** + * Get singleton instance of the class. + * + * @return NewAction + */ + public static NewActionFile getInstance() { + return INSTANCE; + } + + /** + * Get Directory path from the module root. + * + * @param entityName String + * + * @return String + */ + public static String getDirectory(final @NotNull String entityName) { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java index 7cb9ad184..c3634e547 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -39,21 +39,6 @@ public static String getDirectory(final @NotNull String entityName) { return DIRECTORY.concat("/" + entityName); } - /** - * Get admin resource. - * - * @param moduleName String - * @param acl String - * - * @return String - */ - public static String getAdminResource( - final @NotNull String moduleName, - final @NotNull String acl - ) { - return moduleName + "::" + acl; - } - @Override public String getFileName() { return CLASS_NAME.concat("." + FILE_EXTENSION); diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java index 1036a4413..2fe113598 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java @@ -10,7 +10,8 @@ public enum BackendModuleType { CONTEXT("Magento\\Backend\\App\\Action\\Context"), - EXTENDS("Magento\\Backend\\App\\Action"); + EXTENDS("Magento\\Backend\\App\\Action"), + FORWARD("Magento\\Backend\\Model\\View\\Result\\Forward"); /** * Backend module type. 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..f208640a1 --- /dev/null +++ b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php @@ -0,0 +1,36 @@ +resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('edit'); + + return $resultForward; + } +} 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..bead2052f --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.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.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"; + + + /** + * Test generation of NewAction controller. + */ + public void testGenerateNewActionEntityFile() { + final NewActionEntityControllerFileData newActionEntityControllerFileData = + new NewActionEntityControllerFileData( + ENTITY_NAME, + MODULE_NAME, + NAMESPACE, + ACL + ); + final NewActionEntityControllerFileGenerator newActionEntityControllerFileGenerator = + new NewActionEntityControllerFileGenerator( + newActionEntityControllerFileData, + myFixture.getProject() + ); + final PsiFile newActionEntityActionFile = newActionEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath(NewActionFile.getInstance().getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + newActionEntityActionFile + ); + } +} From cb17ceb1301474a8cb14d941bc92241ec6211d65 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 10 Feb 2021 16:04:32 +0200 Subject: [PATCH 32/84] Data provider extended to provide right data into the entity form, test case adjustments --- ...omponent Custom Data Provider Class.php.ft | 25 +++++++++++++++++++ .../GridDataProvider.php | 24 ++++++++++++++++++ 2 files changed, 49 insertions(+) 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 27151b44a..16c133089 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 @@ -29,6 +29,11 @@ class ${CLASS_NAME} extends ${EXTENDS} */ private $searchResultFactory; + /** + * @var array + */ + private $loadedData = []; + /** * @param string $name * @param string $primaryFieldName @@ -85,6 +90,26 @@ class ${CLASS_NAME} extends ${EXTENDS} '#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(); + + foreach ($this->loadedData['items'] as $item) { + #set($idAccessor = '[' + "#if(${ENTITY_ID})'${ENTITY_ID}'#{else}'entity_id'#end" + ']') + $this->loadedData['items'][$item$idAccessor] = $item; + } + + return $this->loadedData; + } #else /** * @inheritDoc diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php index b5ba1faa2..e4ce073f5 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -25,6 +25,11 @@ class GridDataProvider extends DataProvider */ private $searchResultFactory; + /** + * @var array + */ + private $loadedData = []; + /** * @param string $name * @param string $primaryFieldName @@ -82,4 +87,23 @@ public function getSearchResult() 'entity_id' ); } + + /** + * Get data. + * + * @return array + */ + public function getData(): array + { + if ($this->loadedData) { + return $this->loadedData; + } + $this->loadedData = parent::getData(); + + foreach ($this->loadedData['items'] as $item) { + $this->loadedData['items'][$item['entity_id']] = $item; + } + + return $this->loadedData; + } } From aca6257453ff514b6925f74125156b35c1aa0e4b Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Wed, 10 Feb 2021 16:09:52 +0200 Subject: [PATCH 33/84] Fixed Test --- .../generation/generator/SaveEntityActionGeneratorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java index 28c6eb258..085742712 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityActionGeneratorTest.java @@ -22,7 +22,7 @@ public class SaveEntityActionGeneratorTest extends BaseGeneratorTestCase { "Foo\\Bar\\Model\\" + ENTITY_NAME + "Model" + "\\CompanyModel"; private static final String DTO_TYPE_INTERFACE = "Foo\\Bar\\Api\\Data\\" + ENTITY_NAME + "Interface"; - private static final String ACL = "company_id"; + private static final String ACL = "Foo_Bar::company_id"; private static final String ENTITY_ID = "entity_id"; /** From 8d3e89355a79ebcecdaae8a7674bcd6013acf133 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 11 Feb 2021 12:58:55 +0200 Subject: [PATCH 34/84] Improved buttons generation, test coverage changes --- ...nto Php Form Button Block Type Back.php.ft | 6 - ...o Php Form Button Block Type Back.php.html | 1 - ...o Php Form Button Block Type Delete.php.ft | 11 -- ...Php Form Button Block Type Delete.php.html | 1 - ...nto Php Form Button Block Type Save.php.ft | 22 --- ...o Php Form Button Block Type Save.php.html | 1 - .../Magento Form Button Block Class.php.ft | 23 ++- .../generation/dialog/NewEntityDialog.java | 4 +- .../dialog/NewUiComponentFormDialog.java | 10 +- .../generator/SaveEntityCommandGenerator.java | 1 - .../UiComponentFormButtonBlockGenerator.java | 184 ++++++++++++++++++ ...iComponentFormButtonPhpClassGenerator.java | 99 ---------- .../generator/UiComponentFormGenerator.java | 47 ++++- .../generator/code/ButtonMethodGenerator.java | 180 ----------------- ...BlockPhp.java => FormButtonBlockFile.java} | 19 +- .../packages/UiFormButtonTypeSettings.java | 157 +++++++++++++++ .../generateBackButtonBlock/MyBackButton.php | 19 +- .../generateCustomButtonBlock/MyCustom.php | 18 +- .../generateDeleteButtonBlock/DeleteBlock.php | 22 ++- .../generateSaveButtonBlock/SaveBlock.php | 23 ++- .../custom_entity_grid.xml | 5 + .../custom_entity_grid.xml | 5 + .../FormButtonBlockGeneratorTest.java | 48 +++-- 23 files changed, 512 insertions(+), 394 deletions(-) delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.ft delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.html delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.ft delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.html delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.ft delete mode 100644 resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonPhpClassGenerator.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/code/ButtonMethodGenerator.java rename src/com/magento/idea/magento2plugin/magento/files/{FormButtonBlockPhp.java => FormButtonBlockFile.java} (55%) create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/UiFormButtonTypeSettings.java 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 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/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 70d037a41..927bb8f29 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -744,7 +744,7 @@ protected List getButtons() { directory, "Delete", getModuleName(), - "Save", + "Delete", namespaceBuilderDelete.getNamespace(), "Delete Entity", "30", @@ -1235,7 +1235,7 @@ private void generateUiComponentFormFile() { getEntityName(), getSubmitActionName(), getDataProviderNamespace().getClassFqn() - ), project).generate(ACTION_NAME, true); + ), project, getEntityName(), getEntityIdColumn()).generate(ACTION_NAME, true); } /** 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 692698399..2a35d094f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -42,7 +42,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.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; @@ -274,10 +274,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); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java index aa74dfc5d..92949b49b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -20,7 +20,6 @@ import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; 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..d4cbe6ecd --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java @@ -0,0 +1,184 @@ +/* + * 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 = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(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.getButtonClassName()), + 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 NamespaceBuilder genericBtnNamespace = new NamespaceBuilder( + buttonData.getButtonModule(), + FormGenericButtonBlockFile.CLASS_NAME, + FormGenericButtonBlockFile.DIRECTORY + ); + attributes.setProperty("GENERIC_BUTTON", + PhpClassGeneratorUtil.getNameFromFqn(genericBtnNamespace.getClassFqn())); + + if (!FormGenericButtonBlockFile.DIRECTORY.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 a87f842b1..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 = - FileFromTemplateGenerator.getInstance(project); - - final String moduleName = buttonData.getButtonModule(); - PsiDirectory parentDirectory = ModuleIndex.getInstance(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 473e7e833..e28a9087e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java @@ -25,11 +25,14 @@ import org.jetbrains.annotations.NotNull; public class UiComponentFormGenerator extends FileGenerator { + private final UiComponentFormFileData uiFormFileData; private final Project project; + private final String entityName; + private final String entityIdField; /** - * Constructor. + * Ui Component form generator constructor. * * @param uiFormFileData UiFormFileData * @param project Project @@ -37,16 +40,36 @@ public class UiComponentFormGenerator extends FileGenerator { public UiComponentFormGenerator( final @NotNull UiComponentFormFileData uiFormFileData, final Project project + ) { + this(uiFormFileData, project, "Entity", "entity_id"); + } + + /** + * Ui Component form generator constructor. + * + * @param uiFormFileData UiFormFileData + * @param project Project + * @param entityName String + * @param entityIdField String + */ + public UiComponentFormGenerator( + final @NotNull UiComponentFormFileData uiFormFileData, + final Project project, + final @NotNull String entityName, + final @NotNull String entityIdField ) { super(project); this.uiFormFileData = uiFormFileData; this.project = project; + this.entityName = entityName; + this.entityIdField = entityIdField; } /** * Creates a module UI form file. * * @param actionName String + * * @return PsiFile */ @Override @@ -54,17 +77,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 : uiFormFileData.getButtons()) { + new UiComponentFormButtonBlockGenerator( + buttonData, + project, + entityName, + entityIdField ).generate(actionName); } } @@ -73,6 +103,7 @@ protected void createButtonClasses(final String actionName) { * Finds or creates form. * * @param actionName String + * * @return PsiFile */ protected PsiFile createForm( 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/magento/files/FormButtonBlockPhp.java b/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java similarity index 55% rename from src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockPhp.java rename to src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java index f88d51713..f705a3ab7 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/FormButtonBlockFile.java @@ -5,21 +5,24 @@ package com.magento.idea.magento2plugin.magento.files; -public class FormButtonBlockPhp extends AbstractPhpClass { - public static String template = "Magento Form Button Block Class"; +import org.jetbrains.annotations.NotNull; - 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 class FormButtonBlockFile extends AbstractPhpClass { + public static String template = "Magento 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"; - public static final String DEFAULT_METHOD = "getButtonData"; - - public FormButtonBlockPhp(final String className) { + /** + * Form button block file constructor. + * + * @param className String + */ + public FormButtonBlockFile(final @NotNull String className) { super(className); } 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..f0afbeb10 --- /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/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php index 83c14e26b..589a2bc3a 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..cb7893108 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..ed0400764 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..54d15843e 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/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml index 6e457353f..c93e58584 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml @@ -36,5 +36,10 @@ 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..d9442aa34 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml @@ -43,5 +43,10 @@ desc + + + entity_id + + 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..594fa4be0 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormButtonBlockGeneratorTest.java @@ -15,6 +15,8 @@ public class FormButtonBlockGeneratorTest extends BaseGeneratorTestCase { private static final String FORM_NAME = "my_form"; private static final String BLOCK_DIRECTORY = "Block/Form"; private static final String ACTION_NAME = "test"; + private static final String ENTITY_NAME = "Book"; + private static final String ENTITY_ID = "book_id"; public static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Block/Form"; /** @@ -42,11 +44,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 +82,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 +120,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 +158,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); From ebc4beed17e22f94eaa2259c6dc454c8651cea4b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 11 Feb 2021 16:31:00 +0200 Subject: [PATCH 35/84] Improved UX by adding autocompletion for entity name dependent fields --- .../generation/dialog/NewEntityDialog.java | 39 +++++++++++++++++++ .../dialog/NewMessageQueueDialog.java | 4 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 70d037a41..99469c4af 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; +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.OverrideClassByAPreferenceAction; @@ -94,6 +95,7 @@ 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.GetPhpClassByFQN; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; @@ -109,7 +111,9 @@ 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; @@ -121,8 +125,11 @@ import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.KeyStroke; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; import org.apache.commons.lang.StringUtils; +import org.bouncycastle.util.Strings; import org.jetbrains.annotations.NotNull; @SuppressWarnings({ @@ -257,6 +264,13 @@ public void windowClosing(final WindowEvent event) { KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + + entityName.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + autoCompleteIdentifiers(); + } + }); } /** @@ -1362,4 +1376,29 @@ private List getMenuReferences() { return menuReferencesList; } + + /** + * Autocomplete entity name dependent fields. + */ + private void autoCompleteIdentifiers() { + if (getEntityName().isEmpty()) { + return; + } + final String entityName = CamelCaseToSnakeCase.getInstance().convert(getEntityName()); + 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(getModuleName().concat("::management")); + aclTitle.setText(entityNameLabel.concat(" Management")); + menuIdentifier.setText(getModuleName().concat("::management")); + menuTitle.setText(entityNameLabel.concat(" Management")); + } } 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); From f57f07b04d20450b7ac486044938c5b128e01475 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 11 Feb 2021 16:33:01 +0200 Subject: [PATCH 36/84] Removed useless imports --- .../actions/generation/dialog/NewEntityDialog.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 99469c4af..c15b34937 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -126,10 +126,8 @@ import javax.swing.JTextPane; import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; import org.apache.commons.lang.StringUtils; -import org.bouncycastle.util.Strings; import org.jetbrains.annotations.NotNull; @SuppressWarnings({ From ded43dec2020e98a085d73dbe9ddd3ce9274fe9a Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 11 Feb 2021 18:45:09 +0200 Subject: [PATCH 37/84] Added ui components tab toggling --- .../generation/dialog/NewEntityDialog.form | 21 +++++++++++++++---- .../generation/dialog/NewEntityDialog.java | 18 ++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index 8934c75a4..e0fa57154 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -18,7 +18,10 @@
- + + + + @@ -26,7 +29,10 @@ - + + + + @@ -137,12 +143,19 @@ - + - + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index c15b34937..4551b7597 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -196,6 +196,7 @@ public class NewEntityDialog extends AbstractDialog { private static final String GRID_NAME = "Grit 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"; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME}) @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) @@ -221,6 +222,7 @@ public class NewEntityDialog extends AbstractDialog { private JTextPane exampleAclId; private JTextPane exampleFormName; private JTextPane exampleGridName; + private JPanel uiComponentsPanel; private JTextField observerName; /** @@ -269,6 +271,10 @@ protected void textChanged(final @NotNull DocumentEvent event) { autoCompleteIdentifiers(); } }); + + toggleUiComponentsPanel(); + + createUiComponent.addItemListener(event -> toggleUiComponentsPanel()); } /** @@ -1399,4 +1405,16 @@ private void autoCompleteIdentifiers() { menuIdentifier.setText(getModuleName().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); + } + } } From 8447132d08e91045f478a099f9897c338c296b0c Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 12 Feb 2021 12:15:46 +0200 Subject: [PATCH 38/84] Fix ui component tab view --- .../generation/dialog/NewEntityDialog.form | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index e0fa57154..5ca5f1575 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -18,10 +18,7 @@ - - - - + @@ -29,10 +26,7 @@ - - - - + @@ -148,14 +142,7 @@ - - - - - - - - + From 0da4503fcff2338e4c762c427c51c77910f20984 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 12 Feb 2021 12:24:56 +0200 Subject: [PATCH 39/84] Removed border from ui component tab --- .../actions/generation/dialog/NewEntityDialog.form | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index 5ca5f1575..416f2c4d4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -142,8 +142,11 @@ - - + + + + + From 55147af5bf15f5d38b9799fc9572282dbab8ea13 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Fri, 12 Feb 2021 21:57:56 +0200 Subject: [PATCH 40/84] Fixed code by recommendation --- ...gento Entity New Action Controller Class.php.ft | 11 ++++++----- .../data/NewActionEntityControllerFileData.java | 14 +++++++++++++- .../actions/generation/dialog/NewEntityDialog.java | 3 ++- .../NewActionEntityControllerFileGenerator.java | 3 ++- .../magento/packages/code/BackendModuleType.java | 2 +- .../generator/NewActionEntityGeneratorTest.java | 4 +++- 6 files changed, 27 insertions(+), 10 deletions(-) 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 index c7aa24380..ec41276d1 100644 --- a/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft +++ b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft @@ -23,14 +23,15 @@ class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS} /** * Create new ${ENTITY_NAME} action. * - * @return ${RESULT_INTERFACE}|${FORWARD} + * @return ${RESULT_PAGE}|${RESULT_INTERFACE} */ public function execute() { - /** @var ${FORWARD} $resultForward */ - $resultForward = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD); - $resultForward->forward('edit'); + /** @var ${RESULT_PAGE} $resultPage */ + $resultPage = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD); + $resultPage->setActiveMenu('${MENU_IDENTIFIER}'); + $resultPage->getConfig()->getTitle()->prepend(__('New ${ENTITY_NAME}')); - return $resultForward; + return $resultPage; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java index 2f5dc4d13..ac88e84e6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java @@ -13,6 +13,7 @@ public class NewActionEntityControllerFileData { private final String moduleName; private final String namespace; private final String acl; + private final String menuIdentifier; /** * Controller NewAction file constructor. @@ -25,12 +26,14 @@ public NewActionEntityControllerFileData( final @NotNull String entityName, final @NotNull String moduleName, final @NotNull String namespace, - final @NotNull String acl + final @NotNull String acl, + final @NotNull String menuIdentifier ) { this.entityName = entityName; this.moduleName = moduleName; this.namespace = namespace; this.acl = acl; + this.menuIdentifier = menuIdentifier; } /** @@ -68,4 +71,13 @@ public String getNamespace() { public String getAcl() { return acl; } + + /** + * Get menu. + * + * @return String + */ + public String getMenu() { + return menuIdentifier; + } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 288cea7d7..fbde1e8b0 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -1212,7 +1212,8 @@ private void generateFormNewActionControllerFile() { getEntityName(), getModuleName(), namespace.getNamespace(), - getAcl() + getAcl(), + getMenuIdentifier() ), project).generate(ACTION_NAME, false); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java index 7f0adcc91..08bc06b10 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java @@ -76,9 +76,10 @@ protected void fillAttributes(final @NotNull Properties attributes) { addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()); attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); + attributes.setProperty("MENU_IDENTIFIER", fileData.getMenu()); addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()); addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); - addProperty(attributes, "FORWARD", BackendModuleType.FORWARD.getType()); + addProperty(attributes, "RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java index 2fe113598..434ecf17f 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java @@ -11,7 +11,7 @@ public enum BackendModuleType { CONTEXT("Magento\\Backend\\App\\Action\\Context"), EXTENDS("Magento\\Backend\\App\\Action"), - FORWARD("Magento\\Backend\\Model\\View\\Result\\Forward"); + RESULT_PAGE("Magento\\Backend\\Model\\View\\Result\\Page"); /** * Backend module type. diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java index bead2052f..e9fec69cb 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java @@ -17,6 +17,7 @@ public class NewActionEntityGeneratorTest extends BaseGeneratorTestCase { 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"; /** @@ -28,7 +29,8 @@ public void testGenerateNewActionEntityFile() { ENTITY_NAME, MODULE_NAME, NAMESPACE, - ACL + ACL, + MENU ); final NewActionEntityControllerFileGenerator newActionEntityControllerFileGenerator = new NewActionEntityControllerFileGenerator( From 4e2e13c4cec7c7e01cc00ea3d77cf2df3f574356 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Fri, 12 Feb 2021 22:05:23 +0200 Subject: [PATCH 41/84] Fixed code --- .../Magento Entity New Action Controller Class.php.ft | 2 +- .../generator/NewActionEntityControllerFileGenerator.java | 4 +++- .../generation/generator/NewActionEntityGeneratorTest.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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 index ec41276d1..36989b2c2 100644 --- a/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft +++ b/resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft @@ -28,7 +28,7 @@ class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS} public function execute() { /** @var ${RESULT_PAGE} $resultPage */ - $resultPage = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD); + $resultPage = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_PAGE); $resultPage->setActiveMenu('${MENU_IDENTIFIER}'); $resultPage->getConfig()->getTitle()->prepend(__('New ${ENTITY_NAME}')); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java index 08bc06b10..623812fc8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java @@ -77,7 +77,9 @@ protected void fillAttributes(final @NotNull Properties attributes) { addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()); attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); attributes.setProperty("MENU_IDENTIFIER", fileData.getMenu()); - addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()); + addProperty(attributes, "RESULT_INTERFACE", + FrameworkLibraryType.RESULT_INTERFACE.getType() + ); addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); addProperty(attributes, "RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()); diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java index e9fec69cb..3690e1180 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java @@ -37,7 +37,8 @@ public void testGenerateNewActionEntityFile() { newActionEntityControllerFileData, myFixture.getProject() ); - final PsiFile newActionEntityActionFile = newActionEntityControllerFileGenerator.generate("test"); + final PsiFile newActionEntityActionFile = + newActionEntityControllerFileGenerator.generate("test"); final String filePath = this.getFixturePath(NewActionFile.getInstance().getFileName()); final PsiFile expectedFile = myFixture.configureByFile(filePath); From 766a29fcdb93165e45ea5e28dba55ad2053f8917 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Fri, 12 Feb 2021 22:09:39 +0200 Subject: [PATCH 42/84] Changed test template file --- .../generateNewActionEntityFile/NewAction.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php index f208640a1..96710c60e 100644 --- a/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php +++ b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php @@ -1,13 +1,10 @@ resultFactory->create(ResultFactory::TYPE_FORWARD); - $resultForward->forward('edit'); - - return $resultForward; + /** @var Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Foo_Bar::menu_id'); + $resultPage->getConfig()->getTitle()->prepend(__('New Company')); + return $resultPage; } -} +} \ No newline at end of file From 19e927423f7c89f9779c3d3b49f83500141c3ca3 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 12 Feb 2021 22:42:35 +0200 Subject: [PATCH 43/84] Small fixes --- .../internal/Magento UI Component Grid XML.xml.ft | 7 +++++++ .../generateNewActionEntityFile/NewAction.php | 7 ++++++- .../generateUiGridForBaseArea/custom_entity_grid.xml | 7 +++++++ .../generateUiGridWithoutToolbar/custom_entity_grid.xml | 7 +++++++ 4 files changed, 27 insertions(+), 1 deletion(-) 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 4c765a560..d72447bda 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 diff --git a/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php index 96710c60e..6140d1520 100644 --- a/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php +++ b/testData/actions/generation/generator/NewActionEntityGenerator/generateNewActionEntityFile/NewAction.php @@ -1,10 +1,13 @@ resultFactory->create(ResultFactory::TYPE_PAGE); $resultPage->setActiveMenu('Foo_Bar::menu_id'); $resultPage->getConfig()->getTitle()->prepend(__('New Company')); + return $resultPage; } -} \ No newline at end of file +} diff --git a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml index 6e457353f..b292d05fd 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml @@ -8,6 +8,13 @@ + + + custom_entity_grid_columns custom_entity_grid.custom_entity_grid_data_source 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 From dc6cb89867aef699971d2cb4b3117d7b330e2a2b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Feb 2021 11:20:41 +0200 Subject: [PATCH 44/84] Added new entity layout file generation, test for generation --- resources/META-INF/plugin.xml | 1 + .../Magento New Entity Layout XML.xml.ft | 4 + .../Magento New Entity Layout XML.xml.html | 0 .../generation/data/NewEntityLayoutData.java | 59 +++++++++ .../generation/dialog/NewEntityDialog.java | 24 ++++ .../generator/NewEntityLayoutGenerator.java | 116 ++++++++++++++++++ .../magento/files/NewEntityLayoutFile.java | 60 +++++++++ .../book_book_new.xml | 4 + .../NewEntityLayoutGeneratorTest.java | 46 +++++++ 9 files changed, 314 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento New Entity Layout XML.xml.ft create mode 100644 resources/fileTemplates/internal/Magento New Entity Layout XML.xml.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/NewEntityLayoutData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/NewEntityLayoutFile.java create mode 100644 testData/actions/generation/generator/NewEntityLayoutGenerator/generateNewEntityLayoutFile/book_book_new.xml create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/NewEntityLayoutGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 9672205da..5fe1a47c9 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -236,6 +236,7 @@ + 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/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/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 6dd4a0227..e1ad6dd28 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -27,6 +27,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; import com.magento.idea.magento2plugin.actions.generation.data.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; @@ -64,6 +65,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.NewEntityLayoutGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; @@ -362,6 +364,7 @@ private void onOK() { generateUiComponentGridFile(); generateFormViewControllerFile(); generateFormLayoutFile(); + generateNewEntityLayoutFile(); generateSaveEntityCommandFile(); generateFormSaveControllerFile(); generateFormUiComponentGenericButtonFile(); @@ -1083,6 +1086,19 @@ private String getEditViewAction() { + "edit"; } + /** + * Get new entity action path. + * + * @return String + */ + private String getNewEntityAction() { + return getRoute() + + File.separator + + FirstLetterToLowercaseUtil.convert(getEntityName()) + + File.separator + + "new"; + } + /** * Get delete action path. * @@ -1131,6 +1147,14 @@ private void generateFormLayoutFile() { ), project).generate(ACTION_NAME, false); } + private void generateNewEntityLayoutFile() { + new NewEntityLayoutGenerator(new NewEntityLayoutData( + getModuleName(), + getNewEntityAction(), + getEditViewAction() + ), project).generate(ACTION_NAME, false); + } + /** * Run SaveCommand.php file generator for an entity. */ 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..c41360581 --- /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 = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(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/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/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/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 + ); + } +} From 2bbda0ade95d5a64ed4962cdc301885d89044fee Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Feb 2021 15:15:50 +0200 Subject: [PATCH 45/84] Fixed entity saving use case flow --- .../internal/Magento Entity Save Controller Class.php.ft | 2 +- .../internal/Magento Resource Model Class.php.ft | 1 + .../internal/Magento Save Entity Command Model.php.ft | 5 +++++ .../generateFile/TestResourceModel.php | 1 + .../generateSaveEntityActionWithInterfaceFile/Save.php | 2 +- .../generateSaveEntityActionWithoutInterfaceFile/Save.php | 2 +- .../generateSaveEntityCommandFile/SaveCommand.php | 5 +++++ 7 files changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft index 64de350af..552eac78c 100644 --- a/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft +++ b/resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft @@ -66,7 +66,7 @@ class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS} try { /** @var ${ENTITY_DTO}|${DATA_OBJECT} $entityModel */ $entityModel = $this->entityDataFactory->create(); - $entityModel->addData($params); + $entityModel->addData($params['general']); $this->saveCommand->execute($entityModel); $this->messageManager->addSuccessMessage( __('The ${ENTITY_NAME} data was saved successfully') 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 index 793c0a48b..39bf47820 100644 --- a/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft +++ b/resources/fileTemplates/internal/Magento Save Entity Command Model.php.ft @@ -57,6 +57,11 @@ class ${CLASS_NAME} /** @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( 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/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php index ea566a347..dcff220fd 100644 --- a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithInterfaceFile/Save.php @@ -73,7 +73,7 @@ public function execute() try { /** @var CompanyInterface|DataObject $entityModel */ $entityModel = $this->entityDataFactory->create(); - $entityModel->addData($params); + $entityModel->addData($params['general']); $this->saveCommand->execute($entityModel); $this->messageManager->addSuccessMessage( __('The Company data was saved successfully') diff --git a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php index 8a809357c..d55ca4843 100644 --- a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php @@ -73,7 +73,7 @@ public function execute() try { /** @var CompanyModel|DataObject $entityModel */ $entityModel = $this->entityDataFactory->create(); - $entityModel->addData($params); + $entityModel->addData($params['general']); $this->saveCommand->execute($entityModel); $this->messageManager->addSuccessMessage( __('The Company data was saved successfully') diff --git a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php index c27c4045a..b985bc32c 100644 --- a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php +++ b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php @@ -61,6 +61,11 @@ public function execute(BookData $book): int /** @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( From 0bb50469b5b41660251f6f23835b7a0a55537380 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Feb 2021 17:13:45 +0200 Subject: [PATCH 46/84] Rewrited edit action generation, added test case for edit action generation --- resources/META-INF/plugin.xml | 1 + ...Entity Edit Action Controller Class.php.ft | 37 +++++ ...tity Edit Action Controller Class.php.html | 18 +++ .../generation/data/EditEntityActionData.java | 98 ++++++++++++ .../generation/dialog/NewEntityDialog.java | 49 +++--- .../generator/EditEntityActionGenerator.java | 145 ++++++++++++++++++ ...ewActionEntityControllerFileGenerator.java | 5 + .../files/actions/EditEntityActionFile.java | 61 ++++++++ .../generateEditEntityActionFile/Edit.php | 37 +++++ .../EditEntityActionGeneratorTest.java | 51 ++++++ 10 files changed, 484 insertions(+), 18 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Entity Edit Action Controller Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java create mode 100644 testData/actions/generation/generator/EditEntityActionGenerator/generateEditEntityActionFile/Edit.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index acaae1a3e..d4d3e3dc1 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -238,6 +238,7 @@ + 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/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..b4568376c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java @@ -0,0 +1,98 @@ +/* + * 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 classFqn; + private final String namespace; + private final String acl; + private final String menuIdentifier; + + /** + * Edit action data constructor. + * + * @param entityName String + * @param moduleName String + * @param classFqn String + * @param namespace String + * @param acl String + * @param menuIdentifier String + */ + public EditEntityActionData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String classFqn, + final @NotNull String namespace, + final @NotNull String acl, + final @NotNull String menuIdentifier + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.classFqn = classFqn; + 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 class FQN. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * 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/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 208996700..e27cd9271 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -20,6 +20,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.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; @@ -56,6 +57,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.EditEntityActionGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; @@ -87,6 +89,7 @@ import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; +import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile; import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; @@ -365,12 +368,12 @@ private void onOK() { generateDataProviderFile(); generateUiComponentGridActionColumnFile(); generateUiComponentGridFile(); - generateFormViewControllerFile(); generateFormLayoutFile(); generateNewEntityLayoutFile(); generateSaveEntityCommandFile(); - generateFormSaveControllerFile(); generateFormUiComponentGenericButtonFile(); + generateFormEditControllerFile(); + generateFormSaveControllerFile(); generateFormNewActionControllerFile(); generateUiComponentFormFile(); } @@ -645,12 +648,22 @@ public String getRoute() { return route.getText().trim(); } - private String getViewActionName() { + /** + * Get edit action name. + * + * @return String + */ + private String getEditActionName() { return "Edit"; } + /** + * Get submit action name. + * + * @return String + */ private String getSubmitActionName() { - return "Save";//NOPMD + return "Save"; } private String getControllerDirectory() { @@ -1117,24 +1130,24 @@ private String getDeleteAction() { } /** - * Generate form view controller file. + * Generate form edit controller file. */ - private void generateFormViewControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( + private void generateFormEditControllerFile() { + final EditEntityActionFile file = new EditEntityActionFile(getEntityName()); + final NamespaceBuilder editActionNamespaceBuilder = new NamespaceBuilder( getModuleName(), - getViewActionName(), - getControllerDirectory().concat(getEntityName()) + file.getClassName(), + file.getDirectory() ); - new ModuleControllerClassGenerator(new ControllerFileData( - getControllerDirectory().concat(getEntityName()), - getViewActionName(), + final EditEntityActionData data = new EditEntityActionData( + getEntityName(), getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), + editActionNamespaceBuilder.getClassFqn(), + editActionNamespaceBuilder.getNamespace(), getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); + getMenuIdentifier() + ); + new EditEntityActionGenerator(data, project).generate(ACTION_NAME, false); } /** @@ -1146,7 +1159,7 @@ private void generateFormLayoutFile() { getRoute(), getModuleName(), getEntityName(), - getViewActionName(), + getEditActionName(), getFormName() ), project).generate(ACTION_NAME, false); } 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..e218e54a2 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java @@ -0,0 +1,145 @@ +/* + * 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.EditEntityActionData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class EditEntityActionGenerator extends FileGenerator { + + private final Project project; + private final EditEntityActionFile file; + private final EditEntityActionData data; + private final boolean checkFileAlreadyExists; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final List uses; + + /** + * 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); + this.data = data; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + file = new EditEntityActionFile(data.getEntityName()); + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + moduleIndex = ModuleIndex.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + uses = new ArrayList<>(); + } + + /** + * Generate edit action controller for entity. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass editActionClass = GetPhpClassByFQN.getInstance(project).execute( + data.getClassFqn() + ); + + if (this.checkFileAlreadyExists && editActionClass != null) { + return editActionClass.getContainingFile(); + } + + final PsiDirectory editActionBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleIndex.getModuleDirectoryByModuleName( + data.getModuleName() + ), + file.getDirectory() + ); + + return fileFromTemplateGenerator.generate( + file, + getAttributes(), + editActionBaseDir, + actionName + ); + } + + /** + * Fill edit action file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", data.getNamespace()); + attributes.setProperty("ENTITY_NAME", data.getEntityName()); + attributes.setProperty("CLASS_NAME", file.getClassName()); + attributes.setProperty("ADMIN_RESOURCE", data.getAcl()); + attributes.setProperty("MENU_IDENTIFIER", data.getMenu()); + + addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); + addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()); + addProperty(attributes, "RESULT_INTERFACE", + FrameworkLibraryType.RESULT_INTERFACE.getType() + ); + addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); + addProperty(attributes, "RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to properties. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java index 623812fc8..b67c7b52e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java @@ -1,3 +1,8 @@ +/* + * 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; diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java new file mode 100644 index 000000000..013908606 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java @@ -0,0 +1,61 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + +public final class EditEntityActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Edit"; + public static final String FILE_EXTENSION = "php"; + 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 entityName String + */ + public EditEntityActionFile(final @NotNull String entityName) { + this.entityName = entityName; + } + + /** + * Get class name. + * + * @return String + */ + public String getClassName() { + return CLASS_NAME; + } + + /** + * Get Directory path from the module root. + * + * @return String + */ + public String getDirectory() { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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/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..2c569040d --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.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.EditEntityActionData; +import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile; + +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 NAMESPACE = + "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 EditEntityActionFile file = new EditEntityActionFile(ENTITY_NAME); + final EditEntityActionGenerator generator = + new EditEntityActionGenerator( + new EditEntityActionData( + ENTITY_NAME, + MODULE_NAME, + NAMESPACE.concat("\\" + file.getClassName()), + NAMESPACE, + 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 + ); + } +} From 813aed55c9245968a3de04bf6ad4dc4d358b8c30 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Tue, 16 Feb 2021 20:06:38 +0200 Subject: [PATCH 47/84] Changed boolean field view on the form, converted labels for fields --- ...agento Module UI Component Form Field Xml.xml.ft | 13 +++++++++++++ .../actions/generation/dialog/NewEntityDialog.java | 6 +++++- .../packages/uiComponent/FormElementType.java | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) 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/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 208996700..3ad35d238 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -271,6 +271,7 @@ public void windowClosing(final WindowEvent event) { ); entityName.getDocument().addDocumentListener(new DocumentAdapter() { + @SuppressWarnings("PMD.AccessorMethodGeneration") @Override protected void textChanged(final @NotNull DocumentEvent event) { autoCompleteIdentifiers(); @@ -805,7 +806,10 @@ public List getFields() { final String name = model.getValueAt(count, 0).toString(); final String dataType = model.getValueAt(count, 1).toString(); - final String label = model.getValueAt(count, 0).toString(); //todo: convert + 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"; diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java b/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java index 992414e46..600c52d69 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java @@ -78,7 +78,7 @@ public static FormElementType getDefaultForProperty(final @NotNull PropertiesTyp case STRING: return FormElementType.INPUT; case BOOL: - return FormElementType.BOOLEAN; + return FormElementType.CHECKBOX; case FLOAT: return FormElementType.PRICE; default: From b756009ceae13bb372b5194b72bfd6fc5187550d Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Tue, 16 Feb 2021 20:48:53 +0200 Subject: [PATCH 48/84] Fixed data provider to work with listing and form --- ...nto UI Component Custom Data Provider Class.php.ft | 11 +++++++++-- .../internal/Magento UI Component Form XML.xml.ft | 1 + .../generateFormXmlFile/my_form.xml | 1 + .../GridDataProvider.php | 7 ++++++- 4 files changed, 17 insertions(+), 3 deletions(-) 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 16c133089..c92a2c01e 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 @@ -102,10 +102,17 @@ class ${CLASS_NAME} extends ${EXTENDS} 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($getIdFromParamsAccessor = "[(int) $this->request->getParam('$entityId')]") foreach ($this->loadedData['items'] as $item) { - #set($idAccessor = '[' + "#if(${ENTITY_ID})'${ENTITY_ID}'#{else}'entity_id'#end" + ']') - $this->loadedData['items'][$item$idAccessor] = $item; + $itemsById$entityIdAccessor = $item; + } + + if ($this->request->getParam('$entityId')) { + $this->loadedData['entity'] = $itemsById$getIdFromParamsAccessor; } return $this->loadedData; 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/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml index 6685de535..9553a38d1 100644 --- a/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml +++ b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml @@ -10,6 +10,7 @@ my_form + data.general my_form.my_form_data_source diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php index e4ce073f5..3debfb491 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -99,9 +99,14 @@ public function getData(): array return $this->loadedData; } $this->loadedData = parent::getData(); + $itemsById = []; foreach ($this->loadedData['items'] as $item) { - $this->loadedData['items'][$item['entity_id']] = $item; + $itemsById[(int)$item['entity_id']] = $item; + } + + if ($this->request->getParam('entity_id')) { + $this->loadedData['entity'] = $itemsById[(int)$this->request->getParam('entity_id')]; } return $this->loadedData; From dbb584ca2d6215b6f424e25c4b6df30ab7588e6c Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 17 Feb 2021 08:48:17 +0200 Subject: [PATCH 49/84] Small fixes --- .../actions/generation/dialog/NewEntityDialog.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index e27cd9271..169b06c36 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -16,7 +16,6 @@ import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; -import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; 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.DbSchemaXmlData; @@ -65,7 +64,6 @@ import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; 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.NewActionEntityControllerFileGenerator; @@ -95,7 +93,6 @@ import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; 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.PropertiesTypes; import com.magento.idea.magento2plugin.magento.packages.database.TableEngines; import com.magento.idea.magento2plugin.magento.packages.database.TableResources; From 8f9f18928a992a4ba4013aa29f625b1e9dceb406 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Wed, 17 Feb 2021 15:09:18 +0200 Subject: [PATCH 50/84] Added Generator Delete Entity By Id --- resources/META-INF/plugin.xml | 1 + ...o Delete Entity By Id Command Model.php.ft | 83 ++++++++++ ...Delete Entity By Id Command Model.php.html | 18 +++ .../data/DeleteEntityByIdCommandData.java | 110 +++++++++++++ .../generation/dialog/NewEntityDialog.java | 31 ++++ .../DeleteEntityByIdCommandGenerator.java | 149 ++++++++++++++++++ .../commands/DeleteEntityByIdCommandFile.java | 84 ++++++++++ .../magento/packages/code/ExceptionType.java | 4 +- .../DeleteByIdCommand.php | 86 ++++++++++ .../DeleteEntityCommandGeneratorTest.java | 56 +++++++ 10 files changed, 621 insertions(+), 1 deletion(-) create mode 100644 resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.ft create mode 100644 resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java create mode 100644 testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityCommandGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index acaae1a3e..1a92857d8 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -238,6 +238,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.ft b/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.ft new file mode 100644 index 000000000..ac18b5b21 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.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 Model.php.html b/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.html new file mode 100644 index 000000000..f36b52820 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.html @@ -0,0 +1,18 @@ + + +

+ +

+ + + + + + + + + + +
Template's predefined variables:
${NAMESPACE} 
+ + 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..f674bfb39 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java @@ -0,0 +1,110 @@ +/* + * 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 namespace; + private final String classFqn; + private final String modelClassFqn; + private final String resourceModelClassFqn; + private final String entityId; + + /** + * Delete Command DTO Constructor. + * + * @param moduleName String + * @param entityName String + * @param namespace String + * @param classFqn String + * @param modelClassFqn String + * @param resourceModelClassFqn String + * @param entityId String + */ + public DeleteEntityByIdCommandData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String namespace, + final @NotNull String classFqn, + final @NotNull String modelClassFqn, + final @NotNull String resourceModelClassFqn, + final @NotNull String entityId + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.namespace = namespace; + this.classFqn = classFqn; + this.modelClassFqn = modelClassFqn; + this.resourceModelClassFqn = resourceModelClassFqn; + this.entityId = entityId; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get class FQN. + * + * @return String + */ + public String getClassFqn() { + return classFqn; + } + + /** + * Get entity model class FQN. + * + * @return String + */ + public String getModelClassFqn() { + return modelClassFqn; + } + + /** + * Get entity resource model class FQN. + * + * @return String + */ + public String getResourceModelClassFqn() { + return resourceModelClassFqn; + } + + /** + * Get entity Id. + * + * @return String + */ + public String getEntityId() { + return entityId; + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 208996700..4368bfc46 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -20,6 +20,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.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; @@ -56,6 +57,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.DeleteEntityByIdCommandGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; @@ -89,6 +91,7 @@ import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; +import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; import com.magento.idea.magento2plugin.magento.packages.Areas; import com.magento.idea.magento2plugin.magento.packages.File; @@ -369,6 +372,7 @@ private void onOK() { generateFormLayoutFile(); generateNewEntityLayoutFile(); generateSaveEntityCommandFile(); + generateDeleteEntityByIdCommandFile(); generateFormSaveControllerFile(); generateFormUiComponentGenericButtonFile(); generateFormNewActionControllerFile(); @@ -1193,6 +1197,33 @@ private void generateSaveEntityCommandFile() { modelNamespace.getClassFqn(), resourceModelNamespace.getClassFqn(), dtoType + ), project).generate(ACTION_NAME, true); + } + + /** + * Run DeleteEntityById.php file generator for an entity. + */ + private void generateDeleteEntityByIdCommandFile() { + final String classFqn = DeleteEntityByIdCommandFile.getClassFqn( + getModuleName(), + getEntityName() + ); + final String namespace = DeleteEntityByIdCommandFile.getNamespace( + getModuleName(), + getEntityName() + ); + final NamespaceBuilder modelNamespace = getModelNamespace(); + final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); + + new DeleteEntityByIdCommandGenerator( + new DeleteEntityByIdCommandData( + getModuleName(), + getEntityName(), + namespace, + classFqn, + modelNamespace.getClassFqn(), + resourceModelNamespace.getClassFqn(), + getEntityIdColumn() ), project ).generate(ACTION_NAME, true); 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..4128b7443 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java @@ -0,0 +1,149 @@ +/* + * 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.DeleteEntityByIdCommandData; +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.indexes.ModuleIndex; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class DeleteEntityByIdCommandGenerator extends FileGenerator { + + private final Project project; + private final DeleteEntityByIdCommandData deleteEntityByIdCommandData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final boolean checkFileAlreadyExists; + private final List uses; + + /** + * Delete entity command generator constructor. + * + * @param deleteEntityByIdCommandData DeleteEntityCommandData + * @param project Project + */ + public DeleteEntityByIdCommandGenerator( + final @NotNull DeleteEntityByIdCommandData deleteEntityByIdCommandData, + final @NotNull Project project + ) { + this(deleteEntityByIdCommandData, project, true); + } + + /** + * Delete entity command generator constructor. + * + * @param deleteEntityByIdCommandData DeleteEntityCommandData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public DeleteEntityByIdCommandGenerator( + final @NotNull DeleteEntityByIdCommandData deleteEntityByIdCommandData, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project); + this.deleteEntityByIdCommandData = deleteEntityByIdCommandData; + this.project = project; + this.checkFileAlreadyExists = checkFileAlreadyExists; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + moduleIndex = ModuleIndex.getInstance(project); + uses = new ArrayList<>(); + } + + /** + * Generate delete command for entity. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PhpClass deleteEntityCommandClass = GetPhpClassByFQN.getInstance(project).execute( + deleteEntityByIdCommandData.getClassFqn() + ); + + if (this.checkFileAlreadyExists && deleteEntityCommandClass != null) { + return deleteEntityCommandClass.getContainingFile(); + } + + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + deleteEntityByIdCommandData.getModuleName() + ); + final PsiDirectory deleteCommandFileBaseDir = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + DeleteEntityByIdCommandFile.getDirectory(deleteEntityByIdCommandData.getEntityName()) + ); + + return fileFromTemplateGenerator.generate( + new DeleteEntityByIdCommandFile(), + getAttributes(), + deleteCommandFileBaseDir, + actionName + ); + } + + /** + * Fill delete command file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("ENTITY_NAME", deleteEntityByIdCommandData.getEntityName()); + attributes.setProperty("NAMESPACE", deleteEntityByIdCommandData.getNamespace()); + attributes.setProperty("CLASS_NAME", DeleteEntityByIdCommandFile.CLASS_NAME); + attributes.setProperty("ENTITY_ID", deleteEntityByIdCommandData.getEntityId()); + uses.add("Exception"); + addProperty(attributes, "COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType()); + addProperty(attributes, "NO_SUCH_ENTITY_EXCEPTION", + ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()); + addProperty(attributes, "LOGGER", FrameworkLibraryType.LOGGER.getType()); + + final String modelType = deleteEntityByIdCommandData.getModelClassFqn(); + addProperty(attributes, "MODEL", modelType); + + final String modelFactoryType = modelType.concat("Factory"); + addProperty(attributes, "MODEL_FACTORY", modelFactoryType); + + final String resourceType = deleteEntityByIdCommandData.getResourceModelClassFqn(); + addProperty(attributes, "RESOURCE", resourceType); + + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to property list. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..9021d3272 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -0,0 +1,84 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.commands; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import com.magento.idea.magento2plugin.magento.packages.Package; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityByIdCommandFile implements ModuleFileInterface { + public static final String CLASS_NAME = "DeleteByIdCommand"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Delete Entity By Id Command Model"; + private static final String DIRECTORY = "Command"; + + /** + * Get namespace. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull String getNamespace( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( + moduleName, + DeleteEntityByIdCommandFile.CLASS_NAME, + DeleteEntityByIdCommandFile.getDirectory(entityName) + ); + + return namespaceBuilder.getNamespace(); + } + + /** + * Get class FQN. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static String getClassFqn( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return getNamespace(moduleName, entityName) + .concat(Package.fqnSeparator) + .concat(CLASS_NAME); + } + + /** + * Get directory for delete command file. + * + * @param entityName String + * + * @return String + */ + public static String getDirectory(final @NotNull String entityName) { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java index 9e4d426c5..21cbb6a98 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java @@ -9,7 +9,9 @@ import org.jetbrains.annotations.NotNull; public enum ExceptionType { - COULD_NOT_SAVE("Magento\\Framework\\Exception\\CouldNotSaveException"); + 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. 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/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..9708154fa --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityCommandGeneratorTest.java @@ -0,0 +1,56 @@ +/* + * 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 EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Command/" + ENTITY_NAME; + private static final String NAMESPACE = "Foo\\Bar\\Command\\" + ENTITY_NAME; + private static final String CLASS_FQN = NAMESPACE + "\\" + + DeleteEntityByIdCommandFile.CLASS_NAME; + private static final String MODEL_CLASS_FQN = "Foo\\Bar\\Model\\" + ENTITY_NAME + "Model"; + private static final String RESOURCE_CLASS_FQN = "Foo\\Bar\\Model\\ResourceModel\\" + + ENTITY_NAME + "Resource"; + 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, + NAMESPACE, + CLASS_FQN, + MODEL_CLASS_FQN, + RESOURCE_CLASS_FQN, + ENTITY_ID + ); + final DeleteEntityByIdCommandGenerator deleteEntityByIdCommandGenerator = + new DeleteEntityByIdCommandGenerator( + deleteEntityByIdCommandData, + myFixture.getProject(), + false + ); + final String filePath = this.getFixturePath( + new DeleteEntityByIdCommandFile().getFileName() + ); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + final PsiFile deleteEntityCommandFile = deleteEntityByIdCommandGenerator.generate("test"); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + deleteEntityCommandFile + ); + } +} From 3a91fe986211dcc598bbf6368e1d0e26e0d16ead Mon Sep 17 00:00:00 2001 From: eduard13 Date: Wed, 17 Feb 2021 15:46:12 +0200 Subject: [PATCH 51/84] Code improvements --- .../Magento UI Component Custom Data Provider Class.php.ft | 6 +++--- .../GridDataProvider.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) 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 c92a2c01e..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 @@ -106,13 +106,13 @@ class ${CLASS_NAME} extends ${EXTENDS} #set($entityId = "#if(${ENTITY_ID})${ENTITY_ID}#{else}entity_id#end") #set($entityIdAccessor = '[(int) $item[' + "'$entityId'" + ']]') -#set($getIdFromParamsAccessor = "[(int) $this->request->getParam('$entityId')]") +#set($getIdAccessor = "[(int) $id]") foreach ($this->loadedData['items'] as $item) { $itemsById$entityIdAccessor = $item; } - if ($this->request->getParam('$entityId')) { - $this->loadedData['entity'] = $itemsById$getIdFromParamsAccessor; + if ($id = $this->request->getParam('$entityId', null)) { + $this->loadedData['entity'] = $itemsById$getIdAccessor; } return $this->loadedData; diff --git a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php index 3debfb491..153b4eaf5 100644 --- a/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php +++ b/testData/actions/generation/generator/UiComponentGridDataProviderGenerator/generateDataProviderWithInjectedGetListQuery/GridDataProvider.php @@ -105,8 +105,8 @@ public function getData(): array $itemsById[(int)$item['entity_id']] = $item; } - if ($this->request->getParam('entity_id')) { - $this->loadedData['entity'] = $itemsById[(int)$this->request->getParam('entity_id')]; + if ($id = $this->request->getParam('entity_id', null)) { + $this->loadedData['entity'] = $itemsById[(int)$id]; } return $this->loadedData; From 9c4be7f7c1bed9b2312f2fa7873811d48c214046 Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Wed, 17 Feb 2021 18:28:16 +0200 Subject: [PATCH 52/84] Added Generator for Delete Controller --- resources/META-INF/plugin.xml | 1 + ...ento Entity Delete Controller Class.php.ft | 61 ++++++++++ ...to Entity Delete Controller Class.php.html | 18 +++ .../data/DeleteEntityControllerFileData.java | 97 ++++++++++++++++ .../generation/dialog/NewEntityDialog.java | 40 +++++++ .../DeleteEntityControllerFileGenerator.java | 107 ++++++++++++++++++ .../files/actions/DeleteActionFile.java | 54 +++++++++ .../magento/packages/code/ExceptionType.java | 4 +- .../generateDeleteEntityFile/Delete.php | 66 +++++++++++ .../generator/DeleteEntityGeneratorTest.java | 53 +++++++++ 10 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java create mode 100644 testData/actions/generation/generator/DeleteEntityGenerator/generateDeleteEntityFile/Delete.php create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index acaae1a3e..b67395afe 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -238,6 +238,7 @@ + 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/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..83487b35a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java @@ -0,0 +1,97 @@ +/* + * 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 namespace; + private final String deleteCommandFqn; + private final String acl; + private final String entityId; + + /** + * Controller Delete file constructor. + * + * @param entityName String + * @param moduleName String + * @param namespace String + * @param acl String + * @param entityId String + */ + public DeleteEntityControllerFileData( + final @NotNull String entityName, + final @NotNull String moduleName, + final @NotNull String namespace, + final @NotNull String deleteCommandFqn, + final @NotNull String acl, + final @NotNull String entityId + ) { + this.entityName = entityName; + this.moduleName = moduleName; + this.namespace = namespace; + this.deleteCommandFqn = deleteCommandFqn; + 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 namespace. + * + * @return String + */ + public String getNamespace() { + return namespace; + } + + /** + * Get delete command Fqn. + * + * @return String + */ + public String getDeleteCommandFqn() { + return deleteCommandFqn; + } + + /** + * 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/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 3ad35d238..1a089f1e1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -20,6 +20,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.DbSchemaXmlData; +import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData; import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; @@ -56,6 +57,7 @@ import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.DeleteEntityControllerFileGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; @@ -373,6 +375,7 @@ private void onOK() { generateFormSaveControllerFile(); generateFormUiComponentGenericButtonFile(); generateFormNewActionControllerFile(); + generateFormDeleteControllerFile(); generateUiComponentFormFile(); } @@ -1251,6 +1254,43 @@ private void generateFormNewActionControllerFile() { ), project).generate(ACTION_NAME, false); } + /** + * Generate Delete Controller file. + */ + private void generateFormDeleteControllerFile() { + final NamespaceBuilder namespace = new NamespaceBuilder( + getModuleName(), + NewActionFile.CLASS_NAME, + NewActionFile.getDirectory(getEntityName()) + ); + + new DeleteEntityControllerFileGenerator(new DeleteEntityControllerFileData( + getEntityName(), + getModuleName(), + namespace.getNamespace(), + getDeleteEntityCommandClassFqn(), + getAcl(), + getEntityIdColumn() + ), project).generate(ACTION_NAME, false); + } + + /** + * Get delete entity command class Fqn. + * + * @return String + */ + private String getDeleteEntityCommandClassFqn() { + final NamespaceBuilder namespaceBuilder = + new NamespaceBuilder( + getModuleName(), + "DeleteByIdCommand", //TODO after command added: DeleteEntityCommandFile.CLASS_NAME, + "Command".concat("/" + getEntityName()) //TODO after command added: DeleteEntityCommandFile.getDirectory(getEntityName()) + ); + + return namespaceBuilder.getClassFqn(); + } + + /** * Get save entity command class Fqn. * 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..9748c5fb5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java @@ -0,0 +1,107 @@ +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.DeleteEntityControllerFileData; +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.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile; +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.ArrayList; +import java.util.List; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class DeleteEntityControllerFileGenerator extends FileGenerator { + + private final DeleteEntityControllerFileData fileData; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final DirectoryGenerator directoryGenerator; + private final ModuleIndex moduleIndex; + private final List uses; + + /** + * Delete Entity Controller File Generator. + * @param fileData DeleteEntityControllerFileData + * @param project Project + */ + public DeleteEntityControllerFileGenerator( + final DeleteEntityControllerFileData fileData, + final @NotNull Project project + ) { + super(project); + this.fileData = fileData; + fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + moduleIndex = ModuleIndex.getInstance(project); + directoryGenerator = DirectoryGenerator.getInstance(); + uses = new ArrayList<>(); + } + + /** + * Generate Delete controller. + * + * @param actionName String + * + * @return PsiFile + */ + @Override + public PsiFile generate(final @NotNull String actionName) { + final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( + fileData.getModuleName() + ); + final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( + moduleBaseDir, + DeleteActionFile.getDirectory(fileData.getEntityName()) + ); + + return fileFromTemplateGenerator.generate( + DeleteActionFile.getInstance(), + getAttributes(), + baseDirectory, + actionName + ); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", fileData.getNamespace()); + attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); + attributes.setProperty("CLASS_NAME", DeleteActionFile.CLASS_NAME); + attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); + attributes.setProperty("ENTITY_ID", fileData.getEntityId()); + addProperty(attributes, "DELETE_COMMAND", fileData.getDeleteCommandFqn()); + addProperty(attributes, "CONTEXT", BackendModuleType.CONTEXT.getType()); + addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); + addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()); + addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); + addProperty(attributes, "IMPLEMENTS_POST", HttpMethod.POST.getInterfaceFqn()); + addProperty(attributes, "IMPLEMENTS_GET", HttpMethod.GET.getInterfaceFqn()); + addProperty(attributes, "NO_SUCH_ENTITY_EXCEPTION", + ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()); + addProperty(attributes, "COULD_NOT_DELETE", + ExceptionType.COULD_NOT_DELETE.getType()); + attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); + } + + /** + * Add type to properties. + * + * @param properties Properties + * @param propertyName String + * @param type String + */ + protected void addProperty( + final @NotNull Properties properties, + final String propertyName, + final String type + ) { + uses.add(type); + properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + } +} 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..632b8e09d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java @@ -0,0 +1,54 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files.actions; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; +import org.jetbrains.annotations.NotNull; + +public final class DeleteActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Delete"; + public static final String FILE_EXTENSION = "php"; + public static final String TEMPLATE = "Magento Entity Delete Controller Class"; + private static final String DIRECTORY = "Controller/Adminhtml"; + private static final DeleteActionFile INSTANCE = new DeleteActionFile(); + + /** + * Get singleton instance of the class. + * + * @return Delete + */ + public static DeleteActionFile getInstance() { + return INSTANCE; + } + + /** + * Get Directory path from the module root. + * + * @param entityName String + * + * @return String + */ + public static String getDirectory(final @NotNull String entityName) { + return DIRECTORY.concat("/" + entityName); + } + + @Override + public String getFileName() { + return CLASS_NAME.concat("." + FILE_EXTENSION); + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java index 9e4d426c5..21cbb6a98 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/ExceptionType.java @@ -9,7 +9,9 @@ import org.jetbrains.annotations.NotNull; public enum ExceptionType { - COULD_NOT_SAVE("Magento\\Framework\\Exception\\CouldNotSaveException"); + 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. 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/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..0f68ef428 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.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.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 NAMESPACE = + "Foo\\Bar\\Controller\\Adminhtml\\" + ENTITY_NAME; + private static final String DELETE_COMMAND_FQN = + "Foo\\Bar\\Command\\" + ENTITY_NAME + "\\DeleteByIdCommand"; + 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, + NAMESPACE, + DELETE_COMMAND_FQN, + ACL, + ENTITY_ID + ); + final DeleteEntityControllerFileGenerator deleteEntityControllerFileGenerator = + new DeleteEntityControllerFileGenerator( + deleteEntityControllerFileData, + myFixture.getProject() + ); + final PsiFile DeleteEntityActionFile = + deleteEntityControllerFileGenerator.generate("test"); + final String filePath = this.getFixturePath(DeleteActionFile.getInstance().getFileName()); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + EXPECTED_DIRECTORY, + DeleteEntityActionFile + ); + } +} From b3146e07be1fb6e1bf185d0d5e2a2a52b12bc44f Mon Sep 17 00:00:00 2001 From: "andrii.zinkevych" Date: Thu, 18 Feb 2021 15:41:09 +0200 Subject: [PATCH 53/84] Fixed code by recommendation --- resources/META-INF/plugin.xml | 2 +- ... Model.php.ft => Magento Delete Entity By Id Command.php.ft} | 0 ...el.php.html => Magento Delete Entity By Id Command.php.html} | 0 .../magento/files/commands/DeleteEntityByIdCommandFile.java | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename resources/fileTemplates/internal/{Magento Delete Entity By Id Command Model.php.ft => Magento Delete Entity By Id Command.php.ft} (100%) rename resources/fileTemplates/internal/{Magento Delete Entity By Id Command Model.php.html => Magento Delete Entity By Id Command.php.html} (100%) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 1a92857d8..ab4ea1122 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -238,7 +238,7 @@ - + diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.ft b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft similarity index 100% rename from resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.ft rename to resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.html b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html similarity index 100% rename from resources/fileTemplates/internal/Magento Delete Entity By Id Command Model.php.html rename to resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java index 9021d3272..0cca3f573 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -15,7 +15,7 @@ public class DeleteEntityByIdCommandFile implements ModuleFileInterface { public static final String CLASS_NAME = "DeleteByIdCommand"; public static final String FILE_EXTENSION = "php"; - public static final String TEMPLATE = "Magento Delete Entity By Id Command Model"; + public static final String TEMPLATE = "Magento Delete Entity By Id Command"; private static final String DIRECTORY = "Command"; /** From 79a7744566fa3503246bdc3bf148d00efe982385 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Thu, 11 Mar 2021 14:09:47 +0200 Subject: [PATCH 54/84] Capitalizing the entity name in order to correctly use it for generating all the php classes --- .../actions/generation/dialog/NewEntityDialog.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 6331c507a..43049aa75 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -111,6 +111,7 @@ import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; 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; @@ -275,6 +276,13 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + entityName.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + entityName.setText(StringUtils.capitalize(entityName.getText())); + } + }); + entityName.getDocument().addDocumentListener(new DocumentAdapter() { @SuppressWarnings("PMD.AccessorMethodGeneration") @Override From 59015e0589483b404cdf769ecad42f5d024d9033 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 12 Mar 2021 16:41:05 +0200 Subject: [PATCH 55/84] Entity manager refactoring, main part of code --- .../data/PreferenceDiXmFileData.java | 58 +- .../data/UiComponentFormFileData.java | 71 + .../data/converter/DataObjectConverter.java | 12 + .../newentitydialog/AclXmlDtoConverter.java | 33 + .../CollectionModelDtoConverter.java | 42 + .../DataModelDtoConverter.java | 36 + .../DataModelInterfaceDtoConverter.java | 34 + .../DataProviderDtoConverter.java | 35 + .../DbSchemaXmlDtoConverter.java | 34 + .../EntityDataMapperDtoConverter.java | 36 + .../EntityListActionDtoConverter.java | 36 + .../FormGenericButtonBlockDtoConverter.java | 35 + .../FormLayoutDtoConverter.java | 38 + .../FormSaveControllerDtoConverter.java | 37 + .../FormViewControllerDtoConverter.java | 45 + .../GetListQueryDtoConverter.java | 34 + .../GridActionColumnDtoConverter.java | 35 + .../GridLayoutXmlDtoConverter.java | 37 + .../newentitydialog/MenuXmlDtoConverter.java | 36 + .../newentitydialog/ModelDtoConverter.java | 36 + .../NewControllerDtoConverter.java | 35 + .../NewEntityLayoutDtoConverter.java | 33 + .../PreferenceDiXmlFileDtoConverter.java | 36 + .../ResourceModelDtoConverter.java | 35 + .../RoutesXmlDtoConverter.java | 33 + .../SaveEntityCommandDtoConverter.java | 37 + .../UiComponentFormLayoutDtoConverter.java | 40 + .../UiComponentGridDtoConverter.java | 39 + .../UiComponentGridToolbarDtoConverter.java | 39 + .../generation/data/dialog/DialogData.java | 11 + .../data/dialog/EntityManagerContextData.java | 202 +++ .../data/dialog/GenerationContextData.java | 35 + .../data/dialog/NewEntityDialogData.java | 354 +++++ .../generation/dialog/NewDataModelDialog.java | 43 +- .../generation/dialog/NewEntityDialog.java | 1356 +++++------------ .../generation/dialog/NewModelsDialog.java | 10 +- .../dialog/NewUiComponentGridDialog.java | 16 +- .../OverrideClassByAPreferenceDialog.java | 2 +- .../util/ClassPropertyFormatterUtil.java | 64 + .../AdminListViewEntityActionGenerator.java | 8 +- .../generator/DataModelGenerator.java | 10 +- .../DataModelInterfaceGenerator.java | 6 +- .../generator/ModuleCollectionGenerator.java | 8 +- .../generator/ModuleModelGenerator.java | 10 +- .../ModuleResourceModelGenerator.java | 10 +- .../generator/PreferenceDiXmlGenerator.java | 5 +- .../generation/generator/QueryGenerator.java | 4 +- .../UiComponentDataProviderGenerator.java | 12 +- .../generator/UiComponentFormGenerator.java | 25 +- .../generator/pool/GeneratorHandler.java | 93 ++ .../generator/pool/GeneratorPoolHandler.java | 106 ++ .../pool/GeneratorRunnerValidator.java | 16 + .../pool/handler/AclXmlGeneratorHandler.java | 54 + .../CollectionModelGeneratorHandler.java | 53 + .../handler/DataModelGeneratorHandler.java | 53 + .../DataModelInterfaceGeneratorHandler.java | 53 + .../DataModelPreferenceGeneratorHandler.java | 53 + .../handler/DataProviderGeneratorHandler.java | 54 + .../DbSchemaWhitelistGeneratorHandler.java | 54 + .../handler/DbSchemaXmlGeneratorHandler.java | 54 + .../EntityDataMapperGeneratorHandler.java | 53 + .../EntityListActionGeneratorHandler.java | 53 + ...ormGenericButtonBlockGeneratorHandler.java | 53 + .../handler/FormLayoutGeneratorHandler.java | 53 + .../FormSaveControllerGeneratorHandler.java | 53 + .../FormViewControllerGeneratorHandler.java | 53 + .../handler/GetListQueryGeneratorHandler.java | 53 + .../GridActionColumnGeneratorHandler.java | 53 + .../GridLayoutXmlGeneratorHandler.java | 53 + .../pool/handler/MenuXmlGeneratorHandler.java | 53 + .../pool/handler/ModelGeneratorHandler.java | 53 + .../NewControllerGeneratorHandler.java | 53 + .../NewEntityLayoutGeneratorHandler.java | 53 + .../ResourceModelGeneratorHandler.java | 53 + .../handler/RoutesXmlGeneratorHandler.java | 53 + .../handler/SaveCommandGeneratorHandler.java | 53 + ...UiComponentFormLayoutGeneratorHandler.java | 55 + .../UiComponentGridGeneratorHandler.java | 53 + .../magento/files/AbstractPhpClass.java | 14 +- .../magento/files/CollectionModelFile.java | 55 + .../magento/files/CollectionPhp.java | 20 - .../magento/files/DataModel.java | 34 - .../magento/files/DataModelFile.java | 56 + .../magento/files/DataModelInterface.java | 33 - .../magento/files/DataModelInterfaceFile.java | 55 + .../magento/files/EntityDataMapperFile.java | 17 + .../files/FormGenericButtonBlockFile.java | 19 + .../magento/files/GridActionColumnFile.java | 2 +- .../magento/files/ModelFile.java | 42 + .../magento/files/ModelPhp.java | 21 - .../magento/files/ResourceModelFile.java | 42 + .../magento/files/ResourceModelPhp.java | 21 - ....java => UiComponentDataProviderFile.java} | 37 +- ...ewActionFile.java => IndexActionFile.java} | 22 +- .../magento/files/actions/NewActionFile.java | 20 + .../magento/files/actions/SaveActionFile.java | 20 + .../files/commands/SaveEntityCommandFile.java | 32 +- .../BlockActions.php | 2 +- ...ListViewEntityControllerGeneratorTest.java | 6 +- .../PreferenceDiXmlGeneratorTest.java | 5 +- 100 files changed, 4188 insertions(+), 1264 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/DataObjectConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/AclXmlDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelInterfaceDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataProviderDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DbSchemaXmlDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityDataMapperDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormGenericButtonBlockDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormLayoutDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormSaveControllerDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GetListQueryDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridActionColumnDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GridLayoutXmlDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/MenuXmlDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ModelDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewControllerDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/NewEntityLayoutDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/PreferenceDiXmlFileDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ResourceModelDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/RoutesXmlDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SaveEntityCommandDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentFormLayoutDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridToolbarDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/dialog/DialogData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ClassPropertyFormatterUtil.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorRunnerValidator.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/AclXmlGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/CollectionModelGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelInterfaceGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataModelPreferenceGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DataProviderGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaWhitelistGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DbSchemaXmlGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityDataMapperGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormGenericButtonBlockGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormLayoutGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormSaveControllerGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GetListQueryGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridActionColumnGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/GridLayoutXmlGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/MenuXmlGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ModelGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewControllerGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/NewEntityLayoutGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/ResourceModelGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/RoutesXmlGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SaveCommandGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentFormLayoutGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentGridGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/CollectionPhp.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/DataModel.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/DataModelInterface.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/DataModelInterfaceFile.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModelFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModelPhp.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java delete mode 100644 src/com/magento/idea/magento2plugin/magento/files/ResourceModelPhp.java rename src/com/magento/idea/magento2plugin/magento/files/{UiComponentDataProviderPhp.java => UiComponentDataProviderFile.java} (59%) rename src/com/magento/idea/magento2plugin/magento/files/actions/{AdminListViewActionFile.java => IndexActionFile.java} (70%) 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..53b540a8e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceDiXmFileData.java @@ -4,21 +4,30 @@ */ 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 targetClass; + private final String preferenceFqn; + private final String namespace; + private final String area; + /** + * Preference DI XML file data. + * + * @param preferenceModule String + * @param targetClass String + * @param preferenceFqn String + * @param namespace String + * @param area String + */ public PreferenceDiXmFileData( - String preferenceModule, - PhpClass targetClass, - String preferenceFqn, - String namespace, - String area + final @NotNull String preferenceModule, + final @NotNull String targetClass, + final @NotNull String preferenceFqn, + final @NotNull String namespace, + final @NotNull String area ) { this.preferenceModule = preferenceModule; this.targetClass = targetClass; @@ -27,22 +36,47 @@ public PreferenceDiXmFileData( this.area = area; } + /** + * Get preference module. + * + * @return String + */ public String getPreferenceModule() { return preferenceModule; } - public PhpClass getTargetClass() { + /** + * Get target class. + * + * @return String + */ + public String getTargetClass() { return targetClass; } + /** + * Get preference FQN. + * + * @return String + */ public String getPreferenceFqn() { return preferenceFqn; } + /** + * Get namespace. + * + * @return String + */ public String getNamespace() { return namespace; } + /** + * Get area. + * + * @return String + */ public String getArea() { return area; } 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..10326082d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentFormFileData.java @@ -19,6 +19,8 @@ public class UiComponentFormFileData { private final String submitControllerName; private final String submitActionName; private final String dataProviderFqn; + private final String entityName; + private final String entityId; /** * UI Form data file constructor. @@ -47,6 +49,55 @@ public UiComponentFormFileData( final String submitControllerName, final String submitActionName, final String dataProviderFqn + ) { + this( + formName, + formArea, + moduleName, + label, + buttons, + fieldsets, + fields, + route, + submitControllerName, + submitActionName, + dataProviderFqn, + "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 dataProviderFqn 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 dataProviderFqn, + final String entityName, + final String entityId ) { this.formName = formName; this.formArea = formArea; @@ -59,6 +110,8 @@ public UiComponentFormFileData( this.submitControllerName = submitControllerName; this.submitActionName = submitActionName; this.dataProviderFqn = dataProviderFqn; + this.entityName = entityName; + this.entityId = entityId; } /** @@ -159,4 +212,22 @@ public String getSubmitActionName() { public String getDataProviderFqn() { return dataProviderFqn; } + + /** + * 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/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..01fa69ef0 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public AclXmlDtoConverter( + final @NotNull EntityManagerContextData 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..b634c78b3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.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.CollectionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; +import com.magento.idea.magento2plugin.magento.packages.File; +import org.jetbrains.annotations.NotNull; + +public class CollectionModelDtoConverter extends CollectionData implements DataObjectConverter { + + /** + * Collection model DTO converter. + * + * @param generationContextData EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public CollectionModelDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Collection"), + generationContextData.getCollectionModelNamespaceBuilder().getClassFqn(), + ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + + newEntityDialogData.getEntityName(), + generationContextData.getCollectionModelNamespaceBuilder().getNamespace(), + newEntityDialogData.getEntityName().concat("Resource"), + generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), + generationContextData.getModelNamespaceBuilder().getClassFqn() + ); + } +} 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..f125af2f4 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelDtoConverter.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.DataModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DataModelDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getDtoModelNamespaceBuilder().getNamespace(), + newEntityDialogData.getEntityName().concat("Data"), + generationContextData.getModuleName(), + generationContextData.getDtoModelNamespaceBuilder().getClassFqn(), + generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), + 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..9502d0508 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataModelInterfaceDtoConverter.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.DataModelInterfaceData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DataModelInterfaceDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getDtoInterfaceNamespaceBuilder().getNamespace(), + newEntityDialogData.getEntityName().concat("Interface"), + generationContextData.getModuleName(), + generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), + 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..9ed2a2d36 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DataProviderDtoConverter.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.UiComponentDataProviderData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DataProviderDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName().concat("DataProvider"), + generationContextData.getDataProviderNamespaceBuilder().getNamespace(), + UiComponentDataProviderFile.DIRECTORY, + 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..809f7320a --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DbSchemaXmlDtoConverter( + final @NotNull EntityManagerContextData 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/EntityDataMapperDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityDataMapperDtoConverter.java new file mode 100644 index 000000000..7ed4510a6 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public EntityDataMapperDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + generationContextData.getEntityDataMapperNamespaceBuilder().getNamespace(), + generationContextData.getEntityDataMapperNamespaceBuilder().getClassFqn(), + generationContextData.getModelNamespaceBuilder().getClassFqn(), + generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java new file mode 100644 index 000000000..c0dad3fd9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.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.AdminListViewEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import org.jetbrains.annotations.NotNull; + +public class EntityListActionDtoConverter extends AdminListViewEntityActionData + implements DataObjectConverter { + + /** + * Entity list action converter. + * + * @param generationContextData EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public EntityListActionDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + generationContextData.getEntityListActionNamespaceBuilder().getNamespace(), + generationContextData.getEntityListActionNamespaceBuilder().getClassFqn(), + 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..984e9dd85 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormGenericButtonBlockDtoConverter.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.FormGenericButtonBlockData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormGenericButtonBlockDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.getIdFieldName(), + generationContextData.getGenericButtonBlockNamespaceBuilder().getClassFqn(), + generationContextData.getGenericButtonBlockNamespaceBuilder().getNamespace() + ); + } +} 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..e3216bbbf --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormLayoutDtoConverter( + final @NotNull EntityManagerContextData 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..bb63cc77a --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormSaveControllerDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + generationContextData.getSaveControllerNamespaceBuilder().getNamespace(), + generationContextData.getSaveEntityCommandNamespaceBuilder().getClassFqn(), + generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn(), + newEntityDialogData.getAclId(), + newEntityDialogData.getIdFieldName() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java new file mode 100644 index 000000000..ebbfa39f6 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java @@ -0,0 +1,45 @@ +/* + * 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.ControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; +import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; +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 org.jetbrains.annotations.NotNull; + +public class FormViewControllerDtoConverter extends ControllerFileData + implements DataObjectConverter { + + private static final String VIEW_ACTION_NAME = "Edit"; + + /** + * Form view controller converter. + * + * @param generationContextData EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormViewControllerDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + ControllerBackendPhp.DEFAULT_DIR + File.separator + + newEntityDialogData.getEntityName(), + VIEW_ACTION_NAME, + generationContextData.getModuleName(), + Areas.adminhtml.toString(), + HttpMethod.GET.toString(), + newEntityDialogData.getAclId(), + true, + generationContextData.getFormViewNamespaceBuilder().getNamespace() + ); + } +} 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..e03c45d23 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GetListQueryDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + generationContextData.getCollectionModelNamespaceBuilder().getClassFqn(), + generationContextData.getEntityDataMapperNamespaceBuilder().getClassFqn() + ); + } +} 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..b5555782c --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GridActionColumnDtoConverter( + final @NotNull EntityManagerContextData 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..2f7700ff1 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public GridLayoutXmlDtoConverter( + final @NotNull EntityManagerContextData 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/MenuXmlDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/MenuXmlDtoConverter.java new file mode 100644 index 000000000..703876e71 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public MenuXmlDtoConverter( + final @NotNull EntityManagerContextData 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..bc94e33e3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ModelDtoConverter.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.ModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public ModelDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource"), + generationContextData.getModelNamespaceBuilder().getClassFqn(), + generationContextData.getModelNamespaceBuilder().getNamespace(), + generationContextData.getResourceModelNamespaceBuilder().getClassFqn() + ); + } +} 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..7974f3ce0 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public NewControllerDtoConverter( + final @NotNull EntityManagerContextData 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..30a1baeeb --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public NewEntityLayoutDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + 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..7264ec6f1 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public PreferenceDiXmlFileDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), + generationContextData.getDtoModelNamespaceBuilder().getClassFqn(), + newEntityDialogData.getEntityName().concat("Model"), + 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..0a80dd08f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/ResourceModelDtoConverter.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.ResourceModelData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public ResourceModelDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getTableName(), + newEntityDialogData.getEntityName().concat("Resource"), + newEntityDialogData.getIdFieldName(), + generationContextData.getResourceModelNamespaceBuilder().getNamespace(), + generationContextData.getResourceModelNamespaceBuilder().getClassFqn() + ); + } +} 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..be6306507 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public RoutesXmlDtoConverter( + final @NotNull EntityManagerContextData 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..dc91a5de0 --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public SaveEntityCommandDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + generationContextData.getSaveEntityCommandNamespaceBuilder().getNamespace(), + generationContextData.getSaveEntityCommandNamespaceBuilder().getClassFqn(), + generationContextData.getModelNamespaceBuilder().getClassFqn(), + generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), + generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn() + ); + } +} 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..599c551a3 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentFormLayoutDtoConverter.java @@ -0,0 +1,40 @@ +/* + * 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.EntityManagerContextData; +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 UiComponentFormLayoutDtoConverter extends UiComponentFormFileData + implements DataObjectConverter { + + private final static String SUBMIT_ACTION_NAME = "Save"; + + public UiComponentFormLayoutDtoConverter( + final @NotNull EntityManagerContextData 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, + generationContextData.getDataProviderNamespaceBuilder().getClassFqn(), + 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..d36421ee0 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/UiComponentGridDtoConverter.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.UiComponentGridData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 UiComponentGridDtoConverter extends UiComponentGridData + implements DataObjectConverter { + + /** + * Ui component grid DTO converter. + * + * @param generationContextData EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public UiComponentGridDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + Areas.adminhtml.toString(), + newEntityDialogData.getGridName(), + generationContextData.getDataProviderNamespaceBuilder().getClassFqn(), + newEntityDialogData.getIdFieldName(), + newEntityDialogData.getAclId(), + 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..e354ab52c --- /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.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.UnusedFormalParameter") + public UiComponentGridToolbarDtoConverter( + final @NotNull EntityManagerContextData 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/EntityManagerContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java new file mode 100644 index 000000000..bf1b250b1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java @@ -0,0 +1,202 @@ +/* + * 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 org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; + +public class EntityManagerContextData implements GenerationContextData { + + private final Project project; + private final String moduleName; + private final String actionName; + private final String indexViewAction; + private final String editViewAction; + private final String newViewAction; + private final String deleteAction; + private final NamespaceBuilder modelNamespaceBuilder; + private final NamespaceBuilder resourceModelNamespaceBuilder; + private final NamespaceBuilder collectionModelNamespaceBuilder; + private final NamespaceBuilder dtoModelNamespaceBuilder; + private final NamespaceBuilder dtoInterfaceNamespaceBuilder; + private final NamespaceBuilder finalDtoTypeNamespaceBuilder; + private final NamespaceBuilder dataProviderNamespaceBuilder; + private final NamespaceBuilder entityListActionNamespaceBuilder; + private final NamespaceBuilder entityDataMapperNamespaceBuilder; + private final NamespaceBuilder saveEntityCommandNamespaceBuilder; + private final NamespaceBuilder formViewNamespaceBuilder; + private final NamespaceBuilder newControllerNamespaceBuilder; + private final NamespaceBuilder saveControllerNamespaceBuilder; + private final NamespaceBuilder genericButtonBlockNamespaceBuilder; + private final List> entityProps; + private final List buttons; + private final List fieldsetData; + private final List fieldsData; + + public EntityManagerContextData( + final @NotNull Project project, + final @NotNull String moduleName, + final @NotNull String actionName, + final @NotNull String indexViewAction, + final @NotNull String editViewAction, + final @NotNull String newViewAction, + final @NotNull String deleteAction, + final @NotNull NamespaceBuilder modelNamespaceBuilder, + final @NotNull NamespaceBuilder resourceModelNamespaceBuilder, + final @NotNull NamespaceBuilder collectionModelNamespaceBuilder, + final @NotNull NamespaceBuilder dtoModelNamespaceBuilder, + final @NotNull NamespaceBuilder dtoInterfaceNamespaceBuilder, + final @NotNull NamespaceBuilder finalDtoTypeNamespaceBuilder, + final @NotNull NamespaceBuilder dataProviderNamespaceBuilder, + final @NotNull NamespaceBuilder entityListActionNamespaceBuilder, + final @NotNull NamespaceBuilder entityDataMapperNamespaceBuilder, + final @NotNull NamespaceBuilder saveEntityCommandNamespaceBuilder, + final @NotNull NamespaceBuilder formViewNamespaceBuilder, + final @NotNull NamespaceBuilder newControllerNamespaceBuilder, + final @NotNull NamespaceBuilder saveControllerNamespaceBuilder, + final @NotNull NamespaceBuilder genericButtonBlockNamespaceBuilder, + 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.indexViewAction = indexViewAction; + this.editViewAction = editViewAction; + this.newViewAction = newViewAction; + this.deleteAction = deleteAction; + this.modelNamespaceBuilder = modelNamespaceBuilder; + this.resourceModelNamespaceBuilder = resourceModelNamespaceBuilder; + this.dtoModelNamespaceBuilder = dtoModelNamespaceBuilder; + this.dtoInterfaceNamespaceBuilder = dtoInterfaceNamespaceBuilder; + this.collectionModelNamespaceBuilder = collectionModelNamespaceBuilder; + this.finalDtoTypeNamespaceBuilder = finalDtoTypeNamespaceBuilder; + this.dataProviderNamespaceBuilder = dataProviderNamespaceBuilder; + this.entityListActionNamespaceBuilder = entityListActionNamespaceBuilder; + this.entityDataMapperNamespaceBuilder = entityDataMapperNamespaceBuilder; + this.saveEntityCommandNamespaceBuilder = saveEntityCommandNamespaceBuilder; + this.formViewNamespaceBuilder = formViewNamespaceBuilder; + this.newControllerNamespaceBuilder = newControllerNamespaceBuilder; + this.saveControllerNamespaceBuilder = saveControllerNamespaceBuilder; + this.genericButtonBlockNamespaceBuilder = genericButtonBlockNamespaceBuilder; + 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; + } + + public String getIndexViewAction() { + return indexViewAction; + } + + public String getEditViewAction() { + return editViewAction; + } + + public String getNewViewAction() { + return newViewAction; + } + + public String getDeleteAction() { + return deleteAction; + } + + public NamespaceBuilder getModelNamespaceBuilder() { + return modelNamespaceBuilder; + } + + public NamespaceBuilder getResourceModelNamespaceBuilder() { + return resourceModelNamespaceBuilder; + } + + public NamespaceBuilder getCollectionModelNamespaceBuilder() { + return collectionModelNamespaceBuilder; + } + + public NamespaceBuilder getDtoModelNamespaceBuilder() { + return dtoModelNamespaceBuilder; + } + + public NamespaceBuilder getDtoInterfaceNamespaceBuilder() { + return dtoInterfaceNamespaceBuilder; + } + + public NamespaceBuilder getFinalDtoTypeNamespaceBuilder() { + return finalDtoTypeNamespaceBuilder; + } + + public NamespaceBuilder getDataProviderNamespaceBuilder() { + return dataProviderNamespaceBuilder; + } + + public NamespaceBuilder getEntityListActionNamespaceBuilder() { + return entityListActionNamespaceBuilder; + } + + public NamespaceBuilder getEntityDataMapperNamespaceBuilder() { + return entityDataMapperNamespaceBuilder; + } + + public NamespaceBuilder getSaveEntityCommandNamespaceBuilder() { + return saveEntityCommandNamespaceBuilder; + } + + public NamespaceBuilder getFormViewNamespaceBuilder() { + return formViewNamespaceBuilder; + } + + public NamespaceBuilder getNewControllerNamespaceBuilder() { + return newControllerNamespaceBuilder; + } + + public NamespaceBuilder getSaveControllerNamespaceBuilder() { + return saveControllerNamespaceBuilder; + } + + public NamespaceBuilder getGenericButtonBlockNamespaceBuilder() { + return genericButtonBlockNamespaceBuilder; + } + + public List> getEntityProps() { + return entityProps; + } + + public List getButtons() { + return buttons; + } + + public List getFieldsetData() { + return fieldsetData; + } + + 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..064e32caf --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.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.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(); +} 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..84dc1939d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java @@ -0,0 +1,354 @@ +/* + * 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; + +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 hasAdminUiComponents; + private final boolean hasDtoInterface; + + // Admin UI Components tab data. + private final String route; + private final String formLabel; + private final String formName; + private final String gridName; + private final boolean hasToolbar; + private final boolean hasToolbarBookmarks; + private final boolean hasToolbarColumnsControl; + private final boolean hasToolbarListingFilters; + private final boolean hasToolbarListingPaging; + private final boolean hasToolbarFullTextSearch; + + // 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.hasAdminUiComponents = hasAdminUiComponents; + this.hasDtoInterface = hasDtoInterface; + this.route = route; + this.formLabel = formLabel; + this.formName = formName; + this.gridName = gridName; + this.hasToolbar = hasToolbar; + this.hasToolbarBookmarks = hasToolbarBookmarks; + this.hasToolbarColumnsControl = hasToolbarColumnsControl; + this.hasToolbarListingFilters = hasToolbarListingFilters; + this.hasToolbarListingPaging = hasToolbarListingPaging; + this.hasToolbarFullTextSearch = 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 hasAdminUiComponents; + } + + /** + * Check if has dto interface. + * + * @return boolean + */ + public boolean hasDtoInterface() { + return hasDtoInterface; + } + + /** + * 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 hasToolbar; + } + + /** + * Check if has toolbar bookmarks. + * + * @return boolean + */ + public boolean hasToolbarBookmarks() { + return hasToolbarBookmarks; + } + + /** + * Check if has toolbar columns control. + * + * @return boolean + */ + public boolean hasToolbarColumnsControl() { + return hasToolbarColumnsControl; + } + + /** + * Check if has toolbar listing filters. + * + * @return boolean + */ + public boolean hasToolbarListingFilters() { + return hasToolbarListingFilters; + } + + /** + * Check if has toolbar listing paging. + * + * @return boolean + */ + public boolean hasToolbarListingPaging() { + return hasToolbarListingPaging; + } + + /** + * Check if has toolbar fulltext search. + * + * @return boolean + */ + public boolean hasToolbarFullTextSearch() { + return hasToolbarFullTextSearch; + } + + /** + * 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/NewDataModelDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 8bb0c189a..89a68299f 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; @@ -25,8 +24,8 @@ 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; @@ -50,7 +49,6 @@ import javax.swing.KeyStroke; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; -import org.apache.commons.lang.StringUtils; @SuppressWarnings({ "PMD.ExcessiveImports", @@ -198,7 +196,7 @@ private void generateModelInterfaceFile() { getInterfaceName(), getModuleName(), getInterfaceFQN(), - getProperties() + ClassPropertyFormatterUtil.joinProperties(properties) )).generate(NewDataModelAction.ACTION_NAME, true); } @@ -209,7 +207,7 @@ private void generateModelFile() { getModuleName(), getModelFQN(), getInterfaceFQN(), - getProperties(), + ClassPropertyFormatterUtil.joinProperties(properties), isInterfaceShouldBeCreated() )).generate(NewDataModelAction.ACTION_NAME, true); } @@ -217,7 +215,7 @@ private void generateModelFile() { private void generatePreference() { new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getModuleName(), - GetPhpClassByFQN.getInstance(project).execute(getInterfaceFQN()), + getInterfaceFQN(), getModelFQN(), getModelNamespace(), "base" @@ -226,10 +224,10 @@ private void generatePreference() { private void buildNamespaces() { interfaceNamespace = new NamespaceBuilder( - getModuleName(), getInterfaceName(), DataModelInterface.DIRECTORY + getModuleName(), getInterfaceName(), DataModelInterfaceFile.DIRECTORY ); modelNamespace = new NamespaceBuilder( - getModuleName(), getModelName(), DataModel.DIRECTORY + getModuleName(), getModelName(), DataModelFile.DIRECTORY ); } @@ -237,22 +235,7 @@ private void buildNamespaces() { * Formats properties into an array of ClassPropertyData objects. */ 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()); - } + properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); } private boolean isInterfaceShouldBeCreated() { @@ -287,14 +270,6 @@ private String getModelFQN() { return modelNamespace.getClassFqn(); } - /** - * Gets properties as a string, ready for templating. - * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". - */ - private String getProperties() { - return StringUtils.join(properties, ","); - } - private void initPropertiesTable() { final DefaultTableModel propertiesTable = getPropertiesTable(); propertiesTable.setDataVector( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 3ad35d238..a6b6c1a4b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -5,44 +5,43 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; -import com.google.common.base.CaseFormat; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; 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.OverrideClassByAPreferenceAction; -import com.magento.idea.magento2plugin.actions.generation.data.AclXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; -import com.magento.idea.magento2plugin.actions.generation.data.CollectionData; -import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; -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.DbSchemaXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData; -import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData; -import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData; -import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData; -import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.MenuXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.ModelData; -import com.magento.idea.magento2plugin.actions.generation.data.NewActionEntityControllerFileData; -import com.magento.idea.magento2plugin.actions.generation.data.NewEntityLayoutData; -import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; -import com.magento.idea.magento2plugin.actions.generation.data.ResourceModelData; -import com.magento.idea.magento2plugin.actions.generation.data.RoutesXmlData; -import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityCommandData; -import com.magento.idea.magento2plugin.actions.generation.data.SaveEntityControllerFileData; -import com.magento.idea.magento2plugin.actions.generation.data.UiComponentDataProviderData; +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.EntityDataMapperDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.EntityListActionDtoConverter; +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.FormViewControllerDtoConverter; +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.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.UiComponentFormLayoutDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.UiComponentGridDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; 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.UiComponentFormFileData; -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.data.code.ClassPropertyData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.SaveEntityCommandDtoConverter; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; +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.AclResourceIdRule; @@ -50,49 +49,50 @@ 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.generator.AclXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator; -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.DbSchemaWhitelistJsonGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.MenuXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.ModuleCollectionGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; -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.NewActionEntityControllerFileGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.NewEntityLayoutGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.RoutesXmlGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityCommandGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.SaveEntityControllerFileGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentDataProviderGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentFormGenerator; -import com.magento.idea.magento2plugin.actions.generation.generator.UiComponentGridXmlGenerator; +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.EntityDataMapperGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.EntityListActionGeneratorHandler; +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.FormViewControllerGeneratorHandler; +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.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 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.CollectionModelFile; import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp; -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.files.EntityDataMapperFile; import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; -import com.magento.idea.magento2plugin.magento.files.ModelPhp; +import com.magento.idea.magento2plugin.magento.files.ModelFile; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; -import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp; -import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp; -import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; 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.Areas; import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.HttpMethod; 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; @@ -102,7 +102,6 @@ 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.GetPhpClassByFQN; import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; @@ -132,23 +131,16 @@ 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.MissingSerialVersionUID", - "PMD.DataClass", "PMD.UnusedPrivateField", - "PMD.ExcessiveImports", - "PMD.GodClass", - "PMD.TooManyMethods", - "PMD.CyclomaticComplexity", - "PMD.ExcessiveClassLength" + "PMD.CouplingBetweenObjects", + "PMD.ExcessiveImports" }) public class NewEntityDialog extends AbstractDialog { - @NotNull - private final Project project; + private final @NotNull Project project; private final String moduleName; private JPanel contentPane; private JTabbedPane tabbedPane1; @@ -185,9 +177,9 @@ public class NewEntityDialog extends AbstractDialog { private JCheckBox addFullTextSearchCheckBox; private JCheckBox addListingFiltersCheckBox; private JCheckBox addListingPagingCheckBox; - private JComboBox tableEngine; + private JComboBox tableEngine; private JLabel tableEngineLabel; - private JComboBox tableResource; + private JComboBox tableResource; private JLabel tableResourceLabel; private JCheckBox createInterface; private final List properties; @@ -203,6 +195,13 @@ public class NewEntityDialog extends AbstractDialog { private static final String SORT_ORDER = "Sort Order"; private static final String UI_COMPONENTS_TAB_NAME = "Admin UI Components"; + 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"; + @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME}) @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) private JTextField formName; @@ -222,6 +221,7 @@ public class NewEntityDialog extends AbstractDialog { @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; @@ -236,7 +236,7 @@ public class NewEntityDialog extends AbstractDialog { * @param project Project * @param directory PsiDirectory */ - public NewEntityDialog(final Project project, final PsiDirectory directory) { + public NewEntityDialog(final @NotNull Project project, final PsiDirectory directory) { super(); this.project = project; @@ -331,340 +331,221 @@ private void initPropertiesTable() { entityPropertiesTableGroupWrapper.initTableGroup(); } - private DefaultTableModel getPropertiesTable() { - return (DefaultTableModel) propertyTable.getModel(); - } - /** * Perform code generation using input data. */ + @SuppressWarnings("PMD.ExcessiveMethodLength") private void onOK() { if (!validateFormFields()) { return; } - - generateModelFile(); - generateResourceModelFile(); - generateCollectionFile(); formatProperties(); - generateDataModelFile(); - if (createInterface.isSelected()) { - generateDataModelInterfaceFile(); - generateDataModelPreference(); - } + final NewEntityDialogData dialogData = getNewEntityDialogData(); + final EntityManagerContextData context = getEntityManagerContextData(dialogData); - generateRoutesXmlFile(); - generateAclXmlFile(); - generateMenuFile(); + final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(context); - if (createUiComponent.isSelected()) { - generateGridViewControllerFile(); - generateGridLayoutFile(); - generateEntityDataMapperFile(); - generateModelGetListQueryFile(); - generateDataProviderFile(); - generateUiComponentGridActionColumnFile(); - generateUiComponentGridFile(); - generateFormViewControllerFile(); - generateFormLayoutFile(); - generateNewEntityLayoutFile(); - generateSaveEntityCommandFile(); - generateFormSaveControllerFile(); - generateFormUiComponentGenericButtonFile(); - generateFormNewActionControllerFile(); - generateUiComponentFormFile(); - } + 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) + ) + .addNext( + AclXmlGeneratorHandler.class, + new AclXmlDtoConverter(context, dialogData) + ) + .addNext( + MenuXmlGeneratorHandler.class, + new MenuXmlDtoConverter(context, dialogData) + ) + .addNext( + EntityListActionGeneratorHandler.class, + new EntityListActionDtoConverter(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( + FormViewControllerGeneratorHandler.class, + new FormViewControllerDtoConverter(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( + FormSaveControllerGeneratorHandler.class, + new FormSaveControllerDtoConverter(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) + ); - final DbSchemaXmlData dbSchemaXmlData = new DbSchemaXmlData( - getDbTableName(), - getTableResource(), - getTableEngine(), - getEntityName(), - getEntityProperties() - ); + generatorPoolHandler.run(); - generateDbSchemaXmlFile(dbSchemaXmlData); - generateWhitelistJsonFile(dbSchemaXmlData); this.setVisible(false); } - private PsiFile generateModelFile() { - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - final String resourceModelName = getResourceModelName(); - - - return new ModuleModelGenerator(new ModelData( - getModuleName(), - getDbTableName(), - getModelName(), - resourceModelName, - modelNamespace.getClassFqn(), - modelNamespace.getNamespace(), - resourceModelNamespace.getClassFqn() - ), project).generate(ACTION_NAME, true); - } - - /** - * Get Magento 2 model namespace builder for the entity. - * - * @return NamespaceBuilder - */ - private NamespaceBuilder getModelNamespace() { - return new NamespaceBuilder(getModuleName(), getModelName(), ModelPhp.MODEL_DIRECTORY); - } - /** - * Get DTO model namespace builder for the entity. + * Get entity manager context data. * - * @return NamespaceBuilder - */ - private NamespaceBuilder getDataModelNamespace() { - return new NamespaceBuilder(getModuleName(), getDataModelName(), DataModel.DIRECTORY); - } - - /** - * Get DTO model interface namespace builder for the entity. + * @param dialogData NewEntityDialogData * - * @return NamespaceBuilder - */ - private NamespaceBuilder getDataModelInterfaceNamespace() { - return new NamespaceBuilder( - getModuleName(), - getDataModelInterfaceName(), - DataModelInterface.DIRECTORY - ); - } + * @return EntityManagerContextData + */ + private EntityManagerContextData getEntityManagerContextData( + final @NotNull NewEntityDialogData dialogData + ) { + final String entityName = dialogData.getEntityName(); + final String modelClassName = entityName.concat(MODEL_SUFFIX); + final String resourceClassName = entityName.concat(RESOURCE_MODEL_SUFFIX); + final String collectionClassName = entityName.concat(COLLECTION_MODEL_SUFFIX); + final String dataProviderClassName = entityName.concat(DATA_PROVIDER_SUFFIX); + 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(dtoClassName).getNamespaceBuilder(moduleName); + final NamespaceBuilder dtoInterfaceNamespace = + new DataModelInterfaceFile(dtoInterfaceClassName).getNamespaceBuilder(moduleName); + + final NamespaceBuilder formViewNamespaceBuilder = + new NamespaceBuilder( + moduleName, + "Edit", + ControllerBackendPhp.DEFAULT_DIR + File.separator + entityName + ); - /** - * Get Magento 2 Resource model namespace builder for the entity. - * - * @return NamespaceBuilder - */ - private NamespaceBuilder getResourceModelNamespace() { - return new NamespaceBuilder( - getModuleName(), - getResourceModelName(), - ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + return new EntityManagerContextData( + project, + moduleName, + ACTION_NAME, + actionsPathPrefix.concat("index"), + actionsPathPrefix.concat("edit"), + actionsPathPrefix.concat("new"), + actionsPathPrefix.concat("delete"), + new ModelFile(modelClassName).getNamespaceBuilder(moduleName), + new ResourceModelFile(resourceClassName).getNamespaceBuilder(moduleName), + new CollectionModelFile(collectionClassName) + .getNamespaceBuilder(moduleName, entityName), + dtoModelNamespace, + dtoInterfaceNamespace, + createInterface.isSelected() ? dtoInterfaceNamespace : dtoModelNamespace, + UiComponentDataProviderFile + .getInstance(dataProviderClassName).getNamespaceBuilder(moduleName), + new IndexActionFile(entityName).getNamespaceBuilder(moduleName), + new EntityDataMapperFile(entityName).getNamespaceBuilder(moduleName), + SaveEntityCommandFile.getNamespaceBuilder(moduleName, entityName), + formViewNamespaceBuilder, + NewActionFile.getNamespaceBuilder(moduleName, entityName), + SaveActionFile.getNamespaceBuilder(moduleName, entityName), + FormGenericButtonBlockFile.getNamespaceBuilder(moduleName), + getEntityProperties(), + getButtons(), + getFieldSets(), + getFields() ); } - /** - * Generate preference for data model. - */ - private void generateDataModelPreference() { - final NamespaceBuilder dataModelNamespace = getDataModelNamespace(); - final NamespaceBuilder modelInterfaceNamespace = getDataModelInterfaceNamespace(); - new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( - getModuleName(), - GetPhpClassByFQN.getInstance(project).execute( - modelInterfaceNamespace.getClassFqn() - ), - dataModelNamespace.getClassFqn(), - getModelName(), - Areas.base.toString() - ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); - } - - private String getModuleName() { - return moduleName; - } - - private String getEntityName() { - return entityName.getText().trim(); - } - - private String getModelName() { - return getEntityName().concat("Model"); - } - - private String getDataModelName() { - return getEntityName().concat("Data"); - } - - /** - * Get data provider class name. - * - * @return String - */ - private String getDataProviderClassName() { - return getEntityName().concat("DataProvider"); - } - - private String getDataModelInterfaceName() { - return getEntityName().concat("Interface"); - } - - private String getResourceModelName() { - return getEntityName().concat("Resource"); - } - - private String getCollectionName() { - return getEntityName().concat("Collection"); - } - - private String getDbTableName() { - return dbTableName.getText().trim(); - } - - private PsiFile generateResourceModelFile() { - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - return new ModuleResourceModelGenerator(new ResourceModelData( - getModuleName(), - getDbTableName(), - getResourceModelName(), - getEntityIdColumn(), - resourceModelNamespace.getNamespace(), - resourceModelNamespace.getClassFqn() - ), project).generate(ACTION_NAME, true); - } - - /** - * Get entity id column name. - * - * @return String - */ - private String getEntityIdColumn() { - return entityId.getText().trim(); - } - - private PsiFile generateCollectionFile() { - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder collectionNamespace = getCollectionNamespace(); - final StringBuilder modelFqn = new StringBuilder(modelNamespace.getClassFqn()); - final String modelName = getModelName(); - final StringBuilder resourceModelFqn - = new StringBuilder(resourceModelNamespace.getClassFqn()); - final String resourceModelName = getResourceModelName(); - - - return new ModuleCollectionGenerator(new CollectionData( - getModuleName(), - getDbTableName(), - modelName, - getCollectionName(), - collectionNamespace.getClassFqn(), - getCollectionDirectory(), - collectionNamespace.getNamespace(), - resourceModelName, - resourceModelFqn.toString(), - modelFqn.toString() - ), project).generate(ACTION_NAME, true); - } - - /** - * Generate Data Model File. - */ - private void generateDataModelFile() { - final NamespaceBuilder nameSpaceBuilder = getDataModelNamespace(); - new DataModelGenerator(project, new DataModelData( - getDataModelNamespace().getNamespace(), - getDataModelName(), - getModuleName(), - nameSpaceBuilder.getClassFqn(), - getDataModelInterfaceNamespace().getClassFqn(), - getProperties(), - createInterface.isSelected() - )).generate(ACTION_NAME, true); - } - - private void generateDataModelInterfaceFile() { - final NamespaceBuilder nameSpaceBuilder = getDataModelInterfaceNamespace(); - new DataModelInterfaceGenerator(project, new DataModelInterfaceData( - nameSpaceBuilder.getNamespace(), - getDataModelInterfaceName(), - getModuleName(), - nameSpaceBuilder.getClassFqn(), - getProperties() - )).generate(ACTION_NAME, true); - } - - /** - * Gets properties as a string, ready for templating. - * "UPPER_SNAKE;lower_snake;type;UpperCamel;lowerCamel". - */ - private String getProperties() { - return StringUtils.join(properties, ","); - } - /** * Formats properties into an array of ClassPropertyData objects. */ private void formatProperties() { - final DefaultTableModel propertiesTable = getPropertiesTable(); - final int rowCount = propertiesTable.getRowCount(); - String name; - String type; - - name = getEntityIdColumn(); - type = "int"; - 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()); - - 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 NamespaceBuilder getCollectionNamespace() { - return new NamespaceBuilder( - getModuleName(), - getCollectionName(), - getCollectionDirectory() - ); - } - - private String getCollectionDirectory() { - return ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + File.separator - + getEntityName(); - } - - private PsiFile generateRoutesXmlFile() { - return new RoutesXmlGenerator(new RoutesXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName() - ), project).generate(ACTION_NAME, false); - } - - public String getRoute() { - return route.getText().trim(); - } - - private String getViewActionName() { - return "Edit"; - } - - private String getSubmitActionName() { - return "Save";//NOPMD - } - - private String getControllerDirectory() { - return ControllerBackendPhp.DEFAULT_DIR + File.separator; - } + final String name = getEntityIdColumn(); + final String type = "int"; - /** - * Get Acl id. - * - * @return String - */ - public String getAcl() { - return acl.getText().trim(); + properties.add(ClassPropertyFormatterUtil.formatSingleProperty(name, type)); + properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); } /** @@ -676,46 +557,21 @@ public String getFormName() { return formName.getText().trim(); } - private PsiFile generateAclXmlFile() { - return new AclXmlGenerator(new AclXmlData( - getParentAcl(), - getAcl(), - getAclTitle() - ), getModuleName(), project).generate(ACTION_NAME, false); - } - - public String getParentAcl() { - return parentAcl.getSelectedItem().toString().trim(); - } - - public String getAclTitle() { - return aclTitle.getText().trim(); - } - - public String getFormLabel() { - return formLabel.getText().trim(); - } - /** - * Returns form fieldsets. + * Returns form fieldSets. * * @return List[UiComponentFormFieldsetData] */ - public List getFieldsets() { - - final ArrayList fieldsets = - new ArrayList<>(); + public List getFieldSets() { + final ArrayList fieldSets = new ArrayList<>(); final UiComponentFormFieldsetData fieldsetData = new UiComponentFormFieldsetData( "general", "General", "10" ); + fieldSets.add(fieldsetData); - fieldsets.add( - fieldsetData - ); - - return fieldsets; + return fieldSets; } /** @@ -728,14 +584,14 @@ protected List getButtons() { final String directory = "Block/Form"; final NamespaceBuilder namespaceBuilderSave = new NamespaceBuilder( - getModuleName(), + moduleName, "Save", directory ); buttons.add(new UiComponentFormButtonData( directory, "Save", - getModuleName(), + moduleName, "Save", namespaceBuilderSave.getNamespace(), "Save Entity", @@ -745,14 +601,14 @@ protected List getButtons() { )); final NamespaceBuilder namespaceBuilderBack = new NamespaceBuilder( - getModuleName(), + moduleName, "Back", directory ); buttons.add(new UiComponentFormButtonData( directory, "Back", - getModuleName(), + moduleName, "Back", namespaceBuilderBack.getNamespace(), "Back To Grid", @@ -762,14 +618,14 @@ protected List getButtons() { )); final NamespaceBuilder namespaceBuilderDelete = new NamespaceBuilder( - getModuleName(), + moduleName, "Delete", directory ); buttons.add(new UiComponentFormButtonData( directory, "Delete", - getModuleName(), + moduleName, "Delete", namespaceBuilderDelete.getNamespace(), "Delete Entity", @@ -840,632 +696,164 @@ public List getFields() { @SuppressWarnings({"PMD.UnusedPrivateMethod"}) private void createUIComponents() { - this.parentAcl = new FilteredComboBox(getAclResourcesList()); - this.parentMenu = new FilteredComboBox(getMenuReferences()); + 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 (getAclResourcesList().contains(ModuleMenuXml.defaultAcl)) { + if (aclResourcesList.contains(ModuleMenuXml.defaultAcl)) { parentAcl.setSelectedItem(ModuleMenuXml.defaultAcl); } } - private List getAclResourcesList() { - return GetAclResourcesListUtil.execute(project); - } - - /** - * Generate Grid view controller file. - */ - private void generateGridViewControllerFile() { - final AdminListViewActionFile indexFile = new AdminListViewActionFile(getEntityName()); - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - AdminListViewActionFile.CLASS_NAME, - indexFile.getDirectory() - ); - final AdminListViewEntityActionData data = new AdminListViewEntityActionData( - getModuleName(), - getEntityName(), - namespace.getNamespace(), - namespace.getClassFqn(), - getAcl(), - getMenuIdentifier() - ); - new AdminListViewEntityActionGenerator(data, project).generate(ACTION_NAME, false); - } - /** - * Generate grid layout file. - */ - private void generateGridLayoutFile() { - new LayoutXmlGenerator(new LayoutXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName(), - getEntityName(), - AdminListViewActionFile.CLASS_NAME, - getGridName() - ), project).generate(ACTION_NAME, false); - } - - /** - * Get grid name. + * Get entity properties table columns data and format to suitable for generator. * - * @return String - */ - private String getGridName() { - return gridName.getText(); - } - - /** - * Generate entity data mapper type. - */ - private void generateEntityDataMapperFile() { - final EntityDataMapperFile entityDataMapperFile = - new EntityDataMapperFile(getEntityName()); - - final String namespace = entityDataMapperFile.getNamespace(getModuleName()); - final String classFqn = entityDataMapperFile.getClassFqn(getModuleName()); - - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); - final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); - - final String dtoType; - - if (createInterface.isSelected()) { - dtoType = dtoInterfaceModelNamespace.getClassFqn(); - } else { - dtoType = dtoModelNamespace.getClassFqn(); - } - - new EntityDataMapperGenerator( - new EntityDataMapperData( - getModuleName(), - getEntityName(), - namespace, - classFqn, - modelNamespace.getClassFqn(), - dtoType - ), - project - ).generate(ACTION_NAME, false); - } - - /** - * Run GetListQuery.php file generator. + * @return List of entity properties stored in HashMap. */ - private void generateModelGetListQueryFile() { - final String entityCollectionType = getCollectionNamespace().getClassFqn(); - - new GetListQueryModelGenerator( - new GetListQueryModelData( - getModuleName(), - getEntityName(), - entityCollectionType, - getEntityDataMapperType() - ), - project - ).generate(ACTION_NAME, true); - } + private List> getEntityProperties() { + final List> shortColumnsData = + entityPropertiesTableGroupWrapper.getColumnsData(); - /** - * Get entity data mapper type. - * - * @return String - */ - private String getEntityDataMapperType() { - final EntityDataMapperFile entityDataMapperFile = - new EntityDataMapperFile(getEntityName()); + final List> columnsData = + DbSchemaGeneratorUtil.complementShortPropertiesByDefaults(shortColumnsData); + columnsData.add(0, DbSchemaGeneratorUtil.getTableIdentityColumnData(getEntityIdColumn())); - return entityDataMapperFile.getClassFqn(getModuleName()); + return columnsData; } /** - * Generate data provider file. + * Autocomplete entity name dependent fields. */ - private void generateDataProviderFile() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { - final NamespaceBuilder namespaceBuilder = getDataProviderNamespace(); - new UiComponentDataProviderGenerator(new UiComponentDataProviderData( - getDataProviderClassName(), - namespaceBuilder.getNamespace(), - getDataProviderDirectory(), - getEntityIdColumn() - ), getModuleName(), project).generate(ACTION_NAME, false); + private void autoCompleteIdentifiers() { + final String entityNameValue = entityName.getText().trim(); + if (entityNameValue.isEmpty()) { + return; } - } - - /** - * Get data provider namespace builder. - * - * @return NamespaceBuilder - */ - @NotNull - private NamespaceBuilder getDataProviderNamespace() { - return new NamespaceBuilder( - getModuleName(), - getDataProviderClassName(), - getDataProviderDirectory() - ); - } - - /** - * Get data provider directory. - * - * @return String - */ - public String getDataProviderDirectory() { - // TODO: add ui part with dynamic implementation. - return "UI/DataProvider"; - } - - /** - * Get data provider type. - * - * @return String - */ - public String getDataProviderType() { - // TODO: add ui part with dynamic implementation. - return UiComponentDataProviderPhp.CUSTOM_TYPE; - } - - /** - * Generate Grid UI Component action column file. - */ - private void generateUiComponentGridActionColumnFile() { - final GridActionColumnData data = new GridActionColumnData( - getModuleName(), - getEntityName(), - getEntityIdColumn(), - getEditViewAction(), - getDeleteAction() - ); - new GridActionColumnFileGenerator(data, project).generate(ACTION_NAME, true); - } + 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(" ")); - /** - * Generate UI Component grid file. - */ - private void generateUiComponentGridFile() { - final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator( - getUiComponentGridData(), - project - ); - gridXmlGenerator.generate(ACTION_NAME, true); + 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")); } /** - * Get grid UI component data. - * - * @return UiComponentGridData + * Resolve ui components panel state. */ - public UiComponentGridData getUiComponentGridData() { - return new UiComponentGridData( - getModuleName(), - Areas.adminhtml.toString(), - getGridName(), - getDataProviderNamespace().getClassFqn(), - getEntityIdColumn(), - getAcl(), - getUiComponentGridToolbarData(), - getEntityProperties() - ); + private void toggleUiComponentsPanel() { + if (createUiComponent.isSelected()) { + tabbedPane1.add(uiComponentsPanel, 1); + tabbedPane1.setTitleAt(1, UI_COMPONENTS_TAB_NAME); + } else { + tabbedPane1.remove(1); + } } /** - * Get grid toolbar data. + * Get new entity dialog data object. * - * @return UiComponentGridToolbarData + * @return NewEntityDialogData */ - public UiComponentGridToolbarData getUiComponentGridToolbarData() { - return new UiComponentGridToolbarData( - getAddToolBar(), - getAddBookmarksCheckBox(), - getAddColumnsControlCheckBox(), - getAddFullTextSearchCheckBox(), - getAddListingFiltersCheckBox(), - getAddListingPagingCheckBox() + 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 index view action path. - * - * @return String - */ - private String getIndexViewAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "index"; - } - - /** - * Get edit view action path. - * - * @return String - */ - private String getEditViewAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "edit"; - } - - /** - * Get new entity action path. + * Get properties table. * - * @return String + * @return DefaultTableModel */ - private String getNewEntityAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "new"; + private DefaultTableModel getPropertiesTable() { + return (DefaultTableModel) propertyTable.getModel(); } /** - * Get delete action path. + * Get entity id column name. * * @return String */ - private String getDeleteAction() { - return getRoute() - + File.separator - + FirstLetterToLowercaseUtil.convert(getEntityName()) - + File.separator - + "delete"; - } - - /** - * Generate form view controller file. - */ - private void generateFormViewControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - getViewActionName(), - getControllerDirectory().concat(getEntityName()) - ); - new ModuleControllerClassGenerator(new ControllerFileData( - getControllerDirectory().concat(getEntityName()), - getViewActionName(), - getModuleName(), - Areas.adminhtml.toString(), - HttpMethod.GET.toString(), - getAcl(), - true, - namespace.getNamespace() - ), project).generate(ACTION_NAME, false); - } - - /** - * Generate UI Component form layout file. - */ - private void generateFormLayoutFile() { - new LayoutXmlGenerator(new LayoutXmlData( - Areas.adminhtml.toString(), - getRoute(), - getModuleName(), - getEntityName(), - getViewActionName(), - getFormName() - ), project).generate(ACTION_NAME, false); - } - - private void generateNewEntityLayoutFile() { - new NewEntityLayoutGenerator(new NewEntityLayoutData( - getModuleName(), - getNewEntityAction(), - getEditViewAction() - ), project).generate(ACTION_NAME, false); - } - - /** - * Run SaveCommand.php file generator for an entity. - */ - private void generateSaveEntityCommandFile() { - final String classFqn = SaveEntityCommandFile.getClassFqn( - getModuleName(), - getEntityName() - ); - final String namespace = SaveEntityCommandFile.getNamespace( - getModuleName(), - getEntityName() - ); - final NamespaceBuilder modelNamespace = getModelNamespace(); - final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace(); - final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); - final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); - - final String dtoType; - - if (createInterface.isSelected()) { - dtoType = dtoInterfaceModelNamespace.getClassFqn(); - } else { - dtoType = dtoModelNamespace.getClassFqn(); - } - - new SaveEntityCommandGenerator( - new SaveEntityCommandData( - getModuleName(), - getEntityName(), - namespace, - classFqn, - modelNamespace.getClassFqn(), - resourceModelNamespace.getClassFqn(), - dtoType - ), - project - ).generate(ACTION_NAME, true); - } - - /** - * Generate Save Controller file. - */ - private void generateFormSaveControllerFile() { - final NamespaceBuilder dtoModelNamespace = getDataModelNamespace(); - final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace(); - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - SaveActionFile.CLASS_NAME, - SaveActionFile.getDirectory(getEntityName()) - ); - final String dtoType; - - if (createInterface.isSelected()) { - dtoType = dtoInterfaceModelNamespace.getClassFqn(); - } else { - dtoType = dtoModelNamespace.getClassFqn(); - } - - new SaveEntityControllerFileGenerator(new SaveEntityControllerFileData( - getEntityName(), - getModuleName(), - namespace.getNamespace(), - getSaveEntityCommandClassFqn(), - dtoType, - getAcl(), - getEntityIdColumn() - ), project).generate(ACTION_NAME, false); - } - - /** - * Generate NewAction Controller file. - */ - private void generateFormNewActionControllerFile() { - final NamespaceBuilder namespace = new NamespaceBuilder( - getModuleName(), - NewActionFile.CLASS_NAME, - NewActionFile.getDirectory(getEntityName()) - ); - - new NewActionEntityControllerFileGenerator(new NewActionEntityControllerFileData( - getEntityName(), - getModuleName(), - namespace.getNamespace(), - getAcl(), - getMenuIdentifier() - ), project).generate(ACTION_NAME, false); + private String getEntityIdColumn() { + return entityId.getText().trim(); } /** - * Get save entity command class Fqn. + * Get table engine. * * @return String */ - private String getSaveEntityCommandClassFqn() { - final NamespaceBuilder namespaceBuilder = - new NamespaceBuilder( - getModuleName(), - SaveEntityCommandFile.CLASS_NAME, - SaveEntityCommandFile.getDirectory(getEntityName()) - ); - - return namespaceBuilder.getClassFqn(); - } - - /** - * Generate Form UI Component generic button block file. - */ - private void generateFormUiComponentGenericButtonFile() { - final NamespaceBuilder genericButtonBlockNamespace = new NamespaceBuilder( - getModuleName(), - FormGenericButtonBlockFile.CLASS_NAME, - FormGenericButtonBlockFile.DIRECTORY - ); - new FormGenericButtonBlockGenerator( - new FormGenericButtonBlockData( - getModuleName(), - getEntityName(), - getEntityIdColumn(), - genericButtonBlockNamespace.getClassFqn(), - genericButtonBlockNamespace.getNamespace() - ), - project - ).generate(ACTION_NAME, true); - } - - /** - * Generate UI Component form file. - */ - private void generateUiComponentFormFile() { - new UiComponentFormGenerator(new UiComponentFormFileData( - getFormName(), - Areas.adminhtml.toString(), - getModuleName(), - getFormLabel(), - getButtons(), - getFieldsets(), - getFields(), - getRoute(), - getEntityName(), - getSubmitActionName(), - getDataProviderNamespace().getClassFqn() - ), project, getEntityName(), getEntityIdColumn()).generate(ACTION_NAME, true); - } - - /** - * Generate menu file. - */ - private void generateMenuFile() { - new MenuXmlGenerator(new MenuXmlData( - getParentMenuItem(), - getSortOrder(), - getModuleName(), - getMenuIdentifier(), - getMenuTitle(), - getAcl(), - getIndexViewAction() - ), project).generate(ACTION_NAME, false); - } - - private String getParentMenuItem() { - return parentMenu.getSelectedItem().toString(); - } - - public String getSortOrder() { - return sortOrder.getText().trim(); - } - - public String getMenuIdentifier() { - return menuIdentifier.getText().trim(); - } - - public String getMenuTitle() { - return menuTitle.getText().trim(); - } - - private Boolean getAddToolBar() { - return addToolBar.isSelected(); - } - - private Boolean getAddColumnsControlCheckBox() { - return addColumnsControlCheckBox.isSelected(); - } - - private Boolean getAddFullTextSearchCheckBox() { - return addFullTextSearchCheckBox.isSelected(); - } - - private Boolean getAddListingFiltersCheckBox() { - return addListingFiltersCheckBox.isSelected(); - } - - private Boolean getAddListingPagingCheckBox() { - return addListingPagingCheckBox.isSelected(); - } - - private Boolean getAddBookmarksCheckBox() { - return addBookmarksCheckBox.isSelected(); - } - - /** - * Run db_schema.xml file generator. - * - * @param dbSchemaXmlData DbSchemaXmlData - */ - private void generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { - new DbSchemaXmlGenerator( - dbSchemaXmlData, - project, - moduleName - ).generate(ACTION_NAME, false); - } - - /** - * Run db_schema_whitelist.json generator. - * - * @param dbSchemaXmlData DbSchemaXmlData - */ - private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) { - new DbSchemaWhitelistJsonGenerator( - project, - dbSchemaXmlData, - moduleName - ).generate(ACTION_NAME, false); + private String getTableEngine() { + return tableEngine.getSelectedItem() == null ? "" + : tableEngine.getSelectedItem().toString().trim(); } /** - * Get tableResource field value. + * Get table resource. * * @return String */ private String getTableResource() { - return tableResource.getSelectedItem().toString().trim(); + return tableResource.getSelectedItem() == null ? "" + : tableResource.getSelectedItem().toString().trim(); } /** - * Get tableEngine field value. + * Get parent acl resource id. * * @return String */ - private String getTableEngine() { - return tableEngine.getSelectedItem().toString().trim(); + private String getParentAcl() { + return parentAcl.getSelectedItem() == null ? "" + : parentAcl.getSelectedItem().toString().trim(); } /** - * Get entity properties table columns data and format to suitable for generator. + * Get parent menu id. * - * @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; - } - - @NotNull - private List getMenuReferences() { - final Collection menuReferences - = FileBasedIndex.getInstance().getAllKeys(MenuIndex.KEY, project); - final ArrayList menuReferencesList = new ArrayList<>(menuReferences); - Collections.sort(menuReferencesList); - - return menuReferencesList; - } - - /** - * Autocomplete entity name dependent fields. - */ - private void autoCompleteIdentifiers() { - if (getEntityName().isEmpty()) { - return; - } - final String entityName = CamelCaseToSnakeCase.getInstance().convert(getEntityName()); - 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(getModuleName().concat("::management")); - aclTitle.setText(entityNameLabel.concat(" Management")); - menuIdentifier.setText(getModuleName().concat("::management")); - menuTitle.setText(entityNameLabel.concat(" Management")); - } - - /** - * Resolve ui components panel state. + * @return String */ - private void toggleUiComponentsPanel() { - if (createUiComponent.isSelected()) { - tabbedPane1.add(uiComponentsPanel, 1); - tabbedPane1.setTitleAt(1, UI_COMPONENTS_TAB_NAME); - } else { - tabbedPane1.remove(1); - } + private String getParentMenu() { + return parentMenu.getSelectedItem() == null ? "" + : parentMenu.getSelectedItem().toString().trim(); } } 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..c6355a489 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -21,8 +21,8 @@ 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.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; import java.awt.event.ActionEvent; @@ -175,19 +175,19 @@ private String getEntityIdColumn() { } private String getCollectionDirectory() { - return ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + File.separator + return ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + collectionDirectory.getText().trim(); } private NamespaceBuilder getModelNamespace() { - return new NamespaceBuilder(getModuleName(), getModelName(), ModelPhp.MODEL_DIRECTORY); + return new NamespaceBuilder(getModuleName(), getModelName(), ModelFile.MODEL_DIRECTORY); } private NamespaceBuilder getResourceModelNamespace() { return new NamespaceBuilder( getModuleName(), getResourceModelName(), - ResourceModelPhp.RESOURCE_MODEL_DIRECTORY + ResourceModelFile.RESOURCE_MODEL_DIRECTORY ); } 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..1c5d4357b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -44,7 +44,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; @@ -342,7 +342,7 @@ private void generateUiComponentFile() { } private void generateDataProviderClass() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.CUSTOM_TYPE)) { + if (getDataProviderType().equals(UiComponentDataProviderFile.CUSTOM_TYPE)) { final UiComponentDataProviderGenerator dataProviderGenerator; dataProviderGenerator = new UiComponentDataProviderGenerator( getGridDataProviderData(), @@ -354,7 +354,7 @@ private void generateDataProviderClass() { } private void generateDataProviderDeclaration() { - if (getDataProviderType().equals(UiComponentDataProviderPhp.COLLECTION_TYPE)) { + if (getDataProviderType().equals(UiComponentDataProviderFile.COLLECTION_TYPE)) { final DataProviderDeclarationGenerator dataProviderGenerator; dataProviderGenerator = new DataProviderDeclarationGenerator( new DataProviderDeclarationData( @@ -439,7 +439,7 @@ private void onAreaChange() { private void onDataProviderTypeChange() { final boolean visible = getDataProviderType().equals( - UiComponentDataProviderPhp.COLLECTION_TYPE + UiComponentDataProviderFile.COLLECTION_TYPE ); collection.setVisible(visible); @@ -492,8 +492,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,8 +529,8 @@ 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", 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 41b13c09b..81bff2daf 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -165,7 +165,7 @@ protected void onOK() { } final PsiFile diXml = new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getPreferenceModule(), - targetClass, + targetClass.getPresentableFQN(), getPreferenceClassFqn(), getNamespace(), getPreferenceArea() 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..ebff9a7e1 --- /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 org.apache.commons.lang.StringUtils; +import javax.swing.table.DefaultTableModel; +import java.util.ArrayList; +import java.util.List; + +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++) { + String name = table.getValueAt(index, 0).toString(); + 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/generator/AdminListViewEntityActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java index db8fb408b..bdfcaeb39 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java @@ -14,7 +14,7 @@ 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.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile; +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; @@ -28,7 +28,7 @@ public class AdminListViewEntityActionGenerator extends FileGenerator { private final Project project; private final AdminListViewEntityActionData data; - private final AdminListViewActionFile file; + private final IndexActionFile file; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; @@ -64,7 +64,7 @@ public AdminListViewEntityActionGenerator( this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; - file = new AdminListViewActionFile(data.getEntityName()); + file = new IndexActionFile(data.getEntityName()); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); @@ -113,7 +113,7 @@ public PsiFile generate(final @NotNull String actionName) { protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("ENTITY_NAME", data.getEntityName()); attributes.setProperty("NAMESPACE", data.getNamespace()); - attributes.setProperty("CLASS_NAME", AdminListViewActionFile.CLASS_NAME); + attributes.setProperty("CLASS_NAME", IndexActionFile.CLASS_NAME); attributes.setProperty("ACL", data.getAcl()); attributes.setProperty("MENU", data.getMenu()); 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 1fe146725..2cf82170c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java @@ -18,7 +18,7 @@ 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.magento.files.DataModelFile; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import java.util.LinkedList; @@ -101,7 +101,7 @@ protected void fillAttributes(final Properties attributes) { attributes.setProperty("NAME", modelData.getName()); attributes.setProperty( "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(DataModel.DATA_OBJECT) + PhpClassGeneratorUtil.getNameFromFqn(DataModelFile.DATA_OBJECT) ); attributes.setProperty( "IMPLEMENTS", @@ -113,7 +113,7 @@ protected void fillAttributes(final Properties attributes) { private List getUses() { final List usesList = new LinkedList<>(); - usesList.add(DataModel.DATA_OBJECT); + usesList.add(DataModelFile.DATA_OBJECT); if (modelData.hasInterface()) { usesList.add(modelData.getInterfaceFQN()); @@ -127,14 +127,14 @@ private PhpClass createModel(final String actionName) { final PsiFile interfaceFile; final Properties attributes = getAttributes(); - for (final String directory: DataModel.DIRECTORY.split("/")) { + for (final String directory: DataModelFile.DIRECTORY.split("/")) { parentDirectory = directoryGenerator.findOrCreateSubdirectory( parentDirectory, directory ); } interfaceFile = fileFromTemplateGenerator.generate( - new DataModel(modelData.getName()), + new DataModelFile(modelData.getName()), attributes, parentDirectory, actionName 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 65865d23f..33cdde120 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java @@ -17,7 +17,7 @@ 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.magento.files.DataModelInterfaceFile; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import java.util.Properties; @@ -106,14 +106,14 @@ private PhpClass createInterface(final String actionName) { final PsiFile interfaceFile; final Properties attributes = getAttributes(); - for (final String directory: DataModelInterface.DIRECTORY.split("/")) { + for (final String directory: DataModelInterfaceFile.DIRECTORY.split("/")) { parentDirectory = directoryGenerator.findOrCreateSubdirectory( parentDirectory, directory ); } interfaceFile = fileFromTemplateGenerator.generate( - new DataModelInterface(interfaceData.getName()), + new DataModelInterfaceFile(interfaceData.getName()), attributes, parentDirectory, actionName 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 a9cdac186..a6226100b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java @@ -18,7 +18,7 @@ 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.files.CollectionModelFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; @@ -138,7 +138,7 @@ private PhpClass createClass(final String actionName) { final Properties attributes = getAttributes(); modelFile = fileFromTemplateGenerator.generate( - new CollectionPhp(collectionData.getCollectionName()), + new CollectionModelFile(collectionData.getCollectionName()), attributes, parentDirectory, actionName @@ -168,7 +168,7 @@ protected void fillAttributes(final Properties attributes) { attributes.setProperty( "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(CollectionPhp.ABSTRACT_COLLECTION) + PhpClassGeneratorUtil.getNameFromFqn(CollectionModelFile.ABSTRACT_COLLECTION) ); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); @@ -176,7 +176,7 @@ protected void fillAttributes(final Properties attributes) { private List getUses() { return new ArrayList<>(Arrays.asList( - CollectionPhp.ABSTRACT_COLLECTION + CollectionModelFile.ABSTRACT_COLLECTION )); } } 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 fc9b0960d..6431fab9c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java @@ -18,7 +18,7 @@ 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.magento.files.ModelFile; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; import java.util.ArrayList; @@ -127,12 +127,12 @@ private PhpClass createModelClass(final String actionName) { final PsiFile modelFile; parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, ModelPhp.MODEL_DIRECTORY + parentDirectory, ModelFile.MODEL_DIRECTORY ); final Properties attributes = getAttributes(); modelFile = fileFromTemplateGenerator.generate( - new ModelPhp(modelData.getModelName()), + new ModelFile(modelData.getModelName()), attributes, parentDirectory, actionName @@ -155,7 +155,7 @@ protected void fillAttributes(final Properties attributes) { attributes.setProperty( "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(ModelPhp.ABSTRACT_MODEL) + PhpClassGeneratorUtil.getNameFromFqn(ModelFile.ABSTRACT_MODEL) ); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); @@ -163,7 +163,7 @@ protected void fillAttributes(final Properties attributes) { private List getUses() { return new ArrayList<>(Arrays.asList( - ModelPhp.ABSTRACT_MODEL, + ModelFile.ABSTRACT_MODEL, modelData.getResourceModelFqn() )); } 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 e1a7542ae..1bbf4c128 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java @@ -18,7 +18,7 @@ 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.files.ResourceModelFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; @@ -127,7 +127,7 @@ private PhpClass createClass(final String actionName) { .getModuleDirectoryByModuleName(getModuleName()); final PsiFile modelFile; - final String[] resourceModelDirectories = ResourceModelPhp.RESOURCE_MODEL_DIRECTORY.split( + final String[] resourceModelDirectories = ResourceModelFile.RESOURCE_MODEL_DIRECTORY.split( File.separator ); for (final String directory: resourceModelDirectories) { @@ -138,7 +138,7 @@ private PhpClass createClass(final String actionName) { final Properties attributes = getAttributes(); modelFile = fileFromTemplateGenerator.generate( - new ResourceModelPhp(resourceModelData.getResourceModelName()), + new ResourceModelFile(resourceModelData.getResourceModelName()), attributes, parentDirectory, actionName @@ -163,7 +163,7 @@ protected void fillAttributes(final Properties attributes) { attributes.setProperty( "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(ResourceModelPhp.ABSTRACT_DB) + PhpClassGeneratorUtil.getNameFromFqn(ResourceModelFile.ABSTRACT_DB) ); attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); @@ -171,7 +171,7 @@ protected void fillAttributes(final Properties attributes) { private List getUses() { return new ArrayList<>(Arrays.asList( - ResourceModelPhp.ABSTRACT_DB + ResourceModelFile.ABSTRACT_DB )); } } 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..28626faa7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/PreferenceDiXmlGenerator.java @@ -96,7 +96,7 @@ private boolean getTypeAttributeValue(final XmlFile diXml) { ModuleDiXml.PREFERENCE_TAG_NAME, ModuleDiXml.PREFERENCE_ATTR_FOR ); - final String fqn = preferenceDiXmFileData.getTargetClass().getPresentableFQN(); + final String fqn = preferenceDiXmFileData.getTargetClass(); for (final XmlAttributeValue preference: preferences) { if (PhpLangUtil.toPresentableFQN(preference.getValue()).equals(fqn)) { return true; @@ -108,8 +108,7 @@ private boolean getTypeAttributeValue(final XmlFile diXml) { @Override protected void fillAttributes(final Properties attributes) { - attributes.setProperty("FOR", preferenceDiXmFileData.getTargetClass() - .getPresentableFQN()); + attributes.setProperty("FOR", preferenceDiXmFileData.getTargetClass()); attributes.setProperty("TYPE", preferenceDiXmFileData.getPreferenceFqn()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java index 94c00245b..d95c182e5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java @@ -17,7 +17,7 @@ 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.files.UiComponentDataProviderFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; @@ -128,7 +128,7 @@ private PhpClass createDataProviderClass(final String actionName) { final Properties attributes = getAttributes(); dataProviderFile = fileFromTemplateGenerator.generate( - UiComponentDataProviderPhp.getInstance( + UiComponentDataProviderFile.getInstance( uiComponentGridDataProviderData.getName() ), attributes, 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 23832539b..c7538c694 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java @@ -18,7 +18,7 @@ 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.files.UiComponentDataProviderFile; import com.magento.idea.magento2plugin.magento.files.queries.GetListQuery; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.Package; @@ -139,11 +139,11 @@ protected void fillAttributes(final @NotNull Properties attributes) { final List uses = new LinkedList<>(); - uses.add(UiComponentDataProviderPhp.DEFAULT_DATA_PROVIDER); + uses.add(UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER); attributes.setProperty( "EXTENDS", PhpClassGeneratorUtil.getNameFromFqn( - UiComponentDataProviderPhp.DEFAULT_DATA_PROVIDER + UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER ) ); @@ -170,10 +170,10 @@ protected void fillAttributes(final @NotNull Properties attributes) { uses.add(FrameworkLibraryType.FILTER_BUILDER.getType()); attributes.setProperty("FILTER_BUILDER", FrameworkLibraryType.FILTER_BUILDER.getTypeName()); - uses.add(UiComponentDataProviderPhp.SEARCH_RESULT_FACTORY); + uses.add(UiComponentDataProviderFile.SEARCH_RESULT_FACTORY); attributes.setProperty("SEARCH_RESULT_FACTORY", PhpClassGeneratorUtil.getNameFromFqn( - UiComponentDataProviderPhp.SEARCH_RESULT_FACTORY + UiComponentDataProviderFile.SEARCH_RESULT_FACTORY ) ); @@ -210,7 +210,7 @@ private PhpClass createDataProviderClass(final @NotNull String actionName) { final Properties attributes = getAttributes(); dataProviderFile = fileFromTemplateGenerator.generate( - UiComponentDataProviderPhp.getInstance( + UiComponentDataProviderFile.getInstance( uiComponentGridDataProviderData.getName() ), attributes, 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 e28a9087e..84a4f4a95 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java @@ -28,8 +28,6 @@ public class UiComponentFormGenerator extends FileGenerator { private final UiComponentFormFileData uiFormFileData; private final Project project; - private final String entityName; - private final String entityIdField; /** * Ui Component form generator constructor. @@ -40,29 +38,10 @@ public class UiComponentFormGenerator extends FileGenerator { public UiComponentFormGenerator( final @NotNull UiComponentFormFileData uiFormFileData, final Project project - ) { - this(uiFormFileData, project, "Entity", "entity_id"); - } - - /** - * Ui Component form generator constructor. - * - * @param uiFormFileData UiFormFileData - * @param project Project - * @param entityName String - * @param entityIdField String - */ - public UiComponentFormGenerator( - final @NotNull UiComponentFormFileData uiFormFileData, - final Project project, - final @NotNull String entityName, - final @NotNull String entityIdField ) { super(project); this.uiFormFileData = uiFormFileData; this.project = project; - this.entityName = entityName; - this.entityIdField = entityIdField; } /** @@ -93,8 +72,8 @@ protected void generateButtonClasses(final @NotNull String actionName) { new UiComponentFormButtonBlockGenerator( buttonData, project, - entityName, - entityIdField + uiFormFileData.getEntityName(), + uiFormFileData.getEntityId() ).generate(actionName); } } 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..4015d4e21 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java @@ -0,0 +1,93 @@ +/* + * 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 org.jetbrains.annotations.NotNull; + +public abstract class GeneratorHandler { + + private final GenerationContextData contextData; + private final DataObjectConverter dataObjectConverter; + private final GeneratorRunnerValidator runnerValidator; + + /** + * 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 + */ + protected boolean validate() { + if (runnerValidator != null) { + return runnerValidator.validate(); + } + return true; + } + + /** + * Run chain of generators. + */ + protected abstract void generate(); + + /** + * 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..60fe95420 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java @@ -0,0 +1,106 @@ +/* + * 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.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import java.lang.reflect.Constructor; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public final class GeneratorPoolHandler { + + private final GenerationContextData contextData; + private final List pool; + + /** + * Generator pool handler constructor. + * + * @param contextData GenerationContextData + */ + public GeneratorPoolHandler(final @NotNull GenerationContextData contextData) { + this.contextData = contextData; + pool = 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 (Exception exception) { + // + } + + return this; + } + + /** + * Trigger generation process. + */ + public void run() { + for (final GeneratorHandler handler : pool) { + if (handler.validate()) { + handler.generate(); + } + } + } +} 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..a5b1499d0 --- /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 + protected void generate() { + new AclXmlGenerator( + (AclXmlData) getDataObjectConverter(), + getContextData().getModuleName(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..67a6c9179 --- /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 + protected void generate() { + new ModuleCollectionGenerator( + (CollectionData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..8b9b65b6f --- /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 + protected void generate() { + new DataModelGenerator( + getProject(), + (DataModelData) getDataObjectConverter() + ).generate(getContextData().getActionName(), true); + } +} 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..64a7f6804 --- /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 + protected void generate() { + new DataModelInterfaceGenerator( + getProject(), + (DataModelInterfaceData) getDataObjectConverter() + ).generate(getContextData().getActionName(), true); + } +} 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..6766f0894 --- /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 + protected void generate() { + new PreferenceDiXmlGenerator( + (PreferenceDiXmFileData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..b4cad2cfd --- /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 + protected void generate() { + new UiComponentDataProviderGenerator( + (UiComponentDataProviderData) getDataObjectConverter(), + getContextData().getModuleName(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..9cd99858c --- /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 + protected void generate() { + new DbSchemaWhitelistJsonGenerator( + getProject(), + (DbSchemaXmlData) getDataObjectConverter(), + getContextData().getModuleName() + ).generate(getContextData().getActionName(), true); + } +} 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..428891676 --- /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 + protected void generate() { + new DbSchemaXmlGenerator( + (DbSchemaXmlData) getDataObjectConverter(), + getProject(), + getContextData().getModuleName() + ).generate(getContextData().getActionName(), true); + } +} 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..1ed9e1e9e --- /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 + protected void generate() { + new EntityDataMapperGenerator( + (EntityDataMapperData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java new file mode 100644 index 000000000..50d838f2c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.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.AdminListViewEntityActionData; +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.AdminListViewEntityActionGenerator; +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 EntityListActionGeneratorHandler extends GeneratorHandler { + + /** + * Entity index action generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public EntityListActionGeneratorHandler( + 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 EntityListActionGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + protected void generate() { + new AdminListViewEntityActionGenerator( + (AdminListViewEntityActionData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..63ceb8a85 --- /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 + protected void generate() { + new FormGenericButtonBlockGenerator( + (FormGenericButtonBlockData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..f5d056a81 --- /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 + ) { + this(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 + protected void generate() { + new LayoutXmlGenerator( + (LayoutXmlData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..31b0adbcf --- /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 + protected void generate() { + new SaveEntityControllerFileGenerator( + (SaveEntityControllerFileData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java new file mode 100644 index 000000000..9e045ecd5 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.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.FormViewControllerDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator; +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 FormViewControllerGeneratorHandler extends GeneratorHandler { + + /** + * Form view controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public FormViewControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Form view controller generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public FormViewControllerGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + protected void generate() { + new ModuleControllerClassGenerator( + (FormViewControllerDtoConverter) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..19179212c --- /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 + protected void generate() { + new GetListQueryModelGenerator( + (GetListQueryModelData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..930f58b82 --- /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 + protected void generate() { + new GridActionColumnFileGenerator( + (GridActionColumnDtoConverter) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..6b607c6cd --- /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 + protected void generate() { + new LayoutXmlGenerator( + (LayoutXmlData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..ca06446ae --- /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 + protected void generate() { + new MenuXmlGenerator( + (MenuXmlData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..c49177415 --- /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 + protected void generate() { + new ModuleModelGenerator( + (ModelData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..e1fb0d142 --- /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 + protected void generate() { + new NewActionEntityControllerFileGenerator( + (NewActionEntityControllerFileData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..2acb51e10 --- /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 + protected void generate() { + new NewEntityLayoutGenerator( + (NewEntityLayoutData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..4338dce9a --- /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 + protected void generate() { + new ModuleResourceModelGenerator( + (ResourceModelData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..dc5cf1117 --- /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 + protected void generate() { + new RoutesXmlGenerator( + (RoutesXmlData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..8fa6eebac --- /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 + protected void generate() { + new SaveEntityCommandGenerator( + (SaveEntityCommandData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..152933d93 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/UiComponentFormLayoutGeneratorHandler.java @@ -0,0 +1,55 @@ +/* + * 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 + protected void generate() { + final UiComponentFormFileData data = (UiComponentFormFileData) getDataObjectConverter(); + + new UiComponentFormGenerator( + data, + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..26fc711bf --- /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 + protected void generate() { + new UiComponentGridXmlGenerator( + (UiComponentGridData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java index bba99ba24..4d5f1f96a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java +++ b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpClass.java @@ -7,14 +7,26 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import org.jetbrains.annotations.NotNull; public abstract class AbstractPhpClass implements ModuleFileInterface { private final String fileName; + private final String className; - public AbstractPhpClass(final String className) { + public AbstractPhpClass(final @NotNull String className) { + this.className = className; fileName = className.concat(".php"); } + /** + * Get class name. + * + * @return String + */ + public String getClassName() { + return className; + } + @Override public String getFileName() { return this.fileName; 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..423b41c7a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java @@ -0,0 +1,55 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.packages.File; +import org.jetbrains.annotations.NotNull; + +public class CollectionModelFile extends AbstractPhpClass { + public static final String TEMPLATE = "Magento Collection Class"; + public static final String ABSTRACT_COLLECTION + = "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection"; + + public CollectionModelFile(final @NotNull String className) { + super(className); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + getClassName(), + getDirectory(entityName) + ); + } + + /** + * Get collection file directory. + * + * @param entityName String + * + * @return String + */ + public @NotNull String getDirectory(final @NotNull String entityName) { + return ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + entityName; + } + + @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/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..3b13eb951 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java @@ -0,0 +1,56 @@ +/* + * 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 class DataModelFile implements ModuleFileInterface { + public static final String TEMPLATE = "Magento Data Model"; + public static final String DIRECTORY = "Model/Data"; + public static final String DATA_OBJECT = "Magento\\Framework\\DataObject"; + private final String className; + private final String fileName; + + public DataModelFile(final @NotNull String className) { + this.className = className; + fileName = className.concat(".php"); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + + @Override + public String getFileName() { + return fileName; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} 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..3bef9586e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/DataModelInterfaceFile.java @@ -0,0 +1,55 @@ +/* + * 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 class DataModelInterfaceFile implements ModuleFileInterface { + public static final String TEMPLATE = "Magento Data Model Interface"; + public static final String DIRECTORY = "Api/Data"; + private final String className; + private final String filename; + + public DataModelInterfaceFile(final @NotNull String className) { + this.className = className; + filename = className.concat(".php"); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + + @Override + public String getFileName() { + return filename; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java index 252bfff49..4cd427d6d 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java @@ -30,6 +30,23 @@ public EntityDataMapperFile(final @NotNull String entityName) { this.className = entityName.concat(CLASS_NAME_SUFFIX); } + /** + * Get namespace builder. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + /** * Get namespace. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java index eb2e33d55..43404c85a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java @@ -7,6 +7,8 @@ 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 class FormGenericButtonBlockFile implements ModuleFileInterface { @@ -16,6 +18,23 @@ public class FormGenericButtonBlockFile implements ModuleFileInterface { public static final String DIRECTORY = "Block/Form"; public static final String CONTEXT = "Magento\\Backend\\Block\\Widget\\Context"; + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + DIRECTORY + ); + } + @Override public String getFileName() { return CLASS_NAME.concat("." + FILE_EXTENSION); diff --git a/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java index b127b6609..5eb5c7ea5 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/GridActionColumnFile.java @@ -12,7 +12,7 @@ public final class GridActionColumnFile implements ModuleFileInterface { public static final String CLASS_NAME = "BlockActions"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Grid Ui Component Action Column Class"; - public static final String DIRECTORY = "UI/Component/Listing/Column"; + public static final String DIRECTORY = "Ui/Component/Listing/Column"; public static final String PARENT_CLASS = "Magento\\Ui\\Component\\Listing\\Columns\\Column"; public static final String CONTEXT = "Magento\\Framework\\View\\Element\\UiComponent\\ContextInterface"; 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..cac59c6e4 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java @@ -0,0 +1,42 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import org.jetbrains.annotations.NotNull; + +public class ModelFile extends AbstractPhpClass { + 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 ModelFile(final String className) { + super(className); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + getClassName(), + MODEL_DIRECTORY + ); + } + + @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/ResourceModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java new file mode 100644 index 000000000..79ad22fc9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java @@ -0,0 +1,42 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import org.jetbrains.annotations.NotNull; + +public class ResourceModelFile extends AbstractPhpClass { + public static final String RESOURCE_MODEL_DIRECTORY = "Model/ResourceModel"; + public static final String TEMPLATE = "Magento Resource Model Class"; + public static final String ABSTRACT_DB + = "Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb"; + + public ResourceModelFile(final @NotNull String className) { + super(className); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + getClassName(), + RESOURCE_MODEL_DIRECTORY + ); + } + + @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/UiComponentDataProviderPhp.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java similarity index 59% rename from src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java rename to src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java index 1cb3f62bf..5db31d220 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java @@ -7,18 +7,21 @@ 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; @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 class UiComponentDataProviderFile implements ModuleFileInterface { + public static final String TEMPLATE = "Magento UI Component Custom Data Provider Class"; + public static final String DIRECTORY = "Ui/DataProvider"; 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 static UiComponentDataProviderFile INSTANCE = null; private String className; public static final String DEFAULT_DATA_PROVIDER = "Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\DataProvider"; @@ -29,13 +32,14 @@ public class UiComponentDataProviderPhp implements ModuleFileInterface { * Returns a new instance of the class. * * @param className DataProvider class name - * @return UiComponentGridDataProviderPhp + * + * @return UiComponentDataProviderFile */ - public static UiComponentDataProviderPhp getInstance( - final String className + public static UiComponentDataProviderFile getInstance( + final @NotNull String className ) { if (null == INSTANCE) { - INSTANCE = new UiComponentDataProviderPhp(); + INSTANCE = new UiComponentDataProviderFile(); } INSTANCE.setClassName(className); @@ -43,6 +47,23 @@ public static UiComponentDataProviderPhp getInstance( return INSTANCE; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + /** * Set class name. * @@ -59,7 +80,7 @@ public String getFileName() { @Override public String getTemplate() { - return CUSTOM_TEMPLATE; + return TEMPLATE; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java similarity index 70% rename from src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java rename to src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java index 92ab92803..9579d338b 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/AdminListViewActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java @@ -7,10 +7,11 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; -public final class AdminListViewActionFile implements ModuleFileInterface { +public final class IndexActionFile implements ModuleFileInterface { public static final String CLASS_NAME = "Index"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Index Adminhtml Controller Class"; @@ -22,12 +23,29 @@ public final class AdminListViewActionFile implements ModuleFileInterface { * * @param entityName String */ - public AdminListViewActionFile( + public IndexActionFile( final @NotNull String entityName ) { this.entityName = entityName; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + /** * Get Directory path from the module root. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java index 2fe00e29c..534ab6abd 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/NewActionFile.java @@ -7,6 +7,7 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; @@ -26,6 +27,25 @@ public static NewActionFile getInstance() { return INSTANCE; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); + } + /** * Get Directory path from the module root. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java index c3634e547..20bdfc2f5 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -7,6 +7,7 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; @@ -28,6 +29,25 @@ public static SaveActionFile getInstance() { return INSTANCE; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); + } + /** * Get Directory path from the module root. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java index 68b414338..5a03ec49b 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java @@ -9,7 +9,6 @@ import com.jetbrains.php.lang.PhpLanguage; import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; -import com.magento.idea.magento2plugin.magento.packages.Package; import org.jetbrains.annotations.NotNull; public class SaveEntityCommandFile implements ModuleFileInterface { @@ -30,13 +29,7 @@ public class SaveEntityCommandFile implements ModuleFileInterface { final @NotNull String moduleName, final @NotNull String entityName ) { - final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( - moduleName, - SaveEntityCommandFile.CLASS_NAME, - SaveEntityCommandFile.getDirectory(entityName) - ); - - return namespaceBuilder.getNamespace(); + return getNamespaceBuilder(moduleName, entityName).getNamespace(); } /** @@ -51,9 +44,26 @@ public static String getClassFqn( final @NotNull String moduleName, final @NotNull String entityName ) { - return getNamespace(moduleName, entityName) - .concat(Package.fqnSeparator) - .concat(CLASS_NAME); + return getNamespaceBuilder(moduleName, entityName).getClassFqn(); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); } /** diff --git a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php index 2922f23d8..124a69350 100644 --- a/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php +++ b/testData/actions/generation/generator/GridActionColumnFileGenerator/generateGridActionColumnFile/BlockActions.php @@ -1,6 +1,6 @@ Date: Fri, 12 Mar 2021 18:10:48 +0200 Subject: [PATCH 56/84] Additional development after the branch updating, bug fix --- .../DeleteEntityByIdCommandDtoConverter.java | 37 ++++ .../FormDeleteControllerDtoConverter.java | 36 ++++ .../FormEditControllerDtoConverter.java | 36 ++++ .../data/dialog/EntityManagerContextData.java | 183 +++++++++++++++++- .../generation/dialog/NewEntityDialog.java | 43 +++- .../generator/EditEntityActionGenerator.java | 6 +- .../DeleteByIdCommandGeneratorHandler.java | 53 +++++ .../FormDeleteControllerGeneratorHandler.java | 53 +++++ .../FormEditControllerGeneratorHandler.java | 53 +++++ .../files/actions/DeleteActionFile.java | 20 ++ ...ityActionFile.java => EditActionFile.java} | 22 ++- .../commands/DeleteEntityByIdCommandFile.java | 32 +-- .../packages/uiComponent/FormElementType.java | 3 +- .../custom_entity_grid.xml | 2 +- .../custom_entity_grid.xml | 2 +- .../EditEntityActionGeneratorTest.java | 4 +- 16 files changed, 551 insertions(+), 34 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DeleteEntityByIdCommandDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormDeleteControllerDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormEditControllerDtoConverter.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/DeleteByIdCommandGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormDeleteControllerGeneratorHandler.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormEditControllerGeneratorHandler.java rename src/com/magento/idea/magento2plugin/magento/files/actions/{EditEntityActionFile.java => EditActionFile.java} (70%) 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..fbf010a59 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/DeleteEntityByIdCommandDtoConverter.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.DeleteEntityByIdCommandData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public DeleteEntityByIdCommandDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getNamespace(), + generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getClassFqn(), + generationContextData.getModelNamespaceBuilder().getClassFqn(), + generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), + newEntityDialogData.getIdFieldName() + ); + } +} 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..d7ddd5174 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormDeleteControllerDtoConverter.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.DeleteEntityControllerFileData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormDeleteControllerDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + generationContextData.getDeleteControllerNamespaceBuilder().getNamespace(), + generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getClassFqn(), + 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..331d10c9e --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormEditControllerDtoConverter.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.EditEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; +import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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 EntityManagerContextData + * @param newEntityDialogData NewEntityDialogData + */ + public FormEditControllerDtoConverter( + final @NotNull EntityManagerContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + newEntityDialogData.getEntityName(), + generationContextData.getModuleName(), + generationContextData.getEditControllerNamespaceBuilder().getClassFqn(), + generationContextData.getEditControllerNamespaceBuilder().getNamespace(), + newEntityDialogData.getAclId(), + newEntityDialogData.getMenuId() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java index bf1b250b1..fca84790a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java @@ -10,11 +10,11 @@ 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 org.jetbrains.annotations.NotNull; - import java.util.List; import java.util.Map; +import org.jetbrains.annotations.NotNull; +@SuppressWarnings("PMD.TooManyFields") public class EntityManagerContextData implements GenerationContextData { private final Project project; @@ -34,15 +34,51 @@ public class EntityManagerContextData implements GenerationContextData { private final NamespaceBuilder entityListActionNamespaceBuilder; private final NamespaceBuilder entityDataMapperNamespaceBuilder; private final NamespaceBuilder saveEntityCommandNamespaceBuilder; + private final NamespaceBuilder deleteEntityByIdCommandNamespaceBuilder; private final NamespaceBuilder formViewNamespaceBuilder; private final NamespaceBuilder newControllerNamespaceBuilder; private final NamespaceBuilder saveControllerNamespaceBuilder; + private final NamespaceBuilder deleteControllerNamespaceBuilder; + private final NamespaceBuilder editControllerNamespaceBuilder; private final NamespaceBuilder genericButtonBlockNamespaceBuilder; private final List> entityProps; private final List buttons; private final List fieldsetData; private final List fieldsData; + /** + * Entity manager context data. + * + * @param project Project + * @param moduleName String + * @param actionName String + * @param indexViewAction String + * @param editViewAction String + * @param newViewAction String + * @param deleteAction String + * @param modelNamespaceBuilder NamespaceBuilder + * @param resourceModelNamespaceBuilder NamespaceBuilder + * @param collectionModelNamespaceBuilder NamespaceBuilder + * @param dtoModelNamespaceBuilder NamespaceBuilder + * @param dtoInterfaceNamespaceBuilder NamespaceBuilder + * @param finalDtoTypeNamespaceBuilder NamespaceBuilder + * @param dataProviderNamespaceBuilder NamespaceBuilder + * @param entityListActionNamespaceBuilder NamespaceBuilder + * @param entityDataMapperNamespaceBuilder NamespaceBuilder + * @param saveEntityCommandNamespaceBuilder NamespaceBuilder + * @param deleteEntityByIdCommandNamespaceBuilder NamespaceBuilder + * @param formViewNamespaceBuilder NamespaceBuilder + * @param newControllerNamespaceBuilder NamespaceBuilder + * @param saveControllerNamespaceBuilder NamespaceBuilder + * @param deleteControllerNamespaceBuilder NamespaceBuilder + * @param editControllerNamespaceBuilder NamespaceBuilder + * @param genericButtonBlockNamespaceBuilder NamespaceBuilder + * @param entityProps List + * @param buttons List + * @param fieldsetData List + * @param fieldsData List + */ + @SuppressWarnings("PMD.ExcessiveParameterList") public EntityManagerContextData( final @NotNull Project project, final @NotNull String moduleName, @@ -61,9 +97,12 @@ public EntityManagerContextData( final @NotNull NamespaceBuilder entityListActionNamespaceBuilder, final @NotNull NamespaceBuilder entityDataMapperNamespaceBuilder, final @NotNull NamespaceBuilder saveEntityCommandNamespaceBuilder, + final @NotNull NamespaceBuilder deleteEntityByIdCommandNamespaceBuilder, final @NotNull NamespaceBuilder formViewNamespaceBuilder, final @NotNull NamespaceBuilder newControllerNamespaceBuilder, final @NotNull NamespaceBuilder saveControllerNamespaceBuilder, + final @NotNull NamespaceBuilder deleteControllerNamespaceBuilder, + final @NotNull NamespaceBuilder editControllerNamespaceBuilder, final @NotNull NamespaceBuilder genericButtonBlockNamespaceBuilder, final @NotNull List> entityProps, final @NotNull List buttons, @@ -87,9 +126,12 @@ public EntityManagerContextData( this.entityListActionNamespaceBuilder = entityListActionNamespaceBuilder; this.entityDataMapperNamespaceBuilder = entityDataMapperNamespaceBuilder; this.saveEntityCommandNamespaceBuilder = saveEntityCommandNamespaceBuilder; + this.deleteEntityByIdCommandNamespaceBuilder = deleteEntityByIdCommandNamespaceBuilder; this.formViewNamespaceBuilder = formViewNamespaceBuilder; this.newControllerNamespaceBuilder = newControllerNamespaceBuilder; this.saveControllerNamespaceBuilder = saveControllerNamespaceBuilder; + this.deleteControllerNamespaceBuilder = deleteControllerNamespaceBuilder; + this.editControllerNamespaceBuilder = editControllerNamespaceBuilder; this.genericButtonBlockNamespaceBuilder = genericButtonBlockNamespaceBuilder; this.entityProps = entityProps; this.buttons = buttons; @@ -112,90 +154,227 @@ public String getActionName() { return actionName; } + /** + * 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 model namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getModelNamespaceBuilder() { return modelNamespaceBuilder; } + /** + * Get resource model namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getResourceModelNamespaceBuilder() { return resourceModelNamespaceBuilder; } + /** + * Get collection model namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getCollectionModelNamespaceBuilder() { return collectionModelNamespaceBuilder; } + /** + * 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 final DTO type namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getFinalDtoTypeNamespaceBuilder() { return finalDtoTypeNamespaceBuilder; } + /** + * Get data provider namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getDataProviderNamespaceBuilder() { return dataProviderNamespaceBuilder; } + /** + * Get entity list action namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getEntityListActionNamespaceBuilder() { return entityListActionNamespaceBuilder; } + /** + * Get entity data mapper namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getEntityDataMapperNamespaceBuilder() { return entityDataMapperNamespaceBuilder; } + /** + * Get save entity command namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getSaveEntityCommandNamespaceBuilder() { return saveEntityCommandNamespaceBuilder; } + /** + * Get delete by id command namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getDeleteEntityByIdCommandNamespaceBuilder() { + return deleteEntityByIdCommandNamespaceBuilder; + } + + /** + * 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 save controller namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getSaveControllerNamespaceBuilder() { return saveControllerNamespaceBuilder; } + /** + * Get delete controller namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getDeleteControllerNamespaceBuilder() { + return deleteControllerNamespaceBuilder; + } + + /** + * Get edit controller namespace builder. + * + * @return NamespaceBuilder + */ + public NamespaceBuilder getEditControllerNamespaceBuilder() { + return editControllerNamespaceBuilder; + } + + /** + * Get generic button block namespace builder. + * + * @return NamespaceBuilder + */ public NamespaceBuilder getGenericButtonBlockNamespaceBuilder() { return genericButtonBlockNamespaceBuilder; } + /** + * 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/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 6bec113de..217793dea 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -10,14 +10,20 @@ 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.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.EntityListActionDtoConverter; +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; @@ -32,14 +38,11 @@ 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.EntityManagerContextData; import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; -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.converter.newentitydialog.SaveEntityCommandDtoConverter; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.actions.generation.dialog.util.ClassPropertyFormatterUtil; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; @@ -58,8 +61,11 @@ 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.EntityListActionGeneratorHandler; +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; @@ -88,9 +94,12 @@ import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile; +import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile; import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; +import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; import com.magento.idea.magento2plugin.magento.packages.File; import com.magento.idea.magento2plugin.magento.packages.PropertiesTypes; @@ -272,8 +281,9 @@ public void windowClosing(final WindowEvent event) { ); entityName.addKeyListener(new KeyAdapter() { + @SuppressWarnings("PMD.AccessorMethodGeneration") @Override - public void keyReleased(KeyEvent e) { + public void keyReleased(final KeyEvent event) { entityName.setText(StringUtils.capitalize(entityName.getText())); } }); @@ -448,11 +458,26 @@ private void onOK() { 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), @@ -479,11 +504,6 @@ private void onOK() { generatorPoolHandler.run(); - generateDeleteEntityByIdCommandFile(); - generateFormEditControllerFile(); - generateFormSaveControllerFile(); - generateFormDeleteControllerFile(); - this.setVisible(false); } @@ -539,9 +559,12 @@ private EntityManagerContextData getEntityManagerContextData( new IndexActionFile(entityName).getNamespaceBuilder(moduleName), new EntityDataMapperFile(entityName).getNamespaceBuilder(moduleName), SaveEntityCommandFile.getNamespaceBuilder(moduleName, entityName), + DeleteEntityByIdCommandFile.getNamespaceBuilder(moduleName, entityName), formViewNamespaceBuilder, NewActionFile.getNamespaceBuilder(moduleName, entityName), SaveActionFile.getNamespaceBuilder(moduleName, entityName), + DeleteActionFile.getNamespaceBuilder(moduleName, entityName), + new EditActionFile(entityName).getNamespaceBuilder(moduleName), FormGenericButtonBlockFile.getNamespaceBuilder(moduleName), getEntityProperties(), getButtons(), diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java index e218e54a2..24a92507e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java @@ -14,7 +14,7 @@ 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.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile; +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; @@ -27,7 +27,7 @@ public class EditEntityActionGenerator extends FileGenerator { private final Project project; - private final EditEntityActionFile file; + private final EditActionFile file; private final EditEntityActionData data; private final boolean checkFileAlreadyExists; private final FileFromTemplateGenerator fileFromTemplateGenerator; @@ -64,7 +64,7 @@ public EditEntityActionGenerator( this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; - file = new EditEntityActionFile(data.getEntityName()); + file = new EditActionFile(data.getEntityName()); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); moduleIndex = ModuleIndex.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); 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..61ef7aa33 --- /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 + protected void generate() { + new DeleteEntityByIdCommandGenerator( + (DeleteEntityByIdCommandData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..2743ed1b3 --- /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 + protected void generate() { + new DeleteEntityControllerFileGenerator( + (DeleteEntityControllerFileData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} 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..fccf451e9 --- /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 + protected void generate() { + new EditEntityActionGenerator( + (EditEntityActionData) getDataObjectConverter(), + getProject() + ).generate(getContextData().getActionName(), true); + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java index 632b8e09d..fc998a6ba 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java @@ -7,6 +7,7 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; @@ -26,6 +27,25 @@ public static DeleteActionFile getInstance() { return INSTANCE; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); + } + /** * Get Directory path from the module root. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java similarity index 70% rename from src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java rename to src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java index 013908606..4f8b1956a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/EditEntityActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java @@ -7,10 +7,11 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; import org.jetbrains.annotations.NotNull; -public final class EditEntityActionFile implements ModuleFileInterface { +public final class EditActionFile implements ModuleFileInterface { public static final String CLASS_NAME = "Edit"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Edit Action Controller Class"; @@ -22,10 +23,27 @@ public final class EditEntityActionFile implements ModuleFileInterface { * * @param entityName String */ - public EditEntityActionFile(final @NotNull String entityName) { + public EditActionFile(final @NotNull String entityName) { this.entityName = entityName; } + /** + * Get namespace builder for file. + * + * @param moduleName String + * + * @return String + */ + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + /** * Get class name. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java index 0cca3f573..9b3294190 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -9,7 +9,6 @@ import com.jetbrains.php.lang.PhpLanguage; import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; -import com.magento.idea.magento2plugin.magento.packages.Package; import org.jetbrains.annotations.NotNull; public class DeleteEntityByIdCommandFile implements ModuleFileInterface { @@ -30,13 +29,7 @@ public class DeleteEntityByIdCommandFile implements ModuleFileInterface { final @NotNull String moduleName, final @NotNull String entityName ) { - final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( - moduleName, - DeleteEntityByIdCommandFile.CLASS_NAME, - DeleteEntityByIdCommandFile.getDirectory(entityName) - ); - - return namespaceBuilder.getNamespace(); + return getNamespaceBuilder(moduleName, entityName).getNamespace(); } /** @@ -51,9 +44,26 @@ public static String getClassFqn( final @NotNull String moduleName, final @NotNull String entityName ) { - return getNamespace(moduleName, entityName) - .concat(Package.fqnSeparator) - .concat(CLASS_NAME); + return getNamespaceBuilder(moduleName, entityName).getClassFqn(); + } + + /** + * Get namespace builder for file. + * + * @param moduleName String + * @param entityName String + * + * @return String + */ + public static @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + return new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); } /** diff --git a/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java b/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java index 600c52d69..71aaee407 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/uiComponent/FormElementType.java @@ -76,11 +76,10 @@ public static FormElementType getDefaultForProperty(final @NotNull PropertiesTyp switch (property) { case INT: case STRING: + case FLOAT: return FormElementType.INPUT; case BOOL: return FormElementType.CHECKBOX; - case FLOAT: - return FormElementType.PRICE; default: throw new NotSupportedException( "ENUMs " + FormElementType.class + " property is not supported." diff --git a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml index 2b32cdcba..d3c1b611c 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridForBaseArea/custom_entity_grid.xml @@ -43,7 +43,7 @@ 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 9effc2e2c..afccc39bd 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml @@ -50,7 +50,7 @@ desc
- + entity_id diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java index 2c569040d..67a13e72c 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGeneratorTest.java @@ -7,7 +7,7 @@ import com.intellij.psi.PsiFile; import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData; -import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile; +import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile; public class EditEntityActionGeneratorTest extends BaseGeneratorTestCase { private static final String MODULE_NAME = "Foo_Bar"; @@ -23,7 +23,7 @@ public class EditEntityActionGeneratorTest extends BaseGeneratorTestCase { * Test generation of edit entity controller file. */ public void testGenerateEditEntityActionFile() { - final EditEntityActionFile file = new EditEntityActionFile(ENTITY_NAME); + final EditActionFile file = new EditActionFile(ENTITY_NAME); final EditEntityActionGenerator generator = new EditEntityActionGenerator( new EditEntityActionData( From 7bc0a2978299e33688bfe2fce709f7bfcc99892b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 13 Mar 2021 11:26:23 +0200 Subject: [PATCH 57/84] Made generate and validate methods public --- .../actions/generation/generator/pool/GeneratorHandler.java | 4 ++-- .../generator/pool/handler/AclXmlGeneratorHandler.java | 2 +- .../pool/handler/CollectionModelGeneratorHandler.java | 2 +- .../generator/pool/handler/DataModelGeneratorHandler.java | 2 +- .../pool/handler/DataModelInterfaceGeneratorHandler.java | 2 +- .../pool/handler/DataModelPreferenceGeneratorHandler.java | 2 +- .../generator/pool/handler/DataProviderGeneratorHandler.java | 2 +- .../pool/handler/DbSchemaWhitelistGeneratorHandler.java | 2 +- .../generator/pool/handler/DbSchemaXmlGeneratorHandler.java | 2 +- .../pool/handler/DeleteByIdCommandGeneratorHandler.java | 2 +- .../pool/handler/EntityDataMapperGeneratorHandler.java | 2 +- .../pool/handler/EntityListActionGeneratorHandler.java | 2 +- .../pool/handler/FormDeleteControllerGeneratorHandler.java | 2 +- .../pool/handler/FormEditControllerGeneratorHandler.java | 2 +- .../pool/handler/FormGenericButtonBlockGeneratorHandler.java | 2 +- .../generator/pool/handler/FormLayoutGeneratorHandler.java | 2 +- .../pool/handler/FormSaveControllerGeneratorHandler.java | 2 +- .../pool/handler/FormViewControllerGeneratorHandler.java | 2 +- .../generator/pool/handler/GetListQueryGeneratorHandler.java | 2 +- .../pool/handler/GridActionColumnGeneratorHandler.java | 2 +- .../generator/pool/handler/GridLayoutXmlGeneratorHandler.java | 2 +- .../generator/pool/handler/MenuXmlGeneratorHandler.java | 2 +- .../generator/pool/handler/ModelGeneratorHandler.java | 2 +- .../generator/pool/handler/NewControllerGeneratorHandler.java | 2 +- .../pool/handler/NewEntityLayoutGeneratorHandler.java | 2 +- .../generator/pool/handler/ResourceModelGeneratorHandler.java | 2 +- .../generator/pool/handler/RoutesXmlGeneratorHandler.java | 2 +- .../generator/pool/handler/SaveCommandGeneratorHandler.java | 2 +- .../pool/handler/UiComponentFormLayoutGeneratorHandler.java | 2 +- .../pool/handler/UiComponentGridGeneratorHandler.java | 2 +- 30 files changed, 31 insertions(+), 31 deletions(-) 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 index 4015d4e21..71282789f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java @@ -52,7 +52,7 @@ public GeneratorHandler( * * @return boolean */ - protected boolean validate() { + public boolean validate() { if (runnerValidator != null) { return runnerValidator.validate(); } @@ -62,7 +62,7 @@ protected boolean validate() { /** * Run chain of generators. */ - protected abstract void generate(); + public abstract void generate(); /** * Get project. 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 index a5b1499d0..7896dcb31 100644 --- 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 @@ -44,7 +44,7 @@ public AclXmlGeneratorHandler( } @Override - protected void generate() { + public void generate() { new AclXmlGenerator( (AclXmlData) getDataObjectConverter(), getContextData().getModuleName(), 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 index 67a6c9179..b3c077cad 100644 --- 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 @@ -44,7 +44,7 @@ public CollectionModelGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 8b9b65b6f..107e89820 100644 --- 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 @@ -44,7 +44,7 @@ public DataModelGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 64a7f6804..7076fb528 100644 --- 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 @@ -44,7 +44,7 @@ public DataModelInterfaceGeneratorHandler( } @Override - protected void generate() { + public void generate() { new DataModelInterfaceGenerator( getProject(), (DataModelInterfaceData) getDataObjectConverter() 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 index 6766f0894..cb90bec4f 100644 --- 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 @@ -44,7 +44,7 @@ public DataModelPreferenceGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index b4cad2cfd..b5c9fd380 100644 --- 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 @@ -44,7 +44,7 @@ public DataProviderGeneratorHandler( } @Override - protected void generate() { + public void generate() { new UiComponentDataProviderGenerator( (UiComponentDataProviderData) getDataObjectConverter(), getContextData().getModuleName(), 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 index 9cd99858c..c5d5a9858 100644 --- 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 @@ -44,7 +44,7 @@ public DbSchemaWhitelistGeneratorHandler( } @Override - protected void generate() { + public void generate() { new DbSchemaWhitelistJsonGenerator( getProject(), (DbSchemaXmlData) getDataObjectConverter(), 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 index 428891676..0ee432ae6 100644 --- 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 @@ -44,7 +44,7 @@ public DbSchemaXmlGeneratorHandler( } @Override - protected void generate() { + public void generate() { new DbSchemaXmlGenerator( (DbSchemaXmlData) getDataObjectConverter(), getProject(), 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 index 61ef7aa33..02dbd875f 100644 --- 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 @@ -44,7 +44,7 @@ public DeleteByIdCommandGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 1ed9e1e9e..29c56676b 100644 --- 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 @@ -44,7 +44,7 @@ public EntityDataMapperGeneratorHandler( } @Override - protected void generate() { + public void generate() { new EntityDataMapperGenerator( (EntityDataMapperData) getDataObjectConverter(), getProject() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java index 50d838f2c..554235a58 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java @@ -44,7 +44,7 @@ public EntityListActionGeneratorHandler( } @Override - protected void generate() { + public void generate() { new AdminListViewEntityActionGenerator( (AdminListViewEntityActionData) 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 index 2743ed1b3..fd37b916b 100644 --- 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 @@ -44,7 +44,7 @@ public FormDeleteControllerGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index fccf451e9..d47d1e3ec 100644 --- 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 @@ -44,7 +44,7 @@ public FormEditControllerGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 63ceb8a85..679b68aa1 100644 --- 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 @@ -44,7 +44,7 @@ public FormGenericButtonBlockGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index f5d056a81..162fc7e52 100644 --- 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 @@ -44,7 +44,7 @@ public FormLayoutGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 31b0adbcf..7df7fd6e4 100644 --- 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 @@ -44,7 +44,7 @@ public FormSaveControllerGeneratorHandler( } @Override - protected void generate() { + public void generate() { new SaveEntityControllerFileGenerator( (SaveEntityControllerFileData) getDataObjectConverter(), getProject() diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java index 9e045ecd5..2fea4366d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java @@ -44,7 +44,7 @@ public FormViewControllerGeneratorHandler( } @Override - protected void generate() { + public void generate() { new ModuleControllerClassGenerator( (FormViewControllerDtoConverter) 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 index 19179212c..750c470de 100644 --- 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 @@ -44,7 +44,7 @@ public GetListQueryGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 930f58b82..c7bbf6707 100644 --- 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 @@ -44,7 +44,7 @@ public GridActionColumnGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 6b607c6cd..16010cc20 100644 --- 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 @@ -44,7 +44,7 @@ public GridLayoutXmlGeneratorHandler( } @Override - protected void generate() { + public void generate() { new LayoutXmlGenerator( (LayoutXmlData) 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 index ca06446ae..332833efb 100644 --- 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 @@ -44,7 +44,7 @@ public MenuXmlGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index c49177415..80a899be6 100644 --- 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 @@ -44,7 +44,7 @@ public ModelGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index e1fb0d142..ab68d9c82 100644 --- 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 @@ -44,7 +44,7 @@ public NewControllerGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 2acb51e10..6914a1297 100644 --- 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 @@ -44,7 +44,7 @@ public NewEntityLayoutGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 4338dce9a..6e4fdafa1 100644 --- 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 @@ -44,7 +44,7 @@ public ResourceModelGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index dc5cf1117..ed3e7434d 100644 --- 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 @@ -44,7 +44,7 @@ public RoutesXmlGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 8fa6eebac..16d8f4c47 100644 --- 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 @@ -44,7 +44,7 @@ public SaveCommandGeneratorHandler( } @Override - protected void generate() { + public void generate() { 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 index 152933d93..dd9d7ba83 100644 --- 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 @@ -44,7 +44,7 @@ public UiComponentFormLayoutGeneratorHandler( } @Override - protected void generate() { + public void generate() { final UiComponentFormFileData data = (UiComponentFormFileData) getDataObjectConverter(); new UiComponentFormGenerator( 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 index 26fc711bf..2615ae46e 100644 --- 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 @@ -44,7 +44,7 @@ public UiComponentGridGeneratorHandler( } @Override - protected void generate() { + public void generate() { new UiComponentGridXmlGenerator( (UiComponentGridData) getDataObjectConverter(), getProject() From 65ad74d193d205a2a5b6af28ccb04c13ade635d2 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Sat, 13 Mar 2021 14:06:36 +0200 Subject: [PATCH 58/84] Added testing for entity manager in pool generation, showed message if generator handler is incorrect, fixed open file flag ignored --- resources/magento2/exception.properties | 3 + .../data/dialog/EntityManagerContextData.java | 9 + .../data/dialog/GenerationContextData.java | 7 + .../generation/dialog/NewEntityDialog.java | 205 +--------------- .../generation/generator/FileGenerator.java | 23 +- .../generator/pool/GeneratorHandler.java | 24 +- .../generator/pool/GeneratorPoolHandler.java | 85 ++++++- .../pool/handler/AclXmlGeneratorHandler.java | 6 +- .../CollectionModelGeneratorHandler.java | 6 +- .../handler/DataModelGeneratorHandler.java | 6 +- .../DataModelInterfaceGeneratorHandler.java | 6 +- .../DataModelPreferenceGeneratorHandler.java | 6 +- .../handler/DataProviderGeneratorHandler.java | 6 +- .../DbSchemaWhitelistGeneratorHandler.java | 6 +- .../handler/DbSchemaXmlGeneratorHandler.java | 6 +- .../DeleteByIdCommandGeneratorHandler.java | 6 +- .../EntityDataMapperGeneratorHandler.java | 6 +- .../EntityListActionGeneratorHandler.java | 6 +- .../FormDeleteControllerGeneratorHandler.java | 6 +- .../FormEditControllerGeneratorHandler.java | 6 +- ...ormGenericButtonBlockGeneratorHandler.java | 6 +- .../handler/FormLayoutGeneratorHandler.java | 8 +- .../FormSaveControllerGeneratorHandler.java | 6 +- .../FormViewControllerGeneratorHandler.java | 6 +- .../handler/GetListQueryGeneratorHandler.java | 6 +- .../GridActionColumnGeneratorHandler.java | 6 +- .../GridLayoutXmlGeneratorHandler.java | 10 +- .../pool/handler/MenuXmlGeneratorHandler.java | 6 +- .../pool/handler/ModelGeneratorHandler.java | 6 +- .../NewControllerGeneratorHandler.java | 6 +- .../NewEntityLayoutGeneratorHandler.java | 6 +- .../ResourceModelGeneratorHandler.java | 6 +- .../handler/RoutesXmlGeneratorHandler.java | 6 +- .../handler/SaveCommandGeneratorHandler.java | 6 +- ...UiComponentFormLayoutGeneratorHandler.java | 10 +- .../UiComponentGridGeneratorHandler.java | 6 +- .../NewEntityGeneratorsProviderUtil.java | 229 ++++++++++++++++++ .../bundles/ExceptionBundle.java | 18 ++ .../pool/NewEntityGeneratorPoolTest.java | 145 +++++++++++ 39 files changed, 631 insertions(+), 301 deletions(-) create mode 100644 resources/magento2/exception.properties create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/pool/provider/NewEntityGeneratorsProviderUtil.java create mode 100644 src/com/magento/idea/magento2plugin/bundles/ExceptionBundle.java create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java diff --git a/resources/magento2/exception.properties b/resources/magento2/exception.properties new file mode 100644 index 000000000..dead840c7 --- /dev/null +++ b/resources/magento2/exception.properties @@ -0,0 +1,3 @@ +exception.common.checkLogg=Please, 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}. You should implement it. diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java index fca84790a..9ea2a3329 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java @@ -20,6 +20,7 @@ public class EntityManagerContextData 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; @@ -52,6 +53,7 @@ public class EntityManagerContextData implements GenerationContextData { * @param project Project * @param moduleName String * @param actionName String + * @param hasOpenFileFlag boolean * @param indexViewAction String * @param editViewAction String * @param newViewAction String @@ -83,6 +85,7 @@ public EntityManagerContextData( 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, @@ -112,6 +115,7 @@ public EntityManagerContextData( this.project = project; this.moduleName = moduleName; this.actionName = actionName; + this.hasOpenFileFlag = hasOpenFileFlag; this.indexViewAction = indexViewAction; this.editViewAction = editViewAction; this.newViewAction = newViewAction; @@ -154,6 +158,11 @@ public String getActionName() { return actionName; } + @Override + public boolean hasOpenFileFlag() { + return hasOpenFileFlag; + } + /** * Get index action. * 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 index 064e32caf..779850d23 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java @@ -32,4 +32,11 @@ public interface GenerationContextData { * @return String */ String getActionName(); + + /** + * Check if files should be opened after generation. + * + * @return boolean + */ + boolean hasOpenFileFlag(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 217793dea..718035265 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -13,34 +13,6 @@ 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.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.EntityListActionDtoConverter; -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.FormViewControllerDtoConverter; -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.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.EntityManagerContextData; import com.magento.idea.magento2plugin.actions.generation.data.dialog.NewEntityDialogData; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; @@ -53,35 +25,7 @@ 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.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.EntityListActionGeneratorHandler; -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.FormViewControllerGeneratorHandler; -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.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 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.CollectionModelFile; @@ -147,7 +91,6 @@ @SuppressWarnings({ "PMD.TooManyFields", "PMD.UnusedPrivateField", - "PMD.CouplingBetweenObjects", "PMD.ExcessiveImports" }) public class NewEntityDialog extends AbstractDialog { @@ -213,6 +156,8 @@ public class NewEntityDialog extends AbstractDialog { 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, FORM_NAME}) @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) private JTextField formName; @@ -352,7 +297,6 @@ private void initPropertiesTable() { /** * Perform code generation using input data. */ - @SuppressWarnings("PMD.ExcessiveMethodLength") private void onOK() { if (!validateFormFields()) { return; @@ -364,143 +308,11 @@ private void onOK() { final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(context); - 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) - ) - .addNext( - AclXmlGeneratorHandler.class, - new AclXmlDtoConverter(context, dialogData) - ) - .addNext( - MenuXmlGeneratorHandler.class, - new MenuXmlDtoConverter(context, dialogData) - ) - .addNext( - EntityListActionGeneratorHandler.class, - new EntityListActionDtoConverter(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( - FormViewControllerGeneratorHandler.class, - new FormViewControllerDtoConverter(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) - ); + NewEntityGeneratorsProviderUtil.initializeGenerators( + generatorPoolHandler, + context, + dialogData + ); generatorPoolHandler.run(); @@ -543,6 +355,7 @@ private EntityManagerContextData getEntityManagerContextData( project, moduleName, ACTION_NAME, + OPEN_FILES_FLAG, actionsPathPrefix.concat("index"), actionsPathPrefix.concat("edit"), actionsPathPrefix.concat("new"), 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..fd5a4d250 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; @@ -13,24 +14,32 @@ public abstract class FileGenerator { private final Project project; private final NavigateToCreatedFile navigateToCreatedFile; - public FileGenerator(Project project) - { + public FileGenerator(final Project project) { this.project = project; this.navigateToCreatedFile = NavigateToCreatedFile.getInstance(); } - public abstract PsiFile generate(String actionName); + 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; } protected Properties getAttributes() { - Properties attributes = new Properties(); + final Properties attributes = new Properties(); this.fillAttributes(attributes); return attributes; } 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 index 71282789f..b787fd619 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java @@ -8,7 +8,7 @@ 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 { @@ -16,6 +16,7 @@ public abstract class GeneratorHandler { private final GenerationContextData contextData; private final DataObjectConverter dataObjectConverter; private final GeneratorRunnerValidator runnerValidator; + private FileGenerator generator; /** * Generator handler constructor. @@ -60,9 +61,26 @@ public boolean validate() { } /** - * Run chain of generators. + * 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 abstract void generate(); + public final void generate() { + generator.generate(getContextData().getActionName(), getContextData().hasOpenFileFlag()); + } /** * Get project. 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 index 60fe95420..cc3e03aa8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java @@ -5,17 +5,26 @@ 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 java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +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. @@ -25,6 +34,8 @@ public final class GeneratorPoolHandler { public GeneratorPoolHandler(final @NotNull GenerationContextData contextData) { this.contextData = contextData; pool = new LinkedList<>(); + exceptionBundle = new ExceptionBundle(); + errors = new LinkedList<>(); } /** @@ -85,9 +96,31 @@ public GeneratorPoolHandler addNext( 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(); - } catch (Exception exception) { - // + LOGGER.error(noSuchMethodException.getMessage()); + errors.add(this.exceptionBundle.message( + "exception.NoSuchMethod", + runnerValidator == null ? constructorDescWithTwoArgs + : constructorDescWithThreeArgs, + handlerClass.getSimpleName() + )); } return this; @@ -97,10 +130,58 @@ public GeneratorPoolHandler addNext( * 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. + * Those errors are system and must be processed by the dev during the testing. + * They cannot go to live. + */ + private void showErrorMessages() { + if (!errors.isEmpty()) { + final String title = this.exceptionBundle.message( + "exception.common.checkLogg" + ); + final AtomicInteger messageNum = new AtomicInteger(1); + final String errorMessage = errors.stream() + .map(message -> messageNum.getAndIncrement() + ". " + message) + .collect(Collectors.joining("\n")); + + JOptionPane.showMessageDialog( + null, + errorMessage, + title, + JOptionPane.ERROR_MESSAGE + ); + } + } } 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 index 7896dcb31..65bc2ffea 100644 --- 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 @@ -44,11 +44,11 @@ public AclXmlGeneratorHandler( } @Override - public void generate() { - new AclXmlGenerator( + public void instantiateGenerator() { + setGenerator(new AclXmlGenerator( (AclXmlData) getDataObjectConverter(), getContextData().getModuleName(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index b3c077cad..ecfbddbe0 100644 --- 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 @@ -44,10 +44,10 @@ public CollectionModelGeneratorHandler( } @Override - public void generate() { - new ModuleCollectionGenerator( + public void instantiateGenerator() { + setGenerator(new ModuleCollectionGenerator( (CollectionData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 107e89820..7ab55ff8f 100644 --- 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 @@ -44,10 +44,10 @@ public DataModelGeneratorHandler( } @Override - public void generate() { - new DataModelGenerator( + public void instantiateGenerator() { + setGenerator(new DataModelGenerator( getProject(), (DataModelData) getDataObjectConverter() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 7076fb528..b1bca9a72 100644 --- 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 @@ -44,10 +44,10 @@ public DataModelInterfaceGeneratorHandler( } @Override - public void generate() { - new DataModelInterfaceGenerator( + public void instantiateGenerator() { + setGenerator(new DataModelInterfaceGenerator( getProject(), (DataModelInterfaceData) getDataObjectConverter() - ).generate(getContextData().getActionName(), true); + )); } } 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 index cb90bec4f..30ad3e70c 100644 --- 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 @@ -44,10 +44,10 @@ public DataModelPreferenceGeneratorHandler( } @Override - public void generate() { - new PreferenceDiXmlGenerator( + public void instantiateGenerator() { + setGenerator(new PreferenceDiXmlGenerator( (PreferenceDiXmFileData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index b5c9fd380..66e0b04ba 100644 --- 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 @@ -44,11 +44,11 @@ public DataProviderGeneratorHandler( } @Override - public void generate() { - new UiComponentDataProviderGenerator( + public void instantiateGenerator() { + setGenerator(new UiComponentDataProviderGenerator( (UiComponentDataProviderData) getDataObjectConverter(), getContextData().getModuleName(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index c5d5a9858..b06f3300b 100644 --- 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 @@ -44,11 +44,11 @@ public DbSchemaWhitelistGeneratorHandler( } @Override - public void generate() { - new DbSchemaWhitelistJsonGenerator( + public void instantiateGenerator() { + setGenerator(new DbSchemaWhitelistJsonGenerator( getProject(), (DbSchemaXmlData) getDataObjectConverter(), getContextData().getModuleName() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 0ee432ae6..25e9ec3c3 100644 --- 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 @@ -44,11 +44,11 @@ public DbSchemaXmlGeneratorHandler( } @Override - public void generate() { - new DbSchemaXmlGenerator( + public void instantiateGenerator() { + setGenerator(new DbSchemaXmlGenerator( (DbSchemaXmlData) getDataObjectConverter(), getProject(), getContextData().getModuleName() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 02dbd875f..6c7c7ec30 100644 --- 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 @@ -44,10 +44,10 @@ public DeleteByIdCommandGeneratorHandler( } @Override - public void generate() { - new DeleteEntityByIdCommandGenerator( + public void instantiateGenerator() { + setGenerator(new DeleteEntityByIdCommandGenerator( (DeleteEntityByIdCommandData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 29c56676b..3e547dae9 100644 --- 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 @@ -44,10 +44,10 @@ public EntityDataMapperGeneratorHandler( } @Override - public void generate() { - new EntityDataMapperGenerator( + public void instantiateGenerator() { + setGenerator(new EntityDataMapperGenerator( (EntityDataMapperData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java index 554235a58..00a8a3eae 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java @@ -44,10 +44,10 @@ public EntityListActionGeneratorHandler( } @Override - public void generate() { - new AdminListViewEntityActionGenerator( + public void instantiateGenerator() { + setGenerator(new AdminListViewEntityActionGenerator( (AdminListViewEntityActionData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index fd37b916b..c14caddf7 100644 --- 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 @@ -44,10 +44,10 @@ public FormDeleteControllerGeneratorHandler( } @Override - public void generate() { - new DeleteEntityControllerFileGenerator( + public void instantiateGenerator() { + setGenerator(new DeleteEntityControllerFileGenerator( (DeleteEntityControllerFileData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index d47d1e3ec..5ec5f8c0d 100644 --- 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 @@ -44,10 +44,10 @@ public FormEditControllerGeneratorHandler( } @Override - public void generate() { - new EditEntityActionGenerator( + public void instantiateGenerator() { + setGenerator(new EditEntityActionGenerator( (EditEntityActionData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 679b68aa1..12f9d5fc9 100644 --- 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 @@ -44,10 +44,10 @@ public FormGenericButtonBlockGeneratorHandler( } @Override - public void generate() { - new FormGenericButtonBlockGenerator( + public void instantiateGenerator() { + setGenerator(new FormGenericButtonBlockGenerator( (FormGenericButtonBlockData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 162fc7e52..b3bf67721 100644 --- 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 @@ -25,7 +25,7 @@ public FormLayoutGeneratorHandler( final @NotNull GenerationContextData contextData, final @NotNull DataObjectConverter dataObjectConverter ) { - this(contextData, dataObjectConverter, null); + super(contextData, dataObjectConverter, null); } /** @@ -44,10 +44,10 @@ public FormLayoutGeneratorHandler( } @Override - public void generate() { - new LayoutXmlGenerator( + public void instantiateGenerator() { + setGenerator(new LayoutXmlGenerator( (LayoutXmlData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 7df7fd6e4..54ab4b099 100644 --- 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 @@ -44,10 +44,10 @@ public FormSaveControllerGeneratorHandler( } @Override - public void generate() { - new SaveEntityControllerFileGenerator( + public void instantiateGenerator() { + setGenerator(new SaveEntityControllerFileGenerator( (SaveEntityControllerFileData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java index 2fea4366d..437af58e4 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/FormViewControllerGeneratorHandler.java @@ -44,10 +44,10 @@ public FormViewControllerGeneratorHandler( } @Override - public void generate() { - new ModuleControllerClassGenerator( + public void instantiateGenerator() { + setGenerator(new ModuleControllerClassGenerator( (FormViewControllerDtoConverter) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 750c470de..120c74943 100644 --- 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 @@ -44,10 +44,10 @@ public GetListQueryGeneratorHandler( } @Override - public void generate() { - new GetListQueryModelGenerator( + public void instantiateGenerator() { + setGenerator(new GetListQueryModelGenerator( (GetListQueryModelData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index c7bbf6707..012e51dc5 100644 --- 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 @@ -44,10 +44,10 @@ public GridActionColumnGeneratorHandler( } @Override - public void generate() { - new GridActionColumnFileGenerator( + public void instantiateGenerator() { + setGenerator(new GridActionColumnFileGenerator( (GridActionColumnDtoConverter) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 16010cc20..c168b18fa 100644 --- 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 @@ -44,10 +44,10 @@ public GridLayoutXmlGeneratorHandler( } @Override - public void generate() { - new LayoutXmlGenerator( - (LayoutXmlData) getDataObjectConverter(), - getProject() - ).generate(getContextData().getActionName(), true); + public void instantiateGenerator() { + setGenerator(new LayoutXmlGenerator( + (LayoutXmlData) 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 index 332833efb..858507559 100644 --- 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 @@ -44,10 +44,10 @@ public MenuXmlGeneratorHandler( } @Override - public void generate() { - new MenuXmlGenerator( + public void instantiateGenerator() { + setGenerator(new MenuXmlGenerator( (MenuXmlData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 80a899be6..316aefe8d 100644 --- 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 @@ -44,10 +44,10 @@ public ModelGeneratorHandler( } @Override - public void generate() { - new ModuleModelGenerator( + public void instantiateGenerator() { + setGenerator(new ModuleModelGenerator( (ModelData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index ab68d9c82..a5fe02f07 100644 --- 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 @@ -44,10 +44,10 @@ public NewControllerGeneratorHandler( } @Override - public void generate() { - new NewActionEntityControllerFileGenerator( + public void instantiateGenerator() { + setGenerator(new NewActionEntityControllerFileGenerator( (NewActionEntityControllerFileData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 6914a1297..15728bade 100644 --- 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 @@ -44,10 +44,10 @@ public NewEntityLayoutGeneratorHandler( } @Override - public void generate() { - new NewEntityLayoutGenerator( + public void instantiateGenerator() { + setGenerator(new NewEntityLayoutGenerator( (NewEntityLayoutData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 6e4fdafa1..3eb28350b 100644 --- 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 @@ -44,10 +44,10 @@ public ResourceModelGeneratorHandler( } @Override - public void generate() { - new ModuleResourceModelGenerator( + public void instantiateGenerator() { + setGenerator(new ModuleResourceModelGenerator( (ResourceModelData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index ed3e7434d..95e29db18 100644 --- 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 @@ -44,10 +44,10 @@ public RoutesXmlGeneratorHandler( } @Override - public void generate() { - new RoutesXmlGenerator( + public void instantiateGenerator() { + setGenerator(new RoutesXmlGenerator( (RoutesXmlData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 16d8f4c47..cec5271b7 100644 --- 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 @@ -44,10 +44,10 @@ public SaveCommandGeneratorHandler( } @Override - public void generate() { - new SaveEntityCommandGenerator( + public void instantiateGenerator() { + setGenerator(new SaveEntityCommandGenerator( (SaveEntityCommandData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index dd9d7ba83..3bce7562c 100644 --- 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 @@ -44,12 +44,10 @@ public UiComponentFormLayoutGeneratorHandler( } @Override - public void generate() { - final UiComponentFormFileData data = (UiComponentFormFileData) getDataObjectConverter(); - - new UiComponentFormGenerator( - data, + public void instantiateGenerator() { + setGenerator(new UiComponentFormGenerator( + (UiComponentFormFileData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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 index 2615ae46e..992a61c5f 100644 --- 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 @@ -44,10 +44,10 @@ public UiComponentGridGeneratorHandler( } @Override - public void generate() { - new UiComponentGridXmlGenerator( + public void instantiateGenerator() { + setGenerator(new UiComponentGridXmlGenerator( (UiComponentGridData) getDataObjectConverter(), getProject() - ).generate(getContextData().getActionName(), true); + )); } } 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..a778277ff --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/provider/NewEntityGeneratorsProviderUtil.java @@ -0,0 +1,229 @@ +/* + * 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.EntityListActionDtoConverter; +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.FormViewControllerDtoConverter; +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.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.EntityManagerContextData; +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.EntityListActionGeneratorHandler; +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.FormViewControllerGeneratorHandler; +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.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 EntityManagerContextData + * @param dialogData NewEntityDialogData + */ + @SuppressWarnings("PMD.ExcessiveMethodLength") + public static void initializeGenerators( + final @NotNull GeneratorPoolHandler generatorPoolHandler, + final @NotNull EntityManagerContextData 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) + ) + .addNext( + AclXmlGeneratorHandler.class, + new AclXmlDtoConverter(context, dialogData) + ) + .addNext( + MenuXmlGeneratorHandler.class, + new MenuXmlDtoConverter(context, dialogData) + ) + .addNext( + EntityListActionGeneratorHandler.class, + new EntityListActionDtoConverter(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( + FormViewControllerGeneratorHandler.class, + new FormViewControllerDtoConverter(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/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/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..f0a1afa70 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java @@ -0,0 +1,145 @@ +/* + * 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.EntityManagerContextData; +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 final static String MODULE_NAME = "Foo_Bar"; + private final static String ACTION_NAME = "Test"; + private final static String INDEX_PATH = "index"; + private final static String EDIT_PATH = "edit"; + private final static String NEW_PATH = "new"; + private final static String DELETE_PATH = "delete"; + + /** + * Test if generator pool handler instantiated without any error. + */ + public void testGeneratorsInPoolInstantiating() { + final NewEntityDialogData dialogData = getMockNewEntityDialogData(); + final EntityManagerContextData 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 EntityManagerContextData 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 manager context data. + * + * @return EntityManagerContextData + */ + private EntityManagerContextData getMockContext() { + final NamespaceBuilder mockNamespace = new NamespaceBuilder( + MODULE_NAME, + "MockClass", + "Mock/Directory" + ); + + return new EntityManagerContextData( + this.myFixture.getProject(), + MODULE_NAME, + ACTION_NAME, + false, + INDEX_PATH, + EDIT_PATH, + NEW_PATH, + DELETE_PATH, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + mockNamespace, + new ArrayList<>(), + new ArrayList<>(), + new ArrayList<>(), + new ArrayList<>() + ); + } +} From 922666cfd9a12c07a29a6ca968d8d770506f710f Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Mar 2021 11:21:08 +0200 Subject: [PATCH 59/84] Renamed Entity Manager to Entity Creator --- .../newentitydialog/AclXmlDtoConverter.java | 6 +++--- .../CollectionModelDtoConverter.java | 6 +++--- .../DataModelDtoConverter.java | 6 +++--- .../DataModelInterfaceDtoConverter.java | 6 +++--- .../DataProviderDtoConverter.java | 6 +++--- .../DbSchemaXmlDtoConverter.java | 6 +++--- .../DeleteEntityByIdCommandDtoConverter.java | 6 +++--- .../EntityDataMapperDtoConverter.java | 6 +++--- .../EntityListActionDtoConverter.java | 6 +++--- .../FormDeleteControllerDtoConverter.java | 6 +++--- .../FormEditControllerDtoConverter.java | 6 +++--- .../FormGenericButtonBlockDtoConverter.java | 6 +++--- .../FormLayoutDtoConverter.java | 6 +++--- .../FormSaveControllerDtoConverter.java | 6 +++--- .../FormViewControllerDtoConverter.java | 6 +++--- .../GetListQueryDtoConverter.java | 6 +++--- .../GridActionColumnDtoConverter.java | 6 +++--- .../GridLayoutXmlDtoConverter.java | 6 +++--- .../newentitydialog/MenuXmlDtoConverter.java | 6 +++--- .../newentitydialog/ModelDtoConverter.java | 6 +++--- .../NewControllerDtoConverter.java | 6 +++--- .../NewEntityLayoutDtoConverter.java | 6 +++--- .../PreferenceDiXmlFileDtoConverter.java | 6 +++--- .../ResourceModelDtoConverter.java | 6 +++--- .../RoutesXmlDtoConverter.java | 6 +++--- .../SaveEntityCommandDtoConverter.java | 6 +++--- .../UiComponentFormLayoutDtoConverter.java | 4 ++-- .../UiComponentGridDtoConverter.java | 6 +++--- .../UiComponentGridToolbarDtoConverter.java | 6 +++--- ...ata.java => EntityCreatorContextData.java} | 6 +++--- .../generation/dialog/NewEntityDialog.java | 21 ++++++++++--------- .../NewEntityGeneratorsProviderUtil.java | 6 +++--- .../pool/NewEntityGeneratorPoolTest.java | 14 ++++++------- 33 files changed, 110 insertions(+), 109 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/data/dialog/{EntityManagerContextData.java => EntityCreatorContextData.java} (98%) 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 index 01fa69ef0..a7127c8b9 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,12 +16,12 @@ public class AclXmlDtoConverter extends AclXmlData implements DataObjectConverte /** * Acl XML DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ @SuppressWarnings("PMD.UnusedFormalParameter") public AclXmlDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index b634c78b3..d8bbf09fd 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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.ResourceModelFile; import com.magento.idea.magento2plugin.magento.packages.File; @@ -18,11 +18,11 @@ public class CollectionModelDtoConverter extends CollectionData implements DataO /** * Collection model DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public CollectionModelDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index f125af2f4..33b560504 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class DataModelDtoConverter extends DataModelData implements DataObjectCo /** * DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public DataModelDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 9502d0508..bdd6689f9 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class DataModelInterfaceDtoConverter extends DataModelInterfaceData /** * DTO interface converter. - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public DataModelInterfaceDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 9ed2a2d36..9f5759042 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -18,11 +18,11 @@ public class DataProviderDtoConverter extends UiComponentDataProviderData /** * Data provider converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public DataProviderDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 809f7320a..5ae51978d 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class DbSchemaXmlDtoConverter extends DbSchemaXmlData implements DataObje /** * Db Schema XML converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public DbSchemaXmlDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index fbf010a59..4e4c13bd6 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class DeleteEntityByIdCommandDtoConverter extends DeleteEntityByIdCommand /** * Delete entity by id command DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public DeleteEntityByIdCommandDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 7ed4510a6..0afa556b0 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class EntityDataMapperDtoConverter extends EntityDataMapperData /** * Entity data mapper converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public EntityDataMapperDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java index c0dad3fd9..4b6764803 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java @@ -7,7 +7,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; -import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class EntityListActionDtoConverter extends AdminListViewEntityActionData /** * Entity list action converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public EntityListActionDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index d7ddd5174..d8898f981 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class FormDeleteControllerDtoConverter extends DeleteEntityControllerFile /** * Form delete controller converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormDeleteControllerDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 331d10c9e..36639ef26 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class FormEditControllerDtoConverter extends EditEntityActionData /** * Form edit controller converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormEditControllerDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 984e9dd85..8ae9092de 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class FormGenericButtonBlockDtoConverter extends FormGenericButtonBlockDa /** * Form generic button block converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormGenericButtonBlockDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index e3216bbbf..e70ed644a 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -19,11 +19,11 @@ public class FormLayoutDtoConverter extends LayoutXmlData implements DataObjectC /** * Form layout converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormLayoutDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index bb63cc77a..ff8632d1d 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class FormSaveControllerDtoConverter extends SaveEntityControllerFileData /** * Form save controller converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormSaveControllerDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java index ebbfa39f6..7e884b97e 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/FormViewControllerDtoConverter.java @@ -7,7 +7,7 @@ import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData; import com.magento.idea.magento2plugin.actions.generation.data.converter.DataObjectConverter; -import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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.ControllerBackendPhp; import com.magento.idea.magento2plugin.magento.packages.Areas; @@ -23,11 +23,11 @@ public class FormViewControllerDtoConverter extends ControllerFileData /** * Form view controller converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public FormViewControllerDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index e03c45d23..763306684 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class GetListQueryDtoConverter extends GetListQueryModelData /** * Get list query converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public GetListQueryDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index b5555782c..851d4e09b 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class GridActionColumnDtoConverter extends GridActionColumnData /** * Grid action column converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public GridActionColumnDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 2f7700ff1..63870167e 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -18,11 +18,11 @@ public class GridLayoutXmlDtoConverter extends LayoutXmlData implements DataObje /** * Grid layout XML converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public GridLayoutXmlDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 703876e71..6c585919f 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class MenuXmlDtoConverter extends MenuXmlData implements DataObjectConver /** * Menu XML DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public MenuXmlDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index bc94e33e3..71340d379 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class ModelDtoConverter extends ModelData implements DataObjectConverter /** * Model DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public ModelDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 7974f3ce0..290327794 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class NewControllerDtoConverter extends NewActionEntityControllerFileData /** * New controller DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public NewControllerDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 30a1baeeb..e83c05a2a 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class NewEntityLayoutDtoConverter extends NewEntityLayoutData /** * New entity layout DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public NewEntityLayoutDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 7264ec6f1..add6f61fa 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -18,11 +18,11 @@ public class PreferenceDiXmlFileDtoConverter extends PreferenceDiXmFileData /** * Preference DI XML file DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public PreferenceDiXmlFileDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 0a80dd08f..926da405d 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -16,11 +16,11 @@ public class ResourceModelDtoConverter extends ResourceModelData implements Data /** * Resource model DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public ResourceModelDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index be6306507..9c8e86460 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class RoutesXmlDtoConverter extends RoutesXmlData implements DataObjectCo /** * Routes XML DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public RoutesXmlDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index dc91a5de0..3c59fd45b 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,11 +17,11 @@ public class SaveEntityCommandDtoConverter extends SaveEntityCommandData /** * Save entity command DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public SaveEntityCommandDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index 599c551a3..5b7149a58 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -18,7 +18,7 @@ public class UiComponentFormLayoutDtoConverter extends UiComponentFormFileData private final static String SUBMIT_ACTION_NAME = "Save"; public UiComponentFormLayoutDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index d36421ee0..516fdc6eb 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -18,11 +18,11 @@ public class UiComponentGridDtoConverter extends UiComponentGridData /** * Ui component grid DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ public UiComponentGridDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( 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 index e354ab52c..e033a9247 100644 --- 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 @@ -7,7 +7,7 @@ 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.EntityManagerContextData; +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; @@ -17,12 +17,12 @@ public class UiComponentGridToolbarDtoConverter extends UiComponentGridToolbarDa /** * Ui component grid toolbar DTO converter. * - * @param generationContextData EntityManagerContextData + * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ @SuppressWarnings("PMD.UnusedFormalParameter") public UiComponentGridToolbarDtoConverter( - final @NotNull EntityManagerContextData generationContextData, + final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java similarity index 98% rename from src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java rename to src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java index 9ea2a3329..0fbed16c5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityManagerContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; @SuppressWarnings("PMD.TooManyFields") -public class EntityManagerContextData implements GenerationContextData { +public class EntityCreatorContextData implements GenerationContextData { private final Project project; private final String moduleName; @@ -48,7 +48,7 @@ public class EntityManagerContextData implements GenerationContextData { private final List fieldsData; /** - * Entity manager context data. + * Entity creator context data. * * @param project Project * @param moduleName String @@ -81,7 +81,7 @@ public class EntityManagerContextData implements GenerationContextData { * @param fieldsData List */ @SuppressWarnings("PMD.ExcessiveParameterList") - public EntityManagerContextData( + public EntityCreatorContextData( final @NotNull Project project, final @NotNull String moduleName, final @NotNull String actionName, diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 718035265..ddda13616 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -13,7 +13,7 @@ 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.EntityManagerContextData; +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.util.ClassPropertyFormatterUtil; @@ -57,6 +57,7 @@ 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; @@ -304,7 +305,7 @@ private void onOK() { formatProperties(); final NewEntityDialogData dialogData = getNewEntityDialogData(); - final EntityManagerContextData context = getEntityManagerContextData(dialogData); + final EntityCreatorContextData context = getEntityCreatorContextData(dialogData); final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(context); @@ -320,13 +321,13 @@ private void onOK() { } /** - * Get entity manager context data. + * Get entity creator context data. * * @param dialogData NewEntityDialogData * - * @return EntityManagerContextData + * @return EntityCreatorContextData */ - private EntityManagerContextData getEntityManagerContextData( + private EntityCreatorContextData getEntityCreatorContextData( final @NotNull NewEntityDialogData dialogData ) { final String entityName = dialogData.getEntityName(); @@ -351,7 +352,7 @@ private EntityManagerContextData getEntityManagerContextData( ControllerBackendPhp.DEFAULT_DIR + File.separator + entityName ); - return new EntityManagerContextData( + return new EntityCreatorContextData( project, moduleName, ACTION_NAME, @@ -402,7 +403,7 @@ private void formatProperties() { * * @return String */ - public String getFormName() { + private String getFormName() { return formName.getText().trim(); } @@ -411,7 +412,7 @@ public String getFormName() { * * @return List[UiComponentFormFieldsetData] */ - public List getFieldSets() { + private List getFieldSets() { final ArrayList fieldSets = new ArrayList<>(); final UiComponentFormFieldsetData fieldsetData = new UiComponentFormFieldsetData( "general", @@ -428,7 +429,7 @@ public List getFieldSets() { * * @return List[UiComponentFormButtonData] */ - protected List getButtons() { + private List getButtons() { final List buttons = new ArrayList<>(); final String directory = "Block/Form"; @@ -490,7 +491,7 @@ protected List getButtons() { * * @return List[UiComponentFormFieldData] */ - public List getFields() { + private List getFields() { final DefaultTableModel model = getPropertiesTable(); final ArrayList fieldsets = new ArrayList<>(); 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 index a778277ff..9210d73da 100644 --- 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 @@ -33,7 +33,7 @@ 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.EntityManagerContextData; +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; @@ -79,13 +79,13 @@ private NewEntityGeneratorsProviderUtil() {} * Generators initializing excluded from dialog to better test coverage. * * @param generatorPoolHandler GeneratorPoolHandler - * @param context EntityManagerContextData + * @param context EntityCreatorContextData * @param dialogData NewEntityDialogData */ @SuppressWarnings("PMD.ExcessiveMethodLength") public static void initializeGenerators( final @NotNull GeneratorPoolHandler generatorPoolHandler, - final @NotNull EntityManagerContextData context, + final @NotNull EntityCreatorContextData context, final @NotNull NewEntityDialogData dialogData ) { generatorPoolHandler 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 index f0a1afa70..a1a1505e0 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/pool/NewEntityGeneratorPoolTest.java @@ -5,7 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.generator.pool; -import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityManagerContextData; +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; @@ -26,7 +26,7 @@ public class NewEntityGeneratorPoolTest extends BaseGeneratorTestCase { */ public void testGeneratorsInPoolInstantiating() { final NewEntityDialogData dialogData = getMockNewEntityDialogData(); - final EntityManagerContextData contextData = getMockContext(); + final EntityCreatorContextData contextData = getMockContext(); final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(contextData); NewEntityGeneratorsProviderUtil.initializeGenerators( @@ -46,7 +46,7 @@ public void testGeneratorsInPoolInstantiating() { */ public void testGeneratorsInPoolOnCorrectDtoConverterTypes() { final NewEntityDialogData dialogData = getMockNewEntityDialogData(); - final EntityManagerContextData contextData = getMockContext(); + final EntityCreatorContextData contextData = getMockContext(); final GeneratorPoolHandler generatorPoolHandler = new GeneratorPoolHandler(contextData); NewEntityGeneratorsProviderUtil.initializeGenerators( @@ -99,18 +99,18 @@ private NewEntityDialogData getMockNewEntityDialogData() { } /** - * Get mocked entity manager context data. + * Get mocked entity creator context data. * - * @return EntityManagerContextData + * @return EntityCreatorContextData */ - private EntityManagerContextData getMockContext() { + private EntityCreatorContextData getMockContext() { final NamespaceBuilder mockNamespace = new NamespaceBuilder( MODULE_NAME, "MockClass", "Mock/Directory" ); - return new EntityManagerContextData( + return new EntityCreatorContextData( this.myFixture.getProject(), MODULE_NAME, ACTION_NAME, From d9ddba617798806169724c584f83d20c0b28fc96 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Mar 2021 11:26:46 +0200 Subject: [PATCH 60/84] Removed unused import --- .../actions/generation/dialog/NewEntityDialog.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index ddda13616..06332080d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -57,7 +57,6 @@ 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; From 94e4d804a4bd66ffcf179bf9eae757624695ef97 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Mar 2021 12:31:37 +0200 Subject: [PATCH 61/84] Generalized message for the user --- .../generator/pool/GeneratorPoolHandler.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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 index cc3e03aa8..55648813a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorPoolHandler.java @@ -163,18 +163,15 @@ public boolean hasErrorMessages() { /** * Show error messages for the user. - * Those errors are system and must be processed by the dev during the testing. - * They cannot go to live. */ private void showErrorMessages() { if (!errors.isEmpty()) { final String title = this.exceptionBundle.message( - "exception.common.checkLogg" + "exception.common.title" + ); + final String errorMessage = this.exceptionBundle.message( + "exception.common.informUs" ); - final AtomicInteger messageNum = new AtomicInteger(1); - final String errorMessage = errors.stream() - .map(message -> messageNum.getAndIncrement() + ". " + message) - .collect(Collectors.joining("\n")); JOptionPane.showMessageDialog( null, From 32e57c9f637191896137f16546961a9a0c6fa4c0 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Mar 2021 12:32:43 +0200 Subject: [PATCH 62/84] Updated messages --- resources/magento2/exception.properties | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/magento2/exception.properties b/resources/magento2/exception.properties index dead840c7..14412aa7a 100644 --- a/resources/magento2/exception.properties +++ b/resources/magento2/exception.properties @@ -1,3 +1,4 @@ -exception.common.checkLogg=Please, check logging console to get full exception stack trace. +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}. You should implement it. +exception.NoSuchMethod=Method {0} not found for class {1}. From 8c00b0c3d0d7a78645b9f4409ad9d981764118ce Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Mon, 15 Mar 2021 14:27:07 +0200 Subject: [PATCH 63/84] Enhanced UX with generation process, generation in the separate thread (non blocking UI), fixed multiple action listener firing --- .../generation/dialog/NewEntityDialog.java | 42 ++++++- .../generation/dialog/util/ProcessWorker.java | 118 ++++++++++++++++++ 2 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 06332080d..872a7b36c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -17,6 +17,7 @@ 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.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.rule.AclResourceIdRule; @@ -57,6 +58,7 @@ 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; @@ -184,6 +186,7 @@ public class NewEntityDialog extends AbstractDialog { private JTextPane exampleGridName; private JPanel uiComponentsPanel; private JTextField observerName; + private final ProcessWorker.InProgressFlag onOkActionFired; /** * Constructor. @@ -203,7 +206,8 @@ public NewEntityDialog(final @NotNull Project project, final PsiDirectory direct setTitle(NewEntityAction.ACTION_DESCRIPTION); getRootPane().setDefaultButton(buttonOK); - buttonOK.addActionListener((final ActionEvent event) -> onOK()); + onOkActionFired = new ProcessWorker.InProgressFlag(false); + buttonOK.addActionListener(this::generateNewEntityFiles); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); // call onCancel() when cross is clicked @@ -294,13 +298,35 @@ private void initPropertiesTable() { 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); + + 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(); @@ -315,8 +341,20 @@ private void onOK() { ); 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); - this.setVisible(false); + if (onOkActionFired.isFinished()) { + this.setVisible(false); + } } /** 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..28bf02c3b --- /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 isFinished; + + /** + * In progress flag constructor. + * + * @param inProgress boolean + */ + public InProgressFlag(final boolean inProgress) { + this.inProgress = inProgress; + isFinished = 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 isFinished; + } + + /** + * Set is progress finished flag value. + * + * @param finished boolean + */ + public void setFinished(boolean finished) { + isFinished = finished; + } + } +} From 1ca8d8d405e0cf7f9234219652c2bc222dda8077 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 17 Mar 2021 12:29:32 +0200 Subject: [PATCH 64/84] Enhanced Model, Resource Model, Collection generation, fixed collection path bug, added PhpClassTypesBuilder, added new testcases testing --- .../generation/data/CollectionData.java | 71 +---- .../actions/generation/data/ModelData.java | 42 +-- .../generation/data/ResourceModelData.java | 29 +-- .../CollectionModelDtoConverter.java | 11 +- .../newentitydialog/ModelDtoConverter.java | 5 +- .../ResourceModelDtoConverter.java | 4 +- .../generation/dialog/NewModelsDialog.java | 221 ++++++++-------- .../generator/ModuleCollectionGenerator.java | 134 +++++----- .../generator/ModuleModelGenerator.java | 96 +++---- .../ModuleResourceModelGenerator.java | 76 +++--- .../generator/util/PhpClassGeneratorUtil.java | 7 +- .../generator/util/PhpClassTypesBuilder.java | 244 ++++++++++++++++++ .../magento/files/CollectionModelFile.java | 25 +- .../magento/files/ModelFile.java | 16 +- .../magento/files/ResourceModelFile.java | 16 +- .../generateFile/TestCollection.php | 2 +- .../Collection.php | 23 ++ .../Test.php | 22 ++ .../ModuleCollectionGeneratorTest.java | 36 ++- .../generator/ModuleModelGeneratorTest.java | 35 ++- .../ModuleResourceModelGeneratorTest.java | 13 +- 21 files changed, 680 insertions(+), 448 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/util/PhpClassTypesBuilder.java create mode 100644 testData/actions/generation/generator/ModuleCollectionGenerator/generateWithTheSameNamesForResourceModelAndModel/Collection.php create mode 100644 testData/actions/generation/generator/ModuleModelGenerator/generateWithTheSameNameForResourceModel/Test.php 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/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/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/converter/newentitydialog/CollectionModelDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/CollectionModelDtoConverter.java index d8bbf09fd..c20fe1c3c 100644 --- 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 @@ -9,8 +9,6 @@ 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.ResourceModelFile; -import com.magento.idea.magento2plugin.magento.packages.File; import org.jetbrains.annotations.NotNull; public class CollectionModelDtoConverter extends CollectionData implements DataObjectConverter { @@ -29,14 +27,9 @@ public CollectionModelDtoConverter( generationContextData.getModuleName(), newEntityDialogData.getTableName(), newEntityDialogData.getEntityName().concat("Model"), - newEntityDialogData.getEntityName().concat("Collection"), - generationContextData.getCollectionModelNamespaceBuilder().getClassFqn(), - ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator - + newEntityDialogData.getEntityName(), - generationContextData.getCollectionModelNamespaceBuilder().getNamespace(), newEntityDialogData.getEntityName().concat("Resource"), - generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), - generationContextData.getModelNamespaceBuilder().getClassFqn() + newEntityDialogData.getEntityName().concat("Collection"), + newEntityDialogData.getEntityName().concat("Model") ); } } 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 index 71340d379..2d61484fc 100644 --- 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 @@ -27,10 +27,7 @@ public ModelDtoConverter( generationContextData.getModuleName(), newEntityDialogData.getTableName(), newEntityDialogData.getEntityName().concat("Model"), - newEntityDialogData.getEntityName().concat("Resource"), - generationContextData.getModelNamespaceBuilder().getClassFqn(), - generationContextData.getModelNamespaceBuilder().getNamespace(), - generationContextData.getResourceModelNamespaceBuilder().getClassFqn() + newEntityDialogData.getEntityName().concat("Resource") ); } } 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 index 926da405d..fa47a527b 100644 --- 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 @@ -27,9 +27,7 @@ public ResourceModelDtoConverter( generationContextData.getModuleName(), newEntityDialogData.getTableName(), newEntityDialogData.getEntityName().concat("Resource"), - newEntityDialogData.getIdFieldName(), - generationContextData.getResourceModelNamespaceBuilder().getNamespace(), - generationContextData.getResourceModelNamespaceBuilder().getClassFqn() + newEntityDialogData.getIdFieldName() ); } } 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 c6355a489..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.ModelFile; -import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; -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 ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator - + collectionDirectory.getText().trim(); - } - - private NamespaceBuilder getModelNamespace() { - return new NamespaceBuilder(getModuleName(), getModelName(), ModelFile.MODEL_DIRECTORY); - } - - private NamespaceBuilder getResourceModelNamespace() { - return new NamespaceBuilder( - getModuleName(), - getResourceModelName(), - ResourceModelFile.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/generator/ModuleCollectionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java index a6226100b..7431648ef 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleCollectionGenerator.java @@ -15,60 +15,68 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; 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.CollectionModelFile; -import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.files.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; 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 java.util.Properties; import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; public class ModuleCollectionGenerator extends FileGenerator { - private final CollectionData collectionData; + + private final CollectionData data; private final Project project; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; private final GetFirstClassOfFile getFirstClassOfFile; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final CollectionModelFile file; /** * 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.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.validatorBundle = new ValidatorBundle(); this.commonBundle = new CommonBundle(); + file = new CollectionModelFile(data.getCollectionName()); } /** * Generates collection model class. * * @param actionName Action name + * * @return PsiFile */ - public PsiFile generate(final String actionName) { + @Override + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] collectionFiles = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass collection = GetPhpClassByFQN.getInstance(project).execute( - getCollectionModelFqn() + file.getNamespaceBuilder( + data.getModuleName(), + data.getCollectionDirectory() + ).getClassFqn() ); if (collection != null) { @@ -110,37 +118,27 @@ public PsiFile generate(final String actionName) { } /** - * Get controller module. + * Create collection class. + * + * @param actionName String * - * @return String + * @return PhpClass */ - public String getModuleName() { - return collectionData.getModuleName(); - } - - private String getCollectionModelFqn() { - return collectionData.getCollectionFqn(); - } - - private PhpClass createClass(final String actionName) { - PsiDirectory parentDirectory = ModuleIndex.getInstance(project) - .getModuleDirectoryByModuleName(getModuleName()); + private PhpClass createClass(final @NotNull String actionName) { + final PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + .getModuleDirectoryByModuleName(data.getModuleName()); final PsiFile modelFile; - final String[] collectionDirectories = collectionData.getCollectionDirectory().split( - File.separator + final PsiDirectory collectionDirectory = directoryGenerator.findOrCreateSubdirectories( + parentDirectory, + file.getDirectory(data.getCollectionDirectory()) ); - for (final String directory: collectionDirectories) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } - final Properties attributes = getAttributes(); + modelFile = fileFromTemplateGenerator.generate( - new CollectionModelFile(collectionData.getCollectionName()), + file, attributes, - parentDirectory, + collectionDirectory, actionName ); @@ -151,32 +149,52 @@ private PhpClass createClass(final String actionName) { 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()); + /** + * Fill collection model file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + final ResourceModelFile resourceModelFile = + new ResourceModelFile(data.getResourceModelName()); + final ModelFile modelFile = new ModelFile(data.getModelName()); + + phpClassTypesBuilder.appendProperty("NAME", data.getCollectionName()) + .appendProperty( + "NAMESPACE", + file.getNamespaceBuilder( + data.getModuleName(), + data.getCollectionDirectory() + ).getNamespace() + ) + .appendProperty("DB_NAME", data.getDbTableName()) + .appendProperty("MODEL", data.getModelName()) + .appendProperty("RESOURCE_MODEL", data.getResourceModelName()) + .append("EXTENDS", CollectionModelFile.ABSTRACT_COLLECTION) + .append( + "RESOURCE_MODEL", + resourceModelFile.getNamespaceBuilder( + data.getModuleName() + ).getClassFqn(), + ResourceModelFile.ALIAS + ) + .append( + "MODEL", + modelFile.getNamespaceBuilder( + data.getModuleName() + ).getClassFqn(), + ModelFile.ALIAS + ) + .mergeProperties(attributes); attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn(CollectionModelFile.ABSTRACT_COLLECTION) + "USES", + PhpClassGeneratorUtil.formatUses( + phpClassTypesBuilder.getUses() + ) ); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - - private List getUses() { - return new ArrayList<>(Arrays.asList( - CollectionModelFile.ABSTRACT_COLLECTION - )); } } 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 6431fab9c..993f00198 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java @@ -15,59 +15,63 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; 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.ModelFile; +import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; 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 java.util.Properties; import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; public class ModuleModelGenerator extends FileGenerator { - private final ModelData modelData; + private final ModelData data; private final Project project; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; private final GetFirstClassOfFile getFirstClassOfFile; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final ModelFile file; /** * 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.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.validatorBundle = new ValidatorBundle(); this.commonBundle = new CommonBundle(); + file = new ModelFile(data.getModelName()); } /** * Generates model class. * * @param actionName Action name + * * @return PsiFile */ - public PsiFile generate(final String actionName) { + @Override + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] modelFiles = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass model = GetPhpClassByFQN.getInstance(project).execute( - getModelFqn() + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (model != null) { @@ -109,21 +113,15 @@ public PsiFile generate(final String actionName) { } /** - * Get module. + * Create model class. + * + * @param actionName String * - * @return String + * @return PhpClass */ - public String getModuleName() { - return modelData.getModuleName(); - } - - private String getModelFqn() { - return modelData.getFqn(); - } - - private PhpClass createModelClass(final String actionName) { + private PhpClass createModelClass(final @NotNull String actionName) { PsiDirectory parentDirectory = ModuleIndex.getInstance(project) - .getModuleDirectoryByModuleName(getModuleName()); + .getModuleDirectoryByModuleName(data.getModuleName()); final PsiFile modelFile; parentDirectory = directoryGenerator.findOrCreateSubdirectory( @@ -132,7 +130,7 @@ private PhpClass createModelClass(final String actionName) { final Properties attributes = getAttributes(); modelFile = fileFromTemplateGenerator.generate( - new ModelFile(modelData.getModelName()), + file, attributes, parentDirectory, actionName @@ -145,26 +143,36 @@ private PhpClass createModelClass(final String actionName) { 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(ModelFile.ABSTRACT_MODEL) - ); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - - private List getUses() { - return new ArrayList<>(Arrays.asList( - ModelFile.ABSTRACT_MODEL, - modelData.getResourceModelFqn() - )); + /** + * Fill model file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final ResourceModelFile resourceModelFile = new ResourceModelFile(data.getResourceName()); + + phpClassTypesBuilder + .appendProperty("NAME", data.getModelName()) + .appendProperty( + "NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).getNamespace() + ) + .appendProperty("DB_NAME", data.getDbTableName()) + .append( + "RESOURCE_MODEL", + resourceModelFile.getNamespaceBuilder(data.getModuleName()).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 1bbf4c128..4ff077f97 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleResourceModelGenerator.java @@ -15,6 +15,7 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.bundles.CommonBundle; import com.magento.idea.magento2plugin.bundles.ValidatorBundle; import com.magento.idea.magento2plugin.indexes.ModuleIndex; @@ -22,13 +23,13 @@ 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 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; @@ -36,6 +37,7 @@ public class ModuleResourceModelGenerator extends FileGenerator { private final GetFirstClassOfFile getFirstClassOfFile; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final ResourceModelFile file; /** * Generates new Resource Model PHP Class based on provided data. @@ -55,20 +57,24 @@ public ModuleResourceModelGenerator( this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.validatorBundle = new ValidatorBundle(); this.commonBundle = new CommonBundle(); + file = new ResourceModelFile(resourceModelData.getResourceModelName()); + } /** * Generates resource model class. * * @param actionName Action name + * * @return PsiFile */ - public PsiFile generate(final String actionName) { + @Override + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] resourceModelFiles = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass resourceModel = GetPhpClassByFQN.getInstance(project).execute( - getResourceModelFqn() + file.getNamespaceBuilder(resourceModelData.getModuleName()).getClassFqn() ); if (resourceModel != null) { @@ -110,21 +116,15 @@ public PsiFile generate(final String actionName) { } /** - * Get module. + * Create resource model class. * - * @return String + * @param actionName String + * + * @return PhpClass */ - public String getModuleName() { - return resourceModelData.getModuleName(); - } - - private String getResourceModelFqn() { - return resourceModelData.getFqn(); - } - - private PhpClass createClass(final String actionName) { + private PhpClass createClass(final @NotNull String actionName) { PsiDirectory parentDirectory = ModuleIndex.getInstance(project) - .getModuleDirectoryByModuleName(getModuleName()); + .getModuleDirectoryByModuleName(resourceModelData.getModuleName()); final PsiFile modelFile; final String[] resourceModelDirectories = ResourceModelFile.RESOURCE_MODEL_DIRECTORY.split( @@ -138,7 +138,7 @@ private PhpClass createClass(final String actionName) { final Properties attributes = getAttributes(); modelFile = fileFromTemplateGenerator.generate( - new ResourceModelFile(resourceModelData.getResourceModelName()), + file, attributes, parentDirectory, actionName @@ -151,27 +151,27 @@ private PhpClass createClass(final String actionName) { 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(ResourceModelFile.ABSTRACT_DB) - ); - + /** + * Fill resource model file attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAME", resourceModelData.getResourceModelName()) + .appendProperty( + "NAMESPACE", + file.getNamespaceBuilder(resourceModelData.getModuleName()).getNamespace() + ) + .appendProperty("DB_NAME", resourceModelData.getDbTableName()) + .appendProperty("ENTITY_ID_COLUMN", resourceModelData.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( - ResourceModelFile.ABSTRACT_DB - )); - } } 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/magento/files/CollectionModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java index 423b41c7a..d9061ec67 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/CollectionModelFile.java @@ -13,6 +13,7 @@ public class CollectionModelFile extends AbstractPhpClass { public static final String TEMPLATE = "Magento Collection Class"; public static final String ABSTRACT_COLLECTION = "Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection"; + private NamespaceBuilder namespaceBuilder; public CollectionModelFile(final @NotNull String className) { super(className); @@ -22,30 +23,34 @@ public CollectionModelFile(final @NotNull String className) { * Get namespace builder for file. * * @param moduleName String - * @param entityName String + * @param directoryName String * * @return String */ public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName, - final @NotNull String entityName + final @NotNull String directoryName ) { - return new NamespaceBuilder( - moduleName, - getClassName(), - getDirectory(entityName) - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + getClassName(), + getDirectory(directoryName) + ); + } + + return namespaceBuilder; } /** * Get collection file directory. * - * @param entityName String + * @param directoryName String * * @return String */ - public @NotNull String getDirectory(final @NotNull String entityName) { - return ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + entityName; + public @NotNull String getDirectory(final @NotNull String directoryName) { + return ResourceModelFile.RESOURCE_MODEL_DIRECTORY + File.separator + directoryName; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java index cac59c6e4..14d064008 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java @@ -13,6 +13,8 @@ public class ModelFile extends AbstractPhpClass { "Magento\\Framework\\Model\\AbstractModel"; public static final String MODEL_DIRECTORY = "Model"; public static final String TEMPLATE = "Magento Model Class"; + public static final String ALIAS = "Model"; + private NamespaceBuilder namespaceBuilder; public ModelFile(final String className) { super(className); @@ -28,11 +30,15 @@ public ModelFile(final String className) { public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - getClassName(), - MODEL_DIRECTORY - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + getClassName(), + MODEL_DIRECTORY + ); + } + + return namespaceBuilder; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java index 79ad22fc9..9ab7309b1 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ResourceModelFile.java @@ -13,6 +13,8 @@ public class ResourceModelFile extends AbstractPhpClass { public static final String TEMPLATE = "Magento Resource Model Class"; public static final String ABSTRACT_DB = "Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb"; + public static final String ALIAS = "ResourceModel"; + private NamespaceBuilder namespaceBuilder; public ResourceModelFile(final @NotNull String className) { super(className); @@ -28,11 +30,15 @@ public ResourceModelFile(final @NotNull String className) { public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - getClassName(), - RESOURCE_MODEL_DIRECTORY - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + getClassName(), + RESOURCE_MODEL_DIRECTORY + ); + } + + return namespaceBuilder; } @Override 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/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 ); } } From 8921267e679441ad693aadc5c636d853bd151324 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 19 Mar 2021 16:45:37 +0200 Subject: [PATCH 65/84] Enhanced and refactored bunch of generators and all related files and their testcases --- .../generation/data/DataModelData.java | 47 ++---- .../data/DataModelInterfaceData.java | 44 +++-- .../generation/data/EntityDataMapperData.java | 58 ++++--- .../data/GetListQueryModelData.java | 40 ++--- ...tyActionData.java => IndexActionData.java} | 30 +--- .../data/PreferenceDiXmFileData.java | 39 ++--- .../data/UiComponentDataProviderData.java | 26 ++- .../DataModelDtoConverter.java | 4 +- .../DataModelInterfaceDtoConverter.java | 3 +- .../DataProviderDtoConverter.java | 3 +- .../EntityDataMapperDtoConverter.java | 8 +- .../GetListQueryDtoConverter.java | 4 +- ...rter.java => IndexActionDtoConverter.java} | 9 +- .../PreferenceDiXmlFileDtoConverter.java | 2 +- .../generation/dialog/NewDataModelDialog.java | 129 +++++++------- .../generation/dialog/NewEntityDialog.java | 5 +- .../dialog/NewUiComponentFormDialog.java | 51 ++++-- .../dialog/NewUiComponentGridDialog.java | 46 +++-- .../OverrideClassByAPreferenceDialog.java | 8 +- .../generator/DataModelGenerator.java | 127 ++++++++------ .../DataModelInterfaceGenerator.java | 75 +++++---- .../generator/EntityDataMapperGenerator.java | 96 ++++++----- .../generator/GetListQueryModelGenerator.java | 125 +++++++------- ...nerator.java => IndexActionGenerator.java} | 68 ++++---- .../generator/PreferenceDiXmlGenerator.java | 43 +++-- .../generation/generator/QueryGenerator.java | 76 ++++----- .../generator/SaveEntityCommandGenerator.java | 86 ++++------ .../UiComponentDataProviderGenerator.java | 159 ++++++------------ .../DataModelInterfaceGeneratorHandler.java | 4 +- ....java => IndexActionGeneratorHandler.java} | 14 +- .../NewEntityGeneratorsProviderUtil.java | 8 +- .../magento/files/DataModelFile.java | 15 +- .../magento/files/EntityDataMapperFile.java | 37 ++-- .../files/UiComponentDataProviderFile.java | 53 ++---- .../files/actions/IndexActionFile.java | 16 +- ...etListQuery.java => GetListQueryFile.java} | 52 +++--- .../generateIndexControllerFile}/Index.php | 0 .../GetListQuery.php | 2 +- .../GridDataProvider.php | 2 +- .../GridDataProvider.php | 4 +- .../generator/DataModelGeneratorTest.java | 15 +- .../DataModelInterfaceGeneratorTest.java | 28 ++- .../EntityDataMapperClassGeneratorTest.java | 16 +- ...java => IndexControllerGeneratorTest.java} | 17 +- .../PreferenceDiXmlGeneratorTest.java | 5 +- .../generator/QueryModelGeneratorTest.java | 20 +-- ...omponentGridDataProviderGeneratorTest.java | 42 ++--- 47 files changed, 848 insertions(+), 913 deletions(-) rename src/com/magento/idea/magento2plugin/actions/generation/data/{AdminListViewEntityActionData.java => IndexActionData.java} (69%) rename src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/{EntityListActionDtoConverter.java => IndexActionDtoConverter.java} (71%) rename src/com/magento/idea/magento2plugin/actions/generation/generator/{AdminListViewEntityActionGenerator.java => IndexActionGenerator.java} (65%) rename src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/{EntityListActionGeneratorHandler.java => IndexActionGeneratorHandler.java} (79%) rename src/com/magento/idea/magento2plugin/magento/files/queries/{GetListQuery.java => GetListQueryFile.java} (51%) rename testData/actions/generation/generator/{AdminListViewEntityControllerGenerator/generateListViewControllerFile => IndexControllerGenerator/generateIndexControllerFile}/Index.php (100%) rename tests/com/magento/idea/magento2plugin/actions/generation/generator/{AdminListViewEntityControllerGeneratorTest.java => IndexControllerGeneratorTest.java} (59%) 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/EntityDataMapperData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java index 197c29b18..1ce9e75e1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java @@ -8,36 +8,38 @@ import org.jetbrains.annotations.NotNull; public class EntityDataMapperData { + private final String moduleName; private final String entityName; - private final String namespace; - private final String classFqn; - private final String modelClassFqn; - private final String dataModelClassFqn; + private final String modelName; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean isDtoWithInterface; /** * Magento entity data mapper data constructor. * * @param moduleName String * @param entityName String - * @param namespace String - * @param modelClassFqn String - * @param dataModelClassFqn 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 namespace, - final @NotNull String classFqn, - final @NotNull String modelClassFqn, - final @NotNull String dataModelClassFqn + final @NotNull String modelName, + final @NotNull String dtoName, + final @NotNull String dtoInterfaceName, + final boolean isDtoWithInterface ) { this.moduleName = moduleName; this.entityName = entityName; - this.namespace = namespace; - this.classFqn = classFqn; - this.modelClassFqn = modelClassFqn; - this.dataModelClassFqn = dataModelClassFqn; + this.modelName = modelName; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.isDtoWithInterface = isDtoWithInterface; } /** @@ -59,38 +61,38 @@ public String getEntityName() { } /** - * Get namespace. + * Get model name. * * @return String */ - public String getNamespace() { - return namespace; + public String getModelName() { + return modelName; } /** - * Get class fqn. + * Get DTO name. * * @return String */ - public String getClassFqn() { - return classFqn; + public String getDtoName() { + return dtoName; } /** - * Get model class fqn. + * Get DTO interface name. * * @return String */ - public String getModelClassFqn() { - return modelClassFqn; + public String getDtoInterfaceName() { + return dtoInterfaceName; } /** - * Get data model class fqn. + * Check if DTO has interface. * - * @return String + * @return boolean */ - public String getDataModelClassFqn() { - return dataModelClassFqn; + public boolean isDtoWithInterface() { + return isDtoWithInterface; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java index 41178ecbb..882f433aa 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java @@ -8,31 +8,30 @@ import org.jetbrains.annotations.NotNull; public class GetListQueryModelData { + private final String moduleName; private final String entityName; - private final String collectionType; - private final String collectionTypeFactory; - private final String entityDataMapperType; + private final String modelName; + private final String collectionName; /** * Query Model DTO Constructor. * * @param moduleName String * @param entityName String - * @param collectionType String - * @param entityDataMapperType String + * @param modelName String + * @param collectionName String */ public GetListQueryModelData( final @NotNull String moduleName, final @NotNull String entityName, - final @NotNull String collectionType, - final @NotNull String entityDataMapperType + final @NotNull String modelName, + final @NotNull String collectionName ) { this.moduleName = moduleName; this.entityName = entityName; - this.collectionType = collectionType; - this.collectionTypeFactory = collectionType.concat("Factory"); - this.entityDataMapperType = entityDataMapperType; + this.modelName = modelName; + this.collectionName = collectionName; } /** @@ -54,29 +53,20 @@ public String getEntityName() { } /** - * Get entity collection type. - * - * @return String - */ - public String getCollectionType() { - return collectionType; - } - - /** - * Get entity collection type factory. + * Get model name. * * @return String */ - public String getCollectionTypeFactory() { - return collectionTypeFactory; + public String getModelName() { + return modelName; } /** - * Get entity data mapper type. + * Get entity collection name. * * @return String */ - public String getEntityDataMapperType() { - return entityDataMapperType; + public String getCollectionName() { + return collectionName; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java similarity index 69% rename from src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java rename to src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java index f52382111..33258c784 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/AdminListViewEntityActionData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/IndexActionData.java @@ -7,11 +7,10 @@ import org.jetbrains.annotations.NotNull; -public class AdminListViewEntityActionData { +public class IndexActionData { + private final String moduleName; private final String entityName; - private final String namespace; - private final String classFqn; private final String acl; private final String menu; @@ -20,22 +19,17 @@ public class AdminListViewEntityActionData { * * @param moduleName String * @param entityName String - * @param namespace String * @param acl String * @param menu String */ - public AdminListViewEntityActionData( + public IndexActionData( final @NotNull String moduleName, final @NotNull String entityName, - final @NotNull String namespace, - final @NotNull String classFqn, final @NotNull String acl, final @NotNull String menu ) { this.moduleName = moduleName; this.entityName = entityName; - this.namespace = namespace; - this.classFqn = classFqn; this.acl = acl; this.menu = menu; } @@ -58,24 +52,6 @@ public String getEntityName() { return entityName; } - /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - - /** - * Get class fqn. - * - * @return String - */ - public String getClassFqn() { - return classFqn; - } - /** * Get ACL resource id. * 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 53b540a8e..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,37 +2,35 @@ * 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 PreferenceDiXmFileData { + private final String preferenceModule; - private final String targetClass; - private final String preferenceFqn; - private final String namespace; + private final String preferenceFor; + private final String preferenceType; private final String area; /** * Preference DI XML file data. * * @param preferenceModule String - * @param targetClass String - * @param preferenceFqn String - * @param namespace String + * @param preferenceFor String + * @param preferenceType String * @param area String */ public PreferenceDiXmFileData( final @NotNull String preferenceModule, - final @NotNull String targetClass, - final @NotNull String preferenceFqn, - final @NotNull String namespace, + 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; } @@ -50,8 +48,8 @@ public String getPreferenceModule() { * * @return String */ - public String getTargetClass() { - return targetClass; + public String getPreferenceFor() { + return preferenceFor; } /** @@ -59,17 +57,8 @@ public String getTargetClass() { * * @return String */ - public String getPreferenceFqn() { - return preferenceFqn; - } - - /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; + public String getPreferenceType() { + return preferenceType; } /** 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 e82cafb20..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,45 +5,43 @@ 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, namespace, path, null); + this(name, path, null, null); } /** * UiComponentGridDataProviderData constructor. * * @param name String - * @param namespace String * @param path String + * @param entityName String * @param entityIdFieldName String */ public UiComponentDataProviderData( final String name, - final String namespace, final String path, + final String entityName, final String entityIdFieldName ) { this.name = name; - this.namespace = namespace; this.path = path; + this.entityName = entityName; this.entityIdFieldName = entityIdFieldName; } @@ -57,21 +55,21 @@ 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; } /** 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 index 33b560504..5d7107faf 100644 --- 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 @@ -24,11 +24,9 @@ public DataModelDtoConverter( final @NotNull NewEntityDialogData newEntityDialogData ) { super( - generationContextData.getDtoModelNamespaceBuilder().getNamespace(), newEntityDialogData.getEntityName().concat("Data"), + newEntityDialogData.getEntityName().concat("Interface"), generationContextData.getModuleName(), - generationContextData.getDtoModelNamespaceBuilder().getClassFqn(), - generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), 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 index bdd6689f9..7e557ede1 100644 --- 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 @@ -16,6 +16,7 @@ public class DataModelInterfaceDtoConverter extends DataModelInterfaceData /** * DTO interface converter. + * * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ @@ -24,10 +25,8 @@ public DataModelInterfaceDtoConverter( final @NotNull NewEntityDialogData newEntityDialogData ) { super( - generationContextData.getDtoInterfaceNamespaceBuilder().getNamespace(), newEntityDialogData.getEntityName().concat("Interface"), generationContextData.getModuleName(), - generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), 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 index 9f5759042..ea11eb0d6 100644 --- 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 @@ -21,14 +21,15 @@ public class DataProviderDtoConverter extends UiComponentDataProviderData * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ + @SuppressWarnings("PMD.UnusedFormalParameter") public DataProviderDtoConverter( final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( newEntityDialogData.getEntityName().concat("DataProvider"), - generationContextData.getDataProviderNamespaceBuilder().getNamespace(), UiComponentDataProviderFile.DIRECTORY, + newEntityDialogData.getEntityName(), newEntityDialogData.getIdFieldName() ); } 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 index 0afa556b0..43458c409 100644 --- 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 @@ -27,10 +27,10 @@ public EntityDataMapperDtoConverter( super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - generationContextData.getEntityDataMapperNamespaceBuilder().getNamespace(), - generationContextData.getEntityDataMapperNamespaceBuilder().getClassFqn(), - generationContextData.getModelNamespaceBuilder().getClassFqn(), - generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn() + 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/GetListQueryDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/GetListQueryDtoConverter.java index 763306684..08acdfbc7 100644 --- 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 @@ -27,8 +27,8 @@ public GetListQueryDtoConverter( super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - generationContextData.getCollectionModelNamespaceBuilder().getClassFqn(), - generationContextData.getEntityDataMapperNamespaceBuilder().getClassFqn() + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Collection") ); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java similarity index 71% rename from src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java rename to src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java index 4b6764803..52efc63e9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/EntityListActionDtoConverter.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/IndexActionDtoConverter.java @@ -5,14 +5,13 @@ package com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog; -import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; +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 EntityListActionDtoConverter extends AdminListViewEntityActionData - implements DataObjectConverter { +public class IndexActionDtoConverter extends IndexActionData implements DataObjectConverter { /** * Entity list action converter. @@ -20,15 +19,13 @@ public class EntityListActionDtoConverter extends AdminListViewEntityActionData * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ - public EntityListActionDtoConverter( + public IndexActionDtoConverter( final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData ) { super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - generationContextData.getEntityListActionNamespaceBuilder().getNamespace(), - generationContextData.getEntityListActionNamespaceBuilder().getClassFqn(), newEntityDialogData.getAclId(), newEntityDialogData.getMenuId() ); 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 index add6f61fa..8fd7b3010 100644 --- 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 @@ -21,6 +21,7 @@ public class PreferenceDiXmlFileDtoConverter extends PreferenceDiXmFileData * @param generationContextData EntityCreatorContextData * @param newEntityDialogData NewEntityDialogData */ + @SuppressWarnings("PMD.UnusedFormalParameter") public PreferenceDiXmlFileDtoConverter( final @NotNull EntityCreatorContextData generationContextData, final @NotNull NewEntityDialogData newEntityDialogData @@ -29,7 +30,6 @@ public PreferenceDiXmlFileDtoConverter( generationContextData.getModuleName(), generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn(), generationContextData.getDtoModelNamespaceBuilder().getClassFqn(), - newEntityDialogData.getEntityName().concat("Model"), Areas.base.toString() ); } 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 89a68299f..f8fbe1af5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -21,7 +21,6 @@ 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.DataModelFile; @@ -30,7 +29,6 @@ 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; @@ -51,17 +49,15 @@ import javax.swing.table.TableColumn; @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"; @@ -131,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); } @@ -148,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"); @@ -190,88 +189,86 @@ 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(), ClassPropertyFormatterUtil.joinProperties(properties) - )).generate(NewDataModelAction.ACTION_NAME, true); + ), 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(), ClassPropertyFormatterUtil.joinProperties(properties), - isInterfaceShouldBeCreated() + createInterface.isSelected() )).generate(NewDataModelAction.ACTION_NAME, true); } - private void generatePreference() { + /** + * Generate preference for interface DTO. + */ + private void generatePreferenceForInterface() { new PreferenceDiXmlGenerator(new PreferenceDiXmFileData( getModuleName(), - getInterfaceFQN(), - getModelFQN(), - getModelNamespace(), + new DataModelInterfaceFile( + getDtoInterfaceName() + ).getNamespaceBuilder(getModuleName()).getClassFqn(), + new DataModelFile( + getDtoModelName() + ).getNamespaceBuilder(getModuleName()).getClassFqn(), "base" ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); } - private void buildNamespaces() { - interfaceNamespace = new NamespaceBuilder( - getModuleName(), getInterfaceName(), DataModelInterfaceFile.DIRECTORY - ); - modelNamespace = new NamespaceBuilder( - getModuleName(), getModelName(), DataModelFile.DIRECTORY - ); - } - /** - * Formats properties into an array of ClassPropertyData objects. + * Get module name. + * + * @return String */ - private void formatProperties() { - properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); - } - - private boolean isInterfaceShouldBeCreated() { - return createInterface.isSelected(); - } - private String getModuleName() { return moduleName; } - private String getInterfaceNamespace() { - return interfaceNamespace.getNamespace(); + /** + * Get DTO model name. + * + * @return String + */ + private String getDtoModelName() { + return modelName.getText().trim(); } - private String getInterfaceName() { + /** + * Get DTO interface name. + * + * @return String + */ + private String getDtoInterfaceName() { return modelName.getText().trim().concat("Interface"); } - private String getInterfaceFQN() { - return interfaceNamespace.getClassFqn(); - } - - private String getModelNamespace() { - return modelNamespace.getNamespace(); - } - - private String getModelName() { - return modelName.getText().trim(); - } - - private String getModelFQN() { - return modelNamespace.getClassFqn(); + /** + * Formats properties into an array of ClassPropertyData objects. + */ + private void formatProperties() { + properties.addAll(ClassPropertyFormatterUtil.formatProperties(getPropertiesTable())); } + /** + * Initialize properties table. + */ private void initPropertiesTable() { final DefaultTableModel propertiesTable = getPropertiesTable(); + propertiesTable.setDataVector( new Object[][]{}, new Object[]{ @@ -297,6 +294,9 @@ private void initPropertiesTable() { initPropertyTypeColumn(); } + /** + * Initialize property type column. + */ private void initPropertyTypeColumn() { final TableColumn formElementTypeColumn = propertyTable.getColumn(PROPERTY_TYPE); formElementTypeColumn.setCellEditor( @@ -307,6 +307,11 @@ private void initPropertyTypeColumn() { ); } + /** + * Get properties table. + * + * @return DefaultTableModel + */ private DefaultTableModel getPropertiesTable() { return (DefaultTableModel) propertyTable.getModel(); } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 872a7b36c..bab4a0ff1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -96,6 +96,7 @@ "PMD.ExcessiveImports" }) public class NewEntityDialog extends AbstractDialog { + private final @NotNull Project project; private final String moduleName; private JPanel contentPane; @@ -405,8 +406,8 @@ private EntityCreatorContextData getEntityCreatorContextData( dtoModelNamespace, dtoInterfaceNamespace, createInterface.isSelected() ? dtoInterfaceNamespace : dtoModelNamespace, - UiComponentDataProviderFile - .getInstance(dataProviderClassName).getNamespaceBuilder(moduleName), + new UiComponentDataProviderFile(dataProviderClassName) + .getNamespaceBuilder(moduleName, null), new IndexActionFile(entityName).getNamespaceBuilder(moduleName), new EntityDataMapperFile(entityName).getNamespaceBuilder(moduleName), SaveEntityCommandFile.getNamespaceBuilder(moduleName, entityName), 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 2a35d094f..4617faa2a 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -418,11 +418,12 @@ 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); } @@ -436,8 +437,11 @@ private NamespaceBuilder getDataProviderNamespace() { ); } - private PsiFile generateFormFile() { - return new UiComponentFormGenerator(new UiComponentFormFileData( + /** + * Generate form file. + */ + private void generateFormFile() { + new UiComponentFormGenerator(new UiComponentFormFileData( getFormName(), getArea(), getModuleName(), @@ -452,21 +456,27 @@ private PsiFile generateFormFile() { ), 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(), @@ -478,13 +488,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(), @@ -496,8 +509,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(), @@ -507,8 +523,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 1c5d4357b..e0e3ef082 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; @@ -256,7 +255,6 @@ public static void open(final Project project, final PsiDirectory directory) { public UiComponentDataProviderData getGridDataProviderData() { return new UiComponentDataProviderData( getDataProviderClass(), - getDataProviderNamespace(), getDataProviderDirectory() ); } @@ -325,14 +323,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,6 +345,9 @@ private void generateUiComponentFile() { gridXmlGenerator.generate(NewUiComponentGridAction.ACTION_NAME, true); } + /** + * Generate data provider class. + */ private void generateDataProviderClass() { if (getDataProviderType().equals(UiComponentDataProviderFile.CUSTOM_TYPE)) { final UiComponentDataProviderGenerator dataProviderGenerator; @@ -353,6 +360,9 @@ private void generateDataProviderClass() { } } + /** + * Generate data provider declaration. + */ private void generateDataProviderDeclaration() { if (getDataProviderType().equals(UiComponentDataProviderFile.COLLECTION_TYPE)) { final DataProviderDeclarationGenerator dataProviderGenerator; @@ -368,13 +378,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 +399,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 +413,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 +428,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() 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 81bff2daf..5cd36c2b2 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; @@ -167,7 +170,6 @@ protected void onOK() { getPreferenceModule(), targetClass.getPresentableFQN(), getPreferenceClassFqn(), - getNamespace(), getPreferenceArea() ), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME); if (diXml == null) { 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 2cf82170c..856e05311 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java @@ -15,54 +15,63 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; 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.DataModelFile; +import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.LinkedList; -import java.util.List; 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 DataModelData data; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final GetFirstClassOfFile getFirstClassOfFile; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; + private final DataModelFile file; /** - * Constructor. + * Data model generator constructor. + * + * @param project Project + * @param data DataModelData */ - public DataModelGenerator(final Project project, final DataModelData modelData) { + public DataModelGenerator( + final @NotNull Project project, + final @NotNull DataModelData data + ) { super(project); - this.project = project; - this.modelData = modelData; + this.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.validatorBundle = new ValidatorBundle(); this.commonBundle = new CommonBundle(); + file = new DataModelFile(data.getName()); } @Override - public PsiFile generate(final String actionName) { + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] files = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass model = GetPhpClassByFQN.getInstance(project).execute( - modelData.getFQN() + PhpClass dataModel = GetPhpClassByFQN.getInstance(project).execute( + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); - if (model == null) { - model = createModel(actionName); + if (dataModel == null) { + dataModel = createModel(actionName); - if (model == null) { + if (dataModel == null) { final String errorMessage = this.validatorBundle.message( "validator.file.cantBeCreated", "Data Model" @@ -74,7 +83,7 @@ public PsiFile generate(final String actionName) { JOptionPane.ERROR_MESSAGE ); } else { - files[0] = model.getContainingFile(); + files[0] = dataModel.getContainingFile(); } } else { final String errorMessage = this.validatorBundle.message( @@ -93,53 +102,63 @@ public PsiFile generate(final String actionName) { return files[0]; } - @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(DataModelFile.DATA_OBJECT) - ); - attributes.setProperty( - "IMPLEMENTS", - PhpClassGeneratorUtil.getNameFromFqn(modelData.getInterfaceFQN()) + /** + * Create model class. + * + * @param actionName String + * + * @return PhpClass + */ + private PhpClass createModel(final @NotNull String actionName) { + final PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + .getModuleDirectoryByModuleName(data.getModuleName()); + final PsiDirectory dataModelDirectory = directoryGenerator.findOrCreateSubdirectories( + parentDirectory, + DataModelFile.DIRECTORY ); - attributes.setProperty("PROPERTIES", modelData.getProperties()); - attributes.setProperty("HASINTERFACE", Boolean.toString(modelData.hasInterface())); - } - private List getUses() { - final List usesList = new LinkedList<>(); - usesList.add(DataModelFile.DATA_OBJECT); + final PsiFile dataModelFile = fileFromTemplateGenerator.generate( + file, + getAttributes(), + dataModelDirectory, + actionName + ); - if (modelData.hasInterface()) { - usesList.add(modelData.getInterfaceFQN()); - } - return usesList; + return dataModelFile == null ? null : getFirstClassOfFile.execute((PhpFile) dataModelFile); } - private PhpClass createModel(final String actionName) { - PsiDirectory parentDirectory = ModuleIndex.getInstance(project) - .getModuleDirectoryByModuleName(modelData.getModuleName()); - final PsiFile interfaceFile; - final Properties attributes = getAttributes(); - - for (final String directory: DataModelFile.DIRECTORY.split("/")) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); + /** + * 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.getNamespaceBuilder(data.getModuleName()).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.getInterfaceName() + ).getNamespaceBuilder(data.getModuleName()).getClassFqn()); } - interfaceFile = fileFromTemplateGenerator.generate( - new DataModelFile(modelData.getName()), - attributes, - parentDirectory, - actionName - ); + phpClassTypesBuilder.mergeProperties(attributes); - return interfaceFile == null ? null : getFirstClassOfFile.execute((PhpFile) interfaceFile); + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); } } 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 33cdde120..ba1f55ebc 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGenerator.java @@ -22,32 +22,38 @@ import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; 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 DataModelInterfaceData data; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final GetFirstClassOfFile getFirstClassOfFile; private final ValidatorBundle validatorBundle; private final CommonBundle commonBundle; + private final DataModelInterfaceFile file; /** - * 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.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.validatorBundle = new ValidatorBundle(); this.commonBundle = new CommonBundle(); + file = new DataModelInterfaceFile(data.getName()); } @Override @@ -56,7 +62,7 @@ public PsiFile generate(final String actionName) { WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass modelInterface = GetPhpClassByFQN.getInstance(project).execute( - interfaceData.getFQN() + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (modelInterface == null) { @@ -93,32 +99,41 @@ public PsiFile generate(final String actionName) { return files[0]; } - @Override - protected void fillAttributes(final Properties attributes) { - attributes.setProperty("NAME", interfaceData.getName()); - attributes.setProperty("NAMESPACE", interfaceData.getNamespace()); - attributes.setProperty("PROPERTIES", interfaceData.getProperties()); - } - - private PhpClass createInterface(final String actionName) { - PsiDirectory parentDirectory = ModuleIndex.getInstance(project) - .getModuleDirectoryByModuleName(interfaceData.getModuleName()); - final PsiFile interfaceFile; - final Properties attributes = getAttributes(); - - for (final String directory: DataModelInterfaceFile.DIRECTORY.split("/")) { - parentDirectory = directoryGenerator.findOrCreateSubdirectory( - parentDirectory, directory - ); - } + /** + * Create DTO interface file. + * + * @param actionName String + * + * @return PhpClass + */ + private PhpClass createInterface(final @NotNull String actionName) { + final PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + .getModuleDirectoryByModuleName(data.getModuleName()); + final PsiDirectory dtoInterfaceDirectory = directoryGenerator + .findOrCreateSubdirectories(parentDirectory, DataModelInterfaceFile.DIRECTORY); - interfaceFile = fileFromTemplateGenerator.generate( - new DataModelInterfaceFile(interfaceData.getName()), - attributes, - parentDirectory, + final PsiFile dtoInterfaceFile = fileFromTemplateGenerator.generate( + file, + getAttributes(), + dtoInterfaceDirectory, actionName ); - return interfaceFile == null ? null : getFirstClassOfFile.execute((PhpFile) interfaceFile); + return dtoInterfaceFile == null ? null : getFirstClassOfFile.execute( + (PhpFile) dtoInterfaceFile + ); + } + + /** + * 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.getNamespaceBuilder(data.getModuleName()).getNamespace()); + attributes.setProperty("PROPERTIES", data.getProperties()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java index a477fe0ee..88a32b2aa 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java @@ -13,60 +13,60 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class EntityDataMapperGenerator extends FileGenerator { - private final EntityDataMapperData entityDataMapperData; + private final EntityDataMapperData data; private final Project project; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; - private final EntityDataMapperFile entityDataMapperFile; + private final EntityDataMapperFile file; private final boolean checkFileAlreadyExists; - private final List uses; /** * Entity data mapper generator constructor. * - * @param entityDataMapperData EntityDataMapperData + * @param data EntityDataMapperData * @param project Project */ public EntityDataMapperGenerator( - final @NotNull EntityDataMapperData entityDataMapperData, + final @NotNull EntityDataMapperData data, final @NotNull Project project ) { - this(entityDataMapperData, project, true); + this(data, project, true); } /** * Entity data mapper generator constructor. * - * @param entityDataMapperData EntityDataMapperData + * @param data EntityDataMapperData * @param project Project * @param checkFileAlreadyExists boolean */ public EntityDataMapperGenerator( - final @NotNull EntityDataMapperData entityDataMapperData, + final @NotNull EntityDataMapperData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { super(project); - this.entityDataMapperData = entityDataMapperData; + this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; - entityDataMapperFile = new EntityDataMapperFile(entityDataMapperData.getEntityName()); + file = new EntityDataMapperFile(data.getEntityName()); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - uses = new ArrayList<>(); } /** @@ -79,22 +79,22 @@ public EntityDataMapperGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass entityDataMapperClass = GetPhpClassByFQN.getInstance(project).execute( - entityDataMapperData.getClassFqn() + file.getClassFqn(data.getModuleName()) ); if (this.checkFileAlreadyExists && entityDataMapperClass != null) { return entityDataMapperClass.getContainingFile(); } final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - entityDataMapperData.getModuleName() + data.getModuleName() ); final PsiDirectory entityDataMapperDir = directoryGenerator.findOrCreateSubdirectory( moduleBaseDir, - entityDataMapperFile.getDirectory() + file.getDirectory() ); return fileFromTemplateGenerator.generate( - entityDataMapperFile, + file, getAttributes(), entityDataMapperDir, actionName @@ -108,40 +108,38 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", entityDataMapperData.getNamespace()); - attributes.setProperty("ENTITY_NAME", entityDataMapperData.getEntityName()); - attributes.setProperty("CLASS_NAME", entityDataMapperFile.getClassName()); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); - addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); - addProperty(attributes, "DTO_TYPE", entityDataMapperData.getDataModelClassFqn()); - addProperty(attributes, "MAGENTO_MODEL_TYPE", entityDataMapperData.getModelClassFqn()); - addProperty( - attributes, - "DTO_FACTORY", - entityDataMapperData.getDataModelClassFqn().concat("Factory") - ); - addProperty( - attributes, - "ABSTRACT_COLLECTION", - FrameworkLibraryType.ABSTRACT_COLLECTION.getType() - ); + final ModelFile modelFile = new ModelFile(data.getModelName()); + final DataModelFile dtoFile = new DataModelFile(data.getDtoName()); + final DataModelInterfaceFile dtoInterfaceFile = + new DataModelInterfaceFile(data.getDtoInterfaceName()); + String dtoType; - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } + if (data.isDtoWithInterface()) { + dtoType = dtoInterfaceFile.getNamespaceBuilder(data.getModuleName()).getClassFqn(); + } else { + dtoType = dtoFile.getNamespaceBuilder(data.getModuleName()).getClassFqn(); + } - /** - * Add type to property list. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace(data.getModuleName())) + .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.getNamespaceBuilder(data.getModuleName()).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/GetListQueryModelGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java index ba7eb9f22..71e4b615b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java @@ -14,62 +14,59 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; -import com.magento.idea.magento2plugin.magento.files.queries.GetListQuery; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.LinkedList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class GetListQueryModelGenerator extends FileGenerator { private final Project project; - private final GetListQueryModelData queryModelData; + private final GetListQueryModelData data; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; - private final NamespaceBuilder queryModelNamespaceBuilder; private final boolean checkFileAlreadyExists; + private final GetListQueryFile file; /** * Query model generator Constructor. * - * @param queryModelData QueryModelData + * @param data QueryModelData * @param project Project */ public GetListQueryModelGenerator( - final @NotNull GetListQueryModelData queryModelData, + final @NotNull GetListQueryModelData data, final @NotNull Project project ) { - this(queryModelData, project, true); + this(data, project, true); } /** * Query model generator Constructor. * - * @param queryModelData QueryModelData + * @param data QueryModelData * @param project Project * @param checkFileAlreadyExists boolean */ public GetListQueryModelGenerator( - final @NotNull GetListQueryModelData queryModelData, + final @NotNull GetListQueryModelData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { super(project); this.project = project; - this.queryModelData = queryModelData; + this.data = data; this.checkFileAlreadyExists = checkFileAlreadyExists; fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - queryModelNamespaceBuilder = new NamespaceBuilder( - queryModelData.getModuleName(), - GetListQuery.CLASS_NAME, - GetListQuery.DIRECTORY - ); + file = new GetListQueryFile(data.getEntityName()); } /** @@ -82,7 +79,7 @@ public GetListQueryModelGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass getListQueryClass = GetPhpClassByFQN.getInstance(project).execute( - GetListQuery.getClassFqn(queryModelData.getModuleName()) + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (this.checkFileAlreadyExists && getListQueryClass != null) { @@ -90,15 +87,15 @@ public PsiFile generate(final @NotNull String actionName) { } final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - queryModelData.getModuleName() + data.getModuleName() ); - final PsiDirectory queryModelBaseDir = directoryGenerator.findOrCreateSubdirectory( + final PsiDirectory queryModelBaseDir = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - GetListQuery.DIRECTORY + file.getDirectory() ); return fileFromTemplateGenerator.generate( - GetListQuery.getInstance(), + file, getAttributes(), queryModelBaseDir, actionName @@ -112,48 +109,58 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - final List uses = new LinkedList<>(); - - uses.add(queryModelData.getCollectionTypeFactory()); - uses.add(queryModelData.getCollectionType()); - uses.add(queryModelData.getEntityDataMapperType()); - uses.add(FrameworkLibraryType.COLLECTION_PROCESSOR.getType()); - uses.add(FrameworkLibraryType.SEARCH_CRITERIA_BUILDER.getType()); - uses.add(FrameworkLibraryType.SEARCH_CRITERIA.getType()); - uses.add(FrameworkLibraryType.SEARCH_RESULT.getFactory()); - uses.add(FrameworkLibraryType.SEARCH_RESULT.getType()); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final CollectionModelFile collectionModelFile = + new CollectionModelFile(data.getCollectionName()); + final NamespaceBuilder collectionNamespace = + collectionModelFile.getNamespaceBuilder(data.getModuleName(), data.getModelName()); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - attributes.setProperty("ENTITY_NAME", queryModelData.getEntityName()); - attributes.setProperty("NAMESPACE", queryModelNamespaceBuilder.getNamespace()); - attributes.setProperty("CLASS_NAME", GetListQuery.CLASS_NAME); - attributes.setProperty( - "ENTITY_COLLECTION_FACTORY_TYPE", - PhpClassGeneratorUtil.getNameFromFqn( - queryModelData.getCollectionTypeFactory() + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty( + "NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).getNamespace() ) - ); - attributes.setProperty( - "ENTITY_COLLECTION_TYPE", - PhpClassGeneratorUtil.getNameFromFqn( - queryModelData.getCollectionType() + .appendProperty("CLASS_NAME", GetListQueryFile.CLASS_NAME) + .append( + "ENTITY_COLLECTION_TYPE", + collectionNamespace.getClassFqn() ) - ); - attributes.setProperty( - "ENTITY_DATA_MAPPER_TYPE", - PhpClassGeneratorUtil.getNameFromFqn( - queryModelData.getEntityDataMapperType() + .append( + "ENTITY_COLLECTION_FACTORY_TYPE", + collectionNamespace.getClassFqn().concat("Factory") + ) + .append( + "ENTITY_DATA_MAPPER_TYPE", + new EntityDataMapperFile( + data.getEntityName() + ).getClassFqn(data.getModuleName()) ) + .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()) ); - attributes.setProperty("COLLECTION_PROCESSOR_TYPE", - FrameworkLibraryType.COLLECTION_PROCESSOR.getTypeName()); - attributes.setProperty("SEARCH_CRITERIA_BUILDER_TYPE", - FrameworkLibraryType.SEARCH_CRITERIA_BUILDER.getTypeName()); - attributes.setProperty("SEARCH_CRITERIA_TYPE", - FrameworkLibraryType.SEARCH_CRITERIA.getTypeName()); - attributes.setProperty("SEARCH_RESULT_FACTORY_TYPE", - FrameworkLibraryType.SEARCH_RESULT.getFactoryName()); - attributes.setProperty("SEARCH_RESULT_TYPE", - FrameworkLibraryType.SEARCH_RESULT.getTypeName()); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java similarity index 65% rename from src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java rename to src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java index bdfcaeb39..d1e4e7da1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/AdminListViewEntityActionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/IndexActionGenerator.java @@ -9,31 +9,29 @@ 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.AdminListViewEntityActionData; +import com.magento.idea.magento2plugin.actions.generation.data.IndexActionData; 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; 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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; -public class AdminListViewEntityActionGenerator extends FileGenerator { +public class IndexActionGenerator extends FileGenerator { private final Project project; - private final AdminListViewEntityActionData data; + private final IndexActionData data; private final IndexActionFile file; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; - private final List uses; /** * Constructor for adminhtml index (list) controller generator. @@ -41,8 +39,8 @@ public class AdminListViewEntityActionGenerator extends FileGenerator { * @param data EntityIndexAdminhtmlActionData * @param project Project */ - public AdminListViewEntityActionGenerator( - final @NotNull AdminListViewEntityActionData data, + public IndexActionGenerator( + final @NotNull IndexActionData data, final @NotNull Project project ) { this(data, project, true); @@ -55,8 +53,8 @@ public AdminListViewEntityActionGenerator( * @param project Project * @param checkFileAlreadyExists boolean */ - public AdminListViewEntityActionGenerator( - final @NotNull AdminListViewEntityActionData data, + public IndexActionGenerator( + final @NotNull IndexActionData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { @@ -68,7 +66,6 @@ public AdminListViewEntityActionGenerator( fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - uses = new ArrayList<>(); } /** @@ -81,7 +78,7 @@ public AdminListViewEntityActionGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass indexActionClass = GetPhpClassByFQN.getInstance(project).execute( - data.getClassFqn() + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (this.checkFileAlreadyExists && indexActionClass != null) { @@ -111,34 +108,27 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("ENTITY_NAME", data.getEntityName()); - attributes.setProperty("NAMESPACE", data.getNamespace()); - attributes.setProperty("CLASS_NAME", IndexActionFile.CLASS_NAME); - attributes.setProperty("ACL", data.getAcl()); - attributes.setProperty("MENU", data.getMenu()); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); - addProperty(attributes, "PARENT_CLASS_NAME", BackendModuleType.EXTENDS.getType()); - addProperty(attributes, "HTTP_GET_METHOD", HttpMethod.GET.getInterfaceFqn()); - addProperty(attributes, "RESULT", FrameworkLibraryType.RESULT_INTERFACE.getType()); - addProperty(attributes, "RESPONSE", FrameworkLibraryType.RESPONSE_INTERFACE.getType()); - addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("CLASS_NAME", IndexActionFile.CLASS_NAME) + .appendProperty("ACL", data.getAcl()) + .appendProperty("MENU", data.getMenu()) + .appendProperty( + "NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).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(uses)); - } - - /** - * Add type to property list. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - private void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + attributes.setProperty( + "USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()) + ); } } 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 28626faa7..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(); + final String fqn = data.getPreferenceFor(); + for (final XmlAttributeValue preference: preferences) { if (PhpLangUtil.toPresentableFQN(preference.getValue()).equals(fqn)) { return true; @@ -106,9 +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()); - 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 index d95c182e5..b5cbcbd62 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueryGenerator.java @@ -18,15 +18,15 @@ 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.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 java.util.Properties; import javax.swing.JOptionPane; +import org.jetbrains.annotations.NotNull; public class QueryGenerator extends FileGenerator { - private final UiComponentDataProviderData uiComponentGridDataProviderData; + + private final UiComponentDataProviderData data; private final Project project; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; @@ -34,22 +34,22 @@ public class QueryGenerator extends FileGenerator { private final CommonBundle commonBundle; private final String moduleName; private final GetFirstClassOfFile getFirstClassOfFile; + private final UiComponentDataProviderFile file; /** * Ui component grid data provider constructor. * - * @param uiComponentGridDataProviderData UiComponentGridDataProviderData + * @param data UiComponentGridDataProviderData * @param moduleName String * @param project Project */ public QueryGenerator( - final UiComponentDataProviderData uiComponentGridDataProviderData, + final UiComponentDataProviderData data, final String moduleName, final Project project ) { super(project); - - this.uiComponentGridDataProviderData = uiComponentGridDataProviderData; + this.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.validatorBundle = new ValidatorBundle(); @@ -57,15 +57,16 @@ public QueryGenerator( this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.project = project; this.moduleName = moduleName; + file = new UiComponentDataProviderFile(data.getName()); } @Override - public PsiFile generate(final String actionName) { + public PsiFile generate(final @NotNull String actionName) { final PsiFile[] dataProviderFiles = new PsiFile[1]; WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass dataProvider = GetPhpClassByFQN.getInstance(project).execute( - getDataProviderFqn() + file.getNamespaceBuilder(moduleName, data.getPath()).getClassFqn() ); if (dataProvider != null) { @@ -106,33 +107,23 @@ public PsiFile generate(final String actionName) { return dataProviderFiles[0]; } - @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 = ModuleIndex.getInstance(project) + /** + * Create data provider file. + * + * @param actionName String + * + * @return PhpClass + */ + private PhpClass createDataProviderClass(final @NotNull String actionName) { + final PsiDirectory parentDirectory = ModuleIndex.getInstance(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 - ); - } + final PsiDirectory dataProviderDirectory = + directoryGenerator.findOrCreateSubdirectories(parentDirectory, data.getPath()); - final Properties attributes = getAttributes(); - - dataProviderFile = fileFromTemplateGenerator.generate( - UiComponentDataProviderFile.getInstance( - uiComponentGridDataProviderData.getName() - ), - attributes, - parentDirectory, + final PsiFile dataProviderFile = fileFromTemplateGenerator.generate( + new UiComponentDataProviderFile(data.getName()), + getAttributes(), + dataProviderDirectory, actionName ); @@ -143,12 +134,15 @@ private PhpClass createDataProviderClass(final String actionName) { return getFirstClassOfFile.execute((PhpFile) dataProviderFile); } - private String getDataProviderFqn() { - return String.format( - "%s%s%s", - uiComponentGridDataProviderData.getNamespace(), - Package.fqnSeparator, - uiComponentGridDataProviderData.getName() - ); + /** + * Fill file property attributes. + * + * @param attributes Properties + */ + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + attributes.setProperty("NAMESPACE", + file.getNamespaceBuilder(moduleName, data.getPath()).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 index 92949b49b..4dba29d63 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -14,59 +14,56 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; 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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class SaveEntityCommandGenerator extends FileGenerator { private final Project project; - private final SaveEntityCommandData saveEntityCommandData; + private final SaveEntityCommandData data; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; - private final List uses; /** * Save entity command generator constructor. * - * @param saveEntityCommandData SaveEntityCommandData + * @param data SaveEntityCommandData * @param project Project */ public SaveEntityCommandGenerator( - final @NotNull SaveEntityCommandData saveEntityCommandData, + final @NotNull SaveEntityCommandData data, final @NotNull Project project ) { - this(saveEntityCommandData, project, true); + this(data, project, true); } /** * Save entity command generator constructor. * - * @param saveEntityCommandData SaveEntityCommandData + * @param data SaveEntityCommandData * @param project Project * @param checkFileAlreadyExists boolean */ public SaveEntityCommandGenerator( - final @NotNull SaveEntityCommandData saveEntityCommandData, + final @NotNull SaveEntityCommandData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { super(project); - this.saveEntityCommandData = saveEntityCommandData; + this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - uses = new ArrayList<>(); } /** @@ -79,7 +76,7 @@ public SaveEntityCommandGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass saveEntityCommandClass = GetPhpClassByFQN.getInstance(project).execute( - saveEntityCommandData.getClassFqn() + data.getClassFqn() ); if (this.checkFileAlreadyExists && saveEntityCommandClass != null) { @@ -87,11 +84,11 @@ public PsiFile generate(final @NotNull String actionName) { } final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - saveEntityCommandData.getModuleName() + data.getModuleName() ); final PsiDirectory saveCommandFileBaseDir = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - SaveEntityCommandFile.getDirectory(saveEntityCommandData.getEntityName()) + SaveEntityCommandFile.getDirectory(data.getEntityName()) ); return fileFromTemplateGenerator.generate( @@ -109,48 +106,37 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("ENTITY_NAME", saveEntityCommandData.getEntityName()); - attributes.setProperty("NAMESPACE", saveEntityCommandData.getNamespace()); - attributes.setProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME); - attributes.setProperty("EXCEPTION", "Exception"); - uses.add("Exception"); - addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); - addProperty(attributes, "COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getType()); - addProperty(attributes, "LOGGER", FrameworkLibraryType.LOGGER.getType()); - - final String dtoType = saveEntityCommandData.getDataModelClassFqn(); - addProperty(attributes, "DTO", dtoType); + attributes.setProperty("NAMESPACE", data.getNamespace()); - final String dtoProperty = CaseFormat.UPPER_CAMEL.to( - CaseFormat.LOWER_CAMEL, saveEntityCommandData.getEntityName() - ); - attributes.setProperty("DTO_PROPERTY", dtoProperty); + PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); - final String modelType = saveEntityCommandData.getModelClassFqn(); - addProperty(attributes, "MODEL", modelType); + phpClassTypesBuilder + .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 String dtoType = data.getDataModelClassFqn(); + final String dtoProperty = CaseFormat.UPPER_CAMEL.to( + CaseFormat.LOWER_CAMEL, data.getEntityName() + ); + final String modelType = data.getModelClassFqn(); final String modelFactoryType = modelType.concat("Factory"); - addProperty(attributes, "MODEL_FACTORY", modelFactoryType); + final String resourceType = data.getResourceModelClassFqn(); - final String resourceType = saveEntityCommandData.getResourceModelClassFqn(); - addProperty(attributes, "RESOURCE", resourceType); + phpClassTypesBuilder.append("DTO", dtoType) + .appendProperty("DTO_PROPERTY", dtoProperty) + .append("MODEL", modelType) + .append("MODEL_FACTORY", modelFactoryType) + .append("RESOURCE", resourceType); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } + phpClassTypesBuilder.mergeProperties(attributes); - /** - * Add type to property list. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + 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 c7538c694..c73c76e36 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentDataProviderGenerator.java @@ -15,25 +15,22 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; 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.magento.files.queries.GetListQuery; -import com.magento.idea.magento2plugin.magento.packages.File; -import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.magento.files.queries.GetListQueryFile; import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.LinkedList; -import java.util.List; 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 UiComponentDataProviderData data; private final Project project; private final DirectoryGenerator directoryGenerator; private final FileFromTemplateGenerator fileFromTemplateGenerator; @@ -41,21 +38,22 @@ public class UiComponentDataProviderGenerator extends FileGenerator { private final CommonBundle commonBundle; private final String moduleName; private final GetFirstClassOfFile getFirstClassOfFile; + private final UiComponentDataProviderFile file; /** * Ui component grid data provider constructor. * - * @param uiComponentGridDataProviderData UiComponentGridDataProviderData + * @param data UiComponentGridDataProviderData * @param moduleName String * @param project Project */ public UiComponentDataProviderGenerator( - final @NotNull UiComponentDataProviderData uiComponentGridDataProviderData, + final @NotNull UiComponentDataProviderData data, final @NotNull String moduleName, final @NotNull Project project ) { super(project); - this.uiComponentGridDataProviderData = uiComponentGridDataProviderData; + this.data = data; this.directoryGenerator = DirectoryGenerator.getInstance(); this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); this.validatorBundle = new ValidatorBundle(); @@ -63,6 +61,7 @@ public UiComponentDataProviderGenerator( this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); this.project = project; this.moduleName = moduleName; + file = new UiComponentDataProviderFile(data.getName()); } /** @@ -78,7 +77,7 @@ public PsiFile generate(final @NotNull String actionName) { WriteCommandAction.runWriteCommandAction(project, () -> { PhpClass dataProvider = GetPhpClassByFQN.getInstance(project).execute( - getDataProviderFqn() + file.getNamespaceBuilder(moduleName, data.getPath()).getClassFqn() ); if (dataProvider != null) { @@ -119,74 +118,6 @@ public PsiFile generate(final @NotNull String actionName) { return dataProviderFiles[0]; } - /** - * Fill file property attributes. - * - * @param attributes Properties - */ - @Override - protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", uiComponentGridDataProviderData.getNamespace()); - attributes.setProperty("CLASS_NAME", uiComponentGridDataProviderData.getName()); - - if (uiComponentGridDataProviderData.getEntityIdFieldName() != null) { - attributes.setProperty( - "ENTITY_ID", - uiComponentGridDataProviderData.getEntityIdFieldName() - ); - } - attributes.setProperty("HAS_GET_LIST_QUERY", "false"); - - final List uses = new LinkedList<>(); - - uses.add(UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER); - attributes.setProperty( - "EXTENDS", - PhpClassGeneratorUtil.getNameFromFqn( - UiComponentDataProviderFile.DEFAULT_DATA_PROVIDER - ) - ); - - final PhpClass getListQueryFile = GetPhpClassByFQN.getInstance(project).execute( - GetListQuery.getClassFqn(moduleName) - ); - - if (getListQueryFile == null) { - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - return; - } - attributes.setProperty("HAS_GET_LIST_QUERY", "true"); - - uses.add(FrameworkLibraryType.REPORTING.getType()); - attributes.setProperty("REPORTING_TYPE", FrameworkLibraryType.REPORTING.getTypeName()); - - uses.add(FrameworkLibraryType.API_SEARCH_CRITERIA_BUILDER.getType()); - attributes.setProperty("SEARCH_CRITERIA_BUILDER", - FrameworkLibraryType.API_SEARCH_CRITERIA_BUILDER.getTypeName()); - - uses.add(FrameworkLibraryType.REQUEST.getType()); - attributes.setProperty("REQUEST_TYPE", FrameworkLibraryType.REQUEST.getTypeName()); - - uses.add(FrameworkLibraryType.FILTER_BUILDER.getType()); - attributes.setProperty("FILTER_BUILDER", FrameworkLibraryType.FILTER_BUILDER.getTypeName()); - - uses.add(UiComponentDataProviderFile.SEARCH_RESULT_FACTORY); - attributes.setProperty("SEARCH_RESULT_FACTORY", - PhpClassGeneratorUtil.getNameFromFqn( - UiComponentDataProviderFile.SEARCH_RESULT_FACTORY - ) - ); - - final @NotNull String getListQueryFqn = getListQueryFile.getPresentableFQN(); - - uses.add(getListQueryFqn); - attributes.setProperty("GET_LIST_QUERY_TYPE", PhpClassGeneratorUtil.getNameFromFqn( - getListQueryFqn - )); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - /** * Generate data provider class. * @@ -195,26 +126,15 @@ protected void fillAttributes(final @NotNull Properties attributes) { * @return PhpClass */ private PhpClass createDataProviderClass(final @NotNull String actionName) { - PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + final PsiDirectory parentDirectory = ModuleIndex.getInstance(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 - ); - } - - final Properties attributes = getAttributes(); + final PsiDirectory fileDirectory = + directoryGenerator.findOrCreateSubdirectories(parentDirectory, data.getPath()); - dataProviderFile = fileFromTemplateGenerator.generate( - UiComponentDataProviderFile.getInstance( - uiComponentGridDataProviderData.getName() - ), - attributes, - parentDirectory, + final PsiFile dataProviderFile = fileFromTemplateGenerator.generate( + file, + getAttributes(), + fileDirectory, actionName ); @@ -226,16 +146,43 @@ private PhpClass createDataProviderClass(final @NotNull String actionName) { } /** - * Get data provider class FQN. + * Fill file property attributes. * - * @return String + * @param attributes Properties */ - private String getDataProviderFqn() { - return String.format( - "%s%s%s", - uiComponentGridDataProviderData.getNamespace(), - Package.fqnSeparator, - uiComponentGridDataProviderData.getName() - ); + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", + file.getNamespaceBuilder(moduleName, data.getPath()).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( + data.getEntityName() + ).getNamespaceBuilder(moduleName).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); + + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); } } 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 index b1bca9a72..712a8a656 100644 --- 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 @@ -46,8 +46,8 @@ public DataModelInterfaceGeneratorHandler( @Override public void instantiateGenerator() { setGenerator(new DataModelInterfaceGenerator( - getProject(), - (DataModelInterfaceData) getDataObjectConverter() + (DataModelInterfaceData) getDataObjectConverter(), + getProject() )); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java similarity index 79% rename from src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java rename to src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java index 00a8a3eae..f9c2f82e1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/EntityListActionGeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/IndexActionGeneratorHandler.java @@ -5,15 +5,15 @@ package com.magento.idea.magento2plugin.actions.generation.generator.pool.handler; -import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData; +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.AdminListViewEntityActionGenerator; +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 EntityListActionGeneratorHandler extends GeneratorHandler { +public class IndexActionGeneratorHandler extends GeneratorHandler { /** * Entity index action generator handler. @@ -21,7 +21,7 @@ public class EntityListActionGeneratorHandler extends GeneratorHandler { * @param contextData GenerationContextData * @param dataObjectConverter DataObjectConverter */ - public EntityListActionGeneratorHandler( + public IndexActionGeneratorHandler( final @NotNull GenerationContextData contextData, final @NotNull DataObjectConverter dataObjectConverter ) { @@ -35,7 +35,7 @@ public EntityListActionGeneratorHandler( * @param dataObjectConverter DataObjectConverter * @param runnerValidator GeneratorRunnerValidator */ - public EntityListActionGeneratorHandler( + public IndexActionGeneratorHandler( final @NotNull GenerationContextData contextData, final @NotNull DataObjectConverter dataObjectConverter, final GeneratorRunnerValidator runnerValidator @@ -45,8 +45,8 @@ public EntityListActionGeneratorHandler( @Override public void instantiateGenerator() { - setGenerator(new AdminListViewEntityActionGenerator( - (AdminListViewEntityActionData) getDataObjectConverter(), + setGenerator(new IndexActionGenerator( + (IndexActionData) 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 index 9210d73da..d28a7307a 100644 --- 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 @@ -13,7 +13,7 @@ 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.EntityListActionDtoConverter; +import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.IndexActionDtoConverter; 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; @@ -46,7 +46,7 @@ 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.EntityListActionGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.IndexActionGeneratorHandler; 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; @@ -128,8 +128,8 @@ public static void initializeGenerators( new MenuXmlDtoConverter(context, dialogData) ) .addNext( - EntityListActionGeneratorHandler.class, - new EntityListActionDtoConverter(context, dialogData), + IndexActionGeneratorHandler.class, + new IndexActionDtoConverter(context, dialogData), dialogData::hasAdminUiComponents ) .addNext( diff --git a/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java index 3b13eb951..6d2234e7e 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/DataModelFile.java @@ -16,6 +16,7 @@ public class DataModelFile implements ModuleFileInterface { public static final String DATA_OBJECT = "Magento\\Framework\\DataObject"; private final String className; private final String fileName; + private NamespaceBuilder namespaceBuilder; public DataModelFile(final @NotNull String className) { this.className = className; @@ -32,11 +33,15 @@ public DataModelFile(final @NotNull String className) { public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - className, - DIRECTORY - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + + return namespaceBuilder; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java index 4cd427d6d..5d3235648 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java @@ -8,7 +8,6 @@ import com.intellij.lang.Language; import com.jetbrains.php.lang.PhpLanguage; import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; -import com.magento.idea.magento2plugin.magento.packages.Package; import org.jetbrains.annotations.NotNull; public class EntityDataMapperFile implements ModuleFileInterface { @@ -18,8 +17,7 @@ public class EntityDataMapperFile implements ModuleFileInterface { public static final String TEMPLATE = "Magento Entity Data Mapper"; private static final String DIRECTORY = "Mapper"; private final String className; - private String namespaceFqn; - private String classFqn; + private NamespaceBuilder namespaceBuilder; /** * Entity data mapper file constructor. @@ -40,11 +38,15 @@ public EntityDataMapperFile(final @NotNull String entityName) { public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - className, - DIRECTORY - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + className, + DIRECTORY + ); + } + + return namespaceBuilder; } /** @@ -57,16 +59,7 @@ public EntityDataMapperFile(final @NotNull String entityName) { public @NotNull String getNamespace( final @NotNull String moduleName ) { - if (namespaceFqn == null) { - final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( - moduleName, - className, - DIRECTORY - ); - namespaceFqn = namespaceBuilder.getNamespace(); - } - - return namespaceFqn; + return getNamespaceBuilder(moduleName).getNamespace(); } /** @@ -79,13 +72,7 @@ public EntityDataMapperFile(final @NotNull String entityName) { public @NotNull String getClassFqn( final @NotNull String moduleName ) { - if (classFqn == null) { - classFqn = getNamespace(moduleName) - .concat(Package.fqnSeparator) - .concat(className); - } - - return classFqn; + return getNamespaceBuilder(moduleName).getClassFqn(); } /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java index 5db31d220..dc4627da1 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentDataProviderFile.java @@ -10,67 +10,50 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import org.jetbrains.annotations.NotNull; -@SuppressWarnings({ - "PMD.FieldNamingConventions", - "PMD.NonThreadSafeSingleton", - "PMD.RedundantFieldInitializer" -}) public class UiComponentDataProviderFile implements ModuleFileInterface { + public static final String TEMPLATE = "Magento UI Component Custom Data Provider Class"; public static final String DIRECTORY = "Ui/DataProvider"; public static final String FILE_EXTENSION = "php"; public static final String CUSTOM_TYPE = "custom"; public static final String COLLECTION_TYPE = "collection"; - private static UiComponentDataProviderFile INSTANCE = null; - private String className; 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 className; + private NamespaceBuilder namespaceBuilder; /** - * Returns a new instance of the class. - * - * @param className DataProvider class name + * Ui Component data provider file constructor. * - * @return UiComponentDataProviderFile + * @param className String */ - public static UiComponentDataProviderFile getInstance( - final @NotNull String className - ) { - if (null == INSTANCE) { - INSTANCE = new UiComponentDataProviderFile(); - } - - INSTANCE.setClassName(className); - - return INSTANCE; + public UiComponentDataProviderFile(final @NotNull String className) { + this.className = className; } /** * Get namespace builder for file. * * @param moduleName String + * @param directory String * * @return String */ public @NotNull NamespaceBuilder getNamespaceBuilder( - final @NotNull String moduleName + final @NotNull String moduleName, + final String directory ) { - return new NamespaceBuilder( - moduleName, - className, - DIRECTORY - ); - } + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + className, + directory == null ? DIRECTORY : directory + ); + } - /** - * Set class name. - * - * @param className String - */ - public void setClassName(final String className) { - this.className = className; + return namespaceBuilder; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java index 9579d338b..03b484ffc 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/IndexActionFile.java @@ -12,11 +12,13 @@ import org.jetbrains.annotations.NotNull; public final class IndexActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Index"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Index Adminhtml Controller Class"; private static final String DIRECTORY = "Controller/Adminhtml"; private final String entityName; + private NamespaceBuilder namespaceBuilder; /** * Index adminhtml controller for an entity. @@ -39,11 +41,15 @@ public IndexActionFile( public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory() - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; } /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java similarity index 51% rename from src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java rename to src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java index 34f12c60b..f88245b80 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQuery.java +++ b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java @@ -9,45 +9,53 @@ import com.jetbrains.php.lang.PhpLanguage; import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface; -import com.magento.idea.magento2plugin.magento.packages.Package; +import java.io.File; import org.jetbrains.annotations.NotNull; -public final class GetListQuery implements ModuleFileInterface { - public static final String DIRECTORY = "Query"; +public final class GetListQueryFile implements ModuleFileInterface { + public static final String CLASS_NAME = "GetListQuery"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Get List Query Model"; - private static final GetListQuery INSTANCE = new GetListQuery(); + private static final String DIRECTORY = "Query"; + private final String entityName; + private NamespaceBuilder namespaceBuilder; /** - * Get singleton instance of the class. + * Get list query file constructor. * - * @return GetListQuery + * @param entityName String */ - public static GetListQuery getInstance() { - return INSTANCE; + public GetListQueryFile(final @NotNull String entityName) { + this.entityName = entityName; } /** - * Get class FQN. + * Get namespace builder for file. * * @param moduleName String * - * @return String + * @return NamespaceBuilder */ - public static String getClassFqn(final @NotNull String moduleName) { - final NamespaceBuilder namespaceBuilder = new NamespaceBuilder( - moduleName, - GetListQuery.CLASS_NAME, - GetListQuery.DIRECTORY - ); + public NamespaceBuilder getNamespaceBuilder(final @NotNull String moduleName) { + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + GetListQueryFile.CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; + } - return String.format( - "%s%s%s", - namespaceBuilder.getNamespace(), - Package.fqnSeparator, - CLASS_NAME - ); + /** + * Get get list query file directory. + * + * @return String + */ + public String getDirectory() { + return DIRECTORY.concat(File.separator).concat(entityName); } @Override diff --git a/testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/Index.php b/testData/actions/generation/generator/IndexControllerGenerator/generateIndexControllerFile/Index.php similarity index 100% rename from testData/actions/generation/generator/AdminListViewEntityControllerGenerator/generateListViewControllerFile/Index.php rename to testData/actions/generation/generator/IndexControllerGenerator/generateIndexControllerFile/Index.php diff --git a/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php index 4e23950a9..d1d2182e1 100644 --- a/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php +++ b/testData/actions/generation/generator/QueryModelGenerator/generateGetListQueryModelFile/GetListQuery.php @@ -1,6 +1,6 @@ Date: Mon, 22 Mar 2021 16:16:44 +0200 Subject: [PATCH 66/84] Focusing on the first text field --- .../actions/generation/dialog/NewEntityDialog.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index bab4a0ff1..f60eacf4d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -218,6 +218,11 @@ public NewEntityDialog(final @NotNull Project project, final PsiDirectory direct public void windowClosing(final WindowEvent event) { onCancel(); } + + @Override + public void windowOpened(WindowEvent e) { + entityName.requestFocus(); + } }); initializeComboboxSources(); From a3f4ed16e3c7d27f3dd3d768af6f65627b5b087b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 24 Mar 2021 13:53:54 +0200 Subject: [PATCH 67/84] Validation enhanced to show all errors above the fields on the form --- resources/magento2/validation.properties | 1 + .../generation/dialog/AbstractDialog.java | 176 ++++++++++++++---- .../generation/dialog/NewEntityDialog.form | 85 +++++++-- .../generation/dialog/NewEntityDialog.java | 13 +- .../dialog/util/DialogFieldErrorUtil.java | 169 +++++++++++++++++ .../util/HighlightDialogFieldOnErrorUtil.java | 42 ----- 6 files changed, 388 insertions(+), 98 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/DialogFieldErrorUtil.java delete mode 100644 src/com/magento/idea/magento2plugin/actions/generation/dialog/util/HighlightDialogFieldOnErrorUtil.java diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index bb61cd54a..778209381 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -36,3 +36,4 @@ 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/dialog/AbstractDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index f340c83a7..aee60a8fe 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -5,7 +5,7 @@ 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.util.DialogFieldErrorUtil; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidations; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule; @@ -28,17 +28,21 @@ import javax.swing.JOptionPane; 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(); private final String errorTitle; - private final Map> textFieldValidationRuleMap; - private final Map> errorMessageFieldValidationRuleMap; + private final Map> textFieldValidationRuleMap; + private final Map> errorMessageFieldValidationRuleMap; + private boolean isValidationErrorShown; + private boolean dialogHasErrors; /** * Abstract Dialog Constructor. @@ -62,11 +66,18 @@ protected void onCancel() { this.setVisible(false); } + /** + * Validate all form fields. + * + * @return boolean + */ protected boolean validateFormFields() { addValidationRulesFromAnnotations(); - for (final Map.Entry> entry + isValidationErrorShown = dialogHasErrors = false; + + for (final Map.Entry> entry : textFieldValidationRuleMap.entrySet()) { - final Object field = entry.getKey(); + final Field field = entry.getKey(); final List rules = entry.getValue(); for (final ValidationRule rule : rules) { @@ -75,25 +86,66 @@ protected boolean validateFormFields() { if (value != null && !rule.check(value)) { if (errorMessageFieldValidationRuleMap.containsKey(field) && errorMessageFieldValidationRuleMap.get(field).containsKey(rule)) { - showErrorMessage(errorMessageFieldValidationRuleMap.get(field).get(rule)); - highlightFieldWithErrorStyle(field); + dialogHasErrors = true; + showErrorMessage( + field, + errorMessageFieldValidationRuleMap.get(field).get(rule) + ); } - return false; + break; } } } - return true; + + if (dialogHasErrors && !isValidationErrorShown) { + showErrorMessage( + validatorBundle.message("validator.someFieldsHaveErrors") + ); + } + + return !dialogHasErrors; } + /** + * 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); + } + } + + /** + * Show error message in dialog. + * + * @param errorMessage String + */ protected void showErrorMessage(final String errorMessage) { + if (isValidationErrorShown) { + return; + } JOptionPane.showMessageDialog( null, errorMessage, errorTitle, JOptionPane.ERROR_MESSAGE ); + isValidationErrorShown = true; } + /** + * Process validation rules from annotations. + */ private void addValidationRulesFromAnnotations() { final Class type = this.getClass(); final List validations = new LinkedList<>(); @@ -114,18 +166,28 @@ private void addValidationRulesFromAnnotations() { for (final FieldValidation validation : validations) { try { addValidationRuleToField( - field.get(this), + field, getRuleFromAnnotation(validation), getMessageFromAnnotation(validation) ); - } catch (Exception exception) { // NOPMD - // We don't need to cover this case. + } catch (NoSuchMethodException | IllegalAccessException + | InvocationTargetException | InstantiationException exception) { + return; + } finally { + field.setAccessible(false); } } field.setAccessible(false); } } + /** + * Get error message from annotation. + * + * @param validation FieldValidation + * + * @return String + */ private String getMessageFromAnnotation(final FieldValidation validation) { String[] params; final int minMessageArrayLength = 1; @@ -138,22 +200,38 @@ private String getMessageFromAnnotation(final FieldValidation validation) { return validatorBundle.message(validation.message()[0], (Object[]) params); } + /** + * Get validation rule from annotation. + * + * @param validation FieldValidation + * + * @return ValidationRule + */ private ValidationRule getRuleFromAnnotation(final FieldValidation validation) - throws NoSuchMethodException, - IllegalAccessException, InvocationTargetException, InstantiationException { + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, + InstantiationException { final Class ruleType = validation.rule().getRule(); return (ValidationRule) ruleType.getConstructor().newInstance(); } + /** + * Add validation rule for field. + * + * @param field Field + * @param rule ValidationRule + * @param message String + */ protected void addValidationRuleToField( - final Object field, + final Field field, final ValidationRule rule, - final String message) { - if (!(field instanceof JComponent)) { + final String message + ) { + if (getComponentForField(field) == null) { return; } List rules; + if (textFieldValidationRuleMap.containsKey(field)) { rules = textFieldValidationRuleMap.get(field); } else { @@ -167,10 +245,18 @@ protected void addValidationRuleToField( } } + /** + * Associate validation rule with field. + * + * @param field Field + * @param rule ValidationRule + * @param message String + */ private void addFieldValidationRuleMessageAssociation( - final Object field, + final Field field, final ValidationRule rule, - final String message) { + final String message + ) { Map validationRuleErrorMessageMap; if (errorMessageFieldValidationRuleMap.containsKey(field)) { validationRuleErrorMessageMap = errorMessageFieldValidationRuleMap.get(field); @@ -181,31 +267,53 @@ private void addFieldValidationRuleMessageAssociation( errorMessageFieldValidationRuleMap.put(field, validationRuleErrorMessageMap); } - 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 = getComponentForField(field); + + 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. + * Get JComponent for field. + * + * @param field Field * - * @param field Object + * @return JComponent */ - private void highlightFieldWithErrorStyle(final Object field) { - if (field instanceof JTextField) { - HighlightDialogFieldOnErrorUtil.execute((JTextField) field); - } else if (field instanceof JComboBox) { - HighlightDialogFieldOnErrorUtil.execute((JComboBox) field); + private JComponent getComponentForField(final @NotNull Field field) { + try { + field.setAccessible(true); + final Object component = field.get(this); + + 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/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index 416f2c4d4..a8c6246e8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -196,7 +196,7 @@
- + @@ -206,7 +206,7 @@ - + @@ -216,7 +216,7 @@ - + @@ -228,9 +228,18 @@
+ + + + + + + + +
- + @@ -240,7 +249,7 @@ - + @@ -248,7 +257,7 @@ - + @@ -260,6 +269,15 @@
+ + + + + + + + +
@@ -373,7 +391,7 @@
- + @@ -383,7 +401,7 @@ - + @@ -394,7 +412,7 @@ - + @@ -406,6 +424,15 @@ + + + + + + + + + @@ -415,7 +442,7 @@ - + @@ -433,7 +460,7 @@ - + @@ -441,7 +468,7 @@ - + @@ -449,7 +476,7 @@ - + @@ -457,7 +484,7 @@ - + @@ -465,7 +492,7 @@ - + @@ -479,17 +506,17 @@ - + - + - + @@ -497,7 +524,7 @@ - + @@ -509,13 +536,31 @@ + + + + + + + + + - + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index bab4a0ff1..25177564d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -162,11 +162,11 @@ public class NewEntityDialog extends AbstractDialog { private static final boolean OPEN_FILES_FLAG = false; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, FORM_NAME}) - @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE}) + @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}) + @FieldValidation(rule = RuleRegistry.IDENTIFIER, message = {IdentifierRule.MESSAGE, FORM_NAME}) private JTextField gridName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ACL_ID}) @@ -186,6 +186,15 @@ public class NewEntityDialog extends AbstractDialog { 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 JTextField observerName; private final ProcessWorker.InProgressFlag onOkActionFired; 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..302209a43 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/DialogFieldErrorUtil.java @@ -0,0 +1,169 @@ +/* + * 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 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.JComponent; +import javax.swing.JLabel; +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 = getComponentForField(dialog, field); + + if (fieldComponent != null) { + highlightField(fieldComponent); + } + } + + /** + * Add error highlighting for JComponent. + * + * @param fieldComponent JComponent + */ + public static void highlightField(final @NotNull JComponent fieldComponent) { + final Color defaultBackgroundColor = fieldComponent.getBackground(); + + fieldComponent.setBorder(BorderFactory.createLineBorder(ERROR_COLOR)); + fieldComponent.setBackground(ERROR_BACKGROUND_COLOR); + + fieldComponent.addFocusListener(new FocusListener() { + @Override + public void focusGained(final FocusEvent event) { + fieldComponent.setBorder(null); + fieldComponent.setBackground(defaultBackgroundColor); + } + + @Override + public void focusLost(final FocusEvent event) { + fieldComponent.setBorder(null); + fieldComponent.setBackground(defaultBackgroundColor); + } + }); + } + + /** + * 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 = getComponentForField(dialog, field); + + 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; + } + + /** + * Get JComponent for field. + * + * @param field Field + * + * @return JComponent + */ + private static JComponent getComponentForField( + final @NotNull AbstractDialog dialog, + final @NotNull Field field + ) { + try { + field.setAccessible(true); + final Object component = field.get(dialog); + + 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/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 - }); - } -} From e658ebc8d53288ec01bc13a5e218d9faf1ac22e7 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Wed, 24 Mar 2021 14:44:37 +0200 Subject: [PATCH 68/84] Changed error message position (below the field) --- .../generation/dialog/NewEntityDialog.form | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form index a8c6246e8..7863f6a9c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.form @@ -206,7 +206,7 @@ - + @@ -230,7 +230,7 @@ - + @@ -249,7 +249,7 @@ - + @@ -271,7 +271,7 @@ - + @@ -401,7 +401,7 @@ - + @@ -426,7 +426,7 @@ - + @@ -460,7 +460,7 @@ - + @@ -476,7 +476,7 @@ - + @@ -516,7 +516,7 @@ - + @@ -538,7 +538,7 @@ - + @@ -554,7 +554,7 @@ - + From 09faed8fe4b0d747aefdb760c1f02f6d9e22f2a5 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Thu, 25 Mar 2021 23:44:05 +0200 Subject: [PATCH 69/84] Refactored entity creator generators, removed unnecessary namespace builders from dto --- .../data/DeleteEntityByIdCommandData.java | 63 ++----- .../data/DeleteEntityControllerFileData.java | 25 --- .../generation/data/EditEntityActionData.java | 26 --- .../data/FormGenericButtonBlockData.java | 28 +-- .../data/SaveEntityCommandData.java | 73 ++++---- .../data/SaveEntityControllerFileData.java | 58 +++--- .../data/UiComponentFormFileData.java | 37 +++- .../generation/data/UiComponentGridData.java | 63 ++++--- .../DeleteEntityByIdCommandDtoConverter.java | 8 +- .../FormDeleteControllerDtoConverter.java | 2 - .../FormEditControllerDtoConverter.java | 2 - .../FormGenericButtonBlockDtoConverter.java | 4 +- .../FormSaveControllerDtoConverter.java | 8 +- .../SaveEntityCommandDtoConverter.java | 10 +- .../UiComponentFormLayoutDtoConverter.java | 4 +- .../UiComponentGridDtoConverter.java | 4 +- .../data/dialog/EntityCreatorContextData.java | 171 +----------------- .../data/dialog/GenerationContextData.java | 2 +- .../dialog/NewControllerDialog.java | 8 +- .../generation/dialog/NewEntityDialog.java | 31 ---- .../dialog/NewUiComponentFormDialog.java | 12 +- .../dialog/NewUiComponentGridDialog.java | 16 +- .../DeleteEntityByIdCommandGenerator.java | 92 ++++------ .../DeleteEntityControllerFileGenerator.java | 85 +++++---- .../generator/EditEntityActionGenerator.java | 56 ++---- .../FormGenericButtonBlockGenerator.java | 46 ++--- .../ModuleControllerClassGenerator.java | 39 ++-- .../generator/SaveEntityCommandGenerator.java | 45 +++-- .../SaveEntityControllerFileGenerator.java | 118 ++++++------ .../generator/UiComponentFormGenerator.java | 99 ++++++---- .../UiComponentGridXmlGenerator.java | 76 ++++---- .../code/XmlDeclarationsGenerator.java | 4 +- .../generator/pool/GeneratorHandler.java | 5 +- .../files/FormGenericButtonBlockFile.java | 19 +- .../magento/files/ModelFile.java | 1 + ...rmXml.java => UiComponentFormXmlFile.java} | 5 +- ...idXml.java => UiComponentGridXmlFile.java} | 5 +- .../files/actions/DeleteActionFile.java | 36 ++-- .../magento/files/actions/EditActionFile.java | 16 +- .../magento/files/actions/SaveActionFile.java | 36 ++-- .../commands/DeleteEntityByIdCommandFile.java | 48 +++-- .../files/commands/SaveEntityCommandFile.java | 52 +++--- .../Save.php | 12 +- .../SaveCommand.php | 2 +- .../generateFormXmlFile/my_form.xml | 10 +- .../DeleteEntityCommandGeneratorTest.java | 23 +-- .../generator/DeleteEntityGeneratorTest.java | 10 +- .../EditEntityActionGeneratorTest.java | 5 +- .../FormGenericButtonBlockGeneratorTest.java | 8 +- .../SaveEntityActionGeneratorTest.java | 31 ++-- .../SaveEntityCommandGeneratorTest.java | 23 ++- .../UiComponentFormGeneratorTest.java | 54 ++++-- .../UiComponentGridXmlGeneratorTest.java | 15 +- .../pool/NewEntityGeneratorPoolTest.java | 13 -- 54 files changed, 771 insertions(+), 973 deletions(-) rename src/com/magento/idea/magento2plugin/magento/files/{UiComponentFormXml.java => UiComponentFormXmlFile.java} (87%) rename src/com/magento/idea/magento2plugin/magento/files/{UiComponentGridXml.java => UiComponentGridXmlFile.java} (87%) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java index f674bfb39..446730e54 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityByIdCommandData.java @@ -8,41 +8,34 @@ import org.jetbrains.annotations.NotNull; public class DeleteEntityByIdCommandData { + private final String moduleName; private final String entityName; - private final String namespace; - private final String classFqn; - private final String modelClassFqn; - private final String resourceModelClassFqn; private final String entityId; + private final String modelName; + private final String resourceModelName; /** * Delete Command DTO Constructor. * * @param moduleName String * @param entityName String - * @param namespace String - * @param classFqn String - * @param modelClassFqn String - * @param resourceModelClassFqn String * @param entityId String + * @param modelName String + * @param resourceModelName String */ public DeleteEntityByIdCommandData( final @NotNull String moduleName, final @NotNull String entityName, - final @NotNull String namespace, - final @NotNull String classFqn, - final @NotNull String modelClassFqn, - final @NotNull String resourceModelClassFqn, - final @NotNull String entityId + final @NotNull String entityId, + final @NotNull String modelName, + final @NotNull String resourceModelName ) { this.moduleName = moduleName; this.entityName = entityName; - this.namespace = namespace; - this.classFqn = classFqn; - this.modelClassFqn = modelClassFqn; - this.resourceModelClassFqn = resourceModelClassFqn; this.entityId = entityId; + this.modelName = modelName; + this.resourceModelName = resourceModelName; } /** @@ -64,47 +57,29 @@ public String getEntityName() { } /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - - /** - * Get class FQN. - * - * @return String - */ - public String getClassFqn() { - return classFqn; - } - - /** - * Get entity model class FQN. + * Get entity Id. * * @return String */ - public String getModelClassFqn() { - return modelClassFqn; + public String getEntityId() { + return entityId; } /** - * Get entity resource model class FQN. + * Get model name. * * @return String */ - public String getResourceModelClassFqn() { - return resourceModelClassFqn; + public String getModelName() { + return modelName; } /** - * Get entity Id. + * Get resource model name. * * @return String */ - public String getEntityId() { - return entityId; + 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 index 83487b35a..f83516204 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/DeleteEntityControllerFileData.java @@ -11,8 +11,6 @@ public class DeleteEntityControllerFileData { private final String entityName; private final String moduleName; - private final String namespace; - private final String deleteCommandFqn; private final String acl; private final String entityId; @@ -21,22 +19,17 @@ public class DeleteEntityControllerFileData { * * @param entityName String * @param moduleName String - * @param namespace String * @param acl String * @param entityId String */ public DeleteEntityControllerFileData( final @NotNull String entityName, final @NotNull String moduleName, - final @NotNull String namespace, - final @NotNull String deleteCommandFqn, final @NotNull String acl, final @NotNull String entityId ) { this.entityName = entityName; this.moduleName = moduleName; - this.namespace = namespace; - this.deleteCommandFqn = deleteCommandFqn; this.acl = acl; this.entityId = entityId; } @@ -59,24 +52,6 @@ public String getModuleName() { return moduleName; } - /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - - /** - * Get delete command Fqn. - * - * @return String - */ - public String getDeleteCommandFqn() { - return deleteCommandFqn; - } - /** * Get acl. * diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java index b4568376c..6851b8faa 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EditEntityActionData.java @@ -11,8 +11,6 @@ public class EditEntityActionData { private final String entityName; private final String moduleName; - private final String classFqn; - private final String namespace; private final String acl; private final String menuIdentifier; @@ -21,23 +19,17 @@ public class EditEntityActionData { * * @param entityName String * @param moduleName String - * @param classFqn String - * @param namespace String * @param acl String * @param menuIdentifier String */ public EditEntityActionData( final @NotNull String entityName, final @NotNull String moduleName, - final @NotNull String classFqn, - final @NotNull String namespace, final @NotNull String acl, final @NotNull String menuIdentifier ) { this.entityName = entityName; this.moduleName = moduleName; - this.classFqn = classFqn; - this.namespace = namespace; this.acl = acl; this.menuIdentifier = menuIdentifier; } @@ -60,24 +52,6 @@ public String getModuleName() { return moduleName; } - /** - * Get class FQN. - * - * @return String - */ - public String getClassFqn() { - return classFqn; - } - - /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } - /** * Get acl. * diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java index 076b07aa7..c31d20f91 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/FormGenericButtonBlockData.java @@ -12,8 +12,6 @@ public class FormGenericButtonBlockData { private final String moduleName; private final String entityName; private final String entityId; - private final String classFqn; - private final String namespace; /** * Generic button DTO constructor. @@ -21,21 +19,15 @@ public class FormGenericButtonBlockData { * @param moduleName String * @param entityName String * @param entityId String - * @param classFqn String - * @param namespace String */ public FormGenericButtonBlockData( final @NotNull String moduleName, final @NotNull String entityName, - final @NotNull String entityId, - final @NotNull String classFqn, - final @NotNull String namespace + final @NotNull String entityId ) { this.moduleName = moduleName; this.entityName = entityName; this.entityId = entityId; - this.classFqn = classFqn; - this.namespace = namespace; } /** @@ -64,22 +56,4 @@ public String getEntityName() { public String getEntityId() { return entityId; } - - /** - * Get class FQN. - * - * @return String - */ - public String getClassFqn() { - return classFqn; - } - - /** - * Get namespace. - * - * @return String - */ - public String getNamespace() { - return namespace; - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java index 747905b6d..24f43723c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java @@ -8,41 +8,42 @@ import org.jetbrains.annotations.NotNull; public class SaveEntityCommandData { + private final String moduleName; private final String entityName; - private final String namespace; - private final String classFqn; - private final String modelClassFqn; - private final String resourceModelClassFqn; - private final String dataModelClassFqn; + private final String modelName; + private final String resourceModelName; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean isDtoWithInterface; /** * Save Command DTO Constructor. * * @param moduleName String * @param entityName String - * @param namespace String - * @param classFqn String - * @param modelClassFqn String - * @param resourceModelClassFqn String - * @param dataModelClassFqn 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 namespace, - final @NotNull String classFqn, - final @NotNull String modelClassFqn, - final @NotNull String resourceModelClassFqn, - final @NotNull String dataModelClassFqn + 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.namespace = namespace; - this.classFqn = classFqn; - this.modelClassFqn = modelClassFqn; - this.resourceModelClassFqn = resourceModelClassFqn; - this.dataModelClassFqn = dataModelClassFqn; + this.modelName = modelName; + this.resourceModelName = resourceModelName; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.isDtoWithInterface = isDtoWithInterface; } /** @@ -64,47 +65,47 @@ public String getEntityName() { } /** - * Get namespace. + * Get model name. * * @return String */ - public String getNamespace() { - return namespace; + public String getModelName() { + return modelName; } /** - * Get class FQN. + * Get resource model name. * * @return String */ - public String getClassFqn() { - return classFqn; + public String getResourceModelName() { + return resourceModelName; } /** - * Get entity model class FQN. + * Get DTO name. * * @return String */ - public String getModelClassFqn() { - return modelClassFqn; + public String getDtoName() { + return dtoName; } /** - * Get entity resource model class FQN. + * Get DTO interface name. * * @return String */ - public String getResourceModelClassFqn() { - return resourceModelClassFqn; + public String getDtoInterfaceName() { + return dtoInterfaceName; } /** - * Get entity DTO class FQN. + * Check if DTO has an interface. * - * @return String + * @return boolean */ - public String getDataModelClassFqn() { - return dataModelClassFqn; + public boolean isDtoWithInterface() { + return isDtoWithInterface; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java index cfab60a1e..d09561a14 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java @@ -11,39 +11,39 @@ public class SaveEntityControllerFileData { private final String entityName; private final String moduleName; - private final String namespace; - private final String saveCommandFqn; - private final String dtoType; private final String acl; private final String entityId; + private final String dtoName; + private final String dtoInterfaceName; + private final boolean isDtoWithInterface; /** * Controller save file constructor. * * @param entityName String * @param moduleName String - * @param namespace String - * @param saveCommandFqn String * @param acl String - * @param dtoType 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 namespace, - final @NotNull String saveCommandFqn, - final @NotNull String dtoType, final @NotNull String acl, - final @NotNull String entityId + final @NotNull String entityId, + final @NotNull String dtoName, + final @NotNull String dtoInterfaceName, + final boolean isDtoWithInterface ) { this.entityName = entityName; this.moduleName = moduleName; - this.namespace = namespace; - this.saveCommandFqn = saveCommandFqn; - this.dtoType = dtoType; this.acl = acl; this.entityId = entityId; + this.dtoName = dtoName; + this.dtoInterfaceName = dtoInterfaceName; + this.isDtoWithInterface = isDtoWithInterface; } /** @@ -65,47 +65,47 @@ public String getAcl() { } /** - * Get dto type. + * Get entity name. * * @return String */ - public String getDtoType() { - return dtoType; + public String getEntityName() { + return entityName; } /** - * Get save command Fqn. + * Get module name. * * @return String */ - public String getSaveCommandFqn() { - return saveCommandFqn; + public String getModuleName() { + return moduleName; } /** - * Get entity name. + * Get DTO name. * * @return String */ - public String getEntityName() { - return entityName; + public String getDtoName() { + return dtoName; } /** - * Get module name. + * Get DTO interface name. * * @return String */ - public String getModuleName() { - return moduleName; + public String getDtoInterfaceName() { + return dtoInterfaceName; } /** - * Get namespace. + * Check if DTO has interface. * - * @return String + * @return boolean */ - public String getNamespace() { - return namespace; + public boolean isDtoWithInterface() { + return isDtoWithInterface; } } 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 10326082d..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,8 @@ 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; @@ -34,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( @@ -48,7 +51,8 @@ public UiComponentFormFileData( final String route, final String submitControllerName, final String submitActionName, - final String dataProviderFqn + final String dataProviderName, + final String dataProviderPath ) { this( formName, @@ -61,7 +65,8 @@ public UiComponentFormFileData( route, submitControllerName, submitActionName, - dataProviderFqn, + dataProviderName, + dataProviderPath, "Entity", "entity_id" ); @@ -79,7 +84,8 @@ public UiComponentFormFileData( * @param route String * @param submitControllerName String * @param submitActionName String - * @param dataProviderFqn String + * @param dataProviderName String + * @param dataProviderPath String * @param entityName String * @param entityId String */ @@ -95,7 +101,8 @@ public UiComponentFormFileData( final String route, final String submitControllerName, final String submitActionName, - final String dataProviderFqn, + final String dataProviderName, + final String dataProviderPath, final String entityName, final String entityId ) { @@ -109,7 +116,8 @@ 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; } @@ -205,12 +213,21 @@ 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 getDataProviderFqn() { - return dataProviderFqn; + public String getDataProviderPath() { + return dataProviderPath; } /** 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 975af0f12..9bc9c3214 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java @@ -10,40 +10,47 @@ import java.util.Map; 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 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, - providerClassName, idFieldName, acl, + dataProviderName, + dataProviderPath, gridToolbarData, new ArrayList<>() ); @@ -52,29 +59,34 @@ public UiComponentGridData( /** * 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 * @param columns List */ 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, 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.gridToolbarData = gridToolbarData; this.columns = columns; } @@ -125,21 +137,30 @@ public String getAcl() { } /** - * Get ID field name. + * Get data provider name. * * @return String */ - public String getIdFieldName() { - return idFieldName; + public String getDataProviderName() { + return dataProviderName; } /** - * Get data provider class name. + * Get data provider path. * * @return String */ - public String getProviderClassName() { - return providerClassName; + public String getDataProviderPath() { + return dataProviderPath; + } + + /** + * Get ID field name. + * + * @return String + */ + public String getIdFieldName() { + return idFieldName; } /** 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 index 4e4c13bd6..d0f9e457c 100644 --- 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 @@ -27,11 +27,9 @@ public DeleteEntityByIdCommandDtoConverter( super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getNamespace(), - generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getClassFqn(), - generationContextData.getModelNamespaceBuilder().getClassFqn(), - generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), - newEntityDialogData.getIdFieldName() + newEntityDialogData.getIdFieldName(), + newEntityDialogData.getEntityName().concat("Model"), + newEntityDialogData.getEntityName().concat("Resource") ); } } 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 index d8898f981..c3a5f797d 100644 --- 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 @@ -27,8 +27,6 @@ public FormDeleteControllerDtoConverter( super( newEntityDialogData.getEntityName(), generationContextData.getModuleName(), - generationContextData.getDeleteControllerNamespaceBuilder().getNamespace(), - generationContextData.getDeleteEntityByIdCommandNamespaceBuilder().getClassFqn(), 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 index 36639ef26..ff48ea9b9 100644 --- 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 @@ -27,8 +27,6 @@ public FormEditControllerDtoConverter( super( newEntityDialogData.getEntityName(), generationContextData.getModuleName(), - generationContextData.getEditControllerNamespaceBuilder().getClassFqn(), - generationContextData.getEditControllerNamespaceBuilder().getNamespace(), 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 index 8ae9092de..4eb3c9860 100644 --- 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 @@ -27,9 +27,7 @@ public FormGenericButtonBlockDtoConverter( super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - newEntityDialogData.getIdFieldName(), - generationContextData.getGenericButtonBlockNamespaceBuilder().getClassFqn(), - generationContextData.getGenericButtonBlockNamespaceBuilder().getNamespace() + newEntityDialogData.getIdFieldName() ); } } 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 index ff8632d1d..c80380378 100644 --- 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 @@ -27,11 +27,11 @@ public FormSaveControllerDtoConverter( super( newEntityDialogData.getEntityName(), generationContextData.getModuleName(), - generationContextData.getSaveControllerNamespaceBuilder().getNamespace(), - generationContextData.getSaveEntityCommandNamespaceBuilder().getClassFqn(), - generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn(), newEntityDialogData.getAclId(), - newEntityDialogData.getIdFieldName() + 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/SaveEntityCommandDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SaveEntityCommandDtoConverter.java index 3c59fd45b..85d9182b7 100644 --- 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 @@ -27,11 +27,11 @@ public SaveEntityCommandDtoConverter( super( generationContextData.getModuleName(), newEntityDialogData.getEntityName(), - generationContextData.getSaveEntityCommandNamespaceBuilder().getNamespace(), - generationContextData.getSaveEntityCommandNamespaceBuilder().getClassFqn(), - generationContextData.getModelNamespaceBuilder().getClassFqn(), - generationContextData.getResourceModelNamespaceBuilder().getClassFqn(), - generationContextData.getFinalDtoTypeNamespaceBuilder().getClassFqn() + 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 index 5b7149a58..9cc0e3e6a 100644 --- 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 @@ -9,6 +9,7 @@ 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; @@ -32,7 +33,8 @@ public UiComponentFormLayoutDtoConverter( newEntityDialogData.getRoute(), newEntityDialogData.getEntityName(), SUBMIT_ACTION_NAME, - generationContextData.getDataProviderNamespaceBuilder().getClassFqn(), + 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 index 516fdc6eb..b55425be7 100644 --- 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 @@ -9,6 +9,7 @@ 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; @@ -29,9 +30,10 @@ public UiComponentGridDtoConverter( generationContextData.getModuleName(), Areas.adminhtml.toString(), newEntityDialogData.getGridName(), - generationContextData.getDataProviderNamespaceBuilder().getClassFqn(), newEntityDialogData.getIdFieldName(), newEntityDialogData.getAclId(), + newEntityDialogData.getEntityName().concat("DataProvider"), + UiComponentDataProviderFile.DIRECTORY, new UiComponentGridToolbarDtoConverter(generationContextData, newEntityDialogData), generationContextData.getEntityProps() ); 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 index 0fbed16c5..63ac992b8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/EntityCreatorContextData.java @@ -25,23 +25,10 @@ public class EntityCreatorContextData implements GenerationContextData { private final String editViewAction; private final String newViewAction; private final String deleteAction; - private final NamespaceBuilder modelNamespaceBuilder; - private final NamespaceBuilder resourceModelNamespaceBuilder; - private final NamespaceBuilder collectionModelNamespaceBuilder; private final NamespaceBuilder dtoModelNamespaceBuilder; private final NamespaceBuilder dtoInterfaceNamespaceBuilder; - private final NamespaceBuilder finalDtoTypeNamespaceBuilder; - private final NamespaceBuilder dataProviderNamespaceBuilder; - private final NamespaceBuilder entityListActionNamespaceBuilder; - private final NamespaceBuilder entityDataMapperNamespaceBuilder; - private final NamespaceBuilder saveEntityCommandNamespaceBuilder; - private final NamespaceBuilder deleteEntityByIdCommandNamespaceBuilder; private final NamespaceBuilder formViewNamespaceBuilder; private final NamespaceBuilder newControllerNamespaceBuilder; - private final NamespaceBuilder saveControllerNamespaceBuilder; - private final NamespaceBuilder deleteControllerNamespaceBuilder; - private final NamespaceBuilder editControllerNamespaceBuilder; - private final NamespaceBuilder genericButtonBlockNamespaceBuilder; private final List> entityProps; private final List buttons; private final List fieldsetData; @@ -58,23 +45,10 @@ public class EntityCreatorContextData implements GenerationContextData { * @param editViewAction String * @param newViewAction String * @param deleteAction String - * @param modelNamespaceBuilder NamespaceBuilder - * @param resourceModelNamespaceBuilder NamespaceBuilder - * @param collectionModelNamespaceBuilder NamespaceBuilder * @param dtoModelNamespaceBuilder NamespaceBuilder * @param dtoInterfaceNamespaceBuilder NamespaceBuilder - * @param finalDtoTypeNamespaceBuilder NamespaceBuilder - * @param dataProviderNamespaceBuilder NamespaceBuilder - * @param entityListActionNamespaceBuilder NamespaceBuilder - * @param entityDataMapperNamespaceBuilder NamespaceBuilder - * @param saveEntityCommandNamespaceBuilder NamespaceBuilder - * @param deleteEntityByIdCommandNamespaceBuilder NamespaceBuilder * @param formViewNamespaceBuilder NamespaceBuilder * @param newControllerNamespaceBuilder NamespaceBuilder - * @param saveControllerNamespaceBuilder NamespaceBuilder - * @param deleteControllerNamespaceBuilder NamespaceBuilder - * @param editControllerNamespaceBuilder NamespaceBuilder - * @param genericButtonBlockNamespaceBuilder NamespaceBuilder * @param entityProps List * @param buttons List * @param fieldsetData List @@ -90,23 +64,10 @@ public EntityCreatorContextData( final @NotNull String editViewAction, final @NotNull String newViewAction, final @NotNull String deleteAction, - final @NotNull NamespaceBuilder modelNamespaceBuilder, - final @NotNull NamespaceBuilder resourceModelNamespaceBuilder, - final @NotNull NamespaceBuilder collectionModelNamespaceBuilder, final @NotNull NamespaceBuilder dtoModelNamespaceBuilder, final @NotNull NamespaceBuilder dtoInterfaceNamespaceBuilder, - final @NotNull NamespaceBuilder finalDtoTypeNamespaceBuilder, - final @NotNull NamespaceBuilder dataProviderNamespaceBuilder, - final @NotNull NamespaceBuilder entityListActionNamespaceBuilder, - final @NotNull NamespaceBuilder entityDataMapperNamespaceBuilder, - final @NotNull NamespaceBuilder saveEntityCommandNamespaceBuilder, - final @NotNull NamespaceBuilder deleteEntityByIdCommandNamespaceBuilder, final @NotNull NamespaceBuilder formViewNamespaceBuilder, final @NotNull NamespaceBuilder newControllerNamespaceBuilder, - final @NotNull NamespaceBuilder saveControllerNamespaceBuilder, - final @NotNull NamespaceBuilder deleteControllerNamespaceBuilder, - final @NotNull NamespaceBuilder editControllerNamespaceBuilder, - final @NotNull NamespaceBuilder genericButtonBlockNamespaceBuilder, final @NotNull List> entityProps, final @NotNull List buttons, final @NotNull List fieldsetData, @@ -120,23 +81,10 @@ public EntityCreatorContextData( this.editViewAction = editViewAction; this.newViewAction = newViewAction; this.deleteAction = deleteAction; - this.modelNamespaceBuilder = modelNamespaceBuilder; - this.resourceModelNamespaceBuilder = resourceModelNamespaceBuilder; this.dtoModelNamespaceBuilder = dtoModelNamespaceBuilder; this.dtoInterfaceNamespaceBuilder = dtoInterfaceNamespaceBuilder; - this.collectionModelNamespaceBuilder = collectionModelNamespaceBuilder; - this.finalDtoTypeNamespaceBuilder = finalDtoTypeNamespaceBuilder; - this.dataProviderNamespaceBuilder = dataProviderNamespaceBuilder; - this.entityListActionNamespaceBuilder = entityListActionNamespaceBuilder; - this.entityDataMapperNamespaceBuilder = entityDataMapperNamespaceBuilder; - this.saveEntityCommandNamespaceBuilder = saveEntityCommandNamespaceBuilder; - this.deleteEntityByIdCommandNamespaceBuilder = deleteEntityByIdCommandNamespaceBuilder; this.formViewNamespaceBuilder = formViewNamespaceBuilder; this.newControllerNamespaceBuilder = newControllerNamespaceBuilder; - this.saveControllerNamespaceBuilder = saveControllerNamespaceBuilder; - this.deleteControllerNamespaceBuilder = deleteControllerNamespaceBuilder; - this.editControllerNamespaceBuilder = editControllerNamespaceBuilder; - this.genericButtonBlockNamespaceBuilder = genericButtonBlockNamespaceBuilder; this.entityProps = entityProps; this.buttons = buttons; this.fieldsetData = fieldsetData; @@ -159,7 +107,7 @@ public String getActionName() { } @Override - public boolean hasOpenFileFlag() { + public boolean checkIfHasOpenFileFlag() { return hasOpenFileFlag; } @@ -199,33 +147,6 @@ public String getDeleteAction() { return deleteAction; } - /** - * Get model namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getModelNamespaceBuilder() { - return modelNamespaceBuilder; - } - - /** - * Get resource model namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getResourceModelNamespaceBuilder() { - return resourceModelNamespaceBuilder; - } - - /** - * Get collection model namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getCollectionModelNamespaceBuilder() { - return collectionModelNamespaceBuilder; - } - /** * Get DTO model namespace builder. * @@ -244,60 +165,6 @@ public NamespaceBuilder getDtoInterfaceNamespaceBuilder() { return dtoInterfaceNamespaceBuilder; } - /** - * Get final DTO type namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getFinalDtoTypeNamespaceBuilder() { - return finalDtoTypeNamespaceBuilder; - } - - /** - * Get data provider namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getDataProviderNamespaceBuilder() { - return dataProviderNamespaceBuilder; - } - - /** - * Get entity list action namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getEntityListActionNamespaceBuilder() { - return entityListActionNamespaceBuilder; - } - - /** - * Get entity data mapper namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getEntityDataMapperNamespaceBuilder() { - return entityDataMapperNamespaceBuilder; - } - - /** - * Get save entity command namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getSaveEntityCommandNamespaceBuilder() { - return saveEntityCommandNamespaceBuilder; - } - - /** - * Get delete by id command namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getDeleteEntityByIdCommandNamespaceBuilder() { - return deleteEntityByIdCommandNamespaceBuilder; - } - /** * Get form view namespace builder. * @@ -316,42 +183,6 @@ public NamespaceBuilder getNewControllerNamespaceBuilder() { return newControllerNamespaceBuilder; } - /** - * Get save controller namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getSaveControllerNamespaceBuilder() { - return saveControllerNamespaceBuilder; - } - - /** - * Get delete controller namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getDeleteControllerNamespaceBuilder() { - return deleteControllerNamespaceBuilder; - } - - /** - * Get edit controller namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getEditControllerNamespaceBuilder() { - return editControllerNamespaceBuilder; - } - - /** - * Get generic button block namespace builder. - * - * @return NamespaceBuilder - */ - public NamespaceBuilder getGenericButtonBlockNamespaceBuilder() { - return genericButtonBlockNamespaceBuilder; - } - /** * Get entity properties. * 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 index 779850d23..924be84d8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/GenerationContextData.java @@ -38,5 +38,5 @@ public interface GenerationContextData { * * @return boolean */ - boolean hasOpenFileFlag(); + boolean checkIfHasOpenFileFlag(); } 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/NewEntityDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 25177564d..c8797bca6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -29,23 +29,11 @@ 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.CollectionModelFile; 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.EntityDataMapperFile; -import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; -import com.magento.idea.magento2plugin.magento.files.ModelFile; import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml; -import com.magento.idea.magento2plugin.magento.files.ResourceModelFile; -import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; -import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile; -import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile; -import com.magento.idea.magento2plugin.magento.files.actions.IndexActionFile; import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile; -import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile; -import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile; -import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile; 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; @@ -378,10 +366,6 @@ private EntityCreatorContextData getEntityCreatorContextData( final @NotNull NewEntityDialogData dialogData ) { final String entityName = dialogData.getEntityName(); - final String modelClassName = entityName.concat(MODEL_SUFFIX); - final String resourceClassName = entityName.concat(RESOURCE_MODEL_SUFFIX); - final String collectionClassName = entityName.concat(COLLECTION_MODEL_SUFFIX); - final String dataProviderClassName = entityName.concat(DATA_PROVIDER_SUFFIX); final String dtoClassName = entityName.concat(DTO_MODEL_SUFFIX); final String dtoInterfaceClassName = entityName.concat(DTO_INTERFACE_SUFFIX); @@ -408,25 +392,10 @@ private EntityCreatorContextData getEntityCreatorContextData( actionsPathPrefix.concat("edit"), actionsPathPrefix.concat("new"), actionsPathPrefix.concat("delete"), - new ModelFile(modelClassName).getNamespaceBuilder(moduleName), - new ResourceModelFile(resourceClassName).getNamespaceBuilder(moduleName), - new CollectionModelFile(collectionClassName) - .getNamespaceBuilder(moduleName, entityName), dtoModelNamespace, dtoInterfaceNamespace, - createInterface.isSelected() ? dtoInterfaceNamespace : dtoModelNamespace, - new UiComponentDataProviderFile(dataProviderClassName) - .getNamespaceBuilder(moduleName, null), - new IndexActionFile(entityName).getNamespaceBuilder(moduleName), - new EntityDataMapperFile(entityName).getNamespaceBuilder(moduleName), - SaveEntityCommandFile.getNamespaceBuilder(moduleName, entityName), - DeleteEntityByIdCommandFile.getNamespaceBuilder(moduleName, entityName), formViewNamespaceBuilder, NewActionFile.getNamespaceBuilder(moduleName, entityName), - SaveActionFile.getNamespaceBuilder(moduleName, entityName), - DeleteActionFile.getNamespaceBuilder(moduleName, entityName), - new EditActionFile(entityName).getNamespaceBuilder(moduleName), - FormGenericButtonBlockFile.getNamespaceBuilder(moduleName), getEntityProperties(), getButtons(), getFieldSets(), 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 4617faa2a..a203e21d7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -428,15 +428,6 @@ private void generateDataProviderFile() { ), getModuleName(), project).generate(NewUiComponentFormAction.ACTION_NAME, false); } - @NotNull - private NamespaceBuilder getDataProviderNamespace() { - return new NamespaceBuilder( - getModuleName(), - getDataProviderClassName(), - getDataProviderDirectory() - ); - } - /** * Generate form file. */ @@ -452,7 +443,8 @@ private void generateFormFile() { getRoute(), getSubmitControllerName(), getSubmitActionName(), - getDataProviderNamespace().getClassFqn() + getDataProviderClassName(), + getDataProviderDirectory() ), project).generate(NewUiComponentFormAction.ACTION_NAME, true); } 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 e0e3ef082..21b5d2bc5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -254,7 +254,7 @@ public static void open(final Project project, final PsiDirectory directory) { */ public UiComponentDataProviderData getGridDataProviderData() { return new UiComponentDataProviderData( - getDataProviderClass(), + getDataProviderClassName(), getDataProviderDirectory() ); } @@ -285,9 +285,10 @@ public UiComponentGridData getUiComponentGridData() { getModuleName(), getArea(), getUiComponentName(), - getDataProviderClassFqn(), getEntityIdFieldName(), getAcl(), + getDataProviderClassName(), + getDataProviderDirectory(), getUiComponentGridToolbarData() ); } @@ -369,7 +370,7 @@ private void generateDataProviderDeclaration() { dataProviderGenerator = new DataProviderDeclarationGenerator( new DataProviderDeclarationData( getModuleName(), - getDataProviderClass(), + getDataProviderClassName(), getCollection(), getUiComponentName() + "_data_source", getTableName() @@ -558,7 +559,7 @@ private String getDataProviderClassFqn() { "%s%s%s", getDataProviderNamespace(), Package.fqnSeparator, - getDataProviderClass() + getDataProviderClassName() ); } @@ -616,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/generator/DeleteEntityByIdCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java index 4128b7443..bcae49773 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java @@ -13,60 +13,60 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; +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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; import java.util.Properties; +import org.jetbrains.annotations.NotNull; public class DeleteEntityByIdCommandGenerator extends FileGenerator { private final Project project; - private final DeleteEntityByIdCommandData deleteEntityByIdCommandData; + private final DeleteEntityByIdCommandData data; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; - private final List uses; + private final DeleteEntityByIdCommandFile file; /** * Delete entity command generator constructor. * - * @param deleteEntityByIdCommandData DeleteEntityCommandData + * @param data DeleteEntityCommandData * @param project Project */ public DeleteEntityByIdCommandGenerator( - final @NotNull DeleteEntityByIdCommandData deleteEntityByIdCommandData, + final @NotNull DeleteEntityByIdCommandData data, final @NotNull Project project ) { - this(deleteEntityByIdCommandData, project, true); + this(data, project, true); } /** * Delete entity command generator constructor. * - * @param deleteEntityByIdCommandData DeleteEntityCommandData + * @param data DeleteEntityCommandData * @param project Project * @param checkFileAlreadyExists boolean */ public DeleteEntityByIdCommandGenerator( - final @NotNull DeleteEntityByIdCommandData deleteEntityByIdCommandData, + final @NotNull DeleteEntityByIdCommandData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { super(project); - this.deleteEntityByIdCommandData = deleteEntityByIdCommandData; + this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - uses = new ArrayList<>(); + file = new DeleteEntityByIdCommandFile(data.getEntityName()); } /** @@ -79,7 +79,7 @@ public DeleteEntityByIdCommandGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass deleteEntityCommandClass = GetPhpClassByFQN.getInstance(project).execute( - deleteEntityByIdCommandData.getClassFqn() + file.getClassFqn(data.getModuleName()) ); if (this.checkFileAlreadyExists && deleteEntityCommandClass != null) { @@ -87,15 +87,15 @@ public PsiFile generate(final @NotNull String actionName) { } final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - deleteEntityByIdCommandData.getModuleName() + data.getModuleName() ); final PsiDirectory deleteCommandFileBaseDir = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - DeleteEntityByIdCommandFile.getDirectory(deleteEntityByIdCommandData.getEntityName()) + DeleteEntityByIdCommandFile.getDirectory(data.getEntityName()) ); return fileFromTemplateGenerator.generate( - new DeleteEntityByIdCommandFile(), + file, getAttributes(), deleteCommandFileBaseDir, actionName @@ -109,41 +109,29 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("ENTITY_NAME", deleteEntityByIdCommandData.getEntityName()); - attributes.setProperty("NAMESPACE", deleteEntityByIdCommandData.getNamespace()); - attributes.setProperty("CLASS_NAME", DeleteEntityByIdCommandFile.CLASS_NAME); - attributes.setProperty("ENTITY_ID", deleteEntityByIdCommandData.getEntityId()); - uses.add("Exception"); - addProperty(attributes, "COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType()); - addProperty(attributes, "NO_SUCH_ENTITY_EXCEPTION", - ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()); - addProperty(attributes, "LOGGER", FrameworkLibraryType.LOGGER.getType()); - - final String modelType = deleteEntityByIdCommandData.getModelClassFqn(); - addProperty(attributes, "MODEL", modelType); - + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final ModelFile modelFile = new ModelFile(data.getModelName()); + final String modelType = modelFile.getNamespaceBuilder(data.getModuleName()).getClassFqn(); final String modelFactoryType = modelType.concat("Factory"); - addProperty(attributes, "MODEL_FACTORY", modelFactoryType); - - final String resourceType = deleteEntityByIdCommandData.getResourceModelClassFqn(); - addProperty(attributes, "RESOURCE", resourceType); - - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - - /** - * Add type to property list. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + final ResourceModelFile resourceFile = new ResourceModelFile(data.getResourceModelName()); + + phpClassTypesBuilder + .appendProperty("ENTITY_NAME", data.getEntityName()) + .appendProperty("NAMESPACE", file.getNamespace(data.getModuleName())) + .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.getNamespaceBuilder(data.getModuleName()).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 index 9748c5fb5..7d96be42c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java @@ -7,40 +7,40 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; 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.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class DeleteEntityControllerFileGenerator extends FileGenerator { - private final DeleteEntityControllerFileData fileData; + private final DeleteEntityControllerFileData data; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; - private final List uses; + private final DeleteActionFile file; /** * Delete Entity Controller File Generator. - * @param fileData DeleteEntityControllerFileData + * @param data DeleteEntityControllerFileData * @param project Project */ public DeleteEntityControllerFileGenerator( - final DeleteEntityControllerFileData fileData, + final DeleteEntityControllerFileData data, final @NotNull Project project ) { super(project); - this.fileData = fileData; + this.data = data; fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); moduleIndex = ModuleIndex.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); - uses = new ArrayList<>(); + file = new DeleteActionFile(data.getEntityName()); } /** @@ -53,55 +53,54 @@ public DeleteEntityControllerFileGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - fileData.getModuleName() + data.getModuleName() ); final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - DeleteActionFile.getDirectory(fileData.getEntityName()) + file.getDirectory() ); return fileFromTemplateGenerator.generate( - DeleteActionFile.getInstance(), + file, getAttributes(), baseDirectory, actionName ); } - @Override - protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", fileData.getNamespace()); - attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); - attributes.setProperty("CLASS_NAME", DeleteActionFile.CLASS_NAME); - attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); - attributes.setProperty("ENTITY_ID", fileData.getEntityId()); - addProperty(attributes, "DELETE_COMMAND", fileData.getDeleteCommandFqn()); - addProperty(attributes, "CONTEXT", BackendModuleType.CONTEXT.getType()); - addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); - addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType()); - addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); - addProperty(attributes, "IMPLEMENTS_POST", HttpMethod.POST.getInterfaceFqn()); - addProperty(attributes, "IMPLEMENTS_GET", HttpMethod.GET.getInterfaceFqn()); - addProperty(attributes, "NO_SUCH_ENTITY_EXCEPTION", - ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType()); - addProperty(attributes, "COULD_NOT_DELETE", - ExceptionType.COULD_NOT_DELETE.getType()); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } - /** - * Add type to properties. + * Fill delete action file attributes. * - * @param properties Properties - * @param propertyName String - * @param type String + * @param attributes Properties */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + + phpClassTypesBuilder + .appendProperty("NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).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.getEntityName() + ).getClassFqn(data.getModuleName()) + ) + .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 index 24a92507e..7cc40a357 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java @@ -13,27 +13,25 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; 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 com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class EditEntityActionGenerator extends FileGenerator { private final Project project; - private final EditActionFile file; private final EditEntityActionData data; private final boolean checkFileAlreadyExists; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; - private final List uses; + private final EditActionFile file; /** * Edit entity action/controller file generator constructor. @@ -64,11 +62,10 @@ public EditEntityActionGenerator( this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; - file = new EditActionFile(data.getEntityName()); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); moduleIndex = ModuleIndex.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); - uses = new ArrayList<>(); + file = new EditActionFile(data.getEntityName()); } /** @@ -81,7 +78,7 @@ public EditEntityActionGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass editActionClass = GetPhpClassByFQN.getInstance(project).execute( - data.getClassFqn() + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (this.checkFileAlreadyExists && editActionClass != null) { @@ -110,36 +107,23 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", data.getNamespace()); - attributes.setProperty("ENTITY_NAME", data.getEntityName()); - attributes.setProperty("CLASS_NAME", file.getClassName()); - attributes.setProperty("ADMIN_RESOURCE", data.getAcl()); - attributes.setProperty("MENU_IDENTIFIER", data.getMenu()); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); - addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); - addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn()); - addProperty(attributes, "RESULT_INTERFACE", - FrameworkLibraryType.RESULT_INTERFACE.getType() - ); - addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType()); - addProperty(attributes, "RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType()); + phpClassTypesBuilder + .appendProperty("NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).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(uses)); - } - - /** - * Add type to properties. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java index 0e8f7f44b..81082172f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java @@ -13,13 +13,12 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile; import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.stream.Collectors; @@ -33,7 +32,7 @@ public class FormGenericButtonBlockGenerator extends FileGenerator { private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; - private final List uses; + private final FormGenericButtonBlockFile file; /** * Generic Button Block generator constructor. @@ -67,7 +66,7 @@ public FormGenericButtonBlockGenerator( fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); - uses = new ArrayList<>(); + file = new FormGenericButtonBlockFile(); } /** @@ -80,7 +79,7 @@ public FormGenericButtonBlockGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass genericButtonClass = GetPhpClassByFQN.getInstance(project).execute( - data.getClassFqn() + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (this.checkFileAlreadyExists && genericButtonClass != null) { @@ -110,34 +109,23 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", data.getNamespace()); - attributes.setProperty("ENTITY_NAME", data.getEntityName()); - attributes.setProperty("CLASS_NAME", FormGenericButtonBlockFile.CLASS_NAME); - attributes.setProperty("ENTITY_ID", data.getEntityId()); - + 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()); - attributes.setProperty("ENTITY_ID_GETTER", entityIdGetter); - addProperty(attributes, "CONTEXT", FormGenericButtonBlockFile.CONTEXT); - addProperty(attributes, "URL", FrameworkLibraryType.URL.getType()); - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } + phpClassTypesBuilder + .appendProperty("NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).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); - /** - * Add type to property list. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + attributes.setProperty("USES", + PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())); } } 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 ff7ab2d44..585369a52 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 = FileFromTemplateGenerator.getInstance(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 = ModuleIndex.getInstance(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,16 @@ 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()), + ControllerBackendPhp.getInstance(data.getActionClassName()), attributes, parentDirectory, actionName ); } else { controllerFile = fileFromTemplateGenerator.generate( - ControllerFrontendPhp.getInstance(controllerFileData.getActionClassName()), + ControllerFrontendPhp.getInstance(data.getActionClassName()), attributes, parentDirectory, actionName @@ -182,12 +184,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 +199,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 +210,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/SaveEntityCommandGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java index 4dba29d63..4246864c1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -16,6 +16,10 @@ 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.indexes.ModuleIndex; +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; @@ -31,6 +35,7 @@ public class SaveEntityCommandGenerator extends FileGenerator { private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final boolean checkFileAlreadyExists; + private final SaveEntityCommandFile file; /** * Save entity command generator constructor. @@ -64,6 +69,7 @@ public SaveEntityCommandGenerator( fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); + file = new SaveEntityCommandFile(data.getEntityName()); } /** @@ -76,7 +82,7 @@ public SaveEntityCommandGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass saveEntityCommandClass = GetPhpClassByFQN.getInstance(project).execute( - data.getClassFqn() + file.getClassFqn(data.getModuleName()) ); if (this.checkFileAlreadyExists && saveEntityCommandClass != null) { @@ -88,11 +94,11 @@ public PsiFile generate(final @NotNull String actionName) { ); final PsiDirectory saveCommandFileBaseDir = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - SaveEntityCommandFile.getDirectory(data.getEntityName()) + file.getDirectory() ); return fileFromTemplateGenerator.generate( - new SaveEntityCommandFile(), + file, getAttributes(), saveCommandFileBaseDir, actionName @@ -106,11 +112,10 @@ public PsiFile generate(final @NotNull String actionName) { */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - attributes.setProperty("NAMESPACE", data.getNamespace()); - - PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); phpClassTypesBuilder + .appendProperty("NAMESPACE", file.getNamespace(data.getModuleName())) .appendProperty("ENTITY_NAME", data.getEntityName()) .appendProperty("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME) .append("EXCEPTION", "Exception") @@ -118,15 +123,33 @@ protected void fillAttributes(final @NotNull Properties attributes) { .append("COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getType()) .append("LOGGER", FrameworkLibraryType.LOGGER.getType()); - final String dtoType = data.getDataModelClassFqn(); + final ModelFile modelFile = new ModelFile(data.getModelName()); + final ResourceModelFile resourceModelFile = + new ResourceModelFile(data.getResourceModelName()); + + final String modelType = modelFile.getNamespaceBuilder(data.getModuleName()).getClassFqn(); + final String modelFactoryType = modelType.concat("Factory"); + final String resourceType = resourceModelFile + .getNamespaceBuilder(data.getModuleName()).getClassFqn(); + + if (data.isDtoWithInterface()) { + final DataModelInterfaceFile dataModelInterfaceFile = + new DataModelInterfaceFile(data.getDtoInterfaceName()); + final String dtoType = dataModelInterfaceFile + .getNamespaceBuilder(data.getModuleName()).getClassFqn(); + phpClassTypesBuilder.append("DTO", dtoType); + } else { + final DataModelFile dataModelFile = new DataModelFile(data.getDtoName()); + final String dtoType = dataModelFile + .getNamespaceBuilder(data.getModuleName()).getClassFqn(); + phpClassTypesBuilder.append("DTO", dtoType); + } + final String dtoProperty = CaseFormat.UPPER_CAMEL.to( CaseFormat.LOWER_CAMEL, data.getEntityName() ); - final String modelType = data.getModelClassFqn(); - final String modelFactoryType = modelType.concat("Factory"); - final String resourceType = data.getResourceModelClassFqn(); - phpClassTypesBuilder.append("DTO", dtoType) + phpClassTypesBuilder .appendProperty("DTO_PROPERTY", dtoProperty) .append("MODEL", modelType) .append("MODEL_FACTORY", modelFactoryType) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java index de779b246..4b695c8ff 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityControllerFileGenerator.java @@ -1,3 +1,8 @@ +/* + * 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; @@ -8,61 +13,62 @@ 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.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; +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.Package; import com.magento.idea.magento2plugin.magento.packages.code.BackendModuleType; import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.jetbrains.annotations.NotNull; public class SaveEntityControllerFileGenerator extends FileGenerator { - private final SaveEntityControllerFileData fileData; + private final SaveEntityControllerFileData data; private final FileFromTemplateGenerator fileFromTemplateGenerator; private final DirectoryGenerator directoryGenerator; private final ModuleIndex moduleIndex; private final Project project; private final boolean checkFileAlreadyExists; - private final List uses; + private final SaveActionFile file; /** * Save Entity Controller File Generator. * - * @param fileData SaveEntityControllerFileData + * @param data SaveEntityControllerFileData * @param project Project */ public SaveEntityControllerFileGenerator( - final @NotNull SaveEntityControllerFileData fileData, + final @NotNull SaveEntityControllerFileData data, final @NotNull Project project ) { - this(fileData, project, true); + this(data, project, true); } /** * Save Entity Controller File Generator. * - * @param fileData SaveEntityControllerFileData + * @param data SaveEntityControllerFileData * @param project Project * @param checkFileAlreadyExists boolean */ public SaveEntityControllerFileGenerator( - final @NotNull SaveEntityControllerFileData fileData, + final @NotNull SaveEntityControllerFileData data, final @NotNull Project project, final boolean checkFileAlreadyExists ) { super(project); - this.fileData = fileData; + this.data = data; this.project = project; this.checkFileAlreadyExists = checkFileAlreadyExists; fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); moduleIndex = ModuleIndex.getInstance(project); directoryGenerator = DirectoryGenerator.getInstance(); - uses = new ArrayList<>(); + file = new SaveActionFile(data.getEntityName()); } /** @@ -75,68 +81,74 @@ public SaveEntityControllerFileGenerator( @Override public PsiFile generate(final @NotNull String actionName) { final PhpClass saveActionClass = GetPhpClassByFQN.getInstance(project).execute( - String.format( - "%s%s%s", - fileData.getNamespace(), - Package.fqnSeparator, - SaveActionFile.CLASS_NAME - ) + file.getNamespaceBuilder(data.getModuleName()).getClassFqn() ); if (this.checkFileAlreadyExists && saveActionClass != null) { return saveActionClass.getContainingFile(); } final PsiDirectory moduleBaseDir = moduleIndex.getModuleDirectoryByModuleName( - fileData.getModuleName() + data.getModuleName() ); final PsiDirectory baseDirectory = directoryGenerator.findOrCreateSubdirectories( moduleBaseDir, - SaveActionFile.getDirectory(fileData.getEntityName()) + file.getDirectory() ); return fileFromTemplateGenerator.generate( - SaveActionFile.getInstance(), + file, getAttributes(), baseDirectory, actionName ); } + /** + * Fill save action file attributes. + * + * @param attributes Properties + */ @Override protected void fillAttributes(final @NotNull Properties attributes) { - uses.add(BackendModuleType.CONTEXT.getType()); - uses.add(FrameworkLibraryType.RESPONSE_INTERFACE.getType()); - uses.add(FrameworkLibraryType.RESULT_INTERFACE.getType()); - attributes.setProperty("NAMESPACE", fileData.getNamespace()); - attributes.setProperty("ENTITY_NAME", fileData.getEntityName()); - attributes.setProperty("CLASS_NAME", SaveActionFile.CLASS_NAME); - attributes.setProperty("ENTITY_ID", fileData.getEntityId()); - attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl()); - addProperty(attributes, "IMPLEMENTS", HttpMethod.POST.getInterfaceFqn()); - addProperty(attributes, "DATA_PERSISTOR", FrameworkLibraryType.DATA_PERSISTOR.getType()); - addProperty(attributes, "ENTITY_DTO", fileData.getDtoType()); - addProperty(attributes, "ENTITY_DTO_FACTORY", fileData.getDtoType().concat("Factory")); - addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType()); - addProperty(attributes, "SAVE_COMMAND", fileData.getSaveCommandFqn()); - addProperty(attributes, "DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()); - addProperty(attributes, "COULD_NOT_SAVE", SaveActionFile.COULD_NOT_SAVE); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + String dtoType; - attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); - } + if (data.isDtoWithInterface()) { + final DataModelInterfaceFile dataModelInterfaceFile = + new DataModelInterfaceFile(data.getDtoInterfaceName()); + dtoType = dataModelInterfaceFile + .getNamespaceBuilder(data.getModuleName()).getClassFqn(); + } else { + final DataModelFile dataModelFile = new DataModelFile(data.getDtoName()); + dtoType = dataModelFile + .getNamespaceBuilder(data.getModuleName()).getClassFqn(); + } - /** - * Add type to properties. - * - * @param properties Properties - * @param propertyName String - * @param type String - */ - protected void addProperty( - final @NotNull Properties properties, - final String propertyName, - final String type - ) { - uses.add(type); - properties.setProperty(propertyName, PhpClassGeneratorUtil.getNameFromFqn(type)); + phpClassTypesBuilder + .appendProperty("NAMESPACE", + file.getNamespaceBuilder(data.getModuleName()).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.getEntityName() + ).getClassFqn(data.getModuleName()) + ) + .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/UiComponentFormGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java index 84a4f4a95..9379f111b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java @@ -14,33 +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; /** * 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; } @@ -68,12 +72,12 @@ public PsiFile generate(final String actionName) { */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") protected void generateButtonClasses(final @NotNull String actionName) { - for (final UiComponentFormButtonData buttonData : uiFormFileData.getButtons()) { + for (final UiComponentFormButtonData buttonData : data.getButtons()) { new UiComponentFormButtonBlockGenerator( buttonData, project, - uiFormFileData.getEntityName(), - uiFormFileData.getEntityId() + data.getEntityName(), + data.getEntityId() ).generate(actionName); } } @@ -92,59 +96,82 @@ protected PsiFile createForm( final FileFromTemplateGenerator fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); - final String moduleName = uiFormFileData.getModuleName(); - PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + final String moduleName = data.getModuleName(); + final PsiDirectory parentDirectory = ModuleIndex.getInstance(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); + + 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.findModuleConfigFile( uiComponentFormXml.getFileName(), getArea(area), formName, project ); + if (formFile == null) { formFile = (XmlFile) fileFromTemplateGenerator.generate( uiComponentFormXml, getAttributes(), - parentDirectory, + formDirectory, actionName ); } - - new XmlDeclarationsGenerator(uiFormFileData, project).generate(formFile); + 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.getDataProviderName() + ).getNamespaceBuilder( + data.getModuleName(), + 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 082e1b92b..a1efaa809 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java @@ -14,10 +14,11 @@ 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.NamespaceBuilder; +import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; -import com.magento.idea.magento2plugin.magento.files.UiComponentGridXml; -import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderFile; +import com.magento.idea.magento2plugin.magento.files.UiComponentGridXmlFile; 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; @@ -32,8 +33,9 @@ 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; @@ -42,16 +44,16 @@ public class UiComponentGridXmlGenerator extends FileGenerator { /** * 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.data = data; directoryGenerator = DirectoryGenerator.getInstance(); moduleIndex = ModuleIndex.getInstance(project); fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); @@ -60,28 +62,21 @@ public UiComponentGridXmlGenerator( @Override public PsiFile generate(final String actionName) { - final String moduleName = this.uiComponentGridData.getModuleName(); - PsiDirectory uiComponentDirectory = this.moduleIndex.getModuleDirectoryByModuleName( + final String moduleName = this.data.getModuleName(); + final PsiDirectory parentDirectory = this.moduleIndex.getModuleDirectoryByModuleName( moduleName ); final String subdirectory = String.format( "%s/%s/%s", Package.moduleViewDir, - this.uiComponentGridData.getArea(), + this.data.getArea(), Package.moduleViewUiComponentDir ); - - for (final String directory: subdirectory.split(File.separator)) { - uiComponentDirectory = directoryGenerator.findOrCreateSubdirectory( - uiComponentDirectory, - directory - ); - } - - final UiComponentGridXml uiGridXml = new UiComponentGridXml(uiComponentGridData.getName()); + final PsiDirectory uiComponentDirectory = + directoryGenerator.findOrCreateSubdirectories(parentDirectory, subdirectory); return this.fileFromTemplateGenerator.generate( - uiGridXml, + new UiComponentGridXmlFile(data.getName()), getAttributes(), uiComponentDirectory, actionName @@ -95,36 +90,47 @@ public PsiFile generate(final String actionName) { */ @Override protected void fillAttributes(final @NotNull 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(); + final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder(); + final String dataProviderClassName = + new UiComponentDataProviderFile( + data.getDataProviderName() + ).getNamespaceBuilder( + data.getModuleName(), + 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); } @@ -135,13 +141,13 @@ protected void fillAttributes(final @NotNull Properties attributes) { * @param attributes Properties */ private void prepareColumnsProperties(final @NotNull Properties attributes) { - final List> columnsProperties = uiComponentGridData.getColumns(); + 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(uiComponentGridData.getIdFieldName())) { + if (columnName.equals(data.getIdFieldName())) { continue; } @@ -167,7 +173,7 @@ private void prepareColumnsProperties(final @NotNull Properties attributes) { try { columnsTextList.add( getCodeTemplateUtil.execute( - UiComponentGridXml.COLUMN_TEMPLATE, + UiComponentGridXmlFile.COLUMN_TEMPLATE, fillColumnCodeTemplateAttributes( columnName, columnLabel, @@ -185,7 +191,7 @@ private void prepareColumnsProperties(final @NotNull Properties attributes) { } final NamespaceBuilder actionColumnNamespace = new NamespaceBuilder( - uiComponentGridData.getModuleName(), + data.getModuleName(), GridActionColumnFile.CLASS_NAME, GridActionColumnFile.DIRECTORY ); 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..4fabcd80d 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; @@ -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 index b787fd619..6004a57d5 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/GeneratorHandler.java @@ -79,7 +79,10 @@ public void setGenerator(final FileGenerator generator) { * Run generator. */ public final void generate() { - generator.generate(getContextData().getActionName(), getContextData().hasOpenFileFlag()); + generator.generate( + getContextData().getActionName(), + getContextData().checkIfHasOpenFileFlag() + ); } /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java index 43404c85a..6438f3c43 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/FormGenericButtonBlockFile.java @@ -10,13 +10,14 @@ import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; import org.jetbrains.annotations.NotNull; -public class FormGenericButtonBlockFile implements ModuleFileInterface { +public final class FormGenericButtonBlockFile implements ModuleFileInterface { public static final String CLASS_NAME = "GenericButton"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento PHP Form Generic Button Block Class"; public static final String DIRECTORY = "Block/Form"; public static final String CONTEXT = "Magento\\Backend\\Block\\Widget\\Context"; + private NamespaceBuilder namespaceBuilder; /** * Get namespace builder for file. @@ -25,14 +26,18 @@ public class FormGenericButtonBlockFile implements ModuleFileInterface { * * @return String */ - public static @NotNull NamespaceBuilder getNamespaceBuilder( + public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - DIRECTORY - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + DIRECTORY + ); + } + + return namespaceBuilder; } @Override diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java index 14d064008..da8ca90b7 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ModelFile.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; public class ModelFile extends AbstractPhpClass { + public static final String ABSTRACT_MODEL = "Magento\\Framework\\Model\\AbstractModel"; public static final String MODEL_DIRECTORY = "Model"; 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 87% rename from src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java rename to src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXmlFile.java index 468067cbb..8e05d35f6 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXml.java +++ b/src/com/magento/idea/magento2plugin/magento/files/UiComponentGridXmlFile.java @@ -8,7 +8,8 @@ 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"; @@ -19,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 index fc998a6ba..90317408a 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/DeleteActionFile.java @@ -12,48 +12,50 @@ import org.jetbrains.annotations.NotNull; public final class DeleteActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Delete"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Delete Controller Class"; private static final String DIRECTORY = "Controller/Adminhtml"; - private static final DeleteActionFile INSTANCE = new DeleteActionFile(); + private final String entityName; + private NamespaceBuilder namespaceBuilder; /** - * Get singleton instance of the class. + * Delete action file constructor. * - * @return Delete + * @param entityName String */ - public static DeleteActionFile getInstance() { - return INSTANCE; + public DeleteActionFile(final @NotNull String entityName) { + this.entityName = entityName; } /** * Get namespace builder for file. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull NamespaceBuilder getNamespaceBuilder( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory(entityName) - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; } /** * Get Directory path from the module root. * - * @param entityName String - * * @return String */ - public static String getDirectory(final @NotNull String entityName) { + public String getDirectory() { return DIRECTORY.concat("/" + entityName); } diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java index 4f8b1956a..1df3c774b 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/EditActionFile.java @@ -12,11 +12,13 @@ import org.jetbrains.annotations.NotNull; public final class EditActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Edit"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Edit Action Controller Class"; private static final String DIRECTORY = "Controller/Adminhtml"; private final String entityName; + private NamespaceBuilder namespaceBuilder; /** * Edit action (adminhtml) file. @@ -37,11 +39,15 @@ public EditActionFile(final @NotNull String entityName) { public @NotNull NamespaceBuilder getNamespaceBuilder( final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory() - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; } /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java index 20bdfc2f5..6999e5419 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/actions/SaveActionFile.java @@ -12,50 +12,52 @@ import org.jetbrains.annotations.NotNull; public final class SaveActionFile implements ModuleFileInterface { + public static final String CLASS_NAME = "Save"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Entity Save Controller Class"; private static final String DIRECTORY = "Controller/Adminhtml"; - private static final SaveActionFile INSTANCE = new SaveActionFile(); public static final String COULD_NOT_SAVE = "Magento\\Framework\\Exception\\CouldNotSaveException"; + private final String entityName; + private NamespaceBuilder namespaceBuilder; /** - * Get singleton instance of the class. + * Save action file controller. * - * @return SaveAction + * @param entityName String */ - public static SaveActionFile getInstance() { - return INSTANCE; + public SaveActionFile(final @NotNull String entityName) { + this.entityName = entityName; } /** * Get namespace builder for file. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull NamespaceBuilder getNamespaceBuilder( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory(entityName) - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; } /** * Get Directory path from the module root. * - * @param entityName String - * * @return String */ - public static String getDirectory(final @NotNull String entityName) { + public String getDirectory() { return DIRECTORY.concat("/" + entityName); } diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java index 9b3294190..48814fef8 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -12,58 +12,68 @@ import org.jetbrains.annotations.NotNull; public class DeleteEntityByIdCommandFile implements ModuleFileInterface { + public static final String CLASS_NAME = "DeleteByIdCommand"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Delete Entity By Id Command"; private static final String DIRECTORY = "Command"; + private final String entityName; + private NamespaceBuilder namespaceBuilder; + + /** + * Delete entity by id command file constructor. + * + * @param entityName String + */ + public DeleteEntityByIdCommandFile(final @NotNull String entityName) { + this.entityName = entityName; + } /** * Get namespace. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull String getNamespace( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull String getNamespace( + final @NotNull String moduleName ) { - return getNamespaceBuilder(moduleName, entityName).getNamespace(); + return getNamespaceBuilder(moduleName).getNamespace(); } /** * Get class FQN. * * @param moduleName String - * @param entityName String * * @return String */ - public static String getClassFqn( - final @NotNull String moduleName, - final @NotNull String entityName + public String getClassFqn( + final @NotNull String moduleName ) { - return getNamespaceBuilder(moduleName, entityName).getClassFqn(); + return getNamespaceBuilder(moduleName).getClassFqn(); } /** * Get namespace builder for file. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull NamespaceBuilder getNamespaceBuilder( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory(entityName) - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory(entityName) + ); + } + + return namespaceBuilder; } /** diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java index 5a03ec49b..3dae5c809 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/SaveEntityCommandFile.java @@ -12,68 +12,76 @@ import org.jetbrains.annotations.NotNull; public class SaveEntityCommandFile implements ModuleFileInterface { + public static final String CLASS_NAME = "SaveCommand"; public static final String FILE_EXTENSION = "php"; public static final String TEMPLATE = "Magento Save Entity Command Model"; private static final String DIRECTORY = "Command"; + private final String entityName; + private NamespaceBuilder namespaceBuilder; + + /** + * Save entity command file constructor. + * + * @param entityName String + */ + public SaveEntityCommandFile(final @NotNull String entityName) { + this.entityName = entityName; + } /** * Get namespace. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull String getNamespace( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull String getNamespace( + final @NotNull String moduleName ) { - return getNamespaceBuilder(moduleName, entityName).getNamespace(); + return getNamespaceBuilder(moduleName).getNamespace(); } /** * Get class FQN. * * @param moduleName String - * @param entityName String * * @return String */ - public static String getClassFqn( - final @NotNull String moduleName, - final @NotNull String entityName + public String getClassFqn( + final @NotNull String moduleName ) { - return getNamespaceBuilder(moduleName, entityName).getClassFqn(); + return getNamespaceBuilder(moduleName).getClassFqn(); } /** * Get namespace builder for file. * * @param moduleName String - * @param entityName String * * @return String */ - public static @NotNull NamespaceBuilder getNamespaceBuilder( - final @NotNull String moduleName, - final @NotNull String entityName + public @NotNull NamespaceBuilder getNamespaceBuilder( + final @NotNull String moduleName ) { - return new NamespaceBuilder( - moduleName, - CLASS_NAME, - getDirectory(entityName) - ); + if (namespaceBuilder == null) { + namespaceBuilder = new NamespaceBuilder( + moduleName, + CLASS_NAME, + getDirectory() + ); + } + + return namespaceBuilder; } /** * Get directory for save command file. * - * @param entityName String - * * @return String */ - public static String getDirectory(final @NotNull String entityName) { + public String getDirectory() { return DIRECTORY.concat("/" + entityName); } diff --git a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php index d55ca4843..2bac73502 100644 --- a/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php +++ b/testData/actions/generation/generator/SaveEntityActionGenerator/generateSaveEntityActionWithoutInterfaceFile/Save.php @@ -3,8 +3,8 @@ namespace Foo\Bar\Controller\Adminhtml\Company; use Foo\Bar\Command\Company\SaveCommand; -use Foo\Bar\Model\CompanyModel\CompanyModel; -use Foo\Bar\Model\CompanyModel\CompanyModelFactory; +use Foo\Bar\Model\Data\CompanyData; +use Foo\Bar\Model\Data\CompanyDataFactory; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; use Magento\Framework\App\Action\HttpPostActionInterface; @@ -37,7 +37,7 @@ class Save extends Action implements HttpPostActionInterface private $saveCommand; /** - * @var CompanyModelFactory + * @var CompanyDataFactory */ private $entityDataFactory; @@ -45,13 +45,13 @@ class Save extends Action implements HttpPostActionInterface * @param Context $context * @param DataPersistorInterface $dataPersistor * @param SaveCommand $saveCommand - * @param CompanyModelFactory $entityDataFactory + * @param CompanyDataFactory $entityDataFactory */ public function __construct( Context $context, DataPersistorInterface $dataPersistor, SaveCommand $saveCommand, - CompanyModelFactory $entityDataFactory + CompanyDataFactory $entityDataFactory ) { parent::__construct($context); @@ -71,7 +71,7 @@ public function execute() $params = $this->getRequest()->getParams(); try { - /** @var CompanyModel|DataObject $entityModel */ + /** @var CompanyData|DataObject $entityModel */ $entityModel = $this->entityDataFactory->create(); $entityModel->addData($params['general']); $this->saveCommand->execute($entityModel); diff --git a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php index b985bc32c..533eb48e5 100644 --- a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php +++ b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php @@ -3,9 +3,9 @@ namespace Foo\Bar\Command\Book; use Exception; -use Foo\Bar\Data\BookData; use Foo\Bar\Model\BookModel; use Foo\Bar\Model\BookModelFactory; +use Foo\Bar\Model\Data\BookData; use Foo\Bar\Model\ResourceModel\BookResource; use Magento\Framework\DataObject; use Magento\Framework\Exception\CouldNotSaveException; diff --git a/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml index 9553a38d1..15b70e2b3 100644 --- a/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml +++ b/testData/actions/generation/generator/UiComponentFormGenerator/generateFormXmlFile/my_form.xml @@ -15,17 +15,17 @@ my_form.my_form_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 afccc39bd..12c11dbc2 100644 --- a/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml +++ b/testData/actions/generation/generator/UiComponentGridXmlGenerator/generateUiGridWithoutToolbar/custom_entity_grid.xml @@ -50,10 +50,5 @@ desc - - - entity_id - - 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 594fa4be0..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,13 +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 ACTION_NAME = "test"; private static final String ENTITY_NAME = "Book"; + private static final String BLOCK_DIRECTORY = "Block/Form/" + ENTITY_NAME; + private static final String ACTION_NAME = "test"; private static final String ENTITY_ID = "book_id"; - public static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Block/Form"; + public static final String EXPECTED_DIRECTORY + = "src/app/code/Foo/Bar/Block/Form/" + ENTITY_NAME; /** * Test creation Block type Save. diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java index 41317c8c8..6df775add 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGeneratorTest.java @@ -13,7 +13,8 @@ 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"; + private static final String EXPECTED_DIRECTORY + = "src/app/code/Foo/Bar/Block/Form/" + ENTITY_NAME; /** * Test generation of form ui component generic button block. @@ -31,7 +32,7 @@ public void testGenerateFormGenericButtonBlockFile() { false ); final String filePath = this.getFixturePath( - new FormGenericButtonBlockFile(MODULE_NAME).getFileName() + new FormGenericButtonBlockFile(MODULE_NAME, ENTITY_NAME).getFileName() ); assertGeneratedFileIsCorrect( diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java index 19acda4a0..e5943a706 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGeneratorTest.java @@ -20,7 +20,7 @@ public class GridActionColumnFileGeneratorTest extends BaseGeneratorTestCase { * Test generation of grid actions column file. */ public void testGenerateGridActionColumnFile() { - final GridActionColumnFile file = new GridActionColumnFile(MODULE_NAME); + final GridActionColumnFile file = new GridActionColumnFile(MODULE_NAME, ENTITY_NAME); final GridActionColumnData data = new GridActionColumnData( MODULE_NAME, ENTITY_NAME, 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 31d7d4d6c..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,12 +12,14 @@ 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 DATA_PROVIDER_NAME = "DataProvider"; @@ -53,6 +55,18 @@ 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. * @@ -92,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. * From 519026bdfb2583da6a29db968f7af8edb0e45ae7 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 7 Apr 2021 14:55:04 +0300 Subject: [PATCH 81/84] Static fixes, fixed observer reference --- .../generation/data/EntityDataMapperData.java | 7 +-- .../data/SaveEntityCommandData.java | 6 +-- .../data/SaveEntityControllerFileData.java | 6 +-- .../generation/data/UiComponentGridData.java | 1 + .../NewEntityLayoutDtoConverter.java | 2 +- .../data/dialog/NewEntityDialogData.java | 48 +++++++++---------- .../generation/dialog/util/ProcessWorker.java | 10 ++-- .../UiComponentGridXmlGenerator.java | 1 - .../xml/ObserverDeclarationInspection.java | 7 +++ .../magento/files/AbstractPhpFile.java | 4 +- .../ObserverNameReferenceProvider.java | 1 + .../generator/DeleteEntityGeneratorTest.java | 4 +- 12 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java index 1ce9e75e1..4a4e24c68 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/EntityDataMapperData.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; +@SuppressWarnings({"PMD.ExcessiveParameterList", "PMD.TooManyFields"}) public class EntityDataMapperData { private final String moduleName; @@ -14,7 +15,7 @@ public class EntityDataMapperData { private final String modelName; private final String dtoName; private final String dtoInterfaceName; - private final boolean isDtoWithInterface; + private final boolean dtoWithInterface; /** * Magento entity data mapper data constructor. @@ -39,7 +40,7 @@ public EntityDataMapperData( this.modelName = modelName; this.dtoName = dtoName; this.dtoInterfaceName = dtoInterfaceName; - this.isDtoWithInterface = isDtoWithInterface; + this.dtoWithInterface = isDtoWithInterface; } /** @@ -93,6 +94,6 @@ public String getDtoInterfaceName() { * @return boolean */ public boolean isDtoWithInterface() { - return isDtoWithInterface; + return dtoWithInterface; } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java index 24f43723c..257b932ab 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityCommandData.java @@ -15,7 +15,7 @@ public class SaveEntityCommandData { private final String resourceModelName; private final String dtoName; private final String dtoInterfaceName; - private final boolean isDtoWithInterface; + private final boolean dtoWithInterface; /** * Save Command DTO Constructor. @@ -43,7 +43,7 @@ public SaveEntityCommandData( this.resourceModelName = resourceModelName; this.dtoName = dtoName; this.dtoInterfaceName = dtoInterfaceName; - this.isDtoWithInterface = isDtoWithInterface; + this.dtoWithInterface = isDtoWithInterface; } /** @@ -106,6 +106,6 @@ public String getDtoInterfaceName() { * @return boolean */ public boolean isDtoWithInterface() { - return 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 index d09561a14..5508f1bc3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java @@ -15,7 +15,7 @@ public class SaveEntityControllerFileData { private final String entityId; private final String dtoName; private final String dtoInterfaceName; - private final boolean isDtoWithInterface; + private final boolean dtoWithInterface; /** * Controller save file constructor. @@ -43,7 +43,7 @@ public SaveEntityControllerFileData( this.entityId = entityId; this.dtoName = dtoName; this.dtoInterfaceName = dtoInterfaceName; - this.isDtoWithInterface = isDtoWithInterface; + this.dtoWithInterface = isDtoWithInterface; } /** @@ -106,6 +106,6 @@ public String getDtoInterfaceName() { * @return boolean */ public boolean isDtoWithInterface() { - return isDtoWithInterface; + return dtoWithInterface; } } 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 0120543a1..99d0bc118 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/UiComponentGridData.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +@SuppressWarnings({"PMD.ExcessiveParameterList"}) public class UiComponentGridData { private final String moduleName; 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 index e83c05a2a..b30c59903 100644 --- 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 @@ -22,7 +22,7 @@ public class NewEntityLayoutDtoConverter extends NewEntityLayoutData */ public NewEntityLayoutDtoConverter( final @NotNull EntityCreatorContextData generationContextData, - final @NotNull NewEntityDialogData newEntityDialogData + final @NotNull NewEntityDialogData newEntityDialogData //NOPMD ) { super( generationContextData.getModuleName(), 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 index 84dc1939d..8d8fab692 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java @@ -15,20 +15,20 @@ public class NewEntityDialogData implements DialogData { private final String idFieldName; private final String tableEngine; private final String tableResource; - private final boolean hasAdminUiComponents; - private final boolean hasDtoInterface; + 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 hasToolbar; - private final boolean hasToolbarBookmarks; - private final boolean hasToolbarColumnsControl; - private final boolean hasToolbarListingFilters; - private final boolean hasToolbarListingPaging; - private final boolean hasToolbarFullTextSearch; + 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; @@ -105,18 +105,18 @@ public NewEntityDialogData( this.idFieldName = idFieldName; this.tableEngine = tableEngine; this.tableResource = tableResource; - this.hasAdminUiComponents = hasAdminUiComponents; - this.hasDtoInterface = hasDtoInterface; + this.adminUiComponents = hasAdminUiComponents; + this.dtoInterface = hasDtoInterface; this.route = route; this.formLabel = formLabel; this.formName = formName; this.gridName = gridName; - this.hasToolbar = hasToolbar; - this.hasToolbarBookmarks = hasToolbarBookmarks; - this.hasToolbarColumnsControl = hasToolbarColumnsControl; - this.hasToolbarListingFilters = hasToolbarListingFilters; - this.hasToolbarListingPaging = hasToolbarListingPaging; - this.hasToolbarFullTextSearch = hasToolbarFullTextSearch; + 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; @@ -178,7 +178,7 @@ public String getTableResource() { * @return boolean */ public boolean hasAdminUiComponents() { - return hasAdminUiComponents; + return adminUiComponents; } /** @@ -187,7 +187,7 @@ public boolean hasAdminUiComponents() { * @return boolean */ public boolean hasDtoInterface() { - return hasDtoInterface; + return dtoInterface; } /** @@ -232,7 +232,7 @@ public String getGridName() { * @return boolean */ public boolean hasToolbar() { - return hasToolbar; + return toolbar; } /** @@ -241,7 +241,7 @@ public boolean hasToolbar() { * @return boolean */ public boolean hasToolbarBookmarks() { - return hasToolbarBookmarks; + return toolbarBookmarks; } /** @@ -250,7 +250,7 @@ public boolean hasToolbarBookmarks() { * @return boolean */ public boolean hasToolbarColumnsControl() { - return hasToolbarColumnsControl; + return toolbarColumnsControl; } /** @@ -259,7 +259,7 @@ public boolean hasToolbarColumnsControl() { * @return boolean */ public boolean hasToolbarListingFilters() { - return hasToolbarListingFilters; + return toolbarListingFilters; } /** @@ -268,7 +268,7 @@ public boolean hasToolbarListingFilters() { * @return boolean */ public boolean hasToolbarListingPaging() { - return hasToolbarListingPaging; + return toolbarListingPaging; } /** @@ -277,7 +277,7 @@ public boolean hasToolbarListingPaging() { * @return boolean */ public boolean hasToolbarFullTextSearch() { - return hasToolbarFullTextSearch; + return toolbarFullTextSearch; } /** 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 index 28bf02c3b..f8add1558 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/util/ProcessWorker.java @@ -69,7 +69,7 @@ public static final class InProgressFlag { /** * Is action finished flag. */ - private boolean isFinished; + private boolean finished; /** * In progress flag constructor. @@ -78,7 +78,7 @@ public static final class InProgressFlag { */ public InProgressFlag(final boolean inProgress) { this.inProgress = inProgress; - isFinished = false; + finished = false; } /** @@ -103,7 +103,7 @@ public void setInProgress(final boolean inProgress) { * Get is progress finished flag value. */ public boolean isFinished() { - return isFinished; + return finished; } /** @@ -111,8 +111,8 @@ public boolean isFinished() { * * @param finished boolean */ - public void setFinished(boolean finished) { - isFinished = finished; + public void setFinished(final boolean finished) { + this.finished = finished; } } } 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 aefea9c18..ef457393d 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java @@ -14,7 +14,6 @@ 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.NamespaceBuilder; import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder; import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile; 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/AbstractPhpFile.java b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java index bd008f2ba..5de4b9341 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/AbstractPhpFile.java @@ -96,9 +96,7 @@ public String getClassName() { * * @return String */ - public String getHumanReadableName() { - return null; - } + public abstract String getHumanReadableName(); @Override public String getFileName() { 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/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java index 892e9dcf7..2533f44e5 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityGeneratorTest.java @@ -34,7 +34,7 @@ public void testGenerateDeleteEntityFile() { deleteEntityControllerFileData, myFixture.getProject() ); - final PsiFile DeleteEntityActionFile = + final PsiFile deleteEntityActionFile = deleteEntityControllerFileGenerator.generate("test"); final String filePath = this.getFixturePath(new DeleteActionFile(MODULE_NAME, ENTITY_NAME).getFileName()); @@ -43,7 +43,7 @@ public void testGenerateDeleteEntityFile() { assertGeneratedFileIsCorrect( expectedFile, EXPECTED_DIRECTORY, - DeleteEntityActionFile + deleteEntityActionFile ); } } From b1390d362bc5e1edbc85f4b380a93940c55fa202 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 7 Apr 2021 15:10:28 +0300 Subject: [PATCH 82/84] Test fixes --- .../actions/generation/data/dialog/NewEntityDialogData.java | 1 + .../dialog/validator/annotation/TypeFieldsRulesParser.java | 4 ++-- .../magento2plugin/magento/files/ControllerBackendPhp.java | 5 +++++ .../magento2plugin/magento/files/ControllerFrontendPhp.java | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) 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 index 8d8fab692..ba6d6c2f3 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/dialog/NewEntityDialogData.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; +@SuppressWarnings({"PMD.ExcessiveParameterList", "PMD.TooManyFields"}) public class NewEntityDialogData implements DialogData { // General tab data. 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 index d5ffcd79f..9436b44f3 100644 --- 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 @@ -60,12 +60,12 @@ public List parseValidationRules() { final String message = ValidationMessageExtractorUtil.extract(annotation); if (rule != null) { - rulePairList.add(new Pair<>(rule, message)); + rulePairList.add(new Pair<>(rule, message)); //NOPMD } } if (!rulePairList.isEmpty()) { - fieldValidationList.add(new FieldValidationData(field, rulePairList)); + fieldValidationList.add(new FieldValidationData(field, rulePairList)); //NOPMD } } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java index 73b41177b..9c08500f0 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ControllerBackendPhp.java @@ -24,6 +24,11 @@ public String getDirectory() { return DEFAULT_DIR; } + @Override + public String getHumanReadableName() { + return null; + } + /** * Get name of backend controller template. * diff --git a/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java b/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java index e3e415e59..93e966df0 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/ControllerFrontendPhp.java @@ -24,6 +24,11 @@ public String getDirectory() { return DEFAULT_DIR; } + @Override + public String getHumanReadableName() { + return null; + } + /** * Get name of frontend controller template. * From c065a5a1e7937ecef13fc10e05eec93482c51a67 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 7 Apr 2021 15:39:17 +0300 Subject: [PATCH 83/84] Fixed Windows compatibility --- .../actions/generation/generator/util/DirectoryGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b59adb67d..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,8 +8,8 @@ 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.io.File; import java.util.Arrays; import org.jetbrains.annotations.NotNull; From 773d57e04f007d4673567eb839c2b3a52bb29801 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 7 Apr 2021 15:55:27 +0300 Subject: [PATCH 84/84] Fixed Windows compatibility 2 --- .../magento2plugin/magento/files/queries/GetListQueryFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java index 66e1706f9..db4732721 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/queries/GetListQueryFile.java @@ -6,7 +6,7 @@ package com.magento.idea.magento2plugin.magento.files.queries; import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; -import java.io.File; +import com.magento.idea.magento2plugin.magento.packages.File; import org.jetbrains.annotations.NotNull; public final class GetListQueryFile extends AbstractPhpFile {