Search in sources :

Example 51 with AssertException

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

the class AdobeConnectProvider method getScoIdFor.

private String getScoIdFor(String roomId) {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("action", "sco-search-by-field");
    parameters.put("query", PREFIX + roomId);
    parameters.put("filter-type", "meeting");
    Document responseDoc = getResponseDocument(sendRequest(parameters));
    if (!evaluateOk(responseDoc))
        return null;
    Object result = evaluate(responseDoc, "//sco/url-path[text()='/" + PREFIX + roomId + "/']", XPathConstants.NODESET);
    if (result == null)
        return null;
    NodeList nodes = (NodeList) result;
    if (nodes.getLength() == 1) {
        String scoId = evaluate(responseDoc, "//sco[1]/attribute::sco-id");
        return scoId;
    } else if (nodes.getLength() > 1)
        throw new AssertException("More than one Adobe Connect room found for one course node!");
    else
        return null;
}
Also used : AssertException(org.olat.core.logging.AssertException) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 52 with AssertException

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

the class AdobeConnectProvider method existsClassroom.

@Override
public boolean existsClassroom(String roomId, VCConfiguration config) {
    if (!loginAdmin())
        return false;
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("action", "sco-search-by-field");
    parameters.put("query", PREFIX + roomId);
    parameters.put("filter-type", "meeting");
    Document responseDoc = getResponseDocument(sendRequest(parameters));
    if (!evaluateOk(responseDoc))
        return false;
    Object result = evaluate(responseDoc, "//sco/url-path[text()='/" + PREFIX + roomId + "/']", XPathConstants.NODESET);
    logout();
    if (result == null)
        return false;
    NodeList nodes = (NodeList) result;
    if (nodes.getLength() == 1)
        return true;
    else if (nodes.getLength() > 1)
        throw new AssertException("More than one Adobe Connect room found for one course node!");
    else
        return false;
}
Also used : AssertException(org.olat.core.logging.AssertException) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 53 with AssertException

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

the class CmdUnzip method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wContr, Translator trans) {
    this.translator = trans;
    FileSelection selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    if (!(currentContainer.canWrite() == VFSConstants.YES))
        throw new AssertException("Cannot unzip to folder. Writing denied.");
    // check if command is executed on a file containing invalid filenames or paths - checks if the resulting folder has a valid name
    if (selection.getInvalidFileNames().size() > 0) {
        status = FolderCommandStatus.STATUS_INVALID_NAME;
        return null;
    }
    List<String> lockedFiles = new ArrayList<String>();
    for (String sItem : selection.getFiles()) {
        VFSItem vfsItem = currentContainer.resolve(sItem);
        if (vfsItem instanceof VFSLeaf) {
            try {
                Roles roles = ureq.getUserSession().getRoles();
                lockedFiles.addAll(checkLockedFiles((VFSLeaf) vfsItem, currentContainer, ureq.getIdentity(), roles));
            } catch (Exception e) {
                String name = vfsItem == null ? "NULL" : vfsItem.getName();
                getWindowControl().setError(translator.translate("FileUnzipFailed", new String[] { name }));
            }
        }
    }
    if (!lockedFiles.isEmpty()) {
        String msg = FolderCommandHelper.renderLockedMessageAsHtml(trans, lockedFiles);
        List<String> buttonLabels = Collections.singletonList(trans.translate("ok"));
        lockedFiledCtr = activateGenericDialog(ureq, trans.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
        return null;
    }
    VFSItem currentVfsItem = null;
    try {
        boolean fileNotExist = false;
        for (String sItem : selection.getFiles()) {
            currentVfsItem = currentContainer.resolve(sItem);
            if (currentVfsItem != null && (currentVfsItem instanceof VFSLeaf)) {
                if (!doUnzip((VFSLeaf) currentVfsItem, currentContainer, ureq, wContr)) {
                    status = FolderCommandStatus.STATUS_FAILED;
                    break;
                }
            } else {
                fileNotExist = true;
                break;
            }
        }
        if (fileNotExist) {
            status = FolderCommandStatus.STATUS_FAILED;
            getWindowControl().setError(translator.translate("FileDoesNotExist"));
        }
        VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(folderComponent.getRootContainer());
        if (inheritingCont != null) {
            VFSSecurityCallback secCallback = inheritingCont.getLocalSecurityCallback();
            if (secCallback != null) {
                SubscriptionContext subsContext = secCallback.getSubscriptionContext();
                if (subsContext != null) {
                    NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        logError("Corrupted ZIP", e);
        String name = currentVfsItem == null ? "NULL" : currentVfsItem.getName();
        getWindowControl().setError(translator.translate("FileUnzipFailed", new String[] { name }));
    }
    return null;
}
Also used : FileSelection(org.olat.core.commons.modules.bc.FileSelection) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) Roles(org.olat.core.id.Roles) AssertException(org.olat.core.logging.AssertException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Example 54 with AssertException

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

the class DBImpl method loadObject.

/**
 * loads an object if needed. this makes sense if you have an object which had
 * been generated in a previous hibernate session AND you need to access a Set
 * or a attribute which was defined as a proxy.
 *
 * @param persistable the object which needs to be reloaded
 * @param forceReloadFromDB if true, force a reload from the db (e.g. to catch
 *          up to an object commited by another thread which is still in this
 *          thread's session cache
 * @return the loaded Object
 */
@Override
public Persistable loadObject(Persistable persistable, boolean forceReloadFromDB) {
    if (persistable == null)
        throw new AssertException("persistable must not be null");
    EntityManager em = getCurrentEntityManager();
    Class<? extends Persistable> theClass = persistable.getClass();
    if (forceReloadFromDB) {
        if (contains(persistable)) {
            // case b - then we can use evict and load
            evict(em, persistable, getData());
            return em.find(theClass, persistable.getKey());
        } else {
            // case a or c - unfortunatelly we can't distinguish these two cases
            // and session.refresh(Object) doesn't work.
            // the only scenario that works is load/evict/load
            Persistable attachedObj = em.find(theClass, persistable.getKey());
            evict(em, attachedObj, getData());
            return em.find(theClass, persistable.getKey());
        }
    } else if (!contains(persistable)) {
        // therefore the following loadObject can either return it from the cache or load it from the DB
        return em.find(theClass, persistable.getKey());
    } else {
        // nothing to do, return the same object
        return persistable;
    }
}
Also used : EntityManager(javax.persistence.EntityManager) AssertException(org.olat.core.logging.AssertException) Persistable(org.olat.core.id.Persistable)

Example 55 with AssertException

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

the class NotificationsManagerImpl method getSubscriber.

/**
 * @param identity
 * @param publisher
 * @return a Subscriber object belonging to the identity and listening to the
 *         given publisher
 */
@Override
public Subscriber getSubscriber(Identity identity, Publisher publisher) {
    List<Subscriber> res = dbInstance.getCurrentEntityManager().createNamedQuery("subscribersByPublisherAndIdentity", Subscriber.class).setParameter("publisherKey", publisher.getKey()).setParameter("identityKey", identity.getKey()).getResultList();
    if (res.size() == 0)
        return null;
    if (res.size() != 1)
        throw new AssertException("only one subscriber per person and publisher!!");
    Subscriber s = res.get(0);
    return s;
}
Also used : AssertException(org.olat.core.logging.AssertException) Subscriber(org.olat.core.commons.services.notifications.Subscriber)

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