1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package olr.om;
20
21 import java.sql.ResultSet;
22
23 import olr.rdf.Definitions;
24 import olr.rdf.OLR3Definitions;
25
26 import org.apache.torque.TorqueException;
27
28 /***
29 * This is an artificial entity.
30 * It does not exists as a relation in the database.
31 * A coursee is defined as a statement about a model
32 * with the predciate "hasCourse".
33 */
34 public class Course extends RdfStatement
35 {
36 private Model model;
37 private String course;
38 private String name;
39
40 Course(Model model) throws Exception
41 {
42 this.setRdfUser(OmContext.getUser());
43 this.setModel(model);
44 this.setRes(IS_OBJECT_RESOURCE_TRUE);
45 }
46
47 Course(ResultSet rs)
48 {
49 try
50 {
51 setModel(new Model());
52 model.setId(rs.getInt("modelID"));
53 course = rs.getString("course");
54 name = rs.getString("name");
55 }
56 catch(Exception e)
57 {
58 e.printStackTrace();
59 }
60 }
61
62 private void setModel(Model model)
63 {
64 this.model = model;
65 }
66
67 public Model getModel()
68 {
69 return model;
70 }
71
72 public String getCourse()
73 {
74 return course;
75 }
76
77 public String getName()
78 {
79 return name;
80 }
81
82 public void setName(String name)
83 {
84 this.name = name;
85 }
86
87 public String getRelativeUrl() {
88 return getCourse().substring(getCourse().indexOf("#")+1);
89 }
90
91 /***
92 * Creates all statements needed to describe/attach a course to a model.
93 */
94 public void save() throws TorqueException
95 {
96 try {
97 this.setRdfResourceRelatedBySubject(RdfResourcePeer.selectElseInsert(Definitions.HOME_NS, OLR3Definitions.OLR3_MODEL_NAME+getModel().getId()));
98 this.setRdfResourceRelatedByPredicate(RdfResourcePeer.getHasCourseResource());
99 this.setRdfResourceRelatedByObjResource(RdfResourcePeer.selectElseInsert(Definitions.HOME_NS, String.valueOf(DBUtils.getInstanceId())));
100 super.save(OmContext.getConnection());
101
102 ModelStatement modelStatement = new ModelStatement(getModel(), this);
103 modelStatement.save(OmContext.getConnection());
104
105 final RdfStatement courseTypeStatement = new RdfStatement(
106 this.getRdfResourceRelatedByObjResource(),
107 RdfResourcePeer.getTypeResource(),
108 RdfResourcePeer.getCourseResource());
109
110 courseTypeStatement.save(OmContext.getConnection());
111
112 modelStatement = new ModelStatement(getModel(), courseTypeStatement);
113 modelStatement.save(OmContext.getConnection());
114
115 ModelPeer.createLabel(getModel(), this.getRdfResourceRelatedByObjResource(), getModel().getName());
116 }
117 catch(Exception e)
118 {
119 throw new TorqueException(e);
120 }
121 }
122 }