Upgrade to latest oparent
[aaf/authz.git] / authz-batch / src / main / java / com / att / authz / actions / ActionPuntDAO.java
1 /*******************************************************************************
2  * Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
3  *******************************************************************************/
4 package com.att.authz.actions;
5
6 import java.io.IOException;
7 import java.security.SecureRandom;
8 import java.util.Date;
9 import java.util.GregorianCalendar;
10
11 import com.att.authz.env.AuthzTrans;
12 import org.onap.aaf.inno.env.APIException;
13 import com.datastax.driver.core.Cluster;
14
15 public abstract class ActionPuntDAO<T, RV> extends ActionDAO<T, RV> {
16         private static final SecureRandom random = new SecureRandom();
17         private int months, range;
18         protected static final Date now = new Date();
19
20         public ActionPuntDAO(AuthzTrans trans, Cluster cluster, int months, int range) throws APIException, IOException {
21                 super(trans, cluster);
22                 this.months = months;
23                 this.range = range;
24         }
25
26         public ActionPuntDAO(AuthzTrans trans, ActionDAO<?, ?> predecessor, int months, int range) {
27                 super(trans, predecessor);
28                 this.months = months;
29                 this.range = range;
30         }
31         
32
33         protected Date puntDate() {
34                 GregorianCalendar temp = new GregorianCalendar();
35                 temp.setTime(now);
36                 if(range>0) {
37                         int forward = months+Math.abs(random.nextInt()%range);
38                         temp.add(GregorianCalendar.MONTH, forward);
39                         temp.add(GregorianCalendar.DAY_OF_MONTH, (random.nextInt()%30)-15);
40                 }
41                 return temp.getTime();
42                 
43         }
44
45 }