diff --git a/src/main/java/io/aiven/klaw/auth/KwAuthenticationService.java b/src/main/java/io/aiven/klaw/auth/KwAuthenticationService.java index 0c464162a6..00b633b937 100644 --- a/src/main/java/io/aiven/klaw/auth/KwAuthenticationService.java +++ b/src/main/java/io/aiven/klaw/auth/KwAuthenticationService.java @@ -177,16 +177,18 @@ Authentication searchUserAttributes(HttpServletRequest request, HttpServletRespo // User found in AD and not in KW db - if (userAttributesObject.get("userFound").equals(Boolean.TRUE)) { + if (Boolean.TRUE.equals(userAttributesObject.get("userFound"))) { try { log.info("User found in AD and not in Klaw db :{}", userName); String existingRegistrationId = manageDatabase.getHandleDbRequests().getRegistrationId(userName); if (existingRegistrationId != null) { - if (existingRegistrationId.equals("PENDING_ACTIVATION")) + if ("PENDING_ACTIVATION".equals(existingRegistrationId)) { response.sendRedirect("registrationReview"); - else response.sendRedirect("register?userRegistrationId=" + existingRegistrationId); + } else { + response.sendRedirect("register?userRegistrationId=" + existingRegistrationId); + } } else { String randomId = UUID.randomUUID().toString(); @@ -198,11 +200,12 @@ Authentication searchUserAttributes(HttpServletRequest request, HttpServletRespo registerUserInfoModel.setPwd(""); Attributes attributes = (Attributes) userAttributesObject.get("attributes"); - if (attributes.get("mail") != null) + if (attributes.get("mail") != null) { registerUserInfoModel.setMailid((String) attributes.get("mail").get()); - if (attributes.get("displayname") != null) + } + if (attributes.get("displayname") != null) { registerUserInfoModel.setFullname((String) attributes.get("displayname").get()); - + } RegisterUserInfo registerUserInfo = new RegisterUserInfo(); copyProperties(registerUserInfoModel, registerUserInfo); manageDatabase.getHandleDbRequests().registerUserForAD(registerUserInfo); diff --git a/src/main/java/io/aiven/klaw/auth/KwRequestFilter.java b/src/main/java/io/aiven/klaw/auth/KwRequestFilter.java index 69938e881c..2cdbef3758 100644 --- a/src/main/java/io/aiven/klaw/auth/KwRequestFilter.java +++ b/src/main/java/io/aiven/klaw/auth/KwRequestFilter.java @@ -53,14 +53,14 @@ public void setAuthenticationManager(AuthenticationManager authenticationManager public Authentication attemptAuthentication( HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { - if (kwInstallationType.equals("saas")) { + if ("saas".equals(kwInstallationType)) { String gRecaptchaResponse = request.getParameter("g-recaptcha-response"); boolean captchaResponse = validateCaptchaService.validateCaptcha(gRecaptchaResponse); if (!captchaResponse) throw new AuthenticationServiceException("Invalid Captcha."); } - if (authenticationType.equals("ad")) { - // Check if useer exists in kw database + if ("ad".equals(authenticationType)) { + // Check if user exists in kw database if (manageDatabase.getHandleDbRequests().getUsersInfo(request.getParameter("username")) == null) { return kwAuthenticationService.searchUserAttributes(request, response); diff --git a/src/main/java/io/aiven/klaw/config/ManageDatabase.java b/src/main/java/io/aiven/klaw/config/ManageDatabase.java index 047c239c8b..360ed8cbdf 100644 --- a/src/main/java/io/aiven/klaw/config/ManageDatabase.java +++ b/src/main/java/io/aiven/klaw/config/ManageDatabase.java @@ -191,7 +191,7 @@ private void loadStaticDataToDb() { String productName = "Klaw"; Optional productDetails = handleDbRequests.selectProductDetails(productName); if (productDetails.isPresent()) { - if (!productDetails.get().getVersion().equals(kwVersion)) + if (!Objects.equals(productDetails.get().getVersion(), kwVersion)) handleDbRequests.insertProductDetails( defaultDataService.getProductDetails(productName, kwVersion)); } else @@ -208,7 +208,7 @@ private void loadStaticDataToDb() { // } private void checkSSOAuthentication() { - if (authenticationType.equals("db") && ssoEnabled.equals("true")) { + if ("db".equals(authenticationType) && "true".equals(ssoEnabled)) { log.error( "Error : Please configure authentication type to ad, if SSO is enabled. Shutting down.."); shutdownApp(); @@ -280,7 +280,7 @@ public boolean getIsTrialLicense() { private Integer getTenantIdFromName(String tenantName) { return tenantMap.entrySet().stream() - .filter(obj -> obj.getValue().equals(tenantName)) + .filter(obj -> Objects.equals(obj.getValue(), tenantName)) .findFirst() .get() .getKey(); @@ -304,7 +304,7 @@ public Integer getTeamIdFromTeamName(int tenantId, String teamName) { if (teamName != null) optionalTeam = teamIdAndNamePerTenant.get(tenantId).entrySet().stream() - .filter(a -> a.getValue().equals(teamName)) + .filter(a -> Objects.equals(a.getValue(), teamName)) .findFirst(); else return null; @@ -363,15 +363,15 @@ private void loadEnvsForAllTenants() { public void loadEnvsForOneTenant(Integer tenantId) { List kafkaEnvList = handleDbRequests.selectAllKafkaEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List schemaEnvList = handleDbRequests.selectAllSchemaRegEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List kafkaConnectEnvList = handleDbRequests.selectAllKafkaConnectEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List envList1 = kafkaEnvList.stream().map(Env::getId).collect(Collectors.toList()); @@ -403,7 +403,7 @@ public void loadTenantTeamsForOneTenant(List allTeams, Integer tenantId) { List teamList = allTeams.stream() - .filter(team -> team.getTenantId().equals(tenantId)) + .filter(team -> Objects.equals(team.getTenantId(), tenantId)) .collect(Collectors.toList()); for (Team team : teamList) { @@ -579,15 +579,15 @@ private void loadEnvironmentsMapForAllTenants() { public void loadEnvMapForOneTenant(Integer tenantId) { List kafkaEnvList = handleDbRequests.selectAllKafkaEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List schemaEnvList = handleDbRequests.selectAllSchemaRegEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List kafkaConnectEnvList = handleDbRequests.selectAllKafkaConnectEnvs(tenantId).stream() - .filter(env -> env.getEnvExists().equals("true")) + .filter(env -> "true".equals(env.getEnvExists())) .collect(Collectors.toList()); List allEnvList = new ArrayList<>(); allEnvList.addAll(kafkaEnvList); @@ -601,7 +601,7 @@ public void loadEnvMapForOneTenant(Integer tenantId) { List kafkaEnvTenantList = kafkaEnvList.stream() - .filter(kafkaEnv -> kafkaEnv.getTenantId().equals(tenantId)) + .filter(kafkaEnv -> Objects.equals(kafkaEnv.getTenantId(), tenantId)) .collect(Collectors.toList()); Map>> envParamsMap = new HashMap<>(); diff --git a/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java b/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java index 12cbf599e9..0707824cec 100644 --- a/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java +++ b/src/main/java/io/aiven/klaw/helpers/db/rdbms/InsertDataJdbc.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -102,8 +103,11 @@ public synchronized Map insertIntoRequestTopic(TopicRequest topi activityLog.setEnv(topicRequest.getEnvironment()); activityLog.setTenantId(topicRequest.getTenantId()); - if (insertIntoActivityLog(activityLog).equals("success")) hashMap.put("result", "success"); - else hashMap.put("result", "failure"); + if ("success".equals(insertIntoActivityLog(activityLog))) { + hashMap.put("result", "success"); + } else { + hashMap.put("result", "failure"); + } return hashMap; } @@ -136,8 +140,11 @@ public synchronized Map insertIntoRequestConnector( activityLog.setEnv(connectorRequest.getEnvironment()); activityLog.setTenantId(connectorRequest.getTenantId()); - if (insertIntoActivityLog(activityLog).equals("success")) hashMap.put("result", "success"); - else hashMap.put("result", "failure"); + if ("success".equals(insertIntoActivityLog(activityLog))) { + hashMap.put("result", "success"); + } else { + hashMap.put("result", "failure"); + } return hashMap; } @@ -304,7 +311,7 @@ public String insertIntoTeams(Team team) { // making unique teamnames per tenant if (teamRepo.findAllByTenantId(team.getTenantId()).stream() - .anyMatch(team1 -> team1.getTeamname().equals(team.getTeamname()))) { + .anyMatch(team1 -> Objects.equals(team1.getTeamname(), team.getTeamname()))) { return "Failure. Team already exists"; } @@ -347,10 +354,10 @@ public String insertIntoRegisterUsers(RegisterUserInfo userInfo) { // STAGING status comes from AD users if (userExists.isPresent()) { - if (userExists.get().getStatus().equals("APPROVED")) { + if ("APPROVED".equals(userExists.get().getStatus())) { // do nothing -- user is deleted - } else if (!userExists.get().getStatus().equals("STAGING") - && !userExists.get().getStatus().equals("PENDING")) + } else if (!"STAGING".equals(userExists.get().getStatus()) + && !"PENDING".equals(userExists.get().getStatus())) return "Failure. Registration already exists"; } @@ -384,13 +391,11 @@ public synchronized Integer getNextActivityLogRequestId(int tenantId) { } public Integer getNextTopicRequestId(String idType, int tenantId) { - Integer topicId; - if (idType.equals("TOPIC_REQ_ID")) topicId = topicRequestsRepo.getNextTopicRequestId(tenantId); - else if (idType.equals("TOPIC_ID")) topicId = topicRepo.getNextTopicRequestId(tenantId); - else topicId = null; + Integer topicId = null; + if ("TOPIC_REQ_ID".equals(idType)) topicId = topicRequestsRepo.getNextTopicRequestId(tenantId); + else if ("TOPIC_ID".equals(idType)) topicId = topicRepo.getNextTopicRequestId(tenantId); - if (topicId == null) return 1001; - else return topicId + 1; + return topicId == null ? 1001 : topicId + 1; } public Integer getNextConnectorRequestId(String idType, int tenantId) { @@ -406,14 +411,14 @@ else if (idType.equals("CONNECTOR_ID")) } public Integer getNextSchemaRequestId(String idType, int tenantId) { - Integer schemaReqId; - if (idType.equals("SCHEMA_REQ_ID")) + Integer schemaReqId = null; + if ("SCHEMA_REQ_ID".equals(idType)) { schemaReqId = schemaRequestRepo.getNextSchemaRequestId(tenantId); - else if (idType.equals("SCHEMA_ID")) schemaReqId = messageSchemaRepo.getNextSchemaId(tenantId); - else schemaReqId = null; + } else if ("SCHEMA_ID".equals(idType)) { + schemaReqId = messageSchemaRepo.getNextSchemaId(tenantId); + } - if (schemaReqId == null) return 1001; - else return schemaReqId + 1; + return schemaReqId == null ? 1001 : schemaReqId + 1; } public String addNewTenant(KwTenants kwTenants) { diff --git a/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java b/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java index 1450ff20d5..84d7e026e7 100644 --- a/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java +++ b/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java @@ -7,7 +7,14 @@ import io.aiven.klaw.repository.*; import java.math.BigInteger; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.TreeSet; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -84,9 +91,11 @@ public List selectAclRequests( log.debug("selectAclRequests {}", requestor); List aclList = new ArrayList<>(); List aclListSub; - if (status.equals("all")) + if ("all".equals(status)) { aclListSub = Lists.newArrayList(aclRequestsRepo.findAllByTenantId(tenantId)); - else aclListSub = aclRequestsRepo.findAllByAclstatusAndTenantId(status, tenantId); + } else { + aclListSub = aclRequestsRepo.findAllByAclstatusAndTenantId(status, tenantId); + } Integer teamSelected = selectUserInfo(requestor).getTeamId(); @@ -94,11 +103,18 @@ public List selectAclRequests( Integer teamName; String aclType = row.getAclType(); if (allReqs) { - if (role.equals("requestor_subscriptions")) teamName = row.getRequestingteam(); - else teamName = row.getTeamId(); + if ("requestor_subscriptions".equals(role)) { + teamName = row.getRequestingteam(); + } else { + teamName = row.getTeamId(); + } - if (aclType.equals("Delete")) teamName = row.getRequestingteam(); - } else teamName = row.getRequestingteam(); + if ("Delete".equals(aclType)) { + teamName = row.getRequestingteam(); + } + } else { + teamName = row.getRequestingteam(); + } if (showRequestsOfAllTeams) // show all requests of all teams aclList.add(row); @@ -175,7 +191,7 @@ public List selectSyncTopics(String env, Integer teamId, int tenantId) { return topicRepo.findAllByTenantId(tenantId); } else return topicRepo.findAllByEnvironmentAndTenantId(env, tenantId); } else { - if (env.equals("ALL")) return topicRepo.findAllByTeamIdAndTenantId(teamId, tenantId); + if ("ALL".equals(env)) return topicRepo.findAllByTeamIdAndTenantId(teamId, tenantId); else return topicRepo.findAllByEnvironmentAndTeamIdAndTenantId(env, teamId, tenantId); } } @@ -284,18 +300,20 @@ public List selectTopicRequestsByStatus( List claimTopicReqs = topicRequestsRepo.findAllByTopictypeAndTenantId(TopicRequestTypes.Claim.name(), tenantId); - if (status.equals("all")) { + if ("all".equals(status)) { topicRequestListSub = topicRequestsRepo.findAllByTenantId(tenantId); topicRequestListSub = topicRequestListSub.stream() .filter( topicRequest -> - !topicRequest.getTopictype().equals(TopicRequestTypes.Claim.name())) + !TopicRequestTypes.Claim.name().equals(topicRequest.getTopictype())) .collect(Collectors.toList()); claimTopicReqs = claimTopicReqs.stream() - .filter(claimTopicReq -> claimTopicReq.getDescription().equals("" + teamSelected)) + .filter( + claimTopicReq -> + Objects.equals("" + teamSelected, claimTopicReq.getDescription())) .collect(Collectors.toList()); } else { topicRequestListSub = topicRequestsRepo.findAllByTopicstatusAndTenantId(status, tenantId); @@ -303,20 +321,22 @@ public List selectTopicRequestsByStatus( topicRequestListSub.stream() .filter( topicRequest -> - !topicRequest.getTopictype().equals(TopicRequestTypes.Claim.name())) + !TopicRequestTypes.Claim.name().equals(topicRequest.getTopictype())) .collect(Collectors.toList()); claimTopicReqs = claimTopicReqs.stream() .filter( claimTopicReq -> - claimTopicReq.getDescription().equals("" + teamSelected) - && claimTopicReq.getTopicstatus().equals(status)) + Objects.equals(claimTopicReq.getDescription(), "" + teamSelected) + && Objects.equals(claimTopicReq.getTopicstatus(), status)) .collect(Collectors.toList()); } topicRequestListSub.addAll(claimTopicReqs); - } else topicRequestListSub = Lists.newArrayList(topicRequestsRepo.findAllByTenantId(tenantId)); + } else { + topicRequestListSub = Lists.newArrayList(topicRequestsRepo.findAllByTenantId(tenantId)); + } for (TopicRequest row : topicRequestListSub) { Integer teamName = row.getTeamId(); @@ -354,19 +374,21 @@ public List selectConnectorRequestsByStatus( kafkaConnectorRequestsRepo.findAllByConnectortypeAndTenantId( TopicRequestTypes.Claim.name(), tenantId); - if (status.equals("all")) { + if ("all".equals(status)) { topicRequestListSub = Lists.newArrayList(kafkaConnectorRequestsRepo.findAllByTenantId(tenantId)); topicRequestListSub = topicRequestListSub.stream() .filter( topicRequest -> - !topicRequest.getConnectortype().equals(TopicRequestTypes.Claim.name())) + !TopicRequestTypes.Claim.name().equals(topicRequest.getConnectortype())) .collect(Collectors.toList()); claimTopicReqs = claimTopicReqs.stream() - .filter(claimTopicReq -> claimTopicReq.getDescription().equals("" + teamSelected)) + .filter( + claimTopicReq -> + Objects.equals(claimTopicReq.getDescription(), "" + teamSelected)) .collect(Collectors.toList()); } else { topicRequestListSub = @@ -375,15 +397,15 @@ public List selectConnectorRequestsByStatus( topicRequestListSub.stream() .filter( topicRequest -> - !topicRequest.getConnectortype().equals(TopicRequestTypes.Claim.name())) + !TopicRequestTypes.Claim.name().equals(topicRequest.getConnectortype())) .collect(Collectors.toList()); claimTopicReqs = claimTopicReqs.stream() .filter( claimTopicReq -> - claimTopicReq.getDescription().equals("" + teamSelected) - && claimTopicReq.getConnectorStatus().equals(status)) + Objects.equals(claimTopicReq.getDescription(), "" + teamSelected) + && Objects.equals(claimTopicReq.getConnectorStatus(), status)) .collect(Collectors.toList()); } @@ -403,7 +425,8 @@ public List selectConnectorRequestsByStatus( if (showRequestsOfAllTeams) topicRequestList.add(row); // no team filter else if (teamSelected != null - && (teamSelected.equals(teamName) || ("" + teamSelected).equals(row.getDescription()))) { + && (Objects.equals(teamSelected, teamName) + || Objects.equals("" + teamSelected, row.getDescription()))) { topicRequestList.add(row); } } @@ -454,7 +477,7 @@ public List selectAllUsersInfoForTeam(Integer teamId, int tenantId) { } public List selectAllEnvs(String type, int tenantId) { - if (type.equals("all")) return Lists.newArrayList(envRepo.findAllByTenantId(tenantId)); + if ("all".equals(type)) return Lists.newArrayList(envRepo.findAllByTenantId(tenantId)); else return Lists.newArrayList(envRepo.findAllByTypeAndTenantId(type, tenantId)); } @@ -512,9 +535,9 @@ public List selectTeamsOfUsers(String username, int tenantId) { Integer finalTeamId = teamId; Optional teamSel = - allTeams.stream().filter(a -> a.getTeamId().equals(finalTeamId)).findFirst(); + allTeams.stream().filter(a -> Objects.equals(a.getTeamId(), finalTeamId)).findFirst(); - if (username.equals(row.getUsername())) { + if (Objects.equals(username, row.getUsername())) { teamSel.ifPresent(teamList::add); } } @@ -731,12 +754,18 @@ public List> selectAclsCountByTeams( List> totalAclCount = new ArrayList<>(); try { List acls; - if (aclType.equals("Producer")) { - if (teamId != null) acls = aclRepo.findAllProducerAclsForTeamId(teamId, tenantId); - else acls = aclRepo.findAllProducerAclsGroupByTeamId(tenantId); + if ("Producer".equals(aclType)) { + if (teamId != null) { + acls = aclRepo.findAllProducerAclsForTeamId(teamId, tenantId); + } else { + acls = aclRepo.findAllProducerAclsGroupByTeamId(tenantId); + } } else { - if (teamId != null) acls = aclRepo.findAllConsumerAclsForTeamId(teamId, tenantId); - else acls = aclRepo.findAllConsumerAclsGroupByTeamId(tenantId); + if (teamId != null) { + acls = aclRepo.findAllConsumerAclsForTeamId(teamId, tenantId); + } else { + acls = aclRepo.findAllConsumerAclsGroupByTeamId(tenantId); + } } Map hashMap; @@ -838,15 +867,13 @@ public Integer getNextTopicRequestId(String idType, int tenantId) { } public Integer getNextConnectorRequestId(String idType, int tenantId) { - Integer connectorId; - if (idType.equals("CONNECTOR_REQ_ID")) + Integer connectorId = null; + if ("CONNECTOR_REQ_ID".equals(idType)) { connectorId = kafkaConnectorRequestsRepo.getNextConnectorRequestId(tenantId); - else if (idType.equals("CONNECTOR_ID")) + } else if ("CONNECTOR_ID".equals(idType)) { connectorId = kafkaConnectorRepo.getNextConnectorRequestId(tenantId); - else connectorId = null; - - if (connectorId == null) return 1001; - else return connectorId + 1; + } + return (connectorId == null) ? 1001 : connectorId + 1; } public List getTenants() { @@ -866,7 +893,7 @@ public List getRolesPermissionsPerTenant(int tenantId) { } public List getAllClusters(String typeOfCluster, int tenantId) { - if (typeOfCluster.equals("all")) + if ("all".equals(typeOfCluster)) return Lists.newArrayList(kwClusterRepo.findAllByTenantId(tenantId)); else return Lists.newArrayList( @@ -907,15 +934,16 @@ public String getRegistrationId(String userId) { public RegisterUserInfo getRegistrationDetails(String registrationId, String status) { List registerUserInfoList; - if (status.equals("")) + if ("".equals(status)) { registerUserInfoList = registerInfoRepo.findAllByRegistrationId(registrationId); - else + } else { registerUserInfoList = registerInfoRepo.findAllByRegistrationIdAndStatus(registrationId, status); - + } if (registerUserInfoList.size() == 1) { return registerUserInfoList.get(0); - } else return null; + } + return null; } public List getTopicsforTeam(Integer teamId, int tenantId) { @@ -944,9 +972,10 @@ public List selectSyncConnectors(String env, Integer teamId, i return kafkaConnectorRepo.findAllByTenantId(tenantId); } else return kafkaConnectorRepo.findAllByEnvironmentAndTenantId(env, tenantId); } else { - if (env.equals("ALL")) return kafkaConnectorRepo.findAllByTeamIdAndTenantId(teamId, tenantId); - else - return kafkaConnectorRepo.findAllByEnvironmentAndTeamIdAndTenantId(env, teamId, tenantId); + if ("ALL".equals(env)) { + return kafkaConnectorRepo.findAllByTeamIdAndTenantId(teamId, tenantId); + } + return kafkaConnectorRepo.findAllByEnvironmentAndTeamIdAndTenantId(env, teamId, tenantId); } } diff --git a/src/main/java/io/aiven/klaw/helpers/db/rdbms/UpdateDataJdbc.java b/src/main/java/io/aiven/klaw/helpers/db/rdbms/UpdateDataJdbc.java index 24b7221bf4..ba77fe0bf3 100644 --- a/src/main/java/io/aiven/klaw/helpers/db/rdbms/UpdateDataJdbc.java +++ b/src/main/java/io/aiven/klaw/helpers/db/rdbms/UpdateDataJdbc.java @@ -136,12 +136,14 @@ public String updateTopicRequest(TopicRequest topicRequest, String approver) { topicObj.setHistory(topicRequest.getHistory()); topics.add(topicObj); - if (topicRequest.getTopictype().equals(TopicRequestTypes.Create.name())) { + final TopicRequestTypes topicRequestTypes = TopicRequestTypes.of(topicRequest.getTopictype()); + if (topicRequestTypes == TopicRequestTypes.Create) { insertDataJdbcHelper.insertIntoTopicSOT(topics, false); - } else if (topicRequest.getTopictype().equals(TopicRequestTypes.Update.name())) + } else if (topicRequestTypes == TopicRequestTypes.Update) { updateTopicSOT(topics, topicRequest.getOtherParams()); - else if (topicRequest.getTopictype().equals(TopicRequestTypes.Delete.name())) + } else if (topicRequestTypes == TopicRequestTypes.Delete) { deleteDataJdbcHelper.deleteTopics(topicObj); + } return "success"; } @@ -165,12 +167,15 @@ public String updateConnectorRequest(KafkaConnectorRequest connectorRequest, Str topicObj.setHistory(connectorRequest.getHistory()); connectors.add(topicObj); - if (connectorRequest.getConnectortype().equals(TopicRequestTypes.Create.name())) { + final TopicRequestTypes topicRequestTypes = + TopicRequestTypes.of(connectorRequest.getConnectortype()); + if (topicRequestTypes == TopicRequestTypes.Create) { insertDataJdbcHelper.insertIntoConnectorSOT(connectors, false); - } else if (connectorRequest.getConnectortype().equals(TopicRequestTypes.Update.name())) + } else if (topicRequestTypes == TopicRequestTypes.Update) { updateConnectorSOT(connectors, connectorRequest.getOtherParams()); - else if (connectorRequest.getConnectortype().equals(TopicRequestTypes.Delete.name())) + } else if (topicRequestTypes == TopicRequestTypes.Delete) { deleteDataJdbcHelper.deleteConnectors(topicObj); + } return "success"; } @@ -311,7 +316,7 @@ public void updateNewUserRequest(String username, String approver, boolean isApp else status = "DECLINED"; if (registerUser.isPresent()) { RegisterUserInfo registerUserInfo = registerUser.get(); - if (registerUserInfo.getStatus().equals("PENDING")) { + if ("PENDING".equals(registerUserInfo.getStatus())) { registerUserInfo.setStatus(status); registerUserInfo.setApprover(approver); registerUserInfo.setRegisteredTime(new Timestamp(System.currentTimeMillis())); @@ -364,7 +369,7 @@ public String updatePermissions(List permissions, String add List rolePermFound; - if (addDelete.equals("DELETE")) { + if ("DELETE".equals(addDelete)) { for (KwRolesPermissions permission : permissions) { rolePermFound = kwRolesPermsRepo.findAllByRoleIdAndPermissionAndTenantId( diff --git a/src/main/java/io/aiven/klaw/listeners/MetadataListener.java b/src/main/java/io/aiven/klaw/listeners/MetadataListener.java index b179a757f7..fa3cd0b550 100644 --- a/src/main/java/io/aiven/klaw/listeners/MetadataListener.java +++ b/src/main/java/io/aiven/klaw/listeners/MetadataListener.java @@ -35,7 +35,7 @@ public static T getBean(Class clazz) throws BeansException { @PostRemove private void afterAnyUpdate(KwMetadataUpdates metadataUpdates) { log.info("MetadataUpdates : " + metadataUpdates); - if (metadataUpdates.getEntityType().equals(EntityType.TEAM.name())) + if (EntityType.TEAM.name().equals(metadataUpdates.getEntityType())) getBean(ManageDatabase.class) .loadTenantTeamsForOneTenant(null, metadataUpdates.getTenantId()); } diff --git a/src/main/java/io/aiven/klaw/model/EntityType.java b/src/main/java/io/aiven/klaw/model/EntityType.java index 05f1b710f7..5a2336dba4 100644 --- a/src/main/java/io/aiven/klaw/model/EntityType.java +++ b/src/main/java/io/aiven/klaw/model/EntityType.java @@ -1,5 +1,9 @@ package io.aiven.klaw.model; +import lombok.extern.slf4j.Slf4j; +import org.checkerframework.checker.nullness.qual.Nullable; + +@Slf4j public enum EntityType { TEAM, ENVIRONMENT, @@ -7,4 +11,15 @@ public enum EntityType { TENANT, ROLES_PERMISSIONS, PROPERTIES; + + @Nullable + public static EntityType of(@Nullable String value) { + for (EntityType val : values()) { + if (val.name().equals(value)) { + return val; + } + } + log.warn("Unknown EntityType value '{}'", value); + return null; + } } diff --git a/src/main/java/io/aiven/klaw/model/MetadataOperationType.java b/src/main/java/io/aiven/klaw/model/MetadataOperationType.java index a04097ac43..5e1fd00996 100644 --- a/src/main/java/io/aiven/klaw/model/MetadataOperationType.java +++ b/src/main/java/io/aiven/klaw/model/MetadataOperationType.java @@ -1,8 +1,23 @@ package io.aiven.klaw.model; +import lombok.extern.slf4j.Slf4j; +import org.checkerframework.checker.nullness.qual.Nullable; + +@Slf4j public enum MetadataOperationType { CREATE, DELETE, UPDATE, INSERT; + + @Nullable + public static MetadataOperationType of(@Nullable String value) { + for (MetadataOperationType val : values()) { + if (val.name().equals(value)) { + return val; + } + } + log.warn("Unknown MetadataOperationType value '{}'", value); + return null; + } } diff --git a/src/main/java/io/aiven/klaw/model/TopicRequestTypes.java b/src/main/java/io/aiven/klaw/model/TopicRequestTypes.java index d277733043..3ea10c1633 100644 --- a/src/main/java/io/aiven/klaw/model/TopicRequestTypes.java +++ b/src/main/java/io/aiven/klaw/model/TopicRequestTypes.java @@ -1,8 +1,23 @@ package io.aiven.klaw.model; +import lombok.extern.slf4j.Slf4j; +import org.checkerframework.checker.nullness.qual.Nullable; + +@Slf4j public enum TopicRequestTypes { Create, Update, Delete, - Claim + Claim; + + @Nullable + public static TopicRequestTypes of(@Nullable String value) { + for (TopicRequestTypes val : values()) { + if (val.name().equals(value)) { + return val; + } + } + log.warn("Unknown TopicRequestTypes value '{}'", value); + return null; + } } diff --git a/src/main/java/io/aiven/klaw/service/AclControllerService.java b/src/main/java/io/aiven/klaw/service/AclControllerService.java index 1031e2e0a9..85a1f96c10 100644 --- a/src/main/java/io/aiven/klaw/service/AclControllerService.java +++ b/src/main/java/io/aiven/klaw/service/AclControllerService.java @@ -86,9 +86,9 @@ public String createAcl(AclRequestsModel aclReq) { boolean topicFound = false; String result; - if (aclReq.getAclPatternType().equals("LITERAL")) { + if ("LITERAL".equals(aclReq.getAclPatternType())) { for (Topic topic : topics) { - if (topic.getEnvironment().equals(aclReq.getEnvironment())) { + if (Objects.equals(topic.getEnvironment(), aclReq.getEnvironment())) { topicFound = true; break; } @@ -97,8 +97,8 @@ public String createAcl(AclRequestsModel aclReq) { if (!topicFound) return "{\"result\":\"" + result + "\"}"; } - if (aclReq.getTopictype().equals("Consumer")) { - if (aclReq.getAclPatternType().equals("PREFIXED")) { + if ("Consumer".equals(aclReq.getTopictype())) { + if ("PREFIXED".equals(aclReq.getAclPatternType())) { result = "Failure : Please change the pattern to LITERAL for topic type."; return "{\"result\":\"" + result + "\"}"; } @@ -144,7 +144,7 @@ public String createAcl(AclRequestsModel aclReq) { String execRes = manageDatabase.getHandleDbRequests().requestForAcl(aclRequestsDao).get("result"); - if (execRes.equals("success")) { + if ("success".equals(execRes)) { mailService.sendMail( aclReq.getTopicname(), aclReq.getTopictype(), @@ -250,7 +250,7 @@ public Map> updateSyncBackAcls(SyncBackAcls syncBackAcls) { resultMap.put("result", resultStatus); - if (syncBackAcls.getTypeOfSync().equals("SELECTED_ACLS")) { + if ("SELECTED_ACLS".equals(syncBackAcls.getTypeOfSync())) { for (String aclId : syncBackAcls.getAclIds()) { Acl acl = manageDatabase @@ -304,7 +304,7 @@ private void approveSyncBackAcls( } else if (resultAclReq.contains("Acl already exists")) { logUpdateSyncBackTopics.add("Acl already exists " + aclFound.getTopicname()); } else { - if (!syncBackAcls.getSourceEnv().equals(syncBackAcls.getTargetEnv())) { + if (!Objects.equals(syncBackAcls.getSourceEnv(), syncBackAcls.getTargetEnv())) { logUpdateSyncBackTopics.add("Acl added: " + aclFound.getTopicname()); // Create request Map resultMapReq = @@ -378,7 +378,7 @@ private List getAclRequestsModels(List aclReqs, i manageDatabase.getTeamNameFromTeamId(tenantId, aclRequests.getTeamId())); // show approving info only before approvals - if (!aclRequestsModel.getAclstatus().equals(RequestStatus.approved.name())) { + if (!RequestStatus.approved.name().equals(aclRequestsModel.getAclstatus())) { aclRequestsModel.setApprovingTeamDetails( updateApprovingInfo( aclRequestsModel.getTopicname(), @@ -406,7 +406,7 @@ private String updateApprovingInfo( if (topicTeamsList.size() > 0) { Integer teamId = getFilteredTopicsForTenant(topicTeamsList).get(0).getTeamId(); - if (aclType.equals("Delete")) teamId = team; + if ("Delete".equals(aclType)) teamId = team; List userList = manageDatabase.getHandleDbRequests().selectAllUsersInfoForTeam(teamId, tenantId); @@ -415,7 +415,8 @@ private String updateApprovingInfo( "Team : " + manageDatabase.getTeamNameFromTeamId(tenantId, teamId) + ", Users : "); for (UserInfo userInfo : userList) { - if (approverRoles.contains(userInfo.getRole()) && !requestor.equals(userInfo.getUsername())) + if (approverRoles.contains(userInfo.getRole()) + && !Objects.equals(requestor, userInfo.getUsername())) approvingInfo.append(userInfo.getUsername()).append(","); } return String.valueOf(approvingInfo); @@ -586,7 +587,7 @@ public String createDeleteAclSubscriptionRequest(String req_no) { aclReq.setJsonParams(acl.getJsonParams()); String execRes = manageDatabase.getHandleDbRequests().requestForAcl(aclReq).get("result"); - if (execRes.equals("success")) { + if ("success".equals(execRes)) { mailService.sendMail( aclReq.getTopicname(), aclReq.getTopictype(), @@ -611,10 +612,10 @@ public String approveAclRequests(String req_no) throws KlawException { HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests(); AclRequests aclReq = dbHandle.selectAcl(Integer.parseInt(req_no), tenantId); - if (aclReq.getUsername().equals(userDetails)) + if (Objects.equals(aclReq.getUsername(), userDetails)) return "{\"result\":\"You are not allowed to approve your own subscription requests.\"}"; - if (!aclReq.getAclstatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(aclReq.getAclstatus())) { return "{\"result\":\"This request does not exist anymore.\"}"; } @@ -685,7 +686,7 @@ public String declineAclRequests(String req_no, String reasonToDecline) { AclRequests aclReq = dbHandle.selectAcl(Integer.parseInt(req_no), commonUtilsService.getTenantId(getUserName())); - if (!aclReq.getAclstatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(aclReq.getAclstatus())) { return "{\"result\":\"This request does not exist anymore.\"}"; } @@ -734,11 +735,11 @@ private List> updateConsumerGroups( for (Map hMapGroupItem : groupedList) { for (Map hMapItem : clusterAclList) { - if (hMapGroupItem.get("operation").equals("READ") - && hMapItem.get("operation").equals("READ") - && hMapItem.get("resourceType").equals("GROUP")) { - if (hMapItem.get("host").equals(hMapGroupItem.get("host")) - && hMapItem.get("principle").equals(hMapGroupItem.get("principle"))) { + if ("READ".equals(hMapGroupItem.get("operation")) + && "READ".equals(hMapItem.get("operation")) + && "GROUP".equals(hMapItem.get("resourceType"))) { + if (Objects.equals(hMapItem.get("host"), hMapGroupItem.get("host")) + && Objects.equals(hMapItem.get("principle"), hMapGroupItem.get("principle"))) { Map hashMap = new HashMap<>(hMapGroupItem); hashMap.put("consumerGroup", hMapItem.get("resourceName")); updateList.add(hashMap); @@ -758,11 +759,11 @@ private List> groupAcls( hItem -> { if (isSync) { if (topicNameSearch != null) { - return hItem.get("resourceType").equals("TOPIC") + return "TOPIC".equals(hItem.get("resourceType")) && hItem.get("resourceName").contains(topicNameSearch); - } else return hItem.get("resourceType").equals("TOPIC"); + } else return "TOPIC".equals(hItem.get("resourceType")); } else { - return hItem.get("resourceName").equals(topicNameSearch); + return Objects.equals(hItem.get("resourceName"), topicNameSearch); } }) .collect(Collectors.toList()); @@ -857,7 +858,7 @@ public TopicOverview getAcls(String topicNameSearch) { HandleDbRequests handleDb = manageDatabase.getHandleDbRequests(); int tenantId = commonUtilsService.getTenantId(getUserName()); String retrieveSchemasStr = manageDatabase.getKwPropertyValue(RETRIEVE_SCHEMAS_KEY, tenantId); - boolean retrieveSchemas = retrieveSchemasStr.equals("true"); + boolean retrieveSchemas = "true".equals(retrieveSchemasStr); if (topicNameSearch != null) topicNameSearch = topicNameSearch.trim(); else return null; @@ -971,7 +972,7 @@ public TopicOverview getAcls(String topicNameSearch) { } // show edit button only for restricted envs - if (topicOwnerTeam.equals(loggedInUserTeam) + if (Objects.equals(topicOwnerTeam, loggedInUserTeam) && reqTopicsEnvsList.contains(topicInfo.getClusterId())) { topicInfo.setShowEditTopic(true); } @@ -1005,14 +1006,15 @@ public TopicOverview getAcls(String topicNameSearch) { topicOverview.setTopicInfoList(topicInfoList); try { - if (topicOwnerTeam.equals(loggedInUserTeam)) { + if (Objects.equals(topicOwnerTeam, loggedInUserTeam)) { topicOverview.setPromotionDetails(getTopicPromotionEnv(topicNameSearch, topics, tenantId)); if (topicInfoList.size() > 0) { TopicInfo lastItem = topicInfoList.get(topicInfoList.size() - 1); lastItem.setTopicDeletable( aclInfo.stream() - .noneMatch(aclItem -> aclItem.getEnvironment().equals(lastItem.getCluster()))); + .noneMatch( + aclItem -> Objects.equals(aclItem.getEnvironment(), lastItem.getCluster()))); lastItem.setShowDeleteTopic(true); } } else { @@ -1253,15 +1255,15 @@ private List applyFiltersAcls( String tmpPermType = aclListItem.get("operation"); - if (tmpPermType.equals("WRITE")) mp.setTopictype("Producer"); - else if (tmpPermType.equals("READ")) { + if ("WRITE".equals(tmpPermType)) mp.setTopictype("Producer"); + else if ("READ".equals(tmpPermType)) { mp.setTopictype("Consumer"); if (aclListItem.get("consumerGroup") != null) mp.setConsumergroup(aclListItem.get("consumerGroup")); else continue; } - if (aclListItem.get("resourceType").toLowerCase().equals("topic")) + if ("topic".equalsIgnoreCase(aclListItem.get("resourceType"))) mp.setTopicname(aclListItem.get("resourceName")); mp.setAcl_ip(aclListItem.get("host")); @@ -1274,7 +1276,7 @@ else if (tmpPermType.equals("READ")) { if (acl_ssl == null || acl_ssl.equals("")) acl_ssl = "User:*"; else { if (!KafkaFlavors.AIVEN_FOR_APACHE_KAFKA.value.equals(kafkaFlavor) - && !acl_ssl.equals("User:*") + && !"User:*".equals(acl_ssl) && !acl_ssl.startsWith("User:")) { acl_ssl = "User:" + acl_ssl; } @@ -1283,10 +1285,10 @@ else if (tmpPermType.equals("READ")) { if (acl_host == null || acl_host.equals("")) acl_host = "*"; if (aclSotItem.getTopicname() != null - && aclListItem.get("resourceName").equals(aclSotItem.getTopicname()) - && aclListItem.get("host").equals(acl_host) - && aclListItem.get("principle").equals(acl_ssl) - && aclSotItem.getTopictype().equals(mp.getTopictype())) { + && Objects.equals(aclListItem.get("resourceName"), aclSotItem.getTopicname()) + && Objects.equals(aclListItem.get("host"), acl_host) + && Objects.equals(aclListItem.get("principle"), acl_ssl) + && Objects.equals(aclSotItem.getTopictype(), mp.getTopictype())) { mp.setTeamname(manageDatabase.getTeamNameFromTeamId(tenantId, aclSotItem.getTeamId())); mp.setReq_no(aclSotItem.getReq_no() + ""); break; @@ -1320,7 +1322,9 @@ private List tenantFiltering(List teamList) { List teams = manageDatabase.getHandleDbRequests().selectAllTeams(tenantId); teams = - teams.stream().filter(t -> t.getTenantId().equals(tenantId)).collect(Collectors.toList()); + teams.stream() + .filter(t -> Objects.equals(t.getTenantId(), tenantId)) + .collect(Collectors.toList()); List teamListUpdated = new ArrayList<>(); for (Team teamsItem : teams) { teamListUpdated.add(teamsItem.getTeamname()); @@ -1378,9 +1382,9 @@ private boolean validateTeamConsumerGroup(Integer teamId, String consumerGroup, List acls = manageDatabase.getHandleDbRequests().getUniqueConsumerGroups(tenantId); for (Acl acl : acls) { - if (!acl.getTeamId().equals(teamId) + if (!Objects.equals(acl.getTeamId(), teamId) && acl.getConsumergroup() != null - && acl.getConsumergroup().equals(consumerGroup)) { + && Objects.equals(acl.getConsumergroup(), consumerGroup)) { return true; } } @@ -1391,7 +1395,7 @@ public Env getEnvDetails(String envId, int tenantId) { Optional envFound = manageDatabase.getKafkaEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } diff --git a/src/main/java/io/aiven/klaw/service/AnalyticsControllerService.java b/src/main/java/io/aiven/klaw/service/AnalyticsControllerService.java index f420c87e2a..923f9241a1 100644 --- a/src/main/java/io/aiven/klaw/service/AnalyticsControllerService.java +++ b/src/main/java/io/aiven/klaw/service/AnalyticsControllerService.java @@ -69,7 +69,7 @@ private List getEnvsFromUserId() { public String getEnvName(String envId) { Optional envFound = manageDatabase.getKafkaEnvList(commonUtilsService.getTenantId(getUserName())).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.map(Env::getName).orElse(null); } @@ -91,7 +91,7 @@ public Map getAclsCountPerEnv(String sourceEnvSelected) { .filter( mapObj -> allowedEnvIdList.contains(mapObj.get("cluster")) - && mapObj.get("cluster").equals(sourceEnvSelected)) + && Objects.equals(mapObj.get("cluster"), sourceEnvSelected)) .collect(Collectors.toList()); if (aclsPerEnvList.size() == 1) { @@ -122,7 +122,7 @@ public Map getTopicsCountPerEnv(String sourceEnvSelected) { .filter( mapObj -> allowedEnvIdList.contains(mapObj.get("cluster")) - && mapObj.get("cluster").equals(sourceEnvSelected)) + && Objects.equals(mapObj.get("cluster"), sourceEnvSelected)) .collect(Collectors.toList()); if (topicsCountList.size() == 1) { @@ -572,7 +572,7 @@ private void generateReportPerView( // content for (int i = 0; i < data1.size(); i++) { - if (!labels.get(i).equals("")) { + if (!"".equals(labels.get(i))) { data.put(id, new Object[] {id - 1, labels.get(i), data1.get(i)}); id++; } @@ -610,7 +610,7 @@ private Map> getTopicNames(int tenantId) { topicsPerEnv.put( getEnvName(env), topics.stream() - .filter(topic -> topic.getEnvironment().equals(env)) + .filter(topic -> Objects.equals(topic.getEnvironment(), env)) .map(Topic::getTopicname) .sorted() .collect(Collectors.toList())); @@ -622,7 +622,7 @@ private Map> getTopicNames(int tenantId) { topicsPerEnv.put( getEnvName(env), topics.stream() - .filter(topic -> topic.getEnvironment().equals(env)) + .filter(topic -> Objects.equals(topic.getEnvironment(), env)) .map(Topic::getTopicname) .sorted() .collect(Collectors.toList())); @@ -647,7 +647,9 @@ private Map> getConsumerGroups(int tenantId) { aclsPerEnv.put( getEnvName(env), acls.stream() - .filter(acl -> acl.getEnvironment().equals(env) && acl.getConsumergroup() != null) + .filter( + acl -> + Objects.equals(acl.getEnvironment(), env) && acl.getConsumergroup() != null) .map(Acl::getConsumergroup) .sorted() .collect(Collectors.toList())); @@ -659,7 +661,9 @@ private Map> getConsumerGroups(int tenantId) { aclsPerEnv.put( getEnvName(env), acls.stream() - .filter(acl -> acl.getEnvironment().equals(env) && acl.getConsumergroup() != null) + .filter( + acl -> + Objects.equals(acl.getEnvironment(), env) && acl.getConsumergroup() != null) .map(Acl::getConsumergroup) .sorted() .collect(Collectors.toList())); diff --git a/src/main/java/io/aiven/klaw/service/ClusterApiService.java b/src/main/java/io/aiven/klaw/service/ClusterApiService.java index 333cfad261..ebd9377144 100644 --- a/src/main/java/io/aiven/klaw/service/ClusterApiService.java +++ b/src/main/java/io/aiven/klaw/service/ClusterApiService.java @@ -434,9 +434,9 @@ public String approveConnectorRequests( String uri; String URI_GET_TOPICS = "/topics/"; - if (connectorType.equals("Create")) { + if ("Create".equals(connectorType)) { uri = clusterConnUrl + URI_GET_TOPICS + "postConnector"; - } else if (connectorType.equals("Update")) { + } else if ("Update".equals(connectorType)) { uri = clusterConnUrl + URI_GET_TOPICS + "updateConnector"; } else uri = clusterConnUrl + URI_GET_TOPICS + "deleteConnector"; @@ -446,7 +446,7 @@ public String approveConnectorRequests( HttpEntity> request = new HttpEntity<>(params, headers); response = restTemplate.postForEntity(uri, request, HashMap.class); - if (response.getBody().get("result").equals("success")) { + if ("success".equals(response.getBody().get("result"))) { return "success"; } else { return (String) response.getBody().get("errorText"); @@ -498,11 +498,11 @@ public ResponseEntity approveTopicRequests( params.add("topicName", topicName); String uri; - if (topicRequestType.equals("Create")) { + if ("Create".equals(topicRequestType)) { uri = clusterConnUrl + URI_CREATE_TOPICS; params.add("partitions", "" + topicPartitions); params.add("rf", replicationFactor); - } else if (topicRequestType.equals("Update")) { + } else if ("Update".equals(topicRequestType)) { uri = clusterConnUrl + URI_UPDATE_TOPICS; params.add("partitions", "" + topicPartitions); params.add("rf", replicationFactor); @@ -533,7 +533,7 @@ public ResponseEntity> approveAclRequests(AclRequests aclReq String URI_CREATE_ACLS = "/topics/createAcls"; String URI_DELETE_ACLS = "/topics/deleteAcls"; - if (aclReq.getAclType().equals("Create")) uri = clusterConnUrl + URI_CREATE_ACLS; + if ("Create".equals(aclReq.getAclType())) uri = clusterConnUrl + URI_CREATE_ACLS; else uri = clusterConnUrl + URI_DELETE_ACLS; RestTemplate restTemplate = getRestTemplate(); @@ -548,17 +548,18 @@ public ResponseEntity> approveAclRequests(AclRequests aclReq .get(envSelected.getClusterId()); // aiven config - if (KafkaFlavors.AIVEN_FOR_APACHE_KAFKA.value.equals(kwClusters.getKafkaFlavor())) { + if (Objects.equals(KafkaFlavors.AIVEN_FOR_APACHE_KAFKA.value, kwClusters.getKafkaFlavor())) { params.add("aclsNativeType", AclsNativeType.AIVEN.name()); params.add("projectName", kwClusters.getProjectName()); params.add("serviceName", kwClusters.getServiceName()); params.add("topic", aclReq.getTopicname()); params.add("username", aclReq.getAcl_ssl()); - if (aclReq.getTopictype().equals(AclType.PRODUCER.value)) params.add("permission", "write"); + if (Objects.equals(aclReq.getTopictype(), AclType.PRODUCER.value)) + params.add("permission", "write"); else params.add("permission", "read"); - if (AclOperation.DELETE.value.equals(aclReq.getAclType()) + if (Objects.equals(AclOperation.DELETE.value, aclReq.getAclType()) && null != aclReq.getJsonParams()) { ObjectMapper objectMapper = new ObjectMapper(); Map jsonObj = objectMapper.readValue(aclReq.getJsonParams(), Map.class); diff --git a/src/main/java/io/aiven/klaw/service/CommonUtilsService.java b/src/main/java/io/aiven/klaw/service/CommonUtilsService.java index 6ecf7f55ad..d52a4c04ce 100644 --- a/src/main/java/io/aiven/klaw/service/CommonUtilsService.java +++ b/src/main/java/io/aiven/klaw/service/CommonUtilsService.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import lombok.extern.slf4j.Slf4j; @@ -83,7 +84,7 @@ public Authentication getAuthentication() { } String getAuthority(Object principal) { - if (enableUserAuthorizationFromAD.equals("true")) { + if ("true".equals(enableUserAuthorizationFromAD)) { if (principal instanceof DefaultOAuth2User) { DefaultOAuth2User defaultOAuth2User = (DefaultOAuth2User) principal; Object[] authorities = defaultOAuth2User.getAuthorities().toArray(); @@ -158,7 +159,7 @@ public ChartsJsOverview getChartsJsOverview( totalCount += Integer.parseInt(hashMap.get(yaxisCount)); data.add(Integer.parseInt(hashMap.get(yaxisCount))); - if (xaxisLabel.equals("teamid")) + if ("teamid".equals(xaxisLabel)) labels.add( manageDatabase.getTeamNameFromTeamId( tenantId, Integer.parseInt(hashMap.get(xaxisLabel)))); @@ -307,36 +308,35 @@ public void updateMetadata( } public synchronized void updateMetadata(KwMetadataUpdates kwMetadataUpdates) { - if (kwMetadataUpdates.getEntityType().equals(EntityType.TEAM.name())) { + final EntityType entityType = EntityType.of(kwMetadataUpdates.getEntityType()); + if (entityType == null) return; + final MetadataOperationType operationType = + MetadataOperationType.of(kwMetadataUpdates.getOperationType()); + if (entityType == EntityType.TEAM) { manageDatabase.loadEnvsForOneTenant(kwMetadataUpdates.getTenantId()); manageDatabase.loadTenantTeamsForOneTenant(null, kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.CLUSTER.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.DELETE.name())) + } else if (entityType == EntityType.CLUSTER && operationType == MetadataOperationType.DELETE) manageDatabase.deleteCluster(kwMetadataUpdates.getTenantId()); - else if (kwMetadataUpdates.getEntityType().equals(EntityType.CLUSTER.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.CREATE.name())) + else if (entityType == EntityType.CLUSTER && operationType == MetadataOperationType.CREATE) manageDatabase.loadClustersForOneTenant(null, null, null, kwMetadataUpdates.getTenantId()); - else if (kwMetadataUpdates.getEntityType().equals(EntityType.ENVIRONMENT.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.CREATE.name())) { + else if (entityType == EntityType.ENVIRONMENT + && operationType == MetadataOperationType.CREATE) { manageDatabase.loadEnvsForOneTenant(kwMetadataUpdates.getTenantId()); manageDatabase.loadEnvMapForOneTenant(kwMetadataUpdates.getTenantId()); manageDatabase.loadTenantTeamsForOneTenant(null, kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.ENVIRONMENT.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.DELETE.name())) { + } else if (entityType == EntityType.ENVIRONMENT + && operationType == MetadataOperationType.DELETE) { manageDatabase.loadEnvMapForOneTenant(kwMetadataUpdates.getTenantId()); manageDatabase.loadEnvsForOneTenant(kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.TENANT.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.CREATE.name())) { + } else if (entityType == EntityType.TENANT && operationType == MetadataOperationType.CREATE) { manageDatabase.updateStaticDataForTenant(kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.TENANT.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.DELETE.name())) { + } else if (entityType == EntityType.TENANT && operationType == MetadataOperationType.DELETE) { manageDatabase.deleteTenant(kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.TENANT.name()) - && kwMetadataUpdates.getOperationType().equals(MetadataOperationType.UPDATE.name())) { + } else if (entityType == EntityType.TENANT && operationType == MetadataOperationType.UPDATE) { manageDatabase.loadOneTenant(kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.ROLES_PERMISSIONS.name())) { + } else if (entityType == EntityType.ROLES_PERMISSIONS) { manageDatabase.loadRolesPermissionsOneTenant(null, kwMetadataUpdates.getTenantId()); - } else if (kwMetadataUpdates.getEntityType().equals(EntityType.PROPERTIES.name())) { + } else if (entityType == EntityType.PROPERTIES) { manageDatabase.loadKwPropsPerOneTenant(null, kwMetadataUpdates.getTenantId()); } } @@ -351,7 +351,7 @@ public String getLoginUrl() { } public String getBaseUrl() { - if (kwContextPath.equals("")) + if ("".equals(kwContextPath)) return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); else return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString() @@ -364,7 +364,9 @@ public void resetCacheOnOtherServers(KwMetadataUpdates kwMetadataUpdates) { try { String tenantName = manageDatabase.getHandleDbRequests().getTenants().stream() - .filter(kwTenant -> kwTenant.getTenantId().equals(kwMetadataUpdates.getTenantId())) + .filter( + kwTenant -> + Objects.equals(kwTenant.getTenantId(), kwMetadataUpdates.getTenantId())) .findFirst() .get() .getTenantName(); @@ -381,7 +383,7 @@ public void resetCacheOnOtherServers(KwMetadataUpdates kwMetadataUpdates) { String basePath; for (String server : servers) { - if (kwContextPath.equals("")) basePath = server; + if ("".equals(kwContextPath)) basePath = server; else basePath = server + "/" + kwContextPath; String uri = basePath diff --git a/src/main/java/io/aiven/klaw/service/DefaultDataService.java b/src/main/java/io/aiven/klaw/service/DefaultDataService.java index ce0baa6980..faf39f886f 100644 --- a/src/main/java/io/aiven/klaw/service/DefaultDataService.java +++ b/src/main/java/io/aiven/klaw/service/DefaultDataService.java @@ -309,7 +309,7 @@ public List createDefaultRolesPermissions( Map defaultAdminPermissionsList = getDefaultAdminPermissionsList(); Map superAdminPermissionsList = getDefaultSuperAdminPermissionsList(); - if (!kwInstallationType.equals("saas")) // on premise + if (!"saas".equals(kwInstallationType)) // on premise { defaultAdminPermissionsList.put("ADD_TENANT", PermissionType.ADD_TENANT.getDescription()); } diff --git a/src/main/java/io/aiven/klaw/service/EmailService.java b/src/main/java/io/aiven/klaw/service/EmailService.java index 46e4e8bb2b..dd83b6626e 100644 --- a/src/main/java/io/aiven/klaw/service/EmailService.java +++ b/src/main/java/io/aiven/klaw/service/EmailService.java @@ -104,7 +104,7 @@ public void sendSimpleMessage( text = headerString + text + footerString; message.setContent(text, "text/html"); - if (emailNotificationsEnabled.equals("true")) { + if ("true".equals(emailNotificationsEnabled)) { try { CompletableFuture.runAsync( () -> { diff --git a/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java b/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java index 6d99418ce0..2c4016ec21 100644 --- a/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java +++ b/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java @@ -79,7 +79,7 @@ public synchronized EnvModel getEnvDetails(String envSelected, String clusterTyp } Env env = manageDatabase.getHandleDbRequests().selectEnvDetails(envSelected, tenantId); - if (env != null && env.getEnvExists().equals("false")) { + if (env != null && "false".equals(env.getEnvExists())) { return null; } @@ -164,7 +164,8 @@ public List getClusters(String typeOfCluster) { if (!commonUtilsService.isNotAuthorizedUser( getPrincipal(), PermissionType.ADD_EDIT_DELETE_CLUSTERS)) { if (allEnvList.stream() - .anyMatch(env -> env.getClusterId().equals(finalTmpClusterModel.getClusterId()))) { + .anyMatch( + env -> Objects.equals(env.getClusterId(), finalTmpClusterModel.getClusterId()))) { tmpClusterModel.setShowDeleteCluster(false); } } @@ -182,7 +183,7 @@ public List getClustersPaginated( if (clusterId != null && !clusterId.equals("")) { kwClustersModelList = kwClustersModelList.stream() - .filter(env -> (env.getClusterId() + "").toLowerCase().equals(clusterId)) + .filter(env -> Objects.equals((env.getClusterId() + "").toLowerCase(), clusterId)) .collect(Collectors.toList()); } @@ -271,7 +272,8 @@ public List> getSyncEnvs() { hMap = new HashMap<>(); hMap.put("id", env.getId()); String baseClusterDropDownStr = " (Base Sync cluster)"; - if (syncCluster.equals(env.getId())) hMap.put("name", env.getName() + baseClusterDropDownStr); + if (Objects.equals(syncCluster, env.getId())) + hMap.put("name", env.getName() + baseClusterDropDownStr); else hMap.put("name", env.getName()); envsOnly.add(hMap); @@ -295,7 +297,7 @@ public List getEnvsForRequestTopicsCluster() { env -> { boolean found = false; for (String reqTopicEnv : reqTopicsEnvs) { - if (env.getId().equals(reqTopicEnv)) { + if (Objects.equals(env.getId(), reqTopicEnv)) { found = true; break; } @@ -407,7 +409,9 @@ public List getEnvsPaginated(String envId, String pageNo, String searc if (envId != null && !envId.equals("")) { envListMap = - envListMap.stream().filter(env -> env.getId().equals(envId)).collect(Collectors.toList()); + envListMap.stream() + .filter(env -> Objects.equals(env.getId(), envId)) + .collect(Collectors.toList()); } if (searchEnvParam != null && !searchEnvParam.equals("")) { @@ -617,7 +621,8 @@ public String addNewEnv(EnvModel newEnv) { if (newEnv.getClusterId() == null) return "{\"result\":\"Please select a cluster.\"}"; - if (newEnv.getName().length() > 3 && newEnv.getType().equals(KafkaClustersType.KAFKA.value)) + if (newEnv.getName().length() > 3 + && Objects.equals(newEnv.getType(), KafkaClustersType.KAFKA.value)) newEnv.setName(newEnv.getName().substring(0, 3)); newEnv.setName(newEnv.getName().toUpperCase()); @@ -646,10 +651,10 @@ public String addNewEnv(EnvModel newEnv) { envActualList.stream() .anyMatch( en -> - en.getName().equals(newEnv.getName()) - && en.getType().equals(newEnv.getType()) - && en.getTenantId().equals(newEnv.getTenantId()) - && en.getEnvExists().equals("true")); // 504 change + Objects.equals(en.getName(), newEnv.getName()) + && Objects.equals(en.getType(), newEnv.getType()) + && Objects.equals(en.getTenantId(), newEnv.getTenantId()) + && Objects.equals(en.getEnvExists(), "true")); // 504 change if (envNameAlreadyPresent) { return "{\"result\":\"Failure " + "Please choose a different name. This environment name already exists." @@ -657,10 +662,10 @@ public String addNewEnv(EnvModel newEnv) { } else if (envActualList.stream() .anyMatch( en -> - en.getName().equals(newEnv.getName()) - && en.getType().equals(newEnv.getType()) - && en.getTenantId().equals(newEnv.getTenantId()) - && en.getEnvExists().equals("false"))) { + Objects.equals(en.getName(), newEnv.getName()) + && Objects.equals(en.getType(), newEnv.getType()) + && Objects.equals(en.getTenantId(), newEnv.getTenantId()) + && Objects.equals(en.getEnvExists(), "false"))) { Optional envAlreadyExistsInDeleted = envActualList.stream() .filter( @@ -677,7 +682,7 @@ public String addNewEnv(EnvModel newEnv) { Env env = new Env(); copyProperties(newEnv, env); - if (!envIdAlreadyExistsInDeleteStatus.equals("")) env.setId(envIdAlreadyExistsInDeleteStatus); + if (!"".equals(envIdAlreadyExistsInDeleteStatus)) env.setId(envIdAlreadyExistsInDeleteStatus); env.setEnvExists("true"); try { @@ -709,8 +714,8 @@ public Map addNewCluster(KwClustersModel kwClustersModel) { .getClusters("all", tenantId) .forEach( (k, v) -> { - if (v.getClusterName().equals(kwClustersModel.getClusterName()) - && v.getClusterType().equals(kwClustersModel.getClusterType())) { + if (Objects.equals(v.getClusterName(), kwClustersModel.getClusterName()) + && Objects.equals(v.getClusterType(), kwClustersModel.getClusterType())) { clusterNameAlreadyExists.set(true); } }); @@ -727,9 +732,9 @@ public Map addNewCluster(KwClustersModel kwClustersModel) { kwCluster.setClusterName(kwCluster.getClusterName().toUpperCase()); // only for new cluster requests on saas - if (kwCluster.getProtocol().equals("SSL") + if ("SSL".equals(kwCluster.getProtocol()) && kwCluster.getClusterId() == null - && kwInstallationType.equals("saas")) { + && "saas".equals(kwInstallationType)) { if (!savePublicKey(kwClustersModel, resultMap, tenantId, kwCluster)) { resultMap.put("result", "Failure. Unable to save public key."); return resultMap; @@ -804,7 +809,7 @@ public String deleteCluster(String clusterId) { List allEnvList = manageDatabase.getAllEnvList(tenantId); if (allEnvList.stream() - .anyMatch(env -> env.getClusterId().equals(Integer.parseInt(clusterId)))) { + .anyMatch(env -> Objects.equals(env.getClusterId(), Integer.parseInt(clusterId)))) { return "{\"result\":\"Not allowed to delete this cluster, as there are associated environments.\"}"; } @@ -883,11 +888,9 @@ private String getUserName() { } public List getAllTenants() { - if (manageDatabase - .getHandleDbRequests() - .getUsersInfo(getUserName()) - .getRole() - .equals(SUPERADMIN.name()) + if (SUPERADMIN + .name() + .equals(manageDatabase.getHandleDbRequests().getUsersInfo(getUserName()).getRole()) && commonUtilsService.getTenantId(getUserName()) == DEFAULT_TENANT_ID) { HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests(); List tenants = dbHandle.getTenants(); @@ -905,7 +908,7 @@ public List getAllTenants() { .filter( userInfo -> userInfo.getTenantId() == tenant.getTenantId() - && userInfo.getRole().equals(SUPERADMIN_ROLE)) + && Objects.equals(userInfo.getRole(), SUPERADMIN_ROLE)) .findFirst(); if (userFound.isPresent()) { kwTenantModel.setEmailId(userFound.get().getMailid()); @@ -988,7 +991,7 @@ public Map addTenantId(KwTenantModel kwTenantModel, boolean isEx if (kwTenantModel.isActiveTenant()) kwTenants.setIsActive("true"); else kwTenants.setIsActive("false"); - if (kwInstallationType.equals("saas")) + if ("saas".equals(kwInstallationType)) kwTenants.setLicenseExpiry( new Timestamp(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(DAYS_TRIAL_PERIOD))); else @@ -999,7 +1002,8 @@ public Map addTenantId(KwTenantModel kwTenantModel, boolean isEx addTenantStatus.put("result", manageDatabase.getHandleDbRequests().addNewTenant(kwTenants)); int tenantId = manageDatabase.getHandleDbRequests().getTenants().stream() - .filter(kwTenant -> kwTenant.getTenantName().equals(kwTenantModel.getTenantName())) + .filter( + kwTenant -> Objects.equals(kwTenant.getTenantName(), kwTenantModel.getTenantName())) .findFirst() .get() .getTenantId(); @@ -1037,7 +1041,7 @@ public KwTenantModel getMyTenantInfo() { ((new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss")) .format(tenant.get().getLicenseExpiry().getTime()))); kwTenantModel.setContactPerson(tenant.get().getContactPerson()); - kwTenantModel.setInTrialPhase(tenant.get().getInTrial().equals("true")); + kwTenantModel.setInTrialPhase("true".equals(tenant.get().getInTrial())); long timeInMilliSeconds = tenant.get().getLicenseExpiry().getTime() - System.currentTimeMillis(); long hours = TimeUnit.MILLISECONDS.toHours(timeInMilliSeconds); @@ -1047,7 +1051,7 @@ public KwTenantModel getMyTenantInfo() { kwTenantModel.setNumberOfDays("" + days); kwTenantModel.setNumberOfHours("" + hoursN); - kwTenantModel.setActiveTenant(tenant.get().getIsActive().equals("true")); + kwTenantModel.setActiveTenant("true".equals(tenant.get().getIsActive())); kwTenantModel.setOrgName(tenant.get().getOrgName()); if (commonUtilsService.isNotAuthorizedUser( @@ -1092,7 +1096,7 @@ public Map deleteTenant() { String result = manageDatabase.getHandleDbRequests().disableTenant(tenantId); - if (result.equals("success")) { + if ("success".equals(result)) { commonUtilsService.updateMetadata(tenantId, EntityType.TENANT, MetadataOperationType.DELETE); resultMap.put("result", "success"); resultMap.put("tenantId", tenantName); @@ -1113,7 +1117,7 @@ public Map updateTenant(String orgName) { int tenantId = commonUtilsService.getTenantId(getUserName()); String result = manageDatabase.getHandleDbRequests().updateTenant(tenantId, orgName); - if (result.equals("success")) { + if ("success".equals(result)) { resultMap.put("result", "success"); commonUtilsService.updateMetadata(tenantId, EntityType.TENANT, MetadataOperationType.UPDATE); } else { @@ -1148,7 +1152,7 @@ public Map udpateTenantExtension(String selectedTenantExtensionP selectedTenantExtensionPeriod, commonUtilsService.getLoginUrl()); - if (result.equals("success")) { + if ("success".equals(result)) { resultMap.put("result", "success"); } else { resultMap.put("result", "failure"); diff --git a/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java b/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java index 1b75484c20..f796addc8e 100644 --- a/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java +++ b/src/main/java/io/aiven/klaw/service/KafkaConnectControllerService.java @@ -111,7 +111,7 @@ public Map createConnectorRequest(KafkaConnectorRequestModel top if (kafkaConnectorList != null && kafkaConnectorList.size() > 0 - && !kafkaConnectorList.get(0).getTeamId().equals(topicRequestReq.getTeamId())) { + && !Objects.equals(kafkaConnectorList.get(0).getTeamId(), topicRequestReq.getTeamId())) { hashMapTopicReqRes.put("result", "Failure. This connector is owned by a different team."); return hashMapTopicReqRes; } @@ -124,7 +124,7 @@ public Map createConnectorRequest(KafkaConnectorRequestModel top int devTopicFound = (int) kafkaConnectorList.stream() - .filter(topic -> topic.getEnvironment().equals(syncCluster)) + .filter(topic -> Objects.equals(topic.getEnvironment(), syncCluster)) .count(); if (devTopicFound != 1) { if (getKafkaConnectEnvDetails(syncCluster) == null) { @@ -140,7 +140,7 @@ public Map createConnectorRequest(KafkaConnectorRequestModel top return hashMapTopicReqRes; } } - } else if (!topicRequestReq.getEnvironment().equals(syncCluster)) { + } else if (!Objects.equals(topicRequestReq.getEnvironment(), syncCluster)) { if (promotionOrderCheck) { hashMapTopicReqRes.put( "result", @@ -167,13 +167,14 @@ public Map createConnectorRequest(KafkaConnectorRequestModel top } // Ignore connector exists check if Update request - if (!topicRequestReq.getConnectortype().equals(TopicRequestTypes.Update.name())) { + if (!TopicRequestTypes.Update.name().equals(topicRequestReq.getConnectortype())) { boolean topicExists = false; if (kafkaConnectorList != null) { topicExists = kafkaConnectorList.stream() .anyMatch( - topicEx -> topicEx.getEnvironment().equals(topicRequestReq.getEnvironment())); + topicEx -> + Objects.equals(topicEx.getEnvironment(), topicRequestReq.getEnvironment())); } if (topicExists) { hashMapTopicReqRes.put( @@ -490,7 +491,7 @@ public Map approveConnectorRequests(String connectorId) throws K return resultMap; } - if (!connectorRequest.getConnectorStatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(connectorRequest.getConnectorStatus())) { resultMap.put("result", "This request does not exist anymore."); return resultMap; } @@ -504,7 +505,7 @@ public Map approveConnectorRequests(String connectorId) throws K HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests(); String updateTopicReqStatus; - if (connectorRequest.getConnectortype().equals(TopicRequestTypes.Claim.name())) { + if (TopicRequestTypes.Claim.name().equals(connectorRequest.getConnectortype())) { List allTopics = getConnectorsFromName(connectorRequest.getConnectorName(), tenantId); for (KwKafkaConnector allTopic : allTopics) { @@ -514,7 +515,7 @@ public Map approveConnectorRequests(String connectorId) throws K } updateTopicReqStatus = dbHandle.addToSyncConnectors(allTopics); - if (updateTopicReqStatus.equals("success")) + if ("success".equals(updateTopicReqStatus)) updateTopicReqStatus = dbHandle.updateConnectorRequestStatus(connectorRequest, userDetails); } else { Env envSelected = @@ -528,8 +529,9 @@ public Map approveConnectorRequests(String connectorId) throws K String protocol = kwClusters.getProtocol(); String kafkaConnectHost = kwClusters.getBootstrapServers(); - if (connectorRequest.getConnectortype().equals("Update")) // only config - updateTopicReqStatus = + if ("Update".equals(connectorRequest.getConnectortype())) // only config + { + updateTopicReqStatus = clusterApiService.approveConnectorRequests( connectorRequest.getConnectorName(), protocol, @@ -537,7 +539,7 @@ public Map approveConnectorRequests(String connectorId) throws K connectorRequest.getConnectorConfig(), kafkaConnectHost, tenantId); - else + } else { updateTopicReqStatus = clusterApiService.approveConnectorRequests( connectorRequest.getConnectorName(), @@ -546,7 +548,7 @@ public Map approveConnectorRequests(String connectorId) throws K jsonConnectorConfig, kafkaConnectHost, tenantId); - + } if (Objects.equals(updateTopicReqStatus, "success")) { setConnectorHistory(connectorRequest, userDetails, tenantId); updateTopicReqStatus = dbHandle.updateConnectorRequest(connectorRequest, userDetails); @@ -573,11 +575,12 @@ private void setConnectorHistory( List existingTopicHistory; List topicHistoryList = new ArrayList<>(); - if (connectorRequest.getConnectortype().equals(TopicRequestTypes.Update.name())) { + if (TopicRequestTypes.Update.name().equals(connectorRequest.getConnectortype())) { List existingTopicList = getConnectorsFromName(connectorRequest.getConnectorName(), tenantId); existingTopicList.stream() - .filter(topic -> topic.getEnvironment().equals(connectorRequest.getEnvironment())) + .filter( + topic -> Objects.equals(topic.getEnvironment(), connectorRequest.getEnvironment())) .findFirst() .ifPresent(a -> existingHistory.set(a.getHistory())); existingTopicHistory = objectMapper.readValue(existingHistory.get(), ArrayList.class); @@ -616,7 +619,7 @@ public String declineConnectorRequests(String connectorId, String reasonForDecli KafkaConnectorRequest connectorRequest = dbHandle.selectConnectorRequestsForConnector(Integer.parseInt(connectorId), tenantId); - if (!connectorRequest.getConnectorStatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(connectorRequest.getConnectorStatus())) { return "{\"result\":\"This request does not exist anymore.\"}"; } @@ -657,7 +660,9 @@ public Map createConnectorDeleteRequest(String connectorName, St List topics = getConnectorsFromName(connectorName, tenantId); Integer userTeamId = getMyTeamId(userDetails); - if (topics != null && topics.size() > 0 && !topics.get(0).getTeamId().equals(userTeamId)) { + if (topics != null + && topics.size() > 0 + && !Objects.equals(topics.get(0).getTeamId(), userTeamId)) { hashMap.put( "result", "Failure. Sorry, you cannot delete this connector, as you are not part of this team."); @@ -673,7 +678,8 @@ public Map createConnectorDeleteRequest(String connectorName, St Optional topicOb = getConnectorsFromName(connectorName, tenantId).stream() - .filter(topic -> topic.getEnvironment().equals(topicRequestReq.getEnvironment())) + .filter( + topic -> Objects.equals(topic.getEnvironment(), topicRequestReq.getEnvironment())) .findFirst(); if (manageDatabase @@ -735,10 +741,11 @@ public List getConnectorRequests( Comparator.comparing(KafkaConnectorRequest::getRequesttime))) .collect(Collectors.toList()); - if (!requestsType.equals("all") && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) + if (!"all".equals(requestsType) && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) topicReqs = topicReqs.stream() - .filter(topicRequest -> topicRequest.getConnectorStatus().equals(requestsType)) + .filter( + topicRequest -> Objects.equals(topicRequest.getConnectorStatus(), requestsType)) .collect(Collectors.toList()); topicReqs = getConnectorRequestsPaged(topicReqs, pageNo, currentPage); @@ -769,7 +776,7 @@ public Map createClaimConnectorRequest(String connectorName, Str Integer topicOwnerTeam = topics.get(0).getTeamId(); Optional topicOwnerContact = manageDatabase.getHandleDbRequests().selectAllUsersInfo(tenantId).stream() - .filter(user -> user.getTeamId().equals(topicOwnerTeam)) + .filter(user -> Objects.equals(user.getTeamId(), topicOwnerTeam)) .findFirst(); Integer userTeamId = getMyTeamId(userDetails); @@ -873,7 +880,7 @@ public ConnectorOverview getConnectorOverview(String connectorNamesearch) { topicInfo.setConnectorConfig(topic.getConnectorConfig()); topicInfo.setTeamName(manageDatabase.getTeamNameFromTeamId(tenantId, topic.getTeamId())); - if (syncCluster != null && syncCluster.equals(topic.getEnvironment())) { + if (Objects.equals(syncCluster, topic.getEnvironment())) { topicOverview.setTopicDocumentation(topic.getDocumentation()); topicOverview.setTopicIdForDocumentation(topic.getConnectorId()); } @@ -905,7 +912,7 @@ public ConnectorOverview getConnectorOverview(String connectorNamesearch) { for (KafkaConnectorModel topicInfo : topicInfoList) { // show edit button only for restricted envs - if (topicOwnerTeam.equals(loggedInUserTeam) + if (Objects.equals(topicOwnerTeam, loggedInUserTeam) && reqTopicsEnvsList.contains(topicInfo.getEnvironmentId())) { topicInfo.setShowEditConnector(true); } @@ -913,7 +920,7 @@ public ConnectorOverview getConnectorOverview(String connectorNamesearch) { topicOverview.setTopicInfoList(topicInfoList); try { - if (topicOwnerTeam.equals(loggedInUserTeam)) { + if (Objects.equals(topicOwnerTeam, loggedInUserTeam)) { topicOverview.setPromotionDetails( getConnectorPromotionEnv(connectorNamesearch, connectors, tenantId)); @@ -968,7 +975,7 @@ public Map getConnectorDetailsPerEnv(String envId, String connec } connectors = connectors.stream() - .filter(topic -> topic.getEnvironment().equals(envId)) + .filter(topic -> Objects.equals(topic.getEnvironment(), envId)) .collect(Collectors.toList()); } @@ -990,7 +997,7 @@ public Map getConnectorDetailsPerEnv(String envId, String connec .selectAllTeamsOfUsers(getUserName(), tenantId) .get(0) .getTeamname(); - if (!loggedInUserTeam.equals(connectorModel.getTeamName())) { + if (!Objects.equals(loggedInUserTeam, connectorModel.getTeamName())) { hashMap.put("error", "Sorry, your team does not own the connector !!"); return hashMap; } @@ -1025,7 +1032,7 @@ private Map getConnectorPromotionEnv( String lastEnv = envList.get(envList.size() - 1); AtomicReference sourceConnectorConfig = new AtomicReference<>(""); kafkaConnectors.stream() - .filter(kwKafkaConnector -> kwKafkaConnector.getEnvironment().equals(lastEnv)) + .filter(kwKafkaConnector -> Objects.equals(kwKafkaConnector.getEnvironment(), lastEnv)) .findFirst() .ifPresent(a -> sourceConnectorConfig.set(a.getConnectorConfig())); @@ -1073,7 +1080,7 @@ public Map saveConnectorDocumentation(KafkaConnectorModel topicI Integer loggedInUserTeam = getMyTeamId(getUserName()); - if (topicOwnerTeam.equals(loggedInUserTeam)) { + if (Objects.equals(topicOwnerTeam, loggedInUserTeam)) { saveResult.put( "result", manageDatabase.getHandleDbRequests().updateConnectorDocumentation(topic)); } else saveResult.put("result", "failure"); @@ -1101,9 +1108,9 @@ private List getConnectorRequestModels( if (fromSyncTopics) { // show approving info only before approvals - if (!topicRequestModel.getConnectorStatus().equals(RequestStatus.approved.name())) { + if (!RequestStatus.approved.name().equals(topicRequestModel.getConnectorStatus())) { if (topicRequestModel.getConnectortype() != null - && topicRequestModel.getConnectortype().equals(TopicRequestTypes.Claim.name())) { + && TopicRequestTypes.Claim.name().equals(topicRequestModel.getConnectortype())) { List topics = getConnectorsFromName(topicRequestModel.getConnectorName(), tenantId); topicRequestModel.setApprovingTeamDetails( @@ -1134,7 +1141,8 @@ private String updateApproverInfo( StringBuilder approvingInfo = new StringBuilder("Team : " + teamName + ", Users : "); for (UserInfo userInfo : userList) { - if (approverRoles.contains(userInfo.getRole()) && !requestor.equals(userInfo.getUsername())) + if (approverRoles.contains(userInfo.getRole()) + && !Objects.equals(requestor, userInfo.getUsername())) approvingInfo.append(userInfo.getUsername()).append(","); } @@ -1234,7 +1242,7 @@ public Env getKafkaConnectEnvDetails(String envId) { manageDatabase .getKafkaConnectEnvList(commonUtilsService.getTenantId(getUserName())) .stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } @@ -1249,7 +1257,7 @@ private List getConvertedEnvs(List allEnvs, List selectedEn List newEnvList = new ArrayList<>(); for (String env : selectedEnvs) { for (Env env1 : allEnvs) { - if (env.equals(env1.getId())) { + if (Objects.equals(env, env1.getId())) { newEnvList.add(env1.getName()); break; } diff --git a/src/main/java/io/aiven/klaw/service/KafkaConnectSyncControllerService.java b/src/main/java/io/aiven/klaw/service/KafkaConnectSyncControllerService.java index e643b1a2cb..1d05c3388a 100644 --- a/src/main/java/io/aiven/klaw/service/KafkaConnectSyncControllerService.java +++ b/src/main/java/io/aiven/klaw/service/KafkaConnectSyncControllerService.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; @@ -105,18 +106,18 @@ public Map updateSyncConnectors(List updat if (existingTopics != null) { for (KwKafkaConnector existingTopic : existingTopics) { - if (existingTopic.getEnvironment().equals(syncCluster)) { - if (!manageDatabase - .getTeamNameFromTeamId(tenantId, existingTopic.getTeamId()) - .equals(topicUpdate.getTeamSelected()) - && !topicUpdate.getEnvSelected().equals(syncCluster)) { + if (Objects.equals(existingTopic.getEnvironment(), syncCluster)) { + if (!Objects.equals( + manageDatabase.getTeamNameFromTeamId(tenantId, existingTopic.getTeamId()), + topicUpdate.getTeamSelected()) + && !Objects.equals(topicUpdate.getEnvSelected(), syncCluster)) { erroredTopics.append(topicUpdate.getConnectorName()).append(" "); topicsWithDiffTeams = true; } break; } } - } else if (!topicUpdate.getEnvSelected().equals(syncCluster)) { + } else if (!Objects.equals(topicUpdate.getEnvSelected(), syncCluster)) { erroredTopicsExist.append(topicUpdate.getConnectorName()).append(" "); if (checkInPromotionOrder( topicUpdate.getConnectorName(), topicUpdate.getEnvSelected(), orderOfEnvs)) @@ -153,7 +154,7 @@ public Map updateSyncConnectors(List updat kafkaConnectorList.add(t); } else { for (KwKafkaConnector existingTopic : existingTopics) { - if (existingTopic.getEnvironment().equals(topicUpdate.getEnvSelected())) { + if (Objects.equals(existingTopic.getEnvironment(), topicUpdate.getEnvSelected())) { t = existingTopic; t.setTeamId( manageDatabase.getTeamIdFromTeamName(tenantId, topicUpdate.getTeamSelected())); @@ -163,11 +164,9 @@ public Map updateSyncConnectors(List updat t.setExistingConnector(true); kafkaConnectorList.add(t); topicAdded = true; - } else if (!existingTopic - .getTeamId() - .equals( - manageDatabase.getTeamIdFromTeamName( - tenantId, topicUpdate.getTeamSelected()))) { + } else if (!Objects.equals( + existingTopic.getTeamId(), + manageDatabase.getTeamIdFromTeamName(tenantId, topicUpdate.getTeamSelected()))) { t = existingTopic; t.setTeamId( manageDatabase.getTeamIdFromTeamName(tenantId, topicUpdate.getTeamSelected())); @@ -184,7 +183,7 @@ public Map updateSyncConnectors(List updat boolean envFound = false; if (existingTopics != null) { for (KwKafkaConnector existingTopic : existingTopics) { - if (existingTopic.getEnvironment().equals(topicUpdate.getEnvSelected())) { + if (Objects.equals(existingTopic.getEnvironment(), topicUpdate.getEnvSelected())) { envFound = true; break; } @@ -264,7 +263,7 @@ private List handleConnectorDeletes( List updatedSyncTopics, List updatedSyncTopicsDelete) { List updatedSyncTopicsUpdated = new ArrayList<>(); for (SyncConnectorUpdates updatedSyncTopic : updatedSyncTopics) { - if (updatedSyncTopic.getTeamSelected().equals("REMOVE FROM KLAW")) { + if ("REMOVE FROM KLAW".equals(updatedSyncTopic.getTeamSelected())) { updatedSyncTopicsDelete.add(Integer.parseInt(updatedSyncTopic.getSequence())); } else updatedSyncTopicsUpdated.add(updatedSyncTopic); } @@ -353,9 +352,9 @@ public List getSyncConnectors( for (KafkaConnectorModel kafkaConnectorModel : kafkaConnectorModelSourceList) { if (!allConnectors.contains(kafkaConnectorModel.getConnectorName())) { for (KafkaConnectorModel kafkaConnectorModelCluster : kafkaConnectorModelClusterList) { - if (kafkaConnectorModelCluster - .getConnectorName() - .equals(kafkaConnectorModel.getConnectorName())) { + if (Objects.equals( + kafkaConnectorModelCluster.getConnectorName(), + kafkaConnectorModel.getConnectorName())) { kafkaConnectorModelCluster.setRemarks("DELETED"); // kafkaConnectorModelCluster.setPossibleTeams(teamList); // possibleTeams.add("REMOVE FROM KLAW"); @@ -497,7 +496,7 @@ public Env getKafkaConnectorEnvDetails(String envId) { manageDatabase .getKafkaConnectEnvList(commonUtilsService.getTenantId(getUserName())) .stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } diff --git a/src/main/java/io/aiven/klaw/service/MailUtils.java b/src/main/java/io/aiven/klaw/service/MailUtils.java index d43522080f..8f9c4d74e5 100644 --- a/src/main/java/io/aiven/klaw/service/MailUtils.java +++ b/src/main/java/io/aiven/klaw/service/MailUtils.java @@ -193,13 +193,13 @@ void sendMailRegisteredUserSaas( registrationRequest, registerUserInfo.getUsername(), registerUserInfo.getFullname()); subject = "New User Registration request"; - if (!registerUserInfo - .getMailid() - .equals(manageDatabase.getKwPropertyValue(SUPERUSER_MAILID_KEY, tenantId))) + if (!Objects.equals( + registerUserInfo.getMailid(), + manageDatabase.getKwPropertyValue(SUPERUSER_MAILID_KEY, tenantId))) sendMailToAdmin(subject, formattedStr, tenantId, loginUrl); // Sending to user - if (registerUserInfo.getTeam().equals(KwConstants.INFRATEAM)) { + if (KwConstants.INFRATEAM.equals(registerUserInfo.getTeam())) { registrationRequest = manageDatabase.getKwPropertyValue(REGISTER_USER_SAASADMIN_TOUSER_KEY, tenantId); formattedStr = @@ -253,9 +253,9 @@ void sendMailRegisteredUser( registerUserInfo.getRole()); subject = "New User Registration request"; - if (!registerUserInfo - .getMailid() - .equals(manageDatabase.getKwPropertyValue(SUPERUSER_MAILID_KEY, tenantId))) + if (!Objects.equals( + registerUserInfo.getMailid(), + manageDatabase.getKwPropertyValue(SUPERUSER_MAILID_KEY, tenantId))) sendMailToAdmin(subject, formattedStr, tenantId, loginUrl); // Sending to user diff --git a/src/main/java/io/aiven/klaw/service/MetricsControllerService.java b/src/main/java/io/aiven/klaw/service/MetricsControllerService.java index 54f2324d0b..40824450f2 100644 --- a/src/main/java/io/aiven/klaw/service/MetricsControllerService.java +++ b/src/main/java/io/aiven/klaw/service/MetricsControllerService.java @@ -50,7 +50,7 @@ private Integer getMyTeamId(String userName) { fixedRateString = "${klaw.monitoring.metrics.collectinterval.ms:60000}", initialDelay = 60000) private void loadMetricsScheduler() { - if (enableMetrics.equals("false")) return; + if ("false".equals(enableMetrics)) return; log.info("Scheduled job : Collect metrics"); diff --git a/src/main/java/io/aiven/klaw/service/RolesPermissionsControllerService.java b/src/main/java/io/aiven/klaw/service/RolesPermissionsControllerService.java index e0fed9ac4a..d124a7fddb 100644 --- a/src/main/java/io/aiven/klaw/service/RolesPermissionsControllerService.java +++ b/src/main/java/io/aiven/klaw/service/RolesPermissionsControllerService.java @@ -79,7 +79,7 @@ public Map>> getPermissions(boolean isExternal mapList = new ArrayList<>(); for (String perm : permsList) { Map perMap = new HashMap<>(); - if (kwInstallationType.equals("saas") && perm.equals("ADD_TENANT")) { + if ("saas".equals(kwInstallationType) && "ADD_TENANT".equals(perm)) { // do nothing } else { perMap.put(perm, existingPerms.get(role).contains(perm)); @@ -131,8 +131,8 @@ public Map updatePermissions(KwRolesPermissionsModel[] permissio tmpKwRolePermModel.setRoleId(permKey.substring(0, indexOfDelimiter)); tmpKwRolePermModel.setPermission(permKey.substring(indexOfDelimiter + 5)); - if (isPermEnabled.equals("true")) kwRolesPermissionsAdd.add(tmpKwRolePermModel); - else if (isPermEnabled.equals("false")) kwRolesPermissionsDelete.add(tmpKwRolePermModel); + if ("true".equals(isPermEnabled)) kwRolesPermissionsAdd.add(tmpKwRolePermModel); + else if ("false".equals(isPermEnabled)) kwRolesPermissionsDelete.add(tmpKwRolePermModel); } if (kwRolesPermissionsAdd.size() > 0) @@ -155,7 +155,7 @@ public Map deleteRole(String roleId) { return deleteRoleStatus; } - if (roleId.equals(KwConstants.USER_ROLE) || roleId.equals(KwConstants.SUPERADMIN_ROLE)) { + if (KwConstants.USER_ROLE.equals(roleId) || KwConstants.SUPERADMIN_ROLE.equals(roleId)) { deleteRoleStatus.put("result", "Not Allowed"); return deleteRoleStatus; } @@ -204,23 +204,23 @@ protected List getApproverRoles(String requestType, int tenantId) { List> entryDets = permissionsListEntry.getValue(); for (Map entryDet : entryDets) { for (Map.Entry stringBooleanEntry : entryDet.entrySet()) { - if (stringBooleanEntry.getValue().equals(true)) { - if (requestType.equals("SUBSCRIPTIONS") - && stringBooleanEntry - .getKey() - .equals(PermissionType.APPROVE_SUBSCRIPTIONS.name())) { + if (Boolean.TRUE.equals(stringBooleanEntry.getValue())) { + if ("SUBSCRIPTIONS".equals(requestType) + && PermissionType.APPROVE_SUBSCRIPTIONS + .name() + .equals(stringBooleanEntry.getKey())) { approverRoles.add(permissionsListEntry.getKey()); break; - } else if (requestType.equals("TOPICS") - && stringBooleanEntry.getKey().equals(PermissionType.APPROVE_TOPICS.name())) { + } else if ("TOPICS".equals(requestType) + && PermissionType.APPROVE_TOPICS.name().equals(stringBooleanEntry.getKey())) { approverRoles.add(permissionsListEntry.getKey()); break; - } else if (requestType.equals("SCHEMAS") - && stringBooleanEntry.getKey().equals(PermissionType.APPROVE_SCHEMAS.name())) { + } else if ("SCHEMAS".equals(requestType) + && PermissionType.APPROVE_SCHEMAS.name().equals(stringBooleanEntry.getKey())) { approverRoles.add(permissionsListEntry.getKey()); break; - } else if (requestType.equals("CONNECTORS") - && stringBooleanEntry.getKey().equals(PermissionType.APPROVE_SCHEMAS.name())) { + } else if ("CONNECTORS".equals(requestType) + && PermissionType.APPROVE_SCHEMAS.name().equals(stringBooleanEntry.getKey())) { approverRoles.add(permissionsListEntry.getKey()); break; } diff --git a/src/main/java/io/aiven/klaw/service/SaasService.java b/src/main/java/io/aiven/klaw/service/SaasService.java index 3423373835..7101b3cece 100644 --- a/src/main/java/io/aiven/klaw/service/SaasService.java +++ b/src/main/java/io/aiven/klaw/service/SaasService.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.UUID; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -48,7 +49,8 @@ public Map approveUserSaas(RegisterUserInfoModel newUser) throws // check if user exists List userList = manageDatabase.getHandleDbRequests().selectAllUsersAllTenants(); - if (userList.stream().anyMatch(user -> user.getUsername().equals(newUser.getMailid()))) { + if (userList.stream() + .anyMatch(user -> Objects.equals(user.getUsername(), newUser.getMailid()))) { resultMap.put("error", "User already exists. You may login."); return resultMap; } @@ -70,7 +72,7 @@ public Map approveUserSaas(RegisterUserInfoModel newUser) throws envsClustersTenantsControllerService.addTenantId(kwTenantModel, false); // create INFRATEAM and STAGINGTEAM - if (addTenantResult.get("result").equals("success")) { + if ("success".equals(addTenantResult.get("result"))) { tenantId = Integer.parseInt(addTenantResult.get("tenantId")); Map teamAddMap = @@ -160,7 +162,7 @@ private boolean createNewUserForActivation( newUserTarget.setRegisteredTime(new Timestamp(System.currentTimeMillis())); Map userRegMap = usersTeamsControllerService.registerUser(newUserTarget, false); - if (!userRegMap.get("result").equals("success")) { + if (!"success".equals(userRegMap.get("result"))) { resultMap.put("error", "Something went wrong. Please try again."); return true; } @@ -196,7 +198,7 @@ private boolean createUserForExistingTenant( String finalNewTenantName = newTenantName; tenantId = tenantMap.entrySet().stream() - .filter(obj -> obj.getValue().equals(finalNewTenantName)) + .filter(obj -> Objects.equals(obj.getValue(), finalNewTenantName)) .findFirst() .get() .getKey(); @@ -206,7 +208,7 @@ private boolean createUserForExistingTenant( newUserTarget.setRole(KwConstants.USER_ROLE); Map userRegMap = usersTeamsControllerService.registerUser(newUserTarget, false); - if (!userRegMap.get("result").equals("success")) { + if (!"success".equals(userRegMap.get("result"))) { resultMap.put("error", "Something went wrong. Please try again."); return true; } else { @@ -251,7 +253,8 @@ private boolean handleValidations( // check if user exists List userList = manageDatabase.getHandleDbRequests().selectAllUsersAllTenants(); - if (userList.stream().anyMatch(user -> user.getUsername().equals(newUser.getMailid()))) { + if (userList.stream() + .anyMatch(user -> Objects.equals(user.getUsername(), newUser.getMailid()))) { resultMap.put("error", "User already exists. You may login."); return true; } @@ -259,14 +262,13 @@ private boolean handleValidations( List registerUserInfoList = manageDatabase.getHandleDbRequests().selectAllRegisterUsersInfo(); if (registerUserInfoList.stream() - .anyMatch(user -> user.getUsername().equals(newUser.getMailid()))) { + .anyMatch(user -> Objects.equals(user.getUsername(), newUser.getMailid()))) { resultMap.put("error", "Registration already exists. You may login."); return true; } - if (newUser - .getTenantName() - .equals("default")) { // don't allow users to be created on default tenant + if ("default" + .equals(newUser.getTenantName())) { // don't allow users to be created on default tenant resultMap.put("error", "You cannot request users for default tenant."); return true; } @@ -297,14 +299,14 @@ public Map getActivationInfo(String activationId) { if (registerUserInfoModel == null) { resultMap.put("result", "failure"); return resultMap; - } else if (registerUserInfoModel.getStatus().equals("APPROVED")) { + } else if ("APPROVED".equals(registerUserInfoModel.getStatus())) { resultMap.put("result", "already_activated"); return resultMap; - } else if (registerUserInfoModel.getStatus().equals("PENDING")) { + } else if ("PENDING".equals(registerUserInfoModel.getStatus())) { Map result; try { result = approveUserSaas(registerUserInfoModel); - if (result.get("result").equals("success")) { + if ("success".equals(result.get("result"))) { resultMap.put("result", "success"); } else resultMap.put("result", "othererror"); } catch (Exception e) { diff --git a/src/main/java/io/aiven/klaw/service/SchemaRegstryControllerService.java b/src/main/java/io/aiven/klaw/service/SchemaRegstryControllerService.java index cdc02e65ea..b9662be0ea 100644 --- a/src/main/java/io/aiven/klaw/service/SchemaRegstryControllerService.java +++ b/src/main/java/io/aiven/klaw/service/SchemaRegstryControllerService.java @@ -62,11 +62,12 @@ public List getSchemaRequests( .collect(Collectors.toList()); // request status filtering - if (!requestsType.equals("all") && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) + if (!"all".equals(requestsType) && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) if (schemaReqs != null) { schemaReqs = schemaReqs.stream() - .filter(schemaRequest -> schemaRequest.getTopicstatus().equals(requestsType)) + .filter( + schemaRequest -> Objects.equals(schemaRequest.getTopicstatus(), requestsType)) .collect(Collectors.toList()); } @@ -90,7 +91,7 @@ public List getSchemaRequests( copyProperties(schemaReq, schemaRequestModel); // show approving info only before approvals - if (!schemaRequestModel.getTopicstatus().equals(RequestStatus.approved.name())) { + if (!RequestStatus.approved.name().equals(schemaRequestModel.getTopicstatus())) { schemaRequestModel.setApprovingTeamDetails( updateApproverInfo( userList, @@ -110,7 +111,8 @@ private String updateApproverInfo( StringBuilder approvingInfo = new StringBuilder("Team : " + teamName + ", Users : "); for (UserInfo userInfo : userList) { - if (approverRoles.contains(userInfo.getRole()) && !requestor.equals(userInfo.getUsername())) + if (approverRoles.contains(userInfo.getRole()) + && !Objects.equals(requestor, userInfo.getUsername())) approvingInfo.append(userInfo.getUsername()).append(","); } @@ -196,7 +198,7 @@ public String execSchemaRequests(String avroSchemaId) throws KlawException { .getHandleDbRequests() .selectSchemaRequest(Integer.parseInt(avroSchemaId), tenantId); - if (schemaRequest.getUsername().equals(userDetails)) + if (Objects.equals(schemaRequest.getUsername(), userDetails)) return "{\"result\":\"You are not allowed to approve your own schema requests.\"}"; List allowedEnvIdList = getEnvsFromUserId(getUserName()); @@ -301,7 +303,7 @@ public String uploadSchema(SchemaRequestModel schemaRequest) { // tenant filtering Integer topicOwnerTeam = getFilteredTopicsForTenant(topicsSearchList).get(0).getTeamId(); - if (!userTeamId.equals(topicOwnerTeam)) { + if (!Objects.equals(userTeamId, topicOwnerTeam)) { return "No topic selected Or Not authorized to register schema for this topic."; } @@ -322,8 +324,9 @@ public String uploadSchema(SchemaRequestModel schemaRequest) { schemaReqs.stream() .filter( schemaRequest1 -> - schemaRequest1.getTopicstatus().equals("created") - && schemaRequest1.getTopicname().equals(schemaRequest.getTopicname())) + "created".equals(schemaRequest1.getTopicstatus()) + && Objects.equals( + schemaRequest1.getTopicname(), schemaRequest.getTopicname())) .collect(Collectors.toList()); if (schemaReqs.size() > 0) { return "Failure. A request already exists for this topic."; diff --git a/src/main/java/io/aiven/klaw/service/ServerConfigService.java b/src/main/java/io/aiven/klaw/service/ServerConfigService.java index 8b5477fe11..9657ef371a 100644 --- a/src/main/java/io/aiven/klaw/service/ServerConfigService.java +++ b/src/main/java/io/aiven/klaw/service/ServerConfigService.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -87,7 +88,7 @@ public List getAllProps() { private boolean checkPropertyExists(List props, String key) { for (ServerConfigProperties serverProps : props) { - if (serverProps.getKey().equals(key)) return true; + if (Objects.equals(serverProps.getKey(), key)) return true; } return false; } @@ -113,7 +114,7 @@ public List> getAllEditableProps() { kwVal = stringStringEntry.getValue().get("kwvalue"); resultMap.put("kwkey", kwKey); - if (kwKey.equals(KwConstants.TENANT_CONFIG_PROPERTY)) { + if (KwConstants.TENANT_CONFIG_PROPERTY.equals(kwKey)) { ObjectMapper objectMapper = new ObjectMapper(); TenantConfig dynamicObj; try { @@ -169,7 +170,7 @@ public Map updateKwCustomProperty(KwPropertiesModel kwProperties } try { - if (kwKey.equals(KwConstants.TENANT_CONFIG_PROPERTY)) { + if (KwConstants.TENANT_CONFIG_PROPERTY.equals(kwKey)) { ObjectMapper objectMapper = new ObjectMapper(); TenantConfig dynamicObj; try { @@ -199,7 +200,7 @@ public Map updateKwCustomProperty(KwPropertiesModel kwProperties KwProperties kwProperties = new KwProperties(); copyProperties(kwPropertiesModel, kwProperties); String res = manageDatabase.getHandleDbRequests().updateKwProperty(kwProperties, tenantId); - if (res.equals("success")) + if ("success".equals(res)) commonUtilsService.updateMetadata( tenantId, EntityType.PROPERTIES, MetadataOperationType.CREATE); response.put("result", "success"); @@ -420,7 +421,7 @@ private boolean validateTenantConfig(TenantConfig dynamicObj, int tenantId) { public Env getEnvDetails(String envId, int tenantId) { Optional envFound = manageDatabase.getKafkaEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } @@ -428,7 +429,7 @@ public Env getEnvDetails(String envId, int tenantId) { public Env getKafkaConnectEnvDetails(String envId, int tenantId) { Optional envFound = manageDatabase.getKafkaConnectEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } @@ -436,7 +437,10 @@ public Env getKafkaConnectEnvDetails(String envId, int tenantId) { public Env getEnvDetailsFromName(String envName, Integer tenantId) { Optional envFound = manageDatabase.getKafkaEnvList(tenantId).stream() - .filter(env -> env.getName().equals(envName) && env.getTenantId().equals(tenantId)) + .filter( + env -> + Objects.equals(env.getName(), envName) + && Objects.equals(env.getTenantId(), tenantId)) .findFirst(); return envFound.orElse(null); } @@ -459,7 +463,7 @@ public Map testClusterApiConnection(String clusterApiUrl) { Map hashMap = new HashMap<>(); int tenantId = commonUtilsService.getTenantId(getUserName()); String clusterApiStatus = clusterApiService.getClusterApiStatus(clusterApiUrl, true, tenantId); - if (clusterApiStatus.equals("ONLINE")) clusterApiStatus = "successful."; + if ("ONLINE".equals(clusterApiStatus)) clusterApiStatus = "successful."; else clusterApiStatus = "failure."; hashMap.put("result", clusterApiStatus); return hashMap; @@ -471,7 +475,7 @@ private Object getPrincipal() { private Integer getTenantIdFromName(String tenantName) { return manageDatabase.getTenantMap().entrySet().stream() - .filter(obj -> obj.getValue().equals(tenantName)) + .filter(obj -> Objects.equals(obj.getValue(), tenantName)) .findFirst() .get() .getKey(); diff --git a/src/main/java/io/aiven/klaw/service/TopicControllerService.java b/src/main/java/io/aiven/klaw/service/TopicControllerService.java index b6f70f03f5..86b15c4ff8 100644 --- a/src/main/java/io/aiven/klaw/service/TopicControllerService.java +++ b/src/main/java/io/aiven/klaw/service/TopicControllerService.java @@ -116,7 +116,7 @@ public Map createTopicsRequest(TopicRequestModel topicRequestReq if (topics != null && topics.size() > 0 - && !topics.get(0).getTeamId().equals(topicRequestReq.getTeamId())) { + && !Objects.equals(topics.get(0).getTeamId(), topicRequestReq.getTeamId())) { hashMapTopicReqRes.put("result", "Failure. This topic is owned by a different team."); return hashMapTopicReqRes; } @@ -128,7 +128,9 @@ public Map createTopicsRequest(TopicRequestModel topicRequestReq if (promotionOrderCheck) { int devTopicFound = (int) - topics.stream().filter(topic -> topic.getEnvironment().equals(syncCluster)).count(); + topics.stream() + .filter(topic -> Objects.equals(topic.getEnvironment(), syncCluster)) + .count(); if (devTopicFound != 1) { if (getEnvDetails(syncCluster) == null) { hashMapTopicReqRes.put("result", "Failure. This topic does not exist in base cluster"); @@ -142,7 +144,7 @@ public Map createTopicsRequest(TopicRequestModel topicRequestReq return hashMapTopicReqRes; } } - } else if (!topicRequestReq.getEnvironment().equals(syncCluster)) { + } else if (!Objects.equals(topicRequestReq.getEnvironment(), syncCluster)) { if (promotionOrderCheck) { hashMapTopicReqRes.put( "result", @@ -169,13 +171,14 @@ public Map createTopicsRequest(TopicRequestModel topicRequestReq } // Ignore topic exists check if Update request - if (!topicRequestReq.getTopictype().equals(TopicRequestTypes.Update.name())) { + if (!TopicRequestTypes.Update.name().equals(topicRequestReq.getTopictype())) { boolean topicExists = false; if (topics != null) { topicExists = topics.stream() .anyMatch( - topicEx -> topicEx.getEnvironment().equals(topicRequestReq.getEnvironment())); + topicEx -> + Objects.equals(topicEx.getEnvironment(), topicRequestReq.getEnvironment())); } if (topicExists) { hashMapTopicReqRes.put( @@ -190,7 +193,7 @@ public Map createTopicsRequest(TopicRequestModel topicRequestReq validateParameters(topicRequestReq, env, topicPartitions, topicRf); String validTopicStatus = isValidTopicMap.get("status"); - if (validTopicStatus.equals("true")) { + if ("true".equals(validTopicStatus)) { TopicRequest topicRequestDao = new TopicRequest(); copyProperties(topicRequestReq, topicRequestDao); topicRequestDao.setTenantId(tenantId); @@ -284,7 +287,9 @@ public Map createTopicDeleteRequest(String topicName, String env List topics = getTopicFromName(topicName, tenantId); Integer userTeamId = getMyTeamId(userDetails); - if (topics != null && topics.size() > 0 && !topics.get(0).getTeamId().equals(userTeamId)) { + if (topics != null + && topics.size() > 0 + && !Objects.equals(topics.get(0).getTeamId(), userTeamId)) { hashMap.put( "result", "Failure. Sorry, you cannot delete this topic, as you are not part of this team."); @@ -301,7 +306,8 @@ public Map createTopicDeleteRequest(String topicName, String env Optional topicOb = getTopicFromName(topicName, tenantId).stream() - .filter(topic -> topic.getEnvironment().equals(topicRequestReq.getEnvironment())) + .filter( + topic -> Objects.equals(topic.getEnvironment(), topicRequestReq.getEnvironment())) .findFirst(); if (manageDatabase @@ -383,7 +389,7 @@ public Map createClaimTopicRequest(String topicName, String env) Integer topicOwnerTeamId = topics.get(0).getTeamId(); Optional topicOwnerContact = manageDatabase.getHandleDbRequests().selectAllUsersInfo(tenantId).stream() - .filter(user -> user.getTeamId().equals(topicOwnerTeamId)) + .filter(user -> Objects.equals(user.getTeamId(), topicOwnerTeamId)) .findFirst(); // String userTeam = dbHandle.getUsersInfo(userDetails).getTeam(); @@ -444,10 +450,10 @@ public List getTopicRequests( .sorted(Collections.reverseOrder(Comparator.comparing(TopicRequest::getRequesttime))) .collect(Collectors.toList()); - if (!requestsType.equals("all") && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) + if (!"all".equals(requestsType) && EnumUtils.isValidEnum(RequestStatus.class, requestsType)) topicReqs = topicReqs.stream() - .filter(topicRequest -> topicRequest.getTopicstatus().equals(requestsType)) + .filter(topicRequest -> Objects.equals(topicRequest.getTopicstatus(), requestsType)) .collect(Collectors.toList()); topicReqs = getTopicRequestsPaged(topicReqs, pageNo, currentPage); @@ -503,7 +509,7 @@ public Map getTopicTeamOnly(String topicName, String patternType log.debug("getTopicTeamOnly {} {}", topicName, patternType); Map teamMap = new HashMap<>(); int tenantId = commonUtilsService.getTenantId(getUserName()); - if (patternType.equals("PREFIXED")) { + if ("PREFIXED".equals(patternType)) { List topics = manageDatabase.getHandleDbRequests().getAllTopics(tenantId); // tenant filtering @@ -616,9 +622,9 @@ private List getTopicRequestModels( if (fromSyncTopics) { // show approving info only before approvals - if (!topicRequestModel.getTopicstatus().equals(RequestStatus.approved.name())) { + if (!RequestStatus.approved.name().equals(topicRequestModel.getTopicstatus())) { if (topicRequestModel.getTopictype() != null - && topicRequestModel.getTopictype().equals(TopicRequestTypes.Claim.name())) { + && TopicRequestTypes.Claim.name().equals(topicRequestModel.getTopictype())) { List topics = getTopicFromName(topicRequestModel.getTopicname(), tenantId); topicRequestModel.setApprovingTeamDetails( updateApproverInfo( @@ -648,7 +654,8 @@ private String updateApproverInfo( StringBuilder approvingInfo = new StringBuilder("Team : " + teamName + ", Users : "); for (UserInfo userInfo : userList) { - if (approverRoles.contains(userInfo.getRole()) && !requestor.equals(userInfo.getUsername())) + if (approverRoles.contains(userInfo.getRole()) + && !Objects.equals(requestor, userInfo.getUsername())) approvingInfo.append(userInfo.getUsername()).append(","); } @@ -684,10 +691,10 @@ public String approveTopicRequests(String topicId) throws KlawException { .getHandleDbRequests() .selectTopicRequestsForTopic(Integer.parseInt(topicId), tenantId); - if (topicRequest.getRequestor().equals(userDetails)) + if (Objects.equals(topicRequest.getRequestor(), userDetails)) return "{\"result\":\"You are not allowed to approve your own topic requests.\"}"; - if (!topicRequest.getTopicstatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(topicRequest.getTopicstatus())) { return "{\"result\":\"This request does not exist anymore.\"}"; } @@ -698,7 +705,7 @@ public String approveTopicRequests(String topicId) throws KlawException { HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests(); String updateTopicReqStatus; - if (topicRequest.getTopictype().equals(TopicRequestTypes.Claim.name())) { + if (TopicRequestTypes.Claim.name().equals(topicRequest.getTopictype())) { List allTopics = getTopicFromName(topicRequest.getTopicname(), tenantId); for (Topic allTopic : allTopics) { allTopic.setTeamId(topicRequest.getTeamId()); // for claim reqs, team stored in description @@ -706,7 +713,7 @@ public String approveTopicRequests(String topicId) throws KlawException { } updateTopicReqStatus = dbHandle.addToSynctopics(allTopics); - if (updateTopicReqStatus.equals("success")) + if ("success".equals(updateTopicReqStatus)) updateTopicReqStatus = dbHandle.updateTopicRequestStatus(topicRequest, userDetails); } else { ResponseEntity response = @@ -720,7 +727,7 @@ public String approveTopicRequests(String topicId) throws KlawException { updateTopicReqStatus = response.getBody(); - if (Objects.equals(response.getBody(), "success")) { + if ("success".equals(response.getBody())) { setTopicHistory(topicRequest, userDetails, tenantId); updateTopicReqStatus = dbHandle.updateTopicRequest(topicRequest, userDetails); mailService.sendMail( @@ -744,11 +751,11 @@ private void setTopicHistory(TopicRequest topicRequest, String userName, int ten List existingTopicHistory; List topicHistoryList = new ArrayList<>(); - if (topicRequest.getTopictype().equals(TopicRequestTypes.Update.name())) { + if (TopicRequestTypes.Update.name().equals(topicRequest.getTopictype())) { List existingTopicList = getTopicFromName(topicRequest.getTopicname(), topicRequest.getTenantId()); existingTopicList.stream() - .filter(topic -> topic.getEnvironment().equals(topicRequest.getEnvironment())) + .filter(topic -> Objects.equals(topic.getEnvironment(), topicRequest.getEnvironment())) .findFirst() .ifPresent(a -> existingHistory.set(a.getHistory())); existingTopicHistory = objectMapper.readValue(existingHistory.get(), ArrayList.class); @@ -785,7 +792,7 @@ public String declineTopicRequests(String topicId, String reasonForDecline) { dbHandle.selectTopicRequestsForTopic( Integer.parseInt(topicId), commonUtilsService.getTenantId(getUserName())); - if (!topicRequest.getTopicstatus().equals(RequestStatus.created.name())) { + if (!RequestStatus.created.name().equals(topicRequest.getTopicstatus())) { return "{\"result\":\"This request does not exist anymore.\"}"; } @@ -823,7 +830,7 @@ public List getAllTopics(boolean isMyTeamTopics) { // manageDatabase.getHandleDbRequests().getUsersInfo(getUserName()).getTeam(); topicsFromSOT = topicsFromSOT.stream() - .filter(topic -> topic.getTeamId().equals(userTeamId)) + .filter(topic -> Objects.equals(topic.getTeamId(), userTeamId)) .collect(Collectors.toList()); } @@ -852,7 +859,7 @@ public Map saveTopicDocumentation(TopicInfo topicInfo) { // String loggedInUserTeam = handleDb.selectAllTeamsOfUsers(getUserName(), // tenantId).get(0).getTeamname(); Integer loggedInUserTeamId = getMyTeamId(getUserName()); - if (topicOwnerTeamId.equals(loggedInUserTeamId)) { + if (Objects.equals(topicOwnerTeamId, loggedInUserTeamId)) { saveResult.put( "result", manageDatabase.getHandleDbRequests().updateTopicDocumentation(topic)); } else saveResult.put("result", "failure"); @@ -895,7 +902,7 @@ public Map getTopicDetailsPerEnv(String envId, String topicName) } topics = topics.stream() - .filter(topic -> topic.getEnvironment().equals(envId)) + .filter(topic -> Objects.equals(topic.getEnvironment(), envId)) .collect(Collectors.toList()); } @@ -916,7 +923,7 @@ public Map getTopicDetailsPerEnv(String envId, String topicName) .selectAllTeamsOfUsers(getUserName(), tenantId) .get(0) .getTeamname(); - if (!loggedInUserTeam.equals(topicInfo.getTeamname())) { + if (!Objects.equals(loggedInUserTeam, topicInfo.getTeamname())) { hashMap.put("error", "Sorry, your team does not own the topic !!"); return hashMap; } @@ -992,7 +999,7 @@ private List getTopicsPaginated( // To get Producer or Consumer topics, first get all topics based on acls and then filter List producerConsumerTopics = new ArrayList<>(); if (topicType != null - && (topicType.equals("Producer") || topicType.equals("Consumer")) + && ("Producer".equals(topicType) || "Consumer".equals(topicType)) && teamName != null) { producerConsumerTopics = handleDbRequests.selectAllTopicsByTopictypeAndTeamname( @@ -1034,7 +1041,7 @@ private List getTopicsPaginated( topicInfo.setEnvironmentsList(producerConsumerTopic.getEnvironmentsList()); filterProducerConsumerList.add(topicInfo); } - } else if (producerConsumerTopic.getTopicname().equals(topicInfo.getTopicname()) + } else if (Objects.equals(producerConsumerTopic.getTopicname(), topicInfo.getTopicname()) && topicInfo.getEnvironmentsList().contains(producerConsumerTopic.getEnvironment())) { topicInfo.setEnvironmentsList(producerConsumerTopic.getEnvironmentsList()); filterProducerConsumerList.add(topicInfo); @@ -1127,7 +1134,7 @@ private List getConvertedEnvs(List allEnvs, List selectedEn List newEnvList = new ArrayList<>(); for (String env : selectedEnvs) { for (Env env1 : allEnvs) { - if (env.equals(env1.getId())) { + if (Objects.equals(env, env1.getId())) { newEnvList.add(env1.getName()); break; } @@ -1206,7 +1213,7 @@ private Object getPrincipal() { public Env getEnvDetails(String envId) { Optional envFound = manageDatabase.getKafkaEnvList(commonUtilsService.getTenantId(getUserName())).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } @@ -1214,7 +1221,10 @@ public Env getEnvDetails(String envId) { public Env getEnvDetailsFromName(String envName, Integer tenantId) { Optional envFound = manageDatabase.getKafkaEnvList(tenantId).stream() - .filter(env -> env.getName().equals(envName) && env.getTenantId().equals(tenantId)) + .filter( + env -> + Objects.equals(env.getName(), envName) + && Objects.equals(env.getTenantId(), tenantId)) .findFirst(); return envFound.orElse(null); } diff --git a/src/main/java/io/aiven/klaw/service/TopicSyncControllerService.java b/src/main/java/io/aiven/klaw/service/TopicSyncControllerService.java index 3508fe4ada..212c7423cd 100644 --- a/src/main/java/io/aiven/klaw/service/TopicSyncControllerService.java +++ b/src/main/java/io/aiven/klaw/service/TopicSyncControllerService.java @@ -122,7 +122,7 @@ public Map getReconTopics( .filter( topicRequestModel -> topicRequestModel != null - && (topicRequestModel.getRemarks().equals("DELETED") + && ("DELETED".equals(topicRequestModel.getRemarks()) || topicRequestModel.getTeamname() == null || topicRequestModel.getTeamname().equals(""))) .collect(Collectors.toList()); @@ -136,7 +136,7 @@ public Map getReconTopics( }); int tenantId = commonUtilsService.getTenantId(getUserName()); - if (!pageNo.equals("-1")) // scheduler call + if (!"-1".equals(pageNo)) // scheduler call topicRequestModelList = getPagedTopicReqModels(pageNo, currentPage, topicRequestModelList, tenantId); @@ -159,7 +159,7 @@ public Map getSyncTopics( int tenantId = commonUtilsService.getTenantId(getUserName()); log.info("getSyncTopics {} {} {}", env, pageNo, topicNameSearch); - if (!pageNo.equals("-1")) { // ignore check for scheduler + if (!"-1".equals(pageNo)) { // ignore check for scheduler if (commonUtilsService.isNotAuthorizedUser(getPrincipal(), PermissionType.SYNC_TOPICS)) return null; } @@ -329,9 +329,9 @@ private List getTopicRequestModels( if (fromSyncTopics) { // show approving info only before approvals - if (!topicRequestModel.getTopicstatus().equals(RequestStatus.approved.name())) { + if (!RequestStatus.approved.name().equals(topicRequestModel.getTopicstatus())) { if (topicRequestModel.getTopictype() != null - && topicRequestModel.getTopictype().equals(TopicRequestTypes.Claim.name())) { + && TopicRequestTypes.Claim.name().equals(topicRequestModel.getTopictype())) { List topics = getTopicFromName(topicRequestModel.getTopicname(), tenantId); topicRequestModel.setApprovingTeamDetails( updateApproverInfo( @@ -361,7 +361,8 @@ private String updateApproverInfo( StringBuilder approvingInfo = new StringBuilder("Team : " + teamName + ", Users : "); for (UserInfo userInfo : userList) { - if (approverRoles.contains(userInfo.getRole()) && !requestor.equals(userInfo.getUsername())) + if (approverRoles.contains(userInfo.getRole()) + && !Objects.equals(requestor, userInfo.getUsername())) approvingInfo.append(userInfo.getUsername()).append(","); } @@ -390,7 +391,9 @@ private boolean createTopicRequest( try { Optional teamUpdatedFirst = - topicsFromSOT.stream().filter(a -> a.getTopicname().equals(tmpTopicName)).findFirst(); + topicsFromSOT.stream() + .filter(a -> Objects.equals(a.getTopicname(), tmpTopicName)) + .findFirst(); if (teamUpdatedFirst.isPresent()) teamUpdated = @@ -506,7 +509,7 @@ public Map> updateSyncBackTopics(SyncBackTopics syncBackTop resultMap.put("result", resultStatus); - if (syncBackTopics.getTypeOfSync().equals("SELECTED_TOPICS")) { + if ("SELECTED_TOPICS".equals(syncBackTopics.getTypeOfSync())) { for (String topicId : syncBackTopics.getTopicIds()) { Optional topicFoundOptional = manageDatabase @@ -564,7 +567,7 @@ private void approveSyncBackTopics( + response.getBody()); } else { logUpdateSyncBackTopics.add("Topic created " + topicFound.getTopicname()); - if (!syncBackTopics.getSourceEnv().equals(syncBackTopics.getTargetEnv())) + if (!Objects.equals(syncBackTopics.getSourceEnv(), syncBackTopics.getTargetEnv())) createAndApproveTopicRequest(syncBackTopics, topicFound, tenantId); } } catch (KlawException e) { @@ -637,7 +640,7 @@ private List getTopicsPaginated( // To get Producer or Consumer topics, first get all topics based on acls and then filter List producerConsumerTopics = new ArrayList<>(); if (topicType != null - && (topicType.equals("Producer") || topicType.equals("Consumer")) + && ("Producer".equals(topicType) || "Consumer".equals(topicType)) && teamName != null) { producerConsumerTopics = handleDbRequests.selectAllTopicsByTopictypeAndTeamname( @@ -679,7 +682,7 @@ private List getTopicsPaginated( topicInfo.setEnvironmentsList(producerConsumerTopic.getEnvironmentsList()); filterProducerConsumerList.add(topicInfo); } - } else if (producerConsumerTopic.getTopicname().equals(topicInfo.getTopicname()) + } else if (Objects.equals(producerConsumerTopic.getTopicname(), topicInfo.getTopicname()) && topicInfo.getEnvironmentsList().contains(producerConsumerTopic.getEnvironment())) { topicInfo.setEnvironmentsList(producerConsumerTopic.getEnvironmentsList()); filterProducerConsumerList.add(topicInfo); @@ -785,7 +788,7 @@ private List getConvertedEnvs(List allEnvs, List selectedEn List newEnvList = new ArrayList<>(); for (String env : selectedEnvs) { for (Env env1 : allEnvs) { - if (env.equals(env1.getId())) { + if (Objects.equals(env, env1.getId())) { newEnvList.add(env1.getName()); break; } @@ -840,7 +843,7 @@ public Map> updateSyncTopicsBulk(SyncTopicsBulk syncTopicsB resultMap.put("result", resultStatus); - if (syncTopicsBulk.getTypeOfSync().equals("SELECTED_TOPICS")) { + if ("SELECTED_TOPICS".equals(syncTopicsBulk.getTypeOfSync())) { Object[] topicMap = syncTopicsBulk.getTopicDetails(); Map> hashMap = new HashMap<>(); Map subObj; @@ -1022,7 +1025,7 @@ public Map updateSyncTopics(List updatedSyncTo break; } } - } else if (!topicUpdate.getEnvSelected().equals(syncCluster)) { + } else if (!Objects.equals(syncCluster, topicUpdate.getEnvSelected())) { erroredTopicsExist.append(topicUpdate.getTopicName()).append(" "); if (checkInPromotionOrder( topicUpdate.getTopicName(), topicUpdate.getEnvSelected(), orderOfEnvs)) @@ -1048,7 +1051,7 @@ public Map updateSyncTopics(List updatedSyncTo listTopics.add(t); } else { for (Topic existingTopic : existingTopics) { - if (existingTopic.getEnvironment().equals(topicUpdate.getEnvSelected())) { + if (Objects.equals(existingTopic.getEnvironment(), topicUpdate.getEnvSelected())) { t = existingTopic; t.setTeamId( manageDatabase.getTeamIdFromTeamName(tenantId, topicUpdate.getTeamSelected())); @@ -1058,9 +1061,9 @@ public Map updateSyncTopics(List updatedSyncTo t.setTenantId(tenantId); listTopics.add(t); topicAdded = true; - } else if (!manageDatabase - .getTeamNameFromTeamId(tenantId, existingTopic.getTeamId()) - .equals(topicUpdate.getTeamSelected())) { + } else if (!Objects.equals( + manageDatabase.getTeamNameFromTeamId(tenantId, existingTopic.getTeamId()), + topicUpdate.getTeamSelected())) { t = existingTopic; t.setTeamId( manageDatabase.getTeamIdFromTeamName(tenantId, topicUpdate.getTeamSelected())); @@ -1077,7 +1080,7 @@ public Map updateSyncTopics(List updatedSyncTo boolean envFound = false; if (existingTopics != null) { for (Topic existingTopic : existingTopics) { - if (existingTopic.getEnvironment().equals(topicUpdate.getEnvSelected())) { + if (Objects.equals(existingTopic.getEnvironment(), topicUpdate.getEnvSelected())) { envFound = true; break; } @@ -1144,7 +1147,7 @@ private List handleTopicDeletes( int tenantId) { List updatedSyncTopicsUpdated = new ArrayList<>(); for (SyncTopicUpdates updatedSyncTopic : updatedSyncTopics) { - if (updatedSyncTopic.getTeamSelected().equals("REMOVE FROM KLAW")) { + if ("REMOVE FROM KLAW".equals(updatedSyncTopic.getTeamSelected())) { updatedSyncTopicsDelete.add(Integer.parseInt(updatedSyncTopic.getSequence())); } else updatedSyncTopicsUpdated.add(updatedSyncTopic); } @@ -1178,7 +1181,7 @@ public List getTopicFromName(String topicName, int tenantId) { public Env getEnvDetails(String envId) { Optional envFound = manageDatabase.getKafkaEnvList(commonUtilsService.getTenantId(getUserName())).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } diff --git a/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java b/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java index 0d427361c9..865f0330c7 100644 --- a/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java +++ b/src/main/java/io/aiven/klaw/service/UiConfigControllerService.java @@ -27,7 +27,7 @@ public class UiConfigControllerService { public Map getDbAuth() { Map dbMap = new HashMap<>(); - if (authenticationType.equals("db")) dbMap.put("dbauth", "true"); + if ("db".equals(authenticationType)) dbMap.put("dbauth", "true"); else dbMap.put("dbauth", "false"); return dbMap; } @@ -101,20 +101,20 @@ private List getActivityLogsPaginated( public String getEnvName(String envId, String activityName, int tenantId) { Optional envFound; - if (activityName.equals("SchemaRequest")) + if ("SchemaRequest".equals(activityName)) envFound = manageDatabase.getSchemaRegEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); - else if (activityName.equals("ConnectorRequest")) + else if ("ConnectorRequest".equals(activityName)) envFound = manageDatabase.getKafkaConnectEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); else envFound = manageDatabase.getKafkaEnvList(tenantId).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.map(Env::getName).orElse(null); diff --git a/src/main/java/io/aiven/klaw/service/UiControllerLoginService.java b/src/main/java/io/aiven/klaw/service/UiControllerLoginService.java index 73b1c2ed99..57fba75b24 100644 --- a/src/main/java/io/aiven/klaw/service/UiControllerLoginService.java +++ b/src/main/java/io/aiven/klaw/service/UiControllerLoginService.java @@ -61,48 +61,48 @@ public String getReturningPage(String uri) { if (userInfo == null) { SecurityContextHolder.getContext().setAuthentication(null); - if (kwInstallationType.equals("saas")) { + if ("saas".equals(kwInstallationType)) { return "registerSaas.html"; } - if (authenticationType.equals("ad")) return "registerLdap.html"; + if ("ad".equals(authenticationType)) return "registerLdap.html"; return "register.html"; } - if (kwInstallationType.equals("saas")) { + if ("saas".equals(kwInstallationType)) { int tenantId = commonUtilsService.getTenantId(userDetails.getUsername()); - if (!manageDatabase.getTenantFullConfig(tenantId).getIsActive().equals("true")) { + if (!"true".equals(manageDatabase.getTenantFullConfig(tenantId).getIsActive())) { return "tenantInfo.html"; } } log.debug("Authenticated user : {}", userDetails.getUsername()); - if (uri.equals("login.html") - || uri.equals("loginSaas.html") - || uri.equals("home.html") - || uri.equals("register.html") + if ("login.html".equals(uri) + || "loginSaas.html".equals(uri) + || "home.html".equals(uri) + || "register.html".equals(uri) || uri.contains("registrationReview") || uri.contains("userActivation") - || uri.equals("forgotPassword.html") - || uri.equals("newADUser.html")) return indexPage; + || "forgotPassword.html".equals(uri) + || "newADUser.html".equals(uri)) return indexPage; return uri; } - if (authenticationType.equals("db") && kwInstallationType.equals("saas")) + if ("db".equals(authenticationType) && "saas".equals(kwInstallationType)) return defaultPageSaas; else return defaultPage; } catch (Exception e) { log.error("Exception:", e); - if (uri.equals("login.html") - || uri.equals("register.html") - || uri.equals("registerSaas.html") - || uri.equals("registerLdap.html") + if ("login.html".equals(uri) + || "register.html".equals(uri) + || "registerSaas.html".equals(uri) + || "registerLdap.html".equals(uri) || uri.contains("registrationReview") || uri.contains("userActivation") - || uri.equals("forgotPassword.html") - || uri.equals("newADUser.html") - || uri.equals("terms.html") - || uri.equals("feedback.html")) return uri; + || "forgotPassword.html".equals(uri) + || "newADUser.html".equals(uri) + || "terms.html".equals(uri) + || "feedback.html".equals(uri)) return uri; - if (authenticationType.equals("db") && kwInstallationType.equals("saas")) + if ("db".equals(authenticationType) && "saas".equals(kwInstallationType)) return defaultPageSaas; else return defaultPage; } @@ -138,22 +138,24 @@ public String checkAnonymousLogin( } public String checkAuth(String uri, HttpServletRequest request, HttpServletResponse response) { - if (uri.equals("tenants.html")) { + if ("tenants.html".equals(uri)) { UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - if (manageDatabase - .getHandleDbRequests() - .getUsersInfo(userDetails.getUsername()) - .getRole() - .equals(SUPERADMIN.name()) + if (SUPERADMIN + .name() + .equals( + manageDatabase + .getHandleDbRequests() + .getUsersInfo(userDetails.getUsername()) + .getRole()) && commonUtilsService.getTenantId(userDetails.getUsername()) == KwConstants.DEFAULT_TENANT_ID) { return getReturningPage(uri); } else uri = "index"; } - if (ssoEnabled.equals("true")) { + if ("true".equals(ssoEnabled)) { if (uri.contains("register") || uri.equals("registrationReview.html")) return uri; else return checkAnonymousLogin(uri, request, response); } else { @@ -168,7 +170,7 @@ public String registerStagingUser(String userName, Object fullName) { manageDatabase.getHandleDbRequests().getRegistrationId(userName); if (existingRegistrationId != null) { - if (existingRegistrationId.equals("PENDING_ACTIVATION")) + if ("PENDING_ACTIVATION".equals(existingRegistrationId)) return "redirect:" + "registrationReview"; else return "redirect:" + "register?userRegistrationId=" + existingRegistrationId; } else { diff --git a/src/main/java/io/aiven/klaw/service/UsersTeamsControllerService.java b/src/main/java/io/aiven/klaw/service/UsersTeamsControllerService.java index 806eec8888..57e8b0f0bb 100644 --- a/src/main/java/io/aiven/klaw/service/UsersTeamsControllerService.java +++ b/src/main/java/io/aiven/klaw/service/UsersTeamsControllerService.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Random; import java.util.regex.Matcher; @@ -107,22 +108,24 @@ public String updateUser(UserInfoModel newUser) { manageDatabase.getRolesPermissionsPerTenant(tenantId).get(existingUserInfo.getRole()); if (permissions != null && permissions.contains(PermissionType.FULL_ACCESS_USERS_TEAMS_ROLES.name())) { - if (!getUserName().equals(newUser.getUsername())) // should be able to update same user - return "{\"result\":\"Not Authorized to update another SUPERADMIN user.\"}"; + if (!Objects.equals( + getUserName(), newUser.getUsername())) { // should be able to update same user + return "{\"result\":\"Not Authorized to update another SUPERADMIN user.\"}"; + } } String pwdUpdated = newUser.getUserPassword(); String existingPwd; - if (pwdUpdated.equals("*******") && authenticationType.equals("db")) { + if ("*******".equals(pwdUpdated) && "db".equals(authenticationType)) { existingPwd = existingUserInfo.getPwd(); - if (!existingPwd.equals("")) newUser.setUserPassword(decodePwd(existingPwd)); + if (!"".equals(existingPwd)) newUser.setUserPassword(decodePwd(existingPwd)); } try { PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); - if (authenticationType.equals("db")) { + if ("db".equals(authenticationType)) { if (inMemoryUserDetailsManager.userExists(newUser.getUsername())) { inMemoryUserDetailsManager.updateUser( User.withUsername(newUser.getUsername()) @@ -176,7 +179,7 @@ public TeamModel getTeamDetails(Integer teamId, String tenantName) { private int getTenantId(String tenantName) { return manageDatabase.getTenantMap().entrySet().stream() - .filter(obj -> obj.getValue().equals(tenantName)) + .filter(obj -> Objects.equals(obj.getValue(), tenantName)) .findFirst() .get() .getKey(); @@ -207,7 +210,7 @@ public Map resetPassword(String username) { inMemoryUserDetailsManager.updatePassword( updatePwdUserDetails, encoder.encode(newGeneratedPwd)); String pwdUpdated = dbHandle.updatePassword(username, encodePwd(newGeneratedPwd)); - if (pwdUpdated.equals("success")) { + if ("success".equals(pwdUpdated)) { userMap.put("passwordSent", "true"); mailService.sendMailResetPwd( username, @@ -329,7 +332,7 @@ public String deleteTeam(Integer teamId) { } // own team cannot be deleted - if (getMyTeamId(userDetails).equals(teamId)) return envAddResult; + if (Objects.equals(getMyTeamId(userDetails), teamId)) return envAddResult; try { String result = @@ -337,7 +340,7 @@ public String deleteTeam(Integer teamId) { .getHandleDbRequests() .deleteTeamRequest(teamId, commonUtilsService.getTenantId(getUserName())); - if (result.equals("success")) { + if ("success".equals(result)) { commonUtilsService.updateMetadata(tenantId, EntityType.TEAM, MetadataOperationType.DELETE); } @@ -367,7 +370,7 @@ public String deleteUser(String userId, boolean isExternal) { String envAddResult = "{\"result\":\"User cannot be deleted\"}"; - if (userDetails.equals(userId) && isExternal) return envAddResult; + if (Objects.equals(userDetails, userId) && isExternal) return envAddResult; inMemoryUserDetailsManager.deleteUser(userId); @@ -402,7 +405,7 @@ public Map addNewUser(UserInfoModel newUser, boolean isExternal) Map resMap = new HashMap<>(); log.info("addNewUser {} {} {}", newUser.getUsername(), newUser.getTeam(), newUser.getRole()); - if (kwInstallationType.equals("saas")) { + if ("saas".equals(kwInstallationType)) { String regex = "^[A-Za-z0-9+_.-]+@(.+)$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(newUser.getUsername()); @@ -439,12 +442,12 @@ public Map addNewUser(UserInfoModel newUser, boolean isExternal) return resMap; } - if (authenticationType.equals("ad") && adAuthRoleEnabled.equals("true")) newUser.setRole("NA"); + if ("ad".equals(authenticationType) && "true".equals(adAuthRoleEnabled)) newUser.setRole("NA"); try { PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); - if (authenticationType.equals("db")) { + if ("db".equals(authenticationType)) { inMemoryUserDetailsManager.createUser( User.withUsername(newUser.getUsername()) .password(encoder.encode(newUser.getUserPassword())) @@ -463,7 +466,7 @@ public Map addNewUser(UserInfoModel newUser, boolean isExternal) // log.info("pwd : "+decodePwd(newUser.getUserPassword())); if (isExternal) { - if (newUser.getUserPassword().equals("")) + if ("".equals(newUser.getUserPassword())) mailService.sendMail( newUser.getUsername(), newUser.getUserPassword(), @@ -514,7 +517,7 @@ public String addNewTeam(TeamModel newTeam, boolean isExternal) { } try { String res = manageDatabase.getHandleDbRequests().addNewTeam(team); - if (res.equals("success")) { + if ("success".equals(res)) { commonUtilsService.updateMetadata(tenantId, EntityType.TEAM, MetadataOperationType.CREATE); } return "{\"result\":\"" + res + "\"}"; @@ -553,7 +556,7 @@ public String updateTeam(TeamModel updatedTeam) { } public String changePwd(String changePwd) { - if (authenticationType.equals("ldap") || authenticationType.equals("ad")) { + if ("ldap".equals(authenticationType) || "ad".equals(authenticationType)) { return "{\"result\":\" Password cannot be updated in ldap/ad authentication mode. \"}"; } String userDetails = getUserName(); @@ -596,9 +599,9 @@ public List showUsers(String teamName, String userSearchStr, Stri UserInfoModel userInfoModel = new UserInfoModel(); copyProperties(userListItem, userInfoModel); if (teamName != null && !teamName.equals("")) { - if (manageDatabase - .getTeamNameFromTeamId(tenantId, userInfoModel.getTeamId()) - .equals(teamName)) userInfoModels.add(userInfoModel); + if (Objects.equals( + manageDatabase.getTeamNameFromTeamId(tenantId, userInfoModel.getTeamId()), + teamName)) userInfoModels.add(userInfoModel); } else userInfoModels.add(userInfoModel); }); userInfoModels.forEach( @@ -686,10 +689,11 @@ public Map registerUser(RegisterUserInfoModel newUser, boolean i // check if user exists List userList = manageDatabase.getHandleDbRequests().selectAllUsersAllTenants(); - if (userList.stream().anyMatch(user -> user.getUsername().equals(newUser.getMailid()))) { + if (userList.stream() + .anyMatch(user -> Objects.equals(user.getUsername(), newUser.getMailid()))) { throw new KlawException("User already exists."); } else if (userList.stream() - .anyMatch(user -> user.getUsername().equals(newUser.getUsername()))) { + .anyMatch(user -> Objects.equals(user.getUsername(), newUser.getUsername()))) { throw new KlawException("User already exists."); } @@ -775,7 +779,7 @@ public List getNewUserRequests() { int tenantId = commonUtilsService.getTenantId(getUserName()); List registerUserInfoList; - if (kwInstallationType.equals("saas")) + if ("saas".equals(kwInstallationType)) registerUserInfoList = manageDatabase.getHandleDbRequests().selectAllRegisterUsersInfoForTenant(tenantId); else registerUserInfoList = manageDatabase.getHandleDbRequests().selectAllRegisterUsersInfo(); @@ -832,7 +836,7 @@ public String approveNewUserRequests( userInfo.setRole(registerUserInfo.getRole()); userInfo.setTenantId(tenantId); - if (authenticationType.equals("db")) + if ("db".equals(authenticationType)) userInfo.setUserPassword(decodePwd(registerUserInfo.getPwd())); else userInfo.setUserPassword(""); userInfo.setMailid(registerUserInfo.getMailid()); @@ -880,7 +884,7 @@ public RegisterUserInfoModel getRegistrationInfoFromId(String registrationId, St public Env getEnvDetailsFromId(String envId) { Optional envFound = manageDatabase.getKafkaEnvList(commonUtilsService.getTenantId(getUserName())).stream() - .filter(env -> env.getId().equals(envId)) + .filter(env -> Objects.equals(env.getId(), envId)) .findFirst(); return envFound.orElse(null); } diff --git a/src/main/java/io/aiven/klaw/service/UtilControllerService.java b/src/main/java/io/aiven/klaw/service/UtilControllerService.java index 89dbca0286..656b4fc28c 100644 --- a/src/main/java/io/aiven/klaw/service/UtilControllerService.java +++ b/src/main/java/io/aiven/klaw/service/UtilControllerService.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -84,7 +85,7 @@ public String getTenantNameFromUser(String userId) { UserInfo userInfo = manageDatabase.getHandleDbRequests().getUsersInfo(userId); if (userInfo != null) { return manageDatabase.getTenantMap().entrySet().stream() - .filter(obj -> obj.getKey().equals(userInfo.getTenantId())) + .filter(obj -> Objects.equals(obj.getKey(), userInfo.getTenantId())) .findFirst() .get() .getValue(); @@ -309,10 +310,10 @@ public Map getAuth() { requestConnector = "NotAuthorized"; } else requestConnector = "Authorized"; - if (requestTopics.equals("Authorized") - || requestAcls.equals("Authorized") - || requestSchemas.equals("Authorized") - || requestConnector.equals("Authorized")) requestItems = "Authorized"; + if ("Authorized".equals(requestTopics) + || "Authorized".equals(requestAcls) + || "Authorized".equals(requestSchemas) + || "Authorized".equals(requestConnector)) requestItems = "Authorized"; else requestItems = "NotAuthorized"; String approveDeclineTopics; @@ -338,23 +339,23 @@ public Map getAuth() { approveDeclineConnectors = "NotAuthorized"; } else approveDeclineConnectors = "Authorized"; - if (approveDeclineTopics.equals("Authorized") - || approveDeclineSubscriptions.equals("Authorized") - || approveDeclineSchemas.equals("Authorized") - || approveDeclineConnectors.equals("Authorized") - || addUser.equals("Authorized")) approveAtleastOneRequest = "Authorized"; + if ("Authorized".equals(approveDeclineTopics) + || "Authorized".equals(approveDeclineSubscriptions) + || "Authorized".equals(approveDeclineSchemas) + || "Authorized".equals(approveDeclineConnectors) + || "Authorized".equals(addUser)) approveAtleastOneRequest = "Authorized"; String redirectionPage = ""; - if (approveAtleastOneRequest.equals("Authorized")) { - if (outstandingTopicReqsInt > 0 && approveDeclineTopics.equals("Authorized")) + if ("Authorized".equals(approveAtleastOneRequest)) { + if (outstandingTopicReqsInt > 0 && "Authorized".equals(approveDeclineTopics)) redirectionPage = "execTopics"; - else if (outstandingAclReqsInt > 0 && approveDeclineSubscriptions.equals("Authorized")) + else if (outstandingAclReqsInt > 0 && "Authorized".equals(approveDeclineSubscriptions)) redirectionPage = "execAcls"; - else if (outstandingSchemasReqsInt > 0 && approveDeclineSchemas.equals("Authorized")) + else if (outstandingSchemasReqsInt > 0 && "Authorized".equals(approveDeclineSchemas)) redirectionPage = "execSchemas"; - else if (outstandingConnectorReqsInt > 0 && approveDeclineConnectors.equals("Authorized")) + else if (outstandingConnectorReqsInt > 0 && "Authorized".equals(approveDeclineConnectors)) redirectionPage = "execConnectors"; - else if (outstandingUserReqsInt > 0 && addUser.equals("Authorized")) + else if (outstandingUserReqsInt > 0 && "Authorized".equals(addUser)) redirectionPage = "execUsers"; } @@ -385,11 +386,13 @@ else if (outstandingUserReqsInt > 0 && addUser.equals("Authorized")) else showServerConfigEnvProperties = "NotAuthorized"; if (tenantId == KwConstants.DEFAULT_TENANT_ID - && manageDatabase - .getHandleDbRequests() - .getUsersInfo(userName) - .getRole() - .equals(SUPERADMIN.name())) // allow adding tenants only to "default" + && SUPERADMIN + .name() + .equals( + manageDatabase + .getHandleDbRequests() + .getUsersInfo(userName) + .getRole())) // allow adding tenants only to "default" addDeleteEditTenants = "Authorized"; else addDeleteEditTenants = "NotAuthorized"; @@ -401,7 +404,7 @@ else if (outstandingUserReqsInt > 0 && addUser.equals("Authorized")) addDeleteEditClusters = "NotAuthorized"; else addDeleteEditClusters = "Authorized"; - if (authenticationType.equals("ad") && adAuthRoleEnabled.equals("true")) + if ("ad".equals(authenticationType) && "true".equals(adAuthRoleEnabled)) dashboardData.put("adAuthRoleEnabled", "true"); else dashboardData.put("adAuthRoleEnabled", "false"); @@ -414,7 +417,7 @@ else if (outstandingUserReqsInt > 0 && addUser.equals("Authorized")) companyInfo = "Our Organization"; } - if (kwInstallationType.equals("saas")) + if ("saas".equals(kwInstallationType)) dashboardData.put("supportlink", "https://github.com/aiven/klaw/issues"); else dashboardData.put("supportlink", "https://github.com/aiven/klaw/issues"); @@ -516,7 +519,7 @@ public Map getBasicInfo() { Map resultBasicInfo = new HashMap<>(); resultBasicInfo.put("contextPath", kwContextPath); - if (ssoEnabled.equals("true")) { + if ("true".equals(ssoEnabled)) { resultBasicInfo.put("ssoServerUrl", ssoServerLoginUrl); } @@ -528,7 +531,7 @@ public void resetCache(String tenantName, String entityType, String operationTyp try { tenantId = manageDatabase.getHandleDbRequests().getTenants().stream() - .filter(kwTenant -> kwTenant.getTenantName().equals(tenantName)) + .filter(kwTenant -> Objects.equals(kwTenant.getTenantName(), tenantName)) .findFirst() .get() .getTenantId();