RLiferayTool 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjVjNzFjZjgwOGZmYTI0YTZiODI3MjM5ZGZlODVjZmNiNzhmMDc3OA==
4
+ ZjgwZmZjZDVkZWU1MDY2NWRhOTdmNzVmYzUzNmIyMjlmZjQ5NmNkOQ==
5
5
  data.tar.gz: !binary |-
6
- ZDYwNTI3MDVkMjU3YmEyMzc4YTRjMGExZmNiYTljYTVjMDJmODE4MA==
6
+ ZTkxOTdlMzBlNDE1MzEwNjY0YTVmYzJiNTZhZTRjN2YwMDhlMDFiOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjM5ZTc0NWRiYmFlODVhZTI0NTlkZmJmYTAxNmNiMWYzMzU4YTU4MDZiZWFj
10
- Y2M4ZTUxYjU2YWVmNDM0NThmNDMxMmYyZDllZjI1ZTc3ZTZiZjYyNzJiNjZj
11
- ZTZiNzA0YjliM2ZmNzI5MmE4NDJlMTFkYWE2Y2I3NDk5OTg5ZDE=
9
+ MjViZGJiM2JjYjgwYjYzN2FiYzNiMmU3ZDEyYjczYjUzMWQ3NzFlOTg4YmQw
10
+ NjJhODgyZDhhZjI3NzUxNmZkODk3ZjIxZmU2YzUzMGYwNzBmYjU1OWRkMDlh
11
+ Nzk4MDI4ZWIxMTExYzVkOGY5ZDFmODBiMDAwMjQyYmI3YjdkZjU=
12
12
  data.tar.gz: !binary |-
13
- ZGMyZDdlM2U2OTc3MzdkNmExZDY0MzRjMDMyOTBiYmYxMWQ2ZjY2YzFjNWJi
14
- OTJkOTFmOGVhMjc4Y2IyZmE3NDZlY2QxNzg5N2ZjYTJiYzVlNDI3OTBkMmFi
15
- YjRlMzRhMDBkZmZlYjQzYTQ0M2UwOGZhNTM5YTUxODNlN2M2NjU=
13
+ M2Q1ZDllNzgyNDUxODUyMTk1NzkyYjI1ZTk4NDM2YjY3YTgxNjY5NTBkMzM4
14
+ ODZmZWY5OGRkNmNkODlmZjA3OTA5NmVjM2IyYjlmN2JlNjYwNmZhZjczMThi
15
+ MzRiZjk5OWNjMzUwNDNmZjc4NGU5MzgyZjZiOWNmZDY4Y2RjMWY=
@@ -0,0 +1,27 @@
1
+
2
+ module RLiferayLib
3
+ class Column
4
+ attr_reader :column_name, :column_type
5
+
6
+ def initialize(column_name, column_type)
7
+ self.column_name=column_name
8
+ self.column_type=column_type
9
+ end
10
+
11
+ def getFormType
12
+ FORM_TYPE_MAP[column_type]
13
+ end
14
+
15
+ def getJavaType
16
+ JAVA_TYPE_MAP[column_type]
17
+ end
18
+
19
+ private
20
+
21
+ attr_writer :column_name, :column_type
22
+
23
+ FORM_TYPE_MAP = {'String' => 'text', 'int' => 'number', 'long' => 'number', 'Date' => 'date', 'boolean' => 'checkbox'}
24
+ JAVA_TYPE_MAP = {'String' => 'String', 'int' => 'Integer', 'long' => 'long', 'Date' => 'date', 'boolean' => 'Boolean'}
25
+
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ package mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.impl;
2
+
3
+ import com.liferay.portal.kernel.exception.PortalException;
4
+ import com.liferay.portal.kernel.exception.SystemException;
5
+ import java.util.Date;
6
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.base.<%= template_variables['name']%>LocalServiceBaseImpl;
7
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.model.<%= template_variables['name']%>;
8
+
9
+ /**
10
+ * The implementation of the <%= template_variables['name']%> local service.
11
+ *
12
+ * <p>
13
+ * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.<%= template_variables['name']%>LocalService} interface.
14
+ *
15
+ * <p>
16
+ * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
17
+ * </p>
18
+ *
19
+ * @author Brian Wing Shun Chan
20
+ * @see mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.base.<%= template_variables['name']%>LocalServiceBaseImpl
21
+ * @see mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.<%= template_variables['name']%>LocalServiceUtil
22
+ */
23
+ public class <%= template_variables['name']%>LocalServiceImpl extends <%= template_variables['name']%>LocalServiceBaseImpl {
24
+ /*
25
+ * NOTE FOR DEVELOPERS:
26
+ *
27
+ * Never reference this interface directly. Always use {@link mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.<%= template_variables['name']%>LocalServiceUtil} to access the <%= template_variables['name']%> local service.
28
+ */
29
+ public <%= template_variables['name']%> add<%= template_variables['name']%>(<% template_variables['columns'].each_with_index do |(column_name, column_object), index| %>
30
+ <%= column_object.column_type %> <%=column_name%><% if index < template_variables['columns'].size - 1 %>,<%end%><% end %>
31
+ ) throws PortalException, SystemException{
32
+ long itemId = counterLocalService.increment(<%= template_variables['name']%>.class.getName());
33
+ <%= template_variables['name']%> item = <%= template_variables['name'][0,1].downcase + template_variables['name'][1..-1]%>Persistence.create(itemId);
34
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
35
+ item.set<%=column_name[0,1].capitalize + column_name[1..-1]%>(<%=column_name%>);
36
+ <%- end -%>
37
+ super.add<%= template_variables['name']%>(item);
38
+ return item;
39
+ }
40
+ }
@@ -0,0 +1,41 @@
1
+ package mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.impl;
2
+
3
+ import com.liferay.portal.kernel.exception.PortalException;
4
+ import com.liferay.portal.kernel.exception.SystemException;
5
+ import java.util.Date;
6
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.base.<%= template_variables['name']%>ServiceBaseImpl;
7
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.model.<%= template_variables['name']%>;
8
+
9
+ /**
10
+ * The implementation of the <%= template_variables['name']%> remote service.
11
+ *
12
+ * <p>
13
+ * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.<%= template_variables['name']%>Service} interface.
14
+ *
15
+ * <p>
16
+ * This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
17
+ * </p>
18
+ *
19
+ * @author Brian Wing Shun Chan
20
+ * @see mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.base.<%= template_variables['name']%>ServiceBaseImpl
21
+ * @see mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.<%= template_variables['name']%>ServiceUtil
22
+ */
23
+ public class <%= template_variables['name']%>ServiceImpl extends <%= template_variables['name']%>ServiceBaseImpl {
24
+ /*
25
+ * NOTE FOR DEVELOPERS:
26
+ *
27
+ * Never reference this interface directly. Always use {@link mil.army.hrc.ikrome.<%= template_variables['project_name'] %>.service.<%= template_variables['name']%>ServiceUtil} to access the <%= template_variables['name']%> remote service.
28
+ */
29
+
30
+ public <%= template_variables['name']%> add<%= template_variables['name']%>(
31
+ <%- template_variables['columns'].each_with_index do |(column_name, column_object), index| -%>
32
+ <%= column_object.column_type %> <%=column_name%><% if index < template_variables['columns'].size - 1 %>,<%end%>
33
+ <%- end -%>
34
+ ) throws PortalException, SystemException{
35
+ return <%= template_variables['name'][0,1].downcase + template_variables['name'][1..-1]%>LocalService.add<%= template_variables['name']%>(
36
+ <%- template_variables['columns'].each_with_index do |(column_name, column_object), index| -%>
37
+ <%=column_name%><% if index < template_variables['columns'].size - 1 %>,<%end%>
38
+ <%- end -%>
39
+ );
40
+ }
41
+ }
@@ -0,0 +1,145 @@
1
+ package mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.portlet;
2
+
3
+ import com.liferay.portal.kernel.dao.orm.QueryUtil;
4
+ import com.liferay.portal.kernel.dao.search.SearchContainer;
5
+ import com.liferay.portal.kernel.exception.PortalException;
6
+ import com.liferay.portal.kernel.exception.SystemException;
7
+ import com.liferay.portal.kernel.log.Log;
8
+ import com.liferay.portal.kernel.log.LogFactoryUtil;
9
+ import com.liferay.portal.kernel.util.ParamUtil;
10
+ import com.liferay.portal.util.PortalUtil;
11
+ import com.liferay.util.bridges.mvc.MVCPortlet;
12
+ import java.io.IOException;
13
+ import java.util.List;
14
+ import java.util.Date;
15
+ import java.text.ParseException;
16
+ import java.text.SimpleDateFormat;
17
+ import javax.portlet.ActionRequest;
18
+ import javax.portlet.ActionResponse;
19
+ import javax.portlet.PortletException;
20
+ import javax.portlet.PortletURL;
21
+ import javax.portlet.RenderRequest;
22
+ import javax.portlet.RenderResponse;
23
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.model.<%= template_variables['name']%>;
24
+ import mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.<%= template_variables['name']%>LocalServiceUtil;
25
+
26
+ public class PortletController extends MVCPortlet {
27
+
28
+ private static Log _log = LogFactoryUtil.getLog(PortletController.class);
29
+
30
+ @Override
31
+ public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
32
+ try {
33
+ List<<%= template_variables['name']%>> allItems = <%= template_variables['name']%>LocalServiceUtil.get<%= template_variables['name'].pluralize%>(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
34
+ SearchContainer searchContainer = setupSearchContainer(request, response, allItems);
35
+ request.setAttribute("searchContainer", searchContainer);
36
+ } catch (SystemException se) {
37
+ _log.error("System error retrieving list items.", se);
38
+ }
39
+ request.setAttribute("currentURL", PortalUtil.getCurrentURL(request));
40
+ super.doView(request, response);
41
+ }
42
+
43
+ public void addItem(ActionRequest actionRequest, ActionResponse actionResponse) {
44
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
45
+ <%- if column_object.column_type == 'Date' -%>
46
+ Date <%=column_name%> = parseDateFromRequest(actionRequest, "<%=column_name%>");
47
+ <%- else -%>
48
+ <%=column_object.column_type%> <%=column_name%> = ParamUtil.get<%=column_object.getJavaType.capitalize%>(actionRequest, "<%=column_name%>");
49
+ <%- end -%>
50
+ <%- end -%>
51
+ try {
52
+ <%= template_variables['name']%>LocalServiceUtil.add<%= template_variables['name']%>(
53
+ <%- template_variables['columns'].each_with_index do |(column_name, column_object), index| -%>
54
+ <%=column_name%><% if index < template_variables['columns'].size - 1 %>,<%end%>
55
+ <%- end -%>
56
+ );
57
+ } catch (SystemException se) {
58
+ _log.error("System exception adding item.", se);
59
+ } catch (PortalException pe) {
60
+ _log.error("PortalException adding item", pe);
61
+ }
62
+ }
63
+
64
+ public void deleteItem(ActionRequest actionRequest, ActionResponse actionResponse) {
65
+ long itemId = ParamUtil.getLong(actionRequest, "item-id");
66
+ _log.info("Delete Item Id: " + itemId);
67
+
68
+ try {
69
+ <%= template_variables['name']%>LocalServiceUtil.delete<%= template_variables['name']%>(itemId);
70
+ } catch (SystemException se) {
71
+ _log.error("System exception adding item.", se);
72
+ } catch (PortalException pe) {
73
+ _log.error("PortalException adding item", pe);
74
+ }
75
+ }
76
+
77
+ public void updateItem(ActionRequest actionRequest, ActionResponse actionResponse) {
78
+ long itemId = ParamUtil.getLong(actionRequest, "item-id");
79
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
80
+ <%- if column_object.column_type == 'Date' -%>
81
+ Date <%=column_name%> = parseDateFromRequest(actionRequest, "<%=column_name%>");
82
+ <%- else -%>
83
+ <%=column_object.column_type%> <%=column_name%> = ParamUtil.get<%=column_object.getJavaType.capitalize%>(actionRequest, "<%=column_name%>");
84
+ <%- end -%>
85
+ <%- end -%>
86
+ try {
87
+ <%= template_variables['name']%> item = <%= template_variables['name']%>LocalServiceUtil.get<%= template_variables['name']%>(itemId);
88
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
89
+ item.set<%=column_name[0,1].capitalize + column_name[1..-1]%>(<%=column_name%>);
90
+ <%- end -%>
91
+ <%= template_variables['name']%>LocalServiceUtil.update<%= template_variables['name']%>(item);
92
+ } catch (SystemException se) {
93
+ _log.error("System Exception retrieving item" + itemId, se);
94
+ } catch (PortalException pe) {
95
+ _log.error("Portal Exception retrieving item" + itemId, pe);
96
+ }
97
+ }
98
+
99
+ private SearchContainer setupSearchContainer(RenderRequest request, RenderResponse response, List allItems) {
100
+ int currentPage = ParamUtil.getInteger(request, "cur");
101
+ int delta = ParamUtil.getInteger(request, "delta-param");
102
+ if (delta == 0) {
103
+ delta = 5;
104
+ }
105
+ PortletURL iteratorURL = response.createRenderURL();
106
+ iteratorURL.setParameter("delta-param", String.valueOf(delta));
107
+ SearchContainer<<%= template_variables['name']%>> searchContainer = new SearchContainer<<%= template_variables['name']%>>(request, iteratorURL, null, "No items were found.");
108
+ searchContainer.setDelta(delta);
109
+ searchContainer.setDeltaParam("delta-param");
110
+ int searchStart = getSearchContainerStart(currentPage, delta);
111
+ int searchEnd = getSearchContainerEnd(currentPage, delta, allItems.size());
112
+ List<<%= template_variables['name']%>> results = allItems.subList(searchStart, searchEnd);
113
+ searchContainer.setTotal(allItems.size());
114
+ searchContainer.setResults(results);
115
+ return searchContainer;
116
+ }
117
+
118
+ private int getSearchContainerStart(int currentPage, int delta) {
119
+ int start = 0;
120
+ if (currentPage > 0) {
121
+ start = (currentPage - 1) * delta;
122
+ }
123
+ return start;
124
+ }
125
+
126
+ private int getSearchContainerEnd(int currentPage, int delta, int total) {
127
+ int end = getSearchContainerStart(currentPage, delta) + delta;
128
+ if (end > total) {
129
+ end = total;
130
+ }
131
+ return end;
132
+ }
133
+
134
+ private Date parseDateFromRequest(ActionRequest actionRequest, String fieldName){
135
+ SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
136
+ String dateString= ParamUtil.getString(actionRequest, fieldName+"Day")+"/"+(ParamUtil.getInteger(actionRequest, fieldName + "Month") +1) +"/"+ParamUtil.getString(actionRequest, fieldName+"Year");
137
+ Date resultDate = new Date();
138
+ try{
139
+ resultDate = dateFormatter.parse(dateString);
140
+ }catch(ParseException pe){
141
+ _log.error("Error parsing date for: " + fieldName);
142
+ }
143
+ return resultDate;
144
+ }
145
+ }
@@ -0,0 +1,16 @@
1
+ <%%@include file="/html/init.jsp" %>
2
+ <portlet:actionURL name="addItem" var="addItemURL">
3
+ <portlet:param name="redirect" value="${param.backURL}"/>
4
+ </portlet:actionURL>
5
+
6
+ <aui:form action="${addItemURL}" method="post" name="newitemfm">
7
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
8
+ <%- if column_object.getFormType == 'date' -%>
9
+ <liferay-ui:input-date dayParam="<%=column_name%>Day" monthParam="<%=column_name%>Month" yearParam="<%=column_name%>Year" />
10
+ <%- else -%>
11
+ <aui:input type="<%= column_object.getFormType %>" name="<%= column_name %>" label="<%= column_name %>"></aui:input>
12
+ <%- end -%>
13
+ <%- end -%>
14
+ <aui:button type="submit"/>
15
+ <aui:button type="cancel" onClick="${param.backURL}"/>
16
+ </aui:form>
@@ -0,0 +1,20 @@
1
+ <%%@include file="/html/init.jsp" %>
2
+
3
+ <portlet:actionURL name="updateItem" var="updateItemURL">
4
+ <portlet:param name="redirect" value="${param.backURL}"/>
5
+ </portlet:actionURL>
6
+
7
+ <aui:form action="${updateItemURL}" method="post" name="updateitemfm">
8
+ <aui:input type="hidden" name="item-id" value="${param.itemId}"></aui:input>
9
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
10
+ <%- if column_object.getFormType == 'date' -%>
11
+ <liferay-ui:input-date dayParam="<%=column_name%>Day" monthParam="<%=column_name%>Month" yearParam="<%=column_name%>Year" dayValue="${param.<%=column_name%>Day}" monthValue="${param.<%=column_name%>Month}" yearValue="${param.<%=column_name%>Year}"/>
12
+ <%- elsif column_object.getFormType == 'checkbox' -%>
13
+ <aui:input type="<%= column_object.getFormType %>" name="<%= column_name %>" label="<%= column_name %>" checked="${param.<%= column_name %>}"></aui:input>
14
+ <%- else -%>
15
+ <aui:input type="<%= column_object.getFormType %>" name="<%= column_name %>" label="<%= column_name %>" value="${param.<%= column_name %>}"></aui:input>
16
+ <%- end -%>
17
+ <%- end -%>
18
+ <aui:button type="submit"/>
19
+ <aui:button type="cancel" onClick="${param.backURL}"/>
20
+ </aui:form>
@@ -0,0 +1,12 @@
1
+ <%%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
2
+ <%%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3
+ <%%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
4
+ <%%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
5
+ <%%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security"%>
6
+ <%%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
7
+ <%%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
8
+ <%%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
9
+ <%%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
10
+ <%%@ page import="mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.service.<%= template_variables['name']%>LocalServiceUtil" %>
11
+
12
+ <portlet:defineObjects />
@@ -0,0 +1,13 @@
1
+ name=<%= template_variables['project_name'] %>
2
+ module-group-id=<%= template_variables['project_name'].downcase %>
3
+ module-incremental-version=<%= template_variables['project_version'] %>
4
+ tags=
5
+ short-description=
6
+ change-log=
7
+ page-url=http://www.liferay.com
8
+ author=Liferay, Inc.
9
+ licenses=EE
10
+ portal-dependency-jars=\
11
+ jstl-api.jar,\
12
+ jstl-impl.jar,\
13
+ commons-lang.jar
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0"?>
2
+ <portlet-app schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
3
+ <portlet>
4
+ <portlet-name><%= template_variables['project_name'] %></portlet-name>
5
+ <display-name><%= template_variables['project_name'] %></display-name>
6
+ <portlet-class>mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.portlet.PortletController</portlet-class>
7
+ <init-param>
8
+ <name>view-template</name>
9
+ <value>/html/view.jsp</value>
10
+ </init-param>
11
+ <expiration-cache>0</expiration-cache>
12
+ <supports>
13
+ <mime-type>text/html</mime-type>
14
+ </supports>
15
+ <portlet-info>
16
+ <title><%= template_variables['project_name'] %></title>
17
+ <short-title><%= template_variables['project_name'] %></short-title>
18
+ <keywords><%= template_variables['project_name'] %></keywords>
19
+ </portlet-info>
20
+ <security-role-ref>
21
+ <role-name>administrator</role-name>
22
+ </security-role-ref>
23
+ <security-role-ref>
24
+ <role-name>guest</role-name>
25
+ </security-role-ref>
26
+ <security-role-ref>
27
+ <role-name>power-user</role-name>
28
+ </security-role-ref>
29
+ <security-role-ref>
30
+ <role-name>user</role-name>
31
+ </security-role-ref>
32
+ </portlet>
33
+ </portlet-app>
@@ -0,0 +1,64 @@
1
+ <%%@include file="/html/init.jsp" %>
2
+
3
+ <portlet:renderURL var="addItemURL">
4
+ <portlet:param name="jspPage" value="/html/add.jsp" />
5
+ <portlet:param name="backURL" value="${currentURL}" />
6
+ </portlet:renderURL>
7
+
8
+ <a href="${addItemURL}">Add Item</a>
9
+
10
+ <liferay-ui:search-container searchContainer="${searchContainer}" >
11
+ <liferay-ui:search-container-results
12
+ results="${searchContainer.results}"
13
+ total="${searchContainer.total}"
14
+ />
15
+
16
+ <liferay-ui:search-container-row
17
+ className="mil.army.hrc.ikrome.<%= template_variables['project_name'].downcase %>.model.<%= template_variables['name'] %>"
18
+ keyProperty="<%= template_variables['primary_key'] %>"
19
+ modelVar="item"
20
+ >
21
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
22
+ <liferay-ui:search-container-column-text
23
+ name="<%=column_name %>"
24
+ <%- if column_object.column_type == 'Date' -%>
25
+ >
26
+ <fmt:formatDate type="date" value="${item.<%=column_name%>}" />
27
+ </liferay-ui:search-container-column-text>
28
+ <%- else -%>
29
+ property="<%=column_name %>"
30
+ />
31
+ <%- end -%>
32
+ <% end %>
33
+ <liferay-ui:search-container-column-text
34
+ name="actions"
35
+ >
36
+ <liferay-ui:icon-menu >
37
+ <portlet:renderURL var="updateItemURL">
38
+ <portlet:param name="itemId" value="${item.<%= template_variables['primary_key'] %>}" />
39
+ <%- template_variables['columns'].each do |column_name, column_object| -%>
40
+ <%- if column_object.column_type == 'Date' -%>
41
+ <fmt:formatDate value="${item.<%=column_name%>}" pattern="MM" var="<%=column_name%>m"/>
42
+ <fmt:formatDate value="${item.<%=column_name%>}" pattern="dd" var="<%=column_name%>d"/>
43
+ <fmt:formatDate value="${item.<%=column_name%>}" pattern="yyyy" var="<%=column_name%>y" />
44
+ <portlet:param name="<%=column_name%>Month" value="${<%=column_name%>m -1}" />
45
+ <portlet:param name="<%=column_name%>Day" value="${<%=column_name%>d}" />
46
+ <portlet:param name="<%=column_name%>Year" value="${<%=column_name%>y}" />
47
+ <%- else -%>
48
+ <portlet:param name="<%=column_name%>" value="${item.<%=column_name%>}" />
49
+ <%- end -%>
50
+ <%- end -%>
51
+ <portlet:param name="backURL" value="${currentURL}" />
52
+ <portlet:param name="jspPage" value="/html/edit.jsp" />
53
+ </portlet:renderURL>
54
+ <liferay-ui:icon image="edit" message="edit" url="${updateItemURL}" />
55
+ <portlet:actionURL name="deleteItem" var="deleteItemURL">
56
+ <portlet:param name="item-id" value="${item.<%= template_variables['primary_key'] %>}" />
57
+ <portlet:param name="redirect" value="${currentURL}" />
58
+ </portlet:actionURL>
59
+ <liferay-ui:icon-delete url="${deleteItemURL}" />
60
+ </liferay-ui:icon-menu>
61
+ </liferay-ui:search-container-column-text>
62
+ </liferay-ui:search-container-row>
63
+ <liferay-ui:search-iterator />
64
+ </liferay-ui:search-container>
@@ -0,0 +1,139 @@
1
+ require_relative 'template_utility'
2
+
3
+ module RLiferayLib
4
+ class PreparePortletService
5
+ attr_reader :template_directory, :target_directory, :template_variables
6
+
7
+ WEB_INF_DIR = '/src/main/webapp/WEB-INF'
8
+ JSP_DIR = '/src/main/webapp/html'
9
+ JAVA_DIR = 'src/main/java/mil/army/hrc/ikrome'
10
+ PLUGIN_PACKAGE_NAME = 'liferay-plugin-package.properties'
11
+ PORTLET_XML_NAME = 'portlet.xml'
12
+ CONTROLLER_NAME = 'PortletController.java'
13
+ LOCAL_IMPL_NAME = 'LocalServiceImpl.java'
14
+ REMOTE_IMPL_NAME = 'ServiceImpl.java'
15
+
16
+ def initialize(template_directory, target_directory, template_variables)
17
+ self.template_directory=template_directory
18
+ self.target_directory=target_directory
19
+ self.template_variables=template_variables
20
+ generate_properties
21
+ generate_jsp_files
22
+ generate_java_files
23
+ end
24
+
25
+ private
26
+ attr_writer :template_directory, :target_directory, :template_variables
27
+
28
+ def generate_properties
29
+ target_directory = self.target_directory + WEB_INF_DIR
30
+ generate_portlet_xml(target_directory)
31
+ generate_plugin_package_properties(target_directory)
32
+ end
33
+
34
+ def generate_portlet_xml(target_directory)
35
+ template_utility = TemplateUtility.new(
36
+ self.template_directory + '/portlet.xml.erb',
37
+ target_directory,
38
+ PORTLET_XML_NAME,
39
+ self.template_variables)
40
+ end
41
+
42
+ def generate_plugin_package_properties(target_directory)
43
+ template_utility = TemplateUtility.new(
44
+ self.template_directory + '/liferay-plugin-package.properties.erb',
45
+ target_directory,
46
+ PLUGIN_PACKAGE_NAME,
47
+ self.template_variables)
48
+ end
49
+
50
+
51
+ def generate_jsp_files
52
+ jsp_target = self.target_directory + JSP_DIR
53
+ prepare_directory(jsp_target)
54
+ generate_view_jsp(jsp_target)
55
+ generate_init_jsp(jsp_target)
56
+ generate_edit_jsp(jsp_target)
57
+ generate_add_jsp(jsp_target)
58
+ end
59
+
60
+ def generate_view_jsp(jsp_target)
61
+ template_utility = TemplateUtility.new(
62
+ self.template_directory + '/view.jsp.erb',
63
+ jsp_target,
64
+ 'view.jsp', self.template_variables)
65
+ end
66
+
67
+ def generate_init_jsp(jsp_target)
68
+ template_utility = TemplateUtility.new(
69
+ self.template_directory + '/init.jsp.erb',
70
+ jsp_target,
71
+ 'init.jsp',
72
+ self.template_variables)
73
+ end
74
+
75
+ def generate_edit_jsp(jsp_target)
76
+ template_utility = TemplateUtility.new(
77
+ self.template_directory + '/edit.jsp.erb',
78
+ jsp_target,
79
+ 'edit.jsp',
80
+ self.template_variables)
81
+ end
82
+
83
+ def generate_add_jsp(jsp_target)
84
+ template_utility = TemplateUtility.new(
85
+ self.template_directory + '/add.jsp.erb',
86
+ jsp_target,
87
+ 'add.jsp',
88
+ self.template_variables)
89
+ end
90
+
91
+
92
+ def generate_java_files
93
+ target_directory = self.target_directory + '/' + JAVA_DIR + "/#{self.template_variables['project_name'].downcase}"
94
+ prepare_directory(target_directory)
95
+ generate_controller(target_directory)
96
+ generate_local_impl(target_directory)
97
+ generate_remote_impl(target_directory)
98
+ end
99
+
100
+ def generate_controller(target_directory)
101
+ target_directory = target_directory + '/portlet'
102
+ prepare_directory(target_directory)
103
+ template_utility = TemplateUtility.new(
104
+ self.template_directory + '/PortletController.java.erb',
105
+ target_directory,
106
+ CONTROLLER_NAME,
107
+ self.template_variables)
108
+ end
109
+
110
+ def generate_local_impl(target_directory)
111
+ target_directory = target_directory + '/service/impl'
112
+ prepare_directory(target_directory)
113
+ template_utility = TemplateUtility.new(
114
+ self.template_directory + '/ListItemLocalServiceImpl.java.erb',
115
+ target_directory,
116
+ "#{self.template_variables['name']}" + LOCAL_IMPL_NAME,
117
+ self.template_variables)
118
+ end
119
+
120
+ def generate_remote_impl(target_directory)
121
+ target_directory = target_directory + '/service/impl'
122
+ prepare_directory(target_directory)
123
+ template_utility = TemplateUtility.new(
124
+ self.template_directory + '/ListItemServiceImpl.java.erb',
125
+ target_directory,
126
+ "#{self.template_variables['name']}" + REMOTE_IMPL_NAME,
127
+ self.template_variables)
128
+ end
129
+
130
+
131
+ private
132
+ def prepare_directory(directory_path)
133
+ if !Dir.exist? directory_path
134
+ FileUtils.mkpath directory_path
135
+ end
136
+ end
137
+
138
+ end
139
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'column'
2
+ require_relative 'xml_utility'
3
+
4
+ module RLiferayLib
5
+ class ReadPOM
6
+ attr_reader :pom_xml_file, :version
7
+
8
+ def initialize(pom_xml_file)
9
+ self.pom_xml_file=pom_xml_file
10
+ read_xml
11
+ end
12
+
13
+
14
+
15
+ private
16
+ attr_writer :pom_xml_file, :version
17
+
18
+ def read_xml
19
+ xml_utility = XMLUtility.new(self.pom_xml_file)
20
+ self.version = xml_utility.xml_content.at_xpath('/project/version').to_s
21
+ end
22
+
23
+
24
+
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'column'
2
+ require_relative 'xml_utility'
3
+
4
+ module RLiferayLib
5
+ class ReadService
6
+ attr_reader :service_xml_file, :entities
7
+
8
+ def initialize(service_xml_file)
9
+ self.service_xml_file=service_xml_file
10
+ self.entities = Hash.new()
11
+ read_xml
12
+ end
13
+
14
+
15
+
16
+ private
17
+ attr_writer :service_xml_file, :entities
18
+
19
+ def read_xml
20
+ xml_utility = XMLUtility.new(self.service_xml_file)
21
+ entity_nodes = xml_utility.xml_content.xpath('/service-builder/entity')
22
+
23
+ entity_nodes.each { | entity_node |
24
+ entity_name = entity_node.attr('name')
25
+ self.entities[entity_name] = Hash.new()
26
+ self.entities[entity_name]['name'] = entity_name
27
+ self.entities[entity_name]['primary_key'] = ''
28
+ self.entities[entity_name]['columns'] = Hash.new()
29
+ read_columns(entity_name, entity_node)
30
+ }
31
+ end
32
+
33
+ def read_columns(entity_name, entity_node)
34
+ column_nodes = entity_node.xpath('./column')
35
+ column_nodes.each { | column_node|
36
+ column_name = column_node.attr('name')
37
+ if column_node.attr("primary") == 'true'
38
+ self.entities[entity_name]['primary_key'] = column_name
39
+ elsif !IGNORE_COLUMNS.include?(column_name)
40
+ self.entities[entity_name]['columns'][column_name] = Column.new(column_name, column_node.attr('type'))
41
+ end
42
+ }
43
+ end
44
+
45
+ IGNORE_COLUMNS = {
46
+ 'groupId' => 'long',
47
+ 'companyId' => 'long',
48
+ 'userId' => 'long',
49
+ 'userName' => 'String',
50
+ 'createDate' => 'Date',
51
+ 'modifiedDate' => 'Date'
52
+ }
53
+
54
+
55
+ end
56
+ end
@@ -0,0 +1,49 @@
1
+ require 'erb'
2
+ require 'active_support/all'
3
+
4
+ module RLiferayLib
5
+ class TemplateUtility
6
+ attr_accessor :content
7
+
8
+
9
+ def initialize(template_path, target_directory, target_name, template_variables )
10
+ run_erb(template_path, target_name, target_directory, template_variables)
11
+ end
12
+
13
+
14
+ private
15
+ attr_writer :content
16
+
17
+ def run_erb(template_path, target_name, target_directory, template_variables)
18
+ target_file_name = target_directory + '/' + target_name
19
+ write_template_results(target_file_name,erb_output(template_path,template_variables))
20
+ end
21
+
22
+ def erb_output(template_name,template_variables=Hash.new())
23
+ template_content = load_template(template_name)
24
+ template = ERB.new(template_content, nil, '-')
25
+ template_results = template.result(binding)
26
+ template_results
27
+ end
28
+
29
+ def load_template(template_name)
30
+ if File.exists?(template_name)
31
+ file = File.open(template_name)
32
+ contents=file.read()
33
+ end
34
+ end
35
+
36
+ def write_template_results(file_name,template_results)
37
+ if File.exist?(file_name)
38
+ backup_file(file_name)
39
+ end
40
+ File.open(file_name,'w') { |file|
41
+ file.write(template_results)
42
+ }
43
+ end
44
+
45
+ def backup_file(file_name)
46
+ FileUtils.mv(file_name,file_name + '.' + Time.now.strftime("%Y%m%d%H%M%S%L"), :force => true)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ require 'nokogiri'
2
+
3
+ module RLiferayLib
4
+ class XMLUtility
5
+ attr_reader :xml_file_location, :xml_content, :namespaces
6
+
7
+ def initialize(xml_file_location)
8
+ self.xml_file_location=xml_file_location
9
+ read_xml_content()
10
+ end
11
+
12
+ def read_xml_content()
13
+ f = nil
14
+ begin
15
+ f = File.open(xml_file_location)
16
+ self.xml_content = Nokogiri::XML(f)
17
+ self.namespaces = self.xml_content.collect_namespaces
18
+ xml_content.remove_namespaces!
19
+ ensure
20
+ f.close()
21
+ end
22
+ end
23
+
24
+ def write_xml_content()
25
+ f = nil
26
+ begin
27
+ f = File.new(self.xml_file_location,"w")
28
+ add_namespaces
29
+ f.write(xml_content.to_s)
30
+ ensure
31
+ f.close()
32
+ end
33
+ end
34
+
35
+
36
+
37
+
38
+ private
39
+ attr_writer :xml_file_location, :xml_content, :namespaces
40
+
41
+ def add_namespaces
42
+ self.namespaces.each { | key, value|
43
+ xml_content.add_namespace_definition(key,value)
44
+ }
45
+ end
46
+
47
+
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RLiferayTool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lynch, Mike Zanchi
@@ -89,6 +89,21 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - lib/r_liferay_tool.rb
92
+ - lib/r_liferay_lib/column.rb
93
+ - lib/r_liferay_lib/prepare_portlet_service.rb
94
+ - lib/r_liferay_lib/read_service.rb
95
+ - lib/r_liferay_lib/xml_utility.rb
96
+ - lib/r_liferay_lib/read_pom.rb
97
+ - lib/r_liferay_lib/template_utility.rb
98
+ - lib/r_liferay_lib/portlet_service_templates/add.jsp.erb
99
+ - lib/r_liferay_lib/portlet_service_templates/liferay-plugin-package.properties.erb
100
+ - lib/r_liferay_lib/portlet_service_templates/PortletController.java.erb
101
+ - lib/r_liferay_lib/portlet_service_templates/edit.jsp.erb
102
+ - lib/r_liferay_lib/portlet_service_templates/ListItemLocalServiceImpl.java.erb
103
+ - lib/r_liferay_lib/portlet_service_templates/portlet.xml.erb
104
+ - lib/r_liferay_lib/portlet_service_templates/init.jsp.erb
105
+ - lib/r_liferay_lib/portlet_service_templates/ListItemServiceImpl.java.erb
106
+ - lib/r_liferay_lib/portlet_service_templates/view.jsp.erb
92
107
  - test/liferay-plugin-package.properties
93
108
  - test/pom.xml
94
109
  - test/portlet.xml