Skip to content

Commit

Permalink
refactoring (Issue #171)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Feb 12, 2025
1 parent fc4b4ac commit 1d05815
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 120 deletions.
12 changes: 7 additions & 5 deletions imixs-adapters-datev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ Für das Einfügen eines Beleges in den DATEV Belegsapel müssen im Workitem fol
| datev.gegenkonto | Gegenkonto |
| datev.buschluessel | Buschluessel |

Auf diese weise können unterschiedliche Prozessdaten in einen Belegstapel zusammgefasst werden. Um ein Mapping eines workflow Items auf ein DATEV item zu erhalten kann dieses im BPMN Result event angelegt werden. Beisiel:
Auf diese weise können unterschiedliche Prozessdaten in einen Belegstapel zusammengefasst werden. Um ein Mapping eines workflow Items auf ein DATEV item zu erhalten kann dieses im BPMN Result event angelegt werden.

Beispiel:

```xml
<item name="datev.betrag"><itemvalue>invoice.total</itemvalue></item>
<item name="datev.belegfeld1"><itemvalue>invoice.number</itemvalue></item>
<item name="datev.gegenkonto"><itemvalue>cdtr.number</itemvalue></item>
...
<item name="datev.betrag" type="double"><itemvalue>invoice.total</itemvalue></item>
<item name="datev.belegdatum" type="date"><itemvalue>invoice.date</itemvalue></item>
<item name="datev.belegfeld1"><itemvalue>invoice.number</itemvalue></item>
<item name="datev.gegenkonto"><itemvalue>cdtr.number</itemvalue></item>
```

Der DATEV Export Workflow kann vollständig über das DATEV Export Modell gesteuert werden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import org.imixs.workflow.exceptions.PluginException;

public class DatevException extends PluginException {

public class DatevException extends PluginException{
public static final String DATEV_EXPORT_ERROR = "DATEV_EXPORT_ERROR";
public static final String DATEV_IMPORT_ERROR = "DATEV_IMPORT_ERROR";
public static final String DATEV_CONFIG_ERROR = "DATEV_CONFIG_ERROR";
public static final String DATEV_REPORT_ERROR = "DATEV_REPORT_ERROR";
public static final String DATEV_MODEL_ERROR = "DATEV_MODEL_ERROR";
public static final String DATEV_DATA_ERROR = "DATEV_DATA_ERROR";


private static final long serialVersionUID = 1L;

public DatevException(String aErrorContext, String aErrorCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
@ConversationScoped
public class DatevBookingController implements Serializable {

public static final String ITEM_DATEV_BOOKING_LIST = "datev.booking.list";

private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(DatevBookingController.class.getName());

Expand Down Expand Up @@ -126,17 +124,17 @@ public void onWorkflowEvent(@Observes WorkflowEvent workflowEvent) throws Access
// reset orderItems if workItem has changed
if (WorkflowEvent.WORKITEM_CHANGED == eventType || WorkflowEvent.WORKITEM_CREATED == eventType) {
// reset state
bookingList = explodeChildList(workitem, ITEM_DATEV_BOOKING_LIST);
bookingList = explodeChildList(workitem, DatevService.ITEM_DATEV_BOOKING_LIST);
}

// before the workitem is saved we update the field txtOrderItems
if (WorkflowEvent.WORKITEM_BEFORE_PROCESS == eventType) {
implodeChildList(workitem, bookingList, ITEM_DATEV_BOOKING_LIST);
implodeChildList(workitem, bookingList, DatevService.ITEM_DATEV_BOOKING_LIST);
}

if (WorkflowEvent.WORKITEM_AFTER_PROCESS == eventType) {
// reset state
bookingList = explodeChildList(workitem, ITEM_DATEV_BOOKING_LIST);
bookingList = explodeChildList(workitem, DatevService.ITEM_DATEV_BOOKING_LIST);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.datev.DatevException;
import org.imixs.workflow.datev.imports.DatevImportService;
import org.imixs.workflow.datev.imports.DatevService;
import org.imixs.workflow.engine.DocumentService;
Expand Down Expand Up @@ -406,7 +407,7 @@ public void startImport() throws PluginException {
String result = datevImportService.importData(input, "ISO-8859-1");
getImportData().replaceItemValue("log", result);
} else {
throw new PluginException(this.getClass().getName(), DatevImportService.IMPORT_ERROR,
throw new PluginException(this.getClass().getName(), DatevException.DATEV_IMPORT_ERROR,
"File Format not supported: " + file.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.ItemCollectionComparator;
import org.imixs.workflow.SignalAdapter;
import org.imixs.workflow.datev.DatevException;
import org.imixs.workflow.datev.imports.DatevService;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.engine.WorkflowService;
Expand Down Expand Up @@ -138,8 +139,6 @@
*/
public class DatevExportAdapter implements SignalAdapter {

public static final String DATEV_EXPORT_ERROR = "DATEV_EXPORT_ERROR";

public static final int EVENT_INVOICE_COMPLETED = 200;

private static Logger logger = Logger.getLogger(DatevExportAdapter.class.getName());
Expand Down Expand Up @@ -208,7 +207,8 @@ public ItemCollection execute(ItemCollection datevExport, ItemCollection event)
processDatevExportEntities(datevExport, masterDataSet, event, configuration);

} catch (AccessDeniedException | ProcessingErrorException | ModelException e) {
throw new PluginException(DatevExportAdapter.class.getName(), DATEV_EXPORT_ERROR, e.getMessage(), e);
throw new PluginException(DatevExportAdapter.class.getName(), DatevException.DATEV_EXPORT_ERROR,
e.getMessage(), e);
}

return datevExport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.WorkflowKernel;
import org.imixs.workflow.datev.DatevException;
import org.imixs.workflow.datev.DatevHelper;
import org.imixs.workflow.datev.imports.DatevService;
import org.imixs.workflow.engine.DocumentService;
Expand Down Expand Up @@ -102,11 +103,6 @@ public class DatevExportService {
public static final String ITEM_FTP_PATH_UPLOAD = "_datev.ftp.path.upload";
public static final String ITEM_FTP_ERROR = "_ftp_error";

public static final String CHILD_ITEM_PROPERTY = "_ChildItems";

public static final String REPORT_ERROR = "REPORT_ERROR";
public static final String MODEL_ERROR = "MODEL_ERROR";

@Inject
WorkflowService workflowService;

Expand Down Expand Up @@ -203,7 +199,7 @@ public void buildDocumentsZipFile(ItemCollection datevExport, List<ItemCollectio
String reportNameDocuments = configuration.getItemValueString("report.documents");
ItemCollection documentsReport = reportService.findReport(reportNameDocuments);
if (documentsReport == null) {
throw new PluginException(this.getClass().getClass().getName(), REPORT_ERROR,
throw new PluginException(this.getClass().getClass().getName(), DatevException.DATEV_REPORT_ERROR,
"unable to load documents report definition '" + reportNameDocuments
+ "'. Please check the configuration");
}
Expand All @@ -215,7 +211,7 @@ public void buildDocumentsZipFile(ItemCollection datevExport, List<ItemCollectio

String xslDocuments = documentsReport.getItemValueString("XSL").trim();
if (xslDocuments.isEmpty()) {
throw new PluginException(this.getClass().getClass().getName(), REPORT_ERROR,
throw new PluginException(this.getClass().getClass().getName(), DatevException.DATEV_REPORT_ERROR,
"Failed to build DATEV zip archive '"
+ documentsReport.getItemValueString("txtname") + " XSL content is missing.");
}
Expand Down Expand Up @@ -300,7 +296,7 @@ public void buildDocumentsZipFile(ItemCollection datevExport, List<ItemCollectio
datevZip.write(byteData);
datevZip.closeEntry();
} catch (IOException | TransformerException | JAXBException e) {
throw new PluginException(DatevExportService.class.getName(), REPORT_ERROR,
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_REPORT_ERROR,
"Failed to build DATEV zip archive '"
+ documentsReport.getItemValueString("txtname") + "' : " + e.getMessage(),
e);
Expand All @@ -316,7 +312,7 @@ public void buildDocumentsZipFile(ItemCollection datevExport, List<ItemCollectio
datevExport.addFileData(zipFileData);

} catch (IOException e) {
throw new PluginException(DatevExportService.class.getName(), REPORT_ERROR,
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_REPORT_ERROR,
"Failed to create Documents archive '" + documentsReport.getItemValueString("txtname") + "' : "
+ e.getClass().getName() + " -> " + e.getMessage(),
e);
Expand All @@ -330,7 +326,7 @@ public void buildDocumentsZipFile(ItemCollection datevExport, List<ItemCollectio
zipOutputStream.close();
}
} catch (IOException e) {
throw new PluginException(DatevExportService.class.getName(), REPORT_ERROR,
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_REPORT_ERROR,
"Failed to close DATEV archive '"
+ documentsReport.getItemValueString("txtname") + "' : " + e.getMessage(),
e);
Expand Down Expand Up @@ -366,7 +362,7 @@ public void buildCSVFile(ItemCollection datevExport, List<ItemCollection> data,
ItemCollection invoiceReport = null;
invoiceReport = reportService.findReport(reportNameInvoices);
if (invoiceReport == null) {
throw new PluginException(DatevExportService.class.getName(), REPORT_ERROR,
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_REPORT_ERROR,
"unable to load invoice report definition '"
+ reportNameInvoices + "'. Please check the configuration");
}
Expand Down Expand Up @@ -418,8 +414,10 @@ public void buildCSVFile(ItemCollection datevExport, List<ItemCollection> data,
// xsl transformation based on our tmp_data collection....
filedata = reportService.transformDataSource(invoiceReport, tmp_data, datevFileName);
} catch (JAXBException | TransformerException | IOException e) {
throw new PluginException(DatevExportService.class.getName(), REPORT_ERROR, "Failed to execute CSV report '"
+ invoiceReport.getItemValueString("txtname") + "' : " + e.getMessage(), e);
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_REPORT_ERROR,
"Failed to execute CSV report '"
+ invoiceReport.getItemValueString("txtname") + "' : " + e.getMessage(),
e);
}

// attach the file
Expand Down Expand Up @@ -620,25 +618,6 @@ public ItemCollection buildExportWorkitem(ItemCollection configuration, String m
return datevExport;
}

/**
* Helper Method to copute the grouping key
*
* (MandantID+Buchungsperiode)
*
* @return
*/
public String computeKey(ItemCollection invoice, String datevClientID) {

Date datInvoice = invoice.getItemValueDate("invoice.date");

// Berechnung der Buchungsperiode
DateFormat df = new SimpleDateFormat("yyyyMM");
String keyPeriode = df.format(datInvoice);
String key = keyPeriode + "_" + datevClientID;

return key;
}

/**
* Prüft alle offenen Datev Exporte und gibt den neuesten zur angegebenen Datev
* Client ID zurück, oder null falls es keinen Offenen Datev Export gibt.
Expand Down Expand Up @@ -728,7 +707,7 @@ public FileData getWorkItemFileFromWorkitem(ItemCollection invoice) throws Plugi
}

} else {
throw new PluginException(DatevExportService.class.getName(), MODEL_ERROR,
throw new PluginException(DatevExportService.class.getName(), DatevException.DATEV_MODEL_ERROR,
"Invoice Document not defined");
}

Expand Down
Loading

0 comments on commit 1d05815

Please sign in to comment.