View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Like a regular accounting line rendering transformer, though this  
32   */
33  public class AccountingLineAuthorizationTransformerImpl implements AccountingLineAuthorizationTransformer {
34  
35      /**
36       * Performs transformations to the element rendering tree based on the authorization's reactions to the accounting line
37       * @param elements the element rendering tree
38       * @param accountingLine the accounting line to be rendered
39       * @param document the document that accounting line lives on
40       * @param lineAuthorizer the authorizer for the accounting line
41       * @param newLine is this line a new line or a line already on a document?
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       * @param elements the elements of the rendering tree
52       * @param unviewableBlocks a Set of the names of blocks that are not viewable
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