HistoryDAO.java-sonar fixes
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / dao / cass / HistoryDAO.java
index 69d1d26..6dd0fdd 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,16 +40,16 @@ import com.datastax.driver.core.Row;
 
 /**
  * History
- * 
+ *
  * Originally written PE3617
  * @author Jonathan
- * 
+ *
  * History is a special case, because we don't want Updates or Deletes...  Too likely to mess up history.
- * 
+ *
  * Jonathan 9-9-2013 - Found a problem with using "Prepare".  You cannot prepare anything with a "now()" in it, as
  * it is evaluated once during the prepare, and kept.  That renders any use of "now()" pointless.  Therefore
  * the Create function needs to be run fresh everytime.
- * 
+ *
  * Fixed in Cassandra 1.2.6 https://issues.apache.org/jira/browse/CASSANDRA-5616
  *
  */
@@ -84,8 +84,8 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
         public String  memo;
         public ByteBuffer reconstruct;
     }
-    
-    private static class HistLoader extends Loader<Data> {
+
+    public static class HistLoader extends Loader<Data> {
         public HistLoader(int keylimit) {
             super(keylimit);
         }
@@ -117,11 +117,10 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
             obj[++idx]=data.target;
             obj[++idx]=data.subject;
             obj[++idx]=data.memo;
-//            obj[++idx]=data.detail;
-            obj[++idx]=data.reconstruct;        
+            obj[++idx]=data.reconstruct;
         }
     };
-    
+
     private void init(AuthzTrans trans) {
         // Loader must match fields order
         defLoader = new HistLoader(KEYLIMIT);
@@ -130,19 +129,18 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
         // Need a specialty Creator to handle the "now()"
         // 9/9/2013 - Jonathan - Just great... now() is evaluated once on Client side, invalidating usage (what point is a now() from a long time in the past?
         // Unless this is fixed, we're putting in non-prepared statement
-        // Solved in Cassandra.  Make sure you are running 1.2.6 Cassandra or later. https://issues.apache.org/jira/browse/CASSANDRA-5616    
+        // Solved in Cassandra.  Make sure you are running 1.2.6 Cassandra or later. https://issues.apache.org/jira/browse/CASSANDRA-5616
         replace(CRUD.create, new PSInfo(trans, "INSERT INTO history (" +  helpers[FIELD_COMMAS] +
-                    ") VALUES(now(),?,?,?,?,?,?,?)", 
+                    ") VALUES(now(),?,?,?,?,?,?,?)",
                     new HistLoader(0) {
                         @Override
                         protected void key(Data data, int idx, Object[] obj) {
                         }
                     },writeConsistency)
                 );
-//        disable(CRUD.Create);
-        
-        replace(CRUD.read, new PSInfo(trans, SELECT_SP +  helpers[FIELD_COMMAS] +
-                " FROM history WHERE id = ?", defLoader,readConsistency) 
+
+       replace(CRUD.read, new PSInfo(trans, SELECT_SP +  helpers[FIELD_COMMAS] +
+                " FROM history WHERE id = ?", defLoader,readConsistency)
 //                new HistLoader(2) {
 //                    @Override
 //                    protected void key(Data data, int idx, Object[] obj) {
@@ -153,12 +151,12 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
             );
         disable(CRUD.update);
         disable(CRUD.delete);
-        
-        readByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + 
+
+        readByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] +
                 " FROM history WHERE user = ?", defLoader,readConsistency);
-        readBySubject = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + 
+        readBySubject = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] +
                 " FROM history WHERE subject = ? and target = ? ALLOW FILTERING", defLoader,readConsistency);
-        readByYRMN = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + 
+        readByYRMN = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] +
                 " FROM history WHERE yr_mon = ?", defLoader,readConsistency);
         async(true); //TODO dropping messages with Async
     }
@@ -169,25 +167,25 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
         // Sonar claims that SimpleDateFormat is not thread safe, so we can't be static
         data.yr_mon = Integer.parseInt(new SimpleDateFormat("yyyyMM").format(now));
         // data.day_time = Integer.parseInt(dayTimeFormat.format(now));
-        return data;        
+        return data;
     }
-    
+
     public void createBatch(StringBuilder sb, Data data) {
-       sb.append("INSERT INTO history (");
-       sb.append(helpers[FIELD_COMMAS]);
-       sb.append(") VALUES(now(),");
-       sb.append(data.yr_mon);
-       sb.append(",'");
-       sb.append(data.user);
-       sb.append("','");
-       sb.append(data.action);
-       sb.append("','");
-       sb.append(data.target);
-       sb.append("','");
-       sb.append(data.subject);
-       sb.append("','");
-       sb.append(data.memo);
-       sb.append("',null);\n");
+        sb.append("INSERT INTO history (");
+        sb.append(helpers[FIELD_COMMAS]);
+        sb.append(") VALUES(now(),");
+        sb.append(data.yr_mon);
+        sb.append(",'");
+        sb.append(data.user);
+        sb.append("','");
+        sb.append(data.action);
+        sb.append("','");
+        sb.append(data.target);
+        sb.append("','");
+        sb.append(data.subject);
+        sb.append("','");
+        sb.append(data.memo);
+        sb.append("',null);\n");
     }
 
     public Result<List<Data>> readByYYYYMM(AuthzTrans trans, int yyyymm) {
@@ -213,7 +211,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
         }
         return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt);
     }
-    
+
     public Result<List<Data>> readBySubject(AuthzTrans trans, String subject, String target, int ... yyyymm) {
         if (yyyymm.length==0) {
             return Result.err(Status.ERR_BadData, "No or invalid yyyymm specified");
@@ -224,10 +222,10 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
         }
         return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt);
     }
-    
+
     private class YYYYMM implements Accept<Data> {
         private int[] yyyymm;
-        public YYYYMM(int yyyymm[]) {
+        public YYYYMM(int[] yyyymm) {
             this.yyyymm = yyyymm;
         }
         @Override
@@ -240,7 +238,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> {
             }
             return false;
         }
-        
+
     };
-    
+
 }