Search in sources :

Example 41 with PortfolioStructure

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

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 42 with PortfolioStructure

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

the class OLATUpgrade_7_1_1 method fixInvalidMapReferences.

private void fixInvalidMapReferences(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CHECK_AND_FIX_TEMPLATEMAPS)) {
        log.audit("+---------------------------------------------------------------------------------------+");
        log.audit("+... check templates and collect lost sub-structures to actualy bound pages/structs  ...+");
        log.audit("+---------------------------------------------------------------------------------------+");
        ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager");
        int amount = 10;
        int count = countPortfolioTemplates();
        log.audit("found a total of " + count + " portfolio templates. check stepwise with stepsize: " + amount);
        for (int start = 0; start < count; start = start + amount) {
            List<PortfolioStructure> templates = ePFMgr.getStructureElements(start, amount, ElementType.TEMPLATE_MAP);
            log.audit("start at " + start + " . Will check (next) " + templates.size() + " portfolio task for irregularities.");
            templates = getInvalidTemplates(templates);
            log.audit("#1: found " + templates.size() + " templates that look invalid and might have produced bad portfolio-tasks!");
            for (PortfolioStructure templateStruct : templates) {
                log.audit(" #2: handling Structured Maps (maps collected from a portfolio task) for template " + templateStruct.getKey() + " " + templateStruct.getTitle());
                // get corresponding portfolio-tasks taken from templates
                List<PortfolioStructure> structMaps = getStructuredMapsLinkedToTemplate(templateStruct);
                log.audit("  this task has been taken " + structMaps.size() + " times.");
                for (PortfolioStructure structuredMap : structMaps) {
                    log.audit("  #3: now work on StructuredMap: " + structuredMap);
                    processStructuredMapDeeply(structuredMap);
                }
                // loop struct-maps
                // fix template with children
                fixTemplateEntry(templateStruct);
                DBFactory.getInstance().intermediateCommit();
            }
        // loop templates
        }
        // steps
        DBFactory.getInstance().intermediateCommit();
    }
    uhd.setBooleanDataValue(TASK_CHECK_AND_FIX_TEMPLATEMAPS, true);
    upgradeManager.setUpgradesHistory(uhd, VERSION);
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 43 with PortfolioStructure

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

the class OLATUpgrade_7_1_1 method getInvalidTemplates.

private List<PortfolioStructure> getInvalidTemplates(List<PortfolioStructure> templates) {
    List<PortfolioStructure> temps = new ArrayList<PortfolioStructure>();
    for (PortfolioStructure portfolioStructure : templates) {
        recurseIntoTemplateAndCheck(temps, new ArrayList<PortfolioStructure>(), portfolioStructure);
    }
    // get unique root-templates
    HashSet<PortfolioStructure> h = new HashSet<PortfolioStructure>(temps);
    temps.clear();
    temps.addAll(h);
    return temps;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 44 with PortfolioStructure

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

the class OLATUpgrade_7_1_1 method mergeLinkedArtefactsToFinalStruct.

private void mergeLinkedArtefactsToFinalStruct(PortfolioStructure finalStruct, List<PortfolioStructure> wrongStructs) {
    if (wrongStructs == null || wrongStructs.isEmpty())
        return;
    // temporarily remove the collectrestriction, will be added by next sync.
    // TODO: somehow user must be warned, that map may contain too much artefacts on one node
    finalStruct.getCollectRestrictions().clear();
    ePFMgr.savePortfolioStructure(finalStruct);
    int artefactCount = 0;
    for (PortfolioStructure portfolioStructure : wrongStructs) {
        portfolioStructure = ePFMgr.loadPortfolioStructureByKey(portfolioStructure.getKey());
        List<AbstractArtefact> artefacts = ePFMgr.getArtefacts(portfolioStructure);
        for (AbstractArtefact abstractArtefact : artefacts) {
            if (!ePFMgr.isArtefactInStructure(abstractArtefact, finalStruct)) {
                artefactCount++;
                ePFMgr.moveArtefactFromStructToStruct(abstractArtefact, portfolioStructure, finalStruct);
            } else {
                log.audit("An Artefact " + abstractArtefact + " has already been added to new target, therefore will be removed from wrong structure.");
                // TODO: maybe we should save the reflexion on the link artefact -> structure!
                ePFMgr.removeArtefactFromStructure(abstractArtefact, portfolioStructure);
            }
        }
    }
    log.audit("       merged " + artefactCount + " artefacts to new destinations.");
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact)

Example 45 with PortfolioStructure

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

the class OLATUpgrade_7_1_1 method mergeCommentsToFinalStruct.

private void mergeCommentsToFinalStruct(PortfolioStructure finalStruct, List<PortfolioStructure> wrongStructs) {
    if (wrongStructs == null || wrongStructs.isEmpty())
        return;
    List<UserComment> collectedComments = new ArrayList<UserComment>();
    // collect all comments out there
    for (PortfolioStructure portfolioStructure : wrongStructs) {
        // no comments on StructureElements!
        if (!(portfolioStructure instanceof EPPage))
            return;
        List<UserComment> oldComments = commentAndRatingService.getComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
        collectedComments.addAll(oldComments);
        commentAndRatingService.deleteAllComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
    }
    log.audit("       found " + collectedComments.size() + " comments for this structure, will be merged to new destination.");
    if (collectedComments.size() == 0)
        return;
    Identity ident = collectedComments.get(0).getCreator();
    UserComment topComment = commentAndRatingService.createComment(ident, finalStruct.getRootMap(), finalStruct.getKey().toString(), "The following comments were restored from a migration task to rescue lost data.");
    // attach all to this info-comment
    for (UserComment userComment : collectedComments) {
        UserComment attachedComment = commentAndRatingService.replyTo(topComment, userComment.getCreator(), userComment.getComment());
        // set original date
        attachedComment.setCreationDate(userComment.getCreationDate());
        commentAndRatingService.updateComment(attachedComment, attachedComment.getComment());
    }
}
Also used : EPPage(org.olat.portfolio.model.structel.EPPage) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) ArrayList(java.util.ArrayList) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Identity(org.olat.core.id.Identity)

Aggregations

PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)236 Test (org.junit.Test)90 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)70 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)54 ArrayList (java.util.ArrayList)40 OLATResource (org.olat.resource.OLATResource)30 Identity (org.olat.core.id.Identity)26 RepositoryEntry (org.olat.repository.RepositoryEntry)24 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)22 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)16 EPPage (org.olat.portfolio.model.structel.EPPage)16 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)12 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)12 DBQuery (org.olat.core.commons.persistence.DBQuery)10 EPFrontendManager (org.olat.portfolio.manager.EPFrontendManager)10 Date (java.util.Date)8 Document (org.apache.lucene.document.Document)8 Link (org.olat.core.gui.components.link.Link)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)8