Project

General

Profile

« Previous | Next » 

Revision 57149

Purge catalogue items

View differences:

modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/CatalogueRegistrator.java
71 71
		return catalogueAPIClient.purgeItem(resCatName);
72 72
	}
73 73

  
74
	public int purgeAll(final int bulkSize) throws ParthenosPublisherException {
75
		return catalogueAPIClient.purgeAll(bulkSize);
76
	}
77

  
78

  
79

  
74 80
	protected String getJson(final Resource type, final Resource resource, final String resNameForCatalogue, final String datasourceName)
75 81
			throws IOException, ParthenosPublisherException {
76 82
		switch (type.getLocalName()) {
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/catalogue/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
	}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/jrr/JRRPublisher.java
51 51
		baseModel.read(CRMdig.RDFS_URL);
52 52
	}
53 53

  
54

  
54 55
	//No need to pass the RDF inside an OAI record: use register(String, String, String) to explicitely pass the needed information.
55 56
	@Deprecated
56 57
	public void register(final String record)
......
61 62
		register(rdfRecord, id, datasourceName);
62 63
	}
63 64

  
65
	public int purgeFromCatalogue(int bulkSize) throws ParthenosPublisherException {
66
		return catalogueRegistrator.purgeAll(bulkSize);
67
	}
68

  
64 69
	public void register(final String rdfRecord, final String objIdentifier, final String datasourceName)
65 70
			throws ParthenosPublisherException, IOException, URISyntaxException, InterruptedException {
66 71
		//objIdentifier contains the subject URI used to get the RDF: that is the only resource we have to register when processing this rdf file!
......
151 156
	}
152 157

  
153 158

  
159

  
160

  
154 161
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherHelper.java
87 87
		return deletedTriples;
88 88
	}
89 89

  
90
	public void dropRegistry(){
90
	public int dropRegistry(final int bulkSize) throws ParthenosPublisherException {
91 91
		log.debug("Dropping JRR");
92
		//TODO: implement me
93
		throw new UnsupportedOperationException("Not implemented yet");
92
		return jrrPublisher.purgeFromCatalogue(bulkSize);
94 93
	}
95 94

  
96 95

  
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherController.java
44 44
	}
45 45

  
46 46
	@RequestMapping(value = "/dropRegistry", method = RequestMethod.GET)
47
	public void unpublish() throws ParthenosPublisherException {
48
		getParthenosPublisherHelper().dropRegistry();
47
	public void unpublish(@RequestParam final int bulkSize) throws ParthenosPublisherException {
48
		getParthenosPublisherHelper().dropRegistry(bulkSize);
49 49
	}
50 50

  
51 51
	private ParthenosTargets getTarget(String value) {
modules/dnet-parthenos-publisher/trunk/pom.xml
68 68
				<enabled>true</enabled>
69 69
			</snapshots>
70 70
		</repository>
71
		-->
71 72
		<repository>
72 73
			<id>gcube-releases</id>
73 74
			<name>gCube Releases</name>
......
90 91
				<enabled>true</enabled>
91 92
			</releases>
92 93
		</repository>
93
		-->
94 94
	</repositories>
95 95

  
96 96
	<dependencies>
97
<!--		<dependency>-->
98
<!--			<groupId>org.gcube.data-publishing</groupId>-->
99
<!--			<artifactId>gcat-client</artifactId>-->
100
<!--			<version>[1.1.0, 2.0.0)</version>-->
101
<!--			<type>pom</type>-->
102
<!--		</dependency>-->
97 103
		<dependency>
98 104
			<groupId>net.sf.saxon</groupId>
99 105
			<artifactId>Saxon-HE</artifactId>

Also available in: Unified diff