Search in sources :

Example 61 with EPStructureElement

use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.

the class EPFrontendManagerTest method testAssignMapTemplateToUser.

@Test
public void testAssignMapTemplateToUser() {
    // create a template
    OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();
    // create a repository entry
    RepositoryEntry addedEntry = repositoryService.create(ident1, null, "-", "template-1", "map-template-1", resource, RepositoryEntry.ACC_OWNERS);
    dbInstance.commitAndCloseSession();
    // create the template owned by ident1
    PortfolioStructureMap templateEl = epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    // first page
    PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-1", "template-page-1");
    // structure element 1 from page 1
    PortfolioStructure struct11 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.1", "template-structure-1.1");
    epStructureManager.addCollectRestriction(struct11, "Forum", "minimum", 2);
    epStructureManager.savePortfolioStructure(struct11);
    // structure element 2 from page 1
    PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.2", "template-structure-1.2");
    assertNotNull(struct12);
    // first page
    PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-2", "template-page-2");
    // structure element 1 from page 2
    PortfolioStructure struct21 = epFrontendManager.createAndPersistPortfolioStructureElement(page2, "template-structure-2.1", "template-structure-2.1");
    epStructureManager.addCollectRestriction(struct21, "bc", "maximum", 4);
    epStructureManager.savePortfolioStructure(struct21);
    // save the template
    dbInstance.commitAndCloseSession();
    // make the copy
    PortfolioStructureMap map = epFrontendManager.assignStructuredMapToUser(ident2, templateEl, addedEntry, null, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(map);
    // check the copy
    PortfolioStructure retrievedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
    assertNotNull(retrievedMap);
    assertTrue(retrievedMap instanceof EPStructuredMap);
    assertNotNull(((EPStructuredMap) retrievedMap).getStructuredMapSource());
    assertEquals(templateEl.getKey(), ((EPStructuredMap) retrievedMap).getStructuredMapSource().getKey());
    // check pages of the copied map
    List<PortfolioStructure> pages = epFrontendManager.loadStructureChildren(retrievedMap);
    assertNotNull(pages);
    assertEquals(2, pages.size());
    assertTrue(pages.get(0) instanceof EPPage);
    assertTrue(pages.get(1) instanceof EPPage);
    assertEquals("template-page-1", ((EPStructureElement) pages.get(0)).getTitle());
    assertEquals("template-page-2", ((EPStructureElement) pages.get(1)).getTitle());
    // check root
    assertNotNull(((EPStructureElement) pages.get(0)).getRoot());
    assertEquals(retrievedMap.getKey(), ((EPStructureElement) pages.get(0)).getRoot().getKey());
    // check children of the pages
    List<PortfolioStructure> structs1 = epFrontendManager.loadStructureChildren(pages.get(0));
    assertNotNull(structs1);
    assertEquals(2, structs1.size());
    assertTrue(structs1.get(0) instanceof EPStructureElement);
    assertTrue(structs1.get(1) instanceof EPStructureElement);
    EPStructureElement struct11El = (EPStructureElement) structs1.get(0);
    assertEquals("template-structure-1.1", struct11El.getTitle());
    assertEquals("template-structure-1.2", ((EPStructureElement) structs1.get(1)).getTitle());
    // check root
    assertNotNull(((EPStructureElement) structs1.get(0)).getRoot());
    assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(0)).getRoot().getKey());
    assertNotNull(((EPStructureElement) structs1.get(1)).getRoot());
    assertEquals(retrievedMap.getKey(), ((EPStructureElement) structs1.get(1)).getRoot().getKey());
    // check collect restriction
    assertNotNull(struct11El.getCollectRestrictions());
    assertEquals("Forum", struct11El.getCollectRestrictions().get(0).getArtefactType());
    assertEquals("minimum", struct11El.getCollectRestrictions().get(0).getRestriction());
    assertEquals(2, struct11El.getCollectRestrictions().get(0).getAmount());
    List<PortfolioStructure> structs2 = epFrontendManager.loadStructureChildren(pages.get(1));
    assertNotNull(structs2);
    assertEquals(1, structs2.size());
    assertTrue(structs2.get(0) instanceof EPStructureElement);
    EPStructureElement struct21El = (EPStructureElement) structs2.get(0);
    assertEquals("template-structure-2.1", struct21El.getTitle());
    // check root
    assertNotNull(struct21El.getRoot());
    assertEquals(retrievedMap.getKey(), struct21El.getRoot().getKey());
    // check collect restriction
    assertNotNull(struct21El.getCollectRestrictions());
    assertEquals("bc", struct21El.getCollectRestrictions().get(0).getArtefactType());
    assertEquals("maximum", struct21El.getCollectRestrictions().get(0).getRestriction());
    assertEquals(4, struct21El.getCollectRestrictions().get(0).getAmount());
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPPage(org.olat.portfolio.model.structel.EPPage) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 62 with EPStructureElement

use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.

the class EPStructureManagerTest method testCreateAndRetrieveCollectRestrictionElement.

@Test
public void testCreateAndRetrieveCollectRestrictionElement() {
    PortfolioStructure el = epFrontendManager.createAndPersistPortfolioStructureElement(null, "structure-el-3", "structure-element-3");
    epStructureManager.addCollectRestriction(el, "Forum", "minimum", 3);
    epStructureManager.savePortfolioStructure(el);
    dbInstance.commitAndCloseSession();
    PortfolioStructure retrievedEl = epStructureManager.loadPortfolioStructure(el.getOlatResource());
    assertNotNull(retrievedEl);
    assertTrue(retrievedEl instanceof EPStructureElement);
    EPStructureElement retrievedStructEl = (EPStructureElement) retrievedEl;
    assertNotNull(retrievedStructEl.getCollectRestrictions());
    assertEquals("Forum", retrievedStructEl.getCollectRestrictions().get(0).getArtefactType());
    assertEquals("minimum", retrievedStructEl.getCollectRestrictions().get(0).getRestriction());
    assertEquals(3, retrievedStructEl.getCollectRestrictions().get(0).getAmount());
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Test(org.junit.Test)

Example 63 with EPStructureElement

use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.

the class OLATUpgrade_7_1_1 method filterLinkedStructs.

private void filterLinkedStructs(PortfolioStructure filterBase, List<PortfolioStructure> dbChildren) {
    for (Iterator<PortfolioStructure> iterator = dbChildren.iterator(); iterator.hasNext(); ) {
        PortfolioStructure portfolioStructure = iterator.next();
        long filterBaseSourceKey = ((EPStructureElement) filterBase).getStructureElSource();
        long structSourceKey = ((EPStructureElement) portfolioStructure).getStructureElSource();
        if (portfolioStructure.getKey() == filterBase.getKey() || filterBaseSourceKey != structSourceKey) {
            iterator.remove();
        }
    }
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 64 with EPStructureElement

use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.

the class OLATUpgrade_7_1_1 method processStructure.

/**
 * call the needed methods to really do the magic.
 */
private void processStructure(PortfolioStructure structuredMap) {
    List<PortfolioStructure> linkedChildren = ePFMgr.loadStructureChildren(structuredMap);
    for (PortfolioStructure childStruct : linkedChildren) {
        // reload dbchildren in each run, because of filtering
        List<PortfolioStructure> dbChildren;
        if (childStruct instanceof EPPage) {
            dbChildren = loadMapChildrenByInternalFK(childStruct, structuredMap);
        } else {
            dbChildren = loadMapChildrenByInternalFK(childStruct, structuredMap.getRoot());
        }
        // filter the struct that is already linked by a struct->struct link
        // and filter such with other struct-source
        filterLinkedStructs(childStruct, dbChildren);
        log.audit("       found " + dbChildren.size() + " faulty children (of " + childStruct + ") linked by internal fk to be merged and removed afterwards.");
        // merge artefacts to the linked struct
        mergeLinkedArtefactsToFinalStruct(childStruct, dbChildren);
        // collect comments on structures and merge to target
        mergeCommentsToFinalStruct(childStruct, dbChildren);
        // ratings are not merged, see OLAT-6306
        // remove the old elements
        removeWrongElements(dbChildren);
        // fix root-reference on EPStructureElements
        if (!(childStruct instanceof EPPage)) {
            if (childStruct.getRoot().equals(childStruct.getRootMap())) {
                EPStructureElement realParentRoot = (EPStructureElement) ePFMgr.loadStructureParent(childStruct);
                ((EPStructureElement) childStruct).setRoot(realParentRoot);
                ePFMgr.savePortfolioStructure(childStruct);
            }
        }
    }
    // loop children
    DBFactory.getInstance().intermediateCommit();
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) EPPage(org.olat.portfolio.model.structel.EPPage) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 65 with EPStructureElement

use of org.olat.portfolio.model.structel.EPStructureElement in project openolat by klemens.

the class EPStructureDetailsController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    if (formLayout.getFormComponent("struct.title") != null) {
        formLayout.remove("struct.title");
    }
    titleEl = uifactory.addTextElement("struct.title", "struct.title", 512, editStructure.getTitle(), formLayout);
    titleEl.setNotEmptyCheck("map.title.not.empty");
    titleEl.setMandatory(true);
    // choose representation mode (table or minimized artefact-view)
    if (formLayout.getFormComponent("view.mode") != null) {
        formLayout.remove("view.mode");
    }
    final String[] theKeys = new String[] { VIEWMODE_TABLE, VIEWMODE_MINI };
    final String[] theValues = new String[] { translate("view.mode." + VIEWMODE_TABLE), translate("view.mode." + VIEWMODE_MINI) };
    viewRadio = uifactory.addRadiosHorizontal("view.mode", formLayout, theKeys, theValues);
    final String artRepMode = editStructure.getArtefactRepresentationMode();
    if (artRepMode != null) {
        viewRadio.select(artRepMode, true);
    } else {
        viewRadio.select(VIEWMODE_MINI, true);
    }
    if (formLayout.getFormComponent("struct.description") != null) {
        formLayout.remove("struct.description");
    }
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("struct.description", "struct.description", editStructure.getDescription(), -1, -1, formLayout, getWindowControl());
    descriptionEl.setMaxLength(2047);
    descriptionEl.setNotLongerThanCheck(2047, "map.description.too.long");
    // hint for no edit options
    if (formLayout.getFormComponent("noEditInfo") != null) {
        formLayout.remove("noEditInfo");
    }
    noEditInfo = uifactory.addStaticTextElement("noEditInfo", "no.edit.info.label", translate("no.edit.info"), formLayout);
    noEditInfo.setVisible(false);
    if (formLayout.getFormComponent("collect.restriction") != null) {
        formLayout.remove("collect.restriction");
    }
    // show restrictions only for templates and on page/structure-level, as artefacts are not linkable on maps itself
    if (editStructure instanceof EPStructureElement && rootStructure instanceof EPStructuredMapTemplate && editStructure.getRoot() != null) {
        final FormLayoutContainer collectContainer = FormLayoutContainer.createCustomFormLayout("collect.restriction", getTranslator(), velocity_root + "/restrictions.html");
        collectContainer.setRootForm(mainForm);
        collectContainer.setLabel("collect.restriction", null);
        formLayout.add(collectContainer);
        final String[] restrictionKeys = new String[] { "", RestrictionsConstants.MAX, RestrictionsConstants.EQUAL, RestrictionsConstants.MIN };
        final String[] restrictionValues = new String[restrictionKeys.length];
        restrictionValues[0] = "";
        for (int i = 1; i < restrictionKeys.length; i++) {
            restrictionValues[i] = translate("restriction." + restrictionKeys[i]);
        }
        // allow only to use enabled handlers
        final List<EPArtefactHandler<?>> handlers = portfolioModule.getArtefactHandlers();
        final String[] artefactKeys = new String[handlers.size() + 1];
        final String[] artefactValues = new String[artefactKeys.length];
        artefactValues[0] = artefactKeys[0] = "";
        for (int i = 0; i < handlers.size(); i++) {
            final EPArtefactHandler<?> handler = handlers.get(i);
            artefactKeys[i + 1] = handler.getType();
            final String handlerClass = PortfolioFilterController.HANDLER_PREFIX + handler.getClass().getSimpleName() + PortfolioFilterController.HANDLER_TITLE_SUFFIX;
            artefactValues[i + 1] = handler.getHandlerTranslator(getTranslator()).translate(handlerClass);
        }
        if (collectRestrictions.isEmpty()) {
            collectRestrictions.add(new CollectRestriction());
        }
        restrictionElements = new ArrayList<SingleSelection>();
        restrictToArtefactElements = new ArrayList<SingleSelection>();
        amountElements = new ArrayList<TextElement>();
        errorElements = new ArrayList<StaticTextElement>();
        final List<String> counts = new ArrayList<String>();
        for (final CollectRestriction restriction : collectRestrictions) {
            final int count = restrictionElements.size();
            final SingleSelection restrictionElement = uifactory.addDropdownSingleselect("collect.restriction.restriction." + count, "", collectContainer, restrictionKeys, restrictionValues, null);
            restrictionElement.setDomReplacementWrapperRequired(false);
            restrictionElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getRestriction())) {
                restrictionElement.select(restriction.getRestriction(), true);
            }
            restrictionElement.setUserObject(restriction);
            final SingleSelection restrictToArtefactElement = uifactory.addDropdownSingleselect("collect.restriction.artefacts." + count, "", collectContainer, artefactKeys, artefactValues, null);
            restrictToArtefactElement.setDomReplacementWrapperRequired(false);
            restrictToArtefactElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getArtefactType())) {
                restrictToArtefactElement.select(restriction.getArtefactType(), true);
            }
            String amountStr = "";
            if (restriction != null && restriction.getAmount() > 0) {
                amountStr = Integer.toString(restriction.getAmount());
            }
            final TextElement amountElement = uifactory.addTextElement("collect.restriction.amount." + count, null, 2, amountStr, collectContainer);
            amountElement.setDomReplacementWrapperRequired(false);
            amountElement.setDisplaySize(3);
            StaticTextElement errorElement = uifactory.addStaticTextElement("collect.restriction.error." + count, null, "", collectContainer);
            errorElement.setVisible(false);
            restrictionElements.add(restrictionElement);
            restrictToArtefactElements.add(restrictToArtefactElement);
            amountElements.add(amountElement);
            errorElements.add(errorElement);
            final FormLink addLink = uifactory.addFormLink("collect.restriction.add." + count, "collect.restriction.add", "collect.restriction.add", collectContainer, Link.BUTTON_SMALL);
            addLink.setDomReplacementWrapperRequired(false);
            addLink.setUserObject(restriction);
            final FormLink delLink = uifactory.addFormLink("collect.restriction.del." + count, "collect.restriction.delete", "collect.restriction.delete", collectContainer, Link.BUTTON_SMALL);
            delLink.setDomReplacementWrapperRequired(false);
            delLink.setUserObject(restriction);
            counts.add(Integer.toString(count));
        }
        collectContainer.contextPut("counts", counts);
    }
    if (formLayout.getFormComponent("save") != null) {
        formLayout.remove("save");
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) EPArtefactHandler(org.olat.portfolio.EPArtefactHandler) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement)

Aggregations

EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)66 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)18 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)16 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)8 EPPage (org.olat.portfolio.model.structel.EPPage)8 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)6 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)6 Identity (org.olat.core.id.Identity)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2