Search in sources :

Example 1 with LightValueMessageDataContainer

use of org.opensmartgridplatform.domain.core.valueobjects.LightValueMessageDataContainer in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method enqueueSetLightRequest.

public String enqueueSetLightRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, @Size(min = 1, max = 6) @Valid final List<LightValue> lightValues, final int messagePriority) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_LIGHT);
    this.domainHelperService.isInMaintenance(device);
    LOGGER.debug("enqueueSetLightRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final LightValueMessageDataContainer lightValueMessageDataContainer = new LightValueMessageDataContainer(lightValues);
    final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_LIGHT.name()).withMessagePriority(messagePriority).build();
    final PublicLightingRequestMessage message = new PublicLightingRequestMessage.Builder().messageMetadata(deviceMessageMetadata).request(lightValueMessageDataContainer).build();
    this.messageSender.send(message);
    return correlationUid;
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightValueMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.LightValueMessageDataContainer) Device(org.opensmartgridplatform.domain.core.entities.Device) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) PublicLightingRequestMessage(org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)

Example 2 with LightValueMessageDataContainer

use of org.opensmartgridplatform.domain.core.valueobjects.LightValueMessageDataContainer in project open-smart-grid-platform by OSGP.

the class PublicLightingSetLightRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.debug("Processing public lighting set light request message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    Object dataObject = null;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        dataObject = message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function: {}", messageType);
        final LightValueMessageDataContainer lightValueMessageDataContainer = (LightValueMessageDataContainer) dataObject;
        this.adHocManagementService.setLight(organisationIdentification, deviceIdentification, correlationUid, lightValueMessageDataContainer.getLightValues(), messageType, messagePriority);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : LightValueMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.LightValueMessageDataContainer) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Aggregations

LightValueMessageDataContainer (org.opensmartgridplatform.domain.core.valueobjects.LightValueMessageDataContainer)2 JMSException (javax.jms.JMSException)1 PublicLightingRequestMessage (org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 Builder (org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)1