Versão gerando o caderno sem configuração

parent 061cd904
/settings/
/target/
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
validateFragments=false
validation.use-project-settings=true
activeProfiles=Liferay-v6.2-EE-(Tomcat-7)
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="mprj-doerj-geracao-caderno-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="mprj-doerj-geracao-caderno-portlet"/>
<property name="java-output-path" value="/mprj-doerj-geracao-caderno-portlet/target/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.4"/>
<installed facet="liferay.portlet" version="6.0"/>
<installed facet="jboss.m2" version="1.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Window
\ No newline at end of file
disabled=06target
eclipse.preferences.version=1
{"ide":{},"libs":["ecma5","browser"],"plugins":{"guess-types":{},"angular":{},"liferay":{}}}
\ No newline at end of file
......@@ -4,9 +4,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mprj-doerj-geracao-caderno-portlet</groupId>
<artifactId>mprj-doerj-geracao-caderno-portlet</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>mprj-doerj-geracao-caderno-portlet</name>
<version>0.0.1</version>
<parent>
<groupId>root-pom</groupId>
......@@ -57,6 +57,7 @@
</configuration>
</plugin>
</plugins>
<finalName>mprj-doerj-geracao-caderno-portlet</finalName>
</build>
<dependencies>
<dependency>
......
......@@ -12,6 +12,7 @@ import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
......@@ -23,18 +24,29 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletModeException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletURL;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceURL;
import javax.portlet.WindowState;
import javax.portlet.WindowStateException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.Cookie;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import org.apache.log4j.Logger;
import org.docx4j.XmlUtils;
......@@ -45,6 +57,8 @@ import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
......@@ -62,15 +76,14 @@ public class CadernoPortlet extends MVCPortlet{
String dataDivulgacao = ParamUtil.getString(uploadRequest, "dataP");
String situacao = ParamUtil.getString(uploadRequest, "situacao");
//System.out.println(valor);
//System.out.println(valor);
com.liferay.portal.kernel.json.JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
if (cmd.equals("geraCaderno")){
try {
geraCaderno(resourceRequest,resourceResponse,dataDivulgacao,situacao);
//geraCaderno(resourceRequest,resourceResponse,dataDivulgacao,situacao);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -93,55 +106,89 @@ public class CadernoPortlet extends MVCPortlet{
writer.println(jsonResponse);
// Creating a JSON object which will contain the sum.
}
PortletURL renderUrl = resourceResponse.createRenderURL();
//renderUrl.setParameter("erro", "");
// resourceResponse.addProperty("Location", renderUrl.toString());
//resourceResponse.encodeURL(renderUrl.toString());
//resourceResponse.createActionURL().addProperty("Location", renderUrl.toString());
//resourceResponse.createRenderURL();
resourceResponse.addProperty("Location", resourceResponse.createRenderURL().toString());
return;
}
public void geraCaderno(ResourceRequest resourceRequest,
ResourceResponse resourceResponse,String dataDivulgacao,String idStatus)throws Exception {
public void geraCaderno(ActionRequest actionRequest, ActionResponse actionResponse)throws Exception {
UploadPortletRequest uploadRequest=PortalUtil.getUploadPortletRequest(resourceRequest);
UploadPortletRequest uploadRequest=PortalUtil.getUploadPortletRequest(actionRequest);
ThemeDisplay themeDisplay = (ThemeDisplay) uploadRequest.getAttribute(WebKeys.THEME_DISPLAY);
String dataDivulgacao = ParamUtil.getString(uploadRequest, "dataP");
String idStatus = ParamUtil.getString(uploadRequest, "situacao");
JSONArray listaConteudos = new JSONArray();
RestServices rest = new RestServices();
String dataDivulgacaoRest = dataDivulgacao.replace("/", "");
listaConteudos = rest.getRest(dataDivulgacaoRest,idStatus);
SessionMessages.add(actionRequest.getPortletSession(), PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
if(!mensagensDeErro(listaConteudos, dataDivulgacao, resourceRequest)){
if(!mensagensDeErro(listaConteudos, dataDivulgacao, actionRequest)){
GeraCaderno caderno = new GeraCaderno();
caderno.processaCaderno(resourceRequest, resourceResponse,listaConteudos,dataDivulgacao);
caderno.processaCaderno(actionRequest, actionResponse,listaConteudos,dataDivulgacao);
}else{
com.liferay.portal.kernel.json.JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
/*com.liferay.portal.kernel.json.JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
jsonResponse.put("erroDataNula", true);
PrintWriter writer = resourceResponse.getWriter();
writer.println(jsonResponse);
writer.println(jsonResponse);*/
/* PortletRequestDispatcher dispatcher;
dispatcher = getPortletContext().getRequestDispatcher("/jsp/admin/view-admin.jsp");
dispatcher.include(resourceRequest, resourceResponse);*/
// SessionMessages.add(actionRequest.getPortletSession(), "erro");
String portletName = (String) actionRequest.getAttribute(WebKeys.PORTLET_ID);
/*PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(resourceRequest), portletName, themeDisplay.getLayout().getPlid(),
PortletRequest.RENDER_PHASE);
redirectURL.setParameter("jspPage", "/jsp/admin/view-admin.jsp");
((ActionResponse) resourceResponse).sendRedirect(redirectURL.toString());*/
}
String portletName = (String) resourceRequest.getAttribute(WebKeys.PORTLET_ID);
/*String portletName = (String) resourceRequest.getAttribute(WebKeys.PORTLET_ID);
PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(resourceRequest), portletName, themeDisplay.getLayout().getPlid(),
PortletRequest.RENDER_PHASE);
redirectURL.setParameter("jspPage", "/jsp/admin/view-admin.jsp");
//resourceResponse.sendRedirect(redirectURL.toString());
//resourceResponse.sendRedirect(redirectURL.toString());*/
//HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(resourceResponse);
//httpResponse.sendRedirect(redirect);
}
protected Boolean mensagensDeErro(JSONArray listaConteudos, String dataDivulgacao, ResourceRequest resourceRequest) throws ParseException{
protected Boolean mensagensDeErro(JSONArray listaConteudos, String dataDivulgacao, ActionRequest actionRequest) throws ParseException{
Boolean contemErro = Boolean.FALSE;
if(listaConteudos.length()==0) {
if(listaConteudos.length()==0 && !dataDivulgacao.equals("")) {
contemErro = Boolean.TRUE;
resourceRequest.setAttribute("erro", true);
SessionErrors.add(resourceRequest.getPortletSession(), "erroArquivo");
actionRequest.setAttribute("erroListagemNula", true);
SessionErrors.add(actionRequest.getPortletSession(), "erroListagemNula");
SessionMessages.add(actionRequest.getPortletSession(), PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
} else if(dataDivulgacao.equals("")) {
contemErro = Boolean.TRUE;
resourceRequest.setAttribute("erroVazio", true);
SessionErrors.add(resourceRequest.getPortletSession(), "erroVazio");
actionRequest.setAttribute("erroDataNula", true);
SessionErrors.add(actionRequest.getPortletSession(), "erroDataNula");
SessionMessages.add(actionRequest.getPortletSession(), PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
}
return contemErro;
}
......
package br.mp.mprj.portal.portlet.caderno.conf;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.util.ParamUtil;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
public class Configuration extends DefaultConfigurationAction {
@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
super.processAction(portletConfig, actionRequest, actionResponse);
PortletPreferences prefs = actionRequest.getPreferences();
String urlConfig = ParamUtil.getString(actionRequest, "urlConfig");
String urlOrgao = ParamUtil.getString(actionRequest, "urlOrgao");
prefs.setValue("urlConfig", urlConfig);
prefs.setValue("urlOrgao", urlOrgao);
prefs.store();
}
}
\ No newline at end of file
package br.mp.mprj.portal.portlet.caderno.service;
import com.liferay.portal.util.PortalUtil;
import br.mp.mprj.portal.portlet.caderno.util.CadernoUtil;
import br.mp.mprj.portal.portlet.caderno.util.Estilos;
......@@ -7,17 +9,30 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Locale;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.CacheControl;
import javax.portlet.ClientDataRequest;
import javax.portlet.PortletContext;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletURL;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceURL;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBException;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.poi.ss.formula.functions.Replace;
import org.docx4j.XmlUtils;
import org.docx4j.openpackaging.Base;
......@@ -27,13 +42,16 @@ import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
public class GeraCaderno {
public static void processaCaderno(ResourceRequest resourceRequest,ResourceResponse resourceResponse,JSONArray listaConteudos,String dataDivulgacao) throws Docx4JException, JAXBException, IOException, ParseException{
public static void processaCaderno(ActionRequest actionRequest,ActionResponse actionResponse,JSONArray listaConteudos,String dataDivulgacao) throws Docx4JException, JAXBException, IOException, ParseException{
PortletContext context = resourceRequest.getPortletSession().getPortletContext();
PortletContext context = actionRequest.getPortletSession().getPortletContext();
String pathTemplate = context.getRealPath("/template");
String conteudo="";
String orgao="";
......@@ -188,6 +206,9 @@ public class GeraCaderno {
}
MainDocumentPart acumuladoDocumentPart = acumuladoPackage.getMainDocumentPart();
estilo.alterStyleSheet(templatePackage);
......@@ -203,8 +224,9 @@ public class GeraCaderno {
templatePackage.save(exportFile);
resourceResponse.setContentType("application/force-download");
resourceResponse.addProperty("Content-Disposition", "attachment; filename="+nomeArquivo + ".docx");
/*response.setContentType("application/force-download");
((PortletResponse) response).addProperty("Content-Disposition", "attachment; filename="+nomeArquivo + ".docx");
File outputFile = new File(System.getProperty("java.io.tmpdir"), nomeArquivo);
FileInputStream in = new FileInputStream(exportFile);
......@@ -218,7 +240,28 @@ public class GeraCaderno {
}
in.close();
out.flush();
out.close();
out.close();*/
PortletRequest pRequest = PortalUtil.getLiferayPortletRequest(actionRequest);
PortletResponse pResponse = PortalUtil.getLiferayPortletResponse(actionResponse);
HttpServletRequest req = PortalUtil.getHttpServletRequest(pRequest);
HttpServletResponse res = PortalUtil.getHttpServletResponse(pResponse);
res.setHeader("Content-Disposition", "attachment; filename="+nomeArquivo + ".docx");//
res.setHeader("Content-Transfer-Encoding", "binary");
res.setContentType("application/force-download");
FileInputStream in = new FileInputStream(exportFile);
OutputStream out = res.getOutputStream();
byte[] buffer = new byte[4096];
int numBytesRead;
while ((numBytesRead = in.read(buffer)) > 0) {
out.write(buffer, 0, numBytesRead);
}
res.flushBuffer();
}
......
......@@ -5,6 +5,7 @@
<portlet>
<portlet-name>mprj-doerj-geracao-caderno-portlet</portlet-name>
<icon>/icon.png</icon>
<configuration-action-class>br.mp.mprj.portal.portlet.caderno.conf.Configuration</configuration-action-class>
<control-panel-entry-category>content</control-panel-entry-category>
<control-panel-entry-weight>2</control-panel-entry-weight>
<header-portlet-css>/css/admin/admin.css</header-portlet-css>
......
......@@ -9,9 +9,14 @@
<name>view-template</name>
<value>/jsp/admin/view-admin.jsp</value>
</init-param>
<init-param>
<name>config-template</name>
<value>/jsp/configuration.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<resource-bundle>content/Language</resource-bundle>
<portlet-info>
......
......@@ -36,20 +36,23 @@
<liferay-theme:defineObjects />
<portlet:defineObjects />
<liferay-ui:error key="erroListagemNula" message="No existem matrias cadastradas para os parmetros utilizados." />
<h3><liferay-ui:message key="admin.form.agendamento.titulo"/></h3>
<hr />
<div class="texto-obs"><liferay-ui:message key="admin.form.agendamento.observacao"/></div>
<portlet:resourceURL var="submitURL">
<portlet:param name="caderno" value="geraCaderno"/>
</portlet:resourceURL>
<liferay-ui:success key="sucesso" message="Sua solicitao foi completada com sucesso!" />
<liferay-ui:error key="erro" message="Os campos do formulrio no foram preenchidos corretamente. Por favor, verifique e tente novamente." />
<portlet:actionURL var="submitActionURL">
<portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="geraCaderno" />
</portlet:actionURL>
<form id="<portlet:namespace />formDO" name="<portlet:namespace />formDO" method="POST" enctype="multipart/form-data" action="<%=submitURL%>" >
<form id="<portlet:namespace />formDO" name="<portlet:namespace />formDO" method="POST" enctype="multipart/form-data" action="<%=submitActionURL%>" >
<div id="campo-situacao" class="campo">
<label><liferay-ui:message key="admin.form.editar.situacao"/></label>
......@@ -78,7 +81,7 @@
</div>
</div>
<liferay-ui:error key="erroDataNula" message="Uma data deve ser selecionada." />
<liferay-ui:error key="erroHorarioLimite" message="O horrio limite para agendar divulgao para hoje foi ultrapassado (19h49)." />
</div>
<button type="submit" id="enviarFormDO" name="enviarFormDO" class="btn btn-primary">Gerar Caderno</button>
......
<%@ include file="/jsp/init.jsp" %>
<liferay-portlet:actionURL portletConfiguration="true" var="configurationURL" />
<%
String urlConfig = portletPreferences.getValue("urlConfig", StringPool.BLANK);
String urlOrgao = portletPreferences.getValue("urlOrgao", StringPool.BLANK);
%>
<aui:form action="<%=configurationURL %>" method="post" name="fm">
<aui:input name="urlConfig" label="URL do Solr utilizado: " type="text" value="<%= urlConfig %>" />
<aui:input name="urlOrgao" label="URL do Servio Orgao: " type="text" value="<%= urlOrgao %>" />
<aui:button-row>
<aui:button type="submit" value="Salvar" />
</aui:button-row>
</aui:form>
\ No newline at end of file
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
<%@page import="java.util.List"%>
<%@page import="java.lang.String"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@ page import="javax.portlet.PortletPreferences"%>
<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:defineObjects />
<theme:defineObjects />
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment