tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
public ResponseEntity<String> onboardSingleCert(UserDetails userDetails,  String token, String certType, 
			    									String commonname,  String appName) throws Exception {
			    	
			    	SSLCertificateRequest sslCertificateRequest = new SSLCertificateRequest();
			    	ResponseEntity<String> response;
			    	JsonObject jsonObject = new JsonObject();;
			    	jsonObject.addProperty(SSLCertificateConstants.COMMON_NAME,commonname);
			    	jsonObject.addProperty(SSLCertificateConstants.CERT_TYPE,certType);
			    	
			    	if (!isValidInputs(commonname, certType)) {
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE, SSLCertificateConstants.INVALID_INPUT_MSG)
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
						return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ERRORINVALID);
					}

                    // External certificate disabled check
                    if (certType.equalsIgnoreCase(SSLCertificateConstants.EXTERNAL) && !isExternalCertEnabled){
                        log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
                                .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
                                .put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
                                .put(LogMessage.MESSAGE,
                                        "Failed to onboard external SSL certificate. Operation not allowed.")
                                .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
                        return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(
                                "{\"errors\":[\"Failed to onboard external SSL certificate. Operation not allowed.\"]}");
                    }
			    	
			    	if(isCertAvailableInMetadata(jsonObject, token)) {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE, "Certificate already available in metadata.")
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
						return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Certificate already available in tvault\"]}");
			    	}
			    	
			    	int containerId=0;
			    	List<Integer> containerList = new ArrayList<>();
			    	sslCertificateRequest.setCertificateName(commonname);
			    	sslCertificateRequest.setCertType(certType);
			    	sslCertificateRequest.setAppName(appName);

			    	if(certType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL)) {
			    		containerList.add(private_single_san_ts_gp_id_test!=0?private_single_san_ts_gp_id_test:private_single_san_ts_gp_id);
			    	}
			    	
			    	else {
			    		CertificateData certDetailsExtSsan = null;
			    		CertificateData certDetailsExtMsan = null;
				        String nclmAccessToken = getNclmToken();
				        int containerIdExtSsan=public_single_san_ts_gp_id_test!=0?public_single_san_ts_gp_id_test:public_single_san_ts_gp_id;
				        int containerIdExtMsan=public_multi_san_ts_gp_id_test!=0?public_multi_san_ts_gp_id_test:public_multi_san_ts_gp_id;
						certDetailsExtSsan = getLatestCertificateFromNCLM(commonname, nclmAccessToken,
								containerIdExtSsan);
						if (certDetailsExtSsan != null && (!ObjectUtils.isEmpty(certDetailsExtSsan))
								&& (!ObjectUtils.isEmpty(certDetailsExtSsan.getCertificateName()))) {
							containerList.add(containerIdExtSsan);
						}
						certDetailsExtMsan = getLatestCertificateFromNCLM(commonname, nclmAccessToken,
								containerIdExtMsan);
						if (certDetailsExtMsan != null && (!ObjectUtils.isEmpty(certDetailsExtMsan))
								&& (!ObjectUtils.isEmpty(certDetailsExtMsan.getCertificateName()))) {
							containerList.add(containerIdExtMsan);
						}
			    		
			    	}
			    	if(containerList.size() >0) {
			    		for(int i=0; i<containerList.size();i++) {
			    	response = onboardCertificate(sslCertificateRequest,userDetails,containerList.get(i),"");
			    	
			    	if (response !=null && !HttpStatus.OK.equals(response.getStatusCode())) {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER,ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE,String.format(
												"Onboarding failed for certificate name [%s]", commonname ))
								.build()));
			    		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Certificate onboard failed\"]}");
			    	}
			    	
			    	else {
			    		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
			                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
			                    put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE).
			                    put(LogMessage.MESSAGE, String.format("Onbaording successful for certificate name [%s]", commonname )).
			                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
			                    build()));
			    	}
			    		}
			    	}else {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER,ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "onboardSingleCert")
								.put(LogMessage.MESSAGE,String.format(
												"Onboarding failed for certificate name [%s]. Certificate not available in NCLM.", commonname ))
								.build()));
			    		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Certificate onboard failed\"]}");
			    	}
			    	return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"ssl certificate onboard successfully\"]}");
			    }
/**
			     * API to onboard single certificate to tvault
			     * @param userDetails
			     * @param bearerToken
			     * @return
			     * @throws Exception 
			     */
API to onboard single certificate to tvault
@param userDetails
@param bearerToken
@return
@throws Exception
API to onboard single certificate to tvault @param userDetails @param bearerToken @return @throws Exception
public ResponseEntity<String> onboardSingleCert(UserDetails userDetails,  String token, String certType, 
			    									String commonname,  String appName) throws Exception {
			    	SSLCertificateRequest sslCertificateRequest = new SSLCertificateRequest();
			    	ResponseEntity<String> response;
			    	JsonObject jsonObject = new JsonObject();;
			    	jsonObject.addProperty(SSLCertificateConstants.COMMON_NAME,commonname);
			    	jsonObject.addProperty(SSLCertificateConstants.CERT_TYPE,certType);
			    	if (!isValidInputs(commonname, certType)) {
						log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE, SSLCertificateConstants.INVALID_INPUT_MSG)
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
						return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ERRORINVALID);
					}
                    if (certType.equalsIgnoreCase(SSLCertificateConstants.EXTERNAL) && !isExternalCertEnabled){
                        log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
                                .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
                                .put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
                                .put(LogMessage.MESSAGE,
                                        "Failed to onboard external SSL certificate. Operation not allowed.")
                                .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
                        return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(
                                "{\"errors\":[\"Failed to onboard external SSL certificate. Operation not allowed.\"]}");
                    }
			    	if(isCertAvailableInMetadata(jsonObject, token)) {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder()
								.put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE, "Certificate already available in metadata.")
								.put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build()));
						return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Certificate already available in tvault\"]}");
			    	}
			    	int containerId=0;
			    	List<Integer> containerList = new ArrayList<>();
			    	sslCertificateRequest.setCertificateName(commonname);
			    	sslCertificateRequest.setCertType(certType);
			    	sslCertificateRequest.setAppName(appName);
			    	if(certType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL)) {
			    		containerList.add(private_single_san_ts_gp_id_test!=0?private_single_san_ts_gp_id_test:private_single_san_ts_gp_id);
			    	}
			    	else {
			    		CertificateData certDetailsExtSsan = null;
			    		CertificateData certDetailsExtMsan = null;
				        String nclmAccessToken = getNclmToken();
				        int containerIdExtSsan=public_single_san_ts_gp_id_test!=0?public_single_san_ts_gp_id_test:public_single_san_ts_gp_id;
				        int containerIdExtMsan=public_multi_san_ts_gp_id_test!=0?public_multi_san_ts_gp_id_test:public_multi_san_ts_gp_id;
						certDetailsExtSsan = getLatestCertificateFromNCLM(commonname, nclmAccessToken,
								containerIdExtSsan);
						if (certDetailsExtSsan != null && (!ObjectUtils.isEmpty(certDetailsExtSsan))
								&& (!ObjectUtils.isEmpty(certDetailsExtSsan.getCertificateName()))) {
							containerList.add(containerIdExtSsan);
						}
						certDetailsExtMsan = getLatestCertificateFromNCLM(commonname, nclmAccessToken,
								containerIdExtMsan);
						if (certDetailsExtMsan != null && (!ObjectUtils.isEmpty(certDetailsExtMsan))
								&& (!ObjectUtils.isEmpty(certDetailsExtMsan.getCertificateName()))) {
							containerList.add(containerIdExtMsan);
						}
			    	}
			    	if(containerList.size() >0) {
			    		for(int i=0; i<containerList.size();i++) {
			    	response = onboardCertificate(sslCertificateRequest,userDetails,containerList.get(i),"");
			    	if (response !=null && !HttpStatus.OK.equals(response.getStatusCode())) {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER,ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE)
								.put(LogMessage.MESSAGE,String.format(
												"Onboarding failed for certificate name [%s]", commonname ))
								.build()));
			    		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Certificate onboard failed\"]}");
			    	}
			    	else {
			    		log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
			                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
			                    put(LogMessage.ACTION, SSLCertificateConstants.ONBOARD_SSL_CERTIFICATE).
			                    put(LogMessage.MESSAGE, String.format("Onbaording successful for certificate name [%s]", commonname )).
			                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
			                    build()));
			    	}
			    		}
			    	}else {
			    		log.error(JSONUtil.getJSON(ImmutableMap.<String, String> builder()
								.put(LogMessage.USER,ThreadLocalContext.getCurrentMap().get(LogMessage.USER))
								.put(LogMessage.ACTION, "onboardSingleCert")
								.put(LogMessage.MESSAGE,String.format(
												"Onboarding failed for certificate name [%s]. Certificate not available in NCLM.", commonname ))
								.build()));
			    		return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Certificate onboard failed\"]}");
			    	}
			    	return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"ssl certificate onboard successfully\"]}");
			    }
public ResponseEntity < String > onboardSingleCert ( UserDetails userDetails , String token , String certType , String commonname , String appName ) throws Exception { SSLCertificateRequest sslCertificateRequest = new SSLCertificateRequest ( ) ; ResponseEntity < String > response ; JsonObject jsonObject = new JsonObject ( ) ; ; jsonObject . addProperty ( SSLCertificateConstants . COMMON_NAME , commonname ) ; jsonObject . addProperty ( SSLCertificateConstants . CERT_TYPE , certType ) ; if ( ! isValidInputs ( commonname , certType ) ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , SSLCertificateConstants . INVALID_INPUT_MSG ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( ERRORINVALID ) ; } if ( certType . equalsIgnoreCase ( SSLCertificateConstants . EXTERNAL ) && ! isExternalCertEnabled ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , "Failed to onboard external SSL certificate. Operation not allowed." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . UNPROCESSABLE_ENTITY ) . body ( "{\"errors\":[\"Failed to onboard external SSL certificate. Operation not allowed.\"]}" ) ; } if ( isCertAvailableInMetadata ( jsonObject , token ) ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , "Certificate already available in metadata." ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . body ( "{\"errors\":[\"Certificate already available in tvault\"]}" ) ; } int containerId = 0 ; List < Integer > containerList = new ArrayList < > ( ) ; sslCertificateRequest . setCertificateName ( commonname ) ; sslCertificateRequest . setCertType ( certType ) ; sslCertificateRequest . setAppName ( appName ) ; if ( certType . equalsIgnoreCase ( SSLCertificateConstants . INTERNAL ) ) { containerList . add ( private_single_san_ts_gp_id_test != 0 ? private_single_san_ts_gp_id_test : private_single_san_ts_gp_id ) ; } else { CertificateData certDetailsExtSsan = null ; CertificateData certDetailsExtMsan = null ; String nclmAccessToken = getNclmToken ( ) ; int containerIdExtSsan = public_single_san_ts_gp_id_test != 0 ? public_single_san_ts_gp_id_test : public_single_san_ts_gp_id ; int containerIdExtMsan = public_multi_san_ts_gp_id_test != 0 ? public_multi_san_ts_gp_id_test : public_multi_san_ts_gp_id ; certDetailsExtSsan = getLatestCertificateFromNCLM ( commonname , nclmAccessToken , containerIdExtSsan ) ; if ( certDetailsExtSsan != null && ( ! ObjectUtils . isEmpty ( certDetailsExtSsan ) ) && ( ! ObjectUtils . isEmpty ( certDetailsExtSsan . getCertificateName ( ) ) ) ) { containerList . add ( containerIdExtSsan ) ; } certDetailsExtMsan = getLatestCertificateFromNCLM ( commonname , nclmAccessToken , containerIdExtMsan ) ; if ( certDetailsExtMsan != null && ( ! ObjectUtils . isEmpty ( certDetailsExtMsan ) ) && ( ! ObjectUtils . isEmpty ( certDetailsExtMsan . getCertificateName ( ) ) ) ) { containerList . add ( containerIdExtMsan ) ; } } if ( containerList . size ( ) > 0 ) { for ( int i = 0 ; i < containerList . size ( ) ; i ++ ) { response = onboardCertificate ( sslCertificateRequest , userDetails , containerList . get ( i ) , "" ) ; if ( response != null && ! HttpStatus . OK . equals ( response . getStatusCode ( ) ) ) { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , String . format ( "Onboarding failed for certificate name [%s]" , commonname ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( "{\"errors\":[\"Certificate onboard failed\"]}" ) ; } else { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , SSLCertificateConstants . ONBOARD_SSL_CERTIFICATE ) . put ( LogMessage . MESSAGE , String . format ( "Onbaording successful for certificate name [%s]" , commonname ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; } } } else { log . error ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "onboardSingleCert" ) . put ( LogMessage . MESSAGE , String . format ( "Onboarding failed for certificate name [%s]. Certificate not available in NCLM." , commonname ) ) . build ( ) ) ) ; return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( "{\"errors\":[\"Certificate onboard failed\"]}" ) ; } return ResponseEntity . status ( HttpStatus . OK ) . body ( "{\"messages\":[\"ssl certificate onboard successfully\"]}" ) ; }
API to onboard single certificate to tvault
 @param userDetails
 @param bearerToken
 @return
 @throws Exception
API to onboard single certificate to tvault @param userDetails @param bearerToken @return @throws Exception
// External certificate disabled check