Skip to content

Data model generation #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

Expand Down Expand Up @@ -214,6 +215,8 @@
<internalFileTemplate name="Magento Collection Class"/>
<internalFileTemplate name="Magento Model Class"/>
<internalFileTemplate name="Magento Resource Model Class"/>
<internalFileTemplate name="Magento Data Model"/>
<internalFileTemplate name="Magento Data Model Interface"/>

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
#parse("PHP File Header.php")

#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

interface ${NAME}
{
#if (${PROPERTIES})
/**
* String constants for property names
*/
#set ($properties = ${PROPERTIES})
#foreach ($property in $properties.split(","))
#set ($propertyData = $property.split(";"))
#set ($propertyUpperSnake = $propertyData.get(0))
#set ($propertyLowerSnake = $propertyData.get(1))
const $propertyUpperSnake = "$propertyLowerSnake";
#end
#end
#if (${PROPERTIES})
#set ($properties = ${PROPERTIES})
#foreach ($property in $properties.split(","))
#set ($propertyData = $property.split(";"))
#set ($propertyType = $propertyData.get(2))
#set ($propertyUpperCamel = $propertyData.get(3))
#set ($propertyLowerCamel = $propertyData.get(4))

/**
* @return $propertyType
*/
public function get$propertyUpperCamel();

/**
* @param $propertyType $$propertyLowerCamel
* @return $this
*/
public function set$propertyUpperCamel($$propertyLowerCamel);
#end
#end
}
Empty file.
42 changes: 42 additions & 0 deletions resources/fileTemplates/internal/Magento Data Model.php.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
#parse("PHP File Header.php")

#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS})implements ${IMPLEMENTS}#end
{
#if (${PROPERTIES})
#set ($properties = ${PROPERTIES})
#foreach ($property in $properties.split(","))
#set ($propertyData = $property.split(";"))
#set ($propertyUpperSnake = $propertyData.get(0))
#set ($propertyUpperCamel = $propertyData.get(3))
#set ($propertyLowerCamel = $propertyData.get(4))
#if(!($foreach.first))

#end
/**
* @inheritDoc
*/
public function get$propertyUpperCamel()
{
return $this->getData(self::$propertyUpperSnake);
}

/**
* @inheritDoc
*/
public function set$propertyUpperCamel($$propertyLowerCamel)
{
return $this->setData(self::$propertyUpperSnake, $$propertyLowerCamel);
}
#end
#end
}
Empty file.
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ validator.mustNotBeEmptyShouldContainLettersOrNumbers=Must not be empty, should
validator.magentoRouteIdInvalid=The route id is invalid
validator.magentoAclResourceIdInvalid=The ACL resource id is invalid
validator.lowercaseCharacters={0} must contain lowercase characters only
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation;

import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDataModelDialog;
import org.jetbrains.annotations.NotNull;

public class NewDataModelAction extends AnAction {
public static final String ACTION_NAME = "Magento 2 Data Model";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";

/**
* Constructor.
*/
public NewDataModelAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
final DataContext dataContext = event.getDataContext();

final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();
if (directory == null) {
return;
}

NewDataModelDialog.open(project, directory);
}

@Override
public boolean isDumbAware() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

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

public class DataModelData {
private final String namespace;
private final String name;
private final String moduleName;
private final String fqn;
private final String interfaceFQN;
private final String properties;

/**
* Constructor.
*/
public DataModelData(
final String namespace,
final String name,
final String moduleName,
final String fqn,
final String interfaceFQN,
final String properties
) {
this.namespace = namespace;
this.name = name;
this.moduleName = moduleName;
this.fqn = fqn;
this.interfaceFQN = interfaceFQN;
this.properties = properties;
}

public String getNamespace() {
return namespace;
}

public String getName() {
return name;
}

public String getModuleName() {
return moduleName;
}

public String getFQN() {
return fqn;
}

public String getInterfaceFQN() {
return interfaceFQN;
}

public String getProperties() {
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

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

public class DataModelInterfaceData {
private final String namespace;
private final String name;
private final String moduleName;
private final String fqn;
private final String properties;

/**
* Constructor.
*/
public DataModelInterfaceData(
final String namespace,
final String name,
final String moduleName,
final String fqn,
final String properties
) {
this.namespace = namespace;
this.name = name;
this.moduleName = moduleName;
this.fqn = fqn;
this.properties = properties;
}

public String getNamespace() {
return namespace;
}

public String getName() {
return name;
}

public String getModuleName() {
return moduleName;
}

public String getFQN() {
return fqn;
}

public String getProperties() {
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.data.code;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;

public class ClassPropertyData {
private final List<String> data = new ArrayList<>();

/**
* Constructor.
*/
public ClassPropertyData(
final String type,
final String lowerCamelName,
final String upperCamelName,
final String lowerSnakeName,
final String upperSnakeName
) {
data.add(upperSnakeName);
data.add(lowerSnakeName);
data.add(type);
data.add(upperCamelName);
data.add(lowerCamelName);
}

public String string() {
return StringUtils.join(data, ";");
}
}
Loading