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);
}
}
}
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;
}
Aggregations