themes=rfdb.getThemeTags4Folder(folder_id);
+ for(String ttag:themes){
+ if(user.getRwx().contains(ttag)) rtn=ACCESS_PRIVILEGE_RWX;
+ }
+ if(themes.size()==0) rtn=ACCESS_PRIVILEGE_RWX;
+
+ }
+ log.debug("user:"+user);
+
+ String superuser=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_SUPERUSER);
+ if(superuser!=null && !superuser.equals("")){
+ rtn=ACCESS_PRIVILEGE_RWX;
+ }
+ if(rtn.equals("")) rtn=null;
+ return rtn;
+ }
+
+
+ /**
+ * Get folder tagname by R function id
+ * @param r_function_id r function id
+ * @return folder name
+ * @throws Exception
+ */
+ public String getFolderThemeByRFunctionId(int r_function_id) throws Exception {
+ String result = "";
+ RFunctionDB rfdb=RFunctionDB.getRFunctionDB();
+ try {
+ rfdb.connectDB();
+ result = rfdb.getFolderThemeByRFunctionId(r_function_id);
+ } catch (Exception e) {
+ throw e;
+ }
+ return result;
+ }
+
+
+
+
+}
diff --git a/project/bldb/src/main/java/com/fe/client/SchedulerAPIServlet.java b/project/bldb/src/main/java/com/fe/client/SchedulerAPIServlet.java
new file mode 100644
index 0000000..47be675
--- /dev/null
+++ b/project/bldb/src/main/java/com/fe/client/SchedulerAPIServlet.java
@@ -0,0 +1,1041 @@
+/******************************************************************************
+*
+* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
+* All rights reserved.
+*
+******************************************************************************/
+
+package com.fe.client;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Vector;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import net.jxta.peergroup.PeerGroup;
+import net.jxta.pipe.PipeService;
+import net.jxta.protocol.PipeAdvertisement;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.jfree.util.Log;
+
+import com.fe.common.Constant;
+import com.fe.scheduler.balance.LoadBalancingLinkedQueue;
+import com.fe.util.ProxifyURL;
+import com.fe.util.RestartTomcat;
+import com.fourelementscapital.db.SchedulerDB;
+import com.fourelementscapital.scheduler.SchedulerEngine;
+import com.fourelementscapital.scheduler.balance.ExecutingQueueCleaner;
+import com.fourelementscapital.scheduler.balance.LoadBalancingQueue;
+import com.fourelementscapital.scheduler.balance.LoadBalancingQueueItem;
+import com.fourelementscapital.scheduler.error.ClientError;
+import com.fourelementscapital.scheduler.p2p.MessageBean;
+import com.fourelementscapital.scheduler.p2p.P2PAdvertisement;
+import com.fourelementscapital.scheduler.p2p.P2PService;
+import com.fourelementscapital.scheduler.p2p.listener.IncomingMessage;
+import com.fourelementscapital.scheduler.p2p.listener.OutgoingMessage;
+import com.fourelementscapital.scheduler.p2p.listener.P2PTransportMessage;
+import com.fourelementscapital.scheduler.rscript.RScript;
+import com.fourelementscapital.scheduler.rscript.RScriptAsyncListenerImpl;
+
+/**
+ *
+ * SchedulerAPI
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * run
+ * Executes scheduled tasks
+ *
+ * Parameters:ids={id1,id2...}
+ * Returns:
+ * {@code
+ *
+ * done
+ * }
+ * Example: http://server-ip-or-name/bldb/schedulerAPI?method=run&ids=21,22
+ *
+ *
+ *
+ *
+ *
+ * livepeers
+ * This method lists out all live peers
+ *
+ * Parameters:Nil
+ * Returns:
+ * {@code
+ *
+ *
+ * 4ECAPSVSG1
+ * 4ecappcsg11
+ * 4ecappcsg12
+ * 4ecappcsg14
+ * 4ecappcsg7
+ * 4ecapsvsg5
+ * dev-server
+ *
+ * }
+ * Example: http://server-ip-or-name/bldb/schedulerAPI?method=livepeers
+ *
+ *
+ *
+ *
+ * queue
+ * This method lists all tasks that currently executing by peers and ready to execute by peer in any moment.
+ *
+ * Parameters:Nil
+ * Returns:
+ * {@code
+ *
+ *
+ *
+ *
+ *
+ * }
+ * Example: http://server-ip-or-name/bldb/schedulerAPI?method=queue
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * syncContract
+ * This method synchronize bloomberg data with Market Contracts those mapped with reference database.
+ * Accepts optional parameter.
+ * Parameter contract synchronizes only specified contract
+ * Nil parameter synchronizes all new contracts that haven't synchronized so far
+ *
+ * Parameters:[contract={@code }] if no parameter specified, this synchronizes all new contracts those haven't synchronized yet.
+ * Returns:
+ * {@code
+ *
+ * true/false
+ * }
+ * Example:
+ * http://server-ip-or-name/bldb/schedulerAPI?method=syncContract&contract=CL010
+ * http://server-ip-or-name/bldb/schedulerAPI?method=syncContract
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * syncSecurity
+ * This method synchronize bloomberg data with Securities those mapped with reference database.
+ * Accepts optional parameter.
+ * Parameter security synchronizes only specified contract
+ * Nil parameter synchronizes all new securities that haven't synchronized so far
+ *
+ * Parameters:[security={@code }] if no parameter specified, this synchronizes all new securities those haven't synchronized yet.
+ * Returns:
+ * {@code
+ *
+ * true/false
+ * }
+ * Example:
+ * http://server-ip-or-name/bldb/schedulerAPI?method=syncSecurity&contract=AIGC
+ * http://server-ip-or-name/bldb/schedulerAPI?method=syncSecurity
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * @author Rams Kannan
+ *
+ */
+public class SchedulerAPIServlet extends HttpServlet {
+
+
+ private static String EXECUTETASKS="run";
+ private static String GETLIVE="livepeers";
+ private static String QUEUE="queue";
+ private static String SYNC_REF_CONTRACT="syncContract";
+ private static String EXECUTE_R_QUEUEINFO="xRQInfo";
+ private static String EXECUTE_R_QUEUE="executeR_queue";
+
+ private static String PEER_PACKAGES="getPeerPackages";
+ private static String PEER_INFO="getPeerInfo";
+ private static String PEER_QUEUE="getPeerQueue";
+
+ private static String SERVER_DATE_TIME="getCurrentDateTime";
+ private static String SYNC_REF_SECURITY="syncSecurity";
+
+ private static String SCHEDULER_QUEUEGROUP_ADD="addGroupIntoQueue";
+ private static String SCHEDULER_QUEUEGROUP_REMOVE="removeGroupFromQueue";
+
+ private static String RESTART_PEER="restartPeer";
+ private static String RESTART_PEER_LATER="restartAfterDone";
+ private static String RESTART_SERVER="restartServer";
+
+ private static String PRIORITY_QUEUE="priorityQueue";
+ private static String REMOVE_EXECUTING_TASK="removeExecutingTask";
+ private static String STRATEGY_XML="strategyXML";
+
+ private static String EXECUTE_SSCRIPT_P2P="execSyncScript";
+ private static String EXECUTE_ASCRIPT_P2P="execAsyncScript";
+ private static String EXECUTE_ASCRIPT_P2P_RESULT="getScriptResult";
+
+ private static int EXPIRY_FOR_UNRETRIEVED=30; //seconds
+ private static int EXPIRY_FOR_RETRIEVED=2;
+
+ private static String AUTHENTICATION_CHECK="check_auth";
+
+
+ private String msg=null;
+
+ private Logger log = LogManager.getLogger(SchedulerAPIServlet.class.getName());
+
+ private static JCS cache=null;
+ private static JCS getCache() throws Exception {
+ if(cache==null){
+ cache=JCS.getInstance("direct_script");
+ }
+ return cache;
+ }
+
+ public static Map getAllTokens() throws Exception {
+
+ Map rtn=getCache().getMatching("^[A-Za-z0-9\\-]+$");
+ return (rtn!=null)?rtn:new HashMap(); //all alpha numeric keys.
+
+ }
+
+
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String method = request.getParameter("method");
+
+ if(method!=null && !method.equals("") && (method.equals(SchedulerAPIServlet.EXECUTE_SSCRIPT_P2P) || method.equals(SchedulerAPIServlet.EXECUTE_ASCRIPT_P2P))){
+ log.debug("debug doPost: method:"+method);
+ try{
+ String script=request.getParameter("script");
+ RScript rs=new RScript();
+
+
+ //set unique name from the parameter
+ //rs.setUniquename("[no-unique-name]");
+
+ rs.setUniquename(rs.getUid());
+ if(request.getParameter("uniquename")!=null && !request.getParameter("uniquename").trim().equals("")){
+ rs.setUniquename(request.getParameter("uniquename"));
+ }
+
+ //set remote host from getRemoteHost
+ if(request.getRemoteHost()!=null){
+ rs.setRequesthost(request.getRemoteHost());
+ }
+
+ rs.setTaskuid("direct_script");
+ if(request.getParameter("engine")!=null && request.getParameter("engine").equalsIgnoreCase("rserve")){
+ rs.setTaskuid("direct_script_unix");
+ }
+
+ if(request.getParameter("executeAt")!=null && !request.getParameter("executeAt").equals("")){
+ rs.setExecuteAt(request.getParameter("executeAt"));
+ }
+ rs.setScript(script);
+ String id=rs.getUid();
+
+ IElementAttributes att= getCache().getDefaultElementAttributes();
+ att.setMaxLifeSeconds(EXPIRY_FOR_UNRETRIEVED);
+
+ RScriptAsyncListenerImpl liten=new RScriptAsyncListenerImpl(getCache(),att);
+ getCache().put(id, RScriptAsyncListenerImpl.ALIVE,att); //listener
+
+ LoadBalancingQueue.getExecuteRScriptDefault().addExecuteR(rs,liten);
+
+ boolean finished=false;
+ String rtn=null;
+
+ if(method.equals(SchedulerAPIServlet.EXECUTE_SSCRIPT_P2P)){
+ while(!finished){
+
+ String ri=(String)getCache().get(id);
+ if(ri!=null && !ri.equalsIgnoreCase(RScriptAsyncListenerImpl.ALIVE)){
+ getCache().remove(id);
+ rtn=ri;
+ finished=true;
+ }
+ if(ri==null){
+ finished=true;
+ }
+ try{
+ Thread.sleep(10);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ String resptype=(request.getParameter("responseType")!=null)?request.getParameter("responseType"):"text/xml";
+ response.setContentType(resptype);
+ }else{
+ response.setContentType("text/plain");
+ rtn=id;
+ }
+ PrintWriter out = response.getWriter();
+ out.println(rtn);
+ out.flush();
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+
+ }else{
+ //report error saying no method parameter found;
+ }
+ }
+
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ String method = request.getParameter("method");
+ this.msg="Error in current request, Method value required";
+ boolean noerror=false;
+ if(method!=null && !method.equals("")){
+
+
+ /**
+ * executing tasks, accepts parameter ids=
+ *
+ * expression with code injection can be like the following
+ * [23:inj] your_code_here [inj][2454:inj] your_code_here [inj]
+ */
+ if(method.equals(SchedulerAPIServlet.EXECUTETASKS) && request.getParameter("ids")!=null && !request.getParameter("ids").equals("") && ( request.getParameter("delay")==null || (request.getParameter("delay")!=null && request.getParameter("delay").equals(""))) ){
+ noerror=executeTask(request,response);
+ }else if(method.equals(SchedulerAPIServlet.EXECUTETASKS) && request.getParameter("ids")!=null && !request.getParameter("ids").equals("")
+ &&(request.getParameter("delay")!=null && !request.getParameter("delay").equals(""))
+ ){
+ int delay=0;
+ boolean validdelay=false;
+ try{
+ delay=Integer.parseInt(request.getParameter("delay"));
+ validdelay=true;
+ }catch(Exception e){
+ validdelay=false;
+
+ }
+ if(validdelay){
+ if(delay==0) noerror=executeTask(request,response);
+ if(delay>0){
+ noerror=executeTaskDelayed(request,response);
+ }
+ }else{
+ this.msg="Integer value expected for delay";
+ noerror=false;
+
+ }
+
+ }else{
+ this.msg="Error in current request, Method value required";
+ noerror=true;
+ }
+
+
+ /**
+ * Get peer packages, this request will be forwarded to all online peer and wait few seconds to receive all the responses and returns to UI.
+ * The responses will includes installed packages and version nos
+ */
+ if(method.equals(SchedulerAPIServlet.PEER_PACKAGES) ){
+ String status=null;
+ try{
+ status=getPeerInfo("rpackages");
+ }catch(Exception e){
+ status=""+e.getMessage()+"";
+ }
+ generateResult(response,status);
+ }
+
+
+ /**
+ * This returns info about all online peers and the response will includes peer started time, executing tasks, JRI version, OS and R version
+ */
+ if(method.equals(SchedulerAPIServlet.PEER_INFO) ){
+ String status=null;
+ try{
+ status=getPeerInfo("statistics");
+
+ }catch(Exception e){
+ status=""+e.getMessage()+"";
+ }
+ generateResult(response,status);
+ }
+
+
+ /**
+ * This will return live queue data, such as queued,executing and finished tasks with its trigger time.
+ */
+ if(method.equals(SchedulerAPIServlet.EXECUTE_R_QUEUEINFO) ){
+ String status=null;
+ try{
+ ExecuteRMgmt erm=new ExecuteRMgmt(request);
+ status=erm.getQueueXML();
+
+ }catch(Exception e){
+ status=""+e.getMessage()+"";
+ }
+ generateResult(response,status);
+ }
+
+
+ /**
+ * This will return executeR queue, including number of scripts queued, executing and successfull.
+ * ExecuteR server is not the same as scheduler server, the request is proxyfied to executeR server
+ */
+ if(method.equals(SchedulerAPIServlet.EXECUTE_R_QUEUE) && request.getParameter("server_ip")!=null ){
+
+ ProxifyURL purl=new ProxifyURL(request,response);
+ purl.proxifyGet("http://"+request.getParameter("server_ip")+":8080/bldb/schedulerAPI","method="+SchedulerAPIServlet.EXECUTE_R_QUEUEINFO);
+ //System.out.println("SchedulerAPIServerlet.class: proxyfy");
+
+ }
+
+
+
+ /**
+ * peer queue information
+ * recommended not to use this, as there are live stream connection between peers and server available and
+ * eventually the queue will be maitained at the server level.
+ * @deprecated
+ */
+ if(method.equals(SchedulerAPIServlet.PEER_QUEUE) ){
+ String status=null;
+ try{
+ status=getPeerInfo("peerqueue");
+ }catch(Exception e){
+ status=""+e.getMessage()+"";
+ }
+ generateResult(response,status);
+ }
+
+
+ /**
+ * This will be used in other applications to check the current session is authenticated
+ * For example: Tools done in .NET and PHP.
+ */
+ if(method.equals(SchedulerAPIServlet.AUTHENTICATION_CHECK)){
+ try{
+ authenticationCheck(request,response);
+ }catch(Exception e){
+ generateResult(response,"Error:"+e.getMessage()+"");
+ }
+
+ }
+
+ /**
+ * @deprecated
+ * recommended not to use.
+ */
+ if(method.equalsIgnoreCase(SchedulerAPIServlet.STRATEGY_XML) && request.getParameter("strategy")!=null && request.getParameter("contract")!=null){
+
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+ String contract=request.getParameter("contract");
+ if(contract==null){
+ contract="";
+ }
+ try{
+ IExecMgmt iemgmt=new IExecMgmt(request,false);
+
+ out.write(iemgmt.getMyParsedXML(request.getParameter("strategy"),contract ));
+ }catch(Exception e){
+ out.write("Error:"+e.getMessage());
+ e.printStackTrace();
+ }
+ out.flush();
+
+ }
+
+
+ /**
+ * Get the result of previously executed executeR script in asynchronous mode, using the returned token
+ */
+ if(method.equals(SchedulerAPIServlet.EXECUTE_ASCRIPT_P2P_RESULT) && request.getParameter("token")!=null && !request.getParameter("token").equals("") ){
+
+ String ri=null;
+ String token=null;
+ try{
+
+ ri=(String)getCache().get(request.getParameter("token").trim());
+ token=request.getParameter("token").trim();
+ }catch(Exception e){
+ Log.error("Error:"+e.getMessage());
+ }
+ //if(ri!=null && ri.isFinished()){
+ if(ri!=null && !ri.equalsIgnoreCase(RScriptAsyncListenerImpl.ALIVE)){
+ String resptype=(request.getParameter("responseType")!=null)?request.getParameter("responseType"):"text/xml";
+ response.setContentType(resptype);
+ PrintWriter out = response.getWriter();
+ out.print(ri);
+ out.flush();
+
+ //remove the result from cache and set the storance once it is retrieved.
+ try{
+ IElementAttributes att= getCache().getDefaultElementAttributes();
+ att.setMaxLifeSeconds(EXPIRY_FOR_RETRIEVED);
+ getCache().remove(token);
+ getCache().put(token,ri,att);
+ }catch(Exception e){
+ log.error("Error while resetting token in cache");
+ }
+
+ }else if(ri!=null && ri.equalsIgnoreCase(RScriptAsyncListenerImpl.ALIVE)) {
+ //generateResult(response,"not ready");
+ //response.setContentType("text/xml");
+ String resptype=(request.getParameter("responseType")!=null)?request.getParameter("responseType"):"text/xml";
+ response.setContentType(resptype);
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println("not ready");
+ out.flush();
+
+ }else {
+ String resptype=(request.getParameter("responseType")!=null)?request.getParameter("responseType"):"text/xml";
+ response.setContentType(resptype);
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println("No script associated to this token, Result for the token expires in "+EXPIRY_FOR_UNRETRIEVED+" seconds. ");
+ out.flush();
+ }
+ }
+
+
+ if(method.equals(SchedulerAPIServlet.SCHEDULER_QUEUEGROUP_ADD) && request.getParameter("taskuid")!=null && !request.getParameter("taskuid").equals("") ){
+ String status=addRemoveGroup2Queue(request, response, method);
+ generateResult(response,""+status+"");
+ }
+
+
+ if(method.equals(SchedulerAPIServlet.REMOVE_EXECUTING_TASK)
+ && request.getParameter("task_id")!=null && !request.getParameter("task_id").equals("")
+ && request.getParameter("trigger_time")!=null && !request.getParameter("trigger_time").equals("")
+ ){
+ String status=removeTaskID(request, response);
+ generateResult(response,""+status+"");
+ }
+
+
+ /**
+ * adding and removing scheduler group, i.e Bloomberg download,
+ */
+ if(method.equals(SchedulerAPIServlet.SCHEDULER_QUEUEGROUP_REMOVE) && request.getParameter("taskuid")!=null && !request.getParameter("taskuid").equals("") ){
+ String status=addRemoveGroup2Queue(request, response, method);
+ generateResult(response,""+status+"");
+ }
+
+ /**
+ * Restart peer, this method is not very reliable as it uses OS dependent tools to kill the running process and it works only on windows peers and still not reliable and consistent.
+ */
+ if((method.equals(SchedulerAPIServlet.RESTART_PEER) || method.equals(SchedulerAPIServlet.RESTART_PEER_LATER))
+ && request.getParameter("peer")!=null && !request.getParameter("peer").equals("")
+ ){
+ String status=restartPeer(method,request);
+ generateResult(response,""+status+"");
+ }
+
+
+
+ if(method.equals(SchedulerAPIServlet.SERVER_DATE_TIME)){
+ SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
+ Date d=new Date();
+ generateResult(response,"");
+ }
+
+
+
+ /**
+ * ment for chaning queue dispatch algorithm, not working well.
+ * @deprecated
+ */
+ if(method.equals(SchedulerAPIServlet.PRIORITY_QUEUE) ){
+ if(request.getParameter("enable")!=null && request.getParameter("enable").equalsIgnoreCase("true")){
+ LoadBalancingLinkedQueue.priorityQueue=true;
+ }
+ if(request.getParameter("enable")!=null && request.getParameter("enable").equalsIgnoreCase("false")){
+ LoadBalancingLinkedQueue.priorityQueue=false;
+ }
+ generateResult(response,""+LoadBalancingLinkedQueue.priorityQueue+"");
+ }
+
+ if(method.equals(SchedulerAPIServlet.GETLIVE)){
+ noerror=getLive(request,response);
+ }
+ if(method.equals(SchedulerAPIServlet.QUEUE)){
+ noerror=getQueue(request,response);
+ }
+ }
+ if(!noerror){
+ try {
+ //no valid parameter take to the documention about this API.
+ getServletConfig().getServletContext().getRequestDispatcher("/schedulerAPI.jsp").forward(request,response);
+ } catch (ServletException e) {
+ log.error(e);
+ }
+ }
+ }
+
+
+
+ public String addRemoveGroup2Queue(HttpServletRequest request, HttpServletResponse response,String method){
+ String taskuid=request.getParameter("taskuid");
+ try{
+
+ if(taskuid!=null && !taskuid.equals("")){
+ if(method.equals(SchedulerAPIServlet.SCHEDULER_QUEUEGROUP_ADD)){
+ new SchedulerEngine().addGroup2Queue(taskuid);
+ }
+ if(method.equals(SchedulerAPIServlet.SCHEDULER_QUEUEGROUP_REMOVE)){
+ new SchedulerEngine().removeGroup2Queue(taskuid);
+ }
+
+ }else{
+ throw new Exception("Parameter taskuid not found");
+ }
+ return "success";
+ }catch(Exception e){
+ return "Error:" +e.getMessage();
+
+ }
+
+ }
+
+
+
+ private String removeTaskID (HttpServletRequest request, HttpServletResponse response){
+ int scheduler_id=0;
+ long trigger_time=0;
+ try{
+ scheduler_id=Integer.parseInt( request.getParameter("task_id"));
+ trigger_time=Long.parseLong( request.getParameter("trigger_time"));
+
+ new ExecutingQueueCleaner().removeFaultyExecutingTask(scheduler_id, trigger_time);
+
+ return "success";
+ }catch(Exception e){
+ return "ERROR:"+e.getMessage();
+ }
+
+ }
+
+ private boolean executeTask(HttpServletRequest request, HttpServletResponse response){
+
+
+ try{
+
+ String ids_exp=request.getParameter("ids");
+ String suffixcode=null;
+ String status=new SchedulerEngine().executeScriptExpression(ids_exp, "SchedulerAPI",suffixcode);
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println(""+status+"");
+ out.flush();
+
+ return true;
+ }catch(Exception e){
+ log.error("executeTask() Error:"+e.getMessage());
+ this.msg="Error occured: MSG:"+e.getMessage();
+ return false;
+ }
+ }
+
+ private boolean executeTaskDelayed(HttpServletRequest request, HttpServletResponse response){
+ StringTokenizer st=new StringTokenizer(request.getParameter("ids"),",");
+ Vector v=new Vector();
+ while(st.hasMoreTokens()){
+ v.add(st.nextToken());
+ }
+
+ int delay=Integer.parseInt(request.getParameter("delay"));
+
+ try{
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ sdb.connectDB();
+ for(Iterator i=v.iterator();i.hasNext();){
+ String sid=(String)i.next();
+ int scheduler_id=Integer.parseInt(sid);
+
+ Map data=sdb.getScheduler(scheduler_id);
+ if(data!=null){
+ Number active=(Number)data.get("active");
+ String taskuid=(String)data.get("taskuid");
+ String name=(String)data.get("name");
+ new SchedulerEngine().runJobDelayed(data,taskuid,sdb,delay,"SchedulerAPI");
+ }
+ }
+ sdb.closeDB();
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println("done");
+ out.flush();
+ return true;
+ }catch(Exception e){
+ ClientError.reportError(e, null);
+ //throw e;
+ this.msg="Error occured: MSG:"+e.getMessage();
+ return false;
+ }
+ }
+
+
+ private void generateResult(HttpServletResponse response,String status){
+
+ try{
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println(""+status+"");
+ out.flush();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+
+ private boolean getLive(HttpServletRequest request, HttpServletResponse response) {
+
+ try{
+
+ SchedulerMgmt sm=new SchedulerMgmt();
+ Map t=sm.getOnlinePeers();
+
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+
+ out.println("");
+
+ out.println("");
+ for(Iterator i=t.keySet().iterator();i.hasNext();){
+ String peer=(String)i.next();
+ out.println(""+peer+"");
+ }
+ out.println("");
+ out.flush();
+
+ return true;
+
+ }catch(Exception e){
+ return false;
+ }
+ }
+
+
+ private boolean getQueue(HttpServletRequest request, HttpServletResponse response) {
+ try{
+ Collection executingTasks=LoadBalancingQueue.getDefault().getExecutingTasks();
+ Collection queuedTasks=LoadBalancingQueue.getDefault().getQueuedTasks();
+
+ response.setContentType("text/xml");
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println("");
+
+ for(Iterator i=executingTasks.iterator();i.hasNext();){
+ LoadBalancingQueueItem item=i.next();
+
+
+ out.println(" ");
+ }
+ for(Iterator i=queuedTasks.iterator();i.hasNext();){
+ LoadBalancingQueueItem item=i.next();
+ item.getSchedulerid() ;
+ out.println(" ");
+ }
+ out.println("");
+ out.flush();
+ return true;
+ }catch(Exception e){
+ return false;
+ }
+
+ }
+
+ /**
+ * @deprecated
+ * not working well.
+ * Recommended not to try this method in production, as it is not very reliable and also windows dependent, linux/unix peers won't work
+ * @return
+ */
+ public static String restartServer() {
+ TimerTask tt=new TimerTask() {
+ public void run() {
+
+ RestartTomcat.restartMainServer();
+ }
+ };
+ //checks every 1 minute to see if a thread still running....
+ long delay=4*1000;
+ Timer timer = new Timer();
+ timer.schedule(tt,delay);
+
+
+ return "Server has been restarted, Please check the server status after 1 minute ";
+ }
+
+
+ private void authenticationCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ String ky=(String)request.getSession().getAttribute(Constant.SESSION_LOGGED_USER);
+
+
+ if((ky==null || (ky!=null && ky.equals(""))) ){
+
+
+
+ String user=null;
+ String pwd=null;
+ Cookie cookie[]=request.getCookies();
+ if(cookie!=null){
+ for(int i=0;i=2){
+ String ky=st1.nextToken();
+ String val=st1.nextToken();
+ if(!allKeys.contains(ky)) allKeys.add(ky);
+ h.put(ky, val);
+ }
+ }
+ pdata.put(peer, h);
+
+ }
+ }
+
+ for(Iterator i=pdata.keySet().iterator();i.hasNext();){
+ String peer=(String)i.next();
+ Map pack=(Map)pdata.get(peer);
+ rtn+="";
+ }
+ }
+
+ if(what.equals("peerqueue")){
+ data=IncomingMessage.getPeerQueueStat();
+
+ for(Iterator it=data.keySet().iterator();it.hasNext();){
+ String peer=(String)it.next();
+ String value=(String)data.get(peer);
+ if(peer!=null && value!=null && !value.equals("")){
+
+ StringTokenizer st=new StringTokenizer(value,"|");
+
+ while(st.hasMoreTokens()){
+
+ rtn+="=2){
+ String ky=st1.nextToken();
+ String val=st1.nextToken();
+ rtn+=ky+"=\""+val+"\" ";
+ }
+ }
+ rtn+="/>";
+ }
+ }
+ }
+
+ }
+ return rtn;
+ }catch(Exception e){
+ ClientError.reportError(e, "what:"+what);
+ throw e;
+ }
+ }
+}
+
+
+
diff --git a/project/bldb/src/main/java/com/fe/client/SchedulerMgmt.java b/project/bldb/src/main/java/com/fe/client/SchedulerMgmt.java
new file mode 100644
index 0000000..49ab4d9
--- /dev/null
+++ b/project/bldb/src/main/java/com/fe/client/SchedulerMgmt.java
@@ -0,0 +1,4258 @@
+/******************************************************************************
+*
+* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
+* All rights reserved.
+*
+******************************************************************************/
+
+package com.fe.client;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
+import java.util.TreeMap;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.mozilla.javascript.edu.emory.mathcs.backport.java.util.Arrays;
+import org.tmatesoft.svn.core.SVNLogEntry;
+
+import EDU.oswego.cs.dl.util.concurrent.Semaphore;
+
+import com.fe.lucene.LuceneCrawler;
+import com.fe.lucene.TickerIndexRecord;
+import com.fe.lucene.TokenCollectorFactory;
+import com.fe.scheduler.TemplateParser;
+import com.fe.svn.SVNSchedulerCommitInfo;
+import com.fe.svn.SVNSync;
+import com.fe.util.RestartTomcat;
+import com.fe.util.WikiRFunctionManual;
+import com.fourelementscapital.alarm.Alarm;
+import com.fourelementscapital.alarm.AlarmType;
+import com.fourelementscapital.alarm.ThemeVO;
+import com.fourelementscapital.auth.UserThemeAccessPermission;
+import com.fourelementscapital.db.BBSyncDB;
+import com.fourelementscapital.db.ConstructQueryDB;
+import com.fourelementscapital.db.InfrastructureDB;
+import com.fourelementscapital.db.RFunctionDB;
+import com.fourelementscapital.db.SchedulerDB;
+import com.fourelementscapital.db.vo.FlexiField;
+import com.fourelementscapital.db.vo.SchedulerTrigger;
+import com.fourelementscapital.db.vo.ValueObject;
+import com.fourelementscapital.scheduler.ScheduledTaskFactory;
+import com.fourelementscapital.scheduler.ScheduledTaskQueue;
+import com.fourelementscapital.scheduler.SchedulerEngine;
+import com.fourelementscapital.scheduler.SchedulerEngineUtils;
+import com.fourelementscapital.scheduler.balance.LoadBalancingQueue;
+import com.fourelementscapital.scheduler.balance.LoadBalancingQueueItem;
+import com.fourelementscapital.scheduler.balance.LoadBalancingQueueTimeout;
+import com.fourelementscapital.scheduler.config.Config;
+import com.fourelementscapital.scheduler.engines.ScheduledTask;
+import com.fourelementscapital.scheduler.engines.ScheduledTaskField;
+import com.fourelementscapital.scheduler.error.ClientError;
+import com.fourelementscapital.scheduler.group.DirectRServeExecuteRUnix;
+import com.fourelementscapital.scheduler.group.REngineScriptTask;
+import com.fourelementscapital.scheduler.group.RServeUnixTask;
+import com.fourelementscapital.scheduler.group.PythonScriptTask;
+import com.fourelementscapital.scheduler.p2p.P2PService;
+import com.fourelementscapital.scheduler.p2p.listener.IncomingMessage;
+import com.fourelementscapital.scheduler.p2p.listener.P2PTransportMessage;
+import com.fourelementscapital.scheduler.p2p.msg.PostMessage;
+import com.fourelementscapital.scheduler.p2p.msg.impl.helper.SendCommand2Helper;
+import com.fourelementscapital.scheduler.p2p.msg.scheduler.InstantPeerStatus;
+import com.fourelementscapital.scheduler.p2p.msg.scheduler.rserve.PeerPropertiesGet;
+import com.fourelementscapital.scheduler.p2p.msg.scheduler.rserve.PeerPropertiesSet;
+import com.fourelementscapital.scheduler.p2p.msg.scheduler.rserve.RServeSessionQuery;
+import com.fourelementscapital.scheduler.p2p.msg.scheduler.rserve.RServeSessionStat;
+import com.fourelementscapital.scheduler.p2p.peer.PeerMachine;
+import com.fourelementscapital.scheduler.p2p.peer.PeerManagerHSQL;
+import com.fourelementscapital.scheduler.pluggin.PlugginInterface;
+import com.fourelementscapital.scheduler.pluggin.SchedulerPlugginRegister;
+
+
+/**
+ * This class exposes data in JSON format for scheduler UI.
+ *
+ * The following infos can be retrived for the UI.
+ * -Queue data
+ * -Executing tasks
+ * -Queued tasks
+ * -Online peers
+ * -Queue history
+ * -Execution Logs
+ * -Queue settings
+ *
+ * -Managing task groups and order
+ * -Managing task folders and order
+ * -Managing tasks and its order
+ * -Managing contents of tasks including Scripts and code management
+ * -Managing themes and privileges
+ *
+ * -Managing peers and association with tasks
+ * -Enabling/Disabling peers
+ *
+ * -Rendering scheduler related reports
+ *
+ * Changing anything in this class required extensive testing as it can directly impact the queue behaviours and sometimes may lead to
+ * critical bugs and could stop certain scheduler functionalities.
+ *
+ * Returned data will be parsed as JSON objects in the javascript side.
+ *
+ * Check DWR documentation to know more about why this class needed.
+ *
+ */
+public class SchedulerMgmt extends AbstractTeamOrgMgmt {
+
+
+ private Logger log = LogManager.getLogger(SchedulerMgmt.class.getName());
+ private HttpServletRequest request=null;
+
+
+ /*
+ * Session key constant to keep some of the settings in session;
+ */
+ private String ACTIVE_TAB_ATTRIBUTE="$$$ActiveSchedulerTab"; //current tab
+ private String TAG_SHOWHIDE_ATTRIBUTE="$$$ShowHideTags"; //show or hide his tags;
+ private String COOKIE_SCHEDULER_ALLITEMS="scheduler_showAll"; //remember the scheduler list filter (all/only mine)
+
+ private static String LOG_STATUS_RESTARTED="re-executed";
+ private static JCS lockcache=null;
+ private static Semaphore logListLock=new Semaphore(1);
+
+ private static String CALLING_ANOTHER_SCRIPT_PATTERN="executeSchedulerScript(";
+
+
+
+
+ /**
+ * for DWR invocation
+ * @throws Exception
+ */
+ public SchedulerMgmt() throws Exception {
+ super();
+
+ }
+
+
+ /**
+ * Invocation only when you have HttpRequest is available,
+ * in JSP or internally.
+ * @param request
+ * @throws Exception
+ */
+ public SchedulerMgmt(HttpServletRequest request) throws Exception {
+ super(request);
+
+ }
+
+
+ /**
+ * checks the current scheduler script has valid edit permission in the current request.
+ * @param scheduler_id
+ * @param sdb
+ * @throws Exception
+ */
+ public void validateEditPrivilege(int scheduler_id, SchedulerDB sdb) throws Exception {
+ String access=getAccessPrivilege(scheduler_id, sdb);
+ if(access==null || (access!=null && access.equals("") || access!=null && access.equals(ACCESS_PRIVILEGE_R) || access!=null && access.equals(ACCESS_PRIVILEGE_RX))){
+ throw new Exception("Access denied to scheduler ID ("+scheduler_id+") Contact Administrator.");
+ }
+ }
+
+
+
+
+
+
+ /**
+ * This method returns Map that contains data for rendering
+ * tree menu item in the left side panel of the scheduler tasks User interface screen
+ * Map contains, group, folders, tasks and tags together with the access permission.
+ *
+ * @return
+ * @throws Exception
+ */
+ public Map listScheduledItems() throws Exception {
+ return listScheduledItems2(null);
+ }
+
+
+
+ private Vector getGroupOrder() throws Exception {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+ sdb.connectDB();
+ Vector rtn=sdb.getGroupOrder();
+
+
+ return rtn;
+ }catch(Exception e){ throw e;}
+ finally{
+ sdb.closeDB();
+ }
+
+ }
+
+
+ /**
+ * @deprecated
+ * @return
+ * @throws Exception
+ */
+ public boolean killServerTaskQueue() throws Exception {
+ ScheduledTaskQueue.killQueueThread();
+ return true;
+ }
+
+
+ private Map getGroupIconsAndColors() throws Exception {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+
+ try{
+ HashMap rtn=new HashMap();
+
+ HashMap icons=new HashMap();
+ HashMap colors=new HashMap();
+ sdb.connectDB();
+ Vector data=sdb.getActiveGroups();
+ for(Iterator i=data.iterator();i.hasNext();){
+ Map row=(Map)i.next();
+ icons.put(row.get("taskuid"),row.get("icon"));
+ colors.put(row.get("taskuid"),row.get("bar_colorcode"));
+ }
+ rtn.put("group_icons",icons);
+ rtn.put("group_colorcodes",colors);
+ return rtn;
+ }catch(Exception e){ throw e;}
+ finally{
+ sdb.closeDB();
+ }
+ }
+
+
+ /**
+ * Search by task name, within the selected tag.
+ * @deprecated
+ * @param keyword
+ * @param tagid
+ * @return
+ * @throws Exception
+ */
+ public Map searchScheduledItems(String keyword, String tagid) throws Exception {
+ //return listScheduledItems2(keyword);
+ HashMap rtn=new HashMap();
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+ sdb.connectDB();
+ int tid=0;
+ try{tid=Integer.parseInt(tagid);}catch(Exception e){}
+
+ List slist=sdb.searchScheduler(keyword,tid);
+ rtn.put("scheduleditems", slist);
+ return rtn;
+ }catch(Exception e){ throw e;}
+ finally{
+ sdb.closeDB();
+ }
+
+ }
+
+
+
+ private boolean isSchedulerShowAll() throws Exception{
+ boolean showAll=false;
+
+ Cookie cookies[]=getRequest().getCookies();
+ for(int i=0;i tasks= new ScheduledTaskFactory().getTasks();
+
+ LinkedHashMap tasksnames=new LinkedHashMap ();
+ Vector uniqt=new Vector();
+
+ Vector orders=getGroupOrder();
+
+ for(int i=0;i<=orders.size();i++){
+ Object item=(i it=tasks.iterator();it.hasNext();){
+ ScheduledTask tsk=it.next();
+ if(item==null || (item!=null && item.equals(tsk.getUniqueid()))){
+ if(!uniqt.contains(tsk.getUniqueid())){
+ if(tsk.getClass().getName().equals(REngineScriptTask.class.getName()) || tsk.getClass().getName().equals(DirectRServeExecuteRUnix.class.getName())){
+ //ignore REngineScript Tasks (direct_script) as this type available only via SchedulerAPI
+ }else{
+ tasksnames.put(tsk.getUniqueid(),tsk.getName());
+ uniqt.add(tsk.getUniqueid());
+ }
+ }
+ }
+ }
+
+ }
+
+
+
+ TreeMap relationship=new TreeMap();
+ for(Iterator i=tasksnames.keySet().iterator();i.hasNext();){
+ String tas1=(String)i.next();
+ for(Iterator ia=uniqt.iterator();ia.hasNext();){
+ String tas2=(String)ia.next();
+ if(tas1.substring(0,4).equals(tas2.substring(0,4)) && !tas1.equals(tas2)){
+ HashMap h ;
+ if(relationship.get(tas1)==null){
+ h=new HashMap();
+ relationship.put(tas1,h);
+ }else{
+ h=(HashMap)relationship.get(tas1);
+ }
+ h.put(tas2,tasksnames.get(tas2));
+ }
+ }
+ }
+
+
+ rtn.putAll(getThemeAccessData(sdb)); //putting team organization data example: tags
+
+ sdb.closeDB();
+
+
+ rtn.put("scheduleditems", slist);
+
+ rtn.put("folders", folders);
+ rtn.put("tasktypes",tasksnames );
+ rtn.put("taskrelation", relationship);
+ rtn.put("isShowAll", showAll);
+
+ return rtn;
+
+ }
+
+
+ /**
+ * return list of task types
+ * @return
+ * @throws Exception
+ */
+ public Map getScriptTypes () throws Exception {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+
+
+ Map sitems=listScheduledItems2(null);
+ Map types=(Map)sitems.get("tasktypes");
+
+ sdb.connectDB();
+ LoadBalancingQueueTimeout lqt=new LoadBalancingQueueTimeout(sdb,types.keySet());
+
+ Map timeoutdata=BeanUtils.describe(lqt);
+ timeoutdata.putAll(lqt.getMaxWaitingAlert());
+ Map tags4new=getTags4New();
+ Map rtn=(Map)tags4new.get("tag_follow");
+ rtn.put("types",types);
+ rtn.put("data",timeoutdata);
+
+ return rtn;
+
+ }catch(Exception e){
+ throw e;
+ }finally{
+ sdb.closeDB();
+ }
+ }
+
+ /**
+ * Saves timeout settings, includes sql query criteria for timeout and what should be done incase of timeout and so on.
+ * @param data
+ * @return
+ * @throws Exception
+ */
+ public boolean updateTimeoutSettings(Map data) throws Exception {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+
+ sdb.connectDB();
+ sdb.updateTimeoutSettings(data);
+ return true;
+ }catch(Exception e){
+ throw e;
+ }finally{
+ sdb.closeDB();
+ }
+ }
+
+ /**
+ * called during clicking trash icon
+ * @return
+ * @throws Exception
+ */
+ public List trashedItems() throws Exception {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+
+ sdb.connectDB();
+ List rtn=sdb.listTrashedScheduler();
+ return rtn;
+ }catch(Exception e){
+ throw e;
+ }finally{
+ sdb.closeDB();
+ }
+ }
+
+
+ private void updateWikiThread(final int scheduler_id){
+
+
+ Thread thread=new Thread() {
+
+ public void run() {
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+ sdb.connectDB();
+ String wiki=getWikiHelp(scheduler_id+"");
+ log.debug("wiki taskname:"+scheduler_id+" found: "+wiki.contains("\"noarticletext\"")+" scheduler_id:"+scheduler_id);
+ if(wiki.contains("\"noarticletext\"")){
+ sdb.updateWikiDone(scheduler_id, 0);
+ }else{
+ sdb.updateWikiDone(scheduler_id, 1);
+ }
+ }catch(Exception e){
+ log.error("Error while updating");
+ }finally{
+ try{
+ sdb.closeDB();
+ }catch(Exception e){}
+ }
+
+ }
+ };
+ thread.start();
+
+
+ }
+
+ /**
+ * On cick of edit button on task item from tree menu
+ *
+ * @param scheduleditem_id
+ * @return
+ * @throws Exception
+ */
+ public Map getScheduledItem(int scheduleditem_id) throws Exception {
+
+
+ HashMap rtn=new HashMap();
+
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+ sdb.connectDB();
+
+ Map data=sdb.getScheduler(scheduleditem_id);
+ log.debug("rscript:"+data.get("rscript"));
+
+ String access=getAccessPrivilege(scheduleditem_id, sdb);
+
+ if(access==null || (access!=null && access.equals(""))){
+
+ rtn.put("access", ACCESS_PRIVILEGE_R);
+ }else{
+ rtn.put("access", access);
+ }
+
+ log.debug("access:"+rtn.get("access"));
+
+ //added 29/Oct/2013 no access to restricted scripts.
+ /*if(rtn.get("access")!=null && (rtn.get("access").equals(ACCESS_PRIVILEGE_R) || rtn.get("access").equals(ACCESS_PRIVILEGE_RX) )) {
+ throw new Exception("No access to view this task");
+ }*/
+ if(access==null){
+ throw new Exception("No access to view this task");
+ }
+ updateWikiThread( scheduleditem_id);
+
+ Vector tdata=sdb.getTriggerData(scheduleditem_id);
+ rtn.put("triggerdata", convertTriggerData(tdata));
+ try{
+ rtn.put("revisions",getSVNLogs(sdb,scheduleditem_id));
+ }catch(Exception e){
+ log.error("error while reading revisions, ERR:"+e.getMessage());
+ }
+
+
+ if(data!=null){
+ String taskuid=(String)data.get("taskuid");
+
+
+ ScheduledTask task=new ScheduledTaskFactory().getTask(taskuid);
+
+ if(task==null){
+ throw new Exception("No engine active engine found for type "+taskuid);
+ }
+ log.debug("task:"+task);
+
+
+ for(ScheduledTaskField field:task.listFormFields()){
+ if(field.getPluggindata()!=null){
+ PlugginInterface pl=SchedulerPlugginRegister.getPluggin(field.getFieldtype());
+
+ String rec_id=(String)data.get(pl.getPlugginData().getFieldreference());
+ log.debug("field:"+field.getFieldlabel()+" recordid:"+rec_id+" ref:"+pl.getPlugginData().getFieldreference()+" data:"+data);
+
+ if(rec_id!=null){
+ Map pluggindata=pl.fetchData(Integer.parseInt(rec_id),getRequest());
+ data.put("pluggindata_field", field);
+ data.put("pluggindata", pl.getPlugginData());
+
+ data.put("pluggindata_data", pluggindata);
+ }
+ }
+ }
+
+ log.debug("pluggin processed");
+
+ List fields=getTaskFields(taskuid);
+ ScheduledTaskField folder=null;
+ for(Iterator i=fields.iterator();i.hasNext();){
+ ScheduledTaskField sf=i.next();
+ if(sf.getShortname().equalsIgnoreCase("folder_id")) folder=sf;
+ }
+
+ log.debug("folder:"+folder);
+
+ if(folder!=null) fields.remove(folder);
+ rtn.put("fields",fields);
+ rtn.put("taskdata", data) ;
+ rtn.put("lockedby", getLockedBy(scheduleditem_id,sdb));
+ try{
+ rtn.put("isAuthorized", isAuthorizedUser(sdb)) ;
+ rtn.put("authorizedUser", getAuthorizedUser(sdb));
+
+ String access1=(String)rtn.get("access");
+
+
+ String usr=new SchedulerMgmt(getRequest()).getAuthorizedUser(sdb);
+ if(getLockedBy(scheduleditem_id,sdb)==null){
+ if(access1!=null && access1.equals(ACCESS_PRIVILEGE_RWX)){
+
+ refreshCache(scheduleditem_id,LOCK_AUTO_RELEASE,usr);
+ }
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ log.debug("near end");
+ rtn.put("tag_follow", getItemTags2(scheduleditem_id,sdb));
+ log.debug("end");
+
+ }
+ return rtn;
+ }catch(Exception e){
+ //e.printStackTrace();
+ ClientError.reportError(e, null);
+ throw e;
+ }finally{
+ sdb.closeDB();
+ }
+
+ }
+
+ public Map getTags4New() throws Exception {
+ HashMap rtn=new HashMap();
+
+ SchedulerDB sdb=SchedulerDB.getSchedulerDB();
+ try{
+ sdb.connectDB();
+ rtn.put("tag_follow", getItemTags2(0,sdb));
+ return rtn;
+ }catch(Exception e){
+ throw e;
+ }finally{
+ sdb.closeDB();
+ }
+ }
+
+ public String getScriptRev(String scheduler_id, String revision,boolean flag) throws Exception {
+ SVNSync sync=new SVNSync();
+ String script=null;
+ if(flag)
+ script=sync.getScript(Integer.parseInt(scheduler_id), Long.parseLong(revision));
+ else
+ script=sync.diffWC(Integer.parseInt(scheduler_id), Long.parseLong(revision));
+
+ return script;
+
+ }
+
+
+ private Vector getSVNLogs(SchedulerDB sdb, int scheduler_id) throws Exception {
+ SVNSync sync=new SVNSync();
+ TreeMap rtn=new TreeMap();
+ Vector d=sync.log(scheduler_id);
+ List otherlogsList=sdb.getEditLogs(scheduler_id);
+ if( (d!=null && d.size()>0) || (otherlogsList!=null && otherlogsList.size()>0)){
+
+ SimpleDateFormat format=new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
+ for(Iterator