@Override public void readProperties(RequestContext ctx, PropertySink sink) throws Exception { sink.accept("name", "Resource Triggered Scripts"); sink.accept("description", "Scripts which are run when a monitored resource is modified."); // TODO: it not very performant to have count as part of the properties (since have to query the // size) // count should be specified in the readMembers method response ResourceParams resourceParams = ctx.resourceParams(); if (resourceParams != null && resourceParams.value(TARGET_PARAMETER) != null) { String target = resourceParams.value(TARGET_PARAMETER); sink.accept("count", scripts.getByTarget(target).size()); } else { sink.accept("count", scripts.size()); } sink.close(); }
@Override public void readMembers(RequestContext ctx, ResourceSink sink) throws Exception { ResourceParams resourceParams = ctx.resourceParams(); if (resourceParams != null && resourceParams.value(TARGET_PARAMETER) != null) { String target = resourceParams.value(TARGET_PARAMETER); for (Script script : scripts.getByTarget(target)) { sink.accept(new ResourceScript(this, script)); } } else { for (Script script : scripts.values()) { sink.accept(new ResourceScript(this, script)); } } sink.close(); }