Difference between revisions of "GenerateRoyalPages"

From BITPlan royal-family Wiki
Jump to navigation Jump to search
(Created page with "{{Action |name=GenerateRoyalPages |servicetype=WikiTask |inputtype=Page |input=Royal92#sidif |actionpage={{FULLPAGENAME}}#template |output=Royal92/pages |engine=rythm |author=...")
 
Line 13: Line 13:
 
}}
 
}}
 
__NOCACHE__
 
__NOCACHE__
 
+
= template =
 +
<source lang='java' id='dialog'>
 +
@// This is a rythm template
 +
@import org.sidif.triple.TripleQuery
 +
@import org.sidif.triple.Triple
 +
@import org.sidif.wiki.SSLWiki
 +
@import com.bitplan.topic.ContextSetting.TripleStoreMode
 +
@import com.alibaba.fastjson.JSON
 +
@import com.bitplan.mediawiki.japi.MediawikiApi
 +
@import com.bitplan.mediawiki.japi.Mediawiki
 +
@import com.bitplan.mediawiki.japi.api.Api
 +
@include(wiki.SiDIFTemplates.propertiesdefs)
 +
@args() {
 +
  String title
 +
  String logo
 +
  org.sidif.wiki.WikiTask wikiTask
 +
  org.sidif.triple.TripleStore tripleStore
 +
}
 +
@{
 +
  TripleQuery query=tripleStore.query();
 +
  TripleQuery needed=query.query(null,"needs","Properties");
 +
  Triple contextTriple=query.selectSingle(null,"isA","Context");
 +
  String contextName=contextTriple.getSubject().toString();
 +
  Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
 +
  String contextSidif=sidifTriple.getObject().toString();
 +
  // now get the context
 +
  ContextSetting contextSetting=ContextSetting.fromWikiTask(wikiTask);
 +
  contextSetting.setContextName(contextName);
 +
  contextSetting.setSidifInput(contextSidif);
 +
  contextSetting.setTripleStoreMode(TripleStoreMode.SiDIF);
 +
  Context context = ContextFactory.getInstance().getContext(contextSetting);
 +
}
 +
@(wikiTask.getWiki().getIsoTimeStamp())
 +
@(needed.size()) Topics need Properties to be generated
 +
@for (Triple neededTriple:needed.getTriples()) {
 +
@{
 +
  String topicName=neededTriple.getSubject().toString();
 +
  Topic topic=context.byName(topicName);
 +
}
 +
== Topic: @(topicName) ==
 +
=== properties of @(topic.name) ===
 +
@for (Property property:topic.getProperties()) {
 +
==== [[Property:@(topic.name) @(property.name)]] ====
 +
@{
 +
  Throwable error=null;
 +
  try {
 +
    // get the Rythm template result
 +
    org.rythmengine.utils.RawData pageContentRaw=property(topic,property);
 +
    String pageContent=pageContentRaw.toString();
 +
    String pageTitle="Property:"+topic.name+" "+property.name;
 +
    SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
 +
    String currentContent=wiki.getPageContent(pageTitle);
 +
    // if (currentContent==null || currentContent.length()==0) {
 +
      String summary="generated by GenerateProperties at "+wiki.getIsoTimeStamp();
 +
      wiki.edit(pageTitle,pageContent,summary);
 +
    // }
 +
  } catch (Throwable th) {
 +
    error=th;
 +
  }
 +
}
 +
@if (error) {
 +
<span style='color:red'>Error: @(error.getMessage())</span>
 +
}
 +
<pre>
 +
@property(topic,property)
 +
</pre>
 +
}
 +
}
 +
</source>
 +
{{#default_form:Action}}
 +
= Links =
 
* {{Link|target=Concept:Action}}
 
* {{Link|target=Concept:Action}}
 
* {{Link|target=Template:Action}}
 
* {{Link|target=Template:Action}}
 
* {{Link|target=Template:Wikitask}}
 
* {{Link|target=Template:Wikitask}}
 +
<headertabs/>

Revision as of 11:16, 5 October 2017

Action
edit
name  GenerateRoyalPages
servicetype  WikiTask
service  
inputtype  Page
input  Royal92#sidif
actionpage  GenerateRoyalPages#template
output  Royal92/pages
engine  rythm
author  Wf
since  2017/10/06
comment  Create wiki pages for Royal-Family

login reset runtemplate -> Royal92/pages


[edit]
@// This is a rythm template
@import org.sidif.triple.TripleQuery
@import org.sidif.triple.Triple
@import org.sidif.wiki.SSLWiki
@import com.bitplan.topic.ContextSetting.TripleStoreMode
@import com.alibaba.fastjson.JSON
@import com.bitplan.mediawiki.japi.MediawikiApi
@import com.bitplan.mediawiki.japi.Mediawiki
@import com.bitplan.mediawiki.japi.api.Api
@include(wiki.SiDIFTemplates.propertiesdefs)
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask wikiTask
  org.sidif.triple.TripleStore tripleStore
}
@{
  TripleQuery query=tripleStore.query();
  TripleQuery needed=query.query(null,"needs","Properties");
  Triple contextTriple=query.selectSingle(null,"isA","Context");
  String contextName=contextTriple.getSubject().toString();
  Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
  String contextSidif=sidifTriple.getObject().toString();
  // now get the context
  ContextSetting contextSetting=ContextSetting.fromWikiTask(wikiTask);
  contextSetting.setContextName(contextName);
  contextSetting.setSidifInput(contextSidif);
  contextSetting.setTripleStoreMode(TripleStoreMode.SiDIF);
  Context context = ContextFactory.getInstance().getContext(contextSetting);
}
@(wikiTask.getWiki().getIsoTimeStamp())
@(needed.size()) Topics need Properties to be generated
@for (Triple neededTriple:needed.getTriples()) {
@{
  String topicName=neededTriple.getSubject().toString();
  Topic topic=context.byName(topicName);
}
== Topic: @(topicName) ==
=== properties of @(topic.name) ===
@for (Property property:topic.getProperties()) {
==== [[Property:@(topic.name) @(property.name)]] ====
@{
  Throwable error=null;
  try {
    // get the Rythm template result
    org.rythmengine.utils.RawData pageContentRaw=property(topic,property);
    String pageContent=pageContentRaw.toString();
    String pageTitle="Property:"+topic.name+" "+property.name;
    SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
    String currentContent=wiki.getPageContent(pageTitle);
    // if (currentContent==null || currentContent.length()==0) {
      String summary="generated by GenerateProperties at "+wiki.getIsoTimeStamp();
      wiki.edit(pageTitle,pageContent,summary);
    // }
  } catch (Throwable th) {
    error=th;
  }
}
@if (error) {
<span style='color:red'>Error: @(error.getMessage())</span>
}
<pre>
@property(topic,property)
</pre>
}
}