/** * Constructor for a test run controller * * @param userCourseEnv * @param moduleConfiguration * @param secCallback * @param ureq * @param wControl * @param testCourseNode */ IQRunController( final UserCourseEnvironment userCourseEnv, final ModuleConfiguration moduleConfiguration, final IQSecurityCallback secCallback, final UserRequest ureq, final WindowControl wControl, final IQTESTCourseNode testCourseNode, final AssessmentNotificationsHandler notificationHandler) { super(ureq, wControl); this.modConfig = moduleConfiguration; this.secCallback = secCallback; this.userCourseEnv = userCourseEnv; this.courseNode = testCourseNode; this.type = AssessmentInstance.QMD_ENTRY_TYPE_ASSESS; this.singleUserEventCenter = ureq.getUserSession().getSingleUserEventCenter(); this.assessmentEventOres = OresHelper.createOLATResourceableType(AssessmentEvent.class); this.assessmentInstanceOres = OresHelper.createOLATResourceableType(AssessmentInstance.class); this.chatEventOres = OresHelper.createOLATResourceableType(InstantMessaging.class); this.notificationHandler = notificationHandler; this.userSession = ureq.getUserSession(); addLoggingResourceable(LoggingResourceable.wrap(courseNode)); myContent = createVelocityContainer("testrun"); mainPanel = putInitialPanel(myContent); if (!modConfig .get(IQEditController.CONFIG_KEY_TYPE) .equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) { throw new OLATRuntimeException( "IQRunController launched with Test constructor but module configuration not configured as test", null); } init(ureq); exposeUserTestDataToVC(ureq); final StringBuilder qtiChangelog = createChangelogMsg(ureq); // decide about changelog in VC if (qtiChangelog.length() > 0) { // there is some message myContent.contextPut("changeLog", qtiChangelog); } // if show results on test home page configured - show log final Boolean showResultOnHomePage = (Boolean) testCourseNode .getModuleConfiguration() .get(IQEditController.CONFIG_KEY_RESULT_ON_HOME_PAGE); myContent.contextPut("showChangelog", showResultOnHomePage); }
/** * Collection of constants stored in DB, and referenced in data layer (only?). They cannot be * changed without migrating the DB data. Package visibility. * * <p>Initial Date: 23.06.2011 <br> * * @author lavinia */ public class Constants { // same as BlogFileResource.TYPE_NAME - pure coincidence ?! static final String BLOG_ARTEFACT_NAME = "FileResource.BLOG"; static final String WIKI_ARTEFACT_NAME = "FileResource.WIKI"; static final String EFFICIENCY_STATEMENT_ARTEFACT_NAME = "EfficiencyStatement"; static final String STRUCTURE_ELEMENT_ARTEFACT_NAME = "ep-structure-element"; static final String TEXT_ARTEFACT_NAME = "text"; static final String FILE_ARTEFACT_NAME = "bc"; static final String FORUM_ARTEFACT_NAME = OresHelper.calculateTypeName(Forum.class); static final String LIVE_BLOG_ARTEFACT_NAME = "liveblog"; }
@Override public LockResult acquireLock( final OLATResourceable ores, final OLATPrincipal requestor, final String locksubkey) { final String asset = OresHelper.createStringRepresenting(ores, locksubkey); final LockResult res = syncer.doInSync( ores, new SyncerCallback<LockResult>() { @Override public LockResult execute() { LockResultImpl lres; LockImpl li = clusterLockManager.findLock(asset); if (li == null) { // fine, we can lock it li = clusterLockManager.createLockImpl(asset, requestor); clusterLockManager.saveLock(li); final LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner()); lres = new LockResultImpl(true, le); } else { // already locked by a user. // if that user is us, we can reacquire it final LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner()); if (requestor.equals(li.getOwner())) { // that's us -> success (asset, owner is the // same, and we leave creationdate to when the // lock was originally acquired, not // when it was reacquired. lres = new LockResultImpl(true, le); } else { log.info( "Lock for resource: " + asset + " requested by " + requestor + " already held by " + li.getOwner()); lres = new LockResultImpl(false, le); } } return lres; } }); return res; }
/** * @param ureq * @param cpRoot * @param showMenu * @param activateFirstPage */ CPDisplayController( final UserRequest ureq, final WindowControl wControl, final VFSContainer rootContainer, final boolean showMenu, final boolean activateFirstPage, final String initialUri, final OLATResourceable ores) { super(ureq, wControl); this.rootContainer = rootContainer; // wrapper velocity container for page content this.myContent = createVelocityContainer("cpDisplay"); // the cp component, added to the velocity if (!ureq.getUserSession().getRoles().isGuestOnly()) { final SearchServiceUIFactory searchServiceUIFactory = (SearchServiceUIFactory) CoreSpringFactory.getBean(SearchServiceUIFactory.class); searchCtrl = searchServiceUIFactory.createInputController(ureq, wControl, DisplayOption.BUTTON, null); myContent.put("search_input", searchCtrl.getInitialComponent()); } // TODO:gs:a // may add an additional config for disabling, enabling IFrame style or not in CP mode // but always disable IFrame display when in screenreader mode (no matter whether style gets // ugly) if (getWindowControl().getWindowBackOffice().getWindowManager().isForScreenReader()) { cpComponent = new HtmlStaticPageComponent("", rootContainer); cpComponent.addListener(this); myContent.put("cpContent", cpComponent); } else { cpContentCtr = new IFrameDisplayController(ureq, getWindowControl(), rootContainer, null, ores); cpContentCtr.setAllowDownload(true); listenTo(cpContentCtr); myContent.put("cpContent", cpContentCtr.getInitialComponent()); } // even if we do not show the menu, we need to build parse the manifest and // find the first node to display at startup final VFSItem mani = rootContainer.resolve("imsmanifest.xml"); if (mani == null || !(mani instanceof VFSLeaf)) { throw new OLATRuntimeException( "error.manifest.missing", null, this.getClass().getPackage().getName(), "CP " + rootContainer + " has no imsmanifest", null); } // initialize tree model in any case ctm = new CPManifestTreeModel((VFSLeaf) mani); if (showMenu) { // the menu is only initialized when needed. cpTree = new MenuTree("cpDisplayTree"); cpTree.setTreeModel(ctm); cpTree.addListener(this); } LoggingResourceable nodeInfo = null; if (activateFirstPage) { // set content to first accessible child or root node if no children // available TreeNode node = ctm.getRootNode(); if (node == null) { throw new OLATRuntimeException( CPDisplayController.class, "root node of content packaging was null, file:" + rootContainer, null); } while (node != null && !node.isAccessible()) { if (node.getChildCount() > 0) { node = (TreeNode) node.getChildAt(0); } else { node = null; } } if (node != null) { // node.isAccessible final String nodeUri = (String) node.getUserObject(); if (cpContentCtr != null) { cpContentCtr.setCurrentURI(nodeUri); } if (cpComponent != null) { cpComponent.setCurrentURI(nodeUri); } if (showMenu) { cpTree.setSelectedNodeId(node.getIdent()); } // activate the selected node in the menu (skips the root node that is // empty anyway and saves one user click) selNodeId = node.getIdent(); nodeInfo = LoggingResourceable.wrapCpNode(nodeUri); } } else if (initialUri != null) { // set page if (cpContentCtr != null) { cpContentCtr.setCurrentURI(initialUri); } if (cpComponent != null) { cpComponent.setCurrentURI(initialUri); } // update menu final TreeNode newNode = ctm.lookupTreeNodeByHref(initialUri); if (newNode != null) { // user clicked on a link which is listed in the // toc if (cpTree != null) { cpTree.setSelectedNodeId(newNode.getIdent()); } else { selNodeId = newNode.getIdent(); } } nodeInfo = LoggingResourceable.wrapCpNode(initialUri); } // Note: the ores has a typename of ICourse - see // CPCourseNode.createNodeRunConstructorResult // which has the following line: // OresHelper.createOLATResourceableInstance(ICourse.class, // userCourseEnv.getCourseEnvironment().getCourseResourceableId()); // therefore we use OresHelper.calculateTypeName(ICourse.class) here if (ores != null && nodeInfo != null && !OresHelper.calculateTypeName(ICourse.class).equals(ores.getResourceableTypeName())) { addLoggingResourceable(LoggingResourceable.wrap(ores, OlatResourceableType.cp)); ThreadLocalUserActivityLogger.log( LearningResourceLoggingAction.LEARNING_RESOURCE_OPEN, getClass(), nodeInfo); } putInitialPanel(myContent); }
@Override public boolean isLocked(final OLATResourceable ores, final String locksubkey) { final String asset = OresHelper.createStringRepresenting(ores, locksubkey); final LockImpl li = clusterLockManager.findLock(asset); return (li != null); }
/** * Description:<br> * Test for the marking service * * <p>Initial Date: 8 juin 2010 <br> * * @author srosse, [email protected] */ public class MarkingITCase extends OlatTestCase { private Identity ident1, ident2, ident3; private Identity[] identities; private final String subPath1 = "sub-path-1"; private final String subPath2 = "sub-path-2"; private final String subPath3 = "sub-path-3"; private final String subPath4 = "sub-path-4"; private final String[] subPaths = {subPath1, subPath2, subPath3, subPath4}; private static final OLATResourceable ores = OresHelper.createOLATResourceableInstance("testresource", Long.valueOf(1234l)); private static MarkDAO marking; /** @see junit.framework.TestCase#setUp() */ @Before public void setUp() throws Exception { ident1 = JunitTestHelper.createAndPersistIdentityAsUser("test-1"); ident2 = JunitTestHelper.createAndPersistIdentityAsUser("test-2"); ident3 = JunitTestHelper.createAndPersistIdentityAsUser("test-3"); identities = new Identity[] {ident1, ident2, ident3}; marking = applicationContext.getBean(MarkDAO.class); } @Test public void testSetMark() { for (final Identity ident : identities) { final Mark mark = marking.setMark(ores, ident, subPath1, ""); assertEquals(ident, mark.getCreator()); assertEquals(subPath1, mark.getResSubPath()); assertEquals( ores.getResourceableTypeName(), mark.getOLATResourceable().getResourceableTypeName()); assertEquals(ores.getResourceableId(), mark.getOLATResourceable().getResourceableId()); final boolean marked = marking.isMarked(ores, ident, subPath1); assertTrue(marked); } } @Test public void testRemoveMark() { for (final Identity ident : identities) { marking.setMark(ores, ident, subPath1, ""); } marking.removeMark(ores, ident1, subPath1); final boolean markedAfterRemove = marking.isMarked(ores, ident1, subPath1); assertEquals(markedAfterRemove, false); final boolean marked = marking.isMarked(ores, ident2, subPath1); assertTrue(marked); } @Test public void testRemoveResource() { for (final Identity ident : identities) { for (final String subPath : subPaths) { marking.setMark(ores, ident, subPath, ""); } } marking.deleteMark(ores); boolean marked = false; for (final Identity ident : identities) { for (final String subPath : subPaths) { marked |= marking.isMarked(ores, ident, subPath); } } assertFalse(marked); } @Test public void testIdentityStats() { for (final String subPath : subPaths) { if (subPath.equals(subPath3)) { continue; } marking.setMark(ores, ident1, subPath, ""); } final List<String> subPathList = Arrays.asList(subPaths); final List<MarkResourceStat> stats = marking.getStats(ores, subPathList, ident1); assertEquals(3, stats.size()); for (final MarkResourceStat stat : stats) { assertEquals(1, stat.getCount()); } } @Test public void testStats() { for (final Identity ident : identities) { for (final String subPath : subPaths) { if (subPath.equals(subPath3)) { continue; } marking.setMark(ores, ident, subPath, ""); } } final List<String> subPathList = Arrays.asList(subPath1, subPath2, subPath3); final List<MarkResourceStat> stats = marking.getStats(ores, subPathList, null); assertEquals(2, stats.size()); for (final MarkResourceStat stat : stats) { assertEquals(3, stat.getCount()); } } /* * @Test public void testHeavyLoadStats() { final int numberOf = 30; List<Identity> loadIdentities = new ArrayList<Identity>(); for(int i=0; i<numberOf; i++) { * loadIdentities.add(JunitTestHelper.createAndPersistIdentityAsUser("identity-test-" + i)); } DBFactory.getInstance().intermediateCommit(); List<OLATResourceable> * loadOres = new ArrayList<OLATResourceable>(); for(int i=0; i<numberOf; i++) { loadOres.add(OresHelper.createOLATResourceableInstance("testresource", * Long.valueOf(12300 + i))); } List<String> loadSubPaths = new ArrayList<String>(); for(int i=0; i<numberOf; i++) { loadSubPaths.add("sub-path-" + i); } int count = * 0; for(Identity ident:loadIdentities) { for(OLATResourceable o:loadOres) { for(String sPath:loadSubPaths) { service.setMark(o, ident, sPath, ""); if(++count % 20 * == 0) { DBFactory.getInstance().intermediateCommit(); } } } } DBFactory.getInstance().intermediateCommit(); long start = System.currentTimeMillis(); * List<MarkResourceStat> stat1s = service.getStats(loadOres.get(7), null, loadIdentities.get(15)); System.out.println(stat1s.size() + " in (ms): " + * (System.currentTimeMillis() - start)); DBFactory.getInstance().intermediateCommit(); start = System.currentTimeMillis(); List<MarkResourceStat> stat2s = * service.getStats(loadOres.get(18), null, null); System.out.println(stat2s.size() + " in (ms): " + (System.currentTimeMillis() - start)); * DBFactory.getInstance().intermediateCommit(); } */ }