View Javadoc

1   package org.lsst.ccs.localdb.statusdb.model;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import javax.persistence.Column;
8   import javax.persistence.Entity;
9   import javax.persistence.GeneratedValue;
10  import javax.persistence.GenerationType;
11  import javax.persistence.Id;
12  import javax.persistence.OneToMany;
13  import javax.persistence.Table;
14  import javax.persistence.Transient;
15  
16  import org.hibernate.annotations.NaturalId;
17  
18  @Entity
19  @org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
20  @Table(name = "datadesc")
21  public class DataDesc implements Serializable {
22  
23  	private static final long serialVersionUID = 2636311585766032024L;
24  	private long id; // can have a path
25  	private String name;
26  
27  	// or have the path in some other metadata to build the JAS tree.
28  	// ?? String path; // for JAS
29  	// ?? String label; // for JAS : label as it appears in tree
30  	// when JAS plotting the axes labels can still be something different.
31  	// used in Fermi to have different views (shifter/engineers)
32  	// TODO publish the list of all variables with a web service REST
33  	@Transient
34  	public String[] getPath() {
35  		String[] namePath = getSrcName().split("/");
36  		String[] result = new String[namePath.length + 1];
37  		result[0] = getSrcSubsystem();
38  		for (int i = 1; i < result.length; i++) {
39  			result[i] = namePath[i - 1];
40  		}
41  		return result;
42  	}
43  
44  	public static String encodePath(String[] path) {
45  		// escape slashs
46  		StringBuilder result = new StringBuilder();
47  		for (int i = 0; i < path.length; i++) {
48  			result.append('/');
49  			result.append(path[i].replaceAll("/", "\\\\/"));
50  		}
51  		return result.toString();
52  	}
53  
54  	public static String[] decodePath(String path) {
55  		if (path.startsWith("/")) {
56  			path = path.substring(1);
57  		}
58  		String[] elts = path.split("(?<!\\\\)/");
59  		for (int i = 0; i < elts.length; i++) {
60  			elts[i] = elts[i].replaceAll("\\\\/", "/");
61  		}
62  		return elts;
63  	}
64  
65  	private String srcSubsystem;
66  	private String srcName;
67  	private int maxSamplingMillis = 0;
68  	private String dataType;
69  	private long preservationDelay;
70  	private List<StatDesc> derived = new ArrayList<StatDesc>();
71  
72  	/**
73  	 * @return the id
74  	 */
75  	@Id()
76  	@GeneratedValue(strategy = GenerationType.AUTO)
77  	public long getId() {
78  		return id;
79  	}
80  
81  	/**
82  	 * @param id
83  	 *            the id to set
84  	 */
85  	public void setId(long id) {
86  		this.id = id;
87  	}
88  
89  	/**
90  	 * @return the name
91  	 */
92  	@NaturalId
93  	@Column(unique = true)
94  	public String getName() {
95  		return name;
96  	}
97  
98  	/**
99  	 * @param name
100 	 *            the name to set
101 	 */
102 	public void setName(String name) {
103 		this.name = name;
104 	}
105 
106 	/**
107 	 * @return the srcSubsystem
108 	 */
109 	public String getSrcSubsystem() {
110 		return srcSubsystem;
111 	}
112 
113 	/**
114 	 * @param srcSubsystem
115 	 *            the srcSubsystem to set
116 	 */
117 	public void setSrcSubsystem(String srcSubsystem) {
118 		this.srcSubsystem = srcSubsystem;
119 	}
120 
121 	/**
122 	 * @return the srcName
123 	 */
124 	public String getSrcName() {
125 		return srcName;
126 	}
127 
128 	/**
129 	 * @param srcName
130 	 *            the srcName to set
131 	 */
132 	public void setSrcName(String srcName) {
133 		this.srcName = srcName;
134 	}
135 
136 	/**
137 	 * @return the maxSamplingMillis
138 	 */
139 	@Column(columnDefinition = "int default 0")
140 	public int getMaxSamplingMillis() {
141 		return maxSamplingMillis;
142 	}
143 
144 	/**
145 	 * @param maxSamplingMillis
146 	 *            the maxSamplingMillis to set
147 	 */
148 	public void setMaxSamplingMillis(int maxSamplingMillis) {
149 		this.maxSamplingMillis = maxSamplingMillis;
150 	}
151 
152 	/**
153 	 * @return the dataType
154 	 */
155 	@Column(length = 1)
156 	public String getDataType() {
157 		return dataType;
158 	}
159 
160 	/**
161 	 * @param dataType
162 	 *            the dataType to set
163 	 */
164 	public void setDataType(String dataType) {
165 		this.dataType = dataType;
166 	}
167 
168 	/**
169 	 * @return the preservationDelay
170 	 */
171 	@Column(columnDefinition = "int default 0")
172 	public long getPreservationDelay() {
173 		return preservationDelay;
174 	}
175 
176 	/**
177 	 * @param preservationDelay
178 	 *            the preservationDelay to set
179 	 */
180 	public void setPreservationDelay(long preservationDelay) {
181 		this.preservationDelay = preservationDelay;
182 	}
183 
184 	/**
185 	 * @return the derived
186 	 */
187 	@OneToMany(mappedBy = "rawDescr")
188 	public List<StatDesc> getDerived() {
189 		return derived;
190 	}
191 
192 	/**
193 	 * @param derived
194 	 *            the derived to set
195 	 */
196 	public void setDerived(List<StatDesc> derived) {
197 		this.derived = derived;
198 	}
199 }