Class: Mxrb::Model::Module

Inherits:
Unit
  • Object
show all
Defined in:
lib/mxrb/model/module.rb

Overview

$Type: Projects$Module ContainmentName: "Modules"

Constant Summary collapse

INFRASTRUCTURE_DOCUMENT_ROUTES =
{
  'ExportMappings$ExportMapping' => 'mappings/exports',
  'ImportMappings$ImportMapping' => 'mappings/imports',
  'JsonStructures$JsonStructure' => 'mappings/json_structures',
  'MessageDefinitions$MessageDefinitionCollection' => 'mappings/message_definitions',
  'MessageDefinitions$MessageDefinition2' => 'mappings/message_definitions',
  'XmlSchemas$XmlSchema' => 'mappings/xml_schemas',
  'Rest$PublishedRestService' => 'endpoints',
  'WebServices$PublishedService' => 'endpoints',
  'WebServices$PublishedWebService' => 'endpoints',
  'ODataPublish$PublishedODataService' => 'endpoints',
  'ODataPublish$PublishedODataService2' => 'endpoints',
  'Rest$ConsumedRestService' => 'integrations',
  'Rest$ConsumedODataService' => 'integrations',
  'AppServices$ConsumedAppService' => 'integrations',
  'ODataImport$ConsumedODataService' => 'integrations'
}.freeze
MAPPING_DOCUMENT_TYPES =
INFRASTRUCTURE_DOCUMENT_ROUTES.keys.grep(
  /Mappings|JsonStructures|MessageDefinitions|XmlSchemas/
).freeze
APPLICATION_DOCUMENT_ROUTES =
{
  'DataSets$DataSet' => 'queries/datasets',
  'ScheduledEvents$ScheduledEvent' => 'jobs/scheduled_events'
}.freeze
DOMAIN_DOCUMENT_ROUTES =
{
  'DomainModels$ViewEntitySourceDocument' => 'oql_views',
  'Enumerations$Enumeration' => 'enumerations',
  'Constants$Constant' => 'constants'
}.freeze
EDITABLE_DOCUMENT_TYPES =
(
  INFRASTRUCTURE_DOCUMENT_ROUTES.keys + APPLICATION_DOCUMENT_ROUTES.keys +
  DOMAIN_DOCUMENT_ROUTES.keys
).freeze

Instance Attribute Summary collapse

Attributes inherited from Unit

#bson_type, #container_id, #containment_name, #id, #mpr

Instance Method Summary collapse

Methods inherited from Unit

#initialize, #save!

Constructor Details

This class inherits a constructor from Mxrb::Model::Unit

Instance Attribute Details

#app_store_guidObject (readonly)

Returns the value of attribute app_store_guid.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def app_store_guid
  @app_store_guid
end

#app_store_versionObject (readonly)

Returns the value of attribute app_store_version.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def app_store_version
  @app_store_version
end

#export_levelObject (readonly)

Returns the value of attribute export_level.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def export_level
  @export_level
end

#from_app_storeObject (readonly)

Returns the value of attribute from_app_store.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def from_app_store
  @from_app_store
end

#nameObject (readonly)

Returns the value of attribute name.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def name
  @name
end

#sort_indexObject (readonly)

Returns the value of attribute sort_index.



44
45
46
# File 'lib/mxrb/model/module.rb', line 44

def sort_index
  @sort_index
end

Instance Method Details

#application_documentsObject



129
130
131
# File 'lib/mxrb/model/module.rb', line 129

def application_documents
  @application_documents ||= routed_documents(APPLICATION_DOCUMENT_ROUTES)
end

#associationsObject



77
# File 'lib/mxrb/model/module.rb', line 77

def associations = domain_model&.associations || []

#constantsObject



109
110
111
112
113
# File 'lib/mxrb/model/module.rb', line 109

def constants
  @constants ||= document_units
                 .select { |u| u[:type] == "Constants$Constant" }
                 .map { unit_to_doc(_1) }
end

#decode(doc) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/mxrb/model/module.rb', line 47

def decode(doc)
  @name              = doc["Name"]
  @sort_index        = doc["SortIndex"] || doc["NewSortIndex"]
  @from_app_store    = doc["FromAppStore"] == true
  @app_store_guid    = doc["AppStoreGuid"]
  @app_store_version = doc["AppStoreVersion"]
  @export_level      = doc["ExportLevel"] || "Hidden"
end

#domain_documentsObject



133
134
135
# File 'lib/mxrb/model/module.rb', line 133

def domain_documents
  @domain_documents ||= routed_documents(DOMAIN_DOCUMENT_ROUTES)
end

#domain_modelObject

── Children (resolved from Unit table by ContainerID) ────────────



69
70
71
72
73
74
# File 'lib/mxrb/model/module.rb', line 69

def domain_model
  @domain_model ||= begin
    raws = @mpr.units_by_containment("DomainModel").select { _1["ContainerID"] == @id }
    raws.empty? ? nil : DomainModel.new(raws.first, @mpr)
  end
end

#entitiesObject



76
# File 'lib/mxrb/model/module.rb', line 76

def entities    = domain_model&.entities    || []

#enumerationsObject



103
104
105
106
107
# File 'lib/mxrb/model/module.rb', line 103

def enumerations
  @enumerations ||= document_units
                    .select { |u| u[:type] == "Enumerations$Enumeration" }
                    .map { unit_to_doc(_1) }
end

#infrastructure_documentsObject



125
126
127
# File 'lib/mxrb/model/module.rb', line 125

def infrastructure_documents
  @infrastructure_documents ||= routed_documents(INFRASTRUCTURE_DOCUMENT_ROUTES)
end

#inspectObject



157
158
159
160
# File 'lib/mxrb/model/module.rb', line 157

def inspect
  "#<Mxrb::Module name=#{@name.inspect} entities=#{entities.size} " \
    "pages=#{pages.size} microflows=#{microflows.size}>"
end

#mapping_documentsObject



121
122
123
# File 'lib/mxrb/model/module.rb', line 121

def mapping_documents
  infrastructure_documents.select { MAPPING_DOCUMENT_TYPES.include?(_1[:type]) }
end


97
98
99
100
101
# File 'lib/mxrb/model/module.rb', line 97

def menus
  @menus ||= document_units
             .select { |u| u[:type] == "Menus$MenuDocument" }
             .map { Menu.new(_1[:raw], @mpr) }
end

#microflowsObject



85
86
87
88
89
# File 'lib/mxrb/model/module.rb', line 85

def microflows
  @microflows ||= document_units
                  .select { |u| u[:type] == "Microflows$Microflow" }
                  .map { Microflow.new(_1[:raw], @mpr) }
end

#module_rolesObject



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mxrb/model/module.rb', line 143

def module_roles
  @module_roles ||= begin
    raw = @mpr.children_of(@id).find { _1["ContainmentName"] == "ModuleSecurity" }
    if raw
      doc = @mpr.parse_contents(raw)
      parse_array(doc["ModuleRoles"]).map do |role|
        { name: role["Name"], description: role["Description"].to_s }
      end
    else
      []
    end
  end
end

#nanoflowsObject



91
92
93
94
95
# File 'lib/mxrb/model/module.rb', line 91

def nanoflows
  @nanoflows ||= document_units
                 .select { |u| u[:type] == "Microflows$Nanoflow" }
                 .map { Microflow.new(_1[:raw], @mpr) }
end

#oql_view_documentsObject



137
138
139
140
141
# File 'lib/mxrb/model/module.rb', line 137

def oql_view_documents
  @oql_view_documents ||= domain_documents.select do |document|
    document[:type] == 'DomainModels$ViewEntitySourceDocument'
  end
end

#pagesObject



79
80
81
82
83
# File 'lib/mxrb/model/module.rb', line 79

def pages
  @pages ||= document_units
             .select { |u| %w[Pages$Page Forms$Page].include?(u[:type]) }
             .map { Page.new(_1[:raw], @mpr) }
end

#scheduled_eventsObject



115
116
117
118
119
# File 'lib/mxrb/model/module.rb', line 115

def scheduled_events
  @scheduled_events ||= document_units
                        .select { |u| u[:type] == "ScheduledEvents$ScheduledEvent" }
                        .map { unit_to_doc(_1) }
end

#to_bsonObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/mxrb/model/module.rb', line 56

def to_bson
  {
    "$ID"          => @id,
    "$Type"        => "Projects$Module",
    "Name"         => @name,
    "SortIndex"    => @sort_index || 0,
    "FromAppStore" => @from_app_store || false,
    "ExportLevel"  => @export_level || "Hidden",
  }
end