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.batch.helpers;
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;
33 import org.onap.aaf.cadi.PropAccess;
35 public class ExpireRange {
36 private static final String AAF_BATCH_RANGE = "aaf_batch_range.";
37 public Map<String,List<Range>> ranges;
38 public final Date now;
40 public ExpireRange(final Access access) {
42 ranges = new HashMap<>();
44 String prop = access.getProperty(AAF_BATCH_RANGE + i,null);
47 List<Range> lcred = getRangeList("cred");
48 List<Range> lur = getRangeList("ur");
49 List<Range> lx509 = getRangeList("x509");
51 Range del = new Range("Delete",0,0,-1,0,GregorianCalendar.WEEK_OF_MONTH,-2);
56 lcred.add(new Range("CredOneWeek",3,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1));
57 lcred.add(new Range("CredTwoWeek",2,1,GregorianCalendar.WEEK_OF_MONTH,1,GregorianCalendar.WEEK_OF_MONTH,2));
58 lcred.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
59 lcred.add(new Range("TwoMonth",1,0,GregorianCalendar.MONTH,1,GregorianCalendar.MONTH,2));
61 lur.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
63 lx509.add(new Range("OneMonth",1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
68 public Set<String> names() {
69 Set<String> names = new HashSet<>();
70 for(List<Range> lr : ranges.values()) {
79 private synchronized List<Range> getRangeList(final String key) {
80 List<Range> rv = ranges.get(key);
82 rv = new ArrayList<>();
89 private final String name;
90 private final int reportingLevel;
91 private final int interval; // in Days
92 private final Date start;
93 private final Date end;
96 final String name, final int reportingLevel, final int interval,
97 final int startGCType, final int startQty,
98 final int endGCType,final int endQty) {
100 this.reportingLevel = reportingLevel;
101 this.interval = interval;
102 GregorianCalendar gc = new GregorianCalendar();
104 gc.set(GregorianCalendar.YEAR, 1);
107 gc.add(startGCType, startQty);
109 start = gc.getTime();
112 gc.set(GregorianCalendar.YEAR, 1);
115 gc.add(endGCType, endQty);
120 public String name() {
124 public int reportingLevel() {
125 return reportingLevel;
128 public Date getStart() {
132 public Date getEnd() {
136 private boolean inRange(final Date date) {
140 return date.getTime()>=start.getTime() && date.before(end);
144 public boolean shouldContact(final Date lastContact) {
145 if(reportingLevel<=0) {
147 } else if(lastContact==null) {
149 } else if(interval==0) {
150 return lastContact.before(start);
152 GregorianCalendar gc = new GregorianCalendar();
154 gc.add(GregorianCalendar.DAY_OF_WEEK, interval);
155 return lastContact.before(gc.getTime());
160 public Range getRange(final String key, final Date date) {
163 List<Range> lr = ranges.get(key);
168 if(r.inRange(date)) {