class OrchestrationStatusValidator {

    public void validateOrchestrationStatus(BuildingBlockExecution execution) {
        try {
            execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
            String buildingBlockFlowName = execution.getFlowToBeCalled();
            BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);

            if (buildingBlockDetail == null) {
                throw new OrchestrationStatusValidationException(
                        String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
            }

            OrchestrationStatus orchestrationStatus =
                    getOrchestrationStatus(execution, buildingBlockFlowName, buildingBlockDetail);
            if (buildingBlockDetail.getResourceType().equals(ResourceType.NO_VALIDATE)) {
                return;
            }

            if (orchestrationStatus == null) {
                throw new OrchestrationStatusValidationException(
                        "The resource's orchstration status is null. Cannot perform task on a null orchestration status");
            }
            OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient
                    .getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(),
                            orchestrationStatus, buildingBlockDetail.getTargetAction());

            if (orchestrationStatusStateTransitionDirective
                    .getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
                throw new OrchestrationStatusValidationException(
                        String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(),
                                buildingBlockDetail.getTargetAction(), orchestrationStatus));
            }

            execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
                    orchestrationStatusStateTransitionDirective.getFlowDirective());

            if (buildingBlockFlowName.matches("Create(.*)|Delete(.*)") && orchestrationStatusStateTransitionDirective
                    .getFlowDirective() == OrchestrationStatusValidationDirective.SILENT_SUCCESS) {

                updatedResourceStatus(execution, buildingBlockDetail);
            }

        } catch (BBObjectNotFoundException ex) {
            logger.error(
                    "Error occurred for bb object notfound in OrchestrationStatusValidator validateOrchestrationStatus ",
                    ex);
            if (execution.getFlowToBeCalled().contains("Unassign")) {
                execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT,
                        OrchestrationStatusValidationDirective.SILENT_SUCCESS);
            } else {
                exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
            }
        } catch (Exception e) {
            logger.error("Exception occurred", e);
            exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
        }
    }

}