Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LD102Importer.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LD102Importer.java,v diff -u -r1.8 -r1.9 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LD102Importer.java 23 Aug 2006 07:54:13 -0000 1.8 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LD102Importer.java 29 Aug 2006 04:35:03 -0000 1.9 @@ -65,6 +65,7 @@ import org.lamsfoundation.lams.tool.dao.IToolImportSupportDAO; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.wddx.WDDXProcessor; import org.lamsfoundation.lams.util.wddx.WDDXProcessorConversionException; @@ -101,6 +102,8 @@ private String originalPacket = null; private List toolsErrorMsgs; private Date createDate = new Date(); + private User importer = null; + private UserDTO importerDTO = null; // pass the dto to tools, rather than the real user object /** * Store relationship between an activity and its grouping for processing after all the activities have been process. @@ -317,16 +320,19 @@ this.libraryActivityUiImages = getLibraryActivityUiImages(); this.toolImportSupport = getToolImportSupport(); this.toolsErrorMsgs = toolsErrorMsgs; + if ( toolsErrorMsgs == null ) { log.warn("The list toolsErrorMsgs supplied is null so any warnings will be logged but won't appear in the user's screen."); toolsErrorMsgs = new ArrayList(); } originalPacket = ldWddxPacket; - if (importer == null) - { + if (importer == null) { throw new ImportToolContentException("Importer is missing"); + } else { + this.importer = importer; + this.importerDTO = importer.getUserDTO(); } if (containsNulls(ldWddxPacket)) @@ -367,7 +373,7 @@ else if (isLearningDesign((String) ldHashTable.get(WDDXTAGS102.OBJECT_TYPE))){ - processLearningDesign(ldHashTable, importer, folder); + processLearningDesign(ldHashTable, folder); Vector listOfValidationErrorDTOs = learningDesignService.validateLearningDesign(ldInProgress); if (listOfValidationErrorDTOs.size() > 0) { @@ -403,12 +409,12 @@ toolsErrorMsgs.add("Invalid import data format - WDDX caused an exception. Some data from the design will have been lost. See log for more details."); } - private void processLearningDesign(Hashtable newLdHashTable, User importer, WorkspaceFolder folder) + private void processLearningDesign(Hashtable newLdHashTable, WorkspaceFolder folder) { // put the learning design in a member variable - the updating of the tasks and // activities needs to get to the content, but its a pain to keep passing everything around! - createLearningDesign(newLdHashTable, importer, folder); + createLearningDesign(newLdHashTable, folder); baseDAO.insert(ldInProgress); // put all the content in the contentMap ready for use by activities. @@ -452,12 +458,11 @@ *
  • lams_license - all details null as 1.0.x doesn't support licenses
  • *
  • lams_copy_type - Set to 1.This indicates it is "normal" design.
  • *
  • lams_workspace_folder - An input parameters to let user choose import workspace
  • - *
  • User - The person who execute import action
  • *
  • OriginalLearningDesign - set to null
  • * * Sets ldInProgress to the new learning design. */ - private void createLearningDesign(Hashtable newLdHashTable, User importer, WorkspaceFolder folder) { + private void createLearningDesign(Hashtable newLdHashTable, WorkspaceFolder folder) { LearningDesign ld = new LearningDesign(); @@ -565,7 +570,7 @@ createActivityFromTask(task, nextTransition, xCoOrd, yCoOrd, activityUIID, title, description); } else if ( taskTransitions.size()==3 ) { - createReflectiveActivity(activityDetails, activityUIID, nextTransition, xCoOrd, yCoOrd, title, description, taskTransitions); + createTwoPartActivity(activityDetails, activityUIID, nextTransition, xCoOrd, yCoOrd, title, description, taskTransitions); } else { String message = "Unexpected activity format for activity "+ title +" expect either 1 or 3 tasks within an activity. This activity will be missing from the sequence. Activity "+activityDetails; @@ -575,40 +580,28 @@ } - /** Assume this is a "do something on one task/multi-task, reflect on it another multitask" + /** Assume that this is either a "do something on one task/multi-task, reflect on it another multitask" * e.g. Chat & Scribe + Notebook Scribe + Notebook + * or a "do something and view the results on another page" e.g. Voting. + *

    + * So look for a journal and if we find it assume we have case 1. * In all cases in 1.0.2 the second part should only be for the purposes of reflection * so we just need to convert the first part and set the "journal" flag on the task that * had the content output (as that is the one displayed on the following notebook). + *

    + * If we don't find a journal then we assume it is the second case */ - private Activity createReflectiveActivity(Hashtable activityDetails, Integer activityUIID, Long nextTransition, Integer xCoOrd, Integer yCoOrd, String title, String description, List taskTransitions) throws WDDXProcessorConversionException { + private Activity createTwoPartActivity(Hashtable activityDetails, Integer activityUIID, Long nextTransition, Integer xCoOrd, Integer yCoOrd, String title, String description, List taskTransitions) throws WDDXProcessorConversionException { Activity realTask = null; Activity reflectiveTask = null; - String reflectiveTitle = null; - String reflectiveDescription = null; + String[] reflectiveText = null; // 2 entries: 0 title, 1 description - Integer firstTaskId = WDDXProcessor.convertToInteger(activityDetails,WDDXTAGS102.ACT_FIRSTTASK); - if ( firstTaskId == null ) { - // hmmm, firstTaskId missing - try to derive it from the transition. - Iterator iter = taskTransitions.iterator(); - while ( iter.hasNext() ) { - Hashtable task = (Hashtable) iter.next(); - if ( isTransition((String) task.get(WDDXTAGS102.OBJECT_TYPE)) ) { - firstTaskId = WDDXProcessor.convertToInteger(task, WDDXTAGS102.TRANSITION_FROM_TASKS); - } - } - - if ( firstTaskId == null || NUMERIC_NULL_VALUE_INTEGER.equals(firstTaskId) ) { - firstTaskId = null; - String message = "Unable to determine the first task definition in a combined activity "+ title +". This activity will be missing from the sequence. Activity "+activityDetails; - log.warn(message); - toolsErrorMsgs.add(message); - return null; - } else { - String message = "First task definition missing from activity "+ title +". Guessed it from the rest of the packet. This activity may be incorrect. Activity "+activityDetails; - log.warn(message); - toolsErrorMsgs.add(message); - } + Integer firstTaskId = getFirstTaskId(activityDetails, title, taskTransitions); + if ( firstTaskId == null || NUMERIC_NULL_VALUE_INTEGER.equals(firstTaskId) ) { + String message = "Unable to determine the first task definition in a combined activity "+ title +". This activity will be missing from the sequence. Activity "+activityDetails; + log.warn(message); + toolsErrorMsgs.add(message); + return null; } Iterator iter = taskTransitions.iterator(); @@ -625,58 +618,14 @@ // create the activity that we keep realTask = createActivityFromTask(task, nextTransition, xCoOrd, yCoOrd, activityUIID, title, description); - - Integer outputContentTaskId = null; - if ( isMultiTask(objectType, toolType) ) { - outputContentTaskId = WDDXProcessor.convertToInteger(task, WDDXTAGS102.MTASK_OUTPUT_CONTENT_TASK); - ComplexActivity cActivity = (ComplexActivity) realTask; - if ( outputContentTaskId != null && ! NUMERIC_NULL_VALUE_INTEGER.equals(outputContentTaskId) ) { - Iterator actIter = cActivity.getActivities().iterator(); - while (reflectiveTask==null && actIter.hasNext()) { - Activity subActivity = (Activity) actIter.next(); - if ( outputContentTaskId.equals(subActivity.getActivityUIID()) ) { - reflectiveTask = subActivity; - } - } - } - } else { - reflectiveTask = realTask; - } + // one of the sub-activities may be reflective + reflectiveTask = findReflectiveTask(realTask, reflectiveTask, task, objectType, toolType); - if ( reflectiveTask==null ) { - String message = "Can't find the task in activity "+title+" that should be reflective. The activity will be created but the reflective part will be missing. Task is "+activityDetails; - log.warn(message); - toolsErrorMsgs.add(message); - } - } else { - // reflective part - just need the title and description - don't create matching activities - List subTasks = (List) task.get(WDDXTAGS102.MTASK_SUBTASKS); - Integer journalTaskInputContentId = null; - if ( subTasks != null ) { - Iterator subTaskIterator = subTasks.iterator(); - while (subTaskIterator.hasNext()) { - Hashtable subTask = (Hashtable) subTaskIterator.next(); - if ( ToolContentImport102Manager.TAGS_JOURNAL.equals(subTask.get(WDDXTAGS102.TASK_TOOLTYPE)) ) { - journalTaskInputContentId = WDDXProcessor.convertToInteger(subTask, WDDXTAGS102.TASK_INPUT_CONTENT); - } - } - } - - Hashtable journalContent = null; - if ( journalTaskInputContentId != null && ! NUMERIC_NULL_VALUE_INTEGER.equals(journalTaskInputContentId) ) { - journalContent = contentMap.get(journalTaskInputContentId); - } - - if ( journalContent != null ) { - reflectiveTitle = (String) journalContent.get(WDDXTAGS102.TITLE); - reflectiveDescription = (String) journalContent.get(WDDXTAGS102.CONTENT_BODY); - } else { - String message = "Can't find the journal details in the reflective part of "+title+". The reflective settings in this activity will be missing. Task is "+task; - log.warn(message); - toolsErrorMsgs.add(message); - } + // second partof the 1.0.2 activity - if it has a journal we just need the + // title and description - don't create matching activities + reflectiveText = getReflectiveText(title, task); } } @@ -686,20 +635,91 @@ String message = "Couldn't find the \"real\" activity inside "+title+". This activity will be missing from the sequence. Activity "+activityDetails; log.warn(message); toolsErrorMsgs.add(message); - } else if ( reflectiveTask == null ) { - String message = "Couldn't find \"reflective\" activity inside "+title+". The reflective settings in this activity will be missing. "; - log.warn(message); - toolsErrorMsgs.add(message); - } else { - // TODO make the appropriate activity reflective. Don't have support for this in the tools yet! - String message = "Activity "+reflectiveTask.getTitle()+" should be reflective ("+reflectiveTitle+":"+reflectiveDescription+") but this isn't supported in the tools yet. To be added when the tools are ready."; - log.warn(message); - toolsErrorMsgs.add(message); + } else if ( reflectiveTask != null ) { + try { + ToolActivity toolActivity = (ToolActivity) reflectiveTask; + ToolContentImport102Manager toolService = (ToolContentImport102Manager) context.getBean(toolActivity.getTool().getServiceName()); + toolService.setReflectiveData(toolActivity.getToolContentId(), reflectiveText[0], reflectiveText[1]); + } catch ( Exception e ) { + String message = "Tool content for activity "+title+" should be reflective ("+reflectiveText[0]+":"+reflectiveText[1]+") but activity doesn't seem to support reflection. Reflective details will be missing."; + log.warn(message,e); + toolsErrorMsgs.add(message); + } } return realTask; } + private Activity findReflectiveTask(Activity realTask, Activity reflectiveTask, Hashtable task, String objectType, String toolType) throws WDDXProcessorConversionException { + Integer outputContentTaskId = null; + if ( isMultiTask(objectType, toolType) ) { + outputContentTaskId = WDDXProcessor.convertToInteger(task, WDDXTAGS102.MTASK_OUTPUT_CONTENT_TASK); + ComplexActivity cActivity = (ComplexActivity) realTask; + if ( outputContentTaskId != null && ! NUMERIC_NULL_VALUE_INTEGER.equals(outputContentTaskId) ) { + Iterator actIter = cActivity.getActivities().iterator(); + while (reflectiveTask==null && actIter.hasNext()) { + Activity subActivity = (Activity) actIter.next(); + if ( outputContentTaskId.equals(subActivity.getActivityUIID()) ) { + reflectiveTask = subActivity; + } + } + } + } else { + reflectiveTask = realTask; + } + return reflectiveTask; + } + + /** If a journal entry exists, return the title and description. If it doesn't, return ["",""] */ + private String[] getReflectiveText(String title, Hashtable task) throws WDDXProcessorConversionException { + String[] reflectiveText = new String[2]; + List subTasks = (List) task.get(WDDXTAGS102.MTASK_SUBTASKS); + Integer journalTaskInputContentId = null; + if ( subTasks != null ) { + Iterator subTaskIterator = subTasks.iterator(); + while (subTaskIterator.hasNext()) { + Hashtable subTask = (Hashtable) subTaskIterator.next(); + if ( ToolContentImport102Manager.TAGS_JOURNAL.equals(subTask.get(WDDXTAGS102.TASK_TOOLTYPE)) ) { + journalTaskInputContentId = WDDXProcessor.convertToInteger(subTask, WDDXTAGS102.TASK_INPUT_CONTENT); + } + } + } + + Hashtable journalContent = null; + if ( journalTaskInputContentId != null && ! NUMERIC_NULL_VALUE_INTEGER.equals(journalTaskInputContentId) ) { + journalContent = contentMap.get(journalTaskInputContentId); + } + + if ( journalContent != null ) { + reflectiveText[0] = (String) journalContent.get(WDDXTAGS102.TITLE); + reflectiveText[1] = (String) journalContent.get(WDDXTAGS102.CONTENT_BODY); + } else { + reflectiveText[0] = ""; + reflectiveText[1] = ""; + } + return reflectiveText; + } + + private Integer getFirstTaskId(Hashtable activityDetails, String title, List taskTransitions) throws WDDXProcessorConversionException { + Integer firstTaskId = WDDXProcessor.convertToInteger(activityDetails,WDDXTAGS102.ACT_FIRSTTASK); + if ( firstTaskId == null ) { + // hmmm, firstTaskId missing - try to derive it from the transition. + Iterator iter = taskTransitions.iterator(); + while ( iter.hasNext() ) { + Hashtable task = (Hashtable) iter.next(); + if ( isTransition((String) task.get(WDDXTAGS102.OBJECT_TYPE)) ) { + firstTaskId = WDDXProcessor.convertToInteger(task, WDDXTAGS102.TRANSITION_FROM_TASKS); + } + } + if ( firstTaskId != null ) { + String message = "First task definition missing from activity "+ title +". Guessed it from the rest of the packet. This activity may be incorrect. Activity "+activityDetails; + log.warn(message); + toolsErrorMsgs.add(message); + } + } + return firstTaskId; + } + /** Handles simple (including grouping), parallel and optional activities. Can cope with the sub activities but not * transitions between activities. */ @@ -891,7 +911,7 @@ activity.setDefineLater(defineLater); ToolContentImport102Manager toolService = (ToolContentImport102Manager) context.getBean(tool.getServiceName()); - toolService.import102ToolContent(toolContentId, ldInProgress.getUser().getUserId(), content); + toolService.import102ToolContent(toolContentId, importerDTO, content); } catch ( Exception e ) { String message = "Tool content for activity "+title+" cannot be set up due to an error. Activity will be use the default content. Activity is "+taskDetails; log.warn(message,e); Index: lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentImport102Manager.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentImport102Manager.java,v diff -u -r1.2 -r1.3 --- lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentImport102Manager.java 23 Aug 2006 07:54:13 -0000 1.2 +++ lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentImport102Manager.java 29 Aug 2006 04:35:03 -0000 1.3 @@ -39,29 +39,34 @@ import org.lamsfoundation.lams.tool.exception.DataMissingException; import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; public interface ToolContentImport102Manager { public static final String TAGS_TYPE_AUTHORING = "authoring"; public static final String TAGS_JOURNAL = "journal"; public static final String TAGS_NOTICEBOARD = "noticeboard"; public static final String TAGS_MESSAGEBOARD = "messageboard"; - public static final String TAGS_LOMS = "loms"; public static final String TAGS_CHAT = "chat"; public static final String TAGS_RPT_SUBMIT= "reportsubmission"; - public static final String TAGS_RPT_MARK= "reportmarking"; public static final String TAGS_GROUPING = "group"; public static final String TAGS_GROUPREPORTING = "groupreporting"; public static final String TAGS_RANKING = "ranking"; public static final String TAGS_QUESTIONANSWER = "qa"; public static final String TAGS_SIMPLE_ASSESSMENT = "simpleassessment"; public static final String TAGS_URLCONTENT = "urlcontent"; - public static final String TAGS_FILECONTENT = "filecontent"; public static final String TAGS_HTMLNOTICBOARD = "htmlnb"; - public static final String TAGS_SINGLE_RESOURCE = "singleresource"; - public static final String TAGS_IMAGEGALLERY = "imagegallery"; - public static final String TAGS_IMAGERANKING = "imageranking"; + // the following tools haven't supported for a while or can't be supported by + // import as they are tied to files which won't be in the import, + // so we won't support them in the import + // public static final String TAGS_LOMS = "loms"; + // public static final String TAGS_IMAGEGALLERY = "imagegallery"; + // public static final String TAGS_IMAGERANKING = "imageranking"; + // public static final String TAGS_RPT_MARK= "reportmarking"; + // public static final String TAGS_SINGLE_RESOURCE = "singleresource"; + // public static final String TAGS_FILECONTENT = "filecontent"; + public static final String CONTENT_BODY = "body"; // used public static final String CONTENT_SHOW_USER = "contentShowUser"; // boolean public static final String CONTENT_DEFINE_LATER = "contentDefineLater"; // boolean // used @@ -129,45 +134,7 @@ // for file upload - SingleResource, HTMLNoticeboard, Image tools public static final String DIRECTORY_NAME = "directoryName"; - // ImageGallery task tags (extended from Content.java) - public static final String CONTENT_IMGG_DIRECTORY = DIRECTORY_NAME; - public static final String CONTENT_IMGG_BODY = CONTENT_BODY; - public static final String CONTENT_IMGG_DEFINE_LATER = CONTENT_DEFINE_LATER; //Bolean - public static final String CONTENT_IMGG_GROUPING = "grouping"; - public static final String CONTENT_IMGG_SHOW_USER = CONTENT_SHOW_USER; - public static final String CONTENT_IMGG_MAX_IMAGES = "maxImages"; - public static final String CONTENT_IMGG_ALLOW_SEARCH = "allowSearch"; // Boolean - public static final String CONTENT_IMGG_SEARCH_URL = "searchURL"; - public static final String CONTENT_IMGG_ALLOW_URL = "allowURL"; // Boolean - public static final String CONTENT_IMGG_ALLOW_UPLOAD = "allowUpload"; - public static final String CONTENT_IMGG_IMAGES = CONTENT_URL_URLS; - - // ImageGallery images array (also used by ImageRanking) - public static final String CONTENT_IMGG_IMAGE_SID = "sid"; - public static final String CONTENT_IMGG_IMAGE_COMMENTS = "comments"; - public static final String CONTENT_IMGG_IMAGE_VIEW_ORDER = "order"; - public static final String CONTENT_IMGG_IMAGE_DATECREATED = "dateCreated"; - public static final String CONTENT_IMGG_IMAGE_DATEUPDATED = "dateUpdated"; - public static final String CONTENT_IMGG_IMAGE_TYPE = "type"; // "resourceType", values are "externalurl" or "file" - public static final String CONTENT_IMGG_IMAGE_URL = "url"; - public static final String CONTENT_IMGG_IMAGE_FILENAME = "filename"; - public static final String CONTENT_IMGG_IMAGE_PATH = "path"; - public static final String CONTENT_IMGG_IMAGE_OWNERID = "ownerId"; - public static final String CONTENT_IMGG_IMAGE_OWNERNAME = "owerName"; - // Additional field to use the image array for ImageRanking (runtime only) - public static final String CONTENT_IMGR_IMAGE_IS_SELECTED = "isSelected"; - // ImageRanking task tags (extended from Content.java) - public static final String CONTENT_IMGR_DIRECTORY = DIRECTORY_NAME; - public static final String CONTENT_IMGR_BODY = CONTENT_BODY; // this is the description - public static final String CONTENT_IMGR_DEFINE_LATER = CONTENT_DEFINE_LATER; //Bolean - public static final String CONTENT_IMGR_GROUPING = "grouping"; - public static final String CONTENT_IMGR_SHOW_USER = CONTENT_SHOW_USER; - public static final String CONTENT_IMGR_MAX_VOTE = CONTENT_VOTE_MAXCHOOSE; - public static final String CONTENT_IMGR_PROGRESSIVE_DISPLAY = CONTENT_VOTE_PROGRESSIVE_DISPLAY; // Boolean - public static final String CONTENT_IMGR_IMAGES = CONTENT_URL_URLS; - // ImageRanking images array - same as the ImageGallery images array - /** * Import some 1.0.2 data, where the importValues is a map of the fields from the * 1.0.2 content record. The keys are WDDX tags, values are the WDDX values as strings. @@ -182,21 +149,21 @@ * * Does not set the "reflective" fields. * - * @param toolContentId new tool content id - * @param newUserId user id of the person importing the data - * @param importValues map of values to import. + * @param toolContentId new tool content id - will not be null. + * @param user user importing the data - will not be null. + * @param importValues map of values to import - will not be null. * @throws ToolException an error occurs */ - public void import102ToolContent(Long toolContentId, Integer newUserId, Hashtable importValues) + public void import102ToolContent(Long toolContentId, UserDTO creator, Hashtable importValues) throws ToolException; /** * Set the "reflective" fields on an existing piece of content. Note: Most / All of LAMS 2.0 tools * do not support the title entry for reflection, so any text in that field will be * lost during the import. Only the description is kept. * - * @param title heading to use above reflective entry box - * @param description default contents for the reflective entry box. + * @param title heading to use above reflective entry box - may be null + * @param description default contents for the reflective entry box - may be null */ public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException, DataMissingException;