15
15
import com .intellij .psi .xml .XmlTag ;
16
16
import com .magento .idea .magento2plugin .actions .generation .data .DbSchemaXmlData ;
17
17
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 ;
18
20
import com .magento .idea .magento2plugin .magento .files .ModuleDbSchemaXml ;
19
21
import com .magento .idea .magento2plugin .magento .packages .database .ColumnAttributes ;
20
22
import com .magento .idea .magento2plugin .magento .packages .database .TableColumnTypes ;
21
23
import java .util .HashMap ;
22
- import java .util .InputMismatchException ;
23
24
import java .util .LinkedHashMap ;
24
25
import java .util .LinkedList ;
25
26
import java .util .List ;
26
27
import java .util .Map ;
27
28
import java .util .Properties ;
29
+ import javax .swing .JOptionPane ;
28
30
import org .jetbrains .annotations .NotNull ;
29
31
30
32
public class DbSchemaXmlGenerator extends FileGenerator {
33
+
31
34
private final Project project ;
32
35
private final String moduleName ;
33
36
private final DbSchemaXmlData dbSchemaXmlData ;
34
37
private final FindOrCreateDbSchemaXmlUtil findOrCreateDbSchemaXmlUtil ;
38
+ private final ValidatorBundle validatorBundle ;
39
+ private final CommonBundle commonBundle ;
35
40
36
41
private final List <XmlTag > newTagsQueue ;
37
42
private final Map <XmlTag , XmlTag > newTagsChildParentRelationMap ;
@@ -52,6 +57,8 @@ public DbSchemaXmlGenerator(
52
57
this .project = project ;
53
58
this .moduleName = moduleName ;
54
59
this .dbSchemaXmlData = dbSchemaXmlData ;
60
+ this .validatorBundle = new ValidatorBundle ();
61
+ this .commonBundle = new CommonBundle ();
55
62
findOrCreateDbSchemaXmlUtil = new FindOrCreateDbSchemaXmlUtil (project );
56
63
57
64
newTagsQueue = new LinkedList <>();
@@ -62,6 +69,7 @@ public DbSchemaXmlGenerator(
62
69
@ SuppressWarnings ({
63
70
"PMD.NPathComplexity" ,
64
71
"PMD.CyclomaticComplexity" ,
72
+ "PMD.CognitiveComplexity" ,
65
73
"PMD.ExcessiveImports" ,
66
74
"PMD.AvoidInstantiatingObjectsInLoops"
67
75
})
@@ -99,32 +107,39 @@ public PsiFile generate(final String actionName) {
99
107
primaryKeyData .putAll (columnData );
100
108
}
101
109
110
+ final String columnName = columnData .get (ColumnAttributes .NAME .getName ());
102
111
final String columnTypeValue = columnData .get (ColumnAttributes .TYPE .getName ());
103
112
final TableColumnTypes columnType = TableColumnTypes .getByValue (columnTypeValue );
104
113
105
114
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
109
125
);
126
+ return null ;
110
127
}
111
128
112
129
final Map <String , String > attributes = new LinkedHashMap <>();
113
130
final List <String > allowedColumns = ModuleDbSchemaXml .getAllowedAttributes (columnType );
131
+
114
132
for (final Map .Entry <String , String > columnDataEntry : columnData .entrySet ()) {
115
133
if (allowedColumns .contains (columnDataEntry .getKey ())
116
134
&& !columnDataEntry .getValue ().isEmpty ()) {
117
135
attributes .put (columnDataEntry .getKey (), columnDataEntry .getValue ());
118
136
}
119
137
}
120
- final String columnIdentityValue =
121
- columnData .get (ColumnAttributes .NAME .getName ());
122
-
123
138
findOrCreateTag (
124
139
ModuleDbSchemaXml .XML_TAG_COLUMN ,
125
140
ColumnAttributes .NAME .getName (),
126
141
tableTag ,
127
- columnIdentityValue ,
142
+ columnName ,
128
143
attributes
129
144
);
130
145
}
0 commit comments