1515import com .intellij .psi .xml .XmlTag ;
1616import com .magento .idea .magento2plugin .actions .generation .data .DbSchemaXmlData ;
1717import 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 ;
1820import com .magento .idea .magento2plugin .magento .files .ModuleDbSchemaXml ;
1921import com .magento .idea .magento2plugin .magento .packages .database .ColumnAttributes ;
2022import com .magento .idea .magento2plugin .magento .packages .database .TableColumnTypes ;
2123import java .util .HashMap ;
22- import java .util .InputMismatchException ;
2324import java .util .LinkedHashMap ;
2425import java .util .LinkedList ;
2526import java .util .List ;
2627import java .util .Map ;
2728import java .util .Properties ;
29+ import javax .swing .JOptionPane ;
2830import org .jetbrains .annotations .NotNull ;
2931
3032public 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