Skip to content

Commit 69c4277

Browse files
626: Fixed Invalid column types provided exception during db_schema.xml file generation
1 parent c1eeebb commit 69c4277

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ validator.db.invalidTableNameLength=Table name must contain up to 64 characters
3838
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
3939
validator.menuIdentifierInvalid=The menu identifier is invalid
4040
validator.someFieldsHaveErrors=Please, check the dialog. Some fields have errors
41+
validator.dbSchema.invalidColumnType=Invalid ''{0}'' column type specified

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
1011
import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction;
1112
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData;
1213
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
@@ -143,7 +144,11 @@ private void onOK() {
143144
getTableComment(),
144145
getColumns()
145146
);
146-
generateDbSchemaXmlFile(dbSchemaXmlData);
147+
final PsiFile dbSchemaXmlFile = generateDbSchemaXmlFile(dbSchemaXmlData);
148+
149+
if (dbSchemaXmlFile == null) {
150+
return;
151+
}
147152
generateWhitelistJsonFile(dbSchemaXmlData);
148153
}
149154
exit();
@@ -170,8 +175,8 @@ public static void open(
170175
*
171176
* @param dbSchemaXmlData DbSchemaXmlData
172177
*/
173-
private void generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) {
174-
new DbSchemaXmlGenerator(
178+
private PsiFile generateDbSchemaXmlFile(final @NotNull DbSchemaXmlData dbSchemaXmlData) {
179+
return new DbSchemaXmlGenerator(
175180
dbSchemaXmlData,
176181
project,
177182
moduleName

src/com/magento/idea/magento2plugin/actions/generation/generator/DbSchemaXmlGenerator.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@
1515
import com.intellij.psi.xml.XmlTag;
1616
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData;
1717
import com.magento.idea.magento2plugin.actions.generation.generator.util.FindOrCreateDbSchemaXmlUtil;
18+
import com.magento.idea.magento2plugin.bundles.CommonBundle;
19+
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
1820
import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml;
1921
import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes;
2022
import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes;
2123
import java.util.HashMap;
22-
import java.util.InputMismatchException;
2324
import java.util.LinkedHashMap;
2425
import java.util.LinkedList;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Properties;
29+
import javax.swing.JOptionPane;
2830
import org.jetbrains.annotations.NotNull;
2931

3032
public class DbSchemaXmlGenerator extends FileGenerator {
33+
3134
private final Project project;
3235
private final String moduleName;
3336
private final DbSchemaXmlData dbSchemaXmlData;
3437
private final FindOrCreateDbSchemaXmlUtil findOrCreateDbSchemaXmlUtil;
38+
private final ValidatorBundle validatorBundle;
39+
private final CommonBundle commonBundle;
3540

3641
private final List<XmlTag> newTagsQueue;
3742
private final Map<XmlTag, XmlTag> newTagsChildParentRelationMap;
@@ -52,6 +57,8 @@ public DbSchemaXmlGenerator(
5257
this.project = project;
5358
this.moduleName = moduleName;
5459
this.dbSchemaXmlData = dbSchemaXmlData;
60+
this.validatorBundle = new ValidatorBundle();
61+
this.commonBundle = new CommonBundle();
5562
findOrCreateDbSchemaXmlUtil = new FindOrCreateDbSchemaXmlUtil(project);
5663

5764
newTagsQueue = new LinkedList<>();
@@ -62,6 +69,7 @@ public DbSchemaXmlGenerator(
6269
@SuppressWarnings({
6370
"PMD.NPathComplexity",
6471
"PMD.CyclomaticComplexity",
72+
"PMD.CognitiveComplexity",
6573
"PMD.ExcessiveImports",
6674
"PMD.AvoidInstantiatingObjectsInLoops"
6775
})
@@ -99,32 +107,39 @@ public PsiFile generate(final String actionName) {
99107
primaryKeyData.putAll(columnData);
100108
}
101109

110+
final String columnName = columnData.get(ColumnAttributes.NAME.getName());
102111
final String columnTypeValue = columnData.get(ColumnAttributes.TYPE.getName());
103112
final TableColumnTypes columnType = TableColumnTypes.getByValue(columnTypeValue);
104113

105114
if (columnType == null) {
106-
throw new InputMismatchException(
107-
"Invalid column types provided. Should be compatible with "
108-
+ TableColumnTypes.class
115+
final String errorMessage = validatorBundle.message(
116+
"validator.dbSchema.invalidColumnType",
117+
columnName == null ? "" : columnName
118+
119+
);
120+
JOptionPane.showMessageDialog(
121+
null,
122+
errorMessage,
123+
commonBundle.message("common.error"),
124+
JOptionPane.ERROR_MESSAGE
109125
);
126+
return null;
110127
}
111128

112129
final Map<String, String> attributes = new LinkedHashMap<>();
113130
final List<String> allowedColumns = ModuleDbSchemaXml.getAllowedAttributes(columnType);
131+
114132
for (final Map.Entry<String, String> columnDataEntry : columnData.entrySet()) {
115133
if (allowedColumns.contains(columnDataEntry.getKey())
116134
&& !columnDataEntry.getValue().isEmpty()) {
117135
attributes.put(columnDataEntry.getKey(), columnDataEntry.getValue());
118136
}
119137
}
120-
final String columnIdentityValue =
121-
columnData.get(ColumnAttributes.NAME.getName());
122-
123138
findOrCreateTag(
124139
ModuleDbSchemaXml.XML_TAG_COLUMN,
125140
ColumnAttributes.NAME.getName(),
126141
tableTag,
127-
columnIdentityValue,
142+
columnName,
128143
attributes
129144
);
130145
}

0 commit comments

Comments
 (0)