forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new process using python script
- Loading branch information
Matus Kasak
committed
Nov 22, 2024
1 parent
2c8c732
commit 6c2fb01
Showing
9 changed files
with
117 additions
and
239 deletions.
There are no files selected for viewing
140 changes: 0 additions & 140 deletions
140
dspace-api/src/main/java/org/dspace/administer/ProcessCleaner2.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
dspace-api/src/main/java/org/dspace/administer/ProcessCleanerCli2.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
dspace-api/src/main/java/org/dspace/administer/ProcessCleanerCliConfiguration2.java
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
dspace-api/src/main/java/org/dspace/administer/ProcessCleanerConfiguration2.java
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.testing; | ||
|
||
import org.apache.commons.cli.ParseException; | ||
import org.dspace.scripts.DSpaceRunnable; | ||
import org.dspace.utils.DSpace; | ||
|
||
import java.io.*; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class Testing extends DSpaceRunnable<TestingScriptConfiguration> { | ||
|
||
@Override | ||
public TestingScriptConfiguration getScriptConfiguration() { | ||
return new DSpace().getServiceManager() | ||
.getServiceByName("testing-script", TestingScriptConfiguration.class); | ||
} | ||
|
||
@Override | ||
public void setup() throws ParseException { | ||
|
||
} | ||
|
||
@Override | ||
public void internalRun() throws Exception { | ||
System.out.println("Hello world from java"); | ||
try { | ||
// loading python scripts stored in resources | ||
InputStream scriptInputStream = getClass().getClassLoader().getResourceAsStream("python-script.py"); | ||
if (scriptInputStream == null) { | ||
throw new FileNotFoundException("Python script not found in resources"); | ||
} | ||
|
||
File tempFile = File.createTempFile("python-script", ".py"); | ||
tempFile.deleteOnExit(); | ||
// transfer the content to the temporary file | ||
try (FileOutputStream out = new FileOutputStream(tempFile)) { | ||
scriptInputStream.transferTo(out); | ||
} | ||
|
||
// configure ProcessBuilder to run script using python commands | ||
ProcessBuilder processBuilder = new ProcessBuilder("python", tempFile.getAbsolutePath()); | ||
processBuilder.directory(tempFile.getParentFile()); | ||
Process process = processBuilder.start(); | ||
|
||
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8); | ||
BufferedReader reader = new BufferedReader(inputStreamReader); | ||
|
||
// reading the scripts output and then outputs it to the console | ||
String line = reader.readLine(); | ||
while (line != null) { | ||
System.out.println(line); | ||
line = reader.readLine(); | ||
} | ||
|
||
inputStreamReader.close(); | ||
reader.close(); | ||
int exitCode = process.waitFor(); | ||
System.out.println("Exited with code: " + exitCode); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
dspace-api/src/main/java/org/dspace/testing/TestingScriptConfiguration.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,36 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.testing; | ||
|
||
import org.apache.commons.cli.Options; | ||
import org.dspace.scripts.configuration.ScriptConfiguration; | ||
|
||
public class TestingScriptConfiguration<T extends Testing> extends ScriptConfiguration<T> { | ||
|
||
private Class<T> dspaceRunnableclass; | ||
|
||
@Override | ||
public Class<T> getDspaceRunnableClass() { | ||
return dspaceRunnableclass; | ||
} | ||
|
||
@Override | ||
public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) { | ||
this.dspaceRunnableclass = dspaceRunnableClass; | ||
} | ||
|
||
@Override | ||
public Options getOptions() { | ||
if (options == null) { | ||
Options options = new Options(); | ||
options.addOption("h", "help", false, "Display help message"); | ||
super.options = options; | ||
} | ||
return options; | ||
} | ||
} |
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 @@ | ||
print("Hello world from python") |
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