Revision 57149
Added by Alessia Bardi over 4 years ago
CatalogueAPIClient.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
import java.net.URI; |
5 | 5 |
import java.net.URISyntaxException; |
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
import java.util.concurrent.TimeUnit; |
|
6 | 9 |
|
10 |
import com.fasterxml.jackson.databind.JavaType; |
|
11 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
7 | 12 |
import com.google.common.collect.Lists; |
8 | 13 |
import eu.dnetlib.parthenos.jrr.ParthenosRegistryResource; |
9 | 14 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException; |
... | ... | |
153 | 158 |
} |
154 | 159 |
} |
155 | 160 |
|
161 |
protected int purgeAll(int bulkSize) throws ParthenosPublisherException { |
|
162 |
log.debug("Catalogue --> Purge All Item"); |
|
163 |
int count = 0; |
|
164 |
try { |
|
165 |
List<String> items = list(bulkSize); |
|
166 |
while (items.size() > 0){ |
|
167 |
for(String itemName : items) { |
|
168 |
purgeItem(itemName); |
|
169 |
count++; |
|
156 | 170 |
|
171 |
Thread.sleep(50); |
|
172 |
|
|
173 |
} |
|
174 |
items = list(200); |
|
175 |
Thread.sleep(TimeUnit.SECONDS.toMillis(5)); |
|
176 |
} |
|
177 |
} catch (Throwable t) { |
|
178 |
throw new ParthenosPublisherException(t); |
|
179 |
|
|
180 |
} |
|
181 |
log.debug(String.format("Catalogue --> Purged all %d Items", count)); |
|
182 |
return count; |
|
183 |
} |
|
184 |
|
|
185 |
protected List<String> list(int limit) throws ParthenosPublisherException { |
|
186 |
log.debug(String.format("Getting list of items")); |
|
187 |
ObjectMapper mapper = new ObjectMapper(); |
|
188 |
JavaType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, String.class); |
|
189 |
HttpEntity<String> entity = new HttpEntity<String>(headersForCatalogue); |
|
190 |
try { |
|
191 |
URI uri = new URIBuilder(getBaseURL()+"list").addParameter("limit", String.valueOf(limit)).addParameter("offset", "0").build(); |
|
192 |
ResponseEntity<String> response |
|
193 |
= restTemplate.exchange(uri, HttpMethod.GET, entity, String.class); |
|
194 |
if(response.getStatusCode().is2xxSuccessful()){ |
|
195 |
String res = response.getBody(); |
|
196 |
return mapper.readValue(res, listType); |
|
197 |
} |
|
198 |
throw new ParthenosPublisherException("Cannot get list of items to purge"); |
|
199 |
} catch (Throwable t) { |
|
200 |
throw new ParthenosPublisherException(t); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
|
|
157 | 205 |
public String getBaseURL() { |
158 | 206 |
return baseURL; |
159 | 207 |
} |
Also available in: Unified diff
Purge catalogue items