34
34
import org .apache .commons .configuration .SubnodeConfiguration ;
35
35
import org .apache .commons .io .FilenameUtils ;
36
36
import org .goobi .beans .Step ;
37
+ import org .goobi .io .BackupFileManager ;
37
38
import org .goobi .managedbeans .StepBean ;
38
39
import org .goobi .production .enums .PluginGuiType ;
39
40
import org .goobi .production .enums .PluginReturnValue ;
@@ -95,9 +96,6 @@ public class TranscriptionStepPlugin implements IStepPluginVersion2 {
95
96
private List <String > deletionCommand = null ;
96
97
@ Getter
97
98
private boolean altoFolderFound ;
98
- @ Getter
99
- @ Setter
100
- private boolean ignoreAltoFolder ;
101
99
102
100
@ Override
103
101
public void initialize (Step step , String returnPath ) {
@@ -145,18 +143,15 @@ public void initImageList(String configuredImageFolder) throws SwapException, DA
145
143
images .clear ();
146
144
Path path = Paths .get (imageFolder );
147
145
String ocrTxtDir = step .getProzess ().getOcrTxtDirectory ();
148
- String ocrAltoDir = step .getProzess ().getOcrAltoDirectory ();
149
146
if (StorageProvider .getInstance ().isFileExists (path )) {
150
147
List <Path > imageNameList = storageProvider .listFiles (imageFolder , NIOFileUtils .imageOrObjectNameFilter );
151
148
int order = 1 ;
152
149
for (Path imagePath : imageNameList ) {
153
150
Image image = new Image (step .getProzess (), configuredImageFolder , imagePath .getFileName ().toString (), order , 800 );
154
151
String basename = FilenameUtils .removeExtension (imagePath .getFileName ().toString ());
155
152
Path ocrFile = Paths .get (ocrTxtDir , basename + ".txt" );
156
- Path altoPath = Paths .get (ocrAltoDir , basename + ".xml" );
157
- boolean hasAlto = Files .exists (altoPath );
158
153
String currentOcr = readOcrFile (ocrFile );
159
- images .add (new TranscriptionImage (imagePath .getFileName ().toString (), image , currentOcr , ocrFile , hasAlto , altoPath ));
154
+ images .add (new TranscriptionImage (imagePath .getFileName ().toString (), image , currentOcr , ocrFile ));
160
155
order ++;
161
156
}
162
157
}
@@ -166,18 +161,30 @@ public void initImageList(String configuredImageFolder) throws SwapException, DA
166
161
this .setImageToIndex ();
167
162
}
168
163
169
- public void deleteSingleAltoResult () throws IOException {
170
- Files .deleteIfExists (image .getAltoPath ());
171
- image .setHasAlto (false );
172
- }
173
-
174
- public void deleteAltoFolder () throws SwapException , DAOException , IOException , InterruptedException {
175
- String altoDir = step .getProzess ().getOcrAltoDirectory ();
176
- StorageProvider .getInstance ().deleteDir (Paths .get (altoDir ));
177
- for (TranscriptionImage image : this .images ) {
178
- image .setHasAlto (false );
164
+ public void backupAlto () {
165
+ if (!this .isAltoFolderFound ()) {
166
+ return ;
167
+ }
168
+ try {
169
+ StorageProviderInterface sp = StorageProvider .getInstance ();
170
+ Path ocrFolder = Path .of (step .getProzess ().getOcrDirectory ());
171
+ if (sp .isFileExists (ocrFolder )) {
172
+ Path backupPath = Paths .get (ocrFolder .getParent ().toString (), BackupFileManager .generateBackupName (ocrFolder .getFileName ().toString ()));
173
+ sp .copyDirectory (ocrFolder , backupPath );
174
+ String directoryToKeep = step .getProzess ().getOcrTxtDirectory ();
175
+ if (directoryToKeep .endsWith ("/" )) {
176
+ directoryToKeep = directoryToKeep .substring (0 , directoryToKeep .length () - 1 );
177
+ }
178
+ for (Path dir : sp .listFiles (ocrFolder .toString ())) {
179
+ if (!dir .toString ().equals (directoryToKeep )) {
180
+ sp .deleteDir (dir );
181
+ }
182
+ }
183
+ }
184
+ this .altoFolderFound = false ;
185
+ } catch (IOException | SwapException e ) {
186
+ log .error ("Error backing up Alto results" , e );
179
187
}
180
- this .altoFolderFound = false ;
181
188
}
182
189
183
190
public String saveOcrAndExit () throws IOException {
0 commit comments