public void invoke(RequestContext context, String action) throws RegistryException {
Resource resource = context.getResource();
String currentState = resource.getProperty(stateProperty);
int stateIndex = states.indexOf(currentState);
if (stateIndex == -1) {
throw new RegistryException("State '" + currentState + "' is not valid!");
}
String newState;
if (PROMOTE.equals(action)) {
if (stateIndex == states.size() - 1) {
throw new RegistryException("Can't promote beyond end of configured lifecycle!");
}
// Make sure all conditions are met
List<Condition> conditions = transitions.get(currentState);
if (conditions != null) {
for (Condition condition : conditions) {
if (!condition.isTrue(resource)) {
throw new RegistryException(
"Condition failed - " + condition.getDescription());
}
}
}
newState = states.get(stateIndex + 1);
} else if (DEMOTE.equals(action)) {
if (stateIndex == 0) {
throw new RegistryException("Can't demote beyond start of configured lifecycle!");
}
newState = states.get(stateIndex - 1);
}
else {
return;