1
2
3
4
5
6 package pt.digitalis.dif.utils.extensions.cms;
7
8 import java.util.ArrayList;
9 import java.util.HashSet;
10 import java.util.List;
11 import java.util.Set;
12
13 import pt.digitalis.dif.controller.security.objects.IDIFUser;
14 import pt.digitalis.dif.exception.security.IdentityManagerException;
15 import pt.digitalis.dif.utils.extensions.cms.exception.ContentItemNotFoundException;
16 import pt.digitalis.dif.utils.extensions.cms.exception.ContentItemWithDuplicateNameAndParentNodeException;
17 import pt.digitalis.dif.utils.extensions.cms.exception.ContentManagerException;
18 import pt.digitalis.dif.utils.extensions.cms.exception.InvalidParentNodeException;
19 import pt.digitalis.dif.utils.extensions.cms.exception.InvalidPathException;
20 import pt.digitalis.dif.utils.extensions.cms.exception.NoAccessException;
21 import pt.digitalis.dif.utils.extensions.cms.exception.NodeNotFoundException;
22 import pt.digitalis.dif.utils.extensions.cms.exception.NodeWithDuplicatePathException;
23 import pt.digitalis.dif.utils.extensions.cms.exception.NodeWithNodesException;
24
25
26
27
28
29
30
31 public abstract class AbstractContentManager implements IContentManager {
32
33
34 protected static char SEPARATOR = '\\';
35
36
37
38
39 public ContentItem addContent(ContentItem content) throws ContentManagerException
40 {
41
42 if (content.getUser() == null)
43 {
44 throw new NoAccessException("The Content User attribute must be filled to complete the insert");
45 }
46
47 if (content.getParentNodeId() != null)
48 {
49 try
50 {
51 if (!nodeExists(content.getParentNodeId(), content.getUser()))
52 throw new InvalidParentNodeException();
53 }
54 catch (Exception e)
55 {
56 throw new InvalidParentNodeException(e);
57 }
58
59 if (!hasNodeAccessUser(content.getParentNodeId(), content.getUser()))
60 throw new NoAccessException("User doesn't have access to the parent node");
61 }
62
63 return persistContentInRepository(content, content.getUser());
64 }
65
66
67
68
69 public Node addNode(Node node) throws ContentManagerException
70 {
71 if (node == null)
72 throw new NodeNotFoundException();
73
74 if (node.getUser() == null)
75 {
76 throw new NoAccessException("The Node User attribute must be filled to complete the insert");
77 }
78
79 String fullPath = determineFullPath(node);
80
81 if (!validadeNameAndPath(fullPath, true))
82 throw new InvalidPathException("Invalid path: " + fullPath);
83
84 node.setFullPathName(fullPath);
85
86 if (node.getParentNodeId() != null)
87 if (!hasNodeAccessUser(node.getParentNodeId(), node.getUser()))
88 throw new NoAccessException("User doesn't have access to the parent node");
89
90 return persistNodeInRepository(node, node.getUser());
91 }
92
93
94
95
96
97
98
99
100
101
102 protected List<ContentItem> checkContentAccessInList(List<ContentItem> listToCheck, IDIFUser user)
103 {
104 List<ContentItem> reviewedList = new ArrayList<ContentItem>();
105
106 for (ContentItem content: listToCheck)
107 {
108 try
109 {
110 if (hasContentAccessUser(content, user))
111 reviewedList.add(content);
112 }
113 catch (ContentManagerException e)
114 {
115
116 }
117 }
118
119 return reviewedList;
120 }
121
122
123
124
125
126
127
128
129
130
131 protected List<Node> checkNodeAccessInList(List<Node> listToCheck, IDIFUser user)
132 {
133 List<Node> reviewedList = new ArrayList<Node>();
134
135 for (Node node: listToCheck)
136 {
137 try
138 {
139 if (hasNodeAccessUser(node, user))
140 reviewedList.add(node);
141 }
142 catch (ContentManagerException e)
143 {
144
145 }
146 }
147
148 return reviewedList;
149 }
150
151
152
153
154
155 public boolean deleteContent(String id, IDIFUser user) throws ContentManagerException
156 {
157 if (!hasContentAccessUser(id, user))
158 throw new NoAccessException("User doesn't have access to content");
159
160 return deleteContentInRepository(id, user);
161 }
162
163
164
165
166
167
168
169
170
171
172
173 protected abstract boolean deleteContentInRepository(String id, IDIFUser user) throws ContentManagerException;
174
175
176
177
178
179 public boolean deleteNode(Long id, IDIFUser user) throws ContentManagerException
180 {
181 return deleteNode(id, user, false);
182 }
183
184
185
186
187
188 public boolean deleteNode(Long id, IDIFUser user, boolean cascadeDelete) throws ContentManagerException
189 {
190 if (!hasNodeAccessUser(id, user))
191 throw new NoAccessException("User doesn't have access to node");
192
193 return deleteNodeInRepository(id, user, cascadeDelete);
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 protected abstract boolean deleteNodeInRepository(Long nodeId, IDIFUser user, boolean cascadeDelete)
212 throws NodeNotFoundException, NodeWithNodesException, ContentManagerException;
213
214
215
216
217
218
219
220
221
222 protected String determineFullPath(Node node) throws ContentManagerException
223 {
224 if (node.getParentNodeId() == null)
225 return SEPARATOR + node.getName();
226 else
227 {
228 String fullPathFromRep = getParentFullPathInRepository(node);
229
230 if (!validadeNameAndPath(fullPathFromRep, true))
231 throw new InvalidPathException("Invalid path: " + fullPathFromRep);
232
233 return fullPathFromRep + SEPARATOR + node.getName();
234 }
235 }
236
237
238
239
240
241 public List<ContentItem> getContentByDescription(String description, IDIFUser user) throws ContentManagerException
242 {
243 return checkContentAccessInList(getContentByDescriptionInRepository(description, user), user);
244 }
245
246
247
248
249
250
251
252
253
254
255
256 protected abstract List<ContentItem> getContentByDescriptionInRepository(String description, IDIFUser user)
257 throws ContentManagerException;
258
259
260
261
262
263 public ContentItem getContentById(String id, IDIFUser user) throws ContentManagerException
264 {
265 ContentItem contentItem = getContentByIdInRepository(id, user);
266 if (!hasContentAccessUser(contentItem, user))
267 throw new NoAccessException("User has no access to content item");
268
269 return contentItem;
270 }
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 protected abstract ContentItem getContentByIdInRepository(String id, IDIFUser user)
286 throws ContentItemNotFoundException, NoAccessException, NodeNotFoundException, ContentManagerException;
287
288
289
290
291
292
293
294
295
296
297
298 protected ContentItem getContentByIdNoPermissions(String id, IDIFUser user) throws ContentManagerException
299 {
300 return getContentByIdNoPermissionsInRepository(id, user);
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314 protected abstract ContentItem getContentByIdNoPermissionsInRepository(String id, IDIFUser user)
315 throws ContentItemNotFoundException, ContentManagerException;
316
317
318
319
320
321 public List<ContentItem> getContentByName(String name, IDIFUser user) throws ContentManagerException
322 {
323 return checkContentAccessInList(getContentByNameInRepository(name, user), user);
324 }
325
326
327
328
329
330
331
332
333
334
335
336 protected abstract List<ContentItem> getContentByNameInRepository(String name, IDIFUser user)
337 throws ContentManagerException;
338
339
340
341
342
343 public List<ContentItem> getContentByParentNode(Long nodeId, IDIFUser user) throws ContentManagerException
344 {
345
346 getNodeByIdNoPermissions(nodeId, user);
347
348 return checkContentAccessInList(getContentByParentNodeInRepository(nodeId, user), user);
349 }
350
351
352
353
354
355
356
357
358
359
360
361 protected abstract List<ContentItem> getContentByParentNodeInRepository(Long nodeId, IDIFUser user)
362 throws ContentManagerException;
363
364
365
366
367
368 public ContentItem getContentFromNodePathByName(String nodeFullPath, String name, IDIFUser user)
369 throws ContentManagerException
370 {
371 ContentItem contentItem = getContentFromNodePathByNameRepository(nodeFullPath, name, user);
372 if (!hasContentAccessUser(contentItem, user))
373 throw new NoAccessException("User has no access to content item");
374
375 return contentItem;
376 }
377
378
379
380
381
382
383
384
385
386
387
388
389
390 protected abstract ContentItem getContentFromNodePathByNameRepository(String nodeFullPath, String name,
391 IDIFUser user) throws ContentManagerException;
392
393
394
395
396 public List<ACLEntry> getContentItemACL(String id) throws ContentManagerException
397 {
398 return getContentItemACLInRepository(id);
399 }
400
401
402
403
404
405
406
407
408
409 protected abstract List<ACLEntry> getContentItemACLInRepository(String id) throws ContentManagerException;
410
411
412
413
414 public List<ACLEntry> getNodeACL(Long id) throws ContentManagerException
415 {
416 return getNodeACLInRepository(id);
417 }
418
419
420
421
422
423
424
425
426
427 protected abstract List<ACLEntry> getNodeACLInRepository(Long id) throws ContentManagerException;
428
429
430
431
432
433 public Node getNodeById(Long id, IDIFUser user) throws ContentManagerException
434 {
435 Node node = getNodeByIdInRepository(id, user);
436 if (!hasNodeAccessUser(node, user))
437 throw new NoAccessException("User does not have access to the Node");
438
439 return node;
440 }
441
442
443
444
445
446
447
448
449
450
451
452 protected abstract Node getNodeByIdInRepository(Long id, IDIFUser user) throws ContentManagerException;
453
454
455
456
457
458
459
460
461
462
463
464 protected Node getNodeByIdNoPermissions(Long nodeID, IDIFUser user) throws ContentManagerException
465 {
466 Node node = getNodeByIdNoPermissionsInRepository(nodeID, user);
467
468 if (node == null)
469 throw new NodeNotFoundException(nodeID);
470
471 return node;
472 }
473
474
475
476
477
478
479
480
481
482
483
484
485 protected abstract Node getNodeByIdNoPermissionsInRepository(Long id, IDIFUser user) throws NodeNotFoundException,
486 ContentManagerException;
487
488
489
490
491
492 public Node getNodeByPath(String fullPath, IDIFUser user) throws ContentManagerException
493 {
494 Node node = getNodeByPathInRespository(fullPath, user);
495 if (user != null)
496 if (!hasNodeAccessUser(node, user))
497 throw new NoAccessException("User doesn't have access to the Node");
498
499 return node;
500 }
501
502
503
504
505
506
507
508
509
510
511
512
513
514 protected abstract Node getNodeByPathInRespository(String fullPath, IDIFUser user) throws NodeNotFoundException,
515 NoAccessException, ContentManagerException;
516
517
518
519
520
521
522
523
524
525
526
527 protected Node getNodeByPathNoPermissions(String nodePath, IDIFUser user) throws ContentManagerException
528 {
529 return getNodeByPathInRespository(nodePath, user);
530 }
531
532
533
534
535
536 public List<Node> getNodesByDescription(String description, IDIFUser user) throws ContentManagerException
537 {
538 return checkNodeAccessInList(getNodesByDescriptionInRepository(description, user), user);
539 }
540
541
542
543
544
545 public List<Node> getNodesByDescription(String basePathToSearch, String description, IDIFUser user)
546 throws ContentManagerException
547 {
548 return checkNodeAccessInList(getNodesByDescriptionInRepository(basePathToSearch, description, user), user);
549 }
550
551
552
553
554
555
556
557
558
559
560
561 protected abstract List<Node> getNodesByDescriptionInRepository(String description, IDIFUser user)
562 throws ContentManagerException;
563
564
565
566
567
568
569
570
571
572
573
574
575
576 protected abstract List<Node> getNodesByDescriptionInRepository(String basePathToSearch, String description,
577 IDIFUser user) throws ContentManagerException;
578
579
580
581
582
583 public List<Node> getNodesByName(String name, IDIFUser user) throws ContentManagerException
584 {
585 return checkNodeAccessInList(getNodesByNameInRepository(name, user), user);
586 }
587
588
589
590
591
592 public List<Node> getNodesByName(String basePathToSearch, String name, IDIFUser user)
593 throws ContentManagerException
594 {
595 return checkNodeAccessInList(getNodesByNameInRepository(basePathToSearch, name, user), user);
596 }
597
598
599
600
601
602
603
604
605
606
607
608 protected abstract List<Node> getNodesByNameInRepository(String name, IDIFUser user) throws ContentManagerException;
609
610
611
612
613
614
615
616
617
618
619
620
621
622 protected abstract List<Node> getNodesByNameInRepository(String basePathToSearch, String name, IDIFUser user)
623 throws ContentManagerException;
624
625
626
627
628
629 public List<Node> getNodesByParentNode(Long nodeId, IDIFUser user) throws ContentManagerException
630 {
631 return checkNodeAccessInList(getNodesByParentNodeInRepository(nodeId, user), user);
632 }
633
634
635
636
637
638
639
640
641
642
643
644 protected abstract List<Node> getNodesByParentNodeInRepository(Long nodeId, IDIFUser user)
645 throws ContentManagerException;
646
647
648
649
650
651
652
653
654
655
656
657 protected List<Node> getNodesByParentNodeNoPermissions(Long nodeId, IDIFUser user) throws ContentManagerException
658 {
659 getNodeByIdNoPermissions(nodeId, user);
660
661 return getNodesByParentNodeNoPermissionsInRepository(nodeId, user);
662 }
663
664
665
666
667
668
669
670
671
672
673
674 protected abstract List<Node> getNodesByParentNodeNoPermissionsInRepository(Long nodeId, IDIFUser user)
675 throws ContentManagerException;
676
677
678
679
680
681
682
683
684
685
686 protected abstract String getParentFullPathInRepository(Node node) throws InvalidParentNodeException,
687 ContentManagerException;
688
689
690
691
692 public List<Node> getRootNodes(IDIFUser user) throws ContentManagerException
693 {
694 return checkNodeAccessInList(getRootNodesInRepository(user), user);
695 }
696
697
698
699
700
701
702
703
704
705 protected abstract List<Node> getRootNodesInRepository(IDIFUser user) throws ContentManagerException;
706
707
708
709
710
711
712
713
714
715
716
717 public boolean grantContentAccessToGroup(String contentId, String groupId) throws ContentManagerException
718 {
719 ContentItem contentItem = this.getContentByIdNoPermissions(contentId, null);
720
721 if (contentItem == null)
722 throw new ContentItemNotFoundException(contentId);
723
724 return grantContentAccessToGroupInRepository(contentItem, groupId);
725 }
726
727
728
729
730
731
732
733
734
735
736
737 protected abstract boolean grantContentAccessToGroupInRepository(ContentItem contentItemParam, String groupId)
738 throws ContentManagerException;
739
740
741
742
743
744 public boolean grantContentAccessToUser(String contentId, IDIFUser user) throws ContentManagerException
745 {
746 ContentItem contentItem = getContentByIdNoPermissions(contentId, user);
747
748 if (contentItem == null)
749 throw new ContentItemNotFoundException(contentId);
750
751 return grantContentAccessToUserInRepository(contentItem, user);
752 }
753
754
755
756
757
758
759
760
761
762
763
764 protected abstract boolean grantContentAccessToUserInRepository(ContentItem contentItemParam, IDIFUser user)
765 throws ContentManagerException;
766
767
768
769
770
771 public boolean grantNodeAccessToGroup(Long nodeId, String groupId) throws ContentManagerException
772 {
773 Node node = getNodeByIdNoPermissions(nodeId, null);
774
775 return grantNodeAccessToGroupInRepository(node, groupId);
776 }
777
778
779
780
781
782
783
784
785
786
787
788 protected abstract boolean grantNodeAccessToGroupInRepository(Node nodeParam, String groupId)
789 throws ContentManagerException;
790
791
792
793
794
795 public boolean grantNodeAccessToUser(Long nodeId, IDIFUser user) throws ContentManagerException
796 {
797 Node node = this.getNodeByIdNoPermissions(nodeId, user);
798
799 return grantNodeAccessToUserInRepository(node, user);
800 }
801
802
803
804
805
806 public boolean grantNodeAccessToUser(String nodePath, IDIFUser user) throws ContentManagerException
807 {
808 Node node = getNodeByPathNoPermissions(nodePath, user);
809 return grantNodeAccessToUser(node.getId(), user);
810 }
811
812
813
814
815
816
817
818
819
820
821
822 protected abstract boolean grantNodeAccessToUserInRepository(Node nodeParam, IDIFUser user)
823 throws ContentManagerException;
824
825
826
827
828
829
830
831
832
833
834
835 public boolean hasContentAccessGroup(ContentItem contentItem, String groupId) throws ContentManagerException
836 {
837 Node node = getNodeByIdNoPermissions(contentItem.getParentNodeId(), null);
838
839 if (node.isPublic())
840 return true;
841
842 Set<String> groups = new HashSet<String>();
843 groups.add(groupId);
844
845 if (hasContentAccessGroupsInRepository(contentItem.getId(), groups))
846 return true;
847 else
848 return hasNodeAccessGroups(contentItem.getParentNodeId(), groups);
849 }
850
851
852
853
854
855 public boolean hasContentAccessGroup(String contentId, String groupId) throws ContentManagerException
856 {
857 ContentItem contentItem = getContentByIdNoPermissions(contentId, null);
858
859 return hasContentAccessGroup(contentItem, groupId);
860 }
861
862
863
864
865
866
867
868
869
870
871
872 public boolean hasContentAccessGroups(ContentItem contentItem, Set<String> groups) throws ContentManagerException
873 {
874 Node node = getNodeByIdNoPermissions(contentItem.getParentNodeId(), null);
875
876 if (node.isPublic())
877 return true;
878
879 if (hasContentAccessGroupsInRepository(contentItem.getId(), groups))
880 return true;
881 else
882 return hasNodeAccessGroups(contentItem.getParentNodeId(), groups);
883 }
884
885
886
887
888
889
890
891
892
893
894
895 protected abstract boolean hasContentAccessGroupsInRepository(String contentId, Set<String> groups)
896 throws ContentManagerException;
897
898
899
900
901
902 public boolean hasContentAccessUser(ContentItem contentItem, IDIFUser user) throws ContentManagerException
903 {
904 boolean result = false;
905 if (hasNodeAccessUser(contentItem.getParentNodeId(), user))
906 {
907 result = true;
908 }
909
910 if (!result && hasContentAccessUserInRepository(contentItem.getId(), user))
911 result = true;
912
913 try
914 {
915 if (!result && hasContentAccessGroups(contentItem, user.getGroupIDs()))
916 result = true;
917 }
918 catch (IdentityManagerException e)
919 {
920 throw new ContentItemNotFoundException(e);
921 }
922
923 return result;
924
925 }
926
927
928
929
930
931 public boolean hasContentAccessUser(String contentId, IDIFUser user) throws ContentManagerException
932 {
933 ContentItem contentItem = getContentByIdNoPermissions(contentId, user);
934
935 if (contentItem == null)
936 throw new ContentItemNotFoundException(contentId);
937
938 return hasContentAccessUser(contentItem, user);
939
940 }
941
942
943
944
945
946
947
948
949
950
951
952 protected abstract boolean hasContentAccessUserInRepository(String contentId, IDIFUser user)
953 throws ContentManagerException;
954
955
956
957
958 public boolean hasNodeAccessGroups(Long nodeId, Set<String> groups) throws ContentManagerException
959 {
960 Node node = getNodeByIdNoPermissions(nodeId, null);
961
962 if (node.isPublic())
963 return true;
964
965 if (hasNodeAccessGroupsInRepository(nodeId, groups))
966 return true;
967
968 if (node.getParentNodeId() != null)
969 return hasNodeAccessGroups(node.getParentNodeId(), groups);
970
971 return false;
972 }
973
974
975
976
977
978
979
980
981
982
983
984 protected abstract boolean hasNodeAccessGroupsInRepository(Long nodeId, Set<String> groups)
985 throws ContentManagerException;
986
987
988
989
990
991 public boolean hasNodeAccessUser(Long nodeId, IDIFUser user) throws ContentManagerException
992 {
993 Node node = getNodeByIdNoPermissions(nodeId, user);
994
995 return hasNodeAccessUser(node, user);
996 }
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008 public boolean hasNodeAccessUser(Node node, IDIFUser user) throws ContentManagerException
1009 {
1010 boolean result = false;
1011 if (node.isPublic())
1012 result = true;
1013
1014 if (!result && hasNodeAccessUserInRespository(node.getId(), user))
1015 result = true;
1016
1017 if (!result)
1018 {
1019 try
1020 {
1021 result = hasNodeAccessGroups(node.getId(), user.getGroupIDs());
1022 }
1023 catch (IdentityManagerException e)
1024 {
1025 new ContentManagerException(e);
1026 }
1027 }
1028
1029 if (!result && node.getParentNodeId() != null)
1030 {
1031 Node parentNode = getNodeByIdNoPermissions(node.getParentNodeId(), null);
1032 result = hasNodeAccessUser(parentNode, user);
1033 }
1034
1035 return result;
1036 }
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 protected abstract boolean hasNodeAccessUserInRespository(Long nodeId, IDIFUser user)
1049 throws ContentManagerException;
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063 protected abstract ContentItem mergeContentInRepository(ContentItem contentParam, IDIFUser user)
1064 throws ContentItemNotFoundException, ContentItemWithDuplicateNameAndParentNodeException,
1065 ContentManagerException;
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076 protected abstract Node mergeNodeInRepository(Node nodeParam, IDIFUser user);
1077
1078
1079
1080
1081
1082 public boolean moveContent(String contentID, Long destinationNodeId, IDIFUser user) throws ContentManagerException
1083 {
1084 ContentItem contentItem = getContentById(contentID, user);
1085
1086 if (contentItem == null)
1087 throw new ContentItemNotFoundException(contentID);
1088
1089 Node node = getNodeByIdNoPermissions(destinationNodeId, user);
1090
1091 if (!hasContentAccessUser(contentItem, user))
1092 {
1093 throw new NoAccessException("User has no access to the content");
1094 }
1095
1096 if (!hasNodeAccessUser(node, user))
1097 {
1098 throw new NoAccessException("User has no access to the destination node");
1099 }
1100
1101 moveContentInRepository(contentItem, node, user);
1102
1103 return true;
1104 }
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119 protected abstract ContentItem moveContentInRepository(ContentItem contentParam, Node nodeParam, IDIFUser user)
1120 throws ContentItemNotFoundException, ContentManagerException;
1121
1122
1123
1124
1125
1126 public boolean moveNode(Long nodeID, Long destinationNodeId, IDIFUser user) throws ContentManagerException
1127 {
1128 Node node = getNodeByIdNoPermissions(nodeID, user);
1129
1130 Node newParentNode = getNodeByIdNoPermissions(destinationNodeId, user);
1131
1132 if (!hasNodeAccessUser(nodeID, user))
1133 {
1134 throw new NoAccessException("User has no access to the node");
1135 }
1136
1137 if (!hasNodeAccessUser(destinationNodeId, user))
1138 {
1139 throw new NoAccessException("User has no access to the destination node");
1140 }
1141
1142 node.setParentNodeId(newParentNode.getId());
1143
1144 try
1145 {
1146 node.setFullPathName(determineFullPath(node));
1147 }
1148 catch (ContentManagerException e)
1149 {
1150 throw new NodeNotFoundException("Error determining full path");
1151 }
1152
1153 moveNodeInRepository(node, user);
1154
1155 return true;
1156 }
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167 protected abstract Node moveNodeInRepository(Node node, IDIFUser user);
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179 protected boolean nodeExists(Long id, IDIFUser user) throws ContentManagerException
1180 {
1181 return nodeExistsInRepository(id, user);
1182 }
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194 protected abstract boolean nodeExistsInRepository(Long id, IDIFUser user) throws ContentManagerException;
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207 protected abstract ContentItem persistContentInRepository(ContentItem content, IDIFUser user)
1208 throws ContentItemWithDuplicateNameAndParentNodeException, ContentManagerException;
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222 protected abstract Node persistNodeInRepository(Node node, IDIFUser user) throws NodeWithDuplicatePathException,
1223 ContentManagerException;
1224
1225
1226
1227
1228
1229 public boolean revokeContentAccessToGroup(String contentId, String groupId) throws ContentManagerException
1230 {
1231 if (getContentByIdNoPermissions(contentId, null) == null)
1232 throw new ContentItemNotFoundException(contentId);
1233
1234 return revokeContentAccessToGroupInRepository(contentId, groupId);
1235 }
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246 protected abstract boolean revokeContentAccessToGroupInRepository(String contentId, String groupId);
1247
1248
1249
1250
1251
1252 public boolean revokeContentAccessToUser(String contentId, IDIFUser user) throws ContentManagerException
1253 {
1254 if (getContentByIdNoPermissions(contentId, user) == null)
1255 throw new ContentItemNotFoundException(contentId);
1256
1257 return revokeContentAccessToUserInRepository(contentId, user);
1258 }
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269 protected abstract boolean revokeContentAccessToUserInRepository(String contentId, IDIFUser user);
1270
1271
1272
1273
1274
1275 public boolean revokeNodeAccessToGroup(Long nodeId, String groupId) throws ContentManagerException
1276 {
1277 getNodeByIdNoPermissions(nodeId, null);
1278
1279 return revokeNodeAccessToGroupInRepository(nodeId, groupId);
1280 }
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292 protected abstract boolean revokeNodeAccessToGroupInRepository(Long nodeId, String groupId)
1293 throws ContentManagerException;
1294
1295
1296
1297
1298
1299 public boolean revokeNodeAccessToUser(Long nodeId, IDIFUser user) throws ContentManagerException
1300 {
1301 getNodeByIdNoPermissions(nodeId, user);
1302
1303 return revokeNodeAccessToUserInRepository(nodeId, user);
1304 }
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316 protected abstract boolean revokeNodeAccessToUserInRepository(Long nodeId, IDIFUser user)
1317 throws ContentManagerException;
1318
1319
1320
1321
1322 public ContentItem updateContent(ContentItem content) throws ContentManagerException
1323 {
1324 if (content == null)
1325 throw new ContentItemNotFoundException();
1326
1327 if (content.getUser() == null)
1328 {
1329 throw new NoAccessException("The Content User attribute must be filled to complete the insert");
1330 }
1331
1332 if (!hasContentAccessUser(content, content.getUser()))
1333 throw new NoAccessException("User doesn't have access to the parent node");
1334
1335 ContentItem currentContent = getContentById(content.getId(), content.getUser());
1336
1337 if (currentContent == null)
1338 throw new ContentItemNotFoundException();
1339
1340 currentContent.setName(content.getName());
1341 currentContent.setDescription(content.getDescription());
1342 currentContent.setContent(content.getContent());
1343
1344 return mergeContentInRepository(currentContent, content.getUser());
1345 }
1346
1347
1348
1349
1350 public Node updateNode(Node node) throws ContentManagerException
1351 {
1352 if (node == null)
1353 throw new NodeNotFoundException();
1354
1355 if (node.getUser() == null)
1356 {
1357 throw new NoAccessException("The Node User attribute must be filled to complete the insert");
1358 }
1359
1360 if (!hasNodeAccessUser(node, node.getUser()))
1361 throw new NoAccessException("User doesn't have access to the node");
1362
1363 Node currentNode = getNodeByIdNoPermissions(node.getId(), node.getUser());
1364
1365 currentNode.setDescription(node.getDescription());
1366 currentNode.setPublic(node.isPublic());
1367
1368 if (!currentNode.getName().equals(node.getName()))
1369 {
1370
1371 try
1372 {
1373 node.setFullPathName(determineFullPath(node));
1374 }
1375 catch (ContentManagerException e)
1376 {
1377 throw new NodeNotFoundException("Error determining full path");
1378 }
1379 currentNode.setName(node.getName());
1380 currentNode.setFullPathName(node.getFullPathName());
1381 }
1382
1383 return mergeNodeInRepository(currentNode, node.getUser());
1384 }
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395 private boolean validadeNameAndPath(String name, boolean isPath)
1396 {
1397 char ch;
1398 for (int i = 0; i < name.length(); i++)
1399 {
1400 ch = name.charAt(i);
1401
1402 if (ch >= 'A' && ch <= 'Z')
1403 continue;
1404 if (ch >= 'a' && ch <= 'z')
1405 continue;
1406 if (ch >= '0' && ch <= '9')
1407 continue;
1408 if (ch == '-' || ch == '_')
1409 continue;
1410 if (isPath && ch == SEPARATOR)
1411 continue;
1412
1413 return false;
1414 }
1415
1416 return true;
1417 }
1418
1419 }