Class: Services::AbaqisMdsPush

Inherits:
MdsPush show all
Defined in:
app/models/services/abaqis_mds_push.rb

Constant Summary collapse

URI_TEMPLATE =
'%s/stagei/mds30_composite_file'

Instance Attribute Summary

Attributes inherited from ServiceImplementation

#service_definition

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MdsPush

#invoke, #push_mds_file

Methods inherited from ServiceImplementation

#account_map, #initialize, #server_credentials

Constructor Details

This class inherits a constructor from Services::ServiceImplementation

Class Method Details

.configured_account(account_id) ⇒ Object



17
18
19
20
# File 'app/models/services/abaqis_mds_push.rb', line 17

def self.()
  svc_def = service_definition
  svc_def.configured_accounts.where(account_id: ).first if svc_def.present?
end

.service_definitionObject



13
14
15
# File 'app/models/services/abaqis_mds_push.rb', line 13

def self.service_definition
  ServiceDefinition.where(service_class: self.name.split("::").last).first
end

.service_implObject



7
8
9
10
11
# File 'app/models/services/abaqis_mds_push.rb', line 7

def self.service_impl
  svc_def = service_definition
  
  svc_def.service_implementation if svc_def.present?
end

Instance Method Details

#submit_to_service(available_file) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/services/abaqis_mds_push.rb', line 22

def submit_to_service(available_file)
   = available_file..
  conf_acct = service_definition.configured_accounts.where(account_id: ).first
  raise "Account '#{}' is not configured for the MDS Web Service" if conf_acct.blank?
  raise "Account '#{}' is not enabled for the MDS Web Service" unless conf_acct.enabled?
  mdsws_password = conf_acct.credentials.first.try(:password)
  raise "Account '#{}' does not have a password defined for the MDS Web Service" if mdsws_password.blank?

  response = RestClient.post(url,
                             { :composite_file => File.new(available_file.actual_file_path, 'rb') },
                             { 'account-id' => ,
                               'account-password' => mdsws_password }).body

  Rails.logger.info response

  r = MdsWsResponse.parse_xml_response(response)
  if r.status == MdsWsResponse::STATUS_SUCCESS
    available_file.update_attribute :status, AvailableFile::STATUS_UPLOADED
  else
    available_file.update_attributes status: AvailableFile::STATUS_UPLOAD_ERROR, error: r.error_message
  end
end

#urlObject



45
46
47
# File 'app/models/services/abaqis_mds_push.rb', line 45

def url
  format URI_TEMPLATE, service_definition.server_base_url
end