001
014
015 package com.liferay.portal.lar;
016
017 import com.liferay.portal.kernel.backgroundtask.BackgroundTaskThreadLocal;
018 import com.liferay.portal.kernel.lar.ManifestSummary;
019 import com.liferay.portal.kernel.lar.PortletDataHandler;
020 import com.liferay.portal.kernel.lar.PortletDataHandlerStatusMessageSender;
021 import com.liferay.portal.kernel.lar.StagedModelDataHandler;
022 import com.liferay.portal.kernel.lar.StagedModelDataHandlerRegistryUtil;
023 import com.liferay.portal.kernel.messaging.Message;
024 import com.liferay.portal.kernel.messaging.sender.SingleDestinationMessageSender;
025 import com.liferay.portal.kernel.util.LongWrapper;
026 import com.liferay.portal.model.Portlet;
027 import com.liferay.portal.model.StagedModel;
028 import com.liferay.portal.service.PortletLocalServiceUtil;
029
030 import java.util.HashMap;
031 import java.util.Map;
032
033
036 public class PortletDataHandlerStatusMessageSenderImpl
037 implements PortletDataHandlerStatusMessageSender {
038
039
043 @Deprecated
044 @Override
045 public void sendStatusMessage(
046 String messageType, ManifestSummary manifestSummary) {
047
048 sendStatusMessage(messageType, (String[])null, manifestSummary);
049 }
050
051 @Override
052 public void sendStatusMessage(
053 String messageType, String portletId, ManifestSummary manifestSummary) {
054
055 if (!BackgroundTaskThreadLocal.hasBackgroundTask()) {
056 return;
057 }
058
059 Message message = createMessage(messageType, manifestSummary);
060
061 message.put("portletId", portletId);
062
063 Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
064
065 if (portlet != null) {
066 PortletDataHandler portletDataHandler =
067 portlet.getPortletDataHandlerInstance();
068
069 long portletModelAdditionCountersTotal =
070 portletDataHandler.getExportModelCount(manifestSummary);
071
072 if (portletModelAdditionCountersTotal < 0) {
073 portletModelAdditionCountersTotal = 0;
074 }
075
076 message.put(
077 "portletModelAdditionCountersTotal",
078 portletModelAdditionCountersTotal);
079 }
080
081 _singleDestinationMessageSender.send(message);
082 }
083
084 @Override
085 public void sendStatusMessage(
086 String messageType, String[] portletIds,
087 ManifestSummary manifestSummary) {
088
089 if (!BackgroundTaskThreadLocal.hasBackgroundTask()) {
090 return;
091 }
092
093 Message message = createMessage(messageType, manifestSummary);
094
095 message.put("portletIds", portletIds);
096
097 _singleDestinationMessageSender.send(message);
098 }
099
100 @Override
101 public <T extends StagedModel> void sendStatusMessage(
102 String messageType, T stagedModel, ManifestSummary manifestSummary) {
103
104 if (!BackgroundTaskThreadLocal.hasBackgroundTask()) {
105 return;
106 }
107
108 Message message = createMessage(messageType, manifestSummary);
109
110 StagedModelDataHandler<T> stagedModelDataHandler =
111 (StagedModelDataHandler<T>)
112 StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(
113 stagedModel.getModelClassName());
114
115 message.put(
116 "stagedModelName",
117 stagedModelDataHandler.getDisplayName(stagedModel));
118
119 message.put(
120 "stagedModelType",
121 String.valueOf(stagedModel.getStagedModelType()));
122 message.put("uuid", stagedModel.getUuid());
123
124 _singleDestinationMessageSender.send(message);
125 }
126
127 public void setSingleDestinationMessageSender(
128 SingleDestinationMessageSender singleDestinationMessageSender) {
129
130 _singleDestinationMessageSender = singleDestinationMessageSender;
131 }
132
133 protected Message createMessage(
134 String messageType, ManifestSummary manifestSummary) {
135
136 Message message = new Message();
137
138 message.put(
139 "backgroundTaskId",
140 BackgroundTaskThreadLocal.getBackgroundTaskId());
141 message.put("messageType", messageType);
142
143 Map<String, LongWrapper> modelAdditionCounters =
144 manifestSummary.getModelAdditionCounters();
145
146 message.put(
147 "modelAdditionCounters",
148 new HashMap<String, LongWrapper>(modelAdditionCounters));
149
150 Map<String, LongWrapper> modelDeletionCounters =
151 manifestSummary.getModelDeletionCounters();
152
153 message.put(
154 "modelDeletionCounters",
155 new HashMap<String, LongWrapper>(modelDeletionCounters));
156
157 return message;
158 }
159
160 private SingleDestinationMessageSender _singleDestinationMessageSender;
161
162 }