Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncaught Exception related to CompoundTableSaver #19

Open
zpeng2003bht opened this issue Sep 19, 2023 · 5 comments
Open

uncaught Exception related to CompoundTableSaver #19

zpeng2003bht opened this issue Sep 19, 2023 · 5 comments

Comments

@zpeng2003bht
Copy link

Dear Thomas:

I am using the following function "writeTable" in our "PLPConnectorTask.java" plugin code, leveraging the DW's "CompoundTableSaver" class, to export the molecules inside the active DW DEFrame into a SDF file:

private void writeTable(String fileName) {
	SwingUtilities.invokeLater(() -> {
		try {
			DEFrame currentDEFrame = sDataExplorer.getActiveFrame();
			DECompoundTableModel currentTableModel = currentDEFrame.getTableModel();
			JTable currentTable = currentDEFrame.getMainFrame().getMainPane().getTable();
			CompoundTableSaver dataSaver = new CompoundTableSaver(currentDEFrame, currentTableModel, currentTable);
			dataSaver.saveSDFile(new File(fileName), FileHelper.cFileTypeSDV2, 0, 2, 1, null);
			// assuming the 0st column contains the idcode encoded structure
			// assuming the 1st column contain the 2D coordinate
			// assuming the 2st column is the idColumn column
			// coordsColumn if -1, then 2D-coords are generated on the fly

		} catch (Exception e) {
			e.printStackTrace();
		}
	});
}

It works well when I test the plugin inside a Java IDE (Eclipse) along with DW source code and its dependencies.

However when we packaged this "PLPConnectorTask.java" plugin as a JAR and placed it within the "plugin" folder of the standalone DataWarrior, this function call leads to the following error message seen in the dialog:
DW_UncaughtExceptio

Since the error message displayed in the dialog is too short, and I could not reproduce this error inside the Eclipse IDE to see the full stack trace of this exception, I wonder if you could provide some tips and suggestions.

best,
Zhengwei

@thsa
Copy link
Owner

thsa commented Sep 22, 2023 via email

@GoldenStone929
Copy link

Dear Mr.Thomas,

I have developed a plugin in Java which operates flawlessly when run from the IDE. I've managed to successfully compile, run, and package the project along with all external libraries in Maven. The expected behavior is to place the resultant jar into the software's plugin folder, and it should function as intended. Indeed, it does work as expected, apart from one critical issue: any operation involving write functionality fails, triggering an error, and it throws different exceptions for different write action. include my “log in” page where it does not really call any method from DataWarrior or its external library.

The peculiar aspect is that the exact same code operates without a hitch when executed from the IDE, but exhibits this problem once packed into a jar. I've attempted to resolve this issue through two different coding approaches, both of which work perfectly in the IDE, but fail when executed from the jar.

Steps already taken to troubleshoot include:

Granted full access permissions to the relevant folder, DataWarrior, and I/O directory.
Relocated the software from Program Files (x86) to Program Files.
Moved the I/O folder to multiple different locations in an attempt to resolve the pathing issue.
Observations:

The output folder seems to be accessed without any problems, but attempts to access the input folder (e.g., adding a column to the current table) fail consistently.
I am seeking guidance or suggestions that might help in resolving this write operation issue in the packaged jar environment. Any assistance would be greatly appreciated.

Thank you,
Shawn Cui

@GoldenStone929
Copy link

Dear Mr.Thomas,

I have developed a plugin in Java which operates flawlessly when run from the IDE. I've managed to successfully compile, run, and package the project along with all external libraries in Maven. The expected behavior is to place the resultant jar into the software's plugin folder, and it should function as intended. Indeed, it does work as expected, apart from one critical issue: any operation involving write functionality fails, triggering an error, and it throws different exceptions for different write action. include my “log in” page where it does not really call any method from DataWarrior or its external library.

The peculiar aspect is that the exact same code operates without a hitch when executed from the IDE, but exhibits this problem once packed into a jar. I've attempted to resolve this issue through two different coding approaches, both of which work perfectly in the IDE, but fail when executed from the jar.

Steps already taken to troubleshoot include:

Granted full access permissions to the relevant folder, DataWarrior, and I/O directory. Relocated the software from Program Files (x86) to Program Files. Moved the I/O folder to multiple different locations in an attempt to resolve the pathing issue. Observations:

The output folder seems to be accessed without any problems, but attempts to access the input folder (e.g., adding a column to the current table) fail consistently. I am seeking guidance or suggestions that might help in resolving this write operation issue in the packaged jar environment. Any assistance would be greatly appreciated.

Thank you, Shawn Cui

HI Mr.Thomas,
I have specified the issue in a more detailed note,
it is live on:
https://blush-cabin-70a.notion.site/DW-Write-into-Folder-issue-de6d895db01c4634b0f29ef83cc359f0?pvs=4

@GoldenStone929
Copy link

GoldenStone929 commented Oct 18, 2023

I have check file permissions:
for:
@OverRide public void run(Properties configuration, IPluginHelper dwInterface) {

    // Correct the path for localInputFolder
    final String localInputFolder = "C:\\Users\\shawn.cui\\DATA_IO\\Input\\";

    // Check if the directory is writable
    File directory = new File(localInputFolder);
    System.out.println("----------------------------------Can write: " + directory.canWrite() + "----------------------------------");

    // Print the absolute path to ensure it's being resolved correctly
    System.out.println("Absolute path: " + directory.getAbsolutePath());

    // Export the current set of molecule inside DW into a SDF file
    String pValue = localInputFolder.concat("input.sdf");
    System.out.println("----------------------------------Full path to output file: " + pValue + "----------------------------------");  // Print the full path of the file you are attempting to write to

    writeTableViaMacro(dwInterface, pValue);  // use macro instead of DW internal per Thomas. 09/22/2023

}

Console:

"----------------------------------Can write: true----------------------------------
Absolute path: C:\Users\shawn.cui\DATA_IO\Input
----------------------------------Full path to output file: C:\Users\shawn.cui\DATA_IO\Input\input.sdf----------------------------------

but package jar wouldn't be able to write.

The error message I am getting is:
org.openmolecules.datawarrior.plugin.IPluginHelper.runMacro(Ljava/lang/String;)V

I have checked source code of IPluginHelper, it is clear that there is indeed a runMacro method defined in the interface: void runMacro(String var1);

@zpeng2003bht
Copy link
Author

Dear Thomas:

Shawn and I have created the following plugin called "SaveSDFPluginTask" which works nicely within the IDE but leads to the same "uncaught Exception" when it is deployed into the "plugin" folder of a standalone DW.

We hope that you can use this "SaveSDFPluginTask" code to

  1. reproduce the same "uncaught Exception" issue on your machine;
  2. identify and fix this issue in DW;
  3. release a new version of DW with the issue already fixed for download (say, from https://openmolecules.org/datawarrior/download.html).

Your help is the only path forward for us to deploy our "PLPConnectorTask" plugin to our internal DW users. Many thanks again.

Best,
Zhengwei

/* The purpose of this class is to demonstrate the "Uncaught Exception:" we have obtained when deploying the

  • PLPConnectorTask Plugin inside the "plugin" folder of a stand-alone DataWarrior installed on a
  • Windows machine.
  • This class will be shared with Thomas for possible in-depth debugging.
    */

import org.openmolecules.datawarrior.plugin.IPluginHelper;
import org.openmolecules.datawarrior.plugin.IPluginTask;
import org.openmolecules.datawarrior.plugin.IUserInterfaceHelper;

import javax.swing.*;
import java.util.Properties;

public class SaveSDFPluginTask implements IPluginTask {
private final String CONFIGURATION_SELECTED = "selected";

private final String[] OPTIONS = { "viaMacro" };


public JComboBox<String> mComboBox;

static final String localInputFolder = "C:/Users/" + System.getProperty("user.name") + "/DW_PLP_Temp_Folder/Input/";

// static final String localInputFolder = "C:/Users/zpeng/DW_PLP_Temp_Folder/Input/";

public SaveSDFPluginTask() {
    System.out.println("localInputFolder: " + localInputFolder);
    //localInputFolder: C:/Users/shawn.cui/DW_PLP_Temp_Folder/Input/
}


@Override public String getTaskCode() {
    return "SaveSDFbugreport";
}

@Override public String getTaskName() {
    return "SaveSDFbugreport";
}

/**
 * This method expects a JPanel with all UI-elements for defining a database query.
 * These may include elements to define a structure search and/or alphanumerical
 * search criteria. 'Cancel' and 'OK' buttons are provided outside of this panel.
 * @param dialogHelper gives access to a chemistry panel to let the user draw a chemical (sub-)structure
 * @return
 */
@Override public JComponent createDialogContent(IUserInterfaceHelper dialogHelper) {
    mComboBox = new JComboBox<String>(OPTIONS);
    mComboBox.setSelectedIndex(0);

    JPanel panel = new JPanel();
    panel.add(new JLabel("Select one:"));
    panel.add(mComboBox);

    return panel;
}

/**
 * This method is called after the users presses the dialog's 'OK' button.
 * At this time the dialog is still shown. This method expects a Properties
 * object containing all UI-elements' states converted into key-value pairs
 * describing the user defined database query. This query configuration is
 * used later for two purposes:<br>
 * - to run the query independent from the actual dialog<br>
 * - to populate a dialog with a query that has been performed earlier<br>
 * @return query configuration
 */
@Override public Properties getDialogConfiguration() {
    Properties configuration = new Properties();
    configuration.setProperty(CONFIGURATION_SELECTED, (String)mComboBox.getSelectedItem());
    return configuration;
}

/**
 * This method populates an empty database query dialog with a previously configured database query.
 * @param configuration
 */
@Override public void setDialogConfiguration(Properties configuration) {
    String selected = configuration.getProperty(CONFIGURATION_SELECTED, OPTIONS[0]);
    mComboBox.setSelectedItem(selected);
}

/**
 * Checks, whether the given database query configuration is a valid one.
 * If not, the this method should return a short and clear error message
 * intended for the user in order to correct the dialog setting.
 * @param configuration
 * @return user-interpretable error message or null, if query configuration is valid
 */
@Override public String checkConfiguration(Properties configuration) {
    return null;    // no need to check, any configuration will be acceptable
}


@Override public void run(Properties configuration, IPluginHelper dwInterface) {

    // Export the current set of molecule inside DW into a SDF file
    String pValue = localInputFolder.concat("input.sdf");
    writeTableViaMacro(dwInterface, pValue);  // use macro instead of DW internal per Thomas. 09/22/2023

}



private void writeTableViaMacro(IPluginHelper dwInterface, String fileName) {
    String macroString = "<macro name=\"zpSaveSDF\">\r\n"
            + "<task name=\"saveSDFile\">\r\n"
            + "version=v3\r\n"
            + "idColumn=Structure No\r\n"
            + "structureColumn=Structure\r\n"
            + "coordinates=2D\r\n";
    macroString = macroString.concat("fileName=");
    macroString = macroString.concat(fileName);
    macroString = macroString.concat("\r\n</task>\r\n"
            + "</macro>");

    System.out.println(macroString);
    dwInterface.runMacro(macroString);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants