Search in sources :

Example 6 with UnsentMessageTypeProperty

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);
    }
}
Also used : SendMovementToPluginRequest(eu.europa.ec.fisheries.schema.exchange.module.v1.SendMovementToPluginRequest) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty) PluginType(eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType) SendMovementToPluginType(eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) SendMovementToPluginType(eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType) ExchangeException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)

Example 7 with UnsentMessageTypeProperty

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");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) NotificationMessage(eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 8 with UnsentMessageTypeProperty

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;
}
Also used : ArrayList(java.util.ArrayList) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)

Example 9 with UnsentMessageTypeProperty

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;
}
Also used : ArrayList(java.util.ArrayList) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)

Example 10 with UnsentMessageTypeProperty

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;
}
Also used : ArrayList(java.util.ArrayList) UnsentMessageTypeProperty(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty) UnsentMessageProperty(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessageProperty)

Aggregations

UnsentMessageTypeProperty (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageTypeProperty)9 ArrayList (java.util.ArrayList)8 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)4 JMSException (javax.jms.JMSException)3 AcknowledgeType (eu.europa.ec.fisheries.schema.exchange.common.v1.AcknowledgeType)2 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)2 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)2 UnsentMessageProperty (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessageProperty)2 ExchangeMessageEvent (eu.europa.ec.fisheries.uvms.exchange.message.event.carrier.ExchangeMessageEvent)2 ExchangeException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeException)2 CommandType (eu.europa.ec.fisheries.schema.exchange.common.v1.CommandType)1 CommandTypeType (eu.europa.ec.fisheries.schema.exchange.common.v1.CommandTypeType)1 SendMovementToPluginRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendMovementToPluginRequest)1 SetCommandRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SetCommandRequest)1 SendMovementToPluginType (eu.europa.ec.fisheries.schema.exchange.movement.v1.SendMovementToPluginType)1 PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)1 UnsentMessageType (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)1 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)1 NotificationMessage (eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage)1 Asset (eu.europa.ec.fisheries.wsdl.asset.types.Asset)1