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 .EntityDataMapperData ;
2223import com .magento .idea .magento2plugin .actions .generation .data .GetListQueryModelData ;
2324import com .magento .idea .magento2plugin .actions .generation .data .LayoutXmlData ;
2627import com .magento .idea .magento2plugin .actions .generation .data .PreferenceDiXmFileData ;
2728import com .magento .idea .magento2plugin .actions .generation .data .ResourceModelData ;
2829import com .magento .idea .magento2plugin .actions .generation .data .RoutesXmlData ;
30+ import com .magento .idea .magento2plugin .actions .generation .data .SaveEntityControllerFileData ;
2931import com .magento .idea .magento2plugin .actions .generation .data .UiComponentDataProviderData ;
3032import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormButtonData ;
3133import com .magento .idea .magento2plugin .actions .generation .data .UiComponentFormFieldData ;
4042import com .magento .idea .magento2plugin .actions .generation .generator .DataModelInterfaceGenerator ;
4143import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaWhitelistJsonGenerator ;
4244import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaXmlGenerator ;
45+ import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
4346import com .magento .idea .magento2plugin .actions .generation .generator .EntityDataMapperGenerator ;
4447import com .magento .idea .magento2plugin .actions .generation .generator .GetListQueryModelGenerator ;
4548import com .magento .idea .magento2plugin .actions .generation .generator .LayoutXmlGenerator ;
5053import com .magento .idea .magento2plugin .actions .generation .generator .ModuleResourceModelGenerator ;
5154import com .magento .idea .magento2plugin .actions .generation .generator .PreferenceDiXmlGenerator ;
5255import com .magento .idea .magento2plugin .actions .generation .generator .RoutesXmlGenerator ;
56+ import com .magento .idea .magento2plugin .actions .generation .generator .SaveEntityControllerFileGenerator ;
5357import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentDataProviderGenerator ;
5458import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentFormGenerator ;
5559import com .magento .idea .magento2plugin .actions .generation .generator .UiComponentGridXmlGenerator ;
6367import com .magento .idea .magento2plugin .magento .files .ModuleMenuXml ;
6468import com .magento .idea .magento2plugin .magento .files .ResourceModelPhp ;
6569import com .magento .idea .magento2plugin .magento .files .UiComponentDataProviderPhp ;
70+ import com .magento .idea .magento2plugin .magento .files .actions .SaveActionFile ;
6671import com .magento .idea .magento2plugin .magento .packages .Areas ;
6772import com .magento .idea .magento2plugin .magento .packages .File ;
6873import com .magento .idea .magento2plugin .magento .packages .HttpMethod ;
111116 "PMD.GodClass" ,
112117 "PMD.TooManyMethods" ,
113118 "PMD.CyclomaticComplexity" ,
114- "PMD.ExcessiveClassLength" ,
119+ "PMD.ExcessiveClassLength"
115120})
116121public class NewEntityDialog extends AbstractDialog {
117122 @ NotNull
@@ -283,7 +288,7 @@ private void onOK() {
283288
284289 generateRoutesXmlFile ();
285290 generateViewControllerFile ();
286- generateSubmitControllerFile ();
291+ generateSaveControllerFile ();
287292 generateEntityDataMapperFile ();
288293 generateModelGetListQueryFile ();
289294 generateDataProviderFile ();
@@ -308,6 +313,49 @@ private void onOK() {
308313 this .setVisible (false );
309314 }
310315
316+ /**
317+ * Generate Save Controller file.
318+ */
319+ private void generateSaveControllerFile () {
320+ final NamespaceBuilder dtoModelNamespace = getDataModelNamespace ();
321+ final NamespaceBuilder dtoInterfaceModelNamespace = getDataModelInterfaceNamespace ();
322+ final NamespaceBuilder namespace = new NamespaceBuilder (
323+ getModuleName (),
324+ SaveActionFile .CLASS_NAME ,
325+ SaveActionFile .getDirectory (getEntityName ())
326+ );
327+ final String dtoType ;
328+
329+ if (createInterface .isSelected ()) {
330+ dtoType = dtoInterfaceModelNamespace .getClassFqn ();
331+ } else {
332+ dtoType = dtoModelNamespace .getClassFqn ();
333+ }
334+
335+ new SaveEntityControllerFileGenerator (new SaveEntityControllerFileData (
336+ getEntityName (),
337+ getModuleName (),
338+ namespace .getNamespace (),
339+ getSaveEntityCommandClassFqn (),
340+ dtoType ,
341+ getAcl (),
342+ getEntityIdColumn ()
343+ ), project ).generate (ACTION_NAME , false );
344+ }
345+
346+ /**
347+ * Get save entity command class Fqn.
348+ *
349+ * @return String
350+ */
351+ private String getSaveEntityCommandClassFqn () {
352+ //TODO: change this stub after the save command generated will be implemented.
353+ final NamespaceBuilder namespaceBuilder =
354+ new NamespaceBuilder (getModuleName (), "SaveCommand" , "Command/" + getEntityName ());
355+
356+ return namespaceBuilder .getClassFqn ();
357+ }
358+
311359 private PsiFile generateModelFile () {
312360 final NamespaceBuilder modelNamespace = getModelNamespace ();
313361 final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace ();
@@ -579,24 +627,11 @@ private String getControllerDirectory() {
579627 return ControllerBackendPhp .DEFAULT_DIR + File .separator ;
580628 }
581629
582- private PsiFile generateSubmitControllerFile () {
583- final NamespaceBuilder namespace = new NamespaceBuilder (
584- getModuleName (),
585- getSubmitActionName (),
586- getViewControllerDirectory ()
587- );
588- return new ModuleControllerClassGenerator (new ControllerFileData (
589- getViewControllerDirectory (),
590- getSubmitActionName (),
591- getModuleName (),
592- Areas .adminhtml .toString (),
593- HttpMethod .POST .toString (),
594- getAcl (),
595- true ,
596- namespace .getNamespace ()
597- ), project ).generate (ACTION_NAME , false );
598- }
599-
630+ /**
631+ * Get Acl id.
632+ *
633+ * @return String
634+ */
600635 public String getAcl () {
601636 return acl .getText ().trim ();
602637 }
0 commit comments