use of org.glassfish.jersey.examples.bookmark.entity.UserEntity in project jersey by jersey.
the class UsersResource method getUsersAsJsonArray.
@GET
@Produces("application/json")
public JSONArray getUsersAsJsonArray() {
JSONArray uriArray = new JSONArray();
for (UserEntity userEntity : getUsers()) {
UriBuilder ub = uriInfo.getAbsolutePathBuilder();
URI userUri = ub.path(userEntity.getUserid()).build();
uriArray.put(userUri.toASCIIString());
}
return uriArray;
}
use of org.glassfish.jersey.examples.bookmark.entity.UserEntity in project jersey by jersey.
the class UserResource method putUser.
@PUT
@Consumes("application/json")
public Response putUser(JSONObject jsonEntity) throws JSONException {
String jsonUserid = jsonEntity.getString("userid");
if ((null != jsonUserid) && !jsonUserid.equals(userid)) {
return Response.status(409).entity("userids differ!\n").build();
}
// insert or update ?
final boolean newRecord = (null == userEntity);
if (newRecord) {
// new user record to be inserted
userEntity = new UserEntity();
userEntity.setUserid(userid);
}
userEntity.setUsername(jsonEntity.getString("username"));
userEntity.setEmail(jsonEntity.getString("email"));
userEntity.setPassword(jsonEntity.getString("password"));
if (newRecord) {
TransactionManager.manage(new Transactional(em) {
public void transact() {
em.persist(userEntity);
}
});
return Response.created(uriInfo.getAbsolutePath()).build();
} else {
TransactionManager.manage(new Transactional(em) {
public void transact() {
em.merge(userEntity);
}
});
return Response.noContent().build();
}
}
Aggregations