Search in sources :

Example 26 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class DatabaseWindowManager method openLatest.

/**
 * Insert the method's description here.
 * Creation date: (6/1/2004 9:49:06 PM)
 */
public void openLatest() {
    VCDocumentInfo latestDocumentInfo = null;
    if (getPanelSelection() != null) {
        VCDocumentInfo thisDocumentInfo = getPanelSelection();
        // 
        // Get the latest version of the documentInfo
        // 
        VCDocumentInfo[] documentVersionsList = null;
        try {
            documentVersionsList = getDocumentVersionDates(thisDocumentInfo);
        } catch (DataAccessException e) {
            PopupGenerator.showErrorDialog(this, "Error accessing document!");
        }
        // 
        if (documentVersionsList != null && documentVersionsList.length > 0) {
            latestDocumentInfo = documentVersionsList[documentVersionsList.length - 1];
            for (int i = 0; i < documentVersionsList.length; i++) {
                if (documentVersionsList[i].getVersion().getDate().after(latestDocumentInfo.getVersion().getDate())) {
                    latestDocumentInfo = documentVersionsList[i];
                }
            }
            if (thisDocumentInfo.getVersion().getDate().after(latestDocumentInfo.getVersion().getDate())) {
                latestDocumentInfo = thisDocumentInfo;
            }
        } else {
            latestDocumentInfo = thisDocumentInfo;
        }
    } else {
        PopupGenerator.showErrorDialog(this, "Error Opening Latest Document : no document currently selected.");
        return;
    }
    getRequestManager().openDocument(latestDocumentInfo, this, true);
}
Also used : VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 27 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class DatabaseWindowManager method accessPermissions.

/**
 * Insert the method's description here.
 * Creation date: (5/14/2004 5:35:55 PM)
 */
public void accessPermissions(final Component requester, final VersionInfo selectedVersionInfo) {
    final GroupAccess groupAccess = selectedVersionInfo.getVersion().getGroupAccess();
    final DocumentManager docManager = getRequestManager().getDocumentManager();
    AsynchClientTask task1 = new AsynchClientTask("show dialog", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            getAclEditor().clearACLList();
            getAclEditor().setACLState(new ACLEditor.ACLState(groupAccess));
            Object choice = showAccessPermissionDialog(getAclEditor(), requester);
            if (choice != null) {
                hashTable.put("choice", choice);
            }
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("access permission", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Object choice = hashTable.get("choice");
            if (choice != null && choice.equals("OK")) {
                ACLEditor.ACLState aclState = getAclEditor().getACLState();
                if (aclState != null) {
                    if (aclState.isAccessPrivate() || (aclState.getAccessList() != null && aclState.getAccessList().length == 0)) {
                        VersionInfo vInfo = null;
                        if (selectedVersionInfo instanceof BioModelInfo) {
                            vInfo = docManager.setGroupPrivate((BioModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof MathModelInfo) {
                            vInfo = docManager.setGroupPrivate((MathModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof GeometryInfo) {
                            vInfo = docManager.setGroupPrivate((GeometryInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof VCImageInfo) {
                            vInfo = docManager.setGroupPrivate((VCImageInfo) selectedVersionInfo);
                        }
                    } else if (aclState.isAccessPublic()) {
                        VersionInfo vInfo = null;
                        if (selectedVersionInfo instanceof BioModelInfo) {
                            vInfo = docManager.setGroupPublic((BioModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof MathModelInfo) {
                            vInfo = docManager.setGroupPublic((MathModelInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof GeometryInfo) {
                            vInfo = docManager.setGroupPublic((GeometryInfo) selectedVersionInfo);
                        } else if (selectedVersionInfo instanceof VCImageInfo) {
                            vInfo = docManager.setGroupPublic((VCImageInfo) selectedVersionInfo);
                        }
                    } else {
                        String[] aclUserNames = aclState.getAccessList();
                        String[] originalGroupAccesNames = new String[0];
                        // Turn User[] into String[]
                        if (groupAccess instanceof GroupAccessSome) {
                            GroupAccessSome gas = (GroupAccessSome) groupAccess;
                            User[] originalUsers = gas.getNormalGroupMembers();
                            for (int i = 0; i < originalUsers.length; i += 1) {
                                originalGroupAccesNames = (String[]) BeanUtils.addElement(originalGroupAccesNames, originalUsers[i].getName());
                            }
                        }
                        // Determine users needing adding
                        String[] needToAddUsers = new String[0];
                        for (int i = 0; i < aclUserNames.length; i += 1) {
                            if (!BeanUtils.arrayContains(originalGroupAccesNames, aclUserNames[i])) {
                                System.out.println("Added user=" + aclUserNames[i]);
                                needToAddUsers = (String[]) BeanUtils.addElement(needToAddUsers, aclUserNames[i]);
                            }
                        }
                        // Determine users needing removing
                        String[] needToRemoveUsers = new String[0];
                        for (int i = 0; i < originalGroupAccesNames.length; i += 1) {
                            if (!BeanUtils.arrayContains(aclUserNames, originalGroupAccesNames[i])) {
                                System.out.println("Removed user=" + originalGroupAccesNames[i]);
                                needToRemoveUsers = (String[]) BeanUtils.addElement(needToRemoveUsers, originalGroupAccesNames[i]);
                            }
                        }
                        VersionInfo vInfo = null;
                        String errorNames = "";
                        // Add Users to Group Access List
                        for (int i = 0; i < needToAddUsers.length; i++) {
                            try {
                                if (selectedVersionInfo instanceof BioModelInfo) {
                                    vInfo = docManager.addUserToGroup((BioModelInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof MathModelInfo) {
                                    vInfo = docManager.addUserToGroup((MathModelInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof GeometryInfo) {
                                    vInfo = docManager.addUserToGroup((GeometryInfo) selectedVersionInfo, needToAddUsers[i]);
                                } else if (selectedVersionInfo instanceof VCImageInfo) {
                                    vInfo = docManager.addUserToGroup((VCImageInfo) selectedVersionInfo, needToAddUsers[i]);
                                }
                            } catch (ObjectNotFoundException e) {
                                errorNames += "Error changing permissions.\n" + selectedVersionInfo.getVersionType().getTypeName() + " \"" + selectedVersionInfo.getVersion().getName() + "\" edition (" + selectedVersionInfo.getVersion().getDate() + ")\nnot found, " + "your model list may be out of date, please go to menu Server->Reconnect to refresh the model list" + "\n";
                                break;
                            } catch (DataAccessException e) {
                                errorNames += "Error adding user '" + needToAddUsers[i] + "' : " + e.getMessage() + "\n";
                            }
                        }
                        // Remove users from Group Access List
                        for (int i = 0; i < needToRemoveUsers.length; i++) {
                            try {
                                if (selectedVersionInfo instanceof BioModelInfo) {
                                    vInfo = docManager.removeUserFromGroup((BioModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof MathModelInfo) {
                                    vInfo = docManager.removeUserFromGroup((MathModelInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof GeometryInfo) {
                                    vInfo = docManager.removeUserFromGroup((GeometryInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                } else if (selectedVersionInfo instanceof VCImageInfo) {
                                    vInfo = docManager.removeUserFromGroup((VCImageInfo) selectedVersionInfo, needToRemoveUsers[i]);
                                }
                            } catch (DataAccessException e) {
                                errorNames += "Error Removing user '" + needToRemoveUsers[i] + "'\n  -----" + e.getMessage() + "\n";
                            }
                        }
                        if (errorNames.length() > 0) {
                            if (DatabaseWindowManager.this.getComponent() != null) {
                                PopupGenerator.showErrorDialog(DatabaseWindowManager.this, errorNames);
                            } else {
                                DialogUtils.showErrorDialog(requester, errorNames);
                            }
                            accessPermissions(requester, selectedVersionInfo);
                        }
                    }
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(requester, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) BioModelInfo(org.vcell.util.document.BioModelInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) ACLEditor(cbit.vcell.client.desktop.ACLEditor) VersionInfo(org.vcell.util.document.VersionInfo) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) GeometryInfo(cbit.vcell.geometry.GeometryInfo) GroupAccessSome(org.vcell.util.document.GroupAccessSome) GroupAccess(org.vcell.util.document.GroupAccess) VCImageInfo(cbit.image.VCImageInfo) DataAccessException(org.vcell.util.DataAccessException)

Example 28 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class TestingFrameworkWindowManager method queryTCritCrossRef.

@SuppressWarnings("serial")
public void queryTCritCrossRef(final TestSuiteInfoNew tsin, final TestCriteriaNew tcrit, final String varName) {
    try {
        QueryTestCriteriaCrossRefOP queryTestCriteriaCrossRefOP = new QueryTestCriteriaCrossRefOP(tsin.getTSKey(), tcrit.getTCritKey(), varName);
        TestCriteriaCrossRefOPResults testCriteriaCrossRefOPResults = (TestCriteriaCrossRefOPResults) getRequestManager().getDocumentManager().doTestSuiteOP(queryTestCriteriaCrossRefOP);
        final Vector<TestCriteriaCrossRefOPResults.CrossRefData> xrefDataV = testCriteriaCrossRefOPResults.getCrossRefData();
        final TestSuiteInfoNew[] testSuiteInfos = getRequestManager().getDocumentManager().getTestSuiteInfos();
        Vector<TestSuiteInfoNew> missingTestSuites = new Vector<TestSuiteInfoNew>();
        for (int i = 0; i < testSuiteInfos.length; i++) {
            boolean bFound = false;
            for (int j = 0; j < xrefDataV.size(); j++) {
                if (xrefDataV.elementAt(j).tsVersion.equals(testSuiteInfos[i].getTSID())) {
                    bFound = true;
                    break;
                }
            }
            if (!bFound) {
                missingTestSuites.add(testSuiteInfos[i]);
            }
        }
        TestCriteriaCrossRefOPResults.CrossRefData xrefDataSource = null;
        for (int i = 0; i < xrefDataV.size(); i++) {
            if (xrefDataV.elementAt(i).tcritKey.equals(tcrit.getTCritKey())) {
                xrefDataSource = xrefDataV.elementAt(i);
                break;
            }
        }
        if (xrefDataSource == null) {
            throw new RuntimeException("Couldn't find source Test Criteria in query results.");
        }
        final int numColumns = 8;
        final int XREFDATA_ALLOWANCE = 1;
        final int TSKEY_ALLOWANCE = 1;
        final int XREFDATA_OFFSET = numColumns;
        final int TSDATE_OFFSET = 1;
        final int VARNAME_OFFSET = 3;
        final int TSKEYMISSING_OFFSET = numColumns + 1;
        final String[] colNames = new String[numColumns];
        final Object[][] sourceRows = new Object[xrefDataV.size() + missingTestSuites.size()][numColumns + XREFDATA_ALLOWANCE + TSKEY_ALLOWANCE];
        String sourceTestSuite = null;
        colNames[0] = "tsVersion";
        colNames[1] = "tsDate";
        colNames[2] = "tsBaseVersion";
        colNames[3] = "varName";
        colNames[4] = "RelErorr";
        colNames[5] = "limitRelErorr";
        colNames[6] = "limitAbsErorr";
        colNames[7] = "AbsErorr";
        for (int i = 0; i < xrefDataV.size(); i++) {
            sourceRows[i][colNames.length] = xrefDataV.elementAt(i);
            if (xrefDataV.elementAt(i).tcritKey.equals(queryTestCriteriaCrossRefOP.getTestCriterium())) {
                sourceTestSuite = xrefDataV.elementAt(i).tsVersion;
            }
            sourceRows[i][0] = xrefDataV.elementAt(i).tsVersion;
            sourceRows[i][2] = (xrefDataV.elementAt(i).tsRefVersion == null ? (xrefDataV.elementAt(i).regressionModelID == null ? /* && xrefDataV.elementAt(i).regressionMMref==null*/
            "" : "Ref Model exist BUT outside of TestSuites") : xrefDataV.elementAt(i).tsRefVersion);
            sourceRows[i][6] = xrefDataV.elementAt(i).maxAbsErorr;
            sourceRows[i][5] = xrefDataV.elementAt(i).maxRelErorr;
            if (xrefDataV.elementAt(i).varName != null) {
                sourceRows[i][VARNAME_OFFSET] = xrefDataV.elementAt(i).varName;
                sourceRows[i][4] = xrefDataV.elementAt(i).varCompSummary.getRelativeError();
                sourceRows[i][7] = xrefDataV.elementAt(i).varCompSummary.getAbsoluteError();
            } else {
                sourceRows[i][VARNAME_OFFSET] = "-No Report-";
                // "No Report";
                sourceRows[i][4] = null;
                // "No Report";
                sourceRows[i][7] = null;
            }
            for (int j = 0; j < testSuiteInfos.length; j++) {
                if (xrefDataV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                    sourceRows[i][1] = testSuiteInfos[j].getTSDate();
                    break;
                }
            }
        }
        for (int i = xrefDataV.size(); i < sourceRows.length; i++) {
            sourceRows[i][0] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSID();
            sourceRows[i][TSDATE_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSDate();
            sourceRows[i][TSKEYMISSING_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSKey();
        }
        // Arrays.sort(rows,
        // new Comparator<Object[]>(){
        // public int compare(Object[] o1, Object[] o2) {
        // return ((String)o1[0]).compareToIgnoreCase((String)o2[0]);
        // //						if(o1[0].equals(o2[0])){
        // //							return o1[3].compareToIgnoreCase(o2[3]);
        // //						}
        // //						return o1[0].compareToIgnoreCase(o2[0]);
        // }
        // }
        // );
        final VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(colNames) {

            public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == TSDATE_OFFSET) {
                    return Date.class;
                } else if (columnIndex >= 4 && columnIndex <= 7) {
                    return Double.class;
                }
                return String.class;
            }

            public boolean isCellEditable(int row, int column) {
                return false;
            }

            public Object getValueAt(int rowIndex, int columnIndex) {
                return getValueAt(rowIndex)[columnIndex];
            }

            public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
                return new Comparator<Object[]>() {

                    public int compare(Object[] o1, Object[] o2) {
                        if (o1[col] == null && o2[col] == null) {
                            return 0;
                        }
                        // if(ascending){
                        if (o1[col] == null) {
                            return 1;
                        }
                        if (o2[col] == null) {
                            return -1;
                        }
                        // }
                        if (getColumnClass(col).equals(String.class)) {
                            if (ascending) {
                                return ((String) o1[col]).compareToIgnoreCase(((String) o2[col]));
                            } else {
                                return ((String) o2[col]).compareToIgnoreCase(((String) o1[col]));
                            }
                        } else if (getColumnClass(col).equals(Date.class)) {
                            if (ascending) {
                                return ((Date) o1[col]).compareTo(((Date) o2[col]));
                            }
                            return ((Date) o2[col]).compareTo(((Date) o1[col]));
                        } else if (getColumnClass(col).equals(Double.class)) {
                            if (ascending) {
                                return ((Double) o1[col]).compareTo(((Double) o2[col]));
                            }
                            return ((Double) o2[col]).compareTo(((Double) o1[col]));
                        }
                        throw new RuntimeException("TestSuite XRef Query unexpecte column class " + getColumnClass(col).getName());
                    }
                };
            }
        };
        tableModel.setData(Arrays.asList(sourceRows));
        // Create table
        final JSortTable table = new JSortTable();
        table.setModel(tableModel);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        final JScrollPane scrollPaneContentPane = new JScrollPane(table);
        table.setPreferredScrollableViewportSize(new Dimension(500, 250));
        table.getColumnModel().getColumn(TSDATE_OFFSET).setCellRenderer(new DefaultTableCellRenderer() {

            // DateFormat formatter = DateFormat.getDateTimeInstance();
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Date) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        });
        DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Double) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        };
        table.getColumnModel().getColumn(4).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(5).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(6).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(7).setCellRenderer(dtcr);
        // table.getColumnModel().getColumn(4).setCellRenderer(
        // new DefaultTableCellRenderer(){
        // public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        // return super.getTableCellRendererComponent(table,(value == null?null:((Double)value).toString())/*formatter.format((Date)value)*/, isSelected, hasFocus, row, column);
        // }
        // }
        // );
        // table.getTableHeader().setReorderingAllowed(false);
        // Popup Menu
        final TestCriteriaCrossRefOPResults.CrossRefData xrefDataSourceFinal = xrefDataSource;
        final JPopupMenu queryPopupMenu = new JPopupMenu();
        final JMenuItem changeLimitsMenuItem = new JMenuItem("Change Selected Error Limits...");
        final String OPEN_MODEL = "Open Model(s)";
        final JMenuItem openModelMenuItem = new JMenuItem(OPEN_MODEL);
        final String OPEN_REGRREFMODEL = "Open Regr Ref Model(s)";
        final JMenuItem openRegrRefModelMenuItem = new JMenuItem(OPEN_REGRREFMODEL);
        final String SELECT_REF_IN_TREE = "Select in Tree View";
        final JMenuItem showInTreeMenuItem = new JMenuItem(SELECT_REF_IN_TREE);
        final String SELECT_REGR_REF_IN_TREE = "Select RegrRef TCase in Tree View";
        final JMenuItem showRegrRefInTreeMenuItem = new JMenuItem(SELECT_REGR_REF_IN_TREE);
        queryPopupMenu.add(changeLimitsMenuItem);
        queryPopupMenu.add(openModelMenuItem);
        queryPopupMenu.add(openRegrRefModelMenuItem);
        queryPopupMenu.add(showInTreeMenuItem);
        queryPopupMenu.add(showRegrRefInTreeMenuItem);
        ActionListener showInTreeActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows == null || selectedRows.length != 1) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Action " + actionEvent.getActionCommand() + " accepts only single selection!");
                    return;
                }
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[0], XREFDATA_OFFSET);
                BigDecimal missingTSKey = (BigDecimal) tableModel.getValueAt(selectedRows[0], TSKEYMISSING_OFFSET);
                if (actionEvent.getActionCommand().equals(SELECT_REF_IN_TREE)) {
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.tsKey : missingTSKey), (xrefData != null ? xrefData.tcaseKey : null), (xrefData != null ? xrefData.tcritKey : null));
                } else if (actionEvent.getActionCommand().equals(SELECT_REGR_REF_IN_TREE)) {
                    if (xrefData == null) {
                        PopupGenerator.showErrorDialog(getComponent(), "No Regression Reference info available.");
                        return;
                    }
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.regressionModelTSuiteID : null), (xrefData != null ? xrefData.regressionModelTCaseID : null), (xrefData != null ? xrefData.regressionModelTCritID : null));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        showInTreeMenuItem.addActionListener(showInTreeActionListener);
        showRegrRefInTreeMenuItem.addActionListener(showInTreeActionListener);
        ActionListener openModelsActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                String failureS = "";
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = null;
                int openCount = 0;
                for (int i = 0; i < selectedRows.length; i++) {
                    try {
                        xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                        if (xrefData != null && (actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID != null : true)) {
                            openCount += 1;
                            VCDocumentInfo vcDocInfo = null;
                            if (xrefData.isBioModel) {
                                vcDocInfo = getRequestManager().getDocumentManager().getBioModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            } else {
                                vcDocInfo = getRequestManager().getDocumentManager().getMathModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            }
                            getRequestManager().openDocument(vcDocInfo, TestingFrameworkWindowManager.this, true);
                        }
                    } catch (Exception e) {
                        failureS += failureS + "key=" + xrefData.modelID + " " + e.getMessage() + "\n";
                        e.printStackTrace();
                    }
                }
                if (failureS.length() > 0 || openCount == 0) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed to open some models\n" + failureS + (openCount == 0 ? "Selection(s) had no model(s)" : ""));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        openModelMenuItem.addActionListener(openModelsActionListener);
        openRegrRefModelMenuItem.addActionListener(openModelsActionListener);
        changeLimitsMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                Vector<TestCriteriaCrossRefOPResults.CrossRefData> changeTCritV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                for (int i = 0; i < selectedRows.length; i++) {
                    TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                    if (xrefData != null) {
                        boolean bFound = false;
                        for (int j = 0; j < changeTCritV.size(); j++) {
                            if (changeTCritV.elementAt(j).tcritKey.equals(xrefData.tcritKey)) {
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound) {
                            changeTCritV.add(xrefData);
                        }
                    }
                }
                if (changeTCritV.size() > 0) {
                    Double relativeErrorLimit = null;
                    Double absoluteErrorLimit = null;
                    while (true) {
                        try {
                            String ret = PopupGenerator.showInputDialog(getComponent(), "Enter new TestCriteria Error Limits for '" + xrefDataSourceFinal.simName + "'.  '-'(dash) to keep original value.", "RelativeErrorLimit,AbsoluteErrorLimit");
                            int commaPosition = ret.indexOf(',');
                            if (commaPosition == -1) {
                                throw new Exception("No comma found separating RelativeErrorLimit AbsoluteErrorLimit");
                            }
                            if (commaPosition != ret.lastIndexOf(',')) {
                                throw new Exception("Only 1 comma allowed separating RelativeErrorLimit and AbsoluteErrorLimit");
                            }
                            final String KEEP_ORIGINAL_VALUE = "-";
                            String relativeErrorS = ret.substring(0, commaPosition);
                            String absoluteErrorS = ret.substring(commaPosition + 1, ret.length());
                            if (!relativeErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                relativeErrorLimit = Double.parseDouble(relativeErrorS);
                            }
                            if (!absoluteErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                absoluteErrorLimit = Double.parseDouble(absoluteErrorS);
                            }
                            if ((relativeErrorLimit != null && relativeErrorLimit <= 0) || (absoluteErrorLimit != null && absoluteErrorLimit <= 0)) {
                                throw new Exception("Error limits must be greater than 0");
                            }
                            break;
                        } catch (UserCancelException e) {
                            ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                            if (childWindow != null) {
                                childWindow.show();
                            }
                            return;
                        } catch (Exception e) {
                            PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error parsing Error Limits\n" + e.getMessage());
                        }
                    }
                    double[] relErrorLimitArr = new double[changeTCritV.size()];
                    double[] absErrorLimitArr = new double[changeTCritV.size()];
                    Object[][] rows = new Object[changeTCritV.size()][5];
                    for (int j = 0; j < changeTCritV.size(); j++) {
                        relErrorLimitArr[j] = (relativeErrorLimit != null ? relativeErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxRelErorr);
                        absErrorLimitArr[j] = (absoluteErrorLimit != null ? absoluteErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][2] = new Double(relErrorLimitArr[j]);
                        rows[j][4] = new Double(absErrorLimitArr[j]);
                        rows[j][1] = new Double(changeTCritV.elementAt(j).maxRelErorr);
                        rows[j][3] = new Double(changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][0] = changeTCritV.elementAt(j).tsVersion;
                    }
                    try {
                        PopupGenerator.showComponentOKCancelTableList(getComponent(), "Confirm Error Limit Changes", new String[] { "TSVersion", "Orig RelErrorLimit", "New RelErrorLimit", "Orig AbsErrorLimit", "New AbsErrorLimit" }, rows, null);
                    } catch (UserCancelException e) {
                        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                        if (childWindow != null) {
                            childWindow.show();
                        }
                        return;
                    }
                    // Get information needed to generate new TestCriteria Reports
                    final String YES_ANSWER = "Yes";
                    Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>> genReportHash = null;
                    String genRepResult = PopupGenerator.showWarningDialog(getComponent(), "Generate Reports for changed Test Criterias?", new String[] { YES_ANSWER, "No" }, YES_ANSWER);
                    if (genRepResult != null && genRepResult.equals(YES_ANSWER)) {
                        genReportHash = new Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>>();
                        for (int i = 0; i < changeTCritV.size(); i++) {
                            boolean bFound = false;
                            for (int j = 0; j < testSuiteInfos.length; j++) {
                                if (changeTCritV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                                    bFound = true;
                                    Vector<TestCriteriaCrossRefOPResults.CrossRefData> tempV = genReportHash.get(testSuiteInfos[j]);
                                    if (tempV == null) {
                                        tempV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                                        genReportHash.put(testSuiteInfos[j], tempV);
                                    }
                                    tempV.add(changeTCritV.elementAt(i));
                                }
                            }
                            if (!bFound) {
                                PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Couldn't find testsuiteinfo for testcriteria");
                                return;
                            }
                        }
                    }
                    BigDecimal[] changeTCritBDArr = new BigDecimal[changeTCritV.size()];
                    for (int i = 0; i < changeTCritV.size(); i++) {
                        changeTCritBDArr[i] = changeTCritV.elementAt(i).tcritKey;
                    }
                    ChangeTestCriteriaErrorLimitOP changeTestCriteriaErrorLimitOP = new ChangeTestCriteriaErrorLimitOP(changeTCritBDArr, absErrorLimitArr, relErrorLimitArr);
                    try {
                        getTestingFrameworkWindowPanel().getDocumentManager().doTestSuiteOP(changeTestCriteriaErrorLimitOP);
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed Changing Error limits for selected " + xrefDataSourceFinal.simName + "\n" + e.getMessage());
                        return;
                    }
                    ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                    if (childWindow != null) {
                        childWindow.close();
                    }
                    getTestingFrameworkWindowPanel().refreshTree((TestSuiteInfoNew) null);
                    if (genReportHash != null) {
                        updateReports(genReportHash);
                    } else {
                        new Thread(new Runnable() {

                            public void run() {
                                TestingFrameworkWindowManager.this.queryTCritCrossRef(tsin, tcrit, varName);
                            }
                        }).start();
                    }
                } else {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "No selected rows contain Test Criteria.");
                }
            }
        });
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                checkPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                super.mousePressed(e);
                checkPopup(e);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                super.mouseReleased(e);
                checkPopup(e);
            }

            private void checkPopup(MouseEvent mouseEvent) {
                if (mouseEvent.isPopupTrigger()) {
                    // Not use because popupmenu will not show at edge
                    // if(table.getSelectedRowCount() <= 1){
                    // table.getSelectionModel().setSelectionInterval(table.rowAtPoint(mouseEvent.getPoint()),table.rowAtPoint(mouseEvent.getPoint()));
                    // }
                    doPopup(mouseEvent);
                } else {
                    queryPopupMenu.setVisible(false);
                }
            }

            private void doPopup(MouseEvent mouseEvent) {
                // queryPopupMenu.add(showInTreeMenuItem);
                if (table.getSelectedRowCount() == 0) {
                    changeLimitsMenuItem.setEnabled(false);
                    openModelMenuItem.setEnabled(false);
                    openRegrRefModelMenuItem.setEnabled(false);
                    showInTreeMenuItem.setEnabled(false);
                    showRegrRefInTreeMenuItem.setEnabled(false);
                } else {
                    changeLimitsMenuItem.setEnabled(true);
                    openModelMenuItem.setEnabled(true);
                    openRegrRefModelMenuItem.setEnabled(true);
                    showInTreeMenuItem.setEnabled(true);
                    if (table.getSelectedRowCount() == 1) {
                        TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(table.getSelectedRow(), numColumns);
                        showRegrRefInTreeMenuItem.setEnabled(xrefData != null && xrefData.regressionModelID != null && xrefData.tsRefVersion != null);
                    }
                }
                queryPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
            }
        });
        String title = (xrefDataSource.isBioModel ? "BM" : "MM") + " " + xrefDataSource.tcSolutionType + " (" + sourceTestSuite + ") " + " \"" + (xrefDataSource.isBioModel ? xrefDataSource.bmName : xrefDataSource.mmName) + "\"  ::  " + (xrefDataSource.isBioModel ? "app=\"" + xrefDataSource.bmAppName + "\"  ::  sim=\"" + xrefDataSource.simName + "\"" : "sim=\"" + xrefDataSource.simName + "\"");
        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).addChildWindow(scrollPaneContentPane, scrollPaneContentPane, title);
        // childWindow.setSize(600,400);
        childWindow.setIsCenteredOnParent();
        childWindow.pack();
        childWindow.setResizable(true);
        childWindow.show();
    } catch (DataAccessException e) {
        e.printStackTrace();
        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error Query TestCriteria Cross Ref:\n" + e.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ActionEvent(java.awt.event.ActionEvent) UserCancelException(org.vcell.util.UserCancelException) Comparator(java.util.Comparator) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Component(java.awt.Component) JComponent(javax.swing.JComponent) JMenuItem(javax.swing.JMenuItem) Vector(java.util.Vector) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) DataAccessException(org.vcell.util.DataAccessException) JScrollPane(javax.swing.JScrollPane) QueryTestCriteriaCrossRefOP(cbit.vcell.numericstest.QueryTestCriteriaCrossRefOP) MouseEvent(java.awt.event.MouseEvent) Hashtable(java.util.Hashtable) MouseAdapter(java.awt.event.MouseAdapter) TestCriteriaCrossRefOPResults(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Date(java.util.Date) JPopupMenu(javax.swing.JPopupMenu) BigDecimal(java.math.BigDecimal) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) JSortTable(org.vcell.util.gui.sorttable.JSortTable) ActionListener(java.awt.event.ActionListener) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) ChangeTestCriteriaErrorLimitOP(cbit.vcell.numericstest.ChangeTestCriteriaErrorLimitOP) JTable(javax.swing.JTable) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew)

Example 29 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class TestingFrameworkWindowManager method duplicateTestSuite.

/**
 * Insert the method's description here.
 * Creation date: (4/10/2003 11:27:32 AM)
 * @param testCase cbit.vcell.numericstestingframework.TestCase
 */
public String duplicateTestSuite(final TestSuiteInfoNew testSuiteInfo_Original, final TestSuiteInfoNew newTestSuiteInfo, int regrRefFlag, ClientTaskStatusSupport pp) throws DataAccessException {
    if (testSuiteInfo_Original == null || newTestSuiteInfo == null) {
        throw new IllegalArgumentException(this.getClass().getName() + "duplicateTestSuite_Private: TestSuite cannot be null");
    }
    checkNewTestSuiteInfo(newTestSuiteInfo);
    TestSuiteNew testSuite_Original = getRequestManager().getDocumentManager().getTestSuite(testSuiteInfo_Original.getTSKey());
    if (testSuite_Original == null) {
        throw new DataAccessException("Couldn't get TestSuite for tsInfo " + testSuiteInfo_Original.getTSID());
    }
    AddTestSuiteOP testSuiteOP = new AddTestSuiteOP(newTestSuiteInfo.getTSID(), newTestSuiteInfo.getTSVCellBuild(), newTestSuiteInfo.getTSNumericsBuild(), null, newTestSuiteInfo.getTSAnnotation());
    getRequestManager().getDocumentManager().doTestSuiteOP(testSuiteOP);
    TestSuiteInfoNew[] tsinArr = getRequestManager().getDocumentManager().getTestSuiteInfos();
    TestSuiteInfoNew tsin = null;
    for (int i = 0; i < tsinArr.length; i += 1) {
        if (tsinArr[i].getTSID().equals(newTestSuiteInfo.getTSID())) {
            tsin = tsinArr[i];
            break;
        }
    }
    if (tsin == null) {
        throw new DataAccessException("couldn't find new TestSuiteInfo " + newTestSuiteInfo.getTSID() + " in DB");
    }
    TestCaseNew[] originalTestCases = testSuite_Original.getTestCases();
    TestCaseNew[] newTestCases = null;
    if (originalTestCases != null && originalTestCases.length > 0) {
        newTestCases = new TestCaseNew[originalTestCases.length];
        for (int i = 0; i < originalTestCases.length; i += 1) {
            if (originalTestCases[i] instanceof TestCaseNewMathModel) {
                TestCaseNewMathModel tcnmm = (TestCaseNewMathModel) originalTestCases[i];
                TestCriteriaNew[] tcritnmm = (TestCriteriaNew[]) tcnmm.getTestCriterias();
                TestCriteriaNewMathModel[] newTCrits = null;
                if (tcritnmm != null && tcritnmm.length > 0) {
                    // Copy regression and errors
                    newTCrits = new TestCriteriaNewMathModel[tcritnmm.length];
                    for (int j = 0; j < tcritnmm.length; j += 1) {
                        newTCrits[j] = new TestCriteriaNewMathModel(null, tcritnmm[j].getSimInfo(), ((TestCriteriaNewMathModel) tcritnmm[j]).getRegressionMathModelInfo(), tcritnmm[j].getRegressionSimInfo(), tcritnmm[j].getMaxRelError(), tcritnmm[j].getMaxAbsError(), null, // new will have no data
                        TestCriteriaNew.TCRIT_STATUS_NODATA, // new will have no data
                        null);
                    }
                }
                // copy mathmodel,type and annotation and copied tcrits
                newTestCases[i] = new TestCaseNewMathModel(null, tcnmm.getMathModelInfo(), tcnmm.getType(), tcnmm.getAnnotation(), newTCrits);
            } else if (originalTestCases[i] instanceof TestCaseNewBioModel) {
                TestCaseNewBioModel tcnbm = (TestCaseNewBioModel) originalTestCases[i];
                TestCriteriaNew[] tcritnbm = (TestCriteriaNew[]) tcnbm.getTestCriterias();
                TestCriteriaNewBioModel[] newTCrits = null;
                if (tcritnbm != null && tcritnbm.length > 0) {
                    // Copy regression and errors
                    newTCrits = new TestCriteriaNewBioModel[tcritnbm.length];
                    for (int j = 0; j < tcritnbm.length; j += 1) {
                        newTCrits[j] = new TestCriteriaNewBioModel(null, tcritnbm[j].getSimInfo(), ((TestCriteriaNewBioModel) tcritnbm[j]).getRegressionBioModelInfo(), ((TestCriteriaNewBioModel) tcritnbm[j]).getRegressionApplicationName(), tcritnbm[j].getRegressionSimInfo(), tcritnbm[j].getMaxRelError(), tcritnbm[j].getMaxAbsError(), null, // new will have no data
                        TestCriteriaNew.TCRIT_STATUS_NODATA, // new will have no data
                        null);
                    }
                }
                // copy mathmodel,type and annotation and copied tcrits
                newTestCases[i] = new TestCaseNewBioModel(null, tcnbm.getBioModelInfo(), tcnbm.getSimContextName(), tcnbm.getSimContextKey(), tcnbm.getType(), tcnbm.getAnnotation(), newTCrits);
            } else {
                throw new RuntimeException("Unsupported TestCase type " + originalTestCases[i].getClass().getName());
            }
        }
    }
    // Add the new TestCases
    if (newTestCases != null && newTestCases.length > 0) {
        return addTestCases(tsin, newTestCases, regrRefFlag, pp);
    } else {
        return null;
    }
}
Also used : TestSuiteNew(cbit.vcell.numericstest.TestSuiteNew) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) TestCaseNew(cbit.vcell.numericstest.TestCaseNew) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) AddTestSuiteOP(cbit.vcell.numericstest.AddTestSuiteOP) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) TestCriteriaNew(cbit.vcell.numericstest.TestCriteriaNew) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew) DataAccessException(org.vcell.util.DataAccessException)

Example 30 with DataAccessException

use of org.vcell.util.DataAccessException in project vcell by virtualcell.

the class DBReactionWizardPanel method searchUserReactions.

/**
 * Insert the method's description here.
 * Creation date: (7/12/2003 2:45:44 PM)
 */
private void searchUserReactions(final ReactionQuerySpec reactionQuerySpec) {
    if (getDocumentManager() != null) {
        final DocumentManager docManager = getDocumentManager();
        final JList jlist = getReactionsJList();
        // 
        final String RXSTRING_VALUE_KEY = "rxString";
        // 
        AsynchClientTask searchReactions = new AsynchClientTask("searching reactions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                try {
                    mapRXStringtoRXIDs.clear();
                    // 
                    ReactionDescription[] dbrd = docManager.getUserReactionDescriptions(reactionQuerySpec);
                    // 
                    if (dbrd != null && !(getStructure() instanceof Membrane)) {
                        Vector<ReactionDescription> noflux = new Vector<ReactionDescription>();
                        for (int i = 0; i < dbrd.length; i += 1) {
                            if (!dbrd[i].isFluxReaction()) {
                                noflux.add(dbrd[i]);
                            }
                        }
                        if (noflux.size() > 0) {
                            dbrd = new ReactionDescription[noflux.size()];
                            noflux.copyInto(dbrd);
                        }
                    }
                    // 
                    String[] dbrdS = null;
                    if (dbrd != null) {
                        // if(mapRXStringtoRXIDs == null){mapRXStringtoRXIDs = new java.util.Hashtable();}
                        for (int i = 0; i < dbrd.length; i += 1) {
                            String rxString = dbrd[i].toString();
                            if (!mapRXStringtoRXIDs.containsKey(rxString)) {
                                mapRXStringtoRXIDs.put(rxString, new Vector<String>());
                            }
                            mapRXStringtoRXIDs.get(rxString).add(dbrd[i].getVCellRXID().toString());
                            mapRXIDtoBMIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellBioModelID());
                            mapRXIDtoStructRefIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellStructRef());
                        }
                        dbrdS = (String[]) mapRXStringtoRXIDs.keySet().toArray(new String[0]);
                    }
                    // 
                    if (dbrd != null && dbrd.length > 0) {
                        hash.put(RXSTRING_VALUE_KEY, dbrdS);
                    }
                } catch (DataAccessException e) {
                    PopupGenerator.showErrorDialog(DBReactionWizardPanel.this, e.getMessage());
                }
            }
        };
        // 
        AsynchClientTask updateRXList = new AsynchClientTask("updateRXList", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                String[] dbrdS = (String[]) hash.get(RXSTRING_VALUE_KEY);
                if (dbrdS != null) {
                    jlist.setListData(dbrdS);
                } else {
                    jlist.setListData(new String[0]);
                }
                afterSearchConfigure();
            }
        };
        // 
        Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
        ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXList }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) Membrane(cbit.vcell.model.Membrane) ReactionDescription(cbit.vcell.model.ReactionDescription) Vector(java.util.Vector) JList(javax.swing.JList) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

DataAccessException (org.vcell.util.DataAccessException)345 KeyValue (org.vcell.util.document.KeyValue)82 XmlParseException (cbit.vcell.xml.XmlParseException)80 ExpressionException (cbit.vcell.parser.ExpressionException)78 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)71 SQLException (java.sql.SQLException)67 IOException (java.io.IOException)60 MathException (cbit.vcell.math.MathException)59 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)46 BigString (org.vcell.util.BigString)45 User (org.vcell.util.document.User)42 FileNotFoundException (java.io.FileNotFoundException)38 ResultSet (java.sql.ResultSet)38 PropertyVetoException (java.beans.PropertyVetoException)37 File (java.io.File)34 PermissionException (org.vcell.util.PermissionException)34 Statement (java.sql.Statement)33 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)32 BioModelInfo (org.vcell.util.document.BioModelInfo)29 Vector (java.util.Vector)26