@@ -65,39 +65,47 @@ protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
65
65
@ Override
66
66
protected void executeImpl (Action action , NodeRef actionedUponNodeRef ) {
67
67
68
- if (! nodeService .hasAspect (actionedUponNodeRef , OCRdModel .ASPECT_OCRD )) {
68
+ if (nodeService .hasAspect (actionedUponNodeRef , OCRdModel .ASPECT_OCRD )) {
69
69
70
- ContentData contentData = (ContentData ) nodeService .getProperty (actionedUponNodeRef , ContentModel .PROP_CONTENT );
71
-
72
- // Exclude folders and other nodes without content
73
- if (contentData != null ) {
74
-
75
- Boolean continueOnError = (Boolean ) action .getParameterValue (PARAM_CONTINUE_ON_ERROR );
76
- if (continueOnError == null ) continueOnError = true ;
77
-
78
- // # 5 Problem writing OCRed file
79
- // As action.getExecuteAsychronously() returns always FALSE (it's an Alfresco issue):
80
- // 1 - Try first with new Transaction
81
- // 2 - In case of error, try then with the current Transaction
82
- try {
83
- executeInNewTransaction (actionedUponNodeRef , contentData );
84
- } catch (Throwable throwableNewTransaction ) {
85
- logger .warn (actionedUponNodeRef + ": " + throwableNewTransaction .getMessage ());
86
- try {
87
- // Current transaction
88
- executeImplInternal (actionedUponNodeRef , contentData );
89
- } catch (Throwable throwableCurrentTransaction ) {
90
- if (continueOnError ) {
91
- logger .warn (actionedUponNodeRef + ": " + throwableNewTransaction .getMessage ());
92
- } else {
93
- throw throwableCurrentTransaction ;
94
- }
95
- }
96
- }
97
-
98
- }
70
+ String versionNode = nodeService .getProperty (actionedUponNodeRef , OCRdModel .PROP_APPLIED_VERSION ).toString ();
71
+ String versionOCR = versionService .getCurrentVersion (actionedUponNodeRef ).getVersionLabel ().toString ();
99
72
73
+ if (versionNode .equals (versionOCR )) {
74
+ return ;
75
+ }
100
76
}
77
+
78
+ ContentData contentData = (ContentData ) nodeService .getProperty (actionedUponNodeRef , ContentModel .PROP_CONTENT );
79
+
80
+ // Exclude folders and other nodes without content
81
+ if (contentData != null ) {
82
+
83
+ Boolean continueOnError = (Boolean ) action .getParameterValue (PARAM_CONTINUE_ON_ERROR );
84
+ if (continueOnError == null ) continueOnError = true ;
85
+
86
+ // # 5 Problem writing OCRed file
87
+ // As action.getExecuteAsychronously() returns always FALSE (it's an Alfresco issue):
88
+ // 1 - Try first with new Transaction
89
+ // 2 - In case of error, try then with the current Transaction
90
+ try {
91
+ executeInNewTransaction (actionedUponNodeRef , contentData );
92
+ } catch (Throwable throwableNewTransaction ) {
93
+ logger .warn (actionedUponNodeRef + ": " + throwableNewTransaction .getMessage ());
94
+ try {
95
+ // Current transaction
96
+ executeImplInternal (actionedUponNodeRef , contentData );
97
+ } catch (Throwable throwableCurrentTransaction ) {
98
+ if (continueOnError ) {
99
+ logger .warn (actionedUponNodeRef + ": " + throwableNewTransaction .getMessage ());
100
+ } else {
101
+ throw throwableCurrentTransaction ;
102
+ }
103
+ }
104
+ }
105
+
106
+ }
107
+
108
+
101
109
102
110
}
103
111
@@ -166,19 +174,19 @@ private void executeImplInternal(NodeRef actionedUponNodeRef, ContentData conten
166
174
writeOriginalContent .setMimetype (MimetypeMap .MIMETYPE_PDF );
167
175
}
168
176
writeOriginalContent .putContent (writer .getReader ());
169
-
170
- // Set OCRd aspect to avoid future re-OCR process
171
- Map <QName , Serializable > aspectProperties = new HashMap <QName , Serializable >();
172
- aspectProperties .put (OCRdModel .PROP_PROCESSED_DATE , new Date ());
173
- nodeService .addAspect (actionedUponNodeRef , OCRdModel .ASPECT_OCRD , aspectProperties );
174
177
175
178
// Manual versioning because of Alfresco insane rules for first version content nodes
176
179
versionService .ensureVersioningEnabled (actionedUponNodeRef , null );
177
180
Map <String , Serializable > versionProperties = new HashMap <String , Serializable >();
178
181
versionProperties .put (Version .PROP_DESCRIPTION , "OCRd" );
179
182
versionProperties .put (VersionModel .PROP_VERSION_TYPE , VersionType .MINOR );
180
183
versionService .createVersion (actionedUponNodeRef , versionProperties );
181
-
184
+
185
+ // Set OCRd aspect to avoid future re-OCR process
186
+ Map <QName , Serializable > aspectProperties = new HashMap <QName , Serializable >();
187
+ aspectProperties .put (OCRdModel .PROP_PROCESSED_DATE , new Date ());
188
+ aspectProperties .put (OCRdModel .PROP_APPLIED_VERSION , versionService .getCurrentVersion (actionedUponNodeRef ).getVersionLabel ());
189
+ nodeService .addAspect (actionedUponNodeRef , OCRdModel .ASPECT_OCRD , aspectProperties );
182
190
}
183
191
184
192
private NodeRef createNode (NodeRef parentNodeRef , String name , Map <QName , Serializable > props ) {
0 commit comments