Search in sources :

Example 16 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureManager method createPortfolioMapTemplate.

/**
 * Create a map template, create an OLAT resource and a repository entry with a security group
 * of type owner to the repository and add the identity has an owner.
 * @param identity
 * @param title
 * @param description
 * @return The structure element
 */
public PortfolioStructureMap createPortfolioMapTemplate(Identity identity, String title, String description) {
    EPStructuredMapTemplate el = new EPStructuredMapTemplate();
    fillStructureElement(el, title, description);
    // create a repository entry with default security settings
    RepositoryEntry re = createRepositoryEntry(identity, el.getOlatResource(), title);
    dbInstance.commit();
    Group ownerGroup = repositoryService.getDefaultGroup(re);
    EPStructureElementToGroupRelation relation = createBaseRelation(el, ownerGroup);
    Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
    relations.add(relation);
    el.setGroups(relations);
    return el;
}
Also used : Group(org.olat.basesecurity.Group) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) RepositoryEntry(org.olat.repository.RepositoryEntry) HashSet(java.util.HashSet)

Example 17 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureManager method loadPortfolioStructuredMap.

public PortfolioStructureMap loadPortfolioStructuredMap(IdentityRef identity, PortfolioStructureMap template, OLATResourceable targetOres, String targetSubPath, String targetBusinessPath) {
    if (template == null)
        throw new NullPointerException();
    if (!(template instanceof EPStructuredMapTemplate))
        throw new AssertException("Only template are acceptable");
    StringBuilder sb = new StringBuilder();
    sb.append("select map from ").append(EPStructuredMap.class.getName()).append(" map").append(" left join fetch map.targetResource as targetResource").append(" inner join map.groups as relGroup on relGroup.defaultGroup=true").append(" inner join relGroup.group as baseGroup").append(" where map.structuredMapSource=:template");
    if (targetOres != null) {
        sb.append(" and targetResource.resourceableId=:resourceId").append(" and targetResource.resourceableTypeName=:resourceType");
    }
    if (targetSubPath != null) {
        sb.append(" and targetResource.subPath=:subPath");
    }
    if (targetBusinessPath != null) {
        sb.append(" and targetResource.businessPath=:businessPath");
    }
    sb.append(" and exists (select membership from bgroupmember as membership ").append("    where baseGroup=membership.group and membership.identity.key=:identityKey and membership.role='").append(GroupRoles.owner.name()).append("'").append(" )");
    TypedQuery<PortfolioStructureMap> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), PortfolioStructureMap.class).setParameter("template", template).setParameter("identityKey", identity.getKey());
    if (targetOres != null) {
        query.setParameter("resourceId", targetOres.getResourceableId());
        query.setParameter("resourceType", targetOres.getResourceableTypeName());
    }
    if (targetSubPath != null) {
        query.setParameter("subPath", targetSubPath);
    }
    if (targetBusinessPath != null) {
        query.setParameter("businessPath", targetBusinessPath);
    }
    List<PortfolioStructureMap> maps = query.getResultList();
    // if not found, it is an empty list
    return maps.isEmpty() ? null : maps.get(0);
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) AssertException(org.olat.core.logging.AssertException) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate)

Example 18 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class EPStructureManager method importPortfolioMapTemplate.

/**
 * Import the structure.
 * @param root
 * @param identity
 * @return
 */
public PortfolioStructureMap importPortfolioMapTemplate(PortfolioStructure root, OLATResource resource) {
    EPStructuredMapTemplate el = new EPStructuredMapTemplate();
    fillStructureElement(el, root.getTitle(), root.getDescription(), resource);
    EPStructuredMapTemplate rootTemp = (EPStructuredMapTemplate) root;
    rootTemp.setStructureElSource(null);
    el.setStyle(((EPStructureElement) root).getStyle());
    importEPStructureElementRecursively((EPStructureElement) root, el);
    // create an empty group
    Group ownerGroup = groupDao.createGroup();
    EPStructureElementToGroupRelation relation = createBaseRelation(el, ownerGroup);
    Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
    relations.add(relation);
    el.setGroups(relations);
    return el;
}
Also used : Group(org.olat.basesecurity.Group) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) EPStructureElementToGroupRelation(org.olat.portfolio.model.structel.EPStructureElementToGroupRelation) HashSet(java.util.HashSet)

Example 19 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

the class PortfolioHandler method readyToDelete.

@Override
public boolean readyToDelete(RepositoryEntry entry, Identity identity, Roles roles, Locale locale, ErrorList errors) {
    EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
    PortfolioStructure map = ePFMgr.loadPortfolioStructure(entry.getOlatResource());
    if (map instanceof EPStructuredMapTemplate) {
        EPStructuredMapTemplate exercise = (EPStructuredMapTemplate) map;
        if (ePFMgr.isTemplateInUse(exercise, null, null, null)) {
            return false;
        }
    }
    ReferenceManager refM = CoreSpringFactory.getImpl(ReferenceManager.class);
    String referencesSummary = refM.getReferencesToSummary(entry.getOlatResource(), locale);
    if (referencesSummary != null) {
        Translator translator = Util.createPackageTranslator(RepositoryManager.class, locale);
        errors.setError(translator.translate("details.delete.error.references", new String[] { referencesSummary, entry.getDisplayname() }));
        return false;
    }
    return true;
}
Also used : EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) Translator(org.olat.core.gui.translator.Translator) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 20 with EPStructuredMapTemplate

use of org.olat.portfolio.model.structel.EPStructuredMapTemplate in project OpenOLAT by OpenOLAT.

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

EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)28 RepositoryEntry (org.olat.repository.RepositoryEntry)10 ArrayList (java.util.ArrayList)8 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)8 HashSet (java.util.HashSet)6 Group (org.olat.basesecurity.Group)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)6 EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)6 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)4 OLATResource (org.olat.resource.OLATResource)4 Date (java.util.Date)2 Document (org.apache.lucene.document.Document)2 Test (org.junit.Test)2 CommentAndRatingService (org.olat.core.commons.services.commentAndRating.CommentAndRatingService)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2