View Javadoc

1   package com.sri.emo.annotations;
2   
3   import com.jcorporate.expresso.core.controller.ControllerRequest;
4   import com.jcorporate.expresso.core.dataobjects.DataException;
5   import com.jcorporate.expresso.core.db.DBConnection;
6   import com.jcorporate.expresso.core.db.DBException;
7   import com.jcorporate.expresso.core.dbobj.DBField;
8   import com.jcorporate.expresso.core.dbobj.SecurDBObject;
9   import com.jcorporate.expresso.core.security.ReadOnlyUser;
10  
11  import java.util.Date;
12  
13  /***
14   * Table of tags associated with the given nodes.
15   *
16   * @author Michael Rimov
17   * @version 1.0
18   */
19  public class NodeTags extends SecurDBObject {
20  
21      /***
22  	 * 
23  	 */
24  	private static final long serialVersionUID = 1L;
25  
26  	public static final String ID = "Id";
27  
28      public static final String PARENT_NODE = "NodeId";
29  
30      public static final String TAG_VALUE = "TagValue";
31  
32      public static final String ADDED_BY = "AddedByUser";
33  
34      public static final String ADDED_ON = "AddedOn";
35  
36  
37      public NodeTags() throws DBException {
38          super();
39      }
40  
41      public NodeTags(final DBConnection newConnection) throws DBException {
42          super(newConnection);
43      }
44  
45      public NodeTags(final DBConnection newConnection, final String setupTablesContext) throws DBException {
46          super(newConnection, setupTablesContext);
47      }
48  
49      public NodeTags(final ControllerRequest request) throws DBException {
50          super(request);
51      }
52  
53      public NodeTags(final ReadOnlyUser readOnlyUser) throws DBException {
54          super(readOnlyUser);
55      }
56  
57      protected void setupFields() throws DBException {
58          setTargetTable("tags");
59          setDescription("Node Tags");
60  
61          addField(ID, DBField.AUTOINC_TYPE, 0, false, "Tag ID");
62          addField(PARENT_NODE, DBField.INTEGER_TYPE, 0, false, "Parent Node ID");
63          addField(TAG_VALUE, DBField.VARCHAR_TYPE, 128, false, "Tag Value");
64          addField(ADDED_BY, DBField.VARCHAR_TYPE, 128, false, "Added By");
65          addField(ADDED_ON, DBField.DATE_TYPE, 0, false, "Added On");
66  
67          setReadOnly(ADDED_BY);
68          setReadOnly(ADDED_ON);
69          addKey(ID);
70  
71          //Index on the parent node and the date added to increase load speeds.
72          addIndex("node_tag_idx", PARENT_NODE + "," + ADDED_ON, false);
73      }
74  
75  
76      /***
77       * Sets the value of the tag.
78       *
79       * @param tagValue String may be initially null, but may not be null once
80       *                 added or updated.
81       * @throws DataException
82       */
83      public void setTagValue(final String tagValue) throws DataException {
84          this.set(TAG_VALUE, tagValue);
85      }
86  
87      /***
88       * Sets the parent node id.
89       *
90       * @param nodeId Integer
91       * @throws DataException
92       */
93      public void setNodeId(final Integer nodeId) throws DataException {
94          this.set(PARENT_NODE, nodeId);
95      }
96  
97      /***
98       * Sets the current user for the 'added by' node value.
99       *
100      * @throws DBException
101      */
102     public void setAddedBy() throws DBException {
103         setAddedBy(this.getRequestingUser().getLoginName());
104     }
105 
106     /***
107      * Set who it was added by.
108      *
109      * @param addedBy String
110      * @throws DataException
111      */
112     public void setAddedBy(final String addedBy) throws DataException {
113         this.set(ADDED_BY, addedBy);
114     }
115 
116     /***
117      * Sets the current date for the item.
118      *
119      * @throws DataException
120      */
121     public void setAddedOn() throws DataException {
122         setAddedOn(new Date());
123     }
124 
125     public void setAddedOn(final Date addedOn) throws DataException {
126         this.set(ADDED_ON, addedOn);
127     }
128 
129     public Integer getTagId() throws DBException {
130         return (Integer) this.getDataField(ID).asInteger();
131     }
132 
133     public String getTagValue() throws DBException {
134         return this.getDataField(TAG_VALUE).asString();
135     }
136 
137     public Integer getNodeId() throws DBException {
138         return this.getDataField(PARENT_NODE).asInteger();
139     }
140 
141     public String getAddedBy() throws DBException {
142         return this.getDataField(ADDED_BY).asString();
143     }
144 
145     public Date getAddedOn() throws DBException {
146         return getDataField(ADDED_ON).asDate();
147     }
148 
149     public void add(String userId) throws DBException {
150         this.setAddedBy(userId);
151         this.setAddedOn();
152         super.add();
153     }
154 
155 
156 }