diff --git a/BUILD b/BUILD index 3ead14015a..49603f8558 100644 --- a/BUILD +++ b/BUILD @@ -75,7 +75,7 @@ java_library( checkstyle_test( name = "checkstyle", targets = [":client-java"], - license_type = "apache" + license_type = "apache", ) diff --git a/Grakn.java b/Grakn.java index cd64ae3e68..556bb6e3ae 100644 --- a/Grakn.java +++ b/Grakn.java @@ -33,8 +33,8 @@ import graql.lang.query.GraqlCompute; import graql.lang.query.GraqlDefine; import graql.lang.query.GraqlDelete; -import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlInsert; +import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlQuery; import graql.lang.query.GraqlUndefine; diff --git a/VERSION b/VERSION index 53adb84c82..227cea2156 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.2 +2.0.0 diff --git a/rpc/RPCProtoBuilder.java b/common/ProtoBuilder.java similarity index 91% rename from rpc/RPCProtoBuilder.java rename to common/ProtoBuilder.java index 388c76a92a..d4600c367a 100644 --- a/rpc/RPCProtoBuilder.java +++ b/common/ProtoBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package grakn.client.rpc; +package grakn.client.common; import grabl.tracing.client.GrablTracingThreadStatic; import grakn.client.GraknOptions; @@ -30,9 +30,9 @@ import static grabl.tracing.client.GrablTracingThreadStatic.currentThreadTrace; import static grabl.tracing.client.GrablTracingThreadStatic.isTracingEnabled; -abstract class RPCProtoBuilder { +public abstract class ProtoBuilder { - static OptionsProto.Options options(final GraknOptions options) { + public static OptionsProto.Options options(final GraknOptions options) { final OptionsProto.Options.Builder builder = OptionsProto.Options.newBuilder(); options.infer().ifPresent(builder::setInfer); options.explain().ifPresent(builder::setExplain); @@ -40,7 +40,7 @@ static OptionsProto.Options options(final GraknOptions options) { return builder.build(); } - static Map tracingData() { + public static Map tracingData() { if (isTracingEnabled()) { final GrablTracingThreadStatic.ThreadTrace threadTrace = currentThreadTrace(); if (threadTrace == null) { diff --git a/common/exception/ErrorMessage.java b/common/exception/ErrorMessage.java index 5d060d4f40..942dc5a17c 100644 --- a/common/exception/ErrorMessage.java +++ b/common/exception/ErrorMessage.java @@ -28,10 +28,9 @@ private ErrorMessage(String codePrefix, int codeNumber, String messagePrefix, St public static class ClientInternal extends ErrorMessage { public static final ClientInternal UNRECOGNISED_VALUE = new ClientInternal(1, "Unrecognised schema value!"); - public static final ClientInternal ILLEGAL_ARGUMENT_NULL = - new ClientInternal(2, "'%s' can not be null."); - public static final ClientInternal ILLEGAL_ARGUMENT_NULL_OR_EMPTY = - new ClientInternal(3, "'%s' can not be null or empty."); + // TODO: variable error messages like this (below) is not good as the error code no longer uniquely identifies the problem for users + public static final ClientInternal MISSING_ARGUMENT = + new ClientInternal(2, "'%s' can not be null or empty."); private static final String codePrefix = "CIN"; private static final String messagePrefix = "Invalid Internal State (Client)"; diff --git a/concept/Concept.java b/concept/Concept.java index 545658c3e8..1576d20a89 100644 --- a/concept/Concept.java +++ b/concept/Concept.java @@ -19,166 +19,76 @@ package grakn.client.concept; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.Rule; import grakn.client.concept.type.Type; +import grakn.client.concept.type.impl.TypeImpl; import grakn.protocol.ConceptProto; -import javax.annotation.CheckReturnValue; - import static grakn.client.common.exception.ErrorMessage.Concept.INVALID_CONCEPT_CASTING; -/** - * The base concept implementation. - * A concept which can be every object in the graph. - * This class forms the basis of assuring the graph follows the Grakn object model. - * It provides methods to retrieve information about the Concept, and determine if it is a Type - * (EntityType, RoleType, RelationType, Rule or AttributeType) - * or an Thing (Entity, Relation, Attribute). - */ public interface Concept { - /** - * Return as a Type if the Concept is a Type. - * - * @return A Type if the Concept is a Type - */ - @CheckReturnValue Type asType(); - /** - * Return as a Thing if the Concept is a Thing. - * - * @return A Thing if the Concept is a Thing - */ - @CheckReturnValue Thing asThing(); - /** - * Return as a Rule if the Concept is a Rule. - * - * @return A Rule if the Concept is a Rule - */ - @CheckReturnValue Rule asRule(); - /** - * Return a Concept.Remote for this Concept. - * - * @param concepts The Concept API to use for the RPCs. - * @return A remote concept using the given Concept API to enable RPCs. - */ - Remote asRemote(Concepts concepts); - - /** - * Determine if the Concept is remote. - * - * @return true if the Concept is remote. - */ + Remote asRemote(Grakn.Transaction transaction); + default boolean isRemote() { return false; } interface Local extends Concept { - static Concept.Local of(ConceptProto.Concept concept) { - if (concept.hasThing()) { - return Thing.Local.of(concept.getThing()); - } else { - return Type.Local.of(concept.getType()); - } - } - - /** - * Return as a Type if the Concept is a Type. - * - * @return A Type if the Concept is a Type - */ @Override default Type.Local asType() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Type.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Type.class.getSimpleName())); } - /** - * Return as a Thing if the Concept is a Thing. - * - * @return A Thing if the Concept is a Thing - */ @Override default Thing.Local asThing() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Thing.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Thing.class.getSimpleName())); } - /** - * Return as a Rule if the Concept is a Rule. - * - * @return A Rule if the Concept is a Rule - */ @Override default Rule.Local asRule() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Rule.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Rule.class.getSimpleName())); } } - /** - * The base remote concept implementation. - * - * Provides the basic RPCs to delete a concept and check if it is deleted. - */ interface Remote extends Concept { - static Concept.Remote of(final Concepts concepts, ConceptProto.Concept concept) { + static Concept.Remote of(final Grakn.Transaction transaction, ConceptProto.Concept concept) { if (concept.hasThing()) { - return Thing.Remote.of(concepts, concept.getThing()); + return ThingImpl.Remote.of(transaction, concept.getThing()); } else { - return Type.Remote.of(concepts, concept.getType()); + return TypeImpl.Remote.of(transaction, concept.getType()); } } - /** - * Delete the Concept - */ void delete(); - /** - * Return whether the concept has been deleted. - */ boolean isDeleted(); - /** - * Return as a Type if the Concept is a Type. - * - * @return A Type if the Concept is a Type - */ @Override default Type.Remote asType() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Type.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Type.class.getSimpleName())); } - /** - * Return as a Thing if the Concept is a Thing. - * - * @return A Thing if the Concept is a Thing - */ @Override default Thing.Remote asThing() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Thing.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Thing.class.getSimpleName())); } - /** - * Return as a Rule if the Concept is a Rule. - * - * @return A Rule if the Concept is a Rule - */ @Override default Rule.Remote asRule() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Rule.class.getCanonicalName())); - } - - @Override - default Remote asRemote(Concepts concepts) { - return this; + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Rule.class.getSimpleName())); } @Override diff --git a/concept/Concepts.java b/concept/Concepts.java index 35cd63afb4..51d368945a 100644 --- a/concept/Concepts.java +++ b/concept/Concepts.java @@ -19,7 +19,9 @@ package grakn.client.concept; +import grakn.client.common.exception.GraknException; import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.EntityType; import grakn.client.concept.type.RelationType; @@ -27,59 +29,194 @@ import grakn.client.concept.type.Rule; import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; +import grakn.client.concept.type.impl.TypeImpl; +import grakn.client.rpc.RPCTransaction; import grakn.protocol.ConceptProto; import grakn.protocol.TransactionProto; +import graql.lang.common.GraqlToken; import graql.lang.pattern.Pattern; import javax.annotation.Nullable; import java.util.function.Function; import java.util.stream.Stream; -public interface Concepts { +import static grakn.client.common.ProtoBuilder.tracingData; +import static grakn.client.concept.proto.ConceptProtoBuilder.iid; +import static grakn.client.concept.proto.ConceptProtoBuilder.valueType; - ThingType.Remote getRootType(); +public final class Concepts { - EntityType.Remote getRootEntityType(); + private final RPCTransaction transaction; - RelationType.Remote getRootRelationType(); + public Concepts(final RPCTransaction transaction) { + this.transaction = transaction; + } - AttributeType.Remote getRootAttributeType(); + public ThingType.Local getRootThingType() { + return getType(GraqlToken.Type.THING.toString()).asThingType(); + } - RoleType.Remote getRootRoleType(); + public EntityType.Local getRootEntityType() { + return getType(GraqlToken.Type.ENTITY.toString()).asEntityType(); + } - Rule.Remote getRootRule(); + public RelationType.Local getRootRelationType() { + return getType(GraqlToken.Type.RELATION.toString()).asRelationType(); + } - EntityType.Remote putEntityType(String label); + public AttributeType.Local getRootAttributeType() { + return getType(GraqlToken.Type.ATTRIBUTE.toString()).asAttributeType(); + } - @Nullable - EntityType.Remote getEntityType(String label); + public RoleType.Local getRootRoleType() { + return getType(GraqlToken.Type.ROLE.toString()).asRoleType(); + } - RelationType.Remote putRelationType(String label); + public Rule.Local getRootRule() { + return getType(GraqlToken.Type.RULE.toString()).asRule(); + } - @Nullable - RelationType.Remote getRelationType(String label); + public EntityType.Remote putEntityType(final String label) { + final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setPutEntityTypeReq(TransactionProto.Transaction.PutEntityType.Req.newBuilder() + .setLabel(label)).build(); - AttributeType.Remote putAttributeType(String label, AttributeType.ValueType valueType); + final TransactionProto.Transaction.Res res = transaction.transceiver().sendAndReceiveOrThrow(req); + return TypeImpl.Remote.of(transaction, res.getPutEntityTypeRes().getEntityType()).asEntityType(); + } @Nullable - AttributeType.Remote getAttributeType(String label); - - Rule.Remote putRule(String label, Pattern when, Pattern then); + public EntityType.Local getEntityType(final String label) { + final Type.Local concept = getType(label); + if (concept instanceof EntityType) return concept.asEntityType(); + else return null; + } + + public RelationType.Remote putRelationType(final String label) { + final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setPutRelationTypeReq(TransactionProto.Transaction.PutRelationType.Req.newBuilder() + .setLabel(label)).build(); + final TransactionProto.Transaction.Res res = transaction.transceiver().sendAndReceiveOrThrow(req); + return TypeImpl.Remote.of(transaction, res.getPutRelationTypeRes().getRelationType()).asRelationType(); + } @Nullable - Rule.Remote getRule(String label); + public RelationType.Local getRelationType(final String label) { + final Type.Local concept = getType(label); + if (concept instanceof RelationType) return concept.asRelationType(); + else return null; + } + + public AttributeType.Local putAttributeType(final String label, final AttributeType.ValueType valueType) { + final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setPutAttributeTypeReq(TransactionProto.Transaction.PutAttributeType.Req.newBuilder() + .setLabel(label) + .setValueType(valueType(valueType))).build(); + final TransactionProto.Transaction.Res res = transaction.transceiver().sendAndReceiveOrThrow(req); + return TypeImpl.Local.of(res.getPutAttributeTypeRes().getAttributeType()).asAttributeType(); + } @Nullable - Type.Remote getType(String label); + public AttributeType.Local getAttributeType(final String label) { + final Type.Local concept = getType(label); + if (concept instanceof AttributeType) return concept.asAttributeType(); + else return null; + } + + public Rule.Remote putRule(final String label, final Pattern when, final Pattern then) { + throw new GraknException(new UnsupportedOperationException()); + /*final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setPutRuleReq(TransactionProto.Transaction.PutRule.Req.newBuilder() + .setLabel(label) + .setWhen(when.toString()) + .setThen(then.toString())).build(); + + final TransactionProto.Transaction.Res res = sendAndReceiveOrThrow(req); + return Type.Remote.of(this, res.getPutRuleRes().getRule()).asRule();*/ + } @Nullable - Thing.Remote getThing(String iid); - - TransactionProto.Transaction.Res runThingMethod(String iid, ConceptProto.ThingMethod.Req thingMethod); + public Rule.Local getRule(String label) { + Type.Local concept = getType(label); + if (concept instanceof Rule) return concept.asRule(); + else return null; + } - TransactionProto.Transaction.Res runTypeMethod(String label, ConceptProto.TypeMethod.Req typeMethod); - - Stream iterateThingMethod(String iid, ConceptProto.ThingMethod.Iter.Req thingMethod, Function responseReader); + @Nullable + public Type.Local getType(final String label) { + final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setGetTypeReq(TransactionProto.Transaction.GetType.Req.newBuilder().setLabel(label)).build(); + + final TransactionProto.Transaction.Res response = transaction.transceiver().sendAndReceiveOrThrow(req); + switch (response.getGetTypeRes().getResCase()) { + case TYPE: + return TypeImpl.Local.of(response.getGetTypeRes().getType()); + default: + case RES_NOT_SET: + return null; + } + } - Stream iterateTypeMethod(String label, ConceptProto.TypeMethod.Iter.Req typeMethod, Function responseReader); + @Nullable + public Thing.Local getThing(final String iid) { + final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() + .putAllMetadata(tracingData()) + .setGetThingReq(TransactionProto.Transaction.GetThing.Req.newBuilder().setIid(iid(iid))).build(); + + final TransactionProto.Transaction.Res response = transaction.transceiver().sendAndReceiveOrThrow(req); + switch (response.getGetThingRes().getResCase()) { + case THING: + return ThingImpl.Local.of(response.getGetThingRes().getThing()); + default: + case RES_NOT_SET: + return null; + } + } + + public TransactionProto.Transaction.Res runThingMethod(final String iid, final ConceptProto.ThingMethod.Req thingMethod) { + final TransactionProto.Transaction.Req request = TransactionProto.Transaction.Req.newBuilder() + .setConceptMethodThingReq(TransactionProto.Transaction.ConceptMethod.Thing.Req.newBuilder() + .setIid(iid(iid)) + .setMethod(thingMethod)).build(); + + return transaction.transceiver().sendAndReceiveOrThrow(request); + } + + public TransactionProto.Transaction.Res runTypeMethod(final String label, @Nullable final String scope, final ConceptProto.TypeMethod.Req method) { + final TransactionProto.Transaction.ConceptMethod.Type.Req.Builder typeMethod = + TransactionProto.Transaction.ConceptMethod.Type.Req.newBuilder().setLabel(label).setMethod(method); + if (scope != null && !scope.isEmpty()) typeMethod.setScope(scope); + + final TransactionProto.Transaction.Req request = TransactionProto.Transaction.Req.newBuilder() + .setConceptMethodTypeReq(typeMethod.build()).build(); + + return transaction.transceiver().sendAndReceiveOrThrow(request); + } + + public Stream iterateThingMethod(final String iid, final ConceptProto.ThingMethod.Iter.Req method, + final Function responseReader) { + final TransactionProto.Transaction.Iter.Req request = TransactionProto.Transaction.Iter.Req.newBuilder() + .setConceptMethodThingIterReq(TransactionProto.Transaction.ConceptMethod.Thing.Iter.Req.newBuilder() + .setIid(iid(iid)) + .setMethod(method)).build(); + + return transaction.transceiver().iterate(request, res -> responseReader.apply(res.getConceptMethodThingIterRes().getResponse())); + } + + public Stream iterateTypeMethod(final String label, @Nullable final String scope, final ConceptProto.TypeMethod.Iter.Req method, + final Function responseReader) { + final TransactionProto.Transaction.ConceptMethod.Type.Iter.Req.Builder typeMethod = + TransactionProto.Transaction.ConceptMethod.Type.Iter.Req.newBuilder().setLabel(label).setMethod(method); + if (scope != null && !scope.isEmpty()) typeMethod.setScope(scope); + + final TransactionProto.Transaction.Iter.Req request = TransactionProto.Transaction.Iter.Req.newBuilder() + .setConceptMethodTypeIterReq(typeMethod.build()).build(); + + return transaction.transceiver().iterate(request, res -> responseReader.apply(res.getConceptMethodTypeIterRes().getResponse())); + } } diff --git a/concept/answer/Answer.java b/concept/answer/Answer.java index 182fdba160..e709bb1381 100644 --- a/concept/answer/Answer.java +++ b/concept/answer/Answer.java @@ -23,20 +23,11 @@ import grakn.client.common.exception.GraknException; import grakn.protocol.AnswerProto; -import javax.annotation.CheckReturnValue; - import static grakn.client.common.exception.ErrorMessage.Protocol.REQUIRED_FIELD_NOT_SET; import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; -/** - * An object that contains the answer of every Graql Query. - */ public interface Answer { - /** - * Whether this answer has an Explanation that can be retrieved - */ - @CheckReturnValue boolean hasExplanation(); static Answer of(final Transaction tx, final AnswerProto.Answer res) { diff --git a/concept/answer/AnswerGroup.java b/concept/answer/AnswerGroup.java index f74d3795bb..94baa235bf 100644 --- a/concept/answer/AnswerGroup.java +++ b/concept/answer/AnswerGroup.java @@ -21,18 +21,14 @@ import grakn.client.Grakn.Transaction; import grakn.client.concept.Concept; +import grakn.client.concept.thing.impl.ThingImpl; +import grakn.client.concept.type.impl.TypeImpl; import grakn.protocol.AnswerProto; import java.util.List; import static java.util.stream.Collectors.toList; -/** - * A type of Answer object that contains a List of Answers as the members and a RemoteConcept - * as the owner. - * - * @param the type of Answer being grouped - */ public class AnswerGroup implements Answer { private final Concept.Local owner; @@ -44,10 +40,10 @@ public AnswerGroup(Concept.Local owner, List answers) { } public static AnswerGroup of(final Transaction tx, final AnswerProto.AnswerGroup res) { - return new AnswerGroup<>( - Concept.Local.of(res.getOwner()), - res.getAnswersList().stream().map(answer -> Answer.of(tx, answer)).collect(toList()) - ); + Concept.Local concept; + if (res.getOwner().hasThing()) concept = ThingImpl.Local.of(res.getOwner().getThing()); + else concept = TypeImpl.Local.of(res.getOwner().getType()); + return new AnswerGroup<>(concept, res.getAnswersList().stream().map(answer -> Answer.of(tx, answer)).collect(toList())); } @Override diff --git a/concept/answer/AnswerMessageReader.java b/concept/answer/AnswerProtoReader.java similarity index 97% rename from concept/answer/AnswerMessageReader.java rename to concept/answer/AnswerProtoReader.java index 8f5d5e40b2..8b381fb20d 100644 --- a/concept/answer/AnswerMessageReader.java +++ b/concept/answer/AnswerProtoReader.java @@ -28,7 +28,7 @@ import static grakn.common.collection.Bytes.bytesToHexString; -abstract class AnswerMessageReader { +abstract class AnswerProtoReader { static String iid(final ByteString res) { return bytesToHexString(res.toByteArray()); diff --git a/concept/answer/ConceptList.java b/concept/answer/ConceptList.java index efaef84fe3..3bc32c4b5d 100644 --- a/concept/answer/ConceptList.java +++ b/concept/answer/ConceptList.java @@ -26,9 +26,6 @@ import static java.util.stream.Collectors.toList; -/** - * A type of Answer object that contains a List of Concepts. - */ public class ConceptList implements Answer { // TODO: change to store List once we are able to construct Concept without a database look up @@ -39,7 +36,7 @@ public ConceptList(List list) { } public static ConceptList of(final AnswerProto.ConceptList res) { - return new ConceptList(res.getIidsList().stream().map(AnswerMessageReader::iid).collect(toList())); + return new ConceptList(res.getIidsList().stream().map(AnswerProtoReader::iid).collect(toList())); } public boolean hasExplanation() { diff --git a/concept/answer/ConceptMap.java b/concept/answer/ConceptMap.java index 378e5accac..9c040b24de 100644 --- a/concept/answer/ConceptMap.java +++ b/concept/answer/ConceptMap.java @@ -22,11 +22,12 @@ import grakn.client.Grakn.Transaction; import grakn.client.common.exception.GraknException; import grakn.client.concept.Concept; +import grakn.client.concept.thing.impl.ThingImpl; +import grakn.client.concept.type.impl.TypeImpl; import grakn.protocol.AnswerProto; import graql.lang.Graql; import graql.lang.pattern.Pattern; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; @@ -40,9 +41,6 @@ import static grakn.client.common.exception.ErrorMessage.Query.VARIABLE_DOES_NOT_EXIST; -/** - * A type of Answer object that contains a Map of Concepts. - */ public class ConceptMap implements Answer { private final Map map; @@ -59,17 +57,18 @@ public ConceptMap(Map map, Pattern queryPattern, boolean hasExp public static ConceptMap of(final Transaction tx, final AnswerProto.ConceptMap res) { final Map variableMap = new HashMap<>(); - res.getMapMap().forEach((resVar, resConcept) -> variableMap.put(resVar, Concept.Local.of(resConcept))); + res.getMapMap().forEach((resVar, resConcept) -> { + Concept.Local concept; + if (resConcept.hasThing()) concept = ThingImpl.Local.of(resConcept.getThing()); + else concept = TypeImpl.Local.of(resConcept.getType()); + variableMap.put(resVar, concept); + }); boolean hasExplanation = res.getHasExplanation(); Pattern queryPattern = res.getPattern().equals("") ? null : Graql.parsePattern(res.getPattern()); return new ConceptMap(Collections.unmodifiableMap(variableMap), queryPattern, hasExplanation, tx); } - /** - * @return all explanations taking part in the derivation of this answer - */ @Nullable - @CheckReturnValue public Set explanations() { if (this.explanation() == null) return Collections.emptySet(); Set explanations = new HashSet<>(); @@ -83,7 +82,6 @@ public Set explanations() { return explanations; } - @CheckReturnValue public Explanation explanation() { if (hasExplanation) { return tx.getExplanation(this); @@ -92,7 +90,6 @@ public Explanation explanation() { } } - @CheckReturnValue public Pattern queryPattern() { return queryPattern; } @@ -102,17 +99,14 @@ public boolean hasExplanation() { return hasExplanation; } - @CheckReturnValue public Map map() { return map; } - @CheckReturnValue public Collection concepts() { return map.values(); } - @CheckReturnValue public Concept get(String variable) { Concept concept = map.get(variable); if (concept == null) throw new GraknException(VARIABLE_DOES_NOT_EXIST.message(variable)); diff --git a/concept/answer/ConceptSet.java b/concept/answer/ConceptSet.java index f75c9d5bf9..1ce43695be 100644 --- a/concept/answer/ConceptSet.java +++ b/concept/answer/ConceptSet.java @@ -25,9 +25,6 @@ import static java.util.stream.Collectors.toSet; -/** - * A type of Answer object that contains a Set. - */ public class ConceptSet implements Answer { // TODO: change to store Set once we are able to construct Concept without a database look up @@ -38,7 +35,7 @@ public ConceptSet(Set set) { } public static ConceptSet of(final AnswerProto.ConceptSet res) { - return new ConceptSet(res.getIidsList().stream().map(AnswerMessageReader::iid).collect(toSet())); + return new ConceptSet(res.getIidsList().stream().map(AnswerProtoReader::iid).collect(toSet())); } @Override diff --git a/concept/answer/ConceptSetMeasure.java b/concept/answer/ConceptSetMeasure.java index cea39bbae3..b5bfa83d5b 100644 --- a/concept/answer/ConceptSetMeasure.java +++ b/concept/answer/ConceptSetMeasure.java @@ -23,12 +23,9 @@ import java.util.Set; -import static grakn.client.concept.answer.AnswerMessageReader.number; +import static grakn.client.concept.answer.AnswerProtoReader.number; import static java.util.stream.Collectors.toSet; -/** - * A type of Answer object that contains a Set and Number, by extending RemoteConceptSet. - */ public class ConceptSetMeasure extends ConceptSet { private final Number measurement; @@ -40,7 +37,7 @@ public ConceptSetMeasure(Set set, Number measurement) { public static ConceptSetMeasure of(final AnswerProto.ConceptSetMeasure res) { return new ConceptSetMeasure( - res.getIidsList().stream().map(AnswerMessageReader::iid).collect(toSet()), + res.getIidsList().stream().map(AnswerProtoReader::iid).collect(toSet()), number(res.getMeasurement()) ); } diff --git a/concept/answer/Explanation.java b/concept/answer/Explanation.java index 8b137a6637..ad89c64472 100644 --- a/concept/answer/Explanation.java +++ b/concept/answer/Explanation.java @@ -19,24 +19,16 @@ package grakn.client.concept.answer; -import grakn.client.Grakn.Transaction; +import grakn.client.Grakn; import grakn.client.concept.type.Rule; -import grakn.client.concept.type.Type; +import grakn.client.concept.type.impl.TypeImpl; import grakn.protocol.AnswerProto; -import grakn.protocol.ConceptProto; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; -/** - * An Explanation can be retrieved using a specific ConceptMap. The concept map's pattern and variable mapping - * correspond to a satisified `then` clause of a rule. - * The corresponding Explanation, contains the concept maps that - * satisfy the `when` clause of a rule that was satisfied. - */ public class Explanation { private final List answers; @@ -47,21 +39,15 @@ public Explanation(List ans, @Nullable Rule.Remote rule) { this.rule = rule; } - public static Explanation of(final Transaction tx, final AnswerProto.Explanation.Res res) { + public static Explanation of(final Grakn.Transaction transaction, final AnswerProto.Explanation.Res res) { + final Rule.Remote rule = res.hasRule() ? TypeImpl.Remote.of(transaction, res.getRule()).asRule() : null; final List answers = new ArrayList<>(); - res.getExplanationList().forEach(explanationMap -> answers.add(ConceptMap.of(tx, explanationMap))); - final ConceptProto.Type ruleProto = res.getRule(); - final Rule.Remote rule = res.hasRule() ? Type.Remote.of(tx.concepts(), ruleProto).asRule() : null; + res.getExplanationList().forEach(explanationMap -> answers.add(ConceptMap.of(transaction, explanationMap))); return new Explanation(answers, rule); } - /** - * @return answers this explanation is dependent on - */ - @CheckReturnValue public List getAnswers() { return answers;} - @CheckReturnValue public Rule.Remote getRule() { return rule; } diff --git a/concept/answer/Numeric.java b/concept/answer/Numeric.java index cb8d9f1c04..529403cab7 100644 --- a/concept/answer/Numeric.java +++ b/concept/answer/Numeric.java @@ -21,9 +21,6 @@ import grakn.protocol.AnswerProto; -/** - * A type of Answer object that contains a Number. - */ public class Numeric implements Answer { private final Number number; @@ -33,7 +30,7 @@ public Numeric(Number number) { } public static Numeric of(final AnswerProto.Value res) { - return new Numeric(AnswerMessageReader.number(res.getNumber())); + return new Numeric(AnswerProtoReader.number(res.getNumber())); } @Override diff --git a/concept/proto/ConceptProtoBuilder.java b/concept/proto/ConceptProtoBuilder.java index cd79c807b0..ddf87d5108 100644 --- a/concept/proto/ConceptProtoBuilder.java +++ b/concept/proto/ConceptProtoBuilder.java @@ -44,9 +44,6 @@ import static grakn.common.collection.Bytes.hexStringToBytes; import static java.util.stream.Collectors.toList; -/** - * An RPC Request Builder class for Concept messages - */ public abstract class ConceptProtoBuilder { public static ConceptProto.Concept concept(Concept concept) { @@ -72,7 +69,7 @@ public static ConceptProto.Type type(Type type) { .setSchema(schema(type)); if (type instanceof RoleType) { - builder.setScopedLabel(type.asRoleType().getScopedLabel()); + builder.setScope(type.asRoleType().getScope()); } return builder.build(); diff --git a/concept/thing/Attribute.java b/concept/thing/Attribute.java index 1e10f50f57..ac1a37834a 100644 --- a/concept/thing/Attribute.java +++ b/concept/thing/Attribute.java @@ -19,13 +19,11 @@ package grakn.client.concept.thing; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.impl.AttributeImpl; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.ThingType; -import javax.annotation.CheckReturnValue; import java.time.LocalDateTime; import java.util.stream.Stream; @@ -33,50 +31,23 @@ public interface Attribute extends Thing { - /** - * Retrieves the type of the Attribute, that is, the AttributeType of which this resource is a Thing. - * - * @return The AttributeType of which this resource is a Thing. - */ - @Override - AttributeType getType(); - - /** - * Retrieves the value of the Attribute. - * - * @return The value itself - */ - @CheckReturnValue VALUE getValue(); - @CheckReturnValue Attribute.Boolean asBoolean(); - @CheckReturnValue Attribute.Long asLong(); - @CheckReturnValue Attribute.Double asDouble(); - @CheckReturnValue Attribute.String asString(); - @CheckReturnValue Attribute.DateTime asDateTime(); - @CheckReturnValue @Override - Attribute.Remote asRemote(Concepts concepts); - - /** - * Represent a literal Attribute in the graph. - * Acts as a Thing when relating to other instances except it has the added functionality of: - * 1. It is unique to its AttributeType based on its value. - * 2. It has an AttributeType.ValueType associated with it which constrains the allowed values. - */ + Attribute.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Thing.Local, Attribute { - @CheckReturnValue @Override default Attribute.Local asAttribute() { return this; @@ -108,45 +79,15 @@ default Attribute.DateTime.Local asDateTime() { } } - /** - * Represent a literal Attribute in the graph. - * Acts as an Thing when relating to other instances except it has the added functionality of: - * 1. It is unique to its AttributeType based on it's value. - * 2. It has an AttributeType.ValueType associated with it which constrains the allowed values. - */ interface Remote extends Thing.Remote, Attribute { - /** - * Retrieves the type of the Attribute, that is, the AttributeType of which this resource is an Thing. - * - * @return The AttributeType of which this resource is an Thing. - */ - @Override - AttributeType.Remote getType(); - - /** - * Retrieves the set of all Instances that possess this Attribute. - * - * @return The list of all Instances that possess this Attribute. - */ - @CheckReturnValue - Stream getOwners(); - - /** - * Retrieves the set of all Instances of the specified type that possess this Attribute. - * - * @return The list of all Instances of the specified type that possess this Attribute. - */ - @CheckReturnValue - Stream getOwners(ThingType ownerType); - - @CheckReturnValue + Stream getOwners(); + + Stream getOwners(ThingType ownerType); + @Override - default Attribute.Remote asRemote(Concepts concepts) { - return this; - } + AttributeType.Local getType(); - @CheckReturnValue @Override default Attribute.Remote asAttribute() { return this; @@ -180,34 +121,19 @@ default Attribute.DateTime.Remote asDateTime() { interface Boolean extends Attribute { + @Override + Attribute.Boolean.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Attribute.Boolean, Attribute.Local { - @CheckReturnValue @Override default Attribute.Boolean.Local asBoolean() { return this; } - - @CheckReturnValue - @Override - default Boolean.Remote asRemote(final Concepts concepts) { - return Boolean.Remote.of(concepts, getIID()); - } } interface Remote extends Attribute.Boolean, Attribute.Remote { - static Boolean.Remote of(final Concepts concepts, final java.lang.String iid) { - return new AttributeImpl.Boolean.Remote(concepts, iid); - } - - @CheckReturnValue - @Override - default Attribute.Boolean.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default Attribute.Boolean.Remote asBoolean() { return this; @@ -217,34 +143,19 @@ default Attribute.Boolean.Remote asBoolean() { interface Long extends Attribute { + @Override + Attribute.Long.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Attribute.Long, Attribute.Local { - @CheckReturnValue @Override default Attribute.Long.Local asLong() { return this; } - - @CheckReturnValue - @Override - default Long.Remote asRemote(final Concepts concepts) { - return Long.Remote.of(concepts, getIID()); - } } interface Remote extends Attribute.Long, Attribute.Remote { - static Long.Remote of(final Concepts concepts, final java.lang.String iid) { - return new AttributeImpl.Long.Remote(concepts, iid); - } - - @CheckReturnValue - @Override - default Attribute.Long.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default Attribute.Long.Remote asLong() { return this; @@ -254,34 +165,19 @@ default Attribute.Long.Remote asLong() { interface Double extends Attribute { + @Override + Attribute.Double.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Attribute.Double, Attribute.Local { - @CheckReturnValue @Override default Attribute.Double.Local asDouble() { return this; } - - @CheckReturnValue - @Override - default Double.Remote asRemote(final Concepts concepts) { - return Double.Remote.of(concepts, getIID()); - } } interface Remote extends Attribute.Double, Attribute.Remote { - static Double.Remote of(final Concepts concepts, final java.lang.String iid) { - return new AttributeImpl.Double.Remote(concepts, iid); - } - - @CheckReturnValue - @Override - default Attribute.Double.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default Attribute.Double.Remote asDouble() { return this; @@ -291,34 +187,19 @@ default Attribute.Double.Remote asDouble() { interface String extends Attribute { + @Override + Attribute.String.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Attribute.String, Attribute.Local { - @CheckReturnValue @Override default Attribute.String.Local asString() { return this; } - - @CheckReturnValue - @Override - default String.Remote asRemote(final Concepts concepts) { - return String.Remote.of(concepts, getIID()); - } } interface Remote extends Attribute.String, Attribute.Remote { - static String.Remote of(final Concepts concepts, final java.lang.String iid) { - return new AttributeImpl.String.Remote(concepts, iid); - } - - @CheckReturnValue - @Override - default Attribute.String.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default Attribute.String.Remote asString() { return this; @@ -328,34 +209,19 @@ default Attribute.String.Remote asString() { interface DateTime extends Attribute { + @Override + Attribute.DateTime.Remote asRemote(Grakn.Transaction transaction); + interface Local extends Attribute.DateTime, Attribute.Local { - @CheckReturnValue @Override default Attribute.DateTime.Local asDateTime() { return this; } - - @CheckReturnValue - @Override - default DateTime.Remote asRemote(final Concepts concepts) { - return DateTime.Remote.of(concepts, getIID()); - } } interface Remote extends Attribute.DateTime, Attribute.Remote { - static DateTime.Remote of(final Concepts concepts, final java.lang.String iid) { - return new AttributeImpl.DateTime.Remote(concepts, iid); - } - - @CheckReturnValue - @Override - default Attribute.DateTime.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default Attribute.DateTime.Remote asDateTime() { return this; diff --git a/concept/thing/Entity.java b/concept/thing/Entity.java index aa2441fce1..a4416c359b 100644 --- a/concept/thing/Entity.java +++ b/concept/thing/Entity.java @@ -19,72 +19,27 @@ package grakn.client.concept.thing; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.impl.EntityImpl; +import grakn.client.Grakn; import grakn.client.concept.type.EntityType; -import javax.annotation.CheckReturnValue; - -/** - * An instance of Entity Type EntityType - * This represents an entity in the graph. - * Entities are objects which are defined by their Attribute and their links to - * other entities via Relation - */ public interface Entity extends Thing { - /** - * @return The EntityType of this Entity - * @see EntityType - */ - @Override - EntityType getType(); - - @CheckReturnValue @Override - Entity.Remote asRemote(Concepts concepts); + Entity.Remote asRemote(Grakn.Transaction transaction); interface Local extends Thing.Local, Entity { - @CheckReturnValue @Override default Entity.Local asEntity() { return this; } - - @CheckReturnValue - @Override - default Entity.Remote asRemote(final Concepts concepts) { - return Entity.Remote.of(concepts, getIID()); - } } - /** - * An instance of Entity Type EntityType - * This represents an entity in the graph. - * Entities are objects which are defined by their Attribute and their links to - * other entities via Relation - */ interface Remote extends Thing.Remote, Entity { - static Entity.Remote of(Concepts concepts, String iid) { - return new EntityImpl.Remote(concepts, iid); - } - - /** - * @return The EntityType of this Entity - * @see EntityType.Remote - */ - @Override - EntityType.Remote getType(); - - @CheckReturnValue @Override - default Entity.Remote asRemote(Concepts concepts) { - return this; - } + EntityType.Local getType(); - @CheckReturnValue @Override default Entity.Remote asEntity() { return this; diff --git a/concept/thing/Relation.java b/concept/thing/Relation.java index 07a3d79d96..84705620ec 100644 --- a/concept/thing/Relation.java +++ b/concept/thing/Relation.java @@ -19,115 +19,40 @@ package grakn.client.concept.thing; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.impl.RelationImpl; +import grakn.client.Grakn; import grakn.client.concept.type.RelationType; import grakn.client.concept.type.RoleType; -import javax.annotation.CheckReturnValue; import java.util.List; import java.util.Map; import java.util.stream.Stream; -/** - * Encapsulates relations between Thing - * A relation which is an instance of a RelationType defines how instances may relate to one another. - * It represents how different entities relate to one another. - * Relation are used to model n-ary relations between instances. - */ public interface Relation extends Thing { - /** - * Retrieve the associated RelationType for this Relation. - * - * @return The associated RelationType for this Relation. - * @see RelationType - */ - @Override - RelationType getType(); - - @CheckReturnValue @Override - Relation.Remote asRemote(Concepts concepts); + Relation.Remote asRemote(Grakn.Transaction transaction); interface Local extends Thing.Local, Relation { - @CheckReturnValue @Override default Relation.Local asRelation() { return this; } - - @Override - default Relation.Remote asRemote(final Concepts concepts) { - return Relation.Remote.of(concepts, getIID()); - } } - /** - * Encapsulates relations between Thing - * A relation which is an instance of a RelationType defines how instances may relate to one another. - * It represents how different entities relate to one another. - * Relation are used to model n-ary relations between instances. - */ interface Remote extends Thing.Remote, Relation { - static Relation.Remote of(final Concepts concepts, final String iid) { - return new RelationImpl.Remote(concepts, iid); - } - - /** - * Retrieve the associated RelationType for this Relation. - * - * @return The associated RelationType for this Relation. - * @see RelationType.Remote - */ @Override - RelationType.Remote getType(); + RelationType.Local getType(); - /** - * Expands this Relation to include a new role player which is playing a specific role. - * - * @param roleType The RoleType of the new role player. - * @param player The new role player. - */ void addPlayer(RoleType roleType, Thing player); - /** - * Removes the Thing which is playing a RoleType in this Relation. - * If the Thing is not playing any RoleType in this Relation nothing happens. - * - * @param roleType The RoleType being played by the Thing - * @param player The Thing playing the Role in this Relation - */ void removePlayer(RoleType roleType, Thing player); - /** - * Retrieves a list of every Thing involved in the Relation, filtered by RoleType played. - * If no RoleTypes are specified then every involved Thing is retrieved, regardless of role. - * - * @param roleTypes Used to filter the returned instances only to ones that play any of the role types. - * @return A list of every Thing involved in the Relation, filtered by RoleType played. - */ - @CheckReturnValue - Stream getPlayers(RoleType... roleTypes); - - /** - * Retrieve a list of all Instances involved in the Relation, and the RoleTypes they play. - * - * @return A list of all the role types and the instances playing them in this Relation. - * @see RoleType.Remote - */ - @CheckReturnValue - Map> getPlayersByRoleType(); + Stream getPlayers(RoleType... roleTypes); - @CheckReturnValue - @Override - default Relation.Remote asRemote(Concepts concepts) { - return this; - } + Map> getPlayersByRoleType(); - @CheckReturnValue @Override default Relation.Remote asRelation() { return this; diff --git a/concept/thing/Thing.java b/concept/thing/Thing.java index 222be2e76e..9813befead 100644 --- a/concept/thing/Thing.java +++ b/concept/thing/Thing.java @@ -19,317 +19,99 @@ package grakn.client.concept.thing; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; import grakn.client.concept.Concept; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.impl.AttributeImpl; -import grakn.client.concept.thing.impl.EntityImpl; -import grakn.client.concept.thing.impl.RelationImpl; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.RoleType; -import grakn.client.concept.type.Rule; import grakn.client.concept.type.ThingType; -import grakn.protocol.ConceptProto; -import javax.annotation.CheckReturnValue; import java.util.stream.Stream; import static grakn.client.common.exception.ErrorMessage.Concept.INVALID_CONCEPT_CASTING; -import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; -import static grakn.common.collection.Bytes.bytesToHexString; - -/** - * A data instance in the graph belonging to a specific Type - * Instances represent data in the graph. - * Every instance belongs to a Type which serves as a way of categorising them. - * Instances can relate to one another via Relation - */ + public interface Thing extends Concept { - /** - * Get the unique IID associated with the Thing. - * - * @return The thing's unique IID. - */ - @CheckReturnValue String getIID(); - /** - * Return the Type of the Concept. - * - * @return A Type which is the type of this concept. This concept is an instance of that type. - */ - @CheckReturnValue - ThingType getType(); - - /** - * Return as an Entity, if the Thing is an Entity. - * - * @return An Entity if the Thing is an Entity - */ - @CheckReturnValue Entity asEntity(); - /** - * Return as a Attribute if the Thing is a Attribute. - * - * @return A Attribute if the Thing is an Attribute - */ - @CheckReturnValue Attribute asAttribute(); - /** - * Return as a Relation if the Thing is a Relation. - * - * @return A Relation if the Thing is a Relation - */ - @CheckReturnValue Relation asRelation(); - /** - * Return a Thing.Remote for this Thing. - * - * @param concepts The transaction to use for the RPCs. - * @return A remote concept using the given transaction to enable RPCs. - */ - @CheckReturnValue @Override - Thing.Remote asRemote(Concepts concepts); + Thing.Remote asRemote(Grakn.Transaction transaction); interface Local extends Concept.Local, Thing { - static Thing.Local of(final ConceptProto.Thing thing) { - switch (thing.getSchema()) { - case ENTITY: - return new EntityImpl.Local(thing); - case RELATION: - return new RelationImpl.Local(thing); - case ATTRIBUTE: - switch (thing.getValueType()) { - case BOOLEAN: - return new AttributeImpl.Boolean.Local(thing); - case LONG: - return new AttributeImpl.Long.Local(thing); - case DOUBLE: - return new AttributeImpl.Double.Local(thing); - case STRING: - return new AttributeImpl.String.Local(thing); - case DATETIME: - return new AttributeImpl.DateTime.Local(thing); - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.AttributeType.VALUE_TYPE.class.getCanonicalName(), thing.getValueType())); - } - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Thing.SCHEMA.class.getCanonicalName(), thing.getSchema())); - } - } - - @CheckReturnValue @Override default Thing.Local asThing() { return this; } - /** - * Return as an Entity, if the Concept is an Entity Thing. - * - * @return An Entity if the Concept is a Thing - */ - @CheckReturnValue @Override default Entity.Local asEntity() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Entity.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Entity.class.getSimpleName())); } - /** - * Return as a Attribute if the Concept is a Attribute Thing. - * - * @return A Attribute if the Concept is a Attribute - */ - @CheckReturnValue @Override default Attribute.Local asAttribute() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Attribute.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Attribute.class.getSimpleName())); } - /** - * Return as a Relation if the Concept is a Relation Thing. - * - * @return A Relation if the Concept is a Relation - */ - @CheckReturnValue @Override default Relation.Local asRelation() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Relation.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Relation.class.getSimpleName())); } } - /** - * A data instance in the graph belonging to a specific Type - * Instances represent data in the graph. - * Every instance belongs to a Type which serves as a way of categorising them. - * Instances can relate to one another via Relation - */ interface Remote extends Concept.Remote, Thing { - static Thing.Remote of(final Concepts concepts, final ConceptProto.Thing thing) { - final String iid = bytesToHexString(thing.getIid().toByteArray()); - switch (thing.getSchema()) { - case ENTITY: - return new EntityImpl.Remote(concepts, iid); - case RELATION: - return new RelationImpl.Remote(concepts, iid); - case ATTRIBUTE: - switch (thing.getValueType()) { - case BOOLEAN: - return new AttributeImpl.Boolean.Remote(concepts, iid); - case LONG: - return new AttributeImpl.Long.Remote(concepts, iid); - case DOUBLE: - return new AttributeImpl.Double.Remote(concepts, iid); - case STRING: - return new AttributeImpl.String.Remote(concepts, iid); - case DATETIME: - return new AttributeImpl.DateTime.Remote(concepts, iid); - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.AttributeType.VALUE_TYPE.class.getCanonicalName(), thing.getValueType())); - } - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Thing.SCHEMA.class.getCanonicalName(), thing.getSchema())); - } - } + ThingType.Local getType(); - /** - * Creates an ownership from this Thing to the provided Attribute. - * - * @param attribute The Attribute to which an ownership is created - */ void setHas(Attribute attribute); - /** - * Removes the provided Attribute from this Thing - * - * @param attribute the Attribute to be removed - */ void unsetHas(Attribute attribute); - /** - * Return the Type of the Concept. - * - * @return A Type which is the type of this concept. This concept is an instance of that type. - */ - @Override - @CheckReturnValue - ThingType.Remote getType(); - - /** - * Used to indicate if this Thing has been created as the result of a Rule inference. - * - * @return true if this Thing exists due to a rule - * @see Rule - */ boolean isInferred(); - /** - * Retrieves a collection of Attribute attached to this Thing, possibly specifying only keys. - * - * @param onlyKey If true, only fetch attributes which are keys. - * @return A collection of Attributes attached to this Thing. - * @see Attribute.Remote - */ - @CheckReturnValue - Stream> getHas(boolean onlyKey); - - @CheckReturnValue - Stream getHas(AttributeType.Boolean attributeType); - - @CheckReturnValue - Stream getHas(AttributeType.Long attributeType); - - @CheckReturnValue - Stream getHas(AttributeType.Double attributeType); - - @CheckReturnValue - Stream getHas(AttributeType.String attributeType); - - @CheckReturnValue - Stream getHas(AttributeType.DateTime attributeType); - - /** - * Retrieves a collection of Attribute attached to this Thing - * - * @param attributeTypes AttributeTypes of the Attributes attached to this entity - * @return A collection of Attributes attached to this Thing. - * @see Attribute.Remote - */ - @CheckReturnValue - Stream> getHas(AttributeType... attributeTypes); - - /** - * Determine the RoleTypes that this Thing is currently playing. - * - * @return A set of all the RoleTypes which this Thing is currently playing. - * @see RoleType.Remote - */ - @CheckReturnValue - Stream getPlays(); - - /** - * Get all {@code Relation} instances that this {@code Thing} is playing any of the specified roles in. - * If no roles are specified, all Relations are retrieved regardless of role. - * - * @param roleTypes The role types that this {@code Thing} can play - * @return a stream of {@code Relation} that this {@code Thing} plays a specified role in - */ + Stream> getHas(boolean onlyKey); + + Stream getHas(AttributeType.Boolean attributeType); + + Stream getHas(AttributeType.Long attributeType); + + Stream getHas(AttributeType.Double attributeType); + + Stream getHas(AttributeType.String attributeType); + + Stream getHas(AttributeType.DateTime attributeType); + + Stream> getHas(AttributeType... attributeTypes); + + Stream getPlays(); + Stream getRelations(RoleType... roleTypes); - @CheckReturnValue @Override default Thing.Remote asThing() { return this; } - /** - * Return as an Entity, if the Thing is an Entity. - * - * @return An Entity if the Thing is an Entity - */ @Override - @CheckReturnValue default Entity.Remote asEntity() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Entity.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Entity.class.getSimpleName())); } - /** - * Return as a Relation if the Thing is a Relation. - * - * @return A Relation if the Thing is a Relation - */ @Override - @CheckReturnValue default Relation.Remote asRelation() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Relation.class.getCanonicalName())); - } - - @CheckReturnValue - @Override - default Thing.Remote asRemote(Concepts concepts) { - return this; + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Relation.class.getSimpleName())); } - /** - * Return as a Attribute if the Thing is a Attribute. - * - * @return An Attribute if the Thing is an Attribute - */ @Override - @CheckReturnValue default Attribute.Remote asAttribute() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Attribute.class.getCanonicalName())); + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, Attribute.class.getSimpleName())); } } } diff --git a/concept/thing/impl/AttributeImpl.java b/concept/thing/impl/AttributeImpl.java index 0b191eea90..2478084247 100644 --- a/concept/thing/impl/AttributeImpl.java +++ b/concept/thing/impl/AttributeImpl.java @@ -19,86 +19,124 @@ package grakn.client.concept.thing.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; +import grakn.client.common.exception.GraknException; import grakn.client.concept.thing.Attribute; import grakn.client.concept.thing.Thing; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.ThingType; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.Attribute.GetOwners; +import grakn.protocol.ConceptProto.ThingMethod; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.stream.Stream; +import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; import static grakn.client.concept.proto.ConceptProtoBuilder.type; +import static grakn.common.collection.Bytes.bytesToHexString; public abstract class AttributeImpl { - /** - * Client implementation of Attribute - * - * @param The value type of this attribute - */ public abstract static class Local extends ThingImpl.Local implements Attribute.Local { - public Local(final ConceptProto.Thing thing) { - super(thing); + Local(final java.lang.String iid) { + super(iid); } - @Override - public AttributeType.Local getType() { - return super.getType().asAttributeType(); + public static AttributeImpl.Local of(ConceptProto.Thing thing) { + switch (thing.getValueType()) { + case BOOLEAN: + return AttributeImpl.Boolean.Local.of(thing); + case LONG: + return AttributeImpl.Long.Local.of(thing); + case DOUBLE: + return AttributeImpl.Double.Local.of(thing); + case STRING: + return AttributeImpl.String.Local.of(thing); + case DATETIME: + return AttributeImpl.DateTime.Local.of(thing); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message( + ConceptProto.AttributeType.VALUE_TYPE.class.getSimpleName(), thing.getValueType()) + ); + } } public abstract VALUE getValue(); } - /** - * Client implementation of Attribute - * - * @param The value type of this attribute - */ public abstract static class Remote extends ThingImpl.Remote implements Attribute.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Thing thingProto) { + switch (thingProto.getValueType()) { + case BOOLEAN: + return AttributeImpl.Boolean.Remote.of(transaction, thingProto); + case LONG: + return AttributeImpl.Long.Remote.of(transaction, thingProto); + case DOUBLE: + return AttributeImpl.Double.Remote.of(transaction, thingProto); + case STRING: + return AttributeImpl.String.Remote.of(transaction, thingProto); + case DATETIME: + return AttributeImpl.DateTime.Remote.of(transaction, thingProto); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message( + ConceptProto.AttributeType.VALUE_TYPE.class.getSimpleName(), thingProto.getValueType()) + ); + } } @Override - public final Stream getOwners() { - ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() - .setAttributeGetOwnersIterReq(ConceptProto.Attribute.GetOwners.Iter.Req.getDefaultInstance()).build(); - return thingStream(method, res -> res.getAttributeGetOwnersIterRes().getThing()); + public final Stream getOwners() { + return stream( + ThingMethod.Iter.Req.newBuilder().setAttributeGetOwnersIterReq( + GetOwners.Iter.Req.getDefaultInstance()).build(), + res -> res.getAttributeGetOwnersIterRes().getThing() + ); } @Override - public Stream getOwners(ThingType ownerType) { - ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() - .setAttributeGetOwnersIterReq(ConceptProto.Attribute.GetOwners.Iter.Req.newBuilder() - .setThingType(type(ownerType))).build(); - return thingStream(method, res -> res.getAttributeGetOwnersIterRes().getThing()); + public Stream getOwners(ThingType ownerType) { + return stream( + ThingMethod.Iter.Req.newBuilder().setAttributeGetOwnersIterReq( + GetOwners.Iter.Req.newBuilder().setThingType(type(ownerType))).build(), + res -> res.getAttributeGetOwnersIterRes().getThing() + ); } @Override - public AttributeType.Remote getType() { - return (AttributeType.Remote) super.getType(); + public AttributeType.Local getType() { + return super.getType().asAttributeType(); } public abstract VALUE getValue(); } public abstract static class Boolean implements Attribute.Boolean { - /** - * Client implementation of Attribute.Boolean - */ + public static class Local extends AttributeImpl.Local implements Attribute.Boolean.Local { private final java.lang.Boolean value; - public Local(final ConceptProto.Thing thing) { - super(thing); - this.value = thing.getValue().getBoolean(); + Local(final java.lang.String iid, boolean value) { + super(iid); + this.value = value; + } + + public static AttributeImpl.Boolean.Local of(final ConceptProto.Thing thingProto) { + return new AttributeImpl.Boolean.Local( + bytesToHexString(thingProto.getIid().toByteArray()), + thingProto.getValue().getBoolean() + ); } @Override @@ -110,43 +148,64 @@ public final java.lang.Boolean getValue() { public final AttributeImpl.Boolean.Local asBoolean() { return this; } + + @Override + public AttributeImpl.Boolean.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Boolean.Remote(transaction, getIID()); + } } - /** - * Client implementation of Attribute.Boolean - */ public static class Remote extends AttributeImpl.Remote implements Attribute.Boolean.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.Boolean.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing thingProto) { + return new AttributeImpl.Boolean.Remote(transaction, bytesToHexString(thingProto.getIid().toByteArray())); + } + + @Override + public Attribute.Boolean.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Boolean.Remote(transaction, iid); } @Override public final java.lang.Boolean getValue() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setAttributeGetValueReq(ConceptProto.Attribute.GetValue.Req.getDefaultInstance()).build(); - return runMethod(method).getAttributeGetValueRes().getValue().getBoolean(); + return execute(method).getAttributeGetValueRes().getValue().getBoolean(); } @Override - public AttributeType.Boolean.Remote getType() { + public AttributeType.Boolean.Local getType() { return super.getType().asBoolean(); } } } public abstract static class Long implements Attribute.Long { - /** - * Client implementation of Attribute.Long - */ + public static class Local extends AttributeImpl.Local implements Attribute.Long.Local { private final long value; - public Local(final ConceptProto.Thing thing) { - super(thing); - this.value = thing.getValue().getLong(); + Local(final java.lang.String iid, long value) { + super(iid); + this.value = value; + } + + public static AttributeImpl.Long.Local of(final ConceptProto.Thing thingProto) { + return new AttributeImpl.Long.Local( + bytesToHexString(thingProto.getIid().toByteArray()), + thingProto.getValue().getLong() + ); + } + + @Override + public AttributeImpl.Long.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Long.Remote(transaction, getIID()); } @Override @@ -160,41 +219,57 @@ public final AttributeImpl.Long.Local asLong() { } } - /** - * Client implementation of Attribute.Long - */ public static class Remote extends AttributeImpl.Remote implements Attribute.Long.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.Long.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing thingProto) { + return new AttributeImpl.Long.Remote(transaction, bytesToHexString(thingProto.getIid().toByteArray())); + } + + @Override + public Attribute.Long.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Long.Remote(transaction, iid); } @Override public final java.lang.Long getValue() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setAttributeGetValueReq(ConceptProto.Attribute.GetValue.Req.getDefaultInstance()).build(); - return runMethod(method).getAttributeGetValueRes().getValue().getLong(); + return execute(method).getAttributeGetValueRes().getValue().getLong(); } @Override - public AttributeType.Long.Remote getType() { + public AttributeType.Long.Local getType() { return super.getType().asLong(); } } } public abstract static class Double implements Attribute.Double { - /** - * Client implementation of Attribute.Double - */ + public static class Local extends AttributeImpl.Local implements Attribute.Double.Local { private final double value; - public Local(final ConceptProto.Thing thing) { - super(thing); - this.value = thing.getValue().getDouble(); + Local(final java.lang.String iid, double value) { + super(iid); + this.value = value; + } + + public static AttributeImpl.Double.Local of(final ConceptProto.Thing thingProto) { + return new AttributeImpl.Double.Local( + bytesToHexString(thingProto.getIid().toByteArray()), + thingProto.getValue().getDouble() + ); + } + + @Override + public AttributeImpl.Double.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Double.Remote(transaction, getIID()); } @Override @@ -208,41 +283,57 @@ public final AttributeImpl.Double.Local asDouble() { } } - /** - * Client implementation of Attribute.Double - */ public static class Remote extends AttributeImpl.Remote implements Attribute.Double.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.Double.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing thingProto) { + return new AttributeImpl.Double.Remote(transaction, bytesToHexString(thingProto.getIid().toByteArray())); + } + + @Override + public Attribute.Double.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.Double.Remote(transaction, iid); } @Override public final java.lang.Double getValue() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setAttributeGetValueReq(ConceptProto.Attribute.GetValue.Req.getDefaultInstance()).build(); - return runMethod(method).getAttributeGetValueRes().getValue().getDouble(); + return execute(method).getAttributeGetValueRes().getValue().getDouble(); } @Override - public AttributeType.Double.Remote getType() { + public AttributeType.Double.Local getType() { return super.getType().asDouble(); } } } public abstract static class String implements Attribute.String { - /** - * Client implementation of Attribute.String - */ + public static class Local extends AttributeImpl.Local implements Attribute.String.Local { private final java.lang.String value; - public Local(final ConceptProto.Thing thing) { - super(thing); - this.value = thing.getValue().getString(); + Local(final java.lang.String iid, java.lang.String value) { + super(iid); + this.value = value; + } + + public static AttributeImpl.String.Local of(final ConceptProto.Thing thingProto) { + return new AttributeImpl.String.Local( + bytesToHexString(thingProto.getIid().toByteArray()), + thingProto.getValue().getString() + ); + } + + @Override + public AttributeImpl.String.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.String.Remote(transaction, getIID()); } @Override @@ -256,25 +347,31 @@ public final AttributeImpl.String.Local asString() { } } - /** - * Client implementation of Attribute.String - */ public static class Remote extends AttributeImpl.Remote implements Attribute.String.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.String.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing thingProto) { + return new AttributeImpl.String.Remote(transaction, bytesToHexString(thingProto.getIid().toByteArray())); } @Override public final java.lang.String getValue() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setAttributeGetValueReq(ConceptProto.Attribute.GetValue.Req.getDefaultInstance()).build(); - return runMethod(method).getAttributeGetValueRes().getValue().getString(); + return execute(method).getAttributeGetValueRes().getValue().getString(); + } + + @Override + public Attribute.String.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.String.Remote(transaction, iid); } @Override - public AttributeType.String.Remote getType() { + public AttributeType.String.Local getType() { return super.getType().asString(); } } @@ -286,16 +383,25 @@ private static LocalDateTime toLocalDateTime(long rpcDatetime) { return LocalDateTime.ofInstant(Instant.ofEpochMilli(rpcDatetime), ZoneId.of("Z")); } - /** - * Client implementation of Attribute.DateTime - */ public static class Local extends AttributeImpl.Local implements Attribute.DateTime.Local { private final LocalDateTime value; - public Local(final ConceptProto.Thing thing) { - super(thing); - this.value = toLocalDateTime(thing.getValue().getDatetime()); + Local(final java.lang.String iid, LocalDateTime value) { + super(iid); + this.value = value; + } + + public static AttributeImpl.DateTime.Local of(final ConceptProto.Thing thingProto) { + return new AttributeImpl.DateTime.Local( + bytesToHexString(thingProto.getIid().toByteArray()), + toLocalDateTime(thingProto.getValue().getDatetime()) + ); + } + + @Override + public AttributeImpl.DateTime.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.DateTime.Remote(transaction, getIID()); } @Override @@ -309,25 +415,31 @@ public final AttributeImpl.DateTime.Local asDateTime() { } } - /** - * Client implementation of Attribute.DateTime - */ public static class Remote extends AttributeImpl.Remote implements Attribute.DateTime.Remote { - public Remote(final Concepts concepts, final java.lang.String iid) { - super(concepts, iid); + Remote(final Grakn.Transaction transaction, final java.lang.String iid) { + super(transaction, iid); + } + + public static AttributeImpl.DateTime.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing thingProto) { + return new AttributeImpl.DateTime.Remote(transaction, bytesToHexString(thingProto.getIid().toByteArray())); + } + + @Override + public Attribute.DateTime.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeImpl.DateTime.Remote(transaction, iid); } @Override public final LocalDateTime getValue() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setAttributeGetValueReq(ConceptProto.Attribute.GetValue.Req.getDefaultInstance()).build(); - return toLocalDateTime(runMethod(method).getAttributeGetValueRes().getValue().getDatetime()); + return toLocalDateTime(execute(method).getAttributeGetValueRes().getValue().getDatetime()); } @Override - public AttributeType.DateTime.Remote getType() { + public AttributeType.DateTime.Local getType() { return super.getType().asDateTime(); } } diff --git a/concept/thing/impl/EntityImpl.java b/concept/thing/impl/EntityImpl.java index bbc5e433d7..ebdf79cdd2 100644 --- a/concept/thing/impl/EntityImpl.java +++ b/concept/thing/impl/EntityImpl.java @@ -19,38 +19,47 @@ package grakn.client.concept.thing.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Entity; import grakn.client.concept.type.EntityType; +import grakn.common.collection.Bytes; import grakn.protocol.ConceptProto; public abstract class EntityImpl { - /** - * Client implementation of Entity - */ public static class Local extends ThingImpl.Local implements Entity.Local { - public Local(final ConceptProto.Thing thing) { - super(thing); + Local(String iid) { + super(iid); } - public EntityType.Local getType() { - return super.getType().asEntityType(); + public static EntityImpl.Local of(final ConceptProto.Thing protoThing) { + return new EntityImpl.Local(Bytes.bytesToHexString(protoThing.getIid().toByteArray())); + } + + @Override + public EntityImpl.Remote asRemote(final Grakn.Transaction transaction) { + return new EntityImpl.Remote(transaction, getIID()); } } - /** - * Client implementation of Entity - */ public static class Remote extends ThingImpl.Remote implements Entity.Remote { - public Remote(final Concepts concepts, final String iid) { - super(concepts, iid); + public Remote(final Grakn.Transaction transaction, final String iid) { + super(transaction, iid); + } + + public static EntityImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing protoThing) { + return new EntityImpl.Remote(transaction, Bytes.bytesToHexString(protoThing.getIid().toByteArray())); + } + + @Override + public Entity.Remote asRemote(Grakn.Transaction transaction) { + return new EntityImpl.Remote(transaction, iid); } @Override - public final EntityType.Remote getType() { - return (EntityType.Remote) super.getType(); + public EntityType.Local getType() { + return super.getType().asEntityType(); } } } diff --git a/concept/thing/impl/RelationImpl.java b/concept/thing/impl/RelationImpl.java index 890f29372f..6e296732c1 100644 --- a/concept/thing/impl/RelationImpl.java +++ b/concept/thing/impl/RelationImpl.java @@ -19,13 +19,18 @@ package grakn.client.concept.thing.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Relation; import grakn.client.concept.thing.Thing; import grakn.client.concept.type.RelationType; import grakn.client.concept.type.RoleType; -import grakn.client.concept.type.Type; +import grakn.client.concept.type.impl.TypeImpl; +import grakn.common.collection.Bytes; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.Relation.AddPlayer; +import grakn.protocol.ConceptProto.Relation.GetPlayers; +import grakn.protocol.ConceptProto.Relation.RemovePlayer; +import grakn.protocol.ConceptProto.ThingMethod; import java.util.ArrayList; import java.util.Arrays; @@ -40,45 +45,54 @@ import static grakn.client.concept.proto.ConceptProtoBuilder.types; public abstract class RelationImpl { - /** - * Client implementation of Relation - */ + public static class Local extends ThingImpl.Local implements Relation.Local { - public Local(final ConceptProto.Thing thing) { - super(thing); + Local(String iid) { + super(iid); } - public RelationType.Local getType() { - return super.getType().asRelationType(); + public static RelationImpl.Local of(final ConceptProto.Thing protoThing) { + return new RelationImpl.Local(Bytes.bytesToHexString(protoThing.getIid().toByteArray())); + } + + @Override + public Relation.Remote asRemote(Grakn.Transaction transaction) { + return new RelationImpl.Remote(transaction, getIID()); } } - /** - * Client implementation of Relation - */ public static class Remote extends ThingImpl.Remote implements Relation.Remote { - public Remote(final Concepts concepts, final String iid) { - super(concepts, iid); + public Remote(final Grakn.Transaction transaction, final String iid) { + super(transaction, iid); + } + + public static RelationImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing protoThing) { + return new RelationImpl.Remote(transaction, Bytes.bytesToHexString(protoThing.getIid().toByteArray())); } @Override - public RelationType.Remote getType() { - return (RelationType.Remote) super.getType(); + public Relation.Remote asRemote(Grakn.Transaction transaction) { + return new RelationImpl.Remote(transaction, iid); } @Override - public Map> getPlayersByRoleType() { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() + public RelationType.Local getType() { + return super.getType().asRelationType(); + } + + @Override + public Map> getPlayersByRoleType() { + final ThingMethod.Iter.Req method = ThingMethod.Iter.Req.newBuilder() .setRelationGetPlayersByRoleTypeIterReq(ConceptProto.Relation.GetPlayersByRoleType.Iter.Req.getDefaultInstance()).build(); - final Stream stream = concepts().iterateThingMethod(getIID(), method, ConceptProto.ThingMethod.Iter.Res::getRelationGetPlayersByRoleTypeIterRes); + final Stream stream = tx().concepts().iterateThingMethod(getIID(), method, ThingMethod.Iter.Res::getRelationGetPlayersByRoleTypeIterRes); - final Map> rolePlayerMap = new HashMap<>(); + final Map> rolePlayerMap = new HashMap<>(); stream.forEach(rolePlayer -> { - final RoleType.Remote role = Type.Remote.of(concepts(), rolePlayer.getRoleType()).asRoleType(); - final Thing.Remote player = Thing.Remote.of(concepts(), rolePlayer.getPlayer()); + final RoleType.Local role = TypeImpl.Local.of(rolePlayer.getRoleType()).asRoleType(); + final Thing.Local player = ThingImpl.Local.of(rolePlayer.getPlayer()); if (rolePlayerMap.containsKey(role)) { rolePlayerMap.get(role).add(player); } else { @@ -86,38 +100,34 @@ public Map> getPlayersBy } }); - final Map> result = new HashMap<>(); - for (Map.Entry> entry : rolePlayerMap.entrySet()) { + final Map> result = new HashMap<>(); + for (Map.Entry> entry : rolePlayerMap.entrySet()) { result.put(entry.getKey(), entry.getValue()); } return result; } @Override - public Stream getPlayers(RoleType... roleTypes) { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() - .setRelationGetPlayersIterReq(ConceptProto.Relation.GetPlayers.Iter.Req.newBuilder() - .addAllRoleTypes(types(Arrays.asList(roleTypes)))).build(); - - return thingStream(method, res -> res.getRelationGetPlayersIterRes().getThing()); + public Stream getPlayers(RoleType... roleTypes) { + return stream( + ThingMethod.Iter.Req.newBuilder().setRelationGetPlayersIterReq( + GetPlayers.Iter.Req.newBuilder().addAllRoleTypes(types(Arrays.asList(roleTypes)))).build(), + res -> res.getRelationGetPlayersIterRes().getThing() + ); } @Override public void addPlayer(RoleType roleType, Thing player) { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() - .setRelationAddPlayerReq(ConceptProto.Relation.AddPlayer.Req.newBuilder() - .setRoleType(type(roleType)) - .setPlayer(thing(player))).build(); - runMethod(method); + execute(ThingMethod.Req.newBuilder().setRelationAddPlayerReq( + AddPlayer.Req.newBuilder().setRoleType(type(roleType)).setPlayer(thing(player)) + ).build()); } @Override public void removePlayer(RoleType roleType, Thing player) { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() - .setRelationRemovePlayerReq(ConceptProto.Relation.RemovePlayer.Req.newBuilder() - .setRoleType(type(roleType)) - .setPlayer(thing(player))).build(); - runMethod(method); + execute(ThingMethod.Req.newBuilder().setRelationRemovePlayerReq( + RemovePlayer.Req.newBuilder().setRoleType(type(roleType)).setPlayer(thing(player)) + ).build()); } } } diff --git a/concept/thing/impl/ThingImpl.java b/concept/thing/impl/ThingImpl.java index ddcd9d5d37..2c3003037c 100644 --- a/concept/thing/impl/ThingImpl.java +++ b/concept/thing/impl/ThingImpl.java @@ -19,8 +19,8 @@ package grakn.client.concept.thing.impl; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; import grakn.client.concept.thing.Attribute; import grakn.client.concept.thing.Relation; import grakn.client.concept.thing.Thing; @@ -28,36 +28,53 @@ import grakn.client.concept.type.RoleType; import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; +import grakn.client.concept.type.impl.TypeImpl; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.Thing.Delete; +import grakn.protocol.ConceptProto.Thing.GetPlays; +import grakn.protocol.ConceptProto.Thing.GetRelations; +import grakn.protocol.ConceptProto.Thing.UnsetHas; +import grakn.protocol.ConceptProto.ThingMethod; import java.util.Arrays; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Stream; -import static grakn.client.common.exception.ErrorMessage.ClientInternal.ILLEGAL_ARGUMENT_NULL; -import static grakn.client.common.exception.ErrorMessage.ClientInternal.ILLEGAL_ARGUMENT_NULL_OR_EMPTY; +import static grakn.client.common.exception.ErrorMessage.ClientInternal.MISSING_ARGUMENT; +import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; import static grakn.client.concept.proto.ConceptProtoBuilder.thing; import static grakn.client.concept.proto.ConceptProtoBuilder.types; public abstract class ThingImpl { - /** - * Client implementation of Thing - */ public abstract static class Local implements Thing.Local { private final String iid; - private final ThingType.Local type; + // TODO: private final ThingType.Local type; + // We (probably) need to storae the concept Type, but we should have a better way of retrieving it. + // In 1.8 it was in a "pre-filled response" in ConceptProto.Concept, which was highly confusing as it was + // not actually prefilled when using the Concept API - only when using the Query API. + // We should probably create a dedicated Proto class for Graql (AnswerProto or QueryProto) and keep the code clean. - protected Local(final ConceptProto.Thing thing) { - // TODO we (probably) do need the Type, but we should have a better way of retrieving it. - // In 1.8 it was in a "pre-filled response" in ConceptProto.Concept, which was highly confusing as it was - // not actually prefilled when using the Concept API - only when using the Query API. - // We should probably create a dedicated Proto class for Graql (AnswerProto or QueryProto) and keep the code clean. - throw new GraknException(new UnsupportedOperationException()); - //this.iid = thing.getIid(); - //this.type = Type.Local.of(thing.getType()).asThingType(); - //this.inferred = thing.getInferredRes().getInferred(); + Local(final String iid) { + this.iid = iid; + } + + public static ThingImpl.Local of(final ConceptProto.Thing thingProto) { + switch (thingProto.getSchema()) { + case ENTITY: + return EntityImpl.Local.of(thingProto); + case RELATION: + return RelationImpl.Local.of(thingProto); + case ATTRIBUTE: + return AttributeImpl.Local.of(thingProto); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message( + ConceptProto.Thing.SCHEMA.class.getSimpleName(), thingProto.getSchema()) + ); + } } @Override @@ -66,28 +83,52 @@ public String getIID() { } @Override - public ThingType.Local getType() { - return type; + public String toString() { + return this.getClass().getCanonicalName() + "[iid:" + iid + "]"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final ThingImpl.Local that = (ThingImpl.Local) o; + return (this.iid.equals(that.iid)); + } + + @Override + public final int hashCode() { + return iid.hashCode(); } } - /** - * Client implementation of Thing - */ public abstract static class Remote implements Thing.Remote { - private final Concepts concepts; - private final String iid; + private final Grakn.Transaction transaction; + final String iid; + private final int hash; - protected Remote(final Concepts concepts, final String iid) { - if (concepts == null) { - throw new GraknException(ILLEGAL_ARGUMENT_NULL.message("concepts")); - } - this.concepts = concepts; - if (iid == null || iid.isEmpty()) { - throw new GraknException(ILLEGAL_ARGUMENT_NULL_OR_EMPTY.message("iid")); - } + protected Remote(final Grakn.Transaction transaction, final String iid) { + if (transaction == null) throw new GraknException(MISSING_ARGUMENT.message("concepts")); + else if (iid == null || iid.isEmpty()) throw new GraknException(MISSING_ARGUMENT.message("iid")); + this.transaction = transaction; this.iid = iid; + this.hash = Objects.hash(this.transaction, this.iid); + } + + public static ThingImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Thing protoThing) { + + switch (protoThing.getSchema()) { + case ENTITY: + return EntityImpl.Remote.of(transaction, protoThing); + case RELATION: + return RelationImpl.Remote.of(transaction, protoThing); + case ATTRIBUTE: + return AttributeImpl.Remote.of(transaction, protoThing); + default: + case UNRECOGNIZED: + throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Thing.SCHEMA.class.getCanonicalName(), protoThing.getSchema())); + } } @Override @@ -95,109 +136,122 @@ public String getIID() { return iid; } - @Override - public ThingType.Remote getType() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + public ThingType.Local getType() { + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setThingGetTypeReq(ConceptProto.Thing.GetType.Req.getDefaultInstance()).build(); - - return Type.Remote.of(concepts, runMethod(method).getThingGetTypeRes().getThingType()).asThingType(); + return TypeImpl.Local.of(execute(method).getThingGetTypeRes().getThingType()).asThingType(); } @Override public final boolean isInferred() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() + final ThingMethod.Req method = ThingMethod.Req.newBuilder() .setThingIsInferredReq(ConceptProto.Thing.IsInferred.Req.getDefaultInstance()).build(); - - return runMethod(method).getThingIsInferredRes().getInferred(); + return execute(method).getThingIsInferredRes().getInferred(); } @Override - public final Stream> getHas(AttributeType... attributeTypes) { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() + public final Stream> getHas(AttributeType... attributeTypes) { + final ThingMethod.Iter.Req method = ThingMethod.Iter.Req.newBuilder() .setThingGetHasIterReq(ConceptProto.Thing.GetHas.Iter.Req.newBuilder() .addAllAttributeTypes(types(Arrays.asList(attributeTypes)))).build(); - return thingStream(method, res -> res.getThingGetHasIterRes().getAttribute()).map(Thing.Remote::asAttribute); + return stream(method, res -> res.getThingGetHasIterRes().getAttribute()).map(Thing.Local::asAttribute); } @Override - public final Stream getHas(AttributeType.Boolean attributeType) { - return getHas((AttributeType) attributeType).map(Attribute.Remote::asBoolean); + public final Stream getHas(AttributeType.Boolean attributeType) { + return getHas((AttributeType) attributeType).map(Attribute.Local::asBoolean); } @Override - public final Stream getHas(AttributeType.Long attributeType) { - return getHas((AttributeType) attributeType).map(Attribute.Remote::asLong); + public final Stream getHas(AttributeType.Long attributeType) { + return getHas((AttributeType) attributeType).map(Attribute.Local::asLong); } @Override - public final Stream getHas(AttributeType.Double attributeType) { - return getHas((AttributeType) attributeType).map(Attribute.Remote::asDouble); + public final Stream getHas(AttributeType.Double attributeType) { + return getHas((AttributeType) attributeType).map(Attribute.Local::asDouble); } @Override - public final Stream getHas(AttributeType.String attributeType) { - return getHas((AttributeType) attributeType).map(Attribute.Remote::asString); + public final Stream getHas(AttributeType.String attributeType) { + return getHas((AttributeType) attributeType).map(Attribute.Local::asString); } @Override - public final Stream getHas(AttributeType.DateTime attributeType) { - return getHas((AttributeType) attributeType).map(Attribute.Remote::asDateTime); + public final Stream getHas(AttributeType.DateTime attributeType) { + return getHas((AttributeType) attributeType).map(Attribute.Local::asDateTime); } @Override - public final Stream> getHas(boolean onlyKey) { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() + public final Stream> getHas(boolean onlyKey) { + final ThingMethod.Iter.Req method = ThingMethod.Iter.Req.newBuilder() .setThingGetHasIterReq(ConceptProto.Thing.GetHas.Iter.Req.newBuilder().setKeysOnly(onlyKey)).build(); - return thingStream(method, res -> res.getThingGetHasIterRes().getAttribute()).map(Thing.Remote::asAttribute); + return stream(method, res -> res.getThingGetHasIterRes().getAttribute()).map(Thing.Local::asAttribute); } @Override - public final Stream getPlays() { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() - .setThingGetPlaysIterReq(ConceptProto.Thing.GetPlays.Iter.Req.getDefaultInstance()).build(); - return typeStream(method, res -> res.getThingGetPlaysIterRes().getRoleType()).map(Type.Remote::asRoleType); + public final Stream getPlays() { + return typeStream( + ThingMethod.Iter.Req.newBuilder().setThingGetPlaysIterReq( + GetPlays.Iter.Req.getDefaultInstance()).build(), + res -> res.getThingGetPlaysIterRes().getRoleType() + ).map(Type.Local::asRoleType); } @Override public final Stream getRelations(RoleType... roleTypes) { - final ConceptProto.ThingMethod.Iter.Req method = ConceptProto.ThingMethod.Iter.Req.newBuilder() - .setThingGetRelationsIterReq(ConceptProto.Thing.GetRelations.Iter.Req.newBuilder() - .addAllRoleTypes(types(Arrays.asList(roleTypes)))).build(); - return thingStream(method, res -> res.getThingGetRelationsIterRes().getRelation()).map(Thing.Remote::asRelation); + return stream( + ThingMethod.Iter.Req.newBuilder().setThingGetRelationsIterReq( + GetRelations.Iter.Req.newBuilder().addAllRoleTypes(types(Arrays.asList(roleTypes)))).build(), + res -> res.getThingGetRelationsIterRes().getRelation() + ).map(Thing.Local::asRelation); } @Override public final void setHas(Attribute attribute) { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() - .setThingSetHasReq(ConceptProto.Thing.SetHas.Req.newBuilder() - .setAttribute(thing(attribute))).build(); - runMethod(method); + execute(ThingMethod.Req.newBuilder().setThingSetHasReq( + ConceptProto.Thing.SetHas.Req.newBuilder().setAttribute(thing(attribute)) + ).build()); } @Override public final void unsetHas(Attribute attribute) { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() - .setThingUnsetHasReq(ConceptProto.Thing.UnsetHas.Req.newBuilder() - .setAttribute(thing(attribute))).build(); - runMethod(method); + execute(ThingMethod.Req.newBuilder().setThingUnsetHasReq( + UnsetHas.Req.newBuilder().setAttribute(thing(attribute)) + ).build()); } @Override public final void delete() { - final ConceptProto.ThingMethod.Req method = ConceptProto.ThingMethod.Req.newBuilder() - .setThingDeleteReq(ConceptProto.Thing.Delete.Req.getDefaultInstance()) - .build(); - runMethod(method); + execute(ThingMethod.Req.newBuilder().setThingDeleteReq(Delete.Req.getDefaultInstance()).build()); } @Override public final boolean isDeleted() { - return concepts.getThing(getIID()) == null; + return transaction.concepts().getThing(getIID()) == null; + } + + final Grakn.Transaction tx() { + return transaction; + } + + Stream stream(final ThingMethod.Iter.Req request, + final Function thingGetter) { + return transaction.concepts().iterateThingMethod(iid, request, response -> ThingImpl.Local.of(thingGetter.apply(response))); + } + + Stream typeStream(final ThingMethod.Iter.Req request, + final Function typeGetter) { + return transaction.concepts().iterateThingMethod(iid, request, response -> TypeImpl.Local.of(typeGetter.apply(response))); + } + + ThingMethod.Res execute(final ThingMethod.Req method) { + return transaction.concepts().runThingMethod(iid, method).getConceptMethodThingRes().getResponse(); } @Override public String toString() { - return this.getClass().getCanonicalName() + "{concepts=" + concepts + ", iid=" + iid + "}"; + return this.getClass().getCanonicalName() + "[iid:" + iid + "]"; } @Override @@ -206,35 +260,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; ThingImpl.Remote that = (ThingImpl.Remote) o; - - return this.concepts.equals(that.concepts) && - this.iid.equals(that.iid); + return (this.transaction.equals(that.transaction) && this.iid.equals(that.iid)); } @Override public int hashCode() { - int h = 1; - h *= 1000003; - h ^= concepts.hashCode(); - h *= 1000003; - h ^= iid.hashCode(); - return h; - } - - protected final Concepts concepts() { - return concepts; - } - - protected Stream thingStream(final ConceptProto.ThingMethod.Iter.Req request, final Function thingGetter) { - return concepts.iterateThingMethod(iid, request, response -> Thing.Remote.of(concepts, thingGetter.apply(response))); - } - - protected Stream typeStream(final ConceptProto.ThingMethod.Iter.Req request, final Function typeGetter) { - return concepts.iterateThingMethod(iid, request, response -> Type.Remote.of(concepts, typeGetter.apply(response))); - } - - protected ConceptProto.ThingMethod.Res runMethod(final ConceptProto.ThingMethod.Req method) { - return concepts.runThingMethod(iid, method).getConceptMethodThingRes().getResponse(); + return hash; } } } diff --git a/concept/type/AttributeType.java b/concept/type/AttributeType.java index 793ec99c40..fe7f3bf2c8 100644 --- a/concept/type/AttributeType.java +++ b/concept/type/AttributeType.java @@ -19,36 +19,30 @@ package grakn.client.concept.type; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; import grakn.client.concept.thing.Attribute; -import grakn.client.concept.type.impl.AttributeTypeImpl; import grakn.protocol.ConceptProto; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.time.LocalDateTime; import java.util.stream.Stream; import static grakn.client.common.exception.ErrorMessage.ClientInternal.UNRECOGNISED_VALUE; -import static grakn.client.common.exception.ErrorMessage.Concept.INVALID_CONCEPT_CASTING; import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; public interface AttributeType extends ThingType { - @CheckReturnValue default ValueType getValueType() { return ValueType.OBJECT; } - @CheckReturnValue default boolean isKeyable() { return getValueType().isKeyable(); } - @CheckReturnValue @Override - AttributeType.Remote asRemote(Concepts concepts); + AttributeType.Remote asRemote(Grakn.Transaction transaction); AttributeType.Boolean asBoolean(); @@ -106,17 +100,14 @@ public static ValueType of(ConceptProto.AttributeType.VALUE_TYPE valueType) { } } - @CheckReturnValue public Class valueClass() { return valueClass; } - @CheckReturnValue public boolean isWritable() { return isWritable; } - @CheckReturnValue public boolean isKeyable() { return isKeyable; } @@ -129,66 +120,31 @@ public java.lang.String toString() { interface Local extends ThingType.Local, AttributeType { - @CheckReturnValue - @Override - AttributeType.Remote asRemote(Concepts concepts); - - @CheckReturnValue @Override default AttributeType.Local asAttributeType() { return this; } @Override - default AttributeType.Boolean.Local asBoolean() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Boolean.class.getCanonicalName())); - } + AttributeType.Boolean.Local asBoolean(); @Override - default AttributeType.Long.Local asLong() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Long.class.getCanonicalName())); - } + AttributeType.Long.Local asLong(); @Override - default AttributeType.Double.Local asDouble() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Double.class.getCanonicalName())); - } + AttributeType.Double.Local asDouble(); @Override - default AttributeType.String.Local asString() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.String.class.getCanonicalName())); - } + AttributeType.String.Local asString(); @Override - default AttributeType.DateTime.Local asDateTime() { - throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.DateTime.class.getCanonicalName())); - } + AttributeType.DateTime.Local asDateTime(); } - /** - * An ontological element which models and categorises the various Attribute in the graph. - * This ontological element behaves similarly to Type when defining how it relates to other - * types. It has two additional functions to be aware of: - * 1. It has a ValueType constraining the data types of the values it's instances may take. - * 2. Any of it's instances are unique to the type. - * For example if you have an AttributeType modelling month throughout the year there can only be one January. - */ interface Remote extends ThingType.Remote, AttributeType { - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - */ void setSupertype(AttributeType type); - @CheckReturnValue - @Override - default AttributeType.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default AttributeType.Remote asAttributeType() { return this; @@ -209,14 +165,8 @@ default AttributeType.Remote asAttributeType() { @Override AttributeType.DateTime.Remote asDateTime(); - /** - * Retrieve all the Attribute instances of this AttributeType - * - * @return All the Attribute instances of this AttributeType - * @see Attribute.Remote - */ @Override - Stream> getInstances(); + Stream> getInstances(); Stream getOwners(); @@ -225,19 +175,16 @@ default AttributeType.Remote asAttributeType() { interface Boolean extends AttributeType { - @CheckReturnValue @Override default ValueType getValueType() { return ValueType.BOOLEAN; } - @CheckReturnValue @Override - AttributeType.Boolean.Remote asRemote(Concepts concepts); + AttributeType.Boolean.Remote asRemote(Grakn.Transaction transaction); interface Local extends AttributeType.Boolean, AttributeType.Local { - @CheckReturnValue @Override default AttributeType.Boolean.Local asBoolean() { return this; @@ -246,74 +193,25 @@ default AttributeType.Boolean.Local asBoolean() { interface Remote extends AttributeType.Boolean, AttributeType.Remote { - static AttributeType.Boolean.Remote of(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - return new AttributeTypeImpl.Boolean.Remote(concepts, label, isRoot); - } + void setSupertype(AttributeType.Boolean type); - /** - * @return The direct supertype of this concept - */ @Override - AttributeType.Boolean.Remote getSupertype(); + AttributeType.Boolean.Local getSupertype(); - /** - * Returns a collection of super-types of this AttributeType. - * - * @return The super-types of this AttributeType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this AttributeType. - * - * @return The subtypes of this AttributeType - */ @Override - Stream getSubtypes(); + Stream getSubtypes(); - /** - * Returns a collection of all Attribute of this AttributeType. - * - * @return The resource instances of this AttributeType - */ @Override - Stream getInstances(); - - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - * @return The AttributeType itself. - */ - void setSupertype(AttributeType.Boolean type); + Stream getInstances(); - /** - * Set the value for the Attribute, unique to its type. - * - * @param value A value for the Attribute which is unique to its type - * @return new or existing Attribute of this type with the provided value. - */ - Attribute.Boolean.Remote put(boolean value); - - /** - * Get the Attribute with the value provided, and its type, or return NULL - * - * @param value A value which an Attribute in the graph may be holding - * @return The Attribute with the provided value and type or null if no such Attribute exists. - * @see Attribute.Boolean.Remote - */ - @CheckReturnValue - @Nullable - Attribute.Boolean.Remote get(boolean value); + Attribute.Boolean.Local put(boolean value); - @CheckReturnValue - @Override - default AttributeType.Boolean.Remote asRemote(Concepts concepts) { - return this; - } + @Nullable + Attribute.Boolean.Local get(boolean value); - @CheckReturnValue @Override default AttributeType.Boolean.Remote asBoolean() { return this; @@ -323,19 +221,16 @@ default AttributeType.Boolean.Remote asBoolean() { interface Long extends AttributeType { - @CheckReturnValue @Override default ValueType getValueType() { return ValueType.LONG; } - @CheckReturnValue @Override - AttributeType.Long.Remote asRemote(Concepts concepts); + AttributeType.Long.Remote asRemote(Grakn.Transaction transaction); interface Local extends AttributeType.Long, AttributeType.Local { - @CheckReturnValue @Override default AttributeType.Long.Local asLong() { return this; @@ -344,73 +239,25 @@ default AttributeType.Long.Local asLong() { interface Remote extends AttributeType.Long, AttributeType.Remote { - static AttributeType.Long.Remote of(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - return new AttributeTypeImpl.Long.Remote(concepts, label, isRoot); - } + void setSupertype(AttributeType.Long type); - /** - * @return The direct supertype of this concept - */ @Override - AttributeType.Long.Remote getSupertype(); + AttributeType.Long.Local getSupertype(); - /** - * Returns a collection of super-types of this AttributeType. - * - * @return The super-types of this AttributeType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this AttributeType. - * - * @return The subtypes of this AttributeType - */ @Override - Stream getSubtypes(); + Stream getSubtypes(); - /** - * Returns a collection of all Attribute of this AttributeType. - * - * @return The resource instances of this AttributeType - */ @Override - Stream getInstances(); + Stream getInstances(); - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - */ - void setSupertype(AttributeType.Long type); + Attribute.Long.Local put(long value); - /** - * Set the value for the Attribute, unique to its type. - * - * @param value A value for the Attribute which is unique to its type - * @return new or existing Attribute of this type with the provided value. - */ - Attribute.Long.Remote put(long value); - - /** - * Get the Attribute with the value provided, and its type, or return NULL - * - * @param value A value which an Attribute in the graph may be holding - * @return The Attribute with the provided value and type or null if no such Attribute exists. - * @see Attribute.Long.Remote - */ - @CheckReturnValue @Nullable - Attribute.Long.Remote get(long value); + Attribute.Long.Local get(long value); - @CheckReturnValue - @Override - default AttributeType.Long.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default AttributeType.Long.Remote asLong() { return this; @@ -420,19 +267,16 @@ default AttributeType.Long.Remote asLong() { interface Double extends AttributeType { - @CheckReturnValue @Override default ValueType getValueType() { return ValueType.DOUBLE; } - @CheckReturnValue @Override - AttributeType.Double.Remote asRemote(Concepts concepts); + AttributeType.Double.Remote asRemote(Grakn.Transaction transaction); interface Local extends AttributeType.Double, AttributeType.Local { - @CheckReturnValue @Override default AttributeType.Double.Local asDouble() { return this; @@ -441,73 +285,25 @@ default AttributeType.Double.Local asDouble() { interface Remote extends AttributeType.Double, AttributeType.Remote { - static AttributeType.Double.Remote of(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - return new AttributeTypeImpl.Double.Remote(concepts, label, isRoot); - } + void setSupertype(AttributeType.Double type); - /** - * @return The direct supertype of this concept - */ @Override - AttributeType.Double.Remote getSupertype(); + AttributeType.Double.Local getSupertype(); - /** - * Returns a collection of super-types of this AttributeType. - * - * @return The super-types of this AttributeType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this AttributeType. - * - * @return The subtypes of this AttributeType - */ @Override - Stream getSubtypes(); + Stream getSubtypes(); - /** - * Returns a collection of all Attribute of this AttributeType. - * - * @return The resource instances of this AttributeType - */ @Override - Stream getInstances(); + Stream getInstances(); - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - */ - void setSupertype(AttributeType.Double type); + Attribute.Double.Local put(double value); - /** - * Set the value for the Attribute, unique to its type. - * - * @param value A value for the Attribute which is unique to its type - * @return new or existing Attribute of this type with the provided value. - */ - Attribute.Double.Remote put(double value); - - /** - * Get the Attribute with the value provided, and its type, or return NULL - * - * @param value A value which an Attribute in the graph may be holding - * @return The Attribute with the provided value and type or null if no such Attribute exists. - * @see Attribute.Double.Remote - */ - @CheckReturnValue @Nullable - Attribute.Double.Remote get(double value); - - @CheckReturnValue - @Override - default AttributeType.Double.Remote asRemote(Concepts concepts) { - return this; - } + Attribute.Double.Local get(double value); - @CheckReturnValue @Override default AttributeType.Double.Remote asDouble() { return this; @@ -517,19 +313,16 @@ default AttributeType.Double.Remote asDouble() { interface String extends AttributeType { - @CheckReturnValue @Override default ValueType getValueType() { return ValueType.STRING; } - @CheckReturnValue @Override - AttributeType.String.Remote asRemote(Concepts concepts); + AttributeType.String.Remote asRemote(Grakn.Transaction transaction); interface Local extends AttributeType.String, AttributeType.Local { - @CheckReturnValue @Override default AttributeType.String.Local asString() { return this; @@ -538,79 +331,30 @@ default AttributeType.String.Local asString() { interface Remote extends AttributeType.String, AttributeType.Remote { - static AttributeType.String.Remote of(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - return new AttributeTypeImpl.String.Remote(concepts, label, isRoot); - } + void setSupertype(AttributeType.String type); - /** - * @return The direct supertype of this concept - */ @Override - AttributeType.String.Remote getSupertype(); + AttributeType.String.Local getSupertype(); - /** - * Returns a collection of super-types of this AttributeType. - * - * @return The super-types of this AttributeType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this AttributeType. - * - * @return The subtypes of this AttributeType - */ @Override - Stream getSubtypes(); + Stream getSubtypes(); - /** - * Returns a collection of all Attribute of this AttributeType. - * - * @return The resource instances of this AttributeType - */ @Override - Stream getInstances(); + Stream getInstances(); - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - */ - void setSupertype(AttributeType.String type); + Attribute.String.Local put(java.lang.String value); - /** - * Set the value for the Attribute, unique to its type. - * - * @param value A value for the Attribute which is unique to its type - * @return new or existing Attribute of this type with the provided value. - */ - Attribute.String.Remote put(java.lang.String value); - - /** - * Get the Attribute with the value provided, and its type, or return NULL - * - * @param value A value which an Attribute in the graph may be holding - * @return The Attribute with the provided value and type or null if no such Attribute exists. - * @see Attribute.String.Remote - */ - @CheckReturnValue @Nullable - Attribute.String.Remote get(java.lang.String value); + Attribute.String.Local get(java.lang.String value); - @CheckReturnValue @Nullable java.lang.String getRegex(); void setRegex(java.lang.String regex); - @CheckReturnValue - @Override - default AttributeType.String.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default AttributeType.String.Remote asString() { return this; @@ -620,19 +364,16 @@ default AttributeType.String.Remote asString() { interface DateTime extends AttributeType { - @CheckReturnValue @Override default ValueType getValueType() { return ValueType.DATETIME; } - @CheckReturnValue @Override - AttributeType.DateTime.Remote asRemote(Concepts concepts); + AttributeType.DateTime.Remote asRemote(Grakn.Transaction transaction); interface Local extends AttributeType.DateTime, AttributeType.Local { - @CheckReturnValue @Override default AttributeType.DateTime.Local asDateTime() { return this; @@ -641,73 +382,25 @@ default AttributeType.DateTime.Local asDateTime() { interface Remote extends AttributeType.DateTime, AttributeType.Remote { - static AttributeType.DateTime.Remote of(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - return new AttributeTypeImpl.DateTime.Remote(concepts, label, isRoot); - } + void setSupertype(AttributeType.DateTime type); - /** - * @return The direct supertype of this concept - */ @Override - AttributeType.DateTime.Remote getSupertype(); + AttributeType.DateTime.Local getSupertype(); - /** - * Returns a collection of super-types of this AttributeType. - * - * @return The super-types of this AttributeType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this AttributeType. - * - * @return The subtypes of this AttributeType - */ @Override - Stream getSubtypes(); + Stream getSubtypes(); - /** - * Returns a collection of all Attribute of this AttributeType. - * - * @return The resource instances of this AttributeType - */ @Override - Stream getInstances(); + Stream getInstances(); - /** - * Sets the supertype of the AttributeType to be the AttributeType specified. - * - * @param type The super type of this AttributeType. - */ - void setSupertype(AttributeType.DateTime type); + Attribute.DateTime.Local put(LocalDateTime value); - /** - * Set the value for the Attribute, unique to its type. - * - * @param value A value for the Attribute which is unique to its type - * @return new or existing Attribute of this type with the provided value. - */ - Attribute.DateTime.Remote put(LocalDateTime value); - - /** - * Get the Attribute with the value provided, and its type, or return NULL - * - * @param value A value which an Attribute in the graph may be holding - * @return The Attribute with the provided value and type or null if no such Attribute exists. - * @see Attribute.DateTime.Remote - */ - @CheckReturnValue @Nullable - Attribute.DateTime.Remote get(LocalDateTime value); - - @CheckReturnValue - @Override - default AttributeType.DateTime.Remote asRemote(Concepts concepts) { - return this; - } + Attribute.DateTime.Local get(LocalDateTime value); - @CheckReturnValue @Override default AttributeType.DateTime.Remote asDateTime() { return this; diff --git a/concept/type/EntityType.java b/concept/type/EntityType.java index f1a0f5b8d3..f2610b57be 100644 --- a/concept/type/EntityType.java +++ b/concept/type/EntityType.java @@ -19,95 +19,42 @@ package grakn.client.concept.type; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Entity; -import grakn.client.concept.type.impl.EntityTypeImpl; -import javax.annotation.CheckReturnValue; import java.util.stream.Stream; -/** - * Type used to represent entities. - * An ontological element which represents entity instances can fall within. - * Any instance of a Entity Type is called an Entity. - */ public interface EntityType extends ThingType { - @CheckReturnValue @Override - EntityType.Remote asRemote(Concepts concepts); + EntityType.Remote asRemote(Grakn.Transaction transaction); interface Local extends ThingType.Local, EntityType { - @CheckReturnValue @Override default EntityType.Local asEntityType() { return this; } - - @CheckReturnValue - @Override - default EntityType.Remote asRemote(final Concepts concepts) { - return EntityType.Remote.of(concepts, getLabel(), isRoot()); - } } - /** - * Type used to represent entities. - * An ontological element which represents entity instances can fall within. - * Any instance of a Entity Type is called an Entity. - */ interface Remote extends ThingType.Remote, EntityType { - static EntityType.Remote of(final Concepts concepts, final String label, final boolean isRoot) { - return new EntityTypeImpl.Remote(concepts, label, isRoot); - } - - /** - * Creates and returns a new Entity instance, whose direct type will be this type. - * - * @return a new empty entity. - * @see Entity.Remote - */ - Entity.Remote create(); + Entity.Local create(); - /** - * Sets the supertype of this instance to the given type. - */ void setSupertype(EntityType superEntityType); - /** - * Returns a collection of supertypes of this EntityType. - * - * @return All the super classes of this EntityType - */ @Override - Stream getSupertypes(); + EntityType.Local getSupertype(); - /** - * Returns a collection of subtypes of this EntityType. - * - * @return All the sub classes of this EntityType - */ @Override - Stream getSubtypes(); + Stream getSupertypes(); - /** - * Returns a collection of all Entity instances for this EntityType. - * - * @return All the instances of this EntityType. - * @see Entity.Remote - */ @Override - Stream getInstances(); + Stream getSubtypes(); - @CheckReturnValue @Override - default EntityType.Remote asRemote(Concepts concepts) { - return this; - } + Stream getInstances(); - @CheckReturnValue @Override default EntityType.Remote asEntityType() { return this; diff --git a/concept/type/RelationType.java b/concept/type/RelationType.java index a7e2173e87..e43e837c6a 100644 --- a/concept/type/RelationType.java +++ b/concept/type/RelationType.java @@ -19,137 +19,51 @@ package grakn.client.concept.type; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Relation; -import grakn.client.concept.type.impl.RelationTypeImpl; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; -/** - * An ontological element which categorises how Things may relate to each other. - * A RelationType defines how Type may relate to one another. - * They are used to model and categorise n-ary Relations. - */ public interface RelationType extends ThingType { - @CheckReturnValue @Override - RelationType.Remote asRemote(Concepts concepts); + RelationType.Remote asRemote(Grakn.Transaction transaction); interface Local extends ThingType.Local, RelationType { - @CheckReturnValue @Override default RelationType.Local asRelationType() { return this; } - - @Override - default RelationType.Remote asRemote(final Concepts concepts) { - return RelationType.Remote.of(concepts, getLabel(), isRoot()); - } } - /** - * An ontological element which categorises how Things may relate to each other. - * A RelationType defines how Type may relate to one another. - * They are used to model and categorise n-ary Relations. - */ interface Remote extends ThingType.Remote, RelationType { - static RelationType.Remote of(final Concepts concepts, final String label, final boolean isRoot) { - return new RelationTypeImpl.Remote(concepts, label, isRoot); - } + Relation.Local create(); - /** - * Create a relation of this relation type. - * - * @return The newly created relation. - */ - Relation.Remote create(); - - /** - * Set the super type of this relation type. - * - * @param superRelationType The super type to set. - */ void setSupertype(RelationType superRelationType); - /** - * Retrieve a specific RoleType. - */ @Nullable - @CheckReturnValue - RoleType.Remote getRelates(String roleLabel); - - /** - * Retrieve a specific RoleType. - * - * @return A list of the RoleTypes which make up this RelationType. - * @see RoleType.Remote - */ - @CheckReturnValue - Stream getRelates(); - - /** - * Creates a new RoleType for this RelationType. - * - * @param roleLabel The label of a new RoleType which is part of this RelationType. - * @see RoleType.Remote - */ + RoleType.Local getRelates(String roleLabel); + + Stream getRelates(); + void setRelates(String roleLabel); - /** - * Creates a new RoleType override for this RelationType. - * - * @param roleLabel The label of a new RoleType which is part of this RelationType. - * @param overriddenLabel The label of the RoleType that is to be overridden. - * @see RoleType.Remote - */ void setRelates(String roleLabel, String overriddenLabel); - /** - * Removes a RoleType from this RelationType. - * - * @param roleLabel The label of a RoleType which is part of this RelationType. - * @see RoleType.Remote - */ void unsetRelates(String roleLabel); - /** - * Returns a collection of supertypes of this RelationType. - * - * @return All the supertypes of this RelationType - */ @Override - Stream getSupertypes(); + Stream getSupertypes(); - /** - * Returns a collection of subtypes of this RelationType. - * - * @return All the sub types of this RelationType - */ - @Override - Stream getSubtypes(); - - /** - * Retrieve all the Relation instances of this RelationType - * - * @return All the Relation instances of this RelationType - * @see Relation.Remote - */ @Override - Stream getInstances(); + Stream getSubtypes(); - @CheckReturnValue @Override - default RelationType.Remote asRemote(Concepts concepts) { - return this; - } + Stream getInstances(); - @CheckReturnValue @Override default RelationType.Remote asRelationType() { return this; diff --git a/concept/type/RoleType.java b/concept/type/RoleType.java index bb80c7a1d7..84171cb295 100644 --- a/concept/type/RoleType.java +++ b/concept/type/RoleType.java @@ -19,111 +19,42 @@ package grakn.client.concept.type; -import grakn.client.concept.Concepts; -import grakn.client.concept.type.impl.RoleTypeImpl; +import grakn.client.Grakn; -import javax.annotation.CheckReturnValue; import java.util.stream.Stream; -/** - * A Type which defines a role which can be played in a RelationType. - * This ontological element defines the RoleTypes which make up a RelationType. - * It behaves similarly to Type when relating to other types. - */ public interface RoleType extends Type { - /** - * Get the label of this RoleType scoped to its relation. - * - * @return The scoped label - */ - String getScopedLabel(); + String getScope(); - @CheckReturnValue @Override - RoleType.Remote asRemote(Concepts concepts); + RoleType.Remote asRemote(Grakn.Transaction transaction); interface Local extends Type.Local, RoleType { - @CheckReturnValue @Override default RoleType.Local asRoleType() { return this; } - - @Override - default RoleType.Remote asRemote(final Concepts concepts) { - return RoleType.Remote.of(concepts, getLabel(), getScopedLabel(), isRoot()); - } } - /** - * A Type which defines a role which can be played in a RelationType. - * This ontological element defines the RoleTypes which make up a RelationType. - * It behaves similarly to Type when relating to other types. - */ interface Remote extends Type.Remote, RoleType { - static RoleType.Remote of(final Concepts concepts, final String label, final String scopedLabel, final boolean isRoot) { - return new RoleTypeImpl.Remote(concepts, label, scopedLabel, isRoot); - } - - /** - * Sets the supertype of this RoleType. - * - * @param type The supertype of this RoleType. - * @return The RoleType itself. - */ - void setSupertype(RoleType type); - - /** - * @return All the supertypes of this RoleType. - */ @Override - Stream getSupertypes(); + RoleType.Local getSupertype(); - /** - * Returns the subtype of this RoleType. - * - * @return The subtype of this RoleType. - */ @Override - Stream getSubtypes(); - - /** - * Returns the RelationType that this RoleType takes part in. - * - * @return The RelationType which this RoleType takes part in. - * @see RelationType.Remote - */ - @CheckReturnValue - RelationType.Remote getRelation(); - - /** - * Returns the RelationTypes that this RoleType takes part in. - * - * @return The RelationType which this RoleType takes part in. - * @see RelationType.Remote - */ - @CheckReturnValue - Stream getRelations(); - - /** - * Returns a collection of the Types that can play this RoleType. - * - * @return A list of all the Types which can play this RoleType. - * @see ThingType.Remote - */ - @CheckReturnValue - Stream getPlayers(); - - @CheckReturnValue + Stream getSupertypes(); + @Override - default RoleType.Remote asRemote(Concepts concepts) { - return this; - } + Stream getSubtypes(); + + RelationType.Local getRelation(); + + Stream getRelations(); + + Stream getPlayers(); - @CheckReturnValue @Override default RoleType.Remote asRoleType() { return this; diff --git a/concept/type/Rule.java b/concept/type/Rule.java index 6e8491386a..a393a01704 100644 --- a/concept/type/Rule.java +++ b/concept/type/Rule.java @@ -19,90 +19,44 @@ package grakn.client.concept.type; -import grakn.client.concept.Concepts; -import grakn.client.concept.type.impl.RuleImpl; +import grakn.client.Grakn; import graql.lang.pattern.Pattern; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; -/** - * A SchemaConcept used to model and categorise Rules. - */ public interface Rule extends Type { - @CheckReturnValue @Override - Rule.Remote asRemote(Concepts concepts); + Rule.Remote asRemote(Grakn.Transaction transaction); interface Local extends Type.Local, Rule { - @CheckReturnValue @Override default Rule.Local asRule() { return this; } - - @Override - default Rule.Remote asRemote(final Concepts concepts) { - return Rule.Remote.of(concepts, getLabel(), isRoot()); - } } - /** - * A SchemaConcept used to model and categorise Rules. - */ interface Remote extends Type.Remote, Rule { - static Rule.Remote of(final Concepts concepts, final String label, final boolean isRoot) { - return new RuleImpl.Remote(concepts, label, isRoot); - } - @Override default boolean isAbstract() { return false; } - /** - * Retrieves the when part of the Rule - * When this query is satisfied the "then" part of the rule is executed. - * - * @return A string representing the left hand side Graql query. - */ - @CheckReturnValue @Nullable Pattern getWhen(); - /** - * Retrieves the then part of the Rule. - * This query is executed when the "when" part of the rule is satisfied - * - * @return A string representing the right hand side Graql query. - */ - @CheckReturnValue @Nullable Pattern getThen(); - /** - * @return All the super-types of this this Rule - */ - @Override - Stream getSupertypes(); - - /** - * @return All the sub of this Rule - */ @Override - Stream getSubtypes(); + Stream getSupertypes(); - @CheckReturnValue @Override - default Rule.Remote asRemote(Concepts concepts) { - return this; - } + Stream getSubtypes(); - @CheckReturnValue @Override default Rule.Remote asRule() { return this; diff --git a/concept/type/ThingType.java b/concept/type/ThingType.java index fcdbeac770..0f47be5bc0 100644 --- a/concept/type/ThingType.java +++ b/concept/type/ThingType.java @@ -19,111 +19,49 @@ package grakn.client.concept.type; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Thing; import grakn.client.concept.type.AttributeType.ValueType; -import grakn.client.concept.type.impl.ThingTypeImpl; -import javax.annotation.CheckReturnValue; import java.util.stream.Stream; -/** - * A ThingType represents any ontological element in the graph. - * ThingTypes are used to model the behaviour of Thing and how they relate to each other. - * They also aid in categorising Thing to different types. - */ public interface ThingType extends Type { - @CheckReturnValue @Override - ThingType.Remote asRemote(Concepts concepts); + ThingType.Remote asRemote(Grakn.Transaction transaction); interface Local extends Type.Local, ThingType { - @CheckReturnValue @Override default ThingType.Local asThingType() { return this; } - - @CheckReturnValue - @Override - default ThingType.Remote asRemote(final Concepts concepts) { - return ThingType.Remote.of(concepts, getLabel(), isRoot()); - } } - /** - * A ThingType represents any ontological element in the graph. - * ThingTypes are used to model the behaviour of Thing and how they relate to each other. - * They also aid in categorising Thing to different types. - */ interface Remote extends Type.Remote, ThingType { - static ThingType.Remote of(final Concepts concepts, final String label, final boolean isRoot) { - return new ThingTypeImpl.Remote(concepts, label, isRoot); - } + @Override + ThingType.Local getSupertype(); - /** - * @return The direct supertype of this concept - */ @Override - ThingType.Remote getSupertype(); + Stream getSupertypes(); - /** - * @return All the the super-types of this Type - */ @Override - Stream getSupertypes(); - - /** - * Get all indirect sub-types of this type. - * The indirect sub-types are the type itself and all indirect sub-types of direct sub-types. - * - * @return All the indirect sub-types of this Type - */ + Stream getSubtypes(); + + Stream getInstances(); + @Override - @CheckReturnValue - Stream getSubtypes(); - - /** - * Get all indirect instances of this type. - * The indirect instances are the direct instances and all indirect instances of direct sub-types. - * - * @return All the indirect instances of this type. - */ - @CheckReturnValue - Stream getInstances(); - - /** - * Changes the Label of this Concept to a new one. - * - * @param label The new Label. - */ void setLabel(String label); - /** - * Sets the ThingType to be abstract - which prevents it from having any instances. - */ void setAbstract(); - /** - * Sets the ThingType to be not abstract - which allows it to have instances. - */ void unsetAbstract(); - /** - * @param role Set the RoleType which the instances of this Type are allowed to play. - */ void setPlays(RoleType role); void setPlays(RoleType roleType, RoleType overriddenType); - /** - * Creates a connection which allows this type and an AttributeType to be linked. - * - * @param attributeType The AttributeType which instances of this type should be allowed to play. - */ void setOwns(AttributeType attributeType, AttributeType otherType, boolean isKey); default void setOwns(AttributeType attributeType, AttributeType overriddenType) { @@ -138,54 +76,26 @@ default void setOwns(AttributeType attributeType) { setOwns(attributeType, false); } - /** - * @return A list of RoleTypes which instances of this Type can indirectly play. - */ - Stream getPlays(); + Stream getPlays(); - /** - * @param keysOnly If true, only returns keys. - * @return The AttributeTypes which this Type is linked with, optionally only keys. - */ - @CheckReturnValue - Stream getOwns(ValueType valueType, boolean keysOnly); + default Stream getOwns() { + return getOwns(false); + } - @CheckReturnValue - default Stream getOwns(ValueType valueType) { + default Stream getOwns(ValueType valueType) { return getOwns(valueType, false); } - @CheckReturnValue - default Stream getOwns(boolean keysOnly) { + default Stream getOwns(boolean keysOnly) { return getOwns(null, keysOnly); } - @CheckReturnValue - default Stream getOwns() { - return getOwns(false); - } + Stream getOwns(ValueType valueType, boolean keysOnly); - /** - * Removes the ability of this Type to play a specific RoleType. - * - * @param role The RoleType which the Things of this Type should no longer be allowed to play. - */ void unsetPlays(RoleType role); - /** - * Removes the ability for Things of this Type to have Attributes of type AttributeType - * - * @param attributeType the AttributeType which this Type can no longer have - */ void unsetOwns(AttributeType attributeType); - @CheckReturnValue - @Override - default ThingType.Remote asRemote(Concepts concepts) { - return this; - } - - @CheckReturnValue @Override default ThingType.Remote asThingType() { return this; diff --git a/concept/type/Type.java b/concept/type/Type.java index 29c4917a87..07a06220f7 100644 --- a/concept/type/Type.java +++ b/concept/type/Type.java @@ -19,342 +19,105 @@ package grakn.client.concept.type; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; import grakn.client.concept.Concept; -import grakn.client.concept.Concepts; -import grakn.client.concept.type.impl.AttributeTypeImpl; -import grakn.client.concept.type.impl.EntityTypeImpl; -import grakn.client.concept.type.impl.RelationTypeImpl; -import grakn.client.concept.type.impl.RoleTypeImpl; -import grakn.client.concept.type.impl.RuleImpl; -import grakn.client.concept.type.impl.ThingTypeImpl; -import grakn.protocol.ConceptProto; - -import javax.annotation.CheckReturnValue; + import javax.annotation.Nullable; import java.util.stream.Stream; import static grakn.client.common.exception.ErrorMessage.Concept.INVALID_CONCEPT_CASTING; -import static grakn.client.common.exception.ErrorMessage.Protocol.ILLEGAL_COMBINATION_OF_FIELDS; -import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; - -/** - * Facilitates construction of ontological elements. - * Allows you to create schema or ontological elements. - * These differ from normal graph constructs in two ways: - * 1. They have a unique Label which identifies them - * 2. You can link them together into a hierarchical structure - */ + public interface Type extends Concept { - /** - * Returns the unique label of this Type. - * - * @return The unique label of this type - */ - @CheckReturnValue String getLabel(); - /** - * Return if the type is a root type. - * - * @return Returns true if the type is a root type. - */ - @CheckReturnValue boolean isRoot(); - /** - * Return as a ThingType if the Concept is a ThingType. - * - * @return A ThingType if the Concept is a ThingType - */ - @CheckReturnValue ThingType asThingType(); - /** - * Return as an EntityType if the Concept is an EntityType. - * - * @return A EntityType if the Concept is an EntityType - */ - @CheckReturnValue EntityType asEntityType(); - /** - * Return as an AttributeType if the Concept is an AttributeType - * - * @return An AttributeType if the Concept is an AttributeType - */ - @CheckReturnValue AttributeType asAttributeType(); - /** - * Return as a RelationType if the Concept is a RelationType. - * - * @return A RelationType if the Concept is a RelationType - */ - @CheckReturnValue RelationType asRelationType(); - /** - * Return as a RoleType if the Concept is a RoleType. - * - * @return A RoleType if the Concept is a RoleType - */ - @CheckReturnValue RoleType asRoleType(); - @CheckReturnValue @Override - Remote asRemote(Concepts concepts); + Remote asRemote(Grakn.Transaction transaction); interface Local extends Type, Concept.Local { - static Type.Local of(ConceptProto.Type type) { - switch (type.getSchema()) { - case ENTITY_TYPE: - return new EntityTypeImpl.Local(type); - case RELATION_TYPE: - return new RelationTypeImpl.Local(type); - case ATTRIBUTE_TYPE: - switch (type.getValueType()) { - case BOOLEAN: - return new AttributeTypeImpl.Boolean.Local(type); - case LONG: - return new AttributeTypeImpl.Long.Local(type); - case DOUBLE: - return new AttributeTypeImpl.Double.Local(type); - case STRING: - return new AttributeTypeImpl.String.Local(type); - case DATETIME: - return new AttributeTypeImpl.DateTime.Local(type); - case OBJECT: - if (type.getRoot()) { - return new AttributeTypeImpl.Local(type); - } else { - throw new GraknException(ILLEGAL_COMBINATION_OF_FIELDS.message( - "valueType", ConceptProto.AttributeType.VALUE_TYPE.OBJECT, - "root", false)); - } - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.AttributeType.VALUE_TYPE.class.getCanonicalName(), type.getValueType())); - } - case ROLE_TYPE: - return new RoleTypeImpl.Local(type); - case RULE: - return new RuleImpl.Local(type); - case THING_TYPE: - return new ThingTypeImpl.Local(type); - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Type.SCHEMA.class.getCanonicalName(), type.getSchema())); - } - } - - @CheckReturnValue @Override default Type.Local asType() { return this; } - /** - * Return as a ThingType if the Type is a ThingType. - * - * @return A ThingType if the Type is a ThingType - */ @Override default ThingType.Local asThingType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, ThingType.class.getCanonicalName())); } - /** - * Return as an EntityType if the Type is an EntityType. - * - * @return A EntityType if the Type is an EntityType - */ @Override default EntityType.Local asEntityType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, EntityType.class.getCanonicalName())); } - /** - * Return as an AttributeType if the Type is an AttributeType - * - * @return An AttributeType if the Type is an AttributeType - */ @Override default AttributeType.Local asAttributeType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.class.getCanonicalName())); } - /** - * Return as a RelationType if the Type is a RelationType. - * - * @return A RelationType if the Type is a RelationType - */ @Override default RelationType.Local asRelationType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, RelationType.class.getCanonicalName())); } - /** - * Return as a RoleType if the Type is a RoleType. - * - * @return A RoleType if the Type is a RoleType - */ @Override default RoleType.Local asRoleType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, RoleType.class.getCanonicalName())); } } - /** - * Facilitates construction of ontological elements. - * Allows you to create schema or ontological elements. - * These differ from normal graph constructs in two ways: - * 1. They have a unique Label which identifies them - * 2. You can link them together into a hierarchical structure - */ interface Remote extends Type, Concept.Remote { - static Type.Remote of(final Concepts concepts, final ConceptProto.Type type) { - final String label = type.getLabel(); - switch (type.getSchema()) { - case ENTITY_TYPE: - return new EntityTypeImpl.Remote(concepts, label, type.getRoot()); - case RELATION_TYPE: - return new RelationTypeImpl.Remote(concepts, label, type.getRoot()); - case ATTRIBUTE_TYPE: - switch (type.getValueType()) { - case BOOLEAN: - return new AttributeTypeImpl.Boolean.Remote(concepts, label, type.getRoot()); - case LONG: - return new AttributeTypeImpl.Long.Remote(concepts, label, type.getRoot()); - case DOUBLE: - return new AttributeTypeImpl.Double.Remote(concepts, label, type.getRoot()); - case STRING: - return new AttributeTypeImpl.String.Remote(concepts, label, type.getRoot()); - case DATETIME: - return new AttributeTypeImpl.DateTime.Remote(concepts, label, type.getRoot()); - case OBJECT: - if (type.getRoot()) { - return new AttributeTypeImpl.Remote(concepts, label, true); - } else { - throw new GraknException(ILLEGAL_COMBINATION_OF_FIELDS.message( - "valueType", ConceptProto.AttributeType.VALUE_TYPE.OBJECT, - "root", false)); - } - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.AttributeType.VALUE_TYPE.class.getCanonicalName(), type.getValueType())); - } - case ROLE_TYPE: - final String scopedLabel = type.getScopedLabel(); - return new RoleTypeImpl.Remote(concepts, label, scopedLabel, type.getRoot()); - case RULE: - return new RuleImpl.Remote(concepts, label, type.getRoot()); - case THING_TYPE: - return new ThingTypeImpl.Remote(concepts, label, type.getRoot()); - default: - case UNRECOGNIZED: - throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Type.SCHEMA.class.getCanonicalName(), type.getSchema())); - } - } - - /** - * Changes the Label of this Concept to a new one. - * - * @param label The new Label. - */ void setLabel(String label); - /** - * Return if the type is set to abstract. - * By default, types are not abstract. - * - * @return returns true if the type is set to be abstract. - */ - @CheckReturnValue boolean isAbstract(); - /** - * @return The direct supertype of this concept - */ - @CheckReturnValue @Nullable - Type.Remote getSupertype(); - - /** - * @return All super-concepts of this Type, including itself and excluding the meta type THING. - */ - @CheckReturnValue - Stream getSupertypes(); - - /** - * Get all indirect subs of this concept. - * The indirect subs are the concept itself and all indirect subs of direct subs. - * - * @return All the indirect sub-types of this Type - */ - @CheckReturnValue - Stream getSubtypes(); + Type.Local getSupertype(); - @Override - default Type.Remote asRemote(Concepts concepts) { - return this; - } + Stream getSupertypes(); + + Stream getSubtypes(); - @CheckReturnValue @Override default Type.Remote asType() { return this; } - /** - * Return as a ThingType if the Type is a ThingType. - * - * @return A ThingType if the Type is a ThingType - */ @Override default ThingType.Remote asThingType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, ThingType.class.getCanonicalName())); } - /** - * Return as an EntityType if the Type is an EntityType. - * - * @return A EntityType if the Type is an EntityType - */ @Override default EntityType.Remote asEntityType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, EntityType.class.getCanonicalName())); } - /** - * Return as a RelationType if the Type is a RelationType. - * - * @return A RelationType if the Type is a RelationType - */ @Override default RelationType.Remote asRelationType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, RelationType.class.getCanonicalName())); } - /** - * Return as a AttributeType if the Type is a AttributeType - * - * @return A AttributeType if the Type is a AttributeType - */ @Override default AttributeType.Remote asAttributeType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.class.getCanonicalName())); } - /** - * Return as a RoleType if the Type is a RoleType. - * - * @return A RoleType if the Type is a RoleType - */ @Override default RoleType.Remote asRoleType() { throw new GraknException(INVALID_CONCEPT_CASTING.message(this, RoleType.class.getCanonicalName())); diff --git a/concept/type/impl/AttributeTypeImpl.java b/concept/type/impl/AttributeTypeImpl.java index b8d173a547..ff39fcaa9f 100644 --- a/concept/type/impl/AttributeTypeImpl.java +++ b/concept/type/impl/AttributeTypeImpl.java @@ -19,65 +19,168 @@ package grakn.client.concept.type.impl; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; import grakn.client.concept.thing.Attribute; -import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.AttributeImpl; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.time.LocalDateTime; import java.util.stream.Stream; import static grakn.client.common.exception.ErrorMessage.Concept.INVALID_CONCEPT_CASTING; +import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; import static grakn.client.concept.proto.ConceptProtoBuilder.attributeValue; public abstract class AttributeTypeImpl { private static final java.lang.String ROOT_LABEL = "attribute"; - /** - * Client implementation of AttributeType - */ public static class Local extends ThingTypeImpl.Local implements AttributeType.Local { - public Local(final ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); + } + + public static AttributeTypeImpl.Local of(ConceptProto.Type type) { + switch (type.getValueType()) { + case BOOLEAN: + return new AttributeTypeImpl.Boolean.Local(type.getLabel(), type.getRoot()); + case LONG: + return new AttributeTypeImpl.Long.Local(type.getLabel(), type.getRoot()); + case DOUBLE: + return new AttributeTypeImpl.Double.Local(type.getLabel(), type.getRoot()); + case STRING: + return new AttributeTypeImpl.String.Local(type.getLabel(), type.getRoot()); + case DATETIME: + return new AttributeTypeImpl.DateTime.Local(type.getLabel(), type.getRoot()); + case OBJECT: + assert type.getRoot(); + return new AttributeTypeImpl.Local(type.getLabel(), type.getRoot()); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message( + ConceptProto.AttributeType.VALUE_TYPE.class.getSimpleName(), type.getValueType()) + ); + } + } + + @Override + public AttributeTypeImpl.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.Remote(transaction, label, isRoot); + } + + @Override + public AttributeType.Boolean.Local asBoolean() { + if (isRoot()) { + return new AttributeTypeImpl.Boolean.Local(ROOT_LABEL, true); + } + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Boolean.class.getCanonicalName())); + } + + @Override + public AttributeType.Long.Local asLong() { + if (isRoot()) { + return new AttributeTypeImpl.Long.Local(ROOT_LABEL, true); + } + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Long.class.getCanonicalName())); + } + + @Override + public AttributeType.Double.Local asDouble() { + if (isRoot()) { + return new AttributeTypeImpl.Double.Local(ROOT_LABEL, true); + } + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Double.class.getCanonicalName())); + } + + @Override + public AttributeType.String.Local asString() { + if (isRoot()) { + return new AttributeTypeImpl.String.Local(ROOT_LABEL, true); + } + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.String.class.getCanonicalName())); + } + + @Override + public AttributeType.DateTime.Local asDateTime() { + if (isRoot()) { + return new AttributeTypeImpl.DateTime.Local(ROOT_LABEL, true); + } + throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.DateTime.class.getCanonicalName())); } @Override - public AttributeType.Remote asRemote(final Concepts concepts) { - return new AttributeTypeImpl.Remote(concepts, getLabel(), isRoot()); + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AttributeTypeImpl.Local)) return false; + // We do the above, as opposed to checking if (object == null || getClass() != object.getClass()) + // because it is possible to compare a attribute root types wrapped in different type classes + // such as: root type wrapped in AttributeTypeImpl.Root and as in AttributeType.Boolean.Root + // We only override equals(), but not hash(), in this class, as hash() the logic from TypeImpl still applies. + + AttributeTypeImpl.Local that = (AttributeTypeImpl.Local) o; + return this.getLabel().equals(that.getLabel()); } } - /** - * Client implementation of AttributeType - */ public static class Remote extends ThingTypeImpl.Remote implements AttributeType.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); + } + + public static AttributeTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type typeProto) { + switch (typeProto.getValueType()) { + case BOOLEAN: + return new AttributeTypeImpl.Boolean.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case LONG: + return new AttributeTypeImpl.Long.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case DOUBLE: + return new AttributeTypeImpl.Double.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case STRING: + return new AttributeTypeImpl.String.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case DATETIME: + return new AttributeTypeImpl.DateTime.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case OBJECT: + assert typeProto.getRoot(); + return new AttributeTypeImpl.Remote(transaction, typeProto.getLabel(), typeProto.getRoot()); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message( + ConceptProto.AttributeType.VALUE_TYPE.class.getSimpleName(), typeProto.getValueType()) + ); + } + } + + @Override + public AttributeTypeImpl.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.Remote(transaction, label, isRoot); + } + + public final void setSupertype(AttributeType type) { + this.setSupertypeExecute(type); } @Nullable @Override - public AttributeType.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asAttributeType); + public AttributeType.Local getSupertype() { + return getSupertype(Type.Local::asAttributeType); } @Override - public Stream getSupertypes() { - return super.getSupertypes().map(Type.Remote::asAttributeType); + public Stream getSupertypes() { + return super.getSupertypes().map(Type.Local::asAttributeType); } @Override - public Stream getSubtypes() { - final Stream stream = super.getSubtypes().map(Type.Remote::asAttributeType); + public Stream getSubtypes() { + final Stream stream = super.getSubtypes().map(Type.Local::asAttributeType); if (isRoot() && getValueType() != ValueType.OBJECT) { // Get all attribute types of this value type @@ -88,8 +191,8 @@ public Stream getSubtypes() { } @Override - public Stream> getInstances() { - return super.getInstances().map(Thing.Remote::asAttribute); + public Stream> getInstances() { + return super.getInstances(AttributeImpl.Local::of); } @Override @@ -103,39 +206,35 @@ public Stream getOwners(boolean onlyKey) { .setAttributeTypeGetOwnersIterReq(ConceptProto.AttributeType.GetOwners.Iter.Req.newBuilder() .setOnlyKey(onlyKey)).build(); - return typeStream(method, res -> res.getAttributeTypeGetOwnersIterRes().getOwner()).map(Type.Remote::asThingType); + return stream(method, res -> res.getAttributeTypeGetOwnersIterRes().getOwner()).map(Type.Local::asThingType); } - protected final Attribute.Remote put(Object value) { + protected final Attribute.Local put(Object value) { final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setAttributeTypePutReq(ConceptProto.AttributeType.Put.Req.newBuilder() .setValue(attributeValue(value))).build(); - return Thing.Remote.of(concepts(), runMethod(method).getAttributeTypePutRes().getAttribute()).asAttribute(); + return ThingImpl.Local.of(execute(method).getAttributeTypePutRes().getAttribute()).asAttribute(); } @Nullable - protected final Attribute.Remote get(Object value) { + protected final Attribute.Local get(Object value) { final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setAttributeTypeGetReq(ConceptProto.AttributeType.Get.Req.newBuilder() .setValue(attributeValue(value))).build(); - ConceptProto.AttributeType.Get.Res response = runMethod(method).getAttributeTypeGetRes(); + ConceptProto.AttributeType.Get.Res response = execute(method).getAttributeTypeGetRes(); switch (response.getResCase()) { case ATTRIBUTE: - return Thing.Remote.of(concepts(), response.getAttribute()).asAttribute(); + return ThingImpl.Local.of(response.getAttribute()).asAttribute(); default: case RES_NOT_SET: return null; } } - public final void setSupertype(AttributeType type) { - setSupertypeInternal(type); - } - @Override public AttributeType.Boolean.Remote asBoolean() { if (isRoot()) { - return new AttributeTypeImpl.Boolean.Remote(concepts(), ROOT_LABEL, true); + return new AttributeTypeImpl.Boolean.Remote(tx(), ROOT_LABEL, true); } throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Boolean.class.getCanonicalName())); } @@ -143,7 +242,7 @@ public AttributeType.Boolean.Remote asBoolean() { @Override public AttributeType.Long.Remote asLong() { if (isRoot()) { - return new AttributeTypeImpl.Long.Remote(concepts(), ROOT_LABEL, true); + return new AttributeTypeImpl.Long.Remote(tx(), ROOT_LABEL, true); } throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Long.class.getCanonicalName())); } @@ -151,7 +250,7 @@ public AttributeType.Long.Remote asLong() { @Override public AttributeType.Double.Remote asDouble() { if (isRoot()) { - return new AttributeTypeImpl.Double.Remote(concepts(), ROOT_LABEL, true); + return new AttributeTypeImpl.Double.Remote(tx(), ROOT_LABEL, true); } throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.Double.class.getCanonicalName())); } @@ -159,7 +258,7 @@ public AttributeType.Double.Remote asDouble() { @Override public AttributeType.String.Remote asString() { if (isRoot()) { - return new AttributeTypeImpl.String.Remote(concepts(), ROOT_LABEL, true); + return new AttributeTypeImpl.String.Remote(tx(), ROOT_LABEL, true); } throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.String.class.getCanonicalName())); } @@ -167,7 +266,7 @@ public AttributeType.String.Remote asString() { @Override public AttributeType.DateTime.Remote asDateTime() { if (isRoot()) { - return new AttributeTypeImpl.DateTime.Remote(concepts(), ROOT_LABEL, true); + return new AttributeTypeImpl.DateTime.Remote(tx(), ROOT_LABEL, true); } throw new GraknException(INVALID_CONCEPT_CASTING.message(this, AttributeType.DateTime.class.getCanonicalName())); } @@ -179,59 +278,61 @@ public boolean equals(Object o) { // We do the above, as opposed to checking if (object == null || getClass() != object.getClass()) // because it is possible to compare a attribute root types wrapped in different type classes // such as: root type wrapped in AttributeTypeImpl.Root and as in AttributeType.Boolean.Root + // We only override equals(), but not hash(), in this class, as hash() the logic from TypeImpl still applies. AttributeTypeImpl.Remote that = (AttributeTypeImpl.Remote) o; - - return this.concepts().equals(that.concepts()) && - this.getLabel().equals(that.getLabel()); + return (this.tx().equals(that.tx()) && this.getLabel().equals(that.getLabel())); } } public static abstract class Boolean implements AttributeType.Boolean { - /** - * Client implementation of AttributeType.Boolean - */ public static class Local extends AttributeTypeImpl.Local implements AttributeType.Boolean.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); + } + + @Override + public AttributeTypeImpl.Boolean.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.Boolean.Remote(transaction, label, isRoot); } - @CheckReturnValue @Override - public AttributeType.Boolean.Remote asRemote(final Concepts concepts) { - return AttributeType.Boolean.Remote.of(concepts, getLabel(), isRoot()); + public AttributeType.Boolean.Local asBoolean() { + return this; } } - /** - * Client implementation of AttributeType.Boolean - */ public static class Remote extends AttributeTypeImpl.Remote implements AttributeType.Boolean.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); + } + + @Override + public AttributeTypeImpl.Boolean.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.Boolean.Remote(transaction, label, isRoot); } @Override - public final AttributeType.Boolean.Remote getSupertype() { - return getSupertypeInternal(t -> t.asAttributeType().asBoolean()); + public final AttributeType.Boolean.Local getSupertype() { + return getSupertype(t -> t.asAttributeType().asBoolean()); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(AttributeType.Remote::asBoolean); + public final Stream getSupertypes() { + return super.getSupertypes().map(AttributeType.Local::asBoolean); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(AttributeType.Remote::asBoolean); + public final Stream getSubtypes() { + return super.getSubtypes().map(AttributeType.Local::asBoolean); } @Override - public final Stream getInstances() { - return super.getInstances().map(Attribute.Remote::asBoolean); + public final Stream getInstances() { + return super.getInstances().map(Attribute.Local::asBoolean); } @Override @@ -240,77 +341,72 @@ public final void setSupertype(AttributeType.Boolean type) { } @Override - public final Attribute.Boolean.Remote put(boolean value) { + public final Attribute.Boolean.Local put(boolean value) { return super.put(value).asBoolean(); } @Nullable @Override - public final Attribute.Boolean.Remote get(boolean value) { - final Attribute.Remote attr = super.get(value); + public final Attribute.Boolean.Local get(boolean value) { + final Attribute.Local attr = super.get(value); return attr != null ? attr.asBoolean() : null; } - @CheckReturnValue @Override public AttributeType.Boolean.Remote asBoolean() { return this; } - - public static final class Root extends AttributeTypeImpl.Boolean.Remote { - - public Root(final Concepts concepts) { - super(concepts, ROOT_LABEL, true); - } - } } } public static abstract class Long implements AttributeType.Long { - /** - * Client implementation of AttributeType.Long - */ public static class Local extends AttributeTypeImpl.Local implements AttributeType.Long.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); + } + + @Override + public AttributeTypeImpl.Long.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.Long.Remote(transaction, label, isRoot); } - @CheckReturnValue @Override - public AttributeType.Long.Remote asRemote(final Concepts concepts) { - return AttributeType.Long.Remote.of(concepts, getLabel(), isRoot()); + public AttributeType.Long.Local asLong() { + return this; } } - /** - * Client implementation of AttributeType.Long - */ public static class Remote extends AttributeTypeImpl.Remote implements AttributeType.Long.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); } @Override - public final AttributeType.Long.Remote getSupertype() { - return getSupertypeInternal(t -> t.asAttributeType().asLong()); + public AttributeTypeImpl.Long.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.Long.Remote(transaction, label, isRoot); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(AttributeType.Remote::asLong); + public final AttributeType.Long.Local getSupertype() { + return getSupertype(t -> t.asAttributeType().asLong()); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(AttributeType.Remote::asLong); + public final Stream getSupertypes() { + return super.getSupertypes().map(AttributeType.Local::asLong); } @Override - public final Stream getInstances() { - return super.getInstances().map(Attribute.Remote::asLong); + public final Stream getSubtypes() { + return super.getSubtypes().map(AttributeType.Local::asLong); + } + + @Override + public final Stream getInstances() { + return super.getInstances().map(Attribute.Local::asLong); } @Override @@ -319,18 +415,17 @@ public final void setSupertype(AttributeType.Long type) { } @Override - public final Attribute.Long.Remote put(long value) { + public final Attribute.Long.Local put(long value) { return super.put(value).asLong(); } @Nullable @Override - public final Attribute.Long.Remote get(long value) { - final Attribute.Remote attr = super.get(value); + public final Attribute.Long.Local get(long value) { + final Attribute.Local attr = super.get(value); return attr != null ? attr.asLong() : null; } - @CheckReturnValue @Override public AttributeType.Long.Remote asLong() { return this; @@ -340,49 +435,52 @@ public AttributeType.Long.Remote asLong() { public static abstract class Double implements AttributeType.Double { - /** - * Client implementation of AttributeType.Double - */ public static class Local extends AttributeTypeImpl.Local implements AttributeType.Double.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); + } + + @Override + public AttributeTypeImpl.Double.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.Double.Remote(transaction, label, isRoot); } - @CheckReturnValue @Override - public AttributeType.Double.Remote asRemote(final Concepts concepts) { - return AttributeType.Double.Remote.of(concepts, getLabel(), isRoot()); + public AttributeType.Double.Local asDouble() { + return this; } } - /** - * Client implementation of AttributeType.Double - */ public static class Remote extends AttributeTypeImpl.Remote implements AttributeType.Double.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); } @Override - public final AttributeType.Double.Remote getSupertype() { - return getSupertypeInternal(t -> t.asAttributeType().asDouble()); + public AttributeTypeImpl.Double.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.Double.Remote(transaction, label, isRoot); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(AttributeType.Remote::asDouble); + public final AttributeType.Double.Local getSupertype() { + return getSupertype(t -> t.asAttributeType().asDouble()); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(AttributeType.Remote::asDouble); + public final Stream getSupertypes() { + return super.getSupertypes().map(AttributeType.Local::asDouble); } @Override - public final Stream getInstances() { - return super.getInstances().map(Attribute.Remote::asDouble); + public final Stream getSubtypes() { + return super.getSubtypes().map(AttributeType.Local::asDouble); + } + + @Override + public final Stream getInstances() { + return super.getInstances().map(Attribute.Local::asDouble); } @Override @@ -391,18 +489,17 @@ public final void setSupertype(AttributeType.Double type) { } @Override - public final Attribute.Double.Remote put(double value) { + public final Attribute.Double.Local put(double value) { return super.put(value).asDouble(); } @Nullable @Override - public final Attribute.Double.Remote get(double value) { - final Attribute.Remote attr = super.get(value); + public final Attribute.Double.Local get(double value) { + final Attribute.Local attr = super.get(value); return attr != null ? attr.asDouble() : null; } - @CheckReturnValue @Override public AttributeType.Double.Remote asDouble() { return this; @@ -412,49 +509,52 @@ public AttributeType.Double.Remote asDouble() { public static abstract class String implements AttributeType.String { - /** - * Client implementation of AttributeType.String - */ public static class Local extends AttributeTypeImpl.Local implements AttributeType.String.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); } - @CheckReturnValue @Override - public AttributeType.String.Remote asRemote(final Concepts concepts) { - return AttributeType.String.Remote.of(concepts, getLabel(), isRoot()); + public AttributeTypeImpl.String.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.String.Remote(transaction, label, isRoot); + } + + @Override + public AttributeType.String.Local asString() { + return this; } } - /** - * Client implementation of AttributeType.Double - */ public static class Remote extends AttributeTypeImpl.Remote implements AttributeType.String.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); + } + + @Override + public AttributeTypeImpl.String.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.String.Remote(transaction, label, isRoot); } @Override - public final AttributeType.String.Remote getSupertype() { - return getSupertypeInternal(t -> t.asAttributeType().asString()); + public final AttributeType.String.Local getSupertype() { + return getSupertype(t -> t.asAttributeType().asString()); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(AttributeType.Remote::asString); + public final Stream getSupertypes() { + return super.getSupertypes().map(AttributeType.Local::asString); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(AttributeType.Remote::asString); + public final Stream getSubtypes() { + return super.getSubtypes().map(AttributeType.Local::asString); } @Override - public final Stream getInstances() { - return super.getInstances().map(Attribute.Remote::asString); + public final Stream getInstances() { + return super.getInstances().map(Attribute.Local::asString); } @Override @@ -463,14 +563,14 @@ public final void setSupertype(AttributeType.String type) { } @Override - public final Attribute.String.Remote put(java.lang.String value) { + public final Attribute.String.Local put(java.lang.String value) { return super.put(value).asString(); } @Nullable @Override - public final Attribute.String.Remote get(java.lang.String value) { - final Attribute.Remote attr = super.get(value); + public final Attribute.String.Local get(java.lang.String value) { + final Attribute.Local attr = super.get(value); return attr != null ? attr.asString() : null; } @@ -479,7 +579,7 @@ public final Attribute.String.Remote get(java.lang.String value) { public final java.lang.String getRegex() { final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setAttributeTypeGetRegexReq(ConceptProto.AttributeType.GetRegex.Req.getDefaultInstance()).build(); - final java.lang.String regex = runMethod(method).getAttributeTypeGetRegexRes().getRegex(); + final java.lang.String regex = execute(method).getAttributeTypeGetRegexRes().getRegex(); return regex.isEmpty() ? null : regex; } @@ -489,10 +589,9 @@ public final void setRegex(java.lang.String regex) { final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setAttributeTypeSetRegexReq(ConceptProto.AttributeType.SetRegex.Req.newBuilder() .setRegex(regex)).build(); - runMethod(method); + execute(method); } - @CheckReturnValue @Override public AttributeType.String.Remote asString() { return this; @@ -502,49 +601,52 @@ public AttributeType.String.Remote asString() { public static abstract class DateTime implements AttributeType.DateTime { - /** - * Client implementation of AttributeType.DateTime - */ public static class Local extends AttributeTypeImpl.Local implements AttributeType.DateTime.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final java.lang.String label, final boolean isRoot) { + super(label, isRoot); } - @CheckReturnValue @Override - public AttributeType.DateTime.Remote asRemote(final Concepts concepts) { - return AttributeType.DateTime.Remote.of(concepts, getLabel(), isRoot()); + public AttributeTypeImpl.DateTime.Remote asRemote(final Grakn.Transaction transaction) { + return new AttributeTypeImpl.DateTime.Remote(transaction, label, isRoot); + } + + @Override + public AttributeType.DateTime.Local asDateTime() { + return this; } } - /** - * Client implementation of AttributeType.DateTime - */ public static class Remote extends AttributeTypeImpl.Remote implements AttributeType.DateTime.Remote { - public Remote(final Concepts concepts, final java.lang.String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final java.lang.String label, final boolean isRoot) { + super(transaction, label, isRoot); + } + + @Override + public AttributeTypeImpl.DateTime.Remote asRemote(Grakn.Transaction transaction) { + return new AttributeTypeImpl.DateTime.Remote(transaction, label, isRoot); } @Override - public final AttributeType.DateTime.Remote getSupertype() { - return getSupertypeInternal(t -> t.asAttributeType().asDateTime()); + public final AttributeType.DateTime.Local getSupertype() { + return getSupertype(t -> t.asAttributeType().asDateTime()); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(AttributeType.Remote::asDateTime); + public final Stream getSupertypes() { + return super.getSupertypes().map(AttributeType.Local::asDateTime); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(AttributeType.Remote::asDateTime); + public final Stream getSubtypes() { + return super.getSubtypes().map(AttributeType.Local::asDateTime); } @Override - public final Stream getInstances() { - return super.getInstances().map(Attribute.Remote::asDateTime); + public final Stream getInstances() { + return super.getInstances().map(Attribute.Local::asDateTime); } @Override @@ -553,18 +655,17 @@ public final void setSupertype(AttributeType.DateTime type) { } @Override - public final Attribute.DateTime.Remote put(LocalDateTime value) { + public final Attribute.DateTime.Local put(LocalDateTime value) { return super.put(value).asDateTime(); } @Nullable @Override - public final Attribute.DateTime.Remote get(LocalDateTime value) { - final Attribute.Remote attr = super.get(value); + public final Attribute.DateTime.Local get(LocalDateTime value) { + final Attribute.Local attr = super.get(value); return attr != null ? attr.asDateTime() : null; } - @CheckReturnValue @Override public AttributeType.DateTime.Remote asDateTime() { return this; diff --git a/concept/type/impl/EntityTypeImpl.java b/concept/type/impl/EntityTypeImpl.java index 07530cc479..5e2574e9b1 100644 --- a/concept/type/impl/EntityTypeImpl.java +++ b/concept/type/impl/EntityTypeImpl.java @@ -19,67 +19,81 @@ package grakn.client.concept.type.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Entity; -import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.EntityImpl; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.EntityType; -import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.EntityType.Create; +import grakn.protocol.ConceptProto.TypeMethod; import java.util.stream.Stream; public class EntityTypeImpl { - /** - * Client implementation of EntityType - */ + public static class Local extends ThingTypeImpl.Local implements EntityType.Local { - public Local(ConceptProto.Type type) { - super(type); + public Local(final String label, final boolean isRoot) { + super(label, isRoot); + } + + public static EntityTypeImpl.Local of(ConceptProto.Type typeProto) { + return new EntityTypeImpl.Local(typeProto.getLabel(), typeProto.getRoot()); + } + + @Override + public EntityTypeImpl.Remote asRemote(final Grakn.Transaction transaction) { + return new EntityTypeImpl.Remote(transaction, getLabel(), isRoot()); } } - /** - * Client implementation of EntityType - */ public static class Remote extends ThingTypeImpl.Remote implements EntityType.Remote { - public Remote(final Concepts concepts, final String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final String label, final boolean isRoot) { + super(transaction, label, isRoot); + } + + public static EntityTypeImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Type proto) { + return new EntityTypeImpl.Remote(transaction, proto.getLabel(), proto.getRoot()); } @Override - public EntityType.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asEntityType); + public final void setSupertype(EntityType superEntityType) { + this.setSupertypeExecute(superEntityType); } @Override - public final Stream getInstances() { - return super.getInstances().map(Thing.Remote::asEntity); + public EntityType.Local getSupertype() { + return super.getSupertype(Type.Local::asEntityType); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(ThingType.Remote::asEntityType); + public final Stream getInstances() { + return super.getInstances(EntityImpl.Local::of); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(ThingType.Remote::asEntityType); + public EntityType.Remote asRemote(Grakn.Transaction transaction) { + return new EntityTypeImpl.Remote(transaction, label, isRoot); } @Override - public final Entity.Remote create() { - ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setEntityTypeCreateReq(ConceptProto.EntityType.Create.Req.getDefaultInstance()).build(); + public final Stream getSupertypes() { + return super.getSupertypes(Type.Local::asEntityType); + } - return Thing.Remote.of(concepts(), runMethod(method).getEntityTypeCreateRes().getEntity()).asEntity(); + @Override + public final Stream getSubtypes() { + return super.getSubtypes(Type.Local::asEntityType); } @Override - public final void setSupertype(EntityType superEntityType) { - setSupertypeInternal(superEntityType); + public final Entity.Local create() { + TypeMethod.Req method = TypeMethod.Req.newBuilder() + .setEntityTypeCreateReq(Create.Req.getDefaultInstance()).build(); + return ThingImpl.Local.of(execute(method).getEntityTypeCreateRes().getEntity()).asEntity(); } } } diff --git a/concept/type/impl/RelationTypeImpl.java b/concept/type/impl/RelationTypeImpl.java index d71fc7db4e..fc64d27823 100644 --- a/concept/type/impl/RelationTypeImpl.java +++ b/concept/type/impl/RelationTypeImpl.java @@ -19,114 +19,124 @@ package grakn.client.concept.type.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.thing.Relation; -import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.RelationImpl; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.RelationType; import grakn.client.concept.type.RoleType; -import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.RelationType.GetRelates; +import grakn.protocol.ConceptProto.RelationType.GetRelatesForRoleLabel; +import grakn.protocol.ConceptProto.RelationType.SetRelates; +import grakn.protocol.ConceptProto.RelationType.UnsetRelates; +import grakn.protocol.ConceptProto.TypeMethod; import java.util.stream.Stream; public class RelationTypeImpl { - /** - * Client implementation of RelationType - */ + public static class Local extends ThingTypeImpl.Local implements RelationType.Local { - public Local(final ConceptProto.Type type) { - super(type); + public Local(final String label, final boolean isRoot) { + super(label, isRoot); + } + + public static RelationTypeImpl.Local of(ConceptProto.Type typeProto) { + return new RelationTypeImpl.Local(typeProto.getLabel(), typeProto.getRoot()); + } + + @Override + public RelationTypeImpl.Remote asRemote(final Grakn.Transaction transaction) { + return new RelationTypeImpl.Remote(transaction, getLabel(), isRoot()); } } - /** - * Client implementation of RelationType - */ public static class Remote extends ThingTypeImpl.Remote implements RelationType.Remote { - public Remote(final Concepts concepts, final String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final String label, final boolean isRoot) { + super(transaction, label, isRoot); } - @Override - public final Stream getInstances() { - return super.getInstances().map(Thing.Remote::asRelation); + public static RelationTypeImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Type proto) { + return new RelationTypeImpl.Remote(transaction, proto.getLabel(), proto.getRoot()); } @Override - public RelationType.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asRelationType); + public final Stream getInstances() { + return super.getInstances(RelationImpl.Local::of); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(ThingType.Remote::asRelationType); + public RelationType.Remote asRemote(Grakn.Transaction transaction) { + return new RelationTypeImpl.Remote(transaction, label, isRoot); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(ThingType.Remote::asRelationType); + public RelationType.Local getSupertype() { + return super.getSupertype(Type.Local::asRelationType); } @Override - public final void setSupertype(final RelationType type) { - setSupertypeInternal(type); + public final Stream getSupertypes() { + return super.getSupertypes(Type.Local::asRelationType); } @Override - public final Relation.Remote create() { - ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRelationTypeCreateReq(ConceptProto.RelationType.Create.Req.getDefaultInstance()).build(); - - return Thing.Remote.of(concepts(), runMethod(method).getRelationTypeCreateRes().getRelation()).asRelation(); + public final Stream getSubtypes() { + return super.getSubtypes(Type.Local::asRelationType); } @Override - public final RoleType.Remote getRelates(final String roleLabel) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRelationTypeGetRelatesForRoleLabelReq(ConceptProto.RelationType.GetRelatesForRoleLabel.Req.newBuilder().setLabel(roleLabel)).build(); + public final void setSupertype(final RelationType type) { + this.setSupertypeExecute(type); + } - final ConceptProto.RelationType.GetRelatesForRoleLabel.Res res = runMethod(method).getRelationTypeGetRelatesForRoleLabelRes(); - if (res.hasRoleType()) { - return Type.Remote.of(concepts(), res.getRoleType()).asRoleType(); - } else { - return null; - } + @Override + public final Relation.Local create() { + TypeMethod.Req method = TypeMethod.Req.newBuilder().setRelationTypeCreateReq( + ConceptProto.RelationType.Create.Req.getDefaultInstance()).build(); + return ThingImpl.Local.of(execute(method).getRelationTypeCreateRes().getRelation()).asRelation(); } @Override - public final Stream getRelates() { - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() - .setRelationTypeGetRelatesIterReq(ConceptProto.RelationType.GetRelates.Iter.Req.getDefaultInstance()).build(); + public final RoleType.Local getRelates(final String roleLabel) { + final TypeMethod.Req method = TypeMethod.Req.newBuilder().setRelationTypeGetRelatesForRoleLabelReq( + GetRelatesForRoleLabel.Req.newBuilder().setLabel(roleLabel)).build(); + final GetRelatesForRoleLabel.Res res = execute(method).getRelationTypeGetRelatesForRoleLabelRes(); + if (res.hasRoleType()) return TypeImpl.Local.of(res.getRoleType()).asRoleType(); + else return null; + } - return typeStream(method, res -> res.getRelationTypeGetRelatesIterRes().getRole()).map(Type.Remote::asRoleType); + @Override + public final Stream getRelates() { + return stream( + TypeMethod.Iter.Req.newBuilder().setRelationTypeGetRelatesIterReq( + GetRelates.Iter.Req.getDefaultInstance()).build(), + res -> res.getRelationTypeGetRelatesIterRes().getRole() + ).map(Type.Local::asRoleType); } @Override public final void setRelates(final String roleLabel) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRelationTypeSetRelatesReq(ConceptProto.RelationType.SetRelates.Req.newBuilder() - .setLabel(roleLabel)).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setRelationTypeSetRelatesReq( + SetRelates.Req.newBuilder().setLabel(roleLabel) + ).build()); } @Override public final void setRelates(final String roleLabel, final String overriddenLabel) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRelationTypeSetRelatesReq(ConceptProto.RelationType.SetRelates.Req.newBuilder() - .setLabel(roleLabel) - .setOverriddenLabel(overriddenLabel)).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setRelationTypeSetRelatesReq( + SetRelates.Req.newBuilder().setLabel(roleLabel).setOverriddenLabel(overriddenLabel) + ).build()); } @Override public final void unsetRelates(String roleLabel) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRelationTypeUnsetRelatesReq(ConceptProto.RelationType.UnsetRelates.Req.newBuilder() - .setLabel(roleLabel)).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setRelationTypeUnsetRelatesReq( + UnsetRelates.Req.newBuilder().setLabel(roleLabel) + ).build()); } } } diff --git a/concept/type/impl/RoleTypeImpl.java b/concept/type/impl/RoleTypeImpl.java index aa4ae192a4..98bb57f0cc 100644 --- a/concept/type/impl/RoleTypeImpl.java +++ b/concept/type/impl/RoleTypeImpl.java @@ -19,120 +19,107 @@ package grakn.client.concept.type.impl; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.Thing; +import grakn.client.Grakn; import grakn.client.concept.type.RelationType; import grakn.client.concept.type.RoleType; import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.RoleType.GetPlayers; +import grakn.protocol.ConceptProto.RoleType.GetRelation; +import grakn.protocol.ConceptProto.RoleType.GetRelations; +import grakn.protocol.ConceptProto.TypeMethod; -import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; -import java.util.function.Function; import java.util.stream.Stream; public class RoleTypeImpl { - /** - * Client implementation of Role - */ + public static class Local extends TypeImpl.Local implements RoleType.Local { - private final String scopedLabel; + public Local(String label, String scope, boolean root) { + super(label, scope, root); + } + + public static RoleTypeImpl.Local of(ConceptProto.Type typeProto) { + return new RoleTypeImpl.Local(typeProto.getLabel(), typeProto.getScope(), typeProto.getRoot()); + } - public Local(ConceptProto.Type type) { - super(type); - scopedLabel = type.getScopedLabel(); + @Override + public final String getScope() { + return scope; } @Override - @CheckReturnValue - public final String getScopedLabel() { - return scopedLabel; + public RoleTypeImpl.Remote asRemote(Grakn.Transaction transaction) { + return new RoleTypeImpl.Remote(transaction, getLabel(), getScope(), isRoot()); } } - /** - * Client implementation of Role - */ public static class Remote extends TypeImpl.Remote implements RoleType.Remote { - private final String scopedLabel; - - public Remote(final Concepts concepts, final String label, final String scopedLabel, final boolean isRoot) { - super(concepts, label, isRoot); - this.scopedLabel = scopedLabel; - } - - @Nullable - @Override - public Type.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asRoleType); - } + private final String scope; - @Override - @CheckReturnValue - public final Stream getSupertypes() { - return super.getSupertypes().map(Type.Remote::asRoleType); + public Remote(final Grakn.Transaction transaction, final String label, + final String scope, final boolean isRoot) { + super(transaction, label, scope, isRoot); + this.scope = scope; } - @Override - @CheckReturnValue - public final Stream getSubtypes() { - return super.getSubtypes().map(Type.Remote::asRoleType); + public static RoleTypeImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Type proto) { + return new RoleTypeImpl.Remote(transaction, proto.getLabel(), proto.getScope(), proto.getRoot()); } + @Nullable @Override - public void setSupertype(RoleType superRole) { - setSupertypeInternal(superRole); + public RoleType.Local getSupertype() { + return getSupertype(Type.Local::asRoleType); } @Override - @CheckReturnValue - public String getScopedLabel() { - return scopedLabel; + public final Stream getSupertypes() { + return super.getSupertypes(Type.Local::asRoleType); } @Override - @CheckReturnValue - public final RelationType.Remote getRelation() { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setRoleTypeGetRelationReq(ConceptProto.RoleType.GetRelation.Req.getDefaultInstance()).build(); - - final ConceptProto.RoleType.GetRelation.Res response = runMethod(method).getRoleTypeGetRelationRes(); - - return Type.Remote.of(concepts(), response.getRelationType()).asRelationType(); + public final Stream getSubtypes() { + return super.getSubtypes(Type.Local::asRoleType); } @Override - @CheckReturnValue - public final Stream getRelations() { - ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() - .setRoleTypeGetRelationsIterReq(ConceptProto.RoleType.GetRelations.Iter.Req.getDefaultInstance()).build(); - return typeStream(method, res -> res.getRoleTypeGetRelationsIterRes().getRelationType()).map(Type.Remote::asRelationType); + public String getScope() { + return scope; } @Override - @CheckReturnValue - public final Stream getPlayers() { - ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() - .setRoleTypeGetPlayersIterReq(ConceptProto.RoleType.GetPlayers.Iter.Req.getDefaultInstance()).build(); - return typeStream(method, res -> res.getRoleTypeGetPlayersIterRes().getThingType()).map(Type.Remote::asThingType); + public RoleType.Remote asRemote(Grakn.Transaction transaction) { + return new RoleTypeImpl.Remote(transaction, label, scope, isRoot); } @Override - protected Stream thingStream(ConceptProto.TypeMethod.Iter.Req request, Function thingGetter) { - return concepts().iterateTypeMethod(scopedLabel, request, response -> Thing.Remote.of(concepts(), thingGetter.apply(response))); + public final RelationType.Local getRelation() { + final TypeMethod.Req method = TypeMethod.Req.newBuilder() + .setRoleTypeGetRelationReq(GetRelation.Req.getDefaultInstance()).build(); + final GetRelation.Res response = execute(method).getRoleTypeGetRelationRes(); + return TypeImpl.Local.of(response.getRelationType()).asRelationType(); } @Override - protected Stream typeStream(ConceptProto.TypeMethod.Iter.Req request, Function typeGetter) { - return concepts().iterateTypeMethod(scopedLabel, request, response -> Type.Remote.of(concepts(), typeGetter.apply(response))); + public final Stream getRelations() { + return stream( + TypeMethod.Iter.Req.newBuilder().setRoleTypeGetRelationsIterReq( + GetRelations.Iter.Req.getDefaultInstance()).build(), + res -> res.getRoleTypeGetRelationsIterRes().getRelationType() + ).map(Type.Local::asRelationType); } @Override - protected ConceptProto.TypeMethod.Res runMethod(ConceptProto.TypeMethod.Req typeMethod) { - return concepts().runTypeMethod(scopedLabel, typeMethod).getConceptMethodTypeRes().getResponse(); + public final Stream getPlayers() { + return stream( + TypeMethod.Iter.Req.newBuilder().setRoleTypeGetPlayersIterReq( + GetPlayers.Iter.Req.getDefaultInstance()).build(), + res -> res.getRoleTypeGetPlayersIterRes().getThingType() + ).map(Type.Local::asThingType); } } } diff --git a/concept/type/impl/RuleImpl.java b/concept/type/impl/RuleImpl.java index 9b4ec7973f..471257f3dc 100644 --- a/concept/type/impl/RuleImpl.java +++ b/concept/type/impl/RuleImpl.java @@ -19,7 +19,7 @@ package grakn.client.concept.type.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; import grakn.client.concept.type.Rule; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; @@ -30,39 +30,43 @@ import java.util.stream.Stream; public class RuleImpl { - /** - * Client implementation of Rule - */ + public static class Local extends TypeImpl.Local implements Rule.Local { - public Local(ConceptProto.Type type) { - super(type); + Local(final String label, final boolean root) { + super(label, null, root); + } + + public static RuleImpl.Local of(final ConceptProto.Type typeProto) { + return new RuleImpl.Local(typeProto.getLabel(), typeProto.getRoot()); + } + + @Override + public Rule.Remote asRemote(final Grakn.Transaction transaction) { + return new RuleImpl.Remote(transaction, getLabel(), isRoot()); } } - /** - * Client implementation of Rule - */ public static class Remote extends TypeImpl.Remote implements Rule.Remote { - public Remote(final Concepts concepts, final String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final String label, final boolean isRoot) { + super(transaction, label, null, isRoot); } @Nullable @Override - public Type.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asRule); + public Type.Local getSupertype() { + return getSupertype(Type.Local::asRule); } @Override - public final Stream getSupertypes() { - return super.getSupertypes().map(Type.Remote::asRule); + public final Stream getSupertypes() { + return super.getSupertypes(Type.Local::asRule); } @Override - public final Stream getSubtypes() { - return super.getSubtypes().map(Type.Remote::asRule); + public final Stream getSubtypes() { + return super.getSubtypes(Type.Local::asRule); } @Override @@ -72,12 +76,12 @@ public final Pattern getWhen() { ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setRuleWhenReq(ConceptProto.Rule.When.Req.getDefaultInstance()).build(); - ConceptProto.Rule.When.Res response = runMethod(method).getRuleWhenRes(); + ConceptProto.Rule.When.Res response = execute(method).getRuleWhenRes(); switch (response.getResCase()) { case PATTERN: return Graql.parsePattern(response.getPattern()); - default: case RES_NOT_SET: + default: return null; } } @@ -89,14 +93,19 @@ public final Pattern getThen() { ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() .setRuleThenReq(ConceptProto.Rule.Then.Req.getDefaultInstance()).build(); - ConceptProto.Rule.Then.Res response = runMethod(method).getRuleThenRes(); + ConceptProto.Rule.Then.Res response = execute(method).getRuleThenRes(); switch (response.getResCase()) { case PATTERN: return Graql.parsePattern(response.getPattern()); - default: case RES_NOT_SET: + default: return null; } } + + @Override + public Rule.Remote asRemote(Grakn.Transaction transaction) { + return new RuleImpl.Remote(transaction, label, isRoot); + } } } diff --git a/concept/type/impl/ThingTypeImpl.java b/concept/type/impl/ThingTypeImpl.java index 577316d474..b8feb22339 100644 --- a/concept/type/impl/ThingTypeImpl.java +++ b/concept/type/impl/ThingTypeImpl.java @@ -19,145 +19,175 @@ package grakn.client.concept.type.impl; -import grakn.client.concept.Concepts; +import grakn.client.Grakn; +import grakn.client.common.exception.GraknException; import grakn.client.concept.thing.Thing; +import grakn.client.concept.thing.impl.ThingImpl; import grakn.client.concept.type.AttributeType; import grakn.client.concept.type.AttributeType.ValueType; import grakn.client.concept.type.RoleType; import grakn.client.concept.type.ThingType; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; - +import grakn.protocol.ConceptProto.ThingType.GetInstances; +import grakn.protocol.ConceptProto.ThingType.GetOwns; +import grakn.protocol.ConceptProto.ThingType.GetPlays; +import grakn.protocol.ConceptProto.ThingType.SetAbstract; +import grakn.protocol.ConceptProto.ThingType.SetOwns; +import grakn.protocol.ConceptProto.ThingType.SetPlays; +import grakn.protocol.ConceptProto.ThingType.UnsetAbstract; +import grakn.protocol.ConceptProto.ThingType.UnsetOwns; +import grakn.protocol.ConceptProto.ThingType.UnsetPlays; +import grakn.protocol.ConceptProto.TypeMethod; + +import java.util.function.Function; import java.util.stream.Stream; +import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; import static grakn.client.concept.proto.ConceptProtoBuilder.type; import static grakn.client.concept.proto.ConceptProtoBuilder.valueType; public abstract class ThingTypeImpl { - /** - * Client implementation of ThingType - */ + public static class Local extends TypeImpl.Local implements ThingType.Local { - public Local(final ConceptProto.Type type) { - super(type); + Local(final String label, final boolean isRoot) { + super(label, null, isRoot); + } + + public static TypeImpl.Local of(ConceptProto.Type typeProto) { + switch (typeProto.getSchema()) { + case ENTITY_TYPE: + return EntityTypeImpl.Local.of(typeProto); + case RELATION_TYPE: + return RelationTypeImpl.Local.of(typeProto); + case ATTRIBUTE_TYPE: + return AttributeTypeImpl.Local.of(typeProto); + case THING_TYPE: + assert typeProto.getRoot(); + return new ThingTypeImpl.Local(typeProto.getLabel(), typeProto.getRoot()); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Type.SCHEMA.class.getCanonicalName(), typeProto.getSchema())); + } + } + + @Override + public ThingTypeImpl.Remote asRemote(Grakn.Transaction transaction) { + return new ThingTypeImpl.Remote(transaction, getLabel(), isRoot()); } } - /** - * Client implementation of ThingType - */ public static class Remote extends TypeImpl.Remote implements ThingType.Remote { - public Remote(final Concepts concepts, final String label, final boolean isRoot) { - super(concepts, label, isRoot); + public Remote(final Grakn.Transaction transaction, final String label, final boolean isRoot) { + super(transaction, label, null, isRoot); } - @Override - public ThingType.Remote getSupertype() { - return getSupertypeInternal(Type.Remote::asThingType); + public static ThingTypeImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Type type) { + return new ThingTypeImpl.Remote(transaction, type.getLabel(), type.getRoot()); } @Override - public Stream getSupertypes() { - return super.getSupertypes().map(Type.Remote::asThingType); + public ThingType.Local getSupertype() { + return super.getSupertype(Type.Local::asThingType); } @Override - public Stream getSubtypes() { - return super.getSubtypes().map(Type.Remote::asThingType); + public Stream getSupertypes() { + return super.getSupertypes(Type.Local::asThingType); } @Override - public Stream getInstances() { - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() - .setThingTypeGetInstancesIterReq(ConceptProto.ThingType.GetInstances.Iter.Req.getDefaultInstance()).build(); + public Stream getSubtypes() { + return super.getSubtypes(Type.Local::asThingType); + } + + Stream getInstances(Function thingConstructor) { + return tx().concepts().iterateTypeMethod( + label, scope, + TypeMethod.Iter.Req.newBuilder().setThingTypeGetInstancesIterReq( + GetInstances.Iter.Req.getDefaultInstance()).build(), + response -> thingConstructor.apply(response.getThingTypeGetInstancesIterRes().getThing()) + ); + } - return thingStream(method, res -> res.getThingTypeGetInstancesIterRes().getThing()); + @Override + public Stream getInstances() { + return getInstances(ThingImpl.Local::of); } @Override public final void setAbstract() { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeSetAbstractReq(ConceptProto.ThingType.SetAbstract.Req.getDefaultInstance()).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeSetAbstractReq( + SetAbstract.Req.getDefaultInstance() + ).build()); } @Override public final void unsetAbstract() { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeUnsetAbstractReq(ConceptProto.ThingType.UnsetAbstract.Req.getDefaultInstance()).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeUnsetAbstractReq( + UnsetAbstract.Req.getDefaultInstance() + ).build()); } @Override - public final Stream getOwns(final ValueType valueType, final boolean keysOnly) { - final ConceptProto.ThingType.GetOwns.Iter.Req.Builder req = ConceptProto.ThingType.GetOwns.Iter.Req.newBuilder() - .setKeysOnly(keysOnly); - - if (valueType != null) { - req.setValueType(valueType(valueType)); - } - - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder().setThingTypeGetOwnsIterReq(req).build(); - - return typeStream(method, res -> res.getThingTypeGetOwnsIterRes().getAttributeType()).map(Type.Remote::asAttributeType); + public final Stream getOwns(final ValueType valueType, final boolean keysOnly) { + final GetOwns.Iter.Req.Builder req = GetOwns.Iter.Req.newBuilder().setKeysOnly(keysOnly); + if (valueType != null) req.setValueType(valueType(valueType)); + return stream( + TypeMethod.Iter.Req.newBuilder().setThingTypeGetOwnsIterReq(req).build(), + res -> res.getThingTypeGetOwnsIterRes().getAttributeType() + ).map(Type.Local::asAttributeType); } @Override - public final Stream getPlays() { - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() - .setThingTypeGetPlaysIterReq(ConceptProto.ThingType.GetPlays.Iter.Req.getDefaultInstance()).build(); - - return typeStream(method, res -> res.getThingTypeGetPlaysIterRes().getRole()).map(Type.Remote::asRoleType); + public final Stream getPlays() { + return stream( + TypeMethod.Iter.Req.newBuilder().setThingTypeGetPlaysIterReq( + GetPlays.Iter.Req.getDefaultInstance()).build(), + res -> res.getThingTypeGetPlaysIterRes().getRole() + ).map(Type.Local::asRoleType); } @Override public final void setOwns(AttributeType attributeType, AttributeType overriddenType, boolean isKey) { - final ConceptProto.ThingType.SetOwns.Req.Builder req = ConceptProto.ThingType.SetOwns.Req.newBuilder() - .setAttributeType(type(attributeType)) - .setIsKey(isKey); - - if (overriddenType != null) { - req.setOverriddenType(type(overriddenType)); - } - - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeSetOwnsReq(req).build(); - runMethod(method); + final SetOwns.Req.Builder req = SetOwns.Req.newBuilder().setAttributeType(type(attributeType)).setIsKey(isKey); + if (overriddenType != null) req.setOverriddenType(type(overriddenType)); + execute(TypeMethod.Req.newBuilder().setThingTypeSetOwnsReq(req).build()); } @Override public final void setPlays(final RoleType role) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeSetPlaysReq(ConceptProto.ThingType.SetPlays.Req.newBuilder() - .setRole(type(role))).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeSetPlaysReq( + SetPlays.Req.newBuilder().setRole(type(role)) + ).build()); } @Override public final void setPlays(final RoleType role, final RoleType overriddenRole) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeSetPlaysReq(ConceptProto.ThingType.SetPlays.Req.newBuilder() - .setRole(type(role)) - .setOverriddenRole(type(overriddenRole))).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeSetPlaysReq( + SetPlays.Req.newBuilder().setRole(type(role)).setOverriddenRole(type(overriddenRole)) + ).build()); } @Override public final void unsetOwns(final AttributeType attributeType) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeUnsetOwnsReq(ConceptProto.ThingType.UnsetOwns.Req.newBuilder() - .setAttributeType(type(attributeType))).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeUnsetOwnsReq( + UnsetOwns.Req.newBuilder().setAttributeType(type(attributeType)) + ).build()); } @Override public final void unsetPlays(final RoleType role) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setThingTypeUnsetPlaysReq(ConceptProto.ThingType.UnsetPlays.Req.newBuilder() - .setRole(type(role))).build(); - runMethod(method); + execute(TypeMethod.Req.newBuilder().setThingTypeUnsetPlaysReq( + UnsetPlays.Req.newBuilder().setRole(type(role)) + ).build()); + } + + @Override + public ThingType.Remote asRemote(Grakn.Transaction transaction) { + return new ThingTypeImpl.Remote(transaction, label, isRoot); } } } diff --git a/concept/type/impl/TypeImpl.java b/concept/type/impl/TypeImpl.java index 6168f0aa03..4b47b281b3 100644 --- a/concept/type/impl/TypeImpl.java +++ b/concept/type/impl/TypeImpl.java @@ -19,33 +19,50 @@ package grakn.client.concept.type.impl; +import grakn.client.Grakn; import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.Thing; import grakn.client.concept.type.Type; import grakn.protocol.ConceptProto; +import grakn.protocol.ConceptProto.Type.SetSupertype; +import grakn.protocol.ConceptProto.TypeMethod; import javax.annotation.Nullable; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Stream; -import static grakn.client.common.exception.ErrorMessage.ClientInternal.ILLEGAL_ARGUMENT_NULL; -import static grakn.client.common.exception.ErrorMessage.ClientInternal.ILLEGAL_ARGUMENT_NULL_OR_EMPTY; +import static grakn.client.common.exception.ErrorMessage.ClientInternal.MISSING_ARGUMENT; +import static grakn.client.common.exception.ErrorMessage.Protocol.UNRECOGNISED_FIELD; import static grakn.client.concept.proto.ConceptProtoBuilder.type; public abstract class TypeImpl { - /** - * Client implementation of Type - */ public abstract static class Local implements Type.Local { - private final String label; - private final boolean isRoot; + final String label; + final String scope; + final boolean isRoot; + private final int hash; - Local(ConceptProto.Type type) { - this.label = type.getLabel(); - this.isRoot = type.getRoot(); + Local(final String label, final @Nullable String scope, final boolean isRoot) { + this.label = label; + this.scope = scope; + this.isRoot = isRoot; + this.hash = Objects.hash(this.scope, this.label); + } + + public static TypeImpl.Local of(final ConceptProto.Type typeProto) { + switch (typeProto.getSchema()) { + case ROLE_TYPE: + return RoleTypeImpl.Local.of(typeProto); + case RULE: + return RuleImpl.Local.of(typeProto); + case UNRECOGNIZED: + throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Type.SCHEMA.class.getCanonicalName(), typeProto.getSchema())); + default: + return ThingTypeImpl.Local.of(typeProto); + + } } @Override @@ -57,27 +74,63 @@ public final String getLabel() { public final boolean isRoot() { return isRoot; } + + @Override + public String toString() { + return this.getClass().getCanonicalName() + "[label: " + (scope != null ? scope + ":" : "") + label + "]"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final TypeImpl.Local that = (TypeImpl.Local) o; + return (this.label.equals(that.label) && Objects.equals(this.scope, that.scope)); + } + + @Override + public int hashCode() { + return hash; + } } - /** - * Client implementation of Type - */ public abstract static class Remote implements Type.Remote { - private final Concepts concepts; - private final String label; - private final boolean isRoot; + private final Grakn.Transaction transaction; + final String label; + final String scope; + final boolean isRoot; + private final int hash; - Remote(final Concepts concepts, final String label, final boolean isRoot) { - if (concepts == null) { - throw new GraknException(ILLEGAL_ARGUMENT_NULL.message("concept")); - } - this.concepts = concepts; - if (label == null || label.isEmpty()) { - throw new GraknException(ILLEGAL_ARGUMENT_NULL_OR_EMPTY.message("label")); - } + Remote(final Grakn.Transaction transaction, final String label, @Nullable String scope, final boolean isRoot) { + if (transaction == null) throw new GraknException(MISSING_ARGUMENT.message("concept")); + else if (label == null || label.isEmpty()) throw new GraknException(MISSING_ARGUMENT.message("label")); + this.transaction = transaction; this.label = label; + this.scope = scope; this.isRoot = isRoot; + this.hash = Objects.hash(this.transaction, this.label, this.scope); + } + + public static TypeImpl.Remote of(final Grakn.Transaction transaction, final ConceptProto.Type type) { + switch (type.getSchema()) { + case ENTITY_TYPE: + return EntityTypeImpl.Remote.of(transaction, type); + case RELATION_TYPE: + return RelationTypeImpl.Remote.of(transaction, type); + case ATTRIBUTE_TYPE: + return AttributeTypeImpl.Remote.of(transaction, type); + case ROLE_TYPE: + return RoleTypeImpl.Remote.of(transaction, type); + case THING_TYPE: + return ThingTypeImpl.Remote.of(transaction, type); + case RULE: + return RuleImpl.Remote.of(transaction, type); + case UNRECOGNIZED: + default: + throw new GraknException(UNRECOGNISED_FIELD.message(ConceptProto.Type.SCHEMA.class.getCanonicalName(), type.getSchema())); + } } @Override @@ -92,78 +145,83 @@ public final String getLabel() { @Override public final void setLabel(String label) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() + final TypeMethod.Req method = TypeMethod.Req.newBuilder() .setTypeSetLabelReq(ConceptProto.Type.SetLabel.Req.newBuilder() .setLabel(label)).build(); - runMethod(method); + execute(method); } @Override public final boolean isAbstract() { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() + final TypeMethod.Req method = TypeMethod.Req.newBuilder() .setTypeIsAbstractReq(ConceptProto.Type.IsAbstract.Req.getDefaultInstance()).build(); - return runMethod(method).getTypeIsAbstractRes().getAbstract(); + return execute(method).getTypeIsAbstractRes().getAbstract(); + } + + void setSupertypeExecute(Type type) { + execute(TypeMethod.Req.newBuilder().setTypeSetSupertypeReq(SetSupertype.Req.newBuilder().setType(type(type))).build()); } @Nullable - protected TYPE getSupertypeInternal(final Function typeConverter) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() + TYPE getSupertype(final Function typeConstructor) { + final TypeMethod.Req method = TypeMethod.Req.newBuilder() .setTypeGetSupertypeReq(ConceptProto.Type.GetSupertype.Req.getDefaultInstance()).build(); - final ConceptProto.Type.GetSupertype.Res response = runMethod(method).getTypeGetSupertypeRes(); + final ConceptProto.Type.GetSupertype.Res response = execute(method).getTypeGetSupertypeRes(); switch (response.getResCase()) { case TYPE: - return typeConverter.apply(Type.Remote.of(concepts, response.getType())); - default: + return typeConstructor.apply(TypeImpl.Local.of(response.getType())); case RES_NOT_SET: + default: return null; } } - @Override - public Stream getSupertypes() { - if (isRoot()) { - return Stream.of(this); - } - - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() + Stream getSupertypes(final Function typeConstructor) { + final TypeMethod.Iter.Req method = TypeMethod.Iter.Req.newBuilder() .setTypeGetSupertypesIterReq(ConceptProto.Type.GetSupertypes.Iter.Req.getDefaultInstance()).build(); - - return typeStream(method, res -> res.getTypeGetSupertypesIterRes().getType()); + return stream(method, res -> res.getTypeGetSupertypesIterRes().getType()).map(typeConstructor); } - @Override - public Stream getSubtypes() { - final ConceptProto.TypeMethod.Iter.Req method = ConceptProto.TypeMethod.Iter.Req.newBuilder() + Stream getSubtypes(final Function typeConstructor) { + final TypeMethod.Iter.Req method = TypeMethod.Iter.Req.newBuilder() .setTypeGetSubtypesIterReq(ConceptProto.Type.GetSubtypes.Iter.Req.getDefaultInstance()).build(); - - return typeStream(method, res -> res.getTypeGetSubtypesIterRes().getType()); - } - - protected void setSupertypeInternal(Type type) { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() - .setTypeSetSupertypeReq(ConceptProto.Type.SetSupertype.Req.newBuilder() - .setType(type(type))).build(); - runMethod(method); + return stream(method, res -> res.getTypeGetSubtypesIterRes().getType()).map(typeConstructor); } @Override public final void delete() { - final ConceptProto.TypeMethod.Req method = ConceptProto.TypeMethod.Req.newBuilder() + final TypeMethod.Req method = TypeMethod.Req.newBuilder() .setTypeDeleteReq(ConceptProto.Type.Delete.Req.getDefaultInstance()).build(); - runMethod(method); + execute(method); } @Override public final boolean isDeleted() { - return concepts.getType(getLabel()) == null; + return transaction.concepts().getType(getLabel()) == null; + } + + protected final Grakn.Transaction tx() { + return transaction; + } + + protected Stream stream(final TypeMethod.Iter.Req request, + final Function typeGetter) { + return transaction.concepts().iterateTypeMethod( + label, scope, request, response -> TypeImpl.Local.of(typeGetter.apply(response)) + ); + } + + protected TypeMethod.Res execute(final TypeMethod.Req typeMethod) { + return transaction.concepts().runTypeMethod(label, scope, typeMethod) + .getConceptMethodTypeRes().getResponse(); } @Override public String toString() { - return this.getClass().getCanonicalName() + "{concepts=" + concepts + ", label=" + label + "}"; + return this.getClass().getCanonicalName() + "[label: " + (scope != null ? scope + ":" : "") + label + "]"; } @Override @@ -172,35 +230,14 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; final TypeImpl.Remote that = (TypeImpl.Remote) o; - - return this.concepts.equals(that.concepts) && - this.label.equals(that.label); + return (this.transaction.equals(that.transaction) && + this.label.equals(that.label) && + Objects.equals(this.scope, that.scope)); } @Override public int hashCode() { - int h = 1; - h *= 1000003; - h ^= concepts.hashCode(); - h *= 1000003; - h ^= label.hashCode(); - return h; - } - - protected final Concepts concepts() { - return concepts; - } - - protected Stream thingStream(final ConceptProto.TypeMethod.Iter.Req request, final Function thingGetter) { - return concepts.iterateTypeMethod(label, request, response -> Thing.Remote.of(concepts, thingGetter.apply(response))); - } - - protected Stream typeStream(final ConceptProto.TypeMethod.Iter.Req request, final Function typeGetter) { - return concepts.iterateTypeMethod(label, request, response -> Type.Remote.of(concepts, typeGetter.apply(response))); - } - - protected ConceptProto.TypeMethod.Res runMethod(final ConceptProto.TypeMethod.Req typeMethod) { - return concepts.runTypeMethod(label, typeMethod).getConceptMethodTypeRes().getResponse(); + return hash; } } } diff --git a/dependencies/graknlabs/artifacts.bzl b/dependencies/graknlabs/artifacts.bzl index aba17aeb82..125f2db112 100644 --- a/dependencies/graknlabs/artifacts.bzl +++ b/dependencies/graknlabs/artifacts.bzl @@ -26,5 +26,5 @@ def graknlabs_grakn_core_artifact(): artifact_name = "grakn-core-server-linux-{version}.tar.gz", tag_source = deployment_private["artifact.release"], commit_source = deployment_private["artifact.snapshot"], - commit = "818139a2ff11b9ae5cefd538a6c2a3c6a0a150ae", + commit = "da958b0632954626399264e03c647bd8da739f09", ) diff --git a/dependencies/graknlabs/repositories.bzl b/dependencies/graknlabs/repositories.bzl index 3c8e553474..3cc645e564 100644 --- a/dependencies/graknlabs/repositories.bzl +++ b/dependencies/graknlabs/repositories.bzl @@ -51,7 +51,7 @@ def graknlabs_protocol(): git_repository( name = "graknlabs_protocol", remote = "https://github.com/graknlabs/protocol", - commit = "0dc1a6286f2726232d24e2de1aa07539b22c4cd9", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_protocol + commit = "6871914abd01dca2c941b88534e0341986acc1df", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_protocol ) def graknlabs_behaviour(): diff --git a/rpc/RPCClient.java b/rpc/RPCClient.java index 2a1b4b6236..a8cb8488ae 100644 --- a/rpc/RPCClient.java +++ b/rpc/RPCClient.java @@ -28,9 +28,6 @@ import java.util.concurrent.TimeUnit; -/** - * Entry-point which communicates with a running Grakn server using gRPC. - */ public class RPCClient implements Client { public static final String DEFAULT_URI = "localhost:48555"; diff --git a/rpc/RPCConcepts.java b/rpc/RPCConcepts.java deleted file mode 100644 index b18ab8d691..0000000000 --- a/rpc/RPCConcepts.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package grakn.client.rpc; - -import grakn.client.common.exception.GraknException; -import grakn.client.concept.Concepts; -import grakn.client.concept.thing.Thing; -import grakn.client.concept.type.AttributeType; -import grakn.client.concept.type.EntityType; -import grakn.client.concept.type.RelationType; -import grakn.client.concept.type.RoleType; -import grakn.client.concept.type.Rule; -import grakn.client.concept.type.ThingType; -import grakn.client.concept.type.Type; -import grakn.protocol.ConceptProto; -import grakn.protocol.TransactionProto; -import graql.lang.common.GraqlToken; -import graql.lang.pattern.Pattern; - -import javax.annotation.Nullable; -import java.util.function.Function; -import java.util.stream.Stream; - -import static grakn.client.concept.proto.ConceptProtoBuilder.iid; -import static grakn.client.concept.proto.ConceptProtoBuilder.valueType; -import static grakn.client.rpc.RPCProtoBuilder.tracingData; - -public final class RPCConcepts implements Concepts { - - private final RPCTransceiver transceiver; - - public RPCConcepts(final RPCTransceiver transceiver) { - this.transceiver = transceiver; - } - - @Override - public ThingType.Remote getRootType() { - return getType(GraqlToken.Type.THING.toString()).asThingType(); - } - - @Override - public EntityType.Remote getRootEntityType() { - return getType(GraqlToken.Type.ENTITY.toString()).asEntityType(); - } - - @Override - public RelationType.Remote getRootRelationType() { - return getType(GraqlToken.Type.RELATION.toString()).asRelationType(); - } - - @Override - public AttributeType.Remote getRootAttributeType() { - return getType(GraqlToken.Type.ATTRIBUTE.toString()).asAttributeType(); - } - - @Override - public RoleType.Remote getRootRoleType() { - return getType(GraqlToken.Type.ROLE.toString()).asRoleType(); - } - - @Override - public Rule.Remote getRootRule() { - return getType(GraqlToken.Type.RULE.toString()).asRule(); - } - - @Override - public EntityType.Remote putEntityType(final String label) { - final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setPutEntityTypeReq(TransactionProto.Transaction.PutEntityType.Req.newBuilder() - .setLabel(label)).build(); - - final TransactionProto.Transaction.Res res = transceiver.sendAndReceiveOrThrow(req); - return Type.Remote.of(this, res.getPutEntityTypeRes().getEntityType()).asEntityType(); - } - - @Override - @Nullable - public EntityType.Remote getEntityType(final String label) { - final Type.Remote concept = getType(label); - if (concept instanceof ThingType.Remote) { - return (EntityType.Remote) concept; - } else { - return null; - } - } - - @Override - public RelationType.Remote putRelationType(final String label) { - final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setPutRelationTypeReq(TransactionProto.Transaction.PutRelationType.Req.newBuilder() - .setLabel(label)).build(); - final TransactionProto.Transaction.Res res = transceiver.sendAndReceiveOrThrow(req); - return Type.Remote.of(this, res.getPutRelationTypeRes().getRelationType()).asRelationType(); - } - - @Override - @Nullable - public RelationType.Remote getRelationType(final String label) { - final Type.Remote concept = getType(label); - if (concept instanceof RelationType.Remote) { - return (RelationType.Remote) concept; - } else { - return null; - } - } - - @Override - public AttributeType.Remote putAttributeType(final String label, final AttributeType.ValueType valueType) { - final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setPutAttributeTypeReq(TransactionProto.Transaction.PutAttributeType.Req.newBuilder() - .setLabel(label) - .setValueType(valueType(valueType))).build(); - final TransactionProto.Transaction.Res res = transceiver.sendAndReceiveOrThrow(req); - return Type.Remote.of(this, res.getPutAttributeTypeRes().getAttributeType()).asAttributeType(); - } - - @Override - @Nullable - public AttributeType.Remote getAttributeType(final String label) { - final Type.Remote concept = getType(label); - if (concept instanceof AttributeType.Remote) { - return (AttributeType.Remote) concept; - } else { - return null; - } - } - - @Override - public Rule.Remote putRule(final String label, final Pattern when, final Pattern then) { - throw new GraknException(new UnsupportedOperationException()); - /*final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setPutRuleReq(TransactionProto.Transaction.PutRule.Req.newBuilder() - .setLabel(label) - .setWhen(when.toString()) - .setThen(then.toString())).build(); - - final TransactionProto.Transaction.Res res = sendAndReceiveOrThrow(req); - return Type.Remote.of(this, res.getPutRuleRes().getRule()).asRule();*/ - } - - @Override - @Nullable - public Rule.Remote getRule(String label) { - Type.Remote concept = getType(label); - if (concept instanceof Rule.Remote) { - return (Rule.Remote) concept; - } else { - return null; - } - } - - @Override - @Nullable - public Type.Remote getType(final String label) { - final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setGetTypeReq(TransactionProto.Transaction.GetType.Req.newBuilder().setLabel(label)).build(); - - final TransactionProto.Transaction.Res response = transceiver.sendAndReceiveOrThrow(req); - switch (response.getGetTypeRes().getResCase()) { - case TYPE: - return Type.Remote.of(this, response.getGetTypeRes().getType()); - default: - case RES_NOT_SET: - return null; - } - } - - @Override - @Nullable - public Thing.Remote getThing(final String iid) { - final TransactionProto.Transaction.Req req = TransactionProto.Transaction.Req.newBuilder() - .putAllMetadata(tracingData()) - .setGetThingReq(TransactionProto.Transaction.GetThing.Req.newBuilder().setIid(iid(iid))).build(); - - final TransactionProto.Transaction.Res response = transceiver.sendAndReceiveOrThrow(req); - switch (response.getGetThingRes().getResCase()) { - case THING: - return Thing.Remote.of(this, response.getGetThingRes().getThing()); - default: - case RES_NOT_SET: - return null; - } - } - - @Override - public TransactionProto.Transaction.Res runThingMethod(final String iid, final ConceptProto.ThingMethod.Req thingMethod) { - final TransactionProto.Transaction.Req request = TransactionProto.Transaction.Req.newBuilder() - .setConceptMethodThingReq(TransactionProto.Transaction.ConceptMethod.Thing.Req.newBuilder() - .setIid(iid(iid)) - .setMethod(thingMethod)).build(); - - return transceiver.sendAndReceiveOrThrow(request); - } - - @Override - public TransactionProto.Transaction.Res runTypeMethod(final String label, final ConceptProto.TypeMethod.Req typeMethod) { - final TransactionProto.Transaction.Req request = TransactionProto.Transaction.Req.newBuilder() - .setConceptMethodTypeReq(TransactionProto.Transaction.ConceptMethod.Type.Req.newBuilder() - .setLabel(label) - .setMethod(typeMethod)).build(); - - return transceiver.sendAndReceiveOrThrow(request); - } - - @Override - public Stream iterateThingMethod(final String iid, final ConceptProto.ThingMethod.Iter.Req method, - final Function responseReader) { - final TransactionProto.Transaction.Iter.Req request = TransactionProto.Transaction.Iter.Req.newBuilder() - .setConceptMethodThingIterReq(TransactionProto.Transaction.ConceptMethod.Thing.Iter.Req.newBuilder() - .setIid(iid(iid)) - .setMethod(method)).build(); - - return transceiver.iterate(request, res -> responseReader.apply(res.getConceptMethodThingIterRes().getResponse())); - } - - @Override - public Stream iterateTypeMethod(final String label, final ConceptProto.TypeMethod.Iter.Req method, - final Function responseReader) { - final TransactionProto.Transaction.Iter.Req request = TransactionProto.Transaction.Iter.Req.newBuilder() - .setConceptMethodTypeIterReq(TransactionProto.Transaction.ConceptMethod.Type.Iter.Req.newBuilder() - .setLabel(label) - .setMethod(method)).build(); - - return transceiver.iterate(request, res -> responseReader.apply(res.getConceptMethodTypeIterRes().getResponse())); - } -} diff --git a/rpc/RPCDatabase.java b/rpc/RPCDatabase.java index 707509c47d..889d49f29b 100644 --- a/rpc/RPCDatabase.java +++ b/rpc/RPCDatabase.java @@ -22,7 +22,7 @@ import grakn.client.Grakn.Database; import grakn.client.common.exception.GraknException; -import static grakn.client.common.exception.ErrorMessage.ClientInternal.ILLEGAL_ARGUMENT_NULL_OR_EMPTY; +import static grakn.client.common.exception.ErrorMessage.ClientInternal.MISSING_ARGUMENT; public class RPCDatabase implements Database { private static final long serialVersionUID = 2726154016735929123L; @@ -36,7 +36,7 @@ public RPCDatabase() { public RPCDatabase(String name) { if (name == null || name.isEmpty()) { - throw new GraknException(ILLEGAL_ARGUMENT_NULL_OR_EMPTY.message("name")); + throw new GraknException(MISSING_ARGUMENT.message("name")); } this.name = name; } diff --git a/rpc/RPCIterator.java b/rpc/RPCIterator.java index f57bb8f227..f814c23b9b 100644 --- a/rpc/RPCIterator.java +++ b/rpc/RPCIterator.java @@ -29,12 +29,6 @@ import static grakn.client.common.exception.ErrorMessage.Protocol.REQUIRED_FIELD_NOT_SET; -/** - * A client-side iterator over gRPC messages. Will send TransactionProto.Transaction.Iter.Req messages until - * TransactionProto.Transaction.Iter.Res returns done as a message. - * - * @param class type of objects being iterated - */ class RPCIterator extends AbstractIterator { private Batch currentBatch; diff --git a/rpc/RPCSession.java b/rpc/RPCSession.java index 018f0c52ac..5470b32ee0 100644 --- a/rpc/RPCSession.java +++ b/rpc/RPCSession.java @@ -28,7 +28,7 @@ import grakn.protocol.SessionProto; import io.grpc.ManagedChannel; -import static grakn.client.rpc.RPCProtoBuilder.options; +import static grakn.client.common.ProtoBuilder.options; public class RPCSession implements Session { diff --git a/rpc/RPCTransaction.java b/rpc/RPCTransaction.java index 145a2f0d2f..066cdf6772 100644 --- a/rpc/RPCTransaction.java +++ b/rpc/RPCTransaction.java @@ -20,7 +20,7 @@ package grakn.client.rpc; import com.google.protobuf.ByteString; -import grabl.tracing.client.GrablTracingThreadStatic; +import grabl.tracing.client.GrablTracingThreadStatic.ThreadTrace; import grakn.client.Grakn.Database; import grakn.client.Grakn.Session; import grakn.client.Grakn.Transaction; @@ -39,13 +39,12 @@ import grakn.protocol.AnswerProto; import grakn.protocol.ConceptProto; import grakn.protocol.GraknGrpc; -import grakn.protocol.OptionsProto; import grakn.protocol.TransactionProto; import graql.lang.query.GraqlCompute; import graql.lang.query.GraqlDefine; import graql.lang.query.GraqlDelete; -import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlInsert; +import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlQuery; import graql.lang.query.GraqlUndefine; @@ -58,10 +57,10 @@ import static grabl.tracing.client.GrablTracingThreadStatic.traceOnThread; import static grakn.client.Grakn.Transaction.Type.WRITE; +import static grakn.client.common.ProtoBuilder.options; +import static grakn.client.common.ProtoBuilder.tracingData; import static grakn.client.common.exception.ErrorMessage.Query.UNRECOGNISED_QUERY_OBJECT; import static grakn.client.concept.proto.ConceptProtoBuilder.concept; -import static grakn.client.rpc.RPCProtoBuilder.options; -import static grakn.client.rpc.RPCProtoBuilder.tracingData; public class RPCTransaction implements Transaction { @@ -71,11 +70,11 @@ public class RPCTransaction implements Transaction { private final RPCTransceiver transceiver; RPCTransaction(final RPCSession session, final ByteString sessionId, final Type type, final GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread(type == WRITE ? "tx.write" : "tx.read")) { + try (ThreadTrace ignored = traceOnThread(type == WRITE ? "tx.write" : "tx.read")) { this.transceiver = RPCTransceiver.create(GraknGrpc.newStub(session.getChannel())); this.session = session; this.type = type; - this.concepts = new RPCConcepts(this.transceiver); + this.concepts = new Concepts(this); final TransactionProto.Transaction.Req openTxReq = TransactionProto.Transaction.Req.newBuilder() .putAllMetadata(tracingData()) @@ -88,6 +87,10 @@ public class RPCTransaction implements Transaction { } } + public RPCTransceiver transceiver() { + return transceiver; + } + @Override public Type type() { return type; @@ -105,21 +108,21 @@ public Database database() { @Override public QueryFuture> execute(GraqlDefine query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.define")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.define")) { return executeInternal(query, new GraknOptions()); } } @Override public QueryFuture> execute(GraqlUndefine query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.undefine")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.undefine")) { return executeInternal(query, new GraknOptions()); } } @Override public QueryFuture> execute(GraqlInsert query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.insert")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.insert")) { return executeInternal(query, options); } } @@ -131,7 +134,7 @@ public QueryFuture> execute(GraqlInsert query) { @Override public QueryFuture> execute(GraqlDelete query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.delete")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.delete")) { return executeInternal(query, options); } } @@ -143,7 +146,7 @@ public QueryFuture> execute(GraqlDelete query) { @Override public QueryFuture> execute(GraqlMatch query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.get")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.get")) { return executeInternal(query, options); } } @@ -155,21 +158,21 @@ public QueryFuture> execute(GraqlMatch query) { @Override public QueryFuture> stream(GraqlDefine query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.define")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.define")) { return streamInternal(query, new GraknOptions()); } } @Override public QueryFuture> stream(GraqlUndefine query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.undefine")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.undefine")) { return streamInternal(query, new GraknOptions()); } } @Override public QueryFuture> stream(GraqlInsert query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.insert")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.insert")) { return streamInternal(query, options); } } @@ -181,7 +184,7 @@ public QueryFuture> stream(GraqlInsert query) { @Override public QueryFuture> stream(GraqlDelete query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.delete")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.delete")) { return streamInternal(query, options); } } @@ -193,7 +196,7 @@ public QueryFuture> stream(GraqlDelete query) { @Override public QueryFuture> stream(GraqlMatch query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.get")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.get")) { return streamInternal(query, options); } } @@ -212,7 +215,7 @@ public QueryFuture> execute(GraqlMatch.Aggregate query) { @Override public QueryFuture> execute(GraqlMatch.Aggregate query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.get.aggregate")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.get.aggregate")) { return executeInternal(query, options); } } @@ -224,7 +227,7 @@ public QueryFuture> stream(GraqlMatch.Aggregate query) { @Override public QueryFuture> stream(GraqlMatch.Aggregate query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.get.aggregate")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.get.aggregate")) { return streamInternal(query, options); } } @@ -238,7 +241,7 @@ public QueryFuture>> execute(GraqlMatch.Group query @Override public QueryFuture>> execute(GraqlMatch.Group query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.get.group")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.get.group")) { return executeInternal(query, options); } } @@ -250,7 +253,7 @@ public QueryFuture>> stream(GraqlMatch.Group quer @Override public QueryFuture>> stream(GraqlMatch.Group query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.get.group")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.get.group")) { return streamInternal(query, options); } } @@ -264,7 +267,7 @@ public QueryFuture>> execute(GraqlMatch.Group.Aggregat @Override public QueryFuture>> execute(GraqlMatch.Group.Aggregate query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.get.group.aggregate")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.get.group.aggregate")) { return executeInternal(query, options); } } @@ -276,7 +279,7 @@ public QueryFuture>> stream(GraqlMatch.Group.Aggrega @Override public QueryFuture>> stream(GraqlMatch.Group.Aggregate query, GraknOptions options) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.get.group.aggregate")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.get.group.aggregate")) { return streamInternal(query, options); } } @@ -285,56 +288,56 @@ public QueryFuture>> stream(GraqlMatch.Group.Aggrega @Override public QueryFuture> execute(GraqlCompute.Statistics query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.compute.statistics")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.compute.statistics")) { return executeInternal(query); } } @Override public QueryFuture> stream(GraqlCompute.Statistics query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.compute.statistics")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.compute.statistics")) { return streamInternal(query); } } @Override public QueryFuture> execute(GraqlCompute.Path query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.compute.path")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.compute.path")) { return executeInternal(query); } } @Override public QueryFuture> stream(GraqlCompute.Path query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.compute.path")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.compute.path")) { return streamInternal(query); } } @Override public QueryFuture> execute(GraqlCompute.Centrality query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.compute.centrality")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.compute.centrality")) { return executeInternal(query); } } @Override public QueryFuture> stream(GraqlCompute.Centrality query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.compute.centrality")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.compute.centrality")) { return streamInternal(query); } } @Override public QueryFuture> execute(GraqlCompute.Cluster query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.execute.compute.cluster")) { + try (ThreadTrace ignored = traceOnThread("tx.execute.compute.cluster")) { return executeInternal(query); } } @Override public QueryFuture> stream(GraqlCompute.Cluster query) { - try (GrablTracingThreadStatic.ThreadTrace trace = traceOnThread("tx.stream.compute.cluster")) { + try (ThreadTrace ignored = traceOnThread("tx.stream.compute.cluster")) { return streamInternal(query); } } @@ -441,8 +444,8 @@ public QueryFuture> stream(GraqlQuery query, private RPCIterator getQueryIterator(final GraqlQuery query, final GraknOptions options) { final TransactionProto.Transaction.Iter.Req.Builder reqBuilder = TransactionProto.Transaction.Iter.Req.newBuilder() .setQueryIterReq(TransactionProto.Transaction.Query.Iter.Req.newBuilder() - .setQuery(query.toString()) - .setOptions(options(options))); + .setQuery(query.toString()) + .setOptions(options(options))); final TransactionProto.Transaction.Iter.Req iterReq = reqBuilder.build(); return new RPCIterator<>(transceiver, iterReq, response -> (T) Answer.of(this, response.getQueryIterRes().getAnswer())); diff --git a/rpc/RPCTransceiver.java b/rpc/RPCTransceiver.java index 0e71cf7b9d..99b8094f2e 100644 --- a/rpc/RPCTransceiver.java +++ b/rpc/RPCTransceiver.java @@ -45,20 +45,6 @@ import static grakn.protocol.TransactionProto.Transaction.Req; import static grakn.protocol.TransactionProto.Transaction.Res; -/** - * Wrapper making transaction calls to the Grakn RPC Server - handles sending a stream of Transaction.Req and - * receiving a stream of Transaction.Res. - * A request is sent with the #send(Transaction.Req)} method, and you can block for a response with the - * #receive() method. - * {@code - * try (GraknTransceiver tx = GraknTransceiver.create(stub) { - * tx.send(openMessage); - * Transaction.Res doneMessage = tx.receive().ok(); - * tx.send(commitMessage); - * StatusRuntimeException validationError = tx.receive.error(); - * } - * } - */ public class RPCTransceiver implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(RPCTransceiver.class); @@ -90,10 +76,6 @@ public Stream iterate(TransactionProto.Transaction.Iter.Req request, Func return StreamSupport.stream(((Iterable) () -> new RPCIterator<>(this, request, responseReader)).spliterator(), false); } - /** - * Send a request and return immediately. - * This method is non-blocking - it returns immediately. - */ private void send(final Req request, final ResponseCollector collector) { LOG.trace("send:{}", request); @@ -142,22 +124,10 @@ synchronized boolean isOpen() { return !responseListener.terminated; } - /** - * Interface for collecting responses from a specific request - */ interface ResponseCollector { - /** - * Collect a response. - * - * @param response the next response for this collector to collect. - * @return true if this is the last response, false if more responses are expected. - */ boolean onResponse(Response response); } - /** - * Simple response collector for when a single result is expected. - */ private static class SingleResponseCollector implements ResponseCollector { private volatile Response response; private final CountDownLatch latch = new CountDownLatch(1); @@ -175,11 +145,6 @@ public Res receive() throws InterruptedException { } } - /** - * Advanced abstract multi-response collector. The {@link #isLastResponse(Res)} method must be - * overridden in a sub-class because the last response must be known by the GRPC response receiving thread in order - * to keep it from blocking other collectors for later responses. - */ public static abstract class MultiResponseCollector implements ResponseCollector { private volatile boolean started; private final BlockingQueue received = new LinkedBlockingQueue<>(); @@ -210,19 +175,9 @@ public boolean isStarted() { return started; } - /** - * Implement to inform the GRPC thread when it has received the last response. - * This is called from the GRPC thread, not the main client thread. - * - * @param response The next response. - * @return true if this is the last response, false if more responses are expected. - */ protected abstract boolean isLastResponse(Res response); } - /** - * A StreamObserver that pushes received responses to the corresponding collector. - */ private static class ResponseListener implements StreamObserver { private volatile ResponseCollector currentCollector; @@ -283,10 +238,6 @@ public synchronized void onCompleted() { } } - /** - * A response from the gRPC server, that may be a successful response #ok(Transaction.Res), an error - * {#error(StatusRuntimeException)} or a "completed" message #completed(). - */ public static class Response { private final Res nullableOk; @@ -336,11 +287,6 @@ public final Type type() { } } - /** - * If this is a successful response, retrieve it. - * - * @throws GraknException if this is not a successful response - */ public final Res ok() { if (nullableOk != null) { return nullableOk; @@ -380,9 +326,6 @@ public int hashCode() { return h; } - /** - * Enum indicating the type of Response. - */ public enum Type { OK, ERROR, COMPLETED } diff --git a/test/behaviour/BUILD b/test/behaviour/BUILD index fb0409e344..fe95886d5c 100644 --- a/test/behaviour/BUILD +++ b/test/behaviour/BUILD @@ -1,16 +1,18 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # diff --git a/test/behaviour/concept/BUILD b/test/behaviour/concept/BUILD index fb0409e344..fe95886d5c 100644 --- a/test/behaviour/concept/BUILD +++ b/test/behaviour/concept/BUILD @@ -1,16 +1,18 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # diff --git a/test/behaviour/concept/thing/BUILD b/test/behaviour/concept/thing/BUILD index ad681edbf4..900826589a 100644 --- a/test/behaviour/concept/thing/BUILD +++ b/test/behaviour/concept/thing/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour/concept/thing:__subpackages__"]) @@ -40,7 +42,6 @@ java_library( checkstyle_test( name = "checkstyle", - targets = [ - ":steps", - ], + targets = [":steps"], + license_type = "apache", ) diff --git a/test/behaviour/concept/thing/ThingSteps.java b/test/behaviour/concept/thing/ThingSteps.java index 5e85f24a1a..d9a4a9d89f 100644 --- a/test/behaviour/concept/thing/ThingSteps.java +++ b/test/behaviour/concept/thing/ThingSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing; @@ -39,13 +40,13 @@ public class ThingSteps { - private static Map things = new HashMap<>(); + private static Map things = new HashMap<>(); - public static Thing.Remote get(String variable) { + public static Thing.Local get(String variable) { return things.get(variable); } - public static void put(String variable, Thing.Remote thing) { + public static void put(String variable, Thing.Local thing) { things.put(variable, thing); } @@ -55,159 +56,182 @@ public static void remove(String variable) { @Then("entity/attribute/relation {var} is null: {bool}") public void thing_is_null(String var, boolean isNull) { - if (isNull) { - assertNull(get(var)); - } else { - assertNotNull(get(var)); - } + if (isNull) assertNull(get(var)); + else assertNotNull(get(var)); } @Then("entity/attribute/relation {var} is deleted: {bool}") public void thing_is_deleted(String var, boolean isDeleted) { - assertEquals(isDeleted, get(var).isDeleted()); + assertEquals(isDeleted, get(var).asRemote(tx()).isDeleted()); } @Then("{root_label} {var} has type: {type_label}") public void thing_has_type(RootLabel rootLabel, String var, String typeLabel) { - ThingType.Remote type = get_thing_type(rootLabel, typeLabel); - assertEquals(type, get(var).getType()); + ThingType.Local type = get_thing_type(rootLabel, typeLabel); + assertEquals(type, get(var).asRemote(tx()).getType()); } @When("delete entity:/attribute:/relation: {var}") public void delete_thing(String var) { - get(var).delete(); + get(var).asRemote(tx()).delete(); } @When("entity/attribute/relation {var} set has: {var}") public void thing_set_has(String var1, String var2) { - get(var1).setHas(get(var2).asAttribute()); + get(var1).asRemote(tx()).setHas(get(var2).asAttribute()); } @Then("entity/attribute/relation {var} set has: {var}; throws exception") public void thing_set_has_throws_exception(String var1, String var2) { - assertThrows(() -> get(var1).setHas(get(var2).asAttribute())); + assertThrows(() -> get(var1).asRemote(tx()).setHas(get(var2).asAttribute())); } @When("entity/attribute/relation {var} unset has: {var}") public void thing_remove_has(String var1, String var2) { - get(var1).unsetHas(get(var2).asAttribute()); + get(var1).asRemote(tx()).unsetHas(get(var2).asAttribute()); } @Then("entity/attribute/relation {var} get keys contain: {var}") public void thing_get_keys_contain(String var1, String var2) { - assertTrue(get(var1).getHas(true).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas(true).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get keys do not contain: {var}") public void thing_get_keys_do_not_contain(String var1, String var2) { - assertTrue(get(var1).getHas(true).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas(true).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes contain: {var}") public void thing_get_attributes_contain(String var1, String var2) { - assertTrue(get(var1).getHas().anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas().anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) contain: {var}") public void thing_get_attributes_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel)).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel) + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?boolean ?) contain: {var}") public void thing_get_attributes_as_boolean_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asBoolean()).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asBoolean() + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?long ?) contain: {var}") public void thing_get_attributes_as_long_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asLong()).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asLong() + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?double ?) contain: {var}") public void thing_get_attributes_as_double_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asDouble()).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asDouble() + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?string ?) contain: {var}") public void thing_get_attributes_as_string_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asString()).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asString() + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?datetime ?) contain: {var}") public void thing_get_attributes_as_datetime_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asDateTime()).anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asDateTime() + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes do not contain: {var}") public void thing_get_attributes_do_not_contain(String var1, String var2) { - assertTrue(get(var1).getHas().noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas().noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) do not contain: {var}") public void thing_get_attributes_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel)).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel) + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?boolean ?) do not contain: {var}") public void thing_get_attributes_as_boolean_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asBoolean()).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asBoolean() + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?long ?) do not contain: {var}") public void thing_get_attributes_as_long_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asLong()).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asLong() + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?double ?) do not contain: {var}") public void thing_get_attributes_as_double_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asDouble()).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asDouble() + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?string ?) do not contain: {var}") public void thing_get_attributes_as_string_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asString()).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asString() + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get attributes\\( ?{type_label} ?) as\\( ?datetime ?) do not contain: {var}") public void thing_get_attributes_as_datetime_do_not_contain(String var1, String typeLabel, String var2) { - assertTrue(get(var1).getHas(tx().concepts().getAttributeType(typeLabel).asDateTime()).noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getHas( + tx().concepts().getAttributeType(typeLabel).asDateTime() + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get relations\\( ?{scoped_label} ?) contain: {var}") public void thing_get_relations_contain(String var1, ScopedLabel scopedLabel, String var2) { - assertTrue(get(var1).getRelations(tx().concepts().getRelationType(scopedLabel.scope()).getRelates(scopedLabel.role())) - .anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getRelations( + tx().concepts().getRelationType(scopedLabel.scope()).asRemote(tx()).getRelates(scopedLabel.role()) + ).anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get relations contain: {var}") public void thing_get_relations_contain(String var1, String var2) { - assertTrue(get(var1).getRelations().anyMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getRelations().anyMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get relations\\( ?{scoped_label} ?) do not contain: {var}") public void thing_get_relations_do_not_contain(String var1, ScopedLabel scopedLabel, String var2) { - assertTrue(get(var1).getRelations(tx().concepts().getRelationType(scopedLabel.scope()).getRelates(scopedLabel.role())) - .noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).getRelations( + tx().concepts().getRelationType(scopedLabel.scope()).asRemote(tx()).getRelates(scopedLabel.role()) + ).noneMatch(k -> k.equals(get(var2)))); } @Then("entity/attribute/relation {var} get relations do not contain: {var}") public void thing_get_relations_do_not_contain(String var1, String var2) { - assertTrue(get(var1).getRelations().noneMatch(k -> k.equals(get(var2)))); + assertTrue(get(var1).asRemote(tx()).asRemote(tx()).getRelations().noneMatch(k -> k.equals(get(var2)))); } @Then("root\\( ?thing ?) get instances count: {int}") public void root_thing_type_get_instances_contain(int count) { - assertEquals(count, tx().concepts().getRootType().getInstances().count()); + assertEquals(count, tx().concepts().getRootThingType().asRemote(tx()).getInstances().count()); } @Then("root\\( ?thing ?) get instances contain: {var}") public void root_thing_type_get_instances_contain(String var) { - assertTrue(tx().concepts().getRootType().getInstances().anyMatch(i -> i.equals(get(var)))); + assertTrue(tx().concepts().getRootThingType().asRemote(tx()).getInstances().anyMatch(i -> i.equals(get(var)))); } @Then("root\\( ?thing ?) get instances is empty") public void root_thing_type_get_instances_is_empty() { - assertEquals(0, tx().concepts().getRootType().getInstances().count()); + assertEquals(0, tx().concepts().getRootThingType().asRemote(tx()).getInstances().count()); } @After diff --git a/test/behaviour/concept/thing/attribute/AttributeSteps.java b/test/behaviour/concept/thing/attribute/AttributeSteps.java index 5ef502e6fe..82460ece32 100644 --- a/test/behaviour/concept/thing/attribute/AttributeSteps.java +++ b/test/behaviour/concept/thing/attribute/AttributeSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.attribute; @@ -35,97 +36,97 @@ public class AttributeSteps { @When("attribute\\( ?{type_label} ?) get instances contain: {var}") public void attribute_type_get_instances_contain(String typeLabel, String var) { - assertTrue(tx().concepts().getAttributeType(typeLabel).getInstances().anyMatch(i -> i.equals(get(var)))); + assertTrue(tx().concepts().getAttributeType(typeLabel).asRemote(tx()).getInstances().anyMatch(i -> i.equals(get(var)))); } @Then("attribute {var} get owners contain: {var}") public void attribute_get_owners_contain(String var1, String var2) { - assertTrue(get(var1).asAttribute().getOwners().anyMatch(o -> o.equals(get(var2)))); + assertTrue(get(var1).asAttribute().asRemote(tx()).getOwners().anyMatch(o -> o.equals(get(var2)))); } @Then("attribute {var} get owners do not contain: {var}") public void attribute_get_owners_do_not_contain(String var1, String var2) { - assertTrue(get(var1).asAttribute().getOwners().noneMatch(o -> o.equals(get(var2)))); + assertTrue(get(var1).asAttribute().asRemote(tx()).getOwners().noneMatch(o -> o.equals(get(var2)))); } @Then("attribute {var} has value type: {value_type}") public void attribute_has_value_type(String var, ValueType valueType) { - assertEquals(valueType, get(var).asAttribute().getType().getValueType()); + assertEquals(valueType, get(var).asAttribute().asRemote(tx()).getType().getValueType()); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?boolean ?) put: {bool}") public void attribute_type_as_boolean_put(String var, String typeLabel, boolean value) { - put(var, tx().concepts().getAttributeType(typeLabel).asBoolean().put(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asBoolean().asRemote(tx()).put(value)); } @Then("attribute\\( ?{type_label} ?) as\\( ?boolean ?) put: {bool}; throws exception") public void attribute_type_as_boolean_put_throws_exception(String typeLabel, boolean value) { - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asBoolean().put(value)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asBoolean().asRemote(tx()).put(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?long ?) put: {int}") public void attribute_type_as_long_put(String var, String typeLabel, long value) { - put(var, tx().concepts().getAttributeType(typeLabel).asLong().put(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asLong().asRemote(tx()).put(value)); } @Then("attribute\\( ?{type_label} ?) as\\( ?long ?) put: {int}; throws exception") public void attribute_type_as_long_put_throws_exception(String typeLabel, long value) { - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asLong().put(value)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asLong().asRemote(tx()).put(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?double ?) put: {double}") public void attribute_type_as_double_put(String var, String typeLabel, double value) { - put(var, tx().concepts().getAttributeType(typeLabel).asDouble().put(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asDouble().asRemote(tx()).put(value)); } @Then("attribute\\( ?{type_label} ?) as\\( ?double ?) put: {double}; throws exception") public void attribute_type_as_double_put_throws_exception(String typeLabel, double value) { - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asDouble().put(value)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asDouble().asRemote(tx()).put(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?string ?) put: {word}") public void attribute_type_as_string_put(String var, String typeLabel, String value) { - put(var, tx().concepts().getAttributeType(typeLabel).asString().put(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asString().asRemote(tx()).put(value)); } @Then("attribute\\( ?{type_label} ?) as\\( ?string ?) put: {word}; throws exception") public void attribute_type_as_string_put_throws_exception(String typeLabel, String value) { - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asString().put(value)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asString().asRemote(tx()).put(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?datetime ?) put: {datetime}") public void attribute_type_as_datetime_put(String var, String typeLabel, LocalDateTime value) { - put(var, tx().concepts().getAttributeType(typeLabel).asDateTime().put(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asDateTime().asRemote(tx()).put(value)); } @Then("attribute\\( ?{type_label} ?) as\\( ?datetime ?) put: {datetime}; throws exception") public void attribute_type_as_datetime_put_throws_exception(String typeLabel, LocalDateTime value) { - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asDateTime().put(value)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asDateTime().asRemote(tx()).put(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?boolean ?) get: {bool}") public void attribute_type_as_boolean_get(String var, String typeLabel, boolean value) { - put(var, tx().concepts().getAttributeType(typeLabel).asBoolean().get(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asBoolean().asRemote(tx()).get(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?long ?) get: {int}") public void attribute_type_as_long_get(String var, String typeLabel, long value) { - put(var, tx().concepts().getAttributeType(typeLabel).asLong().get(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asLong().asRemote(tx()).get(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?double ?) get: {double}") public void attribute_type_as_double_get(String var, String typeLabel, double value) { - put(var, tx().concepts().getAttributeType(typeLabel).asDouble().get(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asDouble().asRemote(tx()).get(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?string ?) get: {word}") public void attribute_type_as_string_get(String var, String typeLabel, String value) { - put(var, tx().concepts().getAttributeType(typeLabel).asString().get(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asString().asRemote(tx()).get(value)); } @When("{var} = attribute\\( ?{type_label} ?) as\\( ?datetime ?) get: {datetime}") public void attribute_type_as_datetime_get(String var, String typeLabel, LocalDateTime value) { - put(var, tx().concepts().getAttributeType(typeLabel).asDateTime().get(value)); + put(var, tx().concepts().getAttributeType(typeLabel).asDateTime().asRemote(tx()).get(value)); } @Then("attribute {var} has boolean value: {bool}") diff --git a/test/behaviour/concept/thing/attribute/AttributeTest.java b/test/behaviour/concept/thing/attribute/AttributeTest.java index 451e4d166a..23772c6247 100644 --- a/test/behaviour/concept/thing/attribute/AttributeTest.java +++ b/test/behaviour/concept/thing/attribute/AttributeTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.attribute; diff --git a/test/behaviour/concept/thing/attribute/BUILD b/test/behaviour/concept/thing/attribute/BUILD index d1de6c66c4..f518fe19b2 100644 --- a/test/behaviour/concept/thing/attribute/BUILD +++ b/test/behaviour/concept/thing/attribute/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -70,4 +72,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/thing/entity/BUILD b/test/behaviour/concept/thing/entity/BUILD index 780c5ef175..a2536e11da 100644 --- a/test/behaviour/concept/thing/entity/BUILD +++ b/test/behaviour/concept/thing/entity/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -71,4 +73,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/thing/entity/EntitySteps.java b/test/behaviour/concept/thing/entity/EntitySteps.java index 3a2d05648f..f6c2567131 100644 --- a/test/behaviour/concept/thing/entity/EntitySteps.java +++ b/test/behaviour/concept/thing/entity/EntitySteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.entity; @@ -36,66 +37,66 @@ public class EntitySteps { @When("{var} = entity\\( ?{type_label} ?) create new instance") public void entity_type_create_new_instance(String var, String typeLabel) { - put(var, tx().concepts().getEntityType(typeLabel).create()); + put(var, tx().concepts().getEntityType(typeLabel).asRemote(tx()).create()); } @When("entity\\( ?{type_label} ?) create new instance; throws exception") public void entity_type_create_new_instance_throws_exception(String typeLabel) { - assertThrows(() -> tx().concepts().getEntityType(typeLabel).create()); + assertThrows(() -> tx().concepts().getEntityType(typeLabel).asRemote(tx()).create()); } @When("{var} = entity\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {int}") public void entity_type_create_new_instance_with_key(String var, String type, String keyType, int keyValue) { - final Attribute.Long.Remote key = tx().concepts().getAttributeType(keyType).asLong().put(keyValue); - final Entity.Remote entity = tx().concepts().getEntityType(type).create(); - entity.setHas(key); + final Attribute.Long.Local key = tx().concepts().getAttributeType(keyType).asLong().asRemote(tx()).put(keyValue); + final Entity.Local entity = tx().concepts().getEntityType(type).asRemote(tx()).create(); + entity.asRemote(tx()).setHas(key); put(var, entity); } @When("{var} = entity\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {word}") public void entity_type_create_new_instance_with_key(String var, String type, String keyType, String keyValue) { - final Attribute.String.Remote key = tx().concepts().getAttributeType(keyType).asString().put(keyValue); - final Entity.Remote entity = tx().concepts().getEntityType(type).create(); - entity.setHas(key); + final Attribute.String.Local key = tx().concepts().getAttributeType(keyType).asString().asRemote(tx()).put(keyValue); + final Entity.Local entity = tx().concepts().getEntityType(type).asRemote(tx()).create(); + entity.asRemote(tx()).setHas(key); put(var, entity); } @When("{var} = entity\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {datetime}") public void entity_type_create_new_instance_with_key(String var, String type, String keyType, LocalDateTime keyValue) { - final Attribute.DateTime.Remote key = tx().concepts().getAttributeType(keyType).asDateTime().put(keyValue); - final Entity.Remote entity = tx().concepts().getEntityType(type).create(); - entity.setHas(key); + final Attribute.DateTime.Local key = tx().concepts().getAttributeType(keyType).asDateTime().asRemote(tx()).put(keyValue); + final Entity.Local entity = tx().concepts().getEntityType(type).asRemote(tx()).create(); + entity.asRemote(tx()).setHas(key); put(var, entity); } @When("{var} = entity\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {long}") public void entity_type_get_instance_with_key(String var1, String type, String keyType, long keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asLong().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getEntityType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asLong().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getEntityType(type))) .findFirst().orElse(null)); } @When("{var} = entity\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {word}") public void entity_type_get_instance_with_key(String var1, String type, String keyType, String keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asString().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getEntityType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asString().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getEntityType(type))) .findFirst().orElse(null)); } @When("{var} = entity\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {datetime}") public void entity_type_get_instance_with_key(String var1, String type, String keyType, LocalDateTime keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asDateTime().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getEntityType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asDateTime().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getEntityType(type))) .findFirst().orElse(null)); } @Then("entity\\( ?{type_label} ?) get instances contain: {var}") public void entity_type_get_instances_contain(String typeLabel, String var) { - assertTrue(tx().concepts().getEntityType(typeLabel).getInstances().anyMatch(i -> i.equals(get(var)))); + assertTrue(tx().concepts().getEntityType(typeLabel).asRemote(tx()).getInstances().anyMatch(i -> i.equals(get(var)))); } @Then("entity\\( ?{type_label} ?) get instances is empty") public void entity_type_get_instances_is_empty(String typeLabel) { - assertEquals(0, tx().concepts().getEntityType(typeLabel).getInstances().count()); + assertEquals(0, tx().concepts().getEntityType(typeLabel).asRemote(tx()).getInstances().count()); } } diff --git a/test/behaviour/concept/thing/entity/EntityTest.java b/test/behaviour/concept/thing/entity/EntityTest.java index c7a653e9f3..1ba39bbd75 100644 --- a/test/behaviour/concept/thing/entity/EntityTest.java +++ b/test/behaviour/concept/thing/entity/EntityTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.entity; diff --git a/test/behaviour/concept/thing/relation/BUILD b/test/behaviour/concept/thing/relation/BUILD index c17ab6ae45..96cf2f2fbe 100644 --- a/test/behaviour/concept/thing/relation/BUILD +++ b/test/behaviour/concept/thing/relation/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -73,4 +75,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/thing/relation/RelationSteps.java b/test/behaviour/concept/thing/relation/RelationSteps.java index 921e5a8be7..fc06931d97 100644 --- a/test/behaviour/concept/thing/relation/RelationSteps.java +++ b/test/behaviour/concept/thing/relation/RelationSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.relation; @@ -40,96 +41,96 @@ public class RelationSteps { @When("{var} = relation\\( ?{type_label} ?) create new instance") public void relation_type_create_new_instance(String var, String typeLabel) { - put(var, tx().concepts().getRelationType(typeLabel).create()); + put(var, tx().concepts().getRelationType(typeLabel).asRemote(tx()).create()); } @Then("relation\\( ?{type_label} ?) create new instance; throws exception") public void relation_type_create_new_instance_throws_exception(String typeLabel) { - assertThrows(() -> tx().concepts().getRelationType(typeLabel).create()); + assertThrows(() -> tx().concepts().getRelationType(typeLabel).asRemote(tx()).create()); } @When("{var} = relation\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {int}") public void relation_type_create_new_instance_with_key(String var, String type, String keyType, int keyValue) { - Attribute.Long.Remote key = tx().concepts().getAttributeType(keyType).asLong().put(keyValue); - final Relation.Remote relation = tx().concepts().getRelationType(type).create(); - relation.setHas(key); + Attribute.Long.Local key = tx().concepts().getAttributeType(keyType).asLong().asRemote(tx()).put(keyValue); + final Relation.Local relation = tx().concepts().getRelationType(type).asRemote(tx()).create(); + relation.asRemote(tx()).setHas(key); put(var, relation); } @When("{var} = relation\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {word}") public void relation_type_create_new_instance_with_key(String var, String type, String keyType, String keyValue) { - Attribute.String.Remote key = tx().concepts().getAttributeType(keyType).asString().put(keyValue); - final Relation.Remote relation = tx().concepts().getRelationType(type).create(); - relation.setHas(key); + Attribute.String.Local key = tx().concepts().getAttributeType(keyType).asString().asRemote(tx()).put(keyValue); + final Relation.Local relation = tx().concepts().getRelationType(type).asRemote(tx()).create(); + relation.asRemote(tx()).setHas(key); put(var, relation); } @When("{var} = relation\\( ?{type_label} ?) create new instance with key\\( ?{type_label} ?): {datetime}") public void relation_type_create_new_instance_with_key(String var, String type, String keyType, LocalDateTime keyValue) { - Attribute.DateTime.Remote key = tx().concepts().getAttributeType(keyType).asDateTime().put(keyValue); - final Relation.Remote relation = tx().concepts().getRelationType(type).create(); - relation.setHas(key); + Attribute.DateTime.Local key = tx().concepts().getAttributeType(keyType).asDateTime().asRemote(tx()).put(keyValue); + final Relation.Local relation = tx().concepts().getRelationType(type).asRemote(tx()).create(); + relation.asRemote(tx()).setHas(key); put(var, relation); } @When("{var} = relation\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {long}") public void relation_type_get_instance_with_key(String var1, String type, String keyType, long keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asLong().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getRelationType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asLong().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getRelationType(type))) .findFirst().orElse(null)); } @When("{var} = relation\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {word}") public void relation_type_get_instance_with_key(String var1, String type, String keyType, String keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asString().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getRelationType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asString().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getRelationType(type))) .findFirst().orElse(null)); } @When("{var} = relation\\( ?{type_label} ?) get instance with key\\( ?{type_label} ?): {datetime}") public void relation_type_get_instance_with_key(String var1, String type, String keyType, LocalDateTime keyValue) { - put(var1, tx().concepts().getAttributeType(keyType).asDateTime().get(keyValue).getOwners() - .filter(owner -> owner.getType().equals(tx().concepts().getRelationType(type))) + put(var1, tx().concepts().getAttributeType(keyType).asDateTime().asRemote(tx()).get(keyValue).asRemote(tx()).getOwners() + .filter(owner -> owner.asRemote(tx()).getType().equals(tx().concepts().getRelationType(type))) .findFirst().orElse(null)); } @Then("relation\\( ?{type_label} ?) get instances contain: {var}") public void relation_type_get_instances_contain(String typeLabel, String var) { - assertTrue(tx().concepts().getRelationType(typeLabel).getInstances().anyMatch(i -> i.equals(get(var)))); + assertTrue(tx().concepts().getRelationType(typeLabel).asRemote(tx()).getInstances().anyMatch(i -> i.equals(get(var)))); } @Then("relation\\( ?{type_label} ?) get instances do not contain: {var}") public void relation_type_get_instances_do_not_contain(String typeLabel, String var) { - assertTrue(tx().concepts().getRelationType(typeLabel).getInstances().noneMatch(i -> i.equals(get(var)))); + assertTrue(tx().concepts().getRelationType(typeLabel).asRemote(tx()).getInstances().noneMatch(i -> i.equals(get(var)))); } @Then("relation\\( ?{type_label} ?) get instances is empty") public void relation_type_get_instances_is_empty(String typeLabel) { - assertEquals(0, tx().concepts().getRelationType(typeLabel).getInstances().count()); + assertEquals(0, tx().concepts().getRelationType(typeLabel).asRemote(tx()).getInstances().count()); } @When("relation {var} add player for role\\( ?{type_label} ?): {var}") public void relation_add_player_for_role(String var1, String roleTypeLabel, String var2) { - get(var1).asRelation().addPlayer(get(var1).asRelation().getType().getRelates(roleTypeLabel), get(var2)); + get(var1).asRelation().asRemote(tx()).addPlayer(get(var1).asRelation().asRemote(tx()).getType().asRemote(tx()).getRelates(roleTypeLabel), get(var2)); } @When("relation {var} remove player for role\\( ?{type_label} ?): {var}") public void relation_remove_player_for_role(String var1, String roleTypeLabel, String var2) { - get(var1).asRelation().removePlayer(get(var1).asRelation().getType().getRelates(roleTypeLabel), get(var2)); + get(var1).asRelation().asRemote(tx()).removePlayer(get(var1).asRelation().asRemote(tx()).getType().asRemote(tx()).getRelates(roleTypeLabel), get(var2)); } @Then("relation {var} get players contain:") public void relation_get_players_contain(String var, Map players) { - Relation.Remote relation = get(var).asRelation(); - players.forEach((rt, var2) -> assertTrue(relation.getPlayersByRoleType().get(relation.getType().getRelates(rt)).contains(get(var2.substring(1))))); + Relation.Local relation = get(var).asRelation(); + players.forEach((rt, var2) -> assertTrue(relation.asRemote(tx()).getPlayersByRoleType().get(relation.asRemote(tx()).getType().asRemote(tx()).getRelates(rt)).contains(get(var2.substring(1))))); } @Then("relation {var} get players do not contain:") public void relation_get_players_do_not_contain(String var, Map players) { - Relation.Remote relation = get(var).asRelation(); + Relation.Local relation = get(var).asRelation(); players.forEach((rt, var2) -> { - List p; - if ((p = relation.getPlayersByRoleType().get(relation.getType().getRelates(rt))) != null) { + List p; + if ((p = relation.asRemote(tx()).getPlayersByRoleType().get(relation.asRemote(tx()).getType().asRemote(tx()).getRelates(rt))) != null) { assertFalse(p.contains(get(var2.substring(1)))); } }); @@ -137,25 +138,25 @@ public void relation_get_players_do_not_contain(String var, Map @Then("relation {var} get players contain: {var}") public void relation_get_players_contain(String var1, String var2) { - assertTrue(get(var1).asRelation().getPlayers().anyMatch(p -> p.equals(get(var2)))); + assertTrue(get(var1).asRelation().asRemote(tx()).getPlayers().anyMatch(p -> p.equals(get(var2)))); } @Then("relation {var} get players do not contain: {var}") public void relation_get_players_do_not_contain(String var1, String var2) { - assertTrue(get(var1).asRelation().getPlayers().noneMatch(p -> p.equals(get(var2)))); + assertTrue(get(var1).asRelation().asRemote(tx()).getPlayers().noneMatch(p -> p.equals(get(var2)))); } @Then("relation {var} get players for role\\( ?{type_label} ?) contain: {var}") public void relation_get_player_for_role_contain(String var1, String roleTypeLabel, String var2) { - assertTrue(get(var1).asRelation() - .getPlayers(get(var1).asRelation().getType().getRelates(roleTypeLabel)) + assertTrue(get(var1).asRelation().asRemote(tx()) + .getPlayers(get(var1).asRelation().asRemote(tx()).getType().asRemote(tx()).getRelates(roleTypeLabel)) .anyMatch(p -> p.equals(get(var2)))); } @Then("relation {var} get players for role\\( ?{type_label} ?) do not contain: {var}") public void relation_get_player_for_role_do_not_contain(String var1, String roleTypeLabel, String var2) { - assertTrue(get(var1).asRelation() - .getPlayers(get(var1).asRelation().getType().getRelates(roleTypeLabel)) + assertTrue(get(var1).asRelation().asRemote(tx()) + .getPlayers(get(var1).asRelation().asRemote(tx()).getType().asRemote(tx()).getRelates(roleTypeLabel)) .noneMatch(p -> p.equals(get(var2)))); } } diff --git a/test/behaviour/concept/thing/relation/RelationTest.java b/test/behaviour/concept/thing/relation/RelationTest.java index 929c562e7a..4f3f288358 100644 --- a/test/behaviour/concept/thing/relation/RelationTest.java +++ b/test/behaviour/concept/thing/relation/RelationTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.thing.relation; diff --git a/test/behaviour/concept/type/attributetype/AttributeTypeSteps.java b/test/behaviour/concept/type/attributetype/AttributeTypeSteps.java index b997289779..0502b03ed6 100644 --- a/test/behaviour/concept/type/attributetype/AttributeTypeSteps.java +++ b/test/behaviour/concept/type/attributetype/AttributeTypeSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.attributetype; @@ -37,9 +38,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -/** - * Behaviour Steps specific to AttributeTypeSteps - */ public class AttributeTypeSteps { @When("put attribute type: {type_label}, with value type: {value_type}") @@ -54,12 +52,12 @@ public void attribute_type_get_value_type(String typeLabel, ValueType valueType) @Then("attribute\\( ?{type_label} ?) get supertype value type: {value_type}") public void attribute_type_get_supertype_value_type(String typeLabel, ValueType valueType) { - Type.Remote supertype = tx().concepts().getAttributeType(typeLabel).getSupertype(); + Type.Local supertype = tx().concepts().getAttributeType(typeLabel).asRemote(tx()).getSupertype(); assertEquals(valueType, supertype.asAttributeType().getValueType()); } - private AttributeType.Remote attribute_type_as_value_type(String typeLabel, ValueType valueType) { - final AttributeType.Remote attributeType = tx().concepts().getAttributeType(typeLabel); + private AttributeType.Local attribute_type_as_value_type(String typeLabel, ValueType valueType) { + final AttributeType.Local attributeType = tx().concepts().getAttributeType(typeLabel); switch (valueType) { case OBJECT: return attributeType; @@ -80,15 +78,15 @@ private AttributeType.Remote attribute_type_as_value_type(String typeLabel, Valu @Then("attribute\\( ?{type_label} ?) as\\( ?{value_type} ?) get subtypes contain:") public void attribute_type_as_value_type_get_subtypes_contain(String typeLabel, ValueType valueType, List subLabels) { - AttributeType.Remote attributeType = attribute_type_as_value_type(typeLabel, valueType); - Set actuals = attributeType.getSubtypes().map(ThingType::getLabel).collect(toSet()); + AttributeType.Local attributeType = attribute_type_as_value_type(typeLabel, valueType); + Set actuals = attributeType.asRemote(tx()).getSubtypes().map(ThingType::getLabel).collect(toSet()); assertTrue(actuals.containsAll(subLabels)); } @Then("attribute\\( ?{type_label} ?) as\\( ?{value_type} ?) get subtypes do not contain:") public void attribute_type_as_value_type_get_subtypes_do_not_contain(String typeLabel, ValueType valueType, List subLabels) { - AttributeType.Remote attributeType = attribute_type_as_value_type(typeLabel, valueType); - Set actuals = attributeType.getSubtypes().map(ThingType::getLabel).collect(toSet()); + AttributeType.Local attributeType = attribute_type_as_value_type(typeLabel, valueType); + Set actuals = attributeType.asRemote(tx()).getSubtypes().map(ThingType::getLabel).collect(toSet()); for (String subLabel : subLabels) { assertFalse(actuals.contains(subLabel)); } @@ -97,28 +95,28 @@ public void attribute_type_as_value_type_get_subtypes_do_not_contain(String type @Then("attribute\\( ?{type_label} ?) as\\( ?{value_type} ?) set regex: {}") public void attribute_type_as_value_type_set_regex(String typeLabel, ValueType valueType, String regex) { if (!valueType.equals(ValueType.STRING)) fail(); - AttributeType.Remote attributeType = attribute_type_as_value_type(typeLabel, valueType); - attributeType.asString().setRegex(regex); + AttributeType.Local attributeType = attribute_type_as_value_type(typeLabel, valueType); + attributeType.asString().asRemote(tx()).setRegex(regex); } @Then("attribute\\( ?{type_label} ?) as\\( ?{value_type} ?) get regex: {}") public void attribute_type_as_value_type_get_regex(String typeLabel, ValueType valueType, String regex) { if (!valueType.equals(ValueType.STRING)) fail(); - AttributeType.Remote attributeType = attribute_type_as_value_type(typeLabel, valueType); - assertEquals(regex, attributeType.asString().getRegex()); + AttributeType.Local attributeType = attribute_type_as_value_type(typeLabel, valueType); + assertEquals(regex, attributeType.asString().asRemote(tx()).getRegex()); } @Then("attribute\\( ?{type_label} ?) get key owners contain:") public void attribute_type_get_owners_as_key_contains(final String typeLabel, final List ownerLabels) { - final AttributeType.Remote attributeType = tx().concepts().getAttributeType(typeLabel); - final Set actuals = attributeType.getOwners(true).map(ThingType::getLabel).collect(toSet()); + final AttributeType.Local attributeType = tx().concepts().getAttributeType(typeLabel); + final Set actuals = attributeType.asRemote(tx()).getOwners(true).map(ThingType::getLabel).collect(toSet()); assertTrue(actuals.containsAll(ownerLabels)); } @Then("attribute\\( ?{type_label} ?) get key owners do not contain:") public void attribute_type_get_owners_as_key_do_not_contains(final String typeLabel, final List ownerLabels) { - final AttributeType.Remote attributeType = tx().concepts().getAttributeType(typeLabel); - final Set actuals = attributeType.getOwners(true).map(ThingType::getLabel).collect(toSet()); + final AttributeType.Local attributeType = tx().concepts().getAttributeType(typeLabel); + final Set actuals = attributeType.asRemote(tx()).getOwners(true).map(ThingType::getLabel).collect(toSet()); for (String ownerLabel : ownerLabels) { assertFalse(actuals.contains(ownerLabel)); } @@ -126,15 +124,15 @@ public void attribute_type_get_owners_as_key_do_not_contains(final String typeLa @Then("attribute\\( ?{type_label} ?) get attribute owners contain:") public void attribute_type_get_owners_as_attribute_contains(final String typeLabel, final List ownerLabels) { - final AttributeType.Remote attributeType = tx().concepts().getAttributeType(typeLabel); - final Set actuals = attributeType.getOwners(false).map(ThingType::getLabel).collect(toSet()); + final AttributeType.Local attributeType = tx().concepts().getAttributeType(typeLabel); + final Set actuals = attributeType.asRemote(tx()).getOwners(false).map(ThingType::getLabel).collect(toSet()); assertTrue(actuals.containsAll(ownerLabels)); } @Then("attribute\\( ?{type_label} ?) get attribute owners do not contain:") public void attribute_type_get_owners_as_attribute_do_not_contains(final String typeLabel, final List ownerLabels) { - final AttributeType.Remote attributeType = tx().concepts().getAttributeType(typeLabel); - final Set actuals = attributeType.getOwners(false).map(ThingType::getLabel).collect(toSet()); + final AttributeType.Local attributeType = tx().concepts().getAttributeType(typeLabel); + final Set actuals = attributeType.asRemote(tx()).getOwners(false).map(ThingType::getLabel).collect(toSet()); for (String ownerLabel : ownerLabels) { assertFalse(actuals.contains(ownerLabel)); } diff --git a/test/behaviour/concept/type/attributetype/AttributeTypeTest.java b/test/behaviour/concept/type/attributetype/AttributeTypeTest.java index 3ddbae8e9c..1ae843fe17 100644 --- a/test/behaviour/concept/type/attributetype/AttributeTypeTest.java +++ b/test/behaviour/concept/type/attributetype/AttributeTypeTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.attributetype; diff --git a/test/behaviour/concept/type/attributetype/BUILD b/test/behaviour/concept/type/attributetype/BUILD index 3067d654cd..de77bf5f75 100644 --- a/test/behaviour/concept/type/attributetype/BUILD +++ b/test/behaviour/concept/type/attributetype/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -68,4 +70,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/type/entitytype/BUILD b/test/behaviour/concept/type/entitytype/BUILD index 4d476a37f4..37d8014cb2 100644 --- a/test/behaviour/concept/type/entitytype/BUILD +++ b/test/behaviour/concept/type/entitytype/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -63,4 +65,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/type/entitytype/EntityTypeSteps.java b/test/behaviour/concept/type/entitytype/EntityTypeSteps.java index 1ae1cd8b76..a3a056cf3b 100644 --- a/test/behaviour/concept/type/entitytype/EntityTypeSteps.java +++ b/test/behaviour/concept/type/entitytype/EntityTypeSteps.java @@ -1,24 +1,22 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.entitytype; -/** - * Behaviour Steps specific to EntityTypes - */ public class EntityTypeSteps {} diff --git a/test/behaviour/concept/type/entitytype/EntityTypeTest.java b/test/behaviour/concept/type/entitytype/EntityTypeTest.java index 8c02aa2821..af52e8c7ab 100644 --- a/test/behaviour/concept/type/entitytype/EntityTypeTest.java +++ b/test/behaviour/concept/type/entitytype/EntityTypeTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.entitytype; diff --git a/test/behaviour/concept/type/relationtype/BUILD b/test/behaviour/concept/type/relationtype/BUILD index b0ebd8cfb7..fd5d0e8da4 100644 --- a/test/behaviour/concept/type/relationtype/BUILD +++ b/test/behaviour/concept/type/relationtype/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -72,4 +74,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/type/relationtype/RelationTypeSteps.java b/test/behaviour/concept/type/relationtype/RelationTypeSteps.java index 1fcb424011..0dfb7aee1d 100644 --- a/test/behaviour/concept/type/relationtype/RelationTypeSteps.java +++ b/test/behaviour/concept/type/relationtype/RelationTypeSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.relationtype; @@ -35,66 +36,61 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -/** - * Behaviour Steps specific to RelationTypes - */ public class RelationTypeSteps { @When("relation\\( ?{type_label} ?) set relates role: {type_label}") public void relation_type_set_relates_role(String relationLabel, String roleLabel) { - tx().concepts().getRelationType(relationLabel).setRelates(roleLabel); + tx().concepts().getRelationType(relationLabel).asRemote(tx()).setRelates(roleLabel); } @When("relation\\( ?{type_label} ?) set relates role: {type_label}; throws exception") public void thing_set_relates_role_throws_exception(String relationLabel, String roleLabel) { - assertThrows(() -> tx().concepts().getRelationType(relationLabel).setRelates(roleLabel)); + assertThrows(() -> tx().concepts().getRelationType(relationLabel).asRemote(tx()).setRelates(roleLabel)); } @When("relation\\( ?{type_label} ?) unset related role: {type_label}") public void relation_type_unset_related_role(String relationLabel, String roleLabel) { - tx().concepts().getRelationType(relationLabel).unsetRelates(roleLabel); + tx().concepts().getRelationType(relationLabel).asRemote(tx()).unsetRelates(roleLabel); } @When("relation\\( ?{type_label} ?) set relates role: {type_label} as {type_label}") public void relation_type_set_relates_role_type_as(String relationLabel, String roleLabel, String superRole) { - tx().concepts().getRelationType(relationLabel).setRelates(roleLabel, superRole); - tx().concepts().getRelationType(relationLabel).setRelates(roleLabel); + tx().concepts().getRelationType(relationLabel).asRemote(tx()).setRelates(roleLabel, superRole); } @When("relation\\( ?{type_label} ?) set relates role: {type_label} as {type_label}; throws exception") public void thing_set_relates_role_type_as_throws_exception(String relationLabel, String roleLabel, String superRole) { - assertThrows(() -> tx().concepts().getRelationType(relationLabel).setRelates(roleLabel, superRole)); + assertThrows(() -> tx().concepts().getRelationType(relationLabel).asRemote(tx()).setRelates(roleLabel, superRole)); } @When("relation\\( ?{type_label} ?) remove related role: {type_label}") public void relation_type_remove_related_role(String relationLabel, String roleLabel) { - tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).delete(); + tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).delete(); } @Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) is null: {bool}") public void relation_type_get_role_type_is_null(String relationLabel, String roleLabel, boolean isNull) { - assertEquals(isNull, isNull(tx().concepts().getRelationType(relationLabel).getRelates(roleLabel))); + assertEquals(isNull, isNull(tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel))); } @When("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) set label: {type_label}") public void relation_type_get_role_type_set_label(String relationLabel, String roleLabel, String newLabel) { - tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).setLabel(newLabel); + tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).setLabel(newLabel); } @When("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get label: {type_label}") public void relation_type_get_role_type_get_label(String relationLabel, String roleLabel, String getLabel) { - assertEquals(getLabel, tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getLabel()); + assertEquals(getLabel, tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).getLabel()); } @When("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) is abstract: {bool}") public void relation_type_get_role_type_is_abstract(String relationLabel, String roleLabel, boolean isAbstract) { - assertEquals(isAbstract, tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).isAbstract()); + assertEquals(isAbstract, tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).isAbstract()); } private Set relation_type_get_related_roles_actuals(String relationLabel) { - return tx().concepts().getRelationType(relationLabel).getRelates() - .map(role -> new Parameters.ScopedLabel(role.getScopedLabel().split(":")[0], - role.getScopedLabel().split(":")[1])).collect(toSet()); + return tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates() + .map(role -> new Parameters.ScopedLabel(role.getScope(), role.getLabel())).collect(toSet()); } @Then("relation\\( ?{type_label} ?) get related roles contain:") @@ -113,14 +109,13 @@ public void relation_type_get_related_roles_do_not_contain(String relationLabel, @Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get supertype: {scoped_label}") public void relation_type_get_role_type_get_supertype(String relationLabel, String roleLabel, Parameters.ScopedLabel superLabel) { - RoleType superType = tx().concepts().getRelationType(superLabel.scope()).getRelates(superLabel.role()); - assertEquals(superType, tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getSupertype()); + RoleType superType = tx().concepts().getRelationType(superLabel.scope()).asRemote(tx()).getRelates(superLabel.role()); + assertEquals(superType, tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).getSupertype()); } private Set relation_type_get_role_type_supertypes_actuals(String relationLabel, String roleLabel) { - return tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getSupertypes() - .map(role -> new Parameters.ScopedLabel(role.getScopedLabel().split(":")[0], - role.getScopedLabel().split(":")[1])).collect(toSet()); + return tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).getSupertypes() + .map(role -> new Parameters.ScopedLabel(role.getScope(), role.getLabel())).collect(toSet()); } @Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get supertypes contain:") @@ -138,7 +133,7 @@ public void relation_type_get_role_type_get_supertypes_do_not_contain(String rel } private Set relation_type_get_role_type_players_actuals(String relationLabel, String roleLabel) { - return tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getPlayers().map(Type::getLabel).collect(toSet()); + return tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).getPlayers().map(Type::getLabel).collect(toSet()); } @Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get players contain:") @@ -156,9 +151,8 @@ public void relation_type_get_role_type_get_plays_do_not_contain(String relation } private Set relation_type_get_role_type_subtypes_actuals(String relationLabel, String roleLabel) { - return tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getSubtypes() - .map(role -> new Parameters.ScopedLabel(role.getScopedLabel().split(":")[0], - role.getScopedLabel().split(":")[1])).collect(toSet()); + return tx().concepts().getRelationType(relationLabel).asRemote(tx()).getRelates(roleLabel).asRemote(tx()).getSubtypes() + .map(role -> new Parameters.ScopedLabel(role.getScope(), role.getLabel())).collect(toSet()); } @Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get subtypes contain:") diff --git a/test/behaviour/concept/type/relationtype/RelationTypeTest.java b/test/behaviour/concept/type/relationtype/RelationTypeTest.java index da9e9e7458..123e08228f 100644 --- a/test/behaviour/concept/type/relationtype/RelationTypeTest.java +++ b/test/behaviour/concept/type/relationtype/RelationTypeTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.relationtype; diff --git a/test/behaviour/concept/type/thingtype/BUILD b/test/behaviour/concept/type/thingtype/BUILD index 7689d0873b..257511381c 100644 --- a/test/behaviour/concept/type/thingtype/BUILD +++ b/test/behaviour/concept/type/thingtype/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -73,4 +75,5 @@ checkstyle_test( ":steps", ":test", ], + license_type = "apache", ) diff --git a/test/behaviour/concept/type/thingtype/ThingTypeSteps.java b/test/behaviour/concept/type/thingtype/ThingTypeSteps.java index f099976095..81e37e8cc2 100644 --- a/test/behaviour/concept/type/thingtype/ThingTypeSteps.java +++ b/test/behaviour/concept/type/thingtype/ThingTypeSteps.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.thingtype; @@ -40,14 +41,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -/** - * Behaviour Steps generic to all ThingTypes - */ public class ThingTypeSteps { private static final String UNRECOGNISED_VALUE = "Unrecognized value"; - public static ThingType.Remote get_thing_type(RootLabel rootLabel, String typeLabel) { + public static ThingType.Local get_thing_type(RootLabel rootLabel, String typeLabel) { switch (rootLabel) { case ENTITY: return tx().concepts().getEntityType(typeLabel); @@ -62,13 +60,13 @@ public static ThingType.Remote get_thing_type(RootLabel rootLabel, String typeLa @Then("thing type root get supertypes contain:") public void thing_type_root_get_supertypes_contain(List superLabels) { - Set actuals = tx().concepts().getRootType().getSupertypes().map(ThingType::getLabel).collect(toSet()); + Set actuals = tx().concepts().getRootThingType().asRemote(tx()).asRemote(tx()).getSupertypes().map(ThingType::getLabel).collect(toSet()); assertTrue(actuals.containsAll(superLabels)); } @Then("thing type root get supertypes do not contain:") public void thing_type_root_get_supertypes_do_not_contain(List superLabels) { - Set actuals = tx().concepts().getRootType().getSupertypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = tx().concepts().getRootThingType().asRemote(tx()).asRemote(tx()).getSupertypes().map(Type.Local::getLabel).collect(toSet()); for (String superLabel : superLabels) { assertFalse(actuals.contains(superLabel)); } @@ -76,13 +74,13 @@ public void thing_type_root_get_supertypes_do_not_contain(List superLabe @Then("thing type root get subtypes contain:") public void thing_type_root_get_subtypes_contain(List subLabels) { - Set actuals = tx().concepts().getRootType().getSubtypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = tx().concepts().getRootThingType().asRemote(tx()).getSubtypes().map(Type.Local::getLabel).collect(toSet()); assertTrue(actuals.containsAll(subLabels)); } @Then("thing type root get subtypes do not contain:") public void thing_type_root_get_subtypes_do_not_contain(List subLabels) { - Set actuals = tx().concepts().getRootType().getSubtypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = tx().concepts().getRootThingType().asRemote(tx()).getSubtypes().map(Type.Local::getLabel).collect(toSet()); for (String subLabel : subLabels) { assertFalse(actuals.contains(subLabel)); } @@ -104,12 +102,12 @@ public void put_thing_type(RootLabel rootLabel, String typeLabel) { @When("delete {root_label} type: {type_label}") public void delete_thing_type(RootLabel rootLabel, String typeLabel) { - get_thing_type(rootLabel, typeLabel).delete(); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).delete(); } @Then("delete {root_label} type: {type_label}; throws exception") public void delete_thing_type_throws_exception(RootLabel rootLabel, String typeLabel) { - assertThrows(() -> get_thing_type(rootLabel, typeLabel).delete()); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).delete()); } @Then("{root_label}\\( ?{type_label} ?) is null: {bool}") @@ -119,7 +117,7 @@ public void thing_type_is_null(RootLabel rootLabel, String typeLabel, boolean is @When("{root_label}\\( ?{type_label} ?) set label: {type_label}") public void thing_type_set_label(RootLabel rootLabel, String typeLabel, String newLabel) { - get_thing_type(rootLabel, typeLabel).setLabel(newLabel); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setLabel(newLabel); } @Then("{root_label}\\( ?{type_label} ?) get label: {type_label}") @@ -129,17 +127,17 @@ public void thing_type_get_label(RootLabel rootLabel, String typeLabel, String g @When("{root_label}\\( ?{type_label} ?) set abstract: {bool}") public void thing_type_set_abstract(RootLabel rootLabel, String typeLabel, boolean isAbstract) { - final ThingType.Remote thingType = get_thing_type(rootLabel, typeLabel); + final ThingType.Local thingType = get_thing_type(rootLabel, typeLabel); if (isAbstract) { - thingType.setAbstract(); + thingType.asRemote(tx()).setAbstract(); } else { - thingType.unsetAbstract(); + thingType.asRemote(tx()).unsetAbstract(); } } @Then("{root_label}\\( ?{type_label} ?) is abstract: {bool}") public void thing_type_is_abstract(RootLabel rootLabel, String typeLabel, boolean isAbstract) { - assertEquals(isAbstract, get_thing_type(rootLabel, typeLabel).isAbstract()); + assertEquals(isAbstract, get_thing_type(rootLabel, typeLabel).asRemote(tx()).isAbstract()); } @When("{root_label}\\( ?{type_label} ?) set supertype: {type_label}") @@ -147,15 +145,15 @@ public void thing_type_set_supertype(RootLabel rootLabel, String typeLabel, Stri switch (rootLabel) { case ENTITY: EntityType entitySuperType = tx().concepts().getEntityType(superLabel); - tx().concepts().getEntityType(typeLabel).setSupertype(entitySuperType); + tx().concepts().getEntityType(typeLabel).asRemote(tx()).setSupertype(entitySuperType); break; case ATTRIBUTE: AttributeType attributeSuperType = tx().concepts().getAttributeType(superLabel); - tx().concepts().getAttributeType(typeLabel).setSupertype(attributeSuperType); + tx().concepts().getAttributeType(typeLabel).asRemote(tx()).setSupertype(attributeSuperType); break; case RELATION: RelationType relationSuperType = tx().concepts().getRelationType(superLabel); - tx().concepts().getRelationType(typeLabel).setSupertype(relationSuperType); + tx().concepts().getRelationType(typeLabel).asRemote(tx()).setSupertype(relationSuperType); break; } } @@ -165,15 +163,15 @@ public void thing_type_set_supertype_throws_exception(RootLabel rootLabel, Strin switch (rootLabel) { case ENTITY: EntityType entitySuperType = tx().concepts().getEntityType(superLabel); - assertThrows(() -> tx().concepts().getEntityType(typeLabel).setSupertype(entitySuperType)); + assertThrows(() -> tx().concepts().getEntityType(typeLabel).asRemote(tx()).setSupertype(entitySuperType)); break; case ATTRIBUTE: AttributeType attributeSuperType = tx().concepts().getAttributeType(superLabel); - assertThrows(() -> tx().concepts().getAttributeType(typeLabel).setSupertype(attributeSuperType)); + assertThrows(() -> tx().concepts().getAttributeType(typeLabel).asRemote(tx()).setSupertype(attributeSuperType)); break; case RELATION: RelationType relationSuperType = tx().concepts().getRelationType(superLabel); - assertThrows(() -> tx().concepts().getRelationType(typeLabel).setSupertype(relationSuperType)); + assertThrows(() -> tx().concepts().getRelationType(typeLabel).asRemote(tx()).setSupertype(relationSuperType)); break; } } @@ -181,18 +179,18 @@ public void thing_type_set_supertype_throws_exception(RootLabel rootLabel, Strin @Then("{root_label}\\( ?{type_label} ?) get supertype: {type_label}") public void thing_type_get_supertype(RootLabel rootLabel, String typeLabel, String superLabel) { ThingType supertype = get_thing_type(rootLabel, superLabel); - assertEquals(supertype, get_thing_type(rootLabel, typeLabel).getSupertype()); + assertEquals(supertype, get_thing_type(rootLabel, typeLabel).asRemote(tx()).getSupertype()); } @Then("{root_label}\\( ?{type_label} ?) get supertypes contain:") public void thing_type_get_supertypes_contain(RootLabel rootLabel, String typeLabel, List superLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getSupertypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).asRemote(tx()).getSupertypes().map(Type.Local::getLabel).collect(toSet()); assertTrue(actuals.containsAll(superLabels)); } @Then("{root_label}\\( ?{type_label} ?) get supertypes do not contain:") public void thing_type_get_supertypes_do_not_contain(RootLabel rootLabel, String typeLabel, List superLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getSupertypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).asRemote(tx()).getSupertypes().map(Type.Local::getLabel).collect(toSet()); for (String superLabel : superLabels) { assertFalse(actuals.contains(superLabel)); } @@ -200,13 +198,13 @@ public void thing_type_get_supertypes_do_not_contain(RootLabel rootLabel, String @Then("{root_label}\\( ?{type_label} ?) get subtypes contain:") public void thing_type_get_subtypes_contain(RootLabel rootLabel, String typeLabel, List subLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getSubtypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getSubtypes().map(Type.Local::getLabel).collect(toSet()); assertTrue(actuals.containsAll(subLabels)); } @Then("{root_label}\\( ?{type_label} ?) get subtypes do not contain:") public void thing_type_get_subtypes_do_not_contain(RootLabel rootLabel, String typeLabel, List subLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getSubtypes().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getSubtypes().map(Type.Local::getLabel).collect(toSet()); for (String subLabel : subLabels) { assertFalse(actuals.contains(subLabel)); } @@ -215,44 +213,44 @@ public void thing_type_get_subtypes_do_not_contain(RootLabel rootLabel, String t @When("{root_label}\\( ?{type_label} ?) set owns key type: {type_label}") public void thing_type_set_has_key_type(RootLabel rootLabel, String typeLabel, String attTypeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attTypeLabel); - get_thing_type(rootLabel, typeLabel).setOwns(attributeType, true); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, true); } @When("{root_label}\\( ?{type_label} ?) set owns key type: {type_label} as {type_label}") public void thing_type_set_has_key_type_as(RootLabel rootLabel, String typeLabel, String attTypeLabel, String overriddenLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attTypeLabel); AttributeType overriddenType = tx().concepts().getAttributeType(overriddenLabel); - get_thing_type(rootLabel, typeLabel).setOwns(attributeType, overriddenType, true); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, overriddenType, true); } @Then("{root_label}\\( ?{type_label} ?) set owns key type: {type_label}; throws exception") public void thing_type_set_has_key_type_throws_exception(RootLabel rootLabel, String typeLabel, String attributeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setOwns(attributeType, true)); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, true)); } @Then("{root_label}\\( ?{type_label} ?) set owns key type: {type_label} as {type_label}; throws exception") public void thing_type_set_has_key_type_as_throws_exception(RootLabel rootLabel, String typeLabel, String attributeLabel, String overriddenLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); AttributeType overriddenType = tx().concepts().getAttributeType(overriddenLabel); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setOwns(attributeType, overriddenType, true)); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, overriddenType, true)); } @When("{root_label}\\( ?{type_label} ?) unset owns key type: {type_label}") public void thing_type_remove_has_key_type(RootLabel rootLabel, String typeLabel, String attributeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); - get_thing_type(rootLabel, typeLabel).unsetOwns(attributeType); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).unsetOwns(attributeType); } @Then("{root_label}\\( ?{type_label} ?) get owns key types contain:") public void thing_type_get_has_key_types_contain(RootLabel rootLabel, String typeLabel, List attributeLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getOwns(true).map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getOwns(true).map(Type.Local::getLabel).collect(toSet()); assertTrue(actuals.containsAll(attributeLabels)); } @Then("{root_label}\\( ?{type_label} ?) get owns key types do not contain:") public void thing_type_get_has_key_types_do_not_contain(RootLabel rootLabel, String typeLabel, List attributeLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getOwns(true).map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getOwns(true).map(Type.Local::getLabel).collect(toSet()); for (String attributeLabel : attributeLabels) { assertFalse(actuals.contains(attributeLabel)); } @@ -261,44 +259,44 @@ public void thing_type_get_has_key_types_do_not_contain(RootLabel rootLabel, Str @When("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label}") public void thing_type_set_has_attribute_type(RootLabel rootLabel, String typeLabel, String attributeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); - get_thing_type(rootLabel, typeLabel).setOwns(attributeType); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType); } @Then("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label}; throws exception") public void thing_type_set_has_attribute_throws_exception(RootLabel rootLabel, String typeLabel, String attributeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setOwns(attributeType)); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType)); } @When("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label} as {type_label}") public void thing_type_set_has_attribute_type_as(RootLabel rootLabel, String typeLabel, String attributeLabel, String overriddenLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); AttributeType overriddenType = tx().concepts().getAttributeType(overriddenLabel); - get_thing_type(rootLabel, typeLabel).setOwns(attributeType, overriddenType); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, overriddenType); } @Then("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label} as {type_label}; throws exception") public void thing_type_set_has_attribute_as_throws_exception(RootLabel rootLabel, String typeLabel, String attributeLabel, String overriddenLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); AttributeType overriddenType = tx().concepts().getAttributeType(overriddenLabel); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setOwns(attributeType, overriddenType)); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType, overriddenType)); } @When("{root_label}\\( ?{type_label} ?) unset owns attribute type: {type_label}") public void thing_type_remove_has_attribute_type(RootLabel rootLabel, String typeLabel, String attributeLabel) { AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel); - get_thing_type(rootLabel, typeLabel).unsetOwns(attributeType); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).unsetOwns(attributeType); } @Then("{root_label}\\( ?{type_label} ?) get owns attribute types contain:") public void thing_type_get_has_attribute_types_contain(RootLabel rootLabel, String typeLabel, List attributeLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getOwns().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getOwns().map(Type.Local::getLabel).collect(toSet()); assertTrue(actuals.containsAll(attributeLabels)); } @Then("{root_label}\\( ?{type_label} ?) get owns attribute types do not contain:") public void thing_type_get_has_attribute_types_do_not_contain(RootLabel rootLabel, String typeLabel, List attributeLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getOwns().map(Type.Remote::getLabel).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getOwns().map(Type.Local::getLabel).collect(toSet()); for (String attributeLabel : attributeLabels) { assertFalse(actuals.contains(attributeLabel)); } @@ -306,52 +304,50 @@ public void thing_type_get_has_attribute_types_do_not_contain(RootLabel rootLabe @When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label}") public void thing_type_set_plays_role(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) { - RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.role()); - get_thing_type(rootLabel, typeLabel).setPlays(roleType); + RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getRelates(roleLabel.role()); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setPlays(roleType); } @When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label}; throws exception") public void thing_type_set_plays_role_throws_exception(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) { - RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.role()); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setPlays(roleType)); + RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getRelates(roleLabel.role()); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setPlays(roleType)); } @When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label} as {type_label}") public void thing_type_set_plays_role_as(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel, String overriddenLabel) { - RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.role()); - RoleType overriddenType = tx().concepts().getRelationType(roleLabel.scope()).getSupertypes() - .flatMap(RelationType.Remote::getRelates).filter(r -> r.getLabel().equals(overriddenLabel)).findAny().get(); - get_thing_type(rootLabel, typeLabel).setPlays(roleType, overriddenType); + RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getRelates(roleLabel.role()); + RoleType overriddenType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getSupertypes() + .flatMap(sup -> sup.asRemote(tx()).getRelates()).filter(r -> r.getLabel().equals(overriddenLabel)).findAny().get(); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).setPlays(roleType, overriddenType); } @When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label} as {scoped_label}; throws exception") public void thing_type_set_plays_role_as_throws_exception(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel, Parameters.ScopedLabel overriddenLabel) { - RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.role()); - RoleType overriddenType = tx().concepts().getRelationType(overriddenLabel.scope()).getRelates(overriddenLabel.role()); - assertThrows(() -> get_thing_type(rootLabel, typeLabel).setPlays(roleType, overriddenType)); + RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getRelates(roleLabel.role()); + RoleType overriddenType = tx().concepts().getRelationType(overriddenLabel.scope()).asRemote(tx()).getRelates(overriddenLabel.role()); + assertThrows(() -> get_thing_type(rootLabel, typeLabel).asRemote(tx()).setPlays(roleType, overriddenType)); } @When("{root_label}\\( ?{type_label} ?) unset plays role: {scoped_label}") public void thing_type_remove_plays_role(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel) { - RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.role()); - get_thing_type(rootLabel, typeLabel).unsetPlays(roleType); + RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).asRemote(tx()).getRelates(roleLabel.role()); + get_thing_type(rootLabel, typeLabel).asRemote(tx()).unsetPlays(roleType); } @Then("{root_label}\\( ?{type_label} ?) get playing roles contain:") public void thing_type_get_playing_roles_contain(RootLabel rootLabel, String typeLabel, List roleLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getPlays().map(r -> { - String[] labels = r.getScopedLabel().split(":"); - return new Parameters.ScopedLabel(labels[0], labels[1]); - }).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getPlays().map( + r -> new Parameters.ScopedLabel(r.getScope(), r.getLabel()) + ).collect(toSet()); assertTrue(actuals.containsAll(roleLabels)); } @Then("{root_label}\\( ?{type_label} ?) get playing roles do not contain:") public void thing_type_get_playing_roles_do_not_contain(RootLabel rootLabel, String typeLabel, List roleLabels) { - Set actuals = get_thing_type(rootLabel, typeLabel).getPlays().map(r -> { - String[] labels = r.getScopedLabel().split(":"); - return new Parameters.ScopedLabel(labels[0], labels[1]); - }).collect(toSet()); + Set actuals = get_thing_type(rootLabel, typeLabel).asRemote(tx()).getPlays().map( + r -> new Parameters.ScopedLabel(r.getScope(), r.getLabel()) + ).collect(toSet()); for (Parameters.ScopedLabel roleLabel : roleLabels) { assertFalse(actuals.contains(roleLabel)); } diff --git a/test/behaviour/concept/type/thingtype/ThingTypeTest.java b/test/behaviour/concept/type/thingtype/ThingTypeTest.java index b1118d94fd..ea842181b6 100644 --- a/test/behaviour/concept/type/thingtype/ThingTypeTest.java +++ b/test/behaviour/concept/type/thingtype/ThingTypeTest.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.concept.type.thingtype; diff --git a/test/behaviour/config/BUILD b/test/behaviour/config/BUILD index ecd190b36b..0d216a1594 100644 --- a/test/behaviour/config/BUILD +++ b/test/behaviour/config/BUILD @@ -34,5 +34,5 @@ java_library( checkstyle_test( name = "checkstyle", targets = [":parameters"], - license_type = "apache" + license_type = "apache", ) diff --git a/test/behaviour/connection/BUILD b/test/behaviour/connection/BUILD index a422a6f7ec..2fac15e6c1 100644 --- a/test/behaviour/connection/BUILD +++ b/test/behaviour/connection/BUILD @@ -42,5 +42,5 @@ checkstyle_test( targets = [ ":steps", ], - license_type = "apache" + license_type = "apache", ) diff --git a/test/behaviour/connection/database/BUILD b/test/behaviour/connection/database/BUILD index c5ac26f0c8..52d6a4aa08 100644 --- a/test/behaviour/connection/database/BUILD +++ b/test/behaviour/connection/database/BUILD @@ -69,5 +69,5 @@ checkstyle_test( ":steps", ":test-core", ], - license_type = "apache" + license_type = "apache", ) diff --git a/test/behaviour/connection/session/BUILD b/test/behaviour/connection/session/BUILD index 60671cb487..1d47cbb10b 100644 --- a/test/behaviour/connection/session/BUILD +++ b/test/behaviour/connection/session/BUILD @@ -68,6 +68,6 @@ checkstyle_test( targets = [ ":steps", ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/connection/transaction/BUILD b/test/behaviour/connection/transaction/BUILD index c663f81527..6b4ae10b2a 100644 --- a/test/behaviour/connection/transaction/BUILD +++ b/test/behaviour/connection/transaction/BUILD @@ -72,6 +72,6 @@ checkstyle_test( targets = [ ":steps", ":test-core", -], - license_type = "apache" + ], + license_type = "apache", ) diff --git a/test/behaviour/debug/BUILD b/test/behaviour/debug/BUILD index 50475b55c5..3d4437a86f 100644 --- a/test/behaviour/debug/BUILD +++ b/test/behaviour/debug/BUILD @@ -54,5 +54,5 @@ checkstyle_test( targets = [ ":test" ], - license_type = "apache" + license_type = "apache", ) diff --git a/test/behaviour/graql/BUILD b/test/behaviour/graql/BUILD index edbccb8fe8..10fcad1fc6 100644 --- a/test/behaviour/graql/BUILD +++ b/test/behaviour/graql/BUILD @@ -48,5 +48,5 @@ checkstyle_test( targets = [ ":steps", ], - license_type = "apache" + license_type = "apache", ) diff --git a/test/behaviour/graql/GraqlSteps.java b/test/behaviour/graql/GraqlSteps.java index 0c8bba8c6c..d56c06084f 100644 --- a/test/behaviour/graql/GraqlSteps.java +++ b/test/behaviour/graql/GraqlSteps.java @@ -22,12 +22,12 @@ import com.google.common.collect.Iterators; import grakn.client.Grakn.Session; import grakn.client.Grakn.Transaction; +import grakn.client.concept.Concept; import grakn.client.concept.answer.Answer; import grakn.client.concept.answer.AnswerGroup; import grakn.client.concept.answer.ConceptMap; import grakn.client.concept.answer.Explanation; import grakn.client.concept.answer.Numeric; -import grakn.client.concept.Concept; import grakn.client.concept.thing.Attribute; import grakn.client.concept.thing.Thing; import grakn.client.concept.type.Rule; @@ -37,8 +37,8 @@ import graql.lang.pattern.Conjunction; import graql.lang.query.GraqlDefine; import graql.lang.query.GraqlDelete; -import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlInsert; +import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlQuery; import graql.lang.query.GraqlUndefine; import io.cucumber.java.After; @@ -671,7 +671,7 @@ public static class ValueUniquenessCheck extends AttributeUniquenessCheck implem public boolean check(Concept concept) { return concept instanceof Attribute - && type.equals(concept.asThing().asAttribute().getType().getLabel()) + && type.equals(concept.asThing().asAttribute().asRemote(tx).getType().getLabel()) && value.equals(concept.asThing().asAttribute().getValue().toString()); } } @@ -681,23 +681,17 @@ public static class KeyUniquenessCheck extends AttributeUniquenessCheck implemen super(typeAndValue); } - /** - * Check that the given key is in the concept's keys - * - * @param concept to check - * @return whether the given key matches a key belonging to the concept - */ @Override public boolean check(Concept concept) { if (!(concept instanceof Thing)) { return false; } - Set keys = concept.asThing().asRemote(tx.concepts()).getHas(true).collect(Collectors.toSet()); + Set keys = concept.asThing().asRemote(tx).getHas(true).collect(Collectors.toSet()); HashMap keyMap = new HashMap<>(); for (Attribute key : keys) { keyMap.put( - key.getType().getLabel(), + key.asRemote(tx).getType().getLabel(), key.getValue().toString()); } return value.equals(keyMap.get(type)); diff --git a/test/behaviour/graql/language/define/BUILD b/test/behaviour/graql/language/define/BUILD index aaa71899f3..72096d82a4 100644 --- a/test/behaviour/graql/language/define/BUILD +++ b/test/behaviour/graql/language/define/BUILD @@ -49,6 +49,6 @@ checkstyle_test( name = "checkstyle", targets = [ ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/graql/language/delete/BUILD b/test/behaviour/graql/language/delete/BUILD index eb2c6fa858..c1b628e6f0 100644 --- a/test/behaviour/graql/language/delete/BUILD +++ b/test/behaviour/graql/language/delete/BUILD @@ -49,6 +49,6 @@ checkstyle_test( name = "checkstyle", targets = [ ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/graql/language/get/BUILD b/test/behaviour/graql/language/get/BUILD index 1fd0165a5c..ea5ba3dce6 100644 --- a/test/behaviour/graql/language/get/BUILD +++ b/test/behaviour/graql/language/get/BUILD @@ -49,6 +49,6 @@ checkstyle_test( name = "checkstyle", targets = [ ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/graql/language/match/BUILD b/test/behaviour/graql/language/match/BUILD index cb249ecc74..f3342454ef 100644 --- a/test/behaviour/graql/language/match/BUILD +++ b/test/behaviour/graql/language/match/BUILD @@ -49,6 +49,6 @@ checkstyle_test( name = "checkstyle", targets = [ ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/graql/language/undefine/BUILD b/test/behaviour/graql/language/undefine/BUILD index f37f36de16..1f394380b3 100644 --- a/test/behaviour/graql/language/undefine/BUILD +++ b/test/behaviour/graql/language/undefine/BUILD @@ -49,6 +49,6 @@ checkstyle_test( name = "checkstyle", targets = [ ":test-core", -], + ], license_type = "apache", ) diff --git a/test/behaviour/util/BUILD b/test/behaviour/util/BUILD index 9bb60880e0..a9aa25b47b 100644 --- a/test/behaviour/util/BUILD +++ b/test/behaviour/util/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # package(default_visibility = ["//test/behaviour:__subpackages__"]) @@ -39,4 +41,5 @@ checkstyle_test( targets = [ ":util", ], + license_type = "apache", ) diff --git a/test/behaviour/util/Util.java b/test/behaviour/util/Util.java index 8c217db100..53523ce5d2 100644 --- a/test/behaviour/util/Util.java +++ b/test/behaviour/util/Util.java @@ -1,19 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.behaviour.util; diff --git a/test/deployment/src/test/java/application/MavenApplicationTest.java b/test/deployment/src/test/java/application/MavenApplicationTest.java index 599978b017..55804d4b3c 100644 --- a/test/deployment/src/test/java/application/MavenApplicationTest.java +++ b/test/deployment/src/test/java/application/MavenApplicationTest.java @@ -19,9 +19,9 @@ public void test() { client.databases().create("grakn"); try (Session session = client.session("grakn")) { try (Transaction tx = session.transaction(Transaction.Type.WRITE)) { - ThingType root = tx.concepts().getRootType(); + ThingType root = tx.concepts().getRootThingType(); assertNotNull(root); - assertEquals(4, root.asRemote(tx.concepts()).getSubtypes().count()); + assertEquals(4, root.asRemote(tx).getSubtypes().count()); } } } diff --git a/test/deployment/src/test/resources/logback-test.xml b/test/deployment/src/test/resources/logback-test.xml index c038cc4bda..915b735dbd 100644 --- a/test/deployment/src/test/resources/logback-test.xml +++ b/test/deployment/src/test/resources/logback-test.xml @@ -1,4 +1,3 @@ - diff --git a/test/integration/BUILD b/test/integration/BUILD index 8442835aa8..0458c3404e 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -1,18 +1,20 @@ # -# Copyright (C) 2020 Grakn Labs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test") @@ -43,4 +45,5 @@ checkstyle_test( targets = [ ":test-client-query", ], + license_type = "apache", ) diff --git a/test/integration/ClientQueryTest.java b/test/integration/ClientQueryTest.java index b2c2763f0d..2a9f3a9eee 100644 --- a/test/integration/ClientQueryTest.java +++ b/test/integration/ClientQueryTest.java @@ -1,18 +1,20 @@ /* - * Copyright (C) 2020 Grakn Labs + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package grakn.client.test.integration; @@ -28,8 +30,8 @@ import graql.lang.query.GraqlCompute; import graql.lang.query.GraqlDefine; import graql.lang.query.GraqlDelete; -import graql.lang.query.GraqlMatch; import graql.lang.query.GraqlInsert; +import graql.lang.query.GraqlMatch; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -53,27 +55,6 @@ import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; -/** - * Performs various queries: - * - define a schema with a rule - * - match; get; - * - match; get of an inferred relation - * - match; insert; - * - match; delete; - * - match; aggregate; - * - and compute count - *

- * The tests are highly interconnected hence why they are grouped into a single test. - * If you split them into multiple tests, there is no guarantee that they are ran in the order they are defined, - * and there is a chance that the match; get; test is performed before the define a schema test, which would cause it to fail. - *

- * The schema describes a lion family which consists of a lion, lioness, and the offspring - three young lions. The mating - * relation captures the mating act between the male and female partners (ie., the lion and lioness). The child-bearing - * relation captures the child-bearing act which results from the mating act. - *

- * The rule is one such that if there is an offspring which is the result of a certain child-bearing act, then - * that offspring is the child of the male and female partners which are involved in the mating act. - */ @SuppressWarnings("Duplicates") public class ClientQueryTest { private static final Logger LOG = LoggerFactory.getLogger(ClientQueryTest.class);