Fixing listing method
This commit is contained in:
parent
b14e1626ba
commit
69d24faf54
|
@ -12,6 +12,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templ
|
|||
*/
|
||||
public interface ResourceRegistryQueryTemplateClient {
|
||||
|
||||
public List<String> all() throws ResourceRegistryException;
|
||||
|
||||
public QueryTemplate create(QueryTemplate queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String create(String queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;
|
||||
|
@ -30,6 +32,4 @@ public interface ResourceRegistryQueryTemplateClient {
|
|||
|
||||
public boolean delete(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public List<QueryTemplate> all() throws ResourceRegistryException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package org.gcube.informationsystem.resourceregistry.queries.templates;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
|
@ -28,6 +30,32 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> all() throws ResourceRegistryException {
|
||||
try {
|
||||
logger.trace("Going to list {}s", QueryTemplate.NAME);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(ResourceRegistryQueryTemplateClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
logger.debug("Got {}s are {}", QueryTemplate.NAME, all);
|
||||
|
||||
JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, String.class);
|
||||
return ElementMapper.getObjectMapper().readValue(all, type);
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryTemplate create(QueryTemplate queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
|
@ -179,28 +207,4 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueryTemplate> all() throws ResourceRegistryException {
|
||||
try {
|
||||
logger.trace("Going to list {}s", QueryTemplate.NAME);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(ResourceRegistryQueryTemplateClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
logger.debug("Got {}s are {}", QueryTemplate.NAME, all);
|
||||
return ElementMapper.unmarshalList(QueryTemplate.class, all);
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue