2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.org;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.GregorianCalendar;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
32 import org.onap.aaf.cadi.Access;
34 public class ExpireRange {
35 private static final String AAF_BATCH_RANGE = "aaf_batch_range.";
36 public Map<String,List<Range>> ranges;
37 public final Date now;
39 public ExpireRange(final Access access) {
41 ranges = new HashMap<>();
43 String prop = access.getProperty(AAF_BATCH_RANGE + i,null);
46 List<Range> lcred = getRangeList("cred");
47 List<Range> lur = getRangeList("ur");
48 List<Range> lx509 = getRangeList("x509");
50 Range del = new Range("Delete",0,0,-1,0,GregorianCalendar.WEEK_OF_MONTH,-2);
55 lcred.add(new Range("CredOneWeek",3,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1));
56 lcred.add(new Range("CredTwoWeek",2,1,GregorianCalendar.WEEK_OF_MONTH,1,GregorianCalendar.WEEK_OF_MONTH,2));
57 lcred.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
58 lcred.add(new Range("TwoMonth",1,0,GregorianCalendar.MONTH,1,GregorianCalendar.MONTH,2));
60 lur.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
62 lx509.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
67 public Set<String> names() {
68 Set<String> names = new HashSet<>();
69 for(List<Range> lr : ranges.values()) {
78 private synchronized List<Range> getRangeList(final String key) {
79 List<Range> rv = ranges.get(key);
81 rv = new ArrayList<>();
88 private final String name;
89 private final int reportingLevel;
90 private final int interval; // in Days
91 private final Date start;
92 private final Date end;
95 final String name, final int reportingLevel, final int interval,
96 final int startGCType, final int startQty,
97 final int endGCType,final int endQty) {
99 this.reportingLevel = reportingLevel;
100 this.interval = interval;
101 GregorianCalendar gc = new GregorianCalendar();
103 gc.set(GregorianCalendar.YEAR, 1);
106 gc.add(startGCType, startQty);
108 start = gc.getTime();
111 gc.set(GregorianCalendar.YEAR, 1);
114 gc.add(endGCType, endQty);
119 public String name() {
123 public int reportingLevel() {
124 return reportingLevel;
127 public Date getStart() {
131 public Date getEnd() {
135 private boolean inRange(final Date date) {
139 return date.getTime()>=start.getTime() && date.before(end);
143 public boolean shouldContact(final Date lastContact) {
144 if(reportingLevel<=0) {
146 } else if(lastContact==null) {
148 } else if(interval==0) {
149 return lastContact.before(start);
151 GregorianCalendar gc = new GregorianCalendar();
153 gc.add(GregorianCalendar.DAY_OF_WEEK, interval);
154 return lastContact.before(gc.getTime());
159 public Range getRange(final String key, final Date date) {
162 List<Range> lr = ranges.get(key);
167 if(r.inRange(date)) {