use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectOneLoadOk.
@Test
public void testLoadObjectsByIds_ExpectOneLoadOk() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
TestDto1 dto = new TestDto1();
when(service.findById(1)).thenReturn(dto);
List<HasId> ret = fixture.loadObjectsByIds(ids(1), "dto1");
assertNotNull(ret);
assertEquals(1, ret.size());
assertEquals(dto, ret.get(0));
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByLongsNfe.
@Test(expected = GenericEntityNotFoundException.class)
public void testLoadObjectsByIds_ExpectManyLoadByLongsNfe() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Collections.emptyList(), 0);
when(service.query(any(PagerParams.class), any(Query.class))).thenReturn(mockret);
fixture.loadObjectsByIds(ids(1L, 2L), "dto1");
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImpl method loadObjectsByIds.
@Override
public List<HasId> loadObjectsByIds(Set<Object> ids, String entityTypeName) throws EntityNotFoundException, NotAuthorizedException {
Preconditions.checkArgument(!CollectionUtils.isEmpty(ids));
EasyCrudService service = easyCrudServiceResolver.resolveByEntityType(entityTypeName);
Object firstId = ids.iterator().next();
List<HasId> ret = new ArrayList<>(ids.size());
if (ids.size() == 1) {
HasId loaded = loadOne(firstId, service);
ret.add(loaded);
} else if (firstId instanceof Long || firstId instanceof String) {
Query query;
if (firstId instanceof String) {
query = Query.n().in(HasId.FN_ID, ids.toArray(new String[0]));
} else {
query = Query.n().in(HasId.FN_ID, ids.toArray(new Long[0]));
}
List loaded = loadMultipleByQuery(query, service);
assertFound(loaded.size() == ids.size(), entityTypeName, "One of: " + Arrays.toString(ids.toArray()));
ret.addAll(loaded);
} else {
List<HasId> loaded = loadOneByOne(ids, service);
ret.addAll(loaded);
}
return ret;
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class EasyCrudServiceResolverSpringImpl method resolveByDtoClass.
@Override
public EasyCrudService resolveByDtoClass(Class<?> entityClass) {
getServicesMap();
EasyCrudService ret = servicesMapByClass.get(entityClass);
Preconditions.checkArgument(ret != null, "Serivce for that entity (by class) wasn't found: " + entityClass);
return ret;
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class EasyCrudServiceResolverSpringImpl method resolveByEntityType.
@Override
public EasyCrudService resolveByEntityType(String entityName) {
EasyCrudService ret = getServicesMap().get(entityName);
Preconditions.checkArgument(ret != null, "Serivce for that entity wasn't found: " + entityName);
return ret;
}
Aggregations