class PIM::ValueFilter

Constants

TEMPLATE_PATTERN

Immediate (${…}) or deferred (#{…}) Jxlt interpolations.

TYPES

Supported types (serialized as uppercase JSON for Java ValueFilter.Type):

  • :array – Ruby Array (membership match)

  • :boolean – true/false (item_scopes allow/deny; always matches when true)

  • :regexp – Ruby Regexp

  • :string – exact string match

  • :template – Jxlt Expression (not a Jexl Expression and not a Jxlt Unified Template). Characters outside ${…} / #{…} are retained as literal text, e.g.

    "GLN of organization ${targetOrganization.name} is ${targetOrganization.gln}"
    

    Structural statements (if/while/return as a script body) are not allowed; only expressions inside interpolations. Boolean-returning templates like

    "${sourceOrganization.isCommunityManager}"
    

    are valid match predicates.

  • :script – Jexl Script (let/if/return, …). Recommended: always set type explicitly, e.g.

    { type: :script,
      value: %q( if (myAttribute == targetOrganization.gln) { return true; } else { return false; } ) }
    

    Heuristic (compat only): a String with at least one newline that did not match array/boolean/regexp/template is classified as :script. Prefer explicit type: :script in new data-model code.

Auto-detect order: array → boolean → regexp → template (${…}/#{…}) → script (newline) → string.

Note: Ruby double-quoted strings interpolate #{…} before create sees them; use %q / single quotes when the DM should carry deferred #{…} or multi-line scripts. map_value on DirectPublication remains a bare String evaluated as a Jexl Script (same engine mode as type :script).

Public Class Methods

create(value, types: TYPES) click to toggle source
# File pim.rb, line 12157
def self.create value, types: TYPES

  if PIM.is_hash?(value)
    type = value[:type] || value['type']
    value = value[:value] || value['value']
  end

  return nil if value.nil?

  if type.nil?
    if types.include?(:array) && PIM.is_array?(value)
      type = :array
    elsif types.include?(:boolean) && PIM.is_boolean?(value)
      type = :boolean
    elsif types.include?(:regexp) && PIM.is_regexp?(value)
      type = :regexp
    elsif types.include?(:template) && TEMPLATE_PATTERN.match?(value.to_s)
      type = :template
    elsif types.include?(:script) && value.to_s.include?("\n")
      # Heuristic: multi-line string → script. Prefer explicit type: :script.
      type = :script
    else
      type = :string
    end
  end

  type = type.to_s.downcase.to_sym
  raise "#{self.name} type '#{type}' is not valid" unless types.include?(type)

  value = Array(value.to_s) if type == :array and !PIM.is_array?(value)
  value = to_boolean(value) if type == :boolean and !PIM.is_boolean?(value)
  value = Regexp.new(value.to_s) if type == :regexp and !PIM.is_regexp?(value)
  value = value.to_s if %i(string template script).include?(type) and !PIM.is_string?(value)

  self.new(value: value, type: type)

end

Public Instance Methods

as_json() click to toggle source
# File pim.rb, line 12211
def as_json
  {
    value: value,
    type: type.to_s.upcase
  }
end
matches?(match_value) click to toggle source
# File pim.rb, line 12195
def matches? match_value
  case type
  when :array
    return self[:value].include?(match_value)
  when :boolean
    return self[:value]
  when :regexp
    return self[:value].match?(match_value)
  when :string
    return self[:value] == match_value
  when :template, :script
    # NOTE: JEXL/JXLT evaluation happens on the Java side only.
  end
  return nil
end
to_json(*args) click to toggle source
# File pim.rb, line 12218
def to_json *args
  as_json.to_json(*args)
end