Search in sources :

Example 96 with AssertException

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

the class BaseSecurityManager method findIdentityByNameCaseInsensitive.

@Override
public Identity findIdentityByNameCaseInsensitive(String identityName) {
    if (identityName == null)
        throw new AssertException("findIdentitybyName: name was null");
    StringBuilder sb = new StringBuilder();
    sb.append("select ident from ").append(IdentityImpl.class.getName()).append(" as ident where lower(ident.name)=:username");
    List<Identity> identities = DBFactory.getInstance().getCurrentEntityManager().createQuery(sb.toString(), Identity.class).setParameter("username", identityName.toLowerCase()).getResultList();
    return identities == null || identities.isEmpty() ? null : identities.get(0);
}
Also used : AssertException(org.olat.core.logging.AssertException) Identity(org.olat.core.id.Identity)

Example 97 with AssertException

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

the class BaseSecurityManager method findSecurityGroupByName.

/**
 * @see org.olat.basesecurity.Manager#findSecurityGroupByName(java.lang.String)
 */
@Override
public SecurityGroup findSecurityGroupByName(String securityGroupName) {
    StringBuilder sb = new StringBuilder();
    sb.append("select sgi from ").append(NamedGroupImpl.class.getName()).append(" as ngroup ").append(" inner join ngroup.securityGroup sgi").append(" where ngroup.groupName=:groupName");
    List<SecurityGroup> group = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), SecurityGroup.class).setParameter("groupName", securityGroupName).setHint("org.hibernate.cacheable", Boolean.TRUE).getResultList();
    int size = group.size();
    if (size == 0)
        return null;
    if (size != 1)
        throw new AssertException("non unique name in namedgroup: " + securityGroupName);
    SecurityGroup sg = group.get(0);
    return sg;
}
Also used : AssertException(org.olat.core.logging.AssertException)

Example 98 with AssertException

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

the class CollaborationTools method deleteTools.

/**
 * delete all CollaborationTools stuff from the database, which is related to
 * the calling OLATResourceable.
 */
public void deleteTools(BusinessGroup businessGroupTodelete) {
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    /*
		 * delete the forum, if existing
		 */
    ForumManager fom = ForumManager.getInstance();
    Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    if (forumKeyProperty != null) {
        // if there was a forum, delete it
        Long forumKey = forumKeyProperty.getLongValue();
        if (forumKey == null)
            throw new AssertException("property had no longValue, prop:" + forumKeyProperty);
        fom.deleteForum(forumKey);
    }
    /*
		 * delete the folder, if existing
		 */
    OlatRootFolderImpl vfsContainer = new OlatRootFolderImpl(getFolderRelPath(), null);
    File fFolderRoot = vfsContainer.getBasefile();
    if (fFolderRoot.exists()) {
        FileUtils.deleteDirsAndFiles(fFolderRoot, true, true);
    }
    /*
		 * delete the wiki if existing
		 */
    VFSContainer rootContainer = WikiManager.getInstance().getWikiRootContainer(ores);
    if (rootContainer != null)
        rootContainer.delete();
    /*
		 * Delete calendar if exists
		 */
    if (businessGroupTodelete != null) {
        CoreSpringFactory.getImpl(ImportToCalendarManager.class).deleteGroupImportedCalendars(businessGroupTodelete);
        CoreSpringFactory.getImpl(CalendarManager.class).deleteGroupCalendar(businessGroupTodelete);
    }
    /*
		 * delete chatRoom
		 */
    // no cleanup needed, automatically done when last user exits the room
    /*
		 * delete all Properties defining enabled/disabled CollabTool XY and the
		 * news content
		 */
    npm.deleteProperties(null, null, PROP_CAT_BG_COLLABTOOLS, null);
    /*
		 * Delete OpenMeetings room
		 */
    OpenMeetingsModule omModule = CoreSpringFactory.getImpl(OpenMeetingsModule.class);
    if (omModule.isEnabled()) {
        OpenMeetingsManager omManager = CoreSpringFactory.getImpl(OpenMeetingsManager.class);
        try {
            omManager.deleteAll(ores, null, null);
        } catch (OpenMeetingsException e) {
            log.error("A room could not be deleted for group: " + ores, e);
        }
    }
    /*
		 * and last but not least the cache is reseted
		 */
    cacheToolStates.clear();
    this.dirty = true;
}
Also used : AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OpenMeetingsModule(org.olat.modules.openmeetings.OpenMeetingsModule) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ForumManager(org.olat.modules.fo.manager.ForumManager) OpenMeetingsException(org.olat.modules.openmeetings.manager.OpenMeetingsException) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) File(java.io.File) OpenMeetingsManager(org.olat.modules.openmeetings.manager.OpenMeetingsManager)

Example 99 with AssertException

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

the class HTMLEditorController method initEditorForm.

private void initEditorForm(VFSContainer bContainer, String relFilePath, CustomLinkTreeModel linkTreeModel, String mPath, boolean editorCheck, boolean versions, boolean withButtons) {
    this.baseContainer = bContainer;
    this.fileRelPath = relFilePath;
    this.mediaPath = mPath;
    this.versionsEnabled = versions;
    this.buttonsEnabled = withButtons;
    this.customLinkTreeModel = linkTreeModel;
    this.editorCheckEnabled = editorCheck;
    // make sure the filename doesn't start with a slash
    this.fileName = ((relFilePath.charAt(0) == '/') ? relFilePath.substring(1) : relFilePath);
    this.fileLeaf = (VFSLeaf) bContainer.resolve(fileName);
    if (fileLeaf == null)
        throw new AssertException("file::" + getFileDebuggingPath(bContainer, relFilePath) + " does not exist!");
    long size = fileLeaf.getSize();
    if (size > FolderConfig.getMaxEditSizeLimit()) {
        // limit to reasonable size, see OO-57
        fileToLargeError = translate("plaintext.error.tolarge", new String[] { (size / 1000) + "", (FolderConfig.getMaxEditSizeLimit() / 1000) + "" });
        this.body = "";
        this.editable = false;
        return;
    }
    // check if someone else is already editing the file
    if (fileLeaf instanceof LocalFileImpl) {
        // Cast to LocalFile necessary because the VFSItem is missing some
        // ID mechanism that identifies an item within the system
        OLATResourceable lockResourceable = createLockResourceable(fileLeaf);
        // OLAT-5066: the use of "fileName" gives users the (false) impression that the file they wish to access
        // is already locked by someone else. Since the lock token must be smaller than 50 characters we us an
        // MD5 hash of the absolute file path which will always be 32 characters long and virtually unique.
        String lockToken = createLockToken(bContainer, relFilePath);
        lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockResourceable, getIdentity(), lockToken);
        VelocityContainer vc = (VelocityContainer) flc.getComponent();
        if (!lock.isSuccess()) {
            vc.contextPut("locked", Boolean.TRUE);
            String fullname = UserManager.getInstance().getUserDisplayName(lock.getOwner());
            vc.contextPut("lockOwner", fullname);
            editable = false;
            return;
        } else {
            vc.contextPut("locked", Boolean.FALSE);
        }
    }
    // Parse the content of the page
    this.body = parsePage(fileLeaf);
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 100 with AssertException

use of org.olat.core.logging.AssertException in project openolat by klemens.

the class NotificationsManagerImpl method getPublisher.

/**
 * @param subsContext
 * @return the publisher belonging to the given context or null
 */
@Override
public Publisher getPublisher(SubscriptionContext subsContext) {
    StringBuilder q = new StringBuilder();
    q.append("select pub from notipublisher pub ").append(" where pub.resName=:resName and pub.resId = :resId");
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        q.append(" and pub.subidentifier=:subidentifier");
    } else {
        q.append(" and (pub.subidentifier='' or pub.subidentifier is null)");
    }
    TypedQuery<Publisher> query = dbInstance.getCurrentEntityManager().createQuery(q.toString(), Publisher.class).setParameter("resName", subsContext.getResName()).setParameter("resId", subsContext.getResId());
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        query.setParameter("subidentifier", subsContext.getSubidentifier());
    }
    List<Publisher> res = query.getResultList();
    if (res.isEmpty())
        return null;
    if (res.size() != 1)
        throw new AssertException("only one subscriber per person and publisher!!");
    return res.get(0);
}
Also used : AssertException(org.olat.core.logging.AssertException) Publisher(org.olat.core.commons.services.notifications.Publisher)

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