Added missing API and tests
This commit is contained in:
parent
764ff9eea6
commit
3ae07be6ce
|
@ -2,6 +2,8 @@ package org.gcube.informationsystem.resourceregistry.queries.templates;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
|
@ -28,6 +30,18 @@ public interface ResourceRegistryQueryTemplateClient {
|
|||
|
||||
public String update(String queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String runGetString(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <E extends Entity> List<E> run(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <E extends Entity> List<E> run(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String run(String name, String params) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <E extends Entity> List<E> run(String name, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <E extends Entity> List<E> run(QueryTemplate queryTemplate, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean delete(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean delete(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
|
||||
|
|
|
@ -5,8 +5,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
|
@ -175,6 +178,77 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String runGetString(String name) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
return run(name, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String run(String name, String params) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
if(params==null || params.compareTo("")==0) {
|
||||
logger.trace("Going to run {} using default parameters", QueryTemplate.NAME);
|
||||
params = null;
|
||||
}else {
|
||||
logger.trace("Going to run {} with the following parameters {}", QueryTemplate.NAME, params);
|
||||
}
|
||||
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(ResourceRegistryQueryTemplateClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(name);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(params);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
logger.trace("The result of the query is {}", c);
|
||||
return c;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Entity> List<E> run(String name) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String ret = runGetString(name);
|
||||
JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Entity.class);
|
||||
return ElementMapper.getObjectMapper().readValue(ret, type);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Entity> List<E> run(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
return run(queryTemplate.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Entity> List<E> run(String name, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String ret = run(name, objectMapper.writeValueAsString(jsonNode));
|
||||
JavaType type = ElementMapper.getObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Entity.class);
|
||||
return ElementMapper.getObjectMapper().readValue(ret, type);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Entity> List<E> run(QueryTemplate queryTemplate, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
return run(queryTemplate.getName(), jsonNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
|
||||
return delete(queryTemplate.getName());
|
||||
|
@ -196,7 +270,7 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
boolean deleted = true;
|
||||
|
||||
logger.info("{} with name {} {}", QueryTemplate.NAME, queryTemplateName,
|
||||
deleted ? " successfully deleted" : "was NOT deleted");
|
||||
deleted ? "successfully deleted" : "was NOT deleted");
|
||||
return deleted;
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
|
@ -206,5 +280,5 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import java.util.List;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
|
||||
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
|
||||
|
@ -108,6 +110,33 @@ public class ResourceRegistryQueryTemplateClientTest extends ContextTest {
|
|||
return queryTemplate;
|
||||
}
|
||||
|
||||
protected void run(QueryTemplate queryTemplate) throws Exception {
|
||||
|
||||
String ret = resourceRegistryQueryTemplateClient.runGetString(queryTemplate.getName());
|
||||
logger.debug("Run result is {}", ret);
|
||||
|
||||
List<Entity> entities = resourceRegistryQueryTemplateClient.run(queryTemplate.getName());
|
||||
logger.debug("Run result is {}", entities);
|
||||
|
||||
entities = resourceRegistryQueryTemplateClient.run(queryTemplate);
|
||||
logger.debug("Run result is {}", entities);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode params = objectMapper.createObjectNode();
|
||||
params.put(STATE_VARIABLE_NAME, "running");
|
||||
params.put(GROUP_VARIABLE_NAME, "DataAccess");
|
||||
params.put(NAME_VARIABLE_NAME, "StorageHub");
|
||||
|
||||
ret = resourceRegistryQueryTemplateClient.run(queryTemplate.getName(), objectMapper.writeValueAsString(params));
|
||||
logger.debug("Run result is {}", ret);
|
||||
|
||||
entities = resourceRegistryQueryTemplateClient.run(queryTemplate.getName(), params);
|
||||
logger.debug("Run result is {}", entities);
|
||||
|
||||
entities = resourceRegistryQueryTemplateClient.run(queryTemplate, params);
|
||||
logger.debug("Run result is {}", entities);
|
||||
}
|
||||
|
||||
protected QueryTemplate update(QueryTemplate queryTemplate) throws ResourceRegistryException, IOException {
|
||||
list(queryTemplate);
|
||||
|
||||
|
@ -229,6 +258,8 @@ public class ResourceRegistryQueryTemplateClientTest extends ContextTest {
|
|||
|
||||
QueryTemplate updatedQueryTemplate = update(readQueryTemplate);
|
||||
|
||||
run(updatedQueryTemplate);
|
||||
|
||||
QueryTemplate readUpdatedQueryTemplate = read(updatedQueryTemplate);
|
||||
|
||||
delete(readUpdatedQueryTemplate);
|
||||
|
|
Loading…
Reference in New Issue