@POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 @Produces(BeeterMediaType.BEETER_AUTH_TOKEN)
 public Response registerUser(
     @FormParam("loginid") String loginid,
     @FormParam("password") String password,
     @FormParam("email") String email,
     @FormParam("fullname") String fullname,
     @Context UriInfo uriInfo)
     throws URISyntaxException {
   if (loginid == null || password == null || email == null || fullname == null)
     throw new BadRequestException("all parameters are mandatory");
   UserDAO userDAO = new UserDAOImpl();
   User user = null;
   AuthToken authToken = null;
   try {
     user = userDAO.createUser(loginid, password, email, fullname);
     authToken = (new AuthTokenDAOImpl()).createAuthToken(user.getId());
   } catch (UserAlreadyExistsException e) {
     throw new WebApplicationException("loginid already exists", Response.Status.CONFLICT);
   } catch (SQLException e) {
     throw new InternalServerErrorException();
   }
   URI uri = new URI(uriInfo.getAbsolutePath().toString() + "/" + user.getId());
   return Response.created(uri).type(BeeterMediaType.BEETER_AUTH_TOKEN).entity(authToken).build();
 }
 @PUT
 @Consumes(MediaType.APPLICATION_XML)
 public Response putTaskData(String value) {
   Response res = null;
   // add your code here
   // first check if the Entity exists in the datastore
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
   syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
   Key entKey = KeyFactory.createKey("TaskData", keyname);
   Date date = new Date();
   try {
     // if it is, signal that we updated the entity
     Entity ts = datastore.get(entKey);
     ts.setProperty("value", value);
     ts.setProperty("date", date);
     datastore.put(ts);
     res = Response.noContent().build();
   } catch (EntityNotFoundException e) {
     // if it is not, create it and
     // signal that we created the entity in the datastore
     Entity taskdata = new Entity("TaskData", keyname);
     taskdata.setProperty("value", value);
     taskdata.setProperty("date", date);
     datastore.put(taskdata);
     res = Response.created(uriInfo.getAbsolutePath()).build();
   }
   TaskData td = new TaskData(keyname, value, date);
   syncCache.put(keyname, td);
   return res;
 }
示例#3
0
 @POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 @Produces(GrouptalkMediaType.GROUPTALK_AUTH_TOKEN)
 public Response createJoinGroup(
     @FormParam("userid") String userid,
     @FormParam("groupid") String groupid,
     @Context UriInfo uriInfo)
     throws URISyntaxException {
   if (userid == null || groupid == null)
     throw new BadRequestException("all parameters are mandatory");
   JoinGroupDAO joinGroupDAO = new JoinGroupDAOImpl();
   JoinGroup joinGroup = null;
   AuthToken authenticationToken = null;
   try {
     joinGroup =
         joinGroupDAO.createJoinGroup(securityContext.getUserPrincipal().getName(), groupid);
   } catch (SQLException e) {
     throw new InternalServerErrorException();
   }
   URI uri = new URI(uriInfo.getAbsolutePath().toString() + "/" + joinGroup.getUserid());
   return Response.created(uri)
       .type(GrouptalkMediaType.GROUPTALK_InterestGroups)
       .entity(joinGroup)
       .build();
 }
  @Path(("/registrar"))
  @POST
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MusicloudMediaType.MUSICLOUD_AUTH_TOKEN)
  public Response registerUser(
      @FormParam("login") String login,
      @FormParam("nombre") String nombre,
      @FormParam("apellidos") String apellidos,
      @FormParam("email") String email,
      @FormParam("password") String password,
      @Context UriInfo uriInfo)
      throws URISyntaxException {
    if (login == null || nombre == null || apellidos == null || password == null || email == null)
      throw new BadRequestException("Se necesitan todos los parametros");
    UserDAO userDAO = new UserDAOImpl();
    User user = null;

    try {
      user = userDAO.crear_usuario_registrado(login, nombre, apellidos, email, password);

    } catch (UserAlreadyExistsException e) {
      throw new WebApplicationException("Este login ya existe ", Response.Status.CONFLICT);
    } catch (SQLException e) {
      throw new InternalServerErrorException();
    }
    URI uri = new URI(uriInfo.getAbsolutePath().toString() + "/" + user.getId());
    return Response.ok().build();
  }