Class: UU::OS::Content::Component

Inherits:
ContentClient
  • Object
show all
Defined in:
lib/uu/os/content/component.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Component

Creates a new instance of Component.

Parameters:

  • session (UU::OS::Security::Session)

    Session to use for remote calls.



14
15
16
# File 'lib/uu/os/content/component.rb', line 14

def initialize(session)
  @cmd = UU::OS::CMD::CommandClient.new('uu-os-content', session)
end

Class Method Details

.create(sheet_uri, dto = nil) ⇒ Object

#create convenience self-instantiating shortcut



49
50
51
52
# File 'lib/uu/os/content/component.rb', line 49

def self.create(sheet_uri, dto = nil)
  session = UU::OS::Security::Session.current_session
  self.new(session).create(sheet_uri, dto)
end

.delete(sheet_uri, component_id) ⇒ Object

#delete convinience self-instantiating shortcut



67
68
69
70
# File 'lib/uu/os/content/component.rb', line 67

def self.delete(sheet_uri, component_id)
  session = UU::OS::Security::Session.current_session
  self.new(session).delete(sheet_uri, component_id)
end

.get_attributes(sheet_uri, component_id) ⇒ Object

#get_attributes convenience self-instantiating shortcut



105
106
107
108
# File 'lib/uu/os/content/component.rb', line 105

def self.get_attributes(sheet_uri, component_id)
  session = UU::OS::Security::Session.current_session
  self.new(session).get_attributes(sheet_uri, component_id)
end

.get_data(sheet_uri, component_id) ⇒ Object

#get_data convenience self-instantiating shortcut



131
132
133
134
# File 'lib/uu/os/content/component.rb', line 131

def self.get_data(sheet_uri, component_id)
  session = UU::OS::Security::Session.current_session
  self.new(session).get_data(sheet_uri, component_id)
end

.set_attributes(sheet_uri, component = nil) ⇒ Object

#set_attributes convenience self-instantiating shortcut



157
158
159
160
# File 'lib/uu/os/content/component.rb', line 157

def self.set_attributes(sheet_uri,  component = nil)
  session = UU::OS::Security::Session.current_session
  self.new(session).set_attributes(sheet_uri,  component)
end

.set_constraints(sheet_uri, constraints = nil) ⇒ Object

#set_constraints convenience self-instantiating shortcut



181
182
183
184
# File 'lib/uu/os/content/component.rb', line 181

def self.set_constraints(sheet_uri,  constraints = nil)
  session = UU::OS::Security::Session.current_session
  self.new(session).set_constraints(sheet_uri ,  constraints)
end

.set_data(sheet_uri, data = nil) ⇒ Object

#set_data convinience self-instantiating shortcut



208
209
210
211
# File 'lib/uu/os/content/component.rb', line 208

def self.set_data(sheet_uri,  data = nil)
  session = UU::OS::Security::Session.current_session
  self.new(session).set_data(sheet_uri,  data)
end

Instance Method Details

#create(sheet_uri, component = nil) ⇒ String

Creates the component in a given column. The type of the component should be specified. The data of the component can be set using a corresponding command set_data.

Examples:

UU::OS::Content::Component.create('ues:TER:ART:SHEET', :column_id => "12345678", :code => "COMPONENT_2",
:opt=>{:mandatory=>true})

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, where the component will be created.

  • component (Hash) (defaults to: nil)

    Object containing attributes of the component.

Options Hash (component):

  • :column_id (String)

    An identifier of the column, where the new component will be created.

  • :code (String)

    User-defined code of the component. Must be unique in a scope of the Content. If nil or empty, the code is automatically generated.

  • :component_code (String)

    The type of the component. If not set, default component is UU.OS.RICHTEXT/RICHTEXT.

  • :component_engine (String)

    The attribute defines the engine of the component. Possible values are: COMPONENT_CONTENT (the only possible component code is UU.OS.RICHTEXT/RICHTEXT at the moment), UUOS8_WIDGET (for widgets registered using UU::OS::Widget) and UUOS9_WIDGET (for widgets in uuOS9). Default value is COMPONENT_CONTENT.

  • :order (Integer)

    Represents the order of the component in a scope of column starting with 0. If the value is less than 0 the component is created at the beginning of the column. If order is nil or empty, or the value is greater than the number of existing components in column the component is created at the end of the column (after last existing component).

  • :props (Hash)

    Contains the specific attributes for the given component.

  • :opt (Hash)

    Object contains the additional attributes of the component.

    • :readonly ([Boolean]) Defines whether the component is readonly (component content cannot be modified, component attributes cannot be modified, component cannot be deleted).

    • :mandatory ([Boolean]) Defines whether the component is mandatory in sheet content (component cannot be deleted). Mandatory constraint is propagated to the column and row, which contain the component.

    • :visible ([Boolean]) Defines whether the component is displayed in sheet content. The value of this attribute does not affect operating with the component through API.

    • :add_before ([Boolean]) Defines, whether it is possible to create new component before the given one. The value of this attribute does not affect operating with the component through API.

    • :add_after ([Boolean]) Defines, whether it is possible to create new component after the given one. The value of this attribute does not affect operating with the component through API.

    • :html_attributes ([Hash]) Contains the attributes defining HTML attributes for the component.

    • :alignment (String) - default: left - Indicates how the widget will be aligned in content, default value is left. If component_engine is COMPONENT_CONTENT the attribute is ignored.

Returns:

  • (String)

    Returns id of the newly created component.



43
44
45
46
# File 'lib/uu/os/content/component.rb', line 43

def create(sheet_uri, component = nil)
  res = @cmd.invoke("Component/create", sheet_uri, prepare_params(component))
  return res
end

#delete(sheet_uri, component_id) ⇒ Object

Removes the given component from the content structure.

Examples:

UU::OS::Content::Component.delete('ues:TER:ART:SHEET', :component_id => "12345678")

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which content component will be deleted.

  • component_id (Hash)

    Object containing basic attributes of the component that will be deleted.

Options Hash (component_id):

  • :component_id (String)

    An identifier of an existing row, which attributes will be deleted.



62
63
64
# File 'lib/uu/os/content/component.rb', line 62

def delete(sheet_uri, component_id)
  @cmd.invoke("Component/delete", sheet_uri, prepare_params(component_id))
end

#get_attributes(sheet_uri, component_id) ⇒ Hash

Retrieves the attributes of the given component.

Examples:

UU::OS::Content::Component.get_attributes('ues:TER:ART:SHEET', :component_id => "12345678")

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which component attributes will be returned.

  • component_id (Hash)

    Object containing basic attributes of the component that will be returned.

Options Hash (component_id):

  • :component_id (String)

    An identifier of an existing component, which attributes will be returned.

Returns:

  • (Hash)

    Returns Object containing the attributes of the given component.

    • :id (String) - Unique identifier of the component. Not nil.

    • :code (String) - User-defined code of the component. Must be unique in a scope of the Content. If nil or empty, the code is automatically generated. Not nil.

    • :component_code (String) -The code of the component artifact.

    • :component_engine (String) - The engine of the component.

    • :order (Integer) - The order of the component in a scope of column.

    • :revision (Integer) - The version of the component. Not nil.

    • :props (Hash) - Contains the specific attributes for the given component.

    • :opt (Hash) - Object contains the additional attributes of the component.

      • :readonly ([Boolean]) - Defines whether the component is readonly (component content cannot be modified, component attributes cannot be modified, component cannot be deleted).

      • :mandatory ([Boolean]) - Defines whether the component is mandatory in sheet content (component cannot be deleted). Mandatory constraint is propagated to the column and row, which contain the component.

      • :visible ([Boolean]) - Defines whether the component is displayed in sheet content. The value of this attribute does not affect operating with the component through API.

      • :add_before ([Boolean]) - Defines, whether it is possible to create new component before the given one. The value of this attribute does not affect operating with the component through API.

      • :add_after ([Boolean]) - Defines, whether it is possible to create new component after the given one. The value of this attribute does not affect operating with the component through API.

      • :html_attributes ([Hash]) - Contains the attributes defining HTML attributes for the component.

      • :alignment (String) - default: left - Indicates how the widget will be aligned in content, default value is left. If component_engine is COMPONENT_CONTENT the attribute is ignored.

    • :lock_time (String) - Time when the component was locked (if locked) in ISO 8601 format.

    • :lock_role_uri (UU::OS::UESURI) - Normalized UESURI of the role that locked the component (if locked).

    • :lock_access_role_uri (UU::OS::UESURI) - Normalized UESURI of the access role that locked the component (if locked).



100
101
102
# File 'lib/uu/os/content/component.rb', line 100

def get_attributes(sheet_uri, component_id)
  transform(@cmd.invoke('Component/getAttributes', sheet_uri, prepare_params(component_id))) #, invocation_method: 'get')
end

#get_data(sheet_uri, data) ⇒ Array<Hash>, BinaryValue

Retrieves the data of the given component. The data format is defined by the component type.

Examples:

data = UU::OS::Content::Component.get_data('ues:TER:ART:SHEET', :component_id=>"123456", :mime_type=>"application/zip")
target_file = File.new("file.zip","wb")
target_file.write(data.content.read)
target_file.close

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which component data will be retrieved.

  • data (Hash)

    Object containing information about export.

Options Hash (data):

  • :component_id (String)

    An identifier of the component which data will be retrieved.

  • :mime_type (String)

    Specifies the format of the retrieved data. Allowed values are 'application/zip', and 'application/xml' (the default value).

  • :version_id (String)

    An identifier of the content version from ChangeLog. When set, corresponding component version will be retrieved.

Returns:

  • (Array<Hash>, BinaryValue)

    Returns the data of the component. The format of the data is defined by the type of the component and by the “format” parameter.



125
126
127
128
# File 'lib/uu/os/content/component.rb', line 125

def get_data(sheet_uri, data)
  res = @cmd.invoke('Component/getData', sheet_uri, prepare_params(data)) #, invocation_method: 'get')
  return res
end

#set_attributes(sheet_uri, component = nil) ⇒ String

Updates basic attributes of the specified component.

Examples:

UU::OS::Content::Component.set_attributes('ues:TER:ART:SHEET', :component_id => "12345678", :code => "COMPONENT_2")

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which component attributes will be set.

  • component (Hash) (defaults to: nil)

    Object containing basic attributes of the component that will be updated.

Options Hash (component):

  • :component_id (String)

    An identifier of the component, which attributes will be set.

  • :code (String)

    User-defined code of the component. Must be unique in a scope of the Content. If nil or empty, the code is automatically generated.

  • :html_attributes (Object)

    Contains the attributes defining HTML attributes for the component.

  • :props (Object)

    Contains the specific attributes for the given component.

  • :order (Integer)

    Represents the order of the component in a scope of column starting with 0. If the value is less than 0 the component is moved to the beginning of the column. If order is nil or empty, or the value is greater than the number of existing components in column the component is moved at the end of the column (after last existing component). The orders of the existing components is changed accordingly.

  • :alignment (String)

    Indicates how the widget will be aligned in content, default value is left. If component_engine is COMPONENT_CONTENT the attribute is ignored.

Returns:

  • (String)

    Returns id of the updated component.



151
152
153
154
# File 'lib/uu/os/content/component.rb', line 151

def set_attributes(sheet_uri, component = nil)
  res = @cmd.invoke('Component/setAttributes', sheet_uri, prepare_params(component))
  return res
end

#set_constraints(sheet_uri, constraints = nil) ⇒ Object

Sets constraints on the component.

Examples:

UU::OS::Content::Component.set_constraints('ues:TER:ART:SHEET', :component_id => "12345678", :readonly => true,
:mandatory => true, :visible => true, :add_before => false, :add_after => false)

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which component constraints will be set.

  • constraints (Hash) (defaults to: nil)

    Object containing constraints definitions.

Options Hash (constraints):

  • :component_id (String)

    An identifier of the component, which constraints will be set.

  • :readonly (Boolean)

    Defines whether the component is readonly (component content cannot be modified, component attributes cannot be modified, component cannot be deleted).

  • :mandatory (Boolean)

    Defines whether the component is mandatory in sheet content (component cannot be deleted). Mandatory constraint is propagated to the column and row, which contain the component.

  • :visible (Boolean)

    Defines whether the component is displayed in sheet content. The value of this attribute does not affect operating with the component through API.

  • :add_before (Boolean)

    Defines, whether it is possible to create new component before the given one. The value of this attribute does not affect operating with the component through API.

  • :add_after (Boolean)

    Defines, whether it is possible to create new component after the given one. The value of this attribute does not affect operating with the component through API.



176
177
178
# File 'lib/uu/os/content/component.rb', line 176

def set_constraints(sheet_uri, constraints = nil)
  @cmd.invoke('Component/setConstraints', sheet_uri, prepare_params(constraints))
end

#set_data(sheet_uri, data = nil) ⇒ Object

Modifies data of the given component. Data should be in a valid format, defined by the component.

Examples:

# Set data as a string
UU::OS::Content::Component.set_data('ues:TER:ART:SHEET',
:component_id=>"12345", :data=>'<Richtext>...</Richtext>')
# Set data in a zip file
file =  File.open("myzip.zip", "rb")
UU::OS::Content::Component.set_data('ues:TER:ART:SHEET',
:component_id=>"12345", :data=>file)

Parameters:

  • sheet_uri (String, UU::OS::UESURI)

    UESURI of the sheet, which component data will be set.

  • data (Hash) (defaults to: nil)

    Object containing information about export.

Options Hash (data):

  • :component_id (String)

    An identifier of the existing component which data will be set.

  • :data (BinaryValue)

    The new data of the component. Data should be in a valid format for the given component.



202
203
204
205
# File 'lib/uu/os/content/component.rb', line 202

def set_data(sheet_uri,  data = nil)
  @cmd.invoke('Component/setData', sheet_uri, prepare_params(data))
  return nil
end