Strange error when upgrading from 4.8.9 to 5.12.

1
I get an Java error that I can not resolve. It gives the following error: Buildfile: C:\Users\Ronald\Mendix\Master Daywize-main\deployment\build_core.xml compile-legacy: [javac] Compiling 1108 source files to C:\Users\Ronald\Mendix\Master Daywize-main\deployment\run\bin [javac] C:\Users\Ronald\Mendix\Master Daywize-main\javasource\csvtoexcelconverter\actions\ConvertFiles.java:52: error: constructor UserAction in class UserAction<R> cannot be applied to given types; [javac] super(); [javac] ^ [javac] required: IContext [javac] found: no arguments [javac] reason: actual and formal argument lists differ in length [javac] where R is a type-variable: [javac] R extends Object declared in class UserAction Problem is that in Eclipse I do not have any error. And where it complains about is outside the user generated code and auto generated by Mendix. The complete Java code is below. It converts some csv files to Excel. Anybody a guess why I get the complaint from Mendix? Regards, Ronald // This file was generated by Mendix Business Modeler 4.0. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package csvtoexcelconverter.actions; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import org.apache.commons.io.comparator.NameFileComparator; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.mendix.core.Core; import com.mendix.core.CoreException; import com.mendix.systemwideinterfaces.core.UserAction; /** * Used to convert CSV files in a source directory to XLS files in the same directory. The source files are deleted if the conversion is a success. Returns 'TRUE' if the convert operation was a success. Returns 'FALSE' if there were any errors. The option 'mergeFiles' can be turned on so that all converted CSV files are combined into a single Excel workbook with 1 tab for each converted CSV file. If you turn this option on you will need to specify an output file name for the workbook. It is possible to specify which delimiter character you want to use (default is ';'). * * Parameters: * * sourcePath: The path to the files to be converted. * destinationPath: The path where converted files should be stored. * delimiterCharacter: The character that is used to delimit fields in the CSV file * mergeFiles: If set to TRUE the CSV files will be converted and merged into a single Excel file. Otherwise they will be converted into separate Excel files. If Excel files are detected in the source directory these will be merged into a single Excel workbook. * mergedWorkbookName: The name you want to give the Excel file that contains all of the converted CSV files. This field is only needed when mergeFiles is set to TRUE. * deleteSourceFiles: If set to TRUE source files will be deleted after successful conversion. */ public class ConvertFiles extends UserAction<Boolean> { private String sourcePath; private String delimiterCharacter; private Boolean mergeFiles; private String mergedWorkbookName; private String destinationPath; private Boolean deleteSourceFiles; public ConvertFiles(String sourcePath, String delimiterCharacter, Boolean mergeFiles, String mergedWorkbookName, String destinationPath, Boolean deleteSourceFiles) { super(); this.sourcePath = sourcePath; this.delimiterCharacter = delimiterCharacter; this.mergeFiles = mergeFiles; this.mergedWorkbookName = mergedWorkbookName; this.destinationPath = destinationPath; this.deleteSourceFiles = deleteSourceFiles; } @Override public Boolean executeAction() throws Exception { // BEGIN USER CODE // Check if source path exists. If it does proceed to convert files. // Note: If there are any sub-directories in the source path this code will fail. File myDir = new File(this.sourcePath); if( myDir.exists() && myDir.isDirectory()) { Core.getLogger("CSV to XLS Converter").info("Directory found: " + this.sourcePath); // Create a new output file and workbook for merge operations. Will only be used if mergeFile is 'TRUE' File mergedWorkbookFile = new File(destinationPath, mergedWorkbookName); HSSFWorkbook mergedWorkbook = new HSSFWorkbook(); // Get list of files in source directory and sort non-case-sensitive/alphabetically/ascending File[] files = myDir.listFiles(); Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); // Check if all source files have the same extension. If not give an error because we don't know what to do. // Based on the extension type decide what kind of action to do. Boolean foundCSVFile = false; Boolean foundExcelFile = false; Core.getLogger("CSV to XLS Converter").info("Detecting file types"); for(int i=0; i < files.length; i++) { File file = files[i]; if( !file.exists() ) throw new CoreException( "No file exists at location: " + sourcePath ); if( !file.canRead() ) throw new CoreException( "The file could not be read, the location is: " + file ); // Check file extension String sourceFileName = file.getName(); if (sourceFileName.indexOf(".csv") > 0) { foundCSVFile = true; } else if (sourceFileName.indexOf(".xls") > 0) { foundExcelFile = true; } else if (sourceFileName.indexOf(".xlsx") > 0) { throw new CoreException( "XLSX files are not supportted at this time: " + file ); } else { throw new CoreException( "File found with an unknown file extension: " + sourceFileName ); } } // Throw exception if there are mixed file extensions in the source directory if (foundCSVFile && foundExcelFile) { throw new CoreException( "Found both CSV files and Excel files in source directory."); } // Start conversion process Core.getLogger("CSV to XLS Converter").info("Starting conversion process"); for(int i=0; i < files.length; i++) { File file = files[i]; Core.getLogger("CSV to XLS Converter").info("Starting conversion for: " + file.getName()); // Convert operation for CSV files try { // Get source file name String sourceFileName = file.getName(); // If CSV files were detected convert them to XLS files. if (foundCSVFile) { // Create new file handler for destination Excel file and give it the name 'sourceName.xls' String destinationFileName = new String(sourceFileName.replaceAll("\\.csv", ".xls")); File destinationFile = new File(destinationPath, destinationFileName); // Convert CSV file to XLS file ConvertCSVToXLS(file, destinationFile, delimiterCharacter, mergedWorkbookFile, mergedWorkbook, mergeFiles); // Delete file only if archive operation is successfully completed and deleteSourceFiles is set to TRUE if (deleteSourceFiles) { try { file.delete(); } catch( SecurityException e ) { throw new CoreException( "Unable to delete source file due to security restriction: " + file, e ); } } } // If XLS/XLSX files were detected merge them to a single XLS file. if (foundExcelFile) { // Convert CSV file to XLS file MergeXLSFile(file, mergedWorkbook); // Delete file only if archive operation is successfully completed and deleteSourceFiles is set to true if (deleteSourceFiles) { try { file.delete(); } catch( SecurityException e ) { throw new CoreException( "Unable to delete source file due to security restriction: " + file, e ); } } } } catch( IOException e ) { throw new CoreException( "There was a problem converting the file: " + file, e ); } } if(files.length == 0) { Core.getLogger("CSV to XLS Converter").info("No files found"); return false; } // If mergeFiles is set to TRUE or this is an Excel merge action write the mergedWorkbook to a file if (mergeFiles && foundCSVFile || foundExcelFile) { try { FileOutputStream fileOut = new FileOutputStream(mergedWorkbookFile); mergedWorkbook.write(fileOut); fileOut.close(); Core.getLogger("CSV to XLS Converter").info(mergedWorkbookFile.getName() + " has been generated"); } catch( IOException e ) { throw new CoreException( "There was a problem writing the following merged workbook to a file: " + mergedWorkbookFile, e ); } } } else { Core.getLogger("CSV to XLS Converter").info("No directory found with path: " + this.sourcePath); return false; } return true; // END USER CODE } /** * Returns a string representation of this action */ @Override public String toString() { return "ConvertFiles"; } // BEGIN EXTRA CODE // CSV to XLS function public static String ConvertCSVToXLS(File sourceFile, File destinationFile, String delimiterCharacter, File mergedWorkbookFile, HSSFWorkbook mergedWorkbook, Boolean mergeFiles) throws IOException { ArrayList<ArrayList<String>> arList = new ArrayList<ArrayList<String>>(); ArrayList<String> al = null; String thisLine; BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFile),"ISO-8859-1")); //Need to force LATIN-1 character set for now to read western europe languages String workbookName = sourceFile.getName().replace(".csv", ""); // Get workbook name from CSV file name while ((thisLine = myInput.readLine()) != null) { al = new ArrayList<String>(); String strar[] = thisLine.split(delimiterCharacter); for (int j = 0; j < strar.length; j++) { // Get rid of EOL characters if they are hiding in the text String edit = strar[j].replace('\n', ' '); // Get rid of double quotes edit = strar[j].replace("\"", ""); al.add(edit); } arList.add(al); } try { // // Need to insert new sheet data directly into merged Excel sheet here as POI doesn't support sheet copying // // If mergeFiles is set to TRUE then add the CSV data directly to a new sheet. if (mergeFiles) { HSSFSheet sheet = mergedWorkbook.createSheet(workbookName); for (int k = 0; k < arList.size(); k++) { ArrayList<String> ardata = (ArrayList<String>) arList.get(k); HSSFRow row = sheet.createRow((short) 0 + k); for (int p = 0; p < ardata.size(); p++) { HSSFCell cell = row.createCell(p); cell.setCellValue(ardata.get(p).toString()); } } } // If mergeFiles is set to FALSE then write the data directly to a new XLS file. else { HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet(workbookName); for (int k = 0; k < arList.size(); k++) { ArrayList<String> ardata = (ArrayList<String>) arList.get(k); HSSFRow row = sheet.createRow((short) 0 + k); for (int p = 0; p < ardata.size(); p++) { //System.out.print(ardata.get(p)); HSSFCell cell = row.createCell(p); cell.setCellValue(ardata.get(p).toString()); } } FileOutputStream fileOut = new FileOutputStream(destinationFile); hwb.write(fileOut); fileOut.close(); Core.getLogger("CSV to XLS Converter").info(destinationFile.getName() + " has been generated"); } } catch (Exception ex) { Core.getLogger("CSV to XLS Converter").error("Error while converting file " + sourceFile.getName()); } // Close buffered reader otherwise I can't delete the source file later myInput.close(); return ""; } // Excel merge function // This function will copy the first worksheet in the given Excel file to the Excel workbook that is passed to the function public static void MergeXLSFile(File sourceFile, HSSFWorkbook mergedWorkbook) throws IOException { try { // Read source file in as new workbook and read in first sheet HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(sourceFile)); HSSFSheet sourceSheet = workbook.getSheetAt(0); HSSFRow sourceRow, newRow; HSSFCell sourceCell, newCell; // Add new sheet to merged workbook with same name as source sheet HSSFSheet newSheet = mergedWorkbook.createSheet(sourceSheet.getSheetName()); // Loop over each row and add to newly added worksheet for (int r = 0; r < sourceSheet.getPhysicalNumberOfRows(); r++) { newRow = newSheet.createRow(r); sourceRow = sourceSheet.getRow(r); // Loop over each cell and add to newly added row for (int c = 0; c < sourceRow.getLastCellNum(); c++) { newCell = newRow.createCell(c); sourceCell = sourceRow.getCell(c); newCell.setCellValue(sourceCell.toString()); } } } catch (IOException ex) { Core.getLogger("CSV to XLS Converter").error("Error while reading Excel input file " + sourceFile.getName()); } } // END EXTRA CODE }
asked
1 answers
1

This is mentioned in the migration guide (https://world.mendix.com/display/refguide5/Moving+from+4+to+5)

The parameterless constructor for UserAction has been removed. Constructing a UserAction always requires an IContext now. Changes are only necessary for custom user actions which are NOT defined as custom Java action in the Modeler, e.g. an action which replaces the LoginAction using an action listener.

I don't think your code is actually still being generated by the Modeler, perhaps you don't have this Java action in your model anymore but it's still on disk. In Mendix 5 it wouldn't inherit straight from UserAction anymore. Also it wouldn't say that the code is generated by Mendix 4.

answered