|
(→AHPSCRIPTS-30)
|
(→AHPSCRIPTS-102)
|
| Line 338: | |||
| bl.setProperty("Agents_not_deployed_too", null); | bl.setProperty("Agents_not_deployed_too", null); | ||
| }</pre> | }</pre> | ||
| + | = Based on Property That Contains Value of Agent Property = | ||
| + | ==== AHPSCRIPTS-10 ==== | ||
| + | <pre>import com.urbancode.anthill3.domain.agent.Agent; | ||
| + | import com.urbancode.anthill3.runtime.scripting.helpers.*; | ||
| + | public class PropertyEqualsAgentVar extends VariableEqualsCriteria { | ||
| + | String propertyname; | ||
| + | public PropertyEqualsAgentVar(String propertyname, String varName) { | ||
| + | super(varName); | ||
| + | this.propertyname = propertyname; | ||
| + | } | ||
| + | public Agent[] filter(Agent[] agents){ | ||
| + | String platform = PropertyLookup.get(propertyname); | ||
| + | this.setValue(platform); | ||
| + | return super.filter(agents); | ||
| + | } | ||
| + | } | ||
| + | // 'my.property.name' is the name of a project or workflow property that contains the value | ||
| + | // of the agent property named 'agent.property.name' | ||
| + | return Where.is(new PropertyEqualsAgentVar("my.property.name", "agent.property.name"));</pre> | ||
| + | ''If you want the filter to work on non-originating workflows where the property determinant was a workflow property on the originating workflow, then use:'' | ||
| + | <pre>import com.urbancode.anthill3.domain.agent.Agent; | ||
| + | import com.urbancode.anthill3.runtime.scripting.helpers.*; | ||
| + | import org.apache.log4j.*; | ||
| + | public class PropertyEqualsAgentVar extends VariableEqualsCriteria { | ||
| + | Logger log = Logger.getLogger(PropertyEqualsAgentVar.class); | ||
| + | String propertyname; | ||
| + | public PropertyEqualsAgentVar(String propertyname, String varName) { | ||
| + | super(varName); | ||
| + | this.propertyname = propertyname; | ||
| + | } | ||
| + | public Agent[] filter(Agent[] agents){ | ||
| + | String platform = PropertyLookup.get(propertyname); | ||
| + | if (platform == null || platform.length() == 0 || "null".equals(platform)) { | ||
| + | platform = BuildLifeLookup.getCurrent().getOriginatingWorkflow().getRequest().getProperty(propertyname); | ||
| + | } | ||
| + | log.warn("platform: " + platform); | ||
| + | this.setValue(platform); | ||
| + | return super.filter(agents); | ||
| + | } | ||
| + | } | ||
| + | // 'my.property.name' is the name of a project or workflow property that contains the value | ||
| + | // of the agent property named 'agent.property.name' | ||
| + | return Where.is(new PropertyEqualsAgentVar("my.property.name", "agent.property.name"));</pre> | ||
| + | ''Basic case'' | ||
| + | <pre>String propValue = PropertyLookup.get("property"); | ||
| + | return Where.is(Variable.equals("property", propValue));</pre> | ||