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 ;
2828import com .magento .idea .magento2plugin .actions .generation .data .SaveEntityCommandData ;
29+ import com .magento .idea .magento2plugin .actions .generation .data .SaveEntityControllerFileData ;
2930import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
3031import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormButtonData ;
3132import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormFieldData ;
4041import com .magento .idea .magento2plugin .actions .generation .generator .DataModelInterfaceGenerator ;
4142import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaWhitelistJsonGenerator ;
4243import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaXmlGenerator ;
44+ import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
4345import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
4446import com .magento .idea .magento2plugin .actions .generation .generator .MenuXmlGenerator ;
4547import com .magento .idea .magento2plugin .actions .generation .generator .ModuleCollectionGenerator ;
4648import com .magento .idea .magento2plugin .actions .generation .generator .ModuleControllerClassGenerator ;
4749import com .magento .idea .magento2plugin .actions .generation .generator .ModuleModelGenerator ;
4850import com .magento .idea .magento2plugin .actions .generation .generator .ModuleResourceModelGenerator ;
49- import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
5051import com .magento .idea .magento2plugin .actions .generation .generator .PreferenceDiXmlGenerator ;
5152import com .magento .idea .magento2plugin .actions .generation .generator .RoutesXmlGenerator ;
53+ import com .magento .idea .magento2plugin .actions .generation .generator .SaveEntityControllerFileGenerator ;
5254import com .magento .idea .magento2plugin .actions .generation .generator .SaveEntityCommandGenerator ;
5355import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
5456import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentFormGenerator ;
6264import com .magento .idea .magento2plugin .magento .files .ModuleMenuXml ;
6365import com .magento .idea .magento2plugin .magento .files .ResourceModelPhp ;
6466import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
67+ import com .magento .idea .magento2plugin .magento .files .actions .SaveActionFile ;
6568import com .magento .idea .magento2plugin .magento .files .commands .SaveEntityCommandFile ;
6669import com .magento .idea .magento2plugin .magento .packages .Areas ;
6770import com .magento .idea .magento2plugin .magento .packages .File ;
110113 "PMD.ExcessiveImports" ,
111114 "PMD.GodClass" ,
112115 "PMD.TooManyMethods" ,
113- "PMD.CyclomaticComplexity"
116+ "PMD.CyclomaticComplexity" ,
117+ "PMD.ExcessiveClassLength"
114118})
115119public class NewEntityDialog extends AbstractDialog {
116120 @ NotNull
@@ -282,7 +286,7 @@ private void onOK() {
282286
283287 generateRoutesXmlFile ();
284288 generateViewControllerFile ();
285- generateSubmitControllerFile ();
289+ generateSaveControllerFile ();
286290 generateModelGetListQueryFile ();
287291 generateSaveEntityCommandFile ();
288292 generateDataProviderFile ();
@@ -307,6 +311,49 @@ private void onOK() {
307311 this .setVisible (false );
308312 }
309313
314+ /**
315+ * Generate Save Controller file.
316+ */
317+ private void generateSaveControllerFile () {
318+ final NamespaceBuilder dtoModelNamespace = getDataModelNamespace ();
319+ final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace ();
320+ final NamespaceBuilder namespace = new NamespaceBuilder (
321+ getModuleName (),
322+ SaveActionFile .CLASS_NAME ,
323+ SaveActionFile .getDirectory (getEntityName ())
324+ );
325+ final String dtoType ;
326+
327+ if (createInterface .isSelected ()) {
328+ dtoType = dtoInterfaceModelNamespace .getClassFqn ();
329+ } else {
330+ dtoType = dtoModelNamespace .getClassFqn ();
331+ }
332+
333+ new SaveEntityControllerFileGenerator (new SaveEntityControllerFileData (
334+ getEntityName (),
335+ getModuleName (),
336+ namespace .getNamespace (),
337+ getSaveEntityCommandClassFqn (),
338+ dtoType ,
339+ getAcl (),
340+ getEntityIdColumn ()
341+ ), project ).generate (ACTION_NAME , false );
342+ }
343+
344+ /**
345+ * Get save entity command class Fqn.
346+ *
347+ * @return String
348+ */
349+ private String getSaveEntityCommandClassFqn () {
350+ //TODO: change this stub after the save command generated will be implemented.
351+ final NamespaceBuilder namespaceBuilder =
352+ new NamespaceBuilder (getModuleName (), "SaveCommand" , "Command/" + getEntityName ());
353+
354+ return namespaceBuilder .getClassFqn ();
355+ }
356+
310357 private PsiFile generateModelFile () {
311358 final NamespaceBuilder modelNamespace = getModelNamespace ();
312359 final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace ();
@@ -598,24 +645,11 @@ private String getControllerDirectory() {
598645 return ControllerBackendPhp .DEFAULT_DIR + File .separator ;
599646 }
600647
601- private PsiFile generateSubmitControllerFile () {
602- final NamespaceBuilder namespace = new NamespaceBuilder (
603- getModuleName (),
604- getSubmitActionName (),
605- getViewControllerDirectory ()
606- );
607- return new ModuleControllerClassGenerator (new ControllerFileData (
608- getViewControllerDirectory (),
609- getSubmitActionName (),
610- getModuleName (),
611- Areas .adminhtml .toString (),
612- HttpMethod .POST .toString (),
613- getAcl (),
614- true ,
615- namespace .getNamespace ()
616- ), project ).generate (ACTION_NAME , false );
617- }
618-
648+ /**
649+ * Get Acl id.
650+ *
651+ * @return String
652+ */
619653 public String getAcl () {
620654 return acl .getText ().trim ();
621655 }
0 commit comments