1 package com.proalpha.pds.paconnector;
3 import java.util.Enumeration;
4 import java.util.Hashtable;
6 import org.eclipse.core.runtime.IPath;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import com.openedge.core.runtime.ProgressCommand;
11 import com.proalpha.pds.exception.ProALPHANotAvailableException;
12 import com.proalpha.pds.paconnector.utils.CharsetConverter;
13 import com.proalpha.pds.paconnector.utils.ExceptionUtils;
17 private final Logger logger = LoggerFactory.getLogger(
RunProgramInPa.class);
18 private static final String S_SUBPATH =
"adm/support/proc/";
24 private static final int P_INTERNALCALL = 1;
25 private static final int P_EXTERNALCALL = 2;
26 private static final int P_FINDRECORD = 3;
27 private static final int P_EXTERNALCALLPERSISTENT = 4;
31 private static final int P_INTERNALFUNCTION = 1;
32 private static final int P_INTERNALPROCEDURE = 2;
33 private static final int P_UNDEFINEDMETHODTYPE = 0;
48 IPath bridgePath = this.paProject.getOeProject().getPropath().search(
"paoidebr.p",
true);
50 if (bridgePath ==
null)
53 this.paProject.setBridgePath(bridgePath);
58 this.paProject.setCustomLevel(getpAStartupParam(
"CustomLevel",
""));
59 this.paProject.setAvailable(
true);
60 }
catch (IllegalArgumentException e) {
61 this.paProject.setCodepage(
"");
76 return run(P_INTERNALCALL, P_INTERNALPROCEDURE, service, procedureName, parameters);
91 return run(P_INTERNALCALL, P_INTERNALFUNCTION, service, functionName, parameters);
103 return run(P_EXTERNALCALL, P_UNDEFINEDMETHODTYPE, procedure,
"", parameters);
115 return run(P_EXTERNALCALLPERSISTENT, P_UNDEFINEDMETHODTYPE, procedure,
"", parameters);
128 public String
recordField(String tableName, Hashtable<String, String> selection, String fieldName) {
130 String[] parameters =
new String[(selection.size() * 2) + 2];
131 parameters[0] = tableName;
132 parameters[1] = fieldName;
134 Enumeration<String> keys = selection.keys();
135 Enumeration<String> values = selection.elements();
136 for (
int i = 0; i < selection.size(); i++) {
137 parameters[k++] = keys.nextElement();
138 parameters[k++] = values.nextElement();
141 return run(P_FINDRECORD, P_UNDEFINEDMETHODTYPE,
"",
"", parameters);
154 private synchronized String run(
int serviceType,
int methodType, String program, String methodName,
155 String... parameters) {
156 return run(serviceType, methodType, program, methodName,
false, parameters);
159 private synchronized String run(
int serviceType,
int methodType, String program, String methodName,
boolean toTop,
160 String... parameters) {
162 String commandString;
164 if (this.paProject.getBridgePath() ==
null) {
165 Throwable e =
new Throwable(
"Bridge to pA not available. cancel action " + program);
166 ExceptionUtils.showAndLogErrorMessage(Activator.getDefault(), e);
171 commandString =
"ServiceType=" + serviceType +
",MethodType=" + methodType +
",Program=" + program
172 +
",MethodName=" + methodName +
",NumberOfParameters=" + parameters.length;
176 StringBuilder cmdStr =
new StringBuilder(commandString);
177 for (String parameter : parameters) {
178 cmdStr.append(
",ParameterValue");
181 cmdStr.append(parameter);
183 commandString = cmdStr.toString();
188 if (this.paProject.getCodepage() !=
null) {
189 commandString = CharsetConverter.encode(this.paProject.getCodepage(), commandString);
192 ProgressCommand cmd =
new ProgressCommand((this.paProject.getBridgePath()).toOSString(), commandString,
196 this.paProject.getOeProject().getRuntime().runProgressCommand(cmd);
200 this.paProject.getOeProject().getRuntime().bringToTop();
210 }
catch (InterruptedException e) {
211 Thread.currentThread().interrupt();
212 ExceptionUtils.showAndLogErrorMessage(Activator.getDefault(), e);
215 if (!cmd.isFinished()) {
216 Throwable e =
new Throwable(
"Openedge Command couldn't get finished!");
217 ExceptionUtils.showAndLogErrorMessage(Activator.getDefault(), e);
223 if (cmd.getCompletionStatus() == ProgressCommand.STATUS_COMPLETED) {
226 String result = cmd.getResult();
227 logger.debug(
"CommandString: {}", commandString);
228 logger.debug(
"Result: {}", result);
245 String filePath =
null;
246 IPath iPath = this.paProject.getOeProject().getPropath().search(S_SUBPATH + supportProcedure,
true);
248 if (iPath !=
null && !iPath.isEmpty())
249 filePath = iPath.toOSString();
251 if (filePath ==
null) {
252 throw new IllegalArgumentException(
253 String.format(
"In this version, this feature is not supported. (%s)", supportProcedure));
257 if (retVal.startsWith(
"PROGRESS runtime error ")) {
258 StringBuilder errorMsg =
new StringBuilder();
260 "Support procedure " + supportProcedure +
" returned\n" + retVal +
"\n\nParameters given:\n");
261 for (
int i = 0; i < parameters.length; i++)
262 errorMsg.append(parameters[i] +
"\n");
264 throw new IllegalArgumentException(errorMsg.toString());
272 public String getpAStartupParam(String startupParam, String defaultValue) {
281 for (String result : results) {
283 if (result.split(
"=")[0].equals(
"2")) {
285 if ((result.split(
"=").length == 1)
288 || !result.split(
"=")[1].contains(
"Unknown"))
String runExternalProcedurePersistent(String procedure, String... parameters)
String runSupportProcedure(String supportProcedure, String... parameters)
String callFunctionInService(String service, String functionName, String... parameters)
String recordField(String tableName, Hashtable< String, String > selection, String fieldName)
final PaProject paProject
String callProcedureInService(String service, String procedureName, String... parameters)
String runExternalProcedure(String procedure, String... parameters)