use of org.structr.core.property.PropertyKey in project structr by structr.
the class AbstractHintProvider method getAllHints.
protected List<Hint> getAllHints(final GraphObject currentNode, final String currentToken, final String previousToken, final String thirdToken) {
final boolean isDeclaration = isJavascript() && "var".equals(previousToken);
final boolean isAssignment = isJavascript() && "=".equals(previousToken);
final boolean isDotNotationRequest = ".".equals(currentToken);
final ConfigurationProvider config = StructrApp.getConfiguration();
final Map<String, DataKey> dataKeys = new TreeMap<>();
final List<Hint> hints = new LinkedList<>();
final List<Hint> local = new LinkedList<>();
Class currentObjectType = null;
// data key etc. hints
if (currentNode != null) {
recursivelyFindDataKeys(currentNode, dataKeys);
}
switch(previousToken) {
case "current":
currentObjectType = AbstractNode.class;
break;
case "this":
currentObjectType = DOMNode.class;
break;
case "me":
currentObjectType = User.class;
break;
case "page":
currentObjectType = Page.class;
break;
case "link":
currentObjectType = File.class;
break;
case "template":
currentObjectType = Template.class;
break;
case "parent":
currentObjectType = DOMElement.class;
break;
default:
DataKey key = dataKeys.get(previousToken);
if (key != null) {
currentObjectType = key.identifyType(config);
} else if (StringUtils.isNotBlank(thirdToken)) {
key = dataKeys.get(thirdToken);
if (key != null) {
currentObjectType = key.identifyType(config);
if (currentObjectType != null) {
final PropertyKey nestedKey = StructrApp.key(currentObjectType, previousToken);
if (nestedKey != null) {
currentObjectType = nestedKey.relatedType();
}
}
}
}
break;
}
if (!keywords.contains(previousToken) && !isDotNotationRequest && !dataKeys.containsKey(previousToken)) {
if (!isAssignment) {
for (final Function<Object, Object> func : Functions.getFunctions()) {
hints.add(func);
}
}
Collections.sort(hints, comparator);
// non-function hints
local.add(createHint("current", "", "Current data object", !isJavascript() ? null : "get('current')"));
local.add(createHint("request", "", "Current request object", !isJavascript() ? null : "get('request')"));
local.add(createHint("this", "", "Current object", !isJavascript() ? null : "get('this')"));
local.add(createHint("element", "", "Current object", !isJavascript() ? null : "get('element')"));
local.add(createHint("page", "", "Current page", !isJavascript() ? null : "get('page')"));
local.add(createHint("link", "", "Current link", !isJavascript() ? null : "get('link')"));
local.add(createHint("template", "", "Closest template node", !isJavascript() ? null : "get('template')"));
local.add(createHint("parent", "", "Parent node", !isJavascript() ? null : "get('parent')"));
local.add(createHint("children", "", "Collection of child nodes", !isJavascript() ? null : "get('children')"));
local.add(createHint("host", "", "Client's host name", !isJavascript() ? null : "get('host')"));
local.add(createHint("port", "", "Client's port", !isJavascript() ? null : "get('port')"));
local.add(createHint("path_info", "", "URL path", !isJavascript() ? null : "get('path_info')"));
local.add(createHint("now", "", "Current date", !isJavascript() ? null : "get('now')"));
local.add(createHint("me", "", "Current user", !isJavascript() ? null : "get('me)"));
local.add(createHint("locale", "", "Current locale", !isJavascript() ? null : "get('locale')"));
}
// add local hints to the beginning of the list
Collections.sort(local, comparator);
hints.addAll(0, local);
// prepend data keys
if (currentObjectType == null && !dataKeys.containsKey(previousToken) && !isDotNotationRequest || isAssignment) {
for (final DataKey dataKey : dataKeys.values()) {
final String replacement = isJavascript() && !isDeclaration ? "get('" + dataKey.getDataKey() + "')" : null;
final Hint dataKeyHint = createHint(dataKey.getDataKey(), "", dataKey.getDescription(), replacement);
// disable replacement with "Structr.get(...)" when in Javascript declaration
dataKeyHint.allowNameModification(!isDeclaration);
hints.add(0, dataKeyHint);
}
}
// prepend property keys of current object type
collectHintsForType(hints, config, currentObjectType);
return hints;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class AbstractHintProvider method collectHintsForType.
private void collectHintsForType(final List<Hint> hints, final ConfigurationProvider config, final Class type) {
if (type != null) {
final List<Hint> propertyHints = new LinkedList<>();
// create hints based on schema type information
for (final PropertyKey propertyKey : config.getPropertySet(type, PropertyView.All)) {
final String keyName = propertyKey.jsonName();
if (!keyName.startsWith(PropertyView.Html) && !keyName.startsWith("data-structr-")) {
final Hint propertyHint = createHint(keyName, "", type.getSimpleName() + " property");
// allow sorting by dynamic / static properties
propertyHint.setIsDynamic(propertyKey.isDynamic());
propertyHint.allowNameModification(false);
propertyHints.add(propertyHint);
}
}
Collections.sort(propertyHints, comparator);
hints.addAll(0, propertyHints);
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class TypeResource method identifyStartNode.
private NodeInterface identifyStartNode(final Relation template, final Map<String, Object> properties) throws FrameworkException {
final Property<String> sourceIdProperty = template.getSourceIdProperty();
final Class sourceType = template.getSourceType();
final Notion notion = template.getStartNodeNotion();
notion.setType(sourceType);
PropertyKey startNodeIdentifier = notion.getPrimaryPropertyKey();
if (startNodeIdentifier != null) {
Object identifierValue = properties.get(startNodeIdentifier.dbName());
properties.remove(sourceIdProperty.dbName());
return (NodeInterface) notion.getAdapterForSetter(securityContext).adapt(identifierValue);
}
return null;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class AdvancedSearchTest method testSearchDynamicNodes.
@Test
public void testSearchDynamicNodes() {
try {
SchemaNode node = null;
// setup
try (final Tx tx = app.tx()) {
node = app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "TestType"));
node.setProperty(new StringProperty("_test"), "Integer");
tx.success();
}
// fetch dynamic type info
final Class dynamicType = StructrApp.getConfiguration().getNodeEntityClass("TestType");
final PropertyKey testKey = StructrApp.key(dynamicType, "test");
// modify schema node but keep reference to "old" type
try (final Tx tx = app.tx()) {
node.setProperty(new StringProperty("_test2"), "String");
tx.success();
}
// create test nodes
try (final Tx tx = app.tx()) {
app.create(dynamicType, new NodeAttribute(testKey, 10));
app.create(dynamicType, new NodeAttribute(testKey, 11));
app.create(dynamicType, new NodeAttribute(testKey, 12));
tx.success();
}
// query test nodes
try (final Tx tx = app.tx()) {
/*
* If this test fails, the method "allSubtypes" in SearchCommand was not able to identify
* a dynamic type as being assignable to itself. This can happen when the reference to an
* existing dynamic type is used after the type has been modified, because the class
* instances produced by the dynamic schema ClassLoader are not equal even if they have
* the same name and package etc.
*/
assertEquals("Query for dynamic node should return exactly one result: ", 1, app.nodeQuery(dynamicType).and(testKey, 10).getAsList().size());
tx.success();
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class AbstractNode method getDynamicProperties.
@Override
public PropertyMap getDynamicProperties() {
final PropertyMap propertyMap = new PropertyMap();
final Class type = getClass();
for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
// include all dynamic keys in definition
if (key.isDynamic() || key.isCMISProperty()) {
// only include primitives here
final PropertyType dataType = key.getDataType();
if (dataType != null) {
propertyMap.put(key, getProperty(key));
}
}
}
return propertyMap;
}
Aggregations