Ejemplo n.º 1
1
  /**
   * @deprecated use getAllModules instead. Doesn't twerk.
   * @return
   */
  public List<Module> getModules() {
    List<Module> modules = new ArrayList<Module>();

    ResultSet result = db.preformQuery("Select * From module");

    try {
      while (result.next()) {
        List links = new ArrayList();
        links = getModuleLinks(result.getString("moduleID"));
        Module module =
            new Module(
                result.getString("moduleID"),
                result.getString("moduleName"),
                result.getString("moduleSummery"),
                result.getString("moduleDescription"),
                links);
        modules.add(module);
      }

    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, e.toString(), "Problem with getting all modules");
    }

    return modules;
  }
Ejemplo n.º 2
0
  /**
   * Gets comments by module list id
   *
   * @param moduleListId
   * @return List DataModel.Comment
   */
  public List<Comment> getCommentsByModuleListId(String moduleListId) {

    List<Comment> comments = new ArrayList<Comment>();

    ResultSet result =
        db.preformQuery("SELECT * FROM Comments WHERE ModuleListID ='" + moduleListId + "'");

    try {
      while (result.next()) {
        Comment entry =
            new Comment(
                result.getInt("commentID"),
                result.getString("commentType"),
                result.getString("moduleListID"),
                result.getString("userID"),
                result.getString("commentDate"),
                result.getString("commentText"));

        comments.add(entry);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with select from getCommentsByModuleListId user", e);
    }

    return comments;
  }
Ejemplo n.º 3
0
  /**
   * Gets a user by the first and last name.
   *
   * @param firstName
   * @param lastName
   * @return DataModel.User
   */
  public User getUser(String firstName, String lastName) {

    ResultSet result =
        db.preformQuery(
            "SELECT * FROM users WHERE firstName = '"
                + firstName
                + "' AND lastName='"
                + lastName
                + "';");
    User user = new User();

    try {
      if (result.isBeforeFirst()) {
        result.next();
        user.setUserId(result.getString("userID"));
        user.setRole(result.getString("role"));
        user.setFirstName(result.getString("firstName"));
        user.setLastName(result.getString("lastName"));
        user.setBirthDate(result.getString("dateOfBirth"));
        user.setPhoneNumber(result.getString("phoneNummer"));
        user.setEmail(result.getString("email"));
        user.setAddress(result.getString("address"));
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem getting the user " + firstName + " " + lastName);
    }

    return user;
  }
Ejemplo n.º 4
0
  /**
   * Gets messages from a user.
   *
   * @param user
   * @return List DataModel.Messages
   */
  public List<Messages> getMessagesFromUser(String user) {
    List<Messages> messages = new ArrayList<Messages>();

    ResultSet result = db.preformQuery("SELECT * FROM Messages WHERE userIDFrom='" + user + "'");

    try {
      while (result.next()) {
        Messages entry =
            new Messages(
                result.getString("messageID"),
                result.getString("messageDate"),
                result.getString("userIDfrom"),
                result.getString("UserIDTo"),
                result.getString("headLine"),
                result.getString("content"));

        messages.add(entry);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with select from messages TO user", e);
    }

    return messages;
  }
Ejemplo n.º 5
0
  /**
   * Gets all the files that is delivered to the module. Module-id refers to a delivered task
   *
   * @param moduleId
   * @return List DataModel.ModuleFile
   */
  public List<ModuleFile> getModuleFiles(String moduleId) {
    ResultSet result =
        db.preformQuery(
            "SELECT * FROM "
                + Tables.MODULEDATEDELIVERY_TABLE
                + " WHERE moduleListID='"
                + moduleId
                + "';");

    List<ModuleFile> files = new ArrayList<ModuleFile>();

    try {
      while (result.next()) {
        ModuleFile file = new ModuleFile();
        file.setModuleFileId(result.getString("moduleFileID"));
        file.setModuleListId(result.getString("moduleListID"));
        file.setFile(result.getString("moduleFile"));

        files.add(file);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with getting module files for " + moduleId, e);
    }

    return files;
  }
Ejemplo n.º 6
0
  /**
   * Gets a delivered module.
   *
   * @param moduleId
   * @return DataModel.ModuleDelivery
   */
  public ModuleDelivery getDeliveryModule(String moduleId) {
    ResultSet result = db.preformQuery("SELECT * FROM " + Tables.MODULELIST_TABLE + ";");

    ModuleDelivery delivery = new ModuleDelivery();

    try {
      if (result.isBeforeFirst()) {
        result.next();
        delivery.setId(result.getString("moduleListID"));
        delivery.setUserId(result.getString("userID"));
        delivery.setUploadDate(result.getString("uploadDate"));
        delivery.setModuleTableId(result.getString("moduleID"));
        delivery.setModuleStatus(result.getString("moduleStatus"));
        delivery.setModuleAssessment(result.getString("moduleAssessment"));
        delivery.setmoduleAssessedBy(result.getString("moduleAssessedBy"));

        return delivery;
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting module for teacher or asTeacher");
    }

    return delivery;
  }
Ejemplo n.º 7
0
  /**
   * Gets all the delivered modules.
   *
   * @return List DataModel.ModuleDelivery
   */
  public List<ModuleDelivery> getDeliveredModuels() {
    List<ModuleDelivery> modules = new ArrayList<ModuleDelivery>();

    ResultSet result = db.preformQuery("SELECT * FROM " + Tables.MODULELIST_TABLE + ";");

    try {
      while (result.next()) {
        ModuleDelivery delivery = new ModuleDelivery();

        delivery.setId(result.getString("moduleListID"));
        delivery.setUserId(result.getString("userID"));
        delivery.setUploadDate(result.getString("uploadDate"));
        delivery.setModuleTableId(result.getString("moduleID"));
        delivery.setModuleStatus(result.getString("moduleStatus"));
        delivery.setModuleAssessment(result.getString("moduleAssessment"));

        modules.add(delivery);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting module for teacher or asTeacher");
    }

    return modules;
  }
Ejemplo n.º 8
0
  /**
   * Gets links to one module
   *
   * @param moduleID
   * @return List DataModel.ModuleResourceLinks
   */
  public List<ModuleResorceLinks> getModuleLinks(String moduleID) {
    List<ModuleResorceLinks> links = new ArrayList<ModuleResorceLinks>();

    ResultSet result =
        db.preformQuery("SELECT * FROM ModuleResorceLinks WHERE moduleID = '" + moduleID + "';");

    try {

      while (result.next()) {
        ModuleResorceLinks link =
            new ModuleResorceLinks(
                result.getInt("moduleLinkID"),
                result.getString("moduleID"),
                result.getString("linkName"),
                result.getString("link"),
                result.getString("linkTags"));
        links.add(link);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting ModuleResorceLinks for " + moduleID);
    }
    return links;
  }
Ejemplo n.º 9
0
  /**
   * Returns a user if the userId exists and the password is the right. If the user cannot login,
   * the user object values will be null.
   *
   * @param userId
   * @param password
   * @return DataModel.User
   */
  public User loginUser(int userId, String password) {
    ResultSet result =
        db.preformQuery(
            "SELECT * FROM users WHERE userID='"
                + Integer.toString(userId)
                + "' AND userPassword='******';");
    User user = new User();

    try {
      if (result.isBeforeFirst()) {
        result.next();
        user.setUserId(result.getString("userID"));
        user.setRole(result.getString("role"));
        user.setFirstName(result.getString("firstName"));
        user.setLastName(result.getString("lastName"));
        user.setBirthDate(result.getString("dateOfBirth"));
        user.setPhoneNumber(result.getString("phoneNummer"));
        user.setEmail(result.getString("email"));
        user.setAddress(result.getString("address"));
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, e.toString(), "Problem logging in the user " + userId);
    }

    return user;
  }
Ejemplo n.º 10
0
  /**
   * Get all users.
   *
   * @return List of DataModel.User
   */
  public List<User> getAllUsers() {
    List<User> users = new ArrayList<User>();

    ResultSet result = db.preformQuery("SELECT * FROM users;");

    try {
      while (result.next()) {
        User user = new User();

        user.setUserId(result.getString("userID"));
        user.setRole(result.getString("role"));
        user.setFirstName(result.getString("firstName"));
        user.setLastName(result.getString("lastName"));
        user.setBirthDate(result.getString("dateOfBirth"));
        user.setPhoneNumber(result.getString("phoneNummer"));
        user.setEmail(result.getString("email"));
        user.setAddress(result.getString("address"));

        users.add(user);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, e.toString(), "Problem with getting all the users");
    }

    return users;
  }
Ejemplo n.º 11
0
  /**
   * Checks if a module exist.
   *
   * @param moduleId
   * @return boolean
   */
  public boolean doesModuleExist(String moduleId) {
    try {
      ResultSet result =
          db.preformQuery(
              "SELECT * FROM " + Tables.MODULE_TABLE + " WHERE moduleID='" + moduleId + "';");

      if (result.isBeforeFirst()) return true;
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with checking if the module exists", e);
    }
    return false;
  }
Ejemplo n.º 12
0
  /**
   * Checks if a headline exists.
   *
   * @param userId
   * @param headLine
   * @return boolean
   */
  public boolean doesHeadLineExist(int userId, String headLine) {
    try {
      ResultSet result =
          db.preformQuery(
              "SELECT * FROM "
                  + Tables.BLOG_TABLE
                  + " WHERE userID='"
                  + userId
                  + "' AND headLine='"
                  + headLine
                  + "';");

      if (result.isBeforeFirst()) return true;
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, "Problem with checking if the blog post exists", e);
    }
    return false;
  }
Ejemplo n.º 13
0
  /**
   * Gets all blog entries
   *
   * @return List DataModel.Blog
   */
  public List<Blog> getAllBlogEntries() {
    List<Blog> blog = new ArrayList<Blog>();

    ResultSet result = db.preformQuery("SELECT * FROM blog;");

    try {
      while (result.next()) {
        Blog entry = new Blog();

        entry.setEntryId(result.getInt("entryID"));
        entry.setUser(this.getUser(Integer.parseInt(result.getString("userID"))));
        entry.setEntryDate(result.getString("entryDate"));
        entry.setHeadline(result.getString("headLine"));
        entry.setContent(result.getString("content"));

        blog.add(entry);
      }
    } catch (Exception e) {
      LogHandler.handler.append(LogHandler.warning.ERROR, "Problem with select from blog", e);
    }

    return blog;
  }
Ejemplo n.º 14
0
  /**
   * Gets all the modules.
   *
   * @return List DataModel.Module
   */
  public List<Module> getAllModules() {
    ResultSet result = db.preformQuery("SELECT * FROM " + Tables.MODULE_TABLE + ";");

    List<Module> moduleList = new ArrayList<Module>();

    try {
      while (result.next()) {
        Module module = new Module();
        module.setModuleID(result.getString("moduleID"));
        module.setModuleName(result.getString("moduleName"));
        module.setModuleSummary(result.getString("moduleSummary"));
        module.setModuleDescription(result.getString("moduleDescription"));
        moduleList.add(module);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting module for teacher or asTeacher");
    }

    return moduleList;
  }
Ejemplo n.º 15
0
  /**
   * Gets a module.
   *
   * @param moduleId
   * @return DataModel.Module
   */
  public Module getModule(String moduleId) {
    ResultSet result =
        db.preformQuery(
            "SELECT * FROM " + Tables.MODULE_TABLE + " WHERE moduleID ='" + moduleId + "';");

    Module module = new Module();

    try {
      if (result.isBeforeFirst()) {
        result.next();
        module.setModuleID(result.getString("moduleID"));
        module.setModuleName(result.getString("moduleName"));
        module.setModuleSummary(result.getString("moduleSummary"));
        module.setModuleDescription(result.getString("moduleDescription"));
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR,
          e.toString(),
          "Problem with getting module for teacher or asTeacher");
    }

    return module;
  }
Ejemplo n.º 16
0
  /**
   * Get the news feed as a List NewsFeed
   *
   * @return List of DataModel.NewsFeed
   */
  public List<NewsFeed> getNewsFeed() {
    List<NewsFeed> news = new ArrayList<NewsFeed>();

    ResultSet result = db.preformQuery("SELECT * FROM newsfeed;");

    try {
      while (result.next()) {
        NewsFeed newsFeed = new NewsFeed();

        newsFeed.setNewsId(result.getString("newsID"));
        newsFeed.setUser(this.getUser(Integer.parseInt(result.getString("userID"))));
        newsFeed.setPostDate(result.getString("postDate"));
        newsFeed.setHeadLine(result.getString("headLine"));
        newsFeed.setContent(result.getString("content"));

        news.add(newsFeed);
      }
    } catch (Exception e) {
      LogHandler.handler.append(
          LogHandler.warning.ERROR, e.toString(), "Problem with getting all the newsfeeds");
    }

    return news;
  }