Search in sources :

Example 1 with ResponseDataBuilder

use of org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder in project open-smart-grid-platform by OSGP.

the class WsCoreResponseDataSteps method aResponseDataRecord.

@Given("^a response data record in ws-core$")
@Transactional("txMgrWsCore")
public ResponseData aResponseDataRecord(final Map<String, String> settings) {
    final ResponseData responseData = this.responseDataRepository.save(new ResponseDataBuilder().fromSettings(settings).build());
    final Date creationTime = DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate();
    LOGGER.info("Creating response data record with correlationUid: {} and creationTime: {}", responseData.getCorrelationUid(), creationTime);
    ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, responseData.getCorrelationUid());
    try {
        // (as it will be overridden on first save)
        if (settings.containsKey(PlatformKeys.KEY_CREATION_TIME)) {
            final Field fld = responseData.getClass().getSuperclass().getDeclaredField("creationTime");
            fld.setAccessible(true);
            fld.set(responseData, creationTime);
            this.responseDataRepository.saveAndFlush(responseData);
            LOGGER.info("Response data record saved with correlationUid: {} and creationTime: {}", responseData.getCorrelationUid(), creationTime);
        }
    } catch (final Exception e) {
        LOGGER.error("Exception", e);
        Assertions.fail("Failed to create response data record in ws-core.");
    }
    return responseData;
}
Also used : Field(java.lang.reflect.Field) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ResponseDataBuilder(org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder) Date(java.util.Date) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ResponseDataBuilder

use of org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder in project open-smart-grid-platform by OSGP.

the class WsPublicLightingResponseDataSteps method createResponseDataRecord.

private ResponseData createResponseDataRecord(final Map<String, String> settings, final ResponseDataRepository responseDataRepository) {
    ResponseData responseData = new ResponseDataBuilder().fromSettings(settings).build();
    responseData = responseDataRepository.save(responseData);
    ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, responseData.getCorrelationUid());
    try {
        // (as it will be overridden on first save)
        if (settings.containsKey(PlatformKeys.KEY_CREATION_TIME)) {
            final Field fld = responseData.getClass().getSuperclass().getDeclaredField("creationTime");
            fld.setAccessible(true);
            fld.set(responseData, DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate());
            responseDataRepository.saveAndFlush(responseData);
        }
    } catch (final Exception e) {
        LOGGER.error("Exception", e);
        Assertions.fail("Failed to create response data record.");
    }
    return responseData;
}
Also used : Field(java.lang.reflect.Field) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ResponseDataBuilder(org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder)

Example 3 with ResponseDataBuilder

use of org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder in project open-smart-grid-platform by OSGP.

the class WsMicrogridsResponseDataSteps method aResponseDataRecord.

@Given("^a response data record$")
@Transactional("txMgrWsMicrogrids")
public ResponseData aResponseDataRecord(final Map<String, String> settings) {
    ResponseData responseData = new ResponseDataBuilder().fromSettings(settings).build();
    responseData = this.microgridsResponseDataRepository.save(responseData);
    ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, responseData.getCorrelationUid());
    try {
        // (as it will be overridden on first save)
        if (settings.containsKey(PlatformKeys.KEY_CREATION_TIME)) {
            final Field fld = responseData.getClass().getSuperclass().getDeclaredField("creationTime");
            fld.setAccessible(true);
            fld.set(responseData, DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate());
            this.microgridsResponseDataRepository.saveAndFlush(responseData);
        }
    } catch (final Exception e) {
        LOGGER.error("Exception", e);
        Assertions.fail("Failed to create response data record.");
    }
    return responseData;
}
Also used : Field(java.lang.reflect.Field) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ResponseDataBuilder(org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ResponseDataBuilder

use of org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder in project open-smart-grid-platform by OSGP.

the class WsSmartMeteringResponseDataSteps method aResponseDataRecord.

@Given("^a response data record$")
@Transactional("txMgrWsSmartMetering")
public ResponseData aResponseDataRecord(final Map<String, String> settings) {
    final ResponseData responseData = this.smartMeteringResponseDataRepository.save(new ResponseDataBuilder().fromSettings(settings).build());
    ScenarioContext.current().put(PlatformKeys.KEY_CORRELATION_UID, responseData.getCorrelationUid());
    try {
        // (as it will be overridden on first save)
        if (settings.containsKey(PlatformKeys.KEY_CREATION_TIME)) {
            final Field fld = responseData.getClass().getSuperclass().getDeclaredField("creationTime");
            fld.setAccessible(true);
            fld.set(responseData, DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate());
            this.smartMeteringResponseDataRepository.saveAndFlush(responseData);
        }
    } catch (final Exception e) {
        LOGGER.error("Exception", e);
        Assertions.fail("Failed to create response data record.");
    }
    return responseData;
}
Also used : Field(java.lang.reflect.Field) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ResponseDataBuilder(org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Field (java.lang.reflect.Field)4 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)4 ResponseDataBuilder (org.opensmartgridplatform.cucumber.platform.glue.steps.database.ws.ResponseDataBuilder)4 Given (io.cucumber.java.en.Given)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)1