Search in sources :

Example 26 with AttributeType

use of ai.grakn.concept.AttributeType in project grakn by graknlabs.

the class AttributeTypeTest method whenCreatingAResourceTypeOfTypeDate_EnsureTheTimeZoneIsSetTOADefaultAndDoesNotAffectRetreival.

@Test
public void whenCreatingAResourceTypeOfTypeDate_EnsureTheTimeZoneIsSetTOADefaultAndDoesNotAffectRetreival() {
    // offset the time to GMT-8
    TimeZone.setDefault(TimeZone.getTimeZone("GMT-8"));
    // get the local time (without timezone)
    LocalDateTime rightNow = LocalDateTime.now();
    // now add the timezone to the graph
    try (GraknSession session = Grakn.session(Grakn.IN_MEMORY, "somethingmorerandom")) {
        try (GraknTx graph = session.open(GraknTxType.WRITE)) {
            AttributeType<LocalDateTime> aTime = graph.putAttributeType("aTime", AttributeType.DataType.DATE);
            aTime.putAttribute(rightNow);
            graph.commit();
        }
    }
    // offset the time to GMT where the colleague is working
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    // the colleague extracts the LocalTime which should be the same
    try (GraknSession session = Grakn.session(Grakn.IN_MEMORY, "somethingmorerandom")) {
        try (GraknTx graph = session.open(GraknTxType.WRITE)) {
            AttributeType aTime = graph.getAttributeType("aTime");
            LocalDateTime databaseTime = (LocalDateTime) ((Attribute) aTime.instances().iterator().next()).getValue();
            // localTime should not have changed as it should not be sensitive to timezone
            assertEquals(rightNow, databaseTime);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) GraknTx(ai.grakn.GraknTx) AttributeType(ai.grakn.concept.AttributeType) GraknSession(ai.grakn.GraknSession) Test(org.junit.Test)

Example 27 with AttributeType

use of ai.grakn.concept.AttributeType in project grakn by graknlabs.

the class InstanceMapper method isHasResourceResource.

/**
 * Check if the given {@link Attribute} conforms to the has syntax and structural requirements
 * @param attribute {@link Attribute} to check
 * @return true if the {@link Attribute} is target of has relation
 */
private static boolean isHasResourceResource(Attribute attribute) {
    AttributeType attributeType = attribute.type();
    // TODO: Make sure this is tested
    boolean plays = attributeType.plays().map(Role::getLabel).allMatch(c -> c.equals(HAS_VALUE.getLabel(attributeType.getLabel())));
    return attribute.ownerInstances().findAny().isPresent() && plays;
}
Also used : AttributeType(ai.grakn.concept.AttributeType)

Aggregations

AttributeType (ai.grakn.concept.AttributeType)27 Test (org.junit.Test)13 EntityType (ai.grakn.concept.EntityType)7 Label (ai.grakn.concept.Label)7 RelationshipType (ai.grakn.concept.RelationshipType)7 GraknTx (ai.grakn.GraknTx)6 Role (ai.grakn.concept.Role)6 Attribute (ai.grakn.concept.Attribute)5 Property (com.pholser.junit.quickcheck.Property)5 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)4 GraknSession (ai.grakn.GraknSession)3 SchemaConcept (ai.grakn.concept.SchemaConcept)3 GraknTxType (ai.grakn.GraknTxType)2 Keyspace (ai.grakn.Keyspace)2 Concept (ai.grakn.concept.Concept)2 ConceptId (ai.grakn.concept.ConceptId)2 Entity (ai.grakn.concept.Entity)2 EmbeddedGraknSession (ai.grakn.factory.EmbeddedGraknSession)2 EngineContext (ai.grakn.test.rule.EngineContext)2 Collection (java.util.Collection)2