Revision 51418
Added by Alessia Bardi about 6 years ago
CatalogueAPIClient.java | ||
---|---|---|
33 | 33 |
private final String createItemPath = "rest/api/items/create"; |
34 | 34 |
private final String showItemPath = "rest/api/items/show"; //param id |
35 | 35 |
private final String purgeItemPath = "rest/api/items/purge"; |
36 |
private final String showGroupPath = "rest/api/groups/show"; //param id |
|
37 |
private final String createGroupPath = "rest/api/groups/create"; |
|
36 | 38 |
private String purgeBodyTemplate = "{\"id\":\"%s\"}"; |
37 | 39 |
|
38 | 40 |
@Autowired |
... | ... | |
58 | 60 |
} catch (Throwable t) { |
59 | 61 |
throw new ParthenosPublisherException(t); |
60 | 62 |
} |
61 |
|
|
62 | 63 |
} |
63 | 64 |
|
64 | 65 |
/** |
... | ... | |
88 | 89 |
} |
89 | 90 |
} |
90 | 91 |
|
92 |
public boolean groupExist(final String groupName) throws ParthenosPublisherException { |
|
93 |
log.debug(String.format("Catalogue --> Checking if %s exists", groupName)); |
|
94 |
HttpEntity<String> entity = new HttpEntity<String>(getHeaders()); |
|
95 |
try { |
|
96 |
URI uri = new URIBuilder(getBaseURL()+showGroupPath).addParameter("gcube-token", getApplicationToken()).addParameter("id", groupName).build(); |
|
97 |
ResponseEntity<String> res = jrrRestTemplate.<String>exchange(uri, HttpMethod.GET, entity, String.class); |
|
98 |
CatalogueAPIResponse response = new CatalogueAPIResponse(); |
|
99 |
response.setResponseBody(res.getBody()); |
|
100 |
return response.isSuccess(); |
|
101 |
} catch (Throwable t) { |
|
102 |
throw new ParthenosPublisherException(t); |
|
103 |
} |
|
104 |
} |
|
91 | 105 |
|
106 |
public boolean registerGroup(final String json, final String groupName) throws URISyntaxException, IOException { |
|
107 |
log.debug(String.format("Catalogue --> Registering group %s : %s", groupName, json)); |
|
108 |
HttpEntity<String> entity = new HttpEntity<String>(json, getHeaders()); |
|
109 |
URI uri = new URIBuilder(getBaseURL() + createGroupPath).addParameter("gcube-token", getApplicationToken()).build(); |
|
110 |
ResponseEntity<String> res = jrrRestTemplate.exchange(uri, HttpMethod.POST, entity, String.class); |
|
111 |
CatalogueAPIResponse response = new CatalogueAPIResponse(); |
|
112 |
if (res.getStatusCode() == HttpStatus.OK) { |
|
113 |
String body = res.getBody(); |
|
114 |
response.setResponseBody(body); |
|
115 |
if (!response.isSuccess()) |
|
116 |
log.warn(groupName + " could not be added because of " + response.getErrorMessage()); |
|
117 |
return response.isSuccess(); |
|
118 |
} else { |
|
119 |
log.warn(groupName + " POST FAILED: " + res.getStatusCodeValue()); |
|
120 |
return false; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
|
|
92 | 125 |
protected boolean purge(final String resCatName) throws URISyntaxException, IOException { |
93 | 126 |
log.debug(String.format("Catalogue --> Purge %s", resCatName)); |
94 | 127 |
String body = String.format(purgeBodyTemplate, resCatName); |
Also available in: Unified diff
Ensure the provider names are already registered as catalogue groups