classdef AddVerificationResultAction < fxptui.internal.action.Action
    %ADDVERIFICATIONRESULTACTION Action of adding a verification result to
    %the WorkflowDepot
    
    %   Copyright 2019 The MathWorks, Inc.
    
    methods(Access = {?fxptui.internal.action.Action, ?WorkflowTestCase})
        
        function executeLocal(~, converter, workflowSetting)
            
            % extract the TopModel information from the DesignSetting
            designSettings = workflowSetting.getSettingValue('DesignSetting');
            topModel = designSettings.TopModel;
            
            % extract the VerificationRunName information from the
            % VerificationSetting
            verificationSettings = workflowSetting.getSettingValue('VerificationSetting');
            verificationRunName = verificationSettings.RunName;
            
            % get the result using the verification run name
            result = converter.getVerificationResult(verificationRunName);
            
            % get the DataLayer instance
            dataLayer = fxptds.DataLayerInterface.getInstance();
            
            % get the current Workflow ID
            currentWorkflow = dataLayer.getCurrentWorkflow(topModel);
            currentWorkflowID = currentWorkflow.ID;
            currentWorkflowIntent = currentWorkflow.WorkflowIntent;
            
            % construct a depot unit
            depotUnit = fxptds.internal.workflow.depot.WorkflowDepotUnit;
            depotUnit = depotUnit.setID(currentWorkflowID);
            depotUnit = depotUnit.setIntent(currentWorkflowIntent);
            depotUnit = depotUnit.setResult(result);
            
            % add the depot unit to dataset
            dataLayer.addDepotUnit(designSettings.TopModel, depotUnit);
            
        end
        
    end
    
end
