Package models

Examples of models.User$UserMapper


    Type dataType = new TypeToken<Data<User>>(){}.getType();
    renderJSON(gson().toJson(data, dataType));
  }
 
  public static void addFamiliar(Long id, JsonObject body) throws ValidationException {
    User internal = User.findById(id);
    if(internal==null) {
      notFound();
    }
    User familiar = new Gson().fromJson(body, User.class);
    validation.valid(familiar);
    if(validation.hasErrors()) {
      throw new ValidationException(validation.errors());
    }
    familiar.insert();
    UserProfile user_profile = new UserProfile(familiar,
        Profile.findByType(Profile.ProfileType.FAMILIAR));
    user_profile.insert();
    InternshipFamiliar internshipFamiliar = new InternshipFamiliar(internal, familiar);
    internshipFamiliar.insert();
View Full Code Here


public class MeApi extends ApiSecured {
 
  protected static User getCurrentUser() {
    String username = Session.current().get(SessionConstants.USER);
    if(username.contains("@")) username = username.substring(0, username.indexOf("@"));
    User current = User.findByUsername(username);
    return current;
  }
View Full Code Here

    return current;
  }
 
 
  public static void familiars(Integer offset, Integer limit) {
    User internship = getCurrentUser();
    if(internship == null) {
      response.status = StatusCode.NOT_FOUND;
      return;
    }
    if(offset == null) offset = 0;
View Full Code Here

    data.data = InternshipFamiliar.paginateByInternship(InternshipFamiliar.findByInternship(internship), offset, limit);
    renderTemplate("api/userList.json", data);
  }
 
  public static void internals(Integer offset, Integer limit) {
    User familiar = getCurrentUser();
    if(familiar == null) {
      response.status = StatusCode.NOT_FOUND;
      return;
   
    if(offset == null) offset = 0;
    if(limit==null || limit > LIMIT || limit==0) {
      limit = LIMIT;
    }
    Data<User> data = new Data<User>();
    if(familiar.isAdmin()) {
      data.total = User.countInternals();
      data.data = User.getInternals(offset, limit);
     
    } else {
      data.total = InternshipFamiliar.countByFamiliar(familiar);
View Full Code Here

  public static void list(Integer offset, Integer limit) {
    if(offset == null) offset = 0;
    if(limit==null || limit > LIMIT || limit==0) {
      limit = LIMIT;
    }
    User current = getCurrentUser();
    Data<InboxMessage> data = new Data<InboxMessage>();
    List<InboxMessage> messages = InboxMessage.paginate(InboxMessage.findReceived(current), offset, limit);
    data.total = InboxMessage.countReceived(current);
    data.data = messages;
    renderTemplate("api/messageList.json",data);
View Full Code Here

    data.data = messages;
    renderTemplate("api/messageList.json",data);
  }
 
  public static void get(Long id) {
    User current = getCurrentUser();
    InboxMessage message = InboxMessage.getReceived(id, current);
    if(message==null) notFound();
    //if(message.owner.id.longValue() != current.id.longValue()) forbidden();
    if(!message.readed) {
      message.readed = Boolean.TRUE;
View Full Code Here

    }
    renderTemplate("api/message.json",message);
  }
 
  public static void delete(Long id) {
    User current = getCurrentUser();
    InboxMessage message = InboxMessage.getReceived(id, current);
    if(message==null) notFound();
    //if(message.owner.id.longValue() != current.id.longValue()) forbidden();
    message.delete();
  }
View Full Code Here

    //if(message.owner.id.longValue() != current.id.longValue()) forbidden();
    message.delete();
  }
 
  public static void edit(Long id, JsonObject body) {
    User current = getCurrentUser();
    InboxMessage message = InboxMessage.getReceived(id, current);
    //Message msgJSON = gson().fromJson(body, Message.class);
    if(message==null) notFound();
    //if(message.id != msgJSON.id) notFound();
    //if(message.to.id.longValue() != current.id.longValue()) forbidden();
View Full Code Here

  public static void list(Integer offset, Integer limit) {
    if(offset == null) offset = 0;
    if(limit==null || limit > LIMIT || limit==0) {
      limit = LIMIT;
    }
    User current = getCurrentUser();
    Data<OutboxMessage> data = new Data<OutboxMessage>();
    List<OutboxMessage> messages = OutboxMessage.paginate(OutboxMessage.findSent(current), offset, limit);
    data.total = OutboxMessage.countSent(current);
    data.data = messages;
    for(OutboxMessage message : messages) {
View Full Code Here

    }
    ok();
  }
*/ 
  public static void add(JsonObject body) {
    User from = getCurrentUser();
    String text = body.get("body").getAsString();
    if(text != null && !("").equals(text)) {
      text = text.trim();
    }
    List<SharedContent> sharedContents = new ArrayList<SharedContent>();
    for(JsonElement element : body.get("contents").getAsJsonArray()) {
      JsonObject contentElement = element.getAsJsonObject();
      String type = contentElement.get("type").getAsString();
      String source = contentElement.get("source").getAsString();
      Long id = contentElement.get("id") != null ? contentElement.get("id").getAsLong() : null;
      if(type==null) {
        Error error = new Error("Type field is empty.");
        error.apply(request, response);
        return;
      }
      Content.ContentType contentType = Content.ContentType.valueOf(type.toUpperCase());
      if(contentType == null) {
        Error error = new Error(type + " is not a correct type value.");
        error.apply(request, response);
        return;
      }
      if(source==null) {
        Error error = new Error("Source field is empty");
        error.apply(request, response);
        return;
      }
      // Se comenta esto para permitir contenido externo
      /*if(id==null) {
        Error error = new Error("Id field is empty");
        error.apply(request, response);
        return;
      }*/
     
      SharedContent sharedContent = new Message().new SharedContent();
      sharedContent.type = contentType;
      sharedContent.id = id;
      sharedContent.source = source;
      sharedContents.add(sharedContent);
    }
   
    ArrayList<User> receivers = new ArrayList<User>();
    for(JsonElement element : body.get("receivers").getAsJsonArray()) {
      JsonObject toElement = element.getAsJsonObject();
      Long userId = toElement.get("id").getAsLong();
      String firstName = toElement.get("firstName").getAsString();
      if(userId == null) {
        Error error = new Error("The id field of " + firstName + " is empty.");
        error.apply(request, response);
        return;
      }
      User to = User.findById(userId);
      if(to == null) {
        Error error = new Error(firstName + " is not a registered user.");
        error.apply(request, response);
        return;
      }
View Full Code Here

TOP

Related Classes of models.User$UserMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.