Skip to content

Commit 7772cdc

Browse files
authored
Merge pull request #71 from cmgrote/master
Implements initial serde for search result entities
2 parents ed8a7ae + e248930 commit 7772cdc

File tree

6 files changed

+392
-6
lines changed

6 files changed

+392
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2020 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ibm.watson.data.client.model;
17+
18+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
19+
import com.ibm.watson.data.client.serde.AbstractSearchResultEntityDeserializer;
20+
21+
/**
22+
* AbstractSearchResultEntity
23+
*/
24+
@JsonDeserialize(using = AbstractSearchResultEntityDeserializer.class)
25+
public class AbstractSearchResultEntity {
26+
27+
/**
28+
* Convert the given object to string with each line indented by 4 spaces
29+
* (except the first line).
30+
* @param o to indent
31+
* @return String indented
32+
*/
33+
protected String toIndentedString(java.lang.Object o) {
34+
if (o == null) { return "null"; }
35+
return o.toString().replace("\n", "\n ");
36+
}
37+
38+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2020 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ibm.watson.data.client.model;
17+
18+
import com.fasterxml.jackson.annotation.JsonInclude;
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.databind.JsonDeserializer;
21+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22+
23+
import java.util.Date;
24+
import java.util.List;
25+
import java.util.Objects;
26+
27+
/**
28+
* ArtifactSearchResultEntity
29+
*/
30+
@JsonDeserialize(using = JsonDeserializer.None.class)
31+
public class ArtifactSearchResultEntity extends AbstractSearchResultEntity {
32+
33+
private List<String> synonymGlobalIds;
34+
private List<String> synonyms;
35+
private String globalId;
36+
private Date effectiveStartDate;
37+
private String versionId;
38+
private List<String> abbreviation;
39+
private String artifactId;
40+
41+
@javax.annotation.Nullable
42+
@JsonProperty("synonym_global_ids")
43+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
44+
public List<String> getSynonymGlobalIds() { return synonymGlobalIds; }
45+
public void setSynonymGlobalIds(List<String> synonymGlobalIds) { this.synonymGlobalIds = synonymGlobalIds; }
46+
47+
@javax.annotation.Nullable
48+
@JsonProperty("synonyms")
49+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
50+
public List<String> getSynonyms() { return synonyms; }
51+
public void setSynonyms(List<String> synonyms) { this.synonyms = synonyms; }
52+
53+
@javax.annotation.Nullable
54+
@JsonProperty("global_id")
55+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
56+
public String getGlobalId() { return globalId; }
57+
public void setGlobalId(String globalId) { this.globalId = globalId; }
58+
59+
@javax.annotation.Nullable
60+
@JsonProperty("effective_start_date")
61+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
62+
public Date getEffectiveStartDate() { return effectiveStartDate; }
63+
public void setEffectiveStartDate(Date effectiveStartDate) { this.effectiveStartDate = effectiveStartDate; }
64+
65+
@javax.annotation.Nullable
66+
@JsonProperty("version_id")
67+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
68+
public String getVersionId() { return versionId; }
69+
public void setVersionId(String versionId) { this.versionId = versionId; }
70+
71+
@javax.annotation.Nullable
72+
@JsonProperty("abbreviation")
73+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
74+
public List<String> getAbbreviation() { return abbreviation; }
75+
public void setAbbreviation(List<String> abbreviation) { this.abbreviation = abbreviation; }
76+
77+
@javax.annotation.Nullable
78+
@JsonProperty("artifact_id")
79+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
80+
public String getArtifactId() { return artifactId; }
81+
public void setArtifactId(String artifactId) { this.artifactId = artifactId; }
82+
83+
@Override
84+
public boolean equals(Object o) {
85+
if (this == o) return true;
86+
if (o == null || getClass() != o.getClass()) return false;
87+
ArtifactSearchResultEntity that = (ArtifactSearchResultEntity) o;
88+
return Objects.equals(synonymGlobalIds, that.synonymGlobalIds) &&
89+
Objects.equals(synonyms, that.synonyms) &&
90+
Objects.equals(globalId, that.globalId) &&
91+
Objects.equals(effectiveStartDate, that.effectiveStartDate) &&
92+
Objects.equals(versionId, that.versionId) &&
93+
Objects.equals(abbreviation, that.abbreviation) &&
94+
Objects.equals(artifactId, that.artifactId);
95+
}
96+
97+
@Override
98+
public int hashCode() {
99+
return Objects.hash(synonymGlobalIds, synonyms, globalId, effectiveStartDate,
100+
versionId, abbreviation, artifactId);
101+
}
102+
103+
@Override
104+
public String toString() {
105+
StringBuilder sb = new StringBuilder();
106+
sb.append("class ArtifactSearchResultEntity {\n");
107+
sb.append(" synonymGlobalIds: ").append(toIndentedString(synonymGlobalIds)).append("\n");
108+
sb.append(" synonyms: ").append(toIndentedString(synonyms)).append("\n");
109+
sb.append(" globalId: ").append(toIndentedString(globalId)).append("\n");
110+
sb.append(" effectiveStartDate: ").append(toIndentedString(effectiveStartDate)).append("\n");
111+
sb.append(" versionId: ").append(toIndentedString(versionId)).append("\n");
112+
sb.append(" abbreviation: ").append(toIndentedString(abbreviation)).append("\n");
113+
sb.append(" artifactId: ").append(toIndentedString(artifactId)).append("\n");
114+
sb.append("}");
115+
return sb.toString();
116+
}
117+
118+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2020 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ibm.watson.data.client.model;
17+
18+
import com.fasterxml.jackson.annotation.JsonInclude;
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.databind.JsonDeserializer;
21+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22+
23+
import java.util.List;
24+
import java.util.Objects;
25+
26+
/**
27+
* AssetSearchResultEntity
28+
*/
29+
@JsonDeserialize(using = JsonDeserializer.None.class)
30+
public class AssetSearchResultEntity extends AbstractSearchResultEntity {
31+
32+
private String catalogId;
33+
private List<String> connectionPaths;
34+
private String resourceKey;
35+
private List<String> columnTerms;
36+
private List<String> columnDataClassNames;
37+
private List<String> columnTermsGlobalIds;
38+
private List<String> columnNames;
39+
private List<String> columnTags;
40+
private List<String> connectionIds;
41+
42+
@javax.annotation.Nullable
43+
@JsonProperty("catalog_id")
44+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
45+
public String getCatalogId() { return catalogId; }
46+
public void setCatalogId(String catalogId) { this.catalogId = catalogId; }
47+
48+
@javax.annotation.Nullable
49+
@JsonProperty("connection_paths")
50+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
51+
public List<String> getConnectionPaths() { return connectionPaths; }
52+
public void setConnectionPaths(List<String> connectionPaths) { this.connectionPaths = connectionPaths; }
53+
54+
@javax.annotation.Nullable
55+
@JsonProperty("resource_key")
56+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
57+
public String getResourceKey() { return resourceKey; }
58+
public void setResourceKey(String resourceKey) { this.resourceKey = resourceKey; }
59+
60+
@javax.annotation.Nullable
61+
@JsonProperty("column_terms")
62+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
63+
public List<String> getColumnTerms() { return columnTerms; }
64+
public void setColumnTerms(List<String> columnTerms) { this.columnTerms = columnTerms; }
65+
66+
@javax.annotation.Nullable
67+
@JsonProperty("column_data_class_names")
68+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
69+
public List<String> getColumnDataClassNames() { return columnDataClassNames; }
70+
public void setColumnDataClassNames(List<String> columnDataClassNames) { this.columnDataClassNames = columnDataClassNames; }
71+
72+
@javax.annotation.Nullable
73+
@JsonProperty("column_terms_global_ids")
74+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
75+
public List<String> getColumnTermsGlobalIds() { return columnTermsGlobalIds; }
76+
public void setColumnTermsGlobalIds(List<String> columnTermsGlobalIds) { this.columnTermsGlobalIds = columnTermsGlobalIds; }
77+
78+
@javax.annotation.Nullable
79+
@JsonProperty("column_names")
80+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
81+
public List<String> getColumnNames() { return columnNames; }
82+
public void setColumnNames(List<String> columnNames) { this.columnNames = columnNames; }
83+
84+
@javax.annotation.Nullable
85+
@JsonProperty("column_tags")
86+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
87+
public List<String> getColumnTags() { return columnTags; }
88+
public void setColumnTags(List<String> columnTags) { this.columnTags = columnTags; }
89+
90+
@javax.annotation.Nullable
91+
@JsonProperty("connection_ids")
92+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
93+
public List<String> getConnectionIds() { return connectionIds; }
94+
public void setConnectionIds(List<String> connectionIds) { this.connectionIds = connectionIds; }
95+
96+
@Override
97+
public boolean equals(Object o) {
98+
if (this == o) return true;
99+
if (o == null || getClass() != o.getClass()) return false;
100+
AssetSearchResultEntity that = (AssetSearchResultEntity) o;
101+
return Objects.equals(catalogId, that.catalogId) &&
102+
Objects.equals(connectionPaths, that.connectionPaths) &&
103+
Objects.equals(resourceKey, that.resourceKey) &&
104+
Objects.equals(columnTerms, that.columnTerms) &&
105+
Objects.equals(columnDataClassNames, that.columnDataClassNames) &&
106+
Objects.equals(columnTermsGlobalIds, that.columnTermsGlobalIds) &&
107+
Objects.equals(columnNames, that.columnNames) &&
108+
Objects.equals(columnTags, that.columnTags) &&
109+
Objects.equals(connectionIds, that.connectionIds);
110+
}
111+
112+
@Override
113+
public int hashCode() {
114+
return Objects.hash(catalogId, connectionPaths, resourceKey, columnTerms,
115+
columnDataClassNames, columnTermsGlobalIds, columnNames, columnTags,
116+
connectionIds);
117+
}
118+
119+
@Override
120+
public String toString() {
121+
StringBuilder sb = new StringBuilder();
122+
sb.append("class AssetSearchResultEntity {\n");
123+
sb.append(" catalogId: ").append(toIndentedString(catalogId)).append("\n");
124+
sb.append(" connectionPaths: ").append(toIndentedString(connectionPaths)).append("\n");
125+
sb.append(" resourceKey: ").append(toIndentedString(resourceKey)).append("\n");
126+
sb.append(" columnTerms: ").append(toIndentedString(columnTerms)).append("\n");
127+
sb.append(" columnDataClassNames: ").append(toIndentedString(columnDataClassNames)).append("\n");
128+
sb.append(" columnTermsGlobalIds: ").append(toIndentedString(columnTermsGlobalIds)).append("\n");
129+
sb.append(" columnNames: ").append(toIndentedString(columnNames)).append("\n");
130+
sb.append(" columnTags: ").append(toIndentedString(columnTags)).append("\n");
131+
sb.append(" connectionIds: ").append(toIndentedString(connectionIds)).append("\n");
132+
sb.append("}");
133+
return sb.toString();
134+
}
135+
136+
}

java/src/main/java/com/ibm/watson/data/client/model/SearchResultRow.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
23+
import java.util.Map;
2324
import java.util.Objects;
2425

2526
/**
@@ -35,7 +36,7 @@ public class SearchResultRow {
3536
private SearchResultCategories categories;
3637
private List<CustomAttribute> customAttributes = null;
3738
private SearchResultMetadata metadata;
38-
private Object entity;
39+
private Map<String, AbstractSearchResultEntity> entity;
3940

4041
public SearchResultRow providerTypeId(String providerTypeId) {
4142
this.providerTypeId = providerTypeId;
@@ -133,16 +134,16 @@ public SearchResultRow metadata(SearchResultMetadata metadata) {
133134
public SearchResultMetadata getMetadata() { return metadata; }
134135
public void setMetadata(SearchResultMetadata metadata) { this.metadata = metadata; }
135136

136-
public SearchResultRow entity(Object entity) {
137+
public SearchResultRow entity(Map<String, AbstractSearchResultEntity> entity) {
137138
this.entity = entity;
138139
return this;
139140
}
140141

141142
@javax.annotation.Nullable
142143
@JsonProperty("entity")
143144
@JsonInclude(value = JsonInclude.Include.NON_NULL)
144-
public Object getEntity() { return entity; }
145-
public void setEntity(Object entity) { this.entity = entity; }
145+
public Map<String, AbstractSearchResultEntity> getEntity() { return entity; }
146+
public void setEntity(Map<String, AbstractSearchResultEntity> entity) { this.entity = entity; }
146147

147148
@Override
148149
public boolean equals(java.lang.Object o) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2020 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.ibm.watson.data.client.serde;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
import com.fasterxml.jackson.core.TreeNode;
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
23+
import com.ibm.watson.data.client.model.*;
24+
25+
import java.io.IOException;
26+
import java.util.Iterator;
27+
28+
/**
29+
* Custom deserialization for (Abstract)SearchResultEntity, to handle deserialization
30+
* across various subtypes based on the properties that actually appear in the JSON being deserialized.
31+
*/
32+
public class AbstractSearchResultEntityDeserializer extends StdDeserializer<AbstractSearchResultEntity> {
33+
34+
protected AbstractSearchResultEntityDeserializer() {
35+
super(AbstractSearchResultEntity.class);
36+
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public AbstractSearchResultEntity deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
43+
String name = p.getCurrentName();
44+
TreeNode node = p.readValueAsTree();
45+
Iterator<String> fieldNames = node.fieldNames();
46+
AbstractSearchResultEntity result = null;
47+
if (name != null) {
48+
switch (name) {
49+
case "assets":
50+
result = p.getCodec().treeToValue(node, AssetSearchResultEntity.class);
51+
break;
52+
case "artifacts":
53+
result = p.getCodec().treeToValue(node, ArtifactSearchResultEntity.class);
54+
break;
55+
default:
56+
System.err.println("Unhandled contextual name '" + name + "' -- returning null!");
57+
break;
58+
}
59+
} else {
60+
System.err.println("No contextual name -- returning null!");
61+
}
62+
return result;
63+
}
64+
65+
}

0 commit comments

Comments
 (0)