diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java index d4f7328595..4437cf9b63 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java @@ -42,7 +42,7 @@ public final class DeltaCacheKey implements Serializable { // indicates that client want to receive resync based on base schema private final boolean resyncOnly; - private final boolean useRawSchema; + private final boolean useConfigurationRawSchema; private final EndpointObjectHash userConfHash; @@ -53,17 +53,17 @@ public DeltaCacheKey(AppVersionKey appConfigVersionKey, List endpointGroups, EndpointObjectHash userConfHash, - EndpointObjectHash endpointConfHash, boolean useRawSchema) { - this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, useRawSchema, false); + EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema) { + this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, useConfigurationRawSchema, false); } public DeltaCacheKey(AppVersionKey appConfigVersionKey, List endpointGroups, - EndpointObjectHash userConfHash, EndpointObjectHash endpointConfHash, boolean useRawSchema, boolean resyncOnly) { + EndpointObjectHash userConfHash, EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema, boolean resyncOnly) { this.appConfigVersionKey = appConfigVersionKey; this.userConfHash = userConfHash; this.endpointGroups = endpointGroups; this.endpointConfHash = endpointConfHash; - this.useRawSchema = useRawSchema; + this.useConfigurationRawSchema = useConfigurationRawSchema; this.resyncOnly = resyncOnly; } @@ -93,8 +93,8 @@ public boolean isResyncOnly() { return resyncOnly; } - public boolean isUseRawSchema() { - return useRawSchema; + public boolean isUseConfigurationRawSchema() { + return useConfigurationRawSchema; } public EndpointObjectHash getUserConfHash() { @@ -102,61 +102,33 @@ public EndpointObjectHash getUserConfHash() { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((appConfigVersionKey == null) ? 0 : appConfigVersionKey.hashCode()); - result = prime * result + ((endpointConfHash == null) ? 0 : endpointConfHash.hashCode()); - result = prime * result + ((endpointGroups == null) ? 0 : endpointGroups.hashCode()); - result = prime * result + (resyncOnly ? 1231 : 1237); - result = prime * result + ((userConfHash == null) ? 0 : userConfHash.hashCode()); - return result; - } + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - DeltaCacheKey other = (DeltaCacheKey) obj; - if (appConfigVersionKey == null) { - if (other.appConfigVersionKey != null) { - return false; - } - } else if (!appConfigVersionKey.equals(other.appConfigVersionKey)) { - return false; - } - if (endpointConfHash == null) { - if (other.endpointConfHash != null) { - return false; - } - } else if (!endpointConfHash.equals(other.endpointConfHash)) { - return false; - } - if (endpointGroups == null) { - if (other.endpointGroups != null) { - return false; - } - } else if (!endpointGroups.equals(other.endpointGroups)) { + DeltaCacheKey that = (DeltaCacheKey) o; + + if (resyncOnly != that.resyncOnly) return false; + if (useConfigurationRawSchema != that.useConfigurationRawSchema) return false; + if (appConfigVersionKey != null ? !appConfigVersionKey.equals(that.appConfigVersionKey) : that.appConfigVersionKey != null) return false; - } - if (resyncOnly != other.resyncOnly) { + if (endpointGroups != null ? !endpointGroups.equals(that.endpointGroups) : that.endpointGroups != null) return false; - } - if (userConfHash == null) { - if (other.userConfHash != null) { - return false; - } - } else if (!userConfHash.equals(other.userConfHash)) { + if (endpointConfHash != null ? !endpointConfHash.equals(that.endpointConfHash) : that.endpointConfHash != null) return false; - } - return true; + return userConfHash != null ? userConfHash.equals(that.userConfHash) : that.userConfHash == null; + + } + + @Override + public int hashCode() { + int result = appConfigVersionKey != null ? appConfigVersionKey.hashCode() : 0; + result = 31 * result + (endpointGroups != null ? endpointGroups.hashCode() : 0); + result = 31 * result + (endpointConfHash != null ? endpointConfHash.hashCode() : 0); + result = 31 * result + (resyncOnly ? 1 : 0); + result = 31 * result + (useConfigurationRawSchema ? 1 : 0); + result = 31 * result + (userConfHash != null ? userConfHash.hashCode() : 0); + return result; } @Override @@ -170,6 +142,8 @@ public String toString() { builder.append(endpointConfHash); builder.append(", resyncOnly="); builder.append(resyncOnly); + builder.append(", useRawSchema="); + builder.append(useConfigurationRawSchema); builder.append(", userConfHash="); builder.append(userConfHash); builder.append("]"); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java index f9647156b1..f11c671d48 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java @@ -89,7 +89,7 @@ public class DefaultDeltaService implements DeltaService { @Autowired private EndpointService endpointService; - /** The configuration merger factory. */ + @Autowired private OverrideAlgorithmFactory configurationOverrideFactory; @@ -120,7 +120,7 @@ public ConfigurationCacheEntry getConfiguration(String appToken, String endpoint LOG.debug("[{}][{}] Calculating new configuration", appToken, endpointId); AppVersionKey appConfigVersionKey = new AppVersionKey(appToken, profile.getConfigurationVersion()); DeltaCacheKey deltaKey = new DeltaCacheKey(appConfigVersionKey, profile.getGroupState(), EndpointObjectHash.fromBytes(profile - .getUserConfigurationHash()), null, true); + .getUserConfigurationHash()), null, profile.isUseConfigurationRawSchema(), true); LOG.debug("[{}][{}] Built resync delta key {}", appToken, endpointId, deltaKey); return getDelta(endpointId, profile.getEndpointUserId(), deltaKey, profile.isUseConfigurationRawSchema()); } @@ -188,8 +188,14 @@ private ConfigurationCacheEntry getDelta(final String endpointId, final String u final DeltaCacheKey newKey; if (userConfiguration != null) { - newKey = new DeltaCacheKey(deltaKey.getAppConfigVersionKey(), deltaKey.getEndpointGroups(), - EndpointObjectHash.fromString(userConfiguration.getBody()), deltaKey.getEndpointConfHash(), deltaKey.isResyncOnly()); + newKey = new DeltaCacheKey( + deltaKey.getAppConfigVersionKey(), + deltaKey.getEndpointGroups(), + EndpointObjectHash.fromString(userConfiguration.getBody()), + deltaKey.getEndpointConfHash(), + useConfigurationRawSchema, + deltaKey.isResyncOnly() + ); } else { newKey = deltaKey; } @@ -373,7 +379,7 @@ public Pair compute(List key) { return mergedConfiguration; } - private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException { + private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException { byte[] configuration = GenericAvroConverter.toRawData(jsonData, schema); return new ConfigurationCacheEntry(configuration, new BaseBinaryDelta(configuration), EndpointObjectHash.fromSHA1(configuration), userConfigurationHash);