Search in sources :

Example 1 with GenericEntityNotFoundException

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);
    }
}
Also used : Query(org.summerb.easycrud.api.query.Query) GenericEntityNotFoundException(org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException) GenericEntityNotFoundException(org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException) EntityNotFoundException(org.summerb.easycrud.api.exceptions.EntityNotFoundException) NotAuthorizedException(org.summerb.security.api.exceptions.NotAuthorizedException)

Example 2 with GenericEntityNotFoundException

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);
    }
}
Also used : Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) GenericEntityNotFoundException(org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException)

Aggregations

GenericEntityNotFoundException (org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException)2 EntityNotFoundException (org.summerb.easycrud.api.exceptions.EntityNotFoundException)1 Query (org.summerb.easycrud.api.query.Query)1 Article (org.summerb.minicms.api.dto.Article)1 RenderedArticle (org.summerb.minicms.api.dto.consuming.RenderedArticle)1 NotAuthorizedException (org.summerb.security.api.exceptions.NotAuthorizedException)1