use of org.motechproject.mds.util.InstanceSecurityRestriction in project motech by motech.
the class DefaultMotechDataService method executeQuery.
@Override
@Transactional
public <R> R executeQuery(QueryExecution<R> queryExecution) {
InstanceSecurityRestriction securityRestriction = validateCredentials();
Query query = repository.getPersistenceManager().newQuery(repository.getClassType());
return queryExecution.execute(query, securityRestriction);
}
use of org.motechproject.mds.util.InstanceSecurityRestriction in project motech by motech.
the class MdsBundleIT method verifyCustomQuery.
private void verifyCustomQuery() throws Exception {
List result = (List) service.executeQuery(new QueryExecution<List>() {
@Override
public List execute(Query query, InstanceSecurityRestriction restriction) {
query.setFilter("someString == param0");
query.declareParameters("java.lang.String param0");
return (List) QueryExecutor.execute(query, "anotherString", restriction);
}
});
assertEquals(1, result.size());
Class objClass = result.get(0).getClass();
assertInstanceOneDotOne(result.get(0), objClass);
List<String> names = (List<String>) service.executeSQLQuery(new SqlQueryExecution<List<String>>() {
@Override
public List<String> execute(Query query) {
Map<String, Integer> params = new HashMap<>();
params.put("param", 4);
return (List<String>) query.executeWithMap(params);
}
@Override
public String getSqlQuery() {
String driverName = sqlDBManager.getChosenSQLDriver();
if (driverName.equals(Constants.Config.MYSQL_DRIVER_CLASSNAME)) {
return "SELECT someString FROM MDS_FOO WHERE someInt = :param";
} else {
return "SELECT \"someString\" FROM \"MDS_FOO\" WHERE \"someInt\" = :param";
}
}
});
assertEquals(asList("notInSet"), names);
}
use of org.motechproject.mds.util.InstanceSecurityRestriction in project motech by motech.
the class RestrictionPropertyTest method getProperty.
@Override
protected Property getProperty() {
InstanceSecurityRestriction restriction = new InstanceSecurityRestriction();
restriction.setByCreator(true);
return new RestrictionProperty(restriction, "motech");
}
use of org.motechproject.mds.util.InstanceSecurityRestriction in project motech by motech.
the class TaskServiceImpl method findActiveTasksForTriggerSubject.
@Override
@Transactional
public List<Task> findActiveTasksForTriggerSubject(final String subject) {
List<Task> list = null;
if (isNotBlank(subject)) {
List enabledTasks = tasksDataService.executeQuery(new QueryExecution<List<Task>>() {
@Override
public List<Task> execute(Query query, InstanceSecurityRestriction restriction) {
String byTriggerSubject = "trigger.subject == param";
String isTaskActive = "enabled == true";
String isUsingTimeWindow = "useTimeWindow == true";
String filter = String.format("((%s) || (%s)) && (%s)", isTaskActive, isUsingTimeWindow, byTriggerSubject);
query.setFilter(filter);
query.declareParameters("java.lang.String param");
query.setOrdering("id asc");
return (List) QueryExecutor.execute(query, subject, restriction);
}
});
if (enabledTasks != null) {
checkChannelAvailableInTasks(enabledTasks);
list = checkTimeWindowInTasks(enabledTasks);
CollectionUtils.filter(list, tasksWithRegisteredChannel());
}
}
return list == null ? new ArrayList<>() : list;
}
use of org.motechproject.mds.util.InstanceSecurityRestriction in project motech by motech.
the class DefaultMotechDataService method validateCredentials.
protected InstanceSecurityRestriction validateCredentials(T instance) {
InstanceSecurityRestriction restriction = new InstanceSecurityRestriction();
restriction.setByOwner(securityMode == SecurityMode.OWNER);
restriction.setByCreator(securityMode == SecurityMode.CREATOR);
if (!restriction.isEmpty() && instance != null) {
restriction = checkInstanceAccess(instance, restriction);
}
return restriction;
}
Aggregations