9a666981e544cc26ecedf4eb3eda0d3e546fed5e
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / approvalsets / Pending.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  *
7  * Modifications Copyright (C) 2019 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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====================================================
21  *
22  */
23 package org.onap.aaf.auth.batch.approvalsets;
24
25 import java.text.ParseException;
26 import java.util.Date;
27 import java.util.List;
28
29 import org.onap.aaf.cadi.util.CSV.Writer;
30 import org.onap.aaf.misc.env.util.Chrono;
31
32 public class Pending {
33     public static final String REMIND = "remind";
34     
35     int qty;
36     boolean hasNew;
37     Date earliest;
38     
39     /**
40      * Use this constructor to indicate when last Notified
41      * @param lastNotified
42      */
43     public Pending(Date lastNotified) {
44         qty = 1;
45         hasNew = lastNotified==null;
46         earliest = lastNotified;
47     }
48
49     /**
50      * Create from CSV Row
51      * @param row
52      * @throws ParseException
53      */
54     public Pending(List<String> row) throws ParseException {
55         hasNew = Boolean.parseBoolean(row.get(2));
56         String d = row.get(3);
57         if(d==null || d.isEmpty()) {
58             earliest = null;
59         } else {
60             earliest = Chrono.dateOnlyFmt.parse(d);
61         }
62         qty = Integer.parseInt(row.get(4));
63     }
64
65     /**
66      *  Write CSV Row
67      * @param approveCW
68      * @param key
69      */
70     public void row(Writer approveCW, String key) {
71         approveCW.row(REMIND,key,hasNew,Chrono.dateOnlyStamp(earliest),qty);
72     }
73
74     public void inc() {
75         ++qty;
76     }
77     
78     public void inc(Pending value) {
79         qty+=value.qty;
80         if(earliest==null) {
81             earliest = value.earliest;
82         } else if(value.earliest!=null && value.earliest.before(earliest)) {
83             earliest = value.earliest;
84         }
85     }
86
87     public void earliest(Date lastnotified) {
88         if(lastnotified==null) {
89             hasNew=true;
90         } else if (earliest==null || lastnotified.before(earliest)) {
91             earliest = lastnotified;
92         }
93     }
94     
95     public int qty() {
96         return qty;
97     }
98     
99     public Date earliest() {
100         return earliest;
101     }
102     
103     public boolean newApprovals() {
104         return hasNew;
105     }
106
107     public static Pending create() {
108         return new Pending((Date)null);
109     }
110
111 }