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