Search in sources :

Example 1 with BookmarkEntity

use of org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity in project jersey by jersey.

the class BookmarksResource method postForm.

@POST
@Consumes("application/json")
public Response postForm(JSONObject bookmark) throws JSONException {
    final BookmarkEntity bookmarkEntity = new BookmarkEntity(getBookmarkId(bookmark.getString("uri")), userResource.getUserEntity().getUserid());
    bookmarkEntity.setUri(bookmark.getString("uri"));
    bookmarkEntity.setUpdated(new Date());
    bookmarkEntity.setSdesc(bookmark.getString("sdesc"));
    bookmarkEntity.setLdesc(bookmark.getString("ldesc"));
    userResource.getUserEntity().getBookmarkEntityCollection().add(bookmarkEntity);
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(userResource.getUserEntity());
        }
    });
    URI bookmarkUri = uriInfo.getAbsolutePathBuilder().path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
    return Response.created(bookmarkUri).build();
}
Also used : BookmarkEntity(org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity) URI(java.net.URI) Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with BookmarkEntity

use of org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity in project jersey by jersey.

the class BookmarksResource method getBookmarksAsJsonArray.

@GET
@Produces("application/json")
public JSONArray getBookmarksAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (BookmarkEntity bookmarkEntity : getBookmarks()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI bookmarkUri = ub.path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
        uriArray.put(bookmarkUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) BookmarkEntity(org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

URI (java.net.URI)2 BookmarkEntity (org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity)2 Date (java.util.Date)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 Transactional (org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional)1