Difference between revisions of "GenerateRoyalPages"

From BITPlan royal-family Wiki
Jump to navigation Jump to search
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Action
+
__NOCACHE__{{Action
 
|name=GenerateRoyalPages
 
|name=GenerateRoyalPages
 
|servicetype=WikiTask
 
|servicetype=WikiTask
Line 12: Line 12:
 
|storemode=property
 
|storemode=property
 
}}
 
}}
__NOCACHE__
 
 
= template =
 
= template =
 
<source lang='java' id='dialog'>
 
<source lang='java' id='dialog'>
Line 24: Line 23:
 
@import com.bitplan.mediawiki.japi.Mediawiki
 
@import com.bitplan.mediawiki.japi.Mediawiki
 
@import com.bitplan.mediawiki.japi.api.Api
 
@import com.bitplan.mediawiki.japi.api.Api
@include(wiki.SiDIFTemplates.propertiesdefs)
+
@include(wiki.PersonJava.Code)
 
@args() {
 
@args() {
 
   String title  
 
   String title  
Line 31: Line 30:
 
   org.sidif.triple.TripleStore tripleStore
 
   org.sidif.triple.TripleStore tripleStore
 
}
 
}
 +
@// get the Stacktrace
 +
@def getStackTrace(Throwable th) {
 
@{
 
@{
   TripleQuery query=tripleStore.query();
+
   StringWriter sw = new StringWriter();
  TripleQuery needed=query.query(null,"needs","Properties");
+
   PrintWriter pw = new PrintWriter(sw);
  Triple contextTriple=query.selectSingle(null,"isA","Context");
+
   th.printStackTrace(pw);
   String contextName=contextTriple.getSubject().toString();
+
   String sStackTrace = sw.toString();
   Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
+
}
   String contextSidif=sidifTriple.getObject().toString();
+
@(sStackTrace)
  // 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())
+
@// handle error
@(needed.size()) Topics need Properties to be generated
+
@def handleError(Throwable th) {
@for (Triple neededTriple:needed.getTriples()) {
+
<span style='color:red'>Error: @(th.getClass().getName()): @(th.getMessage())</span>
@{
+
=== stacktrace ===
  String topicName=neededTriple.getSubject().toString();
+
<pre>
  Topic topic=context.byName(topicName);
+
@getStackTrace(th)
 +
</pre>
 
}
 
}
== Topic: @(topicName) ==
+
@// create the given person
=== properties of @(topic.name) ===
+
@def createPerson(Person p) {
@for (Property property:topic.getProperties()) {
+
# [[@(p.getName())]]
==== [[Property:@(topic.name) @(property.name)]] ====
 
 
@{
 
@{
 
   Throwable error=null;
 
   Throwable error=null;
   try {
+
   try {
    // get the Rythm template result
+
     String pageTitle=p.getName();
    org.rythmengine.utils.RawData pageContentRaw=property(topic,property);
 
     String pageContent=pageContentRaw.toString();
 
    String pageTitle="Property:"+topic.name+" "+property.name;
 
 
     SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
 
     SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
     String currentContent=wiki.getPageContent(pageTitle);
+
     String pageContent=p.toWikiSon();
     // if (currentContent==null || currentContent.length()==0) {
+
     String summary="generated by GenerateRoyalPages at "+wiki.getIsoTimeStamp();
      String summary="generated by GenerateProperties at "+wiki.getIsoTimeStamp();
+
    wiki.edit(pageTitle,pageContent,summary);
      wiki.edit(pageTitle,pageContent,summary);
 
    // }
 
 
   } catch (Throwable th) {
 
   } catch (Throwable th) {
 
     error=th;
 
     error=th;
Line 74: Line 64:
 
}
 
}
 
@if (error) {
 
@if (error) {
<span style='color:red'>Error: @(error.getMessage())</span>
+
@handleError(error)
 +
}
 
}
 
}
<pre>
+
@{
@property(topic,property)
+
  TripleQuery query=tripleStore.query();
</pre>
+
  PersonManager pm=new PersonManager(query);
 +
  FamilyManager fm=new FamilyManager(query);
 +
  int pCount=0;
 +
  int pMax=3;
 +
  //Triple contextTriple=query.selectSingle(null,"isA","Context");
 +
  //String contextName=contextTriple.getSubject().toString();
 +
  //Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
 +
  //String contextSidif=sidifTriple.getObject().toString();
 +
}
 +
@(wikiTask.getWiki().getIsoTimeStamp())
 +
*@(query.size()) triples found
 +
*@(pm.getPersons().size()) persons found
 +
*@(fm.getFamilies().size()) families found
 +
@for (Person p:pm.getPersons()) {
 +
@createPerson(p)
 +
@{
 +
  pCount++;
 +
  if (pCount>=pMax) {
 +
    break;
 +
  }
 
}
 
}
 
}
 
}
 
</source>
 
</source>
 
{{#default_form:Action}}
 
{{#default_form:Action}}
 +
 
= Links =
 
= Links =
 +
* {{Link|target=Royal92#sidif}}
 +
* {{Link|target=PersonJava}}
 
* {{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/>
 
<headertabs/>

Latest revision as of 08:57, 6 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.PersonJava.Code)
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask wikiTask
  org.sidif.triple.TripleStore tripleStore
}
@// get the Stacktrace
@def getStackTrace(Throwable th) {
@{
  StringWriter sw = new StringWriter();
  PrintWriter pw = new PrintWriter(sw);
  th.printStackTrace(pw);
  String sStackTrace = sw.toString();
}
@(sStackTrace)
}
@// handle error
@def handleError(Throwable th) {
<span style='color:red'>Error: @(th.getClass().getName()): @(th.getMessage())</span>
=== stacktrace ===
<pre>
@getStackTrace(th)
</pre>
}
@// create the given person
@def createPerson(Person p) {
# [[@(p.getName())]]
@{
  Throwable error=null;
  try {  
    String pageTitle=p.getName();
    SSLWiki wiki=(SSLWiki)wikiTask.getWiki();
    String pageContent=p.toWikiSon();
    String summary="generated by GenerateRoyalPages at "+wiki.getIsoTimeStamp();
    wiki.edit(pageTitle,pageContent,summary);
  } catch (Throwable th) {
    error=th;
  }
}
@if (error) {
@handleError(error)
}
}
@{
  TripleQuery query=tripleStore.query();
  PersonManager pm=new PersonManager(query);
  FamilyManager fm=new FamilyManager(query);
  int pCount=0;
  int pMax=3;
  //Triple contextTriple=query.selectSingle(null,"isA","Context");
  //String contextName=contextTriple.getSubject().toString();
  //Triple sidifTriple=query.selectSingle(contextName,"sidif", null);
  //String contextSidif=sidifTriple.getObject().toString();
}
@(wikiTask.getWiki().getIsoTimeStamp())
*@(query.size()) triples found
*@(pm.getPersons().size()) persons found
*@(fm.getFamilies().size()) families found
@for (Person p:pm.getPersons()) {
@createPerson(p)
@{
  pCount++;
  if (pCount>=pMax) {
    break;
  }
}
}