Skip to content

Commit

Permalink
Remove unused field userId
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui committed Nov 7, 2023
1 parent 32223e4 commit da0b848
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
Expand All @@ -36,6 +37,7 @@
import org.eclipse.xpanse.modules.models.service.view.ServiceVo;
import org.eclipse.xpanse.modules.orchestrator.deployment.DeployTask;
import org.eclipse.xpanse.modules.orchestrator.deployment.Deployment;
import org.eclipse.xpanse.modules.security.IdentityProviderManager;
import org.eclipse.xpanse.modules.workflow.consts.MigrateConstants;
import org.eclipse.xpanse.modules.workflow.utils.WorkflowProcessUtils;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -66,6 +68,9 @@ public class ServiceDeployerApi {
@Resource
private DeployService deployService;

@Resource
private IdentityProviderManager identityProviderManager;

@Resource
private WorkflowProcessUtils workflowProcessUtils;

Expand Down Expand Up @@ -159,9 +164,7 @@ public Response destroy(@PathVariable("id") String id) {
log.info("Stopping managed service with id {}", id);
DeployTask deployTask = new DeployTask();
deployTask.setId(UUID.fromString(id));
String currentLoginUserId = deployService.getCurrentLoginUserId();
Deployment deployment =
this.deployService.getDestroyHandler(deployTask, currentLoginUserId);
Deployment deployment = this.deployService.getDestroyHandler(deployTask);
this.deployService.updateServiceStatus(deployTask.getId(),
ServiceDeploymentState.DESTROYING);
this.deployService.asyncDestroyService(deployment, deployTask);
Expand All @@ -184,9 +187,7 @@ public Response purge(@PathVariable("id") String id) {
log.info("Purging managed service with id {}", id);
DeployTask deployTask = new DeployTask();
deployTask.setId(UUID.fromString(id));
String currentLoginUserId = deployService.getCurrentLoginUserId();
Deployment deployment =
this.deployService.getDestroyHandler(deployTask, currentLoginUserId);
Deployment deployment = this.deployService.getDestroyHandler(deployTask);
this.deployService.purgeService(deployment, deployTask);
String successMsg = String.format("Purging task for service with ID %s has started.", id);
return Response.successResponse(Collections.singletonList(successMsg));
Expand All @@ -203,11 +204,12 @@ public Response purge(@PathVariable("id") String id) {
@ResponseStatus(HttpStatus.ACCEPTED)
public UUID migrate(@Valid @RequestBody MigrateRequest migrateRequest) {
UUID newId = UUID.randomUUID();
Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
Map<String, Object> variable = new HashMap<>();
variable.put(MigrateConstants.ID, migrateRequest.getId());
variable.put(MigrateConstants.NEW_ID, newId);
variable.put(MigrateConstants.MIGRATE_REQUEST, migrateRequest);
variable.put(MigrateConstants.USER_ID, deployService.getCurrentLoginUserId());
variable.put(MigrateConstants.USER_ID, userIdOptional.orElse(null));
workflowProcessUtils.asyncStartProcess(MigrateConstants.PROCESS_KEY, variable);
return newId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.models.workflow.WorkFlowTask;
import org.eclipse.xpanse.modules.security.IdentityProviderManager;
Expand Down Expand Up @@ -56,8 +57,8 @@ public class WorkFlowApi {
@GetMapping(value = "/workflow/task/todo", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<WorkFlowTask> queryTodoTasks() {
String userId = identityProviderManager.getCurrentUserInfo().getUserId();
return workflowProcessUtils.todoTasks(userId);
Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
return workflowProcessUtils.todoTasks(userIdOptional.orElse(null));
}

/**
Expand All @@ -68,8 +69,8 @@ public List<WorkFlowTask> queryTodoTasks() {
@GetMapping(value = "/workflow/task/done", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<WorkFlowTask> queryDoneTasks() {
String userId = identityProviderManager.getCurrentUserInfo().getUserId();
return workflowProcessUtils.doneTasks(userId);
Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
return workflowProcessUtils.doneTasks(userIdOptional.orElse(null));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.xpanse.modules.database.servicetemplate.ServiceTemplateStorage;
import org.eclipse.xpanse.modules.database.utils.EntityTransUtils;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.terraformboot.model.TerraformResult;
import org.eclipse.xpanse.modules.models.security.model.CurrentUserInfo;
import org.eclipse.xpanse.modules.models.service.common.enums.Csp;
import org.eclipse.xpanse.modules.models.service.deploy.DeployRequest;
import org.eclipse.xpanse.modules.models.service.deploy.DeployResource;
Expand Down Expand Up @@ -269,7 +268,7 @@ private List<DeployResourceEntity> getDeployResourceEntityList(
*
* @param deployTask the task of deploy managed service name.
*/
public Deployment getDestroyHandler(DeployTask deployTask, String userId) {
public Deployment getDestroyHandler(DeployTask deployTask) {
// Find the deployed service.
DeployServiceEntity deployServiceEntity =
deployServiceStorage.findDeployServiceById(deployTask.getId());
Expand All @@ -279,7 +278,8 @@ public Deployment getDestroyHandler(DeployTask deployTask, String userId) {
log.error(errorMsg);
throw new ServiceNotDeployedException(errorMsg);
}
if (!StringUtils.equals(userId, deployServiceEntity.getUserId())) {
Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
if (!StringUtils.equals(userIdOptional.orElse(null), deployServiceEntity.getUserId())) {
throw new AccessDeniedException(
"No permissions to destroy services belonging to other users.");
}
Expand Down Expand Up @@ -547,19 +547,6 @@ public Deployment getDeployment(DeployerKind deployerKind) {
return deployment;
}

/**
* Get the id of the current login user.
*/
public String getCurrentLoginUserId() {
CurrentUserInfo currentUserInfo = identityProviderManager.getCurrentUserInfo();
if (Objects.nonNull(currentUserInfo)
&& StringUtils.isNotBlank(currentUserInfo.getUserId())) {
return currentUserInfo.getUserId();
} else {
return "defaultUserId";
}
}

private ServiceVo convertToServiceVo(DeployServiceEntity serviceEntity) {
if (Objects.nonNull(serviceEntity)) {
ServiceVo serviceVo = new ServiceVo();
Expand Down Expand Up @@ -608,12 +595,12 @@ public CompletableFuture<Void> deployService(UUID newId,
* Destroy service by deployed service id.
*/
@Async("taskExecutor")
public CompletableFuture<Void> destroyService(String id, String userId) {
public CompletableFuture<Void> destroyService(String id) {
MDC.put(TASK_ID, id);
log.info("start destroy service, service id : {}", id);
DeployTask deployTask = new DeployTask();
deployTask.setId(UUID.fromString(id));
Deployment deployment = getDestroyHandler(deployTask, userId);
Deployment deployment = getDestroyHandler(deployTask);
destroy(deployment, deployTask);
return CompletableFuture.completedFuture(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,19 @@ void testGetDestroyHandler_DeployedServiceNotFound_ThrowsServiceNotDeployedExcep
when(deployServiceStorage.findDeployServiceById(deployTask.getId())).thenReturn(null);

assertThrows(ServiceNotDeployedException.class,
() -> deployService.getDestroyHandler(deployTask, userId));
() -> deployService.getDestroyHandler(deployTask));
}

@Test
void testGetDestroyHandler_ServiceStateIsDestroying_ThrowsInvalidServiceStateException() {
deployServiceEntity.setServiceDeploymentState(ServiceDeploymentState.DESTROYING);

when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));

when(deployServiceStorage.findDeployServiceById(deployTask.getId())).thenReturn(
deployServiceEntity);
assertThrows(InvalidServiceStateException.class,
() -> deployService.getDestroyHandler(deployTask, userId));
() -> deployService.getDestroyHandler(deployTask));
}

@Test
Expand All @@ -443,7 +445,9 @@ void testGetDestroyHandler() {
when(applicationContext.getBeansOfType(Deployment.class)).thenReturn(deploymentBeans);
deployService.deploymentMap();

Deployment result = deployService.getDestroyHandler(deployTask, userId);
when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));

Deployment result = deployService.getDestroyHandler(deployTask);

// Verify the interactions and assertions
verify(deployServiceStorage).findDeployServiceById(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
@Data
public class PolicyCreateRequest {

/**
* The id of user who created the policy.
*/
@Hidden
private String userId;

/**
* The csp which the policy belongs to.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.eclipse.xpanse.modules.models.policy;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;
Expand All @@ -26,12 +25,6 @@ public class PolicyUpdateRequest {
@Schema(description = "The id of the policy.")
private UUID id;

/**
* The id of user who created the policy.
*/
@Hidden
private String userId;

/**
* The csp which the policy belongs to.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
Expand All @@ -31,12 +30,6 @@ public class PolicyVo {
@Schema(description = "The id of the policy.")
private UUID id;

/**
* The id of user who created the policy.
*/
@Hidden
private String userId;

/**
* The valid policy created by the user.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ public class ServiceVo {
@Schema(description = "The ID of the service")
private UUID id;

/**
* The id of the user who deployed the service.
*/
@NotNull
@Schema(description = "The id of the user who deployed the service")
private String userId;

/**
* The category of the Service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ void setUp() {
policyCreateRequestUnderTest.setCsp(mockCsp);
}

@Test
void testUserIdGetterAndSetter() {
final String userId = "userId";
policyCreateRequestUnderTest.setUserId(userId);
assertThat(policyCreateRequestUnderTest.getUserId()).isEqualTo(userId);
}

@Test
void testGetCsp() {
assertThat(policyCreateRequestUnderTest.getCsp()).isEqualTo(mockCsp);
Expand Down Expand Up @@ -77,7 +70,7 @@ void testHashCode() {

@Test
void testToString() {
String result = "PolicyCreateRequest(userId=null, csp=mockCsp, policy=null, enabled=null)";
String result = "PolicyCreateRequest(csp=mockCsp, policy=null, enabled=null)";
assertThat(policyCreateRequestUnderTest.toString()).isEqualTo(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ void testIdGetterAndSetter() {
assertThat(policyUpdateRequestUnderTest.getId()).isEqualTo(id);
}

@Test
void testUserIdGetterAndSetter() {
final String userId = "userId";
policyUpdateRequestUnderTest.setUserId(userId);
assertThat(policyUpdateRequestUnderTest.getUserId()).isEqualTo(userId);
}

@Test
void testGetCsp() {
assertThat(policyUpdateRequestUnderTest.getCsp()).isEqualTo(mockCsp);
Expand Down Expand Up @@ -85,7 +78,7 @@ void testHashCode() {
@Test
void testToString() {
String result =
"PolicyUpdateRequest(id=null, userId=null, csp=mockCsp, policy=null, enabled=null)";
"PolicyUpdateRequest(id=null, csp=mockCsp, policy=null, enabled=null)";
assertThat(policyUpdateRequestUnderTest.toString()).isEqualTo(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ void testIdGetterAndSetter() {
assertThat(policyVoUnderTest.getId()).isEqualTo(id);
}

@Test
void testUserIdGetterAndSetter() {
final String userId = "userId";
policyVoUnderTest.setUserId(userId);
assertThat(policyVoUnderTest.getUserId()).isEqualTo(userId);
}

@Test
void testPolicyGetterAndSetter() {
final String policy = "policy";
Expand Down Expand Up @@ -103,7 +96,7 @@ void testHashCode() {

@Test
void testToString() {
String result = "PolicyVo(id=null, userId=null, policy=null, csp=mockCsp, enabled=null," +
String result = "PolicyVo(id=null, policy=null, csp=mockCsp, enabled=null," +
" createTime=null, lastModifiedTime=null)";
assertThat(policyVoUnderTest.toString()).isEqualTo(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ServiceVoTest {
void setUp() {
serviceVo = new ServiceVo();
serviceVo.setId(uuid);
serviceVo.setUserId(userId);
serviceVo.setCategory(category);
serviceVo.setName(name);
serviceVo.setCustomerServiceName(customerServiceName);
Expand All @@ -55,7 +54,6 @@ void setUp() {
@Test
void testGetterAndSetter() {
assertEquals(uuid, serviceVo.getId());
assertEquals(userId, serviceVo.getUserId());
assertEquals(category, serviceVo.getCategory());
assertEquals(name, serviceVo.getName());
assertEquals(customerServiceName, serviceVo.getCustomerServiceName());
Expand Down Expand Up @@ -92,7 +90,6 @@ public void testEqualsAndHashCode() {
assertNotEquals(serviceVo.hashCode(), serviceVo1.hashCode());
assertNotEquals(serviceVo1.hashCode(), serviceVo2.hashCode());

serviceVo1.setUserId(userId);
assertNotEquals(serviceVo, serviceVo1);
assertNotEquals(serviceVo1, serviceVo2);
assertNotEquals(serviceVo.hashCode(), serviceVo1.hashCode());
Expand Down Expand Up @@ -157,7 +154,6 @@ public void testEqualsAndHashCode() {
void testToString() {
String expectedString = "ServiceVo(" +
"id=" + uuid +
", userId=" + userId + "" +
", category=" + category +
", name=" + name + "" +
", customerServiceName=" + customerServiceName + "" +
Expand Down

0 comments on commit da0b848

Please sign in to comment.