> pdResults = new HashMap<>();
+ pdResults.put("PDResults", searchResults);
+
+ return new GsonBuilder().create().toJson(pdResults);
+ }
+
+ /**
+ * Builds a List of Measurement Hierarchies given the individual source lists.
+ * The hierarchy is built from the element in the same position from each input list in the order: Topic -> Term -> Variable -> VariableDetail
+ * "None" and blank strings are ignored. If, at any level, an element does not exist for that position or it is "None" or blank, that hierarchy is considered complete.
+ *
+ * For example, if the input is:
+ *
+ * topics = ["Oceans", "Oceans"]
+ * terms = ["Sea Surface Topography", "Ocean Waves"]
+ * variables = ["Sea Surface Height", "Significant Wave Height"]
+ * variableDetails = ["None", "None"]
+ *
+ *
+ * The output would be:
+ *
+ * [
+ * ["Oceans", "Sea Surface Topography", "Sea Surface Height"],
+ * ["Oceans", "Ocean Waves", "Significant Wave Height"]
+ * ]
+ *
+ * Oceans > Sea Surface Topography > Sea Surface Height
+ * Oceans > Ocean Waves > Significant Wave Height
+ *
+ * @param topics List of topics, the first element of a measurement
+ * @param terms List of terms, the second element of a measurement
+ * @param variables List of variables, the third element of a measurement
+ * @param variableDetails List of variable details, the fourth element of a measurement
+ *
+ * @return A List where each element is a single hierarchy (as a List) built from the provided input lists.
+ */
+ @Override
+ public List> buildMeasurementHierarchies(List topics, List terms, List variables, List variableDetails) {
+ List> measurements = new ArrayList<>();
+
+ for (int x = 0; x < topics.size(); x++) {
+ measurements.add(new ArrayList<>());
+ measurements.get(x).add(topics.get(x));
+ // Only add the next 'level' if we can
+ if (x < terms.size() && !"None".equalsIgnoreCase(terms.get(x)) && StringUtils.isNotBlank(terms.get(x))) {
+ measurements.get(x).add(terms.get(x));
+ if (x < variables.size() && !"None".equalsIgnoreCase(variables.get(x)) && StringUtils.isNotBlank(variables.get(x))) {
+ measurements.get(x).add(variables.get(x));
+ if (x < variableDetails.size() && !"None".equalsIgnoreCase(variableDetails.get(x)) && StringUtils.isNotBlank(variableDetails.get(x))) {
+ measurements.get(x).add(variableDetails.get(x));
+ }
+ }
+ }
+ }
+
+ return measurements;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#autoComplete(java.lang.String, java.lang.String)
+ */
+ @Override
+ public List autoComplete(String index, String term) {
+ boolean exists = this.getClient().admin().indices().prepareExists(index).execute().actionGet().isExists();
+ if (!exists) {
+ return new ArrayList<>();
+ }
+
+ Set suggestHS = new HashSet<>();
+ List suggestList = new ArrayList<>();
+
+ // please make sure that the completion field is configured in the ES mapping
+ CompletionSuggestionBuilder suggestionsBuilder = SuggestBuilders.completionSuggestion("Dataset-Metadata").prefix(term, Fuzziness.fromEdits(2)).size(100);
+ SearchRequestBuilder suggestRequestBuilder = getClient().prepareSearch(index).suggest(new SuggestBuilder().addSuggestion("completeMe", suggestionsBuilder));
+ SearchResponse sr = suggestRequestBuilder.setFetchSource(false).execute().actionGet();
+
+ Iterator extends Suggest.Suggestion.Entry.Option> iterator = sr.getSuggest().getSuggestion("completeMe").iterator().next().getOptions().iterator();
+
+ while (iterator.hasNext()) {
+ Suggest.Suggestion.Entry.Option next = iterator.next();
+ String suggest = next.getText().string().toLowerCase();
+ suggestList.add(suggest);
+ }
+
+ suggestHS.addAll(suggestList);
+ suggestList.clear();
+ suggestList.addAll(suggestHS);
+ return suggestList;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#close()
+ */
+ @Override
+ public void close() {
+ client.close();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#refreshIndex()
+ */
+ @Override
+ public void refreshIndex() {
+ client.admin().indices().prepareRefresh().execute().actionGet();
+ }
+
+ /**
+ * Generates a TransportClient or NodeClient
+ *
+ * @param props a populated {@link java.util.Properties} object
+ * @return a constructed {@link org.elasticsearch.client.Client}
+ * @throws IOException if there is an error building the
+ * {@link org.elasticsearch.client.Client}
+ */
+ protected Client makeClient(Properties props) throws IOException {
+ String clusterName = props.getProperty(MudrodConstants.ES_CLUSTER);
+ String hostsString = props.getProperty(MudrodConstants.ES_UNICAST_HOSTS);
+ String[] hosts = hostsString.split(",");
+ String portStr = props.getProperty(MudrodConstants.ES_TRANSPORT_TCP_PORT);
+ int port = Integer.parseInt(portStr);
+
+ Settings.Builder settingsBuilder = Settings.builder();
+
+ // Set the cluster name and build the settings
+ if (!clusterName.isEmpty())
+ settingsBuilder.put("cluster.name", clusterName);
+
+ settingsBuilder.put("http.type", "netty3");
+ settingsBuilder.put("transport.type", "netty3");
+
+ Settings settings = settingsBuilder.build();
+
+ Client client = null;
+
+ // Prefer TransportClient
+ if (hosts != null && port > 1) {
+ TransportClient transportClient = new ESTransportClient(settings);
+ for (String host : hosts)
+ transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
+ client = transportClient;
+ } else if (clusterName != null) {
+ node = new Node(settings);
+ client = node.client();
+ }
+
+ return client;
+ }
+
+ /**
+ * @return the client
+ */
+ public Client getClient() {
+ return client;
+ }
+
+ /**
+ * @param client the client to set
+ */
+ public void setClient(Client client) {
+ this.client = client;
+ }
+
+ /**
+ * @return the bulkProcessor
+ */
+ public BulkProcessor getBulkProcessor() {
+ return bulkProcessor;
+ }
+
+ /**
+ * @param bulkProcessor the bulkProcessor to set
+ */
+ public void setBulkProcessor(BulkProcessor bulkProcessor) {
+ this.bulkProcessor = bulkProcessor;
+ }
+
+ public UpdateRequest generateUpdateRequest(String index, String type, String id, String field1, Object value1) {
+
+ UpdateRequest ur = null;
+ try {
+ ur = new UpdateRequest(index, type, id).doc(jsonBuilder().startObject().field(field1, value1).endObject());
+ } catch (IOException e) {
+ LOG.error("Error whilst attempting to generate a new Update Request.", e);
+ }
+
+ return ur;
+ }
+
+ public UpdateRequest generateUpdateRequest(String index, String type, String id, Map filedValueMap) {
+
+ UpdateRequest ur = null;
+ try {
+ XContentBuilder builder = jsonBuilder().startObject();
+ for (Entry entry : filedValueMap.entrySet()) {
+ String key = entry.getKey();
+ builder.field(key, filedValueMap.get(key));
+ }
+ builder.endObject();
+ ur = new UpdateRequest(index, type, id).doc(builder);
+ } catch (IOException e) {
+ LOG.error("Error whilst attempting to generate a new Update Request.", e);
+ }
+
+ return ur;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getDocCount(java.lang.String, java.lang.String[])
+ */
+ @Override
+ public int getDocCount(String index, String... type) {
+ MatchAllQueryBuilder search = QueryBuilders.matchAllQuery();
+ String[] indexArr = new String[] { index };
+ return this.getDocCount(indexArr, type, search);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getDocCount(java.lang.String[], java.lang.String[])
+ */
+ @Override
+ public int getDocCount(String[] index, String[] type) {
+ MatchAllQueryBuilder search = QueryBuilders.matchAllQuery();
+ return this.getDocCount(index, type, search);
+ }
+
+ public int getDocCount(String[] index, String[] type, QueryBuilder filterSearch) {
+ SearchRequestBuilder countSrBuilder = getClient().prepareSearch(index).setTypes(type).setQuery(filterSearch).setSize(0);
+ SearchResponse countSr = countSrBuilder.execute().actionGet();
+ int docCount = (int) countSr.getHits().getTotalHits();
+ return docCount;
+ }
+
+}
diff --git a/storage/src/main/java/org/apache/sdap/mudrod/storage/elasticsearch/package-info.java b/storage/src/main/java/org/apache/sdap/mudrod/storage/elasticsearch/package-info.java
new file mode 100644
index 0000000..107ff51
--- /dev/null
+++ b/storage/src/main/java/org/apache/sdap/mudrod/storage/elasticsearch/package-info.java
@@ -0,0 +1,14 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sdap.mudrod.storage.elasticsearch;
\ No newline at end of file
diff --git a/storage/src/main/java/org/apache/sdap/mudrod/storage/package-info.java b/storage/src/main/java/org/apache/sdap/mudrod/storage/package-info.java
new file mode 100644
index 0000000..af07a01
--- /dev/null
+++ b/storage/src/main/java/org/apache/sdap/mudrod/storage/package-info.java
@@ -0,0 +1,14 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sdap.mudrod.storage;
\ No newline at end of file
diff --git a/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/SolrDriver.java b/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/SolrDriver.java
new file mode 100644
index 0000000..58fac37
--- /dev/null
+++ b/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/SolrDriver.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sdap.mudrod.storage.solr;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.sdap.mudrod.storage.StorageDriver;
+
+/**
+ *
+ */
+public class SolrDriver implements StorageDriver {
+
+ /**
+ * @param props
+ *
+ */
+ public SolrDriver(Properties props) {
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#createBulkProcessor()
+ */
+ @Override
+ public void createBulkProcessor() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#destroyBulkProcessor()
+ */
+ @Override
+ public void destroyBulkProcessor() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#putMapping(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void putMapping(String indexName, String settingsJson, String mappingJson) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#customAnalyzing(java.lang.String, java.lang.String)
+ */
+ @Override
+ public String customAnalyzing(String indexName, String str) throws InterruptedException, ExecutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#customAnalyzing(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public String customAnalyzing(String indexName, String analyzer, String str) throws InterruptedException, ExecutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#customAnalyzing(java.lang.String, java.util.List)
+ */
+ @Override
+ public List customAnalyzing(String indexName, List list) throws InterruptedException, ExecutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#deleteType(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void deleteType(String index, String type) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getTypeListWithPrefix(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public List getTypeListWithPrefix(Object object, Object object2) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getIndexListWithPrefix(java.lang.Object)
+ */
+ @Override
+ public List getIndexListWithPrefix(Object object) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#searchByQuery(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public String searchByQuery(String index, String type, String query) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#searchByQuery(java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean)
+ */
+ @Override
+ public String searchByQuery(String index, String type, String query, Boolean bDetail) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#buildMeasurementHierarchies(java.util.List, java.util.List, java.util.List, java.util.List)
+ */
+ @Override
+ public List> buildMeasurementHierarchies(List topics, List terms, List variables, List variableDetails) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#autoComplete(java.lang.String, java.lang.String)
+ */
+ @Override
+ public List autoComplete(String index, String term) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#close()
+ */
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#refreshIndex()
+ */
+ @Override
+ public void refreshIndex() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getDocCount(java.lang.String, java.lang.String[])
+ */
+ @Override
+ public int getDocCount(String index, String... type) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.sdap.mudrod.storage.StorageDriver#getDocCount(java.lang.String[], java.lang.String[])
+ */
+ @Override
+ public int getDocCount(String[] index, String[] type) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
diff --git a/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/package-info.java b/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/package-info.java
new file mode 100644
index 0000000..1c48a7e
--- /dev/null
+++ b/storage/src/main/java/org/apache/sdap/mudrod/storage/solr/package-info.java
@@ -0,0 +1,14 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sdap.mudrod.storage.solr;
\ No newline at end of file
diff --git a/web/pom.xml b/web/pom.xml
index 3b637b0..e6f58da 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -17,7 +17,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- org.apache.sdap.mudrod
+ org.apache.sdap
mudrod-web
0.0.1-SNAPSHOT