|
20 | 20 | import java.util.Calendar; |
21 | 21 | import java.util.Collection; |
22 | 22 | import java.util.Date; |
| 23 | +import java.util.Iterator; |
23 | 24 | import java.util.List; |
24 | 25 | import java.util.logging.Level; |
25 | 26 | import java.util.logging.Logger; |
@@ -109,25 +110,39 @@ public class SchedulerService { |
109 | 110 | /** |
110 | 111 | * Loads the scheduler configuration entity by name. The method returns null if |
111 | 112 | * no scheduler configuration exits. |
| 113 | + * <p> |
| 114 | + * The method removes duplicates if exit. |
112 | 115 | * |
113 | | - * @return |
| 116 | + * @param name - name of the scheduler configuration |
| 117 | + * @return the configuration ItemCollection or null if not found |
114 | 118 | */ |
115 | 119 | public ItemCollection loadConfiguration(String name) { |
116 | 120 | try { |
117 | 121 | // support deprecated txtname attribure |
118 | 122 | String sQuery = "(type:\"" + DOCUMENT_TYPE + "\" AND (name:\"" + name + "\" OR txtname:\"" + name |
119 | 123 | + "\" ) )"; |
120 | | - Collection<ItemCollection> col = documentService.find(sQuery, 1, 0); |
| 124 | + Collection<ItemCollection> col = documentService.find(sQuery, 99, 0); |
121 | 125 | // 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(); |
124 | 129 | // refresh timer details |
125 | 130 | 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 | + } |
126 | 140 | return configuration; |
127 | 141 | } |
128 | 142 | } catch (QueryException e1) { |
129 | 143 | e1.printStackTrace(); |
130 | 144 | } |
| 145 | + // no data found! |
131 | 146 | return null; |
132 | 147 | } |
133 | 148 |
|
|
0 commit comments