Search in sources :

Example 11 with EasyCrudService

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));
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) EasyCrudService(org.summerb.easycrud.api.EasyCrudService) TestDto1(integr.org.summerb.easycrud.TestDto1) Test(org.junit.Test)

Example 12 with EasyCrudService

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");
}
Also used : EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Query(org.summerb.easycrud.api.query.Query) PagerParams(org.summerb.easycrud.api.dto.PagerParams) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) Test(org.junit.Test)

Example 13 with EasyCrudService

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;
}
Also used : HasId(org.summerb.easycrud.api.dto.HasId) EasyCrudService(org.summerb.easycrud.api.EasyCrudService) Query(org.summerb.easycrud.api.query.Query) ArrayList(java.util.ArrayList) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 14 with EasyCrudService

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

Example 15 with EasyCrudService

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

Aggregations

EasyCrudService (org.summerb.easycrud.api.EasyCrudService)17 Test (org.junit.Test)8 HasId (org.summerb.easycrud.api.dto.HasId)8 TestDto1 (integr.org.summerb.easycrud.TestDto1)5 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)5 Query (org.summerb.easycrud.api.query.Query)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 PagerParams (org.summerb.easycrud.api.dto.PagerParams)3 DataSet (org.summerb.easycrud.api.dto.datapackage.DataSet)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Ref (org.summerb.easycrud.api.dto.relations.Ref)2 TestDto2 (integr.org.summerb.easycrud.TestDto2)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1