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.Calendar;
27 import java.util.Date;
28 import java.util.GregorianCalendar;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
35 import org.onap.aaf.auth.org.Organization.Identity;
36 import org.onap.aaf.cadi.Access;
38 public class ExpireRange {
39 private static final String DELETE = "Delete";
40 public static final String ONE_MONTH = "OneMonth";
41 public static final String TWO_MONTH = "TwoMonth";
42 public static final String TWO_WEEK = "TwoWeek";
43 public static final String ONE_WEEK = "OneWeek";
44 private static final String AAF_BATCH_RANGE = "aaf_batch_range.";
45 public final Map<String,List<Range>> ranges;
46 private final Map<Integer,Date> intervalDates;
47 private static final Date now = new Date();
48 public final Range approveDelete ;
50 private Range delRange;
52 public ExpireRange(final Access access) {
53 ranges = new HashMap<>();
54 intervalDates = new HashMap<>();
56 approveDelete = new Range(DELETE,0,0,0,-1,0, Calendar.DAY_OF_YEAR,-100);
57 String prop = access.getProperty(AAF_BATCH_RANGE + i,null);
58 if(prop==null && i==0) {
59 List<Range> lcred = getRangeList("cred");
60 List<Range> lur = getRangeList("ur");
61 List<Range> lx509 = getRangeList("x509");
65 Range(Name, ReportingLevel, PeopleInterval, AppInterval, Start(Type,Qty) End(Type,Qty) )
66 Interval of -1 Means "only once"
67 Interval of 0 means none
68 Interval > 0 means only X number of Days.
70 delRange = new Range(DELETE,0,0,0,-1,0,Calendar.WEEK_OF_MONTH,-2);
75 lcred.add(new Range(ONE_WEEK ,3,-1,1,0,0,Calendar.WEEK_OF_MONTH,1));
76 lcred.add(new Range(TWO_WEEK ,2,-1,-1,Calendar.WEEK_OF_MONTH,1,Calendar.WEEK_OF_MONTH,2));
77 lcred.add(new Range(ONE_MONTH,1,7,7,Calendar.WEEK_OF_MONTH,2,Calendar.MONTH,1));
78 lcred.add(new Range(TWO_MONTH,1,-1,-1,Calendar.MONTH,1,Calendar.MONTH,2));
80 lur.add( new Range(ONE_MONTH,1,-1,-1,0,0,Calendar.MONTH,1));
81 lx509.add(new Range(ONE_MONTH,1,-1,-1,Calendar.WEEK_OF_MONTH,2,Calendar.MONTH,1));
85 public Range newFutureRange() {
86 return new Range("Approval",7,7,1,0,0,Calendar.MONTH,1);
89 public Set<String> names() {
90 Set<String> names = new HashSet<>();
91 for(List<Range> lr : ranges.values()) {
100 private synchronized List<Range> getRangeList(final String key) {
101 List<Range> rv = ranges.get(key);
103 rv = new ArrayList<>();
112 private final String name;
113 private final int reportingLevel;
114 private final int peopleInterval; // in Days
115 private final int appInterval; // in Days
116 private final Date start;
117 private final Date end;
118 private final Date lowerValid;
121 final String name, final int reportingLevel,
122 final int peopleInterval, final int appInterval,
123 final int startGCType, final int startQty,
124 final int endGCType,final int endQty) {
126 this.reportingLevel = reportingLevel;
127 this.peopleInterval = peopleInterval;
128 this.appInterval = appInterval;
129 Calendar gc = new GregorianCalendar();
131 gc.set(Calendar.YEAR, 1);
134 gc.add(startGCType, startQty);
136 start = gc.getTime();
139 gc.set(Calendar.YEAR, 1);
142 gc.add(endGCType, endQty);
148 gc.set(Calendar.YEAR, -1);
151 gc.add(endGCType, endQty * -1);
153 lowerValid = gc.getTime();
157 public String name() {
161 public int reportingLevel() {
162 return reportingLevel;
165 public boolean needsContact(Date lnd, Identity identity) {
167 if(identity==null || identity.isPerson()) {
168 interval = peopleInterval;
170 interval = appInterval;
174 } else if(interval < 0) { // "-1 = only once "
175 return (lnd==null || lnd.before(lowerValid));
177 Date rv = intervalDates.get(interval);
179 GregorianCalendar gc = new GregorianCalendar();
181 gc.add(Calendar.DAY_OF_YEAR, -1*interval);
183 intervalDates.put(interval, rv);
185 return rv.after(lnd);
189 public Date getStart() {
193 public Date getEnd() {
197 public boolean inRange(final Date date) {
201 return date.getTime()>=start.getTime() && date.before(end);
207 public Range getRange(final String key, final Date date) {
210 List<Range> lr = ranges.get(key);
215 if(r.inRange(date)) {