Upgrade to latest oparent
[aaf/authz.git] / authz-batch / src / main / java / com / att / authz / helpers / Approver.java
1 /*******************************************************************************
2  * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3  *******************************************************************************/
4 package com.att.authz.helpers;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import com.att.authz.actions.Message;
10 import com.att.authz.org.Organization;
11
12 public class Approver {
13         public String name;
14         public Organization org;
15         public Map<String, Integer> userRequests;
16         
17         public Approver(String approver, Organization org) {
18                 this.name = approver;
19                 this.org = org;
20                 userRequests = new HashMap<String, Integer>();
21         }
22         
23         public void addRequest(String user) {
24                 if (userRequests.get(user) == null) {
25                     userRequests.put(user, 1);
26                 } else {
27                         Integer curCount = userRequests.remove(user);
28                         userRequests.put(user, curCount+1);
29                 }
30         }
31         
32         /**
33          * @param sb
34          * @return
35          */
36         public void build(Message msg) {
37                 msg.clear();
38                 msg.line("You have %d total pending approvals from the following users:", userRequests.size());
39                 for (Map.Entry<String, Integer> entry : userRequests.entrySet()) {
40                         msg.line("  %s (%d)",entry.getKey(),entry.getValue());
41                 }
42         }
43
44 }