Skip to content

Commit 305f66b

Browse files
author
Vitaliy
authored
Merge pull request #538 from ProkopovVitaliy/eav-attribute-generation-refactoring
Eav attribute generation refactoring
2 parents c75f0d4 + 2f0b610 commit 305f66b

File tree

16 files changed

+269
-473
lines changed

16 files changed

+269
-473
lines changed

resources/fileTemplates/internal/Magento Eav Attribute Data Patch Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ${NAMESPACE};
1010
use $use;
1111
#end
1212

13-
class ${NAME} implements ${IMPLEMENTS} {
13+
class ${CLASS_NAME} implements ${IMPLEMENTS} {
1414

1515
/**
1616
* @var ${MODULE_DATA_SETUP_INTERFACE}

resources/fileTemplates/internal/Magento Source Model Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ${NAME} extends ${EXTENDS}
1717
*/
1818
public function getAllOptions(): array
1919
{
20-
// TODO: Implement getAllOptions() method.
20+
return [];
2121
}
2222
}

src/com/magento/idea/magento2plugin/actions/generation/data/ProductEntityData.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.data;
77

8-
import com.magento.idea.magento2plugin.magento.packages.File;
9-
import com.magento.idea.magento2plugin.magento.packages.Package;
8+
import com.magento.idea.magento2plugin.magento.files.EavAttributeDataPatchFile;
109
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity;
1110

1211
@SuppressWarnings({"PMD.TooManyFields"})
@@ -144,25 +143,9 @@ public String getInput() {
144143

145144
@Override
146145
public String getNamespace() {
147-
if (namespace == null) {
148-
namespace = getDataPathNamespace();
149-
}
150-
151146
return namespace;
152147
}
153148

154-
private String getDataPathNamespace() {
155-
final String[] parts = moduleName.split(Package.vendorModuleNameSeparator);
156-
if (parts[0] == null || parts[1] == null || parts.length > 2) {
157-
return null;
158-
}
159-
final String directoryPart = getDirectory().replace(
160-
File.separator,
161-
Package.fqnSeparator
162-
);
163-
return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart;
164-
}
165-
166149
@Override
167150
public String getModuleName() {
168151
return moduleName;
@@ -171,7 +154,7 @@ public String getModuleName() {
171154
@Override
172155
public String getDirectory() {
173156
if (directory == null) {
174-
directory = "Setup/Patch/Data";
157+
directory = EavAttributeDataPatchFile.DEFAULT_DIR;
175158
}
176159

177160
return directory;

src/com/magento/idea/magento2plugin/actions/generation/data/SourceModelData.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,17 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.data;
77

8-
import com.magento.idea.magento2plugin.magento.files.SourceModelPhp;
9-
import com.magento.idea.magento2plugin.magento.packages.File;
10-
import com.magento.idea.magento2plugin.magento.packages.Package;
8+
import com.magento.idea.magento2plugin.magento.files.SourceModelFile;
119

1210
public class SourceModelData {
1311
private String className;
14-
private String namespace;
1512
private String moduleName;
1613
private String directory;
1714

1815
public String getClassName() {
1916
return className;
2017
}
2118

22-
/**
23-
* Constructor.
24-
*/
25-
public String getNamespace() {
26-
if (namespace == null) {
27-
namespace = getDefaultSourceModelNamespace();
28-
}
29-
30-
return namespace;
31-
}
32-
33-
/**
34-
* Provides default namespace.
35-
*
36-
* @return String
37-
*/
38-
public String getDefaultSourceModelNamespace() {
39-
final String[] parts = moduleName.split(Package.vendorModuleNameSeparator);
40-
if (parts[0] == null || parts[1] == null || parts.length > 2) {
41-
return null;
42-
}
43-
final String directoryPart = getDirectory().replace(
44-
File.separator,
45-
Package.fqnSeparator
46-
);
47-
return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart;
48-
}
49-
5019
/**
5120
* Get default namespace.
5221
*
@@ -63,7 +32,7 @@ public String getModuleName() {
6332
*/
6433
public String getDirectory() {
6534
if (this.directory == null) {
66-
return SourceModelPhp.DEFAULT_DIR;
35+
return SourceModelFile.DEFAULT_DIR;
6736
}
6837

6938
return this.directory;
@@ -73,10 +42,6 @@ public void setClassName(final String className) {
7342
this.className = className;
7443
}
7544

76-
public void setNamespace(final String namespace) {
77-
this.namespace = namespace;
78-
}
79-
8045
public void setModuleName(final String moduleName) {
8146
this.moduleName = moduleName;
8247
}

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
2020
import com.magento.idea.magento2plugin.actions.generation.generator.EavAttributeSetupPatchGenerator;
2121
import com.magento.idea.magento2plugin.actions.generation.generator.SourceModelGenerator;
22-
import com.magento.idea.magento2plugin.magento.packages.Package;
23-
import com.magento.idea.magento2plugin.magento.packages.eav.*;
22+
import com.magento.idea.magento2plugin.magento.files.SourceModelFile;
23+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeInput;
24+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeScope;
25+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeSourceModel;
26+
import com.magento.idea.magento2plugin.magento.packages.eav.AttributeType;
27+
import com.magento.idea.magento2plugin.magento.packages.eav.EavEntity;
2428
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
2529
import java.awt.event.ItemEvent;
2630
import java.awt.event.ItemListener;
@@ -38,7 +42,12 @@
3842
import org.codehaus.plexus.util.StringUtils;
3943
import org.jetbrains.annotations.NotNull;
4044

41-
@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.TooManyMethods", "PMD.UnusedPrivateField"})
45+
@SuppressWarnings({
46+
"PMD.TooManyFields",
47+
"PMD.ExcessiveImports",
48+
"PMD.TooManyMethods",
49+
"PMD.UnusedPrivateField"
50+
})
4251
public class NewEavAttributeDialog extends AbstractDialog {
4352
private final String moduleName;
4453
private JPanel contentPanel;
@@ -285,22 +294,25 @@ private void generateSourceModelFile() {
285294
final ComboBoxItemData selectedSource = (ComboBoxItemData) sourceComboBox.getSelectedItem();
286295

287296
if (selectedSource == null
288-
|| !selectedSource.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource())) {
297+
|| !selectedSource.getText().equals(
298+
AttributeSourceModel.GENERATE_SOURCE.getSource()
299+
)) {
289300
return;
290301
}
291302

292303
sourceModelData.setModuleName(moduleName);
293304
sourceModelData.setClassName(sourceModelNameTexField.getText().trim());
294305
sourceModelData.setDirectory(sourceModelDirectoryTexField.getText().trim());
295306

296-
new SourceModelGenerator(project, sourceModelData)
307+
new SourceModelGenerator(sourceModelData, project, true)
297308
.generate(NewEavAttributeAction.ACTION_NAME, false);
298309
}
299310

300311
private void generateDataPatchFile() {
301312
new EavAttributeSetupPatchGenerator(
302313
populateProductEntityData(new ProductEntityData()),
303-
project
314+
project,
315+
true
304316
).generate(NewEavAttributeAction.ACTION_NAME, true);
305317
}
306318

@@ -331,19 +343,20 @@ private String getAttributeSource() {
331343
final ComboBoxItemData selectedItem = (ComboBoxItemData) sourceComboBox.getSelectedItem();
332344

333345
if (selectedItem == null
334-
|| selectedItem.getText().equals(AttributeSourceModel.NULLABLE_SOURCE.getSource())) {
346+
|| selectedItem.getText().equals(
347+
AttributeSourceModel.NULLABLE_SOURCE.getSource()
348+
)) {
335349
return null;
336350
}
337351

338352
if (selectedItem.getText().equals(AttributeSourceModel.GENERATE_SOURCE.getSource())
339353
&& sourceModelData != null) {
340354

341-
return String.join(
342-
Package.fqnSeparator,
343-
"",
344-
sourceModelData.getNamespace(),
345-
sourceModelData.getClassName()
346-
);
355+
return "\\" + new SourceModelFile(
356+
sourceModelData.getModuleName(),
357+
sourceModelData.getClassName(),
358+
sourceModelData.getDirectory()
359+
).getClassFqn();
347360
}
348361

349362
return sourceComboBox.getSelectedItem().toString();
@@ -360,7 +373,8 @@ private String getAttributeScope() {
360373
}
361374

362375
private String getAttributeInput() {
363-
final ComboBoxItemData selectedAttributeInput = (ComboBoxItemData) inputComboBox.getSelectedItem();
376+
final ComboBoxItemData selectedAttributeInput =
377+
(ComboBoxItemData) inputComboBox.getSelectedItem();
364378

365379
if (selectedAttributeInput != null) {
366380
return selectedAttributeInput.getText().trim();

0 commit comments

Comments
 (0)