server/executionhandlers/ruby/connection.rb in cpee-2.1.14 vs server/executionhandlers/ruby/connection.rb in cpee-2.1.15
- old
+ new
@@ -11,10 +11,11 @@
# You should have received a copy of the GNU General Public License along with
# CPEE (file COPYING in the main directory). If not, see
# <http://www.gnu.org/licenses/>.
require 'charlock_holmes'
+require 'base64'
class ConnectionWrapper < WEEL::ConnectionWrapperBase
def self::loop_guard(arguments,id,count) # {{{
controller = arguments[0]
tsn = Time.now
@@ -195,15 +196,16 @@
end # }}}
def inform_manipulate_change(status,changed_dataelements,changed_endpoints,dataelements,endpoints) # {{{
unless status.nil?
@controller.notify("status/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :id => status.id, :message => status.message)
end
- unless changed_dataelements.nil?
- @controller.notify("dataelements/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :changed => changed_dataelements, :values => dataelements)
+ unless changed_dataelements.nil? || changed_dataelements.empty?
+ de = dataelements.slice(*changed_dataelements).transform_values { |v| detect_encoding(v) == 'UTF-8' ? v : convert_to_base64(v) }
+ @controller.notify("dataelements/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :changed => changed_dataelements, :values => de)
end
- unless changed_endpoints.nil?
- @controller.notify("endpoints/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :changed => changed_endpoints, :values => endpoints)
+ unless changed_endpoints.nil? || changed_endpoints.empty?
+ @controller.notify("endpoints/change", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :label => @label, :activity => @handler_position, :changed => changed_endpoints, :values => endpoints.slice(*changed_endpoints))
end
end # }}}
def vote_sync_after # {{{
@controller.vote("activity/syncing_after", :'activity-uuid' => @handler_activity_uuid, :endpoint => @handler_endpoint, :activity => @handler_position, :label => @label)
@@ -239,16 +241,16 @@
end
end
result
end
- def detected_encoding(text)
+ def detect_encoding(text)
CharlockHolmes::EncodingDetector.detect(text)[:encoding] || 'ISO-8859-1'
end
- def convert_to_utf8(text)
- CharlockHolmes::Converter.convert(text, detected_encoding(text), "UTF-8")
+ def convert_to_base64(text)
+ 'data:application/octet-stream;base64,' + Base64::urlsafe_encode64(text)
end
def structurize_result(result)
result.map do |r|
if r.is_a? Riddl::Parameter::Simple
@@ -265,10 +267,10 @@
r.value.read
end
tmp = {
'name' => r.name == '' ? 'result' : r.name,
'mimetype' => r.mimetype,
- 'data' => res
+ 'data' => (detect_encoding(res) == 'UTF-8' ? res : convert_to_base64(res))
}
r.value.rewind
tmp
end
end