2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright © 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.ArrayList;
26 import java.util.Date;
27 import java.util.GregorianCalendar;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
34 import org.onap.aaf.cadi.Access;
36 public class ExpireRange {
37 public static final String ONE_MONTH = "OneMonth";
38 public static final String TWO_MONTH = "TwoMonth";
39 public static final String TWO_WEEK = "TwoWeek";
40 public static final String ONE_WEEK = "OneWeek";
41 private static final String AAF_BATCH_RANGE = "aaf_batch_range.";
42 public Map<String,List<Range>> ranges;
43 public static final Date now = new Date();
45 private Range delRange;
47 public ExpireRange(final Access access) {
48 ranges = new HashMap<>();
50 String prop = access.getProperty(AAF_BATCH_RANGE + i,null);
51 if(prop==null && i==0) {
52 List<Range> lcred = getRangeList("cred");
53 List<Range> lur = getRangeList("ur");
54 List<Range> lx509 = getRangeList("x509");
56 delRange = new Range("Delete",0,0,-1,0,GregorianCalendar.WEEK_OF_MONTH,-2);
61 lcred.add(new Range(ONE_WEEK,3,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1));
62 lcred.add(new Range(TWO_WEEK,2,1,GregorianCalendar.WEEK_OF_MONTH,1,GregorianCalendar.WEEK_OF_MONTH,2));
63 lcred.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
64 lcred.add(new Range(TWO_MONTH,1,0,GregorianCalendar.MONTH,1,GregorianCalendar.MONTH,2));
66 lur.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
68 lx509.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
72 public static Range newFutureRange() {
73 return new Range("Approval",1,1,0,0,GregorianCalendar.MONTH,1);
76 public Set<String> names() {
77 Set<String> names = new HashSet<>();
78 for(List<Range> lr : ranges.values()) {
87 private synchronized List<Range> getRangeList(final String key) {
88 List<Range> rv = ranges.get(key);
90 rv = new ArrayList<>();
96 public static class Range {
97 private final String name;
98 private final int reportingLevel;
99 private final int interval; // in Days
100 private final Date start;
101 private final Date end;
104 final String name, final int reportingLevel, final int interval,
105 final int startGCType, final int startQty,
106 final int endGCType,final int endQty) {
108 this.reportingLevel = reportingLevel;
109 this.interval = interval;
110 GregorianCalendar gc = new GregorianCalendar();
112 gc.set(GregorianCalendar.YEAR, 1);
115 gc.add(startGCType, startQty);
117 start = gc.getTime();
120 gc.set(GregorianCalendar.YEAR, 1);
123 gc.add(endGCType, endQty);
128 public String name() {
132 public int reportingLevel() {
133 return reportingLevel;
136 public Date getStart() {
140 public Date getEnd() {
144 public boolean inRange(final Date date) {
148 return date.getTime()>=start.getTime() && date.before(end);
152 public boolean shouldContact(final Date lastContact) {
153 if(reportingLevel<=0) {
155 } else if(lastContact==null) {
157 } else if(interval==0) {
158 return lastContact.before(start);
160 GregorianCalendar gc = new GregorianCalendar();
162 gc.add(GregorianCalendar.DAY_OF_WEEK, interval);
163 return lastContact.before(gc.getTime());
168 public Range getRange(final String key, final Date date) {
171 List<Range> lr = ranges.get(key);
176 if(r.inRange(date)) {