Changeset 5529
- Timestamp:
- 07/04/08 14:59:37 (2 months ago)
- Location:
- trunk/SRC/org/openmicroscopy/shoola
- Files:
-
- 2 modified
-
agents/metadata/editor/TagsUI.java (modified) (1 diff)
-
env/data/OmeroMetadataServiceImpl.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/org/openmicroscopy/shoola/agents/metadata/editor/TagsUI.java
r5498 r5529 1025 1025 TagAnnotationData tag = (TagAnnotationData) comp.getAnnotation(); 1026 1026 tag.setTagDescription((String) evt.getNewValue()); 1027 //Need to check if 1028 1029 1027 1030 addedTags.add(tag); 1028 1031 firePropertyChange(EditorControl.SAVE_PROPERTY, Boolean.FALSE, -
trunk/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataServiceImpl.java
r5519 r5529 103 103 } 104 104 105 /** 106 * Prepares the annotation to add. 107 * 108 * @param toAdd The collection of annotation to prepare. 109 * @return See above. 110 * @throws DSOutOfServiceException If the connection is broken, or logged in 111 * @throws DSAccessException If an error occured while trying to 112 * retrieve data from OMEDS service. 113 */ 114 private List<AnnotationData> prepareAnnotationToAdd( 115 List<AnnotationData> toAdd) 116 throws DSOutOfServiceException, DSAccessException 117 { 118 List<AnnotationData> annotations = new ArrayList<AnnotationData>(); 119 Iterator i; 120 if (toAdd == null || toAdd.size() == 0) return annotations; 121 i = toAdd.iterator(); 122 AnnotationData ann; 123 Annotation iobject = null; 124 FileAnnotationData fileAnn; 125 FileAnnotation fa; 126 OriginalFile of; 127 List<Annotation> toCreate = new ArrayList<Annotation>(); 128 List<IObject> links = new ArrayList<IObject>(); 129 TextualAnnotationData desc; 130 TagAnnotationData tag; 131 IObject link = null; 132 Map map = (new PojoOptions()).map(); 133 while (i.hasNext()) { 134 ann = (AnnotationData) i.next(); 135 if (ann.getId() < 0) { 136 if (ann instanceof FileAnnotationData) { 137 fileAnn = (FileAnnotationData) ann; 138 of = gateway.uploadFile(fileAnn.getAttachedFile(), 139 fileAnn.getServerFileFormat()); 140 fa = new FileAnnotation(); 141 fa.setFile(of); 142 iobject = fa; 143 } else { 144 if (ann instanceof TagAnnotationData) { 145 IObject r = gateway.createObject( 146 ModelMapper.createAnnotation(ann), map); 147 tag = (TagAnnotationData) ann; 148 desc = tag.getTagDescription(); 149 if (desc != null) { 150 link = ModelMapper.createAnnotationAndLink(r, desc); 151 if (link != null) 152 gateway.createObject(link, map); 153 } 154 annotations.add( 155 (AnnotationData) PojoMapper.asDataObject(r)); 156 } else 157 iobject = ModelMapper.createAnnotation(ann); 158 } 159 if (iobject != null) 160 toCreate.add(iobject); 161 162 } else { 163 if (ann instanceof TagAnnotationData) { 164 // update description 165 tag = (TagAnnotationData) ann; 166 updateAnnotationData(tag); 167 } 168 annotations.add(ann); 169 } 170 171 } 172 173 if (toCreate.size() > 0) { 174 i = toCreate.iterator(); 175 IObject[] array = new IObject[toCreate.size()]; 176 int index = 0; 177 while (i.hasNext()) { 178 array[index] = (IObject) i.next(); 179 index++; 180 } 181 IObject[] r = gateway.createObjects(array, 182 (new PojoOptions()).map()); 183 annotations.addAll(PojoMapper.asDataObjects(r)); 184 } 185 if (links.size() > 0) { 186 i = links.iterator(); 187 IObject[] array = new IObject[links.size()]; 188 int index = 0; 189 while (i.hasNext()) { 190 array[index] = (IObject) i.next(); 191 index++; 192 } 193 gateway.createObjects(array, (new PojoOptions()).map()); 194 } 195 return annotations; 196 } 197 198 /** 199 * Links the annotation and the data object. 200 * 201 * @param data The data object to annotate. 202 * @param annotation The annotation to link. 203 * @throws DSOutOfServiceException If the connection is broken, or logged in 204 * @throws DSAccessException If an error occured while trying to 205 * retrieve data from OMEDS service. 206 */ 207 private void linkAnnotation(DataObject data, AnnotationData annotation) 208 throws DSOutOfServiceException, DSAccessException 209 { 210 Class ioType = gateway.convertPojos(data.getClass()); 211 IObject ho = gateway.findIObject(ioType, data.getId()); 212 ModelMapper.unloadCollections(ho); 213 ILink link = null; 214 boolean exist = false; 215 IObject annObject; 216 if (annotation instanceof TagAnnotationData) { 217 TagAnnotationData tag = (TagAnnotationData) annotation; 218 // tag a tag 219 if (TagAnnotationData.class.equals(data.getClass())) { 220 annObject = tag.asIObject(); 221 ModelMapper.unloadCollections(annObject); 222 link = (ILink) gateway.findAnnotationLink( 223 AnnotationData.class, tag.getId(), ho.getId()); 224 if (link == null) 225 link = ModelMapper.linkAnnotation(annObject, ho); 226 } else { 227 annObject = tag.asIObject(); 228 ModelMapper.unloadCollections(annObject); 229 link = (ILink) gateway.findAnnotationLink(ho.getClass(), 230 ho.getId(), tag.getId()); 231 if (link == null) 232 link = ModelMapper.linkAnnotation(ho, annObject); 233 else { 234 updateAnnotationData(tag); 235 exist = true; 236 } 237 } 238 } else if (annotation instanceof RatingAnnotationData) { 239 clearAnnotation(data.getClass(), data.getId(), 240 RatingAnnotationData.class); 241 link = ModelMapper.linkAnnotation(ho, annotation.asIObject()); 242 } else { 243 annObject = annotation.asIObject(); 244 ModelMapper.unloadCollections(annObject); 245 link = ModelMapper.linkAnnotation(ho, annObject); 246 } 247 if (link != null) 248 gateway.createObject(link, (new PojoOptions()).map()); 249 } 105 250 /** 106 251 * Updates the passed annotation. … … 122 267 TagAnnotationData tag = (TagAnnotationData) ann; 123 268 TextualAnnotationData description = tag.getTagDescription(); 124 if (description != null) {269 //if (description != null) { 125 270 id = tag.getId(); 126 271 if (id >= 0) { 127 /* 128 List links = gateway.findAnnotationLinks(Annotation.class, 129 id, null); 130 if (links != null) { 131 Iterator i = links.iterator(); 132 long userID = getUserDetails().getId(); 133 AnnotationAnnotationLink aaLink; 134 List<IObject> toRemove = new ArrayList<IObject>(); 135 while (i.hasNext()) { 136 aaLink = (AnnotationAnnotationLink) i.next(); 137 ho = aaLink.getChild(); 138 if (ho.getDetails().getOwner().getId() == userID) { 139 toRemove.add(ho); 140 gateway.deleteObject(aaLink); 141 } 142 } 143 i = toRemove.iterator(); 144 while (i.hasNext()) { 145 gateway.deleteObject((IObject) i.next()); 146 } 147 } 148 */ 272 149 273 gateway.removeTagDescription(id, getUserDetails().getId()); 150 274 } … … 154 278 if (link != null) 155 279 gateway.createObject(link, (new PojoOptions()).map()); 156 } 157 } 158 159 } 160 161 /** 162 * Clears the passed annotations linked to the annotation 163 * specifed by the id. 164 * 165 * @param parentID The id of the parent annotation. 166 * @param childrenAnnotations The collection of linked annotations. 167 * @throws DSOutOfServiceException If the connection is broken, or logged in 168 * @throws DSAccessException If an error occured while trying to 169 * retrieve data from OMEDS service. 170 */ 171 private void clearAnnotationAnnotationLink(long parentID, 172 List childrenAnnotations) 173 throws DSOutOfServiceException, DSAccessException 174 { 175 if (childrenAnnotations == null || 176 childrenAnnotations.size() == 0) return; 177 Iterator i = childrenAnnotations.iterator(); 178 List<Long> ids = new ArrayList<Long>(); 179 List<IObject> toRemove = new ArrayList<IObject>(); 180 long userID = getUserDetails().getId(); 181 AnnotationData data; 182 while (i.hasNext()) { 183 data = (AnnotationData) i.next(); 184 if (data.getOwner().getId() == userID) { 185 ids.add(data.getId()); 186 toRemove.add(data.asIObject()); 187 } 188 } 189 List l = null; 190 if (ids.size() != 0) 191 l = gateway.findAnnotationLinks(Annotation.class, parentID, ids); 192 if (l != null) { 193 i = l.iterator(); 194 while (i.hasNext()) { 195 gateway.deleteObject((IObject) i.next()); 196 } 197 i = toRemove.iterator(); 198 while (i.hasNext()) { 199 gateway.deleteObject((IObject) i.next()); 200 } 201 } 280 //} 281 } 282 202 283 } 203 284 … … 721 802 } 722 803 return annotations; 723 }724 725 private List<AnnotationData> prepareAnnotationToAdd(726 List<AnnotationData> toAdd)727 throws DSOutOfServiceException, DSAccessException728 {729 List<AnnotationData> annotations = new ArrayList<AnnotationData>();730 Iterator i;731 if (toAdd == null || toAdd.size() == 0) return annotations;732 i = toAdd.iterator();733 AnnotationData ann;734 Annotation iobject = null;735 FileAnnotationData fileAnn;736 FileAnnotation fa;737 OriginalFile of;738 List<Annotation> toCreate = new ArrayList<Annotation>();739 List<IObject> links = new ArrayList<IObject>();740 TextualAnnotationData desc;741 TagAnnotationData tag;742 IObject link = null;743 Map map = (new PojoOptions()).map();744 while (i.hasNext()) {745 ann = (AnnotationData) i.next();746 if (ann.getId() < 0) {747 if (ann instanceof FileAnnotationData) {748 fileAnn = (FileAnnotationData) ann;749 of = gateway.uploadFile(fileAnn.getAttachedFile(),750 fileAnn.getServerFileFormat());751 fa = new FileAnnotation();752 fa.setFile(of);753 iobject = fa;754 } else {755 if (ann instanceof TagAnnotationData) {756 IObject r = gateway.createObject(757 ModelMapper.createAnnotation(ann), map);758 tag = (TagAnnotationData) ann;759 desc = tag.getTagDescription();760 if (desc != null) {761 link = ModelMapper.createAnnotationAndLink(r, desc);762 if (link != null)763 gateway.createObject(link, map);764 }765 annotations.add(766 (AnnotationData) PojoMapper.asDataObject(r));767 } else768 iobject = ModelMapper.createAnnotation(ann);769 }770 if (iobject != null)771 toCreate.add(iobject);772 773 } else {774 if (ann instanceof TagAnnotationData) {775 //update description776 tag = (TagAnnotationData) ann;777 updateAnnotationData(tag);778 }779 annotations.add(ann);780 }781 782 }783 784 if (toCreate.size() > 0) {785 i = toCreate.iterator();786 IObject[] array = new IObject[toCreate.size()];787 int index = 0;788 while (i.hasNext()) {789 array[index] = (IObject) i.next();790 index++;791 }792 IObject[] r = gateway.createObjects(array,793 (new PojoOptions()).map());794 annotations.addAll(PojoMapper.asDataObjects(r));795 }796 if (links.size() > 0) {797 i = links.iterator();798 IObject[] array = new IObject[links.size()];799 int index = 0;800 while (i.hasNext()) {801 array[index] = (IObject) i.next();802 index++;803 }804 gateway.createObjects(array, (new PojoOptions()).map());805 }806 return annotations;807 }808 809 private void linkAnnotation(DataObject data, AnnotationData annotation)810 throws DSOutOfServiceException, DSAccessException811 {812 Class ioType = gateway.convertPojos(data.getClass());813 IObject ho = gateway.findIObject(ioType, data.getId());814 ModelMapper.unloadCollections(ho);815 ILink link = null;816 boolean exist = false;817 IObject annObject;818 if (annotation instanceof TagAnnotationData) {819 TagAnnotationData tag = (TagAnnotationData) annotation;820 //tag a tag821 if (TagAnnotationData.class.equals(data.getClass())) {822 annObject = tag.asIObject();823 ModelMapper.unloadCollections(annObject);824 link = (ILink) gateway.findAnnotationLink(825 AnnotationData.class, tag.getId(), ho.getId());826 if (link == null)827 link = ModelMapper.linkAnnotation(annObject, ho);828 } else {829 annObject = tag.asIObject();830 ModelMapper.unloadCollections(annObject);831 link = (ILink) gateway.findAnnotationLink(ho.getClass(),832 ho.getId(), tag.getId());833 if (link == null)834 link = ModelMapper.linkAnnotation(ho, annObject);835 else exist = true;836 }837 } else if (annotation instanceof RatingAnnotationData) {838 clearAnnotation(data.getClass(), data.getId(),839 RatingAnnotationData.class);840 link = ModelMapper.linkAnnotation(ho, annotation.asIObject());841 } else {842 annObject = annotation.asIObject();843 ModelMapper.unloadCollections(annObject);844 link = ModelMapper.linkAnnotation(ho, annObject);845 }846 if (link != null)847 gateway.createObject(link, (new PojoOptions()).map());848 804 } 849 805
