Index: lams_common/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_common/conf/language/lams/ApplicationResources.properties,v diff -u -r1.4 -r1.5 --- lams_common/conf/language/lams/ApplicationResources.properties 28 Sep 2007 05:27:21 -0000 1.4 +++ lams_common/conf/language/lams/ApplicationResources.properties 15 Oct 2007 07:57:39 -0000 1.5 @@ -41,3 +41,10 @@ #======= End labels: Exported 32 labels for en AU ===== +validation.error.branching.must.have.a.branch=A Branching Activity must have at least one Branch. +validation.error.toolBranchingMustHaveDefaultBranch=A Tool Output Based Branching Activity must have a Default Branch. +validation.error.sequenceActivityMustHaveFirstActivity=A Branch must have a first Activity. +validation.error.groupedBranchingMustHaveAGrouping=A Group Based Branching Activity must have a Grouping Activity. Unless Define Later is turned on, it must have at least one group. +validation.error.groupedBranchingMustHaveBranchForGroup=A Group Based Branching Activity must have all Groups assigned to Branches. +validation.error.toolBranchingConditionInvalid=A condition is missing the comparison value. +validation.error.toolBranchingMustHaveAnInputToolActivity=A Tool Output Based Branching Activity must have an Input Tool. \ No newline at end of file Index: lams_common/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_common/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.4 -r1.5 --- lams_common/conf/language/lams/ApplicationResources_en_AU.properties 28 Sep 2007 05:27:21 -0000 1.4 +++ lams_common/conf/language/lams/ApplicationResources_en_AU.properties 15 Oct 2007 07:57:39 -0000 1.5 @@ -41,3 +41,10 @@ #======= End labels: Exported 32 labels for en AU ===== +validation.error.branching.must.have.a.branch=A Branching Activity must have at least one Branch. +validation.error.toolBranchingMustHaveDefaultBranch=A Tool Output Based Branching Activity must have a Default Branch. +validation.error.sequenceActivityMustHaveFirstActivity=A Branch must have a first Activity. +validation.error.groupedBranchingMustHaveAGrouping=A Group Based Branching Activity must have a Grouping Activity. Unless Define Later is turned on, it must have at least one group. +validation.error.groupedBranchingMustHaveBranchForGroup=A Group Based Branching Activity must have all Groups assigned to Branches. +validation.error.toolBranchingConditionInvalid=A condition is missing the comparison value. +validation.error.toolBranchingMustHaveAnInputToolActivity=A Tool Output Based Branching Activity must have an Input Tool. \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java,v diff -u -r1.5 -r1.6 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java 15 Oct 2007 01:58:03 -0000 1.5 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchCondition.java 15 Oct 2007 07:55:45 -0000 1.6 @@ -29,6 +29,7 @@ import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.log4j.Logger; import org.lamsfoundation.lams.learningdesign.dto.BranchConditionDTO; import org.lamsfoundation.lams.tool.ToolOutput; import org.lamsfoundation.lams.tool.ToolOutputValue; @@ -43,6 +44,8 @@ */ public class BranchCondition implements Comparable { + private static Logger log = Logger.getLogger(BranchCondition.class); + private Long conditionId; private Integer conditionUIID; private Integer orderId; @@ -310,4 +313,57 @@ } return new Long (textValue); } + + /** All conditions must have either (a) an exact match value or (b) a start value and no end value + * or (c) start value and an end value and the end value must be >= start value. + */ + protected boolean isValid() { + if ( exactMatchValue != null ) { + try { + if ( getTypedValue(exactMatchValue) != null ) + return true; + } catch ( Exception e ) { } + log.error("Condition contains an unconvertible value for exactMatchValue. Type is "+type+" value "+exactMatchValue); + return false; + } else { + Comparable typedStartValue = null; + Comparable typedEndValue = null; + + try { + if ( startValue != null ) + typedStartValue = getTypedValue(startValue); + } catch ( Exception e ) { + log.error("Condition contains an unconvertible value for startValue. Type is "+type+" value "+startValue); + return false; + } + + try { + if ( endValue != null ) + typedEndValue = getTypedValue(endValue); + } catch ( Exception e ) { + log.error("Condition contains an unconvertible value for endValue. Type is "+type+" value "+endValue); + return false; + } + + if ( typedStartValue != null && ( typedEndValue == null || typedEndValue.compareTo(typedStartValue) >= 0 ) ) { + return true; + } + } + return false; + } + + private Comparable getTypedValue( String untypedValue ) { + if ( "OUTPUT_LONG".equals(type) ) { + return convertToLong(untypedValue); + } else if ( "OUTPUT_DOUBLE".equals(type) ) { + return Double.parseDouble(untypedValue); + } else if ( "OUTPUT_BOOLEAN".equals(type) ) { + return Boolean.parseBoolean(untypedValue); + } else if ( "OUTPUT_STRING".equals(type) ) { + return untypedValue; + } else { + return null; + } + } + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchingActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchingActivity.java,v diff -u -r1.8 -r1.9 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchingActivity.java 15 Oct 2007 01:59:09 -0000 1.8 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/BranchingActivity.java 15 Oct 2007 07:55:45 -0000 1.9 @@ -217,15 +217,15 @@ } /** - * Validate the branching activity. All branching activities should have at least one branch and the - * default activity must be set (this is the default branch). + * Validate the branching activity. All branching activities should have at + * least one branch and the default activity must be set for a tool based branch. * @return error message key */ public Vector validateActivity(MessageService messageService) { Vector listOfValidationErrors = new Vector(); - if ( getActivities() == null || getActivities().size() == 0 || getDefaultActivity() == null ) { - listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH), this.getActivityUIID())); - } + if ( getActivities() == null || getActivities().size() == 0 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH), this.getActivityUIID())); + } return listOfValidationErrors; } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupBranchingActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupBranchingActivity.java,v diff -u -r1.6 -r1.7 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupBranchingActivity.java 5 Sep 2007 08:08:56 -0000 1.6 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/GroupBranchingActivity.java 15 Oct 2007 07:55:45 -0000 1.7 @@ -25,9 +25,12 @@ import java.io.Serializable; import java.util.Set; +import java.util.Vector; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.dto.ValidationErrorDTO; import org.lamsfoundation.lams.tool.SystemTool; +import org.lamsfoundation.lams.util.MessageService; /** * @author Mitchell Seaton @@ -145,4 +148,36 @@ .toString(); } + /** + * Validate the branching activity. A Grouping must be applied to the branching activity. + * If Define Later == false, then there must be at least one group in the grouping. + * If Define Later == false then all groups must have a branch allocated to them + * @return error message key + */ + public Vector validateActivity(MessageService messageService) { + Vector listOfValidationErrors = new Vector(); + if ( getActivities() == null || getActivities().size() == 0 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH), this.getActivityUIID())); + } + + if ( getGrouping() == null ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTVITY_GROUPING_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTVITY_GROUPING), this.getActivityUIID())); + } else if ( ! getDefineLater().booleanValue() ){ + Set groups = getGrouping().getGroups(); + if ( groups == null || groups.size() == 0 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTVITY_GROUPING_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTVITY_GROUPING), this.getActivityUIID())); + } else { + for ( Group group : groups ) { + if ( group.getBranchActivities() == null || group.getBranchActivities().size() != 1 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTVITY_MUST_HAVE_ALL_GROUPS_ALLOCATED_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTVITY_MUST_HAVE_ALL_GROUPS_ALLOCATED), this.getActivityUIID())); + break; + } + } + } + } + return listOfValidationErrors; + } + + + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java,v diff -u -r1.36 -r1.37 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java 15 Oct 2007 01:59:09 -0000 1.36 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java 15 Oct 2007 07:55:45 -0000 1.37 @@ -228,16 +228,18 @@ } /** - * Validate the sequence activity. All sequence activities should have at least one child activity. + * Validate the sequence activity. All sequence activities must have at least child activity and the default + * activity must be set as this is the first activity in the sequence. One sequence activity exists for each + * branch in a branching activity, so this ensures all branches have a valid child activity. * @return error message key */ -// public Vector validateActivity(MessageService messageService) { -// Vector listOfValidationErrors = new Vector(); -// if ( getActivities() == null || getActivities().size() == 0) { -// listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH), this.getActivityUIID())); -// } -// return listOfValidationErrors; -// } + public Vector validateActivity(MessageService messageService) { + Vector listOfValidationErrors = new Vector(); + if ( getActivities() == null || getActivities().size() == 0 || getDefaultActivity() == null ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.SEQUENCE_ACTIVITY_MUST_HAVE_FIRST_ACTIVITY_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.SEQUENCE_ACTIVITY_MUST_HAVE_FIRST_ACTIVITY), this.getActivityUIID())); + } + return listOfValidationErrors; + } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolBranchingActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolBranchingActivity.java,v diff -u -r1.6 -r1.7 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolBranchingActivity.java 5 Sep 2007 08:08:56 -0000 1.6 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolBranchingActivity.java 15 Oct 2007 07:55:45 -0000 1.7 @@ -24,10 +24,14 @@ package org.lamsfoundation.lams.learningdesign; import java.io.Serializable; +import java.util.Iterator; import java.util.Set; +import java.util.Vector; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.dto.ValidationErrorDTO; import org.lamsfoundation.lams.tool.SystemTool; +import org.lamsfoundation.lams.util.MessageService; /** * @author Mitchell Seaton @@ -145,5 +149,46 @@ .append("activityId", getActivityId()) .toString(); } + + /** + * Validate the tool based branching activity. All branching activities should have at + * least one branch and the default activity must be set for a tool based branch and all conditions + * must be valid (as determined by ToolCondition). + * + * @return error message key + */ + public Vector validateActivity(MessageService messageService) { + Vector listOfValidationErrors = new Vector(); + if ( getDefaultActivity() == null ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH), this.getActivityUIID())); + } + + if ( getInputActivities() == null || getInputActivities().size() == 0 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTVITY_TOOLINPUT_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTVITY_TOOLINPUT), this.getActivityUIID())); + } + + if ( getActivities() == null || getActivities().size() == 0 ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE, messageService.getMessage(ValidationErrorDTO.BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH), this.getActivityUIID())); + } else { + Iterator actIterator = getActivities().iterator(); + while (actIterator.hasNext()) { + SequenceActivity branch = (SequenceActivity) actIterator.next(); + if ( branch.getBranchEntries() != null ) { + Iterator condIterator = branch.getBranchEntries().iterator(); + while (condIterator.hasNext()) { + BranchActivityEntry entry = (BranchActivityEntry) condIterator.next(); + BranchCondition condition = entry.getCondition(); + if ( condition == null || ! condition.isValid() ) { + listOfValidationErrors.add(new ValidationErrorDTO(ValidationErrorDTO.BRANCH_CONDITION_INVALID_ERROR_CODE, + messageService.getMessage(ValidationErrorDTO.BRANCH_CONDITION_INVALID), this.getActivityUIID())); + } + } + } + } + } + return listOfValidationErrors; + } + + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java,v diff -u -r1.8 -r1.9 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java 15 Oct 2007 01:55:00 -0000 1.8 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/dto/ValidationErrorDTO.java 15 Oct 2007 07:55:45 -0000 1.9 @@ -47,7 +47,13 @@ public static final String SCHEDULE_GATE_ERROR_TYPE2_KEY = "validation.error.illegalScheduleGateOffsetsType2"; public static final String GROUPING_ACTIVITY_MISSING_GROUPING_KEY = "validation.error.grouping.missing"; // GM public static final String GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_KEY = "validation.error.group.count.mismatch"; // GC - public static final String BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH = "validation.error.branching.must.have.default.branch"; // BB + public static final String BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH = "validation.error.branching.must.have.a.branch"; // BB + public static final String BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH = "validation.error.toolBranchingMustHaveDefaultBranch"; // BDB + public static final String SEQUENCE_ACTIVITY_MUST_HAVE_FIRST_ACTIVITY = "validation.error.sequenceActivityMustHaveFirstActivity"; // SFA + public static final String BRANCHING_ACTVITY_GROUPING = "validation.error.groupedBranchingMustHaveAGrouping"; //BGG + public static final String BRANCHING_ACTVITY_MUST_HAVE_ALL_GROUPS_ALLOCATED = "validation.error.groupedBranchingMustHaveBranchForGroup"; //BGM + public static final String BRANCH_CONDITION_INVALID = "validation.error.toolBranchingConditionInvalid"; // BCOND + public static final String BRANCHING_ACTVITY_TOOLINPUT = "validation.error.toolBranchingMustHaveAnInputToolActivity"; // BTI public static final String OTHER_ERROR_CODE = "O"; public static final String TRANSITION_ERROR_CODE = "T"; @@ -62,7 +68,13 @@ public static final String SCHEDULE_GATE_ERROR_CODE = "SG1"; public static final String GROUPING_ACTIVITY_MISSING_GROUPING_ERROR_CODE = "GM"; public static final String GROUPING_ACTIVITY_GROUP_COUNT_MISMATCH_ERROR_CODE = "GC"; - public static final String BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH_ERROR_CODE = "BB"; + public static final String BRANCHING_ACTIVITY_MUST_HAVE_A_BRANCH_ERROR_CODE = "BB"; + public static final String BRANCHING_ACTIVITY_MUST_HAVE_DEFAULT_BRANCH_ERROR_CODE = "BDB"; + public static final String SEQUENCE_ACTIVITY_MUST_HAVE_FIRST_ACTIVITY_ERROR_CODE = "SFA"; + public static final String BRANCHING_ACTVITY_GROUPING_ERROR_CODE = "BGG"; + public static final String BRANCHING_ACTVITY_MUST_HAVE_ALL_GROUPS_ALLOCATED_ERROR_CODE = "BGM"; + public static final String BRANCH_CONDITION_INVALID_ERROR_CODE = "BCOND"; + public static final String BRANCHING_ACTVITY_TOOLINPUT_ERROR_CODE = "BTI"; private static MessageResources resources = MessageResources.getMessageResources(CONFIG_PARAM);