Search in sources :

Example 6 with RepositoryEntryUpgrade

use of org.olat.upgrade.model.RepositoryEntryUpgrade in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method upgradeRepositoryEntries.

private boolean upgradeRepositoryEntries(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_REPOENTRIES)) {
        int counter = 0;
        List<RepositoryEntryUpgrade> repoEntries;
        do {
            repoEntries = findRepositoryEntries(counter, BATCH_SIZE);
            for (RepositoryEntryUpgrade repoEntry : repoEntries) {
                processRepositoryEntry(repoEntry);
            }
            counter += repoEntries.size();
            log.audit("Repository entries processed: " + repoEntries.size() + ", total processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (repoEntries.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_REPOENTRIES, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade)

Example 7 with RepositoryEntryUpgrade

use of org.olat.upgrade.model.RepositoryEntryUpgrade in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method processRelationToRepo.

private void processRelationToRepo(BusinessGroupUpgrade businessGroup) {
    try {
        List<BGResourceRelation> relationsToRepo = findRelations(businessGroup);
        if (relationsToRepo.size() > 0) {
            Group refGroup = businessGroup.getBaseGroup();
            for (BGResourceRelation relationToRepo : relationsToRepo) {
                RepositoryEntryUpgrade entry = lookupRepositoryEntry(relationToRepo.getResource());
                if (entry == null) {
                    continue;
                }
                boolean found = false;
                Set<RepositoryEntryUpgradeToGroupRelation> groupRelations = entry.getGroups();
                for (RepositoryEntryUpgradeToGroupRelation groupRelation : groupRelations) {
                    if (groupRelation.getGroup().equals(refGroup)) {
                        found = true;
                    }
                }
                if (!found) {
                    create(entry, refGroup, false);
                }
            }
        }
        dbInstance.commit();
    } catch (Exception e) {
        log.error("", e);
        throw e;
    }
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) RepositoryEntryUpgradeToGroupRelation(org.olat.upgrade.model.RepositoryEntryUpgradeToGroupRelation) BGResourceRelation(org.olat.upgrade.model.BGResourceRelation)

Example 8 with RepositoryEntryUpgrade

use of org.olat.upgrade.model.RepositoryEntryUpgrade in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_0_0 method processMap.

private void processMap(EPMapUpgrade map) {
    if (hasGroupsRelations(map)) {
        return;
    }
    Set<EPMapUpgradeToGroupRelation> relations = new HashSet<>();
    SecurityGroup ownerGroup = map.getOwnerGroup();
    if (ownerGroup != null) {
        // create default group
        RepositoryEntryUpgrade re = findMapRepoEntry(ownerGroup);
        if (re != null) {
            Group reGroup = repositoryEntryToGroupDAO.getDefaultGroup(re);
            if (reGroup != null) {
                relations.add(createDefaultGroup(map, reGroup));
            }
        }
        if (relations.isEmpty()) {
            Group group = groupDao.createGroup();
            relations.add(createDefaultGroup(map, group));
            processSecurityGroup(group, GroupRoles.owner.name(), ownerGroup);
        }
        // create policy -> relation
        List<Policy> policies = securityManager.getPoliciesOfResource(map.getOlatResource(), null);
        for (Policy policy : policies) {
            if (policy.getPermission().contains(Constants.PERMISSION_READ)) {
                EPMapUpgradeToGroupRelation policyRelation = processMapPolicy(policy, map);
                if (policyRelation != null) {
                    relations.add(policyRelation);
                }
            }
        }
        for (EPMapUpgradeToGroupRelation relation : relations) {
            dbInstance.getCurrentEntityManager().persist(relation);
        }
    }
}
Also used : Policy(org.olat.basesecurity.Policy) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) SecurityGroup(org.olat.basesecurity.SecurityGroup) HashSet(java.util.HashSet)

Example 9 with RepositoryEntryUpgrade

use of org.olat.upgrade.model.RepositoryEntryUpgrade in project openolat by klemens.

the class OLATUpgrade_10_0_0 method processMap.

private void processMap(EPMapUpgrade map) {
    if (hasGroupsRelations(map)) {
        return;
    }
    Set<EPMapUpgradeToGroupRelation> relations = new HashSet<>();
    SecurityGroup ownerGroup = map.getOwnerGroup();
    if (ownerGroup != null) {
        // create default group
        RepositoryEntryUpgrade re = findMapRepoEntry(ownerGroup);
        if (re != null) {
            Group reGroup = repositoryEntryToGroupDAO.getDefaultGroup(re);
            if (reGroup != null) {
                relations.add(createDefaultGroup(map, reGroup));
            }
        }
        if (relations.isEmpty()) {
            Group group = groupDao.createGroup();
            relations.add(createDefaultGroup(map, group));
            processSecurityGroup(group, GroupRoles.owner.name(), ownerGroup);
        }
        // create policy -> relation
        List<Policy> policies = securityManager.getPoliciesOfResource(map.getOlatResource(), null);
        for (Policy policy : policies) {
            if (policy.getPermission().contains(Constants.PERMISSION_READ)) {
                EPMapUpgradeToGroupRelation policyRelation = processMapPolicy(policy, map);
                if (policyRelation != null) {
                    relations.add(policyRelation);
                }
            }
        }
        for (EPMapUpgradeToGroupRelation relation : relations) {
            dbInstance.getCurrentEntityManager().persist(relation);
        }
    }
}
Also used : Policy(org.olat.basesecurity.Policy) EPMapPolicy(org.olat.portfolio.manager.EPMapPolicy) RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) EPMapUpgradeToGroupRelation(org.olat.upgrade.model.EPMapUpgradeToGroupRelation) SecurityGroup(org.olat.basesecurity.SecurityGroup) HashSet(java.util.HashSet)

Example 10 with RepositoryEntryUpgrade

use of org.olat.upgrade.model.RepositoryEntryUpgrade in project openolat by klemens.

the class OLATUpgrade_10_0_0 method processRelationToRepo.

private void processRelationToRepo(BusinessGroupUpgrade businessGroup) {
    try {
        List<BGResourceRelation> relationsToRepo = findRelations(businessGroup);
        if (relationsToRepo.size() > 0) {
            Group refGroup = businessGroup.getBaseGroup();
            for (BGResourceRelation relationToRepo : relationsToRepo) {
                RepositoryEntryUpgrade entry = lookupRepositoryEntry(relationToRepo.getResource());
                if (entry == null) {
                    continue;
                }
                boolean found = false;
                Set<RepositoryEntryUpgradeToGroupRelation> groupRelations = entry.getGroups();
                for (RepositoryEntryUpgradeToGroupRelation groupRelation : groupRelations) {
                    if (groupRelation.getGroup().equals(refGroup)) {
                        found = true;
                    }
                }
                if (!found) {
                    create(entry, refGroup, false);
                }
            }
        }
        dbInstance.commit();
    } catch (Exception e) {
        log.error("", e);
        throw e;
    }
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) RepositoryEntryUpgradeToGroupRelation(org.olat.upgrade.model.RepositoryEntryUpgradeToGroupRelation) BGResourceRelation(org.olat.upgrade.model.BGResourceRelation)

Aggregations

RepositoryEntryUpgrade (org.olat.upgrade.model.RepositoryEntryUpgrade)10 Group (org.olat.basesecurity.Group)4 SecurityGroup (org.olat.basesecurity.SecurityGroup)4 HashSet (java.util.HashSet)2 Policy (org.olat.basesecurity.Policy)2 DBQuery (org.olat.core.commons.persistence.DBQuery)2 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)2 BGResourceRelation (org.olat.upgrade.model.BGResourceRelation)2 EPMapUpgradeToGroupRelation (org.olat.upgrade.model.EPMapUpgradeToGroupRelation)2 RepositoryEntryUpgradeToGroupRelation (org.olat.upgrade.model.RepositoryEntryUpgradeToGroupRelation)2