Search in sources :

Example 1 with CrudQueryResult

use of org.summerb.approaches.jdbccrud.rest.dto.CrudQueryResult in project summerb by skarpushin.

the class EasyCrudRestControllerBase method resolveReferences.

private void resolveReferences(List<String> referencesToResolve, CrudQueryResult<TId, TDto> ret, List<TDto> items) throws EntityNotFoundException, NotAuthorizedException {
    Preconditions.checkState(dataSetLoader != null, "DataSetLoader is required to resolve references");
    Preconditions.checkState(referencesRegistry != null, "referencesRegistry is required to resolve references");
    DataSet ds = new DataSet();
    DataTable<TId, TDto> table = new DataTable<>(service.getEntityTypeMessageCode());
    table.putAll(items);
    ds.getTables().put(table.getName(), table);
    List<Ref> references = referencesToResolve.stream().map(name -> referencesRegistry.getRefByName(name)).collect(Collectors.toList());
    Ref[] refsArr = (Ref[]) references.toArray(new Ref[references.size()]);
    dataSetLoader.resolveReferencedObjects(ds, refsArr);
    // now remove initial table from dataset because we don't want to
    // duplicate this. It's already populated to rows
    ds.getTables().remove(table.getName());
    // x. ret
    ret.setRefsResolved(references.stream().collect(Collectors.toMap(Ref::getName, Function.identity())));
    ret.setRefs(ds);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) PermissionsResolverStrategy(org.summerb.approaches.jdbccrud.rest.permissions.PermissionsResolverStrategy) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) SingleItemResult(org.summerb.approaches.jdbccrud.rest.dto.SingleItemResult) RestExceptionTranslator(org.summerb.approaches.springmvc.security.implsrest.RestExceptionTranslator) HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) Autowired(org.springframework.beans.factory.annotation.Autowired) DataTable(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable) Function(java.util.function.Function) InitializingBean(org.springframework.beans.factory.InitializingBean) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) RequestBody(org.springframework.web.bind.annotation.RequestBody) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) PutMapping(org.springframework.web.bind.annotation.PutMapping) GenericFilterBean(org.springframework.web.filter.GenericFilterBean) DataSetLoader(org.summerb.approaches.jdbccrud.api.relations.DataSetLoader) GetMapping(org.springframework.web.bind.annotation.GetMapping) OrderBy(org.summerb.approaches.jdbccrud.api.query.OrderBy) MultipleItemsResult(org.summerb.approaches.jdbccrud.rest.dto.MultipleItemsResult) Ref(org.summerb.approaches.jdbccrud.api.dto.relations.Ref) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ReferencesRegistry(org.summerb.approaches.jdbccrud.api.relations.ReferencesRegistry) PostMapping(org.springframework.web.bind.annotation.PostMapping) PathVariablesMap(org.summerb.approaches.jdbccrud.rest.commonpathvars.PathVariablesMap) MediaType(org.springframework.http.MediaType) FilteringParamsToQueryConverterImpl(org.summerb.approaches.jdbccrud.mvc.filter.FilteringParamsToQueryConverterImpl) BeansException(org.springframework.beans.BeansException) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) QueryNarrowerStrategy(org.summerb.approaches.jdbccrud.rest.querynarrower.QueryNarrowerStrategy) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Query(org.summerb.approaches.jdbccrud.api.query.Query) FilteringParamsToQueryConverter(org.summerb.approaches.jdbccrud.mvc.filter.FilteringParamsToQueryConverter) EasyCrudQueryParams(org.summerb.approaches.jdbccrud.mvc.model.EasyCrudQueryParams) CrudQueryResult(org.summerb.approaches.jdbccrud.rest.dto.CrudQueryResult) NotAuthorizedException(org.summerb.approaches.security.api.exceptions.NotAuthorizedException) ApiIgnore(springfox.documentation.annotations.ApiIgnore) List(java.util.List) DataSet(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet) CollectionUtils(org.springframework.util.CollectionUtils) EntityNotFoundException(org.summerb.approaches.jdbccrud.api.exceptions.EntityNotFoundException) Preconditions(com.google.common.base.Preconditions) ApplicationContextAware(org.springframework.context.ApplicationContextAware) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) DataTable(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable) Ref(org.summerb.approaches.jdbccrud.api.dto.relations.Ref) DataSet(org.summerb.approaches.jdbccrud.api.dto.datapackage.DataSet)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 BeansException (org.springframework.beans.BeansException)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ApplicationContextAware (org.springframework.context.ApplicationContextAware)1 MediaType (org.springframework.http.MediaType)1 CollectionUtils (org.springframework.util.CollectionUtils)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1 RequestBody (org.springframework.web.bind.annotation.RequestBody)1 RequestParam (org.springframework.web.bind.annotation.RequestParam)1