use of com.servoy.j2db.ApplicationException in project servoy-client by Servoy.
the class FoundSet method createRecord.
private IRecordInternal createRecord(Row rowData, boolean javascriptRecord) throws ApplicationException {
if (findMode) {
// limit to 200
if (pksAndRecords.getCachedRecords().size() > fsm.pkChunkSize)
return null;
return new FindState(this);
}
if (javascriptRecord && !hasAccess(IRepository.INSERT)) {
throw new ApplicationException(ServoyException.NO_CREATE_ACCESS, new Object[] { getTable().getName() });
}
if (rowData == null && relationName != null) {
Relation relation = fsm.getApplication().getFlattenedSolution().getRelation(relationName);
if (relation != null) {
Placeholder ph = creationSqlSelect.getPlaceholder(SQLGenerator.createRelationKeyPlaceholderKey(creationSqlSelect.getTable(), relation.getName()));
if (ph == null || !ph.isSet() || ph.getValue() == null || ((Object[]) ph.getValue()).length == 0) {
Debug.trace(// $NON-NLS-1$
"New record failed because related foundset had no parameters, or trying to make a new findstate when it is nested more then 2 deep");
return null;
}
if (!relation.getAllowCreationRelatedRecords()) {
ApplicationException applicationException = new ApplicationException(ServoyException.NO_RELATED_CREATE_ACCESS, new Object[] { relation.getName() });
applicationException.setContext(this.toString());
throw applicationException;
}
}
}
try {
if (javascriptRecord && !executeFoundsetTriggerBreakOnFalse(null, PROPERTY_ONCREATEMETHODID, false)) {
// $NON-NLS-1$
Debug.trace("New record creation was denied by onCreateRecord method");
return null;
}
} catch (ServoyException e) {
Debug.error(e);
return null;
}
IRecordInternal newRecord = null;
if (rowData == null) {
Object[] data = sheet.getNewRowData(fsm.getApplication(), this);
newRecord = new Record(this, rowManager.createNotYetExistInDBRowObject(data, true));
sheet.processCopyValues(newRecord);
} else {
newRecord = new Record(this, rowData);
}
try {
if (javascriptRecord) {
executeFoundsetTrigger(new Object[] { newRecord }, PROPERTY_ONAFTERCREATEMETHODID, false);
}
} catch (ServoyException e) {
Debug.error(e);
}
return newRecord;
}
use of com.servoy.j2db.ApplicationException in project servoy-client by Servoy.
the class EditRecordList method getRecordUpdateInfo.
/*
* _____________________________________________________________ Methods for data manipulation
*/
private RowUpdateInfo getRecordUpdateInfo(IRecordInternal state) throws ServoyException {
Table table = state.getParentFoundSet().getSQLSheet().getTable();
RowManager rowManager = fsm.getRowManager(fsm.getDataSource(table));
Row rowData = state.getRawData();
boolean doesExistInDB = rowData.existInDB();
if (doesExistInDB && !hasAccess(table, IRepository.UPDATE)) {
throw new ApplicationException(ServoyException.NO_MODIFY_ACCESS, new Object[] { table.getName() });
}
GlobalTransaction gt = fsm.getGlobalTransaction();
if (gt != null) {
gt.addRecord(table.getServerName(), state);
}
RowUpdateInfo rowUpdateInfo = rowManager.getRowUpdateInfo(rowData, hasAccess(table, IRepository.TRACKING));
return rowUpdateInfo;
}
use of com.servoy.j2db.ApplicationException in project servoy-client by Servoy.
the class RecordItemModel method setValue.
/**
* @param obj
* @param dataProviderID
* @param prevValue
*/
public void setValue(Component component, String dataProviderID, Object value) {
Object obj = value;
String compDpid = getDataProviderID(component);
boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
Object prevValue = null;
if (ownComponentsValue && component instanceof IResolveObject) {
obj = ((IResolveObject) component).resolveRealValue(obj);
}
if (component instanceof IDisplayData) {
obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
}
WebForm webForm = component.findParent(WebForm.class);
IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
// use UI converter to convert from UI value to record value
if (!(record instanceof FindState)) {
obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
}
FormScope fs = webForm.getController().getFormScope();
try {
Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
if (scope.getLeft() != null) {
if (record == null) {
webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
} else {
// does an additional fire in foundset!
prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
}
} else if (fs.has(dataProviderID, fs)) {
prevValue = fs.get(dataProviderID);
fs.put(dataProviderID, obj);
} else {
if (record != null && record.startEditing()) {
try {
prevValue = record.getValue(dataProviderID);
record.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = record.getValue(dataProviderID);
if (!Utils.equalObjects(prevValue, stateValue)) {
// reset display to changed value in validator method
obj = stateValue;
}
if (ownComponentsValue) {
((IDisplayData) component).setValueValid(false, prevValue);
}
return;
}
if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
}
}
}
// then dont call notify
if (ownComponentsValue) {
((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
}
} finally {
// then touch the lastInvalidValue
if (ownComponentsValue) {
if (((IDisplayData) component).isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
return;
}
use of com.servoy.j2db.ApplicationException in project servoy-client by Servoy.
the class RuntimeWindow method showObject.
public void showObject(Object form) throws ServoyException {
String f = null;
if (form instanceof BasicFormController) {
f = ((BasicFormController) form).getName();
} else if (form instanceof FormScope) {
f = ((FormScope) form).getFormController().getName();
} else if (form instanceof FormController.JSForm) {
f = ((FormController.JSForm) form).getFormPanel().getName();
} else if (form instanceof String) {
f = (String) form;
} else if (form instanceof JSForm) {
f = ((JSForm) form).getName();
}
if (f != null) {
Form frm = application.getFlattenedSolution().getForm(f);
IBasicFormManager fm = application.getFormManager();
if (frm == null && fm.isPossibleForm(f))
frm = fm.getPossibleForm(f);
if (!application.getFlattenedSolution().formCanBeInstantiated(frm)) {
// abstract form
throw new ApplicationException(ServoyException.ABSTRACT_FORM, new Object[] { f });
}
show(f);
}
}
use of com.servoy.j2db.ApplicationException in project servoy-client by Servoy.
the class JSApplication method js_executeProgram.
/**
* Execute a program and returns output. Specify the cmd as you would do in a console.
*
* @sample
* // For Windows systems:
* // Runs a binary located in the user's home directory. The application will run in the current working
* // directory, which in general is the one where Servoy was started from.
* application.executeProgram("c:\\Users\\myself\\myapp.exe", ["arg1", "arg2", "arg3"]);
* // The same as above, but run the application in the user's home directory.
* application.executeProgram("c:\\Users\\myself\\myapp.exe", ["arg1", "arg2", "arg3"], null, "c:\\Users\\myself\\");
* // The same as above, but also set an environment variable for the called program.
* application.executeProgram("c:\\Users\\myself\\myapp.exe", ["arg1", "arg2", "arg3"], ["MY_ENV_VAR=something"], "c:\\Users\\myself\\");
* // For non-Windows systems:
* application.executeProgram("/home/myself/myapp", ["arg1", "arg2", "arg3"]);
* application.executeProgram("/home/myself/myapp", ["arg1", "arg2", "arg3"], null, "/home/myself/");
* application.executeProgram("/home/myself/myapp", ["arg1", "arg2", "arg3"], ["MY_ENV_VAR=something"], "/home/myself/");
* // Open a file with the default application associated with it. (on Windows)
* application.executeProgram("rundll32.exe", ["url.dll,FileProtocolHandler", "filename"]);
* // Open a file with the default application associated with it. (on Linux)
* application.executeProgram("xdg-open", ["filename"]);
* // Open a file with the default application associated with it. (on MacOS)
* application.executeProgram("open", ["filename"]);
* // Open a file with a specific application (on MacOS).
* application.executeProgram("open", ["-a", "OpenOffice.org.app", "filename.doc"]);
*
* @param program (fullpath) of the program to execute
* @param params an array of strings as program arguments
* @param environmentVars array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
* @param startDir the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
* @return The output generated by the program execution.
* @throws ApplicationException
*/
public String js_executeProgram(String program, String[] params, String[] environmentVars, String startDir) throws ApplicationException {
StringBuilder output = new StringBuilder();
try {
// startDir can be null or any string
File _startDir = (startDir == null ? null : new File(startDir));
String[] commandWithParams = Utils.arrayJoin(new String[] { program }, params);
Process myProcess = Runtime.getRuntime().exec(commandWithParams, environmentVars, _startDir);
BufferedReader in = new BufferedReader(new InputStreamReader(myProcess.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
output.append(line);
output.append("\n");
}
in.close();
// clear any error
setLastErrorCode(0);
} catch (Exception e) {
setLastErrorCode(ServoyException.EXECUTE_PROGRAM_FAILED);
// throw new ApplicationException(ServoyException.EXECUTE_PROGRAM_FAILED, e);
ApplicationException applicationException = new ApplicationException(ServoyException.EXECUTE_PROGRAM_FAILED, e);
JavaScriptException javaScriptException = new JavaScriptException(applicationException, "", 0);
throw javaScriptException;
}
return output.toString();
}
Aggregations