use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class ResetPasswordResource method doPost.
@Override
public RestMethodResult doPost(Map<String, Object> propertySet) throws FrameworkException {
if (propertySet.containsKey("eMail")) {
final String emailString = (String) propertySet.get("eMail");
if (StringUtils.isEmpty(emailString)) {
return new RestMethodResult(HttpServletResponse.SC_BAD_REQUEST);
}
final ConfigurationProvider config = StructrApp.getConfiguration();
final PropertyKey<String> confirmationKey = StructrApp.key(User.class, "confirmationKey");
final PropertyKey<String> eMail = StructrApp.key(User.class, "eMail");
final String localeString = (String) propertySet.get("locale");
final String confKey = UUID.randomUUID().toString();
final Principal user = StructrApp.getInstance().nodeQuery(User.class).and(eMail, emailString).getFirst();
if (user != null) {
// update confirmation key
user.setProperties(SecurityContext.getSuperUserInstance(), new PropertyMap(confirmationKey, confKey));
if (!sendResetPasswordLink(user, propertySet, localeString, confKey)) {
// return 400 Bad request
return new RestMethodResult(HttpServletResponse.SC_BAD_REQUEST);
}
// return 200 OK
return new RestMethodResult(HttpServletResponse.SC_OK);
} else {
// so we're failing silently here
return new RestMethodResult(HttpServletResponse.SC_OK);
}
} else {
// return 400 Bad request
return new RestMethodResult(HttpServletResponse.SC_BAD_REQUEST);
}
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class ListSchemaPropertiesCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final String view = (String) webSocketData.getNodeData().get("view");
final String id = webSocketData.getId();
final List<GraphObject> result = new LinkedList();
if (view != null) {
if (id != null) {
AbstractNode schemaObject = getNode(id);
if (schemaObject != null) {
final ConfigurationProvider config = StructrApp.getConfiguration();
String typeName = schemaObject.getProperty(AbstractNode.name);
if (typeName == null && schemaObject instanceof SchemaRelationshipNode) {
typeName = ((SchemaRelationshipNode) schemaObject).getClassName();
}
Class type = config.getNodeEntityClass(typeName);
if (type == null || GenericNode.class.equals(type)) {
type = config.getRelationshipEntityClass(typeName);
}
if (type != null) {
final Set<PropertyKey> allProperties = config.getPropertySet(type, PropertyView.All);
final Set<PropertyKey> viewProperties = config.getPropertySet(type, view);
final Set<PropertyKey> parentProperties = config.getPropertySet(type.getSuperclass(), view);
for (final PropertyKey key : allProperties) {
final String declaringClass = key.getDeclaringClass() != null ? key.getDeclaringClass().getSimpleName() : "GraphObject";
final String propertyName = key.jsonName();
final GraphObjectMap property = new GraphObjectMap();
final Class valueType = key.valueType();
String valueTypeName = "Unknown";
boolean _isDisabled = false;
if (valueType != null) {
valueTypeName = valueType.getSimpleName();
}
// (since it has to be configured there instead of locally)
if (parentProperties.contains(key)) {
_isDisabled = true;
}
property.put(AbstractNode.name, propertyName);
property.put(isSelected, viewProperties.contains(key));
property.put(isDisabled, _isDisabled);
property.put(SchemaProperty.propertyType, valueTypeName);
property.put(SchemaProperty.notNull, key.isNotNull());
property.put(SchemaProperty.unique, key.isUnique());
property.put(SchemaProperty.isDynamic, key.isDynamic());
property.put(SchemaProperty.declaringClass, declaringClass);
// store in result
result.add(property);
}
} else {
getWebSocket().send(MessageBuilder.status().code(404).message("Type " + typeName + " not found.").build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(404).message("Schema node with ID " + id + " not found.").build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(422).message("LIST_SCHEMA_PROPERTIES needs an ID.").build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(422).message("LIST_SCHEMA_PROPERTIES needs a view name in nodeData.").build(), true);
}
webSocketData.setView(PropertyView.Ui);
webSocketData.setResult(result);
webSocketData.setRawResultCount(1);
// send only over local connection
getWebSocket().send(webSocketData, true);
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class PathResolvingComparator method resolve.
// ----- private methods -----
private Comparable resolve(final GraphObject obj, final String path) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final String[] parts = path.split("[\\.]+");
GraphObject current = obj;
int pos = 0;
for (final String part : parts) {
final Class type = current.getEntityType();
final PropertyKey key = config.getPropertyKeyForJSONName(type, part, false);
if (key == null) {
logger.warn("Unknown key {} while resolving path {} for sorting.", part, path);
return null;
}
final Object value = current.getProperty(key);
if (value != null) {
// last part of path?
if (++pos == parts.length) {
if (value instanceof Comparable) {
return (Comparable) value;
}
logger.warn("Path evaluation result of component {} of type {} in {} cannot be used for sorting.", part, value.getClass().getSimpleName(), path);
return null;
}
if (value instanceof GraphObject) {
current = (GraphObject) value;
} else {
logger.warn("Path component {} of type {} in {} cannot be evaluated further.", part, value.getClass().getSimpleName(), path);
return null;
}
}
}
return null;
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class SearchFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
try {
if (sources == null) {
throw new IllegalArgumentException();
}
final SecurityContext securityContext = ctx.getSecurityContext();
final ConfigurationProvider config = StructrApp.getConfiguration();
final Query query = StructrApp.getInstance(securityContext).nodeQuery();
applyRange(securityContext, query);
Class type = null;
if (sources.length >= 1 && sources[0] != null) {
final String typeString = sources[0].toString();
type = config.getNodeEntityClass(typeString);
if (type != null) {
query.andTypes(type);
} else {
logger.warn("Error in search(): type {} not found.", typeString);
return "Error in search(): type " + typeString + " not found.";
}
}
// exit gracefully instead of crashing..
if (type == null) {
logger.warn("Error in search(): no type specified. Parameters: {}", getParametersAsString(sources));
return "Error in search(): no type specified.";
}
// experimental: disable result count, prevents instantiation
// of large collections just for counting all the objects..
securityContext.ignoreResultCount(true);
// extension for native javascript objects
if (sources.length == 2 && sources[1] instanceof Map) {
final PropertyMap map = PropertyMap.inputTypeToJavaType(securityContext, type, (Map) sources[1]);
for (final Map.Entry<PropertyKey, Object> entry : map.entrySet()) {
query.and(entry.getKey(), entry.getValue(), false);
}
} else {
final int parameter_count = sources.length;
if (parameter_count % 2 == 0) {
throw new FrameworkException(400, "Invalid number of parameters: " + parameter_count + ". Should be uneven: " + ERROR_MESSAGE_SEARCH);
}
for (int c = 1; c < parameter_count; c += 2) {
final PropertyKey key = StructrApp.key(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);
}
query.and(key, value, false);
}
}
}
// return search results
return query.getAsList();
} catch (final IllegalArgumentException e) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
} finally {
resetRange();
}
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class SourcePattern method type.
private Class type(final String typeString) throws FrameworkException {
Class type = null;
final ConfigurationProvider config = StructrApp.getConfiguration();
if (typeString != null) {
type = config.getNodeEntityClass(typeString);
}
if (type == null) {
throw new FrameworkException(422, "Unknown type '" + typeString + "'");
}
return type;
}
Aggregations