use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty 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.schema.exchange.v1.UnsentMessageTypeProperty 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.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogMapper method getUnsentMessageProperties.
public static List<UnsentMessageTypeProperty> getUnsentMessageProperties(SendMovementToPluginType sendReport) {
List<UnsentMessageTypeProperty> unsentMessageTypeProperties = new ArrayList<>();
UnsentMessageTypeProperty propertyAssetName = new UnsentMessageTypeProperty();
UnsentMessageTypeProperty propertyIrcs = new UnsentMessageTypeProperty();
UnsentMessageTypeProperty propertyLong = new UnsentMessageTypeProperty();
UnsentMessageTypeProperty propertyLat = new UnsentMessageTypeProperty();
UnsentMessageTypeProperty propertyPositionTime = new UnsentMessageTypeProperty();
propertyAssetName.setKey(UnsentMessageTypePropertyKey.ASSET_NAME);
propertyAssetName.setValue(sendReport.getAssetName());
propertyIrcs.setKey(UnsentMessageTypePropertyKey.IRCS);
propertyIrcs.setValue(sendReport.getIrcs());
propertyLong.setKey(UnsentMessageTypePropertyKey.LONGITUDE);
propertyLong.setValue(sendReport.getMovement().getPosition().getLongitude().toString());
propertyLat.setKey(UnsentMessageTypePropertyKey.LATITUDE);
propertyLat.setValue(sendReport.getMovement().getPosition().getLatitude().toString());
propertyPositionTime.setKey(UnsentMessageTypePropertyKey.POSITION_TIME);
propertyPositionTime.setValue(sendReport.getMovement().getPositionTime().toString());
unsentMessageTypeProperties.add(propertyAssetName);
unsentMessageTypeProperties.add(propertyIrcs);
unsentMessageTypeProperties.add(propertyLong);
unsentMessageTypeProperties.add(propertyLat);
unsentMessageTypeProperties.add(propertyPositionTime);
return unsentMessageTypeProperties;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogMapper method getPropertiesForEmail.
public static List<UnsentMessageTypeProperty> getPropertiesForEmail(EmailType email) throws ExchangeLogException {
List<UnsentMessageTypeProperty> unsentMessageTypeProperties = new ArrayList<>();
UnsentMessageTypeProperty propertyEmail = new UnsentMessageTypeProperty();
propertyEmail.setKey(UnsentMessageTypePropertyKey.EMAIL);
propertyEmail.setValue(email.getTo());
unsentMessageTypeProperties.add(propertyEmail);
return unsentMessageTypeProperties;
}
use of eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentMessageMapper method mapToUnsentMessagePropertyEntities.
private static List<UnsentMessageProperty> mapToUnsentMessagePropertyEntities(UnsentMessageType message, UnsentMessage entity) {
List<UnsentMessageTypeProperty> properties = message.getProperties();
List<UnsentMessageProperty> unsentMessageProperties = new ArrayList<>();
for (UnsentMessageTypeProperty property : properties) {
UnsentMessageProperty unsentMessageProperty = new UnsentMessageProperty();
unsentMessageProperty.setKey(property.getKey());
unsentMessageProperty.setValue(property.getValue());
unsentMessageProperty.setUnsentMessage(entity);
unsentMessageProperties.add(unsentMessageProperty);
}
return unsentMessageProperties;
}
Aggregations