Project

General

Profile

« Previous | Next » 

Revision d9091cc0

Added by Marc Dequènes almost 15 years ago

  • ID d9091cc02ae51e84b8c55de5262c8d1847121fcf

[evol] added aspects modification support, complain about missing fields (added for creation too), and better list present (non-empty) attributes

View differences:

bin/shadowwalker
self.short_desc = "Modify attributes of an item"
self.usages_params = [
"<object> <item> (<field>|<relation>)(=|+=|-=)<value> [(<field>|<relation>)(=|+=|-=)<value>] ..."
"<object> <item> (<field>|<relation>|:aspects)(=|+=|-=)<value> [(<field>|<relation>|:aspects)(=|+=|-=)<value>] ..."
]
end
......
modification_done = false
args.each do |mod_info|
mod_info =~ /^([a-zA-Z]+(?::[a-zA-Z]+)?)(=|\+=|-=)(.*)$/
mod_info =~ /^([a-zA-Z]*(?::[a-zA-Z]+)?)(=|\+=|-=)(.*)$/
key = $1
op = $2
val = $3
if key.nil?
STDERR.puts "Syntax error in modification parameters: invalid field name"
if key.nil? or op.nil?
STDERR.puts "Syntax error in modification parameters: invalid field name, or missing/unknown operator, or empty value"
exit 1
end
......
exit 4
end
val = foreign_item_list.first
when ''
case field
when 'aspects'
unless item.class.possible_aspects.include?(val)
STDERR.puts "No such aspect '#{val}' for object '#{obj_hdl}'."
exit 2
end
else
STDERR.puts "Unknown core field '#{field}'"
exit 2
end
else
STDERR.puts "Unknown type '#{type}' for field '#{field}'."
exit 2
end
# if val is nil or the latest value is removed, then the atribute is removed from the object,
# or the association's attribute is removed from one side
case op
when '='
if type == '' and field == 'aspects'
STDERR.puts "The equality operator is not possible for aspects."
exit 2
end
item.send(field + "=", [val])
when '+='
case type
......
end
item.send(field) << val
when ''
case field
when 'aspects'
item.add_aspect(val)
end
end
when '-='
case type
......
item.send(field + "=", new_val)
when 'rel'
item.send(field).delete(val)
when ''
case field
when 'aspects'
item.remove_aspect(val)
end
end
else
STDERR.puts "Syntax error in modification parameters: wrong operator"
......
end
if modification_done
missing_fields = item.missing_attributes
unless missing_fields.empty?
STDERR.puts "Cannot save the modifications; the following fields are missing:"
missing_fields.each do |field|
str = Translator.translate_field_name(field)
str += " [#{field}]" if $program_options[:handles]
puts " - #{str}"
end
exit 2
end
begin
item.save!
rescue ActiveLdap::OperationNotPermitted => e
......
key = $1
val = $2
val = nil if val == ''
if key.nil?
STDERR.puts "Syntax error in creation parameters: invalid field name"
exit 1
......
item.send(field + "=", val)
end
missing_fields = item.missing_attributes
unless missing_fields.empty?
STDERR.puts "Cannot save the new item; the following fields are missing:"
missing_fields.each do |field|
str = Translator.translate_field_name(field)
str += " [#{field}]" if $program_options[:handles]
puts " - #{str}"
end
exit 2
end
item.save!
end
end

Also available in: Unified diff