1
2
3
4
5
6 package pt.digitalis.dif.utils.extensions.document;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import pt.digitalis.dif.controller.interfaces.IDIFSession;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public abstract class AbstractDocumentRepository implements IDocumentRepositoryManager {
30
31
32 private static final String DOCUMENT_AUTHORIZATION_LIST = "authorizedDocuments";
33
34
35
36
37
38 public void authorizeDocumentForCurrentSession(IDIFSession session, Long documentID)
39 {
40 @SuppressWarnings("unchecked")
41 List<Long> authorizedDocuments = (List<Long>) session.getAttribute(DOCUMENT_AUTHORIZATION_LIST);
42
43 if (authorizedDocuments == null)
44 authorizedDocuments = new ArrayList<Long>();
45
46 if (!authorizedDocuments.contains(documentID))
47 authorizedDocuments.add(documentID);
48
49 session.addAttribute(DOCUMENT_AUTHORIZATION_LIST, authorizedDocuments);
50 }
51
52
53
54
55 public synchronized List<DocumentRepositoryEntry> getDocumentsByIds(List<Long> documentIds)
56 throws DocumentRepositoryException
57 {
58 List<DocumentRepositoryEntry> documents = new ArrayList<DocumentRepositoryEntry>();
59
60 for (Long docId: documentIds)
61 documents.add(getDocument(docId));
62
63 return documents;
64 }
65
66
67
68
69
70 public boolean isDocumentAuthorizedInCurrentSession(IDIFSession session, Long documentID)
71 {
72 @SuppressWarnings("unchecked")
73 List<Long> authorizedDocuments = (List<Long>) session.getAttribute(DOCUMENT_AUTHORIZATION_LIST);
74
75 return authorizedDocuments != null && authorizedDocuments.contains(documentID);
76 }
77 }