diff --git a/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft index 625d76ff0..97db4d570 100644 --- a/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft +++ b/resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft @@ -49,9 +49,9 @@ class ${CLASS_NAME} * @param int $entityId * * @return void - * @throws ${COULD_NOT_DELETE}|${NO_SUCH_ENTITY_EXCEPTION} + * @throws ${COULD_NOT_DELETE} */ - public function execute(int $entityId) + public function execute(int $entityId): void { try { /** @var ${MODEL} $model */ diff --git a/resources/fileTemplates/internal/Magento Entity Search Results Interface.php.ft b/resources/fileTemplates/internal/Magento Entity Search Results Interface.php.ft new file mode 100644 index 000000000..30b6268c1 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Entity Search Results Interface.php.ft @@ -0,0 +1,31 @@ +getEntityId(); + return (int) $model->getData(${ENTITY_ID_CONST}); } } 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 67915847e..e374679e6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/GetListQueryModelData.java @@ -14,6 +14,7 @@ public class GetListQueryModelData { private final String modelName; private final String collectionName; private final String aclResource; + private final boolean hasWebApi; /** * Query Model DTO Constructor. @@ -23,19 +24,22 @@ public class GetListQueryModelData { * @param modelName String * @param collectionName String * @param aclResource String + * @param hasWebApi boolean */ public GetListQueryModelData( final @NotNull String moduleName, final @NotNull String entityName, final @NotNull String modelName, final @NotNull String collectionName, - final @NotNull String aclResource + final @NotNull String aclResource, + final boolean hasWebApi ) { this.moduleName = moduleName; this.entityName = entityName; this.modelName = modelName; this.collectionName = collectionName; this.aclResource = aclResource; + this.hasWebApi = hasWebApi; } /** @@ -82,4 +86,13 @@ public String getCollectionName() { public String getAclResource() { return aclResource; } + + /** + * Check if entity has Web API. + * + * @return boolean + */ + public boolean isHasWebApi() { + return hasWebApi; + } } 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 36f3b9ea9..2eff292d7 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 @@ -29,7 +29,8 @@ public GetListQueryDtoConverter( newEntityDialogData.getEntityName(), newEntityDialogData.getEntityName().concat("Model"), newEntityDialogData.getEntityName().concat("Collection"), - newEntityDialogData.getAclId() + newEntityDialogData.getAclId(), + newEntityDialogData.hasWebApi() ); } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SearchResultsDtoConverter.java b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SearchResultsDtoConverter.java new file mode 100644 index 000000000..4479579eb --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/converter/newentitydialog/SearchResultsDtoConverter.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.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.actions.generation.data.php.SearchResultsData; +import org.jetbrains.annotations.NotNull; + +public class SearchResultsDtoConverter extends SearchResultsData implements DataObjectConverter { + + /** + * Save entity command DTO converter. + * + * @param generationContextData EntityCreatorContextData + * @param newEntityDialogData NewEntityDialogData + */ + public SearchResultsDtoConverter( + final @NotNull EntityCreatorContextData generationContextData, + final @NotNull NewEntityDialogData newEntityDialogData + ) { + super( + generationContextData.getModuleName(), + newEntityDialogData.getEntityName(), + newEntityDialogData.hasDtoInterface() + ? generationContextData.getDtoInterfaceNamespaceBuilder().getClassFqn() + : generationContextData.getDtoModelNamespaceBuilder().getClassFqn() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/data/php/SearchResultsData.java b/src/com/magento/idea/magento2plugin/actions/generation/data/php/SearchResultsData.java new file mode 100644 index 000000000..b607e49bd --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/data/php/SearchResultsData.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.php; + +import org.jetbrains.annotations.NotNull; + +public class SearchResultsData { + + private final String moduleName; + private final String entityName; + private final String dtoType; + + /** + * Entity search results data transfer object constructor. + * + * @param moduleName String + * @param entityName String + * @param dtoType String + */ + public SearchResultsData( + final @NotNull String moduleName, + final @NotNull String entityName, + final @NotNull String dtoType + ) { + this.moduleName = moduleName; + this.entityName = entityName; + this.dtoType = dtoType; + } + + /** + * Get module name. + * + * @return String + */ + public String getModuleName() { + return moduleName; + } + + /** + * Get entity name. + * + * @return String + */ + public String getEntityName() { + return entityName; + } + + /** + * Get entity DTO type. + * + * @return String + */ + public String getDtoType() { + return dtoType; + } +} 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 b1d6d724b..5437b96b7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -156,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 String DEFAULT_MENU_SORT_ORDER = "100"; + private static final boolean OPEN_FILES_FLAG = false; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, ENTITY_ID}) @@ -291,6 +293,8 @@ protected void textChanged(final @NotNull DocumentEvent event) { createUiComponent.addItemListener(event -> toggleUiComponentsPanel()); registerTabbedPane(tabbedPane1); + + sortOrder.setText(DEFAULT_MENU_SORT_ORDER); } /** 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 2a660bbc7..81528ec10 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java @@ -11,6 +11,7 @@ import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; import com.magento.idea.magento2plugin.magento.files.CollectionModelFile; import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile; +import com.magento.idea.magento2plugin.magento.files.SearchResultsInterfaceFile; import com.magento.idea.magento2plugin.magento.files.queries.GetListQueryFile; import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; import java.util.Properties; @@ -100,14 +101,24 @@ protected void fillAttributes(final @NotNull Properties attributes) { .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() ); + + String searchResultType; + String searchResultFactoryType; + + if (data.isHasWebApi()) { + final SearchResultsInterfaceFile searchResultsInterfaceFile = + new SearchResultsInterfaceFile(data.getModuleName(), data.getEntityName()); + + searchResultType = searchResultsInterfaceFile.getClassFqn(); + searchResultFactoryType = searchResultType.concat("Factory"); + } else { + searchResultType = FrameworkLibraryType.SEARCH_RESULT.getType(); + searchResultFactoryType = FrameworkLibraryType.SEARCH_RESULT.getFactory(); + } + + typesBuilder + .append("SEARCH_RESULT_TYPE", searchResultType) + .append("SEARCH_RESULT_FACTORY_TYPE", searchResultFactoryType); } } 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 bb851d641..a091c8a53 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/SaveEntityCommandGenerator.java @@ -70,7 +70,6 @@ protected void fillAttributes(final @NotNull Properties attributes) { .append("ENTITY_NAME", data.getEntityName(), false) .append("CLASS_NAME", SaveEntityCommandFile.CLASS_NAME, false) .append("EXCEPTION", "Exception") - .append("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType()) .append("COULD_NOT_SAVE", ExceptionType.COULD_NOT_SAVE.getType()) .append("LOGGER", FrameworkLibraryType.LOGGER.getType()); diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsGenerator.java new file mode 100644 index 000000000..e9ad1c3eb --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsGenerator.java @@ -0,0 +1,73 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.php; + +import com.intellij.openapi.project.Project; +import com.magento.idea.magento2plugin.actions.generation.data.php.SearchResultsData; +import com.magento.idea.magento2plugin.actions.generation.generator.PhpFileGenerator; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.SearchResultsFile; +import com.magento.idea.magento2plugin.magento.files.SearchResultsInterfaceFile; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SearchResultsGenerator extends PhpFileGenerator { + + private final SearchResultsData data; + + /** + * Search results file generator constructor. + * + * @param data SearchResultsData + * @param project Project + */ + public SearchResultsGenerator( + final @NotNull SearchResultsData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Search results file generator constructor. + * + * @param data SearchResultsData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SearchResultsGenerator( + final @NotNull SearchResultsData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + @Override + protected AbstractPhpFile initFile() { + return new SearchResultsFile(data.getModuleName(), data.getEntityName()); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + final String interfaceClassFqn = new SearchResultsInterfaceFile( + data.getModuleName(), + data.getEntityName() + ).getClassFqn(); + + typesBuilder + .append("NAMESPACE", file.getNamespace(), false) + .append("ENTITY_NAME", data.getEntityName(), false) + .append("CLASS_NAME", file.getClassName(), false) + .append("INTERFACE_NAME", interfaceClassFqn) + .append( + "PARENT_CLASS_NAME", + FrameworkLibraryType.SEARCH_RESULT_IMPLEMENTATION.getType() + ); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsInterfaceGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsInterfaceGenerator.java new file mode 100644 index 000000000..197eb9d65 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/php/SearchResultsInterfaceGenerator.java @@ -0,0 +1,100 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator.php; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.magento.idea.magento2plugin.actions.generation.data.PreferenceDiXmFileData; +import com.magento.idea.magento2plugin.actions.generation.data.php.SearchResultsData; +import com.magento.idea.magento2plugin.actions.generation.generator.PhpFileGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; +import com.magento.idea.magento2plugin.magento.files.SearchResultsFile; +import com.magento.idea.magento2plugin.magento.files.SearchResultsInterfaceFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; +import java.util.Properties; +import org.jetbrains.annotations.NotNull; + +public class SearchResultsInterfaceGenerator extends PhpFileGenerator { + + private final SearchResultsData data; + private PsiFile preferenceFile; + + /** + * Search results interface file generator constructor. + * + * @param data SearchResultsData + * @param project Project + */ + public SearchResultsInterfaceGenerator( + final @NotNull SearchResultsData data, + final @NotNull Project project + ) { + this(data, project, true); + } + + /** + * Search results interface file generator constructor. + * + * @param data SearchResultsData + * @param project Project + * @param checkFileAlreadyExists boolean + */ + public SearchResultsInterfaceGenerator( + final @NotNull SearchResultsData data, + final @NotNull Project project, + final boolean checkFileAlreadyExists + ) { + super(project, checkFileAlreadyExists); + this.data = data; + } + + /** + * Get generated/edited preference file. + * + * @return PsiFile + */ + public PsiFile getPreferenceFile() { + return preferenceFile; + } + + @Override + protected AbstractPhpFile initFile() { + return new SearchResultsInterfaceFile(data.getModuleName(), data.getEntityName()); + } + + @Override + protected void fillAttributes(final @NotNull Properties attributes) { + typesBuilder + .append("NAMESPACE", file.getNamespace(), false) + .append("ENTITY_NAME", data.getEntityName(), false) + .append("CLASS_NAME", file.getClassName(), false) + .append("DTO_TYPE", "\\" + data.getDtoType(), false) + .append("PARENT_INTERFACE", FrameworkLibraryType.SEARCH_RESULT.getType()); + } + + @Override + protected void onFileGenerated(final PsiFile generatedFile, final @NotNull String actionName) { + super.onFileGenerated(generatedFile, actionName); + + if (generatedFile instanceof PhpFile) { + final SearchResultsFile implementationFile = + new SearchResultsFile(data.getModuleName(), data.getEntityName()); + + preferenceFile = new PreferenceDiXmlGenerator( + new PreferenceDiXmFileData( + data.getModuleName(), + file.getClassFqn(), + implementationFile.getClassFqn(), + Areas.base.toString() + ), + project + ).generate(actionName, false); + } + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsGeneratorHandler.java new file mode 100644 index 000000000..39ccad47d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsGeneratorHandler.java @@ -0,0 +1,52 @@ +/* + * 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.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.data.php.SearchResultsData; +import com.magento.idea.magento2plugin.actions.generation.generator.php.SearchResultsGenerator; +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 SearchResultsGeneratorHandler extends GeneratorHandler { + + /** + * Search results data model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public SearchResultsGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Search results data model generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public SearchResultsGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new SearchResultsGenerator( + (SearchResultsData) getDataObjectConverter(), getProject() + )); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsInterfaceGeneratorHandler.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsInterfaceGeneratorHandler.java new file mode 100644 index 000000000..234fcd092 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/pool/handler/SearchResultsInterfaceGeneratorHandler.java @@ -0,0 +1,52 @@ +/* + * 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.dialog.GenerationContextData; +import com.magento.idea.magento2plugin.actions.generation.data.php.SearchResultsData; +import com.magento.idea.magento2plugin.actions.generation.generator.php.SearchResultsInterfaceGenerator; +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 SearchResultsInterfaceGeneratorHandler extends GeneratorHandler { + + /** + * Search results interface generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + */ + public SearchResultsInterfaceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter + ) { + this(contextData, dataObjectConverter, null); + } + + /** + * Search results interface generator handler. + * + * @param contextData GenerationContextData + * @param dataObjectConverter DataObjectConverter + * @param runnerValidator GeneratorRunnerValidator + */ + public SearchResultsInterfaceGeneratorHandler( + final @NotNull GenerationContextData contextData, + final @NotNull DataObjectConverter dataObjectConverter, + final GeneratorRunnerValidator runnerValidator + ) { + super(contextData, dataObjectConverter, runnerValidator); + } + + @Override + public void instantiateGenerator() { + setGenerator(new SearchResultsInterfaceGenerator( + (SearchResultsData) 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 fa4a936ff..6ea7b3d9f 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 @@ -30,6 +30,7 @@ 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.SearchResultsDtoConverter; import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.UiComponentFormLayoutDtoConverter; import com.magento.idea.magento2plugin.actions.generation.data.converter.newentitydialog.UiComponentGridDtoConverter; import com.magento.idea.magento2plugin.actions.generation.data.dialog.EntityCreatorContextData; @@ -61,6 +62,8 @@ 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.SearchResultsGeneratorHandler; +import com.magento.idea.magento2plugin.actions.generation.generator.pool.handler.SearchResultsInterfaceGeneratorHandler; 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; @@ -214,6 +217,16 @@ public static void initializeGenerators( .addNext( DbSchemaWhitelistGeneratorHandler.class, new DbSchemaXmlDtoConverter(context, dialogData) + ) + .addNext( + SearchResultsInterfaceGeneratorHandler.class, + new SearchResultsDtoConverter(context, dialogData), + dialogData::hasWebApi + ) + .addNext( + SearchResultsGeneratorHandler.class, + new SearchResultsDtoConverter(context, dialogData), + dialogData::hasWebApi ); } } diff --git a/src/com/magento/idea/magento2plugin/magento/files/SearchResultsFile.java b/src/com/magento/idea/magento2plugin/magento/files/SearchResultsFile.java new file mode 100644 index 000000000..d2a039a42 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/SearchResultsFile.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 org.jetbrains.annotations.NotNull; + +public class SearchResultsFile extends AbstractPhpFile { + + public static final String HUMAN_READABLE_NAME + = "Magento Entity Search Results class"; + public static final String TEMPLATE = "Magento Entity Search Results"; + private static final String CLASS_NAME_PATTERN = "%entityNameSearchResults"; + private static final String DIRECTORY = "Model"; + + /** + * Search results interface file constructor. + * + * @param moduleName String + * @param entityName String + */ + public SearchResultsFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME_PATTERN.replace("%entityName", entityName)); + } + + @Override + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/SearchResultsInterfaceFile.java b/src/com/magento/idea/magento2plugin/magento/files/SearchResultsInterfaceFile.java new file mode 100644 index 000000000..24141b523 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/SearchResultsInterfaceFile.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 org.jetbrains.annotations.NotNull; + +public class SearchResultsInterfaceFile extends AbstractPhpFile { + + public static final String HUMAN_READABLE_NAME + = "Magento Entity Search Results Interface class"; + public static final String TEMPLATE = "Magento Entity Search Results Interface"; + private static final String CLASS_NAME_PATTERN = "%entityNameSearchResultsInterface"; + private static final String DIRECTORY = "Api/Data"; + + /** + * Search results interface file constructor. + * + * @param moduleName String + * @param entityName String + */ + public SearchResultsInterfaceFile( + final @NotNull String moduleName, + final @NotNull String entityName + ) { + super(moduleName, CLASS_NAME_PATTERN.replace("%entityName", entityName)); + } + + @Override + public String getDirectory() { + return DIRECTORY; + } + + @Override + public String getHumanReadableName() { + return HUMAN_READABLE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java index fed5a1cec..01b63dbb8 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java +++ b/src/com/magento/idea/magento2plugin/magento/files/commands/DeleteEntityByIdCommandFile.java @@ -19,7 +19,7 @@ public class DeleteEntityByIdCommandFile extends AbstractPhpFile { public static final String WEB_API_METHOD_NAME = "execute"; private static final String DIRECTORY = "Command"; private static final String WEB_API_INTERFACE_NAME_PATTERN = "Delete%entityName%ByIdInterface"; - private static final String WEB_API_URL_PATTERN = "%entityName%/delete-by-id"; + private static final String WEB_API_URL_PATTERN = "%entityName%/:entityId"; private final String entityName; private final boolean hasWebApiInterface; 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 bf2e7fab4..8387ba57f 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java @@ -26,6 +26,7 @@ public enum FrameworkLibraryType { SEARCH_CRITERIA("Magento\\Framework\\Api\\SearchCriteriaInterface"), SEARCH_CRITERIA_BUILDER("Magento\\Framework\\Api\\SearchCriteriaBuilder"), SEARCH_RESULT("Magento\\Framework\\Api\\SearchResultsInterface"), + SEARCH_RESULT_IMPLEMENTATION("Magento\\Framework\\Api\\SearchResults"), URL("Magento\\Framework\\UrlInterface"); /** diff --git a/src/com/magento/idea/magento2plugin/util/php/PhpTypeMetadataParserUtil.java b/src/com/magento/idea/magento2plugin/util/php/PhpTypeMetadataParserUtil.java index 5e424d4e6..592c27703 100644 --- a/src/com/magento/idea/magento2plugin/util/php/PhpTypeMetadataParserUtil.java +++ b/src/com/magento/idea/magento2plugin/util/php/PhpTypeMetadataParserUtil.java @@ -135,7 +135,7 @@ public static List getMethodsByNames( * * @return String */ - @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"}) + @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.ConfusingTernary"}) public static String getMethodDefinitionForInterface( final @NotNull Method method, final String defaultMethodDescription @@ -144,6 +144,7 @@ public static String getMethodDefinitionForInterface( final int bodyStartIndex = methodText.indexOf('{'); final PhpDocComment methodDoc = method.getDocComment(); String methodDescription = ""; + String methodDocReturn = null; if (bodyStartIndex != -1) { methodText = methodText.substring(0, bodyStartIndex).trim(); @@ -151,6 +152,9 @@ public static String getMethodDefinitionForInterface( if (methodDoc != null) { methodDescription = getShortDescription(method); + methodDocReturn = methodDoc.getReturnTag() == null + ? null + : methodDoc.getReturnTag().getText(); } if (methodDescription.isEmpty() && defaultMethodDescription != null) { @@ -162,6 +166,30 @@ public static String getMethodDefinitionForInterface( PhpDocCommentGenerator.constructDocComment(method.getProject(), method, false); methodDocAnnotation = newMethodDoc == null ? "" : newMethodDoc.getText(); + if (newMethodDoc != null && !methodDocAnnotation.isEmpty() + && methodDocReturn != null + && newMethodDoc.getReturnTag() == null) { + int insertionPos = -1; + final int docEndPos = methodDocAnnotation.indexOf("*/"); + final int lastThrowPos = methodDocAnnotation.lastIndexOf("@throws"); + + if (lastThrowPos != -1) { + insertionPos = lastThrowPos; + } else if (docEndPos != -1) { + insertionPos = docEndPos; + } + + if (insertionPos != -1) { + methodDocAnnotation = new StringBuffer(methodDocAnnotation) + .insert( + insertionPos, + docEndPos == insertionPos + ? "\n".concat(methodDocReturn).concat("\n") + : methodDocReturn.concat("\n") + ).toString(); + } + } + if (!methodDocAnnotation.isEmpty()) { final int openingSymbolPosition = methodDocAnnotation.indexOf("/**"); diff --git a/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php b/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php index 404852ee2..4842f10ae 100644 --- a/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php +++ b/testData/actions/generation/generator/DeleteEntityCommandGenerator/generateDeleteEntityByIdCommandFile/DeleteByIdCommand.php @@ -53,9 +53,9 @@ public function __construct( * @param int $entityId * * @return void - * @throws CouldNotDeleteException|NoSuchEntityException + * @throws CouldNotDeleteException */ - public function execute(int $entityId) + public function execute(int $entityId): void { try { /** @var BookModel $model */ diff --git a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php index 8a28e9071..433510de6 100644 --- a/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php +++ b/testData/actions/generation/generator/SaveEntityCommandGenerator/generateSaveEntityCommandFile/SaveCommand.php @@ -7,7 +7,6 @@ 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; use Psr\Log\LoggerInterface; @@ -50,7 +49,7 @@ public function __construct( /** * Save Book. * - * @param BookData|DataObject $book + * @param BookData $book * * @return int * @throws CouldNotSaveException @@ -78,6 +77,6 @@ public function execute(BookData $book): int throw new CouldNotSaveException(__('Could not save Book.')); } - return (int)$model->getEntityId(); + return (int)$model->getData(BookData::BOOK_ID); } } diff --git a/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsDiPreference/di.xml b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsDiPreference/di.xml new file mode 100644 index 000000000..9b1109038 --- /dev/null +++ b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsDiPreference/di.xml @@ -0,0 +1,5 @@ + + + + diff --git a/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php new file mode 100644 index 000000000..c8f7de1d1 --- /dev/null +++ b/testData/actions/generation/generator/SearchResultsFilesGenerator/generateSearchResultsFile/BookSearchResults.php @@ -0,0 +1,28 @@ +