4 Replies Latest reply: Feb 14, 2013 9:50 PM by user559503 RSS

    Need help for obtaining data of users modified within two dates in OIM

    user559503
      Hi All,

      I have an OIM 11g environment where I need to write a scheduled task that needs to pull out the data of users that have been modified between two dates. After searching through the forums, I did have an idea and wrote the following code for the same. But it doesn't seem to work. Can someone please help me out here?

      >//initialize lower and higher attributes to two oracle.sql.DATE values
      >SearchCriteria criteria1 = null,criteria2=null,criteria;
      >criteria1 = new SearchCriteria("Updated On", lower, SearchCriteria.Operator.GREATER_EQUAL);
      >criteria2 = new SearchCriteria("Updated On", higher, SearchCriteria.Operator.LESS_EQUAL);
      >criteria = new SearchCriteria(criteria1, criteria2, SearchCriteria.Operator.AND);
      >//initialize the necessary parameters, get a user manager object and perform the following
      >users = umgr.search(criteria, attrNames, parameters);

      But this doesn't seem to work. Can someone shed some light on this please? Is the "Updated On" attribute not available for this task? If I use a single search criteria having "User Login" attribute, this things works and gets the data of the user but it doesn't work when I use the "Updated On" attribute so made me think maybe that attribute is not available for use through API or something. Or it might be that using the oracle.sql.DATE creates problem here. Not sure though. So kindly help me with this.

      Thanks in advance,
      $id
        • 1. Re: Need help for obtaining data of users modified within two dates in OIM
          idamGod
          Try the below code in your schedule task.


          Map[] fieldData = getData(startdate,enddate);
          System.out.println("Total rows found:"+fieldData.length);
          for (int i = 0; i < fieldData.length; i++) {
          String userId=fieldData.get("Users.User ID").toString();
          String firstName=fieldData[i].get("Users.First Name").toString();
          String lastName=fieldData[i].get("Users.Last Name").toString();
          }


          private Map[] getData(String startDate,String endDate) throws Exception {
          String query ="select usr_login,usr_first_name,usr_last_name from usr where usr_update between to_date ("+ startdate +") and to_date("+endDate+")";
          tcDataSet dataSet = new tcDataSet();
          tcDataProvider dbProvider = new tcDataBaseClient();
          dataSet.setQuery(dbProvider, query);
          dataSet.executeQuery();
          tcResultSet results = new tcMetaDataSet(dataSet.getDataSetData(), dbProvider);

          Map[] result = new Map[results.getRowCount()];
          for (int i = 0; i < results.getRowCount(); i++) {
          results.goToRow(i);
          result[i] = new HashMap();
          String[] columns = results.getColumnNames();
          for (int j = 0; j < columns.length; j++) {
          result[i].put(columns[j], results.getStringValue(columns[j]));
          }
          }
          }
          return result;
          }
          • 2. Re: Need help for obtaining data of users modified within two dates in OIM
            user559503
            Hi All,

            I had tried the above code suggested but it had not worked. So I used the old APIs and now have code that works correctly. But there is one more problem. I want to obtain the last run date of the scheduled job in the scheduled job itself but not able to do that. Can someone please help me obtain it? I had used the HashMap parameter that the execute method of scheduled job takes and tried to get the last end run date as :
            String lastRunEnd=(String)args.get("Last Run End");
            But I dont think it works this way since it is returning null into the variable. Can someone suggest how to obtain the last end run date of the scheduled task?

            Thanks,
            $id
            • 3. Re: Need help for obtaining data of users modified within two dates in OIM
              Kevin Pinsky
              I would suggest you create an actual attribute on your scheduled task called something like "Last Run Timestamp". The reason i say this is you can modify your search based on this rather than manipulating the actual start and end date of the last run. To retrieve the value, just like any other attribute use this:
              >
              String lastRunTimestamp = hashMap.get("Last Run Timestamp").toString();
              >
              Format your time your are inputting like this: "yyyy-MM-dd HH:mm:ss zzz" so you can retrieve and format the value like this:
              >
              SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
              //retrieve start date so it can be updated back to the field on scheduled task
              Date start = new Date();

              //Convert last timestamp run to date
              Date timestamp = new Date();
              timestamp = time.parse(lastRunTimestamp);
              >
              Now you have your last run timestamp which you can set your retrival time based on.

              And finally, to set the last run time stamp value back on the scheduled task to the time you started this task
              >
              SchedulerService task = Platform.getService(SchedulerService.class);
              ScheduledTask taskEntry = task.lookupScheduledTask(getName());
              JobParameter jobparam = taskEntry.getParameters().get("Last Run Timestamp");
              JobDetails job = task.getJobDetail(getName());
              HashMap<String, JobParameter> attributes = job.getAttributes();
              String timestamp = (time.format(start));
              jobparam.setValue(timestamp);
              attributes.put("Last Run Timestamp", jobparam);
              job.setAttributes(attributes);
              task.updateJob(job);
              >

              Hopefully this is useful. It is how i do all my scheduled tasks that need a timestamp.

              -Kevin
              • 4. Re: Need help for obtaining data of users modified within two dates in OIM
                user559503
                Hi Kevin,

                Thanks a lot!!! It worked like a charm!!! Hmmm so its not possible to get the Last Run End Time from the job status of the scheduled job seemingly. Anyways its working with the work around you suggested so that is fine for now. Will try out a few things and get back to you in case I have any more doubts regarding it.

                Thanks,
                $id