Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Issue #153
  • Loading branch information
rsoika committed Jan 24, 2024
1 parent 3afcfd4 commit 47145a8
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 415 deletions.
9 changes: 7 additions & 2 deletions imixs-adapters-datev/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.imixs.workflow</groupId>
Expand All @@ -14,11 +16,14 @@
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-core</artifactId>
</dependency>

<dependency>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-engine</artifactId>
</dependency>
<dependency>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-faces</artifactId>
</dependency>

<!-- Apache Commons FTP Client -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package org.imixs.workflow.datev.controller;

import java.io.ByteArrayInputStream;

/*******************************************************************************
* Imixs Workflow Technology
* Copyright (C) 2003, 2008 Imixs Software Solutions GmbH,
Expand All @@ -23,20 +26,32 @@
*
*******************************************************************************/

import java.io.Serializable;
import java.util.List;
import java.util.logging.Logger;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.datev.imports.DatevImportService;
import org.imixs.workflow.datev.imports.DatevService;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.engine.index.UpdateService;
import org.imixs.workflow.engine.scheduler.Scheduler;
import org.imixs.workflow.exceptions.AccessDeniedException;
import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.faces.fileupload.FileUploadController;

import org.imixs.workflow.datev.imports.DatevImportScheduler;
import org.imixs.workflow.engine.scheduler.SchedulerController;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.SessionScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

/**
* The DatevController is used to configure the DatevScheduler. This service is
* used to generate datev export workitems.
* <p>
* The Controller creates a configuration entity "type=configuration;
* txtname=datev".
* name=datev".
* <p>
* The following config items are defined:
*
Expand All @@ -52,30 +67,146 @@
*
*/
@Named
@RequestScoped
public class DatevController extends SchedulerController {
@SessionScoped
public class DatevController implements Serializable {

public static final String DATEV_CONFIGURATION = "DATEV_CONFIGURATION";

private ItemCollection importData;

private ItemCollection configuration = null;

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

@Override
@Inject
DocumentService documentService;

@Inject
UpdateService updateService;

@Inject
DatevService datevService;

@Inject
DatevImportService datevImportService;

@Inject
protected FileUploadController fileUploadController;

/**
* This method load the config entity after postContstruct. If no Entity exists
* than the ConfigService EJB creates a new config entity.
*
*/
@PostConstruct
public void init() {
configuration = loadConfiguration(getName());
}

public String getName() {
return DATEV_CONFIGURATION;
}

public ItemCollection getConfiguration() {
if (configuration == null) {
configuration = new ItemCollection();
configuration.setItemValue("$workflowsummary", getName());
configuration.setItemValue(Scheduler.ITEM_SCHEDULER_NAME, getName());
}
return configuration;
}

public void setConfiguration(ItemCollection configuration) {
this.configuration = configuration;
}

/**
* Returns the sepa scheduler class name. This name depends on the _export_type.
* Loads the scheduler configuration entity by name. The method returns null if
* no scheduler configuration exits.
*
* There are two export interfaces available - csv and XML
* @return
*/
public ItemCollection loadConfiguration(String name) {

configuration = datevService.loadConfiguration(name);

return configuration;
}

/**
* This method saves the DATEV configuration. The method ensures that the
* following properties are set to default.
* <ul>
* <li>type</li>
* <li>name</li>
* <li>$writeAccess</li>
* <li>$readAccess</li>
* </ul>
* The method also updates the timer details of a running timer.
*
* @return
* @throws AccessDeniedException
*/
@Override
public String getSchedulerClass() {
String schedulerClass = DatevImportScheduler.class.getName();
logger.finest("......datev scheduler: " + schedulerClass);
return schedulerClass;
public ItemCollection saveConfiguration() {

configuration = datevService.saveConfiguration(configuration);

return configuration;
}

/**
* Itemcollection containing file import data
*
* @return
*/
public ItemCollection getImportData() {
if (importData == null) {
importData = new ItemCollection();
}
return importData;
}

public void setImportData(ItemCollection importData) {
this.importData = importData;
}

/**
* This method imports a DATEV Kreditoren.csv attachment added to the
* ItemCollection 'importData'
* <p>
* It may be possible but not typically that a user uploads multiple files to
* import. The method can handle multiple file uploads.
* <p>
* For each file the method calls the DatevImportService to import the data
*
*/
public void startImport() throws PluginException {

List<FileData> fileList = importData.getFileData();
if (fileList == null) {
return;
}

for (FileData file : fileList) {
logger.info("Import: " + file.getName());

// test if supported CSV file?
if (file.getName().toLowerCase().endsWith(".csv")) {
ByteArrayInputStream input = new ByteArrayInputStream(file.getContent());
String result = datevImportService.importData(input, "ISO-8859-1");
getImportData().replaceItemValue("log", result);
} else {
throw new PluginException(this.getClass().getName(), DatevImportService.IMPORT_ERROR,
"File Format not supported: " + file.getName());
}

}
// Explicit flush the lucene search event log
updateService.updateIndex();

// clear import data
importData.removeItem("$file");

}
}

0 comments on commit 47145a8

Please sign in to comment.