Skip to content

Commit

Permalink
Feature/query microservices (#22)
Browse files Browse the repository at this point in the history
* merging latest changes from integration

* Updated with latest changes from integration

* bumped release version

* bumped versions for some modules

* Updated with latest changes from main/integration

* Added v1 to the model endpoints

* Updated tests to handle the "v1" in the model paths

* Updated package names for commons.lang3 classes due to type-utils fix

* review comments: made the restful paths consistent with other
microservices

* Revert "review comments: made the restful paths consistent with other"

This reverts commit 6914bfa.

---------

Co-authored-by: Ivan Bella <[email protected]>
  • Loading branch information
jwomeara and ivakegg authored May 20, 2024
1 parent 98b13bc commit bc520ef
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 39 deletions.
8 changes: 4 additions & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>gov.nsa.datawave.microservice</groupId>
<artifactId>datawave-microservice-parent</artifactId>
<version>3.0.4</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../microservice-parent/pom.xml</relativePath>
</parent>
<artifactId>dictionary-api</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<url>https://code.nsa.gov/datawave-dictionary-service</url>
<scm>
<connection>scm:git:https://github.com/NationalSecurityAgency/datawave-dictionary-service.git</connection>
Expand All @@ -18,9 +18,9 @@
</scm>
<properties>
<datawave.webservice.namespace>http://webservice.datawave.nsa/v1</datawave.webservice.namespace>
<version.base-responses>3.0.0</version.base-responses>
<version.base-responses>4.0.0-SNAPSHOT</version.base-responses>
<version.guava>31.1-jre</version.guava>
<version.microservice.metadata-utils>3.0.0</version.microservice.metadata-utils>
<version.microservice.metadata-utils>4.0.0-SNAPSHOT</version.microservice.metadata-utils>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
87 changes: 73 additions & 14 deletions api/src/main/java/datawave/webservice/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

import datawave.query.model.FieldMapping;
import datawave.webservice.HtmlProvider;
import datawave.webservice.result.BaseResponse;
import lombok.Data;

@Data
@XmlRootElement(name = "Model")
@XmlAccessorType(XmlAccessType.NONE)
public class Model extends BaseResponse implements Serializable, HtmlProvider {
Expand All @@ -40,15 +45,53 @@ public Model(String jqueryUri, String datatablesUri) {
public Model() {};

@XmlAttribute(name = "name", required = true)
private String name;
private String name = null;

@XmlElementWrapper(name = "Mappings")
@XmlElement(name = "Mapping")
private TreeSet<FieldMapping> fields = new TreeSet<FieldMapping>();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public TreeSet<FieldMapping> getFields() {
return fields;
}

public void setFields(TreeSet<FieldMapping> fields) {
this.fields = fields;
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).append(name).append(fields).toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == this)
return true;
if (obj.getClass() != this.getClass())
return false;
Model other = (Model) obj;
return new EqualsBuilder().append(name, other.name).append(fields, other.fields).isEquals();
}

@Override
public String toString() {
return new ToStringBuilder(this).append("name", name).append("fields", fields).toString();
}

/*
* (non-Javadoc)
*
*
* @see datawave.webservice.HtmlProvider#getTitle()
*/
@Override
Expand All @@ -58,7 +101,7 @@ public String getTitle() {

/*
* (non-Javadoc)
*
*
* @see datawave.webservice.HtmlProvider#getPageHeader()
*/
@Override
Expand All @@ -68,7 +111,7 @@ public String getPageHeader() {

/*
* (non-Javadoc)
*
*
* @see datawave.webservice.HtmlProvider#getHeadContent()
*/
@Override
Expand All @@ -78,7 +121,7 @@ public String getHeadContent() {

/*
* (non-Javadoc)
*
*
* @see datawave.webservice.HtmlProvider#getMainContent()
*/
@Override
Expand All @@ -89,16 +132,32 @@ public String getMainContent() {
builder.append("<div id=\"myTable_wrapper\" class=\"dataTables_wrapper no-footer\">\n");
builder.append("<table id=\"myTable\" class=\"dataTable no-footer\" role=\"grid\" aria-describedby=\"myTable_info\">\n");

builder.append("<thead><tr><th>Visibility</th><th>FieldName</th><th>DataType</th><th>ModelFieldName</th><th>Direction</th></tr></thead>");
builder.append("<thead><tr><th>Visibility</th><th>FieldName</th><th>DataType</th><th>ModelFieldName</th><th>Direction</th><th>Attributes</th></tr></thead>");
builder.append("<tbody>");

// first gather the model fields that are deemed "lenient" (i.e. where the model field name has a lenient attribute)
Multimap<String,String> modelFieldAttributes = HashMultimap.create();
for (FieldMapping field : this.getFields()) {
if (!field.isFieldMapping()) {
modelFieldAttributes.putAll(field.getModelFieldName(), field.getAttributes());
}
}

for (FieldMapping f : this.getFields()) {
builder.append("<td>").append(f.getColumnVisibility()).append("</td>");
builder.append("<td>").append(f.getFieldName()).append("</td>");
builder.append("<td>").append(f.getDatatype()).append("</td>");
builder.append("<td>").append(f.getModelFieldName()).append("</td>");
builder.append("<td>").append(f.getDirection()).append("</td>");
builder.append("</tr>");
// don't include model field attributes
if (f.isFieldMapping()) {
builder.append("<td>").append(f.getColumnVisibility()).append("</td>");
builder.append("<td>").append(f.getFieldName()).append("</td>");
builder.append("<td>").append(f.getDatatype()).append("</td>");
builder.append("<td>").append(f.getModelFieldName()).append("</td>");
builder.append("<td>").append(f.getDirection()).append("</td>");
TreeSet<String> attributes = new TreeSet<>(f.getAttributes());
if (modelFieldAttributes.containsKey(f.getModelFieldName())) {
attributes.addAll(modelFieldAttributes.get(f.getModelFieldName()));
}
builder.append("<td>").append(attributes).append("</td>");
builder.append("</tr>");
}
}

builder.append("</tbody>");
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>gov.nsa.datawave.microservice</groupId>
<artifactId>datawave-microservice-parent</artifactId>
<version>3.0.4</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../microservice-parent/pom.xml</relativePath>
</parent>
<artifactId>dictionary-service-parent</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<url>https://code.nsa.gov/datawave-dictionary-service</url>
<modules>
Expand Down
12 changes: 6 additions & 6 deletions service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>gov.nsa.datawave.microservice</groupId>
<artifactId>datawave-microservice-service-parent</artifactId>
<version>4.0.4</version>
<version>5.0.0-SNAPSHOT</version>
<relativePath>../../../microservice-service-parent/pom.xml</relativePath>
</parent>
<artifactId>dictionary-service</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<description>DATAWAVE Dictionary Service</description>
<url>https://code.nsa.gov/datawave-dictionary-service</url>
<scm>
Expand All @@ -21,10 +21,10 @@
<start-class>datawave.microservice.dictionary.DictionaryService</start-class>
<version.accumulo>2.1.1</version.accumulo>
<version.curator>5.2.0</version.curator>
<version.in-memory-accumulo>3.0.1</version.in-memory-accumulo>
<version.microservice.dictionary-api>3.0.0</version.microservice.dictionary-api>
<version.microservice.starter>3.0.0</version.microservice.starter>
<version.microservice.starter-metadata>2.0.0</version.microservice.starter-metadata>
<version.in-memory-accumulo>4.0.0-SNAPSHOT</version.in-memory-accumulo>
<version.microservice.dictionary-api>4.0.0-SNAPSHOT</version.microservice.dictionary-api>
<version.microservice.starter>4.0.0-SNAPSHOT</version.microservice.starter>
<version.microservice.starter-metadata>3.0.0-SNAPSHOT</version.microservice.starter-metadata>
<version.webjars.datatables>1.11.4</version.webjars.datatables>
<version.webjars.jquery>3.6.0</version.webjars.jquery>
<version.webjars.locator>0.50</version.webjars.locator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
url = "https://github.com/NationalSecurityAgency/datawave-dictionary-service"))
@Slf4j
@RestController
@RequestMapping(path = "/model",
@RequestMapping(path = "/model/v1",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE,
ProtostuffHttpMessageConverter.PROTOSTUFF_VALUE, MediaType.TEXT_HTML_VALUE, "text/x-yaml", "application/x-yaml"})
@Secured({"AuthorizedUser", "AuthorizedQueryServer", "InternalUser", "Administrator", "JBossAdministrator"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testList() {
// @formatter:off
UriComponents uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -130,7 +130,7 @@ public void testImportAKAInsert() {
// @formatter:off
UriComponents uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -142,7 +142,7 @@ public void testImportAKAInsert() {
// @formatter:off
uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/import")
.path("/dictionary/model/v1/import")
.build();
// @formatter:on

Expand All @@ -157,7 +157,7 @@ public void testImportAKAInsert() {
// @formatter:off
uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -172,7 +172,7 @@ public void testClone() {
// @formatter:off
UriComponents uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -185,7 +185,7 @@ public void testClone() {
// @formatter:off
uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/clone")
.path("/dictionary/model/v1/clone")
.queryParam("name", MODEL_ONE.getName())
.queryParam("newName", newName)
.build();
Expand All @@ -199,7 +199,7 @@ public void testClone() {
assertEquals(HttpStatus.OK, imprtResponse.getStatusCode());

// There should now be 2 models....
uri = UriComponentsBuilder.newInstance().scheme("https").host("localhost").port(webServicePort).path("/dictionary/model/list").build();
uri = UriComponentsBuilder.newInstance().scheme("https").host("localhost").port(webServicePort).path("/dictionary/model/v1/list").build();
// @formatter:on

ResponseEntity<ModelList> modelListResponse2 = jwtRestTemplate.exchange(adminUser, HttpMethod.GET, uri, ModelList.class);
Expand All @@ -216,7 +216,7 @@ public void testGet() {
// @formatter:off
UriComponents uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -228,7 +228,7 @@ public void testGet() {
// @formatter:off
uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/{name}")
.path("/dictionary/model/v1/{name}")
.queryParam("name", MODEL_ONE.getName())
.build();
// @formatter:on
Expand All @@ -243,7 +243,7 @@ public void testDelete() {
// @formatter:off
UriComponents uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/list")
.path("/dictionary/model/v1/list")
.build();
// @formatter:on

Expand All @@ -255,7 +255,7 @@ public void testDelete() {
// @formatter:off
uri = UriComponentsBuilder.newInstance()
.scheme("https").host("localhost").port(webServicePort)
.path("/dictionary/model/delete")
.path("/dictionary/model/v1/delete")
.build();
// @formatter:on
HttpHeaders additionalHeaders = new HttpHeaders();
Expand All @@ -265,7 +265,7 @@ public void testDelete() {
assertEquals(HttpStatus.OK, imprtResponse.getStatusCode());

// Verify that it was deleted
uri = UriComponentsBuilder.newInstance().scheme("https").host("localhost").port(webServicePort).path("/dictionary/model/list").build();
uri = UriComponentsBuilder.newInstance().scheme("https").host("localhost").port(webServicePort).path("/dictionary/model/v1/list").build();
// @formatter:on

ResponseEntity<ModelList> modelListResponse2 = jwtRestTemplate.exchange(adminUser, HttpMethod.GET, uri, ModelList.class);
Expand Down

0 comments on commit bc520ef

Please sign in to comment.