Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Issue #177
  • Loading branch information
rsoika committed Jun 11, 2023
1 parent 5e33503 commit 3892eac
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 262 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package org.imixs.archive.export;

import java.io.ByteArrayOutputStream;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.xml.XMLDocument;
import org.imixs.workflow.xml.XMLDocumentAdapter;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;

/**
* The rest service API endpoint
*/
@ApplicationPath("/api")
public class ExportApi extends Application {
// rest service endpoint

public static final String WORKFLOW_SERVICE_ENDPOINT = "workflow.service.endpoint";
public static final String WORKFLOW_SERVICE_USER = "workflow.service.user";
public static final String WORKFLOW_SERVICE_PASSWORD = "workflow.service.password";
Expand All @@ -23,17 +17,15 @@ public class ExportApi extends Application {
public static final String WORKFLOW_SYNC_INITIALDELAY = "workflow.sync.initialdelay";
public static final String WORKFLOW_SYNC_DEADLOCK = "workflow.sync.deadlock";

public static final String ENV_EXPORT_FTP_HOST = "EXPORT_FTP_HOST";
public static final String ENV_EXPORT_FTP_PATH = "EXPORT_FTP_PATH";
public static final String ENV_EXPORT_FTP_PORT = "EXPORT_FTP_PORT";
public static final String ENV_EXPORT_FTP_USER = "EXPORT_FTP_USER";
public static final String ENV_EXPORT_FTP_PASSWORD = "EXPORT_FTP_PASSWORD";
public static final String ENV_EXPORT_FILE_PATH = "EXPORT_FILE_PATH";
public static final String EVENTLOG_TOPIC = "file.export";
public static final String EVENTLOG_DEADLOCK = "export.sync.deadlock";

public static final String EVENTLOG_TOPIC_EXPORT = "file.export";
public static final String EXPORT_SYNC_DEADLOCK = "export.sync.deadlock";
public static final String EXPORT_PATH = "export.path";

public final static String SNAPSHOT_RESOURCE = "snapshot/";
public static final String EXPORT_FTP_HOST = "export.ftp.host";
public static final String EXPORT_FTP_PORT = "export.ftp.port";
public static final String EXPORT_FTP_USER = "export.ftp.user";
public static final String EXPORT_FTP_PASSWORD = "export.ftp.password";

/**
* Returns the $uniqueID from a $SnapshotID
Expand All @@ -49,28 +41,4 @@ public static String getUniqueIDFromSnapshotID(String snapshotID) {

}

/**
* Converts a ItemCollection into a XMLDocument and returns the byte data.
*
* @param itemCol
* @return
* @throws ExportException
*/
public static byte[] getRawData(ItemCollection itemCol) throws ExportException {
byte[] data = null;
// create byte array from XMLDocument...
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
JAXBContext context;
context = JAXBContext.newInstance(XMLDocument.class);
Marshaller m = context.createMarshaller();
XMLDocument xmlDocument = XMLDocumentAdapter.getDocument(itemCol);
m.marshal(xmlDocument, outputStream);
data = outputStream.toByteArray();
} catch (JAXBException e) {
throw new ExportException(ExportException.INVALID_DOCUMENT_OBJECT, e.getMessage(), e);
}

return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
import org.eclipse.microprofile.metrics.annotation.RegistryType;
import org.imixs.archive.export.ExportApi;
import org.imixs.archive.export.ExportException;
import org.imixs.archive.export.services.ExportService;
import org.imixs.archive.export.services.ExportStatusHandler;
import org.imixs.archive.export.services.LogService;
import org.imixs.archive.export.services.SchedulerService;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

/**
* The ExportController is used to monitor the export status of the
* {@link ExportService}. The controller provides a processing log and shows the
* current configuration. This controller does not hold any state.
* {@link SchedulerService}. The controller provides a processing log and shows
* the current configuration. This controller does not hold any state.
*
* @author rsoika
*
Expand All @@ -49,15 +50,15 @@ public class ExportController implements Serializable {
Optional<String> instanceEndpoint;

@Inject
@ConfigProperty(name = ExportApi.ENV_EXPORT_FTP_HOST)
@ConfigProperty(name = ExportApi.EXPORT_FTP_HOST)
Optional<String> ftpServer;

@Inject
@ConfigProperty(name = ExportApi.ENV_EXPORT_FTP_PATH)
Optional<String> ftpPath;
@ConfigProperty(name = ExportApi.EXPORT_PATH)
Optional<String> filePath;

@Inject
@ConfigProperty(name = ExportApi.ENV_EXPORT_FTP_PORT, defaultValue = "21")
@ConfigProperty(name = ExportApi.EXPORT_FTP_PORT, defaultValue = "21")
int ftpPort;

// timeout interval in ms
Expand All @@ -69,11 +70,14 @@ public class ExportController implements Serializable {
@RegistryType(type = MetricRegistry.Type.APPLICATION)
MetricRegistry metricRegistry;

@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ExportController.class.getName());

@Inject
ExportService exportService;
SchedulerService exportService;

@Inject
LogService logService;

@Inject
ExportStatusHandler exportStatusHandler;

Expand Down Expand Up @@ -103,8 +107,8 @@ public String getFtpServer() {
return ftpServer.orElse("");
}

public String getFtpPath() {
return ftpPath.orElse("");
public String getFilePath() {
return filePath.orElse("");
}

public int getFtpPort() {
Expand All @@ -126,7 +130,7 @@ public void start() {
try {
exportService.startScheduler(true);
} catch (ExportException e) {
exportService.warning(ExportApi.EVENTLOG_TOPIC_EXPORT, e.getMessage());
logService.warning(e.getMessage());
}
}

Expand All @@ -137,7 +141,7 @@ public void stop() {
try {
exportService.stopScheduler();
} catch (ExportException e) {
exportService.warning(ExportApi.EVENTLOG_TOPIC_EXPORT, e.getMessage());
logService.warning(e.getMessage());
}
}

Expand All @@ -162,7 +166,7 @@ public long getCounterByName(String name) {
return 0;
}

public List<String> getLogEntries(String context) {
return exportService.getLogEntries();// logTopics.get(context);
public List<String> getLogEntries() {
return logService.getLogEntries();// logTopics.get(context);
}
}
Loading

0 comments on commit 3892eac

Please sign in to comment.