Concept:Design3D/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
/**
* Design3D
* A 3D Design
*/
public static class Design3D extends TopicBase {
public String name;
public String date;
public String idea;
public String design;
public String result;
public String blockscad;
public String stl;
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 getIdea() { return idea; }
public void setIdea(String pIdea) { idea=pIdea; }
public String getDesign() { return design; }
public void setDesign(String pDesign) { design=pDesign; }
public String getResult() { return result; }
public void setResult(String pResult) { result=pResult; }
public String getBlockscad() { return blockscad; }
public void setBlockscad(String pBlockscad) { blockscad=pBlockscad; }
public String getStl() { return stl; }
public void setStl(String pStl) { stl=pStl; }
/**
* convert this Design3D to a JSON string
*/
public String toJson() { return JSON.toJSONString(this); }
/**
* convert this Design3D to a WikiSon string
* @return the WikiSon representation of this Design3D
*/
public String toWikiSon() {
String wikison= "{{Design3D\n";
wikison+=toWikiSon("name",name);
wikison+=toWikiSon("date",date);
wikison+=toWikiSon("idea",idea);
wikison+=toWikiSon("design",design);
wikison+=toWikiSon("result",result);
wikison+=toWikiSon("blockscad",blockscad);
wikison+=toWikiSon("stl",stl);
wikison+="}}\n";
return wikison;
}
/**
* convert this Design3D to a SiDIF string
* @return the SiDIF representation of this Design3D
*/
public String toSiDIF() {
String siDIF = String.format("%s isA Design3D\n",this.pageid);
siDIF+=propertySiDIF("name",name,"Text");
siDIF+=propertySiDIF("date",date,"Date");
siDIF+=propertySiDIF("idea",idea,"Text");
siDIF+=propertySiDIF("design",design,"Text");
siDIF+=propertySiDIF("result",result,"Text");
siDIF+=propertySiDIF("blockscad",blockscad,"Page");
siDIF+=propertySiDIF("stl",stl,"Page");
return siDIF;
}
/**
* get the pageid for this topic
*/
public String getPageid() { return pageid; };
/**
* default constructor for Design3D
*/
public Design3D() {}
/**
* construct a Design3D from the given Triple
* @param query - the TripleQuery to get the triples from
* @param pDesign3DTriple - the triple to construct me from
*/
public Design3D(TripleQuery query,Triple pDesign3DTriple) {
this(query,pDesign3DTriple.getSubject().toString());
} // constructor
/**
* construct a Design3D from the given pageId
* @param query - the TripleQuery to get the triples from
* @param pageid - pageid
*/
public Design3D(TripleQuery query,String pageid) {
this.pageid=pageid;
Triple nameTriple=query.selectSingle(pageid,"name",null);
if (nameTriple==null)
nameTriple=query.selectSingle(pageid,"Property:Design3D_name",null);
if (nameTriple!=null)
name=nameTriple.getObject().toString();
Triple dateTriple=query.selectSingle(pageid,"date",null);
if (dateTriple==null)
dateTriple=query.selectSingle(pageid,"Property:Design3D_date",null);
if (dateTriple!=null)
date=dateTriple.getObject().toString();
Triple ideaTriple=query.selectSingle(pageid,"idea",null);
if (ideaTriple==null)
ideaTriple=query.selectSingle(pageid,"Property:Design3D_idea",null);
if (ideaTriple!=null)
idea=ideaTriple.getObject().toString();
Triple designTriple=query.selectSingle(pageid,"design",null);
if (designTriple==null)
designTriple=query.selectSingle(pageid,"Property:Design3D_design",null);
if (designTriple!=null)
design=designTriple.getObject().toString();
Triple resultTriple=query.selectSingle(pageid,"result",null);
if (resultTriple==null)
resultTriple=query.selectSingle(pageid,"Property:Design3D_result",null);
if (resultTriple!=null)
result=resultTriple.getObject().toString();
Triple blockscadTriple=query.selectSingle(pageid,"blockscad",null);
if (blockscadTriple==null)
blockscadTriple=query.selectSingle(pageid,"Property:Design3D_blockscad",null);
if (blockscadTriple!=null)
blockscad=blockscadTriple.getObject().toString();
Triple stlTriple=query.selectSingle(pageid,"stl",null);
if (stlTriple==null)
stlTriple=query.selectSingle(pageid,"Property:Design3D_stl",null);
if (stlTriple!=null)
stl=stlTriple.getObject().toString();
init(query);
} // constructor for Design3D
// >>>{user defined topic code}{Design3D}{Design3D}
// <<<{user defined topic code}{Design3D}{Design3D}
} // class Design3D
/**
* Manager for Design3D
*/
public static class Design3DManager extends TopicBase {
public String topicName="Design3D";
public transient List<Design3D> mDesign3Ds=new ArrayList<Design3D>();
public transient Map<String,Design3D> mDesign3DMap=new LinkedHashMap<String,Design3D>();
/**
* get my Design3Ds
*/
public List<Design3D> getDesign3Ds() {
List<Design3D> result=this.mDesign3Ds;
return result;
}
/**
* add a new Design3D
*/
public Design3D add(Design3D pDesign3D) {
mDesign3Ds.add(pDesign3D);
mDesign3DMap.put(pDesign3D.getPageid(),pDesign3D);
return pDesign3D;
}
/**
* add a new Design3D from the given triple
*/
public Design3D add(TripleQuery query,Triple pDesign3DTriple) {
Design3D lDesign3D=new Design3D(query,pDesign3DTriple);
add(lDesign3D);
return lDesign3D;
}
// reinitialize my mDesign3D map
public void reinit() {
mDesign3DMap.clear();
for (Design3D lDesign3D:mDesign3Ds) {
mDesign3DMap.put(lDesign3D.getPageid(),lDesign3D);
}
}
// convert this manager to json format
public String toJson() { return JSON.toJSONString(this); }
// get a new manager from the given json string
public static Design3DManager fromJson(String json) {
Design3DManager result=JSON.parseObject(json, Design3DManager.class);
result.reinit();
return result;
}
// default constructor for Design3D Manager
public Design3DManager() {}
// add Design3Ds from the given query
public void addDesign3Ds(TripleQuery pDesign3DQuery,TripleQuery query) {
if (pDesign3DQuery!=null) {
for (Triple lDesign3DTriple:pDesign3DQuery.getTriples()) {
add(query,lDesign3DTriple);
}
}
}
// construct me from the given triple Query query
public Design3DManager(TripleQuery query) {
// first query the SiDIF bases triplestore
TripleQuery lDesign3DQuery=query.query(null,"isA","Design3D");
addDesign3Ds(lDesign3DQuery,query);
// then the SMW triplestore
lDesign3DQuery=query.query(null,"Property:IsA","Design3D");
addDesign3Ds(lDesign3DQuery,query);
init(query);
} // constructor for Design3D Manager
// >>>{user defined topicmanager code}{Design3D}{Design3D}
// <<<{user defined topicmanager code}{Design3D}{Design3D}
} // class Design3D Manager
}