From: Instrumental Date: Tue, 15 Oct 2019 13:19:50 +0000 (-0500) Subject: Sonar Fixes, Formatting X-Git-Tag: 2.1.17~93 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=commitdiff_plain;h=1296352d8eafee57f982a4342ad79ada4aa56d28 Sonar Fixes, Formatting Issue-ID: AAF-1019 Change-Id: Ica49d9e7323aad9622ff9d95cc21b87430c22c54 Signed-off-by: Instrumental --- diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java index f361e750..b5ff59b1 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java @@ -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. @@ -73,12 +73,12 @@ public abstract class Batch { protected static final String STARS = "*****"; - protected static Cluster cluster; + protected static Cluster cluster; protected static AuthzEnv env; protected static Session session; protected static Set specialNames; protected static List specialDomains; - protected static boolean dryRun; + protected static boolean dryRun; protected static String batchEnv; private static File logdir; @@ -88,12 +88,12 @@ public abstract class Batch { protected static final String MAX_EMAILS="MAX_EMAILS"; protected static final String VERSION="VERSION"; public static final String GUI_URL="GUI_URL"; - + protected final Organization org; protected String version; protected static final Date now = new Date(); protected static final Date never = new Date(0); - + protected Batch(AuthzEnv env) throws APIException, IOException, OrganizationException { if (batchEnv != null) { env.info().log("Redirecting to ",batchEnv,"environment"); @@ -149,22 +149,22 @@ public abstract class Batch { } } } - + version = env.getProperty(VERSION,Config.AAF_DEFAULT_API_VERSION); } protected abstract void run(AuthzTrans trans); protected void _close(AuthzTrans trans) {} - + public String[] args() { return env.get(ssargs); } - + public boolean isDryRun() { return dryRun; } - + public boolean isSpecial(String user) { if(user==null) { return false; @@ -230,7 +230,7 @@ public abstract class Batch { return (organization); } - + public static Row executeDeleteQuery(Statement stmt) { Row row = null; if (!dryRun) { @@ -240,7 +240,7 @@ public abstract class Batch { return (row); } - + public static int acquireRunLock(String className) { Boolean testEnv = true; String envStr = env.getProperty("AFT_ENVIRONMENT"); @@ -320,7 +320,7 @@ public abstract class Batch { } return (1); } - + private static void deleteLock( String className) { Row row = session.execute( String.format( "DELETE FROM authz.run_lock WHERE class = '%s' IF EXISTS", className ) ).one(); if (! row.getBool("[applied]")) { @@ -336,7 +336,7 @@ public abstract class Batch { } } } - + protected static File logDir() { if(logdir == null) { String ld = env.getProperty(LOG_DIR); @@ -351,7 +351,7 @@ public abstract class Batch { if(!logdir.exists()) { logdir.mkdirs(); } - } + } return logdir; } protected int count(String str, char c) { @@ -386,13 +386,13 @@ public abstract class Batch { sbos.getBuffer().append(s); sbos.getBuffer().append(' '); } - + InputStream is = null; String filename; String propLoc; try { Define.set(access); - + if(access.getProperty(Config.CADI_PROP_FILES)==null) { File f = new File("authBatch.props"); try { @@ -424,7 +424,7 @@ public abstract class Batch { } env = new AuthzEnv(access); - + transferVMProps(env, CASS_ENV, "DRY_RUN", "NS", "Organization"); // Be able to change Environments @@ -446,7 +446,7 @@ public abstract class Batch { Batch batch = null; AuthzTrans trans = env.newTrans(); - + TimeTaken tt = trans.start("Total Run", Env.SUB); try { int len = args.length; @@ -459,23 +459,23 @@ public abstract class Batch { if (len > 0) { System.arraycopy(args, 1, nargs, 0, len); } - + env.put(ssargs = env.staticSlot("ARGS"), nargs); - + /* * Add New Batch Programs (inherit from Batch) here */ - + // Might be a Report, Update or Temp Batch Class cls = null; String classifier = ""; - + String[] pkgs = new String[] { "org.onap.aaf.auth.batch.update", "org.onap.aaf.auth.batch.reports", "org.onap.aaf.auth.batch.temp" }; - + String ebp = env.getProperty("EXTRA_BATCH_PKGS"); if(ebp!=null) { String[] ebps = Split.splitTrim(':', ebp); @@ -484,12 +484,12 @@ public abstract class Batch { System.arraycopy(ebps,0,temp,pkgs.length,ebps.length); pkgs = temp; } - + for(String p : pkgs) { try { cls = ClassLoader.getSystemClassLoader().loadClass(p + '.' + toolName); int lastDot = p.lastIndexOf('.'); - if(p.length()>0 || p.length()!=lastDot) { + if(p.length()>0 || p.length()!=lastDot) { StringBuilder sb = new StringBuilder(); sb.append(Character.toUpperCase(p.charAt(++lastDot))); while(++lastDot ladd; - + public ApprovalSet(final GregorianCalendar start, final String target, final DataView dv) { dataview = dv; fdd = new FutureDAO.Data(); @@ -46,7 +46,7 @@ public class ApprovalSet { fdd.start = start.getTime(); ladd = new ArrayList<>(); } - + protected void setConstruct(final ByteBuffer bytes) { fdd.construct = bytes; } @@ -54,11 +54,11 @@ public class ApprovalSet { protected void setMemo(final String memo) { fdd.memo = memo; } - + protected void setExpires(final GregorianCalendar expires) { fdd.expires = expires.getTime(); } - + public Result write(AuthzTrans trans) { StringBuilder errs = null; if(ladd == null || ladd.isEmpty()) { @@ -89,7 +89,7 @@ public class ApprovalSet { public boolean hasApprovals() { return !ladd.isEmpty(); } - + public Set approvers() { Set rv = new HashSet<>(); for(ApprovalDAO.Data app : ladd) { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/DataView.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/DataView.java index c197f7f2..018f9493 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/DataView.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/DataView.java @@ -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. @@ -32,7 +32,7 @@ import org.onap.aaf.auth.layer.Result; /** * I have become convinced that Data for Apps is modeled by abstract access methods against multiple data - * sources. With the insistence of JUnits, it becomes much more paramount to create a model which can + * sources. With the insistence of JUnits, it becomes much more paramount to create a model which can * 1) be easily loaded from Disk "Test Data" without resorting to complex "mokito" schemes * 2) tested in Memory * 3) combined for REAL time by running Cached Memory @@ -42,14 +42,14 @@ import org.onap.aaf.auth.layer.Result; * c) JSON * d) XML * 5) persisted Globally through a store like Cassandra - * + * * But in the end, it looks like: * 1) Data Structures - * 2) Find the Data Structures by various means, accounting for + * 2) Find the Data Structures by various means, accounting for * a) Multiple Responses * b) Errors from the deepest level, made available through the call stack - * 3) - * + * 3) + * * @author jonathan.gathman * */ @@ -63,11 +63,11 @@ public interface DataView { // Inserts public Result insert(final AuthzTrans trans, final ApprovalDAO.Data add); public Result insert(final AuthzTrans trans, final FutureDAO.Data add); - + // Deletes public Result delete(final AuthzTrans trans, final ApprovalDAO.Data add); public Result delete(final AuthzTrans trans, final FutureDAO.Data add); - + // Clear any buffers public void flush(); } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Loader.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Loader.java index d91c42c0..654c2bbc 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Loader.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Loader.java @@ -8,9 +8,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. diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Pending.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Pending.java index 9a666981..04083d9e 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Pending.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Pending.java @@ -9,9 +9,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. @@ -31,11 +31,11 @@ import org.onap.aaf.misc.env.util.Chrono; public class Pending { public static final String REMIND = "remind"; - + int qty; boolean hasNew; Date earliest; - + /** * Use this constructor to indicate when last Notified * @param lastNotified @@ -74,32 +74,32 @@ public class Pending { public void inc() { ++qty; } - + public void inc(Pending value) { - qty+=value.qty; - if(earliest==null) { + qty += value.qty; + if(earliest == null) { earliest = value.earliest; - } else if(value.earliest!=null && value.earliest.before(earliest)) { + } else if(value.earliest != null && value.earliest.before(earliest)) { earliest = value.earliest; } } public void earliest(Date lastnotified) { - if(lastnotified==null) { + if(lastnotified == null) { hasNew=true; - } else if (earliest==null || lastnotified.before(earliest)) { + } else if (earliest == null || lastnotified.before(earliest)) { earliest = lastnotified; } } - + public int qty() { return qty; } - + public Date earliest() { return earliest; } - + public boolean newApprovals() { return hasNew; } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Ticket.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Ticket.java index 1884262f..0b8006cb 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Ticket.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/Ticket.java @@ -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. @@ -29,7 +29,7 @@ import org.onap.aaf.auth.batch.helpers.Future; public class Ticket { public final Future f; public final Set approvals; - + public Ticket(Future future) { this.f = future; approvals = new HashSet<>(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java index da13e84c..6b9e5e0b 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java @@ -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. @@ -57,9 +57,9 @@ public class URApprovalSet extends ApprovalSet { expires.setTime(urdd.expires); } setExpires(expires); - setTargetKey(urdd.user+'|'+urdd.role); + setTargetKey(urdd.user + '|' + urdd.role); setTargetDate(urdd.expires); - + Result r = dv.roleByName(trans, urdd.role); if(r.notOKorIsEmpty()) { throw new CadiException(r.errorString()); @@ -81,10 +81,10 @@ public class URApprovalSet extends ApprovalSet { if(found==null) { throw new CadiException(String.format("User '%s' in Role '%s' does not exist", urdd.user,urdd.role)); } - + // Primarily, Owners are responsible, unless it's owned by self boolean isOwner = false; - Result> owners = dv.ursByRole(trans, urdd.ns+".owner"); + Result> owners = dv.ursByRole(trans, urdd.ns + ".owner"); if(owners.isOK()) { for(UserRoleDAO.Data owner : owners.value) { if(urdd.user.equals(owner.user)) { @@ -114,7 +114,7 @@ public class URApprovalSet extends ApprovalSet { } } } - + private void setTargetDate(Date expires) { fdd.target_date = expires; } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java index a9029626..470cfb1e 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java @@ -9,9 +9,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. @@ -55,7 +55,7 @@ public class Approval implements CacheChange.Data { public static TreeMap> byTicket = new TreeMap<>(); public static List list = new LinkedList<>(); private static final CacheChange cache = new CacheChange<>(); - + public final ApprovalDAO.Data add; private String role; @@ -109,8 +109,8 @@ public class Approval implements CacheChange.Data { } } }; - - public Approval(UUID id, UUID ticket, String approver,// Date last_notified, + + public Approval(UUID id, UUID ticket, String approver,// Date last_notified, String user, String memo, String operation, String status, String type, long updated) { add = new ApprovalDAO.Data(); add.id = id; @@ -124,7 +124,7 @@ public class Approval implements CacheChange.Data { add.updated = new Date(updated); role = roleFromMemo(memo); } - + public static String roleFromMemo(String memo) { if (memo==null) { return null; @@ -156,31 +156,31 @@ public class Approval implements CacheChange.Data { public static int load(Trans trans, Session session, Creator creator, Visitor visitor) { int count = 0; try { - count+=call(trans,session,creator.query(null), creator, visitor); + count += call(trans,session,creator.query(null), creator, visitor); } finally { trans.info().log("Found",count,"Approval Records"); } return count; } - + public static int load(Trans trans, Session session, Creator creator ) { int count = 0; try { - count+=call(trans,session,creator.query(null), creator, FullLoad); + count += call(trans,session,creator.query(null), creator, FullLoad); } finally { trans.info().log("Found",count,"Approval Records"); } return count; } - + public static int loadUsers(Trans trans, Session session, Set users, Visitor visitor) { int total = 0; for(String user : users) { - total+=call(trans,session,String.format("%s WHERE user='%s';",v2_0_17.select(), user),v2_0_17,visitor); + total += call(trans,session,String.format("%s WHERE user='%s';",v2_0_17.select(), user),v2_0_17,visitor); } return total; } - + public static void row(CSV.RowSetter crs, Approval app) { crs.row("approval",app.add.id,app.add.ticket,app.add.user,app.role,app.add.memo); } @@ -201,14 +201,14 @@ public class Approval implements CacheChange.Data { tt.done(); } } - + @Override public void expunge() { List la = byApprover.get(getApprover()); if (la!=null) { la.remove(this); } - + la = byUser.get(getUser()); if (la!=null) { la.remove(this); @@ -288,11 +288,11 @@ public class Approval implements CacheChange.Data { add.ticket=null; add.status="lapsed"; } - + public String getRole() { return role; } - + public String toString() { return getUser() + ' ' + getMemo(); } @@ -310,12 +310,12 @@ public class Approval implements CacheChange.Data { } } } - + public static void resetLocalData() { cache.resetLocalData(); } - + public static int sizeForDeletion() { return cache.cacheSize(); } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/BatchDataView.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/BatchDataView.java index 9906f499..156cb097 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/BatchDataView.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/BatchDataView.java @@ -9,9 +9,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. @@ -57,7 +57,7 @@ public class BatchDataView implements DataView { public Session getSession(AuthzTrans trans){ return session; } - + public Result ns(AuthzTrans trans, String id) { NS n; TimeTaken tt = trans.start("Get NS by ID %s", Trans.SUB, id); @@ -66,14 +66,14 @@ public class BatchDataView implements DataView { } finally { tt.done(); } - + if(n==null || n.ndd==null) { return Result.err(Result.ERR_Backend,"Namespace '%s' does not exist", id); } return Result.ok(n.ndd); } - + @Override public Result roleByName(AuthzTrans trans, String name) { Role r = Role.byName.get(name); @@ -116,22 +116,22 @@ public class BatchDataView implements DataView { StringBuilder sb = cqlBatch.inc(); sb.append("DELETE from authz.future WHERE id = "); sb.append(fdd.id.toString()); - return Result.ok(fdd); + return Result.ok(fdd); } - + @Override public Result delete(AuthzTrans trans, ApprovalDAO.Data add) { StringBuilder sb = cqlBatch.inc(); sb.append("DELETE from authz.approval WHERE id = "); sb.append(add.id.toString()); - return Result.ok(add); + return Result.ok(add); } @Override public Result insert(AuthzTrans trans, ApprovalDAO.Data add) { StringBuilder sb = cqlBatch.inc(); - sb.append("INSERT INTO authz.approval (id,approver,memo,operation,status,ticket,type,user) VALUES ("); + sb.append("INSERT INTO authz.approval (id,approver,memo,operation,status,ticket,type,user) VALUES ("); sb.append(add.id.toString()); sb.append(COMMA_QUOTE); sb.append(add.approver); @@ -154,7 +154,7 @@ public class BatchDataView implements DataView { @Override public Result insert(AuthzTrans trans, FutureDAO.Data fdd) { StringBuilder sb = cqlBatch.inc(); - sb.append("INSERT INTO authz.future (id,construct,expires,memo,start,target,target_key,target_date) VALUES ("); + sb.append("INSERT INTO authz.future (id,construct,expires,memo,start,target,target_key,target_date) VALUES ("); sb.append(fdd.id.toString()); sb.append(','); fdd.construct.hasArray(); @@ -178,7 +178,7 @@ public class BatchDataView implements DataView { sb.append(QUOTE_PAREN_SEMI); return Result.ok(fdd); } - + @Override public void flush() { cqlBatch.flush(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java index d62c7781..ccfb1c5f 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java @@ -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. @@ -47,7 +47,7 @@ public class CQLBatch { hasAdded = sb.length(); return sb; } - + private boolean end() { if(sb.length()==hasAdded) { return false; @@ -57,7 +57,7 @@ public class CQLBatch { return true; } } - + public ResultSet execute() { if(end()) { if(sleep>0) { @@ -66,17 +66,19 @@ public class CQLBatch { try { Thread.sleep(left); } catch (InterruptedException e) { - Access.NULL.log(e); // Keep code check idiocy at bay + // PER ORACLE, this isn't actually needed, but Sonar idiocy + // requires something or flags as error. + return null; } } - last = System.currentTimeMillis()+sleep; + last = System.currentTimeMillis() + sleep; } return session.execute(sb.toString()); } else { return null; } } - + public ResultSet execute(boolean dryRun) { ResultSet rv = null; if(dryRun) { @@ -86,10 +88,12 @@ public class CQLBatch { try { Thread.sleep(left); } catch (InterruptedException e) { - Access.NULL.log(e); // Keep code check idiocy at bay + // PER ORACLE, this isn't actually needed, but Sonar idiocy + // requires something or flags as error. + return null; } } - last = System.currentTimeMillis()+sleep; + last = System.currentTimeMillis() + sleep; } end(); } else { @@ -98,7 +102,7 @@ public class CQLBatch { sb.setLength(0); return rv; } - + public ResultSet singleExec(StringBuilder query, boolean dryRun) { if(dryRun) { return null; @@ -106,10 +110,10 @@ public class CQLBatch { return session.execute(query.toString()); } } - + public void touch(String table, int begin, int end, boolean dryRun) { StringBuilder sb = begin(); - for(int i=begin;i=maxBatch || current.length()+sb.length()>MAX_CHARS)&&(i>0)) { - - cqlBatch.execute(dryRun); + if((i>=maxBatch || current.length() + sb.length() > MAX_CHARS) && (i > 0)) { + + cqlBatch.execute(dryRun); i = -1; incBatch(); } - if(i<0) { + if(i < 0) { cqlBatch.begin(); - i=0; + i = 0; } if(current.length() > MAX_CHARS) { cqlBatch.singleExec(current, dryRun); @@ -74,23 +74,23 @@ public class CQLBatchLoop { ++total; return current; } - + /** * Close up when finished. */ public void flush() { - if(current.length()+sb.length()>MAX_CHARS) { - if(i>0) { + if(current.length() + sb.length() > MAX_CHARS) { + if(i > 0) { cqlBatch.execute(dryRun); incBatch(); } - if(current.length()>0) { + if(current.length() > 0) { cqlBatch.singleExec(current, dryRun); current.setLength(0); incBatch(); } } else { - if(i<0) { + if(i < 0) { cqlBatch.begin(); } sb.append(current); @@ -98,23 +98,23 @@ public class CQLBatchLoop { cqlBatch.execute(dryRun); incBatch(); } - i=-1; + i = -1; } private void incBatch() { ++batches; if(showProgress) { System.out.print('.'); - if(batches%70==0) { + if(batches%70 == 0) { System.out.println(); - } + } } } public int total() { return total; } - + public int batches() { return batches; } @@ -124,7 +124,7 @@ public class CQLBatchLoop { batches = 0; i = -1; } - + public String toString() { return cqlBatch.toString(); } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CacheChange.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CacheChange.java index 84d7b5a2..a623945c 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CacheChange.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CacheChange.java @@ -8,9 +8,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. @@ -27,24 +27,24 @@ import java.util.List; public class CacheChange { private List removed; - + public CacheChange() { removed = new ArrayList<>(); } - - @FunctionalInterface + + @FunctionalInterface interface Data { public abstract void expunge(); } - + public final void delayedDelete(T t) { removed.add(t); } - + public final List getRemoved() { return removed; } - + public final void resetLocalData() { if (removed==null || removed.isEmpty()) { return; diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java index a4e4112f..d1389432 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java @@ -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. @@ -26,11 +26,11 @@ import com.datastax.driver.core.Row; public abstract class Creator { public abstract T create(Row row); public abstract String select(); - + public String suffix() { return ""; } - + public String query(String where) { StringBuilder sb = new StringBuilder(select()); if (where!=null) { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java index 6f23c515..49309004 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java @@ -8,9 +8,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. @@ -22,7 +22,6 @@ package org.onap.aaf.auth.batch.helpers; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; @@ -53,13 +52,13 @@ public class Cred { public final String id; public final List instances; public final String ns; - + public Cred(String id) { this.id = id; instances = new ArrayList<>(); ns=Question.domain2ns(id); } - + public static class Instance { public final int type; public final Date expires,written; @@ -67,7 +66,7 @@ public class Cred { public final String tag; public List notes; - + public Instance(int type, Date expires, Integer other, long written, String tag) { this.type = type; this.expires = expires; @@ -75,7 +74,7 @@ public class Cred { this.written = new Date(written); this.tag = tag; } - + /** * Usually returns Null... * @return @@ -83,23 +82,23 @@ public class Cred { public List notes() { return notes; } - + public void addNote(int level, String note) { if(notes==null) { notes=new ArrayList<>(); - } + } notes.add(new Note(level,note)); } - + public String toString() { return expires.toString() + ": " + type + ' ' + tag; } } - + public static class Note { public final int level; public final String note; - + public Note(int level, String note) { this.level = level; this.note = note; @@ -127,7 +126,7 @@ public class Cred { return last; } - + public Set types() { Set types = new HashSet<>(); for (Instance i : instances) { @@ -148,7 +147,7 @@ public class Cred { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Creds", Env.REMOTE); - + ResultSet results; try { Statement stmt = new SimpleStatement( query ); @@ -190,7 +189,7 @@ public class Cred { } public static void add( - final String id, + final String id, final int type, final Date timestamp, final int other, @@ -203,10 +202,10 @@ public class Cred { data.put(id, cred); } cred.instances.add(new Instance(type, timestamp, other, written/1000,tag)); - - List lscd = byNS.get(cred.ns); + + List lscd = byNS.get(cred.ns); if (lscd==null) { - lscd=new ArrayList<>(); + lscd=new ArrayList<>(); byNS.put(cred.ns,lscd); } boolean found = false; @@ -222,10 +221,10 @@ public class Cred { } - /** + /** * Count entries in Cred data. * Note, as opposed to other methods, need to load the whole cred table for the Types. - * @param numbuckets + * @param numbuckets * @return */ public static CredCount count(int numbuckets) { @@ -246,7 +245,7 @@ public class Cred { public int x509Added[]; public int x509Expired[]; public Date dates[]; - + public CredCount(int numbuckets) { raw = new int[numbuckets]; basic_auth = new int[numbuckets]; @@ -263,17 +262,17 @@ public class Cred { gc.set(GregorianCalendar.SECOND,0); gc.set(GregorianCalendar.MILLISECOND,0); gc.add(GregorianCalendar.MILLISECOND, -1); // last milli of month - for (int i=1;i row) { Long l = Long.parseLong(row.get(5)); - String date = sdf.format(new Date(l)); + String date = Chrono.batchFmt.format(new Date(l)); sb.append("DELETE from authz.cred WHERE id='"); sb.append(row.get(1)); sb.append("' AND type="); @@ -331,7 +329,7 @@ public class Cred { // sb.append(" AND expires=dateof(maxtimeuuid("); // sb.append(row.get(5)); // sb.append("));\n"); - + } public String toString() { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/ExpireRange.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/ExpireRange.java index c7d4e7d4..bb3a3e94 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/ExpireRange.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/ExpireRange.java @@ -9,9 +9,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. @@ -47,7 +47,7 @@ public class ExpireRange { public final Range approveDelete ; private Range delRange; - + public ExpireRange(final Access access) { ranges = new HashMap<>(); intervalDates = new HashMap<>(); @@ -58,8 +58,8 @@ public class ExpireRange { List lcred = getRangeList("cred"); List lur = getRangeList("ur"); List lx509 = getRangeList("x509"); - - + + /* Range(Name, ReportingLevel, PeopleInterval, AppInterval, Start(Type,Qty) End(Type,Qty) ) Interval of -1 Means "only once" @@ -70,25 +70,25 @@ public class ExpireRange { lur.add(delRange); lcred.add(delRange); lx509.add(delRange); - + lcred.add(new Range(ONE_WEEK ,3,-1,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1)); lcred.add(new Range(TWO_WEEK ,2,-1,-1,GregorianCalendar.WEEK_OF_MONTH,1,GregorianCalendar.WEEK_OF_MONTH,2)); lcred.add(new Range(ONE_MONTH,1,7,7,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1)); lcred.add(new Range(TWO_MONTH,1,-1,-1,GregorianCalendar.MONTH,1,GregorianCalendar.MONTH,2)); - + lur.add( new Range(ONE_MONTH,1,-1,-1,0,0,GregorianCalendar.MONTH,1)); // Comment out until we can get some more clear actions in place for GUI // lur.add( new Range(ONE_MONTH,1,-1,-1,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1)); // lur.add( new Range(ONE_WEEK,2,-1,1,0,0,GregorianCalendar.WEEK_OF_MONTH,1)); - + lx509.add(new Range(ONE_MONTH,1,-1,-1,GregorianCalendar.WEEK_OF_MONTH,2,GregorianCalendar.MONTH,1)); } } - + public Range newFutureRange() { return new Range("Approval",7,7,1,0,0,GregorianCalendar.MONTH,1); } - + public Set names() { Set names = new HashSet<>(); for(List lr : ranges.values()) { @@ -99,7 +99,7 @@ public class ExpireRange { return names; } - + private synchronized List getRangeList(final String key) { List rv = ranges.get(key); if(rv==null) { @@ -108,7 +108,7 @@ public class ExpireRange { } return rv; } - + public class Range { private final String name; private final int reportingLevel; @@ -117,11 +117,11 @@ public class ExpireRange { private final Date start; private final Date end; private final Date lowerValid; - + public Range( - final String name, final int reportingLevel, - final int peopleInterval, final int appInterval, - final int startGCType, final int startQty, + final String name, final int reportingLevel, + final int peopleInterval, final int appInterval, + final int startGCType, final int startQty, final int endGCType,final int endQty) { this.name = name; this.reportingLevel = reportingLevel; @@ -135,7 +135,7 @@ public class ExpireRange { gc.add(startGCType, startQty); } start = gc.getTime(); - + if(endGCType<0) { gc.set(GregorianCalendar.YEAR, 1); } else { @@ -143,7 +143,7 @@ public class ExpireRange { gc.add(endGCType, endQty); } end = gc.getTime(); - + if(endGCType<0) { gc.set(GregorianCalendar.YEAR, -1); @@ -154,11 +154,11 @@ public class ExpireRange { lowerValid = gc.getTime(); } - + public String name() { return name; } - + public int reportingLevel() { return reportingLevel; } @@ -190,11 +190,11 @@ public class ExpireRange { public Date getStart() { return start; } - + public Date getEnd() { return end; } - + public boolean inRange(final Date date) { if(date==null) { return false; @@ -226,6 +226,6 @@ public class ExpireRange { public Date now() { return now; } - + } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Future.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Future.java index fd0de1fc..4bbab9d3 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Future.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Future.java @@ -9,9 +9,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. @@ -51,7 +51,7 @@ import com.datastax.driver.core.Statement; public class Future implements CacheChange.Data, Comparable { public static final Map data = new TreeMap<>(); public static final Map> byRole = new TreeMap<>(); - + public final FutureDAO.Data fdd; public final String role; // derived private static final CacheChange cache = new CacheChange<>(); @@ -106,27 +106,27 @@ public class Future implements CacheChange.Data, Comparable { } this.role = role; } - + public final UUID id() { return fdd.id; } - + public final String memo() { return fdd.memo; } - + public final String target() { return fdd.target; } - + public final Date start() { return fdd.start; } - + public final Date expires() { return fdd.expires; } - + public static void load(Trans trans, Session session, Creator creator) { load(trans,session,creator, f -> { data.put(f.fdd.id,f); @@ -149,7 +149,7 @@ public class Future implements CacheChange.Data, Comparable { } finally { tt.done(); } - + int count = 0; tt = trans.start("Process Futures", Env.SUB); try { @@ -181,7 +181,7 @@ public class Future implements CacheChange.Data, Comparable { } return rv; } - + /* (non-Javadoc) * @see org.onap.aaf.auth.helpers.CacheChange.Data#resetLocalData() */ @@ -207,7 +207,7 @@ public class Future implements CacheChange.Data, Comparable { public static void resetLocalData() { cache.resetLocalData(); } - + public static int sizeForDeletion() { return cache.cacheSize(); } @@ -215,7 +215,7 @@ public class Future implements CacheChange.Data, Comparable { public static boolean pendingDelete(Future f) { return cache.contains(f); } - + public static void row(CSV.Writer cw, Future f) { cw.row("future",f.fdd.id,f.fdd.target,f.fdd.expires,f.role,f.fdd.memo); } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java index dfacd81b..67203af2 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java @@ -9,9 +9,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. @@ -49,28 +49,28 @@ public class LastNotified { private Session session; public static final Date NEVER = new Date(0); private static final String SELECT = "SELECT user,target,key,last FROM authz.notified"; - + public LastNotified(Session session) { this.session = session; } - + public void add(Set users) { StringBuilder query = new StringBuilder(); startQuery(query); int cnt = 0; for(String user : users) { - if(++cnt>1) { + if(++cnt > 1) { query.append(','); } query.append('\''); query.append(user); query.append('\''); - if(cnt>=30) { + if(cnt >= 30) { endQuery(query); add(session.execute(query.toString()),lastNotifiedVar, (x,y) -> false); query.setLength(0); startQuery(query); - cnt=0; + cnt = 0; } } if(cnt>0) { @@ -81,7 +81,7 @@ public class LastNotified { /** * Note: target_key CAN also contain a Pipe. - * + * * @param user * @param target * @param targetkey @@ -91,12 +91,12 @@ public class LastNotified { String key = user + '|' + target + '|' + (targetkey==null?"":targetkey); return lastNotified(key); } - + public Date lastNotified(String key) { Date d = lastNotifiedVar.get(key); return d==null?NEVER:d; } - + private Date add(ResultSet result, Map lastNotified, MarkDelete md) { Date last = null; Row r; @@ -104,7 +104,7 @@ public class LastNotified { r = iter.next(); String ttKey = r.getString(1) + '|' + r.getString(2); - + String fullKey = r.getString(0) + '|' + ttKey; last=r.getTimestamp(3); @@ -118,7 +118,7 @@ public class LastNotified { } return last; } - + @FunctionalInterface private interface MarkDelete { boolean process(String fullKey, Date last); @@ -167,7 +167,7 @@ public class LastNotified { } public static String newKey(UserRole ur) { - return "ur|" + ur.user() + '|'+ur.role(); + return "ur|" + ur.user() + '|' + ur.role(); } public static String newKey(Cred cred, Instance inst) { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java index e76f5235..bf1338f5 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java @@ -9,9 +9,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. @@ -62,9 +62,9 @@ public class NS implements Comparable { ndd.description = description; ndd.parent = parent; ndd.type = type; - // ndd.attrib = + // ndd.attrib = } - + public static void load(Trans trans, Session session, Creator creator) { load(trans,session, "select name, description, parent, type, scope from authz.ns;" @@ -72,10 +72,10 @@ public class NS implements Comparable { , v -> data.put(v.ndd.name,v) ); } - + public static void loadOne(Trans trans, Session session, Creator creator, String ns) { load(trans,session, - ("select name, description, parent, type, scope from authz.ns WHERE name='"+ns+"';") + ("select name, description, parent, type, scope from authz.ns WHERE name='" + ns + "';") ,creator , v -> data.put(v.ndd.name,v) ); @@ -84,7 +84,7 @@ public class NS implements Comparable { public static void load(Trans trans, Session session, Creator creator, Visitor visitor) { load(trans,session,creator.query(null),creator, visitor); } - + public void row(final CSV.Writer csvw, String tag) { csvw.row(tag,ndd.name,ndd.type,ndd.parent); } @@ -102,7 +102,7 @@ public class NS implements Comparable { } finally { tt.done(); } - + try { Iterator iter = results.iterator(); @@ -136,7 +136,7 @@ public class NS implements Comparable { tt.done(); } } - + public String toString() { return ndd.name; } @@ -161,21 +161,21 @@ public class NS implements Comparable { public int compareTo(NS o) { return ndd.name.compareTo(o.ndd.name); } - + public static class NSSplit { public String ns; public String other; public NSSplit(String s, int dot) { ns = s.substring(0,dot); - other = s.substring(dot+1); + other = s.substring(dot + 1); } } public static NSSplit deriveParent(String dotted) { if (dotted==null) { return null; } - for (int idx = dotted.lastIndexOf('.');idx>=0; idx=dotted.lastIndexOf('.',idx-1)) { - if (data.get(dotted.substring(0, idx))!=null) { + for (int idx = dotted.lastIndexOf('.');idx >= 0; idx = dotted.lastIndexOf('.',idx - 1)) { + if (data.get(dotted.substring(0, idx)) != null) { return new NSSplit(dotted,idx); } } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java index a2cba259..16c40952 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java @@ -9,9 +9,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. @@ -50,14 +50,14 @@ public class NsAttrib { return "select ns,key,value from authz.ns_attrib"; } }; - - + + public NsAttrib(String ns, String key, String value) { this.ns = ns; this.key = key; this.value = value; } - + public static void load(Trans trans, Session session, Creator creator, Visitor visitor) { trans.info().log( "query: " + creator.select() ); ResultSet results; diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Role.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Role.java index e69ef51d..3f750fb8 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Role.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Role.java @@ -9,9 +9,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. @@ -50,7 +50,7 @@ public class Role implements Comparable { public RoleDAO.Data rdd; private String full; private String encode; - + public Role(String full) { rdd = new RoleDAO.Data(); rdd.ns = ""; @@ -59,7 +59,7 @@ public class Role implements Comparable { rdd.perms = new HashSet<>(); this.full = full; } - + public Role(String ns, String name, String description,Set perms) { rdd = new RoleDAO.Data(); rdd.ns = ns; @@ -69,18 +69,18 @@ public class Role implements Comparable { this.full = null; this.encode = null; } - + public String encode() { if (encode==null) { encode = rdd.ns + '|' + rdd.name; - } + } return encode; } public String fullName() { if (full==null) { full = rdd.ns + '.' + rdd.name; - } + } return full; } @@ -95,7 +95,7 @@ public class Role implements Comparable { private static void load(Trans trans, Session session, String query) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Roles", Env.REMOTE); - + ResultSet results; try { Statement stmt = new SimpleStatement( query ); @@ -123,7 +123,7 @@ public class Role implements Comparable { trans.info().log("Found",data.size(),"roles"); } } - + public static long count(Trans trans, Session session) { String query = "select count(*) from authz.role LIMIT 1000000;"; trans.info().log( "query: " + query ); @@ -166,11 +166,11 @@ public class Role implements Comparable { public static String fullName(String role) { return role.replace('|', '.'); } - + public static void stageRemove(Role r) { deleteRoles.add(r); } - + public static void executeRemove() { for (Role p : deleteRoles) { keys.remove(p.encode); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java index dd24d7d9..ae46253c 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java @@ -57,7 +57,7 @@ public class UserRole implements Cloneable, CacheChange.Data { // CACHE Calling private static final String LOG_FMT = "%s UserRole - %s: %s-%s (%s, %s) expiring %s"; private static final String REPLAY_FMT = "%s|%s|%s|%s|%s\n"; - private static final String DELETE_FMT = "# %s\n"+ REPLAY_FMT; + private static final String DELETE_FMT = "# %s\n" + REPLAY_FMT; private static final List data = new ArrayList<>(); private static final SortedMap> byUser = new TreeMap<>(); @@ -81,7 +81,7 @@ public class UserRole implements Cloneable, CacheChange.Data { } }; - public UserRole(String user, String ns, String rname, Date expires) { + public UserRole(String user, String ns, String rname, Date expires) { urdd = new UserRoleDAO.Data(); urdd.user = user; urdd.role = ns + '.' + rname; @@ -114,7 +114,7 @@ public class UserRole implements Cloneable, CacheChange.Data { public static void load(Trans trans, Session session, Creator creator) { load(trans,session,creator,null,new DataLoadVisitor()); } - + public static void load(Trans trans, Session session, Creator creator, Visitor visitor ) { load(trans,session,creator,null,visitor); } @@ -122,19 +122,19 @@ public class UserRole implements Cloneable, CacheChange.Data { public static void loadOneRole(Trans trans, Session session, Creator creator, String role, Visitor visitor) { load(trans,session,creator,"role='" + role +"' ALLOW FILTERING;",visitor); } - + public static void loadOneUser(Trans trans, Session session, Creator creator, String user, Visitor visitor ) { - load(trans,session,creator,"user='"+ user +'\'',visitor); + load(trans,session,creator,"user='" + user + '\'',visitor); } public static void load(Trans trans, CSV csv, Creator creator, Visitor visitor) throws IOException, CadiException { // public UserRole(String user, String role, String ns, String rname, Date expires) { - csv.visit( row -> + csv.visit( row -> visitor.visit(new UserRole(row.get(1),row.get(2),row.get(3),row.get(4), new Date(Long.parseLong(row.get(6))))) ); } - + private static void load(Trans trans, Session session, Creator creator, String where, Visitor visitor) { String query = creator.query(where); trans.debug().log( "query: " + query ); @@ -189,30 +189,30 @@ public class UserRole implements Cloneable, CacheChange.Data { lur.add(ur); } } - + public int totalLoaded() { return totalLoaded; } - + public int deleted() { return deleted; } - + @Override public void expunge() { data.remove(this); - + List lur = byUser.get(urdd.user); if (lur!=null) { lur.remove(this); } - + lur = byRole.get(urdd.role); if (lur!=null) { lur.remove(this); } } - + public static void setDeleteStream(PrintStream ds) { urDelete = ds; } @@ -238,27 +238,27 @@ public class UserRole implements Cloneable, CacheChange.Data { public UserRoleDAO.Data urdd() { return urdd; } - + public String user() { return urdd.user; } - + public String role() { return urdd.role; } - + public String ns() { return urdd.ns; } - + public String rname() { return urdd.rname; } - + public Date expires() { return urdd.expires; } - + public void expires(Date time) { urdd.expires = time; } @@ -296,7 +296,7 @@ public class UserRole implements Cloneable, CacheChange.Data { cache.delayedDelete(this); ++deleted; } - + /** * Calls expunge() for all deleteCached entries @@ -304,7 +304,7 @@ public class UserRole implements Cloneable, CacheChange.Data { public static void resetLocalData() { cache.resetLocalData(); } - + public void row(final CSV.Writer csvw, String tag) { csvw.row(tag,user(),role(),ns(),rname(),Chrono.dateOnlyStamp(expires()),expires().getTime()); } @@ -312,7 +312,7 @@ public class UserRole implements Cloneable, CacheChange.Data { public void row(final CSV.Writer csvw, String tag, String reason) { csvw.row(tag,user(),role(),ns(),rname(),Chrono.dateOnlyStamp(expires()),expires().getTime(),reason); } - + public static Data row(List row) { Data data = new Data(); data.user = row.get(1); @@ -350,7 +350,7 @@ public class UserRole implements Cloneable, CacheChange.Data { sb.append(role()); sb.append("';\n"); } - + public void batchUpdateExpires(StringBuilder sb) { sb.append("UPDATE authz.user_role SET expires='"); sb.append(Chrono.dateTime(expires())); @@ -364,7 +364,7 @@ public class UserRole implements Cloneable, CacheChange.Data { public static String histMemo(String fmt, List row) { String reason; if(row.size()>7) { // Reason included - reason = String.format("%s removed from %s because %s", + reason = String.format("%s removed from %s because %s", row.get(1),row.get(2),row.get(7)); } else { reason = String.format(fmt, row.get(1),row.get(2), row.get(5)); @@ -373,7 +373,7 @@ public class UserRole implements Cloneable, CacheChange.Data { } public static String histSubject(List row) { - return row.get(1) + '|' + row.get(2); + return row.get(1) + '|' + row.get(2); } public static void clear() { @@ -381,6 +381,6 @@ public class UserRole implements Cloneable, CacheChange.Data { byUser.clear(); byRole.clear(); cache.resetLocalData(); - + } } \ No newline at end of file diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Visitor.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Visitor.java index 38a76477..e1b2e01b 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Visitor.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Visitor.java @@ -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. @@ -22,14 +22,14 @@ package org.onap.aaf.auth.batch.helpers; public interface Visitor { void visit(T t); - + public static class Multi implements Visitor { private final Visitor[] visitors; @SafeVarargs public Multi(Visitor ... vs) { visitors = vs; } - + @Override public void visit(T t) { for(Visitor v : visitors) { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java index e2d86947..59b03f6a 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java @@ -9,9 +9,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. @@ -48,7 +48,7 @@ public class X509 { public final String x500; public final String x509; public ByteBuffer serial; - + public X509(String ca, String id, String x500, String x509, ByteBuffer serial) { this.ca = ca; this.id = id; @@ -56,12 +56,12 @@ public class X509 { this.x509 = x509; this.serial = serial; } - + public static void load(Trans trans, Session session, Visitor visitor) { load(trans,session, "" , visitor); } - + public static void load(Trans trans, Session session, String where, Visitor visitor) { load(trans,session, visitor,"select ca, id, x500, x509, serial from authz.x509 " + where +';'); } @@ -70,7 +70,7 @@ public class X509 { private static void load(Trans trans, Session session, Visitor visitor, String query) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read X509", Env.REMOTE); - + ResultSet results; try { Statement stmt = new SimpleStatement( query ); @@ -97,7 +97,7 @@ public class X509 { trans.info().log("Found",count,"X509 Certificates"); } } - + public static long count(Trans trans, Session session) { String query = "select count(*) from authz.x509 LIMIT 1000000;"; trans.info().log( "query: " + query ); @@ -111,7 +111,7 @@ public class X509 { tt.done(); } } - + public void row(CSV.Writer cw, X509Certificate x509Cert) { cw.row("x509",ca,Hash.toHex(serial.array()),Chrono.dateOnlyStamp(x509Cert.getNotAfter()),x500); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Analyze.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Analyze.java index d7d97ad8..78c6ae3a 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Analyze.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Analyze.java @@ -9,9 +9,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. @@ -75,8 +75,8 @@ public class Analyze extends Batch { private static final int total=0; private static final int pending=1; private static final int approved=2; - - + + public static final String NEED_APPROVALS = "NeedApprovals"; private static final String EXTEND = "Extend"; private static final String EXPIRED_OWNERS = "ExpiredOwners"; @@ -92,11 +92,11 @@ public class Analyze extends Batch { private Range futureRange; private final String sdate; private LastNotified ln; - + public Analyze(AuthzTrans trans) throws APIException, IOException, OrganizationException { super(trans.env()); trans.info().log("Starting Connection Process"); - + TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB); try { TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); @@ -105,13 +105,13 @@ public class Analyze extends Batch { } finally { tt.done(); } - + minOwners=1; - // Create Intermediate Output + // Create Intermediate Output writerList = new HashMap<>(); - + expireRange = new ExpireRange(trans.env().access()); sdate = Chrono.dateOnlyStamp(now); for( List lr : expireRange.ranges.values()) { @@ -130,7 +130,7 @@ public class Analyze extends Batch { } } } - + // Setup New Approvals file futureRange = expireRange.newFutureRange(); File file = new File(logDir(),NEED_APPROVALS + sdate +CSV); @@ -138,14 +138,14 @@ public class Analyze extends Batch { needApproveCW = approveCSV.writer(); needApproveCW.row(INFO,NEED_APPROVALS,sdate,1); writerList.put(NEED_APPROVALS,needApproveCW); - + // Setup Extend Approvals file file = new File(logDir(),EXTEND + sdate +CSV); CSV extendCSV = new CSV(env.access(),file); extendCW = extendCSV.writer(); extendCW.row(INFO,EXTEND,sdate,1); writerList.put(EXTEND,extendCW); - + // Load full data of the following ln = new LastNotified(session); @@ -158,17 +158,17 @@ public class Analyze extends Batch { protected void run(AuthzTrans trans) { TimeTaken tt; AuthzTrans noAvg = trans.env().newTransNoAvg(); - + //////////////////// // Load all Notifieds, and either add to local Data, or mark for Deletion. ln.loadAll(noAvg,expireRange.approveDelete,deleteCW); - + // Hold Good Tickets to keyed User/Role for UserRole Step Map mur = new TreeMap<>(); try { Approval.load(trans, session, Approval.v2_0_17); - + //////////////////// final Map goodTickets = new TreeMap<>(); tt = trans.start("Analyze Expired Futures",Trans.SUB); @@ -193,7 +193,7 @@ public class Analyze extends Batch { } finally { tt.done(); } - + Set approvers = new TreeSet<>(); tt = trans.start("Connect Approvals with Futures",Trans.SUB); try { @@ -209,7 +209,7 @@ public class Analyze extends Batch { } else { // for users and approvers still valid String user = appr.getUser(); - + if(org.isRevoked(noAvg, appr.getApprover())) { deleteCW.comment("Approver ID is revoked"); Approval.row(deleteCW, appr); @@ -225,16 +225,16 @@ public class Analyze extends Batch { } finally { tt.done(); } - - /* Run through all Futures, and see if + + /* Run through all Futures, and see if * 1) they have been executed (no longer valid) - * 2) The current Approvals indicate they can proceed + * 2) The current Approvals indicate they can proceed */ Map pendingApprs = new HashMap<>(); Map pendingTemp = new HashMap<>(); - + String approver; - + tt = trans.start("Analyze Good Tickets",Trans.SUB); try { for(Ticket ticket : goodTickets.values()) { @@ -244,7 +244,7 @@ public class Analyze extends Batch { case "user_role": int state[][] = new int[3][3]; int type; - + for(Approval appr : ticket.approvals) { switch(appr.getType()) { case "owner": @@ -276,13 +276,13 @@ public class Analyze extends Batch { ++state[type][unknown]; } } - + // To Approve: // Always must have at least 1 owner if((state[owner][total]>0 && state[owner][approved]>0) && // If there are no Supervisors, that's ok - (state[supervisor][total]==0 || - // But if there is a Supervisor, they must have approved + (state[supervisor][total]==0 || + // But if there is a Supervisor, they must have approved (state[supervisor][approved]>0))) { UserRoleDAO.Data urdd = new UserRoleDAO.Data(); try { @@ -307,7 +307,7 @@ public class Analyze extends Batch { } } finally { if("user_role".equals(ticket.f.fdd.target)) { - String key = ticket.f.fdd.target_key; + String key = ticket.f.fdd.target_key; if(key!=null) { mur.put(key, ticket); } @@ -319,7 +319,7 @@ public class Analyze extends Batch { } // Good Tickets no longer needed goodTickets.clear(); - + /** * Decide to Notify about Approvals, based on activity/last Notified */ @@ -328,11 +328,11 @@ public class Analyze extends Batch { GregorianCalendar gc = new GregorianCalendar(); gc.add(GregorianCalendar.DAY_OF_WEEK, 5); Date remind = gc.getTime(); - + for(Entry es : pendingApprs.entrySet()) { Pending p = es.getValue(); - if(p.newApprovals() - || p.earliest() == LastNotified.NEVER // yes, equals. + if(p.newApprovals() + || p.earliest() == LastNotified.NEVER // yes, equals. || p.earliest().after(remind)) { p.row(needApproveCW,es.getKey()); } @@ -340,22 +340,22 @@ public class Analyze extends Batch { } finally { tt.done(); } - + // clear out Approval Intermediates pendingTemp = null; pendingApprs = null; } finally { } - + /** - Run through User Roles. + Run through User Roles. Owners are treated specially in next section. Regular roles are checked against Date Ranges. If match Date Range, write out to appropriate file. - */ - + */ + try { Role.load(trans, session); - + try { tt = trans.start("Analyze UserRoles, storing Owners",Trans.SUB); Set specialCommented = new HashSet<>(); @@ -391,7 +391,7 @@ public class Analyze extends Batch { return; } // Just let expired UserRoles sit until deleted - if(futureRange.inRange(ur.expires())&&(!mur.containsKey(ur.user() + '|' + ur.role()))) { + if(futureRange.inRange(ur.expires())&&(!mur.containsKey(ur.user() + '|' + ur.role()))) { // Cannot just delete owners, unless there is at least one left. Process later if ("owner".equals(ur.rname())) { Set urs = owners.get(ur.role()); @@ -418,11 +418,11 @@ public class Analyze extends Batch { tt.done(); } mur.clear(); - + /** Now Process Owners, one owner Role at a time, ensuring one is left, - preferably a good one. If so, process the others as normal. - + preferably a good one. If so, process the others as normal. + Otherwise, write to ExpiredOwners Report */ tt = trans.start("Analyze Owners Separately",Trans.SUB); @@ -432,7 +432,7 @@ public class Analyze extends Batch { final CSV ownerCSV = new CSV(env.access(),file); CSV.Writer expOwner = ownerCSV.writer(); expOwner.row(INFO,EXPIRED_OWNERS,sdate,2); - + try { for (Set sur : owners.values()) { int goodOwners = 0; @@ -441,7 +441,7 @@ public class Analyze extends Batch { ++goodOwners; } } - + for (UserRole ur : sur) { if (goodOwners >= minOwners) { Range r = writeAnalysis(noAvg, ur); @@ -473,14 +473,14 @@ public class Analyze extends Batch { Role.clear(); UserRole.clear(); } - + /** * Check for Expired Credentials */ try { // Load Cred. We don't follow Visitor, because we have to gather up everything into Identity Anyway Cred.load(trans, session); - + tt = trans.start("Analyze Expired Credentials",Trans.SUB); try { for (Cred cred : Cred.data.values()) { @@ -509,7 +509,7 @@ public class Analyze extends Batch { } finally { Cred.clear(); } - + //////////////////// tt = trans.start("Analyze Expired X509s",Trans.SUB); try { @@ -529,7 +529,7 @@ public class Analyze extends Batch { noAvg.info().log(e); } } - + private Approval findApproval(UserRole ur) { Approval existing = null; List apprs = Approval.byUser.get(ur.user()); @@ -537,7 +537,7 @@ public class Analyze extends Batch { for(Approval appr : apprs) { if(ur.role().equals(appr.getRole()) && appr.getMemo().contains(Chrono.dateOnlyStamp(ur.expires()))) { - existing = appr; + existing = appr; } } } @@ -555,7 +555,7 @@ public class Analyze extends Batch { } catch (OrganizationException e) { i=null; } - if(r.needsContact(lnd,i)) { + if(r.needsContact(lnd,i)) { CSV.Writer cw = writerList.get(r.name()); if(cw!=null) { ur.row(cw,UserRole.UR); @@ -564,7 +564,7 @@ public class Analyze extends Batch { } return r; } - + private void writeAnalysis(AuthzTrans noAvg, Cred cred, Instance inst) { if(cred!=null && inst!=null) { Range r = expireRange.getRange("cred", inst.expires); @@ -577,7 +577,7 @@ public class Analyze extends Batch { } catch (OrganizationException e) { i=null; } - if(r.needsContact(lnd,i)) { + if(r.needsContact(lnd,i)) { CSV.Writer cw = writerList.get(r.name()); if(cw!=null) { cred.row(cw,inst); @@ -606,7 +606,7 @@ public class Analyze extends Batch { } } } - + @Override protected void _close(AuthzTrans trans) { session.close(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/ApprovedRpt.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/ApprovedRpt.java index 880173b9..a6c49f08 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/ApprovedRpt.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/ApprovedRpt.java @@ -8,9 +8,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. @@ -49,18 +49,18 @@ import com.datastax.driver.core.Statement; public class ApprovedRpt extends Batch { - + private static final String APPR_RPT = "ApprovedRpt"; private static final String CSV = ".csv"; private Date now; private Writer approvedW; private CSV historyR; private static String yr_mon; - + public ApprovedRpt(AuthzTrans trans) throws APIException, IOException, OrganizationException { super(trans.env()); trans.info().log("Starting Connection Process"); - + TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB); try { // TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); @@ -69,15 +69,15 @@ public class ApprovedRpt extends Batch { // } finally { // tt.done(); // } - + now = new Date(); String sdate = Chrono.dateOnlyStamp(now); File file = new File(logDir(),APPR_RPT + sdate +CSV); CSV csv = new CSV(env.access(),file); approvedW = csv.writer(false); - + historyR = new CSV(env.access(),args()[1]).setDelimiter('|'); - + yr_mon = args()[0]; } finally { tt0.done(); @@ -86,7 +86,7 @@ public class ApprovedRpt extends Batch { @Override protected void run(AuthzTrans trans) { - try { + try { // ResultSet results; // Statement stmt = new SimpleStatement( "select dateof(id), approver, status, user, type, memo from authz.approved;" ); // results = session.execute(stmt); @@ -132,15 +132,15 @@ public class ApprovedRpt extends Batch { } } }); - + } catch (Exception e) { trans.info().log(e); } } - + private void write(String a_or_d, List row) { String[] target = Split.splitTrim('|', row.get(4)); - + if(target.length>1) { UUID id = UUID.fromString(row.get(0)); Date date = Chrono.uuidToDate(id); @@ -166,7 +166,7 @@ public class ApprovedRpt extends Batch { } } - + } } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java index bd56fc2e..82542e15 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java @@ -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. @@ -45,20 +45,20 @@ import org.onap.aaf.misc.env.util.Chrono; public class NotInOrg extends Batch { - + private static final String NOT_IN_ORG = "NotInOrg"; private static final String CSV = ".csv"; private static final String INFO = "info"; private Map writerList; - private Map whichWriter; + private Map whichWriter; private Date now; private Writer notInOrgW; private Writer notInOrgDeleteW; - + public NotInOrg(AuthzTrans trans) throws APIException, IOException, OrganizationException { super(trans.env()); trans.info().log("Starting Connection Process"); - + TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB); try { TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); @@ -67,11 +67,11 @@ public class NotInOrg extends Batch { } finally { tt.done(); } - + // Load Cred. We don't follow Visitor, because we have to gather up everything into Identity Anyway Cred.load(trans, session); - // Create Intermediate Output + // Create Intermediate Output writerList = new HashMap<>(); whichWriter = new TreeMap<>(); @@ -82,7 +82,7 @@ public class NotInOrg extends Batch { notInOrgW = csv.writer(false); notInOrgW.row(INFO,NOT_IN_ORG,Chrono.dateOnlyStamp(now),0); writerList.put(NOT_IN_ORG,notInOrgW); - + // These will have been double-checked by the Organization, and can be deleted immediately. String fn = NOT_IN_ORG+"Delete"; file = new File(logDir(),fn + sdate +CSV); @@ -90,7 +90,7 @@ public class NotInOrg extends Batch { notInOrgDeleteW = csvDelete.writer(false); notInOrgDeleteW.row(INFO,fn,Chrono.dateOnlyStamp(now),0); writerList.put(NOT_IN_ORG,notInOrgW); - + } finally { tt0.done(); } @@ -102,7 +102,7 @@ public class NotInOrg extends Batch { Map checked = new TreeMap(); trans.info().log("Process Organization Identities"); trans.info().log("User Roles"); - + final AuthzTrans transNoAvg = trans.env().newTransNoAvg(); UserRole.load(trans, session, UserRole.v2_0_11, ur -> { try { @@ -113,9 +113,9 @@ public class NotInOrg extends Batch { trans.error().log(e, "Error Decrypting X509"); } }); - + trans.info().log("Checking for Creds without IDs"); - + for (Cred cred : Cred.data.values()) { if(!check(transNoAvg,checked, cred.id)) { CSV.Writer cw = whichWriter(transNoAvg, cred.id); @@ -124,13 +124,13 @@ public class NotInOrg extends Batch { } } } - + } catch (OrganizationException e) { trans.info().log(e); } } - - + + private Writer whichWriter(AuthzTrans transNoAvg, String id) { Writer w = whichWriter.get(id); if(w==null) { @@ -146,7 +146,7 @@ public class NotInOrg extends Batch { Boolean rv = checked.get(id); if(rv==null) { if(isSpecial(id)) { // do not check against org... too important to delete. - return true; + return true; } Organization org = trans.org(); if(org != null) { @@ -160,7 +160,7 @@ public class NotInOrg extends Batch { return rv; } - + @Override protected void _close(AuthzTrans trans) { session.close(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java index 54cb7378..981f300d 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java @@ -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. @@ -134,7 +134,7 @@ import org.onap.aaf.misc.env.util.Chrono; } urgent = false; - + sb.setLength(0); fhh = new File(footer_html); if(!fhh.exists()) { @@ -153,14 +153,14 @@ import org.onap.aaf.misc.env.util.Chrono; } noAvg = trans.env().newTransNoAvg(); - cqlBatch = new CQLBatch(noAvg.debug(),session); + cqlBatch = new CQLBatch(noAvg.debug(),session); cbl = new CQLBatchLoop(cqlBatch,50,dryRun); - + lastN = new LastNotified(session); } /* - * Note: We try to put things related to Notify as Main Class in Run, where we might have put in + * Note: We try to put things related to Notify as Main Class in Run, where we might have put in * Constructor, so that we can have other Classes call just the "notify" method. */ @Override @@ -175,7 +175,7 @@ import org.onap.aaf.misc.env.util.Chrono; NotifyBody.load(env.access()); - // Create Intermediate Output + // Create Intermediate Output File logDir = logDir(); Set notifyFile = new HashSet<>(); if(args().length>0) { @@ -219,14 +219,14 @@ import org.onap.aaf.misc.env.util.Chrono; e.printStackTrace(); } - } + } // now create Notification for(NotifyBody nb : NotifyBody.getAll()) { int count = notify(noAvg, nb); trans.info().printf("Emailed %d for %s",count,nb.name()); } - + // // Do Pending Approval Notifies. We do this separately, because we are consolidating // all the new entries, etc. @@ -238,7 +238,7 @@ import org.onap.aaf.misc.env.util.Chrono; csvList.add(new CSV(access,f)); } } - + Map mpending = new TreeMap<>(); Holder count = new Holder<>(0); for(CSV approveCSV : csvList) { @@ -261,7 +261,7 @@ import org.onap.aaf.misc.env.util.Chrono; count.set(count.get()+1); } catch (ParseException e) { trans.error().log(e); - } + } break; } }); @@ -272,23 +272,23 @@ import org.onap.aaf.misc.env.util.Chrono; } } trans.info().printf("Read %d Reminder Rows", count.get()); - + NotifyPendingApprBody npab = new NotifyPendingApprBody(access); GregorianCalendar gc = new GregorianCalendar(); gc.add(GregorianCalendar.DAY_OF_MONTH, 7); // Get from INFO? Date oneWeek = gc.getTime(); CSV.Saver rs = new CSV.Saver(); - + TimeTaken tt = trans.start("Obtain Last Notifications for Approvers", Trans.SUB); try { lastN.add(mpending.keySet()); } finally { tt.done(); } - + Pending p; - + tt = trans.start("Notify for Pending", Trans.SUB); List idList = new ArrayList<>(); String id; @@ -336,7 +336,7 @@ import org.onap.aaf.misc.env.util.Chrono; String run = nb.type()+nb.name(); String test = dryRun?run:null; - + ONE_EMAIL: for(String id : nb.users()) { toList.clear(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/PrepExtend.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/PrepExtend.java index bcdd4401..072363f0 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/PrepExtend.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/PrepExtend.java @@ -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. @@ -51,9 +51,9 @@ public class PrepExtend extends Batch { /** * Create a list of Creds and UserRoles to extend * Note: Certificates cannot be renewed in this way. - * + * * Arguments From (0 = today, -2 = 2 weeks back) and To (weeks from today) - * + * * @param trans * @throws APIException * @throws IOException @@ -80,15 +80,15 @@ public class PrepExtend extends Batch { protected void run(AuthzTrans trans) { GregorianCalendar gc = new GregorianCalendar(); Date now = gc.getTime(); - + int ifrom = 0; int ito = 4; - + for(int i=0; i< args().length;++i) { switch(args()[i]) { case "-from": if(args().length>i+1) { - ifrom = Integer.parseInt(args()[i++ +1]); + ifrom = Integer.parseInt(args()[i++ +1]); } break; case "-to": @@ -102,23 +102,23 @@ public class PrepExtend extends Batch { System.err.println("Invalid -from param"); return; } - + if(ito<=0 || ito>24 || ifrom>ito) { System.err.println("Invalid -to param"); return; } - + // Make sure to is Zero based from today. if(ifrom<0) { ito+= ifrom*-1; } - + gc.add(GregorianCalendar.WEEK_OF_MONTH, ifrom); Date from = gc.getTime(); - + gc.add(GregorianCalendar.WEEK_OF_MONTH, ito /* with From calculated in */); Date to = gc.getTime(); - + try { File file = new File(logDir(), PREP_EXTEND + Chrono.dateOnlyStamp(now) + CSV); final CSV puntCSV = new CSV(env.access(),file); @@ -128,7 +128,7 @@ public class PrepExtend extends Batch { try { trans.info().log("Process UserRoles for Extending"); /** - Run through User Roles. + Run through User Roles. If match Date Range, write out to appropriate file. */ UserRole.load(trans, session, UserRole.v2_0_11, ur -> { @@ -136,7 +136,7 @@ public class PrepExtend extends Batch { ur.row(cw,UserRole.UR); } }); - + trans.info().log("Process BasicAuth for Extending"); TimeTaken tt0 = trans.start("Load Credentials", Env.REMOTE); try { @@ -148,7 +148,7 @@ public class PrepExtend extends Batch { /** - Run through Creds. + Run through Creds. If match Date Range, write out to appropriate file. */ Map imap = new HashMap<>(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java index 6c95f02e..04814e01 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java @@ -8,9 +8,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. @@ -53,13 +53,13 @@ public abstract class NotifyBody { protected Map>> rows; protected final String env; protected final String gui_url; - + private final String name; private final String type; private String date; private int escalation; private int count; - + public NotifyBody(Access access, final String type, final String name) { rows = new TreeMap<>(); this.name = name; @@ -70,7 +70,7 @@ public abstract class NotifyBody { env = access.getProperty("CASS_ENV","DEVL"); gui_url = access.getProperty("GUI_URL", ""); } - + public void store(List row) { if(!row.isEmpty()) { if("info".equals(row.get(0))) { @@ -84,7 +84,7 @@ public abstract class NotifyBody { } else if(type.equals(row.get(0))) { String user = user(row); if(user!=null) { - List> lss = rows.get(user); + List> lss = rows.get(user); if(lss == null) { lss = new ArrayList<>(); rows.put(user,lss); @@ -98,25 +98,25 @@ public abstract class NotifyBody { public String name() { return name; } - + public String type() { return type; } - + public String date() { return date; } public int escalation() { return escalation; } - + public Set users() { return rows.keySet(); } - + /** * ID must be set from Row for Email lookup - * + * * @param trans * @param n * @param id @@ -124,30 +124,30 @@ public abstract class NotifyBody { * @return */ public abstract boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id); - + /** * Return "null" if user not found in row... Code will handle. * @param row * @return */ protected abstract String user(List row); - + /** * Provide a context-sensitive Subject, which includes ENV as well as details - * + * * @return */ public abstract String subject(); /** * Record the fact that a particular Notification was marked as "sent" by Emailer. - * + * * @param trans * @param approver * @param ln */ public abstract void record(AuthzTrans trans, StringBuilder query, String id, List notified, LastNotified ln); - + /** * Get Notify Body based on key of * type|name @@ -155,10 +155,10 @@ public abstract class NotifyBody { public static NotifyBody get(String key) { return bodyMap.get(key); } - + /** * Return set of loaded NotifyBodies - * + * */ public static Collection getAll() { // Note: The same Notify Body is entered several times with different keys. @@ -167,11 +167,11 @@ public abstract class NotifyBody { set.addAll(bodyMap.values()); return set; } - + /** - * @param propAccess - * @throws URISyntaxException - * + * @param propAccess + * @throws URISyntaxException + * */ public static void load(Access access) throws APIException, IOException { // class load available NotifyBodies @@ -199,7 +199,7 @@ public abstract class NotifyBody { File dir = new File(url.getFile()); for( String f : dir.list()) { if(f.endsWith(".class")) { - classNames.add(pkg.getName()+'.'+f.substring(0,f.length()-6)); + classNames.add(pkg.getName() + '.' + f.substring(0,f.length() - 6)); } } } @@ -210,8 +210,8 @@ public abstract class NotifyBody { Constructor cst = c.getConstructor(Access.class); NotifyBody nb = (NotifyBody)cst.newInstance(access); if(nb!=null) { - bodyMap.put("info|"+nb.name, nb); - bodyMap.put(nb.type+'|'+nb.name, nb); + bodyMap.put("info|" + nb.name, nb); + bodyMap.put(nb.type+'|' + nb.name, nb); } } } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { @@ -221,14 +221,14 @@ public abstract class NotifyBody { } protected void print(StringBuilder sb, int indent, Object ... objs) { - for(int i=0;i",current,""); } - + public synchronized void inc() { ++count; } - + public int count() { return count; } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyCredBody.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyCredBody.java index 67013a9a..1ef83441 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyCredBody.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyCredBody.java @@ -9,9 +9,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. @@ -35,16 +35,16 @@ public abstract class NotifyCredBody extends NotifyBody { private final String explanation; private final String instruction; - + public NotifyCredBody(Access access, String name) { super(access,"cred",name); - + // Default explanation = "The following Credentials that you are responsible for " + "are expiring on the dates shown.

" ; - - instruction = "

Instructions for 'Password':