use of org.structr.core.property.PropertyKey in project structr by structr.
the class SearchCommand method or.
@Override
public <P> org.structr.core.app.Query<T> or(final PropertyMap attributes) {
for (final Map.Entry<PropertyKey, Object> entry : attributes.entrySet()) {
final PropertyKey key = entry.getKey();
final Object value = entry.getValue();
or(key, value);
}
return this;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class GraphObjectModificationState method delete.
public void delete(boolean passive) {
int statusBefore = status;
if (passive) {
status |= STATE_DELETED_PASSIVELY;
}
status |= STATE_DELETED;
if (status != statusBefore) {
// copy all properties on deletion
for (final PropertyKey key : object.getPropertyKeys(PropertyView.Public)) {
removedProperties.put(key, object.getProperty(key));
}
modified = true;
}
updateCache();
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class SetFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndAllElementsNotNull(sources, 2)) {
final SecurityContext securityContext = ctx.getSecurityContext();
final ConfigurationProvider config = StructrApp.getConfiguration();
Class type = null;
PropertyMap propertyMap = null;
if (sources[0] instanceof GraphObject) {
final GraphObject source = (GraphObject) sources[0];
type = source.getEntityType();
}
if (type == null) {
throw new FrameworkException(422, "Can't get type of object '" + sources[0].toString() + "' in set() method!");
}
final GraphObject sourceObject = (GraphObject) sources[0];
if (sources.length == 2 && sources[1] instanceof Map) {
propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, (Map) sources[1]);
} else if (sources.length == 2 && sources[1] instanceof GraphObjectMap) {
propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, ((GraphObjectMap) sources[1]).toMap());
} else if (sources.length == 2 && sources[1] instanceof String) {
final Gson gson = new GsonBuilder().create();
final Map<String, Object> values = deserialize(gson, sources[1].toString());
if (values != null) {
propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, values);
}
} else if (sources.length > 2) {
propertyMap = new PropertyMap();
final int parameter_count = sources.length;
if (parameter_count % 2 == 0) {
throw new FrameworkException(400, "Invalid number of parameters: " + parameter_count + ". Should be uneven: " + (ctx.isJavaScriptContext() ? ERROR_MESSAGE_SET_JS : ERROR_MESSAGE_SET));
}
for (int c = 1; c < parameter_count; c += 2) {
final PropertyKey key = config.getPropertyKeyForJSONName(type, sources[c].toString());
if (key != null) {
final PropertyConverter inputConverter = key.inputConverter(securityContext);
Object value = sources[c + 1];
if (inputConverter != null) {
value = inputConverter.convert(value);
}
propertyMap.put(key, value);
}
}
} else {
throw new FrameworkException(422, "Invalid use of builtin method set, usage: set(entity, params..)");
}
if (propertyMap != null) {
sourceObject.setProperties(securityContext, propertyMap);
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return "";
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class DOMElement method findOrCreateAttributeKey.
public static HtmlProperty findOrCreateAttributeKey(final DOMElement thisElement, final String name) {
// try to find native html property defined in DOMElement or one of its subclasses
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisElement.getEntityType(), name, false);
if (key != null && key instanceof HtmlProperty) {
return (HtmlProperty) key;
} else {
// create synthetic HtmlProperty
final HtmlProperty htmlProperty = new HtmlProperty(name);
htmlProperty.setDeclaringClass(DOMElement.class);
return htmlProperty;
}
}
use of org.structr.core.property.PropertyKey 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("\"");
}
}
}
}
}
Aggregations