Coverage Report - org.kuali.student.lum.common.server.StatementUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
StatementUtil
0%
0/22
0%
0/26
7.5
 
 1  
 package org.kuali.student.lum.common.server;
 2  
 
 3  
 import java.util.Iterator;
 4  
 import java.util.List;
 5  
 
 6  
 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
 7  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 8  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 9  
  
 10  
 /**
 11  
  * 
 12  
  * This class contains common utility methods used with statements.
 13  
  * 
 14  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 15  
  *
 16  
  */
 17  0
 public class StatementUtil {
 18  
     
 19  
     /**
 20  
      * WARNING: this constant is also declared in ProgramRequirementsSummaryView.  We cannot use
 21  
      * the one from ProgramRequirementsSummaryView because we cannot compile it into this
 22  
      * package.  
 23  
      * 
 24  
      * TODO: create a constants class that can be shared across view, server, etc.
 25  
      */
 26  
     public static final String NEW_STMT_TREE_ID = "NEWSTMTTREE";
 27  
     
 28  
     /**
 29  
      * WARNING: this constant is also declared in ProgramRequirementsSummaryView.  We cannot use
 30  
      * the one from ProgramRequirementsSummaryView because we cannot compile it into this
 31  
      * package.  
 32  
      * 
 33  
      * TODO: create a constants class that can be shared across view, server, etc.
 34  
      */
 35  
     public static final String NEW_REQ_COMP_ID = "NEWREQCOMP";
 36  
         
 37  
         /**
 38  
          * This method will recursively set the state of all statements in the tree.
 39  
          * <p>
 40  
          * WARNING: you must call the statement service in order to update statements.
 41  
          * <p>
 42  
          * 
 43  
          * @param state is the state we should set all statements in the tree to
 44  
          * @param statementTreeViewInfo the tree of statements
 45  
          * @throws Exception
 46  
          */
 47  
         public static void updateStatementTreeViewInfoState(String state, StatementTreeViewInfo statementTreeViewInfo) {
 48  
                 // Set the state on the statement tree itself
 49  0
             statementTreeViewInfo.setState(state);
 50  
              
 51  
             // Get all the requirements components for this statement
 52  0
         List<ReqComponentInfo> reqComponents = statementTreeViewInfo.getReqComponents();
 53  
         
 54  
         // Loop over requirements and set the state for each requirement
 55  0
         for(Iterator<ReqComponentInfo> it = reqComponents.iterator(); it.hasNext();)
 56  0
                 it.next().setState(state);
 57  
         
 58  
         // Loop over each statement and set the state for each statement (recursively calling this method)
 59  0
         for(Iterator<StatementTreeViewInfo> itr = statementTreeViewInfo.getStatements().iterator(); itr.hasNext();)
 60  0
                 updateStatementTreeViewInfoState(state, (StatementTreeViewInfo)itr.next());
 61  0
         }
 62  
             /**
 63  
             * This method strips the statement ids from the statement tree prior to saving
 64  
             * the tree, which allows the web service to generate new ids from the database.
 65  
             * <p>
 66  
             * The UI needs to create temporary ids in order to work with the statements
 67  
             * in memory prior to storing them in the database.  On save, we strip
 68  
             * the temporary ids in this method, then write the statement tree to the database,
 69  
             * allowing the database to generate proper ids.
 70  
             * <p>
 71  
             * 
 72  
             * @param tree
 73  
             */
 74  
             public static void stripStatementIds(StatementTreeViewInfo tree) {
 75  0
                 List<StatementTreeViewInfo> statements = tree.getStatements();
 76  0
                 List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents();
 77  
                 
 78  
                 // If there are no statements in the tree, set its ID to null
 79  0
                 if ((tree.getId() != null) && (tree.getId().indexOf(NEW_STMT_TREE_ID) >= 0)) {
 80  0
                     tree.setId(null);
 81  
                 }
 82  
                 
 83  
                 // If there are statements in the tree
 84  0
                 if ((statements != null) && (statements.size() > 0)) {
 85  
                     
 86  
                     // retrieve all statements, loop over them, and recursively strip their IDs
 87  0
                      for (StatementTreeViewInfo statement : statements) {
 88  0
                         stripStatementIds(statement); // inside set the children of this statementTreeViewInfo
 89  
                     }
 90  0
                 } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
 91  
                     // If there are requirements, loop over them and set their IDs to null
 92  0
                     for (ReqComponentInfo reqComponent : reqComponentInfos) {
 93  0
                         if ((reqComponent.getId() != null) && (reqComponent.getId().indexOf(NEW_REQ_COMP_ID) >= 0)) {
 94  0
                             reqComponent.setId(null);
 95  
                         }
 96  
                         // Also set the field IDs to null
 97  0
                         for (ReqCompFieldInfo field : reqComponent.getReqCompFields()) {
 98  0
                             field.setId(null);
 99  
                         }
 100  
                          
 101  
                     }
 102  
                 }
 103  0
             }
 104  
 }