Revision 42184
Added by Michele Artini almost 8 years ago
OAISetsCounter.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
import java.util.concurrent.Callable; |
5 |
|
|
5 | 6 |
import javax.annotation.Resource; |
6 | 7 |
|
7 |
import com.google.common.collect.Lists; |
|
8 |
import eu.dnetlib.data.information.oai.publisher.info.MDFInfo; |
|
9 |
import eu.dnetlib.data.oai.store.sets.MongoSetCollection; |
|
10 |
import org.apache.commons.lang.StringUtils; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
11 | 9 |
import org.apache.commons.logging.Log; |
12 | 10 |
import org.apache.commons.logging.LogFactory; |
13 | 11 |
|
12 |
import com.google.common.collect.Lists; |
|
13 |
|
|
14 |
import eu.dnetlib.oai.sets.MongoSetCollection; |
|
15 |
import eu.dnetlib.rmi.provision.MDFInfo; |
|
16 |
|
|
14 | 17 |
/** |
15 | 18 |
* Updates the counts for all sets in the special sets collection of OAI store. |
16 | 19 |
* |
... | ... | |
36 | 39 |
* Otherwise all counts are updated. |
37 | 40 |
* </p> |
38 | 41 |
* |
39 |
* @param storeId oai store id. Can be blank to execute over all metadata served by OAI. |
|
40 |
* @param callback callback to execute when the execution is successful |
|
41 |
* @param failCallbackcallback to execute when the execution fails |
|
42 |
* @param storeId |
|
43 |
* oai store id. Can be blank to execute over all metadata served by OAI. |
|
44 |
* @param callback |
|
45 |
* callback to execute when the execution is successful |
|
46 |
* @param failCallbackcallback |
|
47 |
* to execute when the execution fails |
|
42 | 48 |
*/ |
43 | 49 |
public void updateCounts(final String storeId, final String dbName, final Callable<?> callback, final Callable<?> failCallback) { |
44 | 50 |
new Thread() { |
... | ... | |
46 | 52 |
@Override |
47 | 53 |
public void run() { |
48 | 54 |
try { |
49 |
List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId); |
|
50 |
for (MDFInfo mdFormat : metadataFormats) { |
|
51 |
oaiSetHelper.updateAllCounts(mdFormat, dbName); |
|
55 |
final List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId);
|
|
56 |
for (final MDFInfo mdFormat : metadataFormats) {
|
|
57 |
OAISetsCounter.this.oaiSetHelper.updateAllCounts(mdFormat, dbName);
|
|
52 | 58 |
} |
53 | 59 |
log.info("All sets count updated succesfully on db: " + dbName); |
54 | 60 |
executeCallback(callback); |
55 |
} catch (Exception e) { |
|
61 |
} catch (final Exception e) {
|
|
56 | 62 |
log.error(e); |
57 | 63 |
executeCallback(failCallback); |
58 | 64 |
} |
... | ... | |
66 | 72 |
@Override |
67 | 73 |
public void run() { |
68 | 74 |
try { |
69 |
oaiSetHelper.updateAllCounts(mdf, dbName); |
|
75 |
OAISetsCounter.this.oaiSetHelper.updateAllCounts(mdf, dbName);
|
|
70 | 76 |
log.info("All sets count updated succesfully for metadata format " + mdf + " on db " + dbName); |
71 | 77 |
executeCallback(callback); |
72 |
} catch (Exception e) { |
|
78 |
} catch (final Exception e) {
|
|
73 | 79 |
log.error(e); |
74 | 80 |
executeCallback(failCallback); |
75 | 81 |
} |
... | ... | |
80 | 86 |
/** |
81 | 87 |
* Update counts for configured OAI sets and all md formats. |
82 | 88 |
* |
83 |
* @param callback callback to execute when the execution is successful |
|
84 |
* @param failCallbackcallback to execute when the execution fails |
|
89 |
* @param callback |
|
90 |
* callback to execute when the execution is successful |
|
91 |
* @param failCallbackcallback |
|
92 |
* to execute when the execution fails |
|
85 | 93 |
*/ |
86 | 94 |
public void updateConfigurationCounts(final String storeId, final String dbName, final Callable<?> callback, final Callable<?> failCallback) { |
87 | 95 |
new Thread() { |
... | ... | |
89 | 97 |
@Override |
90 | 98 |
public void run() { |
91 | 99 |
try { |
92 |
List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId); |
|
100 |
final List<MDFInfo> metadataFormats = listProcessableMDFInfo(storeId);
|
|
93 | 101 |
|
94 |
for (MDFInfo mdFormat : metadataFormats) { |
|
95 |
oaiSetHelper.updateConfiguredSetsCount(mdFormat, dbName); |
|
102 |
for (final MDFInfo mdFormat : metadataFormats) {
|
|
103 |
OAISetsCounter.this.oaiSetHelper.updateConfiguredSetsCount(mdFormat, dbName);
|
|
96 | 104 |
} |
97 | 105 |
log.info("All configured sets count updated succesfully on db " + dbName); |
98 | 106 |
executeCallback(callback); |
99 |
} catch (Exception e) { |
|
107 |
} catch (final Exception e) {
|
|
100 | 108 |
log.error(e); |
101 | 109 |
executeCallback(failCallback); |
102 | 110 |
} |
... | ... | |
108 | 116 |
if (callback != null) { |
109 | 117 |
try { |
110 | 118 |
callback.call(); |
111 |
} catch (Exception e) { |
|
119 |
} catch (final Exception e) {
|
|
112 | 120 |
log.error("Error executing callback", e); |
113 | 121 |
} |
114 | 122 |
} |
... | ... | |
117 | 125 |
protected List<MDFInfo> listProcessableMDFInfo(final String storeId) { |
118 | 126 |
List<MDFInfo> metadataFormats = Lists.newArrayList(); |
119 | 127 |
if (StringUtils.isBlank(storeId)) { |
120 |
metadataFormats = configurationReader.getMetadataFormatInfo(); |
|
128 |
metadataFormats = this.configurationReader.getMetadataFormatInfo();
|
|
121 | 129 |
} else { |
122 |
String[] splitted = storeId.split("-"); |
|
123 |
String format = splitted[0]; |
|
124 |
String layout = splitted[1]; |
|
125 |
String inter = splitted[2]; |
|
126 |
metadataFormats = configurationReader.getFormatsServedBy(format, layout, inter); |
|
130 |
final String[] splitted = storeId.split("-");
|
|
131 |
final String format = splitted[0];
|
|
132 |
final String layout = splitted[1];
|
|
133 |
final String inter = splitted[2];
|
|
134 |
metadataFormats = this.configurationReader.getFormatsServedBy(format, layout, inter);
|
|
127 | 135 |
} |
128 | 136 |
return metadataFormats; |
129 | 137 |
} |
130 | 138 |
|
131 | 139 |
public OAIConfigurationReader getConfigurationReader() { |
132 |
return configurationReader; |
|
140 |
return this.configurationReader;
|
|
133 | 141 |
} |
134 | 142 |
|
135 | 143 |
public void setConfigurationReader(final OAIConfigurationReader configurationReader) { |
... | ... | |
137 | 145 |
} |
138 | 146 |
|
139 | 147 |
public MongoSetCollection getMongoSetCollection() { |
140 |
return mongoSetCollection; |
|
148 |
return this.mongoSetCollection;
|
|
141 | 149 |
} |
142 | 150 |
|
143 | 151 |
public void setMongoSetCollection(final MongoSetCollection mongoSetCollection) { |
... | ... | |
145 | 153 |
} |
146 | 154 |
|
147 | 155 |
public OAISetHelper getOaiSetCounterHelper() { |
148 |
return oaiSetHelper; |
|
156 |
return this.oaiSetHelper;
|
|
149 | 157 |
} |
150 | 158 |
|
151 | 159 |
public void setOaiSetCounterHelper(final OAISetHelper oaiSetHelper) { |
Also available in: Unified diff
oai import