Fix sonar issues in Mapper1_0 81/48481/1
authorburdziak <olaf.burdziakowski@nokia.com>
Tue, 22 May 2018 11:54:27 +0000 (13:54 +0200)
committerburdziak <olaf.burdziakowski@nokia.com>
Tue, 22 May 2018 11:54:27 +0000 (13:54 +0200)
Change-Id: I15746954d91610cbcd517d56fa25b98535a76e0e
Issue-ID: AAF-313
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/mapper/Mapper1_0.java

index 3d865d3..16517c9 100644 (file)
@@ -97,50 +97,51 @@ public class Mapper1_0 implements Mapper<BaseRequest,CertInfo,Artifacts,Error> {
         */
        @Override
        public Result<CertInfo> toCert(AuthzTrans trans, Result<CertResp> in, boolean withTrustChain) throws IOException {
-               if(in.isOK()) {
-                       CertResp cin = in.value;
-                       CertInfo cout = newInstance(API.CERT);
-                       cout.setPrivatekey(cin.privateString());
-                       String value;
-                       if((value=cin.challenge())!=null) {
-                               cout.setChallenge(value);
-                       }
-                       cout.getCerts().add(cin.asCertString());
-                       if(cin.trustChain()!=null) {
-                               for(String c : cin.trustChain()) {
-                                       if(c!=null) {
-                                               cout.getCerts().add(c);
-                                       }
+               if(!in.isOK()) {
+                       return Result.err(in);
+               }
+
+               CertResp cin = in.value;
+               CertInfo cout = newInstance(API.CERT);
+               cout.setPrivatekey(cin.privateString());
+               String value;
+               if((value=cin.challenge())!=null) {
+                       cout.setChallenge(value);
+               }
+               cout.getCerts().add(cin.asCertString());
+               if(cin.trustChain()!=null) {
+                       for(String c : cin.trustChain()) {
+                               if(c!=null) {
+                                       cout.getCerts().add(c);
                                }
                        }
-                       // Adding all the Certs in one response is a mistake.  Makes it very hard for Agent to setup 
-                       // Certs in keystore versus Truststore.  Separate in Version 2_0
-                       if(cin.trustCAs()!=null) {
-                               for(String c : cin.trustCAs()) {
-                                       if(c!=null) {
-                                               cout.getCerts().add(c);
-                                       } 
+               }
+               // Adding all the Certs in one response is a mistake.  Makes it very hard for Agent to setup
+               // Certs in keystore versus Truststore.  Separate in Version 2_0
+               if(cin.trustCAs()!=null) {
+                       for(String c : cin.trustCAs()) {
+                               if(c!=null) {
+                                       cout.getCerts().add(c);
                                }
                        }
-                       if(cin.notes()!=null) {
-                               boolean first = true;
-                               StringBuilder sb = new StringBuilder();
-                               for(String n : cin.notes()) {
-                                       if(first) {
-                                               first = false;
-                                       } else {
-                                               sb.append('\n');
-                                       }
-                                       sb.append(n);
+               }
+               if(cin.notes()!=null) {
+                       boolean first = true;
+                       StringBuilder sb = new StringBuilder();
+                       for(String n : cin.notes()) {
+                               if(first) {
+                                       first = false;
+                               } else {
+                                       sb.append('\n');
                                }
-                               cout.setNotes(sb.toString());
+                               sb.append(n);
                        }
-                       cout.getCaIssuerDNs().addAll(cin.caIssuerDNs());
-                       cout.setEnv(cin.env());
-                       return Result.ok(cout);
-               } else {
-                       return Result.err(in);
+                       cout.setNotes(sb.toString());
                }
+               cout.getCaIssuerDNs().addAll(cin.caIssuerDNs());
+               cout.setEnv(cin.env());
+               return Result.ok(cout);
+
        }
 
        @Override
@@ -171,9 +172,10 @@ public class Mapper1_0 implements Mapper<BaseRequest,CertInfo,Artifacts,Error> {
 
                CertReq out = new CertReq();
                CertmanValidator v = new CertmanValidator();
-               v.isNull("CertRequest", req)
-                       .nullOrBlank("MechID", out.mechid=in.getMechid());
-               v.nullBlankMin("FQDNs", out.fqdns=in.getFqdns(),1);
+               out.mechid=in.getMechid();
+               out.fqdns=in.getFqdns();
+               v.isNull("CertRequest", req).nullOrBlank("MechID", out.mechid);
+               v.nullBlankMin("FQDNs", out.fqdns,1);
                if(v.err()) {
                        return Result.err(Result.ERR_BadData, v.errs());
                }
@@ -206,7 +208,7 @@ public class Mapper1_0 implements Mapper<BaseRequest,CertInfo,Artifacts,Error> {
         */
        @Override
        public List<ArtiDAO.Data> toArtifact(AuthzTrans trans, Artifacts artifacts) {
-               List<ArtiDAO.Data> ladd = new ArrayList<ArtiDAO.Data>();
+               List<ArtiDAO.Data> ladd = new ArrayList<>();
                for(Artifact arti : artifacts.getArtifact()) {
                        ArtiDAO.Data data = new ArtiDAO.Data();
                        data.mechid = arti.getMechid();
@@ -226,10 +228,8 @@ public class Mapper1_0 implements Mapper<BaseRequest,CertInfo,Artifacts,Error> {
                        
                        // Derive Optional Data from Machine (Domain) if exists
                        if(data.machine!=null) {
-                               if(data.ca==null) {
-                                       if(data.machine.endsWith(".att.com")) {
+                               if(data.ca==null && data.machine.endsWith(".att.com")) {
                                                data.ca = "aaf"; // default
-                                       }
                                }
                                if(data.ns==null ) {
                                        data.ns=FQI.reverseDomain(data.machine);