package com.capspire.ecm.ot.experimental; import com.opentext.livelink.oml.OScriptObject; import java.util.HashMap; import java.util.Map; public class JOExperiments { private static final Object Undefined = null; private static final String OK = "ok"; private static final String ErrMsg = "ErrMsg"; private static final String ApiError = "ApiError"; private static final String Result = "Result"; public static synchronized Map runSingleThreaded(String scriptPath) { Map retVal = new HashMap(); retVal.put(OK, Boolean.FALSE); retVal.put(ErrMsg, Undefined); retVal.put(ApiError, Undefined); retVal.put(Result, Undefined); try { if (isNullOrEmpty(scriptPath)) { throw new RuntimeException("The scriptPath parameter cannot be null or empty."); } Object result = OScriptObject.runScript(scriptPath); retVal.put(Result, result); retVal.put(OK, Boolean.TRUE); } catch (Exception e) { retVal.put(ErrMsg, e.getLocalizedMessage()); retVal.put(ApiError, e); } if (IsNotOk(retVal)) { if (IsUndefined(retVal.get(ErrMsg))) { retVal.put(ErrMsg, "Unexpected error executing runSingleThreaded. Perhaps you forgot to set OK to true or to provide an ErrMsg value."); } } return retVal; } private static boolean isNullOrEmpty(Object o) { return ((o == null) || (o.toString() == null) || (o.toString().isEmpty())); } private static boolean IsOk(Object o) { Object test; if (o instanceof Map) { test = ((Map) o).get(OK); } else if (o instanceof Boolean) { test = o; } else { throw new RuntimeException(String.format("Expected Boolean or Map, got %s", o.getClass().getName())); } return (Boolean.TRUE.equals(test)); } private static boolean IsNotOk(Object o) { return !IsOk(o); } private static boolean IsUndefined(Object o) { return (o == null); } }