Revision 44144
Added by Alessia Bardi over 7 years ago
OAISetsCounter.java | ||
---|---|---|
4 | 4 |
import java.util.concurrent.Callable; |
5 | 5 |
import javax.annotation.Resource; |
6 | 6 |
|
7 |
import com.google.common.collect.Lists;
|
|
7 |
import com.google.common.base.Splitter;
|
|
8 | 8 |
import eu.dnetlib.oai.sets.MongoSetCollection; |
9 | 9 |
import eu.dnetlib.rmi.provision.MDFInfo; |
10 | 10 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
28 | 28 |
@Autowired |
29 | 29 |
private OAISetHelper oaiSetHelper; |
30 | 30 |
|
31 |
public void updateSetCount(final String storeId, final String dbName, final String set){ |
|
32 |
final List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId); |
|
33 |
for (final MDFInfo mdFormat : metadataFormats) { |
|
34 |
oaiSetHelper.updateSetCount(mdFormat, dbName, set); |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
31 | 38 |
/** |
32 | 39 |
* Update counts for all OAI sets. |
33 | 40 |
* <p> |
... | ... | |
41 | 48 |
* oai store id. Can be blank to execute over all metadata served by OAI. |
42 | 49 |
* @param callback |
43 | 50 |
* callback to execute when the execution is successful |
44 |
* @param failCallbackcallback
|
|
51 |
* @param failCallback |
|
45 | 52 |
* to execute when the execution fails |
46 | 53 |
*/ |
47 | 54 |
public void updateCounts(final String storeId, final String dbName, final Callable<?> callback, final Callable<?> failCallback) { |
48 |
new Thread() { |
|
49 |
|
|
50 |
@Override |
|
51 |
public void run() { |
|
52 |
try { |
|
53 |
final List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId); |
|
54 |
for (final MDFInfo mdFormat : metadataFormats) { |
|
55 |
OAISetsCounter.this.oaiSetHelper.updateAllCounts(mdFormat, dbName); |
|
56 |
} |
|
57 |
log.info("All sets count updated succesfully on db: " + dbName); |
|
58 |
executeCallback(callback); |
|
59 |
} catch (final Exception e) { |
|
60 |
log.error(e); |
|
61 |
executeCallback(failCallback); |
|
62 |
} |
|
63 |
} |
|
64 |
}.start(); |
|
55 |
final List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId); |
|
56 |
for (final MDFInfo mdFormat : metadataFormats) { |
|
57 |
updateCounts(mdFormat, dbName, callback, failCallback); |
|
58 |
} |
|
65 | 59 |
} |
66 | 60 |
|
67 | 61 |
public void updateCounts(final MDFInfo mdf, final String dbName, final Callable<?> callback, final Callable<?> failCallback) { |
... | ... | |
86 | 80 |
* |
87 | 81 |
* @param callback |
88 | 82 |
* callback to execute when the execution is successful |
89 |
* @param failCallbackcallback
|
|
83 |
* @param failCallback |
|
90 | 84 |
* to execute when the execution fails |
91 | 85 |
*/ |
92 | 86 |
public void updateConfigurationCounts(final String storeId, final String dbName, final Callable<?> callback, final Callable<?> failCallback) { |
... | ... | |
121 | 115 |
} |
122 | 116 |
|
123 | 117 |
protected List<MDFInfo> listProcessableMDFInfo(final String storeId) { |
124 |
List<MDFInfo> metadataFormats = Lists.newArrayList();
|
|
118 |
List<MDFInfo> metadataFormats; |
|
125 | 119 |
if (StringUtils.isBlank(storeId)) { |
126 | 120 |
metadataFormats = this.configurationReader.getMetadataFormatInfo(); |
127 | 121 |
} else { |
128 |
final String[] splitted = storeId.split("-");
|
|
129 |
final String format = splitted[0];
|
|
130 |
final String layout = splitted[1];
|
|
131 |
final String inter = splitted[2];
|
|
122 |
List<String> splitted = Splitter.on('-').trimResults().splitToList(storeId);
|
|
123 |
final String format = splitted.get(0);
|
|
124 |
final String layout =splitted.get(1);
|
|
125 |
final String inter = splitted.get(2);
|
|
132 | 126 |
metadataFormats = this.configurationReader.getFormatsServedBy(format, layout, inter); |
133 | 127 |
} |
134 | 128 |
return metadataFormats; |
Also available in: Unified diff
some cleanup in OAI related classes