Concept:OsProject/Java

From BITPlan Wiki
Jump to navigation Jump to search

java code

@// 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 = "<!-- " + name + " is null-->\n";
      if (value != null)
        result = "|" + name + "=" + value + "\n";
      return result;
    }

    /**
     * get the SiDIF representation of the given property
     * 
     * @param name - the name of the property
     * @param value - the value of the property
     * @param type - the type of the property
     * @return - the SiDIF Sting representation of the property
     */
    public static String propertySiDIF(String name, String value, String type) {
      // default is a comment line which can be filled by uncommenting
      String result = String.format("# is is %s of it\n",name);;
      // 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
        // convert double quotes to single quotes - FIXME - should we escape instead?
        value=value.replace("\"","'");
        result = String.format("%s%s%s is %s of it\n",quote,value,quote,name);
      }
      // 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
 /**
  * OsProject
  * An Open Source Project
  */
  public static class OsProject extends TopicBase {
  
    public String id;
    public String state;
    public String owner;
    public String title;
    public String url;
    public String description;
    public String version;
    public String date;
    public String since;
    public String until;

    public String getId() { return id; }
    public void setId(String pId) { id=pId; }
    public String getState() { return state; }
    public void setState(String pState) { state=pState; }
    public String getOwner() { return owner; }
    public void setOwner(String pOwner) { owner=pOwner; }
    public String getTitle() { return title; }
    public void setTitle(String pTitle) { title=pTitle; }
    public String getUrl() { return url; }
    public void setUrl(String pUrl) { url=pUrl; }
    public String getDescription() { return description; }
    public void setDescription(String pDescription) { description=pDescription; }
    public String getVersion() { return version; }
    public void setVersion(String pVersion) { version=pVersion; }
    public String getDate() { return date; }
    public void setDate(String pDate) { date=pDate; }
    public String getSince() { return since; }
    public void setSince(String pSince) { since=pSince; }
    public String getUntil() { return until; }
    public void setUntil(String pUntil) { until=pUntil; }
    /**
     * convert this OsProject to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this OsProject to a WikiSon string
     * @return the WikiSon representation of this OsProject
     */
    public String toWikiSon() {
      String wikison= "{{OsProject\n";
      wikison+=toWikiSon("id",id);
      wikison+=toWikiSon("state",state);
      wikison+=toWikiSon("owner",owner);
      wikison+=toWikiSon("title",title);
      wikison+=toWikiSon("url",url);
      wikison+=toWikiSon("description",description);
      wikison+=toWikiSon("version",version);
      wikison+=toWikiSon("date",date);
      wikison+=toWikiSon("since",since);
      wikison+=toWikiSon("until",until);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this OsProject to a SiDIF string
     * @return the SiDIF representation of this OsProject
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA OsProject\n",this.pageid);
      siDIF+=propertySiDIF("id",id,"Text");
      siDIF+=propertySiDIF("state",state,"Text");
      siDIF+=propertySiDIF("owner",owner,"Text");
      siDIF+=propertySiDIF("title",title,"Text");
      siDIF+=propertySiDIF("url",url,"Text");
      siDIF+=propertySiDIF("description",description,"Text");
      siDIF+=propertySiDIF("version",version,"Text");
      siDIF+=propertySiDIF("date",date,"Date");
      siDIF+=propertySiDIF("since",since,"Date");
      siDIF+=propertySiDIF("until",until,"Date");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for OsProject
     */
    public OsProject() {}

    /**
     * construct a OsProject from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pOsProjectTriple - the triple to construct me from
     */
    public OsProject(TripleQuery query,Triple pOsProjectTriple) {
      this(query,pOsProjectTriple.getSubject().toString());
    } // constructor

    /**
     * construct a OsProject from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public OsProject(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple idTriple=query.selectSingle(pageid,"id",null);
      if (idTriple==null)
        idTriple=query.selectSingle(pageid,"Property:OsProject_id",null);
      if (idTriple!=null) 
        id=idTriple.getObject().toString();
      Triple stateTriple=query.selectSingle(pageid,"state",null);
      if (stateTriple==null)
        stateTriple=query.selectSingle(pageid,"Property:OsProject_state",null);
      if (stateTriple!=null) 
        state=stateTriple.getObject().toString();
      Triple ownerTriple=query.selectSingle(pageid,"owner",null);
      if (ownerTriple==null)
        ownerTriple=query.selectSingle(pageid,"Property:OsProject_owner",null);
      if (ownerTriple!=null) 
        owner=ownerTriple.getObject().toString();
      Triple titleTriple=query.selectSingle(pageid,"title",null);
      if (titleTriple==null)
        titleTriple=query.selectSingle(pageid,"Property:OsProject_title",null);
      if (titleTriple!=null) 
        title=titleTriple.getObject().toString();
      Triple urlTriple=query.selectSingle(pageid,"url",null);
      if (urlTriple==null)
        urlTriple=query.selectSingle(pageid,"Property:OsProject_url",null);
      if (urlTriple!=null) 
        url=urlTriple.getObject().toString();
      Triple descriptionTriple=query.selectSingle(pageid,"description",null);
      if (descriptionTriple==null)
        descriptionTriple=query.selectSingle(pageid,"Property:OsProject_description",null);
      if (descriptionTriple!=null) 
        description=descriptionTriple.getObject().toString();
      Triple versionTriple=query.selectSingle(pageid,"version",null);
      if (versionTriple==null)
        versionTriple=query.selectSingle(pageid,"Property:OsProject_version",null);
      if (versionTriple!=null) 
        version=versionTriple.getObject().toString();
      Triple dateTriple=query.selectSingle(pageid,"date",null);
      if (dateTriple==null)
        dateTriple=query.selectSingle(pageid,"Property:OsProject_date",null);
      if (dateTriple!=null) 
        date=dateTriple.getObject().toString();
      Triple sinceTriple=query.selectSingle(pageid,"since",null);
      if (sinceTriple==null)
        sinceTriple=query.selectSingle(pageid,"Property:OsProject_since",null);
      if (sinceTriple!=null) 
        since=sinceTriple.getObject().toString();
      Triple untilTriple=query.selectSingle(pageid,"until",null);
      if (untilTriple==null)
        untilTriple=query.selectSingle(pageid,"Property:OsProject_until",null);
      if (untilTriple!=null) 
        until=untilTriple.getObject().toString();
      init(query);
    } // constructor for OsProject
    
    // >>>{user defined topic code}{OsProject}{OsProject}
    // <<<{user defined topic code}{OsProject}{OsProject}
  } // class OsProject
  /**
   * Manager for OsProject
   */
  public static class OsProjectManager extends TopicBase {
 
    public String topicName="OsProject";
    public transient List<OsProject> mOsProjects=new ArrayList<OsProject>();
    public transient Map<String,OsProject> mOsProjectMap=new LinkedHashMap<String,OsProject>();

    /**
     * get my OsProjects
     */
    public List<OsProject> getOsProjects() {
      List<OsProject> result=this.mOsProjects;
      return result;
    }

    /**
     *  add a new OsProject 
     */
    public OsProject add(OsProject pOsProject) {
      mOsProjects.add(pOsProject);
      mOsProjectMap.put(pOsProject.getPageid(),pOsProject);
      return pOsProject;
    }

    /**
     *  add a new OsProject from the given triple
     */
    public OsProject add(TripleQuery query,Triple pOsProjectTriple) {
      OsProject lOsProject=new OsProject(query,pOsProjectTriple);
      add(lOsProject);
      return lOsProject;
    }

    // reinitialize my mOsProject map
    public void reinit() {
      mOsProjectMap.clear();
      for (OsProject lOsProject:mOsProjects) {
        mOsProjectMap.put(lOsProject.getPageid(),lOsProject);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static OsProjectManager fromJson(String json) {
      OsProjectManager result=JSON.parseObject(json, OsProjectManager.class);
      result.reinit();
      return result;
    }

    // default constructor for OsProject Manager
    public OsProjectManager() {}

    // add OsProjects from the given query
    public void addOsProjects(TripleQuery pOsProjectQuery,TripleQuery query) {
      if (pOsProjectQuery!=null) {
        for (Triple lOsProjectTriple:pOsProjectQuery.getTriples()) {
          add(query,lOsProjectTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public OsProjectManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lOsProjectQuery=query.query(null,"isA","OsProject");
      addOsProjects(lOsProjectQuery,query);
      // then the SMW triplestore
      lOsProjectQuery=query.query(null,"Property:IsA","OsProject");
      addOsProjects(lOsProjectQuery,query);
      init(query);
    } // constructor for OsProject Manager
    
    // >>>{user defined topicmanager code}{OsProject}{OsProject}
    // <<<{user defined topicmanager code}{OsProject}{OsProject}
  } // class OsProject Manager
 /**
  * Ticket
  * A ticket is an issue in an open source project
  */
  public static class Ticket extends TopicBase {
  
    public String no;
    public String title;
    public String project;

    public String getNo() { return no; }
    public void setNo(String pNo) { no=pNo; }
    public String getTitle() { return title; }
    public void setTitle(String pTitle) { title=pTitle; }
    public String getProject() { return project; }
    public void setProject(String pProject) { project=pProject; }
    /**
     * convert this Ticket to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Ticket to a WikiSon string
     * @return the WikiSon representation of this Ticket
     */
    public String toWikiSon() {
      String wikison= "{{Ticket\n";
      wikison+=toWikiSon("no",no);
      wikison+=toWikiSon("title",title);
      wikison+=toWikiSon("project",project);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this Ticket to a SiDIF string
     * @return the SiDIF representation of this Ticket
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Ticket\n",this.pageid);
      siDIF+=propertySiDIF("no",no,"Text");
      siDIF+=propertySiDIF("title",title,"Text");
      siDIF+=propertySiDIF("project",project,"Page");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Ticket
     */
    public Ticket() {}

    /**
     * construct a Ticket from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pTicketTriple - the triple to construct me from
     */
    public Ticket(TripleQuery query,Triple pTicketTriple) {
      this(query,pTicketTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Ticket from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Ticket(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple noTriple=query.selectSingle(pageid,"no",null);
      if (noTriple==null)
        noTriple=query.selectSingle(pageid,"Property:Ticket_no",null);
      if (noTriple!=null) 
        no=noTriple.getObject().toString();
      Triple titleTriple=query.selectSingle(pageid,"title",null);
      if (titleTriple==null)
        titleTriple=query.selectSingle(pageid,"Property:Ticket_title",null);
      if (titleTriple!=null) 
        title=titleTriple.getObject().toString();
      Triple projectTriple=query.selectSingle(pageid,"project",null);
      if (projectTriple==null)
        projectTriple=query.selectSingle(pageid,"Property:Ticket_project",null);
      if (projectTriple!=null) 
        project=projectTriple.getObject().toString();
      init(query);
    } // constructor for Ticket
    
    // >>>{user defined topic code}{Ticket}{Ticket}
    // <<<{user defined topic code}{Ticket}{Ticket}
  } // class Ticket
  /**
   * Manager for Ticket
   */
  public static class TicketManager extends TopicBase {
 
    public String topicName="Ticket";
    public transient List<Ticket> mTickets=new ArrayList<Ticket>();
    public transient Map<String,Ticket> mTicketMap=new LinkedHashMap<String,Ticket>();

    /**
     * get my Tickets
     */
    public List<Ticket> getTickets() {
      List<Ticket> result=this.mTickets;
      return result;
    }

    /**
     *  add a new Ticket 
     */
    public Ticket add(Ticket pTicket) {
      mTickets.add(pTicket);
      mTicketMap.put(pTicket.getPageid(),pTicket);
      return pTicket;
    }

    /**
     *  add a new Ticket from the given triple
     */
    public Ticket add(TripleQuery query,Triple pTicketTriple) {
      Ticket lTicket=new Ticket(query,pTicketTriple);
      add(lTicket);
      return lTicket;
    }

    // reinitialize my mTicket map
    public void reinit() {
      mTicketMap.clear();
      for (Ticket lTicket:mTickets) {
        mTicketMap.put(lTicket.getPageid(),lTicket);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static TicketManager fromJson(String json) {
      TicketManager result=JSON.parseObject(json, TicketManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Ticket Manager
    public TicketManager() {}

    // add Tickets from the given query
    public void addTickets(TripleQuery pTicketQuery,TripleQuery query) {
      if (pTicketQuery!=null) {
        for (Triple lTicketTriple:pTicketQuery.getTriples()) {
          add(query,lTicketTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public TicketManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lTicketQuery=query.query(null,"isA","Ticket");
      addTickets(lTicketQuery,query);
      // then the SMW triplestore
      lTicketQuery=query.query(null,"Property:IsA","Ticket");
      addTickets(lTicketQuery,query);
      init(query);
    } // constructor for Ticket Manager
    
    // >>>{user defined topicmanager code}{Ticket}{Ticket}
    // <<<{user defined topicmanager code}{Ticket}{Ticket}
  } // class Ticket Manager
 /**
  * Commit
  * A Git commit
  */
  public static class Commit extends TopicBase {
  
    public String host;
    public String path;
    public String project;
    public String subject;
    public String name;
    public String date;
    public String hash;

    public String getHost() { return host; }
    public void setHost(String pHost) { host=pHost; }
    public String getPath() { return path; }
    public void setPath(String pPath) { path=pPath; }
    public String getProject() { return project; }
    public void setProject(String pProject) { project=pProject; }
    public String getSubject() { return subject; }
    public void setSubject(String pSubject) { subject=pSubject; }
    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getDate() { return date; }
    public void setDate(String pDate) { date=pDate; }
    public String getHash() { return hash; }
    public void setHash(String pHash) { hash=pHash; }
    /**
     * convert this Commit to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Commit to a WikiSon string
     * @return the WikiSon representation of this Commit
     */
    public String toWikiSon() {
      String wikison= "{{Commit\n";
      wikison+=toWikiSon("host",host);
      wikison+=toWikiSon("path",path);
      wikison+=toWikiSon("project",project);
      wikison+=toWikiSon("subject",subject);
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("date",date);
      wikison+=toWikiSon("hash",hash);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this Commit to a SiDIF string
     * @return the SiDIF representation of this Commit
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Commit\n",this.pageid);
      siDIF+=propertySiDIF("host",host,"URL");
      siDIF+=propertySiDIF("path",path,"Text");
      siDIF+=propertySiDIF("project",project,"Text");
      siDIF+=propertySiDIF("subject",subject,"Text");
      siDIF+=propertySiDIF("name",name,"Text");
      siDIF+=propertySiDIF("date",date,"Date");
      siDIF+=propertySiDIF("hash",hash,"Text");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Commit
     */
    public Commit() {}

    /**
     * construct a Commit from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pCommitTriple - the triple to construct me from
     */
    public Commit(TripleQuery query,Triple pCommitTriple) {
      this(query,pCommitTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Commit from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Commit(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple hostTriple=query.selectSingle(pageid,"host",null);
      if (hostTriple==null)
        hostTriple=query.selectSingle(pageid,"Property:Commit_host",null);
      if (hostTriple!=null) 
        host=hostTriple.getObject().toString();
      Triple pathTriple=query.selectSingle(pageid,"path",null);
      if (pathTriple==null)
        pathTriple=query.selectSingle(pageid,"Property:Commit_path",null);
      if (pathTriple!=null) 
        path=pathTriple.getObject().toString();
      Triple projectTriple=query.selectSingle(pageid,"project",null);
      if (projectTriple==null)
        projectTriple=query.selectSingle(pageid,"Property:Commit_project",null);
      if (projectTriple!=null) 
        project=projectTriple.getObject().toString();
      Triple subjectTriple=query.selectSingle(pageid,"subject",null);
      if (subjectTriple==null)
        subjectTriple=query.selectSingle(pageid,"Property:Commit_subject",null);
      if (subjectTriple!=null) 
        subject=subjectTriple.getObject().toString();
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:Commit_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple dateTriple=query.selectSingle(pageid,"date",null);
      if (dateTriple==null)
        dateTriple=query.selectSingle(pageid,"Property:Commit_date",null);
      if (dateTriple!=null) 
        date=dateTriple.getObject().toString();
      Triple hashTriple=query.selectSingle(pageid,"hash",null);
      if (hashTriple==null)
        hashTriple=query.selectSingle(pageid,"Property:Commit_hash",null);
      if (hashTriple!=null) 
        hash=hashTriple.getObject().toString();
      init(query);
    } // constructor for Commit
    
    // >>>{user defined topic code}{Commit}{Commit}
    // <<<{user defined topic code}{Commit}{Commit}
  } // class Commit
  /**
   * Manager for Commit
   */
  public static class CommitManager extends TopicBase {
 
    public String topicName="Commit";
    public transient List<Commit> mCommits=new ArrayList<Commit>();
    public transient Map<String,Commit> mCommitMap=new LinkedHashMap<String,Commit>();

    /**
     * get my Commits
     */
    public List<Commit> getCommits() {
      List<Commit> result=this.mCommits;
      return result;
    }

    /**
     *  add a new Commit 
     */
    public Commit add(Commit pCommit) {
      mCommits.add(pCommit);
      mCommitMap.put(pCommit.getPageid(),pCommit);
      return pCommit;
    }

    /**
     *  add a new Commit from the given triple
     */
    public Commit add(TripleQuery query,Triple pCommitTriple) {
      Commit lCommit=new Commit(query,pCommitTriple);
      add(lCommit);
      return lCommit;
    }

    // reinitialize my mCommit map
    public void reinit() {
      mCommitMap.clear();
      for (Commit lCommit:mCommits) {
        mCommitMap.put(lCommit.getPageid(),lCommit);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static CommitManager fromJson(String json) {
      CommitManager result=JSON.parseObject(json, CommitManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Commit Manager
    public CommitManager() {}

    // add Commits from the given query
    public void addCommits(TripleQuery pCommitQuery,TripleQuery query) {
      if (pCommitQuery!=null) {
        for (Triple lCommitTriple:pCommitQuery.getTriples()) {
          add(query,lCommitTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public CommitManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lCommitQuery=query.query(null,"isA","Commit");
      addCommits(lCommitQuery,query);
      // then the SMW triplestore
      lCommitQuery=query.query(null,"Property:IsA","Commit");
      addCommits(lCommitQuery,query);
      init(query);
    } // constructor for Commit Manager
    
    // >>>{user defined topicmanager code}{Commit}{Commit}
    // <<<{user defined topicmanager code}{Commit}{Commit}
  } // class Commit Manager

}
Showing below 0 pages.

Retrieved from "https://wiki.bitplan.com/index.php?title=Concept:OsProject/Java&oldid=15066#smw-result"