Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractDocumentRepository |
|
| 2.3333333333333335;2,333 |
1 | 0 | /** |
2 | * 2009, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos | |
3 | * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt | |
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 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/> | |
15 | * @created 11 de Mar de 2011 | |
16 | */ | |
17 | /** | |
18 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/> | |
19 | * @created 11 de Mar de 2011 | |
20 | */ | |
21 | /** | |
22 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/> | |
23 | * @created 11 de Mar de 2011 | |
24 | */ | |
25 | /** | |
26 | * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/> | |
27 | * @created 11 de Mar de 2011 | |
28 | */ | |
29 | 0 | public abstract class AbstractDocumentRepository implements IDocumentRepositoryManager { |
30 | ||
31 | /** */ | |
32 | private static final String DOCUMENT_AUTHORIZATION_LIST = "authorizedDocuments"; | |
33 | ||
34 | /** | |
35 | * @see pt.digitalis.dif.utils.extensions.document.IDocumentRepositoryManager#authorizeDocumentForCurrentSession(pt.digitalis.dif.controller.interfaces.IDIFSession, | |
36 | * java.lang.Long) | |
37 | */ | |
38 | public void authorizeDocumentForCurrentSession(IDIFSession session, Long documentID) | |
39 | { | |
40 | @SuppressWarnings("unchecked") | |
41 | 0 | List<Long> authorizedDocuments = (List<Long>) session.getAttribute(DOCUMENT_AUTHORIZATION_LIST); |
42 | ||
43 | 0 | if (authorizedDocuments == null) |
44 | 0 | authorizedDocuments = new ArrayList<Long>(); |
45 | ||
46 | 0 | if (!authorizedDocuments.contains(documentID)) |
47 | 0 | authorizedDocuments.add(documentID); |
48 | ||
49 | 0 | session.addAttribute(DOCUMENT_AUTHORIZATION_LIST, authorizedDocuments); |
50 | 0 | } |
51 | ||
52 | /** | |
53 | * @see pt.digitalis.dif.utils.extensions.document.IDocumentRepositoryManager#getDocumentsByIds(java.util.List) | |
54 | */ | |
55 | public synchronized List<DocumentRepositoryEntry> getDocumentsByIds(List<Long> documentIds) | |
56 | throws DocumentRepositoryException | |
57 | { | |
58 | 0 | List<DocumentRepositoryEntry> documents = new ArrayList<DocumentRepositoryEntry>(); |
59 | ||
60 | 0 | for (Long docId: documentIds) |
61 | 0 | documents.add(getDocument(docId)); |
62 | ||
63 | 0 | return documents; |
64 | } | |
65 | ||
66 | /** | |
67 | * @see pt.digitalis.dif.utils.extensions.document.IDocumentRepositoryManager#isDocumentAuthorizedInCurrentSession(pt.digitalis.dif.controller.interfaces.IDIFSession, | |
68 | * java.lang.Long) | |
69 | */ | |
70 | public boolean isDocumentAuthorizedInCurrentSession(IDIFSession session, Long documentID) | |
71 | { | |
72 | @SuppressWarnings("unchecked") | |
73 | 0 | List<Long> authorizedDocuments = (List<Long>) session.getAttribute(DOCUMENT_AUTHORIZATION_LIST); |
74 | ||
75 | 0 | return authorizedDocuments != null && authorizedDocuments.contains(documentID); |
76 | } | |
77 | } |