16 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0;
 
   27 import java.util.ArrayList;
 
   28 import java.util.Iterator;
 
   29 import java.util.List;
 
   30 import java.util.logging.Level;
 
   31 import java.util.logging.Logger;
 
   32 import org.w3c.dom.Element;
 
   33 import org.w3c.dom.NodeList;
 
   61     NodeList annotationsMsg = addAnnotationsEl.getElementsByTagName(
"oa:Annotation");
 
   62     int annotCount = annotationsMsg.getLength();
 
   63     ArrayList<Annotation> annotsToAdd = 
new ArrayList<Annotation>();
 
   67     for(
int index = 0; index < annotCount; index++){
 
   68       Element annotationEl = (Element) annotationsMsg.item(index);
 
   69       if(annotationEl != null) {
 
   71         if(newAnnotation != null){
 
   72           annotsToAdd.add(newAnnotation);
 
   78     requestInfo.getFlier().setAddedAnnotations(annotsToAdd);
 
   88     NodeList annotationsMsg = changeAnnotationsEl.getElementsByTagName(
"oa:Annotation");
 
   89     int annotCount = annotationsMsg.getLength();
 
   90     ArrayList<Annotation> annotsToChange = 
new ArrayList<Annotation>();
 
   94     for(
int index = 0; index < annotCount; index++){
 
   95       Element annotationEl = (Element) annotationsMsg.item(index);
 
   96       if(annotationEl != null) {
 
   98         if(changedAnnotation != null){
 
   99           annotsToChange.add(changedAnnotation);
 
  105     requestInfo.getFlier().setEditedAnnotations(annotsToChange);
 
  115     NodeList annotationsMsg = deleteAnnotationsEl.getElementsByTagName(
"annotation");
 
  116     int annotCount = annotationsMsg.getLength();
 
  119     for(
int index = 0; index < annotCount; index++){
 
  120       Element annotationEl = (Element) annotationsMsg.item(index);
 
  121       if(annotationEl != null) {
 
  123         if(actualAnnot == null){
 
  127         requestInfo.getFlier().AddRemovedAnnotation(actualAnnot);
 
  143     Iterator<Annotation> connectIt = annotsToConnect.iterator();
 
  144     while(connectIt.hasNext()){
 
  151         Iterator<BaseAttribute> attributesIt = actualAnnot.getAttributes().iterator();
 
  152         while (attributesIt.hasNext()) {
 
  157             if (actualAttribute.
getUri() != null && !actualAttribute.getUri().isEmpty()) {
 
  159               String annotUri = actualAttribute.getUri();
 
  163                 if (uriType.equals(
"temp")) {
 
  165                   if (findedAnnot == null) {
 
  169                       if(findedAnnot == null){
 
  171                         int langNum = requestInfo.getSession().getLanguageNum();
 
  172                         int lod = requestInfo.getSession().getProtocolLOD();
 
  173                         String info = 
"<attribute annotationUri=\"" + actualAnnot.getURIV2() 
 
  175                                     + 
"\" name=\"" + actualAttribute.getName() 
 
  176                                     + 
"\" name=\"" + actualAttribute.
getName() 
 
  177                                     + 
"\" valueType=\"" + actualAttribute.getValueType() 
 
  178                                     + 
"\" type=\"" + actualAttribute.
getTypeUriV2() + 
"\"/>";
 
  181                             String msg = 
"Link to unknown annotation:" + actualAttribute.getUri() + 
"";
 
  182                             Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  187                       int langNum = requestInfo.getSession().getLanguageNum();
 
  188                       int lod = requestInfo.getSession().getProtocolLOD();
 
  189                       String info = 
"<attribute annotationUri=\"" + actualAnnot.getURIV2() 
 
  191                                   + 
"\" name=\"" + actualAttribute.getName() 
 
  193                                   + 
"\" type=\"" + actualAttribute.getTypeUriV2() + 
"\"/>";
 
  196                         String msg = 
"Link to unknown annotation:" + actualAttribute.getUri() + 
"";
 
  197                         Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  201                   actualAttribute.setLinkedAnnotation(findedAnnot);
 
  202                 } 
else if (uriType.equals(
"serv")) {
 
  204                   if (findedAnnot == null) {
 
  206                     String idString = annotUri.replace(AppBean.getBaseUri() + 
"/serv/",
"");
 
  208                       id = Integer.decode(idString);
 
  209                     } 
catch (NumberFormatException ex) {
 
  211                       int langNum = requestInfo.getSession().getLanguageNum();
 
  212                       int lod = requestInfo.getSession().getProtocolLOD();
 
  213                       String info = 
"<attribute annotationUri=\"" + actualAnnot.getURIV2() 
 
  215                                     + 
"\" name=\"" + actualAttribute.getName() 
 
  217                                     + 
"\" type=\"" + actualAttribute.getTypeUriV2() + 
"\"/>";
 
  220                         String msg = 
"Cannot decode id of annotation:" + idString + 
"";
 
  221                         Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  224                       PersistM persistMan = AppBean.getPersistenceManager();
 
  226                       Object[] annotParams = 
new Object[2];
 
  227                       annotParams[0] = 
"id";
 
  229                       @SuppressWarnings(
"unchecked")
 
  230                       List<Annotation> annotList = persistMan.queryDB(
"Annotation.findById", annotParams);
 
  231                       if(annotList == null || annotList.isEmpty()){
 
  233                         int langNum = requestInfo.getSession().getLanguageNum();
 
  234                         int lod = requestInfo.getSession().getProtocolLOD();
 
  235                         String info = 
"<attribute annotationUri=\"" + actualAnnot.getURIV2() 
 
  237                                     + 
"\" name=\"" + actualAttribute.getName() 
 
  239                                     + 
"\" type=\"" + actualAttribute.getTypeUriV2() + 
"\"/>";
 
  242                           String msg = 
"Linked annotation is't presented in DB. Annotation id:" + idString + 
"";
 
  243                           Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  248                       LinkedAnnotationAttribute actualLinked = (LinkedAnnotationAttribute)actualAttribute;
 
  249                       actualLinked.setValue(annotList.get(0));
 
  250                       actualLinked.setAttributeType(annotList.get(0).getAnnotType());
 
  253                     actualAttribute.setLinkedAnnotation(findedAnnot);
 
  261             NestedAnnotationAttribute nestedAttr = (NestedAnnotationAttribute) actualAttribute;
 
  262             if (actualAttribute.
getUri() != null && !actualAttribute.getUri().isEmpty()) {
 
  266               if (findedAnnot == null) {
 
  269               if (findedAnnot == null) {
 
  272               if (findedAnnot != null) {
 
  273                 actualAttribute.setNestedAnnotation(findedAnnot);
 
  274                 findedAnnot.setNestedInAnnot(actualAnnot);
 
  305     if (newAnnotation != null) {
 
  306       Integer annotID =  newAnnotation.getId();
 
  309       if (annotID != null) {
 
  311         PersistM persistMan = AppBean.getPersistenceManager();
 
  314         Object[] params = 
new Object[2];
 
  317         @SuppressWarnings(
"unchecked")
 
  318         List<Annotation> annotList = persistMan.queryDB(
"Annotation.findById", params);
 
  319         if (annotList != null && !annotList.isEmpty()) {
 
  320           findedAnnot = annotList.get(0);
 
  323           int langNum = requestInfo.getSession().getLanguageNum();
 
  324           int lod = requestInfo.getSession().getProtocolLOD();
 
  325           String info = 
"<annotation uri=\"" + newAnnotation.getURIV2() + 
"\"/>";
 
  328             String msg = 
"Annotation is't presented in DB. Annotation id:" + annotID.toString() + 
"";
 
  329             Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  334         newAnnotation.setId(findedAnnot.getId());
 
  338     return newAnnotation;
 
  350     String uri = annotationEl.getAttribute(
"uri");
 
  351     if(uri == null || uri.isEmpty()){
 
  353       int langNum = requestInfo.getSession().getLanguageNum();
 
  354       int lod = requestInfo.getSession().getProtocolLOD();
 
  355       String info = 
"<annotation uri=\"\"/>";
 
  358         String msg = 
"Uri of annotation is wrong.";
 
  359         Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  364     Integer annotId = null;
 
  367       annotId = Integer.decode(uri.replace(AppBean.getBaseUri() + 
"/serv/", 
""));
 
  368     } 
catch(NumberFormatException ex){
 
  370       int langNum = requestInfo.getSession().getLanguageNum();
 
  371       int lod = requestInfo.getSession().getProtocolLOD();
 
  372       String info = 
"<annotation uri=\"" + uri + 
"\"/>";
 
  375         String msg = 
"Id of annotation is wrong.";
 
  376         Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  382     PersistM persistMan = AppBean.getPersistenceManager();
 
  384     Object[] params = 
new Object[2];
 
  387     @SuppressWarnings(
"unchecked")
 
  388     List<Annotation> annotList = persistMan.queryDB(
"Annotation.findById", params);
 
  389     if(annotList != null && !annotList.isEmpty()) {
 
  390       deleteAnnotation = annotList.get(0);
 
  393       int langNum = requestInfo.getSession().getLanguageNum();
 
  394       int lod = requestInfo.getSession().getProtocolLOD();
 
  395       String info = 
"<annotation uri=\"" + uri + 
"\"/>";
 
  398         String msg = 
"Unable to find annotation to delete.";
 
  399         Logger.getLogger(P2AnnotationProcessor.class.getName()).log(Level.ALL, msg);
 
  404     return deleteAnnotation;
 
  415     Iterator<Annotation> annotsIt = annots.iterator();
 
  416     while(annotsIt.hasNext()){
 
  418       if(currentAnnot.
getTmpId() != null && uri.equals(AppBean.getBaseUri() + 
"/temp/" + currentAnnot.
getTmpId())){
 
  433     Iterator<Annotation> annotsIt = annots.iterator();
 
  434     while(annotsIt.hasNext()){
 
  436       if(currentAnnot.
getId() != null && uri.equals(AppBean.getBaseUri() + 
"/serv/" + currentAnnot.
getId())){
 
void connectAnnotations(ArrayList< Annotation > annotsToConnect, ArrayList< Annotation > added)
static final int LOG_LEVEL_ALL_ERRORS
Persistence manager (database manipulator) 
Annotation procesAnnotDelete(Element annotationEl, RequestInfo requestInfo)
Class representing attribute of type NestedAnnotation. 
Singleton for storing global variables. 
Class representing attribute of type AnnotationLink. 
static final int ERROR_30_REM_ANNOT_NOT_FOUND
Annotation procesAnnotAdd(Element annotationEl, RequestInfo requestInfo)
Abstract class provides a parser for the annotation of protocol version 2. 
Annotation findAnnotByServUri(ArrayList< Annotation > annots, String uri)
Annotation procesAnnotChange(Element annotationEl, RequestInfo requestInfo)
String getUriInOntology()
Annotation processAnnotation(Element annotationEl, RequestInfo requestInfo)
Base class representing attribute of annotation. 
static final int LOG_LEVEL
void processDeleteAnnotations(Element deleteAnnotationsEl, RequestInfo requestInfo)
Class which parses and process XML with messages with annotations for protocol version 2...
void processChangeAnnotations(Element changeAnnotationsEl, RequestInfo requestInfo)
static final int ERROR_29_CHANGED_ANNOT_NOT_FOUND
Processed informations about client request. 
void processAddAnnotations(Element addAnnotationsEl, RequestInfo requestInfo)
Annotation getLinkedAnnotation()
static final int ERROR_7_ATTRIBUTE_VALUE
Class responsible for localised strings. 
Annotation findAnnotByTempUri(ArrayList< Annotation > annots, String uri)
List< BaseAttribute > getAttributes()
Class representing annotation. 
static String getUriType(String uri)