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;
}
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;
}
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();
}
}
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));
}
}
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);
}
Aggregations