use of org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException 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 {
if (pair == null) {
throw new GenericEntityNotFoundException(getEntityTypeMessageCode(), "" + referencerId + "<->" + referenceeId);
}
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.easycrud.api.exceptions.GenericEntityNotFoundException in project summerb by skarpushin.
the class ArticleRenderingContext method getReferencedArticle.
protected Article getReferencedArticle(String articleKey) throws GenericEntityNotFoundException {
if (referencedArticles.containsKey(articleKey)) {
return referencedArticles.get(articleKey);
}
try {
Article ret = articleService.findArticleByKeyAndLocale(articleKey, locale);
if (ret == null) {
throw new GenericEntityNotFoundException("article", articleKey);
}
referencedArticles.put(articleKey, ret);
registerReferencedArticle(ret.getId());
return ret;
} catch (Throwable e) {
Throwables.throwIfInstanceOf(e, GenericEntityNotFoundException.class);
throw new RuntimeException("Failed to find effective referenced article permutation " + articleKey, e);
}
}
Aggregations