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 | 0 | public abstract class AbstractContentManager implements IContentManager { |
32 | |
|
33 | |
|
34 | 0 | protected static char SEPARATOR = '\\'; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public ContentItem addContent(ContentItem content) throws ContentManagerException |
40 | |
{ |
41 | |
|
42 | 0 | if (content.getUser() == null) |
43 | |
{ |
44 | 0 | throw new NoAccessException("The Content User attribute must be filled to complete the insert"); |
45 | |
} |
46 | |
|
47 | 0 | if (content.getParentNodeId() != null) |
48 | |
{ |
49 | |
try |
50 | |
{ |
51 | 0 | if (!nodeExists(content.getParentNodeId(), content.getUser())) |
52 | 0 | throw new InvalidParentNodeException(); |
53 | |
} |
54 | 0 | catch (Exception e) |
55 | |
{ |
56 | 0 | throw new InvalidParentNodeException(e); |
57 | |
} |
58 | |
|
59 | 0 | if (!hasNodeAccessUser(content.getParentNodeId(), content.getUser())) |
60 | 0 | throw new NoAccessException("User doesn't have access to the parent node"); |
61 | |
} |
62 | |
|
63 | 0 | return persistContentInRepository(content, content.getUser()); |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public Node addNode(Node node) throws ContentManagerException |
70 | |
{ |
71 | 0 | if (node == null) |
72 | 0 | throw new NodeNotFoundException(); |
73 | |
|
74 | 0 | if (node.getUser() == null) |
75 | |
{ |
76 | 0 | throw new NoAccessException("The Node User attribute must be filled to complete the insert"); |
77 | |
} |
78 | |
|
79 | 0 | String fullPath = determineFullPath(node); |
80 | |
|
81 | 0 | if (!validadeNameAndPath(fullPath, true)) |
82 | 0 | throw new InvalidPathException("Invalid path: " + fullPath); |
83 | |
|
84 | 0 | node.setFullPathName(fullPath); |
85 | |
|
86 | 0 | if (node.getParentNodeId() != null) |
87 | 0 | if (!hasNodeAccessUser(node.getParentNodeId(), node.getUser())) |
88 | 0 | throw new NoAccessException("User doesn't have access to the parent node"); |
89 | |
|
90 | 0 | 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 | 0 | List<ContentItem> reviewedList = new ArrayList<ContentItem>(); |
105 | |
|
106 | 0 | for (ContentItem content: listToCheck) |
107 | |
{ |
108 | |
try |
109 | |
{ |
110 | 0 | if (hasContentAccessUser(content, user)) |
111 | 0 | reviewedList.add(content); |
112 | |
} |
113 | 0 | catch (ContentManagerException e) |
114 | |
{ |
115 | |
|
116 | |
} |
117 | |
} |
118 | |
|
119 | 0 | 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 | 0 | List<Node> reviewedList = new ArrayList<Node>(); |
134 | |
|
135 | 0 | for (Node node: listToCheck) |
136 | |
{ |
137 | |
try |
138 | |
{ |
139 | 0 | if (hasNodeAccessUser(node, user)) |
140 | 0 | reviewedList.add(node); |
141 | |
} |
142 | 0 | catch (ContentManagerException e) |
143 | |
{ |
144 | |
|
145 | |
} |
146 | |
} |
147 | |
|
148 | 0 | return reviewedList; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public boolean deleteContent(String id, IDIFUser user) throws ContentManagerException |
156 | |
{ |
157 | 0 | if (!hasContentAccessUser(id, user)) |
158 | 0 | throw new NoAccessException("User doesn't have access to content"); |
159 | |
|
160 | 0 | 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 | 0 | 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 | 0 | if (!hasNodeAccessUser(id, user)) |
191 | 0 | throw new NoAccessException("User doesn't have access to node"); |
192 | |
|
193 | 0 | 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 | 0 | if (node.getParentNodeId() == null) |
225 | 0 | return SEPARATOR + node.getName(); |
226 | |
else |
227 | |
{ |
228 | 0 | String fullPathFromRep = getParentFullPathInRepository(node); |
229 | |
|
230 | 0 | if (!validadeNameAndPath(fullPathFromRep, true)) |
231 | 0 | throw new InvalidPathException("Invalid path: " + fullPathFromRep); |
232 | |
|
233 | 0 | 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 | 0 | 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 | 0 | ContentItem contentItem = getContentByIdInRepository(id, user); |
266 | 0 | if (!hasContentAccessUser(contentItem, user)) |
267 | 0 | throw new NoAccessException("User has no access to content item"); |
268 | |
|
269 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | getNodeByIdNoPermissions(nodeId, user); |
347 | |
|
348 | 0 | 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 | 0 | ContentItem contentItem = getContentFromNodePathByNameRepository(nodeFullPath, name, user); |
372 | 0 | if (!hasContentAccessUser(contentItem, user)) |
373 | 0 | throw new NoAccessException("User has no access to content item"); |
374 | |
|
375 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | Node node = getNodeByIdInRepository(id, user); |
436 | 0 | if (!hasNodeAccessUser(node, user)) |
437 | 0 | throw new NoAccessException("User does not have access to the Node"); |
438 | |
|
439 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissionsInRepository(nodeID, user); |
467 | |
|
468 | 0 | if (node == null) |
469 | 0 | throw new NodeNotFoundException(nodeID); |
470 | |
|
471 | 0 | 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 | 0 | Node node = getNodeByPathInRespository(fullPath, user); |
495 | 0 | if (user != null) |
496 | 0 | if (!hasNodeAccessUser(node, user)) |
497 | 0 | throw new NoAccessException("User doesn't have access to the Node"); |
498 | |
|
499 | 0 | 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 | 0 | return getNodeByPathInRespository(nodePath, user); |
530 | |
} |
531 | |
|
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
public List<Node> getNodesByDescription(String description, IDIFUser user) throws ContentManagerException |
537 | |
{ |
538 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | getNodeByIdNoPermissions(nodeId, user); |
660 | |
|
661 | 0 | 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 | 0 | 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 | 0 | ContentItem contentItem = this.getContentByIdNoPermissions(contentId, null); |
720 | |
|
721 | 0 | if (contentItem == null) |
722 | 0 | throw new ContentItemNotFoundException(contentId); |
723 | |
|
724 | 0 | 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 | 0 | ContentItem contentItem = getContentByIdNoPermissions(contentId, user); |
747 | |
|
748 | 0 | if (contentItem == null) |
749 | 0 | throw new ContentItemNotFoundException(contentId); |
750 | |
|
751 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(nodeId, null); |
774 | |
|
775 | 0 | 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 | 0 | Node node = this.getNodeByIdNoPermissions(nodeId, user); |
798 | |
|
799 | 0 | return grantNodeAccessToUserInRepository(node, user); |
800 | |
} |
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
public boolean grantNodeAccessToUser(String nodePath, IDIFUser user) throws ContentManagerException |
807 | |
{ |
808 | 0 | Node node = getNodeByPathNoPermissions(nodePath, user); |
809 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(contentItem.getParentNodeId(), null); |
838 | |
|
839 | 0 | if (node.isPublic()) |
840 | 0 | return true; |
841 | |
|
842 | 0 | Set<String> groups = new HashSet<String>(); |
843 | 0 | groups.add(groupId); |
844 | |
|
845 | 0 | if (hasContentAccessGroupsInRepository(contentItem.getId(), groups)) |
846 | 0 | return true; |
847 | |
else |
848 | 0 | return hasNodeAccessGroups(contentItem.getParentNodeId(), groups); |
849 | |
} |
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
public boolean hasContentAccessGroup(String contentId, String groupId) throws ContentManagerException |
856 | |
{ |
857 | 0 | ContentItem contentItem = getContentByIdNoPermissions(contentId, null); |
858 | |
|
859 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(contentItem.getParentNodeId(), null); |
875 | |
|
876 | 0 | if (node.isPublic()) |
877 | 0 | return true; |
878 | |
|
879 | 0 | if (hasContentAccessGroupsInRepository(contentItem.getId(), groups)) |
880 | 0 | return true; |
881 | |
else |
882 | 0 | 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 | 0 | boolean result = false; |
905 | 0 | if (hasNodeAccessUser(contentItem.getParentNodeId(), user)) |
906 | |
{ |
907 | 0 | result = true; |
908 | |
} |
909 | |
|
910 | 0 | if (!result && hasContentAccessUserInRepository(contentItem.getId(), user)) |
911 | 0 | result = true; |
912 | |
|
913 | |
try |
914 | |
{ |
915 | 0 | if (!result && hasContentAccessGroups(contentItem, user.getGroupIDs())) |
916 | 0 | result = true; |
917 | |
} |
918 | 0 | catch (IdentityManagerException e) |
919 | |
{ |
920 | 0 | throw new ContentItemNotFoundException(e); |
921 | |
} |
922 | |
|
923 | 0 | return result; |
924 | |
|
925 | |
} |
926 | |
|
927 | |
|
928 | |
|
929 | |
|
930 | |
|
931 | |
public boolean hasContentAccessUser(String contentId, IDIFUser user) throws ContentManagerException |
932 | |
{ |
933 | 0 | ContentItem contentItem = getContentByIdNoPermissions(contentId, user); |
934 | |
|
935 | 0 | if (contentItem == null) |
936 | 0 | throw new ContentItemNotFoundException(contentId); |
937 | |
|
938 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(nodeId, null); |
961 | |
|
962 | 0 | if (node.isPublic()) |
963 | 0 | return true; |
964 | |
|
965 | 0 | if (hasNodeAccessGroupsInRepository(nodeId, groups)) |
966 | 0 | return true; |
967 | |
|
968 | 0 | if (node.getParentNodeId() != null) |
969 | 0 | return hasNodeAccessGroups(node.getParentNodeId(), groups); |
970 | |
|
971 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(nodeId, user); |
994 | |
|
995 | 0 | 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 | 0 | boolean result = false; |
1011 | 0 | if (node.isPublic()) |
1012 | 0 | result = true; |
1013 | |
|
1014 | 0 | if (!result && hasNodeAccessUserInRespository(node.getId(), user)) |
1015 | 0 | result = true; |
1016 | |
|
1017 | 0 | if (!result) |
1018 | |
{ |
1019 | |
try |
1020 | |
{ |
1021 | 0 | result = hasNodeAccessGroups(node.getId(), user.getGroupIDs()); |
1022 | |
} |
1023 | 0 | catch (IdentityManagerException e) |
1024 | |
{ |
1025 | 0 | new ContentManagerException(e); |
1026 | |
} |
1027 | |
} |
1028 | |
|
1029 | 0 | if (!result && node.getParentNodeId() != null) |
1030 | |
{ |
1031 | 0 | Node parentNode = getNodeByIdNoPermissions(node.getParentNodeId(), null); |
1032 | 0 | result = hasNodeAccessUser(parentNode, user); |
1033 | |
} |
1034 | |
|
1035 | 0 | 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 | 0 | ContentItem contentItem = getContentById(contentID, user); |
1085 | |
|
1086 | 0 | if (contentItem == null) |
1087 | 0 | throw new ContentItemNotFoundException(contentID); |
1088 | |
|
1089 | 0 | Node node = getNodeByIdNoPermissions(destinationNodeId, user); |
1090 | |
|
1091 | 0 | if (!hasContentAccessUser(contentItem, user)) |
1092 | |
{ |
1093 | 0 | throw new NoAccessException("User has no access to the content"); |
1094 | |
} |
1095 | |
|
1096 | 0 | if (!hasNodeAccessUser(node, user)) |
1097 | |
{ |
1098 | 0 | throw new NoAccessException("User has no access to the destination node"); |
1099 | |
} |
1100 | |
|
1101 | 0 | moveContentInRepository(contentItem, node, user); |
1102 | |
|
1103 | 0 | 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 | 0 | Node node = getNodeByIdNoPermissions(nodeID, user); |
1129 | |
|
1130 | 0 | Node newParentNode = getNodeByIdNoPermissions(destinationNodeId, user); |
1131 | |
|
1132 | 0 | if (!hasNodeAccessUser(nodeID, user)) |
1133 | |
{ |
1134 | 0 | throw new NoAccessException("User has no access to the node"); |
1135 | |
} |
1136 | |
|
1137 | 0 | if (!hasNodeAccessUser(destinationNodeId, user)) |
1138 | |
{ |
1139 | 0 | throw new NoAccessException("User has no access to the destination node"); |
1140 | |
} |
1141 | |
|
1142 | 0 | node.setParentNodeId(newParentNode.getId()); |
1143 | |
|
1144 | |
try |
1145 | |
{ |
1146 | 0 | node.setFullPathName(determineFullPath(node)); |
1147 | |
} |
1148 | 0 | catch (ContentManagerException e) |
1149 | |
{ |
1150 | 0 | throw new NodeNotFoundException("Error determining full path"); |
1151 | |
} |
1152 | |
|
1153 | 0 | moveNodeInRepository(node, user); |
1154 | |
|
1155 | 0 | 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 | 0 | 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 | 0 | if (getContentByIdNoPermissions(contentId, null) == null) |
1232 | 0 | throw new ContentItemNotFoundException(contentId); |
1233 | |
|
1234 | 0 | 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 | 0 | if (getContentByIdNoPermissions(contentId, user) == null) |
1255 | 0 | throw new ContentItemNotFoundException(contentId); |
1256 | |
|
1257 | 0 | 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 | 0 | getNodeByIdNoPermissions(nodeId, null); |
1278 | |
|
1279 | 0 | 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 | 0 | getNodeByIdNoPermissions(nodeId, user); |
1302 | |
|
1303 | 0 | 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 | 0 | if (content == null) |
1325 | 0 | throw new ContentItemNotFoundException(); |
1326 | |
|
1327 | 0 | if (content.getUser() == null) |
1328 | |
{ |
1329 | 0 | throw new NoAccessException("The Content User attribute must be filled to complete the insert"); |
1330 | |
} |
1331 | |
|
1332 | 0 | if (!hasContentAccessUser(content, content.getUser())) |
1333 | 0 | throw new NoAccessException("User doesn't have access to the parent node"); |
1334 | |
|
1335 | 0 | ContentItem currentContent = getContentById(content.getId(), content.getUser()); |
1336 | |
|
1337 | 0 | if (currentContent == null) |
1338 | 0 | throw new ContentItemNotFoundException(); |
1339 | |
|
1340 | 0 | currentContent.setName(content.getName()); |
1341 | 0 | currentContent.setDescription(content.getDescription()); |
1342 | 0 | currentContent.setContent(content.getContent()); |
1343 | |
|
1344 | 0 | return mergeContentInRepository(currentContent, content.getUser()); |
1345 | |
} |
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
|
1350 | |
public Node updateNode(Node node) throws ContentManagerException |
1351 | |
{ |
1352 | 0 | if (node == null) |
1353 | 0 | throw new NodeNotFoundException(); |
1354 | |
|
1355 | 0 | if (node.getUser() == null) |
1356 | |
{ |
1357 | 0 | throw new NoAccessException("The Node User attribute must be filled to complete the insert"); |
1358 | |
} |
1359 | |
|
1360 | 0 | if (!hasNodeAccessUser(node, node.getUser())) |
1361 | 0 | throw new NoAccessException("User doesn't have access to the node"); |
1362 | |
|
1363 | 0 | Node currentNode = getNodeByIdNoPermissions(node.getId(), node.getUser()); |
1364 | |
|
1365 | 0 | currentNode.setDescription(node.getDescription()); |
1366 | 0 | currentNode.setPublic(node.isPublic()); |
1367 | |
|
1368 | 0 | if (!currentNode.getName().equals(node.getName())) |
1369 | |
{ |
1370 | |
|
1371 | |
try |
1372 | |
{ |
1373 | 0 | node.setFullPathName(determineFullPath(node)); |
1374 | |
} |
1375 | 0 | catch (ContentManagerException e) |
1376 | |
{ |
1377 | 0 | throw new NodeNotFoundException("Error determining full path"); |
1378 | |
} |
1379 | 0 | currentNode.setName(node.getName()); |
1380 | 0 | currentNode.setFullPathName(node.getFullPathName()); |
1381 | |
} |
1382 | |
|
1383 | 0 | 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 | 0 | for (int i = 0; i < name.length(); i++) |
1399 | |
{ |
1400 | 0 | ch = name.charAt(i); |
1401 | |
|
1402 | 0 | if (ch >= 'A' && ch <= 'Z') |
1403 | 0 | continue; |
1404 | 0 | if (ch >= 'a' && ch <= 'z') |
1405 | 0 | continue; |
1406 | 0 | if (ch >= '0' && ch <= '9') |
1407 | 0 | continue; |
1408 | 0 | if (ch == '-' || ch == '_') |
1409 | 0 | continue; |
1410 | 0 | if (isPath && ch == SEPARATOR) |
1411 | 0 | continue; |
1412 | |
|
1413 | 0 | return false; |
1414 | |
} |
1415 | |
|
1416 | 0 | return true; |
1417 | |
} |
1418 | |
|
1419 | |
} |