4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
AlternativeAttribute.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: AlternativeAttribute.java
5  * Description: Class representing attribute of alternative of suggestion.
6  */
7 
8 /**
9  * @file AlternativeAttribute.java
10  *
11  * @brief Class representing attribute of alternative of suggestion.
12  */
13 
14 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative;
15 
22 import java.io.Serializable;
23 import java.math.BigDecimal;
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26 import java.util.*;
27 import javax.persistence.*;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.datatype.DatatypeFactory;
30 import javax.xml.datatype.Duration;
31 
32 /**
33  * Class representing attribute of alternative of suggestion.
34  *
35  * @brief Class representing attribute of alternative of suggestion.
36  * @author Marek Kopecky
37  */
38 @Entity
39 @Table(name = "alternativeAttribute")
40 @XmlRootElement
41 @NamedQueries({
42  @NamedQuery(name = "AlternativeAttribute.findAll", query = "SELECT a FROM AlternativeAttribute a"),
43  @NamedQuery(name = "AlternativeAttribute.findById", query = "SELECT a FROM AlternativeAttribute a WHERE a.id = :id"),
44  @NamedQuery(name = "AlternativeAttribute.findByName", query = "SELECT a FROM AlternativeAttribute a WHERE a.name = :name"),
45  @NamedQuery(name = "AlternativeAttribute.findBySimpleType", query = "SELECT a FROM AlternativeAttribute a WHERE a.simpleType = :simpleType"),
46  @NamedQuery(name = "AlternativeAttribute.findByType", query = "SELECT a FROM AlternativeAttribute a WHERE a.type = :type"),
47  @NamedQuery(name = "AlternativeAttribute.findByAlternative", query = "SELECT a FROM AlternativeAttribute a WHERE a.alternative = :alternative"),
48  @NamedQuery(name = "AlternativeAttribute.deleteByAltId", query = "DELETE FROM AlternativeAttribute a WHERE a.alternative = :altId")
49 })
50 public class AlternativeAttribute implements Serializable, Comparable<Object>, SecAttribute {
51  protected static final long serialVersionUID = 1L;
52 
53  /** Id of attribute of alternative */
54  @Id
55  @GeneratedValue(strategy = GenerationType.IDENTITY)
56  @Basic(optional = false)
57  @Column(name = "id")
58  private Integer id;
59 
60  /** Id of alternative to which this attribute belongs */
61  @Basic(optional = false)
62  @Column(name = "alternative", nullable = false, insertable = false, updatable = false)
63  private int alternative;
64 
65  /** Name of attribute */
66  @Basic(optional = false)
67  @Column(name = "name")
68  private String name;
69 
70  /** Name of simple type of attribute (set in structured attributes too) */
71  @Column(name = "simpleType")
72  private String simpleType;
73 
74  /** Id of structured type of attribute (type of annotation) */
75  @Column(name = "type", insertable = false, updatable = false)
76  private Integer type;
77 
78  /** Value of attribute type URI or URI of linked annotation or Image */
79  @Column(name = "uri")
80  private String uri;
81 
82  /** URI in ontology */
83  @Basic(optional = true)
84  @Column(name = "uriInOntology")
85  private String uriInOntology;
86 
87  /** Id of nested alternative (structured value) */
88  @Column(name = "nestedAlt", insertable = false, updatable = false)
89  private String nestedAlt;
90 
91  /** Id of linked suggestion (can be null in case of foreign annotation) */
92  @Column(name = "linkedAlt", insertable = false, updatable = false)
93  private Integer linkedAlt;
94 
95  /** Attribute value of type String */
96  @Column(name = "stringValue")
97  private String stringValue;
98 
99  /** Attribute value of type Text */
100  @Lob
101  @Column(name = "textValue")
102  private String textValue;
103 
104  /** Attribute value of type DateTime, Date or Time */
105  @Column(name = "dateValue")
106  @Temporal(TemporalType.TIMESTAMP)
107  private Date dateValue;
108 
109  /** Attribute value of type integer */
110  @Column(name = "intValue")
111  private Integer intValue;
112 
113  /** Attribute value of type Decimal */
114  @Column(name = "decValue")
115  private BigDecimal decValue;
116 
117  /** Attribute value of type Boolean */
118  @Column(name = "boolVAlue")
119  private Boolean boolVAlue;
120 
121  /** Attribute value of type Binary */
122  @Lob
123  @Column(name = "binValue")
124  private byte[] binValue;
125 
126  /** Attribute value of type Person (id of user) */
127  @Column(name = "userValue", insertable = false, updatable = false)
128  private Integer userValue;
129 
130  /** Attribute value of type GeoPoint - latitude */
131  @Column(name = "geoLat")
132  private BigDecimal geoLat;
133  /** Attribute value of type GeoPoint - longitude */
134  @Column(name = "geoLong")
135  private BigDecimal geoLong;
136 
137  /** type of vocalbulary entity */
138  @Column(name = "entityType")
139  private String entityType;
140 
141  /** uri of image that entity represents */
142  @Column(name = "entityVisualURI")
143  private String entityVisualURI;
144 
145  /** Comment */
146  @Basic(optional = true)
147  @Lob
148  @Column(name = "commentary")
149  private String comment;
150 
151  /** Attribute priority (for order) */
152  @Column(name = "priority")
153  private Integer priority;
154 
155  /** Annotation to which this attribute belongs */
156  @ManyToOne(optional = false)
157  @JoinColumn(name = "alternative", referencedColumnName = "id")
158  private Alternative refAlternative;
159 
160  /** Structured type of attribute (type of annotation) */
161  @OneToOne(optional = true)
162  @JoinColumn(name = "type", referencedColumnName = "id")
163  private AnnotType attributeType;
164 
165  /** Nested alternative (structured value) */
166  @OneToOne(optional = true, cascade = CascadeType.ALL)
167  @JoinColumn(name = "nestedAlt", referencedColumnName = "id")
168  private Alternative nestedAlternative;
169 
170  /** Linked suggestion (can be null in case of foreign annotation) */
171  @OneToOne(optional = true)
172  @JoinColumn(name = "linkedAlt", referencedColumnName = "id")
173  private Alternative linkedAlternative;
174 
175  /** Attribute value of type Person (user) */
176  @OneToOne(optional = true)
177  @JoinColumn(name = "userValue", referencedColumnName = "id")
178  private User user;
179 
180  /** List of entity additional attribute */
181  @OneToMany(mappedBy = "alternativeAttribute", cascade = CascadeType.ALL,
182  targetEntity = AltEntityAdditionalAttribute.class)
183  protected List<AltEntityAdditionalAttribute> entityAdditionalAttributes;
184 
185  /**
186  * Constructor for attribute.
187  */
189  }
190 
191  /**
192  * Creates new attribute
193  * @param id id of new attribute
194  */
195  public AlternativeAttribute(Integer id) {
196  this.id = id;
197  }
198 
199  /**
200  * Creates new attribute
201  * @param sga Model of new attribute
202  */
204  this.updateFromSugBaseAttribut(sga);
205  }
206 
207  /**
208  * Gets list of entity additional attribute
209  *
210  * @return List of entity additional attribute
211  */
212  public List<AltEntityAdditionalAttribute> getEntityAdditionalAttributes() {
213  return entityAdditionalAttributes;
214  }
215 
216  /**
217  * Sets list of entity additional attribute
218  *
219  * @param entityAdditionalAttributes List of entity additional attribute
220  */
221  public void setEntityAdditionalAttributes(List<AltEntityAdditionalAttribute> entityAdditionalAttributes) {
222  this.entityAdditionalAttributes = entityAdditionalAttributes;
223  }
224 
225 
226  /**
227  * Compares attributes according to priority
228  *
229  * @param o Object to compare with
230  * @return Returns a negative integer, zero, or a positive integer as this
231  * object is less than, equal to, or greater than the specified object.
232  */
233  @Override
234  public int compareTo(Object o) {
235  if (o == null) {
236  return 1;
237  }
238  if (!(o instanceof AlternativeAttribute)) {
239  throw new UnsupportedOperationException("Not supported yet.");
240  }
241  AlternativeAttribute other = (AlternativeAttribute) o;
242  if (this.priority == null && other.getPriority() == null) {
243  return 0;
244  }
245  if (this.priority == null && other.getPriority() != null) {
246  return -1;
247  }
248  if (this.priority != null && other.getPriority() == null) {
249  return 1;
250  }
251  return this.priority.compareTo(other.getPriority());
252  }
253 
254  // <editor-fold defaultstate="collapsed" desc="Equals functions">
255  /**
256  * Compares this with other object and returns, whether objects are same type
257  *
258  * and have same content (id is irrelevant). Contents of nested annotations
259  * are also compared.
260  * @param obj Object to compare with
261  * @return If object is same type and have same content, returns true, false otherwise
262  */
263  public boolean contentEquals(Object obj){
264  return contentEquals(obj,true);
265  }
266 
267 
268  /**
269  * Compares this with attribute of suggestion and returns, whether objects are same type
270  * and have same content (id is irrelevant). Contents of nested annotations
271  * are also compared.
272  *
273  * @param other Object to compare with
274  * @return If object is same type and have same content, returns true, false otherwise
275  */
276  public boolean contentEqualsForSec(SugBaseAttribute other) {
277  if (other == null) {
278  return false;
279  }
280 
281  if ((this.name == null) ? (other.getName() != null) : !this.name.equals(other.getName())) {
282  return false;
283  }
284  if (this.userValue != other.getUserValue() && (this.userValue == null || !this.userValue.equals(other.getUserValue()))) {
285  return false;
286  }
287  if (this.geoLat != other.getGeoLat() && (this.geoLat == null || !this.geoLat.equals(other.getGeoLat()))) {
288  return false;
289  }
290  if (this.geoLong != other.getGeoLong() && (this.geoLong == null || !this.geoLong.equals(other.getGeoLong()))) {
291  return false;
292  }
293  if (this.attributeType != other.getAttributeType() && (this.attributeType == null || !this.attributeType.equals(other.getAttributeType()))) {
294  return false;
295  }
296  if (this.comment == null ? other.getComment() != null : !this.comment.equals(other.getComment())) {
297  return false;
298  }
299  if (this.priority == null ? other.getPriority() != null : !this.priority.equals(other.getPriority())) {
300  return false;
301  }
302 
303  if ((this.simpleType == null) ? (other.getSimpleType() != null) : !this.simpleType.equalsIgnoreCase(other.getSimpleType())) {
304  return false;
305  }
306  if(this.simpleType != null){
307  if(this.simpleType.equalsIgnoreCase("String") || this.simpleType.equalsIgnoreCase("Duration")){
308  if ((this.stringValue == null) ? (other.getStringValue() != null) : !this.stringValue.equals(other.getStringValue())) {
309  return false;
310  }
311  }
312  else if(this.simpleType.equalsIgnoreCase("Binary")){
313  if (!Arrays.equals(this.binValue, other.getBinValue())) {
314  return false;
315  }
316  }
317  else if(this.simpleType.equalsIgnoreCase("Date") ||
318  this.simpleType.equalsIgnoreCase("DateTime") ||
319  this.simpleType.equalsIgnoreCase("Time") ||
320  this.simpleType.equalsIgnoreCase("Integer") ||
321  this.simpleType.equalsIgnoreCase("Decimal") ||
322  this.simpleType.equalsIgnoreCase("Boolean")){
323  if (this.getValue() != other.getValue() && (this.getValue() == null || !this.getValue().equals(other.getValue()))) {
324  return false;
325  }
326  }
327  else if (this.simpleType.equalsIgnoreCase("SuggestionLink")) {
328  if (this.linkedAlternative == null || !this.linkedAlternative.contentEqualsForSec(other.getLinkedSuggestion(), null, false)) {
329  return false;
330  }
331  } else if (this.simpleType.equalsIgnoreCase("NestedSuggestion")) {
332  if (this.nestedAlternative == null || !this.nestedAlternative.contentEqualsForSec(other.getNestedSuggestion(), null, false)) {
333  if (this.nestedAlternative != null && other.getNestedSuggestion() != null) {
334  if (!this.nestedAlternative.contentEqualsForSec(other.getNestedSuggestion(), null, false)) {
335  return false;
336  }
337  } else {
338  return false;
339  }
340  }
341  }
342  else if(this.simpleType.equalsIgnoreCase("GeoPoint")){
343  if (this.geoLat != other.getGeoLat() && (this.geoLat == null || !this.geoLat.equals(other.getGeoLat()))) {
344  return false;
345  }
346  if (this.geoLong != other.getGeoLong() && (this.geoLong == null || !this.geoLong.equals(other.getGeoLong()))) {
347  return false;
348  }
349  }
350  else if (this.simpleType.equalsIgnoreCase("Entity")) {
351  if (this.uri != other.getUri() && (this.uri == null || !this.uri.equals(other.getUri()))) {
352  return false;
353  }
354  if (this.entityType != other.getEntityType() && (this.entityType == null || !this.entityType.equals(other.getEntityType()))) {
355  return false;
356  }
357  if (this.stringValue != other.getStringValue() && (this.stringValue == null || !this.stringValue.equals(other.getStringValue()))) {
358  return false;
359  }
360  if (this.entityType != other.getEntityType() && (this.entityType == null || !this.entityType.equals(other.getEntityType()))) {
361  return false;
362  }
363  if (this.entityVisualURI != other.getEntityVisualURI() && (this.entityVisualURI == null || !this.entityVisualURI.equals(other.getEntityVisualURI()))) {
364  return false;
365  }
366  if (this.textValue != other.getTextValue() && (this.textValue == null || !this.textValue.equals(other.getTextValue()))) {
367  return false;
368  }
369  }
370  //AnyAnnotation, Text, URI, Image
371  else{
372  if ((this.getValue() == null) ? (other.getValue() != null) : (!this.getValue().equals(other.getValue()))) {
373  return false;
374  }
375  }
376  }
377  else{
378  if ((this.getValue() == null) ? (other.getValue() != null) : (!this.getValue().equals(other.getValue()))) {
379  return false;
380  }
381  }
382  return true;
383  } // contentEqualsForSec()
384 
385 
386  /**
387  * Compares this with other object and returns, whether objects are same type
388  * and have same content (id is irrelevant). Contents of nested annotations
389  * are also compared.
390  *
391  * @param obj Object to compare with
392  * @param refAnnot RefAnnotation will not be checked if the parameter is set to false
393  * @return If object is same type and have same content, returns true, false otherwise
394  */
395  public boolean contentEquals(Object obj, boolean refAnnot) {
396  if (obj == null) {
397  return false;
398  }
399  if (obj instanceof AlternativeAttribute) {
400  final AlternativeAttribute other = (AlternativeAttribute) obj;
401 
402  if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
403  return false;
404  }
405  if (this.userValue != other.userValue && (this.userValue == null || !this.userValue.equals(other.userValue))) {
406  return false;
407  }
408  if (this.geoLat != other.geoLat && (this.geoLat == null || !this.geoLat.equals(other.geoLat))) {
409  return false;
410  }
411  if (this.geoLong != other.geoLong && (this.geoLong == null || !this.geoLong.equals(other.geoLong))) {
412  return false;
413  }
414  if (this.attributeType != other.attributeType && (this.attributeType == null || !this.attributeType.equals(other.attributeType))) {
415  return false;
416  }
417  if (this.comment == null ? other.comment != null : !this.comment.equals(other.comment)) {
418  return false;
419  }
420  if (this.priority == null ? other.priority != null : !this.priority.equals(other.priority)) {
421  return false;
422  }
423 
424  if(refAnnot){
425  if (this.refAlternative != other.refAlternative && (this.refAlternative == null || !this.refAlternative.equals(other.refAlternative))) {
426  return false;
427  }
428  }
429 
430  if ((this.simpleType == null) ? (other.simpleType != null) : !this.simpleType.equalsIgnoreCase(other.simpleType)) {
431  return false;
432  }
433  if(this.simpleType != null){
434  if(this.simpleType.equalsIgnoreCase("String") || this.simpleType.equalsIgnoreCase("Duration")){
435  if ((this.stringValue == null) ? (other.stringValue != null) : !this.stringValue.equals(other.stringValue)) {
436  return false;
437  }
438  }
439  else if(this.simpleType.equalsIgnoreCase("Binary")){
440  if (!Arrays.equals(this.binValue, other.binValue)) {
441  return false;
442  }
443  }
444  else if(this.simpleType.equalsIgnoreCase("Date") ||
445  this.simpleType.equalsIgnoreCase("DateTime") ||
446  this.simpleType.equalsIgnoreCase("Time") ||
447  this.simpleType.equalsIgnoreCase("Integer") ||
448  this.simpleType.equalsIgnoreCase("Decimal") ||
449  this.simpleType.equalsIgnoreCase("Boolean")){
450  if (this.getValue() != other.getValue() && (this.getValue() == null || !this.getValue().equals(other.getValue()))) {
451  return false;
452  }
453  }
454  else if(this.simpleType.equalsIgnoreCase("SuggestionLink")){
455  if (this.linkedAlternative != other.linkedAlternative &&
456  (this.linkedAlternative == null || !this.linkedAlternative.equals(other.linkedAlternative))) {
457  return false;
458  }
459  }
460  else if(this.simpleType.equalsIgnoreCase("NestedSuggestion")){
461  if (this.nestedAlternative != other.nestedAlternative &&
462  (this.nestedAlternative == null || !this.nestedAlternative.equals(other.nestedAlternative))) {
463  if (this.nestedAlternative != null && other.nestedAlternative != null) {
464  if (!this.nestedAlternative.contentEquals(other.nestedAlternative)) {
465  return false;
466  }
467  } else {
468  return false;
469  }
470  }
471  }
472  else if(this.simpleType.equalsIgnoreCase("Person")){
473  if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
474  return false;
475  }
476  }
477  else if(this.simpleType.equalsIgnoreCase("GeoPoint")){
478  if (this.geoLat != other.geoLat && (this.geoLat == null || !this.geoLat.equals(other.geoLat))) {
479  return false;
480  }
481  if (this.geoLong != other.geoLong && (this.geoLong == null || !this.geoLong.equals(other.geoLong))) {
482  return false;
483  }
484  }
485  else if (this.simpleType.equalsIgnoreCase("Entity")) {
486  if (this.uri != other.uri && (this.uri == null || !this.uri.equals(other.uri))) {
487  return false;
488  }
489  if (this.entityType != other.entityType && (this.entityType == null || !this.entityType.equals(other.entityType))) {
490  return false;
491  }
492  if (this.stringValue != other.stringValue && (this.stringValue == null || !this.stringValue.equals(other.stringValue))) {
493  return false;
494  }
495  if (this.entityType != other.entityType && (this.entityType == null || !this.entityType.equals(other.entityType))) {
496  return false;
497  }
498  if (this.entityVisualURI != other.entityVisualURI && (this.entityVisualURI == null || !this.entityVisualURI.equals(other.entityVisualURI))) {
499  return false;
500  }
501  if (this.textValue != other.textValue && (this.textValue == null || !this.textValue.equals(other.textValue))) {
502  return false;
503  }
504  }
505  //AnyAnnotation, Text, URI, Image
506  else{
507  if ((this.getValue() == null) ? (other.getValue() != null) : (!this.getValue().equals(other.getValue()))) {
508  return false;
509  }
510  }
511  }
512  else{
513  if ((this.getValue() == null) ? (other.getValue() != null) : (!this.getValue().equals(other.getValue()))) {
514  return false;
515  }
516  }
517  return true;
518  }
519  return false;
520  } // contentEquals()
521 
522  /**
523  * Compares this with other object and returns, whether objects are same type
524  * and have same id.
525  *
526  * @param object Object to compare with
527  * @return If object is same type and have same id, returns true, false otherwise
528  */
529  @Override
530  public boolean equals(Object object) {
531  if (!(object instanceof AlternativeAttribute)) {
532  return false;
533  }
534  AlternativeAttribute other = (AlternativeAttribute) object;
535  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
536  return false;
537  }
538  return true;
539  }
540  // </editor-fold>
541 
542  /**
543  * Checks if attribute value is empty or default value
544  *
545  * @return true, if attribute value is empty
546  */
547  public boolean isEmpty() {
548  return this.getValue() == null;
549  }
550 
551 
552  @Override
553  public String toString() {
554  return "cz.vutbr.fit.knot.annotations.entity.Attribute[id=" + id + "]";
555  }
556 
557  @Override
558  public int hashCode() {
559  int hash = 0;
560  hash += (id != null ? id.hashCode() : 0);
561  return hash;
562  }
563 
564  /**
565  * Gets value of the attribute
566  *
567  * @return value of the attribute
568  */
569  @Override
570  public Object getValue(){
571  if (simpleType.equals("AnyAnnotation")) {
572  return null;
573  } else if (simpleType.equals("Boolean")) {
574  return boolVAlue;
575  } else if (simpleType.equals("Date")) {
576  return dateValue;
577  } else if (simpleType.equals("DateTime")) {
578  return dateValue;
579  } else if (simpleType.equals("Decimal")) {
580  return this.decValue;
581  } else if (simpleType.equals("GeoPoint") || simpleType.equals("geoPoint")) {
582  return new GeoPointAttribute.GeoPoint(geoLat, geoLong);
583  } else if (simpleType.equals("Image")) {
584  return this.uri;
585  } else if (simpleType.equals("Integer")) {
586  return this.intValue;
587  } else if (simpleType.equals("Person") || simpleType.equals("person")) {
588  return this.user;
589  } else if (simpleType.equals("String")) {
590  return this.stringValue;
591  } else if (simpleType.equals("Time")) {
592  return dateValue;
593  } else if (simpleType.equals("URI")) {
594  return this.uri;
595  } else if (simpleType.equals("Duration")) {
596  try {
597  return (Object) DatatypeFactory.newInstance().newDuration(this.stringValue);
598  } catch (Exception e) {
599  return null;
600  }
601  } else if (simpleType.equals("Binary")) {
602  return this.binValue;
603  } else if (simpleType.equals("Text")) {
604  return this.textValue;
605  } else if (simpleType.equals("Entity") || simpleType.equals("entity")) {
606  return new EntityAttribute.Entity(this.entityType,this.stringValue,this.uri,this.entityVisualURI, this.textValue);
607  }
608  return null;
609  }
610 
611 
612  /**
613  * Sets value of the attribute. Value should already be a native java value.
614  *
615  * For example, for attribute of type Integer value should be integer, not
616  * string. If you want to set value and parse that value, you should use
617  * setRawValue
618  *
619  * @param value new value of the attribute
620  */
621  @Override
622  public void setValue(Object value) {
623  if (simpleType.equals("AnyAnnotation")) {
624  return;
625  } else if (simpleType.equals("Boolean")) {
626  this.boolVAlue = (Boolean) value;
627  } else if (simpleType.equals("Date") || simpleType.equals("DateTime") || simpleType.equals("Time")) {
628  this.dateValue = (Date) value;
629  } else if (simpleType.equals("Decimal")) {
630  this.decValue = (BigDecimal) value;
631  } else if (simpleType.equals("GeoPoint") || simpleType.equals("geoPoint")) {
632  this.geoLat = ((GeoPointAttribute.GeoPoint) value).getLatitude();
633  this.geoLong = ((GeoPointAttribute.GeoPoint) value).getLongitude();
634  } else if (simpleType.equals("Image")) {
635  this.uri = (String) value;
636  } else if (simpleType.equals("Integer")) {
637  this.intValue = (Integer) value;
638  } else if (simpleType.equals("Person") || simpleType.equals("person")) {
639  this.user = (User) value;
640  } else if (simpleType.equals("String")) {
641  this.stringValue = (String) value;
642  } else if (simpleType.equals("URI")) {
643  this.uri = (String) value;
644  } else if (simpleType.equals("Duration")) {
645  this.stringValue = ((Duration) value).toString();
646  } else if (simpleType.equals("Binary")) {
647  this.binValue = (byte[]) value;
648  } else if (simpleType.equals("Text")) {
649  this.textValue = (String) value;
650  } else if (simpleType.equals("Entity") || simpleType.equals("entity")) {
651  EntityAttribute.Entity entity = (EntityAttribute.Entity) value;
652  this.entityType = entity.getType();
653  this.stringValue = entity.getName();
654  this.uri = entity.getURI();
655  this.entityVisualURI = entity.getVisualRepresentation();
656  this.textValue = entity.getDescription();
657  }
658  }
659 
660  /**
661  * Sets GeoPoint's latitude and longitude values passed as strings
662  *
663  * @param latitude Latitude value in string form
664  * @param longitude Longitude value in string form
665  *
666  */
667  public void setGeoPointStringValue(String latitude, String longitude) throws IllegalArgumentException{
668  if(latitude == null && longitude == null){
669  return;
670  }
671 
672  if(latitude == null || longitude == null){
673  throw new IllegalArgumentException("Latitude or Longitude value is null");
674  }
675 
676  try{
677  this.geoLat = new BigDecimal(latitude);
678  this.geoLong = new BigDecimal(longitude);
679  } catch (NumberFormatException e) {
680  throw new IllegalArgumentException("Latitude or Longitude is not valid Decimal value.");
681  }
682  }
683 
684  /**
685  * Parses provided value and sets that value as a value of attribute
686  *
687  * @param value new value of the attribute in raw form from XML
688  */
689  public void setRawValue(Object value) throws IllegalArgumentException {
690  if (simpleType.equals("AnyAnnotation")) {
691  return;
692  } else if (simpleType.equals("Boolean")) {
693  this.boolVAlue = Boolean.parseBoolean((String) value);
694  } else if (simpleType.equals("Date")) {
695  String zone = Util.parseTimeZoneID((String) value);
696  String originalOffset = TimeZone.getDefault().getID();
697  if(zone != null){
698  TimeZone.setDefault(TimeZone.getTimeZone("GMT" + zone));
699  this.stringValue = zone;
700  } else {
701  this.boolVAlue = true; // suppress time zone
702  }
703  try {
704  this.dateValue = Util.parseDate((String) value);
705  } catch (Exception e) {
706  try {
707  this.dateValue = Util.parseRFC3339Date((String) value);
708  } catch (Exception ex) {
709  try {
710  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
711  this.dateValue = sdf.parse((String) value);
712  } catch (Exception exx) {
713  throw new IllegalArgumentException("Value " + (String) value + " is not a valid date");
714  }
715  }
716  }
717  if(zone != null){
718  TimeZone.setDefault(TimeZone.getTimeZone(originalOffset));
719  }
720  } else if (simpleType.equals("DateTime")) {
721  String zone = Util.parseTimeZoneID((String) value);
722  String originalOffset = TimeZone.getDefault().getID();
723  if(zone != null){
724  TimeZone.setDefault(TimeZone.getTimeZone("GMT" + zone));
725  this.stringValue = zone;
726  }
727  try {
728  this.dateValue = Util.parseRFC3339Date((String) value);
729  } catch (Exception e) {
730  throw new IllegalArgumentException("Value " + (String) value + " is not a valid RFC3339 date time");
731  }
732  if(zone != null){
733  TimeZone.setDefault(TimeZone.getTimeZone(originalOffset));
734  }
735  } else if (simpleType.equals("Decimal")) {
736  try {
737  this.decValue = new BigDecimal((String) value);
738  } catch (NumberFormatException e) {
739  throw new IllegalArgumentException("Value " + (String) value + " is not a valid Decimal value");
740  }
741  } else if (simpleType.equals("GeoPoint") || simpleType.equals("geoPoint")) {
742  @SuppressWarnings("unchecked") ArrayList<Object> valuesArray = (ArrayList<Object>) value;
743  @SuppressWarnings("unchecked") Map<String,String> tag = (Map<String,String>)valuesArray.get(0);
744 
745  String latitude = tag.get("geo:lat");
746  String longitude = tag.get("geo:long");
747 
748  try {
749  this.geoLat = new BigDecimal(latitude);
750  this.geoLong = new BigDecimal(longitude);
751  } catch (NumberFormatException e) {
752  throw new IllegalArgumentException("Latitude or Longitude is not valid Decimal value.");
753  }
754  } else if (simpleType.equals("Image")) {
755  this.uri = (String) value;
756  } else if (simpleType.equals("Integer")) {
757  try {
758  this.intValue = Integer.parseInt((String) value);
759  } catch (NumberFormatException e) {
760  throw new IllegalArgumentException("Value " + (String) value + " is not a valid integer value");
761  }
762  } else if (simpleType.equals("Person") || simpleType.equals("person")) {
763  throw new UnsupportedOperationException("Server internal error.");
764  } else if (simpleType.equals("String")) {
765  this.stringValue = (String) value;
766  } else if (simpleType.equals("Time")) {
767  String zone = Util.parseTimeZoneID((String) value);
768  String originalOffset = TimeZone.getDefault().getID();
769  if(zone != null){
770  TimeZone.setDefault(TimeZone.getTimeZone("GMT" + zone));
771  this.stringValue = zone;
772  }
773  try {
774  this.dateValue = Util.parseTime((String) value);
775  } catch (Exception e) {
776  try {
777  this.dateValue = Util.parseRFC3339Date((String) value);
778  } catch (Exception ex) {
779  try {
780  // parse time (simple format assumed)
781  DateFormat sdf = new SimpleDateFormat("HH:mm:ss");
782  this.dateValue = sdf.parse((String) value);
783  } catch (Exception exx) {
784  throw new IllegalArgumentException("Value " + (String) value + " is not a valid time");
785  }
786  }
787  }
788  if(zone != null){
789  TimeZone.setDefault(TimeZone.getTimeZone(originalOffset));
790  }
791  } else if (simpleType.equals("URI")) {
792  this.uri = (String) value;
793  } else if (simpleType.equals("Duration")) {
794  try {
795  Duration d = DatatypeFactory.newInstance().newDuration((String) value);
796  this.stringValue = d.toString();
797  } catch (Exception e) {
798  throw new IllegalArgumentException("Value " + (String) value
799  + " is not a valid Duration value according to http://www.w3.org/TR/xmlschema-2/#duration");
800  }
801  } else if (simpleType.equals("Binary")) {
802  this.binValue = org.apache.commons.codec.binary.Base64.decodeBase64((String) value);
803  } else if (simpleType.equals("Text")) {
804  this.setValue(value);
805  } else if (simpleType.equals("Entity") || simpleType.equals("entity")) {
806  @SuppressWarnings("unchecked") ArrayList<Object> valuesArray = (ArrayList<Object>)value;
807  @SuppressWarnings("unchecked") Map<String,String> parameters = (Map<String,String>)valuesArray.get(1);
808  String strValue = (String) valuesArray.get(2);
809 
810  if(parameters.get("name") != null){
811  this.stringValue = parameters.get("name");
812  }
813 
814  if(parameters.get("type") != null){
815  this.entityType = parameters.get("type");
816  }
817 
818  if(parameters.get("uri") != null){
819  this.uri = parameters.get("uri");
820  }
821 
822  if(parameters.get("visualRepresentation") != null){
823  this.entityVisualURI = parameters.get("visualRepresentation");
824  }
825 
826  if(strValue != null){
827  this.textValue = strValue;
828  }
829  }
830  } // setRawValue()
831 
832  /**
833  * Gets attribute priority
834  *
835  * @return Returns attribute priority
836  */
837  @Override
838  public Integer getPriority() {
839  return priority;
840  }
841 
842  /**
843  * Sets attribute priority
844  *
845  * @param priority Attribute priority
846  */
847  @Override
848  public void setPriority(Integer priority) {
849  this.priority = priority;
850  }
851  /**
852  * Gets textual comment
853  *
854  * @return Returns textual comment
855  */
856  public String getComment() {
857  return comment;
858  }
859 
860  /**
861  * Sets textual comment
862  *
863  * @param comment Textual comment
864  */
865  public void setComment(String comment) {
866  this.comment = comment;
867  }
868 
869  /**
870  * Gets name of attribute
871  *
872  * @return Returns name of attribute
873  */
874  @Override
875  public String getName() {
876  return name;
877  }
878 
879  /**
880  * Sets name of attribute
881  *
882  * @param name Name of attribute
883  */
884  @Override
885  public void setName(String name) {
886  this.name = name;
887  }
888 
889  /**
890  * Gets name of simple type of attribute
891  *
892  * @return Returns name of simple type of attribute
893  */
894  @Override
895  public String getSimpleType() {
896  return simpleType;
897  }
898 
899  /**
900  * Sets name of simple type of attribute
901  *
902  * @param simpleType Name of simple type of attribute
903  */
904  public void setSimpleType(String simpleType) {
905  this.simpleType = simpleType;
906  }
907 
908  /**
909  * Gets id of alternative to which this attribute belongs
910  *
911  * @return Returns id of alternative to which this attribute belongs
912  */
913  public int getAlternative() {
914  return alternative;
915  }
916 
917  /**
918  * Sets id of alternative to which this attribute belongs
919  *
920  * @param alternative id of alternative to which this attribute belongs
921  */
922  public void setAlternative(int alternative) {
923  this.alternative = alternative;
924  }
925 
926  /**
927  * Gets alternative to which this attribute belongs
928  *
929  * @return Returns alternative to which this attribute belongs
930  */
932  return refAlternative;
933  }
934 
935  /**
936  * Sets alternative to which this attribute belongs
937  *
938  * @param value Alternative to which this attribute belongs
939  */
940  public void setRefAlternative(Alternative value) {
941  this.refAlternative = value;
942  }
943 
944  /**
945  * Sets secSuggestion to which this attribute belongs
946  *
947  * @param value SecSuggestion to which this attribute belongs
948  */
949  @Override
950  public void setRefSecSuggestion(SecSuggestion value) {
951  if (value instanceof Alternative) {
952  this.refAlternative = (Alternative) value;
953  }
954  }
955 
956  /**
957  * Gets structured type of attribute (type of annotation)
958  *
959  * @return Returns structured type of attribute (type of annotation)
960  */
962  return attributeType;
963  }
964 
965  /**
966  * Sets structured type of attribute (type of annotation)
967  *
968  * @param attributeType Structured type of attribute (type of annotation)
969  */
970  public void setAttributeType(AnnotType attributeType) {
971  this.attributeType = attributeType;
972  }
973  /**
974  * Gets id of attribute of alternative
975  *
976  * @return returns id of attribute of alternative
977  */
978  public Integer getId() {
979  return id;
980  }
981 
982  /**
983  * Sets id of attribute of alternative
984  *
985  * @param id Id of attribute of alternative
986  */
987  public void setId(Integer id) {
988  this.id = id;
989  }
990 
991  /**
992  * Gets id of structured type of attribute (type of annotation)
993  *
994  * @return Returns id of structured type of attribute (type of annotation)
995  */
996  public Integer getType() {
997  return type;
998  }
999 
1000  /**
1001  * Sets id of structured type of attribute (type of annotation)
1002  *
1003  * @param type id of structured type of attribute (type of annotation)
1004  */
1005  public void setType(Integer type) {
1006  this.type = type;
1007  }
1008 
1009  /**
1010  * Gets nested alternative
1011  *
1012  * @return Returns nested alternative
1013  */
1015  return nestedAlternative;
1016  }
1017 
1018  /**
1019  * Sets nested alternative
1020  *
1021  * @param alt Nested alternative
1022  */
1024  this.nestedAlternative = alt;
1025  }
1026 
1027  /**
1028  * Checks if attribute is structured. Structured attribute is for example
1029  * GeoPointAttribute
1030  *
1031  * @return true, if attribute is structured
1032  */
1033  public boolean isStructured() {
1034  return false;
1035  }
1036 
1037  /**
1038  * Update attribute from suggestion attribute.
1039  *
1040  * @param sba attribute of the suggestion
1041  */
1043  this.name = sba.getName();
1044  this.simpleType = sba.getSimpleType();
1045  if(this.simpleType.equalsIgnoreCase("NestedAnnotation")){
1046  this.simpleType = "NestedSuggestion";
1047  }
1048  if(this.simpleType.equalsIgnoreCase("AnnotationLink")){
1049  this.simpleType = "SuggestionLink";
1050  }
1051  this.type = sba.getType();
1052  this.uri = sba.getUri();
1053  this.uriInOntology = sba.getUriInOntology();
1054  this.attributeType = sba.getAttributeType();
1055  this.comment = sba.getComment();
1056  this.entityType = sba.getEntityType();
1057  this.entityVisualURI = sba.getEntityVisualURI();
1058  this.binValue = sba.getBinValue();
1059  this.boolVAlue = sba.getBoolValue();
1060  this.dateValue = sba.getDateValue();
1061  this.decValue = sba.getDecValue();
1062  this.geoLat = sba.getGeoLat();
1063  this.geoLong = sba.getGeoLong();
1064  this.intValue = sba.getIntValue();
1065  this.stringValue = sba.getStringValue();
1066  this.textValue = sba.getTextValue();
1067  this.userValue = sba.getUserValue();
1068  this.priority = sba.getPriority();
1069 
1070  this.linkedAlternative = null;
1071  }
1072 
1073  /**
1074  * Sets attribute value of type Person (user)
1075  *
1076  * @param user Attribute value of type Person (user)
1077  */
1078  public void setUser(User user) {
1079  this.user = user;
1080  }
1081 
1082  /**
1083  * Sets attribute value of uri
1084  *
1085  * @param uri Attribute value of uri
1086  */
1087  public void setUri(String uri){
1088  this.uri = uri;
1089  }
1090 
1091  /**
1092  * Gets attribute value of uri
1093  *
1094  * @return Attribute value of uri
1095  */
1096  public String getUri(){
1097  return uri;
1098  }
1099 
1100  /**
1101  * Sets attributes URI in ontology
1102  *
1103  * @param uriInOntology Uri in ontology
1104  */
1105  public void setUriInOntology(String uriInOntology){
1106  this.uriInOntology = uriInOntology;
1107  }
1108 
1109  /**
1110  * Gets attributes URI in ontology
1111  *
1112  * @return URI in ontology
1113  */
1114  public String getUriInOntology(){
1115  return uriInOntology;
1116  }
1117 
1118  /**
1119  * Gets attribute value of entityType
1120  *
1121  * @return Attribute value of entityType
1122  */
1123  public String getEntityType(){
1124  return this.entityType;
1125  }
1126 
1127  /**
1128  * Gets attribute value of entityVisualURI
1129  *
1130  * @return Attribute value of entityVisualURI
1131  */
1132  public String getEntityVisualURI(){
1133  return this.entityVisualURI;
1134  }
1135 
1136  /**
1137  * Gets attribute value of boolean
1138  *
1139  * @return Attribute value of boolean
1140  */
1141  public Boolean getBoolValue(){
1142  return this.boolVAlue;
1143  }
1144 
1145  /**
1146  * Gets attribute value of binary
1147  *
1148  * @return Attribute value of binary
1149  */
1150  public byte[] getBinValue(){
1151  return this.binValue;
1152  }
1153 
1154  /**
1155  * Gets attribute value of date
1156  *
1157  * @return Attribute value of date
1158  */
1159  public Date getDateValue(){
1160  return this.dateValue;
1161  }
1162 
1163  /**
1164  * Gets attribute value of decimal
1165  *
1166  * @return Attribute value of decimal
1167  */
1168  @Override
1169  public BigDecimal getDecValue(){
1170  return this.decValue;
1171  }
1172 
1173  /**
1174  * Gets attribute value of geo latitude
1175  *
1176  * @return Attribute value of geo latitude
1177  */
1178  public BigDecimal getGeoLat(){
1179  return this.geoLat;
1180  }
1181 
1182  /**
1183  * Gets attribute value of geo longitude
1184  *
1185  * @return Attribute value of geo longitude
1186  */
1187  public BigDecimal getGeoLong(){
1188  return this.geoLong;
1189  }
1190 
1191  /**
1192  * Gets attribute value of integer
1193  *
1194  * @return Attribute value of integer
1195  */
1196  public Integer getIntValue(){
1197  return this.intValue;
1198  }
1199 
1200  /**
1201  * Gets attribute value of string
1202  *
1203  * @return Attribute value of string
1204  */
1205  @Override
1206  public String getStringValue(){
1207  return this.stringValue;
1208  }
1209 
1210  /**
1211  * Gets attribute value of text
1212  *
1213  * @return Attribute value of text
1214  */
1215  @Override
1216  public String getTextValue(){
1217  return this.textValue;
1218  }
1219 
1220 
1221  /**
1222  * Gets attribute value of user
1223  *
1224  * @return Attribute value of user
1225  */
1226  public Integer getUserValue(){
1227  return this.userValue;
1228  }
1229 
1230  /**
1231  * Gets attribute value of linked alternative
1232  *
1233  * @return Returns linked alternative
1234  */
1236  return this.linkedAlternative;
1237  }
1238 
1239  /**
1240  * Sets attribute value of linked alternative
1241  *
1242  * @return Returns linked alternative
1243  */
1244  public void setLinkedAlternative(Alternative linkedAlternative) {
1245  this.linkedAlternative = linkedAlternative;
1246  }
1247 
1248  /**
1249  * Sets boolean value of attribute
1250  *
1251  * @param boolVAlue New boolean value of attribute
1252  */
1253  public void setBoolVAlue(Boolean boolVAlue) {
1254  this.boolVAlue = boolVAlue;
1255  }
1256 
1257 } // public class AlternativeAttribute
Class representing vocabulary entity attribute.
Interface for SugBaseAttribute and AlternativeAttribuge.
void setEntityAdditionalAttributes(List< AltEntityAdditionalAttribute > entityAdditionalAttributes)
Class representing type of annotation.
Definition: AnnotType.java:58
Class representing user.
Definition: User.java:51
Class representing additional attribute of entity in alternative attribute.
Utility class (manipulates RFC 3339 dates)
Definition: Util.java:29