2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Modifications Copyright (C) 2018 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
23 package org.onap.aaf.auth.batch.helpers;
25 import java.util.Date;
26 import java.util.Iterator;
29 import java.util.TreeMap;
31 import org.onap.aaf.auth.batch.helpers.Notification.TYPE;
33 import com.datastax.driver.core.ResultSet;
34 import com.datastax.driver.core.Row;
35 import com.datastax.driver.core.Session;
37 public class LastNotified {
38 private Map<String,Date> lastNotified = new TreeMap<>();
39 private Session session;
41 public LastNotified(Session session) {
42 this.session = session;
45 public void add(Set<String> users) {
46 StringBuilder query = new StringBuilder();
47 startNotifyQuery(query);
49 for(String user : users) {
57 endNotifyQuery(query, Notification.TYPE.OA);
58 add(session.execute(query.toString()),lastNotified);
60 startNotifyQuery(query);
65 endNotifyQuery(query, Notification.TYPE.OA);
66 add(session.execute(query.toString()),lastNotified);
70 public Date lastNotified(String user) {
71 return lastNotified.get(user);
74 private void add(ResultSet result, Map<String, Date> lastNotified) {
75 for(Iterator<Row> iter = result.iterator(); iter.hasNext();) {
77 lastNotified.put(r.getString(0), r.getTimestamp(1));
81 private void startNotifyQuery(StringBuilder query) {
82 query.append("SELECT user,last FROM authz.notify WHERE user in (");
85 private void endNotifyQuery(StringBuilder query, TYPE oa) {
86 query.append(") AND type=");
87 query.append(oa.idx());