QueryTemplate is now created only one time
This commit is contained in:
parent
662f3a90f2
commit
6df1eed2c2
|
@ -74,11 +74,46 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
|
|||
public static final String GET_ACCESS_POINT_FACET_OF_SOLR_SERVICE_FILENAME = "09-get-access-point-facet-of-solr-service.json";
|
||||
|
||||
private static String queryTemplateName;
|
||||
private static boolean queryTemplateFound;
|
||||
|
||||
static {
|
||||
queryTemplateFound = false;
|
||||
queryTemplateName = null;
|
||||
ResourceRegistryQueryTemplateClient rrqtc = ResourceRegistryQueryTemplateClientFactory.create();
|
||||
try {
|
||||
queryTemplateName = installQueryTemplate(rrqtc);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static QueryTemplate getQueryTemplate() throws Exception {
|
||||
File queryTemplateFile = getJsonQueryTemplateFromFile(GET_CALLS_FOR_QUERY_TEMPLATE_FILENAME);
|
||||
QueryTemplate queryTemplate = ElementMapper.unmarshal(QueryTemplate.class, new FileReader(queryTemplateFile));
|
||||
return queryTemplate;
|
||||
}
|
||||
|
||||
protected static String installQueryTemplate(ResourceRegistryQueryTemplateClient rrqtc) throws Exception {
|
||||
QueryTemplate queryTemplate = getQueryTemplate();
|
||||
/*
|
||||
* Going to create/update the query template.
|
||||
* No need to test if exists and/or if is the last version.
|
||||
*/
|
||||
queryTemplate = rrqtc.update(queryTemplate);
|
||||
|
||||
return queryTemplate.getName();
|
||||
}
|
||||
|
||||
protected static File getFile(String directoryName, String filename) throws Exception {
|
||||
URL directoryURL = FacetBasedISConfigurationProxy.class.getClassLoader().getResource(directoryName);
|
||||
File directory = new File(directoryURL.toURI());
|
||||
return new File(directory, filename);
|
||||
}
|
||||
|
||||
protected static File getJsonQueryTemplateFromFile(String filename) throws Exception {
|
||||
return getFile(QUERY_TEMPLATE_DIRECTORY_NAME, filename);
|
||||
}
|
||||
|
||||
protected static File getJsonQueryFromFile(String filename) throws Exception {
|
||||
return getFile(QUERY_DIRECTORY_NAME, filename);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -160,32 +195,9 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
|
|||
this.gcatEServiceID = gcatEServiceID;
|
||||
}
|
||||
|
||||
protected String installQueryTemplate(ResourceRegistryQueryTemplateClient rrqtc) throws Exception {
|
||||
QueryTemplate queryTemplate = getQueryTemplate();
|
||||
/*
|
||||
* Going to create/update the query template.
|
||||
* No need to test if exists and/or if is the last version.
|
||||
*/
|
||||
queryTemplate = rrqtc.update(queryTemplate);
|
||||
|
||||
FacetBasedISConfigurationProxy.queryTemplateFound = true;
|
||||
|
||||
return queryTemplate.getName();
|
||||
}
|
||||
|
||||
protected QueryTemplate getQueryTemplate() throws Exception {
|
||||
File queryTemplateFile = getJsonQueryTemplateFromFile(GET_CALLS_FOR_QUERY_TEMPLATE_FILENAME);
|
||||
QueryTemplate queryTemplate = ElementMapper.unmarshal(QueryTemplate.class, new FileReader(queryTemplateFile));
|
||||
return queryTemplate;
|
||||
}
|
||||
|
||||
public List<CallsFor<EService, VirtualService>> getCallsForToVirtualService() throws Exception {
|
||||
ResourceRegistryQueryTemplateClient rrqtc = ResourceRegistryQueryTemplateClientFactory.create();
|
||||
|
||||
if(!queryTemplateFound) {
|
||||
queryTemplateName = installQueryTemplate(rrqtc);
|
||||
}
|
||||
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
objectNode.put(GCAT_ESERVICE_UUID_VARNAME, gcatEServiceID);
|
||||
|
||||
|
@ -239,20 +251,6 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
|
|||
return callsFor;
|
||||
}
|
||||
|
||||
public File getFile(String directoryName, String filename) throws Exception {
|
||||
URL directoryURL = FacetBasedISConfigurationProxy.class.getClassLoader().getResource(directoryName);
|
||||
File directory = new File(directoryURL.toURI());
|
||||
return new File(directory, filename);
|
||||
}
|
||||
|
||||
public File getJsonQueryTemplateFromFile(String filename) throws Exception {
|
||||
return getFile(QUERY_TEMPLATE_DIRECTORY_NAME, filename);
|
||||
}
|
||||
|
||||
public File getJsonQueryFromFile(String filename) throws Exception {
|
||||
return getFile(QUERY_DIRECTORY_NAME, filename);
|
||||
}
|
||||
|
||||
protected List<Entity> queryListOfEntities(String query) throws Exception {
|
||||
logger.trace("Going to request the following query:\n{}", query);
|
||||
String result = resourceRegistryClient.jsonQuery(query);
|
||||
|
|
Loading…
Reference in New Issue