Search in sources :

Example 1 with InconsistentFieldsException

use of bio.terra.common.exception.InconsistentFieldsException in project terra-workspace-manager by DataBiosphere.

the class MarkPrivateResourcesAbandonedStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    boolean userStillInWorkspace = workingMap.get(ControlledResourceKeys.REMOVED_USER_IS_WORKSPACE_MEMBER, Boolean.class);
    // to private resources.
    if (userStillInWorkspace) {
        return StepResult.getStepResultSuccess();
    }
    List<ResourceRolePair> resourceRolePairs = workingMap.get(ControlledResourceKeys.RESOURCE_ROLES_TO_REMOVE, new TypeReference<>() {
    });
    List<ControlledResource> uniqueControlledResources = resourceRolePairs.stream().map(ResourceRolePair::getResource).distinct().collect(Collectors.toList());
    for (ControlledResource resource : uniqueControlledResources) {
        PrivateResourceState privateResourceState = resource.getPrivateResourceState().orElseThrow(() -> new InconsistentFieldsException("Received private resource without private resource state set"));
        resourceDao.setPrivateResourceState(resource, privateResourceState);
    }
    return StepResult.getStepResultSuccess();
}
Also used : ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) FlightMap(bio.terra.stairway.FlightMap) InconsistentFieldsException(bio.terra.common.exception.InconsistentFieldsException) PrivateResourceState(bio.terra.workspace.service.resource.controlled.model.PrivateResourceState)

Aggregations

InconsistentFieldsException (bio.terra.common.exception.InconsistentFieldsException)1 FlightMap (bio.terra.stairway.FlightMap)1 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)1 PrivateResourceState (bio.terra.workspace.service.resource.controlled.model.PrivateResourceState)1