use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImpl method loadOneToManyReferences.
private EntityTypeToObjectsMap loadOneToManyReferences(Map<Ref, Set<Object>> refToReferencersIds) throws NotAuthorizedException {
Multimap<String, Entry<Ref, Set<Object>>> targetEntityToRef = HashMultimap.create();
for (Entry<Ref, Set<Object>> entry : refToReferencersIds.entrySet()) {
targetEntityToRef.put(entry.getKey().getToEntity(), entry);
}
EntityTypeToObjectsMap ret = new EntityTypeToObjectsMap();
for (String entityTypeCode : targetEntityToRef.keySet()) {
Collection<Entry<Ref, Set<Object>>> entries = targetEntityToRef.get(entityTypeCode);
List<Query> queries = new ArrayList<>(entries.size());
for (Entry<Ref, Set<Object>> entry : entries) {
Set<Object> ids = entry.getValue();
Ref ref = entry.getKey();
Object firstId = ids.iterator().next();
if (firstId instanceof Long) {
queries.add(Query.n().in(ref.getToField(), ids.toArray(new Long[0])));
} else if (firstId instanceof String) {
queries.add(Query.n().in(ref.getToField(), ids.toArray(new String[0])));
} else {
throw new IllegalStateException("such id type is not supported: " + firstId.getClass());
}
}
Query q = queries.size() == 1 ? queries.get(0) : Query.n().or(queries.toArray(new Query[0]));
EasyCrudService service = easyCrudServiceResolver.resolveByEntityType(entityTypeCode);
PaginatedList<HasId> results = service.query(PagerParams.ALL, q);
ret.put(entityTypeCode, new ArrayList<>(results.getItems()));
}
return ret;
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetLoaderImpl method loadManyToManyReferences.
private ManyToManyRefToReferenceesMap loadManyToManyReferences(Map<Ref, Set<Object>> manyToManyReferences) {
// NOTE: Queries to same types of referencees are not grouped. Should we
// impl this like we did for one2many?
ManyToManyRefToReferenceesMap ret = new ManyToManyRefToReferenceesMap();
for (Entry<Ref, Set<Object>> refToReferencersEntry : manyToManyReferences.entrySet()) {
EasyCrudService m2mServiceTmp = easyCrudServiceResolver.resolveByEntityType(refToReferencersEntry.getKey().getM2mEntity());
Preconditions.checkState(m2mServiceTmp instanceof EasyCrudM2mService);
EasyCrudM2mService m2mService = (EasyCrudM2mService) m2mServiceTmp;
Map<Object, List<HasId>> referenceeMap = m2mService.findReferenceeByReferencers(refToReferencersEntry.getValue());
ret.put(refToReferencersEntry.getKey(), referenceeMap);
}
return ret;
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class DataSetUpdaterOnEntityChangedEventImpl method updateDataSet.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void updateDataSet(DataSet dataSet, EntityChangedEvent<?> e) {
if (!e.isTypeOf(HasId.class)) {
return;
}
EasyCrudService service = easyCrudServiceResolver.resolveByDtoClass(e.getValue().getClass());
if (!dataSet.getTables().containsKey(service.getEntityTypeMessageCode())) {
return;
}
DataTable table = dataSet.getTables().get(service.getEntityTypeMessageCode());
HasId dto = (HasId) e.getValue();
if (e.getChangeType() == ChangeType.REMOVED) {
table.getRows().remove(dto.getId());
} else {
table.put(dto);
}
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class EasyCrudServiceResolverSpringImpl method discoverServices.
private Map<String, EasyCrudService> discoverServices() {
Preconditions.checkState(applicationContext != null, "applicationContext expected to be injected");
Map<String, EasyCrudService> foundBeans = applicationContext.getBeansOfType(EasyCrudService.class);
Map<String, EasyCrudService> ret = new HashMap<>();
for (Entry<String, EasyCrudService> entry : foundBeans.entrySet()) {
EasyCrudService service = entry.getValue();
EasyCrudService wasOverwritten = ret.put(service.getEntityTypeMessageCode(), service);
if (wasOverwritten != null) {
log.warn("Ambigious EasyCrudService for same entityTypeMessageCode 1st " + wasOverwritten + " and 2nd " + service + " named " + entry.getKey());
}
}
return ret;
}
use of org.summerb.easycrud.api.EasyCrudService in project summerb by skarpushin.
the class EasyCrudServiceResolverSpringImpl method discoverServicesByClass.
private Map<Class<?>, EasyCrudService> discoverServicesByClass() {
Preconditions.checkState(applicationContext != null, "applicationContext expected to be injected");
Map<String, EasyCrudService> foundBeans = applicationContext.getBeansOfType(EasyCrudService.class);
Map<Class<?>, EasyCrudService> ret = new HashMap<>();
for (Entry<String, EasyCrudService> entry : foundBeans.entrySet()) {
EasyCrudService service = entry.getValue();
EasyCrudService wasOverwritten = ret.put(service.getDtoClass(), service);
if (wasOverwritten != null) {
log.warn("Ambigious EasyCrudService for same dtoClass 1st " + wasOverwritten + " and 2nd " + service + " named " + entry.getKey());
}
}
return ret;
}
Aggregations