Search in sources :

Example 16 with ApplicationException

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;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) Relation(com.servoy.j2db.persistence.Relation) ApplicationException(com.servoy.j2db.ApplicationException) IJSRecord(com.servoy.base.scripting.api.IJSRecord) ServoyException(com.servoy.j2db.util.ServoyException)

Example 17 with ApplicationException

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;
}
Also used : ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) ApplicationException(com.servoy.j2db.ApplicationException)

Example 18 with ApplicationException

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;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) FormScope(com.servoy.j2db.scripting.FormScope) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 19 with ApplicationException

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);
    }
}
Also used : ApplicationException(com.servoy.j2db.ApplicationException) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) IBasicFormManager(com.servoy.j2db.IBasicFormManager) BasicFormController(com.servoy.j2db.BasicFormController)

Example 20 with ApplicationException

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();
}
Also used : ApplicationException(com.servoy.j2db.ApplicationException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) ApplicationException(com.servoy.j2db.ApplicationException) ExitScriptException(com.servoy.j2db.ExitScriptException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Aggregations

ApplicationException (com.servoy.j2db.ApplicationException)22 ServoyException (com.servoy.j2db.util.ServoyException)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)5 Relation (com.servoy.j2db.persistence.Relation)4 Table (com.servoy.j2db.persistence.Table)4 BasicFormController (com.servoy.j2db.BasicFormController)3 IBasicFormManager (com.servoy.j2db.IBasicFormManager)3 Column (com.servoy.j2db.persistence.Column)3 Form (com.servoy.j2db.persistence.Form)3 ITable (com.servoy.j2db.persistence.ITable)3 QuerySelect (com.servoy.j2db.query.QuerySelect)3 RemoteException (java.rmi.RemoteException)3 ArrayList (java.util.ArrayList)3 JavaScriptException (org.mozilla.javascript.JavaScriptException)3 ScriptableObject (org.mozilla.javascript.ScriptableObject)3 IBaseColumn (com.servoy.base.persistence.IBaseColumn)2 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 ExitScriptException (com.servoy.j2db.ExitScriptException)2 FindState (com.servoy.j2db.dataprocessing.FindState)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2