Skip to content

Commit 89a6137

Browse files
committed
improved loadConfiguration() method (Issue #946)
1 parent 4655729 commit 89a6137

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

imixs-workflow-engine/src/main/java/org/imixs/workflow/engine/scheduler/SchedulerService.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Calendar;
2121
import java.util.Collection;
2222
import java.util.Date;
23+
import java.util.Iterator;
2324
import java.util.List;
2425
import java.util.logging.Level;
2526
import java.util.logging.Logger;
@@ -109,25 +110,39 @@ public class SchedulerService {
109110
/**
110111
* Loads the scheduler configuration entity by name. The method returns null if
111112
* no scheduler configuration exits.
113+
* <p>
114+
* The method removes duplicates if exit.
112115
*
113-
* @return
116+
* @param name - name of the scheduler configuration
117+
* @return the configuration ItemCollection or null if not found
114118
*/
115119
public ItemCollection loadConfiguration(String name) {
116120
try {
117121
// support deprecated txtname attribure
118122
String sQuery = "(type:\"" + DOCUMENT_TYPE + "\" AND (name:\"" + name + "\" OR txtname:\"" + name
119123
+ "\" ) )";
120-
Collection<ItemCollection> col = documentService.find(sQuery, 1, 0);
124+
Collection<ItemCollection> col = documentService.find(sQuery, 99, 0);
121125
// check if we found a scheduler configuration
122-
if (col.size() > 0) {
123-
ItemCollection configuration = col.iterator().next();
126+
Iterator<ItemCollection> configIterator = col.iterator();
127+
if (configIterator.hasNext()) {
128+
ItemCollection configuration = configIterator.next();
124129
// refresh timer details
125130
updateTimerDetails(configuration);
131+
// remove deprecated configuration if exits
132+
while (configIterator.hasNext()) {
133+
ItemCollection deprecatedConfig = configIterator.next();
134+
if (deprecatedConfig != null) {
135+
logger.warning("├── Deprecated scheduler configuration '"
136+
+ deprecatedConfig.getUniqueID() + "' - will be removed...");
137+
documentService.remove(deprecatedConfig);
138+
}
139+
}
126140
return configuration;
127141
}
128142
} catch (QueryException e1) {
129143
e1.printStackTrace();
130144
}
145+
// no data found!
131146
return null;
132147
}
133148

0 commit comments

Comments
 (0)