Skip to content

Commit e290833

Browse files
author
Vitaliy
authored
Merge pull request #399 from drpayyne/data-model-generation
Data model generation
2 parents 11b6fa9 + 0ea5907 commit e290833

File tree

22 files changed

+1209
-2
lines changed

22 files changed

+1209
-2
lines changed

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
6969
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
7070
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
71+
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7172
<add-to-group group-id="NewGroup" anchor="last"/>
7273
</group>
7374

@@ -214,6 +215,8 @@
214215
<internalFileTemplate name="Magento Collection Class"/>
215216
<internalFileTemplate name="Magento Model Class"/>
216217
<internalFileTemplate name="Magento Resource Model Class"/>
218+
<internalFileTemplate name="Magento Data Model"/>
219+
<internalFileTemplate name="Magento Data Model Interface"/>
217220

218221
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
219222

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
interface ${NAME}
9+
{
10+
#if (${PROPERTIES})
11+
/**
12+
* String constants for property names
13+
*/
14+
#set ($properties = ${PROPERTIES})
15+
#foreach ($property in $properties.split(","))
16+
#set ($propertyData = $property.split(";"))
17+
#set ($propertyUpperSnake = $propertyData.get(0))
18+
#set ($propertyLowerSnake = $propertyData.get(1))
19+
const $propertyUpperSnake = "$propertyLowerSnake";
20+
#end
21+
#end
22+
#if (${PROPERTIES})
23+
#set ($properties = ${PROPERTIES})
24+
#foreach ($property in $properties.split(","))
25+
#set ($propertyData = $property.split(";"))
26+
#set ($propertyType = $propertyData.get(2))
27+
#set ($propertyUpperCamel = $propertyData.get(3))
28+
#set ($propertyLowerCamel = $propertyData.get(4))
29+
30+
/**
31+
* @return $propertyType
32+
*/
33+
public function get$propertyUpperCamel();
34+
35+
/**
36+
* @param $propertyType $$propertyLowerCamel
37+
* @return $this
38+
*/
39+
public function set$propertyUpperCamel($$propertyLowerCamel);
40+
#end
41+
#end
42+
}

resources/fileTemplates/internal/Magento Data Model Interface.php.html

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS})implements ${IMPLEMENTS}#end
14+
{
15+
#if (${PROPERTIES})
16+
#set ($properties = ${PROPERTIES})
17+
#foreach ($property in $properties.split(","))
18+
#set ($propertyData = $property.split(";"))
19+
#set ($propertyUpperSnake = $propertyData.get(0))
20+
#set ($propertyUpperCamel = $propertyData.get(3))
21+
#set ($propertyLowerCamel = $propertyData.get(4))
22+
#if(!($foreach.first))
23+
24+
#end
25+
/**
26+
* @inheritDoc
27+
*/
28+
public function get$propertyUpperCamel()
29+
{
30+
return $this->getData(self::$propertyUpperSnake);
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function set$propertyUpperCamel($$propertyLowerCamel)
37+
{
38+
return $this->setData(self::$propertyUpperSnake, $$propertyLowerCamel);
39+
}
40+
#end
41+
#end
42+
}

resources/fileTemplates/internal/Magento Data Model.php.html

Whitespace-only changes.

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ validator.mustNotBeEmptyShouldContainLettersOrNumbers=Must not be empty, should
2929
validator.magentoRouteIdInvalid=The route id is invalid
3030
validator.magentoAclResourceIdInvalid=The ACL resource id is invalid
3131
validator.lowercaseCharacters={0} must contain lowercase characters only
32+
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class NewDataModelAction extends AnAction {
21+
public static final String ACTION_NAME = "Magento 2 Data Model";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";
23+
24+
/**
25+
* Constructor.
26+
*/
27+
public NewDataModelAction() {
28+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
}
30+
31+
@Override
32+
public void actionPerformed(@NotNull final AnActionEvent event) {
33+
final DataContext dataContext = event.getDataContext();
34+
35+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36+
if (view == null) {
37+
return;
38+
}
39+
40+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
if (project == null) {
42+
return;
43+
}
44+
45+
final PsiDirectory directory = view.getOrChooseDirectory();
46+
if (directory == null) {
47+
return;
48+
}
49+
50+
NewDataModelDialog.open(project, directory);
51+
}
52+
53+
@Override
54+
public boolean isDumbAware() {
55+
return false;
56+
}
57+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
public class DataModelData {
9+
private final String namespace;
10+
private final String name;
11+
private final String moduleName;
12+
private final String fqn;
13+
private final String interfaceFQN;
14+
private final String properties;
15+
16+
/**
17+
* Constructor.
18+
*/
19+
public DataModelData(
20+
final String namespace,
21+
final String name,
22+
final String moduleName,
23+
final String fqn,
24+
final String interfaceFQN,
25+
final String properties
26+
) {
27+
this.namespace = namespace;
28+
this.name = name;
29+
this.moduleName = moduleName;
30+
this.fqn = fqn;
31+
this.interfaceFQN = interfaceFQN;
32+
this.properties = properties;
33+
}
34+
35+
public String getNamespace() {
36+
return namespace;
37+
}
38+
39+
public String getName() {
40+
return name;
41+
}
42+
43+
public String getModuleName() {
44+
return moduleName;
45+
}
46+
47+
public String getFQN() {
48+
return fqn;
49+
}
50+
51+
public String getInterfaceFQN() {
52+
return interfaceFQN;
53+
}
54+
55+
public String getProperties() {
56+
return properties;
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
public class DataModelInterfaceData {
9+
private final String namespace;
10+
private final String name;
11+
private final String moduleName;
12+
private final String fqn;
13+
private final String properties;
14+
15+
/**
16+
* Constructor.
17+
*/
18+
public DataModelInterfaceData(
19+
final String namespace,
20+
final String name,
21+
final String moduleName,
22+
final String fqn,
23+
final String properties
24+
) {
25+
this.namespace = namespace;
26+
this.name = name;
27+
this.moduleName = moduleName;
28+
this.fqn = fqn;
29+
this.properties = properties;
30+
}
31+
32+
public String getNamespace() {
33+
return namespace;
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
40+
public String getModuleName() {
41+
return moduleName;
42+
}
43+
44+
public String getFQN() {
45+
return fqn;
46+
}
47+
48+
public String getProperties() {
49+
return properties;
50+
}
51+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data.code;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import org.apache.commons.lang.StringUtils;
11+
12+
public class ClassPropertyData {
13+
private final List<String> data = new ArrayList<>();
14+
15+
/**
16+
* Constructor.
17+
*/
18+
public ClassPropertyData(
19+
final String type,
20+
final String lowerCamelName,
21+
final String upperCamelName,
22+
final String lowerSnakeName,
23+
final String upperSnakeName
24+
) {
25+
data.add(upperSnakeName);
26+
data.add(lowerSnakeName);
27+
data.add(type);
28+
data.add(upperCamelName);
29+
data.add(lowerCamelName);
30+
}
31+
32+
public String string() {
33+
return StringUtils.join(data, ";");
34+
}
35+
}

0 commit comments

Comments
 (0)