Select a tab to view language specific
aspect engine implementation.
First let's change the class to extend
CloudAspectEngineBase
. This has the type arguments of
IStarSignData
- the interface extending
aspect data which will be added to the
flow data, and
IAspectPropertyMetaData
- instead of
IElementPropertyMetaData
.
The existing constructor needs to change to match the CloudAspectEngineBase
class.
The constructor will also take a CloudRequestEngine
instance to get the available properties from.
The LoadAspectProperties
method in this example will get the aspect properties from the CloudRequestEngine
and store them. In this case we know the only property will be 'star sign', but more complex cloud engines can have many properties.
Now the abstract methods can be implemented to create a functional aspect engine.
First let's change the class to extend
CloudAspectEngineBase
. This has the type arguments of
StarSignData
- the interface extending
aspect data which will be added to the
flow data, and
AspectPropertyMetaData
- instead of
ElementPropertyMetaData
.
The existing constructor needs to change to match the CloudAspectEngineBase
class.
The constructor will also take a CloudRequestEngine
instance to get the available properties from.
public class SimpleCloudEngine extends CloudAspectEngineBase<StarSignData> {
private List<AspectPropertyMetaData> aspectProperties;
private String dataSourceTier;
public SimpleCloudEngine(
Logger logger,
ElementDataFactory<StarSignData> dataFactory) {
super(logger, dataFactory);
}
The loadAspectProperties
method in this example will get the aspect properties from the CloudRequestEngine
and store them. In this case we know the only property will be 'star sign', but more complex cloud engines can have many properties.
Now the abstract methods can be implemented to create a functional aspect engine.
public class SimpleCloudEngine extends CloudAspectEngineBase<StarSignData> {
private List<AspectPropertyMetaData> aspectProperties;
private String dataSourceTier;
public SimpleCloudEngine(
Logger logger,
ElementDataFactory<StarSignData> dataFactory) {
super(logger, dataFactory);
}
@Override
public List<AspectPropertyMetaData> getProperties() {
return aspectProperties;
}
@Override
public String getDataSourceTier() {
return dataSourceTier;
}
@Override
public String getElementDataKey() {
return "starsign";
}
@Override
public EvidenceKeyFilter getEvidenceKeyFilter() {
return new EvidenceKeyFilterWhitelist(new ArrayList<String>());
}
private boolean checkedForCloudEngine = false;
private CloudRequestEngine cloudRequestEngine = null;
@Override
protected void processEngine(FlowData data, StarSignData aspectData) {
StarSignDataInternal starSignData = (StarSignDataInternal)aspectData;
if (checkedForCloudEngine == false) {
cloudRequestEngine = getRequestEngine().getInstance();
checkedForCloudEngine = true;
}
CloudRequestData requestData = data.getFromElement(cloudRequestEngine);
String json = requestData.getJsonResponse();
JSONObject jsonObj = new JSONObject(json);
JSONObject deviceObj = jsonObj.getJSONObject("starsign");
starSignData.setStarSign(deviceObj.getString("starsign"));
}
@Override
protected void unmanagedResourcesCleanup() {
}
}