Skip to content

Commit

Permalink
added imap importer
Browse files Browse the repository at this point in the history
Issue #122
  • Loading branch information
rsoika committed Oct 6, 2020
1 parent ea41474 commit 83b4870
Show file tree
Hide file tree
Showing 9 changed files with 1,000 additions and 20 deletions.
9 changes: 9 additions & 0 deletions imixs-archive-importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ The CDI Bean DocumentImportController is used to display and select data sources



# FTP Importer

The FTP Importer Service can be used to import documents form a FTP server.


# Mail Importer

The Mail Importer Service is used to import documents form a IMAP server. This module provides also services to convert Java Mail Message objects into HTML or PDF.




3 changes: 2 additions & 1 deletion imixs-archive-importer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
<scope>compile</scope>
</dependency>


</dependencies>

<name>Imixs-Archive Importer</name>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Ralph Soika - Software Developer
*/

package org.imixs.archive.importer.adapter;
package org.imixs.archive.importer.ftp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -51,19 +51,20 @@
import org.imixs.workflow.exceptions.ModelException;
import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.ProcessingErrorException;
;

/**
* The FTPImportAdapter reacts on DocumentImportEvent and processes a FTP data
* The FTPImportService reacts on DocumentImportEvent and processes a FTP data
* source.
* <p>
* The implementation is based on org.apache.commons.net.ftp
*
* @author rsoika
*
*/
*/
@Stateless
public class FTPImportAdapter {
public class FTPImportService {

private static Logger logger = Logger.getLogger(FTPImportAdapter.class.getName());
private static Logger logger = Logger.getLogger(FTPImportService.class.getName());

@EJB
WorkflowService workflowService;
Expand All @@ -78,7 +79,7 @@ public class FTPImportAdapter {
* This method reacts on a CDI ImportEvent and reads documents form a ftp
* server.
*
*
*
*/
public void onEvent(@Observes DocumentImportEvent event) {

Expand Down Expand Up @@ -118,18 +119,18 @@ public void onEvent(@Observes DocumentImportEvent event) {
ftpPort = "21";
}

FTPClient ftpClient = null;
FTPClient ftpClient = null;
try {
logger.finest("......read directories ...");
documentImportService.logMessage("Connecting to FTP server: " + ftpServer,event);

documentImportService.logMessage("Connecting to FTP server: " + ftpServer, event);

// TLS
ftpClient = new FTPSClient("TLS", false);
ftpClient.setControlEncoding("UTF-8");
ftpClient.connect(ftpServer, Integer.parseInt(ftpPort));
if (ftpClient.login(ftpUser, ftpPassword) == false) {
documentImportService.logMessage("FTP file transfer failed: login failed!",event);
documentImportService.logMessage("FTP file transfer failed: login failed!", event);
event.setResult(DocumentImportEvent.PROCESSING_ERROR);
return;
}
Expand All @@ -152,8 +153,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
// if this is a directory or symlink then we do ignore this entry
if (!file.isFile()) {
documentImportService.logMessage(
"'" + file.getName() + "' os not a valid file, object will be ignored!",
event);
"'" + file.getName() + "' os not a valid file, object will be ignored!", event);
continue;
}
logger.info("import file " + file.getName() + "...");
Expand All @@ -166,7 +166,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
+ rawData.length);
// create new workitem
createWorkitem(event.getSource(), file.getName(), rawData);
documentImportService.logMessage("....imported '" + file.getName() + "'",event);
documentImportService.logMessage("....imported '" + file.getName() + "'", event);
count++;
} else {
documentImportService.logMessage(
Expand All @@ -177,7 +177,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
ftpClient.deleteFile(fullFileName);
} catch (AccessDeniedException | ProcessingErrorException | PluginException | ModelException e) {

documentImportService.logMessage("FTP import failed: " + e.getMessage(),event);
documentImportService.logMessage("FTP import failed: " + e.getMessage(), event);
event.setResult(DocumentImportEvent.PROCESSING_ERROR);
return;
}
Expand All @@ -192,7 +192,8 @@ public void onEvent(@Observes DocumentImportEvent event) {
int r = ftpClient.getReplyCode();
logger.severe("FTP ReplyCode=" + r);

documentImportService.logMessage("FTP file transfer failed (replyCode=" + r + ") : " + e.getMessage(),event);
documentImportService.logMessage("FTP file transfer failed (replyCode=" + r + ") : " + e.getMessage(),
event);
event.setResult(DocumentImportEvent.PROCESSING_ERROR);
return;

Expand All @@ -203,7 +204,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
ftpClient.logout();
ftpClient.disconnect();
} catch (IOException e) {
documentImportService.logMessage("FTP file transfer failed: " + e.getMessage(),event);
documentImportService.logMessage("FTP file transfer failed: " + e.getMessage(), event);
event.setResult(DocumentImportEvent.PROCESSING_ERROR);
return;
}
Expand Down Expand Up @@ -231,7 +232,6 @@ public ItemCollection createWorkitem(ItemCollection source, String fileName, byt
workitem.event(source.getItemValueInteger(DocumentImportService.SOURCE_ITEM_EVENT));
workitem.setWorkflowGroup(source.getItemValueString("workflowgroup"));


String contentType = MediaType.WILDCARD;
if (fileName.toLowerCase().endsWith(".pdf")) {
contentType = "Application/PDF";
Expand Down
Loading

0 comments on commit 83b4870

Please sign in to comment.