|
|
|
@ -1,37 +1,54 @@
|
|
|
|
|
package it.mwg.sismica.bo.indexer; |
|
|
|
|
|
|
|
|
|
import it.mwg.sismica.bo.shared.util.AvvisoUtil; |
|
|
|
|
import it.mwg.sismica.bo.shared.util.IndexField; |
|
|
|
|
import it.tref.liferay.portos.bo.model.Comune; |
|
|
|
|
import it.tref.liferay.portos.bo.model.ControlloPratica; |
|
|
|
|
import it.tref.liferay.portos.bo.model.DettPratica; |
|
|
|
|
import it.tref.liferay.portos.bo.model.IntPratica; |
|
|
|
|
import it.tref.liferay.portos.bo.model.ParereGeologo; |
|
|
|
|
import it.tref.liferay.portos.bo.model.Soggetto; |
|
|
|
|
import it.tref.liferay.portos.bo.model.Territorio; |
|
|
|
|
import it.tref.liferay.portos.bo.service.AvvisoLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.service.ComuneLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.service.DettPraticaLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.service.ParereGeologoLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.service.SoggettoLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil; |
|
|
|
|
import it.tref.liferay.portos.bo.shared.util.StatoPraticaConstants; |
|
|
|
|
import it.tref.liferay.portos.bo.shared.util.TipoSoggettoUtil; |
|
|
|
|
import it.tref.liferay.portos.kaleo.model.FormLog; |
|
|
|
|
import it.tref.liferay.portos.kaleo.service.FormLogLocalServiceUtil; |
|
|
|
|
|
|
|
|
|
import java.text.Format; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import com.liferay.portal.kernel.dao.orm.DynamicQuery; |
|
|
|
|
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil; |
|
|
|
|
import com.liferay.portal.kernel.dao.orm.QueryUtil; |
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException; |
|
|
|
|
import com.liferay.portal.kernel.json.JSONFactoryUtil; |
|
|
|
|
import com.liferay.portal.kernel.json.JSONObject; |
|
|
|
|
import com.liferay.portal.kernel.log.Log; |
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil; |
|
|
|
|
import com.liferay.portal.kernel.search.Document; |
|
|
|
|
import com.liferay.portal.kernel.search.Field; |
|
|
|
|
import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil; |
|
|
|
|
import com.liferay.portal.kernel.util.StringPool; |
|
|
|
|
import com.liferay.portal.kernel.util.Validator; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowException; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowInstance; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowInstanceManagerUtil; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowLog; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowLogManagerUtil; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowTask; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowTaskAssignee; |
|
|
|
|
import com.liferay.portal.kernel.workflow.WorkflowTaskManagerUtil; |
|
|
|
|
import com.liferay.portal.kernel.workflow.comparator.WorkflowComparatorFactoryUtil; |
|
|
|
|
import com.liferay.portal.model.Role; |
|
|
|
|
import com.liferay.portal.model.User; |
|
|
|
|
import com.liferay.portal.model.WorkflowInstanceLink; |
|
|
|
@ -42,11 +59,14 @@ public class IndexerUtil {
|
|
|
|
|
|
|
|
|
|
public static final Format DATE_FORMAT = FastDateFormatFactoryUtil.getSimpleDateFormat("yyyyMMdd"); |
|
|
|
|
|
|
|
|
|
private static final Log _log = LogFactoryUtil.getLog(IndexerUtil.class); |
|
|
|
|
|
|
|
|
|
// Manifattura Web Group per Regione Siciliana Modifiche per rendere i campi di testo ricercabili per parole
|
|
|
|
|
// contenute e non per corrispondenza esatta.
|
|
|
|
|
public static Document fillDocument(Document document, IntPratica ip, ControlloPratica cp) throws SystemException, |
|
|
|
|
WorkflowException { |
|
|
|
|
|
|
|
|
|
long intPraticaId = ip.getIntPraticaId(); |
|
|
|
|
document.addKeyword(Field.USER_ID, ip.getUserId()); |
|
|
|
|
User titolare = UserLocalServiceUtil.fetchUser(ip.getUserId()); |
|
|
|
|
if (Validator.isNotNull(titolare)) { |
|
|
|
@ -62,7 +82,6 @@ public class IndexerUtil {
|
|
|
|
|
default: |
|
|
|
|
document.addKeyword(IndexField.PRATICA_APERTA, true); |
|
|
|
|
} |
|
|
|
|
document.addKeyword(IndexField.IN_COMPILAZIONE, Validator.isNull(ip.getStatoPratica())); |
|
|
|
|
Territorio territorio = TerritorioLocalServiceUtil.fetchTerritorio(ip.getTerritorioId()); |
|
|
|
|
if (Validator.isNull(territorio)) { |
|
|
|
|
document.addKeyword(Field.GROUP_ID, ip.getGroupId()); |
|
|
|
@ -74,7 +93,9 @@ public class IndexerUtil {
|
|
|
|
|
document.addKeyword(IndexField.CODICE_PROVINCIA, comune.getCodiceProvincia()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(ip.getStatoPratica())) { |
|
|
|
|
if (Validator.isNull(ip.getStatoPratica())) { |
|
|
|
|
document.addKeyword(IndexField.STATO_PRATICA, StatoPraticaConstants.IN_COMPILAZIONE); |
|
|
|
|
} else { |
|
|
|
|
document.addKeyword(IndexField.STATO_PRATICA, ip.getStatoPratica()); |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(ip.getDtPratica())) { |
|
|
|
@ -84,8 +105,8 @@ public class IndexerUtil {
|
|
|
|
|
document.addKeywordSortable(IndexField.NUMERO_PROGETTO, ip.getNumeroProgetto()); |
|
|
|
|
} |
|
|
|
|
document.addKeyword(IndexField.UNITA_OPERATIVA, ip.getUnitaOperativa()); |
|
|
|
|
List<ParereGeologo> pareri = ParereGeologoLocalServiceUtil.findByIntPraticaId(ip.getIntPraticaId(), |
|
|
|
|
QueryUtil.ALL_POS, QueryUtil.ALL_POS); |
|
|
|
|
List<ParereGeologo> pareri = ParereGeologoLocalServiceUtil.findByIntPraticaId(intPraticaId, QueryUtil.ALL_POS, |
|
|
|
|
QueryUtil.ALL_POS); |
|
|
|
|
List<Long> idGeologi = new ArrayList<>(); |
|
|
|
|
boolean pareriForniti = false; |
|
|
|
|
for (ParereGeologo geo : pareri) { |
|
|
|
@ -106,8 +127,8 @@ public class IndexerUtil {
|
|
|
|
|
istruttore.getScreenName().toLowerCase() }); |
|
|
|
|
} |
|
|
|
|
document.addNumber(IndexField.ISTRUTTORE_ID, ip.getStatusByUserId()); |
|
|
|
|
List<Soggetto> listaCommittenti = SoggettoLocalServiceUtil.findByIntPratica_TipologiaSoggetto( |
|
|
|
|
ip.getIntPraticaId(), TipoSoggettoUtil.COMMITTENTE); |
|
|
|
|
List<Soggetto> listaCommittenti = SoggettoLocalServiceUtil.findByIntPratica_TipologiaSoggetto(intPraticaId, |
|
|
|
|
TipoSoggettoUtil.COMMITTENTE); |
|
|
|
|
if (Validator.isNotNull(listaCommittenti) && listaCommittenti.size() > 0) { |
|
|
|
|
Set<String> committenti = new HashSet<>(); |
|
|
|
|
for (Soggetto committente : listaCommittenti) { |
|
|
|
@ -147,25 +168,26 @@ public class IndexerUtil {
|
|
|
|
|
} |
|
|
|
|
document.addText(IndexField.SOGGETTO, soggetti.toArray(new String[0])); |
|
|
|
|
} |
|
|
|
|
String taskName = hasFirma(intPraticaId) ? "Firma" : StringPool.BLANK; |
|
|
|
|
// Indicizzazione campi da Kaleo
|
|
|
|
|
if (Validator.isNotNull(cp)) { |
|
|
|
|
document.addNumber(IndexField.STATUS, cp.getStatus()); |
|
|
|
|
long companyId = cp.getCompanyId(); |
|
|
|
|
if (Validator.isNotNull(cp.getStatusDate())) { |
|
|
|
|
document.addKeyword(IndexField.DATA_ESITO, DATE_FORMAT.format(cp.getStatusDate())); |
|
|
|
|
} |
|
|
|
|
WorkflowInstanceLink workflowInstanceLink = WorkflowInstanceLinkLocalServiceUtil.fetchWorkflowInstanceLink( |
|
|
|
|
cp.getCompanyId(), cp.getGroupId(), ControlloPratica.class.getName(), cp.getPrimaryKey()); |
|
|
|
|
companyId, cp.getGroupId(), ControlloPratica.class.getName(), cp.getPrimaryKey()); |
|
|
|
|
if (Validator.isNotNull(workflowInstanceLink)) { |
|
|
|
|
WorkflowInstance workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(cp.getCompanyId(), |
|
|
|
|
WorkflowInstance workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance(companyId, |
|
|
|
|
workflowInstanceLink.getWorkflowInstanceId()); |
|
|
|
|
if (Validator.isNotNull(workflowInstance)) { |
|
|
|
|
document.addKeyword(IndexField.WORKFLOW_STATE, workflowInstance.getState()); |
|
|
|
|
List<WorkflowTask> tasks = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance( |
|
|
|
|
cp.getCompanyId(), null, workflowInstance.getWorkflowInstanceId(), false, |
|
|
|
|
QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); |
|
|
|
|
if (Validator.isNotNull(tasks) && !tasks.isEmpty()) { |
|
|
|
|
List<WorkflowTask> tasks = WorkflowTaskManagerUtil.getWorkflowTasksByWorkflowInstance(companyId, |
|
|
|
|
null, workflowInstance.getWorkflowInstanceId(), false, 0, 1, |
|
|
|
|
WorkflowComparatorFactoryUtil.getTaskCreateDateComparator(false)); |
|
|
|
|
if (!tasks.isEmpty()) { |
|
|
|
|
WorkflowTask task = tasks.get(0); |
|
|
|
|
if (task.getAssigneeUserId() != 0L && task.getAssigneeUserId() != -1) { |
|
|
|
|
if (task.getAssigneeUserId() > 0) { |
|
|
|
|
document.addKeyword(IndexField.TASK_ASSIGNEE_USER_ID, task.getAssigneeUserId()); |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(task.getWorkflowTaskAssignees()) |
|
|
|
@ -180,17 +202,73 @@ public class IndexerUtil {
|
|
|
|
|
document.addKeyword(IndexField.TASK_ASSIGNEE_ROLE_IDS, |
|
|
|
|
roleIdsAssignee.toArray(new String[0])); |
|
|
|
|
} |
|
|
|
|
document.addKeyword(IndexField.TASK, task.getName()); |
|
|
|
|
if (taskName.isEmpty()) { |
|
|
|
|
taskName = task.getName(); |
|
|
|
|
} |
|
|
|
|
if (task.getName().equals("Approvazione") && !task.isCompleted()) { |
|
|
|
|
String esito = esitoPendente(cp); |
|
|
|
|
if (!esito.isEmpty()) { |
|
|
|
|
document.addKeyword(IndexField.ESITO_PENDENTE, esito); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!taskName.isEmpty()) { |
|
|
|
|
document.addKeyword(IndexField.TASK, taskName); |
|
|
|
|
} |
|
|
|
|
// Prendo l'ultimo DettPratica legato a IntPratica
|
|
|
|
|
// DettPratica dp = DettPraticaLocalServiceUtil.getLastCompletedByIntPraticaAndProtocolloNotEmpty(ip
|
|
|
|
|
// .getIntPraticaId());
|
|
|
|
|
// if (Validator.isNull(dp)) {
|
|
|
|
|
// dp = DettPraticaLocalServiceUtil.getLastCompletedByIntPratica(ip.getIntPraticaId());
|
|
|
|
|
// }
|
|
|
|
|
DettPratica dp = DettPraticaLocalServiceUtil.getLastCompletedByIntPraticaAndProtocolloNotEmpty(intPraticaId); |
|
|
|
|
if (Validator.isNull(dp)) { |
|
|
|
|
dp = DettPraticaLocalServiceUtil.getLastCompletedByIntPratica(intPraticaId); |
|
|
|
|
} |
|
|
|
|
if (Validator.isNull(dp)) { |
|
|
|
|
dp=DettPraticaLocalServiceUtil.getLastEditableByIntPratica(intPraticaId); |
|
|
|
|
} |
|
|
|
|
if (Validator.isNotNull(dp)) { |
|
|
|
|
document.addText(IndexField.DESCRIZIONE, dp.getDescLongIntervento()); |
|
|
|
|
} |
|
|
|
|
return document; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean hasFirma(long intPraticaId) throws SystemException { |
|
|
|
|
|
|
|
|
|
DynamicQuery query = AvvisoLocalServiceUtil.dynamicQuery(); |
|
|
|
|
query.add(PropertyFactoryUtil.forName("intPraticaId").eq(intPraticaId)); |
|
|
|
|
query.add(PropertyFactoryUtil.forName("tipoAvviso").eq(AvvisoUtil.TIPO_AVVISO_FIRMA)); |
|
|
|
|
query.add(PropertyFactoryUtil.forName("annullato").eq(false)); |
|
|
|
|
query.add(PropertyFactoryUtil.forName("rifiutato").eq(false)); |
|
|
|
|
query.add(PropertyFactoryUtil.forName("fileEntryIdInvio").eq(0L)); |
|
|
|
|
return AvvisoLocalServiceUtil.dynamicQuery(query).size() > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final List<Integer> LOG_TYPES = Arrays.asList(WorkflowLog.TASK_ASSIGN, WorkflowLog.TASK_COMPLETION, |
|
|
|
|
WorkflowLog.TASK_UPDATE, WorkflowLog.TRANSITION); |
|
|
|
|
|
|
|
|
|
private static String esitoPendente(ControlloPratica cp) { |
|
|
|
|
|
|
|
|
|
long companyId = cp.getCompanyId(); |
|
|
|
|
try { |
|
|
|
|
WorkflowInstanceLink link = WorkflowInstanceLinkLocalServiceUtil.getWorkflowInstanceLink(companyId, |
|
|
|
|
cp.getGroupId(), ControlloPratica.class.getName(), cp.getPrimaryKey()); |
|
|
|
|
List<WorkflowLog> logs = WorkflowLogManagerUtil.getWorkflowLogsByWorkflowInstance(companyId, |
|
|
|
|
link.getWorkflowInstanceId(), LOG_TYPES, QueryUtil.ALL_POS, QueryUtil.ALL_POS, |
|
|
|
|
WorkflowComparatorFactoryUtil.getLogCreateDateComparator(false)); |
|
|
|
|
for (WorkflowLog log : logs) { |
|
|
|
|
if (log.getWorkflowTaskId() > 0) { |
|
|
|
|
WorkflowTask task = WorkflowTaskManagerUtil.getWorkflowTask(companyId, log.getWorkflowTaskId()); |
|
|
|
|
FormLog formLog = FormLogLocalServiceUtil.findByC_Task(companyId, task.getWorkflowTaskId()); |
|
|
|
|
if (Validator.isNotNull(formLog) && Validator.isNotNull(formLog.getFormParameters())) { |
|
|
|
|
JSONObject json = JSONFactoryUtil.createJSONObject(formLog.getFormParameters()); |
|
|
|
|
if (json.has("esito")) { |
|
|
|
|
return json.getString("esito"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) {} |
|
|
|
|
return StringPool.BLANK; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|