1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.sys.document.service.impl;
17  
18  import java.util.HashSet;
19  import java.util.List;
20  import java.util.Set;
21  
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.AccountingDocument;
24  import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizer;
25  import org.kuali.ole.sys.document.service.AccountingLineAuthorizationTransformer;
26  import org.kuali.ole.sys.document.web.TableJoining;
27  import org.kuali.rice.kim.api.identity.Person;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  
31  
32  
33  public class AccountingLineAuthorizationTransformerImpl implements AccountingLineAuthorizationTransformer {
34  
35      
36  
37  
38  
39  
40  
41  
42  
43  
44      public void transformElements(List<TableJoining> elements, AccountingLine accountingLine, AccountingDocument document, AccountingLineAuthorizer lineAuthorizer, boolean newLine, String accountingLinePropertyName) {
45          final Person currentUser = GlobalVariables.getUserSession().getPerson();
46          removeUnviewableBlocks(elements, lineAuthorizer.getUnviewableBlocks(document, accountingLine, newLine, currentUser));
47      }
48      
49      
50  
51  
52  
53  
54      protected void removeUnviewableBlocks(List<TableJoining> elements, Set<String> unviewableBlocks) {
55          if (unviewableBlocks.size() > 0) {
56              Set<TableJoining> elementsToRemove = new HashSet<TableJoining>();
57              for (TableJoining element : elements) {
58                  if (unviewableBlocks.contains(element.getName())) {
59                      elementsToRemove.add(element);
60                  } else {
61                      element.removeUnviewableBlocks(unviewableBlocks);
62                  }
63              }
64              elements.removeAll(elementsToRemove);
65          }
66      }
67  }
68