module OEHClient::Meta::Entity ### ### ------------- Constants ### ONE_PARAM_DATA = "data" ONE_PARAM_SUCCESS = "success" ONE_PARAM_ID = "id" ONE_PARAM_NAME = "name" ONE_PARAM_CREATED_ON = "createdDate" ONE_PARAM_CREATED_BY = "createdBy" ONE_PARAM_ITEMS = "items" ### ### ------------- Class Attributes ### def entity_uri_stem=(uri_stem) @entity_stem = uri_stem end def entity_uri_stem @entity_stem end def session=(session_instance) @session = session_instance end def session @session end ### ### ------------- Helper Class Methods ### def create() end # def self.create def find_by_name(active_session, name, **args) get(active_session, {:name => ONE_PARAM_NAME, :value => name}, args) end ### ### ------------- Core Class Methods ### def get_collection(active_session, **args) # store the active session object for future use self.session = active_session if (session.nil?) # get the list of args entity_uri = (args.has_key?(:space)) ? "workspaces/#{args[:space]}/#{entity_uri_stem}" : "#{entity_uri_stem}" # construct the URL for retrieving the entity url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{self.session.space.host}/one/services/api/#{entity_uri}" # set the header information header = (!self.session.cookies.nil? ? {:cookies => self.session.cookies}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header()) # construct the request params using the header and params (if passed) request_params = {:header => header} request_params.merge!({:params => args[:params]}) if (args.has_key?(:params)) # GET the data collection_response = OEHClient.get(url, nil, request_params) # return the data object for valid requests or a blank array otherwise ((collection_response.has_key?(:body) && collection_response[:body][ONE_PARAM_SUCCESS]) ? (collection_response[:body][ONE_PARAM_DATA].is_a?(Hash) ? collection_response[:body][ONE_PARAM_DATA][ONE_PARAM_ITEMS] : collection_response[:body][ONE_PARAM_DATA]) : [] ) end # def get_collection def get(active_session, attribute_nvp, **args) # store the active session object for future use session = active_session if (session.nil?) # initialize the entity instance as a blank hash entity_instance = Hash.new # Get the collection of objects requested get_collection(session, **args).each do | collection_instance | puts "-----] Collection Instance: #{collection_instance}" # find the matching entry and assign the entity instance entity_instance = collection_instance if (collection_instance[attribute_nvp[:name]].casecmp(attribute_nvp[:value]) == 0) end # Each OEHClient::Meta::Entity.get_collection # return the copy of the entity instance data entity_instance end # def get ### ### ------------- Instance Attributes ### ### ### ------------- Instance Methods ### ### ### ------------- Protected Class Methods ### protected end