Package hibernateLogic

Examples of hibernateLogic.DatabaseTools


        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 the group exists
          boolean groupFound = myTools.dataSearch("Group", "id", groupId);
         
          if (!groupFound){
            throw new Exception ("Group not found");
          }
         
          //group exists
          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 part of the group
            else {
             
               Question questionObj = QuestionFactory.createQuestionTF(userId, groupId, question);
                   
                    //add question to the database
                    int newQuestionID = myTools.dataEntry(questionObj);

                    // The logic to decide whether the correct answer is "True" or "False"
                    Answer trueAnswer, falseAnswer;
                   
                  // If the answer is true then "True" is true. If false, then "True" is false.
                  trueAnswer = QuestionFactory.createAnswer("True", 1, newQuestionID, answer);
                    falseAnswer = QuestionFactory.createAnswer("False", 2, newQuestionID, !answer);
               
                    // Now adding the answers to the database
                    int trueAnswerId = myTools.dataEntry(trueAnswer);
                    int falseAnswerId = myTools.dataEntry(falseAnswer);

                    // 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 trueAnswerFound = myTools.dataSearch("Answer", "id", trueAnswerId);

                    boolean falseAnswerFound = myTools.dataSearch("Answer", "id", falseAnswerId);

                    // Now check, if not all the database checks are true, return false status
                    if(!(questionFound && trueAnswerFound && falseAnswerFound)){
                      return new QuestionStatusJson(false);
                    }
View Full Code Here


      }
     
      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 the group exists
          boolean groupFound = myTools.dataSearch("Group", "id", groupId);
         
          if (!groupFound)
          {  // if group is not found, throw an exception
            throw new Exception ("Group not found");
          }
         
          //group exists
          else
          {
            // Confirm that question with this id exists
            boolean questionFound = myTools.dataSearch("Question", "id", questionId);
           
            if(!questionFound)
            {  // if question is not found, throw an exception
              throw new Exception ("Question not found!");
            }
            else // question is found
            {
             
              //get the answers list attributed to a specified question
              DatabasePro<Answer, Integer, Integer, String> myAnswerTools = new DatabasePro<>();
             
              List<Answer> answersList = myAnswerTools.getTypeList(Table.Answer, Column.questionId, questionId);
             
             
             
              if(!(answersList.size() > 0)) // no answers were found; this is a problem.
              {
                throw new Exception("There are no answers associated with this question.");
              }
              else
              {
                for(int i = 0; i < answersList.size(); i++)
                {
                  // Deleting the answer
                  myAnswerTools.dataRemoval(answersList.get(i));
                }
              }
             
              // setup tool to delete the question
              DatabasePro<Question, Integer, Integer, String> myQuestionTools = new DatabasePro<>();
             
              //set up retrieval tools
                 ObjectRetrievalTools<Question> objTool = new ObjectRetrievalTools<Question>();
                
                 //retrieve the Question
                 Question theQuestion = (Question)objTool.getObject(Table.Question, "id", questionId);
                 // Delete the question
              myQuestionTools.dataRemoval(theQuestion);
             
              // Now check that the question is correctly stored in the database
                questionFound = myTools.dataSearch("Question", "id", questionId);
                // get the answers list again, to check if they were deleted; list size 0 = deleted
              answersList = myAnswerTools.getTypeList(Table.Answer, Column.questionId, questionId);
             
              if(questionFound || answersList.size() > 0)
              {
View Full Code Here

        throw new Exception("Failed to find API key");
      }
      else
      {
        // set up database tool
        DatabaseTools myTools = new DatabaseTools();
       
        //first confirm the group with this id exists
        boolean groupFound = myTools.dataSearch("Group", "id", groupId);
       
        if (!groupFound)
        {
          throw new Exception("Failed to find a group with this id" );
        }
View Full Code Here

      }
     
      else {
       
        //set up db tools
        DatabaseTools myTools = new DatabaseTools();
       
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        //verify user exists
        if (!userFound){
          throw new Exception("User not found");
        }
View Full Code Here

      }
     
      else {
       
        //set up db tools
        DatabaseTools myTools = new DatabaseTools();
       
        boolean userFound = myTools.dataSearch("User", "id", userId, "password", password);
       
        //verify user exists
        if (!userFound){
          throw new Exception("User not found");
        }
       
        else {
         
          //set up pro tools
          DatabasePro<UserRoleGroup, Integer, Integer, String> myProTools = new DatabasePro<>();
         
          //list will either be 0 or 1 depending if the user was found
          List<UserRoleGroup> groupBelongs = myProTools.getTypeList(Table.UserRoleGroup, Column.groupId, groupId, Column.userId, userId);
         
          //empty list means user does not belong to the group
          if (groupBelongs.size() == 0) {
            throw new Exception("User does not belong to this group");
          }
         
          else {
           
            boolean invitedUserExists = myTools.dataSearch("User", "email", invitedEmail);
           
            if (!invitedUserExists) {
              throw new Exception("Invited email is not currently an existing user");
            }
           
            else {
             
              //set up object retrieval tools
                ObjectRetrievalTools<User> userLookup = new ObjectRetrievalTools<>();
               
                //retrieves the user object via their email address
                User invitedUser = userLookup.getObject(Table.User, "email", invitedEmail);
           
                //gets the invited users id
                int invitedUserId = invitedUser.getId();
               
                //creates a new joined date to be added to the UserRoleGroup
                Date dateJoined = new Date();
               
                //creates the new UserRoleGroup for the invited user
                UserRoleGroup invitedUserUrg = new UserRoleGroup(invitedUserId, groupId, 0, dateJoined);
               
                //enters the new UserRoleGroup into the db, effectively adding the invited user to the group
                int newUserRoleGroupId = myTools.dataEntry(invitedUserUrg);
               
                //check to see that the new UserRoleGroup was created properly
                boolean relationshipConfirmed = myTools.dataSearch("UserRoleGroup", "id", newUserRoleGroupId);
               
                //when failed to create the UserRoleGroup
                if (!relationshipConfirmed){
                  return UserFactory.validUser(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.