Index: lams_build/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_build/build.xml,v diff -u -r1.79.2.3 -r1.79.2.4 --- lams_build/build.xml 30 Jun 2009 02:30:52 -0000 1.79.2.3 +++ lams_build/build.xml 30 Jun 2009 02:53:02 -0000 1.79.2.4 @@ -322,7 +322,6 @@ -<<<<<<< build.xml @@ -343,9 +342,6 @@ -======= - ->>>>>>> 1.79.2.1.2.5 Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignValidator.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignValidator.java,v diff -u -r1.6.4.3 -r1.6.4.4 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignValidator.java 30 Jun 2009 02:32:55 -0000 1.6.4.3 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignValidator.java 30 Jun 2009 02:53:02 -0000 1.6.4.4 @@ -20,11 +20,7 @@ * **************************************************************** */ -<<<<<<< LearningDesignValidator.java /* $Id$ */ -======= -/* $Id$ */ ->>>>>>> 1.6.4.1.2.1 package org.lamsfoundation.lams.learningdesign.service; import java.util.ArrayList; @@ -159,7 +155,6 @@ } -<<<<<<< LearningDesignValidator.java } /** @@ -434,10 +429,10 @@ } // collection cannot exceed max limit if (numOfChildActivities > floatingActivity.getMaxNumberOfActivitiesNotNull()) { - args[0] = floatingActivity.getMaxNumberOfActivities().toString(); - String errorMsg = messageService.getMessage(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_KEY, args); - errors.add(new ValidationErrorDTO(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_CODE, errorMsg, - floatingActivity.getActivityUIID())); + args[0] = floatingActivity.getMaxNumberOfActivities().toString(); + String errorMsg = messageService.getMessage(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_KEY, args); + errors.add(new ValidationErrorDTO(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_CODE, errorMsg, + floatingActivity.getActivityUIID())); } } @@ -538,385 +533,7 @@ errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_SELECTED_ERROR_CODE, messageService .getMessage(ValidationErrorDTO.GROUPING_SELECTED_ERROR_KEY), activity.getActivityUIID())); } -======= - } - - /** - * Perform transition related validations. - * - * All activities with no input transitions are added to the vector noInputTransition. If the size - * of this list is greater than 1 (which violates the rule of having exactly one top level activity with no input - * transition), then a ValidationErrorDTO will be created for each activity with no input transition. Similarly, the - * same concept applies for activities with no output transition. - * - * @param activities - * A subset of the overall design. Will be just the top level activities. - * @param transitions - * A transitions from the design - * - */ - private void validateActivityTransitionRules(Set activities, Set transitions) { - validateTransitions(transitions); - ArrayList noInputTransition = new ArrayList(); // a list to hold the activities which have - // no input transition - ArrayList noOuputTransition = new ArrayList(); // a list to hold the activities which have - // no output transition - int numOfTopLevelActivities = activities.size(); - - // All the branching activities and optional activities we find are stored in this list, so we can process them - // at the end. - // We don't want to process them straight away or the branch activity errors would be mixed up with the previous - // level's errors. - // We need the optional activities, as they may contain a branching activity. - ArrayList complexActivitiesToProcess = null; - - for (Activity activity : activities) { - if (activity.isFloatingActivity()) { - break; - } - - checkActivityForTransition(activity, numOfTopLevelActivities); - - if (activity.getTransitionFrom() == null) { - noOuputTransition.add(activity); - } - if (activity.getTransitionTo() == null) { - noInputTransition.add(activity); - } - complexActivitiesToProcess = checkActivityForFurtherProcessing(complexActivitiesToProcess, activity); } - if (numOfTopLevelActivities > 0) { - if (noInputTransition.size() == 0) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.INPUT_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.INPUT_TRANSITION_ERROR_TYPE2_KEY))); - } - - if (noInputTransition.size() > 1) { - - // put out an error for each activity, but skip the any activities that are the first activity in the - // branch as they shouldn't have an input transition. - for (Activity a : noInputTransition) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.INPUT_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.INPUT_TRANSITION_ERROR_TYPE1_KEY), a.getActivityUIID())); - } - } - - if (noOuputTransition.size() == 0) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.OUTPUT_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.OUTPUT_TRANSITION_ERROR_TYPE2_KEY))); - } - - if (noOuputTransition.size() > 1) { - // there is more than one activity with no output transitions - for (Activity a : noOuputTransition) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.OUTPUT_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.OUTPUT_TRANSITION_ERROR_TYPE1_KEY), a.getActivityUIID())); - } - } - } - - processComplexActivitiesForTransitions(complexActivitiesToProcess); - } - - private void processComplexActivitiesForTransitions(ArrayList complexActivitiesToProcess) { - - if (complexActivitiesToProcess != null) { - for (ComplexActivity complex : complexActivitiesToProcess) { - checkTransitionsInComplexActivity(complex); - } - } - - } - - private void checkTransitionsInComplexActivity(ComplexActivity complexActivity) { - // All the branching activities and optional activities we find are stored in this list, so we can process them - // at the end. - // We don't want to process them straight away or the branch activity errors would be mixed up with the previous - // level's errors. - // We need the optional activities, as they may contain a branching activity. - ArrayList complexActivitiesToProcess = null; - - if (complexActivity.isBranchingActivity()) { - for (ComplexActivity sequence : (Set) complexActivity.getActivities()) { - for (Activity activity : (Set) sequence.getActivities()) { - checkActivityForTransition(activity, sequence.getActivities().size()); - complexActivitiesToProcess = checkActivityForFurtherProcessing(complexActivitiesToProcess, activity); - } - } - } else { - for (Activity activity : (Set) complexActivity.getActivities()) { - complexActivitiesToProcess = checkActivityForFurtherProcessing(complexActivitiesToProcess, activity); - } - } - - processComplexActivitiesForTransitions(complexActivitiesToProcess); - } - - /** - * @param complexActivitiesToProcess - * @param activity - * @return - */ - private ArrayList checkActivityForFurtherProcessing( - ArrayList complexActivitiesToProcess, Activity activity) { - if (activity.isComplexActivity() && !activity.isParallelActivity() && !activity.isFloatingActivity()) { - if (complexActivitiesToProcess == null) { - complexActivitiesToProcess = new ArrayList(); - } - complexActivitiesToProcess.add((ComplexActivity) activity); - } - return complexActivitiesToProcess; - } - - private boolean isFirstActivityInBranch(Activity a) { - ComplexActivity parentActivity = (ComplexActivity) a.getParentActivity(); - if (parentActivity == null || !parentActivity.isSequenceActivity()) { - return false; - } else { - return parentActivity.getDefaultActivity() != null && parentActivity.getDefaultActivity().equals(a); - } - } - - /** - * This method checks if each transition in the learning design has an activity before and after the transition. - * - * If there exists a transition which does not have an activity before or after it, the ValidationErrorDTO is added - * to the list of validation messages. - * - * @param transitions - * the set of transitions to iterate through and validate - */ - private void validateTransitions(Set transitions) { - Iterator i = transitions.iterator(); - while (i.hasNext()) { - Transition transition = (Transition) i.next(); - Activity fromActivity = transition.getFromActivity(); - Activity toActivity = transition.getToActivity(); - if (fromActivity == null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.TRANSITION_ERROR_KEY), transition.getTransitionUIID())); - } else if (toActivity == null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.TRANSITION_ERROR_KEY), transition.getTransitionUIID())); - } - - } - - } - - /** - * For any learning design that has more than one activity then each activity should have at least an input or - * output transition. If there is only one activity in the learning design, then that activity should not have any - * transitions. This method will check if there is an activity that exists that has no transitions at all (if there - * is more than one activity in the learning design) - * - * @param activity - * The Activity to validate - * @param numOfActivities - * The number of activities in the learning design. - */ - private void checkActivityForTransition(Activity activity, int numOfActivities) { - // if one activity, then shouldn't have any transitions - Transition inputTransition = activity.getTransitionTo(); - Transition outputTransition = activity.getTransitionFrom(); - - if (numOfActivities > 1) { - if (inputTransition == null && outputTransition == null && !isFirstActivityInBranch(activity)) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.ACTIVITY_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.ACTIVITY_TRANSITION_ERROR_KEY), activity.getActivityUIID())); - } - } - if (numOfActivities == 1) { - if (inputTransition != null || outputTransition != null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.ACTIVITY_TRANSITION_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.ACTIVITY_TRANSITION_ERROR_KEY), activity.getActivityUIID())); - } - - } - - } - - /** - * If grouping support type is set to GROUPING_SUPPORT_REQUIRED, then the activity is validated to - * ensure that the grouping exists. If grouping support type is set to GROUPING_SUPPORT_NONE then the - * activity is validated to ensure that the grouping does not exist. - * - * If any validation fails, the message will be added to the list of validation messages. - * - * @param activity - */ - private void checkIfGroupingRequired(Activity activity) { - - Integer groupingSupportType = activity.getGroupingSupportType(); - if (groupingSupportType.intValue() == Grouping.GROUPING_SUPPORT_REQUIRED) { - // make sure activity has been assigned a grouping - Grouping grouping = activity.getGrouping(); - if (grouping == null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_REQUIRED_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.GROUPING_REQUIRED_ERROR_KEY), activity.getActivityUIID())); - } - } else if (groupingSupportType.intValue() == Grouping.GROUPING_SUPPORT_NONE) { - Grouping grouping = activity.getGrouping(); - if (grouping != null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_NOT_REQUIRED_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.GROUPING_NOT_REQUIRED_ERROR_KEY), activity.getActivityUIID())); - } - } - - } - - /** - * If this activity is an OptionalActivity, then it must contain one or more activities. - * - * @param parentActivity - */ - private void validateOptionalActivity(Activity parentActivity) { - - if (parentActivity.isOptionsActivity()) { - // get the child activities and check how many there are. - OptionsActivity optionsActivity = (OptionsActivity) parentActivity; - Set childActivities = optionsActivity.getActivities(); - int numOfChildActivities = childActivities.size(); - if (numOfChildActivities == 0) { - errors - .add(new ValidationErrorDTO(ValidationErrorDTO.OPTIONAL_ACTIVITY_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.OPTIONAL_ACTIVITY_ERROR_KEY), optionsActivity - .getActivityUIID())); - } - - } - - } - - /** - * If this activity is an FloatingActivity, then it must contain at least one activity and no more than the maximum - * activities value. - * - * @param parentActivity - */ - private void validateFloatingActivity(Activity parentActivity) { - - if (parentActivity.isFloatingActivity()) { - // get the child activities and check how many there are. - FloatingActivity floatingActivity = (FloatingActivity) parentActivity; - Set childActivities = floatingActivity.getActivities(); - int numOfChildActivities = childActivities.size(); - // require at least one floating activity - if (numOfChildActivities == 0) { - errors - .add(new ValidationErrorDTO(ValidationErrorDTO.FLOATING_ACTIVITY_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.FLOATING_ACTIVITY_ERROR_KEY), floatingActivity - .getActivityUIID())); - } - // collection cannot exceed max limit - if (numOfChildActivities > floatingActivity.getMaxNumberOfActivitiesNotNull()) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.FLOATING_ACTIVITY_MAX_ERROR_KEY), floatingActivity - .getActivityUIID())); - } - - } - - } - - /** - * If this activity is an GroupingActivity, the number of groups in the grouping records is greater than 0 and the - * grouping has some groups, then the actual number of groups must no exceed the desired number of groups. If the - * desired number of groups is 0 then don't check the number of actual groups as there is no semantic limit to the - * number of groups. - * - * @param parentActivity - */ - private void validateGroupingActivity(Activity activity) { - - if (activity.isGroupingActivity()) { - // get the child activities and check how many there are. - GroupingActivity groupingActivity = (GroupingActivity) activity; - Grouping grouping = groupingActivity.getCreateGrouping(); - if (grouping == null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_ACTIVITY_MISSING_GROUPING_ERROR_CODE, - messageService.getMessage(ValidationErrorDTO.GROUPING_ACTIVITY_MISSING_GROUPING_KEY), activity - .getActivityUIID())); - } - Integer numGroupsInteger = null; - if (grouping.isRandomGrouping()) { - RandomGrouping random = (RandomGrouping) grouping; - numGroupsInteger = random.getNumberOfGroups(); - } else { - numGroupsInteger = grouping.getMaxNumberOfGroups(); - } - int maxNumGroups = numGroupsInteger == null ? 0 : numGroupsInteger.intValue(); - if (maxNumGroups > 0 && grouping.getGroups() != null && grouping.getGroups().size() > maxNumGroups) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_ERROR_CODE, - messageService.getMessage(ValidationErrorDTO.GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_KEY), - activity.getActivityUIID())); - } - } - - } - - /** - * This method ensures that the order id of the optional activities start from 1, are sequential and do not contain - * any duplicates. It will iterate through the child activities of the OptionalActivity, and compare the current - * activity order id with the previous activity order id. The currentActivityId should be 1 greater than the - * previous activity order id. - * - * @param parentActivity - */ - private void validateOptionsActivityOrderId(Activity parentActivity) { - Integer thisActivityOrderId = null; - Integer previousActivityOrderId = null; - boolean validOrderId = true; - if (parentActivity.isOptionsActivity()) { - OptionsActivity optionsActivity = (OptionsActivity) parentActivity; - Set childActivities = optionsActivity.getActivities(); // childActivities should be sorted according to - // order id (using the activityOrderComparator) - Iterator i = childActivities.iterator(); - while (i.hasNext() && validOrderId) { - Activity childActivity = (Activity) i.next(); - thisActivityOrderId = childActivity.getOrderId(); - if (previousActivityOrderId != null) { - // compare the two numbers - if (thisActivityOrderId == null) { - validOrderId = false; - } else if (thisActivityOrderId.longValue() != previousActivityOrderId.longValue() + 1) { - validOrderId = false; - } - - } else { - // this is the first activity, since the previousActivityId is null - if (thisActivityOrderId == null || thisActivityOrderId.longValue() != 1) { - validOrderId = false; - } - } - previousActivityOrderId = thisActivityOrderId; - } - - if (!validOrderId) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.OPTIONAL_ACTIVITY_ORDER_ID_INVALID_ERROR_CODE, - messageService.getMessage(ValidationErrorDTO.OPTIONAL_ACTIVITY_ORDER_ID_INVALID_ERROR_KEY), - optionsActivity.getActivityUIID())); - } - - } - } - - /** - * If applyGrouping is set, then the grouping must exist - * - * @param activity - */ - private void validateGroupingIfGroupingIsApplied(Activity activity) { - if (activity.getApplyGrouping().booleanValue()) // if grouping is applied, ensure grouping exists - { - if (activity.getGrouping() == null) { - errors.add(new ValidationErrorDTO(ValidationErrorDTO.GROUPING_SELECTED_ERROR_CODE, messageService - .getMessage(ValidationErrorDTO.GROUPING_SELECTED_ERROR_KEY), activity.getActivityUIID())); - } ->>>>>>> 1.6.4.1.2.1 - } - - } }