use of org.structr.core.property.BooleanProperty in project structr by structr.
the class DOMNode method renderCustomAttributes.
static void renderCustomAttributes(final DOMNode thisNode, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext) throws FrameworkException {
final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
for (PropertyKey key : thisNode.getDataPropertyKeys()) {
String value = "";
if (EditMode.DEPLOYMENT.equals(editMode)) {
final Object obj = thisNode.getProperty(key);
if (obj != null) {
value = obj.toString();
}
} else {
value = thisNode.getPropertyWithVariableReplacement(renderContext, key);
if (value != null) {
value = value.trim();
}
}
if (!(EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode))) {
value = escapeForHtmlAttributes(value);
}
if (StringUtils.isNotBlank(value)) {
if (key instanceof CustomHtmlAttributeProperty) {
out.append(" ").append(((CustomHtmlAttributeProperty) key).cleanName()).append("=\"").append(value).append("\"");
} else {
out.append(" ").append(key.dbName()).append("=\"").append(value).append("\"");
}
}
}
if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
if (EditMode.DEPLOYMENT.equals(editMode)) {
// export name property if set
final String name = thisNode.getProperty(AbstractNode.name);
if (name != null) {
out.append(" data-structr-meta-name=\"").append(escapeForHtmlAttributes(name)).append("\"");
}
}
for (final String p : rawProps) {
String htmlName = "data-structr-meta-" + CaseHelper.toUnderscore(p, false).replaceAll("_", "-");
Object value = thisNode.getProperty(p);
if (value != null) {
final PropertyKey key = StructrApp.key(DOMNode.class, p);
final boolean isBoolean = key instanceof BooleanProperty;
final String stringValue = value.toString();
if ((isBoolean && "true".equals(stringValue)) || (!isBoolean && StringUtils.isNotBlank(stringValue))) {
out.append(" ").append(htmlName).append("=\"").append(escapeForHtmlAttributes(stringValue)).append("\"");
}
}
}
}
}
use of org.structr.core.property.BooleanProperty 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.BooleanProperty in project structr by structr.
the class StaticRelationshipResource method doGet.
// ~--- methods --------------------------------------------------------
@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
// ok, source node exists, fetch it
final GraphObject sourceEntity = typedIdResource.getEntity();
if (sourceEntity != null) {
// first try: look through existing relations
if (propertyKey == null) {
if (sourceEntity instanceof NodeInterface) {
if (!typeResource.isNode) {
final NodeInterface source = (NodeInterface) sourceEntity;
final Node sourceNode = source.getNode();
final Class relationshipType = typeResource.entityClass;
final Relation relation = AbstractNode.getRelationshipForType(relationshipType);
final Class destNodeType = relation.getOtherType(typedIdResource.getEntityClass());
final Set partialResult = new LinkedHashSet<>(typeResource.doGet(sortKey, sortDescending, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults());
// filter list according to end node type
final Set<GraphObject> set = Iterables.toSet(Iterables.filter(new OtherNodeTypeRelationFilter(securityContext, sourceNode, destNodeType), source.getRelationships(relationshipType)));
// intersect partial result with result list
set.retainAll(partialResult);
final List<GraphObject> finalResult = new LinkedList<>(set);
// sort after merge
applyDefaultSorting(finalResult, sortKey, sortDescending);
// return result
return new Result(PagingHelper.subList(finalResult, pageSize, page), finalResult.size(), isCollectionResource(), isPrimitiveArray());
} else {
// what here?
throw new NotFoundException("Cannot access relationship collection " + typeResource.getRawType());
}
}
} else {
Query query = typeResource.query;
if (query == null) {
query = StructrApp.getInstance(securityContext).nodeQuery();
}
// use search context from type resource
typeResource.collectSearchAttributes(query);
final Predicate<GraphObject> predicate = query.toPredicate();
final Object value = sourceEntity.getProperty(propertyKey, predicate);
if (value != null) {
if (value instanceof Iterable) {
final Set<Object> propertyResults = new LinkedHashSet<>();
Iterator<Object> iter = ((Iterable<Object>) value).iterator();
boolean iterableContainsGraphObject = false;
while (iter.hasNext()) {
Object obj = iter.next();
propertyResults.add(obj);
if (obj != null && !iterableContainsGraphObject) {
if (obj instanceof GraphObject) {
iterableContainsGraphObject = true;
}
}
}
int rawResultCount = propertyResults.size();
if (rawResultCount > 0 && !iterableContainsGraphObject) {
GraphObjectMap gObject = new GraphObjectMap();
gObject.setProperty(new ArrayProperty(this.typeResource.rawType, Object.class), propertyResults.toArray());
Result r = new Result(gObject, true);
r.setRawResultCount(rawResultCount);
return r;
}
final List<GraphObject> finalResult = new LinkedList<>();
propertyResults.forEach(v -> finalResult.add((GraphObject) v));
applyDefaultSorting(finalResult, sortKey, sortDescending);
// return result
Result r = new Result(PagingHelper.subList(finalResult, pageSize, page), finalResult.size(), isCollectionResource(), isPrimitiveArray());
r.setRawResultCount(rawResultCount);
return r;
} else if (value instanceof GraphObject) {
return new Result((GraphObject) value, isPrimitiveArray());
} else {
GraphObjectMap gObject = new GraphObjectMap();
PropertyKey key;
String keyName = this.typeResource.rawType;
int resultCount = 1;
// FIXME: Dynamically resolve all property types and their result count
if (value instanceof String) {
key = new StringProperty(keyName);
} else if (value instanceof Integer) {
key = new IntProperty(keyName);
} else if (value instanceof Long) {
key = new LongProperty(keyName);
} else if (value instanceof Double) {
key = new DoubleProperty(keyName);
} else if (value instanceof Boolean) {
key = new BooleanProperty(keyName);
} else if (value instanceof Date) {
key = new DateProperty(keyName);
} else if (value instanceof String[]) {
key = new ArrayProperty(keyName, String.class);
resultCount = ((String[]) value).length;
} else {
key = new GenericProperty(keyName);
}
gObject.setProperty(key, value);
Result r = new Result(gObject, true);
r.setRawResultCount(resultCount);
return r;
}
}
// check propertyKey to return the right variant of empty result
if (!(propertyKey instanceof StartNode || propertyKey instanceof EndNode)) {
return new Result(Collections.EMPTY_LIST, 1, false, true);
}
}
}
return new Result(Collections.EMPTY_LIST, 0, false, true);
}
use of org.structr.core.property.BooleanProperty in project structr by structr.
the class SchemaHelper method getSchemaTypeInfo.
// ----- public static methods -----
public static List<GraphObjectMap> getSchemaTypeInfo(final SecurityContext securityContext, final String rawType, final Class type, final String propertyView) throws FrameworkException {
List<GraphObjectMap> resultList = new LinkedList<>();
if (type != null) {
if (propertyView != null) {
for (final Map.Entry<String, Object> entry : getPropertiesForView(securityContext, type, propertyView).entrySet()) {
final GraphObjectMap property = new GraphObjectMap();
for (final Map.Entry<String, Object> prop : ((Map<String, Object>) entry.getValue()).entrySet()) {
property.setProperty(new GenericProperty(prop.getKey()), prop.getValue());
}
resultList.add(property);
}
} else {
final GraphObjectMap schema = new GraphObjectMap();
resultList.add(schema);
String url = "/".concat(rawType);
schema.setProperty(new StringProperty("url"), url);
schema.setProperty(new StringProperty("type"), type.getSimpleName());
schema.setProperty(new StringProperty("className"), type.getName());
schema.setProperty(new StringProperty("extendsClass"), type.getSuperclass().getName());
schema.setProperty(new BooleanProperty("isRel"), AbstractRelationship.class.isAssignableFrom(type));
schema.setProperty(new LongProperty("flags"), SecurityContext.getResourceFlags(rawType));
Set<String> propertyViews = new LinkedHashSet<>(StructrApp.getConfiguration().getPropertyViewsForType(type));
// list property sets for all views
Map<String, Map<String, Object>> views = new TreeMap();
schema.setProperty(new GenericProperty("views"), views);
for (final String view : propertyViews) {
if (!View.INTERNAL_GRAPH_VIEW.equals(view)) {
views.put(view, getPropertiesForView(securityContext, type, view));
}
}
}
}
return resultList;
}
Aggregations