Skip to content

Commit

Permalink
Merge branch 'develop' into gh-2435-FederatedStore-changeGraphId-tabl…
Browse files Browse the repository at this point in the history
…e-name-fix
  • Loading branch information
GCHQDev404 committed Jun 15, 2021
2 parents 99d070a + e1fd440 commit 40d443e
Show file tree
Hide file tree
Showing 65 changed files with 1,736 additions and 1,295 deletions.
2 changes: 1 addition & 1 deletion NOTICES
Expand Up @@ -21,7 +21,7 @@ and their licenses, below. For information on the dependencies of these dependen
projects below.


Koryphe (uk.gov.gchq.koryphe:koryphe:1.12.0):
Koryphe (uk.gov.gchq.koryphe:koryphe:1.13.0):

- Apache License, Version 2.0

Expand Down
2 changes: 1 addition & 1 deletion core/access/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>core</artifactId>
<groupId>uk.gov.gchq.gaffer</groupId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/cache/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>core</artifactId>
<groupId>uk.gov.gchq.gaffer</groupId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/common-util/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>

<artifactId>common-util</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/data/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/exception/pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>core</artifactId>
<groupId>uk.gov.gchq.gaffer</groupId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/graph/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/operation/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>gaffer2</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/serialisation/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/store/pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>core</artifactId>
<version>1.16.2-SNAPSHOT</version>
<version>1.17.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
201 changes: 127 additions & 74 deletions core/store/src/main/java/uk/gov/gchq/gaffer/store/schema/Schema.java
Expand Up @@ -29,8 +29,11 @@
import uk.gov.gchq.gaffer.commonutil.GroupUtil;
import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable;
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException;
import uk.gov.gchq.gaffer.data.elementdefinition.ElementDefinitions;
import uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException;
import uk.gov.gchq.gaffer.exception.SerialisationException;
import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser;
import uk.gov.gchq.gaffer.serialisation.Serialiser;
import uk.gov.gchq.koryphe.ValidationResult;
import uk.gov.gchq.koryphe.serialisation.json.SimpleClassNameIdResolver;
Expand All @@ -49,6 +52,8 @@
import java.util.Objects;
import java.util.Set;

import static java.util.Objects.nonNull;

/**
* <p>
* Contains the full list of {@link uk.gov.gchq.gaffer.data.element.Element} types to be stored in the graph.
Expand Down Expand Up @@ -429,96 +434,144 @@ public CHILD_CLASS config(final String key, final String value) {
@Override
@JsonIgnore
public CHILD_CLASS merge(final Schema schema) {
if (null != schema) {
validateSharedGroups(getThisSchema().getEntities(), schema.getEntities());
validateSharedGroups(getThisSchema().getEdges(), schema.getEdges());

// Schema ID is deprecated - remove this when ID is removed.
if (null == getThisSchema().getId()) {
getThisSchema().setId(schema.getId());
} else if (null != schema.getId()
&& !schema.getId().equals(getThisSchema().getId())) {
getThisSchema().setId(getThisSchema().getId() + "_" + schema.getId());
if (nonNull(schema)) {
Schema thatSchema;
try {
thatSchema = JSONSerialiser.deserialise(JSONSerialiser.serialise(schema), Schema.class);
} catch (final SerialisationException e) {
throw new GafferRuntimeException("Error merging Schema", e);
}

if (getThisSchema().getEntities().isEmpty()) {
getThisSchema().getEntities().putAll(schema.getEntities());
} else {
for (final Map.Entry<String, SchemaEntityDefinition> entry : schema.getEntities().entrySet()) {
if (!getThisSchema().getEntities().containsKey(entry.getKey())) {
entity(entry.getKey(), entry.getValue());
} else {
final SchemaEntityDefinition mergedElementDef = new SchemaEntityDefinition.Builder()
.merge(getThisSchema().getEntities().get(entry.getKey()))
.merge(entry.getValue())
.build();
getThisSchema().getEntities().put(entry.getKey(), mergedElementDef);
}
}
}
validateSharedGroupsAreCompatible(thatSchema);

mergeSchemaId(thatSchema);

mergeElements(thatSchema);

if (getThisSchema().getEdges().isEmpty()) {
getThisSchema().getEdges().putAll(schema.getEdges());
} else {
for (final Map.Entry<String, SchemaEdgeDefinition> entry : schema.getEdges().entrySet()) {
if (!getThisSchema().getEdges().containsKey(entry.getKey())) {
edge(entry.getKey(), entry.getValue());
} else {
final SchemaEdgeDefinition mergedElementDef = new SchemaEdgeDefinition.Builder()
.merge(getThisSchema().getEdges().get(entry.getKey()))
.merge(entry.getValue())
.build();
getThisSchema().getEdges().put(entry.getKey(), mergedElementDef);
}
mergeVertexSerialiser(thatSchema);

mergeVisibility(thatSchema);

mergeTimeStamp(thatSchema);

mergeTypes(thatSchema);

mergeConfig(thatSchema);
}

return self();
}

@Deprecated
private void mergeSchemaId(final Schema schema) {
// Schema ID is deprecated - remove this when ID is removed.
if (null == getThisSchema().getId()) {
getThisSchema().setId(schema.getId());
} else if (null != schema.getId()
&& !schema.getId().equals(getThisSchema().getId())) {
getThisSchema().setId(getThisSchema().getId() + "_" + schema.getId());
}
}

private void mergeEntities(final Schema thatSchema) {
if (getThisSchema().getEntities().isEmpty()) {
getThisSchema().getEntities().putAll(thatSchema.getEntities());
} else {
for (final Entry<String, SchemaEntityDefinition> entry : thatSchema.getEntities().entrySet()) {
if (!getThisSchema().getEntities().containsKey(entry.getKey())) {
entity(entry.getKey(), entry.getValue());
} else {
final SchemaEntityDefinition mergedElementDef = new SchemaEntityDefinition.Builder()
.merge(getThisSchema().getEntities().get(entry.getKey()))
.merge(entry.getValue())
.build();
getThisSchema().getEntities().put(entry.getKey(), mergedElementDef);
}
}
}
}

if (null != schema.getVertexSerialiser()) {
if (null == getThisSchema().vertexSerialiser) {
getThisSchema().vertexSerialiser = schema.getVertexSerialiser();
} else if (!getThisSchema().vertexSerialiser.getClass().equals(schema.getVertexSerialiser().getClass())) {
throw new SchemaException("Unable to merge schemas. Conflict with vertex serialiser, options are: "
+ getThisSchema().vertexSerialiser.getClass().getName() + " and " + schema.getVertexSerialiser().getClass().getName());
private void mergeEdges(final Schema thatSchema) {
if (getThisSchema().getEdges().isEmpty()) {
getThisSchema().getEdges().putAll(thatSchema.getEdges());
} else {
for (final Entry<String, SchemaEdgeDefinition> entry : thatSchema.getEdges().entrySet()) {
if (!getThisSchema().getEdges().containsKey(entry.getKey())) {
edge(entry.getKey(), entry.getValue());
} else {
final SchemaEdgeDefinition mergedElementDef = new SchemaEdgeDefinition.Builder()
.merge(getThisSchema().getEdges().get(entry.getKey()))
.merge(entry.getValue())
.build();
getThisSchema().getEdges().put(entry.getKey(), mergedElementDef);
}
}
}
}

if (null == getThisSchema().visibilityProperty) {
getThisSchema().visibilityProperty = schema.getVisibilityProperty();
} else if (null != schema.getVisibilityProperty() && !getThisSchema().visibilityProperty.equals(schema.getVisibilityProperty())) {
throw new SchemaException("Unable to merge schemas. Conflict with visibility property, options are: "
+ getThisSchema().visibilityProperty + " and " + schema.getVisibilityProperty());
private void mergeVertexSerialiser(final Schema thatSchema) {
if (null != thatSchema.getVertexSerialiser()) {
if (null == getThisSchema().vertexSerialiser) {
getThisSchema().vertexSerialiser = thatSchema.getVertexSerialiser();
} else if (!getThisSchema().vertexSerialiser.getClass().equals(thatSchema.getVertexSerialiser().getClass())) {
throw new SchemaException("Unable to merge schemas. Conflict with vertex serialiser, options are: "
+ getThisSchema().vertexSerialiser.getClass().getName() + " and " + thatSchema.getVertexSerialiser().getClass().getName());
}
}
}

if (null == getThisSchema().timestampProperty) {
getThisSchema().timestampProperty = schema.getTimestampProperty();
} else if (null != schema.getTimestampProperty() && !getThisSchema().timestampProperty.equals(schema.getTimestampProperty())) {
throw new SchemaException("Unable to merge schemas. Conflict with timestamp property, options are: "
+ getThisSchema().timestampProperty + " and " + schema.getTimestampProperty());
}
private void mergeVisibility(final Schema thatSchema) {
if (null == getThisSchema().visibilityProperty) {
getThisSchema().visibilityProperty = thatSchema.getVisibilityProperty();
} else if (null != thatSchema.getVisibilityProperty() && !getThisSchema().visibilityProperty.equals(thatSchema.getVisibilityProperty())) {
throw new SchemaException("Unable to merge schemas. Conflict with visibility property, options are: "
+ getThisSchema().visibilityProperty + " and " + thatSchema.getVisibilityProperty());
}
}

if (getThisSchema().types.isEmpty()) {
getThisSchema().types.putAll(schema.types);
} else {
for (final Entry<String, TypeDefinition> entry : schema.types.entrySet()) {
final String newType = entry.getKey();
final TypeDefinition newTypeDef = entry.getValue();
final TypeDefinition typeDef = getThisSchema().types.get(newType);
if (null == typeDef) {
getThisSchema().types.put(newType, newTypeDef);
} else {
typeDef.merge(newTypeDef);
}
@Deprecated
private void mergeTimeStamp(final Schema thatSchema) {
if (null == getThisSchema().timestampProperty) {
getThisSchema().timestampProperty = thatSchema.getTimestampProperty();
} else if (null != thatSchema.getTimestampProperty() && !getThisSchema().timestampProperty.equals(thatSchema.getTimestampProperty())) {
throw new SchemaException("Unable to merge schemas. Conflict with timestamp property, options are: "
+ getThisSchema().timestampProperty + " and " + thatSchema.getTimestampProperty());
}
}

private void mergeTypes(final Schema thatSchema) {
if (getThisSchema().types.isEmpty()) {
getThisSchema().types.putAll(thatSchema.types);
} else {
for (final Entry<String, TypeDefinition> entry : thatSchema.types.entrySet()) {
final String newType = entry.getKey();
final TypeDefinition newTypeDef = entry.getValue();
final TypeDefinition typeDef = getThisSchema().types.get(newType);
if (null == typeDef) {
getThisSchema().types.put(newType, newTypeDef);
} else {
typeDef.merge(newTypeDef);
}
}
}
}

if (null == getThisSchema().config) {
getThisSchema().config = schema.config;
} else if (null != schema.config) {
getThisSchema().config.putAll(schema.config);
}
private void mergeConfig(final Schema thatSchema) {
if (null == getThisSchema().config) {
getThisSchema().config = thatSchema.config;
} else if (null != thatSchema.config) {
getThisSchema().config.putAll(thatSchema.config);
}
}

return self();
private void mergeElements(final Schema thatSchema) {
mergeEntities(thatSchema);
mergeEdges(thatSchema);
}

private void validateSharedGroupsAreCompatible(final Schema schema) {
validateSharedGroupsAreCompatible(getThisSchema().getEntities(), schema.getEntities());
validateSharedGroupsAreCompatible(getThisSchema().getEdges(), schema.getEdges());
}

@JsonIgnore
Expand Down Expand Up @@ -562,7 +615,7 @@ private Schema getThisSchema() {
return getElementDefs();
}

private void validateSharedGroups(final Map<String, ? extends SchemaElementDefinition> elements1, final Map<String, ? extends SchemaElementDefinition> elements2) {
private void validateSharedGroupsAreCompatible(final Map<String, ? extends SchemaElementDefinition> elements1, final Map<String, ? extends SchemaElementDefinition> elements2) {
final Set<String> sharedGroups = new HashSet<>(elements1.keySet());
sharedGroups.retainAll(elements2.keySet());
if (!sharedGroups.isEmpty()) {
Expand Down
Expand Up @@ -296,4 +296,14 @@ private Class<?> getTypeClass(final String key, final SchemaElementDefinition sc
}
return clazz;
}

@Override
public boolean equals(final Object o) {
return this == o || this.getClass() == o.getClass();
}

@Override
public int hashCode() {
return super.hashCode();
}
}

0 comments on commit 40d443e

Please sign in to comment.