use of org.summerb.approaches.jdbccrud.api.exceptions.EntityNotFoundException in project summerb by skarpushin.
the class EasyCrudM2mServiceImpl method removeReferencee.
@Override
public void removeReferencee(T1Id referencerId, T2Id referenceeId) throws NotAuthorizedException {
try {
Query q = Query.n();
addEqQuery(ManyToManyDto.FN_SRC, referencerId, q);
addEqQuery(ManyToManyDto.FN_DST, referenceeId, q);
ManyToManyDto<T1Id, T2Id> pair = findOneByQuery(q);
try {
deleteById(pair.getId());
} catch (EntityNotFoundException e) {
// that's ok, we wanted it to not exist, it's not there. This
// state
// is acceptable
}
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, NotAuthorizedException.class);
throw new RuntimeException("Failed to remove reference from " + serviceFrom.getEntityTypeMessageCode() + " identified by " + referencerId + " to " + serviceTo.getEntityTypeMessageCode() + " identified by " + referenceeId, t);
}
}
use of org.summerb.approaches.jdbccrud.api.exceptions.EntityNotFoundException 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