Sfoglia il codice sorgente
fix richiesta firma direttore lavori per allegato A06feature/pannello-pratiche
marcoalderighi
2 anni fa
27 ha cambiato i file con 312 aggiunte e 167 eliminazioni
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
@ -1,156 +1,156 @@ |
|||||||
package it.nextmind.liferay.portos.advanced.operation.portlet; |
//package it.nextmind.liferay.portos.advanced.operation.portlet;
|
||||||
|
//
|
||||||
import com.liferay.portal.kernel.json.JSONFactoryUtil; |
//import com.liferay.portal.kernel.json.JSONFactoryUtil;
|
||||||
import com.liferay.portal.kernel.json.JSONObject; |
//import com.liferay.portal.kernel.json.JSONObject;
|
||||||
import com.liferay.portal.kernel.log.Log; |
//import com.liferay.portal.kernel.log.Log;
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil; |
//import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||||
import com.liferay.portal.kernel.servlet.ServletResponseUtil; |
//import com.liferay.portal.kernel.servlet.ServletResponseUtil;
|
||||||
import com.liferay.portal.kernel.upload.UploadPortletRequest; |
//import com.liferay.portal.kernel.upload.UploadPortletRequest;
|
||||||
import com.liferay.portal.kernel.util.ContentTypes; |
//import com.liferay.portal.kernel.util.ContentTypes;
|
||||||
import com.liferay.portal.kernel.util.GetterUtil; |
//import com.liferay.portal.kernel.util.GetterUtil;
|
||||||
import com.liferay.portal.kernel.util.ParamUtil; |
//import com.liferay.portal.kernel.util.ParamUtil;
|
||||||
import com.liferay.portal.kernel.util.StreamUtil; |
//import com.liferay.portal.kernel.util.StreamUtil;
|
||||||
import com.liferay.portal.kernel.util.StringPool; |
//import com.liferay.portal.kernel.util.StringPool;
|
||||||
import com.liferay.portal.kernel.util.Validator; |
//import com.liferay.portal.kernel.util.Validator;
|
||||||
import com.liferay.portal.kernel.util.WebKeys; |
//import com.liferay.portal.kernel.util.WebKeys;
|
||||||
import com.liferay.portal.theme.ThemeDisplay; |
//import com.liferay.portal.theme.ThemeDisplay;
|
||||||
import com.liferay.portal.util.PortalUtil; |
//import com.liferay.portal.util.PortalUtil;
|
||||||
import com.liferay.util.bridges.mvc.MVCPortlet; |
//import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||||
|
//
|
||||||
import it.tref.liferay.portos.bo.report.builder.bean.ReportAvvisoBean; |
//import it.tref.liferay.portos.bo.report.builder.bean.ReportAvvisoBean;
|
||||||
import it.tref.liferay.portos.bo.report.builder.builder.ReportAvvisoBeanBuilder; |
//import it.tref.liferay.portos.bo.report.builder.builder.ReportAvvisoBeanBuilder;
|
||||||
import it.tref.liferay.portos.report.html.core.HtmlToPdfEngine; |
//import it.tref.liferay.portos.report.html.core.HtmlToPdfEngine;
|
||||||
import it.tref.liferay.portos.report.jasper.core.provider.JasperPdfProvider; |
//import it.tref.liferay.portos.report.jasper.core.provider.JasperPdfProvider;
|
||||||
import it.tref.liferay.portos.report.jasper.core.report.BeanReport; |
//import it.tref.liferay.portos.report.jasper.core.report.BeanReport;
|
||||||
import it.tref.liferay.portos.report.jasper.core.report.ReportInterface; |
//import it.tref.liferay.portos.report.jasper.core.report.ReportInterface;
|
||||||
import it.tref.liferay.portos.report.odt.core.OdtToPdfEngine; |
//import it.tref.liferay.portos.report.odt.core.OdtToPdfEngine;
|
||||||
import it.tref.liferay.portos.report.shared.constants.ReportConstants; |
//import it.tref.liferay.portos.report.shared.constants.ReportConstants;
|
||||||
import it.tref.liferay.portos.report.shared.constants.ReportConstants.ReportType; |
//import it.tref.liferay.portos.report.shared.constants.ReportConstants.ReportType;
|
||||||
import it.tref.liferay.portos.report.shared.dto.ReportDto; |
//import it.tref.liferay.portos.report.shared.dto.ReportDto;
|
||||||
import it.tref.liferay.portos.report.shared.dto.ReportResultDto; |
//import it.tref.liferay.portos.report.shared.dto.ReportResultDto;
|
||||||
import it.tref.liferay.portos.report.shared.util.ReportUtil; |
//import it.tref.liferay.portos.report.shared.util.ReportUtil;
|
||||||
import it.tref.liferay.portos.report.shared.util.VelocityUtil; |
//import it.tref.liferay.portos.report.shared.util.VelocityUtil;
|
||||||
|
//
|
||||||
import java.io.ByteArrayOutputStream; |
//import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException; |
//import java.io.IOException;
|
||||||
import java.io.InputStream; |
//import java.io.InputStream;
|
||||||
import java.util.HashMap; |
//import java.util.HashMap;
|
||||||
|
//
|
||||||
import javassist.ClassPool; |
//import javassist.ClassPool;
|
||||||
|
//
|
||||||
import javax.portlet.PortletException; |
//import javax.portlet.PortletException;
|
||||||
import javax.portlet.ResourceRequest; |
//import javax.portlet.ResourceRequest;
|
||||||
import javax.portlet.ResourceResponse; |
//import javax.portlet.ResourceResponse;
|
||||||
import javax.servlet.http.HttpServletRequest; |
//import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse; |
//import javax.servlet.http.HttpServletResponse;
|
||||||
|
//
|
||||||
public class TemplateTesterPortlet extends MVCPortlet { |
//public class TemplateTesterPortlet extends MVCPortlet {
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void serveResource(ResourceRequest resourceRequest, |
// public void serveResource(ResourceRequest resourceRequest,
|
||||||
ResourceResponse resourceResponse) throws IOException, |
// ResourceResponse resourceResponse) throws IOException,
|
||||||
PortletException { |
// PortletException {
|
||||||
|
//
|
||||||
String resourceID = GetterUtil.getString(resourceRequest |
// String resourceID = GetterUtil.getString(resourceRequest
|
||||||
.getResourceID()); |
// .getResourceID());
|
||||||
|
//
|
||||||
if (resourceID.equals("templateTester")) { |
// if (resourceID.equals("templateTester")) {
|
||||||
_processTemplate(resourceRequest, resourceResponse); |
// _processTemplate(resourceRequest, resourceResponse);
|
||||||
} else { |
// } else {
|
||||||
super.serveResource(resourceRequest, resourceResponse); |
// super.serveResource(resourceRequest, resourceResponse);
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
private void _processTemplate(ResourceRequest resourceRequest, |
// private void _processTemplate(ResourceRequest resourceRequest,
|
||||||
ResourceResponse resourceResponse){ |
// ResourceResponse resourceResponse){
|
||||||
|
//
|
||||||
HttpServletRequest request = PortalUtil |
// HttpServletRequest request = PortalUtil
|
||||||
.getHttpServletRequest(resourceRequest); |
// .getHttpServletRequest(resourceRequest);
|
||||||
HttpServletResponse response = PortalUtil |
// HttpServletResponse response = PortalUtil
|
||||||
.getHttpServletResponse(resourceResponse); |
// .getHttpServletResponse(resourceResponse);
|
||||||
|
//
|
||||||
try { |
// try {
|
||||||
|
//
|
||||||
ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest |
// ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest
|
||||||
.getAttribute(WebKeys.THEME_DISPLAY); |
// .getAttribute(WebKeys.THEME_DISPLAY);
|
||||||
|
//
|
||||||
byte[] bytes = new byte[0]; |
// byte[] bytes = new byte[0];
|
||||||
|
//
|
||||||
UploadPortletRequest uploadPortletRequest = PortalUtil |
// UploadPortletRequest uploadPortletRequest = PortalUtil
|
||||||
.getUploadPortletRequest(resourceRequest); |
// .getUploadPortletRequest(resourceRequest);
|
||||||
|
//
|
||||||
ReportAvvisoBean bean = ReportAvvisoBeanBuilder.build(avviso, parameters); |
// ReportAvvisoBean bean = ReportAvvisoBeanBuilder.build(avviso, parameters);
|
||||||
String resourcePath = getClass().getName().replaceAll("\\w+\\.", "../") |
// String resourcePath = getClass().getName().replaceAll("\\w+\\.", "../")
|
||||||
.replace(getClass().getSimpleName(), ReportConstants.PATH_LOGO_REGIONE); |
// .replace(getClass().getSimpleName(), ReportConstants.PATH_LOGO_REGIONE);
|
||||||
parameters.put(ReportConstants.LOGO_REGIONE, getClass().getResource(resourcePath).getPath()); |
// parameters.put(ReportConstants.LOGO_REGIONE, getClass().getResource(resourcePath).getPath());
|
||||||
ReportDto reportDto = new ReportDto(); |
// ReportDto reportDto = new ReportDto();
|
||||||
reportDto.setFileEntryIds(new long[] { fileEntryIdTemplate }); |
// reportDto.setFileEntryIds(new long[] { fileEntryIdTemplate });
|
||||||
reportDto.setFolderId(folderId); |
// reportDto.setFolderId(folderId);
|
||||||
reportDto.setFileName(fileName); |
// reportDto.setFileName(fileName);
|
||||||
reportDto.setParameters(parameters); |
// reportDto.setParameters(parameters);
|
||||||
reportDto.setShowNumberOfPage(true); |
// reportDto.setShowNumberOfPage(true);
|
||||||
reportDto.setType(ReportConstants.ReportType.JRXML_TO_PDF.toString()); |
// reportDto.setType(ReportConstants.ReportType.JRXML_TO_PDF.toString());
|
||||||
ReportResultDto result = ReportUtil.generateReport(companyId, userId, reportDto, bean); |
// ReportResultDto result = ReportUtil.generateReport(companyId, userId, reportDto, bean);
|
||||||
|
//
|
||||||
String parametersJSON = ParamUtil.getString( |
// String parametersJSON = ParamUtil.getString(
|
||||||
uploadPortletRequest, "parametersJSON"); |
// uploadPortletRequest, "parametersJSON");
|
||||||
|
//
|
||||||
HashMap<String, Object> params = new HashMap<String, Object>(); |
// HashMap<String, Object> params = new HashMap<String, Object>();
|
||||||
if (Validator.isNotNull(parametersJSON)) { |
// if (Validator.isNotNull(parametersJSON)) {
|
||||||
params = (HashMap<String, Object>) JSONFactoryUtil |
// params = (HashMap<String, Object>) JSONFactoryUtil
|
||||||
.looseDeserialize(parametersJSON); |
// .looseDeserialize(parametersJSON);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
String objectJSON = ParamUtil.getString(uploadPortletRequest, |
// String objectJSON = ParamUtil.getString(uploadPortletRequest,
|
||||||
"objectJSON"); |
// "objectJSON");
|
||||||
|
//
|
||||||
String fileNameTemplate = uploadPortletRequest |
// String fileNameTemplate = uploadPortletRequest
|
||||||
.getFileName("fileTemplate"); |
// .getFileName("fileTemplate");
|
||||||
|
//
|
||||||
ReportInterface reportInterface = null; |
// ReportInterface reportInterface = null;
|
||||||
|
//
|
||||||
if (Validator.isNotNull(objectJSON)) { |
// if (Validator.isNotNull(objectJSON)) {
|
||||||
|
//
|
||||||
JSONObject jsonObject = JSONFactoryUtil |
// JSONObject jsonObject = JSONFactoryUtil
|
||||||
.createJSONObject(objectJSON); |
// .createJSONObject(objectJSON);
|
||||||
|
//
|
||||||
ClassPool pool = ClassPool.getDefault(); |
// ClassPool pool = ClassPool.getDefault();
|
||||||
|
//
|
||||||
Class<?> clazz = makeClass(pool, jsonObject); |
// Class<?> clazz = makeClass(pool, jsonObject);
|
||||||
Object dataSource = clazz.newInstance(); |
// Object dataSource = clazz.newInstance();
|
||||||
|
//
|
||||||
reportInterface = new BeanReport(dataSource); |
// reportInterface = new BeanReport(dataSource);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
if (Validator.isNotNull(fileNameTemplate)) { |
// if (Validator.isNotNull(fileNameTemplate)) {
|
||||||
|
//
|
||||||
InputStream inputStream = null; |
// InputStream inputStream = null;
|
||||||
try { |
// try {
|
||||||
inputStream = uploadPortletRequest |
// inputStream = uploadPortletRequest
|
||||||
.getFileAsStream("fileTemplate"); |
// .getFileAsStream("fileTemplate");
|
||||||
|
//
|
||||||
JasperPdfProvider pdfProvider = new JasperPdfProvider(); |
// JasperPdfProvider pdfProvider = new JasperPdfProvider();
|
||||||
pdfProvider.doReport(inputStream, params, |
// pdfProvider.doReport(inputStream, params,
|
||||||
reportInterface); |
// reportInterface);
|
||||||
|
//
|
||||||
bytes = pdfProvider.getBytes(); |
// bytes = pdfProvider.getBytes();
|
||||||
} finally { |
// } finally {
|
||||||
StreamUtil.cleanUp(inputStream); |
// StreamUtil.cleanUp(inputStream);
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
ServletResponseUtil.sendFile(request, response, "test.pdf", bytes, |
// ServletResponseUtil.sendFile(request, response, "test.pdf", bytes,
|
||||||
ContentTypes.APPLICATION_PDF); |
// ContentTypes.APPLICATION_PDF);
|
||||||
|
//
|
||||||
} catch (Exception e) { |
// } catch (Exception e) {
|
||||||
_log.error(e, e); |
// _log.error(e, e);
|
||||||
|
//
|
||||||
ServletResponseUtil.sendFile(request, response, "test.html", e |
// ServletResponseUtil.sendFile(request, response, "test.html", e
|
||||||
.toString().getBytes(StringPool.UTF8), |
// .toString().getBytes(StringPool.UTF8),
|
||||||
ContentTypes.TEXT_HTML_UTF8); |
// ContentTypes.TEXT_HTML_UTF8);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
} |
// }
|
||||||
|
//
|
||||||
private final static Log _log = LogFactoryUtil.getLog(TestPdf.class); |
// private final static Log _log = LogFactoryUtil.getLog(TestPdf.class);
|
||||||
} |
//}
|
||||||
|
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
File binario non mostrato.
Caricamento…
Reference in new issue