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 final Date now;
45 private Range delRange;
47 public ExpireRange(final Access access) {
49 ranges = new HashMap<>();
51 String prop = access.getProperty(AAF_BATCH_RANGE + i,null);
52 if(prop==null && i==0) {
53 List<Range> lcred = getRangeList("cred");
54 List<Range> lur = getRangeList("ur");
55 List<Range> lx509 = getRangeList("x509");
57 delRange = new Range("Delete",0,0,-1,0,GregorianCalendar.WEEK_OF_MONTH,-2);
62 lcred.add(new Range(ONE_WEEK,3,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1));
63 lcred.add(new Range(TWO_WEEK,2,1,GregorianCalendar.WEEK_OF_MONTH,1,GregorianCalendar.WEEK_OF_MONTH,2));
64 lcred.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
65 lcred.add(new Range(TWO_MONTH,1,0,GregorianCalendar.MONTH,1,GregorianCalendar.MONTH,2));
67 lur.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
69 lx509.add(new Range(ONE_MONTH,1,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1));
73 public Set<String> names() {
74 Set<String> names = new HashSet<>();
75 for(List<Range> lr : ranges.values()) {
84 private synchronized List<Range> getRangeList(final String key) {
85 List<Range> rv = ranges.get(key);
87 rv = new ArrayList<>();
94 private final String name;
95 private final int reportingLevel;
96 private final int interval; // in Days
97 private final Date start;
98 private final Date end;
101 final String name, final int reportingLevel, final int interval,
102 final int startGCType, final int startQty,
103 final int endGCType,final int endQty) {
105 this.reportingLevel = reportingLevel;
106 this.interval = interval;
107 GregorianCalendar gc = new GregorianCalendar();
109 gc.set(GregorianCalendar.YEAR, 1);
112 gc.add(startGCType, startQty);
114 start = gc.getTime();
117 gc.set(GregorianCalendar.YEAR, 1);
120 gc.add(endGCType, endQty);
125 public String name() {
129 public int reportingLevel() {
130 return reportingLevel;
133 public Date getStart() {
137 public Date getEnd() {
141 private boolean inRange(final Date date) {
145 return date.getTime()>=start.getTime() && date.before(end);
149 public boolean shouldContact(final Date lastContact) {
150 if(reportingLevel<=0) {
152 } else if(lastContact==null) {
154 } else if(interval==0) {
155 return lastContact.before(start);
157 GregorianCalendar gc = new GregorianCalendar();
159 gc.add(GregorianCalendar.DAY_OF_WEEK, interval);
160 return lastContact.before(gc.getTime());
165 public Range getRange(final String key, final Date date) {
168 List<Range> lr = ranges.get(key);
173 if(r.inRange(date)) {