Search in sources :

Example 1 with Bookmark

use of com.khartec.waltz.model.bookmark.Bookmark in project waltz by khartec.

the class BookmarksEndpoint method register.

@Override
public void register() {
    get(mkPath(BASE_URL, ":kind", ":id"), (request, response) -> {
        response.type(TYPE_JSON);
        EntityReference ref = getEntityReference(request);
        return bookmarkService.findByReference(ref);
    }, transformer);
    post(mkPath(BASE_URL), (request, response) -> {
        requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
        response.type(TYPE_JSON);
        Bookmark bookmark = readBody(request, Bookmark.class);
        LOG.info("Saving bookmark: " + bookmark);
        boolean isUpdate = bookmark.id().isPresent();
        return isUpdate ? bookmarkService.update(bookmark, getUsername(request)) : bookmarkService.create(bookmark, getUsername(request));
    }, transformer);
    delete(mkPath(BASE_URL, ":id"), (request, response) -> {
        requireRole(userRoleService, request, Role.BOOKMARK_EDITOR);
        response.type(TYPE_JSON);
        long bookmarkId = getId(request);
        Bookmark bookmark = bookmarkService.getById(bookmarkId);
        if (bookmark == null) {
            LOG.warn("Attempt made to delete non-existent bookmark: " + bookmarkId);
            return false;
        }
        LOG.info("Deleting bookmark: " + bookmark);
        return bookmarkService.deleteById(bookmark, getUsername(request));
    }, transformer);
}
Also used : Bookmark(com.khartec.waltz.model.bookmark.Bookmark) EntityReference(com.khartec.waltz.model.EntityReference)

Aggregations

EntityReference (com.khartec.waltz.model.EntityReference)1 Bookmark (com.khartec.waltz.model.bookmark.Bookmark)1