14 package cz.vutbr.fit.knot.annotations.comet;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.Iterator;
34 import java.util.List;
36 import java.util.Map.Entry;
37 import java.util.logging.Level;
38 import java.util.logging.Logger;
39 import javax.persistence.EntityManager;
40 import javax.persistence.EntityTransaction;
41 import javax.persistence.Query;
59 Flier flier = requestInfo.getFlier();
60 EntityManager em = AppBean.getPersistenceManager().getEM();
61 EntityTransaction transaction = em.getTransaction();
62 boolean errorOccurred =
false;
67 if (requestInfo.
getSettings() != null && !requestInfo.getSettings().isEmpty()) {
69 ArrayList<Settings> settings =
new ArrayList<Settings>();
70 Object[] params =
new Object[2];
72 params[1] = requestInfo.getSession().getUser().getId();
73 List sList = AppBean.getPersistenceManager().queryDB(
"Settings.findByUser", params);
74 if (sList != null && !sList.isEmpty()) {
75 Iterator sListIter = sList.iterator();
76 while (sListIter.hasNext()) {
77 settings.add((
Settings) sListIter.next());
84 Iterator<Settings> clientSettIt = requestInfo.getSettings().iterator();
86 while(clientSettIt.hasNext()){
87 Iterator<Settings> oldSettingIt = settings.iterator();
88 Settings clientTmpSett = clientSettIt.next();
92 while(oldSettingIt.hasNext()){
93 Settings oldSetting = oldSettingIt.next();
95 if((oldSetting.
getName()).equals(clientTmpSett.getName())){
98 if(clientTmpSett.getValue() != null){
99 oldSetting = em.merge(oldSetting);
100 oldSetting.setValue(clientTmpSett.getValue());
101 oldSetting.setDescription(clientTmpSett.getDescription());
105 oldSetting = em.merge(oldSetting);
106 em.remove(oldSetting);
114 if(clientTmpSett.getValue() != null)
115 em.persist(clientTmpSett);
121 Iterator<Settings> oldSettingsIter = settings.iterator();
122 while (oldSettingsIter.hasNext()) {
123 Settings param = oldSettingsIter.next();
124 param = em.merge(param);
129 Iterator<Settings> settingsIter = requestInfo.getSettings().iterator();
130 while (settingsIter.hasNext()) {
131 Settings param = settingsIter.next();
138 if(requestInfo.
getNewSubscriptions() != null && !requestInfo.getNewSubscriptions().isEmpty()){
139 ArrayList<Subscription> persistedSubscriptions =
new ArrayList<Subscription>();
140 Iterator<Subscription> subNewIter = requestInfo.getNewSubscriptions().iterator();
141 while (subNewIter.hasNext()) {
143 Integer savedTmpId = subscription.getTmpId();
144 subscription = em.merge(subscription);
145 em.persist(subscription);
146 subscription.setTmpId(savedTmpId);
147 persistedSubscriptions.add(subscription);
150 requestInfo.setNewSubscriptions(persistedSubscriptions);
151 requestInfo.getFlier().setNewSubscriptions(persistedSubscriptions);
156 ArrayList<Subscription> changedSubscriptions =
new ArrayList<Subscription>();
157 Iterator<Subscription> subChangeIter = requestInfo.getUpdatedSubscriptions().iterator();
158 while (subChangeIter.hasNext()){
162 Object[] params =
new Object[2];
164 params[1] = currentSub.getId();
165 @SuppressWarnings(
"unchecked")
166 List<Subscription> SubsList = AppBean.getPersistenceManager().queryDB(
"Subscription.findById", params);
167 if(SubsList == null || SubsList.isEmpty()){
173 requestInfo.addBeforeUpdatedSubscriptions(oldSub);
176 Iterator<Source> oldSourcesIt = oldSub.getSubscriptions().iterator();
177 while(oldSourcesIt.hasNext()){
178 Source currentSource = oldSourcesIt.next();
179 Source mergedSource = em.merge(currentSource);
180 em.remove(mergedSource);
184 em.merge(currentSub);
185 if(requestInfo.
getSession().isInSubscribeList(oldSub)){
186 requestInfo.addToUnsubscribe(oldSub);
187 requestInfo.addToSubscribe(oldSub);
189 requestInfo.getFlier().addChangedSubscription(currentSub);
195 ArrayList<Subscription> deletedSubscriptions =
new ArrayList<Subscription>();
196 Iterator<Subscription> subDeleteIter = requestInfo.getDeletedSubscriptions().iterator();
197 while (subDeleteIter.hasNext()) {
199 subscription = em.merge(subscription);
200 em.remove(subscription);
201 deletedSubscriptions.add(subscription);
203 if(requestInfo.
getSession().isInSubscribeList(subscription)){
204 requestInfo.addToUnsubscribe(subscription);
208 requestInfo.setDeletedSubscriptions(deletedSubscriptions);
213 requestInfo.getSession().setUser(em.merge(requestInfo.
getSession().getUser()));
214 Iterator<UserGroup> ugIter = requestInfo.getJoinedGroups().iterator();
215 while (ugIter.hasNext()) {
219 Iterator<UserGroup> lgIter = requestInfo.getLeavedGroups().iterator();
220 while (lgIter.hasNext()) {
229 em.persist(requestInfo.getSyncDocument());
231 em.merge(requestInfo.getSyncDocument());
235 em.merge(requestInfo.getSession().getSyncDocument());
241 ArrayList<AnnotType> nTWA =
new ArrayList<AnnotType>();
242 Map<String, AnnotType> nTMap =
new HashMap<String, AnnotType>();
243 for (Iterator<AnnotType> ntIt = flier.
getAddedTypes().iterator(); ntIt.hasNext();) {
246 nT.setRestrictedAtt(type.getRestrictedAtt());
247 nT.setUriInOntology(type.getUriInOntology());
248 nT.setComment(type.getComment());
250 nTMap.put(type.getUri(), type);
254 ArrayList<AnnotType> mergedTypes =
new ArrayList<AnnotType>();
255 Map<String, AnnotType> mTypesMap =
new HashMap<String, AnnotType>();
256 for (Iterator<AnnotType> nTWAIt = nTWA.iterator(); nTWAIt.hasNext();) {
258 type = em.merge(type);
259 mergedTypes.add(type);
260 mTypesMap.put(type.getUri(), type);
264 for (Iterator<AnnotType> mIt = mergedTypes.iterator(); mIt.hasNext();) {
266 AnnotType oType = nTMap.get(mType.getUri());
269 List<AnnotTypeAttr> aList = oType.getAttributes();
270 for (Iterator<AnnotTypeAttr> aIt = aList.iterator(); aIt.hasNext();) {
272 AnnotType aTAAT = aTA.getAttributeType();
275 AnnotType rType = mTypesMap.get(aTAAT.getUri());
279 aTA.setAttributeType(rType);
282 aTA.setAnnotationType(mTypesMap.get(aTA.getAnnotationType().getUri()));
284 mType.setAttributes(
new ArrayList<AnnotTypeAttr>(aList));
287 if (oType.getAncestorType() != null) {
289 AnnotType rType = mTypesMap.get(oType.getAncestorType().getUri());
291 rType =
queryType(oType.getAncestorType().getUri(), em);
293 mType.setAncestorType(rType);
297 ArrayList<AnnotType> newAncestors =
new ArrayList<AnnotType>();
298 for (Iterator<AnnotType> ancIt = oType.getAncestorTypes().iterator(); ancIt.hasNext();) {
300 AnnotType mAnc = mTypesMap.get(ancType.getUri());
304 newAncestors.add(mAnc);
306 mType.setAncestorTypes(newAncestors);
308 mType = em.merge(mType);
312 Iterator<AnnotType> editAnnotTypeIter = flier.getEditedTypes().iterator();
313 while (editAnnotTypeIter.hasNext()) {
314 AnnotType type = editAnnotTypeIter.next();
315 Query query = em.createNamedQuery(
"AnnotType.findById");
316 query.setParameter(
"id", type.getId());
317 List tList = query.getResultList();
318 if (tList == null || tList.isEmpty()) {
320 String msg =
"Edited type of annotation was not found by Persister: " + type.getUri();
321 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg);
323 throw new RuntimeException(
"Object not found.");
326 boolean differ =
false;
327 List<AnnotTypeAttr> attrs = pType.getAttributes();
328 Iterator<AnnotTypeAttr> attrIter = attrs.iterator();
329 Iterator<AnnotTypeAttr> newAttrIter = type.getAttributes().iterator();
330 while (attrIter.hasNext()) {
332 if (!newAttrIter.hasNext()) {
336 newAttr.setId(attr.getId());
340 ArrayList<AnnotType> newAnc =
new ArrayList<AnnotType>();
341 for (Iterator<AnnotType> ancIt = type.
getAncestorTypes().iterator(); ancIt.hasNext();) {
346 Object[] params =
new Object[2];
348 params[1] = ancT.getUri();
349 Query q = em.createNamedQuery(
"AnnotType.findByUri");
350 for (
int p = 0; p < params.length; p = p + 2) {
351 q.setParameter((String) params[p], params[p + 1]);
353 List aList = q.getResultList();
354 if (aList != null && !aList.isEmpty()) {
356 annotType = em.merge(annotType);
357 newAnc.add(annotType);
360 String msg =
"Ancestor type of annotaton was not found by Persister: " + ancT.getUri();
361 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg);
363 throw new RuntimeException(
"New type not found!");
366 ancT = em.merge(ancT);
371 type.setAncestorTypes(newAnc);
374 type = em.merge(type);
377 Iterator<AnnotType> delAnnotTypeIter = flier.getRemovedTypes().iterator();
378 while (delAnnotTypeIter.hasNext()) {
379 AnnotType type = delAnnotTypeIter.next();
380 type = em.merge(type);
385 ArrayList<Annotation> nowSavedAnnots =
new ArrayList<Annotation>();
386 ArrayList<Annotation> justSavedAnnots =
new ArrayList<Annotation>();
387 ArrayList<Annotation> nestedBeforeSave =
new ArrayList<Annotation>();
388 ArrayList<Annotation> nestedAfterSave =
new ArrayList<Annotation>();
389 HashMap<Annotation,ArrayList<BaseAttribute>> unSavedLinks =
new HashMap<Annotation, ArrayList<BaseAttribute>>();
390 Iterator<Annotation> addedAnnotIter = flier.getAddedAnnotations().iterator();
391 while (addedAnnotIter.hasNext()) {
392 Annotation annotation = addedAnnotIter.next();
394 updateTypes(annotation, em,
"New type of annotation was not found by Persister: ");
397 if (justSavedAnnots.contains(annotation)) {
401 saveTmpIdRefAnnotations(annotation, requestInfo, em, justSavedAnnots, nowSavedAnnots, nestedBeforeSave, nestedAfterSave, unSavedLinks);
404 flier.setAddedAnnotations(nowSavedAnnots);
407 Iterator<Annotation> naIt = nestedBeforeSave.iterator();
408 while (naIt.hasNext()) {
410 int ni = nestedBeforeSave.indexOf(a);
412 requestInfo.getFlier().addJustAddedAnnotation(
AppBean.
getBaseUri() +
"/temp/" + a.getTmpId(), sav.getURIV2());
415 Iterator<Annotation> editAnnotIter = flier.getEditedAnnotations().iterator();
416 while (editAnnotIter.hasNext()) {
419 updateTypes(annotation, em,
"New type of annotation for edited annotation was not found by Persister: ");
424 Iterator<Annotation> delAnnotIter = flier.getRemovedAnnotations().iterator();
425 while (delAnnotIter.hasNext()) {
427 annotation = em.merge(annotation);
428 em.remove(annotation);
434 Iterator<Annotation>addeAnnotIter = flier.getAddedAnnotations().iterator();
435 while(addeAnnotIter.hasNext()){
436 Annotation actualAnnot = addeAnnotIter.next();
439 Iterator<Annotation>edAnnotIter = flier.getEditedAnnotations().iterator();
440 while(edAnnotIter.hasNext()){
444 Iterator<Annotation>updatedAnnotIter = flier.getAutoUpdatedAnnotations().iterator();
445 while(updatedAnnotIter.hasNext()){
446 Annotation actualAnnot = updatedAnnotIter.next();
450 Iterator<SuggestionLogEntry>confirmedSuggIt = requestInfo.getConfirmedSuggestions().iterator();
451 while (confirmedSuggIt.hasNext()) {
453 Iterator<Annotation>aAnnotIter = nowSavedAnnots.iterator();
454 while (aAnnotIter.hasNext()) {
459 sle.setConfirmedVersion(addAn);
466 transaction.commit();
467 }
catch (Exception e) {
468 transaction.rollback();
470 String msg =
"Exception during the persisting of data.";
471 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg, e);
473 errorOccurred =
true;
480 Object[] params =
new Object[2];
482 params[1] = requestInfo.getSession().getUser().getId();
483 List uList = AppBean.getPersistenceManager().queryDB(
"User.findById", params);
484 if (uList != null && !uList.isEmpty()) {
485 requestInfo.getSession().setUser((
User) uList.get(0));
486 requestInfo.getSession().actualizeAllCachedSettings();
490 return errorOccurred;
500 List attrList = annot.getAttributes();
501 Iterator attrIt = attrList.iterator();
502 while(attrIt.hasNext()){
506 attr = AttributeManager.changeAttributeInstance(attr);
533 Query query = em.createNamedQuery(
"Annotation.findById");
534 query.setParameter(
"id", annotation.getId());
535 List aList = query.getResultList();
536 if (aList == null || aList.isEmpty()) {
538 String msg =
"Updated annotation was not found by the Persister.";
539 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg);
541 throw new RuntimeException(
"Object not found.");
545 List<Fragment> fragments = a.getFragments();
546 Iterator<Fragment> frIter = fragments.iterator();
547 Iterator<Fragment> newFrIter = annotation.getFragments().iterator();
548 while (frIter.hasNext()) {
550 if (!newFrIter.hasNext()) {
554 newFr.setId(fr.getId());
558 List attrs = a.getAttributes();
559 List newAttrs = annotation.getAttributes();
560 Iterator attrsIt = attrs.iterator();
563 HashMap<Integer, Annotation> nestedAnnots =
new HashMap<Integer, Annotation>();
564 ArrayList<Integer> updatedNested =
new ArrayList<Integer>();
565 ArrayList<BaseAttribute> newNested =
new ArrayList<BaseAttribute>();
567 while (attrsIt.hasNext()) {
570 nestedAnnots.put(attr.getNestedAnnotation().getId(), attr.getNestedAnnotation());
585 attrsIt = attrs.iterator();
586 Iterator newAttrsIt = newAttrs.iterator();
589 while (attrsIt.hasNext()) {
591 attr.setNestedAnnotation(null);
594 ArrayList<BaseAttribute> empty =
new ArrayList<BaseAttribute>();
595 a.setAttributes(empty);
600 while (newAttrsIt.hasNext()) {
606 newAttrsIt = newAttrs.iterator();
609 while (newAttrsIt.hasNext()) {
613 Annotation lost = nestedAnnots.get(newAttr.getNestedAnnotation().getId());
614 updatedNested.add(lost.getId());
615 newAttr.getNestedAnnotation().setId(lost.
getId());
617 newAttr.getNestedAnnotation().setNestedInAnnot(a);
619 newAttr.getNestedAnnotation().setNestedInAnnot(a);
620 newNested.add(newAttr);
635 Iterator<Entry<Integer,Annotation>> lIter = nestedAnnots.entrySet().iterator();
636 while (lIter.hasNext()) {
638 if(!updatedNested.contains(lAnnot.
getId())){
639 requestInfo.getFlier().AddRemovedNestedAnnotation(lAnnot);
645 Iterator<BaseAttribute> newNestedIt = newNested.iterator();
646 while (newNestedIt.hasNext()) {
649 String nNUri = AppBean.getBaseUri() +
"/temp/" + newNestedAt.
getNestedAnnotation().getTmpId();
650 Annotation newN = em.merge(newNestedAt.getNestedAnnotation());
651 newNestedAt.setNestedAnnotation(newN);
653 requestInfo.getFlier().addJustAddedAnnotation(nNUri, newN.getURIV2());
654 requestInfo.getFlier().getAddedAnnotations().add(newN);
660 if(annotation.getNestedInAnnot() == null && a.getNestedInAnnot() != null){
661 annotation.setNestedInAnnot(a.getNestedInAnnot());
663 ArrayList<Annotation> editedInFlier = requestInfo.getFlier().getEditedAnnotations();
664 if(editedInFlier.contains(annotation)){
665 editedInFlier.remove(annotation);
667 while(parent.getNestedInAnnot() != null){
668 parent = parent.getNestedInAnnot();
670 editedInFlier.add(parent);
678 annotation.setAttributes(
new ArrayList<BaseAttribute>(mergenAn.getAttributes()));
691 Object[] params =
new Object[2];
694 Query q = em.createNamedQuery(
"AnnotType.findByUri");
695 for (
int p = 0; p < params.length; p = p + 2) {
696 q.setParameter((String) params[p], params[p + 1]);
698 List aList = q.getResultList();
699 if (aList != null && !aList.isEmpty()) {
703 String msg =
"Queried type of annotation was not found by the Persister: " + uri;
704 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg);
706 throw new RuntimeException(
"New type not found!");
718 Flier flier = requestInfo.getFlier();
719 EntityManager em = AppBean.getPersistenceManager().getEM();
720 EntityTransaction transaction = em.getTransaction();
721 boolean errorOccurred =
false;
725 Iterator<Annotation> autoUpdAnnotIter = flier.getAutoUpdatedAnnotations().iterator();
726 while (autoUpdAnnotIter.hasNext()) {
727 Annotation annotation = autoUpdAnnotIter.next();
731 annotation.setAnnotType(annotType);
733 Iterator<BaseAttribute> attIt = annotation.getAttributes().iterator();
734 while (attIt.hasNext()) {
742 Object[] params =
new Object[2];
744 params[1] = att.getAttributeType().getUri();
745 Query attTypeQuery = em.createNamedQuery(
"AnnotType.findByUri");
746 attTypeQuery.setParameter((String) params[0], params[1]);
748 List typeList = attTypeQuery.getResultList();
750 if (typeList != null && !typeList.isEmpty()) {
752 att.setAttributeType((
AnnotType)typeList.get(0));
761 transaction.commit();
762 }
catch (Exception e) {
763 transaction.rollback();
765 String msg =
"Exception during the persisting of automatically updated annotations.";
766 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg, e);
768 errorOccurred =
true;
773 return errorOccurred;
783 Iterator<BaseAttribute> aIt = annotation.getAttributes().iterator();
784 while (aIt.hasNext()) {
786 Annotation nested = attribute.getNestedAnnotation();
787 if (nested != null) {
788 if (nested.getAnnotType().getId() == null) {
791 nested.setAnnotType(annotType);
793 Iterator<BaseAttribute> attIt = annotation.getAttributes().iterator();
794 while (attIt.hasNext()) {
802 Object[] params =
new Object[2];
804 params[1] = att.getAttributeType().getUri();
805 Query attTypeQuery = em.createNamedQuery(
"AnnotType.findByUri");
806 attTypeQuery.setParameter((String) params[0], params[1]);
808 List typeList = attTypeQuery.getResultList();
810 if (typeList != null && !typeList.isEmpty()) {
812 att.setAttributeType((
AnnotType)typeList.get(0));
832 List attrList = annot.getAttributes();
833 Iterator attrIt = attrList.iterator();
834 while(attrIt.hasNext()){
838 if (val.
getId() == null) {
840 attr.setValue(annot4update);
841 if(annot4update != null){
842 attr.setUri(annot4update.getURI());
843 attr.setAttributeType(annot4update.getAnnotType());
850 if(annot.getId() == null && annot.getNestedInAnnot() == null){
851 updateTypes(annot, em,
"New type of annotation for tmpId linked annotation was not found by Persister: ");
853 saved = em.merge(annot);
855 saved.setTmpId(annot.getTmpId());
875 ArrayList<Annotation> justSaved, ArrayList<Annotation> nowSaved,
876 ArrayList<Annotation> nestedBeforeSave, ArrayList<Annotation> nestedAfterSave,
877 HashMap<
Annotation,ArrayList<BaseAttribute>> unSavedLinks) throws RuntimeException {
879 Iterator<Entry<Annotation,ArrayList<BaseAttribute>>> unsavedIt = unSavedLinks.entrySet().iterator();
880 while(unsavedIt.hasNext()){
881 Entry<Annotation,ArrayList<BaseAttribute>> entry = unsavedIt.next();
883 Iterator<BaseAttribute> solvedLinksIt = entry.getValue().iterator();
885 Integer nowSavedIndex = null;
886 Integer nestedIndex = null;
888 if(solvedAnnot.getId() == null){
889 if(nestedBeforeSave.contains(solvedAnnot)){
890 nestedIndex = nestedBeforeSave.indexOf(solvedAnnot);
891 solvedAnnot = nestedAfterSave.get(nestedIndex);
898 nowSavedIndex = nowSaved.indexOf(solvedAnnot);
901 if(solvedAnnot != null){
903 while(solvedLinksIt.hasNext()){
906 attr.setRefAnnotation(solvedAnnot);
907 if(justSaved.contains(link)){
908 int index = justSaved.indexOf(link);
909 Annotation annot4update = nowSaved.get(index);
910 attr.setValue(annot4update);
911 if(annot4update != null){
912 attr.setUri(annot4update.getURI());
913 attr.setAttributeType(annot4update.getAnnotType());
916 else if(nowSaved.contains(link) || nestedAfterSave.contains(link)){
919 attr.setUri(link.getURI());
920 attr.setAttributeType(link.getAnnotType());
923 else if(nestedBeforeSave.contains(link)){
924 int index = nestedBeforeSave.indexOf(link);
925 Annotation annot4update = nestedAfterSave.get(index);
926 attr.setValue(annot4update);
927 if(annot4update != null){
928 attr.setUri(annot4update.getURI());
929 attr.setAttributeType(annot4update.getAnnotType());
936 solvedAnnot.addAttribute(attr);
939 Annotation afterMerge = em.merge(solvedAnnot);
943 if(nowSavedIndex != null){
944 nowSaved.set((int)nowSavedIndex, afterMerge);
946 else if(nestedIndex != null){
947 nestedAfterSave.set((int)nestedIndex, afterMerge);
954 Iterator<SuggestionLogEntry> confirmedIt = requestInfo.getConfirmedSuggestions().iterator();
955 while(confirmedIt.hasNext()){
958 int index = nestedBeforeSave.indexOf(sugLog.getConfirmedVersion());
959 sugLog.setConfirmedVersion(nestedAfterSave.get(index));
979 ArrayList<Annotation> justSaved, ArrayList<Annotation> nowSaved,
980 ArrayList<Annotation> nested4Links, ArrayList<Annotation> nested4LinksFromDB,
981 HashMap<
Annotation,ArrayList<BaseAttribute>> unSavedLinks) throws RuntimeException {
983 ArrayList<BaseAttribute> annotLinks =
new ArrayList<BaseAttribute>();
984 List attrList = annot.getAttributes();
985 Iterator attrIt = attrList.iterator();
986 while(attrIt.hasNext()){
991 if (nowSaved.contains(val) || nested4LinksFromDB.contains(val) || val.
getId() == null) {
992 annotLinks.add(attr);
996 nested4Links.add(attr.getNestedAnnotation());
1000 if(annot.
getId() == null && annot.getNestedInAnnot() == null){
1001 updateTypes(annot, em,
"New type of annotation for tmpId linked annotation was not found by Persister: ");
1003 saved = em.merge(annot);
1005 saved.setTmpId(annot.getTmpId());
1006 justSaved.add(annot);
1007 nowSaved.add(saved);
1015 if(unSavedLinks != null && !annotLinks.isEmpty()){
1017 unSavedLinks.put(saved, annotLinks);
1020 unSavedLinks.put(annot, annotLinks);
1033 Iterator<BaseAttribute> nowSavedAttrIt = saved.getAttributes().iterator();
1034 while(nowSavedAttrIt.hasNext()){
1037 Annotation nestedAnnotation = savedAttribute.getNestedAnnotation();
1038 nested4LinksFromDB.add(nestedAnnotation);
1054 Object[] params =
new Object[2];
1056 params[1] = annotation.getAnnotType().getUri();
1057 Query q = em.createNamedQuery(
"AnnotType.findByUri");
1058 for (
int p = 0; p < params.length; p = p + 2) {
1059 q.setParameter((String) params[p], params[p + 1]);
1061 List aList = q.getResultList();
1062 if (aList != null && !aList.isEmpty()) {
1064 annotation.setAnnotType(annotType);
1066 Iterator<BaseAttribute> attIt = annotation.getAttributes().iterator();
1067 while (attIt.hasNext()) {
1075 params[1] = att.getAttributeType().getUri();
1076 Query attTypeQuery = em.createNamedQuery(
"AnnotType.findByUri");
1077 attTypeQuery.setParameter((String) params[0], params[1]);
1079 List typeList = attTypeQuery.getResultList();
1081 if (typeList != null && !typeList.isEmpty()) {
1083 att.setAttributeType((
AnnotType)typeList.get(0));
1089 String msg = logMsg + annotation.getAnnotType().getUri();
1090 Logger.getLogger(Persister.class.getName()).log(Level.SEVERE, msg);
1092 throw new RuntimeException(
"New type not found!");
1103 Flier flier = requestInfo.getFlier();
1106 Iterator<Annotation> addedIt = flier.getAddedAnnotations().iterator();
1107 while(addedIt.hasNext()){
1109 Iterator attrIt = annot.getAttributes().iterator();
1110 while(attrIt.hasNext()){
1112 if(attr.
getSimpleType().equals(
"AnnotationLink") && tmpId != null &&
1115 attr.setValue(newLink);
1116 if(newLink != null){
1117 attr.setAttributeType(newLink.getAnnotType());
1127 Iterator<Annotation> editedIt = flier.getEditedAnnotations().iterator();
1128 while(editedIt.hasNext()){
1130 Iterator attrIt = annot.getAttributes().iterator();
1131 while(attrIt.hasNext()){
1133 if(attr.
getSimpleType().equals(
"AnnotationLink") && tmpId != null &&
1136 attr.setValue(newLink);
1137 if(newLink != null){
1138 attr.setAttributeType(newLink.getAnnotType());
1148 Iterator<SuggestionLogEntry> suggIt = requestInfo.getConfirmedSuggestions().iterator();
1149 while(suggIt.hasNext()){
1151 Annotation annot = suggest.getConfirmedVersion();
1152 Iterator attrIt = annot.getAttributes().iterator();
1153 while(attrIt.hasNext()){
1155 if(attr.
getSimpleType().equals(
"AnnotationLink") && tmpId != null &&
1158 attr.setValue(newLink);
1159 if(newLink != null){
1160 attr.setAttributeType(newLink.getAnnotType());
1179 Iterator<BaseAttribute> aIt = nestedAnn.getAttributes().iterator();
1180 while (aIt.hasNext()) {
1182 if(attribute.
getSimpleType().equals(
"AnnotationLink") && tmpId != null && !tmpId.isEmpty() &&
1185 attribute.setValue(newLink);
1186 if(newLink != null){
1187 attribute.setAttributeType(newLink.getAnnotType());
Static class which persists data to the database.
Class representing subscription.
Annotation getNestedAnnotation()
ArrayList< Subscription > getUpdatedSubscriptions()
static String getBaseUri()
static Annotation saveTmpIdRefAnnotations(Annotation annot, RequestInfo requestInfo, EntityManager em, ArrayList< Annotation > justSaved, ArrayList< Annotation > nowSaved, ArrayList< Annotation > nested4Links, ArrayList< Annotation > nested4LinksFromDB, HashMap< Annotation, ArrayList< BaseAttribute >> unSavedLinks)
Class representing attribute of type of annotation.
Annotation getConfirmedVersion()
Class representing attribute of type NestedAnnotation.
static boolean persist(RequestInfo requestInfo)
static final int LOG_LEVEL_SERVER_INTERNAL_ERRORS
Singleton for storing global variables.
static void updateTypesInNested(Annotation annotation, EntityManager em)
static void updateTmpIdRefInNested(String tmpId, Annotation nestedAnn, Annotation newLink)
ArrayList< UserGroup > getLeavedGroups()
static void setUriOfAnnotationsParams(Annotation annot)
Class representing attribute of type AnnotationLink.
Suggested annotation with informations about suggestion.
Class representing user group.
static boolean hasAttributeRightInstance(BaseAttribute attr)
Class representing parameter of user settings.
static boolean persistAUpdAnnot(RequestInfo requestInfo)
AnnotType getAttributeType()
ArrayList< UserGroup > getJoinedGroups()
static void addNewReferenceOnNestedAnnotation(Annotation saved, ArrayList< Annotation > nested4LinksFromDB)
Base class representing attribute of annotation.
static AnnotType queryType(String uri, EntityManager em)
static final int LOG_LEVEL
Class representing type of annotation.
static void saveTmpIdRefAnnotationsSolveLinks(RequestInfo requestInfo, EntityManager em, ArrayList< Annotation > justSaved, ArrayList< Annotation > nowSaved, ArrayList< Annotation > nestedBeforeSave, ArrayList< Annotation > nestedAfterSave, HashMap< Annotation, ArrayList< BaseAttribute >> unSavedLinks)
Flier with informations for comet handlers.
EditorSession getSession()
ArrayList< Subscription > getDeletedSubscriptions()
static void updateTypes(Annotation annotation, EntityManager em, String logMsg)
boolean isDocumentChanged()
static final int LOG_LEVEL_SERVER_ERRORS
static final int PROTOCOL_LOD_V2
AnnotDocument getSyncDocument()
Class attribute manager provides a way how to create new attributes.
Processed informations about client request.
static void updateAnnot(EntityManager em, Annotation annotation, RequestInfo requestInfo)
ArrayList< Subscription > getNewSubscriptions()
ArrayList< AnnotType > getAddedTypes()
Class representing annotated fragment.
Class representing annotation.
Class representing source of subscription.
static Annotation saveTmpIdRefAnnotations(Annotation annot, RequestInfo requestInfo, EntityManager em)
List< AnnotType > getAncestorTypes()
ArrayList< Settings > getSettings()
static void updateTmpIdRefInAddedEditedASuggested(String tmpId, Annotation newLink, RequestInfo requestInfo)