Package hibernateLogic

Examples of hibernateLogic.DatabaseTools


       
      }
      else
      {
        // Set up your database Tools
        DatabaseTools myTools = new DatabaseTools();
       
        // Make sure the email is not already registered
        boolean userExists = myTools.dataSearch("User", "email", email);

      // Return false if a user is found!
      if(userExists){
        return UserFactory.id(0); //ID of zero means failed to find
      }
      else{
        // Not found? Create the new user and add them to the database
        User newUser = UserFactory.createUser(firstName,lastName,email,password);
        int myID = myTools.dataEntry(newUser);
       
        // search the database to confirm
        boolean userFound = myTools.dataSearch("User", "email", newUser.getEmail());
         
        // Respond to let them know it was successful (like login API)
        if(userFound){
          return UserFactory.id(myID); //return ID
        }
View Full Code Here


     
      // Create object to hold the user
      User deleteUser;
     
      // Set up your database Tools
    DatabaseTools myTools = new DatabaseTools();
     
    // Confirm user exists (and correct password)
      boolean userFound = myTools.dataSearch("User", "email", email, "password", password);
   
    // If not found return false response
    if(!userFound){
      return UserFactory.validUser(false);
    }
    // if yes extract the user
    else{
      try {
        deleteUser = myTools.getUser(email, password);
      } catch (Exception e)
      {
        // This method throws an error, we made sure this does not get thrown
        // with the previous search made so you can catch this error here and not worry.
        return UserFactory.validUser(false)
      }
    }
     
      // Remove user from table
    myTools.dataRemoval(deleteUser);
   
    // If user is not found return true! That means successful deletion.
    return UserFactory.validUser(!myTools.dataSearch("User", "email", email, "password", password));
    }
View Full Code Here

       
      }
      else
      {
        // Set up your database Tools
        DatabaseTools myTools = new DatabaseTools();
       
        // See if the user exists and if the password is correct
        boolean userFound = myTools.dataSearch("User", "email", email, "password", password);
       
        // If found create StatusOutput=TRUE and return
        if(userFound){
          ObjectRetrievalTools<User> myUser = new ObjectRetrievalTools<User>();
          User test = myUser.getObject(Table.User, "email", email);
View Full Code Here

       
      }
      else
      {
        // Set up your database Tools
        DatabaseTools myTools = new DatabaseTools();
       
        // See if the user exists and if the password is correct
        boolean userFound = myTools.dataSearch("User", "email", email, "password", password);
       
        // If found create StatusOutput=TRUE and return
        if(userFound){
          User myUser = myTools.getUser(email, password);
          if(firstName != null){ myUser.setFirstName(firstName);}
          if(lastName != null){ myUser.setLastName(lastName);}
          myTools.dataUpdate(myUser);
          return UserFactory.validUser(true);
        }
       
        // If not found create StatusOutput=FALSE and return
        else {
View Full Code Here

      if (!APIKeyCheck.exists(apiKey)) {
        throw new Exception("Failed to find API key");
      }
      else {
        // set up database tool set here
        DatabaseTools myTools = new DatabaseTools();
       
        //first confirm id and password are correct
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        if (!userFound) {
          throw new Exception("Failed to find user" );
        }
        else
        {
          //check to see if any UserRoleGroup contain userId
          boolean groupFound = myTools.dataSearch("UserRoleGroup", "userId", userId);
         
          // if there are no groups then return an empty array
          if (!groupFound){
            return new GroupDetailsJson[0];
          }
View Full Code Here

       
      }
      else
      {
        // Set up your database Tools
        DatabaseTools myTools = new DatabaseTools();
       
        // Confirm user exists and has the correct password before letting them pass.
          boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);

        // Return false if a user is not found or password incorrect!
      if(!userFound)
      {
        return GroupFactory.validGroup(false);
      }
      else // If user verified
      {
        // See if the group already exists
         
        boolean groupFound = myTools.dataSearch("Group", "groupTitle", groupName);

        if(groupFound)
        {
          return GroupFactory.validGroup(false);
        }
        else
        {
          // create a topic instance from the GroupFactory
          Group newGroup = GroupFactory.createGroup(groupName, groupDescription);
            // apply data entry on the group instance
          int newGroupID = myTools.dataEntry(newGroup);
         
          // Creating the relational database entry - This is how the user and group are linked
          UserRoleGroup newRelationship = new UserRoleGroup(userId, newGroupID, 1, newGroup.getCreateDate());
          // Adding the relationship to the database
          int newUserRoleGroup = myTools.dataEntry(newRelationship);
           
          //Confirm Group exist by searching its id
          // WILL NEED TO ADD LOGIC IN THE FUTURE TO CLEAN THINGS UP IF ONLY ONE IS ADDED AND NOT THE OTHER
          boolean groupConfirmed = myTools.dataSearch("Group", "id", newGroupID);
          boolean relationshipConfirmed = myTools.dataSearch("UserRoleGroup", "id", newUserRoleGroup);
         
            // If successfully created and it exist in the database return true;
            if(groupConfirmed && relationshipConfirmed)
            {
              return GroupFactory.validGroup(true);
View Full Code Here

         }
        
         else {
          
           // Set up your database Tools
           DatabaseTools myTools = new DatabaseTools();
          
           // Confirm user exists and has the correct password before letting them pass.
             boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);

           // Return false if a user is not found or password incorrect!
         if(!userFound) {
          
           throw new Exception ("User not found");
         }
        
         else {
          
             //check if group exists first
           boolean groupFound = myTools.dataSearch("Group", "id", groupId);
          
           //group not found
           if(!groupFound) {
            
             return GroupFactory.validGroup(false);
           }
          
           //group found
           else {
            
             //check to see if user has permission to delete group (admin)
             //set up retrieval tools
             ObjectRetrievalTools<UserRoleGroup> objTool = new ObjectRetrievalTools<UserRoleGroup>();
            
             //return the UserRoleGroup
             UserRoleGroup urg = (UserRoleGroup)objTool.getObject(Table.UserRoleGroup, "userId", userId, "groupId", groupId);
            
             //get role id
             int admin = urg.getRoleId();
            
             //check for admin
             if (admin == 0) {
              
               throw new Exception ("User does not have admin privledges");
             }
            
             //admin confirmed
             else {
              
               boolean answer;
              
               //first check to see if group has any questions first
               //if there are questions, there will be answers as well
               if (answer = myTools.dataSearch("Question", "groupId", groupId)){
                
                 //get all the questions associated with the group id
                    ObjectRetrievalTools<Question> objTool2 = new ObjectRetrievalTools<Question>();
                    List<Question> questionList = objTool2.getObjectList(Table.Question, "groupId", groupId);
                   
                    //delete the questions from the db
                    for (Iterator<Question> questIterator = questionList.iterator(); questIterator.hasNext();) {
                      Question questionDelete = questIterator.next();
                      //get questionId for answer deletion
                      int questionId = questionDelete.getId();
                      myTools.dataRemoval(questionDelete);
                     
                      //get all the answers associated with the question id
                         ObjectRetrievalTools<Answer> objTool3 = new ObjectRetrievalTools<Answer>();
                         List<Answer> answerList = objTool3.getObjectList(Table.Answer, "questionId", questionId);
                        
                         //delete all the answers from the db
                         for (Iterator<Answer> ansIterator = answerList.iterator(); ansIterator.hasNext();) {
                           Answer answerDelete = ansIterator.next();
                           myTools.dataRemoval(answerDelete);       
                         }
                    }
               }
                              
               //group has no questions/answers
               else {}
                      
               //get all the UserRoleGroup associated with the group id
               //there should be at least 1 for the group creator
               ObjectRetrievalTools<UserRoleGroup> objTool4 = new ObjectRetrievalTools<UserRoleGroup>();
               List<UserRoleGroup> urgList = objTool4.getObjectList(Table.UserRoleGroup, "groupId", groupId);
              
               //delete all the UserRoleGroup from db
               for (Iterator<UserRoleGroup> iterator = urgList.iterator(); iterator.hasNext();) {
                 UserRoleGroup urgDelete = iterator.next();
                 myTools.dataRemoval(urgDelete);
               }
              
               //lastly, retrieve the actual group for deletion
               ObjectRetrievalTools<Group> objTool5 = new ObjectRetrievalTools<Group>();
               Group remGroup = (Group) objTool5.getObject(Table.Group, "id", groupId);
              
               //call the tools to remove the group from the db
               myTools.dataRemoval(remGroup);
              
               //return true when group is deleted
               return GroupFactory.validGroup(!myTools.dataSearch("Group", "id", groupId));
             }                       
           }
         }
         }
    }
View Full Code Here

        throw new Exception ("Failed to find your API key");
      }
     
      else {
        //load database tools
        DatabaseTools myTools = new DatabaseTools();
       
          //confirm user is valid
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        if(!userFound){
          throw new Exception ("User was not found");
      }
       
        else {
          //confirm you can find the group based on ID
          boolean groupConfirmed = myTools.dataSearch("Group", "id", groupId);
         
          if (!groupConfirmed){
            throw new Exception ("Group not found");
          }
         
View Full Code Here

        throw new Exception ("Failed to find you API key");
      }
     
      else {
        //set up db tools
        DatabaseTools myTools = new DatabaseTools();
       
        //check for valid user
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        if (!userFound) {
          throw new Exception ("User was not found");
        }
       
        else {
          //check if group exists
          boolean groupConfirmed = myTools.dataSearch("Group", "id", groupId);
         
          if (!groupConfirmed){
            throw new Exception ("Group not found");
          }
         
          else {
           
            // pull group using the ObjectRetrievalTools class
            ObjectRetrievalTools<Group> retrieval = new ObjectRetrievalTools<Group>();
           
            //pull group object
            Group group = retrieval.getObject(Table.Group, "id", groupId);
           
            //call method in GroupFactory to update Group object
            group = GroupFactory.updateGroup(group, groupTitle, groupDesc);
           
            //send updated group back to db
            myTools.dataUpdate(group);
           
            //create a GroupStatusJson
            GroupStatusJson statusJson = GroupFactory.validGroup(true);
           
            return statusJson;
View Full Code Here

      if (!APIKeyCheck.exists(apiKey)){
        throw new Exception("Failed to find your API key!");
      }
      else {
        // Set up your Database Tools
        DatabaseTools myTools = new DatabaseTools();
       
        // Start by confirming / finding the user
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        if (!userFound){
          throw new Exception ("User not found");
        }
       
        else {
          // next confirm / find the group
          boolean groupFound = myTools.dataSearch("Group", "id", groupId);
         
          if (!groupFound){
            throw new Exception ("Group not found");
          }
         
          else {
           
            //set up db tools to search for a user within a group
            DatabasePro<UserRoleGroup, Integer, Integer, String> myProTools = new DatabasePro<>();
           
            //returns a list searching for a user in a group. size will be either 1 or 0 depending on if they were found
            List<UserRoleGroup> userRoleGroupList = myProTools.getTypeList(Table.UserRoleGroup, Column.groupId, groupId, Column.userId, userId);
           
            //user was not found to be part of the group
            if (userRoleGroupList.size() == 0){
              throw new Exception("User is not a part of the group and can not add questions");
            }
           
            //user is a part of the group
            else {
             
              //create question using factory
              Question questionObj = QuestionFactory.createQuestionMC(userId, groupId, question);
             
              //add question to the database
              int newQuestionID = myTools.dataEntry(questionObj);
       
              //set up answers
              Answer correct= QuestionFactory.createAnswer(correctAnswer, 1, newQuestionID, true);
              Answer wrong1 = QuestionFactory.createAnswer(answer2,     2, newQuestionID, false);
              Answer wrong2 = QuestionFactory.createAnswer(answer3,     3, newQuestionID, false);
              Answer wrong3 = QuestionFactory.createAnswer(answer4,     4, newQuestionID, false);

              // Now adding the answers to the database
              int correctAnswerId = myTools.dataEntry(correct);

              int answer2Id = myTools.dataEntry(wrong1);

              int answer3Id = myTools.dataEntry(wrong2);

              int answer4Id = myTools.dataEntry(wrong3);

              // Now check that the question is correctly stored in the database
              boolean questionFound = myTools.dataSearch("Question", "id", newQuestionID);

              // Now check that the answers are correctly stored in the database
              boolean correctAnswerFound = myTools.dataSearch("Answer", "id", correctAnswerId);

              boolean answer2Found = myTools.dataSearch("Answer", "id", answer2Id);

              boolean answer3Found = myTools.dataSearch("Answer", "id", answer3Id);

              boolean answer4Found = myTools.dataSearch("Answer", "id", answer4Id);
            
              // Now check, if not all the database checks are true, return false status
              if(!(questionFound && correctAnswerFound && answer2Found && answer3Found && answer4Found)) {

                return new QuestionStatusJson(false);
View Full Code Here

TOP

Related Classes of hibernateLogic.DatabaseTools

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.