14 package cz.vutbr.fit.knot.annotations.entity;
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Iterator;
22 import java.util.List;
23 import javax.persistence.Basic;
24 import javax.persistence.CascadeType;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.FetchType;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.JoinTable;
33 import javax.persistence.Lob;
34 import javax.persistence.ManyToMany;
35 import javax.persistence.NamedQueries;
36 import javax.persistence.NamedQuery;
37 import javax.persistence.OneToMany;
38 import javax.persistence.OneToOne;
39 import javax.persistence.Table;
48 @Table(name =
"annotType")
50 @NamedQuery(name =
"AnnotType.findAll", query =
"SELECT a FROM AnnotType a"),
51 @NamedQuery(name =
"AnnotType.findByUri", query =
"SELECT a FROM AnnotType a WHERE a.uri = :uri"),
52 @NamedQuery(name =
"AnnotType.findByUriAndGroup", query =
"SELECT a FROM AnnotType a WHERE a.uri = :uri AND a.groupId = :groupId"),
53 @NamedQuery(name =
"AnnotType.findById", query =
"SELECT a FROM AnnotType a WHERE a.id = :id"),
54 @NamedQuery(name =
"AnnotType.findByName", query =
"SELECT a FROM AnnotType a WHERE a.name = :name"),
55 @NamedQuery(name =
"AnnotType.findByAncestor", query =
"SELECT a FROM AnnotType a WHERE a.ancestor = :ancestor"),
56 @NamedQuery(name =
"AnnotType.findByUserGroup", query =
"SELECT a FROM AnnotType a WHERE a.groupId = :groupId"),
57 @NamedQuery(name =
"AnnotType.findByNUA", query =
"SELECT a FROM AnnotType a WHERE a.name = :name AND a.uri = :uri AND a.ancestor = :ancestor")})
59 private static final long serialVersionUID = 1L;
62 @GeneratedValue(strategy = GenerationType.IDENTITY)
63 @Basic(optional =
false)
67 @Basic(optional = false)
71 @Basic(optional = false)
72 @Column(name = "name")
75 @Basic(optional = true)
76 @Column(name = "ancestor", insertable=false, updatable=false)
77 private Integer ancestor;
79 @Basic(optional = true)
80 @Column(name = "groupId", insertable=false, updatable=false)
81 private Integer groupId;
83 @Basic(optional = false)
84 @Column(name = "restrictedAtt")
85 private Boolean restrictedAtt;
87 @Basic(optional = true)
88 @Column(name = "uriInOntology")
89 private String uriInOntology;
91 @Basic(optional = true)
93 @Column(name = "commentary")
94 private String comment;
97 @OneToMany(mappedBy = "annotationType", cascade = CascadeType.ALL,
101 @OneToOne(optional = true)
102 @JoinColumn(name = "ancestor", referencedColumnName = "
id")
105 @OneToOne(optional = true)
106 @JoinColumn(name = "groupId", referencedColumnName = "
id")
110 @ManyToMany(cascade = CascadeType.MERGE)
111 @JoinTable(name = "typeAncestor",
113 @JoinColumn(name = "type", referencedColumnName = "
id"),
115 @JoinColumn(name = "ancestor", referencedColumnName = "
id"))
145 if (ancestorT != null) {
146 this.ancestor = ancestorT.getId();
148 this.ancestor = null;
150 this.ancestorType = ancestorT;
152 this.attributes =
new ArrayList<AnnotTypeAttr>();
153 this.ancestorTypes =
new ArrayList<AnnotType>();
154 this.restrictedAtt =
false;
155 this.uriInOntology = null;
228 this.ancestor = ancestor;
237 this.ancestorType = ancestorType;
246 return ancestorTypes;
255 this.ancestorTypes = ancestorTypes;
264 return new ArrayList<AnnotType>(ancestorTypes);
273 if(ancestorTypes == null){
274 this.ancestorTypes =
new ArrayList<AnnotType>();
276 if (ancestorTypes.indexOf(ancestor) < 0) {
277 this.ancestorTypes.add(ancestor);
305 this.attributes = attributes;
332 return uriInOntology;
341 this.uriInOntology = uriInOntology;
347 hash += (
id != null ? id.hashCode() : 0);
363 AnnotType other = (AnnotType)
object;
364 if ((this.
id == null && other.
id != null) || (this.id != null && !this.id.equals(other.id))) {
372 return "cz.vutbr.fit.knot.annotations.entity.AnnotType[id=" +
id +
",name=" + name +
"ancestor=" + ancestor +
"]";
383 String serializedAnc =
"";
385 for (Iterator<AnnotType> it = ancestorTypes.iterator(); it.hasNext();) {
387 serializedAnc = serializedAnc +
"<ancestor uri=\"" + ancType.getUri() +
"\"/>";
389 if (comment != null && !comment.isEmpty()) {
390 serializedAnc = serializedAnc +
"<comment>"
398 String grString =
"";
400 grString =
" group=\"" + group.getUri() +
"\"";
403 String rAString =
"";
405 rAString =
" restrictedAttributes=\"true\"";
407 if (attributes.isEmpty() && ancestorType == null) {
408 if (serializedAnc.equals(
"")) {
411 serializedAnc =
">" + serializedAnc +
"</type";
413 return "<type name=\"" + name +
"\" ancestor=\"\" uri=\""
414 + uri +
"\"" + grString + rAString + serializedAnc +
">";
415 }
else if (attributes.isEmpty()) {
416 if (serializedAnc.equals(
"")) {
419 serializedAnc =
">" + serializedAnc +
"</type";
421 return "<type name=\"" + name +
"\" ancestor=\"" + ancestorType.getUri()
422 +
"\" uri=\"" + uri +
"\"" + grString + rAString + serializedAnc +
">";
426 Collections.sort(attributes);
427 Iterator<AnnotTypeAttr> li = attributes.iterator();
429 while (li.hasNext()) {
431 att = att + at.toXMLString(withAncestors);
434 if (ancestorType == null) {
435 return "<type name=\"" + name +
"\" ancestor=\"\" uri=\"" + uri +
"\"" + grString
436 + rAString +
">" + att + serializedAnc +
"</type>";
438 return "<type name=\"" + name +
"\" ancestor=\"" + ancestorType.getUri() +
"\" uri=\""
439 + uri +
"\"" + grString + rAString +
">"
440 + att + serializedAnc +
"</type>";
453 StringBuilder serializedAnc =
new StringBuilder();
454 if(this.ancestorType != null && withAncestors){
455 serializedAnc.append(
"<directAncestors primary=\"");
456 serializedAnc.append(ancestorType.getUri());
457 if(this.ancestorTypes != null && !this.ancestorTypes.isEmpty()){
458 serializedAnc.append(
"\">");
459 Iterator<AnnotType> ancestorsIt = this.ancestorTypes.iterator();
460 while(ancestorsIt.hasNext()){
461 serializedAnc.append(
"<ancestor uri=\"");
462 serializedAnc.append(ancestorsIt.next().getUri());
463 serializedAnc.append(
"\"/>");
465 serializedAnc.append(
"</directAncestors>");
467 serializedAnc.append(
"\"/>");
472 StringBuilder serializedAttrs =
new StringBuilder();
473 List<AnnotTypeAttr> attrList = getAttributes();
474 if(attrList != null && !attrList.isEmpty()){
475 serializedAttrs.append(
"<attributes>");
476 Iterator<AnnotTypeAttr> attrsIt = attrList.iterator();
477 while(attrsIt.hasNext()){
478 serializedAttrs.append(attrsIt.next().toXMLStringV2(
true));
480 serializedAttrs.append(
"</attributes>");
484 StringBuilder serializedAnnotAttr =
new StringBuilder();
485 serializedAnnotAttr.append(
"<type name=\"");
486 serializedAnnotAttr.append(this.name);
487 serializedAnnotAttr.append(
"\" uri=\"");
488 serializedAnnotAttr.append(this.uri);
489 serializedAnnotAttr.append(
"\" groupUri=\"");
490 serializedAnnotAttr.append(this.group.getUri());
491 serializedAnnotAttr.append(
"\" restrictedAttributes=\"");
492 serializedAnnotAttr.append(this.restrictedAtt.toString());
493 if(this.uriInOntology != null && !this.uriInOntology.isEmpty()){
494 serializedAnnotAttr.append(
"\" ontologyUri=\"");
495 serializedAnnotAttr.append(this.uriInOntology);
497 if(withAncestors || (this.comment != null && !this.comment.isEmpty())
498 || serializedAnc.length() > 0 || serializedAttrs.length() > 0){
499 serializedAnnotAttr.append(
"\">");
500 serializedAnnotAttr.append(serializedAnc.toString());
501 serializedAnnotAttr.append(serializedAttrs.toString());
502 if(this.comment != null && !this.comment.isEmpty()){
503 serializedAnnotAttr.append(
"<comment><![CDATA[");
504 serializedAnnotAttr.append(this.comment);
505 serializedAnnotAttr.append(
"]]></comment>");
507 serializedAnnotAttr.append(
"</type>");
509 serializedAnnotAttr.append(
"\"/>");
512 return serializedAnnotAttr.toString();
525 StringBuilder serializedAnc =
new StringBuilder();
526 if(this.ancestorType != null && withAncestors){
527 serializedAnc.append(
"<directAncestors primary=\"");
528 serializedAnc.append(ancestorType.getUri());
529 if(this.ancestorTypes != null && !this.ancestorTypes.isEmpty()){
530 serializedAnc.append(
"\">");
531 Iterator<AnnotType> ancestorsIt = this.ancestorTypes.iterator();
532 while(ancestorsIt.hasNext()){
533 serializedAnc.append(
"<ancestor uri=\"");
534 serializedAnc.append(ancestorsIt.next().getUri());
535 serializedAnc.append(
"\"/>");
537 serializedAnc.append(
"</directAncestors>");
539 serializedAnc.append(
"\"/>");
544 StringBuilder serializedAnnotAttr =
new StringBuilder();
545 serializedAnnotAttr.append(
"<type name=\"");
546 serializedAnnotAttr.append(this.name);
547 serializedAnnotAttr.append(
"\" uri=\"");
548 serializedAnnotAttr.append(this.uri);
549 serializedAnnotAttr.append(
"\" groupUri=\"");
550 serializedAnnotAttr.append(this.group.getUri());
551 serializedAnnotAttr.append(
"\" restrictedAttributes=\"");
552 serializedAnnotAttr.append(this.restrictedAtt.toString());
554 if(withAncestors || (this.comment != null && !this.comment.isEmpty())
555 || serializedAnc.length() > 0){
556 serializedAnnotAttr.append(
"\">");
557 serializedAnnotAttr.append(serializedAnc.toString());
559 if(this.comment != null && !this.comment.isEmpty()){
560 serializedAnnotAttr.append(
"<comment><![CDATA[");
561 serializedAnnotAttr.append(this.comment);
562 serializedAnnotAttr.append(
"]]></comment>");
565 serializedAnnotAttr.append(
"</type>");
567 serializedAnnotAttr.append(
"\"/>");
570 return serializedAnnotAttr.toString();
580 String grString =
"";
582 grString =
" group=\"" + group.getUri() +
"\"";
587 for (Iterator<AnnotType> it = ancestorTypes.iterator(); it.hasNext();) {
589 ending = ending +
"<ancestor uri=\"" + ancType.getUri() +
"\"/>";
591 ending = ending +
"</type";
593 if (ancestorType == null) {
594 return "<type name=\"" + name +
"\" ancestor=\"\" uri=\""
595 + uri +
"\"" + grString + ending +
">";
597 return "<type name=\"" + name +
"\" ancestor=\"" + ancestorType.getUri()
598 +
"\" uri=\"" + uri +
"\"" + grString + ending +
">";
611 String linearized = AppBean.getBaseTypeUri();
612 linearized = linearized +
"g";
614 linearized = linearized + group.getId();
616 linearized = linearized +
"/";
618 ArrayList<String> linArray =
new ArrayList<String>();
619 linArray.add(MessageProcessor.replaceArrows(name));
620 while (ancT != null) {
621 linArray.add(ancT.getName());
622 ancT = ancT.getAncestorType();
625 for(
int i = linArray.size() - 1; i>= 0; i--){
626 linearized = linearized + linArray.get(i) +
"/";
629 linearized = linearized.substring(0, linearized.length() - 1);
642 String linearized =
"";
644 ArrayList<String> linArray =
new ArrayList<String>();
646 while (ancT != null) {
647 linArray.add(ancT.getName());
648 ancT = ancT.getAncestorType();
651 for(
int i = linArray.size() - 1; i>= 0; i--){
652 linearized = linearized + linArray.get(i) +
" -> ";
655 linearized = linearized.substring(0, linearized.length() - 4);
677 return restrictedAtt;
687 this.restrictedAtt = restrictedAtt;
705 this.comment = comment;
List< AnnotTypeAttr > getAttributes()
String toXMLStringWAV2(boolean withAncestors)
void setAncestor(Integer ancestor)
boolean equals(Object object)
Class representing attribute of type of annotation.
static String replaceArrows(String aString)
String getLinearizedName()
AnnotType getAncestorType()
Singleton for storing global variables.
void addAncestorType(AnnotType ancestor)
Boolean getRestrictedAtt()
void setAncestorTypes(List< AnnotType > ancestorTypes)
void setComment(String comment)
String toXMLStringWA(boolean withAncestors)
String getUriInOntology()
void setRestrictedAtt(Boolean restrictedAtt)
Static class which parses and process XML with messages.
Class representing user group.
ArrayList< AnnotType > getAncestorTypesAL()
String toXMLStringV2(boolean withAncestors)
Class representing type of annotation.
void setName(String name)
void setUriInOntology(String uriInOntology)
void setAttributes(ArrayList< AnnotTypeAttr > attributes)
List< AnnotType > getAncestorTypes()
void setGroup(UserGroup group)
String toXMLString(boolean withAncestors)
AnnotType(String uri, String name, AnnotType ancestorT, UserGroup group)
String linearizedNameToUri(String linName)
void setAncestorType(AnnotType ancestorType)