Concept:Fixme/Java

From BITPlan royal-family Wiki
Revision as of 19:44, 3 October 2017 by Wf (talk | contribs) (created by WikiTask 2017-10-03T18:44:51Z)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

java code

<source lang='java' id='javacode'>@// This is a rythm template @// the args are the standard wikiTask arguments @import org.sidif.triple.TripleQuery @import org.sidif.triple.Triple @import com.alibaba.fastjson.JSON @args() {

 String title 
 String logo
 org.sidif.wiki.WikiTask wikiTask
 org.sidif.triple.TripleStore tripleStore

}


@def static {

 /**
  * Base class
  */
 static abstract class TopicBase {
   // each Topic has a pageid - for non subobject thats the pagename
   public String pageid;
   /**
    * get a WikiSon version of the given name value
    * 
    * @param name
    * @param value
    * @return - the string representation
    */
   public String toWikiSon(String name, String value) {
     String result = "\n";
     if (value != null)
       result = "|" + name + "=" + value + "\n";
     return result;
   }
   /**
    * get the propertySidif of the given property
    * 
    * @param name
    * @param value
    * @return
    */
   public static String propertySiDIF(String name, String value, String type) {
     // default is an empty string - no property line for emtpy values
     String result = "";
     // if the value is not empty
     if ((value != null) && (!("".equals(value.trim())))) {
       // do we need to quote the result?
       String quote = "";
       // this depends on the Type
       if ("Text".equals(type)) {
         quote = "\"";
       }
       // create a SIDIF Property line like
       // "John" is lastname of it
       result += quote + value + quote + " is " + name + " of it\n";
     }
     // return the SiDIF property line
     return result;
   }
   /**
    * get me as a String
    * 
    * @param name
    * @param value
    * @return
    */
   public static String propertySiDIF(String name, String value) {
     String result = propertySiDIF(name, value, "Text");
     return result;
   }
   /**
    * check if the given boolean String value is true
    * 
    * @param value
    * @return true if the value is not null and has true/TRUE as it's string
    *         content
    */
   public boolean isTrue(String value) {
     boolean result = false;
     if (value != null && value.toLowerCase().equals("true")) {
       result = true;
     }
     return result;
   }
   /**
    * initialize
    */
   public void init(TripleQuery query) {
   }
 } // TopicBase
/**
 * Fixme
 * I mark something that needs to be fixed optionally with what needs to be done
 */
 public static class Fixme extends TopicBase {
 
   public String done;
   public String todo;
   public String getDone() { return done; }
   public void setDone(String pDone) { done=pDone; }
   public String getTodo() { return todo; }
   public void setTodo(String pTodo) { todo=pTodo; }
   /**
    * convert this Fixme to a JSON string
    */
   public String toJson() { return JSON.toJSONString(this); }
   /**
    * convert this Fixme to a WikiSon string
    */
   public String toWikiSon() {
     String wikison= "{{Fixme\n";
     wikison+=toWikiSon("done",done);
     wikison+=toWikiSon("todo",todo);
     wikison+="}}\n";
     return wikison;
   }

   /**  
    * get the pageid for this topic
    */
   public String getPageid() { return pageid; };
   /**
    * default constructor for Fixme
    */
   public Fixme() {}
   /**
    * construct a Fixme from the given Triple
    * @param query - the TripleQuery to get the triples from
    * @param pFixmeTriple - the triple to construct me from
    */
   public Fixme(TripleQuery query,Triple pFixmeTriple) {
     this(query,pFixmeTriple.getSubject().toString());
   } // constructor
   /**
    * construct a Fixme from the given pageId
    * @param query - the TripleQuery to get the triples from
    * @param pageid - pageid
    */
   public Fixme(TripleQuery query,String pageid) {
     this.pageid=pageid;
     Triple doneTriple=query.selectSingle(pageid,"done",null);
     if (doneTriple==null)
       doneTriple=query.selectSingle(pageid,"Property:Fixme_done",null);
     if (doneTriple!=null) 
       done=doneTriple.getObject().toString();
     Triple todoTriple=query.selectSingle(pageid,"todo",null);
     if (todoTriple==null)
       todoTriple=query.selectSingle(pageid,"Property:Fixme_todo",null);
     if (todoTriple!=null) 
       todo=todoTriple.getObject().toString();
     init(query);
   } // constructor for Fixme
   
   // >>>{user defined topic code}{Fixme}{Fixme}
   // <<<{user defined topic code}{Fixme}{Fixme}
 } // class Fixme
 /**
  * Manager for Fixme
  */
 public static class FixmeManager extends TopicBase {

   public String topicName="Fixme";
   public transient List<Fixme> mFixmes=new ArrayList<Fixme>();
   public transient Map<String,Fixme> mFixmeMap=new LinkedHashMap<String,Fixme>();
   /**
    * get my Fixmes
    */
   public List<Fixme> getFixmes() {
     List<Fixme> result=this.mFixmes;
     return result;
   }
   /**
    *  add a new Fixme 
    */
   public Fixme add(Fixme pFixme) {
     mFixmes.add(pFixme);
     mFixmeMap.put(pFixme.getPageid(),pFixme);
     return pFixme;
   }
   /**
    *  add a new Fixme from the given triple
    */
   public Fixme add(TripleQuery query,Triple pFixmeTriple) {
     Fixme lFixme=new Fixme(query,pFixmeTriple);
     add(lFixme);
     return lFixme;
   }
   // reinitialize my mFixme map
   public void reinit() {
     mFixmeMap.clear();
     for (Fixme lFixme:mFixmes) {
       mFixmeMap.put(lFixme.getPageid(),lFixme);
     }
   }
   // convert this manager to json format 
   public String toJson() { return JSON.toJSONString(this); }
   
   // get a new manager from the given json string
   public static FixmeManager fromJson(String json) {
     FixmeManager result=JSON.parseObject(json, FixmeManager.class);
     result.reinit();
     return result;
   }
   // default constructor for Fixme Manager
   public FixmeManager() {}
   // add Fixmes from the given query
   public void addFixmes(TripleQuery pFixmeQuery,TripleQuery query) {
     if (pFixmeQuery!=null) {
       for (Triple lFixmeTriple:pFixmeQuery.getTriples()) {
         add(query,lFixmeTriple);
       }
     }
   }
   // construct me from the given triple Query query
   public FixmeManager(TripleQuery query) {
     // first query the SiDIF bases triplestore
     TripleQuery lFixmeQuery=query.query(null,"isA","Fixme");
     addFixmes(lFixmeQuery,query);
     // then the SMW triplestore
     lFixmeQuery=query.query(null,"Property:IsA","Fixme");
     addFixmes(lFixmeQuery,query);
     init(query);
   } // constructor for Fixme Manager
   
   // >>>{user defined topicmanager code}{Fixme}{Fixme}
   // <<<{user defined topicmanager code}{Fixme}{Fixme}
 } // class Fixme Manager

}

Showing below 0 pages.

Retrieved from "http://royal-family.bitplan.com/index.php?title=Concept:Fixme/Java&oldid=295#smw-result"