use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.
the class DomLoaderDeviceGatewayTest method testResolveCollectionElementType_expectCorrectFieldTypeResolution.
@Test
public void testResolveCollectionElementType_expectCorrectFieldTypeResolution() {
// Deps and fixture
DataSetLoader dataSetLoader = mock(DataSetLoader.class);
EasyCrudServiceResolver easyCrudServiceResolver = mock(EasyCrudServiceResolver.class);
DomLoaderImpl f = new DomLoaderImpl(dataSetLoader, easyCrudServiceResolver);
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(Env.class, "devices");
// test
Class<HasId<Object>> elType = f.resolveCollectionElementType(pd);
assertEquals(Device.class, elType);
}
use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.
the class EasyCrudRestControllerBase method resolveReferences.
protected 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);
}
use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.
the class DataSetLoaderTest method testResolveReferencedObjects_ExpectDirectReferencesLoadedOk.
@Test
public void testResolveReferencedObjects_ExpectDirectReferencesLoadedOk() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
DataSetLoader loader = buildLoaderCase1();
TestDto1 d1i1 = new TestDto1();
d1i1.setEnv("d1i1");
d1i1.setLinkToFullDonwload("required");
d1i1 = testDto1Service.create(d1i1);
TestDto2 d2i1 = new TestDto2();
d2i1.setEnv(d1i1.getId());
d2i1.setLinkToFullDonwload("required");
d2i1 = testDto2Service.create(d2i1);
TestDto3 d3i1 = new TestDto3();
d3i1.setLinkToDtoTwo(d2i1.getId());
d3i1 = testDto3Service.create(d3i1);
DataSet result = new DataSet();
Map<String, Set<Object>> idsToLoad = new HashMap<String, Set<Object>>();
idsToLoad.put(testDto3Service.getEntityTypeMessageCode(), ids(d3i1.getId()));
loader.loadObjectsByIds(idsToLoad, result);
loader.resolveReferencedObjects(result, Refs.ref3to2mand, Refs.ref2to1);
assertNotNull(result.get(testDto2Service.getEntityTypeMessageCode()).find(d2i1.getId()));
assertNotNull(result.get(testDto1Service.getEntityTypeMessageCode()).find(d1i1.getId()));
}
use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.
the class DataSetLoaderTest method testResolveReferencedObjects_ExpectOneToManyDirectsLoadedOk.
@Test
public void testResolveReferencedObjects_ExpectOneToManyDirectsLoadedOk() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
DataSetLoader loader = buildLoaderCase1();
TestDto2 d2i1 = new TestDto2();
d2i1.setEnv("required");
d2i1.setLinkToFullDonwload("required");
d2i1 = testDto2Service.create(d2i1);
TestDto3 d3i1 = new TestDto3();
d3i1.setLinkToDtoTwo(d2i1.getId());
d3i1 = testDto3Service.create(d3i1);
TestDto3 d3i2 = new TestDto3();
d3i2.setLinkToDtoTwo(d2i1.getId());
d3i2 = testDto3Service.create(d3i2);
DataSet result = new DataSet();
result.get(testDto2Service.getEntityTypeMessageCode()).put(d2i1);
loader.resolveReferencedObjects(result, Refs.ref3to2mand.reverse());
assertNotNull(result.get(testDto3Service.getEntityTypeMessageCode()).find(d3i1.getId()));
assertNotNull(result.get(testDto3Service.getEntityTypeMessageCode()).find(d3i2.getId()));
}
use of org.summerb.easycrud.api.relations.DataSetLoader in project summerb by skarpushin.
the class DataSetLoaderTest method testLoadObjectsByIds_ExpectTwoObjsOfSameTypeLoadedOk.
@Test
public void testLoadObjectsByIds_ExpectTwoObjsOfSameTypeLoadedOk() throws EntityNotFoundException, NotAuthorizedException, FieldValidationException {
DataSetLoader loader = buildLoaderCase1();
TestDto2 d2i1 = new TestDto2();
d2i1.setEnv("d2i1");
d2i1.setLinkToFullDonwload("asdad");
d2i1 = testDto2Service.create(d2i1);
TestDto2 d2i2 = new TestDto2();
d2i2.setEnv("d2i2");
d2i2.setLinkToFullDonwload("asdad");
d2i2 = testDto2Service.create(d2i2);
List<HasId> result = loader.loadObjectsByIds(ids(d2i1, d2i2), testDto2Service.getEntityTypeMessageCode());
assertNotNull(result);
assertEquals(2, result.size());
}
Aggregations