Search in sources :

Example 1 with BookmarkEntity

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

the class BookmarksResource method getBookmarksAsJsonArray.

@GET
@Produces(MediaType.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.entity.BookmarkEntity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with BookmarkEntity

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

the class BookmarksResource method postForm.

@POST
@Consumes(MediaType.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(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.entity.BookmarkEntity) URI(java.net.URI) Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark.util.tx.Transactional) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

URI (java.net.URI)2 BookmarkEntity (org.glassfish.jersey.examples.bookmark.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.util.tx.Transactional)1