summaryrefslogtreecommitdiffstats
path: root/authz-batch/src/main/java/com/att/authz/helpers/Approver.java
blob: 0cac97bcc9eea15cb5f6e5411e6ff9216dc4557e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*******************************************************************************
 * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
 *******************************************************************************/
package com.att.authz.helpers;

import java.util.HashMap;
import java.util.Map;

import com.att.authz.actions.Message;
import com.att.authz.org.Organization;

public class Approver {
	public String name;
	public Organization org;
	public Map<String, Integer> userRequests;
	
	public Approver(String approver, Organization org) {
		this.name = approver;
		this.org = org;
		userRequests = new HashMap<String, Integer>();
	}
	
	public void addRequest(String user) {
		if (userRequests.get(user) == null) {
		    userRequests.put(user, 1);
		} else {
			Integer curCount = userRequests.remove(user);
			userRequests.put(user, curCount+1);
		}
	}
	
	/**
	 * @param sb
	 * @return
	 */
	public void build(Message msg) {
		msg.clear();
		msg.line("You have %d total pending approvals from the following users:", userRequests.size());
		for (Map.Entry<String, Integer> entry : userRequests.entrySet()) {
			msg.line("  %s (%d)",entry.getKey(),entry.getValue());
		}
	}

}