Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/ImportToolContentAction.java =================================================================== diff -u -r0a6c62299b683e8b70b6f58b99d26fcedc0c751f -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/ImportToolContentAction.java (.../ImportToolContentAction.java) (revision 0a6c62299b683e8b70b6f58b99d26fcedc0c751f) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/ImportToolContentAction.java (.../ImportToolContentAction.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -24,7 +24,11 @@ /* $Id$ */ package org.lamsfoundation.lams.authoring.web; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -51,160 +55,267 @@ import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsAction; +import org.lamsfoundation.lams.web.lamscommunity.LamsCommunityUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; + /** - * * @struts.action path = "/authoring/importToolContent" - * validate = "false" - * @struts.action-forward name = "upload" path = "/toolcontent/import.jsp" - * @struts.action-forward name = "success" path = "/toolcontent/importresult.jsp" + * * * - * Import tool content servlet. It needs an uploaded learning design zip file. + * @struts.action path = "/authoring/importToolContent" validate = "false" + * @struts.action-forward name="upload" path="/toolcontent/import.jsp" + * @struts.action-forward name="success" path="/toolcontent/importresult.jsp" + * @struts.action-forward name="successLC" path="/toolcontent/importresultLC.jsp" + * @struts.action-forward name="importLC" path="/toolcontent/importLC.jsp" + * + * Import tool content servlet. It needs an uploaded learning design zip file. * @author Steve.Ni */ public class ImportToolContentAction extends LamsAction { - public static final String EXPORT_TOOLCONTENT_SERVICE_BEAN_NAME = "exportToolContentService"; - public static final String USER_SERVICE_BEAN_NAME = "userManagementService"; - public static final String MESSAGE_SERVICE_BEAN_NAME = "authoringMessageService"; - public static final String PARAM_LEARING_DESIGN_ID = "learningDesignID"; - public static final String ATTR_TOOLS_ERROR_MESSAGE = "toolsErrorMessages"; - public static final String ATTR_LD_ERROR_MESSAGE = "ldErrorMessages"; - public static final String ATTR_LD_ID = "learningDesignID"; - - private static final String KEY_MSG_IMPORT_FILE_NOT_FOUND = "msg.import.file.not.found"; - private static final String KEY_MSG_IMPORT_FAILED_UNKNOWN_REASON = "msg.import.failed.unknown.reason"; + public static final String EXPORT_TOOLCONTENT_SERVICE_BEAN_NAME = "exportToolContentService"; + public static final String USER_SERVICE_BEAN_NAME = "userManagementService"; + public static final String MESSAGE_SERVICE_BEAN_NAME = "authoringMessageService"; + public static final String PARAM_LEARING_DESIGN_ID = "learningDesignID"; + public static final String PARAM_LEARNING_DESIGN_LOCATION = "ldLocation"; + public static final String PARAM_LEARNING_FILE_NAME = "fileName"; + public static final String ATTR_TOOLS_ERROR_MESSAGE = "toolsErrorMessages"; + public static final String ATTR_LD_ERROR_MESSAGE = "ldErrorMessages"; + public static final String ATTR_LD_ID = "learningDesignID"; + private static final String KEY_MSG_IMPORT_FILE_NOT_FOUND = "msg.import.file.not.found"; + private static final String KEY_MSG_IMPORT_FAILED_UNKNOWN_REASON = "msg.import.failed.unknown.reason"; - private Logger log = Logger.getLogger(ImportToolContentAction.class); - + private Logger log = Logger.getLogger(ImportToolContentAction.class); - @Override - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { - String param = request.getParameter("method"); - - //-----------------------Resource Author function --------------------------- - if(StringUtils.equals(param,"import")){ - String customCSV = WebUtil.readStrParam(request, AttributeNames.PARAM_CUSTOM_CSV, true); - if (customCSV != null) - { - request.setAttribute(AttributeNames.PARAM_CUSTOM_CSV, customCSV); - } - //display initial page for upload - return mapping.findForward("upload"); - }else{ - importLD(request); - return mapping.findForward("success"); - } + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + String param = request.getParameter("method"); + String customCSV = WebUtil.readStrParam(request, AttributeNames.PARAM_CUSTOM_CSV, true); + //-----------------------Resource Author function --------------------------- + if (StringUtils.equals(param, "import")) { + if (customCSV != null) { + request.setAttribute(AttributeNames.PARAM_CUSTOM_CSV, customCSV); + } + //display initial page for upload + return mapping.findForward("upload"); + } else if (StringUtils.equals(param, "importLC")) { + + // import from lams community, redirect to sso page + if (customCSV != null) { + request.setAttribute(AttributeNames.PARAM_CUSTOM_CSV, customCSV); + } + //display initial lamscommunity import + return mapping.findForward("importLC"); + } else if (StringUtils.equals(param, "importLCFinish")) { + + // uploading the file from lams commmunity, have to feed the + // location from the request + //String learningDesignLocation = WebUtil.readStrParam(request, PARAM_LEARNING_DESIGN_LOCATION); + + String learningDesignLocation = "http://lamscommunity.org/lams/x/downloads?seq_id=712445"; + importLDFromURL(request, learningDesignLocation, customCSV); + return mapping.findForward("successLC"); + } else { + importLD(request); + return mapping.findForward("success"); } + } + /** + * @param request + */ + private void importLD(HttpServletRequest request) { - /** - * @param request - */ - private void importLD(HttpServletRequest request) { + List ldErrorMsgs = new ArrayList(); + List toolsErrorMsgs = new ArrayList(); + Long ldId = null; - List ldErrorMsgs = new ArrayList(); - List toolsErrorMsgs = new ArrayList(); - Long ldId = null; - - try { - Integer workspaceFolderUid = null; - - //get shared session - HttpSession ss = SessionManager.getSession(); - //get back login user DTO - UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); - User user = (User)getUserService().findById(User.class,userDto.getUserID()); - - File designFile = null; - Map params = new HashMap(); - String filename = null; - - String uploadPath = FileUtil.createTempDirectory("_uploaded_learningdesign"); + try { + Integer workspaceFolderUid = null; - DiskFileUpload fu = new DiskFileUpload(); - // maximum size that will be stored in memory - fu.setSizeThreshold(4096); - // the location for saving data that is larger than getSizeThreshold() - // fu.setRepositoryPath(uploadPath); - - List fileItems = fu.parseRequest(request); - Iterator iter = fileItems.iterator(); - while (iter.hasNext()) { - FileItem fi = (FileItem) iter.next(); - //UPLOAD_FILE is input field from HTML page - if (!fi.getFieldName().equalsIgnoreCase("UPLOAD_FILE")) - params.put(fi.getFieldName(), fi.getString()); - else { - // filename on the client - filename = FileUtil.getFileName(fi.getName()); - designFile = new File(uploadPath + filename); - fi.write(designFile); - - } - workspaceFolderUid = NumberUtils.createInteger((String) params.get("WORKSPACE_FOLDER_UID")); - } - - // get customCSV for tool adapters if it was an external LMS request - String customCSV = params.get(AttributeNames.PARAM_CUSTOM_CSV); - - if (designFile == null) { - MessageService msgService = getMessageService(); - log.error("Upload file missing. Filename was "+filename); - String msg = msgService.getMessage(KEY_MSG_IMPORT_FILE_NOT_FOUND); - ldErrorMsgs.add(msg != null ? msg : "Upload file missing"); - - } else { + //get shared session + HttpSession ss = SessionManager.getSession(); + //get back login user DTO + UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = (User) getUserService().findById(User.class, userDto.getUserID()); - IExportToolContentService service = getExportService(); - Object[] ldResults = service.importLearningDesign(designFile,user,workspaceFolderUid,toolsErrorMsgs, customCSV); - ldId = (Long) ldResults[0]; - ldErrorMsgs = (List) ldResults[1]; - toolsErrorMsgs = (List) ldResults[2]; - + File designFile = null; + Map params = new HashMap(); + String filename = null; - } - - } catch (Exception e) { - log.error("Error occured during import",e); - ldErrorMsgs.add(e.getClass().getName()+" "+e.getMessage()); + String uploadPath = FileUtil.createTempDirectory("_uploaded_learningdesign"); + + DiskFileUpload fu = new DiskFileUpload(); + // maximum size that will be stored in memory + fu.setSizeThreshold(4096); + // the location for saving data that is larger than getSizeThreshold() + // fu.setRepositoryPath(uploadPath); + + List fileItems = fu.parseRequest(request); + Iterator iter = fileItems.iterator(); + while (iter.hasNext()) { + FileItem fi = (FileItem) iter.next(); + //UPLOAD_FILE is input field from HTML page + if (!fi.getFieldName().equalsIgnoreCase("UPLOAD_FILE")) + params.put(fi.getFieldName(), fi.getString()); + else { + // filename on the client + filename = FileUtil.getFileName(fi.getName()); + designFile = new File(uploadPath + filename); + fi.write(designFile); + } - - request.setAttribute(ATTR_LD_ID,ldId); - if( (ldId==null || ldId.longValue()==-1) && ldErrorMsgs.size()==0 ) { - MessageService msgService = getMessageService(); - ldErrorMsgs.add(msgService.getMessage(KEY_MSG_IMPORT_FAILED_UNKNOWN_REASON)); - } - if ( ldErrorMsgs.size() > 0 ) { - request.setAttribute(ATTR_LD_ERROR_MESSAGE,ldErrorMsgs); - } - if ( toolsErrorMsgs.size() > 0 ) { - request.setAttribute(ATTR_TOOLS_ERROR_MESSAGE,toolsErrorMsgs); - } + workspaceFolderUid = NumberUtils.createInteger((String) params.get("WORKSPACE_FOLDER_UID")); + } + // get customCSV for tool adapters if it was an external LMS request + String customCSV = params.get(AttributeNames.PARAM_CUSTOM_CSV); + if (designFile == null) { + MessageService msgService = getMessageService(); + log.error("Upload file missing. Filename was " + filename); + String msg = msgService.getMessage(KEY_MSG_IMPORT_FILE_NOT_FOUND); + ldErrorMsgs.add(msg != null ? msg : "Upload file missing"); + + } else { + + IExportToolContentService service = getExportService(); + Object[] ldResults = service.importLearningDesign(designFile, user, workspaceFolderUid, toolsErrorMsgs, + customCSV); + ldId = (Long) ldResults[0]; + ldErrorMsgs = (List) ldResults[1]; + toolsErrorMsgs = (List) ldResults[2]; + + } + + } catch (Exception e) { + log.error("Error occured during import", e); + ldErrorMsgs.add(e.getClass().getName() + " " + e.getMessage()); } - - //*************************************************************************************** - // Private method - //*************************************************************************************** - private IUserManagementService getUserService(){ - WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServlet().getServletContext()); - return (IUserManagementService) webContext.getBean(USER_SERVICE_BEAN_NAME); + request.setAttribute(ATTR_LD_ID, ldId); + if ((ldId == null || ldId.longValue() == -1) && ldErrorMsgs.size() == 0) { + MessageService msgService = getMessageService(); + ldErrorMsgs.add(msgService.getMessage(KEY_MSG_IMPORT_FAILED_UNKNOWN_REASON)); } - private IExportToolContentService getExportService(){ - WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServlet().getServletContext()); - return (IExportToolContentService) webContext.getBean(EXPORT_TOOLCONTENT_SERVICE_BEAN_NAME); + if (ldErrorMsgs.size() > 0) { + request.setAttribute(ATTR_LD_ERROR_MESSAGE, ldErrorMsgs); } - private MessageService getMessageService(){ - WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServlet().getServletContext()); - return (MessageService) webContext.getBean(MESSAGE_SERVICE_BEAN_NAME); + if (toolsErrorMsgs.size() > 0) { + request.setAttribute(ATTR_TOOLS_ERROR_MESSAGE, toolsErrorMsgs); } - -} + } + /** + * Import a LD from a url. + * + * @param request + */ + @SuppressWarnings("unchecked") + private void importLDFromURL(HttpServletRequest request, String learningDesignLocation, String customCSV) { + + List ldErrorMsgs = new ArrayList(); + List toolsErrorMsgs = new ArrayList(); + Long ldId = null; + + String fileName = FileUtil.generateUniqueContentFolderID() + ".zip"; + + try { + + // append the lams community auth info + learningDesignLocation = LamsCommunityUtil.appendAuthInfoToURL(learningDesignLocation); + + Integer workspaceFolderUid = null; + + //get shared session + HttpSession ss = SessionManager.getSession(); + //get back login user DTO + UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = (User) getUserService().findById(User.class, userDto.getUserID()); + + File designFile = null; + String uploadPath = FileUtil.createTempDirectory("_uploaded_learningdesign") + File.separator + + FileUtil.getFileName(fileName); + + // get the ld input stream form the location + InputStream is = WebUtil.getResponseInputStreamFromExternalServer(learningDesignLocation, + new HashMap()); + + // Get the output stream to write the file for export + OutputStream out = new BufferedOutputStream(new FileOutputStream(uploadPath)); + + byte[] buffer = new byte[1024]; + int numRead; + long numWritten = 0; + while ((numRead = is.read(buffer)) != -1) { + out.write(buffer, 0, numRead); + numWritten += numRead; + } + log.debug("Path to ld import file: " + uploadPath); + + out.flush(); + out.close(); + is.close(); + + designFile = new File(uploadPath); + + if (designFile == null) { + MessageService msgService = getMessageService(); + log.error("Upload file missing. Filename was " + fileName); + String msg = msgService.getMessage(KEY_MSG_IMPORT_FILE_NOT_FOUND); + ldErrorMsgs.add(msg != null ? msg : "Upload file missing"); + + } else { + + IExportToolContentService service = getExportService(); + Object[] ldResults = service.importLearningDesign(designFile, user, workspaceFolderUid, toolsErrorMsgs, + customCSV); + ldId = (Long) ldResults[0]; + ldErrorMsgs = (List) ldResults[1]; + toolsErrorMsgs = (List) ldResults[2]; + } + } catch (Exception e) { + log.error("Error occured during import", e); + ldErrorMsgs.add(e.getClass().getName() + " " + e.getMessage()); + } + + request.setAttribute(ATTR_LD_ID, ldId); + if ((ldId == null || ldId.longValue() == -1) && ldErrorMsgs.size() == 0) { + MessageService msgService = getMessageService(); + ldErrorMsgs.add(msgService.getMessage(KEY_MSG_IMPORT_FAILED_UNKNOWN_REASON)); + } + if (ldErrorMsgs.size() > 0) { + request.setAttribute(ATTR_LD_ERROR_MESSAGE, ldErrorMsgs); + } + if (toolsErrorMsgs.size() > 0) { + request.setAttribute(ATTR_TOOLS_ERROR_MESSAGE, toolsErrorMsgs); + } + } + + //*************************************************************************************** + // Private method + //*************************************************************************************** + private IUserManagementService getUserService() { + WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this + .getServlet().getServletContext()); + return (IUserManagementService) webContext.getBean(USER_SERVICE_BEAN_NAME); + } + + private IExportToolContentService getExportService() { + WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this + .getServlet().getServletContext()); + return (IExportToolContentService) webContext.getBean(EXPORT_TOOLCONTENT_SERVICE_BEAN_NAME); + } + + private MessageService getMessageService() { + WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(this + .getServlet().getServletContext()); + return (MessageService) webContext.getBean(MESSAGE_SERVICE_BEAN_NAME); + } + +} Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java =================================================================== diff -u -rc234c64ad9ff9d713f6d8e3331d0c20075e49303 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java (.../LamsCommunityLoginAction.java) (revision c234c64ad9ff9d713f6d8e3331d0c20075e49303) +++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginAction.java (.../LamsCommunityLoginAction.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -42,6 +42,7 @@ import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; @@ -79,7 +80,10 @@ private IUserManagementService service; private static final String ATTR_ERROR_MESSAGE = "errorMessage"; - private static final String ATTR_LC_USERNAME = "lcUsername"; + + private static final String LC_METHOD_IMPORT = "import"; + private static final String LC_METHOD_SAVE = "import"; + /** * Default action response @@ -213,6 +217,9 @@ HttpServletResponse response) throws Exception { User user = getUser(request); + + // The destination + String lamscommunityDest = WebUtil.readStrParam(request, LamsCommunityUtil.PARAM_DEST, true); // check that the server is registered with lamscommunity Registration reg = Configuration.getRegistration(); @@ -238,19 +245,49 @@ String timestamp = "" + new Date().getTime(); String hash = LamsCommunityUtil.createAuthenticationHash(timestamp, user.getLamsCommunityUsername(), user.getLamsCommunityToken(), serverID, serverKey); - // Refirect the user to the lamscommunity sso url + // Redirect the user to the lamscommunity sso url + String url = LamsCommunityUtil.LAMS_COMMUNITY_SSO_URL + "?"; - url += LamsCommunityUtil.PARAM_LC_USERNAME + "=" + URLEncoder.encode(user.getLamsCommunityUsername(), "UTF8"); - url += "&" + LamsCommunityUtil.PARAM_HASH + "=" + hash; - url += "&" + LamsCommunityUtil.PARAM_SERVER_ID + "=" + serverID; - url += "&" + LamsCommunityUtil.PARAM_TIMESTAMP + "=" + timestamp; + url = LamsCommunityUtil.appendAuthInfoToURL(url); + //String url = LamsCommunityUtil.LAMS_COMMUNITY_SSO_URL + "?"; + //url += LamsCommunityUtil.PARAM_LC_USERNAME + "=" + URLEncoder.encode(user.getLamsCommunityUsername(), "UTF8"); + //url += "&" + LamsCommunityUtil.PARAM_HASH + "=" + hash; + //url += "&" + LamsCommunityUtil.PARAM_SERVER_ID + "=" + serverID; + //url += "&" + LamsCommunityUtil.PARAM_TIMESTAMP + "=" + timestamp; + + if (lamscommunityDest != null) + { + String customCSV = WebUtil.readStrParam(request, AttributeNames.PARAM_CUSTOM_CSV, true); + url = appendReturnUrl(url, lamscommunityDest, customCSV); + } + log.debug("Redirecting to lamscommunity url: " + url); response.sendRedirect(url); return null; } + private String appendReturnUrl(String url, String dest, String customCSV) throws Exception + { + url += "&" + LamsCommunityUtil.PARAM_DEST + "=" + URLEncoder.encode(dest, "UTF8"); + if (dest != null && dest.equals(LC_METHOD_IMPORT)){ + String returnURL = Configuration.get(ConfigurationKeys.SERVER_URL) + "/authoring/importToolContent?method=importLCFinish"; + + url += "&" + LamsCommunityUtil.PARAM_RETURN_URL + "=" + URLEncoder.encode(returnURL, "UTF8"); + } + else if (dest != null && dest.equals(LC_METHOD_SAVE)){ + // handle save + } + + // append the customCSV if it is there so we get it on the return + if (customCSV != null && !(customCSV.length()==0)) + { + url += "&" + AttributeNames.PARAM_CUSTOM_CSV + "=" + customCSV; + } + return url; + } + private User getUser(HttpServletRequest request) { return (User) getService().getUserByLogin(request.getRemoteUser()); } Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java =================================================================== diff -u -rc234c64ad9ff9d713f6d8e3331d0c20075e49303 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java (.../LamsCommunityLoginForm.java) (revision c234c64ad9ff9d713f6d8e3331d0c20075e49303) +++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityLoginForm.java (.../LamsCommunityLoginForm.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -37,7 +37,7 @@ public String lcUserName; public String lcPassword; - public String lcConfirmPassword; + public String lcDest; public String dispatch; public LamsCommunityLoginForm() {} @@ -66,12 +66,12 @@ this.dispatch = dispatch; } - public String getLcConfirmPassword() { - return lcConfirmPassword; + public String getLcDest() { + return lcDest; } - public void setLcConfirmPassword(String lcConfirmPassword) { - this.lcConfirmPassword = lcConfirmPassword; + public void setLcDest(String lcDest) { + this.lcDest = lcDest; } } \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java =================================================================== diff -u -rc234c64ad9ff9d713f6d8e3331d0c20075e49303 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java (.../LamsCommunityUtil.java) (revision c234c64ad9ff9d713f6d8e3331d0c20075e49303) +++ lams_central/src/java/org/lamsfoundation/lams/web/lamscommunity/LamsCommunityUtil.java (.../LamsCommunityUtil.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -24,11 +24,19 @@ package org.lamsfoundation.lams.web.lamscommunity; import java.net.URLEncoder; +import java.util.Date; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import javax.servlet.http.HttpSession; + +import org.lamsfoundation.lams.config.Registration; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.HashUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; @@ -39,16 +47,15 @@ public static final String LAMS_COMMUNITY_URL = "http://lamscommunity.org"; public static final String LAMS_COMMUNITY_SSO_URL = "http://lamscommunity.org/lams/x/sso"; public static final String LAMS_COMMUNITY_AUTH_URL = "http://lamscommunity.org/lams/x/auth"; - - public static final String PARAM_HASH = "hs"; public static final String PARAM_SERVER_ID = "sid"; public static final String PARAM_TIMESTAMP = "ts"; public static final String PARAM_LC_USERNAME = "un"; public static final String PARAM_LC_PASSWORD = "ps"; public static final String PARAM_LC_USER_TOKEN = "tk"; - + public static final String PARAM_DEST = "dest"; + public static final String PARAM_RETURN_URL = "returnURL"; public static String createAuthenticationHash(String timestamp, String username, String password, String serverId, String serverKey) { String hash = ""; @@ -96,4 +103,39 @@ } + /** + * Appends the required authentication info and hash to a url + * @param url + * @return + * @throws Exception + */ + public static String appendAuthInfoToURL(String url) throws Exception + { + Registration reg = Configuration.getRegistration(); + String serverID; + String serverKey; + if(reg != null && reg.getServerID() != null && reg.getServerKey() != null) + { + serverID = reg.getServerID(); + serverKey = reg.getServerKey(); + } + else + { + throw new Exception("Attempt to authenticate in lams community without registration"); + } + + UserDTO userDTO = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + String timestamp = "" + new Date().getTime(); + String hash = LamsCommunityUtil.createAuthenticationHash(timestamp, userDTO.getLamsCommunityUsername(), userDTO.getLamsCommunityToken(), serverID, serverKey); + + url += "&" + LamsCommunityUtil.PARAM_LC_USERNAME + "=" + URLEncoder.encode(userDTO.getLamsCommunityUsername(), "UTF8"); + url += "&" + LamsCommunityUtil.PARAM_HASH + "=" + hash; + url += "&" + LamsCommunityUtil.PARAM_SERVER_ID + "=" + serverID; + url += "&" + LamsCommunityUtil.PARAM_TIMESTAMP + "=" + timestamp; + + return url; + + } + + } Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -r68d2988cca350af15ba4087814f74e1527a71997 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 68d2988cca350af15ba4087814f74e1527a71997) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -56,720 +56,638 @@ public class LessonManagerServlet extends HttpServlet { - private static Logger log = Logger.getLogger(LessonManagerServlet.class); + private static Logger log = Logger.getLogger(LessonManagerServlet.class); - private static IntegrationService integrationService = null; + private static IntegrationService integrationService = null; - private static IWorkspaceManagementService service = null; + private static IWorkspaceManagementService service = null; - private static IMonitoringService monitoringService = null; + private static IMonitoringService monitoringService = null; - private static ILessonService lessonService = null; - - private static IExportToolContentService exportService = null; - - /** - * Constructor of the object. - */ - public LessonManagerServlet() { - super(); - } + private static ILessonService lessonService = null; - /** - * Destruction of the servlet.
- */ - public void destroy() { - super.destroy(); // Just puts "destroy" string in log - // Put your code here - } + private static IExportToolContentService exportService = null; - /** - * The doGet method of the servlet.
- * - * This method is called when a form has its tag value method equals to get. - * - * @param request - * the request send by the client to the server - * @param response - * the response send by the server to the client - * @throws ServletException - * if an error occurred - * @throws IOException - * if an error occurred - */ - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + /** + * Constructor of the object. + */ + public LessonManagerServlet() { + super(); + } - PrintWriter out = response.getWriter(); - response.setContentType("text/xml"); - response.setCharacterEncoding("UTF8"); - - String serverId = request.getParameter(CentralConstants.PARAM_SERVER_ID); - String datetime = request.getParameter(CentralConstants.PARAM_DATE_TIME); - String hashValue = request.getParameter(CentralConstants.PARAM_HASH_VALUE); - String username = request.getParameter(CentralConstants.PARAM_USERNAME); - String courseId = request.getParameter(CentralConstants.PARAM_COURSE_ID); - String ldIdStr = request.getParameter(CentralConstants.PARAM_LEARNING_DESIGN_ID); - String lsIdStr = request.getParameter(CentralConstants.PARAM_LESSON_ID); - String country = request.getParameter(CentralConstants.PARAM_COUNTRY); - String title = request.getParameter(CentralConstants.PARAM_TITLE); - String desc = request.getParameter(CentralConstants.PARAM_DESC); - String startDate = request.getParameter(CentralConstants.PARAM_STARTDATE); - String lang = request.getParameter(CentralConstants.PARAM_LANG); - String method = request.getParameter(CentralConstants.PARAM_METHOD); - String filePath = request.getParameter(CentralConstants.PARAM_FILEPATH); - String progressUser = request.getParameter(CentralConstants.PARAM_PROGRESS_USER); - String learnerIds = request.getParameter(CentralConstants.PARAM_LEARNER_IDS); - String monitorIds = request.getParameter(CentralConstants.PARAM_MONITOR_IDS); + /** + * Destruction of the servlet.
+ */ + public void destroy() { + super.destroy(); // Just puts "destroy" string in log + // Put your code here + } - // Custom CSV string to be used for tool adapters - String customCSV = request.getParameter(CentralConstants.PARAM_CUSTOM_CSV); - - Long ldId = null; - Long lsId = null; - try { - // TODO check input parameters are valid. + /** + * The doGet method of the servlet.
+ * + * This method is called when a form has its tag value method equals to get. + * + * @param request + * the request send by the client to the server + * @param response + * the response send by the server to the client + * @throws ServletException + * if an error occurred + * @throws IOException + * if an error occurred + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Create xml document - DocumentBuilderFactory factory = DocumentBuilderFactory - .newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.newDocument(); + PrintWriter out = response.getWriter(); + response.setContentType("text/xml"); + response.setCharacterEncoding("UTF8"); - Element element = null; - - if (hashValue==null || hashValue.equals("")) - throw new NullPointerException("Hash value missing in parameters"); + String serverId = request.getParameter(CentralConstants.PARAM_SERVER_ID); + String datetime = request.getParameter(CentralConstants.PARAM_DATE_TIME); + String hashValue = request.getParameter(CentralConstants.PARAM_HASH_VALUE); + String username = request.getParameter(CentralConstants.PARAM_USERNAME); + String courseId = request.getParameter(CentralConstants.PARAM_COURSE_ID); + String ldIdStr = request.getParameter(CentralConstants.PARAM_LEARNING_DESIGN_ID); + String lsIdStr = request.getParameter(CentralConstants.PARAM_LESSON_ID); + String country = request.getParameter(CentralConstants.PARAM_COUNTRY); + String title = request.getParameter(CentralConstants.PARAM_TITLE); + String desc = request.getParameter(CentralConstants.PARAM_DESC); + String startDate = request.getParameter(CentralConstants.PARAM_STARTDATE); + String lang = request.getParameter(CentralConstants.PARAM_LANG); + String method = request.getParameter(CentralConstants.PARAM_METHOD); + String filePath = request.getParameter(CentralConstants.PARAM_FILEPATH); + String progressUser = request.getParameter(CentralConstants.PARAM_PROGRESS_USER); + String learnerIds = request.getParameter(CentralConstants.PARAM_LEARNER_IDS); + String monitorIds = request.getParameter(CentralConstants.PARAM_MONITOR_IDS); - if (method.equals(CentralConstants.METHOD_START)) { - ldId = new Long(ldIdStr); - Long lessonId = startLesson(serverId, datetime, hashValue, - username, ldId, courseId, title, desc, country, lang, customCSV); + // Custom CSV string to be used for tool adapters + String customCSV = request.getParameter(CentralConstants.PARAM_CUSTOM_CSV); - element = document.createElement(CentralConstants.ELEM_LESSON); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); + Long ldId = null; + Long lsId = null; + try { + // TODO check input parameters are valid. - } else if (method.equals(CentralConstants.METHOD_PREVIEW)) { - ldId = new Long(ldIdStr); - Long lessonId = startPreview(serverId, datetime, hashValue, - username, ldId, courseId, title, desc, country, lang, customCSV); - - element = document.createElement(CentralConstants.ELEM_LESSON); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); - - } else if (method.equals(CentralConstants.METHOD_SCHEDULE)) { - ldId = new Long(ldIdStr); - Long lessonId = scheduleLesson(serverId, datetime, hashValue, - username, ldId, courseId, title, desc, startDate, - country, lang, customCSV); + // Create xml document + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.newDocument(); - element = document.createElement(CentralConstants.ELEM_LESSON); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); + Element element = null; - } else if (method.equals(CentralConstants.METHOD_DELETE)) { - lsId = new Long(lsIdStr); - Boolean deleted = deleteLesson(serverId, datetime, hashValue, - username, lsId); + if (hashValue == null || hashValue.equals("")) + throw new NullPointerException("Hash value missing in parameters"); - element = document.createElement(CentralConstants.ELEM_LESSON); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsId.toString()); - element.setAttribute(CentralConstants.ATTR_DELETED, deleted.toString()); + if (method.equals(CentralConstants.METHOD_START)) { + ldId = new Long(ldIdStr); + Long lessonId = startLesson(serverId, datetime, hashValue, username, ldId, courseId, title, desc, + country, lang, customCSV); - } else if (method.equals(CentralConstants.METHOD_STUDENT_PROGRESS)) { - lsId = new Long(lsIdStr); - element = getAllStudentProgress(document, serverId, datetime, hashValue, - username, lsId, courseId); + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); - } else if (method.equals(CentralConstants.METHOD_SINGLE_STUDENT_PROGRESS)) { - lsId = new Long(lsIdStr); - element = getSingleStudentProgress(document, serverId, datetime, hashValue, - username, lsId, courseId, progressUser); + } else if (method.equals(CentralConstants.METHOD_PREVIEW)) { + ldId = new Long(ldIdStr); + Long lessonId = startPreview(serverId, datetime, hashValue, username, ldId, courseId, title, desc, + country, lang, customCSV); - } else if (method.equals(CentralConstants.METHOD_IMPORT)) { + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); - // ldId = new Long(ldIdStr); - Long ldID = importLearningDesign(request, response, filePath, username, serverId, customCSV); - - element = document.createElement(CentralConstants.ELEM_LEARNINGDESIGN); - element.setAttribute(CentralConstants.PARAM_LEARNING_DESIGN_ID, ldID.toString()); + } else if (method.equals(CentralConstants.METHOD_SCHEDULE)) { + ldId = new Long(ldIdStr); + Long lessonId = scheduleLesson(serverId, datetime, hashValue, username, ldId, courseId, title, desc, + startDate, country, lang, customCSV); - } else if (method.equals(CentralConstants.METHOD_JOIN_LESSON)) { - Thread t = new Thread(new AddUsersToLessonThread(serverId, datetime, username, hashValue, - lsIdStr, courseId, country, lang, learnerIds, monitorIds, request)); - t.start(); + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); - element = document.createElement(CentralConstants.ELEM_LESSON); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsIdStr); - - } else { - String msg = "Method :" + method + " is not recognised"; - log.error(msg); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); - } + } else if (method.equals(CentralConstants.METHOD_DELETE)) { + lsId = new Long(lsIdStr); + Boolean deleted = deleteLesson(serverId, datetime, hashValue, username, lsId); - document.appendChild(element); + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsId.toString()); + element.setAttribute(CentralConstants.ATTR_DELETED, deleted.toString()); - // write out the xml document. - DOMSource domSource = new DOMSource(document); - StringWriter writer = new StringWriter(); - StreamResult result = new StreamResult(writer); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.transform(domSource, result); - - out.write(writer.toString()); - - } catch (NumberFormatException nfe) { - log.error("lsId or ldId is not an integer" + lsIdStr + ldIdStr, nfe); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, "lsId or ldId is not an integer"); - } catch (TransformerConfigurationException e) { - log.error("Can not convert XML document to string", e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } catch (TransformerException e) { - log.error("Can not convert XML document to string", e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); - } catch (ParserConfigurationException e) { - log.error("Can not build XML document", e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } catch (NullPointerException e) { - log.error("Missing parameters", e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - catch (Exception e) { - log.error("Problem loading learning manager servlet request", e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - - out.flush(); - out.close(); - } + } else if (method.equals(CentralConstants.METHOD_STUDENT_PROGRESS)) { + lsId = new Long(lsIdStr); + element = getAllStudentProgress(document, serverId, datetime, hashValue, username, lsId, courseId); - /** - * The doPost method of the servlet.
- * - * This method is called when a form has its tag value method equals to - * post. - * - * @param request - * the request send by the client to the server - * @param response - * the response send by the server to the client - * @throws ServletException - * if an error occurred - * @throws IOException - * if an error occurred - */ - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - - // TODO services should be implemented as POST - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - out.flush(); - out.close(); + } else if (method.equals(CentralConstants.METHOD_SINGLE_STUDENT_PROGRESS)) { + lsId = new Long(lsIdStr); + element = getSingleStudentProgress(document, serverId, datetime, hashValue, username, lsId, courseId, + progressUser); + + } else if (method.equals(CentralConstants.METHOD_IMPORT)) { + + // ldId = new Long(ldIdStr); + Long ldID = importLearningDesign(request, response, filePath, username, serverId, customCSV); + + element = document.createElement(CentralConstants.ELEM_LEARNINGDESIGN); + element.setAttribute(CentralConstants.PARAM_LEARNING_DESIGN_ID, ldID.toString()); + + } else if (method.equals(CentralConstants.METHOD_JOIN_LESSON)) { + Thread t = new Thread(new AddUsersToLessonThread(serverId, datetime, username, hashValue, lsIdStr, + courseId, country, lang, learnerIds, monitorIds, request)); + t.start(); + + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsIdStr); + + } else { + String msg = "Method :" + method + " is not recognised"; + log.error(msg); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); + } + + document.appendChild(element); + + // write out the xml document. + DOMSource domSource = new DOMSource(document); + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.transform(domSource, result); + + out.write(writer.toString()); + + } catch (NumberFormatException nfe) { + log.error("lsId or ldId is not an integer" + lsIdStr + ldIdStr, nfe); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "lsId or ldId is not an integer"); + } catch (TransformerConfigurationException e) { + log.error("Can not convert XML document to string", e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } catch (TransformerException e) { + log.error("Can not convert XML document to string", e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } catch (ParserConfigurationException e) { + log.error("Can not build XML document", e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } catch (NullPointerException e) { + log.error("Missing parameters", e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } catch (Exception e) { + log.error("Problem loading learning manager servlet request", e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } - - - public Long startLesson(String serverId, String datetime, String hashValue, - String username, long ldId, String courseId, String title, - String desc, String countryIsoCode, String langIsoCode, String customCSV) - throws RemoteException { - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap( - serverMap, userMap, courseId, countryIsoCode, langIsoCode, null); - // 1. init lesson - Lesson lesson = monitoringService.initializeLesson(title, desc, Boolean.TRUE, ldId, - orgMap.getOrganisation().getOrganisationId(), - userMap.getUser().getUserId(), - customCSV, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE); - // 2. create lessonClass for lesson - createLessonClass(lesson, orgMap.getOrganisation(), userMap - .getUser()); - // 3. start lesson - monitoringService.startLesson(lesson.getLessonId(), userMap - .getUser().getUserId()); + out.flush(); + out.close(); + } - return lesson.getLessonId(); - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); - } + /** + * The doPost method of the servlet.
+ * + * This method is called when a form has its tag value method equals to + * post. + * + * @param request + * the request send by the client to the server + * @param response + * the response send by the server to the client + * @throws ServletException + * if an error occurred + * @throws IOException + * if an error occurred + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // TODO services should be implemented as POST + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.flush(); + out.close(); + } + + public Long startLesson(String serverId, String datetime, String hashValue, String username, long ldId, + String courseId, String title, String desc, String countryIsoCode, String langIsoCode, String customCSV) + throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId, + countryIsoCode, langIsoCode, null); + // 1. init lesson + Lesson lesson = monitoringService.initializeLesson(title, desc, Boolean.TRUE, ldId, orgMap + .getOrganisation().getOrganisationId(), userMap.getUser().getUserId(), customCSV, Boolean.FALSE, + Boolean.FALSE, Boolean.FALSE); + // 2. create lessonClass for lesson + createLessonClass(lesson, orgMap.getOrganisation(), userMap.getUser()); + // 3. start lesson + monitoringService.startLesson(lesson.getLessonId(), userMap.getUser().getUserId()); + + return lesson.getLessonId(); + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } + } - public Long scheduleLesson(String serverId, String datetime, - String hashValue, String username, long ldId, String courseId, - String title, String desc, String startDate, String countryIsoCode, - String langIsoCode, String customCSV) throws RemoteException { - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap( - serverMap, userMap, courseId, countryIsoCode, langIsoCode, null); - // 1. init lesson - Lesson lesson = monitoringService - .initializeLesson(title, desc, Boolean.TRUE, ldId, orgMap - .getOrganisation().getOrganisationId(), userMap - .getUser().getUserId(), customCSV, false, false, false); - // 2. create lessonClass for lesson - createLessonClass(lesson, orgMap.getOrganisation(), userMap - .getUser()); - // 3. schedule lesson - Date date = DateUtil.convertFromLAMSFlashFormat(startDate); - monitoringService.startLessonOnSchedule(lesson.getLessonId(), date, - userMap.getUser().getUserId()); - return lesson.getLessonId(); - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); - } + public Long scheduleLesson(String serverId, String datetime, String hashValue, String username, long ldId, + String courseId, String title, String desc, String startDate, String countryIsoCode, String langIsoCode, + String customCSV) throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId, + countryIsoCode, langIsoCode, null); + // 1. init lesson + Lesson lesson = monitoringService.initializeLesson(title, desc, Boolean.TRUE, ldId, orgMap + .getOrganisation().getOrganisationId(), userMap.getUser().getUserId(), customCSV, false, false, + false); + // 2. create lessonClass for lesson + createLessonClass(lesson, orgMap.getOrganisation(), userMap.getUser()); + // 3. schedule lesson + Date date = DateUtil.convertFromLAMSFlashFormat(startDate); + monitoringService.startLessonOnSchedule(lesson.getLessonId(), date, userMap.getUser().getUserId()); + return lesson.getLessonId(); + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } - - public Element getAllStudentProgress(Document document, String serverId, String datetime, - String hashValue, String username, long lsId, String courseID) - throws RemoteException - { - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - Lesson lesson = lessonService.getLesson(lsId); + } - Element element = document.createElement(CentralConstants.ELEM_LESSON_PROGRESS); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - - String prefix = serverMap.getPrefix(); - if(lesson!=null){ - - int activitiesTotal = lesson.getLearningDesign().getActivities().size(); - Iterator iterator = lesson.getLearnerProgresses().iterator(); - while(iterator.hasNext()){ - LearnerProgress learnProg = (LearnerProgress)iterator.next(); - LearnerProgressDTO learnerProgress = learnProg.getLearnerProgressData(); - - //Iterator activities = learnProg.getLesson().getLearningDesign().getActivities().iterator(); - - //String currActivity = ""; - //while (activities.hasNext()) - //{ - // Activity act = (Activity)iterator.next(); - // - // if (learnerProgress.getCurrentActivityId() == ((Activity)iterator.next()).getActivityId()) - // { - // currActivity = act.getTitle(); - // break; - // } - //} - - - - // get the username with the integration prefix removed - String userNoPrefixName = learnerProgress.getUserName(). - substring(prefix.length()+1); - ExtUserUseridMap learnerMap = integrationService.getExtUserUseridMap( - serverMap, userNoPrefixName); - - Element learnerProgElem = document.createElement(CentralConstants.ELEM_LEARNER_PROGRESS); - - int completedActivities = learnerProgress.getCompletedActivities().length; - int attemptedActivities = learnerProgress.getAttemptedActivities().length; - - if(learnerProgElem.getNodeType()== Node.ELEMENT_NODE) - { - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE , "" + learnerProgress.getLessonComplete()); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT , "" + activitiesTotal); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED , "" + completedActivities); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED , "" + attemptedActivities); - //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); - learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + learnerMap.getSid()); - learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); - learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, userNoPrefixName); - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - } - - element.appendChild(learnerProgElem); - } - } - else{ - throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); - } - - return element; - - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); + public Element getAllStudentProgress(Document document, String serverId, String datetime, String hashValue, + String username, long lsId, String courseID) throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + Lesson lesson = lessonService.getLesson(lsId); + + Element element = document.createElement(CentralConstants.ELEM_LESSON_PROGRESS); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + + String prefix = serverMap.getPrefix(); + if (lesson != null) { + + int activitiesTotal = lesson.getLearningDesign().getActivities().size(); + Iterator iterator = lesson.getLearnerProgresses().iterator(); + while (iterator.hasNext()) { + LearnerProgress learnProg = (LearnerProgress) iterator.next(); + LearnerProgressDTO learnerProgress = learnProg.getLearnerProgressData(); + + //Iterator activities = learnProg.getLesson().getLearningDesign().getActivities().iterator(); + + //String currActivity = ""; + //while (activities.hasNext()) + //{ + // Activity act = (Activity)iterator.next(); + // + // if (learnerProgress.getCurrentActivityId() == ((Activity)iterator.next()).getActivityId()) + // { + // currActivity = act.getTitle(); + // break; + // } + //} + + // get the username with the integration prefix removed + String userNoPrefixName = learnerProgress.getUserName().substring(prefix.length() + 1); + ExtUserUseridMap learnerMap = integrationService.getExtUserUseridMap(serverMap, userNoPrefixName); + + Element learnerProgElem = document.createElement(CentralConstants.ELEM_LEARNER_PROGRESS); + + int completedActivities = learnerProgress.getCompletedActivities().length; + int attemptedActivities = learnerProgress.getAttemptedActivities().length; + + if (learnerProgElem.getNodeType() == Node.ELEMENT_NODE) { + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE, "" + + learnerProgress.getLessonComplete()); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT, "" + activitiesTotal); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED, "" + + completedActivities); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED, "" + + attemptedActivities); + //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); + learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + learnerMap.getSid()); + learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); + learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, userNoPrefixName); + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + } + + element.appendChild(learnerProgElem); } - + } else { + throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); + } + + return element; + + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } - - public Element getSingleStudentProgress(Document document, String serverId, String datetime, - String hashValue, String username, long lsId, String courseID, String progressUser) - throws RemoteException - { - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - Lesson lesson = lessonService.getLesson(lsId); - Element element = document.createElement(CentralConstants.ELEM_LESSON_PROGRESS); - element.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - - String prefix = serverMap.getPrefix(); - + } - if(lesson!=null) - { - int activitiesTotal = lesson.getLearningDesign().getActivities().size(); - - ExtUserUseridMap progressUserMap = integrationService.getExistingExtUserUseridMap( - serverMap, progressUser); - - LearnerProgress learnProg = lessonService.getUserProgressForLesson(userMap.getUser().getUserId(), lsId); - - Element learnerProgElem = document.createElement(CentralConstants.ELEM_LEARNER_PROGRESS); - - // if learner progress exists, make a response, otherwise, return an empty learner progress element - if (learnProg != null) - { - LearnerProgressDTO learnerProgress = learnProg.getLearnerProgressData(); - - - int completedActivities = learnerProgress.getCompletedActivities().length; - int attemptedActivities = learnerProgress.getAttemptedActivities().length; - - if(learnerProgElem.getNodeType()== Node.ELEMENT_NODE) - { - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE , "" + learnerProgress.getLessonComplete()); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT , "" + activitiesTotal); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED , "" + completedActivities); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED , "" + attemptedActivities); - //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); - learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + progressUserMap.getSid()); - learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); - learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, progressUser); - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - } - } - else - { - if(learnerProgElem.getNodeType()== Node.ELEMENT_NODE) - { - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE , "false"); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT , "" + activitiesTotal); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED , "0"); - learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED , "0"); - //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); - learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + progressUserMap.getSid()); - learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); - learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, progressUser); - learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); - } - } - - element.appendChild(learnerProgElem); - } - else{ - throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); - } - - return element; - - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); + public Element getSingleStudentProgress(Document document, String serverId, String datetime, String hashValue, + String username, long lsId, String courseID, String progressUser) throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + Lesson lesson = lessonService.getLesson(lsId); + + Element element = document.createElement(CentralConstants.ELEM_LESSON_PROGRESS); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + + String prefix = serverMap.getPrefix(); + + if (lesson != null) { + int activitiesTotal = lesson.getLearningDesign().getActivities().size(); + + ExtUserUseridMap progressUserMap = integrationService.getExistingExtUserUseridMap(serverMap, + progressUser); + + LearnerProgress learnProg = lessonService.getUserProgressForLesson(userMap.getUser().getUserId(), lsId); + + Element learnerProgElem = document.createElement(CentralConstants.ELEM_LEARNER_PROGRESS); + + // if learner progress exists, make a response, otherwise, return an empty learner progress element + if (learnProg != null) { + LearnerProgressDTO learnerProgress = learnProg.getLearnerProgressData(); + + int completedActivities = learnerProgress.getCompletedActivities().length; + int attemptedActivities = learnerProgress.getAttemptedActivities().length; + + if (learnerProgElem.getNodeType() == Node.ELEMENT_NODE) { + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE, "" + + learnerProgress.getLessonComplete()); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT, "" + activitiesTotal); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED, "" + + completedActivities); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED, "" + + attemptedActivities); + //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); + learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + progressUserMap.getSid()); + learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); + learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, progressUser); + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + } + } else { + if (learnerProgElem.getNodeType() == Node.ELEMENT_NODE) { + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE, "false"); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT, "" + activitiesTotal); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED, "0"); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED, "0"); + //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); + learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + progressUserMap.getSid()); + learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); + learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, progressUser); + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + } } - + + element.appendChild(learnerProgElem); + } else { + throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); + } + + return element; + + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } - - - public boolean deleteLesson(String serverId, String datetime, - String hashValue, String username, long lsId) - throws RemoteException { - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - monitoringService.removeLesson(lsId, userMap.getUser().getUserId()); - return true; - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); - } + } + + public boolean deleteLesson(String serverId, String datetime, String hashValue, String username, long lsId) + throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + monitoringService.removeLesson(lsId, userMap.getUser().getUserId()); + return true; + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } - - public Long startPreview(String serverId, String datetime, String hashValue, - String username, Long ldId, String courseId, String title, - String desc, String countryIsoCode, String langIsoCode, String customCSV) - throws RemoteException { + } - try { - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - Authenticator - .authenticate(serverMap, datetime, username, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( - serverMap, username); - ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap( - serverMap, userMap, courseId, countryIsoCode, langIsoCode, null); - // 1. init lesson - Lesson lesson = monitoringService - .initializeLessonForPreview(title, desc, ldId, userMap.getUser().getUserId(), customCSV, false, false, false); - // 2. create lessonClass for lesson - monitoringService.createPreviewClassForLesson(userMap.getUser().getUserId(), lesson.getLessonId()); - - // 3. start lesson - monitoringService.startLesson(lesson.getLessonId(), userMap.getUser().getUserId()); + public Long startPreview(String serverId, String datetime, String hashValue, String username, Long ldId, + String courseId, String title, String desc, String countryIsoCode, String langIsoCode, String customCSV) + throws RemoteException { - return lesson.getLessonId(); - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); - } + try { + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId, + countryIsoCode, langIsoCode, null); + // 1. init lesson + Lesson lesson = monitoringService.initializeLessonForPreview(title, desc, ldId, userMap.getUser() + .getUserId(), customCSV, false, false, false); + // 2. create lessonClass for lesson + monitoringService.createPreviewClassForLesson(userMap.getUser().getUserId(), lesson.getLessonId()); - - + // 3. start lesson + monitoringService.startLesson(lesson.getLessonId(), userMap.getUser().getUserId()); + + return lesson.getLessonId(); + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } + } - public Long importLearningDesign(HttpServletRequest request, HttpServletResponse response, - String filePath, String username, String serverId, String customCSV) - throws RemoteException { - - List ldErrorMsgs = new ArrayList(); - List toolsErrorMsgs = new ArrayList(); - Long ldId = null; - Integer workspaceFolderUid = null; - ExtUserUseridMap userMap; - User user = null; - ExtServerOrgMap serverMap = integrationService - .getExtServerOrgMap(serverId); - - try { - - userMap = integrationService.getExtUserUseridMap( - serverMap, username); - - user = userMap.getUser(); + public Long importLearningDesign(HttpServletRequest request, HttpServletResponse response, String filePath, + String username, String serverId, String customCSV) throws RemoteException { - HttpSession ss = SessionManager.getSession(); - boolean createdTemporarySession = false; - if ( ss == null ) { - // import requires a session containing the user details, so dummy it up here. - SessionManager.startSession(request, response); - ss = SessionManager.getSession(); - ss.setAttribute(AttributeNames.USER, user.getUserDTO()); - createdTemporarySession = true; - } - - File designFile = new File(filePath); - Object[] ldResults = exportService.importLearningDesign(designFile, user, workspaceFolderUid, toolsErrorMsgs, customCSV); - ldId = (Long) ldResults[0]; - ldErrorMsgs = (List) ldResults[1]; - toolsErrorMsgs = (List) ldResults[2]; - - if ( createdTemporarySession ) { - SessionManager.endSession(); - } - - return ldId; - } catch (Exception e) { - throw new RemoteException(e.getMessage(), e); - } - + List ldErrorMsgs = new ArrayList(); + List toolsErrorMsgs = new ArrayList(); + Long ldId = null; + Integer workspaceFolderUid = null; + ExtUserUseridMap userMap; + User user = null; + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + + try { + + userMap = integrationService.getExtUserUseridMap(serverMap, username); + + user = userMap.getUser(); + + HttpSession ss = SessionManager.getSession(); + boolean createdTemporarySession = false; + if (ss == null) { + // import requires a session containing the user details, so dummy it up here. + SessionManager.startSession(request, response); + ss = SessionManager.getSession(); + ss.setAttribute(AttributeNames.USER, user.getUserDTO()); + createdTemporarySession = true; + } + + File designFile = new File(filePath); + Object[] ldResults = exportService.importLearningDesign(designFile, user, workspaceFolderUid, + toolsErrorMsgs, customCSV); + ldId = (Long) ldResults[0]; + ldErrorMsgs = (List) ldResults[1]; + toolsErrorMsgs = (List) ldResults[2]; + + if (createdTemporarySession) { + SessionManager.endSession(); + } + + return ldId; + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); } - - private void createLessonClass(Lesson lesson, Organisation organisation, - User creator) { - List staffList = new LinkedList(); - staffList.add(creator); - List learnerList = new LinkedList(); - monitoringService.createLessonClassForLesson(lesson.getLessonId(), - organisation, organisation.getName() + "Learners", learnerList, - organisation.getName() + "Staff", staffList, creator - .getUserId()); + } + private void createLessonClass(Lesson lesson, Organisation organisation, User creator) { + List staffList = new LinkedList(); + staffList.add(creator); + List learnerList = new LinkedList(); + monitoringService.createLessonClassForLesson(lesson.getLessonId(), organisation, organisation.getName() + + "Learners", learnerList, organisation.getName() + "Staff", staffList, creator.getUserId()); + + } + + /** + * Initialization of the servlet.
+ * + * @throws ServletException + * if an error occure + */ + public void init() throws ServletException { + service = (IWorkspaceManagementService) WebApplicationContextUtils.getRequiredWebApplicationContext( + getServletContext()).getBean("workspaceManagementService"); + + integrationService = (IntegrationService) WebApplicationContextUtils.getRequiredWebApplicationContext( + getServletContext()).getBean("integrationService"); + + monitoringService = (IMonitoringService) WebApplicationContextUtils.getRequiredWebApplicationContext( + getServletContext()).getBean("monitoringService"); + + lessonService = (ILessonService) WebApplicationContextUtils.getRequiredWebApplicationContext( + getServletContext()).getBean("lessonService"); + + exportService = (IExportToolContentService) WebApplicationContextUtils.getRequiredWebApplicationContext( + getServletContext()).getBean("exportToolContentService"); + + } + + private class AddUsersToLessonThread implements Runnable { + + private String serverId; + private String datetime; + private String username; + private String hashValue; + private String lsIdStr; + private String courseId; + private String country; + private String lang; + private String learnerIds; + private String monitorIds; + private HttpServletRequest request; + + public AddUsersToLessonThread(String serverId, String datetime, String username, String hashValue, + String lsIdStr, String courseId, String country, String lang, String learnerIds, String monitorIds, + HttpServletRequest request) { + this.serverId = serverId; + this.datetime = datetime; + this.username = username; + this.hashValue = hashValue; + this.lsIdStr = lsIdStr; + this.courseId = courseId; + this.country = country; + this.lang = lang; + this.learnerIds = learnerIds; + this.monitorIds = monitorIds; + this.request = request; } - + public void run() { + addUsersToLesson(serverId, datetime, username, hashValue, lsIdStr, courseId, country, lang, learnerIds, + monitorIds, request); + } + /** - * Initialization of the servlet.
+ * Adds each user in learnerIds and monitorIds as learner and staff to + * the given lesson id; authenticates using the 3rd party server + * requestor's username. * - * @throws ServletException - * if an error occure + * @param serverId + * @param datetime + * @param hashValue + * @param lsIdStr + * @param learnerIds + * @param monitorIds + * @param request + * @return */ - public void init() throws ServletException { - service = (IWorkspaceManagementService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean( - "workspaceManagementService"); - - integrationService = (IntegrationService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean( - "integrationService"); - - monitoringService = (IMonitoringService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean( - "monitoringService"); - - lessonService = (ILessonService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean( - "lessonService"); - - exportService = (IExportToolContentService) WebApplicationContextUtils - .getRequiredWebApplicationContext(getServletContext()).getBean( - "exportToolContentService"); - - } - - private class AddUsersToLessonThread implements Runnable { - - private String serverId; - private String datetime; - private String username; - private String hashValue; - private String lsIdStr; - private String courseId; - private String country; - private String lang; - private String learnerIds; - private String monitorIds; - private HttpServletRequest request; - - public AddUsersToLessonThread(String serverId, - String datetime, String username, String hashValue, - String lsIdStr, String courseId, String country, String lang, - String learnerIds, String monitorIds, HttpServletRequest request) { - this.serverId = serverId; - this.datetime = datetime; - this.username = username; - this.hashValue = hashValue; - this.lsIdStr = lsIdStr; - this.courseId = courseId; - this.country = country; - this.lang = lang; - this.learnerIds = learnerIds; - this.monitorIds = monitorIds; - this.request = request; - } - - public void run() { - addUsersToLesson(serverId, datetime, username, hashValue, - lsIdStr, courseId, country, lang, learnerIds, monitorIds, request); - } - - /** - * Adds each user in learnerIds and monitorIds as learner and staff to the - * given lesson id; authenticates using the 3rd party server requestor's - * username. - * @param serverId - * @param datetime - * @param hashValue - * @param lsIdStr - * @param learnerIds - * @param monitorIds - * @param request - * @return - */ - public Boolean addUsersToLesson( - String serverId, - String datetime, - String requestorUsername, - String hashValue, - String lsIdStr, - String courseId, - String countryIsoCode, - String langIsoCode, - String learnerIds, - String monitorIds, - HttpServletRequest request) { - try { - if (learnerIds != null) { - String[] learnerIdArray = learnerIds.split(","); - for (String learnerId : learnerIdArray) { - if (StringUtils.isNotBlank(learnerId)) { - addUserToLesson(request, serverId, datetime, requestorUsername, hashValue, - LoginRequestDispatcher.METHOD_LEARNER, lsIdStr, learnerId, courseId, countryIsoCode, langIsoCode); - } - } - } - if (monitorIds != null) { - String[] monitorIdArray = monitorIds.split(","); - for (String monitorId : monitorIdArray) { - if (StringUtils.isNotBlank(monitorId)) { - addUserToLesson(request, serverId, datetime, requestorUsername, hashValue, - LoginRequestDispatcher.METHOD_MONITOR, lsIdStr, monitorId, courseId, countryIsoCode, langIsoCode); - } - } - } - return true; - } catch (UserInfoFetchException e) { - log.error(e, e); - return false; - } catch (AuthenticationException e) { - log.error(e, e); - return false; + public Boolean addUsersToLesson(String serverId, String datetime, String requestorUsername, String hashValue, + String lsIdStr, String courseId, String countryIsoCode, String langIsoCode, String learnerIds, + String monitorIds, HttpServletRequest request) { + try { + if (learnerIds != null) { + String[] learnerIdArray = learnerIds.split(","); + for (String learnerId : learnerIdArray) { + if (StringUtils.isNotBlank(learnerId)) { + addUserToLesson(request, serverId, datetime, requestorUsername, hashValue, + LoginRequestDispatcher.METHOD_LEARNER, lsIdStr, learnerId, courseId, + countryIsoCode, langIsoCode); } + } } - - private void addUserToLesson( - HttpServletRequest request, - String serverId, - String datetime, - String requestorUsername, - String hashValue, - String method, - String lsIdStr, - String username, - String courseId, - String countryIsoCode, - String langIsoCode) throws AuthenticationException, UserInfoFetchException { - - if (log.isDebugEnabled()) { - log.debug("Adding user '" + username + "' as " + method + " to lesson with id '" + lsIdStr + "'."); + if (monitorIds != null) { + String[] monitorIdArray = monitorIds.split(","); + for (String monitorId : monitorIdArray) { + if (StringUtils.isNotBlank(monitorId)) { + addUserToLesson(request, serverId, datetime, requestorUsername, hashValue, + LoginRequestDispatcher.METHOD_MONITOR, lsIdStr, monitorId, courseId, + countryIsoCode, langIsoCode); } - - ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); - Authenticator.authenticate(serverMap, datetime, requestorUsername, hashValue); - ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); - // adds user to group - ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId, countryIsoCode, langIsoCode, null); - - if (lessonService == null) { - lessonService = (ILessonService) WebApplicationContextUtils - .getRequiredWebApplicationContext(request.getSession().getServletContext()) - .getBean("lessonService"); - } - - User user = userMap.getUser(); - if ( user == null ) { - String error = "Unable to add user to lesson class as user is missing from the user map"; - log.error(error); - throw new UserInfoFetchException(error); - } - - if (LoginRequestDispatcher.METHOD_LEARNER.equals(method)) { - lessonService.addLearner(Long.parseLong(lsIdStr), user.getUserId()); - } else if (LoginRequestDispatcher.METHOD_MONITOR.equals(method)) { - lessonService.addStaffMember(Long.parseLong(lsIdStr), user.getUserId()); - } - + } } + return true; + } catch (UserInfoFetchException e) { + log.error(e, e); + return false; + } catch (AuthenticationException e) { + log.error(e, e); + return false; + } } - + + private void addUserToLesson(HttpServletRequest request, String serverId, String datetime, + String requestorUsername, String hashValue, String method, String lsIdStr, String username, + String courseId, String countryIsoCode, String langIsoCode) throws AuthenticationException, + UserInfoFetchException { + + if (log.isDebugEnabled()) { + log.debug("Adding user '" + username + "' as " + method + " to lesson with id '" + lsIdStr + "'."); + } + + ExtServerOrgMap serverMap = integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, requestorUsername, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap(serverMap, username); + // adds user to group + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(serverMap, userMap, courseId, + countryIsoCode, langIsoCode, null); + + if (lessonService == null) { + lessonService = (ILessonService) WebApplicationContextUtils.getRequiredWebApplicationContext( + request.getSession().getServletContext()).getBean("lessonService"); + } + + User user = userMap.getUser(); + if (user == null) { + String error = "Unable to add user to lesson class as user is missing from the user map"; + log.error(error); + throw new UserInfoFetchException(error); + } + + if (LoginRequestDispatcher.METHOD_LEARNER.equals(method)) { + lessonService.addLearner(Long.parseLong(lsIdStr), user.getUserId()); + } else if (LoginRequestDispatcher.METHOD_MONITOR.equals(method)) { + lessonService.addStaffMember(Long.parseLong(lsIdStr), user.getUserId()); + } + + } + } + } Index: lams_central/web/WEB-INF/struts/struts-config.xml =================================================================== diff -u -rda2924f4d15aa5587ed5e5dc7152b850994bdd87 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision da2924f4d15aa5587ed5e5dc7152b850994bdd87) +++ lams_central/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -14,6 +14,10 @@ + @@ -31,6 +35,11 @@ type="org.lamsfoundation.lams.web.planner.GroupingPedagogicalPlannerForm" /> + + @@ -52,6 +61,9 @@ + + + classpath:/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml classpath:/org/lamsfoundation/lams/learning/learningApplicationContext.xml @@ -245,11 +244,6 @@ - XMPP - org.lamsfoundation.lams.web.PresenceServlet - - - BogoPogoServlet org.lamsfoundation.lams.webservice.WhiteboardToJpgServlet @@ -459,10 +453,6 @@ /fckeditor/editor/filemanager/browser/default/connectors/jsp/connector - XMPP - /XMPP - - BogoPogoServlet /BogoPogo Index: lams_central/web/lamscommunity/lamscommunityLogin.jsp =================================================================== diff -u -rc234c64ad9ff9d713f6d8e3331d0c20075e49303 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_central/web/lamscommunity/lamscommunityLogin.jsp (.../lamscommunityLogin.jsp) (revision c234c64ad9ff9d713f6d8e3331d0c20075e49303) +++ lams_central/web/lamscommunity/lamscommunityLogin.jsp (.../lamscommunityLogin.jsp) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -42,7 +42,7 @@ - +

 

Index: lams_central/web/toolcontent/importLC.jsp =================================================================== diff -u --- lams_central/web/toolcontent/importLC.jsp (revision 0) +++ lams_central/web/toolcontent/importLC.jsp (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -0,0 +1,53 @@ +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> +<%@ taglib uri="tags-lams" prefix="lams"%> +<%@ taglib uri="tags-core" prefix="c"%> +<%@ taglib uri="tags-fmt" prefix="fmt"%> + + + + + <fmt:message key="title.import" /> + + + + + + + +
+ +

+ +

+ +
+ + + +
+
+ + + + + +
Index: lams_central/web/toolcontent/importresultLC.jsp =================================================================== diff -u --- lams_central/web/toolcontent/importresultLC.jsp (revision 0) +++ lams_central/web/toolcontent/importresultLC.jsp (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -0,0 +1,58 @@ +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> +<%@ taglib uri="tags-lams" prefix="lams"%> +<%@ taglib uri="tags-core" prefix="c"%> +<%@ taglib uri="tags-fmt" prefix="fmt"%> + + + + <fmt:message key="title.import.result" /> + + + + + + + + + + +

+ +

+ + + + + +

+
+ +

+

+ +

${toolError}

+
+
+
+ <%-- display new learing desing in Flash side even some tool import failed --%> + <%@include file="import_passon.jsp"%> +
+ +

+

+
+ +

${ldError}

+
+
+
+
+ +   + + +
Index: lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java =================================================================== diff -u -r0446a5dedf7a152649853da2454ad203ff6189e8 -rbdd916337e3a48589da367f4c8b7705fe3197af2 --- lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision 0446a5dedf7a152649853da2454ad203ff6189e8) +++ lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision bdd916337e3a48589da367f4c8b7705fe3197af2) @@ -448,7 +448,7 @@ */ public static InputStream getResponseInputStreamFromExternalServer(String urlStr, HashMap params) throws Exception { - if (!urlStr.endsWith("?")) + if (!urlStr.contains("?")) urlStr += "?"; for (Entry entry : params.entrySet()) {