Search in sources :

Example 11 with Query

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);
    }
}
Also used : ManyToManyDto(org.summerb.easycrud.api.dto.relations.ManyToManyDto) Query(org.summerb.easycrud.api.query.Query)

Example 12 with Query

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);
}
Also used : Query(org.summerb.easycrud.api.query.Query) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with Query

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);
    }
}
Also used : Query(org.summerb.easycrud.api.query.Query)

Example 14 with Query

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;
}
Also used : Query(org.summerb.easycrud.api.query.Query)

Aggregations

Query (org.summerb.easycrud.api.query.Query)14 EasyCrudService (org.summerb.easycrud.api.EasyCrudService)4 HasId (org.summerb.easycrud.api.dto.HasId)4 ArrayList (java.util.ArrayList)3 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)3 TestDto1 (integr.org.summerb.easycrud.TestDto1)2 List (java.util.List)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 PagerParams (org.summerb.easycrud.api.dto.PagerParams)2 ManyToManyDto (org.summerb.easycrud.api.dto.relations.ManyToManyDto)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 DataSet (org.summerb.easycrud.api.dto.datapackage.DataSet)1 Ref (org.summerb.easycrud.api.dto.relations.Ref)1 EntityNotFoundException (org.summerb.easycrud.api.exceptions.EntityNotFoundException)1