From 0e3d290aa34c4b94f6a03136400cb551fe9556ad Mon Sep 17 00:00:00 2001 From: Gabriele Zigurella Date: Tue, 23 May 2023 16:00:49 +0200 Subject: [PATCH] add custom fields to trace back to kafka db --- .../bridge/api/QuarkusBridgeConstants.java | 6 ++++ .../scheduler/QuarkusBridgeScheduler.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java index 708f2723..f3ae0ff3 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/api/QuarkusBridgeConstants.java @@ -1,6 +1,7 @@ package portos.nextmind.quarkus.bridge.api; public class QuarkusBridgeConstants { + public final static String HEADER_REQUEST = "HeaderPratica"; public final static String BODY_REQUEST = "SportelloPratica"; public final static String codiceIstat = "cadastralCode"; @@ -9,4 +10,9 @@ public class QuarkusBridgeConstants { public final static String nome = "name"; public final static String cognome = "surname"; public final static String tipoProcedura = "proceedingType"; + public final static String instanceId = "instanceId"; + public final static String correlationId = "correlationId"; + public final static String clientId = "clientId"; + public final static String recordId = "id"; // The generated id in the external database + } diff --git a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java index 640c1ac3..100dfc27 100644 --- a/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java +++ b/liferay-plugins-sdk-6.2/portlets/quarkus-bridge-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java @@ -18,6 +18,8 @@ import com.liferay.portal.model.Company; import com.liferay.portal.model.User; import com.liferay.portal.service.CompanyLocalServiceUtil; import com.liferay.portal.service.ServiceContext; +import com.liferay.portlet.expando.model.ExpandoBridge; +import com.liferay.portlet.expando.model.ExpandoColumnConstants; import it.tref.liferay.portos.bo.model.Comune; import it.tref.liferay.portos.bo.model.DettPratica; @@ -113,6 +115,38 @@ public class QuarkusBridgeScheduler implements MessageListener { DettPratica dettPratica = DettPraticaLocalServiceUtil .addDettPratica(territorioId, tipoProcedura, serviceContext); + // Add custom fields to IntPratica to fetch future updates from Kafka + IntPratica intPratica = IntPraticaLocalServiceUtil.fetchIntPratica(dettPratica.getIntPraticaId()); + + ExpandoBridge customFieldsExpando = intPratica.getExpandoBridge(); + customFieldsExpando.addAttribute(QuarkusBridgeConstants.instanceId, + ExpandoColumnConstants.STRING); + customFieldsExpando.addAttribute(QuarkusBridgeConstants.correlationId, + ExpandoColumnConstants.STRING); + customFieldsExpando.addAttribute(QuarkusBridgeConstants.clientId, + ExpandoColumnConstants.STRING); + customFieldsExpando.addAttribute("HeaderSportelloId", ExpandoColumnConstants.LONG); + customFieldsExpando.addAttribute("SportelloId", ExpandoColumnConstants.LONG); + + String instanceId = Header.getString(QuarkusBridgeConstants.instanceId); + String correlationId = Header.getString(QuarkusBridgeConstants.correlationId); + String clientId = Header.getString(QuarkusBridgeConstants.clientId); + + Long headerSportelloId = Header.getLong(QuarkusBridgeConstants.recordId); + Long sportelloId = Sportello.getLong(QuarkusBridgeConstants.recordId); + + customFieldsExpando.setAttribute(QuarkusBridgeConstants.correlationId, correlationId); + customFieldsExpando.setAttribute(QuarkusBridgeConstants.instanceId, instanceId); + customFieldsExpando.setAttribute(QuarkusBridgeConstants.clientId, clientId); + + customFieldsExpando.setAttribute("HeaderSportelloId", headerSportelloId); + customFieldsExpando.setAttribute("SportelloId", sportelloId); + + intPratica.setExpandoBridgeAttributes(customFieldsExpando); + + // Persist changes to custom fields + IntPraticaLocalServiceUtil.updateIntPratica(intPratica); + } catch (SystemException e) { _log.error(e ,e); } catch (PortalException e) {