This discussion is archived
4 Replies Latest reply: Feb 24, 2011 12:27 PM by stellentpmp RSS

How to call GET_SEARCH_RESULTS service in filter

user4884609 Newbie
Currently Being Moderated
Hi Experts,

I wrote a custom filter and in filter i am calling GET_SEARCH_RESULTS service. But i am getting following error :
intradoc.data.DataException: !csNoServiceDefined,GET_SEARCH_RESULTS
     at test.notification.ExpirationNotification.executeService(ExpirationNotification.java:195)
     at test.notification.ExpirationNotification.doCustomDailyEvent(ExpirationNotification.java:112)
     at test.notification.ExpirationNotification.doFilter(ExpirationNotification.java:51)
     at intradoc.shared.PluginFilters.filter(PluginFilters.java:92)
     at intradoc.server.ScheduledSystemEvents.checkScheduledEvents(ScheduledSystemEvents.java:161)
     at intradoc.server.IdcSystemLoader$13.handleManagerEvent(IdcSystemLoader.java:2411)
     at intradoc.server.SubjectManager$1.run(SubjectManager.java:92)


Here is the code :


public class ExpirationNotification implements FilterImplementor
{
     public int doFilter(Workspace ws, DataBinder eventData, ExecutionContext cxt)
          throws DataException, ServiceException
     {
          try{
          String action = eventData.getLocal("action");
          if (action!=null && action.equals("CustomExpNotifyEvent"))
          {
               doCustomDailyEvent(ws, eventData, cxt);
               
               return CONTINUE;
          }
          
     }catch(Exception e){e.printStackTrace();}
          return CONTINUE;
     }
     
     
     protected void doCustomDailyEvent(Workspace ws, DataBinder eventData,
          ExecutionContext cxt) throws DataException, ServiceException
     {
          update("CustomExpNotifyEvent", "CustomExpNotifyEvent event started...", ws);
          try
          {
               DataBinder serviceBinder = new DataBinder();
               serviceBinder.putLocal("QueryText", "dOutDate > `<$dateCurrent()$>` <AND> dOutDate < `<$dateCurrent(30)$>`");
               serviceBinder.putLocal("IdcService", "GET_SEARCH_RESULTS");
                    executeService(serviceBinder,"sysadmin",false);
                    ResultSet results= serviceBinder.getResultSet("SearchResults");
          }
          } catch(Exception e){e.printStackTrace();}
          update("CustomExpNotifyEvent", "CustomExpNotifyEvent finished successfully", ws);
     }
     
     protected void update(String action, String msg, Workspace workspace) throws ServiceException, DataException
     {
          long curTime = System.currentTimeMillis();
          ScheduledSystemEvents sse = IdcSystemLoader.getOrCreateScheduledSystemEvents(workspace);
          
          sse.updateEventState(action, msg, curTime);
     }
     
     protected void trace(String str)
     {
          SystemUtils.trace("scheduledevents", "- custom - " + str);
     }
     public static Workspace getSystemWorkspace() {
          Workspace workspace = null;
          Provider wsProvider = Providers.getProvider("SystemDatabase");
          if (wsProvider != null)
               workspace = (Workspace) wsProvider.getProvider();
          return workspace;
     }

     /**
     * Obtain information about a user. Only the 'userName' parameter must be
     * non-null.
     */
     public static UserData getFullUserData(String userName, ExecutionContext cxt,
               Workspace ws) throws DataException, ServiceException {
          if (ws == null)
               ws = getSystemWorkspace();
          UserData userData = UserStorage.retrieveUserDatabaseProfileDataFull(userName, ws, null, cxt, true, true);
          return userData;
     }

     public void executeService(DataBinder binder, String userName,
               boolean suppressServiceError) throws DataException,
               ServiceException {
          // obtain a connection to the database
          Workspace workspace = getSystemWorkspace();
          // check for an IdcService value
          String cmd = binder.getLocal("IdcService");
               if (cmd == null)
               throw new DataException("!csIdcServiceMissing");
          // obtain the service definition
          ServiceData serviceData = ServiceManager.getFullService(cmd);
          System.out.println(cmd+".....serviceData-------------"+serviceData);
          if (serviceData == null)
               throw new DataException(LocaleUtils.encodeMessage(
                         "!csNoServiceDefined", null, cmd));
          // create the service object for this service
          Service service = ServiceManager.createService(serviceData.m_classID,workspace, null, binder, serviceData);
          // obtain the full user data for this user
          //if(service.getCachedObject("propFile")==null){
          UserData fullUserData = getFullUserData(userName, service, workspace);
          service.setUserData(fullUserData);
          binder.m_environment.put("REMOTE_USER", userName);
          ServiceException error = null;
          try {
               // init the service to not send HTML back
               service.setSendFlags(true, true);
               // create all the ServiceHandlers and implementors
               service.initDelegatedObjects();
               // do a security check
               service.globalSecurityCheck();
               // prepare for the service
               service.preActions();
               // execute the service
               service.doActions();
               // do any cleanup
               service.postActions();
               // store any new personalization data
               service.updateSubjectInformation(true);
               service.updateTopicInformation(binder);
          } catch (ServiceException e) {
               error = e;
          } finally {
               // Remove all the temp files.
               service.cleanUp(true);
               workspace.releaseConnection();
          }
          
          // handle any error
          if (error != null) {
               if (suppressServiceError) {
                    error.printStackTrace();
                    if (binder.getLocal("StatusCode") == null) {
                         binder.putLocal("StatusCode", String
                                   .valueOf(error.m_errorCode));
                         binder.putLocal("StatusMessage", error.getMessage());
                    }
               } else {
                    throw new ServiceException(error.m_errorCode, error
                              .getMessage());
               }
          }
     }     
}

Edited by: user4884609 on Nov 5, 2012 5:05 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points