Concept:OsProject/Java
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
/**
* Brainteaser
* BITPlan Newsletter
*/
public static class Brainteaser extends TopicBase {
public String issue;
public String date;
public String problem;
public String solution;
public String finishDate;
public String pdf;
public String page;
public String getIssue() { return issue; }
public void setIssue(String pIssue) { issue=pIssue; }
public String getDate() { return date; }
public void setDate(String pDate) { date=pDate; }
public String getProblem() { return problem; }
public void setProblem(String pProblem) { problem=pProblem; }
public String getSolution() { return solution; }
public void setSolution(String pSolution) { solution=pSolution; }
public String getFinishDate() { return finishDate; }
public void setFinishDate(String pFinishDate) { finishDate=pFinishDate; }
public String getPdf() { return pdf; }
public void setPdf(String pPdf) { pdf=pPdf; }
public String getPage() { return page; }
public void setPage(String pPage) { page=pPage; }
/**
* convert this Brainteaser to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Brainteaser to a WikiSon string
* @return the WikiSon representation of this Brainteaser
*/
public String toWikiSon() {
String wikison= "{{Brainteaser\n";
wikison+=toWikiSon("issue",issue);
wikison+=toWikiSon("date",date);
wikison+=toWikiSon("problem",problem);
wikison+=toWikiSon("solution",solution);
wikison+=toWikiSon("finishDate",finishDate);
wikison+=toWikiSon("pdf",pdf);
wikison+=toWikiSon("page",page);
wikison+="}}\n";
return wikison;
}
/**
* convert this Brainteaser to a SiDIF string
* @return the SiDIF representation of this Brainteaser
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Brainteaser\n",this.pageid);
siDIF+=propertySiDIF("issue",issue,"Text");
siDIF+=propertySiDIF("date",date,"Date");
siDIF+=propertySiDIF("problem",problem,"Text");
siDIF+=propertySiDIF("solution",solution,"Text");
siDIF+=propertySiDIF("finishDate",finishDate,"Date");
siDIF+=propertySiDIF("pdf",pdf,"Page");
siDIF+=propertySiDIF("page",page,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Brainteaser
*/
public Brainteaser() {}
/**
* construct a Brainteaser from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pBrainteaserTriple - the triple to construct me from
*/
public Brainteaser(TripleQuery query,Triple pBrainteaserTriple) {
this(query,pBrainteaserTriple.getSubject().toString());
} // constructor
/**
* construct a Brainteaser from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Brainteaser(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple issueTriple=query.selectSingle(pageid,"issue",null);
if (issueTriple==null)
issueTriple=query.selectSingle(pageid,"Property:Brainteaser_issue",null);
if (issueTriple!=null)
issue=issueTriple.getObject().toString();
Triple dateTriple=query.selectSingle(pageid,"date",null);
if (dateTriple==null)
dateTriple=query.selectSingle(pageid,"Property:Brainteaser_date",null);
if (dateTriple!=null)
date=dateTriple.getObject().toString();
Triple problemTriple=query.selectSingle(pageid,"problem",null);
if (problemTriple==null)
problemTriple=query.selectSingle(pageid,"Property:Brainteaser_problem",null);
if (problemTriple!=null)
problem=problemTriple.getObject().toString();
Triple solutionTriple=query.selectSingle(pageid,"solution",null);
if (solutionTriple==null)
solutionTriple=query.selectSingle(pageid,"Property:Brainteaser_solution",null);
if (solutionTriple!=null)
solution=solutionTriple.getObject().toString();
Triple finishDateTriple=query.selectSingle(pageid,"finishDate",null);
if (finishDateTriple==null)
finishDateTriple=query.selectSingle(pageid,"Property:Brainteaser_finishDate",null);
if (finishDateTriple!=null)
finishDate=finishDateTriple.getObject().toString();
Triple pdfTriple=query.selectSingle(pageid,"pdf",null);
if (pdfTriple==null)
pdfTriple=query.selectSingle(pageid,"Property:Brainteaser_pdf",null);
if (pdfTriple!=null)
pdf=pdfTriple.getObject().toString();
Triple pageTriple=query.selectSingle(pageid,"page",null);
if (pageTriple==null)
pageTriple=query.selectSingle(pageid,"Property:Brainteaser_page",null);
if (pageTriple!=null)
page=pageTriple.getObject().toString();
init(query);
} // constructor for Brainteaser
// >>>{user defined topic code}{Brainteaser}{Brainteaser}
// <<<{user defined topic code}{Brainteaser}{Brainteaser}
} // class Brainteaser
/**
* Manager for Brainteaser
*/
public static class BrainteaserManager extends TopicBase {
public String topicName="Brainteaser";
public transient List<Brainteaser> mBrainteasers=new ArrayList<Brainteaser>();
public transient Map<String,Brainteaser> mBrainteaserMap=new LinkedHashMap<String,Brainteaser>();
/**
* get my Brainteasers
*/
public List<Brainteaser> getBrainteasers() {
List<Brainteaser> result=this.mBrainteasers;
return result;
}
/**
* add a new Brainteaser
*/
public Brainteaser add(Brainteaser pBrainteaser) {
mBrainteasers.add(pBrainteaser);
mBrainteaserMap.put(pBrainteaser.getPageid(),pBrainteaser);
return pBrainteaser;
}
/**
* add a new Brainteaser from the given triple
*/
public Brainteaser add(TripleQuery query,Triple pBrainteaserTriple) {
Brainteaser lBrainteaser=new Brainteaser(query,pBrainteaserTriple);
add(lBrainteaser);
return lBrainteaser;
}
// reinitialize my mBrainteaser map
public void reinit() {
mBrainteaserMap.clear();
for (Brainteaser lBrainteaser:mBrainteasers) {
mBrainteaserMap.put(lBrainteaser.getPageid(),lBrainteaser);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static BrainteaserManager fromJson(String json) {
BrainteaserManager result=JSON.parseObject(json, BrainteaserManager.class);
result.reinit();
return result;
}
// default constructor for Brainteaser Manager
public BrainteaserManager() {}
// add Brainteasers from the given query
public void addBrainteasers(TripleQuery pBrainteaserQuery,TripleQuery query) {
if (pBrainteaserQuery!=null) {
for (Triple lBrainteaserTriple:pBrainteaserQuery.getTriples()) {
add(query,lBrainteaserTriple);
}
}
}
// construct me from the given triple Query query
public BrainteaserManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lBrainteaserQuery=query.query(null,"isA","Brainteaser");
addBrainteasers(lBrainteaserQuery,query);
// then the SMW triplestore
lBrainteaserQuery=query.query(null,"Property:IsA","Brainteaser");
addBrainteasers(lBrainteaserQuery,query);
init(query);
} // constructor for Brainteaser Manager
// >>>{user defined topicmanager code}{Brainteaser}{Brainteaser}
// <<<{user defined topicmanager code}{Brainteaser}{Brainteaser}
} // class Brainteaser Manager
/**
* BlogEntry
* An Entry in the Blog
*/
public static class BlogEntry extends TopicBase {
public String date;
public String title;
public String author;
public String pdf;
public String getDate() { return date; }
public void setDate(String pDate) { date=pDate; }
public String getTitle() { return title; }
public void setTitle(String pTitle) { title=pTitle; }
public String getAuthor() { return author; }
public void setAuthor(String pAuthor) { author=pAuthor; }
public String getPdf() { return pdf; }
public void setPdf(String pPdf) { pdf=pPdf; }
/**
* convert this BlogEntry to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this BlogEntry to a WikiSon string
* @return the WikiSon representation of this BlogEntry
*/
public String toWikiSon() {
String wikison= "{{BlogEntry\n";
wikison+=toWikiSon("date",date);
wikison+=toWikiSon("title",title);
wikison+=toWikiSon("author",author);
wikison+=toWikiSon("pdf",pdf);
wikison+="}}\n";
return wikison;
}
/**
* convert this BlogEntry to a SiDIF string
* @return the SiDIF representation of this BlogEntry
*/
public String toSiDIF() {
String siDIF = String.format("%s isA BlogEntry\n",this.pageid);
siDIF+=propertySiDIF("date",date,"Date");
siDIF+=propertySiDIF("title",title,"Text");
siDIF+=propertySiDIF("author",author,"Text");
siDIF+=propertySiDIF("pdf",pdf,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for BlogEntry
*/
public BlogEntry() {}
/**
* construct a BlogEntry from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pBlogEntryTriple - the triple to construct me from
*/
public BlogEntry(TripleQuery query,Triple pBlogEntryTriple) {
this(query,pBlogEntryTriple.getSubject().toString());
} // constructor
/**
* construct a BlogEntry from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public BlogEntry(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple dateTriple=query.selectSingle(pageid,"date",null);
if (dateTriple==null)
dateTriple=query.selectSingle(pageid,"Property:BlogEntry_date",null);
if (dateTriple!=null)
date=dateTriple.getObject().toString();
Triple titleTriple=query.selectSingle(pageid,"title",null);
if (titleTriple==null)
titleTriple=query.selectSingle(pageid,"Property:BlogEntry_title",null);
if (titleTriple!=null)
title=titleTriple.getObject().toString();
Triple authorTriple=query.selectSingle(pageid,"author",null);
if (authorTriple==null)
authorTriple=query.selectSingle(pageid,"Property:BlogEntry_author",null);
if (authorTriple!=null)
author=authorTriple.getObject().toString();
Triple pdfTriple=query.selectSingle(pageid,"pdf",null);
if (pdfTriple==null)
pdfTriple=query.selectSingle(pageid,"Property:BlogEntry_pdf",null);
if (pdfTriple!=null)
pdf=pdfTriple.getObject().toString();
init(query);
} // constructor for BlogEntry
// >>>{user defined topic code}{BlogEntry}{BlogEntry}
// <<<{user defined topic code}{BlogEntry}{BlogEntry}
} // class BlogEntry
/**
* Manager for BlogEntry
*/
public static class BlogEntryManager extends TopicBase {
public String topicName="BlogEntry";
public transient List<BlogEntry> mBlogEntrys=new ArrayList<BlogEntry>();
public transient Map<String,BlogEntry> mBlogEntryMap=new LinkedHashMap<String,BlogEntry>();
/**
* get my BlogEntries
*/
public List<BlogEntry> getBlogEntries() {
List<BlogEntry> result=this.mBlogEntrys;
return result;
}
/**
* add a new BlogEntry
*/
public BlogEntry add(BlogEntry pBlogEntry) {
mBlogEntrys.add(pBlogEntry);
mBlogEntryMap.put(pBlogEntry.getPageid(),pBlogEntry);
return pBlogEntry;
}
/**
* add a new BlogEntry from the given triple
*/
public BlogEntry add(TripleQuery query,Triple pBlogEntryTriple) {
BlogEntry lBlogEntry=new BlogEntry(query,pBlogEntryTriple);
add(lBlogEntry);
return lBlogEntry;
}
// reinitialize my mBlogEntry map
public void reinit() {
mBlogEntryMap.clear();
for (BlogEntry lBlogEntry:mBlogEntrys) {
mBlogEntryMap.put(lBlogEntry.getPageid(),lBlogEntry);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static BlogEntryManager fromJson(String json) {
BlogEntryManager result=JSON.parseObject(json, BlogEntryManager.class);
result.reinit();
return result;
}
// default constructor for BlogEntry Manager
public BlogEntryManager() {}
// add BlogEntries from the given query
public void addBlogEntries(TripleQuery pBlogEntryQuery,TripleQuery query) {
if (pBlogEntryQuery!=null) {
for (Triple lBlogEntryTriple:pBlogEntryQuery.getTriples()) {
add(query,lBlogEntryTriple);
}
}
}
// construct me from the given triple Query query
public BlogEntryManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lBlogEntryQuery=query.query(null,"isA","BlogEntry");
addBlogEntries(lBlogEntryQuery,query);
// then the SMW triplestore
lBlogEntryQuery=query.query(null,"Property:IsA","BlogEntry");
addBlogEntries(lBlogEntryQuery,query);
init(query);
} // constructor for BlogEntry Manager
// >>>{user defined topicmanager code}{BlogEntry}{BlogEntry}
// <<<{user defined topicmanager code}{BlogEntry}{BlogEntry}
} // class BlogEntry Manager
/**
* OsProject
* An Open Source Project
*/
public static class OsProject extends TopicBase {
public String id;
public String owner;
public String title;
public String url;
public String version;
public String getId() { return id; }
public void setId(String pId) { id=pId; }
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 getVersion() { return version; }
public void setVersion(String pVersion) { version=pVersion; }
/**
* 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("owner",owner);
wikison+=toWikiSon("title",title);
wikison+=toWikiSon("url",url);
wikison+=toWikiSon("version",version);
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("owner",owner,"Text");
siDIF+=propertySiDIF("title",title,"Text");
siDIF+=propertySiDIF("url",url,"Text");
siDIF+=propertySiDIF("version",version,"Text");
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 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 versionTriple=query.selectSingle(pageid,"version",null);
if (versionTriple==null)
versionTriple=query.selectSingle(pageid,"Property:OsProject_version",null);
if (versionTriple!=null)
version=versionTriple.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
}