Search in sources :

Example 6 with AssertException

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

the class WikiManager method saveWikiPage.

/**
 * persists a wiki page on the filesystem. It moves the recent page and the
 * metadata to the versions folder with the version on the tail and saves new
 * page with metadata to the wiki folder. Does not need to be synchronized as
 * editing is locked on page level by the
 *
 * @see WikiMainController
 * @param ores
 * @param page
 */
public void saveWikiPage(OLATResourceable ores, WikiPage page, boolean incrementVersion, Wiki wiki) {
    // cluster_OK by guido
    VFSContainer versionsContainer = getWikiContainer(ores, VERSION_FOLDER_NAME);
    VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
    // rename existing content file to version x and copy it to the version
    // container
    VFSItem item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
    if (item != null && incrementVersion) {
        if (page.getVersion() > 0) {
            versionsContainer.copyFrom(item);
            VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_FILE_SUFFIX);
            String fileName = page.getPageId() + "." + WIKI_FILE_SUFFIX + "-" + page.getVersion();
            copiedItem.rename(fileName);
        }
        item.delete();
    }
    // rename existing meta file to version x and copy it to the version
    // container
    item = wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (item != null && incrementVersion) {
        // TODO renaming and coping does not work. Bug?? felix fragen
        if (page.getVersion() > 0) {
            versionsContainer.copyFrom(item);
            VFSItem copiedItem = versionsContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
            String fileName = page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX + "-" + page.getVersion();
            copiedItem.rename(fileName);
        }
        item.delete();
    }
    // store recent content file
    VFSLeaf leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_FILE_SUFFIX);
    if (leaf == null)
        throw new AssertException("Tried to save wiki page with id (" + page.getPageId() + ") and Olatresource: " + ores.getResourceableId() + " but page already existed!");
    FileUtils.save(leaf.getOutputStream(false), page.getContent(), "utf-8");
    // store recent properties file
    leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (leaf == null)
        throw new AssertException("could not create file for wiki page " + page.getPageId() + ", ores: " + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", wikicontainer:" + wikiContentContainer);
    if (incrementVersion)
        page.incrementVersion();
    // update modification time
    if (!page.getContent().equals(""))
        page.setModificationTime(System.currentTimeMillis());
    Properties p = getPageProperties(page);
    try {
        OutputStream os = leaf.getOutputStream(false);
        p.store(os, "wiki page meta properties");
        os.close();
    // if (incrementVersion) page.incrementVersion();
    } catch (IOException e) {
        throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
    }
    // reset view count of the page
    page.setViewCount(0);
    // update cache to inform all nodes about the change
    if (wikiCache != null) {
        wikiCache.update(OresHelper.createStringRepresenting(ores), wiki);
    }
    if (ThreadLocalUserActivityLogger.getLoggedIdentity() != null) {
        // do logging only for real user
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 7 with AssertException

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

the class WikiToZipUtils method createIndexPageForExport.

/**
 * creates an html page with the mappings between the pagename and the Base64
 * encoded filename.
 *
 * @param vfsLeaves
 * @return
 */
private static String createIndexPageForExport(List<VFSItem> vfsLeaves) {
    boolean hasProperties = false;
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>");
    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
    sb.append("</head><body><ul>");
    for (Iterator<VFSItem> iter = vfsLeaves.iterator(); iter.hasNext(); ) {
        VFSLeaf element = (VFSLeaf) iter.next();
        // destination.copyFrom(element);
        if (element.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
            hasProperties = true;
            Properties p = new Properties();
            try {
                p.load(element.getInputStream());
            } catch (IOException e) {
                throw new AssertException("Wiki propterties couldn't be read! ", e);
            }
            sb.append("<li>");
            sb.append(p.getProperty(WikiManager.PAGENAME));
            sb.append(" ----> ");
            sb.append(element.getName().substring(0, element.getName().indexOf(".")));
            sb.append("</li>");
        }
    }
    sb.append("</ul></body></html>");
    if (!hasProperties)
        return null;
    return sb.toString();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 8 with AssertException

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

the class Wiki method getRecentChanges.

protected String getRecentChanges(Locale locale) {
    if (locale == null)
        throw new AssertException("param was null which is not allowed");
    final int MAX_RESULTS = 5;
    List<WikiPage> pages = new ArrayList<>(wikiPages.values());
    Collections.sort(pages, WikiPageSort.MODTIME_ORDER);
    StringBuilder sb = new StringBuilder(512);
    int counter = 0;
    Formatter f = Formatter.getInstance(locale);
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    for (Iterator<WikiPage> iter = pages.iterator(); iter.hasNext(); ) {
        if (counter > MAX_RESULTS)
            break;
        WikiPage page = iter.next();
        if (!page.getPageName().startsWith("O_") && !page.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) {
            sb.append("* [[");
            sb.append(page.getPageName());
            sb.append("]] ");
            sb.append(f.formatDateAndTime(new Date(page.getModificationTime())));
            sb.append(" Author: ");
            long author = page.getModifyAuthor();
            if (author != 0) {
                String authorFullname = userManager.getUserDisplayName(author);
                if (StringHelper.containsNonWhitespace(authorFullname)) {
                    sb.append(" Author: ").append(authorFullname);
                } else {
                    sb.append("???");
                }
            }
            sb.append("\n");
            counter++;
        }
    }
    return sb.toString();
}
Also used : AssertException(org.olat.core.logging.AssertException) Formatter(org.olat.core.util.Formatter) UserManager(org.olat.user.UserManager) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 9 with AssertException

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

the class GroupPortfolioIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
    if (!portfolioModule.isEnabled())
        return;
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    Property mapKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_PORTFOLIO);
    // Check if portfolio map property exist
    if (mapKeyProperty != null) {
        Long mapKey = mapKeyProperty.getLongValue();
        String version = mapKeyProperty.getStringValue();
        if (version == null || !version.equals("2")) {
            PortfolioStructure map = frontendManager.loadPortfolioStructureByKey(mapKey);
            if (map != null) {
                SearchResourceContext resourceContext = new SearchResourceContext(parentResourceContext);
                resourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLPORTFOLIO);
                resourceContext.setDocumentType(TYPE);
                resourceContext.setParentContextType(GroupDocument.TYPE);
                resourceContext.setParentContextName(businessGroup.getName());
                Document document = PortfolioMapDocument.createDocument(resourceContext, map);
                indexerWriter.addDocument(document);
            }
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) SearchResourceContext(org.olat.search.service.SearchResourceContext) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) PortfolioMapDocument(org.olat.search.service.document.PortfolioMapDocument) Document(org.apache.lucene.document.Document) GroupDocument(org.olat.search.service.document.GroupDocument) Property(org.olat.properties.Property)

Example 10 with AssertException

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

the class JmsSearchProvider method stop.

/**
 * @see org.olat.search.service.searcher.OLATSearcher#stop()
 */
public void stop() {
    if (searchService == null)
        throw new AssertException("searchService in ClusteredSearchProvider is null, please check the search configuration!");
    searchService.stop();
    try {
        session_.close();
        connection_.close();
        log_.info("ClusteredSearchProvider stopped");
    } catch (JMSException e) {
        log_.warn("Exception in stop ClusteredSearchProvider, ", e);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) JMSException(javax.jms.JMSException)

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