package org.ijsolutions.testbench.modules; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.UUID; import java.util.concurrent.Executors; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.entermediadb.asset.Asset; import org.entermediadb.asset.MediaArchive; import org.entermediadb.asset.upload.FileUpload; import org.entermediadb.asset.upload.FileUploadItem; import org.entermediadb.asset.upload.UploadRequest; import org.entermediadb.websocket.chat.ChatConnection; import org.ijsolutions.testbench.PlanEntry; import org.ijsolutions.testbench.PlanEntryBuilder; import org.ijsolutions.testbench.Question; import org.ijsolutions.testbench.Response; import org.ijsolutions.testbench.Test; import org.ijsolutions.testbench.TestBench; import org.ijsolutions.testbench.TestManager; import org.ijsolutions.testbench.TestNode; import org.ijsolutions.testbench.TestPlan; import org.ijsolutions.testbench.learninggroup.LearningGroup; import org.ijsolutions.testbench.learninggroup.LearningGroupSearcher; import org.ijsolutions.testing.importers.Importer; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.openedit.Data; import org.openedit.WebPageRequest; import org.openedit.data.PropertyDetailsArchive; import org.openedit.data.Searcher; import org.openedit.event.WebEvent; import org.openedit.hittracker.HitTracker; import org.openedit.hittracker.SearchQuery; import org.openedit.profile.UserProfile; import org.openedit.store.Product; import org.openedit.store.Store; import org.openedit.users.User; import org.openedit.users.UserSearcher; import org.openedit.util.DateStorageUtil; import org.openedit.util.ExecutorManager; public class TestBenchModule extends BaseTestingModule // handles mostly online testing related stuff { protected TestManager fieldTestManager;// protected PropertyDetailsArchive fieldPropertyDetailsArchive; protected Importer fieldImporter; private static final Log log = LogFactory.getLog(TestBenchModule.class); public Importer getImporter() { return fieldImporter; } public void setImporter(Importer inImporter) { fieldImporter = inImporter; } public TestManager getTestManager(String inCatalogId) { if (fieldTestManager == null) { fieldTestManager = (TestManager) getModuleManager().getBean(inCatalogId, "testManager"); } return fieldTestManager; } public void setTestManager(TestManager inTestManager) { fieldTestManager = inTestManager; } public Test createTest(WebPageRequest inReq) throws Exception { Test test = getActiveTest(inReq); TestPlan inStructions = getTestInstructions(inReq); if (inStructions == null) { return test; } if (inStructions != null && test != null && test.getTestPlan() != null && !inStructions.getId().equals(test.getTestPlan().getId())) { } if (test != null) { boolean reset = Boolean.parseBoolean(inReq.findValue("reset")); if (!reset) { return test; } } TestBench bench = getTestBench(inReq); String type = inStructions.getTestType(); if (type == null || type.trim().length() == 0) { type = "planentry"; } type = "planentry"; test = bench.buildTest(type, inStructions); String[] fields = inReq.getRequestParameters("field"); if (fields != null) { bench.getTestSearcher().updateData(inReq, fields, test); } if (test.getId() == null) { test.setId(bench.getTestArchive().nextId()); } test.setProperty("ip", inReq.getRequest().getRemoteAddr()); test.setProperty("user-agent", inReq.getRequest().getHeader("User-Agent")); test.setProperty("referringpage", inReq.getReferringPage()); test.setUser(inReq.getUser()); String id = inStructions.getId(); test.setProperty("plan", id); test.setProperty("planname", inStructions.getName()); test.setProperty("testmode", inStructions.get("testmode")); String source = inReq.getRequestParameter("source"); if (source != null) { test.setProperty("source", source); } test.setTestPlan(inStructions); getTestManager(bench.getCatalogId()).setActiveTest(inReq.getUser(), test); String course = inReq.getRequestParameter("courseid"); if (course != null) { test.setProperty("course", course); } Double passmark = inStructions.getDouble("passmark"); if (passmark == null) { passmark = getTestBench(inReq).getDefaultPassmark(); } if (passmark != null) { test.setPassMark(passmark); } String classid = inReq.getRequestParameter("classid"); if (classid != null) { test.setProperty("class", classid); } test.setStartTime(new Date()); inReq.putPageValue("testplan", inStructions); //makes test available on the page inReq.putPageValue("test", test); if (inStructions.get("language") != null) { String newlang = inStructions.get("language"); if (newlang.equals("locale_browser")) { inReq.removeSessionValue("sessionlocale"); } else { String locale = newlang.substring("locale_".length()); inReq.putSessionValue("sessionlocale", locale); } } getTestBench(inReq).saveTest(test);// may have to watch speed on this. test.start(); //tincan code for launching/creating a test bench.fireLearningEvent(inReq, inReq.getUser(), "attempted", test, "test"); return test; } //this is for a the response to a single question public void recordResponse(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); FileUpload command = (FileUpload) bench.getSearcherManager().getModuleManager().getBean("fileUpload"); UploadRequest properties = command.parseArguments(inReq); String[] response = inReq.getRequestParameters("response"); String questionid = inReq.getRequestParameter("questionid"); Test test = getActiveTest(inReq); if (test == null) { return; } TestNode node = test.getNode(questionid); if (!test.isStarted() && !test.isComplete()) { test.start(); } if (response == null) { return; } boolean recorded = false; for (int i = 0; i < response.length; i++) { Response r = null; String responseid = response[i]; String val = inReq.getRequestParameter(responseid + ".value"); if (val == null) { val = inReq.getRequestParameter("response.value"); } String[] multivalues = inReq.getRequestParameters("response.value"); if (multivalues != null && multivalues.length > 1) { StringBuffer buf = new StringBuffer(); for (int j = 0; j < multivalues.length; j++) { String value = multivalues[j]; buf.append(value); buf.append(" | "); } val = buf.toString(); } if (properties.getFirstItem() != null && node != null) { handleResponseUpload(test, node, properties, inReq); val = "uploadcompleted"; } if (val != null) { if (node == null) { // problem - cannot find the response provided for this // question // can occur when users are logged into different tests // within the same browser inReq.putPageValue("error", "multiple-tests"); return; } r = test.recordResponse(node, val, true, true); recorded = true; } if (r != null) { String[] fields = inReq.getRequestParameters("responsefield"); bench.getQuestionSearcher().updateData(inReq, fields, r); } if (recorded) { break; } } if (test.isTestPassed()) { test.setValue("passed", true); } else { test.setValue("passed", false); } getTestBench(inReq).saveTest(test);// may have to watch speed on this. //tincan code for answering a question HashMap map = new HashMap(); String questiontypeid = node.getQuestion().get("questiontype"); Data questiontype = bench.getData("questiontype", questiontypeid); map.put("name", questiontype.getName()); map.put("testid", test.getId()); map.put("learningGroup", test.get("class")); map.put("course", test.get("course")); map.put("testplan", test.get("plan")); map.put("question", questionid); bench.fireLearningEvent(inReq, inReq.getUser(), "answered", node, "question", map); if (test.isComplete()) { handleTestCompletionEvent(inReq, test, bench, map); } } private void handleTestCompletionEvent(WebPageRequest inReq, Test inTest, TestBench inBench, Map inMap) { inBench.fireLearningEvent(inReq, inTest.getUser(), "completed", inTest, "test", inMap); if (inTest.isTestPassed()) { inBench.fireLearningEvent(inReq, inTest.getUser(), "passed", inTest, "test", inMap); } else { inBench.fireLearningEvent(inReq, inTest.getUser(), "failed", inTest, "test", inMap); inTest.setValue("passed", false); } } private void handleResponseUpload(Test test, TestNode node, UploadRequest properties, WebPageRequest inReq) { FileUploadItem item = properties.getFirstItem(); String fname = item.getName(); Question question = node.getQuestion(); String sourcepath = question.get("uploadsourcepath"); HashMap variables = new HashMap(); if (sourcepath == null || sourcepath.length() == 0) { sourcepath = "userassets/" + inReq.getUserName() + "/tests/" + test.getId() + "/" + node.getId(); } variables.put("userid", test.getUser().getId()); MediaArchive archive = (MediaArchive) inReq.getPageValue("mediaarchive"); sourcepath = archive.getSearcherManager().getValue(archive.getCatalogId(), sourcepath, variables); Asset current = archive.getAssetBySourcePath(sourcepath); if (current == null) { current = archive.createAsset(sourcepath); } current.setProperty("assetaddeddate", DateStorageUtil.getStorageUtil().formatForStorage(new Date())); org.entermediadb.asset.Category target = archive.getCategoryArchive().createCategoryTree(sourcepath); current.addCategory(target); archive.getCategoryArchive().saveAll(); String path = "/WEB-INF/data/" + archive.getCatalogId() + "/originals/" + sourcepath + "/" + fname; current.setProperty("testid", test.getId()); current.setProperty("owner", test.getUser().getId()); current.setProperty("nodeid", node.getId()); current.setProperty("name", fname); node.setProperty("assetid", current.getId()); properties.saveFileAs(properties.getFirstItem(), path, inReq.getUser()); current.setPrimaryFile(properties.getFirstItem().getName()); archive.getAssetSearcher().saveData(current, inReq.getUser()); archive.fireMediaEvent("importing/assetsuploaded", inReq.getUser(), current); //TODO handle tincan code for attachment, check registry for verb... "uploaded"? } public TestPlan getTestInstructions(WebPageRequest inReq) { TestBench testBench = getTestBench(inReq); String planid = inReq.findValue("planid"); TestPlan inStructions = testBench.getTestPlanArchive().getTestPlan(planid); if (inStructions == null) { return null; } inStructions.setId(planid); return inStructions; } public void jumpToQuestion(WebPageRequest inReq) { String questionid = inReq.getRequestParameter("questionid"); if (questionid == null) { return; } Test test = getActiveTest(inReq); TestNode question = test.getNode(questionid); test.setCurrentNode(question); } public void jumpToCategory(WebPageRequest inReq) { String categoryid = inReq.getRequestParameter("categoryid"); if (categoryid == null) { return; } Test test = getActiveTest(inReq); test.jumpToCategory(categoryid); } public Test getActiveTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); String rp = inReq.getRequestParamsAsList(); User user = inReq.getUser(); if (user != null) { Test test = getTestManager(bench.getCatalogId()).getActiveTest(user); inReq.putPageValue("test", test); if (test != null) { inReq.putPageValue("testplan", test.getTestPlan()); if (test.getTestPlan() == null) { if (test.get("plan") != null) { TestPlan plan = bench.getTestPlan(test.get("plan")); test.setTestPlan(plan); } } } return test; } return null; } public void resetActiveTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); User user = inReq.getUser(); Test test = getActiveTest(inReq); if (user != null) { getTestManager(bench.getCatalogId()).clearTest(user.getId()); } inReq.removePageValue("test"); //tin can code to quit/suspend and reset a test bench.fireLearningEvent(inReq, user, "suspended", test, "test"); } public void restartTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Test test = getActiveTest(inReq); test.restart(); //tin can code to restart a test from scratch bench.fireLearningEvent(inReq, inReq.getUser(), "attempted", test, "test"); } public void submitTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Test test = getActiveTest(inReq); TestPlan inStructions = test.getTestPlan(); String[] fields = inReq.getRequestParameters("field"); if (fields != null) { Searcher testsearcher = bench.getTestSearcher(); testsearcher.updateData(inReq, fields, test); } if (test != null) { if (test.isTestPassed()) { test.setValue("passed", true); } else { test.setValue("passed", false); } test.setComplete(true); test.setSubmitted(true); test.setFinishTime(new Date()); bench.saveTest(test); } //tincan code for submitting a test bench.fireLearningEvent(inReq, inReq.getUser(), "submitted", test, "test"); handleTestCompletionEvent(inReq, test, bench, null); //fires completion and pass or fail } //called from xconf files public void saveTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Test test = getActiveTest(inReq); if (test != null) { bench.saveTest(test); } bench.fireLearningEvent(inReq, inReq.getUser(), "saved", test, "test"); } public void getAllQuestions(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery q = bench.getQuestionSearcher().createSearchQuery(); q.addMatches("*"); bench.getQuestionSearcher().cachedSearch(inReq, q); } public void getUserTests(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery q = bench.getTestSearcher().createSearchQuery(); q.addSortBy("starttimeDown"); String userid = inReq.getRequestParameter("id"); if (userid == null) { userid = inReq.getUser().getId(); } q.addMatches("user", userid); bench.getTestSearcher().cachedSearch(inReq, q); } public Test loadTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); String testid = inReq.findValue("testid");// testid.html if (testid == null) { testid = inReq.getRequestParameter("id"); } Test test = (Test) bench.getTestSearcher().searchById(testid); if (test != null) { test.updateStatus(); bench.getTestArchive().setActiveTest(inReq.getUser(), test); inReq.putPageValue("testplan", test.getTestPlan()); inReq.putPageValue("test", test); } if (!test.isComplete() && !test.isSubmitted() && test.getUser().getId().equals(inReq.getUser().getId())) { //tin can code when student reloads an incomplete test bench.fireLearningEvent(inReq, inReq.getUser(), "resumed", test, "test"); } else if (!test.getUser().getId().equals(inReq.getUser().getId())) { //tin can code for when instructor reviews a test bench.fireLearningEvent(inReq, inReq.getUser(), "reviewed", test, "test"); } return test; } public TestPlan loadTestPlan(WebPageRequest inReq) { String testid = inReq.findValue("planid");// testid.html if (testid == null) { testid = inReq.getRequestParameter("id"); } TestBench bench = getTestBench(inReq); TestPlan plan = bench.getTestPlanArchive().getTestPlan(testid); if(plan != null) { inReq.putPageValue("testplan", plan); } return plan; } public void pauseActiveTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Test test = getActiveTest(inReq); if (test != null) { test.pause(); } //tin can code to pause a test bench.fireLearningEvent(inReq, inReq.getUser(), "paused", test, "test"); } public void resumeActiveTest(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Test test = getActiveTest(inReq); if (test != null) { test.resume(); } //tin can code to resume a paused test bench.fireLearningEvent(inReq, inReq.getUser(), "resumed", test, "test"); } public void loadUserTests(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery query = bench.getTestSearcher().createSearchQuery(); query.addMatches("user", inReq.getUserName()); bench.getTestSearcher().search(query); } public void loadCompleteTests(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery query = bench.getTestSearcher().createSearchQuery(); query.addMatches("user", inReq.getUserName()); query.addMatches("status", "complete"); String planid = inReq.getRequestParameter("planid"); if (planid != null) { query.addMatches("plan", planid); } bench.getTestSearcher().cachedSearch(inReq, query); } public void loadIncompleteTests(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery query = bench.getTestSearcher().createSearchQuery(); query.addMatches("user", inReq.getUserName()); query.addMatches("status", "incomplete"); String planid = inReq.getRequestParameter("planid"); if (planid != null) { query.addMatches("plan", planid); } bench.getTestSearcher().cachedSearch(inReq, query); } public void findAllTests(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); SearchQuery query = bench.getTestSearcher().createSearchQuery(); query.addMatches("status", "complete"); query.addMatches("status", "incomplete"); bench.getTestSearcher().cachedSearch(inReq, query); } public void runImports(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); getImporter().convert(bench); } public void reindexTests(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); bench.getTestSearcher().reIndexAll(); } /* * * ID College Available * Start Expiry Batch ID */ public void generatePrepaidCodes(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); Searcher codesearcher = bench.getSearcherManager().getSearcher(bench.getCatalogId(), "prepaid"); String countstring = inReq.findValue("number"); if (countstring == null) { return; // nothing to do } int count = Integer.parseInt(countstring); String[] fields = inReq.getRequestParameters("field"); for (int i = 0; i < count; i++) { Random random = new Random(); long base = 1000000000000l; long add = random.nextInt(999999999); long result = base + add; String barcode = String.valueOf(result); Data data = codesearcher.createNewData(); data.setId(barcode); data.setProperty("sequencenumber", codesearcher.nextId()); data.setProperty("barcode", barcode); data.setProperty("issuedate", DateStorageUtil.getStorageUtil().formatForStorage(new Date())); data.setProperty("issuedby", inReq.getUserName()); for (int j = 0; j < fields.length; j++) { String field = fields[j]; String val = inReq.getRequestParameter(field + ".value"); if (val != null) { data.setProperty(field, val); } } codesearcher.saveData(data, inReq.getUser()); } } public void generateBatchXml(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); Searcher codesearcher = bench.getSearcherManager().getSearcher(bench.getCatalogId(), "prepaid"); String batchid = inReq.getRequestParameter("batchid"); SearchQuery q = codesearcher.createSearchQuery(); q.addMatches("batchid", batchid); HitTracker hits = codesearcher.search(q); Element root = DocumentHelper.createElement("map"); for (Iterator iterator = hits.iterator(); iterator.hasNext();) { Data item = (Data) iterator.next(); Element document = root.addElement("document");// the first // document/page to // be added Element property = document.addElement("property"); property.setText(item.get("id")); property.addAttribute("name", "code"); property = document.addElement("property"); property.setText(item.get("id")); property.addAttribute("name", "barcode"); property.addAttribute("type", "barcode"); } inReq.putPageValue("xmlmap", root); } public void loadNode(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); String questionid = inReq.getRequestParameter("questionid"); Question q = bench.getQuestion(questionid); TestNode node = new TestNode(); node.setQuestion(q); String response = inReq.getRequestParameter("responseid"); if (response != null) { node.setResponse(response); } Test test = new Test(); test.addNode(node); inReq.putPageValue("test", test); node.setTest(test); inReq.putPageValue("node", node); inReq.putPageValue("question", q); } public void analyzeTest(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); Test test = loadTest(inReq); getTestManager(bench.getCatalogId()).getTestAnalyzer().analyze(test); } public boolean isOwner(WebPageRequest inReq) throws Exception { String dataid = inReq.getRequestParameter("id"); if (dataid == null) { FileUpload command = new FileUpload(); command.setPageManager(getPageManager()); UploadRequest properties = command.parseArguments(inReq); if (properties == null) { return false; } else { inReq.putPageValue("properties", properties); } } String userid = inReq.getUserName(); if (userid != null && dataid != null) { boolean equals = userid.equals(dataid); return equals; } return false; } public void redirectToProduct(WebPageRequest inReq) { if (inReq.getUser() != null) { TestBench tb = getTestBench(inReq); Store store = (Store) inReq.getPageValue("store"); String productid = inReq.getRequestParameter("productid"); String lgid = inReq.getRequestParameter("lgid"); String paylater = inReq.getRequestParameter("paylater"); if (productid != null) { Product p = store.getProduct(productid); if (Boolean.parseBoolean(p.get("apprequired"))) { String home = "/" + tb.getApplicationId() + "/views/cart/products/" + productid + ".html"; inReq.redirect(home); } else { String home = "/" + tb.getApplicationId() + "/views/cart/checkout/selectcourse.html?productid=" + productid + "&lgid=" + lgid + "&lg=" + lgid + "&paylater=" + paylater; inReq.redirect(home); } } } } public void redirectToProfile(WebPageRequest inReq) { TestBench tb = getTestBench(inReq); Boolean uselegacy = Boolean.parseBoolean(tb.getSetting("uselegacycart")); if (inReq.getUser() != null) { if (uselegacy || true)//always redirect to home.... { String home = "/" + tb.getApplicationId() + "/views/modules/user/edit/index.html?id=" + inReq.getUserName(); inReq.redirect(home); } else { String shop = "/" + tb.getApplicationId() + "/shop/myaccount/index.html"; //inReq.redirect(shop); } } if (!uselegacy) { String shop = "/" + tb.getApplicationId() + "/shop/index.html"; inReq.redirect(shop); } } public void checkUniqueEmail(WebPageRequest inReq) { boolean allowduplicates = Boolean.parseBoolean(inReq.findValue("allowduplicateemails")); if (allowduplicates) { return; } String email = inReq.getRequestParameter("email.value"); if (email == null) { email = inReq.getRequestParameter("email"); } if (email == null) { return; } UserSearcher userSearcher = (UserSearcher) getTestBench(inReq).getSearcher("user"); Data user = (Data) userSearcher.searchByField("email", email); String id = inReq.getRequestParameter("id"); User current = (User) userSearcher.searchById(id); if (user != null) { if (id != null) { if (id.equals(user.getId())) { return; } } // errors.put("error-email-in-use", "This email address is in use"); // inReq.putPageValue("errors", errors); inReq.putPageValue("emailinuse", true); if (current != null) { inReq.setRequestParameter("email.value", current.getEmail()); } cancelAndForward(inReq); } } private void cancelAndForward(WebPageRequest inReq) { String errorURL = inReq.findValue("errorURL"); inReq.setHasForwarded(true); inReq.setCancelActions(true); inReq.forward(errorURL); } public void addToDemo(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); LearningGroup demo = bench.getLearningGroup("demo"); if (demo != null) { bench.addUserToClass(inReq.getUserName(), "demo", "student"); } } public void recordExperience(WebPageRequest inReq) { WebEvent event = (WebEvent) inReq.getPageValue("webevent"); TestBench bench = getTestBench(inReq); if (event != null) { bench.getTinCan().logEvent(event); } } public void setRecentActivity(WebPageRequest inReq) { //This is used by the TinCanGenerator to create a useful activity ID // classes/CLASSID/courses/COURSEID/ACTIVITYID String classid = inReq.findValue("classid"); if (classid == null) { classid = inReq.findValue("lg"); } String courseid = inReq.findValue("courseid"); String testplan = inReq.findValue("testplan"); if (testplan == null) { testplan = inReq.findValue("target"); } String urifragment = "classes/" + classid + "/courses/" + courseid + "/" + testplan; inReq.putSessionValue("last-tincan-activityid", urifragment); } public void checkReCaptcha(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); String key = bench.getSetting("recaptchakey"); String token = inReq.getRequestParameter("g-recaptcha-response"); HttpPost post = new HttpPost("https://www.google.com/recaptcha/api/siteverify?secret=" + key + "&response=" + token); ; CloseableHttpClient httpclient; httpclient = HttpClients.createDefault(); HttpResponse response = httpclient.execute(post); HttpEntity entity = response.getEntity(); JSONParser parser = new JSONParser(); String content = IOUtils.toString(entity.getContent()); JSONObject object = (JSONObject) parser.parse(content); Boolean success = (Boolean) object.get("success"); if (!success) { inReq.setCancelActions(true); } // https://developers.google.com/recaptcha/docs/verify // "success": true|false, // "challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ) // "hostname": string, // the hostname of the site where the reCAPTCHA was solved // "error-codes": [...] // optional } // public void generateFeed(WebPageRequest req) throws Exception { // SyndFeed feed = new SyndFeedImpl(); // String feedtype = req.getPage().get("feedtype"); // if (feedtype == null) { // feedtype = "atom_0.3"; // } // feed.setFeedType(feedtype); // // // feed.setTitle(blog.getTitle()); // // feed.setLink(blog.getHostName()); // // feed.setDescription(blog.getDescription()); // // List recent = blog.getRecentVisibleEntries(blog.getRecentMaxCount()); // feed.setEntries(recent); // // Writer writer = new StringWriter(); // SyndFeedOutput output = new SyndFeedOutput(); // output.output(feed, writer); // writer.close(); // req.putPageValue("feedresults", writer.toString()); // } // // public void launchActivity(WebPageRequest inReq) throws Exception { TestBench bench = getTestBench(inReq); TestPlan testplan = loadTestPlan(inReq); String redirecturl = null; String testmode = testplan.get("testmode"); String lg = inReq.findValue("classid"); String course = inReq.findValue("courseid"); String activityid = "http://classes/" + lg + "/courses/" + course + "/" + testplan.getId(); String linkroot = null; if (course != null) { linkroot = "/classes/" + lg + "/courses/" + course; } else { linkroot = "/classes/" + lg; } if ("video".equals(testmode)) { redirecturl = "/" + bench.getApplicationId() + "/views/videoactivity/index.html?reset=true&planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg; } else { if ("videoconference".equals(testmode)) { redirecturl = "/" + bench.getApplicationId() + linkroot + "/videoroom/index.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg + "&roomid=" + lg + course + testplan.getId(); } else if ("livestream".equals(testmode)) { redirecturl = "/" + bench.getApplicationId() + linkroot + "/keynote/index.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg + "&roomid=" + lg + course + testplan.getId(); } else if ("livetest".equals(testmode)) { redirecturl = "/" + bench.getApplicationId() + linkroot + "/livetest/index.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg + "&roomid=" + lg + course + testplan.getId(); } else if ("chatroom".equals(testmode)) { redirecturl = "/" + bench.getApplicationId() + "/classes/" + lg + "/chatterbox/chat.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg; } else if ("presentation".equals(testmode)) { String asuser = inReq.findValue("asuser"); User user = inReq.getUser(); if (asuser != null) { user = bench.getUserManager().getUser(asuser); } String url1 = "/" + bench.getApplicationId() + "/activities/presentations/" + testplan.getId() + "/index.html"; String url2 = "/" + bench.getApplicationId() + "/activities/presentations/" + testplan.getId() + "/content/index.html"; String url3 = "/" + bench.getApplicationId() + "/activities/presentations/" + testplan.getId() + "/story.html"; log.info("checking: " + url1); if (inReq.getPageStreamer().doesExist(url1) || inReq.getPageStreamer().doesExist(url2) || inReq.getPageStreamer().doesExist(url3)) { { redirecturl = "/" + bench.getApplicationId() + linkroot + "/embed/index.html?target=" + testplan.getId() + "&classid=" + lg; if (asuser != null) { redirecturl = redirecturl + "&asuser=" + asuser; } } } } else if ("assignment".equals("testmode")) { Data test = bench.findResumableTest(inReq.getUserName(), testplan.getId()); if (test != null) { redirecturl = "/" + bench.getApplicationId() + "/test/active/actions/loadtest.html?id=" + test.getId(); } else { redirecturl = "/" + bench.getApplicationId() + "/test/active/actions/starttest.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg; } } else { redirecturl = "/" + bench.getApplicationId() + "/test/active/actions/starttest.html?planid=" + testplan.getId() + "&courseid=" + course + "&classid=" + lg; } } inReq.redirect(redirecturl); } public void saveSorts(WebPageRequest inReq) { String[] order = inReq.getRequestParameters("order"); String searchtype = inReq.getRequestParameter("searchtype"); String sortfield = inReq.getRequestParameter("sortfield"); TestBench bench = getTestBench(inReq); Searcher searcher = bench.getSearcher(searchtype); ArrayList sorted = new ArrayList(); for (int i = 0; i < order.length; i++) { String dataid = order[i]; Data target = (Data) searcher.searchById(dataid); target.setProperty(sortfield, String.valueOf(i)); sorted.add(target); } searcher.saveAllData(sorted, null); bench.clearCaches(); } public void createSampleReponseFromTest(WebPageRequest inReq) { Test test = loadTest(inReq); TestBench bench = getTestBench(inReq); Searcher searcher = bench.getSearcher("question"); Boolean copiedok = false; int copycount = 0; for (Iterator iterator = test.getNodes().iterator(); iterator.hasNext();) { TestNode node = (TestNode) iterator.next(); Question question = node.getQuestion(); if (question.get("sampleresponse") != null && question.get("sampleresponse").length() > 0) { continue; } Response response = node.getResponse(); if (response != null) { if ("longanswer".equals(question.get("questiontype")) || "textfield".equals(question.get("questiontype"))) { String sampleanswer = response.getText(); if (sampleanswer != null && sampleanswer.length() > 0) { question.setValue("sampleresponse", sampleanswer); searcher.saveData(question); } copiedok = true; copycount++; } } } inReq.putPageValue("copiedok", copiedok); inReq.putPageValue("copycount", copycount); } public ExecutorManager getExecutorManager(String inCatalogId) { ExecutorManager queue = (ExecutorManager) getModuleManager().getBean(inCatalogId, "executorManager"); return queue; } public void trackUserLocation(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); log.info("tracking" + inReq); // getExecutorManager(bench.getCatalogId()).execute( new Runnable() { // @Override // public void run() // { // MediaArchive archive = getMediaArchive(inReq); // JSONObject data = (JSONObject) inReq.getPageValue("json"); // String classid = inReq.findValue("classid"); // String planid = inReq.findValue("planid"); // User user = inReq.getUser(); // if (classid != null && user != null) // { // Searcher participants = bench.getSearcher("activityparticipanttracking"); // Data row = null; // if (planid != null) // { // row = participants.query().ignoreEmpty().exact("testplan", planid).exact("user", user.getId()).exact("learninggroup", classid).searchOne(); // } // else // { // row = participants.query().missing("testplan").exact("user", user.getId()).exact("learninggroup", classid).searchOne(); // } // if (row == null) // { // row = participants.createNewData(); // row.setValue("testplan", planid); // row.setValue("learninggroup", classid); // row.setValue("user", user); // } // boolean classmember = bench.isUserInClass(user.getId(), classid); // row.setValue("classmember", classmember); // row.setValue("onlinestatus", "online"); // row.setValue("lastonlinestatus", new Date()); // if (data != null) // { // row.setValue("onlineactivetab", data.get("active")); // } // else // { // row.setValue("onlineactivetab", "online"); // } // participants.saveData(row); // } // UserProfile profile = (UserProfile) archive.getData("userprofile", inReq.getUserName()); // if (profile != null) // { // profile.setValue("onlinestatus", "online"); // profile.setValue("lastonlinestatus", new Date()); // archive.saveData("userprofile", profile); // } // // } // }); // // } public void logoutOldSessions(WebPageRequest inReq) { //get the class list, flag users who haven't done anything in 5 min as offline? } public void addDefaultClasses(WebPageRequest inReq) { TestBench bench = getTestBench(inReq); LearningGroupSearcher searcher = bench.getLearningGroupSearcher(); MediaArchive archive = getMediaArchive(inReq); HitTracker defaults = searcher.query().exact("addonregistration", "true").search(); for (Iterator iterator = defaults.iterator(); iterator.hasNext();) { Data hit = (Data) iterator.next(); bench.addUserToClass(inReq.getUserName(), hit.getId(), "student"); } if (bench.isTrue(("enableuserrooms"))) { Data group = (Data) searcher.searchByField("owner", inReq.getUserName()); if (group == null) { group = (LearningGroup) searcher.createNewData(); } else { group = searcher.loadLearningGroup(group.getId()); } group.setProperty("owner", inReq.getUserName()); group.setValue("deliverytype", "guestroom"); group.setValue("classtemplate", "guestroomtemplate"); group.setValue("name", "Guest Room"); searcher.saveData(group); bench.addUserToClass(inReq.getUserName(), group.getId(), "owner"); } } public void syncActiveTests(WebPageRequest inReq) { //This is really bad. // TestBench bench = getTestBench(inReq); // String planid = inReq.findValue("planid"); // TestManager manager = getTestManager(bench.getCatalogId()); // // TestPlan plan = loadTestPlan(inReq); // // PlanEntryBuilder builder = (PlanEntryBuilder) bench.getTestBuilder("planentry"); // // // for (Iterator iterator = manager.getTestMap().keySet().iterator(); iterator.hasNext();) // { // String key = (String)iterator.next(); // Test livetest = (Test) manager.getTestMap().get(key); // TestPlan currentplan = bench.getTestPlan(livetest.getTestPlan().getId());//load the newest version // // bench.getTestManager().updateTest(bench, livetest, currentplan); // // // // } // // } public void clear(WebPageRequest inReq) { getTestBench(inReq).clearCaches(); getMediaArchive(inReq).clearAll(); String catalogid = inReq.findValue("catalogid"); Executors.newSingleThreadExecutor().execute(new Runnable() { @Override public void run() { Collection tables = getSearcherManager().reloadLoadedSettings(catalogid); } }); } public void loadPlanEntry(WebPageRequest inReq) { TestPlan testplan = loadTestPlan(inReq); String entryid = inReq.findValue("entryid"); PlanEntry entry = testplan.getPlanEntry(entryid); inReq.putPageValue("planentry", entry); } }