4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
P2EntityTrix.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: P2EntityTrix.java
5  * Description: Class that represents entity trix triple.
6  */
7 
8 /**
9  * @file P2EntityTrix.java
10  *
11  * @brief Class that represents entity trix triple.
12  */
13 
14 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0.P2Trix;
15 
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 
28 /**
29  * Class that represents entity trix triple.
30  *
31  * @brief Class that represents entity trix triple.
32  */
33 public class P2EntityTrix extends P2BaseTrix{
34 
35  /**
36  * Constructs entity trix with specified destination
37  * @param destinationUri Uri of destination
38  */
39  public P2EntityTrix(String destinationUri){
40  super(destinationUri);
41  }
42 
43  /** Uri of entity */
44  private String entityUri;
45 
46  /** Type of entity */
47  private String entityType;
48 
49  /** Name of entity */
50  private String entityName;
51 
52  /** Graphical representation of entity */
53  private String imageUri;
54 
55  /** Description of entity */
56  private String description;
57 
58  /** List of entity additional attributes */
59  private ArrayList<P2EntityAdditionalTrix> entityAdditionalTrixAL;
60 
61  /**
62  * Sets Uri of entity
63  * @return The Uri of entity
64  */
65  public String getEntityUri() {
66  return entityUri;
67  }
68 
69  /**
70  * Gets Uri of entity
71  * @param entityUri The Uri of entity
72  */
73  public void setEntityUri(String entityUri) {
74  this.entityUri = entityUri;
75  }
76 
77  /**
78  * Gets type of entity
79  * @return The type of entity
80  */
81  public String getEntityType() {
82  return entityType;
83  }
84 
85  /**
86  * Sets type of entity
87  * @param entityType The type of entity
88  */
89  public void setEntityType(String entityType) {
90  this.entityType = entityType;
91  }
92 
93  /**
94  * Gets list of entity additional attributes
95  * @return The list of entity additional attributes
96  */
97  public ArrayList<P2EntityAdditionalTrix> getEntityAdditionalTrixAL() {
99  }
100 
101  /**
102  * Sets list of entity additional attributes
103  * @param entityAdditionalTrixAL The list of entity additional attributes
104  */
105  public void setEntityAdditionalTrixAL(ArrayList<P2EntityAdditionalTrix> entityAdditionalTrixAL) {
106  this.entityAdditionalTrixAL = entityAdditionalTrixAL;
107  }
108 
109  /**
110  * Gets name of entity
111  * @return the name of entity
112  */
113  public String getEntityName() {
114  return entityName;
115  }
116 
117  /**
118  * Sets name of entity
119  * @param entityName the entity name to set
120  */
121  public void setEntityName(String entityName) {
122  this.entityName = entityName;
123  }
124 
125  /**
126  * Gets graphical representation of entity
127  * @return the graphical representation of entity
128  */
129  public String getImageUri() {
130  return imageUri;
131  }
132 
133  /**
134  * Sets graphical representation of entity
135  * @param imageUri the graphical representation of entity to set
136  */
137  public void setImageUri(String imageUri) {
138  this.imageUri = imageUri;
139  }
140 
141  /**
142  * Gets description of entity
143  * @return the description of entity
144  */
145  public String getDescription() {
146  return description;
147  }
148 
149  /**
150  * Sets description of entity
151  * @param description the description of entity
152  */
153  public void setDescription(String description) {
154  this.description = description;
155  }
156 
157  @Override
158  public ArrayList<BaseAttribute> trixToAnnotAtt(Annotation annot, RequestInfo requestInfo, Integer sparePriority) {
159  ArrayList<BaseAttribute> atList = new ArrayList<BaseAttribute>();
160  ArrayList<EntityAdditionalAttribute> additionalAttributes = new ArrayList<EntityAdditionalAttribute>();
161 
162  /* Check if name is not empty */
163  if(name.isEmpty()){
164  int langNum = requestInfo.getSession().getLanguageNum();
165  int lod = requestInfo.getSession().getProtocolLOD();
166 
167  String info = "<attribute annotationUri=\"" + annot.getURIV2();
168  if(isFromOntology()){
169  info += "\" uri=\"" + uriInOntology;
170  }
171  else{
172  info += "\" name=\"" + name;
173  }
174  info += "\" invalidProperty=\"name\"/>";
175 
176  requestInfo.addError(lod, langNum, Localisation.ERROR_26_ATTRIBUTE_MALFORMED, info);
178  Logger.getLogger(P2EntityTrix.class.getName()).log(Level.SEVERE, null);
179  }
180  return null;
181  }
182 
183  EntityAttribute newAtt = new EntityAttribute();
184 
185 
186  newAtt.setName(name);
187  newAtt.setUriInOntology(uriInOntology);
188  newAtt.setRefAnnotation(annot);
189 
190 
191  newAtt.setUri(entityUri);
192  newAtt.setEntityType(entityType);
193  newAtt.setEntityVisualURI(searchEntityImage());
194  newAtt.setStringValue(searchEntityName());
195  newAtt.setTextValue(searchEntityDescription());
196 
197  /* Process priority */
198  Integer newPriority = null;
199  if(priority != null){
200  try{
201  newPriority = Integer.parseInt(priority);
202  }catch(NumberFormatException ex){
203  int langNum = requestInfo.getSession().getLanguageNum();
204  int lod = requestInfo.getSession().getProtocolLOD();
205 
206  String info = "<attribute annotationUri=\"" + annot.getURIV2();
207  if(isFromOntology()){
208  info += "\" uri=\"" + uriInOntology;
209  }
210  else{
211  info += "\" name=\"" + name;
212  }
213  info += "\" invalidProperty=\"priority\"/>";
214 
215  requestInfo.addError(lod, langNum, Localisation.ERROR_26_ATTRIBUTE_MALFORMED, info);
217  Logger.getLogger(P2EntityTrix.class.getName()).log(Level.SEVERE, null, ex);
218  }
219  return null;
220  }
221  }
222 
223  if(priority != null){
224  newAtt.setPriority(newPriority);
225  } else {
226  newAtt.setPriority(sparePriority);
227  }
228 
229  Iterator<P2EntityAdditionalTrix> addAttIt = entityAdditionalTrixAL.iterator();
230  while(addAttIt.hasNext()){
231  EntityAdditionalAttribute tmpAtt = makeEntityAdditionalAttribute(addAttIt.next(), newAtt);
232  additionalAttributes.add(tmpAtt);
233  }
234 
235  newAtt.setEntityAdditionalAttributes(additionalAttributes);
236 
237  atList.add(newAtt);
238  return atList;
239  }
240 
241  /**
242  * Method that creates entity additional attribute from trix
243  * @param trixAtt Entity additional trix
244  * @param entity Reference entity
245  * @return Entity additional attribute
246  */
249 
250  newAtt.setName(trixAtt.getEntityAttributeName());
251  newAtt.setStringValue(trixAtt.getValue());
252  newAtt.setRefEntityAttribute(entity);
254  if (trixAtt.getTypeUri() != null) {
255  int typeIndex = Constants.SIMPLE_TYPES_URIS_FOR_ENT_AD_AT.indexOf(trixAtt.getTypeUri());
256  if (typeIndex >= 0 && Constants.SIMPLE_TYPES_FOR_ENT_AD_AT.size() > typeIndex) {
257  newAtt.setType(Constants.SIMPLE_TYPES_FOR_ENT_AD_AT.get(typeIndex));
258  } else {
260  String msg = "Unknown type of entity additional attribute: " + trixAtt.getTypeUri();
261  Logger.getLogger(P2EntityTrix.class.getName()).log(Level.SEVERE, msg);
262  }
263  }
264  } else {
266  String msg = "Type of entity additional attribute is missing.";
267  Logger.getLogger(P2EntityTrix.class.getName()).log(Level.SEVERE, msg);
268  }
269  }
270 
271  return newAtt;
272  }
273 
274  private String searchEntityName(){
275  Iterator<P2EntityAdditionalTrix> it = entityAdditionalTrixAL.iterator();
276  String tmpName = null;
277  while(it.hasNext()){
278  P2EntityAdditionalTrix tmp = it.next();
279  if(tmp.getEntityAttributeName().equalsIgnoreCase("name")){
280  tmpName = tmp.getValue();
281  entityAdditionalTrixAL.remove(tmp);
282  break;
283  }
284  }
285 
286  return tmpName;
287  }
288 
289  private String searchEntityImage(){
290  Iterator<P2EntityAdditionalTrix> it = entityAdditionalTrixAL.iterator();
291  String tmpImage = null;
292  while(it.hasNext()){
293  P2EntityAdditionalTrix tmp = it.next();
294  if(tmp.getEntityAttributeName().equalsIgnoreCase("image")){
295  tmpImage = tmp.getValue();
296  entityAdditionalTrixAL.remove(tmp);
297  break;
298  }
299  }
300 
301  return tmpImage;
302  }
303 
304  private String searchEntityDescription(){
305  Iterator<P2EntityAdditionalTrix> it = entityAdditionalTrixAL.iterator();
306  String tmpDesc = null;
307  while(it.hasNext()){
308  P2EntityAdditionalTrix tmp = it.next();
309  if(tmp.getEntityAttributeName().equalsIgnoreCase("description")){
310  tmpDesc = tmp.getValue();
311  entityAdditionalTrixAL.remove(tmp);
312  break;
313  }
314  }
315 
316  return tmpDesc;
317  }
318 
319 }
Class that represents entity additional attribute trix triple.
EntityAdditionalAttribute makeEntityAdditionalAttribute(P2EntityAdditionalTrix trixAtt, EntityAttribute entity)
Class representing vocabulary entity attribute.
Base class representing attribute of annotation.
static final String DEFAULT_SIMPLE_TYPE_FOR_ENT_AD_AT
Definition: Constants.java:225
static final ArrayList< String > SIMPLE_TYPES_FOR_ENT_AD_AT
Definition: Constants.java:213
ArrayList< BaseAttribute > trixToAnnotAtt(Annotation annot, RequestInfo requestInfo, Integer sparePriority)
Processed informations about client request.
Class responsible for localised strings.
void setEntityAdditionalTrixAL(ArrayList< P2EntityAdditionalTrix > entityAdditionalTrixAL)