use of org.structr.core.property.PropertyKey in project structr by structr.
the class DOMNode method getDataPropertyKeys.
static Set<PropertyKey> getDataPropertyKeys(final DOMNode thisNode) {
final Set<PropertyKey> customProperties = new TreeSet<>();
final org.structr.api.graph.Node dbNode = thisNode.getNode();
final Iterable<String> props = dbNode.getPropertyKeys();
for (final String key : props) {
PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisNode.getClass(), key, false);
if (propertyKey == null) {
// support arbitrary data-* attributes
propertyKey = new StringProperty(key);
}
if (key.startsWith("data-")) {
if (propertyKey != null && propertyKey instanceof BooleanProperty && dbNode.hasProperty(key)) {
final Object defaultValue = propertyKey.defaultValue();
final Object nodeValue = dbNode.getProperty(key);
// don't export boolean false values (which is the default)
if (nodeValue != null && Boolean.FALSE.equals(nodeValue) && (defaultValue == null || nodeValue.equals(defaultValue))) {
continue;
}
}
customProperties.add(propertyKey);
} else if (key.startsWith(CustomHtmlAttributeProperty.CUSTOM_HTML_ATTRIBUTE_PREFIX)) {
final CustomHtmlAttributeProperty customProp = new CustomHtmlAttributeProperty(propertyKey);
customProperties.add(customProp);
}
}
return customProperties;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class DOMNode method render.
static void render(final DOMNode thisNode, final RenderContext renderContext, final int depth) throws FrameworkException {
final SecurityContext securityContext = renderContext.getSecurityContext();
if (!securityContext.isVisible(thisNode)) {
return;
}
final GraphObject details = renderContext.getDetailsDataObject();
final boolean detailMode = details != null;
if (detailMode && thisNode.hideOnDetail()) {
return;
}
if (!detailMode && thisNode.hideOnIndex()) {
return;
}
final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
if (EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode) || EditMode.DEPLOYMENT.equals(editMode)) {
thisNode.renderContent(renderContext, depth);
} else {
final String subKey = thisNode.getDataKey();
if (StringUtils.isNotBlank(subKey)) {
final GraphObject currentDataNode = renderContext.getDataObject();
// fetch (optional) list of external data elements
final Iterable<GraphObject> listData = checkListSources(thisNode, securityContext, renderContext);
final PropertyKey propertyKey;
if (thisNode.renderDetails() && detailMode) {
renderContext.setDataObject(details);
renderContext.putDataObject(subKey, details);
thisNode.renderContent(renderContext, depth);
} else {
if (Iterables.isEmpty(listData) && currentDataNode != null) {
// There are two alternative ways of retrieving sub elements:
// First try to get generic properties,
// if that fails, try to create a propertyKey for the subKey
final Object elements = currentDataNode.getProperty(new GenericProperty(subKey));
renderContext.setRelatedProperty(new GenericProperty(subKey));
renderContext.setSourceDataObject(currentDataNode);
if (elements != null) {
if (elements instanceof Iterable) {
for (Object o : (Iterable) elements) {
if (o instanceof GraphObject) {
GraphObject graphObject = (GraphObject) o;
renderContext.putDataObject(subKey, graphObject);
thisNode.renderContent(renderContext, depth);
}
}
}
} else {
propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(currentDataNode.getClass(), subKey, false);
renderContext.setRelatedProperty(propertyKey);
if (propertyKey != null) {
final Object value = currentDataNode.getProperty(propertyKey);
if (value != null) {
if (value instanceof Iterable) {
for (final Object o : ((Iterable) value)) {
if (o instanceof GraphObject) {
renderContext.putDataObject(subKey, (GraphObject) o);
thisNode.renderContent(renderContext, depth);
}
}
}
}
}
}
// reset data node in render context
renderContext.setDataObject(currentDataNode);
renderContext.setRelatedProperty(null);
} else {
renderContext.setListSource(listData);
thisNode.renderNodeList(securityContext, renderContext, depth, subKey);
}
}
} else {
thisNode.renderContent(renderContext, depth);
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class DOMNode method cloneNode.
public static Node cloneNode(final DOMNode thisNode, boolean deep) {
final SecurityContext securityContext = thisNode.getSecurityContext();
if (deep) {
return cloneAndAppendChildren(securityContext, thisNode);
} else {
final PropertyMap properties = new PropertyMap();
for (Iterator<PropertyKey> it = thisNode.getPropertyKeys(PropertyView.Ui).iterator(); it.hasNext(); ) {
final PropertyKey key = it.next();
// skip blacklisted properties
if (cloneBlacklist.contains(key.jsonName())) {
continue;
}
if (!key.isUnvalidated()) {
properties.put(key, thisNode.getProperty(key));
}
}
// htmlView is necessary for the cloning of DOM nodes - otherwise some properties won't be cloned
for (Iterator<PropertyKey> it = thisNode.getPropertyKeys(PropertyView.Html).iterator(); it.hasNext(); ) {
final PropertyKey key = it.next();
// skip blacklisted properties
if (cloneBlacklist.contains(key.jsonName())) {
continue;
}
if (!key.isUnvalidated()) {
properties.put(key, thisNode.getProperty(key));
}
}
if (thisNode instanceof LinkSource) {
final LinkSource linkSourceElement = (LinkSource) thisNode;
properties.put(StructrApp.key(LinkSource.class, "linkable"), linkSourceElement.getLinkable());
}
final App app = StructrApp.getInstance(securityContext);
try {
return app.create(thisNode.getClass(), properties);
} catch (FrameworkException ex) {
ex.printStackTrace();
throw new DOMException(DOMException.INVALID_STATE_ERR, ex.toString());
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class GraphObject method filterIndexableForCreation.
default void filterIndexableForCreation(final SecurityContext securityContext, final PropertyMap src, final CreationContainer indexable, final PropertyMap filtered) throws FrameworkException {
for (final Iterator<Entry<PropertyKey, Object>> iterator = src.entrySet().iterator(); iterator.hasNext(); ) {
final Entry<PropertyKey, Object> attr = iterator.next();
final PropertyKey key = attr.getKey();
final Object value = attr.getValue();
if (key.indexable(value) && !key.isReadOnly() && !key.isSystemInternal() && !key.isUnvalidated()) {
// value can be set directly, move to creation container
key.setProperty(securityContext, indexable, value);
iterator.remove();
// store value to do notifications later
filtered.put(key, value);
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class GraphQLQuery method init.
// ----- private methods -----
private void init(final SecurityContext securityContext, final Class type, final Field field, final String path) throws FrameworkException {
final QueryConfig config = getConfig(path);
config.handleTypeArguments(securityContext, type, field.getArguments());
final SelectionSet selectionSet = field.getSelectionSet();
if (selectionSet != null) {
for (final Selection selection : selectionSet.getSelections()) {
if (selection instanceof Field) {
final Field childField = (Field) selection;
final SelectionSet childSet = childField.getSelectionSet();
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, childField.getName());
final Class relatedType = key.relatedType() != null ? key.relatedType() : type;
// add field to property set
config.addPropertyKey(key);
config.handleFieldArguments(securityContext, relatedType, field, childField);
// recurse
if (childSet != null) {
init(securityContext, relatedType, childField, path + "/" + childField.getName());
}
}
}
}
}
Aggregations