View Javadoc

1   /**
2    * Copyright 2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Charles on 5/17/13
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.service.util;
18  
19  import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
20  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
21  
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  /**
28   * This class provides a static set of Activity Offering state transitions
29   *
30   * @author Kuali Student Team
31   */
32  public class AoStateTransitionRefSolution {
33      // Only supports draft, approved, offered AO states
34      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_DRAFT =    {
35              {TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.NO},
36              {TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.NO},
37              {TransitionGridYesNoEnum.INVALID, TransitionGridYesNoEnum.INVALID, TransitionGridYesNoEnum.INVALID} };  // Technically, can't be in offered unless SOC in publishing/published
38  
39      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_OPEN = AO_STATE_SOC_DRAFT;
40      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_LOCKED = AO_STATE_SOC_DRAFT;
41      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_FINAL_EDITS = AO_STATE_SOC_DRAFT;
42  
43      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_PUBLISHING =    {
44              {TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES},
45              {TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES},
46              {TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES, TransitionGridYesNoEnum.YES} };
47      public static final TransitionGridYesNoEnum [][] AO_STATE_SOC_PUBLISHED =  AO_STATE_SOC_PUBLISHING;
48      public static Map<String, TransitionGridYesNoEnum [][]> SOC_STATE_TO_AO_TRANSITION;
49      static {
50          SOC_STATE_TO_AO_TRANSITION = new HashMap<String, TransitionGridYesNoEnum [][]>();
51          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY, AO_STATE_SOC_DRAFT);
52          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.OPEN_SOC_STATE_KEY, AO_STATE_SOC_OPEN);
53          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.LOCKED_SOC_STATE_KEY, AO_STATE_SOC_LOCKED);
54          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.FINALEDITS_SOC_STATE_KEY, AO_STATE_SOC_FINAL_EDITS);
55          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.PUBLISHING_SOC_STATE_KEY, AO_STATE_SOC_PUBLISHING);
56          SOC_STATE_TO_AO_TRANSITION.put(CourseOfferingSetServiceConstants.PUBLISHED_SOC_STATE_KEY, AO_STATE_SOC_PUBLISHED);
57      }
58      // AO states (currently, only draft, approved, offered since state matrix doesn't indicate any more
59      public static final List<String> AO_STATES_ORDERED;
60      static {
61          AO_STATES_ORDERED = new ArrayList<String>();
62          AO_STATES_ORDERED.add(LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY);
63          AO_STATES_ORDERED.add(LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY);
64          // can only get to this state if SOC state is publishing/published
65          AO_STATES_ORDERED.add(LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY);
66      }
67  
68      public static PseudoUnitTestStateTransitionGrid getReferenceGridForState(String socState) {
69          final TransitionGridYesNoEnum[][] stateTransition = SOC_STATE_TO_AO_TRANSITION.get(socState);
70          List<String> values = new ArrayList<String>();
71          values.add(TransitionGridYesNoEnum.YES.getName());
72          values.add(TransitionGridYesNoEnum.NO.getName());
73          values.add(TransitionGridYesNoEnum.INVALID.getName());
74          PseudoUnitTestStateTransitionGrid grid = new PseudoUnitTestStateTransitionGrid(AoStateTransitionRefSolution.AO_STATES_ORDERED, values, "ao");
75          grid.setSocStateKey(socState);
76          for (int from = 0; from < stateTransition.length; from++) {
77              for (int to = 0; to < stateTransition.length; to++) {
78                  grid.setTransition(AFUTTypeEnum.EXPECTED, from, to, stateTransition[from][to].getName());
79              }
80          }
81          return grid;
82      }
83  }