14 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative;
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.Iterator;
29 import java.util.List;
30 import javax.persistence.*;
31 import javax.validation.constraints.NotNull;
32 import javax.validation.constraints.Size;
33 import javax.xml.bind.annotation.XmlRootElement;
42 @Table(name =
"alternative")
45 @NamedQuery(name =
"Alternative.findAll", query =
"SELECT a FROM Alternative a"),
46 @NamedQuery(name =
"Alternative.findById", query =
"SELECT a FROM Alternative a WHERE a.id = :id"),
47 @NamedQuery(name =
"Alternative.findByAlternativeOf", query =
"SELECT a FROM Alternative a WHERE a.alternativeOf = :alternativeOf AND a.used = 0"),
48 @NamedQuery(name =
"Alternative.findByType", query =
"SELECT a FROM Alternative a WHERE a.type = :type"),
49 @NamedQuery(name =
"Alternative.findByCreated", query =
"SELECT a FROM Alternative a WHERE a.created = :created"),
50 @NamedQuery(name =
"Alternative.findByAuthorName", query =
"SELECT a FROM Alternative a WHERE a.authorName = :authorName"),
51 @NamedQuery(name =
"Alternative.findByAuthorAddress", query =
"SELECT a FROM Alternative a WHERE a.authorAddress = :authorAddress"),
52 @NamedQuery(name =
"Alternative.findBySource", query =
"SELECT a FROM Alternative a WHERE a.source = :source"),
53 @NamedQuery(name =
"Alternative.findBySourceDocumentID", query =
"SELECT a FROM Alternative a WHERE a.sourceDocumentId = :sourceDocumentId"),
54 @NamedQuery(name =
"Alternative.findBySourceDocumentIDNoNested", query =
"SELECT a FROM Alternative a WHERE a.sourceDocumentId = :sourceDocumentId AND a.nestedIn IS NULL"),
55 @NamedQuery(name =
"Alternative.findByNestedIn", query =
"SELECT a FROM Alternative a WHERE a.nestedIn = :nestedIn"),
56 @NamedQuery(name =
"Alternative.deleteById", query =
"DELETE FROM Alternative a WHERE a.id = :id")
59 private static final long serialVersionUID = 1L;
63 @GeneratedValue(strategy = GenerationType.IDENTITY)
64 @Basic(optional =
false)
69 @Basic(optional = false)
71 @Column(name = "type", nullable=false, insertable=false, updatable=false)
75 @Basic(optional = true)
76 @Column(name = "created")
77 @Temporal(TemporalType.TIMESTAMP)
81 @Basic(optional = true)
82 @Size(min = 1, max = 255)
83 @Column(name = "authorIdStr")
84 private String authorIdStr;
88 @Column(name = "authorName")
89 private String authorName;
93 @Column(name = "authorAddress")
94 private String authorAddress;
97 @Basic(optional = false)
99 @Size(min = 1, max = 255)
100 @Column(name = "source")
101 private String source;
104 @Basic(optional = false)
106 @Column(name = "sourceDocumentId", nullable=false, insertable=false, updatable=false)
107 private
int sourceDocumentId;
110 @Basic(optional = false)
112 @Column(name = "content")
113 private String content;
116 @Basic(optional = false)
117 @Column(name = "confidence")
118 private Integer confidence;
121 @Column(name = "authorId", insertable=false, updatable=false)
122 private String autorId;
125 @Column(name = "nestedIn", insertable=false, updatable=false)
126 private String nestedIn;
129 @Column(name = "alternativeOf", insertable=false, updatable=false)
130 private String alternativeOf;
133 @Column(name = "used")
134 private Boolean used;
137 @OneToOne(optional = false)
138 @JoinColumn(name = "type", referencedColumnName = "
id")
142 @OneToOne(optional = false)
143 @JoinColumn(name = "sourceDocumentId", referencedColumnName = "
id")
147 @OneToMany(mappedBy = "refAlternative", cascade = CascadeType.ALL,
152 @OneToMany(mappedBy = "refAlternative", cascade = CascadeType.ALL,
157 @OneToOne(optional = true)
158 @JoinColumn(name = "authorId", referencedColumnName = "
id")
162 @OneToOne(optional = true)
163 @JoinColumn(name = "nestedIn", referencedColumnName = "
id")
167 @OneToOne(optional = true)
168 @JoinColumn(name = "alternativeOf", referencedColumnName = "
id")
176 @Basic(optional = true)
177 @Column(name = "SAEntityIdentifier")
178 private String SAEntityIdentifier;
182 private String tmpId;
200 this.annotType = type;
201 this.content = content;
202 this.nestedIn = nestedIn;
203 this.attributes =
new ArrayList<AlternativeAttribute>();
204 this.fragments =
new ArrayList<AlternativeFragment>();
219 public Alternative(Integer
id, String authorIdStr, String authorName, String authorAddress,
AnnotDocument sourceDocument, String content, String nestedIn) {
222 this.authorIdStr = authorIdStr;
223 this.authorName = authorName;
224 this.authorAddress = authorAddress;
225 this.sourceDocument = sourceDocument;
226 if (sourceDocument != null) {
227 this.source = sourceDocument.getUriForAnnot();
229 this.content = content;
230 this.nestedIn = nestedIn;
231 this.nestedInAlternative = null;
232 this.attributes =
new ArrayList<AlternativeAttribute>();
233 this.fragments =
new ArrayList<AlternativeFragment>();
250 this.annotType = annotType;
251 this.created = created;
252 this.authorIdStr = authorIdStr;
253 this.authorName = authorName;
254 this.authorAddress = authorAddress;
255 this.sourceDocument = sourceDocument;
256 if (sourceDocument != null) {
257 this.source = sourceDocument.getUriForAnnot();
259 this.content = content;
260 this.nestedInAlternative = null;
261 this.attributes =
new ArrayList<AlternativeAttribute>();
262 this.fragments =
new ArrayList<AlternativeFragment>();
280 this.annotType = annotType;
281 this.created = created;
282 this.authorIdStr = authorIdStr;
283 this.authorName = authorName;
284 this.authorAddress = authorAddress;
285 this.sourceDocument = sourceDocument;
286 if (sourceDocument != null) {
287 this.source = sourceDocument.getUriForAnnot();
289 this.content = content;
290 this.nestedInAlternative = nestedInAlternative;
291 this.attributes =
new ArrayList<AlternativeAttribute>();
292 this.fragments =
new ArrayList<AlternativeFragment>();
328 this.confidence = confidence;
346 this.annotType = annotType;
364 this.created = created;
385 authorIdStr = user.getURI();
386 if (user.
getName() != null && !user.getName().contentEquals(
"")) {
387 authorName = user.getName();
389 if (user.
getEmail() != null && !user.getEmail().contentEquals(
"")) {
390 authorAddress = user.getEmail();
410 this.authorIdStr = authorIdStr;
428 this.authorName = authorName;
437 return authorAddress;
446 this.authorAddress = authorAddress;
464 this.source = source;
473 return sourceDocumentId;
482 this.sourceDocumentId = sourceDocumentId;
518 this.content = content;
536 this.autorId = autorId;
545 return sourceDocument;
555 this.sourceDocument = sourceDocument;
556 if (sourceDocument != null) {
557 this.source = sourceDocument.getUriForAnnot();
576 this.nestedIn = nestedIn;
594 this.attributes = attributes;
603 this.attributes.add(attribute);
622 return new ArrayList<AlternativeFragment>(fragments);
631 this.fragments = fragments;
640 if(fragments == null){
641 fragments =
new ArrayList<AlternativeFragment>();
643 fragments.add(fragment);
654 fragments.add((AlternativeFragment) fragment);
664 return nestedInAlternative;
673 this.nestedInAlternative = nestedInAlternative;
682 return alternativeOfSuggestion;
691 this.alternativeOfSuggestion = alternativeOfSuggestion;
700 return nestedInAnnot;
709 this.nestedInAnnot = nestedInAnnot;
718 return SAEntityIdentifier;
728 this.SAEntityIdentifier = SAEntityIdentifier;
777 hash += (
id != null ? id.hashCode() : 0);
793 Alternative other = (Alternative)
object;
794 if ((this.
id == null && other.
id != null) || (this.id != null && !this.id.equals(other.id))) {
798 if(other.
id == null &&
this.id == null){
799 if(!contentEquals(
object)){
815 public boolean equals(Object
object,
boolean noLinked){
819 Alternative other = (Alternative)
object;
820 if ((this.
id == null && other.
id != null) || (this.id != null && !this.id.equals(other.id))) {
824 if(other.
id == null &&
this.id == null){
825 if(!contentEquals(
object,
false,noLinked)){
842 return contentEquals(obj,
false,
false);
855 public boolean contentEquals(Object obj,
boolean withCreated,
boolean noLinked) {
859 if (getClass() != obj.getClass()) {
864 if (this.created != other.
created && (
this.created == null || !
this.created.equals(other.
created))) {
868 if ((this.authorIdStr == null) ? (other.authorIdStr != null) : !this.authorIdStr.equals(other.
authorIdStr)) {
871 if ((this.authorName == null) ? (other.authorName != null) : !this.authorName.equals(other.
authorName)) {
874 if ((this.authorAddress == null) ? (other.authorAddress != null) : !this.authorAddress.equals(other.
authorAddress)) {
877 if ((this.source == null) ? (other.source != null) : !this.source.equals(other.
source)) {
880 if ((this.content == null) ? (other.content != null) : !this.content.equals(other.
content)) {
883 if (this.annotType != other.
annotType && (
this.annotType == null || !
this.annotType.equals(other.
annotType))) {
886 if (this.sourceDocument != other.
sourceDocument && (
this.sourceDocument == null || !
this.sourceDocument.equals(other.
sourceDocument))) {
890 if (this.attributes == null && other.
attributes != null) {
892 }
else if (this.attributes != null && other.
attributes == null) {
894 }
else if (this.attributes != other.
attributes &&
this.attributes != null && other.
attributes != null) {
895 if (this.attributes.size() != other.attributes.size()) {
898 Iterator<AlternativeAttribute> atIt = this.attributes.iterator();
899 while (atIt.hasNext()) {
901 boolean found =
false;
902 Iterator<AlternativeAttribute> oAtIt = other.attributes.iterator();
903 while (oAtIt.hasNext()) {
916 if (this.fragments == null && other.
fragments != null) {
918 }
else if (this.fragments != null && other.
fragments == null) {
920 }
else if (this.fragments != other.
fragments &&
this.fragments != null && other.
fragments != null) {
921 if (this.fragments.size() != other.fragments.size()) {
924 Iterator frIt = this.fragments.iterator();
925 while (frIt.hasNext()) {
927 boolean found =
false;
928 Iterator oFrIt = other.fragments.iterator();
929 while (oFrIt.hasNext()) {
941 if (this.user != other.
user && (
this.user == null || !
this.user.equals(other.
user))) {
967 if ((this.content == null) ? (other.
getContent() != null) : !this.content.equals(other.
getContent())) {
970 if (this.annotType != other.
getAnnotType() && (this.annotType == null || !this.annotType.equals(other.getAnnotType()))) {
974 if (this.attributes == null && other.
getAttributes() != null) {
976 }
else if (this.attributes != null && other.
getAttributes() == null) {
978 }
else if (this.attributes != null && other.
getAttributes() != null) {
979 if (this.attributes.size() != other.getAttributes().size()) {
982 Iterator<AlternativeAttribute> atIt = this.attributes.iterator();
983 while (atIt.hasNext()) {
985 boolean found =
false;
986 Iterator<SugBaseAttribute> oAtIt = other.getAttributes().iterator();
990 while (oAtIt.hasNext()) {
1003 if (testFragments) {
1004 if (this.fragments == null && linearizedFragments != null) {
1006 }
else if (this.fragments != null && linearizedFragments == null) {
1008 }
else if (this.fragments != null && linearizedFragments != null) {
1009 if (this.fragments.size() != linearizedFragments.size()) {
1012 Iterator frIt = this.fragments.iterator();
1013 while (frIt.hasNext()) {
1015 boolean found =
false;
1016 Iterator<SuggestionFragment> oFrIt = linearizedFragments.iterator();
1017 while (oFrIt.hasNext()) {
1035 return "cz.vutbr.fit.knot.annotations.modules.auggestionManager.alternative.Alternative[ id=" +
id +
" ]";
Alternative getNestedInAlternative()
Class representing attribute of alternative of suggestion.
void setAttributes(ArrayList< AlternativeAttribute > attributes)
List< AlternativeAttribute > attributes
Interface for Suggestion and Alternative.
boolean equals(Object object)
AnnotDocument sourceDocument
Class representing annotated copy of document.
void setConfidence(Integer confidence)
boolean contentEquals(Object obj)
Alternative(AnnotType type, String content, String nestedIn)
boolean contentEqualsForSec(SuggestionFragment other)
void setSourceDocumentId(Integer sourceDocumentId)
void setSAEntityIdentifier(String SAEntityIdentifier)
static final int INITIAL_CONFIDENCE
void setAlternativeOfSuggestion(Suggestion alternativeOfSuggestion)
boolean contentEquals(Object obj, boolean withCreated, boolean noLinked)
void setSource(String source)
void setNestedInAlternative(Alternative nestedInAlternative)
void setAuthorIdStr(String authorIdStr)
Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, Alternative nestedInAlternative)
String getSAEntityIdentifier()
Class representing attribute of suggestion.
void setNestedInAnnot(Annotation nestedInAnnot)
void setAuthorAddress(String authorAddress)
Class representing suggested annotation fragment.
Annotation getNestedInAnnot()
void setType(Integer type)
void setTmpId(String tmpId)
Alternative(Integer id, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, String nestedIn)
Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content)
void setContent(String content)
void setAutorId(String autorId)
Class representing fragment for suggestion alternative.
Class provides offerining of suggestions with usage of local knowledge repository.
void setNestedIn(String nestedIn)
ArrayList< AlternativeFragment > getFragmentsAL()
Integer getSourceDocumentId()
void setAnnotType(AnnotType annotType)
Class representing type of annotation.
AnnotDocument getSourceDocument()
Suggestion getAlternativeOfSuggestion()
boolean equals(Object object, boolean noLinked)
List< AlternativeAttribute > getAttributes()
Class representing attribute of type AnnotationLink for prupose of suggestion.
List< AlternativeFragment > fragments
void setUsed(Boolean used)
void addSecFragment(SecFragment fragment)
void setCreated(Date created)
Class representing alternative of suggestion.
List< SugBaseAttribute > getAttributes()
String getAuthorAddress()
void addFragment(AlternativeFragment fragment)
Class representing suggestion of annotation.
void setAuthorName(String authorName)
boolean contentEqualsForSec(SugBaseAttribute other)
void setSourceDocument(AnnotDocument sourceDocument)
Alternative nestedInAlternative
boolean contentEquals(Object obj)
boolean contentEqualsForSec(Suggestion other, ArrayList< SuggestionFragment > linearizedFragments, boolean testFragments)
void setFragments(ArrayList< AlternativeFragment > fragments)
Class representing annotation.
boolean contentEquals(Object obj)
void addAttribute(AlternativeAttribute attribute)
Interface for SuggestionFragment and AlternativeFragment.