Sfoglia il codice sorgente

Miglioramenti a sostituzione documenti

Salvatore La Manna 4 anni fa
parent
commit
812f66324a
  1. 487
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/AllegatiUtil.java
  2. 343
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/portlet/SismicaAdministrationPortlet.java
  3. 11
      liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/html/sismica_administration/view.jsp
  4. 1321
      liferay-plugins-sdk-6.2/portlets/portos-fe-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/fe/portlet/SoggettiPraticaPortlet.java

487
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/mwg/sismica/bo/util/AllegatiUtil.java

@ -0,0 +1,487 @@
package it.mwg.sismica.bo.util;
import it.tref.liferay.portos.bo.model.Collaudo;
import it.tref.liferay.portos.bo.model.Delega;
import it.tref.liferay.portos.bo.model.DettPratica;
import it.tref.liferay.portos.bo.model.DocPratica;
import it.tref.liferay.portos.bo.model.FineLavori;
import it.tref.liferay.portos.bo.model.IntPratica;
import it.tref.liferay.portos.bo.model.Pagamento;
import it.tref.liferay.portos.bo.model.Soggetto;
import it.tref.liferay.portos.bo.service.ConfigurazioneLocalServiceUtil;
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.DocPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.PagamentoLocalServiceUtil;
import it.tref.liferay.portos.bo.service.SoggettoLocalServiceUtil;
import it.tref.liferay.portos.bo.service.SoggettoServiceUtil;
import it.tref.liferay.portos.bo.shared.bean.FirmeBean;
import it.tref.liferay.portos.bo.shared.bean.FirmeDetail;
import it.tref.liferay.portos.bo.shared.util.ConfigurazioneConstants;
import it.tref.liferay.portos.bo.shared.util.DocumentiPraticaUtil;
import it.tref.liferay.portos.bo.shared.util.FirmeUtil;
import it.tref.liferay.portos.bo.shared.util.TipoSoggettoUtil;
import it.tref.liferay.portos.bo.util.PraticaUtil;
import it.tref.liferay.portos.bo.util.ValidazionePraticaUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.apache.commons.codec.digest.DigestUtils;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.MimeTypesUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.User;
import com.liferay.portal.security.permission.ActionKeys;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.documentlibrary.NoSuchFolderException;
import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
public class AllegatiUtil {
private final static Log _log = LogFactoryUtil.getLog(AllegatiUtil.class);
public static void sostituisciDL(ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
List<String> esito = new ArrayList<>();
String className = ParamUtil.getString(actionRequest, "className");
actionResponse.setRenderParameter("className", className);
long classPK = ParamUtil.getLong(actionRequest, "classPK");
actionResponse.setRenderParameter("classPK", String.valueOf(classPK));
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
String sourceFileName = uploadRequest.getFileName("file");
File file = uploadRequest.getFile("file");
byte[] bytes = FileUtil.getBytes(file);
if (Validator.isNull(bytes)) {
esito.add("Nessun file allegato");
} else {
Date date = new Date();
if (className.equals(DocPratica.class.getName())) {
esito.addAll(sostituisciAllegatoDocPratica(classPK, sourceFileName, bytes, date));
} else if (className.equals(Pagamento.class.getName())) {
esito.addAll(sostituisciAllegatoPagamento(classPK, sourceFileName, bytes));
} else if (className.equals(Soggetto.class.getName())) {
esito.addAll(sostituisciAllegatoSoggetto(classPK, sourceFileName, bytes, date));
} else {
esito.add("Operazione " + className + " non implementata");
}
}
actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
}
private static List<String> sostituisciAllegatoSoggetto(long soggettoId, String sourceFileName,
byte[] bytes, Date date) throws PortalException, SystemException, IOException {
List<String> esito = new ArrayList<>();
Soggetto soggetto = null;
try {
soggetto = SoggettoLocalServiceUtil.getSoggetto(soggettoId);
} catch (PortalException e) {
esito.add("Errore: " + e.getMessage());
return esito;
}
long docPraticaId = soggetto.getFileVariazioneId();
if (Validator.isNull(docPraticaId)) {
esito.add("Il soggetto " + soggettoId + " non ha un'allegato da sostituire");
return esito;
}
long companyId = soggetto.getCompanyId();
long userId = soggetto.getUserId();
DocPratica docPratica = null;
try {
docPratica = DocPraticaLocalServiceUtil.getDocPratica(docPraticaId);
} catch (PortalException e) {
}
if (Validator.isNull(docPratica)) {
esito.add("Ricreo docPratica " + docPraticaId);
docPratica = DocPraticaLocalServiceUtil.createDocPratica(docPraticaId);
User user = UserLocalServiceUtil.getUser(userId);
docPratica.setClassName(Soggetto.class.getName());
docPratica.setClassPk(soggettoId);
docPratica.setCompanyId(companyId);
docPratica.setCreateDate(date);
docPratica.setDescLong(sourceFileName);
docPratica.setGroupId(soggetto.getGroupId());
docPratica.setIntPraticaId(soggetto.getIntPraticaId());
docPratica.setJsonFirmatari(FirmeUtil.serialize(new FirmeBean()));
docPratica.setModifiedDate(date);
docPratica.setTipologia(DocumentiPraticaUtil.TIPOLOGIA_ALLEGATO_VARIAZIONE_SOGGETTO);
docPratica.setUserId(userId);
docPratica.setUserName(user.getFullName());
docPratica.setVersion("0");
}
DocPraticaLocalServiceUtil.updateDocPratica(docPratica);
esito.addAll(sostituisciAllegatoDocPratica(docPraticaId, sourceFileName, bytes, date));
return esito;
}
private static List<String> sostituisciAllegatoDocPratica(long docPraticaId, String sourceFileName,
byte[] bytes, Date date) throws SystemException, PortalException, IOException {
List<String> esito = new ArrayList<>();
DocPratica docPratica = DocPraticaLocalServiceUtil.getDocPratica(docPraticaId);
long companyId = docPratica.getCompanyId();
long userId = docPratica.getUserId();
ServiceContext serviceContext = getServiceContext(companyId, docPratica.getGroupId(), userId);
long dettPraticaId = getDettPraticaId(docPratica.getIntPraticaId());
Folder folder = getFolder(PraticaUtil.getFolderName(dettPraticaId), serviceContext);
String title = getTitle(docPratica, sourceFileName, date);
FileEntry fileEntry = addOrUpdateFileEntry(docPratica.getDlFileEntryId(), folder, userId,
sourceFileName, title, sourceFileName, bytes, serviceContext);
docPratica.setDlFileEntryId(fileEntry.getFileEntryId());
String sha256 = DigestUtils.sha256Hex(bytes);
docPratica.setSha256(sha256);
// Sostituzione delle firme digitali con quelle presenti nel file
FirmeBean firmeBean = FirmeUtil.deserialize(docPratica.getJsonFirmatari());
Set<String> firmeFile = new HashSet<>();
firmeFile.addAll(ValidazionePraticaUtil.gatherSignatures(sourceFileName, bytes, companyId, null));
List<FirmeDetail> firmeDigitali = new ArrayList<>();
for (String firmaFile : firmeFile) {
firmeDigitali.add(new FirmeDetail(firmaFile.toLowerCase(), date));
esito.add("Trovata firma di " + firmaFile);
}
firmeBean.setFirmeDigitali(firmeDigitali);
docPratica.setJsonFirmatari(FirmeUtil.serialize(firmeBean));
DocPraticaLocalServiceUtil.updateDocPratica(docPratica);
esito.add("DocPratica " + docPraticaId + ": aggiornato fileEntry " + fileEntry.getFileEntryId()
+ ", sha256=" + sha256);
return esito;
}
private static List<String> sostituisciAllegatoPagamento(long pagamentoId, String sourceFileName,
byte[] bytes) throws SystemException, PortalException, IOException {
List<String> esito = new ArrayList<>();
Pagamento pagamento = PagamentoLocalServiceUtil.getPagamento(pagamentoId);
Date now = new Date();
long userId = pagamento.getUserId();
ServiceContext serviceContext = getServiceContext(pagamento.getCompanyId(), pagamento.getGroupId(),
userId);
long dettPraticaId = getDettPraticaId(pagamento.getIntPraticaId());
Folder folder = getFolder(PraticaUtil.getFolderName(dettPraticaId), serviceContext);
String title = now.getTime() + "_pagamento_manuale_" + pagamento.getPagamentoId()
+ StringPool.UNDERLINE + sourceFileName;
FileEntry fileEntry = addOrUpdateFileEntry(pagamento.getFileEntryId(), folder, userId,
sourceFileName, title, StringPool.BLANK, bytes, serviceContext);
pagamento.setFileEntryId(fileEntry.getFileEntryId());
PagamentoLocalServiceUtil.updatePagamento(pagamento);
esito.add("Pagamento " + pagamentoId + ": aggiunto file " + fileEntry.getFileEntryId()
+ StringPool.BLANK + title);
return esito;
}
private static long getDettPraticaId(long intPraticaId) throws SystemException {
DettPratica dettPratica = DettPraticaLocalServiceUtil.getLastEditableByIntPratica(intPraticaId);
if (Validator.isNull(dettPratica)) {
List<DettPratica> list = DettPraticaLocalServiceUtil.findByIntPraticaId(intPraticaId);
dettPratica = list.get(list.size() - 1);
}
return dettPratica.getPrimaryKey();
}
private static ServiceContext getServiceContext(long companyId, long groupId, long userId) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(groupId);
serviceContext.setUserId(userId);
serviceContext.setGroupPermissions(new String[] { ActionKeys.VIEW });
return serviceContext;
}
private static Folder getFolder(String folderName, ServiceContext serviceContext) throws PortalException,
SystemException {
Folder folder = null;
long parentFolderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(
serviceContext.getCompanyId(), ConfigurazioneConstants.ATTACHMENT_FOLDER_ID);
Folder parentFolder = DLAppLocalServiceUtil.getFolder(parentFolderId);
long repositoryId = parentFolder.getRepositoryId();
try {
folder = DLAppLocalServiceUtil.getFolder(repositoryId, parentFolderId, folderName);
} catch (NoSuchFolderException e) {
folder = DLAppLocalServiceUtil.addFolder(serviceContext.getUserId(), repositoryId,
parentFolderId, folderName, StringPool.BLANK, serviceContext);
}
return folder;
}
private static String getTitle(DocPratica docPratica, String sourceFileName, Date date) {
String className = DocPratica.class.getName();
String tipologia = docPratica.getTipologia();
if (IntPratica.class.getName().equals(className)) {
if (tipologia.equalsIgnoreCase(DocumentiPraticaUtil.TIPOLOGIA_ALLEGATO_ANNULLAMENTO_FASCICOLO)) {
sourceFileName = date.getTime() + "_annullamento_" + docPratica.getIntPraticaId()
+ StringPool.UNDERLINE + sourceFileName;
}
} else {
sourceFileName = tipologia + StringPool.UNDERLINE + sourceFileName;
}
return sourceFileName;
}
private static FileEntry addOrUpdateFileEntry(long fileEntryId, Folder folder, long userId,
String sourceFileName, String title, String description, byte[] bytes,
ServiceContext serviceContext) throws SystemException, PortalException {
String mimeType = MimeTypesUtil.getContentType(sourceFileName);
FileEntry fileEntry = null;
try {
fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId);
fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),
sourceFileName, mimeType, title, description, StringPool.BLANK, false, bytes,
serviceContext);
} catch (PortalException e) {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, folder.getRepositoryId(),
folder.getFolderId(), sourceFileName, mimeType, title, description, StringPool.BLANK,
bytes, serviceContext);
}
return fileEntry;
}
public void sostituisciDL2(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
long userId = 0;
String title = null;
String description = null;
String mimeType = null;
String changeLog = StringPool.BLANK;
FileEntry fileEntry = null;
Date now = new Date();
long companyId = 0;
long groupId = 0;
long defaultFolderId = 0;
Folder defaultFolder = null;
String folderName = null;
byte[] bytes = null;
long folderId = 0;
long repositoryId = 0;
ServiceContext serviceContext = new ServiceContext();
String className = ParamUtil.getString(actionRequest, "className");
Long idOggetto = ParamUtil.getLong(actionRequest, "classPK");
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
String sourceFileName = uploadRequest.getFileName("file");
File file = uploadRequest.getFile("file");
Folder folder = null;
switch (className) {
case "it.tref.liferay.portos.bo.model.DocPratica":
DocPratica pratica = DocPraticaLocalServiceUtil.getDocPratica(idOggetto);
userId = pratica.getUserId();
companyId = pratica.getCompanyId();
groupId = pratica.getGroupId();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(groupId);
serviceContext.setUserId(userId);
defaultFolderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId,
ConfigurazioneConstants.ATTACHMENT_FOLDER_ID);
defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId);
folderName = PraticaUtil.getFolderName(pratica.getClassPk());
folderId = defaultFolder.getFolderId();
repositoryId = defaultFolder.getRepositoryId();
try {
folder = DLAppLocalServiceUtil.getFolder(repositoryId, folderId, folderName);
} catch (NoSuchFolderException e) {
folder = DLAppLocalServiceUtil.addFolder(userId, repositoryId, folderId, folderName,
StringPool.BLANK, serviceContext);
}
bytes = FileUtil.getBytes(file);
title = pratica.getTipologia() + StringPool.UNDERLINE + sourceFileName;
description = sourceFileName;
mimeType = MimeTypesUtil.getContentType(sourceFileName);
try {
fileEntry = DLAppLocalServiceUtil.getFileEntry(pratica.getDlFileEntryId());
fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),
now.getTime() + "_" + sourceFileName, mimeType, title, description, changeLog, false,
bytes, serviceContext);
} catch (PortalException e) {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, folder.getRepositoryId(),
folder.getFolderId(), now.getTime() + "_" + sourceFileName, mimeType, title,
description, changeLog, bytes, serviceContext);
}
pratica.setDlFileEntryId(fileEntry.getFileEntryId());
pratica.setSha256(DigestUtils.sha256Hex(bytes));
DocPraticaLocalServiceUtil.updateDocPratica(pratica);
break;
case "it.tref.liferay.portos.bo.model.Pagamento":
Pagamento pagamento = PagamentoLocalServiceUtil.getPagamento(idOggetto);
userId = pagamento.getUserId();
companyId = pagamento.getCompanyId();
groupId = pagamento.getGroupId();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(groupId);
serviceContext.setUserId(userId);
defaultFolderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId,
ConfigurazioneConstants.ATTACHMENT_FOLDER_ID);
defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId);
folderName = PraticaUtil.getFolderName(pagamento.getClassPk());
folderId = defaultFolder.getFolderId();
repositoryId = defaultFolder.getRepositoryId();
try {
folder = DLAppLocalServiceUtil.getFolder(repositoryId, folderId, folderName);
} catch (NoSuchFolderException e) {
folder = DLAppLocalServiceUtil.addFolder(userId, repositoryId, folderId, folderName,
StringPool.BLANK, serviceContext);
}
bytes = FileUtil.getBytes(file);
title = now.getTime() + StringPool.UNDERLINE + "pagamento_manuale" + StringPool.UNDERLINE
+ pagamento.getPagamentoId() + StringPool.UNDERLINE + sourceFileName;
description = StringPool.BLANK;
mimeType = MimeTypesUtil.getContentType(sourceFileName);
try {
fileEntry = DLAppLocalServiceUtil.getFileEntry(pagamento.getFileEntryId());
fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),
now.getTime() + "_" + sourceFileName, mimeType, title, description, changeLog, false,
bytes, serviceContext);
} catch (PortalException e) {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, folder.getRepositoryId(),
folder.getFolderId(), now.getTime() + "_" + sourceFileName, mimeType, title,
description, changeLog, bytes, serviceContext);
}
pagamento.setFileEntryId(fileEntry.getFileEntryId());
PagamentoLocalServiceUtil.updatePagamento(pagamento);
break;
case "var_soggetti_no_docpratica":
Soggetto soggetto = SoggettoLocalServiceUtil.getSoggetto(idOggetto);
DettPratica dettPratica = DettPraticaLocalServiceUtil.getDettPratica(soggetto.getDettPraticaId());
long intPraticaId = dettPratica.getIntPraticaId();
serviceContext = ServiceContextFactory.getInstance(Soggetto.class.getName(), actionRequest);
byte[] content = null;
String jsonFirmatari = "";
boolean isSigned = false;
FirmeBean firmeBean = new FirmeBean();
User user = UserLocalServiceUtil.getUser(serviceContext.getUserId());
if (!firmeBean.allSignatures().contains(user.getScreenName())) {
jsonFirmatari = FirmeUtil.addFirma(firmeBean, user.getScreenName());
} else {
jsonFirmatari = FirmeUtil.serialize(firmeBean);
}
if (file.exists()) {
if (Validator.isNotNull(sourceFileName) && file != null) {
// validazione: solo alcune estensioni
String ext = FileUtil.getExtension(sourceFileName);
if (!ext.equalsIgnoreCase("p7m") && !ext.equalsIgnoreCase("pdf")) {
SessionErrors.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.ext.valid");
}
// lunghezza fissata a 200
if (sourceFileName.length() > 200) {
SessionErrors.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.length.valid");
}
} else if (!TipoSoggettoUtil.COMMITTENTE.equalsIgnoreCase(soggetto.getTipologiaSoggetto())) {
SessionErrors.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.is.request");
}
if (!SessionErrors.isEmpty(actionRequest)) {
throw new SystemException("error.geniocivilefe.variazione-soggetto.allegato");
} else if (file != null) {
content = FileUtil.getBytes(file);
}
}
if (TipoSoggettoUtil.COMMITTENTE.equals(soggetto.getTipologiaSoggetto())) {
String[] titolare = new String[] { dettPratica.getCodiceFiscaleDelegatoCommittente() };
isSigned = ValidazionePraticaUtil.isAllegatoSignedBySubjects(sourceFileName, content,
serviceContext.getCompanyId(), Arrays.asList(titolare), jsonFirmatari);
} else {
List<Soggetto> soggettiValidi = SoggettoServiceUtil.getValidTmpByIntPratica(intPraticaId);
List<String> codiciFiscaliValidi = new ArrayList<String>();
for (Soggetto valido : soggettiValidi) {
if (!codiciFiscaliValidi.contains(valido.getCodiceFiscale())
&& !valido.getCodiceFiscale().equalsIgnoreCase(soggetto.getCodiceFiscale())) {
codiciFiscaliValidi.add(valido.getCodiceFiscale());
}
}
isSigned = ValidazionePraticaUtil.isAllegatoSignedBySubjectsAndPerson(sourceFileName,
content, serviceContext.getCompanyId(), codiciFiscaliValidi,
soggetto.getCodiceFiscale(), jsonFirmatari);
}
if (isSigned) {
userId = PortalUtil.getUserId(actionRequest);
try {
SoggettoServiceUtil.allegaFileModifica(soggetto.getSoggettoId(), userId, intPraticaId,
content, sourceFileName, jsonFirmatari, serviceContext);
} catch (PortalException e) {
_log.error(e, e);
throw e;
}
}
break;
default:
break;
}
}
}

343
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/bo/portlet/SismicaAdministrationPortlet.java

@ -1,33 +1,12 @@
package it.tref.liferay.portos.bo.portlet; package it.tref.liferay.portos.bo.portlet;
import it.mwg.sismica.bo.util.PuliziaDatabase; import it.mwg.sismica.bo.util.AllegatiUtil;
import it.mwg.sismica.bo.util.SismicaUtil; import it.mwg.sismica.bo.util.SismicaUtil;
import it.mwg.sismica.bo.util.SorteggioPraticaUtil; import it.mwg.sismica.bo.util.SorteggioPraticaUtil;
import it.tref.liferay.portos.bo.model.ControlloPratica;
import it.tref.liferay.portos.bo.model.DettPratica;
import it.tref.liferay.portos.bo.model.DocPratica;
import it.tref.liferay.portos.bo.model.Pagamento;
import it.tref.liferay.portos.bo.model.Soggetto;
import it.tref.liferay.portos.bo.service.ConfigurazioneLocalServiceUtil;
import it.tref.liferay.portos.bo.service.ConfigurazioneServiceUtil; import it.tref.liferay.portos.bo.service.ConfigurazioneServiceUtil;
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.DocPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil;
import it.tref.liferay.portos.bo.service.PagamentoLocalServiceUtil;
import it.tref.liferay.portos.bo.service.SoggettoLocalServiceUtil;
import it.tref.liferay.portos.bo.service.SoggettoServiceUtil;
import it.tref.liferay.portos.bo.shared.bean.FirmeBean;
import it.tref.liferay.portos.bo.shared.util.ConfigurazioneConstants;
import it.tref.liferay.portos.bo.shared.util.FirmeUtil;
import it.tref.liferay.portos.bo.shared.util.TipoSoggettoUtil;
import it.tref.liferay.portos.bo.util.PraticaUtil;
import it.tref.liferay.portos.bo.util.ValidazionePraticaUtil;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -35,31 +14,16 @@ import java.util.Map;
import javax.portlet.ActionRequest; import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse; import javax.portlet.ActionResponse;
import org.apache.commons.codec.digest.DigestUtils;
import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.exception.SystemException;
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.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.MimeTypesUtil;
import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.FileUtil;
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.model.User;
import com.liferay.portal.service.ServiceContext; import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory; import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.documentlibrary.NoSuchFolderException;
import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet; import com.liferay.util.bridges.mvc.MVCPortlet;
/** /**
@ -67,11 +31,10 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
*/ */
public class SismicaAdministrationPortlet extends MVCPortlet { public class SismicaAdministrationPortlet extends MVCPortlet {
private static final Log _log = LogFactoryUtil private static final Log _log = LogFactoryUtil.getLog(SismicaAdministrationPortlet.class);
.getLog(SismicaAdministrationPortlet.class);
public void mostraConfigurazione(ActionRequest actionRequest, public void mostraConfigurazione(ActionRequest actionRequest, ActionResponse actionResponse)
ActionResponse actionResponse) throws SystemException { throws SystemException {
List<String> esito = new ArrayList<String>(); List<String> esito = new ArrayList<String>();
esito.add("<h3>Env</h3>"); esito.add("<h3>Env</h3>");
@ -80,313 +43,75 @@ public class SismicaAdministrationPortlet extends MVCPortlet {
} }
esito.add("<h3>Properties</h3>"); esito.add("<h3>Properties</h3>");
for (Map.Entry<Object, Object> entry : System.getProperties() for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
.entrySet()) {
esito.add(entry.getKey() + "=" + entry.getValue()); esito.add(entry.getKey() + "=" + entry.getValue());
} }
actionResponse.setRenderParameter("esito", actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
esito.toArray(new String[esito.size()]));
} }
public void generaDocumenti(ActionRequest actionRequest, public void generaDocumenti(ActionRequest actionRequest, ActionResponse actionResponse) {
ActionResponse actionResponse) { ThemeDisplay td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ThemeDisplay td = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
List<String> esito = new ArrayList<>(); List<String> esito = new ArrayList<>();
try { try {
esito = SismicaUtil.generaDocumenti(td.getCompanyId()); esito = SismicaUtil.generaDocumenti(td.getCompanyId());
} catch (PortalException | SystemException e) { } catch (PortalException | SystemException e) {
esito.add("Errore durante l'invio " + e.getMessage()); esito.add("Errore durante l'invio " + e.getMessage());
} }
actionResponse.setRenderParameter("esito", actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
esito.toArray(new String[esito.size()]));
} }
<<<<<<< HEAD
public void sostituisciDL(ActionRequest actionRequest, ActionResponse actionResponse)
throws SystemException, PortalException, IOException {
=======
public void sostituisciDL(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { public void sostituisciDL(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
SismicaUtil.sostituisciDL(actionRequest, actionResponse); AllegatiUtil.sostituisciDL(actionRequest, actionResponse);
>>>>>>> 096838dd46c4f289d1b3f53893c6727c14619a1e
long userId = 0;
String title = null;
String description = null;
String mimeType = null;
String changeLog = StringPool.BLANK;
FileEntry fileEntry = null;
Date now = new Date();
long companyId = 0;
long groupId = 0;
long defaultFolderId = 0;
Folder defaultFolder = null;
String folderName = null;
byte[] bytes = null;
long folderId = 0;
long repositoryId = 0;
ServiceContext serviceContext = new ServiceContext();
String className = ParamUtil.getString(actionRequest, "className");
Long idOggetto = ParamUtil.getLong(actionRequest, "classPK");
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
String sourceFileName = uploadRequest.getFileName("file");
File file = uploadRequest.getFile("file");
Folder folder = null;
switch(className){
case "it.tref.liferay.portos.bo.model.DocPratica":
DocPratica pratica = DocPraticaLocalServiceUtil.getDocPratica(idOggetto);
userId = pratica.getUserId();
companyId = pratica.getCompanyId();
groupId = pratica.getGroupId();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(groupId);
serviceContext.setUserId(userId);
defaultFolderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId, ConfigurazioneConstants.ATTACHMENT_FOLDER_ID);
defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId);
folderName = PraticaUtil.getFolderName(pratica.getClassPk());
folderId = defaultFolder.getFolderId();
repositoryId = defaultFolder.getRepositoryId();
try {
folder = DLAppLocalServiceUtil.getFolder(repositoryId, folderId, folderName);
} catch (NoSuchFolderException e) {
folder = DLAppLocalServiceUtil.addFolder(userId, repositoryId, folderId, folderName,
StringPool.BLANK, serviceContext);
}
bytes = FileUtil.getBytes(file);
title = pratica.getTipologia() + StringPool.UNDERLINE + sourceFileName;
description = sourceFileName;
mimeType = MimeTypesUtil.getContentType(sourceFileName);
try {
fileEntry = DLAppLocalServiceUtil.getFileEntry(pratica.getDlFileEntryId());
fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),
now.getTime() + "_" + sourceFileName, mimeType, title, description, changeLog, false, bytes,
serviceContext);
} catch (PortalException e) {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, folder.getRepositoryId(), folder.getFolderId(), now.getTime() + "_" + sourceFileName,
mimeType, title, description, changeLog, bytes, serviceContext);
}
pratica.setDlFileEntryId(fileEntry.getFileEntryId());
pratica.setSha256(DigestUtils.sha256Hex(bytes));
DocPraticaLocalServiceUtil.updateDocPratica(pratica);
break;
case "it.tref.liferay.portos.bo.model.Pagamento":
Pagamento pagamento = PagamentoLocalServiceUtil.getPagamento(idOggetto);
userId = pagamento.getUserId();
companyId = pagamento.getCompanyId();
groupId = pagamento.getGroupId();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(groupId);
serviceContext.setUserId(userId);
defaultFolderId = ConfigurazioneLocalServiceUtil.findByC_ChiaveLong(companyId, ConfigurazioneConstants.ATTACHMENT_FOLDER_ID);
defaultFolder = DLAppLocalServiceUtil.getFolder(defaultFolderId);
folderName = PraticaUtil.getFolderName(pagamento.getClassPk());
folderId = defaultFolder.getFolderId();
repositoryId = defaultFolder.getRepositoryId();
try {
folder = DLAppLocalServiceUtil.getFolder(repositoryId, folderId, folderName);
} catch (NoSuchFolderException e) {
folder = DLAppLocalServiceUtil.addFolder(userId, repositoryId, folderId, folderName,
StringPool.BLANK, serviceContext);
}
bytes = FileUtil.getBytes(file);
title = now.getTime() + StringPool.UNDERLINE + "pagamento_manuale" + StringPool.UNDERLINE
+ pagamento.getPagamentoId() + StringPool.UNDERLINE + sourceFileName;
description = StringPool.BLANK;
mimeType = MimeTypesUtil.getContentType(sourceFileName);
try {
fileEntry = DLAppLocalServiceUtil.getFileEntry(pagamento.getFileEntryId());
fileEntry = DLAppLocalServiceUtil.updateFileEntry(userId, fileEntry.getFileEntryId(),
now.getTime() + "_" + sourceFileName, mimeType, title, description, changeLog, false, bytes,
serviceContext);
} catch (PortalException e) {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, folder.getRepositoryId(), folder.getFolderId(), now.getTime() + "_" + sourceFileName,
mimeType, title, description, changeLog, bytes, serviceContext);
}
pagamento.setFileEntryId(fileEntry.getFileEntryId());
PagamentoLocalServiceUtil.updatePagamento(pagamento);
break;
case "var_soggetti_no_docpratica":
Soggetto soggetto = SoggettoLocalServiceUtil.getSoggetto(idOggetto);
DettPratica dettPratica = DettPraticaLocalServiceUtil.getDettPratica(soggetto.getDettPraticaId());
long intPraticaId = dettPratica.getIntPraticaId();
serviceContext = ServiceContextFactory.getInstance(Soggetto.class.getName(), actionRequest);
byte[] content = null;
String jsonFirmatari = "";
boolean isSigned = false;
FirmeBean firmeBean = new FirmeBean();
User user = UserLocalServiceUtil.getUser(serviceContext.getUserId());
if (!firmeBean.allSignatures().contains(user.getScreenName())) {
jsonFirmatari = FirmeUtil.addFirma(firmeBean, user.getScreenName());
} else {
jsonFirmatari = FirmeUtil.serialize(firmeBean);
}
if (file.exists()) {
if (Validator.isNotNull(sourceFileName) && file != null) {
// validazione: solo alcune estensioni
String ext = FileUtil.getExtension(sourceFileName);
if (!ext.equalsIgnoreCase("p7m")
&& !ext.equalsIgnoreCase("pdf")) {
SessionErrors
.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.ext.valid");
}
// lunghezza fissata a 200
if (sourceFileName.length() > 200) {
SessionErrors
.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.length.valid");
}
} else if (!TipoSoggettoUtil.COMMITTENTE
.equalsIgnoreCase(soggetto.getTipologiaSoggetto())) {
SessionErrors
.add(actionRequest,
"error.geniocivilefe.variazione-soggetto.allegato.is.request");
}
if (!SessionErrors.isEmpty(actionRequest)) {
throw new SystemException(
"error.geniocivilefe.variazione-soggetto.allegato");
} else if (file != null) {
content = FileUtil.getBytes(file);
}
}
if (TipoSoggettoUtil.COMMITTENTE.equals(soggetto
.getTipologiaSoggetto())) {
String[] titolare = new String[] { dettPratica
.getCodiceFiscaleDelegatoCommittente() };
isSigned = ValidazionePraticaUtil.isAllegatoSignedBySubjects(
sourceFileName, content, serviceContext.getCompanyId(),
Arrays.asList(titolare), jsonFirmatari);
} else {
List<Soggetto> soggettiValidi = SoggettoServiceUtil
.getValidTmpByIntPratica(intPraticaId);
List<String> codiciFiscaliValidi = new ArrayList<String>();
for (Soggetto valido : soggettiValidi) {
if (!codiciFiscaliValidi
.contains(valido.getCodiceFiscale())
&& !valido.getCodiceFiscale().equalsIgnoreCase(
soggetto.getCodiceFiscale())) {
codiciFiscaliValidi.add(valido.getCodiceFiscale());
}
}
isSigned = ValidazionePraticaUtil
.isAllegatoSignedBySubjectsAndPerson(sourceFileName,
content, serviceContext.getCompanyId(),
codiciFiscaliValidi,
soggetto.getCodiceFiscale(), jsonFirmatari);
}
if(isSigned){
userId = PortalUtil.getUserId(actionRequest);
try {
SoggettoServiceUtil.allegaFileModifica(soggetto.getSoggettoId(), userId, intPraticaId, content, sourceFileName, jsonFirmatari,
serviceContext);
} catch (PortalException e) {
_log.error(e, e);
throw e;
}
}
break;
default:
break;
}
} }
public void resetFirme(ActionRequest actionRequest, public void resetFirme(ActionRequest actionRequest, ActionResponse actionResponse) {
ActionResponse actionResponse) { ThemeDisplay td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ThemeDisplay td = (ThemeDisplay) actionRequest String numeroProgetto = ParamUtil.getString(actionRequest, "numeroProgetto");
.getAttribute(WebKeys.THEME_DISPLAY);
String numeroProgetto = ParamUtil.getString(actionRequest,
"numeroProgetto");
List<String> esito = new ArrayList<>(); List<String> esito = new ArrayList<>();
try { try {
esito = SismicaUtil.resetFirme(td.getCompanyId(), numeroProgetto); esito = SismicaUtil.resetFirme(td.getCompanyId(), numeroProgetto);
} catch (SystemException | PortalException e) { } catch (SystemException | PortalException e) {
esito.add("Errore durante l'invio " + e.getMessage()); esito.add("Errore durante l'invio " + e.getMessage());
} }
actionResponse.setRenderParameter("esito", actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
esito.toArray(new String[esito.size()]));
} }
public void reIndexFasciolo(ActionRequest actionRequest, public void reIndexFasciolo(ActionRequest actionRequest, ActionResponse actionResponse)
ActionResponse actionResponse) throws PortalException, throws PortalException, SystemException {
SystemException {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
.getAttribute(WebKeys.THEME_DISPLAY);
long intPraticaId = ParamUtil.getLong(actionRequest, "intPraticaId"); long intPraticaId = ParamUtil.getLong(actionRequest, "intPraticaId");
if (Validator.isNotNull(intPraticaId)) { if (Validator.isNotNull(intPraticaId)) {
IntPraticaLocalServiceUtil.reIndexFasciolo(intPraticaId, IntPraticaLocalServiceUtil.reIndexFasciolo(intPraticaId, themeDisplay.getCompanyId());
themeDisplay.getCompanyId());
} }
String numeroProgetto = ParamUtil.getString(actionRequest, String numeroProgetto = ParamUtil.getString(actionRequest, "numeroProgetto");
"numeroProgetto");
if (Validator.isNotNull(numeroProgetto)) { if (Validator.isNotNull(numeroProgetto)) {
IntPraticaLocalServiceUtil.reIndexFasciolo(numeroProgetto, IntPraticaLocalServiceUtil.reIndexFasciolo(numeroProgetto, themeDisplay.getCompanyId());
themeDisplay.getCompanyId());
} }
} }
public void reIndexFascicoli(ActionRequest actionRequest, public void reIndexFascicoli(ActionRequest actionRequest, ActionResponse actionResponse) {
ActionResponse actionResponse) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
List<String> esito = null; List<String> esito = null;
esito = SismicaUtil.reIndexFascicoli(themeDisplay.getCompanyId()); esito = SismicaUtil.reIndexFascicoli(themeDisplay.getCompanyId());
if (esito != null) if (esito != null)
actionResponse.setRenderParameter("esito", actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
esito.toArray(new String[esito.size()]));
} }
public void lanciaSorteggio(ActionRequest actionRequest, public void lanciaSorteggio(ActionRequest actionRequest, ActionResponse actionResponse) {
ActionResponse actionResponse) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
.getAttribute(WebKeys.THEME_DISPLAY);
List<String> esito = null; List<String> esito = null;
_log.info("Sorteggio lanciato manualmente"); _log.info("Sorteggio lanciato manualmente");
try { try {
esito = SorteggioPraticaUtil.sorteggio(themeDisplay.getCompanyId(), esito = SorteggioPraticaUtil.sorteggio(themeDisplay.getCompanyId(), new Date());
new Date());
} catch (PortalException | SystemException e) { } catch (PortalException | SystemException e) {
_log.error("error", e); _log.error("error", e);
} }
if (esito != null) if (esito != null)
actionResponse.setRenderParameter("esito", actionResponse.setRenderParameter("esito", esito.toArray(new String[esito.size()]));
esito.toArray(new String[esito.size()]));
} }
public void testInterno(ActionRequest actionRequest, ActionResponse actionResponse) public void testInterno(ActionRequest actionRequest, ActionResponse actionResponse)
@ -401,22 +126,18 @@ public class SismicaAdministrationPortlet extends MVCPortlet {
SismicaUtil.inviaAvviso(actionRequest, actionResponse); SismicaUtil.inviaAvviso(actionRequest, actionResponse);
} }
public void salvaDataProssimoSorteggio(ActionRequest actionRequest, public void salvaDataProssimoSorteggio(ActionRequest actionRequest, ActionResponse actionResponse)
ActionResponse actionResponse) throws PortalException, throws PortalException, SystemException {
SystemException {
ServiceContext serviceContext = ServiceContextFactory ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
.getInstance(actionRequest);
serviceContext.setScopeGroupId(-1L); serviceContext.setScopeGroupId(-1L);
serviceContext.setCompanyId(serviceContext.getCompanyId()); serviceContext.setCompanyId(serviceContext.getCompanyId());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dataProssimoSorteggio = ParamUtil.getDate(actionRequest, Date dataProssimoSorteggio = ParamUtil.getDate(actionRequest, "dataProssimoSorteggio", sdf);
"dataProssimoSorteggio", sdf);
ConfigurazioneServiceUtil.storeConfig( ConfigurazioneServiceUtil.storeConfig("conf.geniocivile.sorteggio.data.prossimo.sorteggio",
"conf.geniocivile.sorteggio.data.prossimo.sorteggio",
sdf.format(dataProssimoSorteggio), serviceContext); sdf.format(dataProssimoSorteggio), serviceContext);
} }

11
liferay-plugins-sdk-6.2/portlets/portos-bo-portlet/docroot/html/sismica_administration/view.jsp

@ -134,7 +134,7 @@ String dataProssimoSorteggio =
</div> </div>
<% <%
String tipoAvviso = ParamUtil.getString(renderRequest, "tipoAvviso", ""); String tipoAvviso = ParamUtil.getString(renderRequest, "tipoAvviso", "");
String numeroProgetto = ParamUtil.getString(renderRequest, "numeroProgetto", ""); String numeroProgetto = ParamUtil.getString(renderRequest, "numeroProgetto", "");
%> %>
<div class="span6"> <div class="span6">
<div style="font-weight: bold; font-size: 18px; margin-bottom: 10px;">Invia avviso</div> <div style="font-weight: bold; font-size: 18px; margin-bottom: 10px;">Invia avviso</div>
@ -162,6 +162,7 @@ String dataProssimoSorteggio =
<% <%
String oggetto = ParamUtil.getString(renderRequest, "tipoAvviso", ""); String oggetto = ParamUtil.getString(renderRequest, "tipoAvviso", "");
long classPK = ParamUtil.getLong(renderRequest, "classPK", 0);
%> %>
<liferay-portlet:actionURL name="sostituisciDL" var="sostituisciDLURL" /> <liferay-portlet:actionURL name="sostituisciDL" var="sostituisciDLURL" />
<div class="row-fluid" style="margin-top: 10px"> <div class="row-fluid" style="margin-top: 10px">
@ -176,13 +177,11 @@ String dataProssimoSorteggio =
value="<%=DocPratica.class.getName()%>"></aui:option> value="<%=DocPratica.class.getName()%>"></aui:option>
<aui:option label="Pagamento (allegato)" selected="<%=oggetto.equals(Pagamento.class.getName())%>" <aui:option label="Pagamento (allegato)" selected="<%=oggetto.equals(Pagamento.class.getName())%>"
value="<%=Pagamento.class.getName()%>"></aui:option> value="<%=Pagamento.class.getName()%>"></aui:option>
<aui:option label="Variazione Soggetti (no DocPratica)" selected="<%=oggetto.equals(Pagamento.class.getName())%>" <aui:option label="Soggetto (allegato)" selected="<%=oggetto.equals(Soggetto.class.getName())%>"
value="var_soggetti_no_docpratica"></aui:option> value="<%=Soggetto.class.getName()%>"></aui:option>
<aui:option label="Variazione Soggetti (solo FileEntry)" selected="<%=oggetto.equals(Pagamento.class.getName())%>"
value="var_soggetti_solo_fileentry"></aui:option>
</aui:select> </aui:select>
<aui:input type="file" name="file" label="File" /> <aui:input type="file" name="file" label="File" />
<aui:input name="classPK" label="Id oggetto"> <aui:input name="classPK" label="Id oggetto" value="<%=classPK > 0 ? classPK : \"\"%>">
<aui:validator name="number" /> <aui:validator name="number" />
</aui:input> </aui:input>
<aui:button type="submit" value="Sostituisci file in DL" /> <aui:button type="submit" value="Sostituisci file in DL" />

1321
liferay-plugins-sdk-6.2/portlets/portos-fe-portlet/docroot/WEB-INF/src/it/tref/liferay/portos/fe/portlet/SoggettiPraticaPortlet.java

File diff soppresso perché troppo grande Load Diff
Caricamento…
Annulla
Salva