String errMsg = "Invalid instance filter: " +filter;
log.error(errMsg);
throw new InstanceManagementException(errMsg);
}
if(!isSecureFilter(new InstanceFilter(filter), tenantProcessStore.getProcesses().keySet())){
String errMsg = "Instance deletion operation not permitted due to insecure filter: " +
filter;
log.error(errMsg);
throw new InstanceManagementException(errMsg);
}
if (filter.indexOf(" pid=") == -1) {
filter = filter + getTenantsProcessList(tenantProcessStore.getProcesses().keySet());
}
final InstanceFilter instanceFilter = new InstanceFilter(filter);
final List<Long> ret = new LinkedList<Long>();
try {
dbexec(new BpelDatabase.Callable<Object>() {
public Object run(BpelDAOConnection conn) throws IllegalAccessException {
Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
// Doing this to avoid any half done operation.
// For example if filter returns set of instance which are not owned by this tenant we should
// not delete other instances also.
for (ProcessInstanceDAO instance : instances) {
isOperationIsValidForTheCurrentTenant(instance.getProcess().getProcessId());
}
for (ProcessInstanceDAO instance : instances) {
instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class),
deleteMessageExchanges);
ret.add(instance.getInstanceId());
}
return null;
}
});
} catch (Exception e) {
String errMsg = "Exception during instance deletion. Filter: " +
instanceFilter.toString();
log.error(errMsg, e);
throw new InstanceManagementException(errMsg, e);
}
return ret.size();