Class: EnjuStandaloneInterface::BatchAction
- Inherits:
-
Object
- Object
- EnjuStandaloneInterface::BatchAction
- Defined in:
- lib/enju_standalone_interface.rb
Constant Summary collapse
- Rinjndael_Default_Key =
"1234567890123456"
Class Method Summary collapse
Instance Method Summary collapse
- #checkin(row) ⇒ Object
- #checkout(row) ⇒ Object
- #decode_action(posttext, action, create_date) ⇒ Object
- #default_librarian(library_id) ⇒ Object
- #message_recept(params) ⇒ Object
Class Method Details
.message_recept(params) ⇒ Object
26 27 28 |
# File 'lib/enju_standalone_interface.rb', line 26 def self.(params) return self.new.(params) end |
Instance Method Details
#checkin(row) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/enju_standalone_interface.rb', line 163 def checkin(row) Rails.logger.info "checkin start." = [] unless row.size == 5 Rails.logger.info "row size is invalid. size=#{row.size}" return STAT_ERROR_INVALID_CHECKIN_ROWSIZE, "checkin row size is invalid. size=#{row.size}" end item_identifier = row[3] item = Item.find_by_item_identifier(item_identifier) if item.blank? return STAT_ERROR_INVALID_CHECKIN_ITEM, "item_identifier is invalid. (no record) item_id=#{item_identifier}" end unless item.rent? return STAT_ERROR_INVALID_CHECKIN_ITEM, "item_identifier is invalid. (no rent) item_id=#{item_identifier}" end librarian_number = row[1] librarian_user = User.find_by_user_number(librarian_number) if librarian_user.blank? librarian_user = User.librarians.order("users.id").first # where(:library_id=>library_id).first end worked_at_str = row[4] if worked_at_str.blank? return STAT_ERROR_INVALID_CHECKIN_FORMAT, "datetime is blank." end worked_at = nil begin worked_at = DateTime.strptime(worked_at_str, "%Y-%m-%d %H:%M:%S") worked_at = DateTime.parse(worked_at_str) rescue ArgumentError return STAT_ERROR_INVALID_CHECKOUT_FORMAT, "datetime invalid format. worked_at_str=#{worked_at_str}" end if item.rent? unless item.blank? basket = Basket.new(:user => librarian_user) basket.save!(:validate => false) checkin = basket.checkins.new(:item_id => item.id, :librarian_id => librarian_user.id) checkin.item = item user_id = item.checkouts.select {|checkout| checkout.checkin_id.nil?}.first.user_id rescue nil if checkin.save(:validate => false) = checkin.item_checkin(librarian_user, true) unless .blank? .each do || << if end end end end end Rails.logger.info "checkin success." return STAT_SUCCESS, .join(" ") end |
#checkout(row) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 |
# File 'lib/enju_standalone_interface.rb', line 85 def checkout(row) Rails.logger.info "checkout start." = [] #puts "<<<" #puts "size=#{row.size}" #puts row #puts ">>>" unless row.size == 6 Rails.logger.info "row size is invalid. size=#{row.size}" return STAT_ERROR_INVALID_CHECKOUT_ROWSIZE, "checkout row size is invalid. size=#{row.size}" end user_number = row[3] user = User.find_by_user_number(user_number) if user.blank? return STAT_ERROR_INVALID_CHECKOUT_USER, "user_number is invalid. (no record) user_number=#{user_number}" end item_identifier = row[4] item = Item.find_by_item_identifier(item_identifier) if item.blank? return STAT_ERROR_INVALID_CHECKOUT_ITEM, "item_identifier is invalid. (no record) item_identifier=#{item_identifier}" end library_id = item.shelf.library.id librarian_user = default_librarian(library_id) Rails.logger.info "librarian.id=#{library_id} librarian_user.id=#{librarian_user.id}" worked_at_str = row[5] if worked_at_str.blank? return STAT_ERROR_INVALID_CHECKOUT_FORMAT, "datetime is blank." end worked_at = nil begin worked_at = DateTime.strptime(worked_at_str, "%Y-%m-%d %H:%M:%S") worked_at = DateTime.parse(worked_at_str) rescue ArgumentError return STAT_ERROR_INVALID_CHECKOUT_FORMAT, "datetime invalid format. worked_at_str=#{worked_at_str}" end basket = Basket.new(:user => user) basket.save!(:validate => false) checked_item = CheckedItem.new({"item_identifier"=>item_identifier, "ignore_restriction"=>"1"}) checked_item.basket = basket checked_item.item = item checked_item.created_at = worked_at checked_item.updated_at = worked_at checked_item.save unless checked_item.errors.empty? checked_item.errors[:base].each do |error| << I18n.t(error) end Rails.logger.info "checked item create error. messages=#{}" return STAT_ERROR_CHECKOUT, "#{.join(" ")}" end Rails.logger.info "save start" status = basket.basket_checkout(librarian_user) unless status basket.errors[:base].each do |error| , sound = (error) << end Rails.logger.info "basket_checkout error. @@@" Rails.logger.info return STAT_ERROR_CHECKOUT, "#{.join(" ")}" end Rails.logger.info "checkout success." return STAT_SUCCESS end |
#decode_action(posttext, action, create_date) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/enju_standalone_interface.rb', line 49 def decode_action(posttext, action, create_date) encoding = configatron.encoding rinjndael_key = Rinjndael_Default_Key plaintext = posttext.chomp rescue "" plaintext = Base64.decode64(plaintext) if encoding if posttext.blank? return STAT_ERROR_INVALID_PARAM, "encodetext is empty." end if encoding && configatron.clientkey.blank? return STAT_ERROR_DECODEKEY_EMPTY, "decodekey(configatron.clientkey) is empty. see configatron file on server." end row = [action] if encoding begin rinjndael_key = configatron.clientkey puts "key=#{rinjndael_key}" rijndael = Crypt::Rijndael.new(rinjndael_key) plaintext = rijndael.decrypt_string(plaintext) rescue => ex Rails.logger.info "error occured. BatchactionController#recept.crypt" Rails.logger.info ex Rails.logger.info $@.split.join("\n") return STAT_ERROR_CRYPT, "crypt error. #{ex} (see serverlog)" end row << plaintext.split("\t") else row << plaintext.split(",") end row << create_date return row.flatten end |
#default_librarian(library_id) ⇒ Object
223 224 225 226 227 228 229 230 |
# File 'lib/enju_standalone_interface.rb', line 223 def default_librarian(library_id) librarian_user = User.librarians.order("users.id").where(:library_id=>library_id).first rescue nil if librarian_user.nil? Rails.logger.warn "librarian not found. library_id=#{library_id} " librarian_user = User.find(1) # admin end librarian_user end |
#message_recept(params) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/enju_standalone_interface.rb', line 30 def (params) @statuscode = "" @msg = "" row = [] *row = decode_action(params[:data], params[:kbn], params[:create_date]) case row[0] when "checkout" @statuscode, @msg = checkout(row) when "checkin" @statuscode, @msg = checkin(row) else @statuscode = row[0] @msg = row[1] Rails.logger.error "invalid action" end return @statuscode, @msg end |