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());
}
}
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();
}
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();
}
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);
}
}
}
}
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);
}
}
Aggregations