Date parsing from a text file

Hi All,

I am working on a log file , where i am parsing one log file for user
name and their last login dates …

this output return two columns , user name and last lgin date .

require ‘ldapjclnt11.jar’

class OIDExtract < Batch::Job

include_package 'javax.naming'
include_package 'javax.naming.ldap'
include_package 'javax.naming.directory'
include_package 'oracle.ldap.util'

IDTYPE_SIMPLE = 1
IDTYPE_DEFAULT = 3

configure acronyms: 'OID', do_not_track: true


def get_oid_connection(user_id, password, server, port = 10037)
    env = {
        Context::INITIAL_CONTEXT_FACTORY =>

‘com.sun.jndi.ldap.LdapCtxFactory’,
Context::SECURITY_AUTHENTICATION => ‘simple’,
Context::SECURITY_PRINCIPAL => “uid=#{user_id}, cn=Users,
dc=oracleoutsourcing, dc=com”,
Context::SECURITY_CREDENTIALS => password,
Context::PROVIDER_URL => “ldap://#{server}:#{port}/”,
Context::REFERRAL => “follow”
}
ctx = InitialLdapContext.new(java.util.Hashtable.new(env),
nil.to_java(Control))
end

def get_subscriber(ctx)
    roc = RootOracleContext.new(ctx)
    roc.getSubscriber(ctx, IDTYPE_DEFAULT, nil, ['*'])
end


def get_user(ctx, sub, user_id)
    sub.getUser(ctx, IDTYPE_SIMPLE, user_id, ['*'].to_java(:String))
end


desc 'Extract user details from Oracle Internet Directory (OID)'
job do
    admin_user = 'orcl_CommandCentre'
    admin_pwd = 'FiRST123!'
    server = 'logintrbs.oracleoutsourcing.com'

    oid = get_oid_connection(admin_user, admin_pwd, server)
    sub = get_subscriber(oid)

    xl = xl_create_workbook
    sheet = xl.workbook.add_worksheet(name: 'Users')
    sheet.add_row(['User Id', 'Create Date'], style:

xl_styles[‘Title’])

    log.info "Extracting users..."
    count = 0
    users = sub.getUsers(oid, IDTYPE_SIMPLE, '*', nil,

[‘orcllastlogintime’].to_java(:String))
users.to_a.each do |user|
count += 1
props = user.getProperties(oid,
[‘orcllastlogintime’].to_java(:String))
user.getDN(oid) =~ /^(?:cn|uid)=([^,]+)/
user_id = $1
create_date =
props.getPropertySet(0).getProperty(0).getValue(0)
create_date = Date.new(create_date[0…3].to_i,
create_date[4…5].to_i, create_date[6…7].to_i)
sheet.add_row([user_id, create_date])
# puts “#{$1}: #{Date.new(create_date[0…3].to_i,
create_date[4…5].to_i, create_date[6…7].to_i)} (#{user.getDN(oid)} -
#{create_date})”
end
log.detail “Output #{count.with_commas} users”
xl_filter_and_freeze(sheet, 1)
xl.serialize(‘OID_Users.xlsx’)
end

end

OIDExtract.run! if FILE == $0

the above is the code :

but in the log file some user have last login date as

orcllastlogintime: 00000000
and some
as
orcllastlogintime:
i, e blank only , so my code is getting failed with below error :

D:\Scripts\Batch\utils>jruby OID_Extract.rb
DETAIL Loading configuration from
D:/Scripts/Batch/lib/rbs/…/…/
secure_hp_config.yaml
INFO Job ‘OID Extract’ started on VMHODTRBSP124 by c_anujt with
PID
32252
DETAIL Working directory is: D:/Scripts/Batch/utils
INFO Extracting users…
ERROR An exception occurred in job ‘OID Extract’:
ArgumentError: invalid date
civil at
jar:file:/D:/Scripts/Batch/jars/jruby-complete-1.7.3.jar!/META-I
NF/jruby.home/lib/ruby/1.9/date.rb:809
OIDExtract at OID_Extract.rb:63
OIDExtract at OID_Extract.rb:57
run! at D:/Scripts/Batch/lib/batch/job.rb:66
(root) at OID_Extract.rb:75

INFO Job ‘OID Extract’ completed with errors in 2.001 seconds

now i have to write a code …like

if

orcllastlogintime: 00000000
and some
as
orcllastlogintime:

then it should handle it …accordingly.