use of ai.grakn.concept.Label in project grakn by graknlabs.
the class ConceptController method getSchemaByLabel.
private String getSchemaByLabel(Request request, Response response) throws JsonProcessingException {
Requests.validateRequest(request, APPLICATION_ALL, APPLICATION_JSON);
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
Label label = Label.of(mandatoryPathParameter(request, LABEL_PARAMETER));
return getConcept(response, keyspace, (tx) -> tx.getSchemaConcept(label));
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class ValidateGlobalRules method validateInstancePlaysAllRequiredRoles.
/**
* @param thing The thing to be validated
* @return An error message if the thing does not have all the required resources
*/
static Optional<String> validateInstancePlaysAllRequiredRoles(Thing thing) {
TypeImpl<?, ?> currentConcept = (TypeImpl) thing.type();
while (currentConcept != null) {
Map<Role, Boolean> plays = currentConcept.directPlays();
for (Map.Entry<Role, Boolean> playsEntry : plays.entrySet()) {
if (playsEntry.getValue()) {
Role role = playsEntry.getKey();
// Assert there is a relationship for this type
Stream<Relationship> relationships = thing.relationships(role);
if (!CommonUtil.containsOnly(relationships, 1)) {
Label resourceTypeLabel = Schema.ImplicitType.explicitLabel(role.getLabel());
return Optional.of(VALIDATION_NOT_EXACTLY_ONE_KEY.getMessage(thing.getId(), resourceTypeLabel));
}
}
}
currentConcept = (TypeImpl) currentConcept.sup();
}
return Optional.empty();
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class GlobalCache method populateSchemaTxCache.
void populateSchemaTxCache(TxCache txCache) {
try {
lock.writeLock().lock();
Map<Label, SchemaConcept> cachedSchemaSnapshot = getCachedTypes();
Map<Label, LabelId> cachedLabelsSnapshot = getCachedLabels();
// Read central cache into txCache cloning only base concepts. Sets clones later
for (SchemaConcept type : cachedSchemaSnapshot.values()) {
txCache.cacheConcept(type);
}
// Load Labels Separately. We do this because the TypeCache may have expired.
cachedLabelsSnapshot.forEach(txCache::cacheLabel);
} finally {
lock.writeLock().unlock();
}
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class ConceptControllerTest method whenCallingRoleEndpointAndRequestingJSON_ReturnJSON.
@Test
public void whenCallingRoleEndpointAndRequestingJSON_ReturnJSON() {
Label label = MetaSchema.ROLE.getLabel();
given().accept(ContentType.JSON).pathParam("keyspace", keyspace.getValue()).pathParam("label", label.getValue()).when().get("/kb/{keyspace}/role/{label}").then().statusCode(SC_OK).contentType(ContentType.JSON);
}
use of ai.grakn.concept.Label in project grakn by graknlabs.
the class DefineQueryTest method testDefineReferenceByName.
@Test
public void testDefineReferenceByName() {
String roleTypeLabel = HAS_OWNER.getLabel("title").getValue();
qb.define(label("new-type").sub(Schema.MetaSchema.ENTITY.getLabel().getValue()), label("new-type").plays(roleTypeLabel)).execute();
qb.insert(var("x").isa("new-type")).execute();
Match typeQuery = qb.match(var("n").label("new-type"));
assertEquals(1, typeQuery.stream().count());
// We checked count ahead of time
// noinspection OptionalGetWithoutIsPresent
EntityType newType = typeQuery.get("n").findFirst().get().asEntityType();
assertTrue(newType.plays().anyMatch(role -> role.equals(movies.tx().getRole(roleTypeLabel))));
assertExists(qb, var().isa("new-type"));
}
Aggregations