Class: ShippingBackupClient::Client::ReadClient

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/shipping_backup_client/client/shipping_backup_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#getDecriptedValue, #get_mysql_config, #init_mysql_pool

Constructor Details

#initializeReadClient

Returns a new instance of ReadClient.



12
13
14
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 12

def initialize()
  @log = ShippingBackupLogger.new
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



10
11
12
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 10

def log
  @log
end

Instance Method Details

#by_merchant_ref_id_or_tracking_id_active(id, is_active = true) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 106

def by_merchant_ref_id_or_tracking_id_active(id,is_active=true)
  return_obj = nil
  begin
    return_obj = lite_shipments_by_merchant_reference_id(id,is_active)
    return_obj = lite_shipments_by_vendor_tracking_id(id,is_active) if return_obj.empty?
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShippingLiteShipmentDAO #{e}")
    raise
  end
  return_obj
end

#by_merchant_ref_or_tracking_id(id) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 40

def by_merchant_ref_or_tracking_id(id)
  return_obj = nil
  begin
    shipments = by_merchant_reference_id(id)
    shipments = by_vendor_tracking_id(id) if shipments.empty?
    return_obj = [] if !shipments.empty?
     for shipment in shipments do
       shipment_json = shipment.as_json
       scan_audits = ShipmentScanAuditDAO.where(:shipment_id => shipment.id.to_s, :scanning_type=> "inscan", :status => ['received','received_with_error']).order('id desc').first
       shipment_json["latest_scan_audit"] = scan_audits.as_json unless scan_audits.nil?
       return_obj.push(shipment_json)
     end

    log.get_shipment_by_vendor_tracking_id(id)
    # latestAudit = ShipmentScanAuditDAO.where(:shipment_id => return_obj.shipment_id, :scanning_type=> "inscan", :status => ['received','received_with_error'])
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentDAO #{e}")
    raise
  end
  return_obj
end

#by_merchant_reference_id(mer_ref_id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 28

def by_merchant_reference_id(mer_ref_id)
  return_obj = nil
  begin
    return_obj = ShipmentDAO.by_merchant_ref_id(mer_ref_id)
    log.get_shipment_by_vendor_tracking_id(mer_ref_id)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentDAO #{e}")
    raise
  end
  return_obj
end

#by_vendor_tracking_id(vendor_tracking_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 16

def by_vendor_tracking_id(vendor_tracking_id)
  return_obj = nil
  begin
    return_obj = ShipmentDAO.by_vendor_tracking_id(vendor_tracking_id)
    log.get_shipment_by_vendor_tracking_id(vendor_tracking_id)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentDAO #{e}")
    raise
  end
  return_obj
end

#find_customer_by_id(id) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 118

def find_customer_by_id(id)
  return_obj = nil
  begin
    customer = CustomerDAO.where(:id => id).first
    if !customer.nil?
      return_obj = customer.as_json
      return_obj["postal_addresses"] = PostalAddressDAO.where(:owner_id => id).as_json
      return_obj["electronic_addresses"] = ElectronicAddressDAO.where(:owner_id => id).as_json
      return_obj["telecom_numbers"] = TelecomNumberDAO.where(:owner_id => id).as_json
    end

  rescue Exception => e
    log.error("Exception occurred while fetch data from CustomerDAO #{e}")
    raise
  end
  return_obj
end

#find_shipment_seller_by_id(id) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 137

def find_shipment_seller_by_id(id)
  seller = nil
  return_obj = nil
  begin
    shipment = ShipmentDAO.find_by_id(id)
    if !shipment.nil?
      return_seller = ReturnSellerDAO.joins(:shipment_return_seller_mappings).where(:shipment_return_seller_mappings => {:shipment_id => id}).first
      if return_seller.nil?
        seller = SellerDAO.joins(:shipment_seller_mappings).where(:shipment_seller_mappings => {:shipment_id => id}).first
      else
        seller = return_seller
      end
    end
    if !seller.nil?
      seller_id = seller.id
      return_obj = seller.as_json
      return_obj["postal_addresses"] = PostalAddressDAO.where(:owner_id => seller_id).as_json
      return_obj["electronic_addresses"] = ElectronicAddressDAO.where(:owner_id => seller_id).as_json
      return_obj["telecom_numbers"] = TelecomNumberDAO.where(:owner_id => seller_id).as_json
    end
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentDAO #{e}")
    raise
  end
  return_obj
end

#get_history_by_id(id) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 175

def get_history_by_id(id)
  return_obj = nil
  begin
    return_obj = ShipmentStatusHistoryDAO.find_by_id(id)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentStatusHistoryDAO #{e.message}")
    raise
  end
  return_obj
end

#get_lite_shipments_by_vendor_tracking_vendor_id_active(vendor_tracking_id, vendor_id, is_active = true) ⇒ Object



164
165
166
167
168
169
170
171
172
173
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 164

def get_lite_shipments_by_vendor_tracking_vendor_id_active(vendor_tracking_id, vendor_id,is_active=true)
  return_obj = nil
  begin
    return_obj = ShippingLiteShipmentDAO.where(vendor_tracking_id: vendor_tracking_id,vendor_id: vendor_id ,active: is_active)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShippingLiteShipmentDAO #{e}")
    raise
  end
  return_obj
end

#get_shipment_by_id(id) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 62

def get_shipment_by_id(id)
  return_obj = nil
  begin
    return_obj =  ShipmentDAO.find_by_id(id)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentDAO #{e}")
    raise
  end
  return_obj
end

#get_shipment_history(id) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 73

def get_shipment_history(id)
  return_obj = nil
  begin
    return_obj =  ShipmentStatusHistoryDAO.where(:shipment_id => id).order('id desc').all
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentStatusHistoryDAO #{e}")
    raise
  end
  return_obj
end

#get_shipment_note_by_history_id(id, types) ⇒ Object



186
187
188
189
190
191
192
193
194
195
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 186

def get_shipment_note_by_history_id(id,types)
  return_obj = nil
  begin
    return_obj = ShipmentNoteDAO.where(:shipment_status_history_id => id,:note_type => types.split(","))
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShipmentNoteDAO #{e.message}")
    raise
  end
  return_obj
end

#lite_shipments_by_merchant_reference_id(mer_ref_id, is_active = true) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 84

def lite_shipments_by_merchant_reference_id(mer_ref_id,is_active=true)
  return_obj = nil
  begin
    return_obj = ShippingLiteShipmentDAO.by_merchant_ref_id(mer_ref_id,is_active)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShippingLiteShipmentDAO #{e}")
    raise
  end
  return_obj
end

#lite_shipments_by_vendor_tracking_id(vendor_tracking_id, is_active = true) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/shipping_backup_client/client/shipping_backup_client.rb', line 95

def lite_shipments_by_vendor_tracking_id(vendor_tracking_id,is_active=true)
  return_obj = nil
  begin
    return_obj = ShippingLiteShipmentDAO.by_vendor_track_id(vendor_tracking_id,is_active)
  rescue Exception => e
    log.error("Exception occurred while fetch data from ShippingLiteShipmentDAO #{e}")
    raise
  end
  return_obj
end