Search in sources :

Example 41 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class WikiEditController method getWikiRepoReference.

/**
 * @param config the moduleConfig
 * @param strict an assertion exception is thrown if no entry is found when
 *          strict is set to true, otherwise, null is returned
 * @return the repositoryentry or null if not in strict mode and no entry
 *         found
 * @throws AssertException when in strict mode and no entry is found
 */
public static RepositoryEntry getWikiRepoReference(ModuleConfiguration config, boolean strict) {
    if (config == null)
        throw new AssertException("missing config in wiki course node");
    String repoSoftkey = (String) config.get(WikiEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
    if (repoSoftkey == null)
        throw new AssertException("invalid config when being asked for references");
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repoSoftkey, strict);
    // entry can be null only if !strict
    return entry;
}
Also used : AssertException(org.olat.core.logging.AssertException) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 42 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class TaskController method readConfig.

private void readConfig(ModuleConfiguration config) {
    // get task type
    taskType = (String) config.get(TACourseNode.CONF_TASK_TYPE);
    if (!(taskType.equals(TYPE_MANUAL) || taskType.equals(TYPE_AUTO)))
        throw new AssertException("Invalid task type: " + taskType);
    // get folder path
    String sTaskFolder = FolderConfig.getCanonicalRoot() + TACourseNode.getTaskFolderPathRelToFolderRoot(courseEnv, node);
    taskFolder = new File(sTaskFolder);
    if (!taskFolder.exists() && !taskFolder.mkdirs())
        throw new AssertException("Task folder " + sTaskFolder + " does not exist.");
    // get sampling type
    Boolean bSampling = (Boolean) config.get(TACourseNode.CONF_TASK_SAMPLING_WITH_REPLACEMENT);
    samplingWithReplacement = (bSampling == null) ? true : bSampling.booleanValue();
    // get task introductory text
    taskText = (String) config.get(TACourseNode.CONF_TASK_TEXT);
    hasPreview = config.getBooleanEntry(TACourseNode.CONF_TASK_PREVIEW) == null ? false : config.getBooleanEntry(TACourseNode.CONF_TASK_PREVIEW);
    isDeselectable = config.getBooleanEntry(TACourseNode.CONF_TASK_DESELECT) == null ? false : config.getBooleanEntry(TACourseNode.CONF_TASK_DESELECT);
}
Also used : AssertException(org.olat.core.logging.AssertException) File(java.io.File)

Example 43 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class PublishProcess method updateRefs.

/**
 * Update references of a course node in the run. If the course node is new,
 * simply insert new references. Otherwise, delete old references and insert
 * the new references.
 *
 * @param updatedNode The updated course node
 * @param oldNode The old course node corresponding to the new node. May be
 *          null if updatedNode is a new node.
 */
private void updateRefs(CourseNode updatedNode, CourseNode oldNode) {
    if (oldNode != null)
        deleteRefs(oldNode);
    if (updatedNode.needsReferenceToARepositoryEntry()) {
        RepositoryEntry referencedEntry = updatedNode.getReferencedRepositoryEntry();
        if (referencedEntry == null)
            throw new AssertException("Could not fetch referenced entry where an entry is expected.");
        // if there is an entry, add the reference
        addRef(updatedNode, referencedEntry.getOlatResource());
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 44 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class BusinessGroupImportExport method importGroups.

public BusinessGroupEnvironment importGroups(RepositoryEntry re, File fGroupExportXML) {
    if (!fGroupExportXML.exists())
        return new BusinessGroupEnvironment();
    // start with a new connection
    dbInstance.commitAndCloseSession();
    OLATGroupExport groupConfig = null;
    try {
        groupConfig = xstream.fromXML(fGroupExportXML);
    } catch (Exception ce) {
        throw new OLATRuntimeException("Error importing group config.", ce);
    }
    if (groupConfig == null) {
        throw new AssertException("Invalid group export file. Root does not match.");
    }
    BusinessGroupEnvironment env = new BusinessGroupEnvironment();
    Set<BGArea> areaSet = new HashSet<BGArea>();
    // get areas
    int dbCount = 0;
    if (groupConfig.getAreas() != null && groupConfig.getAreas().getGroups() != null) {
        for (Area area : groupConfig.getAreas().getGroups()) {
            String areaName = area.name;
            String areaDesc = (area.description != null && !area.description.isEmpty()) ? area.description.get(0) : "";
            BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, re.getOlatResource());
            if (areaSet.add(newArea)) {
                env.getAreas().add(new BGAreaReference(newArea, area.key, area.name));
            }
            if (dbCount++ % 25 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
    }
    // get groups
    if (groupConfig.getGroups() != null && groupConfig.getGroups().getGroups() != null) {
        for (Group group : groupConfig.getGroups().getGroups()) {
            // create group
            String groupName = group.name;
            String groupDesc = (group.description != null && !group.description.isEmpty()) ? group.description.get(0) : "";
            // get min/max participants
            int groupMinParticipants = group.minParticipants == null ? -1 : group.minParticipants.intValue();
            int groupMaxParticipants = group.maxParticipants == null ? -1 : group.maxParticipants.intValue();
            // waiting list configuration
            boolean waitingList = false;
            if (group.waitingList != null) {
                waitingList = group.waitingList.booleanValue();
            }
            boolean enableAutoCloseRanks = false;
            if (group.autoCloseRanks != null) {
                enableAutoCloseRanks = group.autoCloseRanks.booleanValue();
            }
            // get properties
            boolean showOwners = true;
            boolean showParticipants = true;
            boolean showWaitingList = true;
            if (group.showOwners != null) {
                showOwners = group.showOwners;
            }
            if (group.showParticipants != null) {
                showParticipants = group.showParticipants;
            }
            if (group.showWaitingList != null) {
                showWaitingList = group.showWaitingList;
            }
            BusinessGroup newGroup = businessGroupService.createBusinessGroup(null, groupName, groupDesc, groupMinParticipants, groupMaxParticipants, waitingList, enableAutoCloseRanks, re);
            // map the group
            env.getGroups().add(new BusinessGroupReference(newGroup, group.key, group.name));
            // get tools config
            String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
            CollabTools toolsConfig = group.tools;
            CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(newGroup);
            for (int i = 0; i < availableTools.length; i++) {
                try {
                    Field field = toolsConfig.getClass().getField(availableTools[i]);
                    Boolean val = field.getBoolean(toolsConfig);
                    if (val != null) {
                        ct.setToolEnabled(availableTools[i], val);
                    }
                } catch (NoSuchFieldException e) {
                // hasOpenMeetings compatibility
                } catch (Exception e) {
                    log.error("", e);
                }
            }
            if (group.calendarAccess != null) {
                Long calendarAccess = group.calendarAccess;
                ct.saveCalendarAccess(calendarAccess);
            }
            if (group.folderAccess != null) {
                ct.saveFolderAccess(group.folderAccess);
            }
            if (group.info != null) {
                ct.saveNews(group.info);
            }
            // get memberships
            List<String> memberships = group.areaRelations;
            if (memberships != null && memberships.size() > 0) {
                Set<String> uniqueMemberships = new HashSet<>(memberships);
                for (String membership : uniqueMemberships) {
                    BGArea area = areaManager.findBGArea(membership, re.getOlatResource());
                    if (area != null) {
                        areaManager.addBGToBGArea(newGroup, area);
                    } else {
                        log.error("Area not found", null);
                    }
                }
            }
            boolean download = groupModule.isUserListDownloadDefaultAllowed();
            newGroup = businessGroupService.updateDisplayMembers(newGroup, showOwners, showParticipants, showWaitingList, false, false, false, download);
            if (dbCount++ % 3 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
    }
    dbInstance.commitAndCloseSession();
    return env;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Field(java.lang.reflect.Field) BGArea(org.olat.group.area.BGArea) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) HashSet(java.util.HashSet) BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) BGAreaReference(org.olat.group.model.BGAreaReference) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) BGArea(org.olat.group.area.BGArea) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CollaborationTools(org.olat.collaboration.CollaborationTools)

Example 45 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class I18nTest method testGetPropertyFile.

/**
 * Test methods i18nManager.getLanguageTranslated() i18nManager.getLanguageInEnglish()
 */
@Test
public void testGetPropertyFile() {
    if (i18nModule.isTransToolEnabled()) {
        File baseDir = i18nModule.getPropertyFilesBaseDir(i18nMgr.getLocaleOrDefault("de"), "org.olat.core");
        assertNotNull(baseDir);
        File file = i18nMgr.getPropertiesFile(i18nMgr.getLocaleOrDefault("de"), "org.olat.core", baseDir);
        assertTrue(file.exists());
        // test get metadata file
        file = i18nMgr.getPropertiesFile(null, "org.olat.core", baseDir);
        assertNotNull(file);
        try {
            file = i18nMgr.getPropertiesFile(i18nMgr.getLocaleOrDefault("de"), null, baseDir);
            fail("exception expected for NULL bundle");
        } catch (AssertException e) {
        // do nothing, expected
        }
        // test with file that does not exist
        file = i18nMgr.getPropertiesFile(i18nMgr.getLocaleOrDefault("de"), "hello.world", baseDir);
        assertFalse(file.exists());
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) File(java.io.File) Test(org.junit.Test)

Aggregations

AssertException (org.olat.core.logging.AssertException)364 IOException (java.io.IOException)38 File (java.io.File)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)24 Controller (org.olat.core.gui.control.Controller)22 OLATResourceable (org.olat.core.id.OLATResourceable)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 WindowControl (org.olat.core.gui.control.WindowControl)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 JSONException (org.json.JSONException)18 BusinessGroup (org.olat.group.BusinessGroup)18 JSONObject (org.json.JSONObject)16 UserRequest (org.olat.core.gui.UserRequest)16 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 Date (java.util.Date)14 Properties (java.util.Properties)14 Property (org.olat.properties.Property)14