{
final InteractionCoordinator coordinator = context.get(ContextKey.COORDINATOR);
final StatementContext delegate = coordinator.getDialogState().getContext(interactionUnit.getId());
assert delegate != null : "StatementContext not provided";
DMRMapping mapping = (DMRMapping) interactionUnit.findMapping(DMR, new Predicate<DMRMapping>()
{
@Override
public boolean appliesTo(final DMRMapping candidate)
{
// the read-resource operation only needs the address of a resource
// hence we can skip mapping without address declarations (i.e. just attributes)
return candidate.getAddress() != null;
}
});
if (mapping != null)
{
FilteringStatementContext stmtContext = new FilteringStatementContext(
delegate,
new FilteringStatementContext.Filter() {
@Override
public String filter(String key) {
if ("selected.entity".equals(key))
return "*";
else
return null;
}
@Override
public String[] filterTuple(String key) {
return null;
}
}
) {
};
String step = "step-" + (steps.size()+1);
String mappedAddress = mapping.getResolvedAddress();
contexts.put(mappedAddress, stmtContext);
AddressMapping addressMapping = AddressMapping.fromString(mappedAddress);
ModelNode op = addressMapping.asResource(stmtContext);
String addressKey = addressMapping.asResource(stmtContext).toString(); // mapping.getResolvedAddress();
if (!resolvedAdresses.contains(addressKey))
{
op.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION);
steps.add(op);
// retain references
resolvedAdresses.add(addressKey);
stepReference.put(step, interactionUnit);
}
else
{
// create an alias for later reference
if(null==aliasMappings.get(addressKey))
aliasMappings.put(addressKey, new HashSet<QName>());
// if a mapping resolves to the same address we can reuse the model description later on
aliasMappings.get(addressKey).add(mapping.getCorrelationId());
}
}
}