From c4f6c5e132c68a99aba0475c34edb3832b8b24c4 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Tue, 21 Nov 2017 14:24:10 +0100 Subject: [PATCH] [fix] Add new attribute 'version' to record model fix #29 --- .../client/model/elasticsearch/Record.java | 11 +++++++ .../client/model/elasticsearch/Records.java | 27 ++++++++++++++++ .../model/elasticsearch/UserProfile.java | 10 ++++++ .../duniter/core/client/model/local/Peer.java | 1 + .../src/test/es-home/config/elasticsearch.yml | 12 +++---- .../elasticsearch/dao/impl/PeerDaoImpl.java | 2 +- .../dao/record/SubscriptionRecordDaoImpl.java | 31 +++++++++++++------ .../user/dao/AbstractCommentDaoImpl.java | 13 ++++++-- .../user/dao/AbstractRecordDaoImpl.java | 31 ++++++++++++------- .../user/dao/profile/UserProfileDaoImpl.java | 27 ++++++++++------ .../user/dao/profile/UserSettingsDaoImpl.java | 9 ++++-- .../elasticsearch/user/model/UserProfile.java | 21 ++++++++++++- 12 files changed, 149 insertions(+), 46 deletions(-) diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Record.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Record.java index 38a94d02..f93951c1 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Record.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Record.java @@ -30,11 +30,13 @@ import org.duniter.core.client.model.local.LocalEntity; */ public class Record implements LocalEntity<String> { + public static final String PROPERTY_VERSION="version"; public static final String PROPERTY_ISSUER="issuer"; public static final String PROPERTY_HASH="hash"; public static final String PROPERTY_SIGNATURE="signature"; public static final String PROPERTY_TIME="time"; + private String version; private String id; private String issuer; private String hash; @@ -45,6 +47,7 @@ public class Record implements LocalEntity<String> { } public Record(Record another) { + this.version = another.getVersion(); this.id = another.getId(); this.issuer = another.getIssuer(); this.hash = another.getHash(); @@ -52,6 +55,14 @@ public class Record implements LocalEntity<String> { this.time = another.getTime(); } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @JsonIgnore public String getId() { return id; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Records.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Records.java index 0fbc3c93..23198ee3 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Records.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/Records.java @@ -28,12 +28,39 @@ package org.duniter.core.client.model.elasticsearch; */ public final class Records { + // Common fields public static final String PROPERTY_ISSUER="issuer"; public static final String PROPERTY_HASH="hash"; public static final String PROPERTY_SIGNATURE="signature"; public static final String PROPERTY_VERSION="version"; public static final String PROPERTY_TIME="time"; + public static final String PROPERTY_CREATION_TIME="creationTime"; + + // Read marker public static final String PROPERTY_READ_SIGNATURE="read_signature"; + // Location + public static final String PROPERTY_ADDRESS="address"; + public static final String PROPERTY_CITY="city"; + public static final String PROPERTY_GEO_POINT="geoPoint"; + + // record + public static final String PROPERTY_TITLE="title"; + public static final String PROPERTY_DESCRIPTION="description"; + + // Avatar & pictures + public static final String PROPERTY_AVATAR="avatar"; + public static final String PROPERTY_PICTURES="pictures"; + public static final String PROPERTY_PICTURES_COUNT="picturesCount"; + + // Socials & tags + public static final String PROPERTY_SOCIALS="socials"; + public static final String PROPERTY_TAGS="tags"; + + // Other + public static final String PROPERTY_CATEGORY="category"; + public static final String PROPERTY_CONTENT="content"; + + } diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/UserProfile.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/UserProfile.java index e9efcdc4..dca4bc89 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/UserProfile.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/elasticsearch/UserProfile.java @@ -29,12 +29,14 @@ public class UserProfile extends Record { public static final String PROPERTY_TITLE = "title"; public static final String PROPERTY_DESCRIPTION="description"; + public static final String PROPERTY_ADDRESS="address"; public static final String PROPERTY_CITY="city"; public static final String PROPERTY_EMAIL="email"; public static final String PROPERTY_LOCALE="locale"; private String title; private String description; + private String address; private String email; private String locale; @@ -69,4 +71,12 @@ public class UserProfile extends Record { public void setLocale(String locale) { this.locale = locale; } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } } diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peer.java index 419608bc..d2e2c649 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/local/Peer.java @@ -403,6 +403,7 @@ public class Peer implements LocalEntity<String>, Serializable { } public static class Stats { + public static final String PROPERTY_VERSION = "version"; public static final String PROPERTY_STATUS = "status"; public static final String PROPERTY_LAST_UP_TIME = "lastUpTime"; public static final String PROPERTY_UID = "uid"; diff --git a/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml b/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml index 553a93e4..0759654b 100644 --- a/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml +++ b/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml @@ -14,7 +14,7 @@ # # Use a descriptive name for your cluster: # -cluster.name: g1-es-data +cluster.name: g1-es-data-test # # ------------------------------------ Node ------------------------------------ # @@ -180,16 +180,14 @@ duniter.p2p.discovery.enable: false # duniter.p2p.includes.endpoints: [ "ES_USER_API g1.data.duniter.fr 443", - "ES_SUBSCRIPTION_API g1.data.duniter.fr 443", - "ES_USER_API g1.data.le-sou.org 443", - "ES_SUBSCRIPTION_API g1.data.le-sou.org 443" + "ES_SUBSCRIPTION_API g1.data.duniter.fr 443" ] # # Pass a list of pubkeys to always synchronize (default: <empty>) # -duniter.p2p.includes.pubkeys: [ - "38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE" -] +#duniter.p2p.includes.pubkeys: [ +# "38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE" +#] #duniter.p2p.fullResyncAtStartup: true # # ---------------------------------- Duniter4j Mail module ----------------------- diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java index 0911dbc7..dcf605ec 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java @@ -373,7 +373,7 @@ public class PeerDaoImpl extends AbstractDao implements PeerDao { .startObject("properties") // stats.version - .startObject("version") + .startObject(Peer.Stats.PROPERTY_VERSION) .field("type", "string") .endObject() diff --git a/duniter4j-es-subscription/src/main/java/org/duniter/elasticsearch/subscription/dao/record/SubscriptionRecordDaoImpl.java b/duniter4j-es-subscription/src/main/java/org/duniter/elasticsearch/subscription/dao/record/SubscriptionRecordDaoImpl.java index e5fa09dd..7ad0fe86 100644 --- a/duniter4j-es-subscription/src/main/java/org/duniter/elasticsearch/subscription/dao/record/SubscriptionRecordDaoImpl.java +++ b/duniter4j-es-subscription/src/main/java/org/duniter/elasticsearch/subscription/dao/record/SubscriptionRecordDaoImpl.java @@ -22,6 +22,7 @@ package org.duniter.elasticsearch.subscription.dao.record; * #L% */ +import org.duniter.core.client.model.elasticsearch.Record; import org.duniter.core.exception.TechnicalException; import org.duniter.core.util.CollectionUtils; import org.duniter.elasticsearch.subscription.PluginSettings; @@ -86,54 +87,64 @@ public class SubscriptionRecordDaoImpl extends AbstractSubscriptionIndexTypeDao< .startObject(getType()) .startObject("properties") + // version + .startObject(SubscriptionRecord.PROPERTY_VERSION) + .field("type", "integer") + .endObject() + + // type + .startObject(SubscriptionRecord.PROPERTY_TYPE) + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + // issuer - .startObject("issuer") + .startObject(SubscriptionRecord.PROPERTY_ISSUER) .field("type", "string") .field("index", "not_analyzed") .endObject() // recipient - .startObject("recipient") + .startObject(SubscriptionRecord.PROPERTY_RECIPIENT) .field("type", "string") .field("index", "not_analyzed") .endObject() // time - .startObject("time") + .startObject(SubscriptionRecord.PROPERTY_TIME) .field("type", "integer") .endObject() // nonce - .startObject("nonce") + .startObject(SubscriptionRecord.PROPERTY_NONCE) .field("type", "string") .field("index", "not_analyzed") .endObject() - // issuer content - .startObject("issuer_content") + // issuerContent + .startObject(SubscriptionRecord.PROPERTY_ISSUER_CONTENT) .field("type", "string") .field("index", "not_analyzed") .endObject() // receiver content - .startObject("receiver_content") + .startObject(SubscriptionRecord.PROPERTY_RECIPIENT_CONTENT) .field("type", "string") .field("index", "not_analyzed") .endObject() // hash - .startObject("hash") + .startObject(SubscriptionRecord.PROPERTY_HASH) .field("type", "string") .field("index", "not_analyzed") .endObject() // signature - .startObject("signature") + .startObject(SubscriptionRecord.PROPERTY_SIGNATURE) .field("type", "string") .field("index", "not_analyzed") .endObject() - .endObject() .endObject().endObject(); diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractCommentDaoImpl.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractCommentDaoImpl.java index 0304e280..64092113 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractCommentDaoImpl.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractCommentDaoImpl.java @@ -24,7 +24,9 @@ package org.duniter.elasticsearch.user.dao; import com.fasterxml.jackson.core.JsonProcessingException; +import org.duniter.core.client.model.elasticsearch.Record; import org.duniter.core.client.model.elasticsearch.RecordComment; +import org.duniter.core.client.model.elasticsearch.Records; import org.duniter.core.exception.TechnicalException; import org.duniter.elasticsearch.dao.AbstractIndexTypeDao; import org.duniter.elasticsearch.user.PluginSettings; @@ -100,19 +102,24 @@ public class AbstractCommentDaoImpl<T extends AbstractCommentDaoImpl> extends Ab XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(getType()) .startObject("properties") + // version + .startObject(Record.PROPERTY_VERSION) + .field("type", "integer") + .endObject() + // issuer - .startObject("issuer") + .startObject(Record.PROPERTY_ISSUER) .field("type", "string") .field("index", "not_analyzed") .endObject() // creationTime - .startObject("creationTime") + .startObject(Records.PROPERTY_CREATION_TIME) .field("type", "integer") .endObject() // time - .startObject("time") + .startObject(Record.PROPERTY_TIME) .field("type", "integer") .endObject() diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractRecordDaoImpl.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractRecordDaoImpl.java index b71b4872..c1428cbe 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractRecordDaoImpl.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/AbstractRecordDaoImpl.java @@ -25,6 +25,8 @@ package org.duniter.elasticsearch.user.dao; import com.fasterxml.jackson.core.JsonProcessingException; import org.duniter.core.client.model.elasticsearch.Record; +import org.duniter.core.client.model.elasticsearch.Records; +import org.duniter.elasticsearch.user.model.UserProfile; import org.duniter.core.exception.TechnicalException; import org.duniter.core.util.ObjectUtils; import org.duniter.elasticsearch.dao.AbstractIndexTypeDao; @@ -74,20 +76,25 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(getType()) .startObject("properties") + // version + .startObject(Record.PROPERTY_VERSION) + .field("type", "integer") + .endObject() + // title - .startObject("title") + .startObject(Records.PROPERTY_TITLE) .field("type", "string") .field("analyzer", stringAnalyzer) .endObject() // description - .startObject("description") + .startObject(Records.PROPERTY_DESCRIPTION) .field("type", "string") .field("analyzer", stringAnalyzer) .endObject() // creationTime - .startObject("creationTime") + .startObject(Records.PROPERTY_CREATION_TIME) .field("type", "integer") .endObject() @@ -115,23 +122,23 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst .endObject() // address - .startObject("address") + .startObject(Records.PROPERTY_ADDRESS) .field("type", "string") .field("analyzer", stringAnalyzer) .endObject() // city - .startObject("city") + .startObject(Records.PROPERTY_CITY) .field("type", "string") .endObject() // geoPoint - .startObject("geoPoint") + .startObject(Records.PROPERTY_GEO_POINT) .field("type", "geo_point") .endObject() // avatar - .startObject("avatar") + .startObject(Records.PROPERTY_AVATAR) .field("type", "attachment") .startObject("fields") // fields .startObject("content") // content @@ -151,7 +158,7 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst .endObject() // social networks - .startObject("socials") + .startObject(Records.PROPERTY_SOCIALS) .field("type", "nested") .field("dynamic", "false") .startObject("properties") @@ -167,7 +174,7 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst .endObject() // tags - .startObject("tags") + .startObject(Records.PROPERTY_TAGS) .field("type", "completion") .field("search_analyzer", "simple") .field("analyzer", "simple") @@ -184,7 +191,7 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst // pictures if (isNestedPicturesEnable) { - mapping.startObject("pictures") + mapping.startObject(Records.PROPERTY_PICTURES) .field("type", "nested") .field("dynamic", "false") .startObject("properties") @@ -212,14 +219,14 @@ public class AbstractRecordDaoImpl<T extends AbstractRecordDaoImpl> extends Abst .endObject() // picturesCount - .startObject("picturesCount") + .startObject(Records.PROPERTY_PICTURES_COUNT) .field("type", "integer") .endObject(); } // category if (isNestedCategoryEnable) { - mapping.startObject("category") + mapping.startObject(Records.PROPERTY_CATEGORY) .field("type", "nested") .field("dynamic", "false") .startObject("properties") diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserProfileDaoImpl.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserProfileDaoImpl.java index 8ce2f972..a2af7982 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserProfileDaoImpl.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserProfileDaoImpl.java @@ -25,12 +25,14 @@ package org.duniter.elasticsearch.user.dao.profile; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import org.duniter.core.client.model.elasticsearch.Record; +import org.duniter.core.client.model.elasticsearch.Records; import org.duniter.core.exception.TechnicalException; import org.duniter.core.util.ObjectUtils; import org.duniter.core.util.Preconditions; import org.duniter.elasticsearch.dao.AbstractIndexTypeDao; import org.duniter.elasticsearch.exception.InvalidFormatException; import org.duniter.elasticsearch.user.PluginSettings; +import org.duniter.elasticsearch.user.model.UserProfile; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -96,46 +98,51 @@ public class UserProfileDaoImpl extends AbstractIndexTypeDao<UserProfileDaoImpl> XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(getType()) .startObject("properties") + // version + .startObject(UserProfile.PROPERTY_VERSION) + .field("type", "integer") + .endObject() + // title - .startObject("title") + .startObject(UserProfile.PROPERTY_TITLE) .field("type", "string") .field("analyzer", stringAnalyzer) .endObject() // description - .startObject("description") + .startObject(UserProfile.PROPERTY_DESCRIPTION) .field("type", "string") .field("analyzer", stringAnalyzer) .endObject() // time - .startObject("time") + .startObject(UserProfile.PROPERTY_TIME) .field("type", "integer") .endObject() // issuer - .startObject("issuer") + .startObject(UserProfile.PROPERTY_ISSUER) .field("type", "string") .field("index", "not_analyzed") .endObject() // city - .startObject("city") + .startObject(UserProfile.PROPERTY_CITY) .field("type", "string") .endObject() // address - .startObject("address") + .startObject(UserProfile.PROPERTY_ADDRESS) .field("type", "string") .endObject() // geoPoint - .startObject("geoPoint") + .startObject(Records.PROPERTY_GEO_POINT) .field("type", "geo_point") .endObject() // avatar - .startObject("avatar") + .startObject(Records.PROPERTY_AVATAR) .field("type", "attachment") .startObject("fields") // fields .startObject("content") // content @@ -155,7 +162,7 @@ public class UserProfileDaoImpl extends AbstractIndexTypeDao<UserProfileDaoImpl> .endObject() // social networks - .startObject("socials") + .startObject(Records.PROPERTY_SOCIALS) .field("type", "nested") .field("dynamic", "false") .startObject("properties") @@ -171,7 +178,7 @@ public class UserProfileDaoImpl extends AbstractIndexTypeDao<UserProfileDaoImpl> .endObject() // tags - .startObject("tags") + .startObject(Records.PROPERTY_TAGS) .field("type", "completion") .field("search_analyzer", "simple") .field("analyzer", "simple") diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserSettingsDaoImpl.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserSettingsDaoImpl.java index 77e6c096..57e3d14b 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserSettingsDaoImpl.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/dao/profile/UserSettingsDaoImpl.java @@ -92,13 +92,18 @@ public class UserSettingsDaoImpl extends AbstractIndexTypeDao<UserSettingsDaoImp XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject(getType()) .startObject("properties") + // version + .startObject(Record.PROPERTY_VERSION) + .field("type", "integer") + .endObject() + // time - .startObject("time") + .startObject(Record.PROPERTY_TIME) .field("type", "integer") .endObject() // issuer - .startObject("issuer") + .startObject(Record.PROPERTY_ISSUER) .field("type", "string") .field("index", "not_analyzed") .endObject() diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java index 73ad472a..6ef6ecb0 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java @@ -31,15 +31,18 @@ public class UserProfile extends Record { public static final String PROPERTY_TITLE = "title"; public static final String PROPERTY_DESCRIPTION="description"; - public static final String PROPERTY_CITY="city"; public static final String PROPERTY_EMAIL="email"; public static final String PROPERTY_LOCALE="locale"; public static final String PROPERTY_AVATAR="avatar"; + public static final String PROPERTY_ADDRESS="address"; + public static final String PROPERTY_CITY="city"; private String title; private String description; private String email; private String locale; + private String address; + private String city; public String getTitle() { return title; @@ -72,4 +75,20 @@ public class UserProfile extends Record { public void setLocale(String locale) { this.locale = locale; } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } } -- GitLab