classdef QueryStrategy < fxptds.WorkflowTopology.Strategy
    %% QUERYSTRATEGY handles read DesignStore requests
    % This class is designed to be a generic class that handles query
    % requests for multiple user intents. Currently it is only being used
    % for UserIntent.VerifyRun.
    
    % Copyright 2018-2019 The MathWorks, Inc.
    
    methods (Access = {?fxptds.WorkflowTopology.Strategy, ?fxptds.WorkflowTopology.Facade, ?WorkflowTopologyTestCase})
        function execute(this)
            
            % get parameterized input
            parsedInput = this.Settings;
            nodeName = string(parsedInput.nodeName);
            
            % create a query struct and overwrite the properties with
            % the ones given
            query = this.createDefaultQuery();
            
            % extract the query components
            query.SourceName = nodeName;
            query.Type = parsedInput.type;
            query.Search = parsedInput.search;
            query.Target = parsedInput.target;
            query.Exclude = parsedInput.exclude;
            query.SortAttribute = parsedInput.sortAttribute;
            query.SortDirection = parsedInput.sortDirection;
            query.Property = parsedInput.property;
            query.Limit = parsedInput.limit;
            query.ContainerID = parsedInput.containerID;
            
            % if node does not exist return early
            if ~this.Store.doesNodeExist(nodeName)
                return;
            end
            
            % execute query to get the requested data
            extractedData = this.executeQuery(nodeName, query);

            % set it as the strategies Response.Data
            if ~isempty(extractedData)
                this.setData(extractedData);
            end
            
        end
    end
    
    
end

