use of org.summerb.approaches.jdbccrud.api.relations.ReferencesRegistry in project summerb by skarpushin.
the class DataSetLoaderImplTest method buildMockedInstance.
private DataSetLoaderImpl buildMockedInstance() {
DataSetLoaderImpl ret = new DataSetLoaderImpl();
EasyCrudServiceResolver easyCrudServiceResolver = Mockito.mock(EasyCrudServiceResolver.class);
ret.setEasyCrudServiceResolver(easyCrudServiceResolver);
ReferencesRegistry referencesRegistry = Mockito.mock(ReferencesRegistry.class);
ret.setReferencesRegistry(referencesRegistry);
return ret;
}
use of org.summerb.approaches.jdbccrud.api.relations.ReferencesRegistry 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);
}
Aggregations