/** * Execute a service call based on the data in the binder using the credentials of the supplied * user */ public static 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); 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 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()); } } }
/** 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); ws.releaseConnection(); return userData; }