use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventOutgoingServiceBean method validate.
private boolean validate(ServiceResponseType service, SendMovementToPluginType sendReport, TextMessage origin, String username) {
// Use first and only
String serviceName = service.getServiceClassName();
if (serviceName == null || serviceName.isEmpty()) {
String faultMessage = "First plugin of type " + sendReport.getPluginType() + " is invalid. Missing serviceClassName";
exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
try {
List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), origin.getText(), unsentMessageProperties, username);
} catch (ExchangeLogException | JMSException e) {
LOG.error("Couldn't create unsent message " + e.getMessage());
}
return false;
} else if (!sendReport.getPluginType().equals(service.getPluginType())) {
String faultMessage = "First plugin of type " + sendReport.getPluginType() + " does not match plugin type of " + serviceName + ". Current type is " + service.getPluginType();
exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
return false;
} else if (sendReport.getPluginName() != null && !serviceName.equalsIgnoreCase(sendReport.getPluginName())) {
String faultMessage = "First plugin of type " + sendReport.getPluginType() + " does not matching input of " + sendReport.getPluginName();
exchangeErrorEvent.fire(new ExchangeMessageEvent(origin, ExchangeModuleResponseMapper.createFaultMessage(FaultCode.EXCHANGE_PLUGIN_INVALID, faultMessage)));
return false;
} else if (!StatusType.STARTED.equals(service.getStatus())) {
try {
List<UnsentMessageTypeProperty> unsentMessageProperties = ExchangeLogMapper.getUnsentMessageProperties(sendReport);
exchangeLog.createUnsentMessage(sendReport.getRecipient(), sendReport.getTimestamp(), ExchangeLogMapper.getSendMovementSenderReceiver(sendReport), origin.getText(), unsentMessageProperties, username);
} catch (ExchangeLogException | JMSException e) {
LOG.error("Couldn't create unsent message " + e.getMessage());
}
try {
AcknowledgeType ackType = ExchangeModuleResponseMapper.mapAcknowledgeTypeNOK(origin.getJMSMessageID(), "Plugin to send movement is not started");
String moduleResponse = ExchangeModuleResponseMapper.mapSendMovementToPluginResponse(ackType);
producer.sendModuleResponseMessage(origin, moduleResponse);
} catch (JMSException | ExchangeModelMarshallException e) {
LOG.error("Plugin not started, couldn't send module response: " + e.getMessage());
}
return false;
}
return true;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeEventOutgoingServiceBean method getSetUnsentMessageTypePropertiesForPoll.
private List<UnsentMessageTypeProperty> getSetUnsentMessageTypePropertiesForPoll(CommandType commandType) throws ExchangeLogException {
List<UnsentMessageTypeProperty> properties = new ArrayList<>();
if (commandType.getPoll() != null) {
String connectId = ExchangeLogMapper.getConnectId(commandType.getPoll());
Asset asset = getAsset(connectId);
properties = ExchangeLogMapper.getPropertiesForPoll(commandType.getPoll(), asset.getName());
} else if (commandType.getEmail() != null) {
properties = ExchangeLogMapper.getPropertiesForEmail(commandType.getEmail());
}
return properties;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentMessageMapper method mapToUnsentMessagePropertyModel.
private static List<UnsentMessageTypeProperty> mapToUnsentMessagePropertyModel(UnsentMessage entity) {
List<UnsentMessageProperty> properties = entity.getProperties();
List<UnsentMessageTypeProperty> unsentMessageTypeProperties = new ArrayList<>();
for (UnsentMessageProperty property : properties) {
UnsentMessageTypeProperty unsentMessageTypeProperty = new UnsentMessageTypeProperty();
unsentMessageTypeProperty.setKey(UnsentMessageTypePropertyKey.fromValue(property.getKey().value()));
unsentMessageTypeProperty.setValue(property.getValue());
unsentMessageTypeProperties.add(unsentMessageTypeProperty);
}
return unsentMessageTypeProperties;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogMapper method getPropertiesForPoll.
public static List<UnsentMessageTypeProperty> getPropertiesForPoll(PollType poll, String assetName) throws ExchangeLogException {
List<UnsentMessageTypeProperty> unsentMessageTypeProperties = new ArrayList<>();
UnsentMessageTypeProperty propertyAssetName = new UnsentMessageTypeProperty();
propertyAssetName.setKey(UnsentMessageTypePropertyKey.ASSET_NAME);
propertyAssetName.setValue(assetName);
UnsentMessageTypeProperty pollType = new UnsentMessageTypeProperty();
pollType.setKey(UnsentMessageTypePropertyKey.POLL_TYPE);
pollType.setValue(poll.getPollTypeType().name());
unsentMessageTypeProperties.add(propertyAssetName);
unsentMessageTypeProperties.add(pollType);
return unsentMessageTypeProperties;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty 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());
}
}
Aggregations