-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[26529] Automatisierte Datei Übertragung (#362)
- Loading branch information
Showing
15 changed files
with
801 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ch.elexis.global_inbox.core</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ds.core.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
2 changes: 2 additions & 0 deletions
2
bundles/ch.elexis.global_inbox.core/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
9 changes: 9 additions & 0 deletions
9
bundles/ch.elexis.global_inbox.core/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | ||
org.eclipse.jdt.core.compiler.compliance=17 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: Global Inbox Core | ||
Bundle-SymbolicName: ch.elexis.global_inbox.core | ||
Bundle-Version: 3.12.0.qualifier | ||
Export-Package: ch.elexis.global_inbox.core.handler | ||
Import-Package: ch.elexis.core.tasks.model, | ||
ch.elexis.data | ||
Require-Bundle: javax.inject, | ||
ch.elexis.core, | ||
at.medevit.elexis.inbox, | ||
ch.elexis.core.ui;bundle-version="3.12.0", | ||
ch.elexis.core.ui.tasks | ||
Service-Component: OSGI-INF/ch.elexis.global_inbox.core.handler.IdentifiedRunnableFactoryImpl.xml, | ||
OSGI-INF/ch.elexis.global_inbox.core.service.IdentifiedRunnableFactoryImplMover.xml | ||
Automatic-Module-Name: ch.elexis.global.inbox.core | ||
Bundle-ActivationPolicy: lazy | ||
Bundle-RequiredExecutionEnvironment: JavaSE-17 |
12 changes: 12 additions & 0 deletions
12
....core/OSGI-INF/ch.elexis.global_inbox.core.service.IdentifiedRunnableFactoryImplMover.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" deactivate="deactivate" immediate="true" name="ch.elexis.global_inbox.core.service.IdentifiedRunnableFactoryImplMover"> | ||
<service> | ||
<provide interface="ch.elexis.core.model.tasks.IIdentifiedRunnableFactory"/> | ||
</service> | ||
<reference bind="setModelService" interface="ch.elexis.core.services.IModelService" name="ModelService" target="(service.model.name=ch.elexis.core.tasks.model)"/> | ||
<reference cardinality="1..1" field="accessControlService" interface="ch.elexis.core.services.IAccessControlService" name="accessControlService"/> | ||
<reference bind="getModelService" interface="ch.elexis.core.services.IModelService" name="getModelService" target="(service.model.name=ch.elexis.core.tasks.model)"/> | ||
<reference cardinality="1..1" field="taskService" interface="ch.elexis.core.tasks.model.ITaskService" name="taskService"/> | ||
<reference cardinality="1..1" field="virtualFilsystemService" interface="ch.elexis.core.services.IVirtualFilesystemService" name="virtualFilsystemService"/> | ||
<implementation class="ch.elexis.global_inbox.core.service.IdentifiedRunnableFactoryImplMover"/> | ||
</scr:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
OSGI-INF/ch.elexis.global_inbox.core.service.IdentifiedRunnableFactoryImplMover.xml |
87 changes: 87 additions & 0 deletions
87
...global_inbox.core/src/ch/elexis/global_inbox/core/handler/MoveFileIdentifiedRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package ch.elexis.global_inbox.core.handler; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.slf4j.Logger; | ||
|
||
import ch.elexis.core.model.tasks.IIdentifiedRunnable; | ||
import ch.elexis.core.model.tasks.TaskException; | ||
import ch.elexis.core.services.IVirtualFilesystemService; | ||
import ch.elexis.core.services.IVirtualFilesystemService.IVirtualFilesystemHandle; | ||
|
||
import ch.elexis.global_inbox.core.util.Constants; | ||
|
||
public class MoveFileIdentifiedRunnable implements IIdentifiedRunnable { | ||
|
||
private IVirtualFilesystemService virtualFilesystemService; | ||
|
||
public MoveFileIdentifiedRunnable(IVirtualFilesystemService virtualFilesystemService) { | ||
this.virtualFilesystemService = virtualFilesystemService; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return Constants.IMPORTFILETOOMNIVORE; | ||
} | ||
|
||
@Override | ||
public Map<String, Serializable> run(Map<String, Serializable> context, IProgressMonitor progressMonitor, | ||
Logger logger) throws TaskException { | ||
String eventFilePath = (String) context.get(RunContextParameter.STRING_URL); | ||
String destinationDir = (String) context.get("destinationDir"); | ||
|
||
if (eventFilePath == null || destinationDir == null) { | ||
throw new TaskException(TaskException.EXECUTION_ERROR, | ||
"Missing required run-context-parameter(s): [url, destinationDir]"); | ||
} | ||
|
||
try { | ||
IVirtualFilesystemHandle vfsHandle = virtualFilesystemService.of(eventFilePath); | ||
Path sourcePath = Paths.get(vfsHandle.getURI()); | ||
Path targetDir = Paths.get(destinationDir); | ||
if (!Files.exists(targetDir)) { | ||
Files.createDirectories(targetDir); | ||
} else if (!Files.isDirectory(targetDir)) { | ||
throw new TaskException(TaskException.EXECUTION_ERROR, destinationDir + " is not a directory"); | ||
} | ||
|
||
if (Files.isDirectory(sourcePath)) { | ||
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(sourcePath)) { | ||
for (Path filePath : directoryStream) { | ||
Path targetPath = targetDir.resolve(filePath.getFileName()); | ||
Files.move(filePath, targetPath); | ||
logger.info("Moved {} to {}", filePath.toString(), targetPath.toString()); | ||
} | ||
} | ||
} else { | ||
Path targetPath = targetDir.resolve(sourcePath.getFileName()); | ||
Files.move(sourcePath, targetPath); | ||
logger.info("Moved {} to {}", sourcePath.toString(), targetPath.toString()); | ||
} | ||
} catch (IOException e) { | ||
throw new TaskException(TaskException.EXECUTION_ERROR, "Error moving files from [" + eventFilePath + "]", | ||
e); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String getLocalizedDescription() { | ||
return "Move files from a directory to Omnivore directory"; | ||
} | ||
|
||
@Override | ||
public Map<String, Serializable> getDefaultRunContext() { | ||
return Collections.singletonMap(RunContextParameter.STRING_URL, | ||
RunContextParameter.VALUE_MISSING_REQUIRED); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
....elexis.global_inbox.core/src/ch/elexis/global_inbox/core/handler/TaskManagerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package ch.elexis.global_inbox.core.handler; | ||
|
||
import ch.elexis.core.eenv.IElexisEnvironmentService; | ||
import ch.elexis.core.exceptions.AccessControlException; | ||
import ch.elexis.core.model.tasks.IIdentifiedRunnable; | ||
import ch.elexis.core.model.tasks.IIdentifiedRunnable.RunContextParameter; | ||
import ch.elexis.core.model.tasks.TaskException; | ||
import ch.elexis.core.tasks.model.ITaskDescriptor; | ||
import ch.elexis.core.tasks.model.ITaskService; | ||
import ch.elexis.core.tasks.model.TaskTriggerType; | ||
import ch.elexis.core.tasks.model.TaskTriggerTypeParameter; | ||
import ch.elexis.core.services.IVirtualFilesystemService; | ||
|
||
import java.io.Serializable; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
public class TaskManagerHandler { | ||
|
||
private ITaskService taskService; | ||
private IVirtualFilesystemService virtualFilesystemService; | ||
|
||
public TaskManagerHandler(ITaskService taskService, IVirtualFilesystemService virtualFilesystemService) { | ||
this.taskService = taskService; | ||
this.virtualFilesystemService = virtualFilesystemService; | ||
} | ||
|
||
public ITaskDescriptor getTaskDescriptorByReferenceId(String referenceId) { | ||
Optional<ITaskDescriptor> taskDescriptorOpt = taskService.findTaskDescriptorByIdOrReferenceId(referenceId); | ||
return taskDescriptorOpt.orElse(null); | ||
} | ||
|
||
public void createAndConfigureTask(String referenceId, String url, String destinationDir) { | ||
try { | ||
Optional<ITaskDescriptor> existingTaskDescriptorOpt = taskService | ||
.findTaskDescriptorByIdOrReferenceId(referenceId); | ||
if (existingTaskDescriptorOpt.isPresent()) { | ||
ITaskDescriptor existingTaskDescriptor = existingTaskDescriptorOpt.get(); | ||
ensureNotDeletedById(existingTaskDescriptor.getReferenceId()); | ||
existingTaskDescriptor.setTriggerParameter(TaskTriggerTypeParameter.FILESYSTEM_CHANGE.URL, url); | ||
existingTaskDescriptor.setRunContextParameter(RunContextParameter.STRING_URL, url); | ||
existingTaskDescriptor.setRunContextParameter("destinationDir", destinationDir); | ||
existingTaskDescriptor.setActive(true); | ||
existingTaskDescriptor.setRunner(IElexisEnvironmentService.ES_STATION_ID_DEFAULT); | ||
taskService.saveTaskDescriptor(existingTaskDescriptor); | ||
} else { | ||
IIdentifiedRunnable runnable = new MoveFileIdentifiedRunnable(virtualFilesystemService); | ||
ITaskDescriptor newTaskDescriptor = taskService.createTaskDescriptor(runnable); | ||
newTaskDescriptor.setReferenceId(referenceId); | ||
newTaskDescriptor.setTriggerType(TaskTriggerType.FILESYSTEM_CHANGE); | ||
newTaskDescriptor.setTriggerParameter(TaskTriggerTypeParameter.FILESYSTEM_CHANGE.URL, url); | ||
newTaskDescriptor.setActive(true); | ||
newTaskDescriptor.setRunner(IElexisEnvironmentService.ES_STATION_ID_DEFAULT); | ||
|
||
Map<String, Serializable> runContext = new HashMap<>(); | ||
runContext.put(RunContextParameter.STRING_URL, url); | ||
runContext.put("destinationDir", destinationDir); | ||
newTaskDescriptor.setRunContext(runContext); | ||
|
||
taskService.saveTaskDescriptor(newTaskDescriptor); | ||
} | ||
} catch (TaskException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void ensureNotDeletedById(String referenceId) { | ||
Optional<ITaskDescriptor> taskDescriptorOpt = taskService.findTaskDescriptorByIdOrReferenceId(referenceId); | ||
if (taskDescriptorOpt.isPresent()) { | ||
ITaskDescriptor taskDescriptor = taskDescriptorOpt.get(); | ||
if (taskDescriptor.getReferenceId().equals(referenceId)) { | ||
try { | ||
if (taskDescriptor.isDeleted()) { | ||
taskDescriptor.setDeleted(false); | ||
taskService.saveTaskDescriptor(taskDescriptor); | ||
} | ||
} catch (TaskException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void deleteTaskDescriptorByReferenceId(String referenceId) { | ||
Optional<ITaskDescriptor> taskDescriptorOpt = taskService.findTaskDescriptorByIdOrReferenceId(referenceId); | ||
if (taskDescriptorOpt.isPresent()) { | ||
ITaskDescriptor taskDescriptor = taskDescriptorOpt.get(); | ||
try { | ||
taskDescriptor.setActive(false); | ||
taskDescriptor.setDeleted(true); | ||
taskService.saveTaskDescriptor(taskDescriptor); | ||
} catch (AccessControlException e) { | ||
LoggerFactory.getLogger(TaskManagerHandler.class).error("Berechtigungsfehler: " + e.getMessage()); | ||
} catch (TaskException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...nbox.core/src/ch/elexis/global_inbox/core/service/IdentifiedRunnableFactoryImplMover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ch.elexis.global_inbox.core.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import ch.elexis.core.model.tasks.IIdentifiedRunnable; | ||
import ch.elexis.core.model.tasks.IIdentifiedRunnableFactory; | ||
import ch.elexis.core.services.IAccessControlService; | ||
import ch.elexis.core.services.IModelService; | ||
import ch.elexis.core.services.IVirtualFilesystemService; | ||
import ch.elexis.core.tasks.internal.runnables.DeleteFileIdentifiedRunnable; | ||
import ch.elexis.core.tasks.internal.runnables.LogResultContextIdentifiedRunnable; | ||
import ch.elexis.core.tasks.internal.runnables.RemoveTaskLogEntriesRunnable; | ||
import ch.elexis.core.tasks.model.ITaskService; | ||
import ch.elexis.global_inbox.core.handler.MoveFileIdentifiedRunnable; | ||
|
||
|
||
@Component(immediate = true) | ||
public class IdentifiedRunnableFactoryImplMover implements IIdentifiedRunnableFactory { | ||
|
||
@Reference | ||
private ITaskService taskService; | ||
|
||
@Reference | ||
private IVirtualFilesystemService virtualFilsystemService; | ||
|
||
private IModelService taskModelService; | ||
|
||
@Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.tasks.model)") | ||
private void setModelService(IModelService modelService) { | ||
taskModelService = modelService; | ||
} | ||
|
||
@Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.tasks.model)") | ||
public void getModelService(IModelService modelService) { | ||
taskModelService = modelService; | ||
} | ||
|
||
@Reference | ||
private IAccessControlService accessControlService; | ||
|
||
@Activate | ||
public void activate() { | ||
taskService.bindIIdentifiedRunnableFactory(this); | ||
} | ||
|
||
@Deactivate | ||
public void deactivate() { | ||
taskService.unbindIIdentifiedRunnableFactory(this); | ||
} | ||
|
||
@Override | ||
public List<IIdentifiedRunnable> getProvidedRunnables() { | ||
List<IIdentifiedRunnable> ret = new ArrayList<>(); | ||
ret.add(new MoveFileIdentifiedRunnable(virtualFilsystemService)); | ||
return ret; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
bundles/ch.elexis.global_inbox.core/src/ch/elexis/global_inbox/core/util/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ch.elexis.global_inbox.core.util; | ||
|
||
public class Constants { | ||
|
||
public static final String IMPORTFILETOOMNIVORE = "importFileToOmnivore"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.