Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Feb 23, 2024
1 parent f6a44bf commit a7a34d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 52 deletions.
1 change: 1 addition & 0 deletions plugin/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<target name="devbuild">
<exec executable="mvn">
<arg value="package"/>
<arg value="-Dmaven.test.skip=true" />
</exec>
<copy file="module-main/target/plugin_intranda_workflow_massupload.jar" todir="/opt/digiverso/goobi/plugins/workflow/"/>
<copy file="module-gui/target/plugin_intranda_workflow_massupload-GUI.jar" todir="/opt/digiverso/goobi/plugins/GUI/"/>
Expand Down
3 changes: 0 additions & 3 deletions plugin/module-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
66 changes: 23 additions & 43 deletions plugin/src/de/intranda/goobi/plugins/MassUploadPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@
@Data
public class MassUploadPlugin implements IWorkflowPlugin, IPlugin {

private static final long serialVersionUID = 2487957051892555829L;

private static final String PLUGIN_NAME = "intranda_workflow_massupload";
private String allowedTypes;
private String filenamePart;
private String userFolderName;
private String processTitleMatchType;
private String filenameSeparator;
// private String processnamePart;
// private String processnameSeparator;
private List<String> stepTitles;
private List<MassUploadedFile> uploadedFiles = new ArrayList<>();
private transient List<MassUploadedFile> uploadedFiles = new ArrayList<>();
private User user;
private File tempFolder;
private HashSet<Integer> stepIDs = new HashSet<>();
private List<MassUploadedProcess> finishedInserts = new ArrayList<>();
private transient List<MassUploadedProcess> finishedInserts = new ArrayList<>();
private boolean copyImagesViaGoobiScript = false;
private boolean useBarcodes = false;
private ExecutorService barcodePool;
private transient ExecutorService barcodePool;
private volatile boolean analyzingBarcodes = false;
private boolean currentlyInserting;
private boolean hideInsertButtonAfterClick = false;
Expand All @@ -109,8 +109,6 @@ public MassUploadPlugin() {
filenamePart = config.getString("filename-part", "prefix").toLowerCase();
userFolderName = config.getString("user-folder-name", "mass_upload").toLowerCase();
filenameSeparator = config.getString("filename-separator", "_").toLowerCase();
// processnamePart = ConfigPlugins.getPluginConfig(this).getString("processname-part", "complete").toLowerCase();
// processnameSeparator = ConfigPlugins.getPluginConfig(this).getString("processname-separator", "_").toLowerCase();
stepTitles = Arrays.asList(config.getStringArray("allowed-step"));
copyImagesViaGoobiScript = config.getBoolean("copy-images-using-goobiscript", false);
useBarcodes = config.getBoolean("use-barcodes", false);
Expand Down Expand Up @@ -155,10 +153,8 @@ public void uploadFile(FileUploadEvent event) {
if (tempFolder == null) {
readUser();
tempFolder = new File(ConfigurationHelper.getInstance().getTemporaryFolder(), user.getLogin());
if (!tempFolder.exists()) {
if (!tempFolder.mkdirs()) {
throw new IOException("Upload folder for user could not be created: " + tempFolder.getAbsolutePath());
}
if (!tempFolder.exists() && !tempFolder.mkdirs()) {
throw new IOException("Upload folder for user could not be created: " + tempFolder.getAbsolutePath());
}
}
UploadedFile upload = event.getFile();
Expand Down Expand Up @@ -203,17 +199,14 @@ private void saveFileTemporary(String fileName, InputStream in) throws IOExcepti
if (tempFolder == null) {
readUser();
tempFolder = new File(ConfigurationHelper.getInstance().getTemporaryFolder(), user.getLogin());
if (!tempFolder.exists()) {
if (!tempFolder.mkdirs()) {
throw new IOException("Upload folder for user could not be created: " + tempFolder.getAbsolutePath());
}
if (!tempFolder.exists() && !tempFolder.mkdirs()) {
throw new IOException("Upload folder for user could not be created: " + tempFolder.getAbsolutePath());
}
}

OutputStream out = null;
try {
File file = new File(tempFolder, fileName);
out = new FileOutputStream(file);
File file = new File(tempFolder, fileName);
try (OutputStream out = new FileOutputStream(file)) {

int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
Expand All @@ -222,23 +215,18 @@ private void saveFileTemporary(String fileName, InputStream in) throws IOExcepti
out.flush();
MassUploadedFile muf = new MassUploadedFile(file, fileName);
if (useBarcodes) {
Callable<String> readBarcodeTask = () -> {
return readBarcode(muf.getFile(), BarcodeFormat.CODE_128);
};
Callable<String> readBarcodeTask = () -> readBarcode(muf.getFile(), BarcodeFormat.CODE_128);
Future<String> futureBarcode = this.barcodePool.submit(readBarcodeTask);
String barcodeInfo = null;
try {
barcodeInfo = futureBarcode.get();
muf.setCheckedForBarcode(true);
} catch (InterruptedException | ExecutionException e) {
log.error(e);
}
barcodeInfo = futureBarcode.get();
muf.setCheckedForBarcode(true);

muf.setBarcodeValue(Optional.ofNullable(barcodeInfo));
} else {
assignProcessByFilename(muf, null);
}
uploadedFiles.add(muf);
} catch (IOException e) {
} catch (IOException | InterruptedException | ExecutionException e) {
log.error(e);
} finally {
if (in != null) {
Expand All @@ -248,13 +236,7 @@ private void saveFileTemporary(String fileName, InputStream in) throws IOExcepti
log.error(e);
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
log.error(e);
}
}

}
}

Expand Down Expand Up @@ -298,7 +280,7 @@ public void readFilesFromUserHomeFolder() {
*/
public void cleanUploadFolder() {
for (MassUploadedFile uploadedFile : uploadedFiles) {
uploadedFile.getFile().delete();
uploadedFile.getFile().delete(); //NOSONAR
}
uploadedFiles = new ArrayList<>();
finishedInserts = new ArrayList<>();
Expand All @@ -311,7 +293,7 @@ public void cleanUploadFolder() {
public void startInserting() {

this.hideInsertButtonAfterClick = true;
if (this.currentlyInserting == true) {
if (this.currentlyInserting) {
return;
}

Expand Down Expand Up @@ -343,7 +325,7 @@ public void startInserting() {
log.error("Error while copying file during mass upload", e);
Helper.setFehlerMeldung("Error while copying file during mass upload", e);
}
muf.getFile().delete();
muf.getFile().delete(); //NOSONAR
} else {
Helper.setFehlerMeldung("File could not be matched and gets skipped: " + muf.getFilename());
}
Expand All @@ -368,7 +350,7 @@ public void startInserting() {
Helper.setFehlerMeldung("Error while closing the step " + so.getTitel() + " for process " + so.getProzess().getTitel());
}
}
Helper.addMessageToProcessLog(so.getProcessId(), LogType.DEBUG,
Helper.addMessageToProcessJournal(so.getProcessId(), LogType.DEBUG,
"Images uploaded and step " + so.getTitel() + " finished using Massupload Plugin.");
HelperSchritte hs = new HelperSchritte();
so.setBearbeitungsbenutzer(user);
Expand Down Expand Up @@ -491,9 +473,7 @@ public boolean getShowInsertButton() {
return false;

}
boolean showInsertButton =
this.uploadedFiles.size() > 0 && this.uploadedFiles.stream().allMatch(muf -> muf.getStatus() != MassUploadedFileStatus.UNKNWON);
return showInsertButton;
return !this.uploadedFiles.isEmpty() && this.uploadedFiles.stream().allMatch(muf -> muf.getStatus() != MassUploadedFileStatus.UNKNWON);
}

public boolean isShowInsertButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class GoobiScriptCopyImages extends AbstractIGoobiScript implements IGoob
private static final Logger logger = Logger.getLogger(GoobiScriptCopyImages.class);

private User user;
private List<MassUploadedFile> uploadedFiles = new ArrayList<MassUploadedFile>();
private List<MassUploadedFile> uploadedFiles = new ArrayList<>();

public void setUser(User user) {
this.user = user;
Expand All @@ -51,7 +51,7 @@ public List<GoobiScriptResult> prepare(List<Integer> processes, String command,
for (MassUploadedFile muf : uploadedFiles) {
if (muf.getStatus() == MassUploadedFileStatus.OK) {
muf.setTransfered(false);
Map<String, String> mufParams = new LinkedHashMap<String, String>();
Map<String, String> mufParams = new LinkedHashMap<>();
mufParams.put("uploadFileIndex", Integer.toString(count));
mufParams.put("filename", muf.getFilename());
GoobiScriptResult gsr = new GoobiScriptResult(muf.getProcessId(), command, mufParams, username, starttime);
Expand Down Expand Up @@ -83,7 +83,7 @@ public void execute(GoobiScriptResult gsr) {
logger.error("Error while copying file during mass upload goobiscript", e);
Helper.setFehlerMeldung("Error while copying file during mass upload goobiscript", e);
}
muf.getFile().delete();
muf.getFile().delete(); //NOSONAR
muf.setTransfered(true);
}

Expand All @@ -106,7 +106,7 @@ public void execute(GoobiScriptResult gsr) {
gsr.updateTimestamp();

if (gsr.getResultType() == GoobiScriptResultType.OK && isLastFileOfProcess(muf)) {
Helper.addMessageToProcessLog(so.getProcessId(), LogType.DEBUG,
Helper.addMessageToProcessJournal(so.getProcessId(), LogType.DEBUG,
"Image uploaded and step " + so.getTitel() + " finished using Massupload Plugin via Goobiscript.");
HelperSchritte hs = new HelperSchritte();
so.setBearbeitungsbenutzer(user);
Expand All @@ -126,7 +126,7 @@ public void execute(GoobiScriptResult gsr) {
*/
private boolean isLastFileOfProcess(MassUploadedFile muf) {
for (MassUploadedFile m : uploadedFiles) {
if (m.getProcessTitle() != null && m.getProcessTitle().equals(muf.getProcessTitle()) && m.isTransfered() == false) {
if (m.getProcessTitle() != null && m.getProcessTitle().equals(muf.getProcessTitle()) && !m.isTransfered()) {
return false;
}
}
Expand All @@ -140,7 +140,6 @@ public boolean isVisible() {

@Override
public String getAction() {
// TODO Auto-generated method stub
return "massuploadCopyImages";
}

Expand Down

0 comments on commit a7a34d4

Please sign in to comment.