1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 package org.astrogrid.filemanager.common ;
103
104 import java.net.URL ;
105
106 import java.util.Map ;
107 import java.util.Vector ;
108 import java.util.HashMap ;
109 import java.util.Iterator ;
110 import java.util.Collection ;
111 import java.util.StringTokenizer ;
112
113 import org.apache.commons.logging.Log ;
114 import org.apache.commons.logging.LogFactory ;
115
116 import org.astrogrid.store.Ivorn ;
117
118 import org.astrogrid.filestore.common.file.FileProperty ;
119 import org.astrogrid.filestore.common.file.FileProperties ;
120
121 import org.astrogrid.filestore.common.transfer.UrlGetRequest ;
122 import org.astrogrid.filestore.common.transfer.UrlGetTransfer ;
123 import org.astrogrid.filestore.common.transfer.UrlPutTransfer ;
124 import org.astrogrid.filestore.common.transfer.TransferProperties ;
125
126 import org.astrogrid.filestore.common.exception.FileStoreServiceException ;
127 import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
128
129 import org.astrogrid.filestore.client.FileStoreDelegate ;
130 import org.astrogrid.filestore.resolver.FileStoreDelegateResolver ;
131
132 import org.astrogrid.filemanager.common.ivorn.FileManagerIvornFactory ;
133 import org.astrogrid.filemanager.common.ivorn.FileManagerIvornParser ;
134
135 import org.astrogrid.filemanager.common.exception.NodeNotFoundException ;
136 import org.astrogrid.filemanager.common.exception.DuplicateNodeException ;
137 import org.astrogrid.filemanager.common.exception.FileManagerServiceException ;
138 import org.astrogrid.filemanager.common.exception.FileManagerIdentifierException ;
139 import org.astrogrid.filemanager.common.exception.FileManagerPropertiesException ;
140
141 /***
142 * A mock implementation of the file manager interface.
143 *
144 */
145 public class FileManagerMock
146 implements FileManager
147 {
148 /***
149 * Our debug logger.
150 *
151 */
152 private static Log log = LogFactory.getLog(FileManagerMock.class);
153
154 /***
155 * Our FileManager configuration.
156 *
157 */
158 private FileManagerConfig config ;
159
160 /***
161 * Our FileManager store.
162 *
163 */
164 private FileManagerStore store ;
165
166 /***
167 * Our FileStore resolver.
168 *
169 */
170 private FileStoreDelegateResolver resolver ;
171
172 /***
173 * Our identifier factory.
174 *
175 */
176 private FileManagerIvornFactory factory ;
177
178 /***
179 * Public constructor, using a custom configuration, identifier factory and resolver.
180 * @param config The local file manager configuration.
181 * @param store The local file manager store.
182 * @param factory A factory for creating resource identifiers.
183 * @param resolver A resolver to locate filestores.
184 *
185 */
186 public FileManagerMock(
187 FileManagerConfig config,
188 FileManagerStore store,
189 FileManagerIvornFactory factory,
190 FileStoreDelegateResolver resolver
191 )
192 {
193 if (null == config)
194 {
195 throw new IllegalArgumentException(
196 "Null manager configuration"
197 );
198 }
199 if (null == store)
200 {
201 throw new IllegalArgumentException(
202 "Null manager store"
203 );
204 }
205 if (null == factory)
206 {
207 throw new IllegalArgumentException(
208 "Null identifier factory"
209 );
210 }
211 if (null == resolver)
212 {
213 throw new IllegalArgumentException(
214 "Null FileStore resolver"
215 );
216 }
217 this.store = store ;
218 this.config = config ;
219 this.factory = factory ;
220 this.resolver = resolver ;
221 }
222
223 /***
224 * Get the manager identifier.
225 * @return The manager identifier (ivorn).
226 * @throws FileManagerServiceException If a problem occurs when handling the request.
227 *
228 */
229 public String getIdentifier()
230 throws FileManagerServiceException
231 {
232 return config.getFileManagerIvorn().toString() ;
233 }
234
235 /***
236 * Create a root node for a new account.
237 * @param ident The identifier for the account.
238 * @return An array of properties for the new account node.
239 * @throws DuplicateNodeException If the the account already exists.
240 * @throws FileManagerServiceException If a problem occurs when handling the request.
241 *
242 */
243 public FileProperty[] addAccount(String ident)
244 throws FileManagerServiceException, DuplicateNodeException
245 {
246 log.debug("");
247 log.debug("FileManagerMock.addAccount()");
248 log.debug(" Account : " + ident);
249 if (null == ident)
250 {
251 throw new IllegalArgumentException(
252 "Null account identifier"
253 );
254 }
255
256
257 if (store.hasAccount(ident))
258 {
259 throw new DuplicateNodeException(
260 "Account already exists"
261 ) ;
262 }
263
264
265 FileManagerStoreNode node = this.addNode(
266 (FileManagerStoreNode) null,
267 "home",
268 FileManagerProperties.CONTAINER_NODE_TYPE
269 ) ;
270
271
272 store.addAccount(
273 ident,
274 node
275 ) ;
276
277
278 return node.getProperties().toArray() ;
279 }
280
281 /***
282 * Get the root node for an account
283 * @param ident The account identifier.
284 * @return An array of properties for the account node.
285 * @throws NodeNotFoundException If the node does not exist.
286 * @throws FileManagerServiceException If a problem occurs when handling the request.
287 *
288 */
289 public FileProperty[] getAccount(String ident)
290 throws FileManagerServiceException, NodeNotFoundException
291 {
292 log.debug("");
293 log.debug("FileManagerMock.getAccount()");
294 log.debug(" Account : " + ident);
295 if (null == ident)
296 {
297 throw new IllegalArgumentException(
298 "Null account identifier"
299 ) ;
300 }
301
302
303 if (store.hasAccount(ident))
304 {
305
306
307 FileManagerStoreNode node = store.getAccount(ident);
308
309
310 return node.getProperties().toArray() ;
311 }
312
313
314 else {
315 throw new NodeNotFoundException() ;
316 }
317 }
318
319 /***
320 * Get a specific node, indexed by ivorn identifier.
321 * @param ivorn The node (ivorn) identifier.
322 * @return The node specified by the identifier.
323 * @throws NodeNotFoundException If the node does not exist.
324 * @throws FileManagerServiceException If a problem occurs when handling the request.
325 * @todo Refactor this as getNode(ivorn, [path])
326 *
327 */
328 public FileProperty[] getNode(String ivorn)
329 throws FileManagerServiceException, NodeNotFoundException
330 {
331 log.debug("");
332 log.debug("FileManagerMock.getNode()");
333 log.debug(" Ivorn : " + ivorn);
334 if (null == ivorn)
335 {
336 throw new NodeNotFoundException(
337 "Null identifier"
338 ) ;
339 }
340
341
342 String path = null ;
343 try {
344 path = new FileManagerIvornParser(
345 ivorn
346 ).getResourceIdent();
347 }
348 catch (FileManagerIdentifierException ouch)
349 {
350 throw new NodeNotFoundException(
351 "Unable to parse node identifier"
352 );
353 }
354 if (null == path)
355 {
356 throw new NodeNotFoundException(
357 "Null node identifier"
358 ) ;
359 }
360
361
362 StringTokenizer tokens = new StringTokenizer(path, "/") ;
363
364
365 if (tokens.hasMoreTokens())
366 {
367 String ident = tokens.nextToken();
368
369
370 if (store.hasNode(ident))
371 {
372 FileManagerStoreNode node = store.getNode(ident) ;
373
374
375 if (tokens.hasMoreTokens())
376 {
377 node = node.getChild(tokens) ;
378 }
379 return node.getProperties().toArray() ;
380 }
381
382
383 else {
384 throw new NodeNotFoundException() ;
385 }
386 }
387
388
389 else {
390 throw new NodeNotFoundException() ;
391 }
392 }
393
394 /***
395 * Refresh the properties for a node, indexed by ivorn identifier.
396 * If this node has stored data, this will trigger a call to the FileStore to update the data properties.
397 * @param ivorn The node (ivorn) identifier.
398 * @return The node properties.
399 * @throws NodeNotFoundException If the node does not exist.
400 * @throws FileManagerServiceException If a problem occurs when handling the request.
401 *
402 */
403 public FileProperty[] refresh(String ivorn)
404 throws FileManagerServiceException, NodeNotFoundException
405 {
406 log.debug("");
407 log.debug("FileManagerMock.refresh()");
408 log.debug(" Ivorn : " + ivorn);
409 if (null == ivorn)
410 {
411 throw new IllegalArgumentException(
412 "Null identifier"
413 ) ;
414 }
415
416
417 String path = null ;
418 try {
419 path = new FileManagerIvornParser(
420 ivorn
421 ).getResourceIdent();
422 }
423 catch (FileManagerIdentifierException ouch)
424 {
425 throw new NodeNotFoundException(
426 "Unable to parse node identifier"
427 );
428 }
429
430
431 StringTokenizer tokens = new StringTokenizer(path, "/") ;
432
433
434 if (tokens.hasMoreTokens())
435 {
436 String ident = tokens.nextToken();
437
438
439 if (store.hasNode(ident))
440 {
441 FileManagerStoreNode node = store.getNode(ident) ;
442
443
444 if (tokens.hasMoreTokens())
445 {
446 node = node.getChild(tokens) ;
447 }
448 log.debug("Found node ...");
449
450
451 FileManagerProperties current = node.getProperties();
452
453
454 if (node.isDataNode())
455 {
456 log.debug("Found data node ...");
457
458
459 Ivorn dataIvorn = null ;
460 String dataIdent = null ;
461 try {
462 dataIvorn = current.getStoreResourceIvorn() ;
463 dataIdent = current.getStoreResourceIdent() ;
464 }
465 catch (FileStoreIdentifierException ouch)
466 {
467 log.warn("");
468 log.warn("Unable to parse current store resource ivorn");
469 log.warn(ouch);
470 throw new FileManagerServiceException(
471 "Unable to parse current store resource ivorn"
472 );
473 }
474
475
476 if (null != dataIvorn)
477 {
478 log.debug("Found store location ...");
479 log.debug(" Ivorn : " + dataIvorn.toString());
480
481
482 FileStoreDelegate filestore = resolve(
483 dataIvorn
484 ) ;
485 log.debug(" PASS : Got data filestore");
486
487
488 try {
489
490
491 FileManagerProperties updated = new FileManagerProperties(
492 filestore.properties(
493 dataIdent
494 )
495 );
496 log.debug(" PASS : Got updated properties");
497 log.debug(" Size : " + String.valueOf(updated.getContentSize()));
498
499
500 current.merge(
501 updated,
502 new FileManagerPropertyFilter()
503 );
504 log.debug(" PASS : Merged updated properties");
505 log.debug(" Size : " + String.valueOf(current.getContentSize()));
506 }
507
508
509
510 catch(Exception ouch)
511 {
512 log.warn("Exception thrown by FileStore.properties()");
513 log.warn(" Exception : " + ouch);
514
515
516
517 }
518 }
519 }
520
521
522 return current.toArray() ;
523 }
524
525
526 else {
527 throw new NodeNotFoundException() ;
528 }
529 }
530
531
532 else {
533 throw new NodeNotFoundException() ;
534 }
535 }
536
537 /***
538 * Get a specific child node, indexed by path.
539 * @param ivorn The parent node (ivorn) identifier.
540 * @param path The target node path, from the parent node.
541 * @return The node specified by the parent and path.
542 * @throws NodeNotFoundException If the node does not exist.
543 * @throws FileManagerServiceException If a problem occurs when handling the request.
544 * @todo Refactor this as getNode(ivorn, [path])
545 *
546 */
547 public FileProperty[] getChild(String ivorn, String path)
548 throws FileManagerServiceException, NodeNotFoundException
549 {
550 log.debug("");
551 log.debug("FileManagerMock.getChild()");
552 log.debug(" Ivorn : " + ivorn);
553 log.debug(" Path : " + path);
554 if (null == ivorn)
555 {
556 throw new IllegalArgumentException(
557 "Null identifier"
558 ) ;
559 }
560 if (null == path)
561 {
562 throw new IllegalArgumentException(
563 "Null path"
564 ) ;
565 }
566
567
568 String ident = null ;
569 try {
570 ident = new FileManagerIvornParser(
571 ivorn
572 ).getResourceIdent();
573 }
574 catch (FileManagerIdentifierException ouch)
575 {
576 throw new NodeNotFoundException(
577 "Unable to parse parent identifier"
578 );
579 }
580
581
582 if (store.hasNode(ident))
583 {
584 FileManagerStoreNode node = store.getNode(ident) ;
585 log.debug("");
586 log.debug(" Node : " + node.getName());
587 log.debug(" Node : " + node.getIdent());
588
589
590 return node.getChild(path).getProperties().toArray() ;
591 }
592
593
594 else {
595 throw new NodeNotFoundException() ;
596 }
597 }
598
599 /***
600 * Add a new child node.
601 * @param ivorn The (ivorn) identifier of the parent node.
602 * @param path The new node name (and path).
603 * @param type The new node type.
604 * @return The new node.
605 * @throws DuplicateNodeException If a node with the same name already exists.
606 * @throws NodeNotFoundException If the parent node does not exist.
607 * @throws FileManagerServiceException If a problem occurs when handling the request.
608 * @todo Refactor this to handle path, and create missing folders.
609 *
610 */
611 public FileProperty[] addNode(String ivorn, String name, String type)
612 throws FileManagerServiceException, DuplicateNodeException, NodeNotFoundException
613 {
614 log.debug("");
615 log.debug("FileManagerMock.addNode(String, String, String)");
616 log.debug(" Parent : " + ivorn);
617 log.debug(" Name : " + name);
618 log.debug(" Type : " + type);
619 if (null == ivorn)
620 {
621 throw new IllegalArgumentException(
622 "Null parent identifier"
623 ) ;
624 }
625
626
627 String ident = null ;
628 try {
629 ident = new FileManagerIvornParser(
630 ivorn
631 ).getResourceIdent();
632 }
633 catch (FileManagerIdentifierException ouch)
634 {
635 throw new NodeNotFoundException(
636 "Unable to parse parent identifier"
637 );
638 }
639
640
641 FileManagerStoreNode node = store.getNode(ident) ;
642
643
644 if (null != node)
645 {
646
647
648 if (node.isContainer())
649 {
650 FileManagerStoreNode child = this.addNode(
651 node,
652 name,
653 type
654 ) ;
655 return child.getProperties().toArray() ;
656 }
657
658
659 else {
660 throw new UnsupportedOperationException(
661 "Parent must be a container"
662 );
663 }
664 }
665
666
667 else {
668 throw new NodeNotFoundException() ;
669 }
670 }
671
672 /***
673 * Add a new child node.
674 * @param parent The parent node.
675 * @param path The new node name (and path).
676 * @param type The new node type.
677 * @return The new node.
678 * @throws DuplicateNodeException If a node with the same name already exists.
679 * @throws NodeNotFoundException If the parent node does not exist.
680 * @throws FileManagerServiceException If a problem occurs when handling the request.
681 * @todo Refactor this to handle path, and create missing folders.
682 *
683 */
684 protected FileManagerStoreNode addNode(FileManagerStoreNode parent, String name, String type)
685 throws FileManagerServiceException, DuplicateNodeException
686 {
687 log.debug("");
688 log.debug("FileManagerMock.addNode(Node, String, String)");
689 log.debug(" Name : " + name);
690 log.debug(" Type : " + type);
691 if (null == parent)
692 {
693 log.debug(" Parent : -");
694 }
695 else {
696 log.debug(" Parent : " + parent.getIdent());
697 log.debug(" Parent : " + parent.getName());
698 }
699 if (null == name)
700 {
701 throw new IllegalArgumentException(
702 "Null name"
703 ) ;
704 }
705 if (null == type)
706 {
707 throw new IllegalArgumentException(
708 "Null type"
709 ) ;
710 }
711 try {
712
713
714 FileManagerStoreNode node = store.addNode(
715 (null != parent) ? parent.getIvorn() : null ,
716 factory.ivorn(
717 config.getFileManagerIvorn()
718 ),
719 name,
720 type
721 );
722
723
724 if (node.isDataNode())
725 {
726
727
728 node.getProperties().setManagerLocationIvorn(
729 config.getFileStoreIvorn()
730 );
731 }
732
733
734 if (null != parent)
735 {
736 parent.addNode(
737 node
738 ) ;
739 }
740
741
742 return node ;
743 }
744 catch (FileManagerIdentifierException ouch)
745 {
746 log.debug("Unable to create node identifier");
747 log.debug("Exception : " + ouch);
748 throw new FileManagerServiceException(
749 "Unable to create node identifier"
750 );
751 }
752 }
753
754 /***
755 * Template for generating an array of strings.
756 *
757 */
758 private static final String[] template = new String[0] ;
759
760 /***
761 * Get a list of the children of a specific node.
762 * @param ivorn The parent node (ivorn) identifier.
763 * @return An array of ivorn(s) for the child node(s).
764 * @throws NodeNotFoundException If the parent node does not exist.
765 * @throws FileManagerServiceException If a problem occurs when handling the request.
766 * @todo Refactor this to listNodes(ivorn, [path])
767 *
768 */
769 public String[] getChildren(String ivorn)
770 throws FileManagerServiceException, NodeNotFoundException
771 {
772 log.debug("");
773 log.debug("FileManagerMock.getChildren(String)");
774 log.debug(" Ivorn : " + ivorn);
775 if (null == ivorn)
776 {
777 throw new IllegalArgumentException(
778 "Null parent identifier"
779 ) ;
780 }
781
782
783 String ident = null ;
784 try {
785 ident = new FileManagerIvornParser(
786 ivorn
787 ).getResourceIdent();
788 }
789 catch (FileManagerIdentifierException ouch)
790 {
791 throw new NodeNotFoundException(
792 "Unable to parse parent identifier"
793 );
794 }
795
796
797 if (store.hasNode(ident))
798 {
799
800
801 FileManagerStoreNode node = store.getNode(ident) ;
802 log.debug("");
803 log.debug(" Node : " + node.getName());
804 log.debug(" Node : " + node.getIdent());
805
806
807 Collection nodes = node.getChildren() ;
808 Iterator iter = nodes.iterator() ;
809 Vector vector = new Vector();
810 while(iter.hasNext())
811 {
812 try {
813 Ivorn child = ((FileManagerStoreNode) iter.next()).getIvorn();
814 if (null != child)
815 {
816 vector.add(
817 child.toString()
818 );
819 }
820 }
821 catch (FileManagerIdentifierException ouch)
822 {
823 log.warn("Unable to parse child node ivorn");
824 }
825 }
826 String[] array = (String[]) vector.toArray(
827 template
828 );
829 return array ;
830 }
831
832
833 else {
834 throw new NodeNotFoundException() ;
835 }
836 }
837
838 /***
839 * Resolve a filestore.
840 * @param ivorn The file store ivorn.
841 * @return A delegate interface for the filestore.
842 * @throws FileManagerServiceException If unbale to resolve the filestore.
843 * @todo Ping the filestore to check it is available ?
844 *
845 */
846 protected FileStoreDelegate resolve(Ivorn ivorn)
847 throws FileManagerServiceException
848 {
849 try {
850 return resolver.resolve(
851 ivorn
852 ) ;
853 }
854 catch (Exception ouch)
855 {
856 log.debug("Exception thrown by FileStoreResolver.resolve()");
857 log.debug(" Exception : " + ouch);
858 throw new FileManagerServiceException(
859 "Unable to locate FileStore service"
860 );
861 }
862 }
863
864 /***
865 * Initialise a data transfer into a FileStore.
866 * The request properties need to specify the (ivorn) identifier of an existing node, or the identifier of a parent node and the new node name and path.
867 * @param request The request properties.
868 * @throws NodeNotFoundException If the target node does not exist.
869 * @throws FileManagerServiceException If a problem occurs when handling the request.
870 * @todo Refactor this to handle path, and create missing folders.
871 *
872 */
873 public TransferProperties importInit(FileProperty[] request)
874 throws FileManagerServiceException, NodeNotFoundException
875 {
876 log.debug("");
877 log.debug("FileManagerMock.importInit(FileProperty[])");
878 if (null == request)
879 {
880 throw new NodeNotFoundException(
881 "Null request properties"
882 ) ;
883 }
884
885
886 FileManagerProperties properties = new FileManagerProperties(
887 request
888 );
889
890
891 String ident = null ;
892 try {
893 ident = properties.getManagerResourceIdent();
894 }
895 catch (FileManagerIdentifierException ouch)
896 {
897 throw new NodeNotFoundException(
898 "Unable to parse node identifier"
899 );
900 }
901
902
903 if (null == ident)
904 {
905 throw new NodeNotFoundException(
906 "Null node identifier"
907 );
908 }
909
910
911 else {
912
913
914 if (store.hasNode(ident))
915 {
916 FileManagerStoreNode node = store.getNode(ident) ;
917 log.debug("");
918 log.debug(" Node : " + node.getName());
919 log.debug(" Node : " + node.getIdent());
920
921
922 return this.importInit(
923 node,
924 properties
925 ) ;
926 }
927
928
929 else {
930 throw new NodeNotFoundException();
931 }
932 }
933 }
934
935 /***
936 * Initialise a data transfer into a FileStore.
937 * The request properties need to specify the (ivorn) identifier of an existing node, or the identifier of a parent node and the new node name and path.
938 * @param node The target node.
939 * @param request The request properties.
940 * @throws NodeNotFoundException If the target node does not exist.
941 * @throws FileManagerServiceException If a problem occurs when handling the request.
942 *
943 */
944 protected TransferProperties importInit(FileManagerStoreNode node, FileManagerProperties request)
945 throws FileManagerServiceException, NodeNotFoundException
946 {
947 log.debug("");
948 log.debug("FileManagerMock.importInit(Node, Properties)");
949 log.debug(" Node : " + node.getName());
950 log.debug(" Node : " + node.getIdent());
951
952
953 if (node.isDataNode() != true)
954 {
955 throw new FileManagerServiceException(
956 "Invalid operation, not a data node"
957 );
958 }
959
960
961 FileManagerProperties current = node.getProperties();
962
963
964
965
966
967
968
969
970 Ivorn target = null ;
971 try {
972 target = current.getStoreResourceIvorn() ;
973 }
974 catch (FileStoreIdentifierException ouch)
975 {
976 log.warn("");
977 log.warn("Unable to parse store location");
978 log.warn(ouch);
979 throw new FileManagerServiceException(
980 "Unable to parse store location"
981 );
982 }
983
984
985 if (null != target)
986 {
987
988
989 request.setStoreResourceIvorn(
990 target
991 );
992 }
993
994
995 else {
996
997
998 try {
999 target = current.getManagerLocationIvorn();
1000 }
1001 catch (FileManagerIdentifierException ouch)
1002 {
1003 log.warn("");
1004 log.warn("Unable to parse store location");
1005 log.warn(ouch);
1006 throw new FileManagerServiceException(
1007 "Unable to parse store location"
1008 );
1009 }
1010
1011
1012 if (null == target)
1013 {
1014
1015
1016 target = config.getFileStoreIvorn() ;
1017 }
1018 }
1019
1020
1021 try {
1022 request.setManagerResourceIvorn(
1023 current.getManagerResourceIvorn()
1024 );
1025 }
1026 catch (FileManagerIdentifierException ouch)
1027 {
1028 log.warn("");
1029 log.warn("Unable to set resource ivorn");
1030 log.warn(ouch);
1031 throw new FileManagerServiceException(
1032 "Unable to parse resource ivorn"
1033 );
1034 }
1035 try {
1036 request.setManagerParentIvorn(
1037 current.getManagerParentIvorn()
1038 );
1039 }
1040 catch (FileManagerIdentifierException ouch)
1041 {
1042 log.warn("");
1043 log.warn("Unable to set parent ivorn");
1044 log.warn(ouch);
1045 throw new FileManagerServiceException(
1046 "Unable to parse parent ivorn"
1047 );
1048 }
1049 request.setManagerResourceName(
1050 current.getManagerResourceName()
1051 );
1052 request.setManagerResourceType(
1053 current.getManagerResourceType()
1054 );
1055
1056
1057 FileStoreDelegate filestore = resolve(
1058 target
1059 ) ;
1060
1061
1062 TransferProperties transfer = null ;
1063 try {
1064 transfer =
1065 filestore.importInit(
1066 new UrlPutTransfer(
1067 request
1068 )
1069 ) ;
1070 }
1071 catch (Exception ouch)
1072 {
1073 log.debug("Exception thrown by FileStore.importInit()");
1074 log.debug(" Exception : " + ouch);
1075 throw new FileManagerServiceException(
1076 "Error occurred when calling FileStore service"
1077 );
1078 }
1079
1080
1081 FileManagerProperties response = new FileManagerProperties(
1082 transfer.getFileProperties()
1083 ) ;
1084
1085
1086
1087 try {
1088 response.setManagerResourceIvorn(
1089 current.getManagerResourceIvorn()
1090 );
1091 }
1092 catch (FileManagerIdentifierException ouch)
1093 {
1094 log.warn("");
1095 log.warn("Unable to set resource ivorn");
1096 log.warn(ouch);
1097 throw new FileManagerServiceException(
1098 "Unable to parse resource ivorn"
1099 );
1100 }
1101 try {
1102 response.setManagerParentIvorn(
1103 current.getManagerParentIvorn()
1104 );
1105 }
1106 catch (FileManagerIdentifierException ouch)
1107 {
1108 log.warn("");
1109 log.warn("Unable to set parent ivorn");
1110 log.warn(ouch);
1111 throw new FileManagerServiceException(
1112 "Unable to parse parent ivorn"
1113 );
1114 }
1115 response.setManagerResourceName(
1116 current.getManagerResourceName()
1117 );
1118 response.setManagerResourceType(
1119 current.getManagerResourceType()
1120 );
1121
1122
1123 try {
1124 response.setManagerLocationIvorn(
1125 response.getStoreServiceIvorn()
1126 );
1127 }
1128 catch (FileStoreIdentifierException ouch)
1129 {
1130 log.warn("");
1131 log.warn("Unable to set location ivorn");
1132 log.warn(ouch);
1133 response.setManagerLocationIvorn(
1134 target
1135 );
1136 }
1137
1138
1139 node.setProperties(
1140 response
1141 ) ;
1142
1143
1144 transfer.setFileProperties(
1145 response
1146 );
1147 return transfer ;
1148 }
1149
1150 /***
1151 * Initialise a data transfer from a FileStore.
1152 * This calls the FileStore to request the HTTP (GET) URL to read the data from the FileStore.
1153 * @param request The request properties.
1154 * @throws NodeNotFoundException If the target node does not exist.
1155 * @throws FileManagerServiceException If a problem occurs when handling the request.
1156 *
1157 */
1158 public TransferProperties exportInit(FileProperty[] request)
1159 throws FileManagerServiceException, NodeNotFoundException
1160 {
1161 log.debug("");
1162 log.debug("FileManagerMock.exportInit(FileProperty[])");
1163 if (null == request)
1164 {
1165 throw new NodeNotFoundException(
1166 "Null request properties"
1167 ) ;
1168 }
1169
1170
1171 FileManagerProperties properties = new FileManagerProperties(
1172 request
1173 );
1174
1175
1176 String ident = null ;
1177 try {
1178 ident = properties.getManagerResourceIdent() ;
1179 }
1180 catch (FileManagerIdentifierException ouch)
1181 {
1182 throw new NodeNotFoundException(
1183 "Unable to parse resource ivorn"
1184 );
1185 }
1186
1187
1188 if (null == ident)
1189 {
1190 throw new NodeNotFoundException(
1191 "Null node identifier"
1192 );
1193 }
1194
1195
1196 else {
1197
1198
1199 if (store.hasNode(ident))
1200 {
1201 FileManagerStoreNode node = store.getNode(ident) ;
1202 log.debug("");
1203 log.debug(" Node : " + node.getName());
1204 log.debug(" Node : " + node.getIdent());
1205
1206
1207 return this.exportInit(
1208 node,
1209 properties
1210 ) ;
1211 }
1212
1213
1214 else {
1215 throw new NodeNotFoundException();
1216 }
1217 }
1218 }
1219
1220 /***
1221 * Initialise a data transfer from a FileStore.
1222 * This calls the FileStore to request the HTTP (GET) URL to read the data from the FileStore.
1223 * @param node The target node.
1224 * @param request The request properties.
1225 * @throws NodeNotFoundException If the target node does not exist.
1226 * @throws FileManagerServiceException If a problem occurs when handling the request.
1227 *
1228 */
1229 protected TransferProperties exportInit(FileManagerStoreNode node, FileManagerProperties request)
1230 throws FileManagerServiceException, NodeNotFoundException
1231 {
1232 log.debug("");
1233 log.debug("FileManagerMock.exportInit(Node, Properties)");
1234 log.debug(" Node : " + node.getName());
1235 log.debug(" Node : " + node.getIdent());
1236
1237
1238 FileManagerProperties current = node.getProperties();
1239
1240
1241
1242
1243
1244
1245
1246 Ivorn target = null ;
1247 try {
1248 target = current.getStoreResourceIvorn() ;
1249 }
1250 catch (FileStoreIdentifierException ouch)
1251 {
1252 throw new FileManagerServiceException(
1253 "Unable to parse current filestore ivorn"
1254 );
1255 }
1256
1257
1258 if (null != target)
1259 {
1260
1261
1262 request.setStoreResourceIvorn(
1263 target
1264 );
1265 }
1266
1267
1268 else {
1269 throw new NodeNotFoundException(
1270 "Node does not have any data"
1271 );
1272 }
1273
1274
1275 try {
1276 request.setManagerResourceIvorn(
1277 current.getManagerResourceIvorn()
1278 );
1279 }
1280 catch (FileManagerIdentifierException ouch)
1281 {
1282 throw new FileManagerServiceException(
1283 "Unable to parse resource ivorn"
1284 );
1285 }
1286 try {
1287 request.setManagerParentIvorn(
1288 current.getManagerParentIvorn()
1289 );
1290 }
1291 catch (FileManagerIdentifierException ouch)
1292 {
1293 throw new FileManagerServiceException(
1294 "Unable to parse parent ivorn"
1295 );
1296 }
1297 request.setManagerResourceName(
1298 current.getManagerResourceName()
1299 );
1300 request.setManagerResourceType(
1301 current.getManagerResourceType()
1302 );
1303
1304
1305 FileStoreDelegate filestore = resolve(target) ;
1306
1307
1308 TransferProperties transfer = null ;
1309 try {
1310 transfer =
1311 filestore.exportInit(
1312 new UrlGetRequest(
1313 request
1314 )
1315 ) ;
1316 }
1317 catch (Exception ouch)
1318 {
1319 log.debug("Exception thrown by FileStore.importInit()");
1320 log.debug(" Exception : " + ouch);
1321 throw new FileManagerServiceException(
1322 "Error occurred when calling FileStore service"
1323 );
1324 }
1325
1326
1327 FileManagerProperties response = new FileManagerProperties(
1328 transfer.getFileProperties()
1329 ) ;
1330
1331
1332
1333 try {
1334 response.setManagerResourceIvorn(
1335 current.getManagerResourceIvorn()
1336 );
1337 }
1338 catch (FileManagerIdentifierException ouch)
1339 {
1340 throw new FileManagerServiceException(
1341 "Unable to parse resource ivorn"
1342 );
1343 }
1344 try {
1345 response.setManagerParentIvorn(
1346 current.getManagerParentIvorn()
1347 );
1348 }
1349 catch (FileManagerIdentifierException ouch)
1350 {
1351 throw new FileManagerServiceException(
1352 "Unable to parse parent ivorn"
1353 );
1354 }
1355 response.setManagerResourceName(
1356 current.getManagerResourceName()
1357 );
1358 response.setManagerResourceType(
1359 current.getManagerResourceType()
1360 );
1361
1362
1363 node.setProperties(
1364 response
1365 ) ;
1366
1367
1368 transfer.setFileProperties(
1369 response
1370 );
1371 return transfer ;
1372 }
1373
1374 /***
1375 * Move a node to a new location.
1376 * If the node already has stored data, then this may involve transfering the data to a new location.
1377 * @param request The request properties.
1378 * @return A new set of properties for the node.
1379 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1380 * @throws NodeNotFoundException If the current node is no longer in the database.
1381 * @throws NodeNotFoundException If the new parent node is no longer in the database.
1382 * @throws FileManagerServiceException If a problem occurs when handling the request.
1383 *
1384 */
1385 public FileProperty[] move(FileProperty[] request)
1386 throws FileManagerServiceException, DuplicateNodeException, NodeNotFoundException
1387 {
1388 log.debug("");
1389 log.debug("FileManagerMock.move(FileProperty[])");
1390 if (null == request)
1391 {
1392 throw new NodeNotFoundException(
1393 "Null request properties"
1394 ) ;
1395 }
1396
1397
1398 FileManagerProperties properties = new FileManagerProperties(
1399 request
1400 );
1401
1402
1403 Ivorn ivorn = null ;
1404 try {
1405 ivorn = properties.getManagerResourceIvorn();
1406 }
1407 catch (FileManagerIdentifierException ouch)
1408 {
1409 throw new NodeNotFoundException(
1410 "Unable to parse node ivorn"
1411 );
1412 }
1413
1414
1415 return this.move(
1416 this.node(
1417 ivorn
1418 ),
1419 properties
1420 ) ;
1421 }
1422
1423 /***
1424 * Move a node to a new location.
1425 * If the node already has stored data, then this may involve transfering the data to a new location.
1426 * @param node The target node.
1427 * @param request The request properties.
1428 * @return A new set of properties for the node.
1429 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1430 * @throws NodeNotFoundException If the new parent node is no longer in the database.
1431 * @throws FileManagerServiceException If a problem occurs when handling the request.
1432 *
1433 */
1434 public FileProperty[] move(FileManagerStoreNode node, FileManagerProperties request)
1435 throws DuplicateNodeException, NodeNotFoundException, FileManagerServiceException
1436 {
1437 log.debug("");
1438 log.debug("FileManagerMock.move(Node, FileManagerProperties)");
1439 log.debug(" Node : " + node.getName());
1440 log.debug(" Node : " + node.getIdent());
1441
1442
1443 FileManagerProperties current = node.getProperties();
1444
1445
1446 FileManagerProperties changed = current.difference(
1447 request
1448 );
1449
1450
1451 Ivorn dest = null ;
1452 try {
1453 dest = changed.getManagerParentIvorn();
1454 }
1455 catch (FileManagerIdentifierException ouch)
1456 {
1457 throw new NodeNotFoundException(
1458 "Unable to parse node ivorn"
1459 );
1460 }
1461
1462
1463 String name = changed.getManagerResourceName();
1464
1465
1466 if ((null != name) || (null != dest))
1467 {
1468 this.moveNode(
1469 node,
1470 name,
1471 dest
1472 );
1473 }
1474
1475
1476 Ivorn store = null ;
1477 try {
1478 store = changed.getManagerLocationIvorn();
1479 }
1480 catch (FileManagerIdentifierException ouch)
1481 {
1482 throw new NodeNotFoundException(
1483 "Unable to parse store ivorn"
1484 );
1485 }
1486
1487
1488 if (null != store)
1489 {
1490 this.moveStore(
1491 node,
1492 store
1493 );
1494 }
1495
1496
1497 return node.getProperties().toArray();
1498 }
1499
1500 /***
1501 * Move a node in the tree.
1502 * @param node The node to move.
1503 * @param name The new name for the node.
1504 * @param dest The (ivorn) identifier of the new parent.
1505 * @return The updated node.
1506 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1507 * @throws NodeNotFoundException If the new parent node is no longer in the database.
1508 * @throws FileManagerServiceException If a problem occurs when handling the request.
1509 *
1510 */
1511 protected void moveNode(FileManagerStoreNode node, String name, Ivorn dest)
1512 throws FileManagerServiceException, DuplicateNodeException, NodeNotFoundException
1513 {
1514 log.debug("");
1515 log.debug("FileManagerMock.move(Node, String, Ivorn)");
1516 log.debug(" Node : " + node.getName());
1517 log.debug(" Node : " + node.getIdent());
1518 log.debug(" Name : " + name);
1519 log.debug(" Dest : " + ((null != dest) ? dest.toString() : "null"));
1520
1521
1522 if (null != dest)
1523 {
1524
1525
1526 this.moveNode(
1527 node,
1528 name,
1529 this.node(
1530 dest
1531 )
1532 );
1533 }
1534
1535
1536 else {
1537
1538
1539 FileManagerStoreNode parent = null ;
1540 try {
1541 parent = this.node(
1542 node.getParentIvorn()
1543 );
1544 }
1545 catch (FileManagerIdentifierException ouch)
1546 {
1547 throw new FileManagerServiceException(
1548 "Unable to oarse parent node ivorn"
1549 );
1550 }
1551 this.moveNode(
1552 node,
1553 name,
1554 parent
1555 );
1556 }
1557 }
1558
1559 /***
1560 * Move a node in the tree.
1561 * @param node The node to move.
1562 * @param name The new name for the node.
1563 * @param dest The new parent node.
1564 * @return The updated node.
1565 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1566 * @throws FileManagerServiceException If a problem occurs when handling the request.
1567 *
1568 */
1569 protected void moveNode(FileManagerStoreNode node, String name, FileManagerStoreNode dest)
1570 throws FileManagerServiceException, DuplicateNodeException
1571 {
1572 log.debug("");
1573 log.debug("FileManagerMock.moveNode(Node, String, Node)");
1574 log.debug(" Node : " + node.getName());
1575 log.debug(" Node : " + node.getIdent());
1576 log.debug(" Name : " + name);
1577 log.debug(" Dest : " + dest.getName());
1578 log.debug(" Dest : " + dest.getIdent());
1579
1580
1581 FileManagerStoreNode parent = null;
1582 try {
1583 parent = this.node(
1584 node.getParentIvorn()
1585 );
1586 }
1587 catch (FileManagerIdentifierException ouch)
1588 {
1589 throw new FileManagerServiceException(
1590 "Unable to parse parent node identifier"
1591 );
1592 }
1593 catch (NodeNotFoundException ouch)
1594 {
1595 throw new FileManagerServiceException(
1596 "Unable to locate parent node"
1597 );
1598 }
1599
1600
1601 String prev = node.getName();
1602
1603
1604 if (null != name)
1605 {
1606
1607
1608 if (name.indexOf('/') != -1)
1609 {
1610 throw new FileManagerServiceException(
1611 "Node name cannot contain '/'"
1612 );
1613 }
1614 node.setName(
1615 name
1616 );
1617 }
1618
1619
1620 try {
1621 dest.addNode(
1622 node
1623 );
1624 }
1625 catch (DuplicateNodeException ouch)
1626 {
1627
1628
1629 node.setName(
1630 prev
1631 );
1632
1633
1634 throw ouch ;
1635 }
1636
1637
1638 try {
1639 parent.delNode(
1640 prev
1641 );
1642 }
1643 catch (NodeNotFoundException ouch)
1644 {
1645
1646
1647 log.warn("");
1648 log.warn("Move failed to remove node from original parent");
1649 log.warn("Parent : " + parent.getIdent());
1650 log.warn("Child : " + node.getIdent());
1651 }
1652 }
1653
1654 /***
1655 * Get a node from our map.
1656 * @param ivorn The node (ivorn) identifier.
1657 * @throws NodeNotFoundException If the node is not in the database.
1658 * @throws FileManagerServiceException If a problem occurs when handling the request.
1659 *
1660 */
1661 private FileManagerStoreNode node(Ivorn ivorn)
1662 throws NodeNotFoundException, FileManagerServiceException
1663 {
1664 try {
1665 return this.node(
1666 new FileManagerIvornParser(
1667 ivorn
1668 ).getResourceIdent()
1669 );
1670 }
1671 catch (FileManagerIdentifierException ouch)
1672 {
1673 throw new NodeNotFoundException(
1674 "Unable to parse node ivorn"
1675 ) ;
1676 }
1677 }
1678
1679 /***
1680 * Get a node from our map.
1681 * @param ident The node identifier.
1682 * @throws NodeNotFoundException If the node is not in the database.
1683 * @throws FileManagerServiceException If a problem occurs when handling the request.
1684 *
1685 */
1686 private FileManagerStoreNode node(String ident)
1687 throws NodeNotFoundException, FileManagerServiceException
1688 {
1689 if (null != ident)
1690 {
1691 if (store.hasNode(ident))
1692 {
1693 return store.getNode(ident) ;
1694 }
1695 else {
1696 throw new NodeNotFoundException(
1697 "Unable to locate node"
1698 ) ;
1699 }
1700 }
1701 else {
1702 throw new NodeNotFoundException(
1703 "Null node identifier"
1704 ) ;
1705 }
1706 }
1707
1708 /***
1709 * Move a file from one location to another.
1710 * @param node The node to move.
1711 * @param targetIvorn The destination filestore (ivorn) identifier).
1712 * @throws DuplicateNodeException If the target node already exists.
1713 * @throws NodeNotFoundException If the current node does not exist.
1714 * @throws NodeNotFoundException If the target parent node does not exist.
1715 * @throws FileManagerServiceException If a problem occurs when handling the request.
1716 *
1717 */
1718 protected void moveStore(FileManagerStoreNode node, Ivorn targetIvorn)
1719 throws DuplicateNodeException, NodeNotFoundException, FileManagerServiceException
1720 {
1721 log.debug("");
1722 log.debug("FileManagerMock.moveStore(Node, Ivorn)");
1723 log.debug(" Node : " + node.getName());
1724 log.debug(" Node : " + node.getIdent());
1725 log.debug(" Dest : " + targetIvorn.toString());
1726
1727
1728 if (node.isDataNode())
1729 {
1730 log.debug("");
1731 log.debug(" PASS : Node is a data node");
1732
1733
1734 FileManagerProperties current = node.getProperties();
1735
1736
1737 Ivorn sourceIvorn = null ;
1738 String sourceIdent = null ;
1739 try {
1740 sourceIvorn = current.getStoreResourceIvorn() ;
1741 sourceIdent = current.getStoreResourceIdent() ;
1742 }
1743 catch (FileStoreIdentifierException ouch)
1744 {
1745 log.warn("");
1746 log.warn("Unable to parse current store resource ivorn");
1747 log.warn(ouch);
1748 throw new FileManagerServiceException(
1749 "Unable to parse current store resource ivorn"
1750 );
1751 }
1752
1753
1754 if (null != sourceIvorn)
1755 {
1756 log.debug("");
1757 log.debug(" PASS : Got store resource ivorn");
1758 log.debug(" Ivorn : " + sourceIvorn.toString());
1759
1760
1761 FileStoreDelegate sourceStore = resolve(
1762 sourceIvorn
1763 ) ;
1764 log.debug(" PASS : Got source filestore");
1765
1766
1767 FileStoreDelegate targetStore = resolve(
1768 targetIvorn
1769 ) ;
1770 log.debug(" PASS : Got target filestore");
1771
1772
1773 TransferProperties transfer = null ;
1774 try {
1775 transfer =
1776 sourceStore.exportInit(
1777 new UrlGetRequest(
1778 current
1779 )
1780 ) ;
1781 }
1782 catch (Exception ouch)
1783 {
1784 log.debug("Exception thrown by FileStore.importInit()");
1785 log.debug(" Exception : " + ouch);
1786 throw new FileManagerServiceException(
1787 "Error occurred when calling FileStore service"
1788 );
1789 }
1790
1791
1792 TransferProperties result = null ;
1793 try {
1794 result =
1795 targetStore.importData(
1796 transfer
1797 ) ;
1798 }
1799 catch (Exception ouch)
1800 {
1801 log.debug("Exception thrown by FileStore.importInit()");
1802 log.debug(" Exception : " + ouch);
1803 throw new FileManagerServiceException(
1804 "Error occurred when calling FileStore service"
1805 );
1806 }
1807
1808
1809 current.merge(
1810 result.getFileProperties(),
1811 new FileManagerPropertyFilter()
1812 );
1813
1814
1815 current.setManagerLocationIvorn(
1816 targetIvorn
1817 );
1818
1819
1820 try {
1821 sourceStore.delete(
1822 sourceIdent
1823 ) ;
1824 }
1825 catch (Exception ouch)
1826 {
1827 log.warn("Exception thrown by FileStore.delete()");
1828 log.warn(" Exception : " + ouch);
1829
1830
1831
1832
1833
1834
1835 }
1836 }
1837
1838
1839 else {
1840 log.debug(" PASS : No data stored yet.");
1841 log.debug("Setting location ivorn");
1842 log.debug(" Dest : " + targetIvorn.toString());
1843
1844
1845
1846
1847
1848 current.setManagerLocationIvorn(
1849 targetIvorn
1850 );
1851 }
1852 }
1853
1854
1855 else {
1856 log.debug("");
1857 log.debug("FAIL : Node is not a data node");
1858
1859
1860
1861 throw new UnsupportedOperationException(
1862 "Container location move not implemented yet"
1863 );
1864 }
1865 }
1866
1867 /***
1868 * Create a copy of a node.
1869 * If the node already has stored data, then this will create a new copy of the data.
1870 * @param request The request properties.
1871 * @return A set of properties for the new node.
1872 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1873 * @throws NodeNotFoundException If the current node is no longer in the database.
1874 * @throws NodeNotFoundException If the new parent node is no longer in the database.
1875 * @throws FileManagerServiceException If a problem occurs when handling the request.
1876 *
1877 */
1878 public FileProperty[] copy(FileProperty[] request)
1879 throws
1880 NodeNotFoundException,
1881 DuplicateNodeException,
1882 FileManagerServiceException
1883 {
1884 log.debug("");
1885 log.debug("FileManagerMock.copy(FileProperty[])");
1886 if (null == request)
1887 {
1888 throw new NodeNotFoundException(
1889 "Null request properties"
1890 ) ;
1891 }
1892
1893
1894 FileManagerProperties properties = new FileManagerProperties(
1895 request
1896 );
1897
1898
1899 Ivorn ivorn = null ;
1900 try {
1901 ivorn = properties.getManagerResourceIvorn();
1902 }
1903 catch (FileManagerIdentifierException ouch)
1904 {
1905 throw new NodeNotFoundException(
1906 "Unable to parse node ivorn"
1907 );
1908 }
1909
1910
1911 return this.copy(
1912 this.node(
1913 ivorn
1914 ),
1915 properties
1916 ).getProperties().toArray() ;
1917 }
1918
1919 /***
1920 * Create a copy of a node.
1921 * If the node already has stored data, then this will create a new copy of the data.
1922 * @param node The target node.
1923 * @param request The request properties.
1924 * @return A set of properties for the new node.
1925 * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
1926 * @throws NodeNotFoundException If the new parent node is no longer in the database.
1927 * @throws FileManagerServiceException If a problem occurs when handling the request.
1928 *
1929 */
1930 protected FileManagerStoreNode copy(FileManagerStoreNode node, FileManagerProperties request)
1931 throws DuplicateNodeException, NodeNotFoundException, FileManagerServiceException
1932 {
1933 log.debug("");
1934 log.debug("FileManagerMock.copy(Node, FileManagerProperties)");
1935 log.debug(" Node : " + node.getName());
1936 log.debug(" Node : " + node.getIdent());
1937
1938
1939 if (node.isDataNode())
1940 {
1941 log.debug("");
1942 log.debug("PASS : Node is a data node");
1943
1944
1945 FileManagerProperties currentProperties = node.getProperties();
1946
1947
1948 FileManagerProperties changedProperties = currentProperties.difference(
1949 request
1950 );
1951
1952
1953 FileManagerProperties targetProperties = new FileManagerProperties(
1954 currentProperties
1955 );
1956 targetProperties.merge(
1957 request,
1958 new FileManagerResourceFilter()
1959 );
1960
1961
1962 FileManagerStoreNode parentNode = null ;
1963 try {
1964 parentNode = this.node(
1965 targetProperties.getManagerParentIvorn()
1966 );
1967 }
1968 catch (FileManagerIdentifierException ouch)
1969 {
1970 throw new NodeNotFoundException(
1971 "Unable to parse parent node ivorn"
1972 );
1973 }
1974
1975
1976 FileManagerStoreNode resultNode = this.addNode(
1977 parentNode,
1978 targetProperties.getManagerResourceName(),
1979 FileManagerProperties.DATA_NODE_TYPE
1980 );
1981 log.debug(" PASS : Created node copy");
1982
1983
1984 FileManagerProperties resultProperties = resultNode.getProperties();
1985
1986
1987 Ivorn currentStoreIvorn = null ;
1988 String currentStoreIdent = null ;
1989 try {
1990 currentStoreIvorn = currentProperties.getStoreResourceIvorn() ;
1991 currentStoreIdent = currentProperties.getStoreResourceIdent() ;
1992 }
1993 catch (FileStoreIdentifierException ouch)
1994 {
1995 throw new FileManagerServiceException(
1996 "Unable to parse current filestore ivorn"
1997 );
1998 }
1999
2000
2001 if (null != currentStoreIvorn)
2002 {
2003 log.debug(" PASS : Node has data");
2004
2005
2006 Ivorn changedLocation = null ;
2007 try {
2008 changedLocation = changedProperties.getManagerLocationIvorn() ;
2009 }
2010 catch (FileManagerIdentifierException ouch)
2011 {
2012 throw new FileManagerServiceException(
2013 "Unable to parse changed filestore ivorn"
2014 );
2015 }
2016
2017
2018 if (null != changedLocation)
2019 {
2020 FileStoreDelegate sourceStore = null ;
2021 FileStoreDelegate targetStore = null ;
2022
2023
2024 try {
2025 sourceStore = resolve(
2026 currentStoreIvorn
2027 ) ;
2028 }
2029 catch (Exception ouch)
2030 {
2031 throw new FileManagerServiceException(
2032 "Unable to resolve current filestore"
2033 );
2034 }
2035
2036
2037 try {
2038 targetStore = resolve(
2039 changedLocation
2040 ) ;
2041 }
2042 catch (Exception ouch)
2043 {
2044 throw new FileManagerServiceException(
2045 "Unable to resolve target filestore"
2046 );
2047 }
2048
2049
2050 TransferProperties transfer = null ;
2051 try {
2052 transfer =
2053 sourceStore.exportInit(
2054 new UrlGetRequest(
2055 currentProperties
2056 )
2057 ) ;
2058 }
2059 catch (Exception ouch)
2060 {
2061 log.debug("Exception thrown by FileStore.importInit()");
2062 log.debug(" Exception : " + ouch);
2063 throw new FileManagerServiceException(
2064 "Unable to initiate data transfer"
2065 );
2066 }
2067
2068
2069 TransferProperties transferResult = null ;
2070 try {
2071 transferResult =
2072 targetStore.importData(
2073 transfer
2074 ) ;
2075 }
2076 catch (Exception ouch)
2077 {
2078 log.debug("Exception thrown by FileStore.importInit()");
2079 log.debug(" Exception : " + ouch);
2080 throw new FileManagerServiceException(
2081 "Unable to complete data transfer"
2082 );
2083 }
2084
2085
2086 resultProperties.merge(
2087 transferResult.getFileProperties(),
2088 new FileManagerPropertyFilter()
2089 );
2090
2091
2092 resultProperties.setManagerLocationIvorn(
2093 changedLocation
2094 );
2095 }
2096
2097
2098 else {
2099 log.debug(" PASS : Location not changed");
2100
2101
2102 FileStoreDelegate filestore = resolve(
2103 currentStoreIvorn
2104 ) ;
2105 log.debug(" PASS : Got current filestore");
2106
2107
2108 try {
2109 log.debug(" PASS : Asking filestore for duplicate");
2110
2111
2112 FileManagerProperties updatedProperties = new FileManagerProperties(
2113 filestore.duplicate(
2114 currentStoreIdent,
2115 resultProperties.toArray()
2116 )
2117 );
2118 log.debug(" PASS : Got duplicate from filestore");
2119
2120
2121 resultProperties.merge(
2122 updatedProperties,
2123 new FileManagerPropertyFilter()
2124 );
2125 log.debug(" PASS : Merged updated properties");
2126 }
2127 catch(Exception ouch)
2128 {
2129 log.warn("Exception thrown by FileStore.duplicate()");
2130 log.warn(" Exception : " + ouch);
2131
2132
2133
2134
2135
2136 }
2137 }
2138 }
2139
2140
2141 else {
2142 log.debug(" PASS : Node is empty");
2143
2144
2145 Ivorn changedLocation = null ;
2146 try {
2147 changedLocation = changedProperties.getManagerLocationIvorn() ;
2148 }
2149 catch (FileManagerIdentifierException ouch)
2150 {
2151 throw new FileManagerServiceException(
2152 "Unable to parse changed filestore ivorn"
2153 );
2154 }
2155
2156
2157 if (null != changedLocation)
2158 {
2159 log.debug(" PASS : Location changed");
2160
2161
2162 resultProperties.setManagerLocationIvorn(
2163 changedLocation
2164 );
2165
2166
2167
2168
2169 }
2170 }
2171
2172
2173 return resultNode ;
2174 }
2175
2176
2177 else {
2178 log.debug("");
2179 log.debug("FAIL : Node is not a data node");
2180
2181
2182 throw new UnsupportedOperationException(
2183 "Container location copy not implemented yet"
2184 );
2185 }
2186 }
2187
2188 /***
2189 * Delete a node.
2190 * @param ivorn The node (ivorn) identifier.
2191 * @throws NodeNotFoundException If the node does not exist.
2192 * @throws FileManagerServiceException If a problem occurs when handling the request.
2193 * @todo Refactor this to take an ivorn.
2194 *
2195 */
2196 public void delete(String ivorn)
2197 throws
2198 NodeNotFoundException,
2199 FileManagerServiceException
2200 {
2201 log.debug("");
2202 log.debug("FileManagerMock.delete(String)");
2203 log.debug(" Ivorn : " + ivorn);
2204 if (null == ivorn)
2205 {
2206 throw new IllegalArgumentException(
2207 "Null node identifier"
2208 ) ;
2209 }
2210
2211
2212 String ident = null ;
2213 try {
2214 ident = new FileManagerIvornParser(
2215 ivorn
2216 ).getResourceIdent();
2217 }
2218 catch (FileManagerIdentifierException ouch)
2219 {
2220 throw new NodeNotFoundException(
2221 "Unable to parse node identifier"
2222 );
2223 }
2224
2225
2226 deleteNode(
2227 this.node(
2228 ident
2229 )
2230 );
2231 }
2232
2233 /***
2234 * Delete a node.
2235 * @param node The node to delete.
2236 * @throws NodeNotFoundException If the node does not exist.
2237 * @throws FileManagerServiceException If a problem occurs when handling the request.
2238 *
2239 */
2240 protected void deleteNode(FileManagerStoreNode node)
2241 throws NodeNotFoundException, FileManagerServiceException
2242 {
2243 log.debug("");
2244 log.debug("FileManagerMock.delete(Node)");
2245 log.debug(" Node : " + node.getName());
2246 log.debug(" Node : " + node.getIdent());
2247
2248
2249 FileManagerStoreNode parent = null;
2250 try {
2251 parent = this.node(
2252 node.getParentIvorn()
2253 );
2254 }
2255 catch (FileManagerIdentifierException ouch)
2256 {
2257 throw new FileManagerServiceException(
2258 "Unable to parse parent node identifier"
2259 );
2260 }
2261 catch (NodeNotFoundException ouch)
2262 {
2263 throw new FileManagerServiceException(
2264 "Unable to locate parent node"
2265 );
2266 }
2267
2268
2269 if (node.isDataNode())
2270 {
2271 log.debug("");
2272 log.debug("PASS : Node is a data node");
2273
2274
2275 FileManagerProperties current = node.getProperties();
2276
2277
2278 Ivorn sourceIvorn = null ;
2279 String sourceIdent = null ;
2280 try {
2281 sourceIvorn = current.getStoreResourceIvorn() ;
2282 sourceIdent = current.getStoreResourceIdent() ;
2283 }
2284 catch (FileStoreIdentifierException ouch)
2285 {
2286 log.warn("");
2287 log.warn("Unable to parse current store resource ivorn");
2288 log.warn(ouch);
2289 throw new FileManagerServiceException(
2290 "Unable to parse current store resource ivorn"
2291 );
2292 }
2293
2294
2295 if (null != sourceIvorn)
2296 {
2297 log.debug("");
2298 log.debug(" PASS : Node has stored data");
2299 log.debug(" PASS : Got store resource ivorn");
2300 log.debug(" Ivorn : " + sourceIvorn.toString());
2301
2302
2303 FileStoreDelegate sourceStore = resolve(
2304 sourceIvorn
2305 ) ;
2306 log.debug(" PASS : Got source filestore");
2307
2308
2309 try {
2310 sourceStore.delete(
2311 sourceIdent
2312 ) ;
2313 }
2314 catch (Exception ouch)
2315 {
2316 log.warn("Exception thrown by FileStore.delete()");
2317 log.warn(" Exception : " + ouch);
2318
2319
2320
2321
2322
2323 }
2324 }
2325
2326
2327 else {
2328 log.debug(" PASS : Node is empty");
2329 }
2330
2331
2332 store.delNode(
2333 node
2334 );
2335
2336
2337 try {
2338 parent.delNode(
2339 node.getName()
2340 );
2341 }
2342 catch (NodeNotFoundException ouch)
2343 {
2344
2345
2346 log.warn("");
2347 log.warn("Move failed to remove node from original parent");
2348 log.warn("Parent : " + parent.getIdent());
2349 log.warn("Child : " + node.getIdent());
2350 }
2351 }
2352
2353
2354 else {
2355 log.debug("");
2356 log.debug("FAIL : Node is a container node");
2357 }
2358 }
2359
2360 /***
2361 * Transfer data from a source URL into a node.
2362 * @param request The transfer request properties.
2363 * @return The updated file properties for the node, after the transfer.
2364 * @throws NodeNotFoundException If the target node does not exist.
2365 * @throws FileManagerServiceException If a problem occurs when handling the request.
2366 * @todo Refactor this to handle path, and create missing folders.
2367 *
2368 */
2369 public FileProperty[] importData(TransferProperties request)
2370 throws
2371 NodeNotFoundException,
2372 FileManagerServiceException
2373 {
2374 log.debug("");
2375 log.debug("FileManagerMock.importData(TransferProperties)");
2376 if (null == request)
2377 {
2378 throw new NodeNotFoundException(
2379 "Null transfer properties"
2380 ) ;
2381 }
2382
2383
2384 FileManagerProperties properties = new FileManagerProperties(
2385 request.getFileProperties()
2386 );
2387 if (null == properties)
2388 {
2389 throw new NodeNotFoundException(
2390 "Null target properties"
2391 ) ;
2392 }
2393
2394
2395 String ident = null ;
2396 try {
2397 ident = properties.getManagerResourceIdent() ;
2398 }
2399 catch (FileManagerIdentifierException ouch)
2400 {
2401 throw new NodeNotFoundException(
2402 "Unable to parse resource ivorn"
2403 );
2404 }
2405
2406
2407 if (null == ident)
2408 {
2409 throw new NodeNotFoundException(
2410 "Null node identifier"
2411 );
2412 }
2413
2414
2415 else {
2416
2417
2418 if (store.hasNode(ident))
2419 {
2420 FileManagerStoreNode node = store.getNode(ident) ;
2421 log.debug("");
2422 log.debug(" Node : " + node.getName());
2423 log.debug(" Node : " + node.getIdent());
2424
2425
2426 return this.importData(
2427 node,
2428 request
2429 ) ;
2430 }
2431
2432
2433 else {
2434 throw new NodeNotFoundException();
2435 }
2436 }
2437 }
2438
2439 /***
2440 * Transfer data from a source URL into a node.
2441 * @param node The target node.
2442 * @param request The transfer request properties.
2443 * @return The updated properties for the node.
2444 * @throws NodeNotFoundException If the target node does not exist.
2445 * @throws FileManagerServiceException If a problem occurs when handling the request.
2446 * @todo Refactor this to handle path, and create missing folders.
2447 *
2448 */
2449 protected FileProperty[] importData(FileManagerStoreNode node, TransferProperties request)
2450 throws FileManagerServiceException, NodeNotFoundException
2451 {
2452 log.debug("");
2453 log.debug("FileManagerMock.importData(Node, TransferProperties)");
2454 log.debug(" Node : " + node.getName());
2455 log.debug(" Node : " + node.getIdent());
2456
2457
2458 if (node.isDataNode() != true)
2459 {
2460 throw new FileManagerServiceException(
2461 "Invalid operation, not a data node"
2462 );
2463 }
2464
2465
2466 if (null == request.getLocation())
2467 {
2468 throw new FileManagerServiceException(
2469 "Null source URL"
2470 );
2471 }
2472
2473
2474 URL source = null ;
2475 try {
2476 source = new URL(
2477 request.getLocation()
2478 );
2479 }
2480 catch(Exception ouch)
2481 {
2482 throw new FileManagerServiceException(
2483 "Invalid source URL",
2484 ouch
2485 );
2486 }
2487
2488
2489 FileManagerProperties current = node.getProperties();
2490
2491
2492 current.merge(
2493 request.getFileProperties(),
2494 new FileManagerPropertyFilter()
2495 );
2496
2497
2498 TransferProperties transfer = new UrlGetTransfer(
2499 source,
2500 current
2501 );
2502
2503
2504 Ivorn target = null ;
2505 try {
2506 target = current.getStoreResourceIvorn() ;
2507 }
2508 catch (FileStoreIdentifierException ouch)
2509 {
2510 log.warn("");
2511 log.warn("Unable to parse store location");
2512 log.warn(ouch);
2513 throw new FileManagerServiceException(
2514 "Unable to parse store location"
2515 );
2516 }
2517
2518
2519 if (null == target)
2520 {
2521
2522
2523 try {
2524 target = current.getManagerLocationIvorn();
2525 }
2526 catch (FileManagerIdentifierException ouch)
2527 {
2528 log.warn("");
2529 log.warn("Unable to parse store location");
2530 log.warn(ouch);
2531 throw new FileManagerServiceException(
2532 "Unable to parse store location"
2533 );
2534 }
2535
2536
2537 if (null == target)
2538 {
2539
2540
2541 target = config.getFileStoreIvorn() ;
2542 }
2543 }
2544
2545
2546 FileStoreDelegate filestore = resolve(
2547 target
2548 ) ;
2549
2550
2551 TransferProperties response = null ;
2552 try {
2553 response =
2554 filestore.importData(
2555 transfer
2556 ) ;
2557 }
2558 catch (Exception ouch)
2559 {
2560 log.debug("Exception thrown by FileStore.importdata()");
2561 log.debug(" Exception : " + ouch);
2562 throw new FileManagerServiceException(
2563 "Error occurred when calling FileStore service"
2564 );
2565 }
2566
2567
2568 current.merge(
2569 response.getFileProperties(),
2570 new FileManagerPropertyFilter()
2571 );
2572
2573
2574 node.setProperties(
2575 current
2576 ) ;
2577
2578
2579 return current.toArray() ;
2580 }
2581
2582
2583 /***
2584 * Transfer data transfer from a node into destination URL.
2585 * @param request The request properties.
2586 * @throws NodeNotFoundException If the target node does not exist.
2587 * @throws FileManagerServiceException If a problem occurs when handling the request.
2588 *
2589 */
2590 public TransferProperties exportData(FileProperty[] request)
2591 throws
2592 NodeNotFoundException,
2593 FileManagerServiceException
2594 {
2595 return null ;
2596 }
2597
2598 }