1818import com .magento .idea .magento2plugin .actions .generation .data .DataModelData ;
1919import com .magento .idea .magento2plugin .actions .generation .data .DataModelInterfaceData ;
2020import com .magento .idea .magento2plugin .actions .generation .data .DbSchemaXmlData ;
21+ import com .magento .idea .magento2plugin .actions .generation .data .GetListQueryModelData ;
2122import com .magento .idea .magento2plugin .actions .generation .data .LayoutXmlData ;
2223import com .magento .idea .magento2plugin .actions .generation .data .MenuXmlData ;
2324import com .magento .idea .magento2plugin .actions .generation .data .ModelData ;
24- import com .magento .idea .magento2plugin .actions .generation .data .GetListQueryModelData ;
2525import com .magento .idea .magento2plugin .actions .generation .data .PreferenceDiXmFileData ;
2626import com .magento .idea .magento2plugin .actions .generation .data .ResourceModelData ;
2727import com .magento .idea .magento2plugin .actions .generation .data .RoutesXmlData ;
28+ import com .magento .idea .magento2plugin .actions .generation .data .SaveEntityControllerFileData ;
2829import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
2930import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormButtonData ;
3031import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormFieldData ;
3940import com .magento .idea .magento2plugin .actions .generation .generator .DataModelInterfaceGenerator ;
4041import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaWhitelistJsonGenerator ;
4142import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaXmlGenerator ;
43+ import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
4244import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
4345import com .magento .idea .magento2plugin .actions .generation .generator .MenuXmlGenerator ;
4446import com .magento .idea .magento2plugin .actions .generation .generator .ModuleCollectionGenerator ;
4547import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
4648import com .magento .idea .magento2plugin .actions .generation .generator .ModuleModelGenerator ;
4749import com .magento .idea .magento2plugin .actions .generation .generator .ModuleResourceModelGenerator ;
48- import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
4950import com .magento .idea .magento2plugin .actions .generation .generator .PreferenceDiXmlGenerator ;
5051import com .magento .idea .magento2plugin .actions .generation .generator .RoutesXmlGenerator ;
52+ import com .magento .idea .magento2plugin .actions .generation .generator .SaveEntityControllerFileGenerator ;
5153import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
5254import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentFormGenerator ;
5355import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentGridXmlGenerator ;
6062import com .magento .idea .magento2plugin .magento .files .ModuleMenuXml ;
6163import com .magento .idea .magento2plugin .magento .files .ResourceModelPhp ;
6264import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
65+ import com .magento .idea .magento2plugin .magento .files .actions .SaveActionFile ;
6366import com .magento .idea .magento2plugin .magento .packages .Areas ;
6467import com .magento .idea .magento2plugin .magento .packages .File ;
6568import com .magento .idea .magento2plugin .magento .packages .HttpMethod ;
107110 "PMD.ExcessiveImports" ,
108111 "PMD.GodClass" ,
109112 "PMD.TooManyMethods" ,
110- "PMD.CyclomaticComplexity"
113+ "PMD.CyclomaticComplexity" ,
114+ "PMD.ExcessiveClassLength"
111115})
112116public class NewEntityDialog extends AbstractDialog {
113117 @ NotNull
@@ -279,7 +283,7 @@ private void onOK() {
279283
280284 generateRoutesXmlFile ();
281285 generateViewControllerFile ();
282- generateSubmitControllerFile ();
286+ generateSaveControllerFile ();
283287 generateModelGetListQueryFile ();
284288 generateDataProviderFile ();
285289 generateLayoutFile ();
@@ -303,6 +307,49 @@ private void onOK() {
303307 this .setVisible (false );
304308 }
305309
310+ /**
311+ * Generate Save Controller file.
312+ */
313+ private void generateSaveControllerFile () {
314+ final NamespaceBuilder dtoModelNamespace = getDataModelNamespace ();
315+ final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace ();
316+ final NamespaceBuilder namespace = new NamespaceBuilder (
317+ getModuleName (),
318+ SaveActionFile .CLASS_NAME ,
319+ SaveActionFile .getDirectory (getEntityName ())
320+ );
321+ final String dtoType ;
322+
323+ if (createInterface .isSelected ()) {
324+ dtoType = dtoInterfaceModelNamespace .getClassFqn ();
325+ } else {
326+ dtoType = dtoModelNamespace .getClassFqn ();
327+ }
328+
329+ new SaveEntityControllerFileGenerator (new SaveEntityControllerFileData (
330+ getEntityName (),
331+ getModuleName (),
332+ namespace .getNamespace (),
333+ getSaveEntityCommandClassFqn (),
334+ dtoType ,
335+ getAcl (),
336+ getEntityIdColumn ()
337+ ), project ).generate (ACTION_NAME , false );
338+ }
339+
340+ /**
341+ * Get save entity command class Fqn.
342+ *
343+ * @return String
344+ */
345+ private String getSaveEntityCommandClassFqn () {
346+ //TODO: change this stub after the save command generated will be implemented.
347+ final NamespaceBuilder namespaceBuilder =
348+ new NamespaceBuilder (getModuleName (), "SaveCommand" , "Command/" + getEntityName ());
349+
350+ return namespaceBuilder .getClassFqn ();
351+ }
352+
306353 private PsiFile generateModelFile () {
307354 final NamespaceBuilder modelNamespace = getModelNamespace ();
308355 final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace ();
@@ -574,24 +621,11 @@ private String getControllerDirectory() {
574621 return ControllerBackendPhp .DEFAULT_DIR + File .separator ;
575622 }
576623
577- private PsiFile generateSubmitControllerFile () {
578- final NamespaceBuilder namespace = new NamespaceBuilder (
579- getModuleName (),
580- getSubmitActionName (),
581- getViewControllerDirectory ()
582- );
583- return new ModuleControllerClassGenerator (new ControllerFileData (
584- getViewControllerDirectory (),
585- getSubmitActionName (),
586- getModuleName (),
587- Areas .adminhtml .toString (),
588- HttpMethod .POST .toString (),
589- getAcl (),
590- true ,
591- namespace .getNamespace ()
592- ), project ).generate (ACTION_NAME , false );
593- }
594-
624+ /**
625+ * Get Acl id.
626+ *
627+ * @return String
628+ */
595629 public String getAcl () {
596630 return acl .getText ().trim ();
597631 }
0 commit comments