use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventOutgoingServiceBean method sendCommandToPlugin.
@Override
public void sendCommandToPlugin(@Observes @SendCommandToPluginEvent ExchangeMessageEvent message) {
SetCommandRequest request = new SetCommandRequest();
try {
request = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), SetCommandRequest.class);
LOG.info("Send command to plugin:{}", request);
String pluginName = request.getCommand().getPluginName();
CommandType commandType = request.getCommand();
ServiceResponseType service = exchangeService.getService(pluginName);
if (validate(request.getCommand(), message.getJmsMessage(), service, commandType, request.getUsername())) {
List<UnsentMessageTypeProperty> setUnsentMessageTypePropertiesForPoll = getSetUnsentMessageTypePropertiesForPoll(commandType);
String unsentMessageGuid = exchangeLog.createUnsentMessage(service.getName(), request.getCommand().getTimestamp(), request.getCommand().getCommand().name(), message.getJmsMessage().getText(), setUnsentMessageTypePropertiesForPoll, request.getUsername());
request.getCommand().setUnsentMessageGuid(unsentMessageGuid);
String text = ExchangePluginRequestMapper.createSetCommandRequest(request.getCommand());
String pluginMessageId = producer.sendEventBusMessage(text, pluginName);
try {
ExchangeLogType log = ExchangeLogMapper.getSendCommandExchangeLog(request.getCommand());
exchangeLog.logAndCache(log, pluginMessageId, request.getUsername());
} catch (ExchangeLogException e) {
LOG.error(e.getMessage());
}
CommandTypeType x = request.getCommand().getCommand();
// response back to MobileTerminal (not to rules when email)
if (request.getCommand().getCommand() != CommandTypeType.EMAIL) {
AcknowledgeType ackType = ExchangeModuleResponseMapper.mapAcknowledgeTypeOK();
String moduleResponse = ExchangeModuleResponseMapper.mapSetCommandResponse(ackType);
producer.sendModuleResponseMessage(message.getJmsMessage(), moduleResponse);
}
} else {
LOG.debug("Can not send to plugin. Response sent to caller.");
}
} catch (NullPointerException | ExchangeException e) {
if (request.getCommand().getCommand() != CommandTypeType.EMAIL) {
LOG.error("[ Error when sending command to plugin {} ]", e.getMessage());
exchangeErrorEvent.fire(new ExchangeMessageEvent(message.getJmsMessage(), ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_EVENT_SERVICE, "Exception when sending command to plugin")));
}
} catch (JMSException ex) {
LOG.error("[ Error when creating unsent message {} ]", ex.getMessage());
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventOutgoingServiceBean method sendReportToPlugin.
@Override
public void sendReportToPlugin(@Observes @SendReportToPluginEvent ExchangeMessageEvent message) {
try {
SendMovementToPluginRequest request = JAXBMarshaller.unmarshallTextMessage(message.getJmsMessage(), SendMovementToPluginRequest.class);
LOG.info("Send report to plugin: {}", request);
SendMovementToPluginType sendReport = request.getReport();
List<PluginType> type = new ArrayList<>();
type.add(sendReport.getPluginType());
List<ServiceResponseType> services = exchangeService.getServiceList(type);
if (services == null || services.isEmpty()) {
String faultMessage = "No plugins of type " + sendReport.getPluginType() + " found";
LOG.debug(faultMessage);
} else {
ServiceResponseType service = services.get(0);
String serviceName = service.getServiceClassName();
if (validate(service, sendReport, message.getJmsMessage(), request.getUsername())) {
List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
String unsentMessageGuid = exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), message.getJmsMessage().getText(), unsentMessageProperties, request.getUsername());
String text = ExchangePluginRequestMapper.createSetReportRequest(sendReport.getTimestamp(), sendReport, unsentMessageGuid);
String pluginMessageId = producer.sendEventBusMessage(text, serviceName);
// System.out.println("SendReport: PluginMessageId: " + pluginMessageId);
try {
ExchangeLogType log = ExchangeLogMapper.getSendMovementExchangeLog(sendReport);
exchangeLog.logAndCache(log, pluginMessageId, request.getUsername());
} catch (ExchangeLogException e) {
LOG.error(e.getMessage());
}
} else {
LOG.debug("Cannot send to plugin. Response sent to caller:{}", message);
}
}
} catch (ExchangeException e) {
LOG.error("[ Error when sending report to plugin {} ] {}", message, e);
} catch (JMSException ex) {
LOG.error("[ Error when creating unsent movement {}] {}", message, ex);
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogServiceBean method setPollStatus.
@Override
public PollStatus setPollStatus(String jmsCorrelationId, String pollId, ExchangeLogStatusTypeType logStatus, String username) throws ExchangeLogException {
try {
// Remove the message from cache, because legancy implementation
logCache.acknowledged(jmsCorrelationId);
PollStatus pollStatus = new PollStatus();
pollStatus.setPollGuid(pollId);
pollStatus.setStatus(logStatus);
ExchangeLogType exchangeLogType = exchangeLogModel.setPollStatus(pollStatus, username);
pollStatus.setExchangeLogGuid(exchangeLogType.getGuid());
sendAuditLogMessageForUpdatePollStatus(pollId, username);
// For long polling
exchangeLogEvent.fire(new NotificationMessage("guid", pollStatus.getExchangeLogGuid()));
return pollStatus;
} catch (ExchangeModelMapperException e) {
throw new ExchangeLogException("Couldn't update status of exchange log");
} catch (ExchangeModelException e) {
throw new ExchangeLogException("Couldn't update status of exchange log");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogServiceBean method createUnsentMessage.
@Override
public String createUnsentMessage(String senderReceiver, Date timestamp, String recipient, String message, List<UnsentMessageTypeProperty> properties, String username) throws ExchangeLogException {
log.debug("createUnsentMessage in service layer:{}", message);
try {
UnsentMessageType unsentMessage = new UnsentMessageType();
unsentMessage.setDateReceived(timestamp);
unsentMessage.setSenderReceiver(senderReceiver);
unsentMessage.setRecipient(recipient);
unsentMessage.setMessage(message);
unsentMessage.getProperties().addAll(properties);
String createdUnsentMessageId = unsentModel.createMessage(unsentMessage, username);
List<String> unsentMessageIds = Arrays.asList(createdUnsentMessageId);
sendAuditLogMessageForCreateUnsentMessage(createdUnsentMessageId, username);
sendingQueueEvent.fire(new NotificationMessage("messageIds", unsentMessageIds));
return createdUnsentMessageId;
} catch (ExchangeModelException e) {
log.error("Couldn't add message to unsent list: {} {}", message, e);
throw new ExchangeLogException("Couldn't add message to unsent list");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogServiceBean method updateStatus.
@Override
public ExchangeLogType updateStatus(String pluginMessageId, ExchangeLogStatusTypeType logStatus, String username) throws ExchangeLogException {
try {
String logGuid = logCache.acknowledged(pluginMessageId);
ExchangeLogStatusType exchangeLogStatusType = createExchangeLogStatusType(logStatus, logGuid);
ExchangeLogType updatedLog = exchangeLogModel.updateExchangeLogStatus(exchangeLogStatusType, username);
sendAuditLogMessageForUpdateExchangeLog(updatedLog.getGuid(), username);
// For long polling
exchangeLogEvent.fire(new NotificationMessage("guid", updatedLog.getGuid()));
return updatedLog;
} catch (ExchangeModelException e) {
throw new ExchangeLogException("Couldn't update status of exchange log", e);
}
}
Aggregations