Commit a21b67ee authored by Duvelis Carao's avatar Duvelis Carao
Browse files

Refactor. Improvements

parent 3ea7d265
Pipeline #13238 failed with stages
in 1 minute and 30 seconds
......@@ -26,11 +26,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -80,18 +80,23 @@ public class TenantFactoryImpl implements ITenantFactory {
* @return list of tenantInfo objects for all the tenants
*/
public Collection<TenantInfo> listTenantInfo() {
Collection<TenantInfo> tenantInfoList = new ArrayList<>();
Collection<String> partitions = this.partitionService.listPartitions();
TenantInfo tenantInfo;
for (String partition : partitions) {
tenantInfo = new TenantInfo();
tenantInfo.setName(partition);
tenantInfo.setDataPartitionId(partition);
tenantInfoList.add(tenantInfo);
}
return tenantInfoList;
return this.partitionService.listPartitions().stream().map(this::buildTenantInfo).collect(Collectors.toList());
}
/**
* Build TenanInfo Object.
*
* @param partitionId Partition Id
* @return TenantInfo object
*/
private TenantInfo buildTenantInfo(final String partitionId) {
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setName(partitionId);
tenantInfo.setDataPartitionId(partitionId);
return tenantInfo;
}
/**
* @param tenantName Tenant name
* @param host Host name
......
......@@ -45,10 +45,8 @@ public class PartitionServiceClient {
*/
public PartitionInfoAzure getPartition(final String partitionId) throws AppException {
Validators.checkNotNullAndNotEmpty(partitionId, "partitionId");
this.headers.put(DpsHeaders.AUTHORIZATION, "Bearer " + this.tokenService.getAuthorizationToken());
try {
IPartitionProvider serviceClient = this.partitionFactory.create(headers);
IPartitionProvider serviceClient = getServiceClient();
PartitionInfo partitionInfo = serviceClient.get(partitionId);
return convert(partitionInfo);
} catch (PartitionException e) {
......@@ -74,13 +72,22 @@ public class PartitionServiceClient {
* @throws AppException Exception thrown by {@link IPartitionFactory}
*/
public List<String> listPartitions() throws AppException {
this.headers.put(DpsHeaders.AUTHORIZATION, "Bearer " + this.tokenService.getAuthorizationToken());
try {
IPartitionProvider serviceClient = this.partitionFactory.create(headers);
IPartitionProvider serviceClient = getServiceClient();
return serviceClient.list();
} catch (PartitionException e) {
throw new AppException(HttpStatus.SC_FORBIDDEN, "Service unavailable", "Error getting list of partitions", e);
}
}
/**
* Get Service client for Partition Service.
*
* @return PartitionServiceClient
*/
private IPartitionProvider getServiceClient() {
this.headers.put(DpsHeaders.AUTHORIZATION, "Bearer " + this.tokenService.getAuthorizationToken());
return this.partitionFactory.create(headers);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment