|
| 1 | +package com.github.couchmove.repository; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import com.couchbase.client.java.manager.search.SearchIndex; |
| 7 | +import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonCreator; |
| 8 | +import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty; |
| 9 | +import com.couchbase.client.core.json.Mapper; |
| 10 | + |
| 11 | +public class CustomSearchIndex extends SearchIndex { |
| 12 | + |
| 13 | + @JsonCreator |
| 14 | + public CustomSearchIndex( |
| 15 | + @JsonProperty("uuid") String uuid, |
| 16 | + @JsonProperty("name") String name, |
| 17 | + @JsonProperty("type") String type, |
| 18 | + @JsonProperty("params") Map<String, Object> params, |
| 19 | + @JsonProperty("sourceUUID") String sourceUuid, |
| 20 | + @JsonProperty("sourceName") String sourceName, |
| 21 | + @JsonProperty("sourceParams") Map<String, Object> sourceParams, |
| 22 | + @JsonProperty("sourceType") String sourceType, |
| 23 | + @JsonProperty("planParams") Map<String, Object> planParams) { |
| 24 | + super(uuid, name, type, params, sourceUuid, sourceName, sourceParams, sourceType, planParams); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public String toJson() { |
| 29 | + Map<String, Object> output = new HashMap<>(); |
| 30 | + |
| 31 | + if (super.uuid() != null) { |
| 32 | + output.put("uuid", super.uuid()); |
| 33 | + } |
| 34 | + output.put("name", super.name()); |
| 35 | + output.put("sourceName", super.sourceName()); |
| 36 | + output.put("type", super.type() == null ? "fulltext-index" : super.type()); |
| 37 | + output.put("sourceType", super.sourceType() == null ? "couchbase" : super.sourceType()); |
| 38 | + output.put("params", super.params()); |
| 39 | + output.put("planParams", super.planParams()); |
| 40 | + output.put("sourceUUID", super.sourceUuid()); |
| 41 | + |
| 42 | + return Mapper.encodeAsString(output); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments