Author: dcosse Date: 2014-08-14 16:00:32 +0200 (Thu, 14 Aug 2014) New Revision: 3910 Url: http://forge.chorem.org/projects/lima/repository/revisions/3910 Log: fix sonar warning Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-08 23:31:21 UTC (rev 3909) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-14 14:00:32 UTC (rev 3910) @@ -161,9 +161,6 @@ String[] columnHeaderTable = {boldBegin+t("lima-business.document.label")+boldEnd, boldBegin+t("lima-business.document.grossamount")+boldEnd, boldBegin+t("lima-business.document.provisiondeprecationamount")+boldEnd, boldBegin+t("lima-business.document.netamount")+boldEnd}; financialReport += constructTableLine(columnHeaderTable); - } else if (printedType == 1) { - String[] columnHeaderTable = {boldBegin+t("lima-business.document.label")+boldEnd, boldBegin+t("lima-business.document.amount")+boldEnd}; - financialReport += constructTableLine(columnHeaderTable); } else { String[] columnHeaderTable = {boldBegin+t("lima-business.document.label")+boldEnd, boldBegin+t("lima-business.document.amount")+boldEnd}; financialReport += constructTableLine(columnHeaderTable); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-08 23:31:21 UTC (rev 3909) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-14 14:00:32 UTC (rev 3910) @@ -45,7 +45,7 @@ */ public abstract class AbstractLimaModel<E> extends AbstractImportModel<E> { - protected static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + protected static String DATE_FORMAT = "dd/MM/yyyy"; public AbstractLimaModel(char separator) { super(separator); @@ -96,37 +96,6 @@ }; /** - * String to double converter (null allowed). - * Can handle , or . as decimal separator and ' ' as thousand separator - */ - protected static final ValueParser<Double> DOUBLE_WITH_NULL_PARSER = new ValueParser<Double>() { - @Override - public Double parse(String value) throws ParseException { - Double result = null; - if (!value.isEmpty()) { - // " " est un espace insécable, pas un " " - result = Double.valueOf(value.replace(',','.').replace(" ", "")); - } - return result; - } - }; - - /** - * Zero to empty string converter. - */ - protected static final ValueParser<String> ZERO_TO_EMPTY_PARSER = new ValueParser<String>() { - @Override - public String parse(String value) throws ParseException { - String result = value.trim(); - result = result.replaceAll("\\s{2,}", " "); // replace multiple spaces - if (result.equals("0")) { - result = ""; - } - return result; - } - }; - - /** * O/N boolean parser. */ protected static final ValueParser<Boolean> O_N_PARSER = new ValueParser<Boolean>() { @@ -150,38 +119,13 @@ } }; - protected static final ValueFormatter<Integer> INTEGER_FORMATTER = new ValueFormatter<Integer>() { - @Override - public String format(Integer value) { - String result; - if (value != null) { - result = String.valueOf(value); - } else { - result = ""; - } - return result; - } - }; - - protected static final ValueFormatter<Double> DOUBLE_FORMATTER = new ValueFormatter<Double>() { - @Override - public String format(Double value) { - String result; - if (value != null) { - result = String.valueOf(value); - } else { - result = ""; - } - return result; - } - }; - protected static final ValueFormatter<Date> DATE_FORMATTER = new ValueFormatter<Date>() { @Override public String format(Date value) { String result; if (value != null) { - result = AbstractLimaModel.simpleDateFormat.format(value); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + result = simpleDateFormat.format(value); } else { result = ""; } @@ -197,7 +141,8 @@ public Date parse(String value) throws ParseException { Date result = null; if (!Strings.isNullOrEmpty(value)) { - result = AbstractLimaModel.simpleDateFormat.parse(value); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + result = simpleDateFormat.parse(value); } return result; } @@ -266,14 +211,18 @@ FinancialStatementWayEnum result = null; if (StringUtils.isNotBlank(value)) { value = StringUtils.trim(value.toUpperCase()); - if (value.equals("BOTH")) { - result = FinancialStatementWayEnum.BOTH; - } else if (value.equals("DEBIT")) { - result = FinancialStatementWayEnum.DEBIT; - } else if (value.equals("CREDIT")) { - result = FinancialStatementWayEnum.CREDIT; - } else { - throw new UnsupportedOperationException("Unsupported statement way" + value); + switch (value) { + case "BOTH": + result = FinancialStatementWayEnum.BOTH; + break; + case "DEBIT": + result = FinancialStatementWayEnum.DEBIT; + break; + case "CREDIT": + result = FinancialStatementWayEnum.CREDIT; + break; + default: + throw new UnsupportedOperationException("Unsupported statement way" + value); } } return result; @@ -326,7 +275,8 @@ public String format(FinancialTransaction value) { String result; if (value != null) { - result = AbstractLimaModel.simpleDateFormat.format(value.getTransactionDate()); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); + result = simpleDateFormat.format(value.getTransactionDate()); } else { result = ""; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2014-08-08 23:31:21 UTC (rev 3909) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2014-08-14 14:00:32 UTC (rev 3910) @@ -109,7 +109,7 @@ } else if( (String.valueOf(e.getKeyChar()).matches(",") || String.valueOf(e.getKeyChar()).matches("\\.")) && comma.equals("")) { comma = ","; - } else if(!getComponent().getText().matches(",") || !getComponent().getText().matches(".") && + } else if(!getComponent().getText().matches(",") || !getComponent().getText().matches("\\.") && (!String.valueOf(e.getKeyChar()).matches(",") || !String.valueOf(e.getKeyChar()).matches("\\."))) { comma = ""; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java 2014-08-08 23:31:21 UTC (rev 3909) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java 2014-08-14 14:00:32 UTC (rev 3910) @@ -82,7 +82,7 @@ LimaConfig.Option backgroundOption; LimaConfig.Option foreGroundOption; - if (line % 2 == 1) { + if ((line & 1) == 1 || line % 2 == 1) { if (isSelected) { if (errorDetector.isError(table, value, row, column)) { backgroundOption = LimaConfig.Option.TABLE_CELL_PAIR_SELECTED_ERROR_BACKGROUND; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-08 23:31:21 UTC (rev 3909) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-14 14:00:32 UTC (rev 3910) @@ -134,26 +134,24 @@ /** * Call the appropriate method in business service. * - * @param importExportMethode - * @param path - * @param verbose + * @param importExportChoice determine what to import/export and export type (CSV, EBP, PDF) + * @param path file path for import/export file, if null a dialog will ask for it + * @param verbose if true a dialog show result */ - public void importExport(ImportExportEnum importExportMethode, String path, boolean verbose) { - final ImportExportEnum importExportMethodeF = importExportMethode; + public void importExport(final ImportExportEnum importExportChoice, String path, boolean verbose) { final Charset defaultCharset = Charsets.UTF_8; String filePath = path; if (Strings.isNullOrEmpty(filePath)) { - filePath = chooseFile(importExportMethode.getImportMode(), importExportMethode); + filePath = chooseFile(importExportChoice.getImportMode(), importExportChoice); } - processImport(importExportMethode, verbose, importExportMethodeF, defaultCharset, filePath); + processImport(verbose, importExportChoice, defaultCharset, filePath); } - protected void processImport(ImportExportEnum importExportMethode, boolean verbose, final ImportExportEnum importExportMethod, final Charset defaultCharset, final String filePath) { + protected void processImport(final boolean verboseMode, final ImportExportEnum importExportMethod, final Charset defaultCharset, final String filePath) { //if export cancel if (!Strings.isNullOrEmpty(filePath)) { - final Boolean verboseMode = verbose; - final Boolean importMode = importExportMethode.getImportMode(); + final Boolean importMode = importExportMethod.getImportMode(); new SwingWorker<ImportExportResults, Void>() { @@ -292,7 +290,7 @@ } } - private void ComputeExportResultMessage(List<ExportResult> exportResults) { + protected void ComputeExportResultMessage(List<ExportResult> exportResults) { StringBuilder message = new StringBuilder(); for (ExportResult result : exportResults) { Class fromSource = result.getFromSource(); @@ -309,7 +307,7 @@ DisplayImportExportResultMessage(message, false); } - private void ComputeImportResultMessage(List<ImportResult> resultList) { + protected void ComputeImportResultMessage(List<ImportResult> resultList) { StringBuilder message = new StringBuilder(); message.append(t("lima.ui.importexport.import.terminated")); StringBuilder errorMessage = null; @@ -336,7 +334,7 @@ } } - private void DisplayImportExportResultMessage(StringBuilder message, Boolean importMode) { + protected void DisplayImportExportResultMessage(StringBuilder message, Boolean importMode) { if (log.isDebugEnabled()){ log.debug(message.toString()); } @@ -349,7 +347,7 @@ JOptionPane.INFORMATION_MESSAGE); } - private StringBuilder displayErrorMessage(Map<Integer, LimaException> exceptionsByLine) { + protected StringBuilder displayErrorMessage(Map<Integer, LimaException> exceptionsByLine) { StringBuilder result = new StringBuilder(); if (exceptionsByLine != null) { for (Map.Entry<Integer, LimaException> e:exceptionsByLine.entrySet()) { @@ -406,7 +404,7 @@ * @param fromSource The imported target class * @return the name of the imported/exported entities class. */ - private String getFromSourceMessage(Class fromSource) { + protected String getFromSourceMessage(Class fromSource) { String message; if (fromSource == null) { message = "BACKUP"+"\n";