Skip to content

Commit

Permalink
JPA Basic data type support
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwani Gupta <[email protected]>
  • Loading branch information
jShiwaniGupta committed Jul 2, 2020
1 parent ece0010 commit 644abb6
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import io.github.jeddict.jcode.util.BuildManager;
import io.github.jeddict.jcode.util.FileUtil;
import io.github.jeddict.jcode.util.ProjectHelper;
import io.github.jeddict.jcode.util.StringHelper;
import static io.github.jeddict.jcode.util.StringHelper.firstLower;
import static io.github.jeddict.jcode.util.StringHelper.firstUpper;
import io.github.jeddict.jpa.spec.Entity;
import io.github.jeddict.jpa.spec.EntityMappings;
import io.github.jeddict.jpa.spec.extend.Attribute;
import io.github.jeddict.jpa.spec.extend.AttributeAnnotation;
import io.github.jeddict.jsf.controller.JsfControllerData;
import io.github.jeddict.jsf.controller.JsfControllerGenerator;
import java.io.IOException;
Expand All @@ -41,6 +40,7 @@
import org.netbeans.api.project.Project;
import org.netbeans.api.project.SourceGroup;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;
import org.openide.util.lookup.ServiceProvider;

/**
Expand Down Expand Up @@ -128,32 +128,33 @@ private void addMavenDependencies(String pom, Project project) {
}

private void generate() throws IOException {
for (Entity entity : entityMapping.getGeneratedEntity().collect(toList())) {
List<Entity> entityList = entityMapping.getGeneratedEntity().collect(toList());
for (Entity entity : entityList) {
handler.progress(jsfViewerData.getPrefixName() + entity.getClazz() + jsfViewerData.getSuffixName());
generateCRUD(entity, true);
generatePropertiesFile(entity, false);
}
generatePropertiesFile(entityList);
}

private void generatePropertiesFile(final Entity entity, boolean overrideExisting) throws IOException {
private void generatePropertiesFile(List<Entity> entityList) {
final FileObject resourceFolder = projectHelper.getResourceDirectory(gatewayProject);
FileObject rootFolder = projectHelper.getProjectWebRoot(targetProject);//getFolderForPackage(source, _package, true);

final String entitySimpleName = entity.getClazz();
String entityClass = firstUpper(entitySimpleName);

List<Attribute> attributeList = entity.getAttributes().getAllAttribute();
List<String> attributes = new ArrayList<>();
for (Attribute attribute : attributeList) {
String attributeAsString = firstUpper(attribute.getName());
attributes.add(attributeAsString);
String indexFilename = "index";
String bundleFileName = "Bundle";
List<String> entityNames = new ArrayList<>();
for (Entity entity : entityList) {
entityNames.add(entity.getName());
}
String fileName = "Bundle";
Map<String, Object> param = new HashMap<>();
param.put("Entity", entityClass);
param.put("attributes", attributes);
Map<String, Object> params = new HashMap<>();
params.put("Entities", entityNames.toArray());

handler.progress(fileName);
FileUtil.expandTemplate(TEMPLATE + "util/Bundle.properties.ftl", resourceFolder, fileName + '.' + "properties", param);
try {
io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/index.xhtml.ftl", rootFolder, indexFilename + '.' + "xhtml", params);
FileUtil.expandTemplate(TEMPLATE + "util/Bundle.properties.ftl", resourceFolder, bundleFileName + '.' + "properties", params);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}

private void generateLayout() throws IOException {
Expand All @@ -173,7 +174,7 @@ private void generateLayout() throws IOException {
public void generateCRUD(final Entity entity, boolean overrideExisting) throws IOException {
String entityName = entity.getName();
List<Attribute> attributes = entity.getAttributes().getAllAttribute();
String entityInstance = firstLower(entityName);
String entityInstance = firstLower(entityName);
String targetPath = "app/entities/" + entityInstance;

FileObject rootFolder = projectHelper.getProjectWebRoot(targetProject);//getFolderForPackage(source, _package, true);
Expand All @@ -183,7 +184,6 @@ public void generateCRUD(final Entity entity, boolean overrideExisting) throws I
String viewFileName = "view" + entityName;
String editFileName = "edit" + entityName;
String listFileName = "list" + entityName;
String indexFilename = "index";
String controllerName = firstLower(controllerData.getPrefixName() + entityName + controllerData.getSuffixName());

Map<String, Object> params = new HashMap<>();
Expand All @@ -197,8 +197,6 @@ public void generateCRUD(final Entity entity, boolean overrideExisting) throws I
io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/view.xhtml.ftl", targetFolder, viewFileName + '.' + "xhtml", params);
io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/edit.xhtml.ftl", targetFolder, editFileName + '.' + "xhtml", params);
io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/list.xhtml.ftl", targetFolder, listFileName + '.' + "xhtml", params);
io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/index.xhtml.ftl", rootFolder, indexFilename + '.' + "xhtml", params);

}

public void generateResources() throws IOException {
Expand All @@ -216,4 +214,5 @@ public void generateResources() throws IOException {
// io.github.jeddict.jcode.util.FileUtil.expandTemplate(TEMPLATE + "jsf/images.js.ftl", jsTargetFolder, fileName + '.' + "js", params);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,27 @@
<h:form id="add" style="margin-left: 20%;margin-right: 20%">
<h:panelGrid columns="3" cellpadding="5" style="margin: 0 auto;">
<#list attributes as attribute>
<#if attribute.attributeType == "String">
<#if (attribute.attributeType == "String")||
(attribute.attributeType == "long") || (attribute.attributeType == "Long") ||
(attribute.attributeType == "int") || (attribute.attributeType == "Integer")||
(attribute.attributeType == "char") || (attribute.attributeType == "Character")||
(attribute.attributeType == "byte") || (attribute.attributeType == "Byte")||
(attribute.attributeType == "float") || (attribute.attributeType == "Float")||
(attribute.attributeType == "double") || (attribute.attributeType == "Double")||
(attribute.attributeType == "short") || (attribute.attributeType == "Short")||
(attribute.attributeType == "java.math.BigInteger") || (attribute.attributeType == "java.math.BigDecimal")>
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "long" >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "int" >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "boolean" >
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}">
</p:inputText>
<p:messages for="${attribute.name}">
<p:autoUpdate />
</p:messages>

<#elseif (attribute.attributeType == "boolean") || (attribute.attributeType == "Boolean") >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:selectOneRadio id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" validatorMessage="${attribute.name} is required">
<f:selectItem itemValue="M" itemLabel="Male" />
<f:selectItem itemValue="F" itemLabel="Female" />
<f:validateRequired/>
</p:selectOneRadio>
<p:message for="${attribute.name}" />
</#if>
</#list>
<p:selectBooleanCheckbox value="${hash}{${EntityController}.selected.${attribute.name}}" id="${attribute.name}"/>
</#if>
</#list>
<p:commandButton value="Create" action="${hash}{${EntityController}.create}">
</p:commandButton>
<p:commandButton value="Cancel" action="${hash}{${EntityController}.prepareList}" immediate="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,30 @@
<div>
<h1 align="center">Edit ${Entity} </h1>
</div>
<h:form id="edit">
<h:form id="edit" style="margin-left: 20%;margin-right: 20%">
<h:panelGrid columns="3" cellpadding="5" style="margin: 0 auto;">
<#list attributes as attribute>
<#if attribute.attributeType == "String">
<#list attributes as attribute>
<#if (attribute.attributeType == "String")||
(attribute.attributeType == "long") || (attribute.attributeType == "Long") ||
(attribute.attributeType == "int") || (attribute.attributeType == "Integer")||
(attribute.attributeType == "char") || (attribute.attributeType == "Character")||
(attribute.attributeType == "byte") || (attribute.attributeType == "Byte")||
(attribute.attributeType == "float") || (attribute.attributeType == "Float")||
(attribute.attributeType == "double") || (attribute.attributeType == "Double")||
(attribute.attributeType == "short") || (attribute.attributeType == "Short")||
(attribute.attributeType == "java.math.BigInteger") || (attribute.attributeType == "java.math.BigDecimal")>
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "long" >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "int" >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" />
<p:message for="${attribute.name}" />

<#elseif attribute.attributeType == "boolean" >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:selectOneRadio id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}" validatorMessage="${attribute.name} is required">
<f:selectItem itemValue="M" itemLabel="Male" />
<f:selectItem itemValue="F" itemLabel="Female" />
<f:validateRequired/>
</p:selectOneRadio>
<p:message for="${attribute.name}" />
</#if>
</#list>
<p:inputText id="${attribute.name}" value="${hash}{${EntityController}.selected.${attribute.name}}">
</p:inputText>
<p:messages for="${attribute.name}">
<p:autoUpdate />
</p:messages>

<#elseif (attribute.attributeType == "boolean") || (attribute.attributeType == "Boolean") >
<p:outputLabel for="${attribute.name}" value="${attribute.name}" />
<p:selectBooleanCheckbox value="${hash}{${EntityController}.selected.${attribute.name}}" id="${attribute.name}"/>
</#if>
</#list>
<p:commandButton value="Update" action="${hash}{${EntityController}.update}">
</p:commandButton>
<p:commandButton value="Cancel" action="${hash}{${EntityController}.prepareList}" immediate="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">



<h:head>
<title>Facelet Title</title>
<h:outputStylesheet name="css/jsfcrud.css"/>
</h:head>
<h:body >
<h:link outcome="app/entities/${entityInstance}/list${Entity}" value="Show ${Entity} Items Latest"/>
<#list Entities as Entity>
<h:link outcome="app/entities/${Entity?lower_case}/list${Entity}" value="Show ${Entity} Items Latest"/>
<br/>
</#list>
</h:body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

</div>
<h:form id="StudentListForm" style="margin-left: 2%; margin-right: 2%">
<!--<p:panel header="${hash}{bundle.ListStudentTitle}">-->
<p:dataTable id="datalist" value="${hash}{${EntityController}.items}" var="item"
selection="${hash}{${EntityController}.selected}"
rowKey="${hash}{item.id}"
Expand All @@ -47,7 +46,6 @@
</p:confirmDialog>
</p:column>
</p:dataTable>
<!--</p:panel>-->
</h:form>

</ui:define>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<p:layout fullPage="true" >
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true" >

<!-- <h:graphicImage value = "/resources/images/jeddictLogo.jpg" height="90" width="90" style="margin-left: 1%"/>-->

<p:commandButton id="home" icon="ui-icon-home" value="Home" style="float:right; margin-right: 2%"></p:commandButton>

<ui:insert name="header" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,36 @@ SelectOneMessage=Select One...
Home=Home
Maintenance=Maintenance


AppName=${Entity} Registration Demo
${Entity}Created=${Entity} was successfully created.
${Entity}Updated=${Entity} was successfully updated.
${Entity}Deleted=${Entity} was successfully deleted.

Create${Entity}Title=Create New ${Entity}
Create${Entity}SaveLink=Save
Create${Entity}ShowAllLink=Show All ${Entity} Items
Create${Entity}IndexLink=Index


Edit${Entity}Title=Edit ${Entity}
Edit${Entity}SaveLink=Save
Edit${Entity}ViewLink=View
Edit${Entity}ShowAllLink=Show All ${Entity} Items
Edit${Entity}IndexLink=Index


View${Entity}Title=View ${Entity}
View${Entity}DestroyLink=Destroy
View${Entity}EditLink=Edit
View${Entity}CreateLink=Create New ${Entity}
View${Entity}ShowAllLink=Show All ${Entity} Items
View${Entity}IndexLink=Index

List${Entity}Title=List
List${Entity}Empty=(No ${Entity} Items Found)
List${Entity}DestroyLink=Destroy
List${Entity}EditLink=Edit
List${Entity}ViewLink=View
List${Entity}CreateLink=Create New ${Entity}
List${Entity}IndexLink=Index

<#list Entities as Entity>
AppName=${Entity} Registration Demo
${Entity}Created=${Entity} was successfully created.
${Entity}Updated=${Entity} was successfully updated.
${Entity}Deleted=${Entity} was successfully deleted.

Create${Entity}Title=Create New ${Entity}
Create${Entity}SaveLink=Save
Create${Entity}ShowAllLink=Show All ${Entity} Items
Create${Entity}IndexLink=Index

Edit${Entity}Title=Edit ${Entity}
Edit${Entity}SaveLink=Save
Edit${Entity}ViewLink=View
Edit${Entity}ShowAllLink=Show All ${Entity} Items
Edit${Entity}IndexLink=Index

View${Entity}Title=View ${Entity}
View${Entity}DestroyLink=Destroy
View${Entity}EditLink=Edit
View${Entity}CreateLink=Create New ${Entity}
View${Entity}ShowAllLink=Show All ${Entity} Items
View${Entity}IndexLink=Index

List${Entity}Title=List
List${Entity}Empty=(No ${Entity} Items Found)
List${Entity}DestroyLink=Destroy
List${Entity}EditLink=Edit
List${Entity}ViewLink=View
List${Entity}CreateLink=Create New ${Entity}
List${Entity}IndexLink=Index

</#list>

0 comments on commit 644abb6

Please sign in to comment.