Search in sources :

Example 1 with ActionRequest

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

the class SmartMeteringBundleEndpoint method bundleRequest.

@PayloadRoot(localPart = "BundleRequest", namespace = NAMESPACE)
@ResponsePayload
public BundleAsyncResponse bundleRequest(@ResponseUrl final String responseUrl, @MessageMetadata final org.opensmartgridplatform.shared.infra.jms.MessageMetadata messageMetadata, @RequestPayload final BundleRequest request) throws OsgpException {
    final String organisationIdentification = messageMetadata.getOrganisationIdentification();
    final String deviceIdentification = request.getDeviceIdentification();
    log.info("Incoming BundleRequest with responseUrl {} and {} actions. [deviceId={} | organisationId={}]", responseUrl, request.getActions().getActionList().size(), deviceIdentification, organisationIdentification);
    BundleAsyncResponse response = null;
    try {
        response = new BundleAsyncResponse();
        final List<ActionRequest> actionRequestList = this.actionMapperService.mapAllActions(request.getActions().getActionList());
        final String correlationUid = this.bundleService.enqueueBundleRequest(messageMetadata.builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.HANDLE_BUNDLED_ACTIONS.name()).build(), actionRequestList);
        log.info("BundleRequest placed on queue [correlationId={} | deviceId={} | organisationId={}]", correlationUid, deviceIdentification, organisationIdentification);
        response.setCorrelationUid(correlationUid);
        response.setDeviceIdentification(request.getDeviceIdentification());
        this.saveResponseUrlIfNeeded(correlationUid, responseUrl);
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) BundleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.BundleAsyncResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 2 with ActionRequest

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

the class ActionMapperService method mapAllActions.

public List<ActionRequest> mapAllActions(final List<? extends Action> actionList) throws FunctionalException {
    final List<ActionRequest> actionRequestList = new ArrayList<>();
    for (final Action action : actionList) {
        final ConfigurableMapper mapper = CLASS_TO_MAPPER_MAP.get(action.getClass());
        final Class<? extends ActionRequest> clazz = CLASS_MAP.get(action.getClass());
        if (mapper != null) {
            actionRequestList.add(this.getActionRequestWithDefaultMapper(action, mapper, clazz));
        } else {
            throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("No mapper defined for class: " + action.getClass().getName()));
        }
    }
    return actionRequestList;
}
Also used : Action(org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.Action) ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest) ArrayList(java.util.ArrayList) ConfigurableMapper(ma.glasnost.orika.impl.ConfigurableMapper) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 3 with ActionRequest

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

the class BundleService method checkIfBundleIsAllowed.

/**
 * checks if the bundle and the {@link ActionRequest}s in the bundle are allowed and valid
 *
 * @param actionList the {@link List} of {@link ActionRequest}s in the bundle
 * @param organisation the organisation to check
 * @param device the device to check
 * @throws FunctionalException when either the bundle or the actions in the bundle are not
 *     allowed, or when the action is not valid
 */
private void checkIfBundleIsAllowed(final List<ActionRequest> actionList, final Organisation organisation, final Device device) throws FunctionalException {
    this.domainHelperService.checkAllowed(organisation, device, DeviceFunction.HANDLE_BUNDLED_ACTIONS);
    for (final ActionRequest action : actionList) {
        this.domainHelperService.checkAllowed(organisation, device, action.getDeviceFunction());
        action.validate();
    }
}
Also used : ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest)

Example 4 with ActionRequest

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

the class BundleServiceTest method testAllOperationsAreAllowed.

/**
 * tests that a {@link SmartMeteringRequestMessage} is send containing all the {@link
 * ActionRequest}s put in.
 *
 * @throws FunctionalException should not be thrown in this test
 */
@Test
void testAllOperationsAreAllowed() throws FunctionalException {
    // Run the test
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withOrganisationIdentification(ORGANISATION_IDENTIFICATION).withDeviceIdentification(DEVICE_IDENTIFICATION).withMessageType(MessageType.HANDLE_BUNDLED_ACTIONS.name()).withMessagePriority(MESSAGE_PRIORITY).withBypassRetry(BYPASS_RETRY).build();
    this.bundleService.enqueueBundleRequest(messageMetadata, this.actionRequestMockList);
    // Verify the test
    final ArgumentCaptor<SmartMeteringRequestMessage> message = ArgumentCaptor.forClass(SmartMeteringRequestMessage.class);
    verify(this.smartMeteringRequestMessageSender).send(message.capture());
    assertThat(message.getValue().getOrganisationIdentification()).isEqualTo(ORGANISATION_IDENTIFICATION);
    assertThat(message.getValue().getDeviceIdentification()).isEqualTo(DEVICE_IDENTIFICATION);
    final BundleMessageRequest requestMessage = (BundleMessageRequest) message.getValue().getRequest();
    final List<ActionRequest> actionList = requestMessage.getBundleList();
    assertThat(actionList.size()).isEqualTo(this.actionRequestMockList.size());
    for (int i = 0; i < actionList.size(); i++) {
        assertThat(actionList.get(i)).isEqualTo(this.actionRequestMockList.get(i));
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) SmartMeteringRequestMessage(org.opensmartgridplatform.adapter.ws.smartmetering.infra.jms.SmartMeteringRequestMessage) ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest) BundleMessageRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.BundleMessageRequest) Test(org.junit.jupiter.api.Test)

Example 5 with ActionRequest

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

the class BundleServiceTest method createActionRequestMockList.

private List<ActionRequest> createActionRequestMockList() {
    final ActionRequest a = mock(ActionRequest.class);
    final ActionRequest b = mock(ActionRequest.class);
    final ActionRequest c = mock(ActionRequest.class);
    final ActionRequest d = mock(ActionRequest.class);
    final ActionRequest e = mock(ActionRequest.class);
    final ActionRequest f = mock(ActionRequest.class);
    return Arrays.asList(a, b, c, d, e, f);
}
Also used : ActionRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest)

Aggregations

ActionRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionRequest)5 ArrayList (java.util.ArrayList)1 ConfigurableMapper (ma.glasnost.orika.impl.ConfigurableMapper)1 Test (org.junit.jupiter.api.Test)1 BundleAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.BundleAsyncResponse)1 Action (org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.Action)1 SmartMeteringRequestMessage (org.opensmartgridplatform.adapter.ws.smartmetering.infra.jms.SmartMeteringRequestMessage)1 BundleMessageRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.BundleMessageRequest)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1