Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java =================================================================== diff -u -rccc06a304397824e204b7b52ce6e3361cee18bbd -rfb5248530c656fdc6731a15e6493fa9050dfbebd --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java (.../WookieService.java) (revision ccc06a304397824e204b7b52ce6e3361cee18bbd) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/service/WookieService.java (.../WookieService.java) (revision fb5248530c656fdc6731a15e6493fa9050dfbebd) @@ -106,745 +106,845 @@ * ToolContentManager and ToolSessionManager. */ -public class WookieService implements ToolSessionManager, ToolContentManager, IWookieService, - ToolContentImport102Manager { +public class WookieService implements ToolSessionManager, ToolContentManager, + IWookieService, ToolContentImport102Manager { - static Logger logger = Logger.getLogger(WookieService.class.getName()); + static Logger logger = Logger.getLogger(WookieService.class.getName()); - private IWookieDAO wookieDAO = null; + private IWookieDAO wookieDAO = null; - private IWookieSessionDAO wookieSessionDAO = null; + private IWookieSessionDAO wookieSessionDAO = null; - private IWookieUserDAO wookieUserDAO = null; + private IWookieUserDAO wookieUserDAO = null; - private IWookieAttachmentDAO wookieAttachmentDAO = null; + private IWookieAttachmentDAO wookieAttachmentDAO = null; - private ILearnerService learnerService; + private ILearnerService learnerService; - private ILamsToolService toolService; + private ILamsToolService toolService; - private IToolContentHandler wookieToolContentHandler = null; + private IToolContentHandler wookieToolContentHandler = null; - private IRepositoryService repositoryService = null; + private IRepositoryService repositoryService = null; - private IAuditService auditService = null; + private IAuditService auditService = null; - private IExportToolContentService exportContentService; + private IExportToolContentService exportContentService; - private ICoreNotebookService coreNotebookService; + private ICoreNotebookService coreNotebookService; - private WookieOutputFactory wookieOutputFactory; + private WookieOutputFactory wookieOutputFactory; - private IWookieConfigItemDAO wookieConfigItemDAO; + private IWookieConfigItemDAO wookieConfigItemDAO; - private MessageService messageService; + private MessageService messageService; - private IUserManagementService userManagementService; + private IUserManagementService userManagementService; - public WookieService() { - super(); - // TODO Auto-generated constructor stub - } - - /* ************ Methods from ToolSessionManager ************* */ - public void createToolSession(Long toolSessionId, String toolSessionName, Long toolContentId) throws ToolException { - if (WookieService.logger.isDebugEnabled()) { - WookieService.logger.debug("entering method createToolSession:" + " toolSessionId = " + toolSessionId - + " toolSessionName = " + toolSessionName + " toolContentId = " + toolContentId); + public WookieService() { + super(); + // TODO Auto-generated constructor stub } - WookieSession session = new WookieSession(); - session.setSessionId(toolSessionId); - session.setSessionName(toolSessionName); - // learner starts - // TODO need to also set other fields. - Wookie wookie = wookieDAO.getByContentId(toolContentId); - session.setWookie(wookie); + /* ************ Methods from ToolSessionManager ************* */ + public void createToolSession(Long toolSessionId, String toolSessionName, + Long toolContentId) throws ToolException { + if (WookieService.logger.isDebugEnabled()) { + WookieService.logger.debug("entering method createToolSession:" + + " toolSessionId = " + toolSessionId + + " toolSessionName = " + toolSessionName + + " toolContentId = " + toolContentId); + } - // Create a copy of the widget for the session - // Clone the wookie widget on the external server - String wookieUrl = getWookieURL(); - try { - String newSharedDataKey = toolSessionId.toString() + "_" + toolContentId.toString(); + WookieSession session = new WookieSession(); + session.setSessionId(toolSessionId); + session.setSessionName(toolSessionName); + // learner starts + // TODO need to also set other fields. + Wookie wookie = wookieDAO.getByContentId(toolContentId); + session.setWookie(wookie); - if (wookieUrl != null) { + // Create a copy of the widget for the session + // Clone the wookie widget on the external server + String wookieUrl = getWookieURL(); + try { + String newSharedDataKey = toolSessionId.toString() + "_" + + toolContentId.toString(); - if (wookie.getWidgetIdentifier() != null && wookie.getWidgetIdentifier() != "") { + if (wookieUrl != null) { - wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + if (wookie.getWidgetIdentifier() != null + && wookie.getWidgetIdentifier() != "") { - logger.debug("Creating a new clone for session of widget: " + toolContentId.toString()); - boolean success = WookieUtil.cloneWidget(wookieUrl, getWookieAPIKey(), - wookie.getWidgetIdentifier(), toolContentId.toString(), newSharedDataKey, wookie - .getCreateBy().toString()); + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; - if (success) { - session.setWidgetSharedDataKey(newSharedDataKey); - session.setWidgetHeight(wookie.getWidgetHeight()); - session.setWidgetWidth(wookie.getWidgetWidth()); - session.setWidgetMaximise(wookie.getWidgetMaximise()); - session.setWidgetIdentifier(wookie.getWidgetIdentifier()); - } else { - throw new WookieException("Failed to copy widget on wookie server, check log for details."); - } + logger.debug("Creating a new clone for session of widget: " + + toolContentId.toString()); + boolean success = WookieUtil.cloneWidget(wookieUrl, + getWookieAPIKey(), wookie.getWidgetIdentifier(), + toolContentId.toString(), newSharedDataKey, wookie + .getCreateBy().toString()); + + if (success) { + session.setWidgetSharedDataKey(newSharedDataKey); + session.setWidgetHeight(wookie.getWidgetHeight()); + session.setWidgetWidth(wookie.getWidgetWidth()); + session.setWidgetMaximise(wookie.getWidgetMaximise()); + session.setWidgetIdentifier(wookie + .getWidgetIdentifier()); + } else { + throw new WookieException( + "Failed to copy widget on wookie server, check log for details."); + } + } + + } else { + throw new WookieException("Wookie url is not set"); + } + } catch (Exception e) { + logger.error("Problem calling wookie server to clone instance", e); + throw new WookieException( + "Problem calling wookie server to clone instance", e); } - } else { - throw new WookieException("Wookie url is not set"); - } - } catch (Exception e) { - logger.error("Problem calling wookie server to clone instance", e); - throw new WookieException("Problem calling wookie server to clone instance", e); + wookieSessionDAO.saveOrUpdate(session); } - wookieSessionDAO.saveOrUpdate(session); - } + public String leaveToolSession(Long toolSessionId, Long learnerId) + throws DataMissingException, ToolException { + return learnerService.completeToolSession(toolSessionId, learnerId); + } - public String leaveToolSession(Long toolSessionId, Long learnerId) throws DataMissingException, ToolException { - return learnerService.completeToolSession(toolSessionId, learnerId); - } + public ToolSessionExportOutputData exportToolSession(Long toolSessionId) + throws DataMissingException, ToolException { + // TODO Auto-generated method stub + return null; + } - public ToolSessionExportOutputData exportToolSession(Long toolSessionId) throws DataMissingException, ToolException { - // TODO Auto-generated method stub - return null; - } + @SuppressWarnings("unchecked") + public ToolSessionExportOutputData exportToolSession(List ToolSessionIds) + throws DataMissingException, ToolException { + // TODO Auto-generated method stub + return null; + } - @SuppressWarnings("unchecked") - public ToolSessionExportOutputData exportToolSession(List ToolSessionIds) throws DataMissingException, - ToolException { - // TODO Auto-generated method stub - return null; - } + public void removeToolSession(Long toolSessionId) + throws DataMissingException, ToolException { + wookieSessionDAO.deleteBySessionID(toolSessionId); + // TODO check if cascade worked + } - public void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException { - wookieSessionDAO.deleteBySessionID(toolSessionId); - // TODO check if cascade worked - } + /** + * Get the tool output for the given tool output names. + * + * @see + * org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.util + * .List, java.lang.Long, java.lang.Long) + */ + public SortedMap getToolOutput(List names, + Long toolSessionId, Long learnerId) { + return getWookieOutputFactory().getToolOutput(names, this, + toolSessionId, learnerId); + } - /** - * Get the tool output for the given tool output names. - * - * @see - * org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.util - * .List, java.lang.Long, java.lang.Long) - */ - public SortedMap getToolOutput(List names, Long toolSessionId, Long learnerId) { - return getWookieOutputFactory().getToolOutput(names, this, toolSessionId, learnerId); - } + /** + * Get the tool output for the given tool output name. + * + * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.lang.String, + * java.lang.Long, java.lang.Long) + */ + public ToolOutput getToolOutput(String name, Long toolSessionId, + Long learnerId) { + return getWookieOutputFactory().getToolOutput(name, this, + toolSessionId, learnerId); + } - /** - * Get the tool output for the given tool output name. - * - * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.lang.String, - * java.lang.Long, java.lang.Long) - */ - public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { - return getWookieOutputFactory().getToolOutput(name, this, toolSessionId, learnerId); - } + /* ************ Methods from ToolContentManager ************************* */ - /* ************ Methods from ToolContentManager ************************* */ + public void copyToolContent(Long fromContentId, Long toContentId) + throws ToolException { - public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException { + if (WookieService.logger.isDebugEnabled()) { + WookieService.logger.debug("entering method copyToolContent:" + + " fromContentId=" + fromContentId + " toContentId=" + + toContentId); + } - if (WookieService.logger.isDebugEnabled()) { - WookieService.logger.debug("entering method copyToolContent:" + " fromContentId=" + fromContentId - + " toContentId=" + toContentId); - } + if (toContentId == null) { + String error = "Failed to copy tool content: toContentID is null"; + throw new ToolException(error); + } - if (toContentId == null) { - String error = "Failed to copy tool content: toContentID is null"; - throw new ToolException(error); - } + Wookie fromContent = null; + if (fromContentId != null) { + fromContent = wookieDAO.getByContentId(fromContentId); + } + if (fromContent == null) { + // create the fromContent using the default tool content + fromContent = getDefaultContent(); + } + Wookie toContent = Wookie.newInstance(fromContent, toContentId, + wookieToolContentHandler); - Wookie fromContent = null; - if (fromContentId != null) { - fromContent = wookieDAO.getByContentId(fromContentId); - } - if (fromContent == null) { - // create the fromContent using the default tool content - fromContent = getDefaultContent(); - } - Wookie toContent = Wookie.newInstance(fromContent, toContentId, wookieToolContentHandler); + // Clone the wookie widget on the external server + String wookieUrl = getWookieURL(); + try { + if (wookieUrl != null) { + if (fromContent.getWidgetIdentifier() != null + && fromContent.getWidgetIdentifier() != "") { + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; - // Clone the wookie widget on the external server - String wookieUrl = getWookieURL(); - try { - if (wookieUrl != null) { - if (fromContent.getWidgetIdentifier() != null && fromContent.getWidgetIdentifier() != "") { - wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + logger + .debug("Creating a new clone for copycontent for widget: " + + fromContentId.toString()); + boolean success = WookieUtil.cloneWidget(wookieUrl, + getWookieAPIKey(), fromContent + .getWidgetIdentifier(), fromContentId + .toString(), toContentId.toString(), + fromContent.getCreateBy().toString()); - logger.debug("Creating a new clone for copycontent for widget: " + fromContentId.toString()); - boolean success = WookieUtil.cloneWidget(wookieUrl, getWookieAPIKey(), fromContent - .getWidgetIdentifier(), fromContentId.toString(), toContentId.toString(), fromContent - .getCreateBy().toString()); + if (success) { + toContent + .setWidgetHeight(fromContent.getWidgetHeight()); + toContent.setWidgetWidth(fromContent.getWidgetWidth()); + toContent.setWidgetAuthorUrl(fromContent + .getWidgetAuthorUrl()); + toContent.setWidgetMaximise(fromContent + .getWidgetMaximise()); + toContent.setWidgetIdentifier(fromContent + .getWidgetIdentifier()); + toContent.setCreateBy(fromContent.getCreateBy()); - if (success) { - toContent.setWidgetHeight(fromContent.getWidgetHeight()); - toContent.setWidgetWidth(fromContent.getWidgetWidth()); - toContent.setWidgetAuthorUrl(fromContent.getWidgetAuthorUrl()); - toContent.setWidgetMaximise(fromContent.getWidgetMaximise()); - toContent.setWidgetIdentifier(fromContent.getWidgetIdentifier()); - toContent.setCreateBy(fromContent.getCreateBy()); + // Need to add the author to the widget so authoring + // widget url is different in the copy + User user = (User) userManagementService.findById( + User.class, fromContent.getCreateBy()); + String returnXML = WookieUtil.getWidget(wookieUrl, + getWookieAPIKey(), fromContent + .getWidgetIdentifier(), user + .getUserDTO(), toContentId.toString(), + true); - // Need to add the author to the widget so authoring widget url is different in the copy - User user = (User) userManagementService.findById(User.class, fromContent.getCreateBy()); - String returnXML = WookieUtil.getWidget(wookieUrl, getWookieAPIKey(), fromContent - .getWidgetIdentifier(), user.getUserDTO(), toContentId.toString(), true); + toContent.setWidgetAuthorUrl(WookieUtil + .getWidgetUrlFromXML(returnXML)); - toContent.setWidgetAuthorUrl(WookieUtil.getWidgetUrlFromXML(returnXML)); - - } else { - throw new WookieException("Failed to copy widget on wookie server, check log for details."); - } + } else { + throw new WookieException( + "Failed to copy widget on wookie server, check log for details."); + } + } + } else { + throw new WookieException("Wookie url is not set"); + } + } catch (Exception e) { + logger.error("Problem calling wookie server to clone instance", e); + throw new WookieException( + "Problem calling wookie server to clone instance", e); } - } else { - throw new WookieException("Wookie url is not set"); - } - } catch (Exception e) { - logger.error("Problem calling wookie server to clone instance", e); - throw new WookieException("Problem calling wookie server to clone instance", e); + + wookieDAO.saveOrUpdate(toContent); } - wookieDAO.saveOrUpdate(toContent); - } + public void copyFile(File srcFile, String destPath) throws Exception { + if (srcFile.exists() && srcFile.canRead()) { + File newFile = new File(destPath); + FileOutputStream out = new FileOutputStream(newFile); + FileInputStream in = new FileInputStream(srcFile); + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + } - public void copyFile(File srcFile, String destPath) throws Exception { - if (srcFile.exists() && srcFile.canRead()) { - File newFile = new File(destPath); - FileOutputStream out = new FileOutputStream(newFile); - FileInputStream in = new FileInputStream(srcFile); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } } - } + public void setAsDefineLater(Long toolContentId, boolean value) + throws DataMissingException, ToolException { + Wookie wookie = wookieDAO.getByContentId(toolContentId); + if (wookie == null) { + throw new ToolException("Could not find tool with toolContentID: " + + toolContentId); + } + wookie.setDefineLater(value); + wookieDAO.saveOrUpdate(wookie); + } - public void setAsDefineLater(Long toolContentId, boolean value) throws DataMissingException, ToolException { - Wookie wookie = wookieDAO.getByContentId(toolContentId); - if (wookie == null) { - throw new ToolException("Could not find tool with toolContentID: " + toolContentId); + public void setAsRunOffline(Long toolContentId, boolean value) + throws DataMissingException, ToolException { + Wookie wookie = wookieDAO.getByContentId(toolContentId); + if (wookie == null) { + throw new ToolException("Could not find tool with toolContentID: " + + toolContentId); + } + wookie.setRunOffline(value); + wookieDAO.saveOrUpdate(wookie); } - wookie.setDefineLater(value); - wookieDAO.saveOrUpdate(wookie); - } - public void setAsRunOffline(Long toolContentId, boolean value) throws DataMissingException, ToolException { - Wookie wookie = wookieDAO.getByContentId(toolContentId); - if (wookie == null) { - throw new ToolException("Could not find tool with toolContentID: " + toolContentId); + public void removeToolContent(Long toolContentId, boolean removeSessionData) + throws SessionDataExistsException, ToolException { + // TODO Auto-generated method stub } - wookie.setRunOffline(value); - wookieDAO.saveOrUpdate(wookie); - } - public void removeToolContent(Long toolContentId, boolean removeSessionData) throws SessionDataExistsException, - ToolException { - // TODO Auto-generated method stub - } + /** + * Export the XML fragment for the tool's content, along with any files + * needed for the content. + * + * @throws DataMissingException + * if no tool content matches the toolSessionId + * @throws ToolException + * if any other error occurs + */ - /** - * Export the XML fragment for the tool's content, along with any files - * needed for the content. - * - * @throws DataMissingException - * if no tool content matches the toolSessionId - * @throws ToolException - * if any other error occurs - */ + public void exportToolContent(Long toolContentId, String rootPath) + throws DataMissingException, ToolException { + Wookie wookie = wookieDAO.getByContentId(toolContentId); + if (wookie == null) { + wookie = getDefaultContent(); + } + if (wookie == null) { + throw new DataMissingException( + "Unable to find default content for the wookie tool"); + } - public void exportToolContent(Long toolContentId, String rootPath) throws DataMissingException, ToolException { - Wookie wookie = wookieDAO.getByContentId(toolContentId); - if (wookie == null) { - wookie = getDefaultContent(); + // set ResourceToolContentHandler as null to avoid copy file node in + // repository again. + wookie = Wookie.newInstance(wookie, toolContentId, null); + wookie.setToolContentHandler(null); + wookie.setWookieSessions(null); + + Set atts = wookie.getWookieAttachments(); + for (WookieAttachment att : atts) { + att.setWookie(null); + } + try { + exportContentService.registerFileClassForExport( + WookieAttachment.class.getName(), "fileUuid", + "fileVersionId"); + exportContentService.exportToolContent(toolContentId, wookie, + wookieToolContentHandler, rootPath); + } catch (ExportToolContentException e) { + throw new ToolException(e); + } } - if (wookie == null) { - throw new DataMissingException("Unable to find default content for the wookie tool"); - } - // set ResourceToolContentHandler as null to avoid copy file node in - // repository again. - wookie = Wookie.newInstance(wookie, toolContentId, null); - wookie.setToolContentHandler(null); - wookie.setWookieSessions(null); + /** + * Import the XML fragment for the tool's content, along with any files + * needed for the content. + * + * @throws ToolException + * if any other error occurs + */ + public void importToolContent(Long toolContentId, Integer newUserUid, + String toolContentPath, String fromVersion, String toVersion) + throws ToolException { + try { + exportContentService.registerFileClassForImport( + WookieAttachment.class.getName(), "fileUuid", + "fileVersionId", "fileName", "fileType", null, null); - Set atts = wookie.getWookieAttachments(); - for (WookieAttachment att : atts) { - att.setWookie(null); - } - try { - exportContentService.registerFileClassForExport(WookieAttachment.class.getName(), "fileUuid", - "fileVersionId"); - exportContentService.exportToolContent(toolContentId, wookie, wookieToolContentHandler, rootPath); - } catch (ExportToolContentException e) { - throw new ToolException(e); - } - } + Object toolPOJO = exportContentService.importToolContent( + toolContentPath, wookieToolContentHandler, fromVersion, + toVersion); + if (!(toolPOJO instanceof Wookie)) { + throw new ImportToolContentException( + "Import Wookie tool content failed. Deserialized object is " + + toolPOJO); + } + Wookie wookie = (Wookie) toolPOJO; - /** - * Import the XML fragment for the tool's content, along with any files - * needed for the content. - * - * @throws ToolException - * if any other error occurs - */ - public void importToolContent(Long toolContentId, Integer newUserUid, String toolContentPath, String fromVersion, - String toVersion) throws ToolException { - try { - exportContentService.registerFileClassForImport(WookieAttachment.class.getName(), "fileUuid", - "fileVersionId", "fileName", "fileType", null, null); + // reset it to new toolContentId + wookie.setToolContentId(toolContentId); + wookie.setCreateBy(newUserUid); - Object toolPOJO = exportContentService.importToolContent(toolContentPath, wookieToolContentHandler, - fromVersion, toVersion); - if (!(toolPOJO instanceof Wookie)) { - throw new ImportToolContentException("Import Wookie tool content failed. Deserialized object is " - + toolPOJO); - } - Wookie wookie = (Wookie) toolPOJO; + User user = (User) userManagementService.findById(User.class, + newUserUid); - // reset it to new toolContentId - wookie.setToolContentId(toolContentId); - wookie.setCreateBy(newUserUid); - - User user = (User)userManagementService.findById(User.class, newUserUid); + // If the wookie has an identifier, it has been initiated. Make an + // new instance using the identifier + if (!StringUtils.isEmpty(wookie.getWidgetIdentifier()) + && user != null) { + String wookieUrl = getWookieURL(); + String wookieKey = getWookieAPIKey(); + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; - // If the wookie has an identifier, it has been initiated. Make an new instance using the identifier - if (!StringUtils.isEmpty(wookie.getWidgetIdentifier()) && user != null) { - String wookieUrl = getWookieURL(); - String wookieKey = getWookieAPIKey(); - wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + String returnXML = WookieUtil.getWidget(wookieUrl, wookieKey, + wookie.getWidgetIdentifier(), user.getUserDTO(), + toolContentId.toString(), true); - String returnXML = WookieUtil.getWidget(wookieUrl, wookieKey, wookie.getWidgetIdentifier(), user.getUserDTO(), - toolContentId.toString(), true); - - WidgetData widgetData = WookieUtil.getWidgetDataFromXML(returnXML); - wookie.setWidgetAuthorUrl(widgetData.getUrl()); - wookie.setWidgetIdentifier(widgetData.getIdentifier()); - wookie.setWidgetHeight(widgetData.getHeight()); - wookie.setWidgetMaximise(widgetData.getMaximize()); - wookie.setWidgetWidth(widgetData.getWidth()); - } + WidgetData widgetData = WookieUtil + .getWidgetDataFromXML(returnXML); + wookie.setWidgetAuthorUrl(widgetData.getUrl()); + wookie.setWidgetIdentifier(wookie.getWidgetIdentifier()); + wookie.setWidgetHeight(widgetData.getHeight()); + wookie.setWidgetMaximise(widgetData.getMaximize()); + wookie.setWidgetWidth(widgetData.getWidth()); + } - wookieDAO.saveOrUpdate(wookie); - } catch (ImportToolContentException e) { - throw new ToolException(e); - } catch (Exception e) { - WookieService.logger.error("Error during import possibly because of file copy error", e); - throw new ToolException(e); + wookieDAO.saveOrUpdate(wookie); + } catch (ImportToolContentException e) { + throw new ToolException(e); + } catch (Exception e) { + WookieService.logger.error( + "Error during import possibly because of file copy error", + e); + throw new ToolException(e); + } } - } - public String getFileExtension(String fileName) { - String ext = ""; - int i = fileName.lastIndexOf('.'); - if (i > 0 && i < fileName.length() - 1) { - ext += "." + fileName.substring(i + 1).toLowerCase(); + public String getFileExtension(String fileName) { + String ext = ""; + int i = fileName.lastIndexOf('.'); + if (i > 0 && i < fileName.length() - 1) { + ext += "." + fileName.substring(i + 1).toLowerCase(); + } + return ext; } - return ext; - } - /** - * Get the definitions for possible output for an activity, based on the - * toolContentId. These may be definitions that are always available for the - * tool (e.g. number of marks for Multiple Choice) or a custom definition - * created for a particular activity such as the answer to the third - * question contains the word Koala and hence the need for the toolContentId - * - * @return SortedMap of ToolOutputDefinitions with the key being the name of - * each definition - */ - public SortedMap getToolOutputDefinitions(Long toolContentId, int definitionType) - throws ToolException { - Wookie wookie = getWookieDAO().getByContentId(toolContentId); - if (wookie == null) { - wookie = getDefaultContent(); + /** + * Get the definitions for possible output for an activity, based on the + * toolContentId. These may be definitions that are always available for the + * tool (e.g. number of marks for Multiple Choice) or a custom definition + * created for a particular activity such as the answer to the third + * question contains the word Koala and hence the need for the toolContentId + * + * @return SortedMap of ToolOutputDefinitions with the key being the name of + * each definition + */ + public SortedMap getToolOutputDefinitions( + Long toolContentId, int definitionType) throws ToolException { + Wookie wookie = getWookieDAO().getByContentId(toolContentId); + if (wookie == null) { + wookie = getDefaultContent(); + } + return getWookieOutputFactory().getToolOutputDefinitions(wookie, + definitionType); } - return getWookieOutputFactory().getToolOutputDefinitions(wookie, definitionType); - } - @SuppressWarnings("unchecked") - public Class[] getSupportedToolOutputDefinitionClasses(int definitionType) { - return getWookieOutputFactory().getSupportedDefinitionClasses(definitionType); - } + @SuppressWarnings("unchecked") + public Class[] getSupportedToolOutputDefinitionClasses(int definitionType) { + return getWookieOutputFactory().getSupportedDefinitionClasses( + definitionType); + } - /* ********** IWookieService Methods ********************************* */ + /* ********** IWookieService Methods ********************************* */ - public Long createNotebookEntry(Long id, Integer idType, String signature, Integer userID, String entry) { - return coreNotebookService.createNotebookEntry(id, idType, signature, userID, "", entry); - } + public Long createNotebookEntry(Long id, Integer idType, String signature, + Integer userID, String entry) { + return coreNotebookService.createNotebookEntry(id, idType, signature, + userID, "", entry); + } - public NotebookEntry getEntry(Long sessionId, Integer idType, String signature, Integer userID) { - List list = coreNotebookService.getEntry(sessionId, idType, signature, userID); - if (list == null || list.isEmpty()) { - return null; - } else { - return list.get(0); + public NotebookEntry getEntry(Long sessionId, Integer idType, + String signature, Integer userID) { + List list = coreNotebookService.getEntry(sessionId, + idType, signature, userID); + if (list == null || list.isEmpty()) { + return null; + } else { + return list.get(0); + } } - } - /** - * @param notebookEntry - */ - public void updateEntry(NotebookEntry notebookEntry) { - coreNotebookService.updateEntry(notebookEntry); - } + /** + * @param notebookEntry + */ + public void updateEntry(NotebookEntry notebookEntry) { + coreNotebookService.updateEntry(notebookEntry); + } - public Long getDefaultContentIdBySignature(String toolSignature) { - Long toolContentId = null; - toolContentId = new Long(toolService.getToolDefaultContentIdBySignature(toolSignature)); - if (toolContentId == null) { - String error = "Could not retrieve default content id for this tool"; - WookieService.logger.error(error); - throw new WookieException(error); + public Long getDefaultContentIdBySignature(String toolSignature) { + Long toolContentId = null; + toolContentId = new Long(toolService + .getToolDefaultContentIdBySignature(toolSignature)); + if (toolContentId == null) { + String error = "Could not retrieve default content id for this tool"; + WookieService.logger.error(error); + throw new WookieException(error); + } + return toolContentId; } - return toolContentId; - } - public Wookie getDefaultContent() { - Long defaultContentID = getDefaultContentIdBySignature(WookieConstants.TOOL_SIGNATURE); - Wookie defaultContent = getWookieByContentId(defaultContentID); - if (defaultContent == null) { - String error = "Could not retrieve default content record for this tool"; - WookieService.logger.error(error); - throw new WookieException(error); + public Wookie getDefaultContent() { + Long defaultContentID = getDefaultContentIdBySignature(WookieConstants.TOOL_SIGNATURE); + Wookie defaultContent = getWookieByContentId(defaultContentID); + if (defaultContent == null) { + String error = "Could not retrieve default content record for this tool"; + WookieService.logger.error(error); + throw new WookieException(error); + } + return defaultContent; } - return defaultContent; - } - public Wookie copyDefaultContent(Long newContentID) { + public Wookie copyDefaultContent(Long newContentID) { - if (newContentID == null) { - String error = "Cannot copy the Wookie tools default content: + " + "newContentID is null"; - WookieService.logger.error(error); - throw new WookieException(error); + if (newContentID == null) { + String error = "Cannot copy the Wookie tools default content: + " + + "newContentID is null"; + WookieService.logger.error(error); + throw new WookieException(error); + } + + Wookie defaultContent = getDefaultContent(); + // create new wookie using the newContentID + Wookie newContent = new Wookie(); + newContent = Wookie.newInstance(defaultContent, newContentID, + wookieToolContentHandler); + wookieDAO.saveOrUpdate(newContent); + return newContent; } - Wookie defaultContent = getDefaultContent(); - // create new wookie using the newContentID - Wookie newContent = new Wookie(); - newContent = Wookie.newInstance(defaultContent, newContentID, wookieToolContentHandler); - wookieDAO.saveOrUpdate(newContent); - return newContent; - } + public Wookie getWookieByContentId(Long toolContentID) { + Wookie wookie = wookieDAO.getByContentId(toolContentID); + if (wookie == null) { + WookieService.logger + .debug("Could not find the content with toolContentID:" + + toolContentID); + } + return wookie; + } - public Wookie getWookieByContentId(Long toolContentID) { - Wookie wookie = wookieDAO.getByContentId(toolContentID); - if (wookie == null) { - WookieService.logger.debug("Could not find the content with toolContentID:" + toolContentID); + public WookieSession getSessionBySessionId(Long toolSessionId) { + WookieSession wookieSession = wookieSessionDAO + .getBySessionId(toolSessionId); + if (wookieSession == null) { + WookieService.logger + .debug("Could not find the wookie session with toolSessionID:" + + toolSessionId); + } + return wookieSession; } - return wookie; - } - public WookieSession getSessionBySessionId(Long toolSessionId) { - WookieSession wookieSession = wookieSessionDAO.getBySessionId(toolSessionId); - if (wookieSession == null) { - WookieService.logger.debug("Could not find the wookie session with toolSessionID:" + toolSessionId); + public WookieUser getUserByUserIdAndSessionId(Long userId, + Long toolSessionId) { + return wookieUserDAO.getByUserIdAndSessionId(userId, toolSessionId); } - return wookieSession; - } - public WookieUser getUserByUserIdAndSessionId(Long userId, Long toolSessionId) { - return wookieUserDAO.getByUserIdAndSessionId(userId, toolSessionId); - } + public WookieUser getUserByLoginNameAndSessionId(String loginName, + Long toolSessionId) { + return wookieUserDAO.getByLoginNameAndSessionId(loginName, + toolSessionId); + } - public WookieUser getUserByLoginNameAndSessionId(String loginName, Long toolSessionId) { - return wookieUserDAO.getByLoginNameAndSessionId(loginName, toolSessionId); - } + public WookieUser getUserByUID(Long uid) { + return wookieUserDAO.getByUID(uid); + } - public WookieUser getUserByUID(Long uid) { - return wookieUserDAO.getByUID(uid); - } + public WookieAttachment uploadFileToContent(Long toolContentId, + FormFile file, String type) { + if (file == null || StringUtils.isEmpty(file.getFileName())) { + throw new WookieException("Could not find upload file: " + file); + } - public WookieAttachment uploadFileToContent(Long toolContentId, FormFile file, String type) { - if (file == null || StringUtils.isEmpty(file.getFileName())) { - throw new WookieException("Could not find upload file: " + file); + NodeKey nodeKey = processFile(file, type); + + WookieAttachment attachment = new WookieAttachment( + nodeKey.getVersion(), type, file.getFileName(), nodeKey + .getUuid(), new Date()); + return attachment; } - NodeKey nodeKey = processFile(file, type); + public void deleteFromRepository(Long uuid, Long versionID) + throws WookieException { + ITicket ticket = getRepositoryLoginTicket(); + try { + repositoryService.deleteVersion(ticket, uuid, versionID); + } catch (Exception e) { + throw new WookieException( + "Exception occured while deleting files from" + + " the repository " + e.getMessage()); + } + } - WookieAttachment attachment = new WookieAttachment(nodeKey.getVersion(), type, file.getFileName(), nodeKey - .getUuid(), new Date()); - return attachment; - } + public void deleteInstructionFile(Long contentID, Long uuid, + Long versionID, String type) { + wookieDAO.deleteInstructionFile(contentID, uuid, versionID, type); - public void deleteFromRepository(Long uuid, Long versionID) throws WookieException { - ITicket ticket = getRepositoryLoginTicket(); - try { - repositoryService.deleteVersion(ticket, uuid, versionID); - } catch (Exception e) { - throw new WookieException("Exception occured while deleting files from" + " the repository " - + e.getMessage()); } - } - public void deleteInstructionFile(Long contentID, Long uuid, Long versionID, String type) { - wookieDAO.deleteInstructionFile(contentID, uuid, versionID, type); + public void saveOrUpdateWookie(Wookie wookie) { + wookieDAO.saveOrUpdate(wookie); + } - } + public void saveOrUpdateWookieSession(WookieSession wookieSession) { + wookieSessionDAO.saveOrUpdate(wookieSession); + } - public void saveOrUpdateWookie(Wookie wookie) { - wookieDAO.saveOrUpdate(wookie); - } + public void saveOrUpdateWookieUser(WookieUser wookieUser) { + wookieUserDAO.saveOrUpdate(wookieUser); + } - public void saveOrUpdateWookieSession(WookieSession wookieSession) { - wookieSessionDAO.saveOrUpdate(wookieSession); - } + public WookieUser createWookieUser(UserDTO user, WookieSession wookieSession) { + WookieUser wookieUser = new WookieUser(user, wookieSession); + saveOrUpdateWookieUser(wookieUser); + return wookieUser; + } - public void saveOrUpdateWookieUser(WookieUser wookieUser) { - wookieUserDAO.saveOrUpdate(wookieUser); - } + public IAuditService getAuditService() { + return auditService; + } - public WookieUser createWookieUser(UserDTO user, WookieSession wookieSession) { - WookieUser wookieUser = new WookieUser(user, wookieSession); - saveOrUpdateWookieUser(wookieUser); - return wookieUser; - } + public void setAuditService(IAuditService auditService) { + this.auditService = auditService; + } - public IAuditService getAuditService() { - return auditService; - } + private NodeKey processFile(FormFile file, String type) { + NodeKey node = null; + if (file != null && !StringUtils.isEmpty(file.getFileName())) { + String fileName = file.getFileName(); + try { + node = getWookieToolContentHandler().uploadFile( + file.getInputStream(), fileName, file.getContentType(), + type); + } catch (InvalidParameterException e) { + throw new WookieException( + "InvalidParameterException occured while trying to upload File" + + e.getMessage()); + } catch (FileNotFoundException e) { + throw new WookieException( + "FileNotFoundException occured while trying to upload File" + + e.getMessage()); + } catch (RepositoryCheckedException e) { + throw new WookieException( + "RepositoryCheckedException occured while trying to upload File" + + e.getMessage()); + } catch (IOException e) { + throw new WookieException( + "IOException occured while trying to upload File" + + e.getMessage()); + } + } + return node; + } - public void setAuditService(IAuditService auditService) { - this.auditService = auditService; - } + /** + * This method verifies the credentials of the SubmitFiles Tool and gives it + * the Ticket to login and access the Content Repository. + * + * A valid ticket is needed in order to access the content from the + * repository. This method would be called evertime the tool needs to + * upload/download files from the content repository. + * + * @return ITicket The ticket for repostory access + * @throws SubmitFilesException + */ + private ITicket getRepositoryLoginTicket() throws WookieException { + ICredentials credentials = new SimpleCredentials( + WookieToolContentHandler.repositoryUser, + WookieToolContentHandler.repositoryId); + try { + ITicket ticket = repositoryService.login(credentials, + WookieToolContentHandler.repositoryWorkspaceName); + return ticket; + } catch (AccessDeniedException ae) { + throw new WookieException("Access Denied to repository." + + ae.getMessage()); + } catch (WorkspaceNotFoundException we) { + throw new WookieException("Workspace not found." + we.getMessage()); + } catch (LoginException e) { + throw new WookieException("Login failed." + e.getMessage()); + } + } - private NodeKey processFile(FormFile file, String type) { - NodeKey node = null; - if (file != null && !StringUtils.isEmpty(file.getFileName())) { - String fileName = file.getFileName(); - try { - node = getWookieToolContentHandler().uploadFile(file.getInputStream(), fileName, file.getContentType(), - type); - } catch (InvalidParameterException e) { - throw new WookieException("InvalidParameterException occured while trying to upload File" - + e.getMessage()); - } catch (FileNotFoundException e) { - throw new WookieException("FileNotFoundException occured while trying to upload File" + e.getMessage()); - } catch (RepositoryCheckedException e) { - throw new WookieException("RepositoryCheckedException occured while trying to upload File" - + e.getMessage()); - } catch (IOException e) { - throw new WookieException("IOException occured while trying to upload File" + e.getMessage()); - } + public WookieConfigItem getConfigItem(String key) { + return wookieConfigItemDAO.getConfigItemByKey(key); } - return node; - } - /** - * This method verifies the credentials of the SubmitFiles Tool and gives it - * the Ticket to login and access the Content Repository. - * - * A valid ticket is needed in order to access the content from the - * repository. This method would be called evertime the tool needs to - * upload/download files from the content repository. - * - * @return ITicket The ticket for repostory access - * @throws SubmitFilesException - */ - private ITicket getRepositoryLoginTicket() throws WookieException { - ICredentials credentials = new SimpleCredentials(WookieToolContentHandler.repositoryUser, - WookieToolContentHandler.repositoryId); - try { - ITicket ticket = repositoryService.login(credentials, WookieToolContentHandler.repositoryWorkspaceName); - return ticket; - } catch (AccessDeniedException ae) { - throw new WookieException("Access Denied to repository." + ae.getMessage()); - } catch (WorkspaceNotFoundException we) { - throw new WookieException("Workspace not found." + we.getMessage()); - } catch (LoginException e) { - throw new WookieException("Login failed." + e.getMessage()); + public void saveOrUpdateWookieConfigItem(WookieConfigItem item) { + wookieConfigItemDAO.saveOrUpdate(item); } - } - public WookieConfigItem getConfigItem(String key) { - return wookieConfigItemDAO.getConfigItemByKey(key); - } + public String getWookieURL() { + String url = null; + WookieConfigItem urlItem = wookieConfigItemDAO + .getConfigItemByKey(WookieConfigItem.KEY_WOOKIE_URL); + if (urlItem != null) { + url = urlItem.getConfigValue(); + } + return url; + } - public void saveOrUpdateWookieConfigItem(WookieConfigItem item) { - wookieConfigItemDAO.saveOrUpdate(item); - } - - public String getWookieURL() { - String url = null; - WookieConfigItem urlItem = wookieConfigItemDAO.getConfigItemByKey(WookieConfigItem.KEY_WOOKIE_URL); - if (urlItem != null) { - url = urlItem.getConfigValue(); + public String getWookieAPIKey() { + String url = null; + WookieConfigItem apiItem = wookieConfigItemDAO + .getConfigItemByKey(WookieConfigItem.KEY_API); + if (apiItem != null) { + url = apiItem.getConfigValue(); + } + return url; } - return url; - } - public String getWookieAPIKey() { - String url = null; - WookieConfigItem apiItem = wookieConfigItemDAO.getConfigItemByKey(WookieConfigItem.KEY_API); - if (apiItem != null) { - url = apiItem.getConfigValue(); + public String getMessage(String key) { + return messageService.getMessage(key); } - return url; - } - public String getMessage(String key) { - return messageService.getMessage(key); - } + /* + * ===============Methods implemented from ToolContentImport102Manager + * =============== + */ - /* ===============Methods implemented from ToolContentImport102Manager =============== */ + /** + * Import the data for a 1.0.2 Wookie + */ + @SuppressWarnings("unchecked") + public void import102ToolContent(Long toolContentId, UserDTO user, + Hashtable importValues) { + Date now = new Date(); + Wookie wookie = new Wookie(); + wookie.setContentInUse(Boolean.FALSE); + wookie.setCreateBy(user.getUserID()); + wookie.setCreateDate(now); + wookie.setDefineLater(Boolean.FALSE); + wookie.setInstructions(WebUtil.convertNewlines((String) importValues + .get(ToolContentImport102Manager.CONTENT_BODY))); + wookie.setLockOnFinished(Boolean.TRUE); + wookie.setOfflineInstructions(null); + wookie.setOnlineInstructions(null); + wookie.setRunOffline(Boolean.FALSE); + wookie.setTitle((String) importValues + .get(ToolContentImport102Manager.CONTENT_TITLE)); + wookie.setToolContentId(toolContentId); + wookie.setUpdateDate(now); + wookie.setReflectOnActivity(Boolean.FALSE); + wookieDAO.saveOrUpdate(wookie); + } - /** - * Import the data for a 1.0.2 Wookie - */ - @SuppressWarnings("unchecked") - public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues) { - Date now = new Date(); - Wookie wookie = new Wookie(); - wookie.setContentInUse(Boolean.FALSE); - wookie.setCreateBy(user.getUserID()); - wookie.setCreateDate(now); - wookie.setDefineLater(Boolean.FALSE); - wookie.setInstructions(WebUtil.convertNewlines((String) importValues - .get(ToolContentImport102Manager.CONTENT_BODY))); - wookie.setLockOnFinished(Boolean.TRUE); - wookie.setOfflineInstructions(null); - wookie.setOnlineInstructions(null); - wookie.setRunOffline(Boolean.FALSE); - wookie.setTitle((String) importValues.get(ToolContentImport102Manager.CONTENT_TITLE)); - wookie.setToolContentId(toolContentId); - wookie.setUpdateDate(now); - wookie.setReflectOnActivity(Boolean.FALSE); - wookieDAO.saveOrUpdate(wookie); - } + /** + * Set the description, throws away the title value as this is not supported + * in 2.0 + */ + public void setReflectiveData(Long toolContentId, String title, + String description) throws ToolException, DataMissingException { - /** - * Set the description, throws away the title value as this is not supported - * in 2.0 - */ - public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException, - DataMissingException { + WookieService.logger + .warn("Setting the reflective field on a wookie. This doesn't make sense as the wookie is for reflection and we don't reflect on reflection!"); + Wookie wookie = getWookieByContentId(toolContentId); + if (wookie == null) { + throw new DataMissingException( + "Unable to set reflective data titled " + title + + " on activity toolContentId " + toolContentId + + " as the tool content does not exist."); + } - WookieService.logger - .warn("Setting the reflective field on a wookie. This doesn't make sense as the wookie is for reflection and we don't reflect on reflection!"); - Wookie wookie = getWookieByContentId(toolContentId); - if (wookie == null) { - throw new DataMissingException("Unable to set reflective data titled " + title - + " on activity toolContentId " + toolContentId + " as the tool content does not exist."); + wookie.setInstructions(description); } - wookie.setInstructions(description); - } + // ========================================================================================= + /* ********** Used by Spring to "inject" the linked objects ************* */ - // ========================================================================================= - /* ********** Used by Spring to "inject" the linked objects ************* */ + public IWookieAttachmentDAO getWookieAttachmentDAO() { + return wookieAttachmentDAO; + } - public IWookieAttachmentDAO getWookieAttachmentDAO() { - return wookieAttachmentDAO; - } + public void setWookieAttachmentDAO(IWookieAttachmentDAO attachmentDAO) { + wookieAttachmentDAO = attachmentDAO; + } - public void setWookieAttachmentDAO(IWookieAttachmentDAO attachmentDAO) { - wookieAttachmentDAO = attachmentDAO; - } + public IWookieDAO getWookieDAO() { + return wookieDAO; + } - public IWookieDAO getWookieDAO() { - return wookieDAO; - } + public void setWookieDAO(IWookieDAO wookieDAO) { + this.wookieDAO = wookieDAO; + } - public void setWookieDAO(IWookieDAO wookieDAO) { - this.wookieDAO = wookieDAO; - } + public IToolContentHandler getWookieToolContentHandler() { + return wookieToolContentHandler; + } - public IToolContentHandler getWookieToolContentHandler() { - return wookieToolContentHandler; - } + public void setWookieToolContentHandler( + IToolContentHandler wookieToolContentHandler) { + this.wookieToolContentHandler = wookieToolContentHandler; + } - public void setWookieToolContentHandler(IToolContentHandler wookieToolContentHandler) { - this.wookieToolContentHandler = wookieToolContentHandler; - } + public IWookieSessionDAO getWookieSessionDAO() { + return wookieSessionDAO; + } - public IWookieSessionDAO getWookieSessionDAO() { - return wookieSessionDAO; - } + public void setWookieSessionDAO(IWookieSessionDAO sessionDAO) { + wookieSessionDAO = sessionDAO; + } - public void setWookieSessionDAO(IWookieSessionDAO sessionDAO) { - wookieSessionDAO = sessionDAO; - } + public ILamsToolService getToolService() { + return toolService; + } - public ILamsToolService getToolService() { - return toolService; - } + public void setToolService(ILamsToolService toolService) { + this.toolService = toolService; + } - public void setToolService(ILamsToolService toolService) { - this.toolService = toolService; - } + public IWookieUserDAO getWookieUserDAO() { + return wookieUserDAO; + } - public IWookieUserDAO getWookieUserDAO() { - return wookieUserDAO; - } + public void setWookieUserDAO(IWookieUserDAO userDAO) { + wookieUserDAO = userDAO; + } - public void setWookieUserDAO(IWookieUserDAO userDAO) { - wookieUserDAO = userDAO; - } + public ILearnerService getLearnerService() { + return learnerService; + } - public ILearnerService getLearnerService() { - return learnerService; - } + public void setLearnerService(ILearnerService learnerService) { + this.learnerService = learnerService; + } - public void setLearnerService(ILearnerService learnerService) { - this.learnerService = learnerService; - } + public IExportToolContentService getExportContentService() { + return exportContentService; + } - public IExportToolContentService getExportContentService() { - return exportContentService; - } + public void setExportContentService( + IExportToolContentService exportContentService) { + this.exportContentService = exportContentService; + } - public void setExportContentService(IExportToolContentService exportContentService) { - this.exportContentService = exportContentService; - } + public ICoreNotebookService getCoreNotebookService() { + return coreNotebookService; + } - public ICoreNotebookService getCoreNotebookService() { - return coreNotebookService; - } + public void setCoreNotebookService(ICoreNotebookService coreNotebookService) { + this.coreNotebookService = coreNotebookService; + } - public void setCoreNotebookService(ICoreNotebookService coreNotebookService) { - this.coreNotebookService = coreNotebookService; - } + public WookieOutputFactory getWookieOutputFactory() { + return wookieOutputFactory; + } - public WookieOutputFactory getWookieOutputFactory() { - return wookieOutputFactory; - } + public void setWookieOutputFactory(WookieOutputFactory wookieOutputFactory) { + this.wookieOutputFactory = wookieOutputFactory; + } - public void setWookieOutputFactory(WookieOutputFactory wookieOutputFactory) { - this.wookieOutputFactory = wookieOutputFactory; - } + public IWookieConfigItemDAO getWookieConfigItemDAO() { + return wookieConfigItemDAO; + } - public IWookieConfigItemDAO getWookieConfigItemDAO() { - return wookieConfigItemDAO; - } + public void setWookieConfigItemDAO(IWookieConfigItemDAO wookieConfigItemDAO) { + this.wookieConfigItemDAO = wookieConfigItemDAO; + } - public void setWookieConfigItemDAO(IWookieConfigItemDAO wookieConfigItemDAO) { - this.wookieConfigItemDAO = wookieConfigItemDAO; - } + public IRepositoryService getRepositoryService() { + return repositoryService; + } - public IRepositoryService getRepositoryService() { - return repositoryService; - } + public void setRepositoryService(IRepositoryService repositoryService) { + this.repositoryService = repositoryService; + } - public void setRepositoryService(IRepositoryService repositoryService) { - this.repositoryService = repositoryService; - } + public MessageService getMessageService() { + return messageService; + } - public MessageService getMessageService() { - return messageService; - } + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } - public void setMessageService(MessageService messageService) { - this.messageService = messageService; - } + public IUserManagementService getUserManagementService() { + return userManagementService; + } - public IUserManagementService getUserManagementService() { - return userManagementService; - } + public void setUserManagementService( + IUserManagementService userManagementService) { + this.userManagementService = userManagementService; + } - public void setUserManagementService(IUserManagementService userManagementService) { - this.userManagementService = userManagementService; - } - } Index: lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java =================================================================== diff -u -r08622dbb2e6672584f1cfcb52a239a46b3d667b1 -rfb5248530c656fdc6731a15e6493fa9050dfbebd --- lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 08622dbb2e6672584f1cfcb52a239a46b3d667b1) +++ lams_tool_wookie/src/java/org/lamsfoundation/lams/tool/wookie/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision fb5248530c656fdc6731a15e6493fa9050dfbebd) @@ -75,513 +75,572 @@ */ public class AuthoringAction extends LamsDispatchAction { - private static Logger logger = Logger.getLogger(AuthoringAction.class); + private static Logger logger = Logger.getLogger(AuthoringAction.class); - public IWookieService wookieService; + public IWookieService wookieService; - // Authoring SessionMap key names - private static final String KEY_TOOL_CONTENT_ID = "toolContentID"; - private static final String KEY_CONTENT_FOLDER_ID = "contentFolderID"; - private static final String KEY_MODE = "mode"; - private static final String KEY_ONLINE_FILES = "onlineFiles"; - private static final String KEY_OFFLINE_FILES = "offlineFiles"; - private static final String KEY_UNSAVED_ONLINE_FILES = "unsavedOnlineFiles"; - private static final String KEY_UNSAVED_OFFLINE_FILES = "unsavedOfflineFiles"; - private static final String KEY_DELETED_FILES = "deletedFiles"; + // Authoring SessionMap key names + private static final String KEY_TOOL_CONTENT_ID = "toolContentID"; + private static final String KEY_CONTENT_FOLDER_ID = "contentFolderID"; + private static final String KEY_MODE = "mode"; + private static final String KEY_ONLINE_FILES = "onlineFiles"; + private static final String KEY_OFFLINE_FILES = "offlineFiles"; + private static final String KEY_UNSAVED_ONLINE_FILES = "unsavedOnlineFiles"; + private static final String KEY_UNSAVED_OFFLINE_FILES = "unsavedOfflineFiles"; + private static final String KEY_DELETED_FILES = "deletedFiles"; - /** - * Default method when no dispatch parameter is specified. It is expected - * that the parameter toolContentID will be passed in. This - * will be used to retrieve content for this tool. - * - */ - @Override - protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + /** + * Default method when no dispatch parameter is specified. It is expected + * that the parameter toolContentID will be passed in. This + * will be used to retrieve content for this tool. + * + */ + @Override + protected ActionForward unspecified(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { - // Extract toolContentID from parameters. - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + // Extract toolContentID from parameters. + Long toolContentID = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_CONTENT_ID)); - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); + String contentFolderID = WebUtil.readStrParam(request, + AttributeNames.PARAM_CONTENT_FOLDER_ID); - AuthoringForm authForm = (AuthoringForm) form; + AuthoringForm authForm = (AuthoringForm) form; - ToolAccessMode mode = null; - String modeStr = WebUtil.readStrParam(request, "mode", true); - if (modeStr != null && !modeStr.trim().equals("")) { - mode = WebUtil.readToolAccessModeParam(request, "mode", true); - } + ToolAccessMode mode = null; + String modeStr = WebUtil.readStrParam(request, "mode", true); + if (modeStr != null && !modeStr.trim().equals("")) { + mode = WebUtil.readToolAccessModeParam(request, "mode", true); + } - // set up wookieService - if (wookieService == null) { - wookieService = WookieServiceProxy.getWookieService(this.getServlet().getServletContext()); - } + // set up wookieService + if (wookieService == null) { + wookieService = WookieServiceProxy.getWookieService(this + .getServlet().getServletContext()); + } - String wookieUrl = wookieService.getWookieURL(); - if (wookieUrl == null) { - throw new WookieException(wookieService.getMessage("error.wookie.not.configured")); - } + String wookieUrl = wookieService.getWookieURL(); + if (wookieUrl == null) { + throw new WookieException(wookieService + .getMessage("error.wookie.not.configured")); + } - // Get the widget count - try { - int widgetCount = WookieUtil.getWidgetCount(wookieUrl); - if (widgetCount > 0) { - int pages = 1; - float pagesFloat = new Float(widgetCount) / WookieConstants.WIDGETS_PER_PAGE; - if (pagesFloat > 1) { + // Get the widget count + try { + int widgetCount = WookieUtil.getWidgetCount(wookieUrl); + if (widgetCount > 0) { + int pages = 1; + float pagesFloat = new Float(widgetCount) + / WookieConstants.WIDGETS_PER_PAGE; + if (pagesFloat > 1) { - pages = (new Float(Math.ceil(pagesFloat))).intValue(); + pages = (new Float(Math.ceil(pagesFloat))).intValue(); + } + + request.setAttribute(WookieConstants.ATTR_WIDGET_PAGES, pages); + } + } catch (Exception e) { + logger.error("Error initiating widget on wookie server", e); + throw new WookieException(wookieService + .getMessage("error.initiating.widget"), e); } - request.setAttribute(WookieConstants.ATTR_WIDGET_PAGES, pages); - } - } catch (Exception e) { - logger.error("Error initiating widget on wookie server", e); - throw new WookieException(wookieService.getMessage("error.initiating.widget"), e); - } + // retrieving Wookie with given toolContentID + Wookie wookie = wookieService.getWookieByContentId(toolContentID); + if (wookie == null) { + wookie = wookieService.copyDefaultContent(toolContentID); + wookie.setCreateDate(new Date()); + wookie.setCreateBy(getUser().getUserID()); + wookieService.saveOrUpdateWookie(wookie); + } - // retrieving Wookie with given toolContentID - Wookie wookie = wookieService.getWookieByContentId(toolContentID); - if (wookie == null) { - wookie = wookieService.copyDefaultContent(toolContentID); - wookie.setCreateDate(new Date()); - wookie.setCreateBy(getUser().getUserID()); - wookieService.saveOrUpdateWookie(wookie); - } + if (mode != null && mode.isTeacher()) { + // Set the defineLater flag so that learners cannot use content + // while we + // are editing. This flag is released when updateContent is called. + wookie.setDefineLater(true); + wookieService.saveOrUpdateWookie(wookie); + } - if (mode != null && mode.isTeacher()) { - // Set the defineLater flag so that learners cannot use content - // while we - // are editing. This flag is released when updateContent is called. - wookie.setDefineLater(true); - wookieService.saveOrUpdateWookie(wookie); - } + // Set up the authForm. + updateAuthForm(authForm, wookie); + authForm.setToolContentID(toolContentID); + if (mode != null) { + authForm.setMode(mode.toString()); + } else { + authForm.setMode(""); + } + authForm.setContentFolderID(contentFolderID); - // Set up the authForm. - updateAuthForm(authForm, wookie); - authForm.setToolContentID(toolContentID); - if (mode != null) { - authForm.setMode(mode.toString()); - } else { - authForm.setMode(""); - } - authForm.setContentFolderID(contentFolderID); - - // Set up sessionMap - SessionMap map = createSessionMap(wookie, getAccessMode(request), contentFolderID, - toolContentID); - authForm.setSessionMapID(map.getSessionID()); + // Set up sessionMap + SessionMap map = createSessionMap(wookie, + getAccessMode(request), contentFolderID, toolContentID); + authForm.setSessionMapID(map.getSessionID()); - // add the sessionMap to HTTPSession. - request.getSession().setAttribute(map.getSessionID(), map); - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + // add the sessionMap to HTTPSession. + request.getSession().setAttribute(map.getSessionID(), map); + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - return mapping.findForward("success"); - } + return mapping.findForward("success"); + } - public ActionForward getWidgets(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws WookieException { + public ActionForward getWidgets(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws WookieException { - // set up wookieService - if (wookieService == null) { - wookieService = WookieServiceProxy.getWookieService(this.getServlet().getServletContext()); - } + // set up wookieService + if (wookieService == null) { + wookieService = WookieServiceProxy.getWookieService(this + .getServlet().getServletContext()); + } - Integer pageNumber = WebUtil.readIntParam(request, WookieConstants.PARAM_PAGE_NUMBER); + Integer pageNumber = WebUtil.readIntParam(request, + WookieConstants.PARAM_PAGE_NUMBER); - // Fetch all the available wookie widgets - try { - String wookieUrl = wookieService.getWookieURL(); - if (wookieUrl == null) { - throw new WookieException(wookieService.getMessage("error.wookie.not.configured")); - } + // Fetch all the available wookie widgets + try { + String wookieUrl = wookieService.getWookieURL(); + if (wookieUrl == null) { + throw new WookieException(wookieService + .getMessage("error.wookie.not.configured")); + } - List widgetDefinitions = WookieUtil.getWidgetDefinitions(wookieUrl); - List cutDownWidgetDefinitions = null; + List widgetDefinitions = WookieUtil + .getWidgetDefinitions(wookieUrl); + List cutDownWidgetDefinitions = null; - int startIndex = WookieConstants.WIDGETS_PER_PAGE * (pageNumber - 1); - int endIndex = WookieConstants.WIDGETS_PER_PAGE * (pageNumber); - if (widgetDefinitions.size() > startIndex) { - if (widgetDefinitions.size() > endIndex) { - // Use the start and end index - within range - cutDownWidgetDefinitions = widgetDefinitions.subList(startIndex, endIndex); - } else { - // Use the start index to the end of the list - cutDownWidgetDefinitions = widgetDefinitions.subList(startIndex, widgetDefinitions.size()); - } + int startIndex = WookieConstants.WIDGETS_PER_PAGE + * (pageNumber - 1); + int endIndex = WookieConstants.WIDGETS_PER_PAGE * (pageNumber); + if (widgetDefinitions.size() > startIndex) { + if (widgetDefinitions.size() > endIndex) { + // Use the start and end index - within range + cutDownWidgetDefinitions = widgetDefinitions.subList( + startIndex, endIndex); + } else { + // Use the start index to the end of the list + cutDownWidgetDefinitions = widgetDefinitions.subList( + startIndex, widgetDefinitions.size()); + } - } - request.setAttribute(WookieConstants.ATTR_WIDGET_LIST, cutDownWidgetDefinitions); - return mapping.findForward("widgetList"); + } + request.setAttribute(WookieConstants.ATTR_WIDGET_LIST, + cutDownWidgetDefinitions); + return mapping.findForward("widgetList"); - } catch (Exception e) { - logger.error("Problem reading xml from wookie server.", e); - throw new WookieException(e); + } catch (Exception e) { + logger.error("Problem reading xml from wookie server.", e); + throw new WookieException(e); + } } - } - public ActionForward initiateWidget(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws WookieException { - try { - // set up wookieService - if (wookieService == null) { - wookieService = WookieServiceProxy.getWookieService(this.getServlet().getServletContext()); - } + public ActionForward initiateWidget(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws WookieException { + try { + // set up wookieService + if (wookieService == null) { + wookieService = WookieServiceProxy.getWookieService(this + .getServlet().getServletContext()); + } - String wookieUrl = wookieService.getWookieURL(); - String wookieKey = wookieService.getWookieAPIKey(); - String wookieIdentifier = WebUtil.readStrParam(request, WookieConstants.PARAM_KEY_WIDGET_ID); - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + String wookieUrl = wookieService.getWookieURL(); + String wookieKey = wookieService.getWookieAPIKey(); + String wookieIdentifier = WebUtil.readStrParam(request, + WookieConstants.PARAM_KEY_WIDGET_ID); + Long toolContentID = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_CONTENT_ID)); - wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; + wookieUrl += WookieConstants.RELATIVE_URL_WIDGET_SERVICE; - String returnXML = WookieUtil.getWidget(wookieUrl, wookieKey, wookieIdentifier, getUser(), toolContentID - .toString(), true); + String returnXML = WookieUtil + .getWidget(wookieUrl, wookieKey, wookieIdentifier, + getUser(), toolContentID.toString(), true); - this.writeResponse(response, "text/xml;charset=utf-8", "utf-8", returnXML); + this.writeResponse(response, "text/xml;charset=utf-8", "utf-8", + returnXML); - } catch (Exception e) { - log.error("Problem intitiation widget" + e); - throw new WookieException(e); + } catch (Exception e) { + log.error("Problem intitiation widget" + e); + throw new WookieException(e); + } + return null; } - return null; - } - public ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws WookieException { - // TODO need error checking. + public ActionForward updateContent(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws WookieException { + // TODO need error checking. - // get authForm and session map. - AuthoringForm authForm = (AuthoringForm) form; - SessionMap map = getSessionMap(request, authForm); - ToolAccessMode mode = (ToolAccessMode) map.get(AuthoringAction.KEY_MODE); + // get authForm and session map. + AuthoringForm authForm = (AuthoringForm) form; + SessionMap map = getSessionMap(request, authForm); + ToolAccessMode mode = (ToolAccessMode) map + .get(AuthoringAction.KEY_MODE); - // get wookie content. - Wookie wookie = wookieService.getWookieByContentId((Long) map.get(AuthoringAction.KEY_TOOL_CONTENT_ID)); + // get wookie content. + Wookie wookie = wookieService.getWookieByContentId((Long) map + .get(AuthoringAction.KEY_TOOL_CONTENT_ID)); - // update wookie content using form inputs. - updateWookie(wookie, authForm, mode); + // update wookie content using form inputs. + updateWookie(wookie, authForm, mode); - // remove attachments marked for deletion. - Set attachments = wookie.getWookieAttachments(); - if (attachments == null) { - attachments = new HashSet(); - } + // remove attachments marked for deletion. + Set attachments = wookie.getWookieAttachments(); + if (attachments == null) { + attachments = new HashSet(); + } - for (WookieAttachment att : getAttList(AuthoringAction.KEY_DELETED_FILES, map)) { - // remove from db, leave in repository - attachments.remove(att); - } + for (WookieAttachment att : getAttList( + AuthoringAction.KEY_DELETED_FILES, map)) { + // remove from db, leave in repository + attachments.remove(att); + } - // add unsaved attachments - attachments.addAll(getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map)); - attachments.addAll(getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map)); + // add unsaved attachments + attachments.addAll(getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, + map)); + attachments.addAll(getAttList( + AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map)); - // set attachments in case it didn't exist - wookie.setWookieAttachments(attachments); + // set attachments in case it didn't exist + wookie.setWookieAttachments(attachments); - // set the update date - wookie.setUpdateDate(new Date()); + // set the update date + wookie.setUpdateDate(new Date()); - // releasing defineLater flag so that learner can start using the tool. - wookie.setDefineLater(false); + // releasing defineLater flag so that learner can start using the tool. + wookie.setDefineLater(false); - wookieService.saveOrUpdateWookie(wookie); + wookieService.saveOrUpdateWookie(wookie); - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, + Boolean.TRUE); - // add the sessionMapID to form - authForm.setSessionMapID(map.getSessionID()); + // add the sessionMapID to form + authForm.setSessionMapID(map.getSessionID()); - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - updateAuthForm(authForm, wookie); - if (mode != null) { - authForm.setMode(mode.toString()); - } else { - authForm.setMode(""); + updateAuthForm(authForm, wookie); + if (mode != null) { + authForm.setMode(mode.toString()); + } else { + authForm.setMode(""); + } + + return mapping.findForward("success"); } - return mapping.findForward("success"); - } + public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + return uploadFile(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_ONLINE, request); + } - public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return uploadFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); - } + public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + return uploadFile(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_OFFLINE, request); + } - public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return uploadFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); - } + public ActionForward deleteOnline(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + return deleteFile(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_ONLINE, request); + } - public ActionForward deleteOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return deleteFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); - } + public ActionForward deleteOffline(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + return deleteFile(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_OFFLINE, request); + } - public ActionForward deleteOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return deleteFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); - } + public ActionForward removeUnsavedOnline(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return removeUnsaved(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_ONLINE, request); + } - public ActionForward removeUnsavedOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return removeUnsaved(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); - } + public ActionForward removeUnsavedOffline(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return removeUnsaved(mapping, (AuthoringForm) form, + IToolContentHandler.TYPE_OFFLINE, request); + } - public ActionForward removeUnsavedOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return removeUnsaved(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); - } + /* ========== Private Methods ********** */ - /* ========== Private Methods ********** */ + private ActionForward uploadFile(ActionMapping mapping, + AuthoringForm authForm, String type, HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - private ActionForward uploadFile(ActionMapping mapping, AuthoringForm authForm, String type, - HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + FormFile file; + List unsavedFiles; + List savedFiles; + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + file = authForm.getOfflineFile(); + unsavedFiles = getAttList( + AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); - FormFile file; - List unsavedFiles; - List savedFiles; - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - file = authForm.getOfflineFile(); - unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); + savedFiles = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); + } else { + file = authForm.getOnlineFile(); + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, + map); - savedFiles = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); - } else { - file = authForm.getOnlineFile(); - unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map); + savedFiles = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); + } - savedFiles = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); - } + // validate file max size + ActionMessages errors = new ActionMessages(); + FileValidatorUtil.validateFileSize(file, true, errors); + if (!errors.isEmpty()) { + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + this.saveErrors(request, errors); + return mapping.findForward("success"); + } - // validate file max size - ActionMessages errors = new ActionMessages(); - FileValidatorUtil.validateFileSize(file, true, errors); - if (!errors.isEmpty()) { - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - this.saveErrors(request, errors); - return mapping.findForward("success"); - } + if (file.getFileName().length() != 0) { - if (file.getFileName().length() != 0) { + // upload file to repository + WookieAttachment newAtt = wookieService.uploadFileToContent( + (Long) map.get(AuthoringAction.KEY_TOOL_CONTENT_ID), file, + type); - // upload file to repository - WookieAttachment newAtt = wookieService.uploadFileToContent((Long) map - .get(AuthoringAction.KEY_TOOL_CONTENT_ID), file, type); + // Add attachment to unsavedFiles + // check to see if file with same name exists + WookieAttachment currAtt; + Iterator iter = savedFiles.iterator(); + while (iter.hasNext()) { + currAtt = (WookieAttachment) iter.next(); + if (StringUtils.equals(currAtt.getFileName(), newAtt + .getFileName()) + && StringUtils.equals(currAtt.getFileType(), newAtt + .getFileType())) { + // move from this this list to deleted list. + getAttList(AuthoringAction.KEY_DELETED_FILES, map).add( + currAtt); + iter.remove(); + break; + } + } + unsavedFiles.add(newAtt); - // Add attachment to unsavedFiles - // check to see if file with same name exists - WookieAttachment currAtt; - Iterator iter = savedFiles.iterator(); - while (iter.hasNext()) { - currAtt = (WookieAttachment) iter.next(); - if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName()) - && StringUtils.equals(currAtt.getFileType(), newAtt.getFileType())) { - // move from this this list to deleted list. - getAttList(AuthoringAction.KEY_DELETED_FILES, map).add(currAtt); - iter.remove(); - break; + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); } - } - unsavedFiles.add(newAtt); - - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); + return mapping.findForward("success"); } - return mapping.findForward("success"); - } - private ActionForward deleteFile(ActionMapping mapping, AuthoringForm authForm, String type, - HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + private ActionForward deleteFile(ActionMapping mapping, + AuthoringForm authForm, String type, HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - List fileList; - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - fileList = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); - } else { - fileList = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); - } + List fileList; + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + fileList = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); + } else { + fileList = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); + } - Iterator iter = fileList.iterator(); + Iterator iter = fileList.iterator(); - while (iter.hasNext()) { - WookieAttachment att = (WookieAttachment) iter.next(); + while (iter.hasNext()) { + WookieAttachment att = (WookieAttachment) iter.next(); - if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { - // move to delete file list, deleted at next updateContent - getAttList(AuthoringAction.KEY_DELETED_FILES, map).add(att); + if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { + // move to delete file list, deleted at next updateContent + getAttList(AuthoringAction.KEY_DELETED_FILES, map).add(att); - // remove from this list - iter.remove(); - break; - } + // remove from this list + iter.remove(); + break; + } + } + + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); + + return mapping.findForward("success"); } - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); + private ActionForward removeUnsaved(ActionMapping mapping, + AuthoringForm authForm, String type, HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - return mapping.findForward("success"); - } + List unsavedFiles; - private ActionForward removeUnsaved(ActionMapping mapping, AuthoringForm authForm, String type, - HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + unsavedFiles = getAttList( + AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); + } else { + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, + map); + } - List unsavedFiles; + Iterator iter = unsavedFiles.iterator(); + while (iter.hasNext()) { + WookieAttachment att = (WookieAttachment) iter.next(); - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); - } else { - unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map); - } + if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { + // delete from repository and list + wookieService.deleteFromRepository(att.getFileUuid(), att + .getFileVersionId()); + iter.remove(); + break; + } + } - Iterator iter = unsavedFiles.iterator(); - while (iter.hasNext()) { - WookieAttachment att = (WookieAttachment) iter.next(); + request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); - if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { - // delete from repository and list - wookieService.deleteFromRepository(att.getFileUuid(), att.getFileVersionId()); - iter.remove(); - break; - } + return mapping.findForward("success"); } - request.setAttribute(WookieConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); + /** + * Updates Wookie content using AuthoringForm inputs. + * + * @param authForm + * @param mode + * @return + */ + private void updateWookie(Wookie wookie, AuthoringForm authForm, + ToolAccessMode mode) { + wookie.setTitle(authForm.getTitle()); + wookie.setInstructions(authForm.getInstructions()); + if (mode.isAuthor()) { // Teacher cannot modify following + wookie.setOfflineInstructions(authForm.getOnlineInstruction()); + wookie.setOnlineInstructions(authForm.getOfflineInstruction()); + wookie.setLockOnFinished(authForm.isLockOnFinished()); + wookie.setReflectOnActivity(authForm.isReflectOnActivity()); + wookie.setReflectInstructions(authForm.getReflectInstructions()); + wookie.setWidgetAuthorUrl(authForm.getWidgetAuthorUrl()); + wookie.setWidgetHeight(authForm.getWidgetHeight()); + wookie.setWidgetWidth(authForm.getWidgetWidth()); + wookie.setWidgetMaximise(authForm.getWidgetMaximise()); + wookie.setWidgetIdentifier(authForm.getWidgetIdentifier()); + } + } - return mapping.findForward("success"); - } + /** + * Updates AuthoringForm using Wookie content. + * + * @param wookie + * @param authForm + * @return + */ + private void updateAuthForm(AuthoringForm authForm, Wookie wookie) { + authForm.setTitle(wookie.getTitle()); + authForm.setInstructions(wookie.getInstructions()); + authForm.setOnlineInstruction(wookie.getOnlineInstructions()); + authForm.setOfflineInstruction(wookie.getOfflineInstructions()); + authForm.setLockOnFinished(wookie.isLockOnFinished()); + authForm.setReflectOnActivity(wookie.isReflectOnActivity()); + authForm.setReflectInstructions(wookie.getReflectInstructions()); - /** - * Updates Wookie content using AuthoringForm inputs. - * - * @param authForm - * @param mode - * @return - */ - private void updateWookie(Wookie wookie, AuthoringForm authForm, ToolAccessMode mode) { - wookie.setTitle(authForm.getTitle()); - wookie.setInstructions(authForm.getInstructions()); - if (mode.isAuthor()) { // Teacher cannot modify following - wookie.setOfflineInstructions(authForm.getOnlineInstruction()); - wookie.setOnlineInstructions(authForm.getOfflineInstruction()); - wookie.setLockOnFinished(authForm.isLockOnFinished()); - wookie.setReflectOnActivity(authForm.isReflectOnActivity()); - wookie.setReflectInstructions(authForm.getReflectInstructions()); - wookie.setWidgetAuthorUrl(authForm.getWidgetAuthorUrl()); - wookie.setWidgetHeight(authForm.getWidgetHeight()); - wookie.setWidgetWidth(authForm.getWidgetWidth()); - wookie.setWidgetMaximise(authForm.getWidgetMaximise()); - wookie.setWidgetIdentifier(authForm.getWidgetIdentifier()); + // Set the wookie params + authForm.setWidgetAuthorUrl(wookie.getWidgetAuthorUrl()); + authForm.setWidgetHeight(wookie.getWidgetHeight()); + authForm.setWidgetWidth(wookie.getWidgetWidth()); + authForm.setWidgetMaximise(wookie.getWidgetMaximise()); + authForm.setWidgetIdentifier(wookie.getWidgetIdentifier()); } - } - /** - * Updates AuthoringForm using Wookie content. - * - * @param wookie - * @param authForm - * @return - */ - private void updateAuthForm(AuthoringForm authForm, Wookie wookie) { - authForm.setTitle(wookie.getTitle()); - authForm.setInstructions(wookie.getInstructions()); - authForm.setOnlineInstruction(wookie.getOnlineInstructions()); - authForm.setOfflineInstruction(wookie.getOfflineInstructions()); - authForm.setLockOnFinished(wookie.isLockOnFinished()); - authForm.setReflectOnActivity(wookie.isReflectOnActivity()); - authForm.setReflectInstructions(wookie.getReflectInstructions()); - - // Set the wookie params - authForm.setWidgetAuthorUrl(wookie.getWidgetAuthorUrl()); - authForm.setWidgetHeight(wookie.getWidgetHeight()); - authForm.setWidgetWidth(wookie.getWidgetWidth()); - authForm.setWidgetMaximise(wookie.getWidgetMaximise()); - authForm.setWidgetIdentifier(wookie.getWidgetIdentifier()); - } + /** + * Updates SessionMap using Wookie content. + * + * @param wookie + * @param mode + */ + private SessionMap createSessionMap(Wookie wookie, + ToolAccessMode mode, String contentFolderID, Long toolContentID) { - /** - * Updates SessionMap using Wookie content. - * - * @param wookie - * @param mode - */ - private SessionMap createSessionMap(Wookie wookie, ToolAccessMode mode, String contentFolderID, - Long toolContentID) { + SessionMap map = new SessionMap(); - SessionMap map = new SessionMap(); + map.put(AuthoringAction.KEY_MODE, mode); + map.put(AuthoringAction.KEY_CONTENT_FOLDER_ID, contentFolderID); + map.put(AuthoringAction.KEY_TOOL_CONTENT_ID, toolContentID); + map.put(AuthoringAction.KEY_ONLINE_FILES, + new LinkedList()); + map.put(AuthoringAction.KEY_OFFLINE_FILES, + new LinkedList()); + map.put(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, + new LinkedList()); + map.put(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, + new LinkedList()); + map.put(AuthoringAction.KEY_DELETED_FILES, + new LinkedList()); - map.put(AuthoringAction.KEY_MODE, mode); - map.put(AuthoringAction.KEY_CONTENT_FOLDER_ID, contentFolderID); - map.put(AuthoringAction.KEY_TOOL_CONTENT_ID, toolContentID); - map.put(AuthoringAction.KEY_ONLINE_FILES, new LinkedList()); - map.put(AuthoringAction.KEY_OFFLINE_FILES, new LinkedList()); - map.put(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, new LinkedList()); - map.put(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, new LinkedList()); - map.put(AuthoringAction.KEY_DELETED_FILES, new LinkedList()); + Iterator iter = wookie.getWookieAttachments() + .iterator(); + while (iter.hasNext()) { + WookieAttachment attachment = (WookieAttachment) iter.next(); + String type = attachment.getFileType(); + if (type.equals(IToolContentHandler.TYPE_OFFLINE)) { + getAttList(AuthoringAction.KEY_OFFLINE_FILES, map).add( + attachment); + } + if (type.equals(IToolContentHandler.TYPE_ONLINE)) { + getAttList(AuthoringAction.KEY_ONLINE_FILES, map).add( + attachment); + } + } - Iterator iter = wookie.getWookieAttachments().iterator(); - while (iter.hasNext()) { - WookieAttachment attachment = (WookieAttachment) iter.next(); - String type = attachment.getFileType(); - if (type.equals(IToolContentHandler.TYPE_OFFLINE)) { - getAttList(AuthoringAction.KEY_OFFLINE_FILES, map).add(attachment); - } - if (type.equals(IToolContentHandler.TYPE_ONLINE)) { - getAttList(AuthoringAction.KEY_ONLINE_FILES, map).add(attachment); - } + return map; } - return map; - } + /** + * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR + * mode. + * + * @param request + * @return + */ + private ToolAccessMode getAccessMode(HttpServletRequest request) { + ToolAccessMode mode; + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER + .toString())) { + mode = ToolAccessMode.TEACHER; + } else { + mode = ToolAccessMode.AUTHOR; + } + return mode; + } - /** - * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR - * mode. - * - * @param request - * @return - */ - private ToolAccessMode getAccessMode(HttpServletRequest request) { - ToolAccessMode mode; - String modeStr = request.getParameter(AttributeNames.ATTR_MODE); - if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER.toString())) { - mode = ToolAccessMode.TEACHER; - } else { - mode = ToolAccessMode.AUTHOR; + /** + * Retrieves a List of attachments from the map using the key. + * + * @param key + * @param map + * @return + */ + @SuppressWarnings("unchecked") + private List getAttList(String key, + SessionMap map) { + List list = (List) map.get(key); + return list; } - return mode; - } - /** - * Retrieves a List of attachments from the map using the key. - * - * @param key - * @param map - * @return - */ - @SuppressWarnings("unchecked") - private List getAttList(String key, SessionMap map) { - List list = (List) map.get(key); - return list; - } + /** + * Retrieve the SessionMap from the HttpSession. + * + * @param request + * @param authForm + * @return + */ + @SuppressWarnings("unchecked") + private SessionMap getSessionMap( + HttpServletRequest request, AuthoringForm authForm) { + return (SessionMap) request.getSession().getAttribute( + authForm.getSessionMapID()); + } - /** - * Retrieve the SessionMap from the HttpSession. - * - * @param request - * @param authForm - * @return - */ - @SuppressWarnings("unchecked") - private SessionMap getSessionMap(HttpServletRequest request, AuthoringForm authForm) { - return (SessionMap) request.getSession().getAttribute(authForm.getSessionMapID()); - } - - private UserDTO getUser() { - return (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); - } + private UserDTO getUser() { + return (UserDTO) SessionManager.getSession().getAttribute( + AttributeNames.USER); + } }