Difference between revisions of "Concept:OsProject/Java"
Jump to navigation
Jump to search
m (created by WikiTask 2021-12-20T09:22:09Z) |
m (created by WikiTask 2022-01-24T06:10:55Z) |
||
Line 98: | Line 98: | ||
} | } | ||
} // TopicBase | } // TopicBase | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
/** | /** | ||
* OsProject | * OsProject | ||
Line 503: | Line 109: | ||
public String title; | public String title; | ||
public String url; | public String url; | ||
+ | public String description; | ||
public String version; | public String version; | ||
public String date; | public String date; | ||
Line 518: | Line 125: | ||
public String getUrl() { return url; } | public String getUrl() { return url; } | ||
public void setUrl(String pUrl) { url=pUrl; } | 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 String getVersion() { return version; } | ||
public void setVersion(String pVersion) { version=pVersion; } | public void setVersion(String pVersion) { version=pVersion; } | ||
Line 542: | Line 151: | ||
wikison+=toWikiSon("title",title); | wikison+=toWikiSon("title",title); | ||
wikison+=toWikiSon("url",url); | wikison+=toWikiSon("url",url); | ||
+ | wikison+=toWikiSon("description",description); | ||
wikison+=toWikiSon("version",version); | wikison+=toWikiSon("version",version); | ||
wikison+=toWikiSon("date",date); | wikison+=toWikiSon("date",date); | ||
Line 561: | Line 171: | ||
siDIF+=propertySiDIF("title",title,"Text"); | siDIF+=propertySiDIF("title",title,"Text"); | ||
siDIF+=propertySiDIF("url",url,"Text"); | siDIF+=propertySiDIF("url",url,"Text"); | ||
+ | siDIF+=propertySiDIF("description",description,"Text"); | ||
siDIF+=propertySiDIF("version",version,"Text"); | siDIF+=propertySiDIF("version",version,"Text"); | ||
siDIF+=propertySiDIF("date",date,"Date"); | siDIF+=propertySiDIF("date",date,"Date"); | ||
Line 619: | Line 230: | ||
if (urlTriple!=null) | if (urlTriple!=null) | ||
url=urlTriple.getObject().toString(); | 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); | Triple versionTriple=query.selectSingle(pageid,"version",null); | ||
if (versionTriple==null) | if (versionTriple==null) |
Revision as of 07:10, 24 January 2022
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
}