use of org.summerb.easycrud.api.query.Query in project summerb by skarpushin.
the class EasyCrudM2mServiceImpl method findReferenceeByReferencer.
@Override
public List<T2Dto> findReferenceeByReferencer(T1Id referencerId) {
try {
Preconditions.checkArgument(referencerId != null, "referencerId is required");
Query q = buildQueryToFindReferenceeByReferencerId(referencerId);
List<ManyToManyDto<T1Id, T2Id>> m2mPairs = query(PagerParams.ALL, q).getItems();
if (m2mPairs.size() == 0) {
return Collections.emptyList();
}
Set<T2Id> referenceeIds = collectReferenceeIds(m2mPairs);
return serviceTo.query(PagerParams.ALL, buildQueryToFindObjectsByIds(referenceeIds)).getItems();
} catch (Throwable t) {
throw new RuntimeException("Failed to find " + serviceTo.getEntityTypeMessageCode() + " refernced by " + serviceFrom.getEntityTypeMessageCode() + " identified by " + referencerId, t);
}
}
use of org.summerb.easycrud.api.query.Query in project summerb by skarpushin.
the class EasyCrudControllerBase method ajaxList.
@RequestMapping(method = RequestMethod.POST, value = "ajaxList")
@ResponseBody
public Map<String, ? extends Object> ajaxList(@RequestBody EasyCrudQueryParams filteringParams, HttpServletResponse response) throws Exception {
Query query = filteringParamsToQueryConverter.convert(filteringParams.getFilterParams(), service.getDtoClass());
PaginatedList<TDto> results = service.query(filteringParams.getPagerParams(), query, filteringParams.getOrderBy());
return Collections.singletonMap(ATTR_LIST, results);
}
use of org.summerb.easycrud.api.query.Query in project summerb by skarpushin.
the class FilteringParamsToQueryConverterImpl method convert.
@Override
public Query convert(Map<String, FilteringParam> filterParams, Class<?> dtoClazz) {
if (filterParams == null || filterParams.isEmpty()) {
return null;
}
try {
Query ret = Query.n();
for (Entry<String, FilteringParam> entry : filterParams.entrySet()) {
String fname = entry.getKey();
String[] values = entry.getValue().getValues();
Class<?> type = getFieldType(dtoClazz, fname);
boolean isStringType = String.class.equals(type);
boolean isNumericType = int.class.equals(type) || long.class.equals(type) || Integer.class.equals(type) || Long.class.equals(type);
boolean isBooleanType = boolean.class.equals(type) || Boolean.class.equals(type);
String command = entry.getValue().getCommand();
addFilteringParamToQUery(fname, command, values, type, isStringType, isNumericType, isBooleanType, ret);
}
return ret;
} catch (Throwable t) {
throw new RuntimeException("Failed to parse filtering params", t);
}
}
use of org.summerb.easycrud.api.query.Query in project summerb by skarpushin.
the class QueryNarrowerStrategyFieldBased method narrow.
@Override
public Query narrow(Query optionalQuery, PathVariablesMap pathVariables) {
Query ret;
if (optionalQuery == null) {
ret = Query.n();
} else {
if (hasRestrictionOnField(optionalQuery, fieldName)) {
return optionalQuery;
}
ret = optionalQuery;
}
ret = doNarrow(ret, pathVariables);
return ret;
}
Aggregations