Skip to content

Commit

Permalink
Make code for exist methods more concise (#1615)
Browse files Browse the repository at this point in the history

Signed-off-by: Sergey Nuyanzin <[email protected]>
  • Loading branch information
snuyanzin authored Aug 22, 2023
1 parent d684a6b commit f3d4a52
Showing 1 changed file with 17 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.TreeSet;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
Expand Down Expand Up @@ -1436,66 +1437,43 @@ public Optional<ProductDetails> selectProductDetails(String name) {
}

public boolean existsKafkaComponentsForEnv(String env, int tenantId) {
List<Supplier<Boolean>> list =
List.of(
return Stream.<Supplier<Boolean>>of(
() -> topicRepo.existsByEnvironmentAndTenantId(env, tenantId),
() ->
topicRequestsRepo.existsByTenantIdAndEnvironmentAndRequestStatus(
tenantId, env, RequestStatus.CREATED.value),
() -> aclRepo.existsByEnvironmentAndTenantId(env, tenantId),
() ->
aclRequestsRepo.existsByTenantIdAndEnvironmentAndRequestStatus(
tenantId, env, RequestStatus.CREATED.value));
for (var elem : list) {
if (elem.get()) {
return true;
}
}
return false;
tenantId, env, RequestStatus.CREATED.value))
.anyMatch(Supplier::get);
}

public boolean existsConnectorComponentsForEnv(String env, int tenantId) {
List<Supplier<Boolean>> list =
List.of(
return Stream.<Supplier<Boolean>>of(
() -> kafkaConnectorRepo.existsByEnvironmentAndTenantId(env, tenantId),
() ->
kafkaConnectorRequestsRepo.existsConnectorRequestsForEnvTenantIdAndCreatedStatus(
env, tenantId));
for (var elem : list) {
if (elem.get()) {
return true;
}
}
return false;
env, tenantId))
.anyMatch(Supplier::get);
}

public boolean existsSchemaComponentsForEnv(String env, int tenantId) {
List<Supplier<Boolean>> list =
List.of(
() ->
schemaRequestRepo.existsSchemaRequestByEnvironmentAndTenantIdAndRequestStatus(
env, tenantId, RequestStatus.CREATED.value),
() -> messageSchemaRepo.existsMessageSchemaByEnvironmentAndTenantId(env, tenantId));
for (var elem : list) {
if (elem.get()) {
return true;
}
}
return false;
return Stream.<Supplier<Boolean>>of(
() -> schemaRequestRepo.existsSchemaRequestByEnvironmentAndTenantId(env, tenantId),
() -> messageSchemaRepo.existsMessageSchemaByEnvironmentAndTenantId(env, tenantId))
.anyMatch(Supplier::get);
}

public boolean existsComponentsCountForTeam(Integer teamId, int tenantId) {
List<Supplier<Boolean>> list =
List.of(
return Stream.<Supplier<Boolean>>of(
() -> {
boolean res = schemaRequestRepo.existsRecordsCountForTeamId(teamId, tenantId);

log.debug("For team {} Active Schema Requests {}", teamId, res);
return res;
},
() -> {
boolean res = messageSchemaRepo.existsRecordsCountForTeamId(teamId, tenantId);

log.debug("For team {} number of Schemas in DB {}", teamId, res);
return res;
},
Expand Down Expand Up @@ -1529,28 +1507,17 @@ public boolean existsComponentsCountForTeam(Integer teamId, int tenantId) {
boolean res = aclRequestsRepo.existsRecordsCountForTeamId(teamId, tenantId);
log.debug("For team {} number of ACL in DB {}", teamId, res);
return res;
});
for (var elem : list) {
if (elem.get()) {
return true;
}
}
return false;
})
.anyMatch(Supplier::get);
}

public boolean existsComponentsCountForUser(String userId, int tenantId) {
List<Supplier<Boolean>> list =
List.of(
return Stream.<Supplier<Boolean>>of(
() -> schemaRequestRepo.existsRecordsCountForUserId(userId, tenantId),
() -> kafkaConnectorRequestsRepo.existsRecordsCountForUserId(userId, tenantId),
() -> topicRequestsRepo.existsRecordsCountForUserId(userId, tenantId),
() -> aclRequestsRepo.existsRecordsCountForUserId(userId, tenantId));
for (var elem : list) {
if (elem.get()) {
return true;
}
}
return false;
() -> aclRequestsRepo.existsRecordsCountForUserId(userId, tenantId))
.anyMatch(Supplier::get);
}

public int getAllTopicsCountInAllTenants() {
Expand Down

0 comments on commit f3d4a52

Please sign in to comment.