######## ####### ######## ####### ######## ######## ## / / / / License \ \ \ \ ## Copyleft culture, Copyright (C) is prohibited here ## This work is licensed under a CC BY-SA 4.0 ## Creative Commons Attribution-ShareAlike 4.0 License ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/ ######## ####### ######## ####### ######## ######## ## / / / / Code Climate \ \ \ \ ## Language = ruby ## Indent = space; 4 chars; ######## ####### ######## ####### ######## ######## module ArchestryLookup module Sql class << self #TODO: flags 'skip' in props # def makeInternalLookups(args, keyType, valueType, container, id) args[keyType][valueType] ||= {} args[keyType][valueType][:id] ||= {} args[keyType][valueType][:id][id] = container args[valueType][:schema].each do |k| args[keyType][valueType][k] ||= {} args[keyType][valueType][k][container[k]] ||= [] args[keyType][valueType][k][container[k]] << id end end def archestry_model_lookup(args, state) mfv = {} sqlQuery(state, "SELECT m1.id as id, m1.name as name, m1.version as ver, m1.created_by as cby, m1.created_on as con FROM models as m1 WHERE version = (select max(m2.version) FROM models as m2 WHERE m1.id = m2.id)").each do |id, model| sqlQuery(state, "SELECT p1.name, p1.value FROM properties as p1 WHERE p1.parent_id LIKE '#{model[:id]}' and p1.name LIKE 'modelType' and p1.parent_version = #{model[:ver]}").each do |id, type| model[:type] = type[:value].to_sym makeInternalLookups(args, :models, :models, model, model[:id]) args[:elements][:base][model[:type]][:id] ||= {} if args[:models][:models][:id][model[:id]][:type] == :library or args[:models][:models][:id][model[:id]][:name] == state[:funcFolder] ArchestryLookup.logger.info "Use model '#{model[:name]}' version #{model[:ver]} type '#{model[:type]}' created by '#{model[:cby]}' on #{model[:con]}" mfv[:model] = model getModelFolders(state, args, mfv) end end end end def getFolderViews(args, state, mfv) a = sqlQuery(state, "select view_id as id, model_version as mver FROM views_in_model as vm1 WHERE vm1.parent_folder_id in ('#{mfv[:folder][:id]}') and vm1.model_version = (select max(vm2.model_version) FROM views_in_model as vm2 WHERE vm2.view_id in (vm1.view_id))").each do |k, viewInM| viewAtr = sqlQuery(state, "select v1.id, v1.version as ver, v1.name, v1.viewpoint, v1.created_by as cby, v1.created_on as con FROM views as v1 WHERE id in ('#{viewInM[:id]}') and version = (select max(version) FROM views as v2 WHERE v2.id in ('#{viewInM[:id]}'))") view = viewAtr[0] # view[:tid]= view[:id].tr("-", "_") makeInternalLookups(args, :views, :models, mfv[:model], view[:id]) makeInternalLookups(args, :views, :folders, mfv[:folder], view[:id]) makeInternalLookups(args, :views, :views, view, view[:id]) mfv[:view] = view view[:viewpoint] == '' ? viewpoint = 'none' : viewpoint = view[:viewpoint] ArchestryLookup.logger.info "Model '#{mfv[:model][:name]}' of type '#{mfv[:model][:type]}': view '#{view[:name]}' (id #{view[:id]}, view ver.#{view[:ver]}, model ver.#{mfv[:model][:ver]}) with viewpoint '#{viewpoint}' suits for me!" getViewConnectionsFromView(args, state, mfv) end end def getModelFolders(state, args, mfv) args[:folders] ||={} foldersInModel = sqlQuery(state, "select fm1.folder_id as id, fm1.parent_folder_id as pid, f1.name as name, f1.type as type, f1.version as ver, f1.root_type as rtype, f1.created_by as cby, f1.created_on as con FROM folders_in_model as fm1 INNER JOIN folders as f1 ON f1.id = fm1.folder_id and f1.version = (select max(f2.version) FROM folders as f2 WHERE f2.id = fm1.folder_id) WHERE fm1.model_id in ('#{mfv[:model][:id]}') and fm1.model_version = (select max(fm2.model_version) FROM folders_in_model as fm2 WHERE fm2.model_id LIKE '#{mfv[:model][:id]}') ") foldersInModel.each do |id, folder| if folder[:rtype].to_i == 7 and folder[:type].to_i == 0 makeInternalLookups(args, :folders, :models, mfv[:model], folder[:id]) makeInternalLookups(args, :folders, :folders, folder, folder[:id]) mfv[:folder] = folder getFolderViews(args, state, mfv) # mod = :view else true # p "This is Archestry core view '#{folder[:name]}' (type #{folder[:type]}, Root type #{folder[:rtype]})" # mod = :objfolder end end end end end end