use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.
the class SchemaHelper method getSourceGenerator.
// ----- private methods -----
private static PropertySourceGenerator getSourceGenerator(final ErrorBuffer errorBuffer, final String className, final PropertyDefinition propertyDefinition) throws FrameworkException {
final String propertyName = propertyDefinition.getPropertyName();
final Type propertyType = propertyDefinition.getPropertyType();
final Class<? extends PropertySourceGenerator> parserClass = parserMap.get(propertyType);
try {
return parserClass.getConstructor(ErrorBuffer.class, String.class, PropertyDefinition.class).newInstance(errorBuffer, className, propertyDefinition);
} catch (Throwable t) {
logger.warn("", t);
}
errorBuffer.add(new InvalidPropertySchemaToken(SchemaProperty.class.getSimpleName(), propertyName, propertyName, "invalid_property_definition", "Unknow value type " + source + ", options are " + Arrays.asList(Type.values()) + "."));
throw new FrameworkException(422, "Invalid property definition for property " + propertyDefinition.getPropertyName(), errorBuffer);
}
use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.
the class ExtendNotionPropertyWithUuid method handleMigration.
@Override
public void handleMigration(final ErrorToken errorToken) throws FrameworkException {
final Object messageObject = errorToken.getDetail();
if (messageObject != null) {
final String message = (String) messageObject;
if (message.startsWith("Invalid notion property expression for property ") && message.endsWith(".")) {
if (errorToken instanceof InvalidPropertySchemaToken) {
final App app = StructrApp.getInstance();
final InvalidPropertySchemaToken token = (InvalidPropertySchemaToken) errorToken;
final String typeName = token.getType();
final String propertyName = token.getProperty();
final SchemaNode type = app.nodeQuery(SchemaNode.class).andName(typeName).getFirst();
if (type != null) {
final SchemaProperty property = app.nodeQuery(SchemaProperty.class).and(SchemaProperty.schemaNode, type).and(SchemaProperty.name, propertyName).getFirst();
if (property != null) {
// load format property
final String format = property.getProperty(SchemaProperty.format);
// store corrected version of format property
property.setProperty(SchemaProperty.format, format + ", id");
}
}
}
}
}
}
use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.
the class NumericalPropertyParser method parseFormatString.
@Override
public void parseFormatString(final Schema entity, final String expression) throws FrameworkException {
boolean error = false;
final String rangeFormatErrorMessage = "Range expression must describe a (possibly open-ended) interval, e.g. [10,99] or ]9,100[ for all two-digit integers";
if (StringUtils.isNotBlank(expression)) {
if ((expression.startsWith("[") || expression.startsWith("]")) && (expression.endsWith("[") || expression.endsWith("]"))) {
final String range = expression.substring(1, expression.length() - 1);
final String[] parts = range.split(",+");
if (parts.length == 2) {
lowerBound = parseNumber(getErrorBuffer(), parts[0].trim(), "lower");
upperBound = parseNumber(getErrorBuffer(), parts[1].trim(), "upper");
if (lowerBound == null || upperBound == null) {
error = true;
}
lowerExclusive = expression.startsWith("]");
upperExclusive = expression.endsWith("[");
} else {
error = true;
}
if (!error) {
addGlobalValidator(new Validator("isValid" + getUnqualifiedValueType() + "InRange", getClassName(), getSourcePropertyName(), expression));
}
} else {
error = true;
}
}
if (error) {
reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), source.getPropertyName(), expression, "invalid_range_expression", rangeFormatErrorMessage));
}
}
use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.
the class EnumPropertyParser method parseFormatString.
@Override
public void parseFormatString(final Schema entity, String expression) throws FrameworkException {
final String[] enumTypes = expression.split("[, ]+");
if (StringUtils.isNotBlank(expression) && enumTypes.length > 0) {
enumTypeName = StringUtils.capitalize(getSourcePropertyName());
// create enum type
enumType = ", " + enumTypeName + ".class";
// build enum type definition
final StringBuilder buf = new StringBuilder();
buf.append("\n\tpublic enum ").append(enumTypeName).append(" {\n\t\t");
for (int i = 0; i < enumTypes.length; i++) {
final String element = enumTypes[i];
if (element.matches("[a-zA-Z_]{1}[a-zA-Z0-9_]*")) {
buf.append(element);
// comma separation
if (i < enumTypes.length - 1) {
buf.append(", ");
}
} else {
reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "Invalid enum type name, must match [a-zA-Z_]{1}[a-zA-Z0-9_]*."));
}
}
buf.append("\n\t};");
addEnumDefinition(buf.toString());
} else if (source.getFqcn() != null) {
// no enum type definition, use external type
enumTypeName = source.getFqcn();
// create enum type
enumType = ", " + enumTypeName + ".class";
} else {
reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), this.source.getPropertyName(), expression, "invalid_property_definition", "No enum types found, please specify a list of types, e.g. (red, green, blue)"));
}
}
use of org.structr.common.error.InvalidPropertySchemaToken in project structr by structr.
the class NotionPropertyParser method parseFormatString.
@Override
public void parseFormatString(final Schema entity, String expression) throws FrameworkException {
if (StringUtils.isBlank(expression)) {
// reportError(new InvalidPropertySchemaToken(SchemaNode.class.getSimpleName(), expression, "invalid_property_definition", "Empty notion property expression."));
throw new FrameworkException(422, "Empty notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Empty notion property expression for property " + source.getPropertyName() + "."));
}
final StringBuilder buf = new StringBuilder();
final String[] parts = expression.split("[, ]+");
if (parts.length > 0) {
boolean isBuiltinProperty = false;
baseProperty = parts[0];
multiplicity = entity.getMultiplicity(baseProperty);
if (multiplicity != null) {
// determine related type from relationship
relatedType = entity.getRelatedType(baseProperty);
switch(multiplicity) {
case "1X":
// this line exists because when a NotionProperty is set up for a builtin propery
// (like for example "owner", there must not be the string "Property" appended
// to the property name, and the SchemaNode returns the above "extended" multiplicity
// string when it has detected a fallback property name like "owner" from NodeInterface.
// no break!
isBuiltinProperty = true;
case "1":
propertyType = EntityNotionProperty.class.getSimpleName();
break;
case "*X":
// this line exists because when a NotionProperty is set up for a builtin propery
// (like for example "owner", there must not be the string "Property" appended
// to the property name, and the SchemaNode returns the above "extended" multiplicity
// string when it has detected a fallback property name like "owner" from NodeInterface.
// no break!
isBuiltinProperty = true;
case "*":
propertyType = CollectionNotionProperty.class.getSimpleName();
break;
default:
break;
}
buf.append(", ");
buf.append(entity.getClassName());
buf.append(".");
buf.append(baseProperty);
// append "Property" only if it is NOT a builtin property!
if (!isBuiltinProperty) {
buf.append("Property");
}
buf.append(",");
final boolean isBoolean = (parts.length == 3 && ("true".equals(parts[2].toLowerCase())));
isAutocreate = isBoolean;
// use PropertyNotion when only a single element is given
if (parts.length == 2 || isBoolean) {
buf.append(" new PropertyNotion(");
isPropertySet = false;
} else {
buf.append(" new PropertySetNotion(");
isPropertySet = true;
}
for (int i = 1; i < parts.length; i++) {
String propertyName = parts[i];
String fullPropertyName = propertyName;
if (!"true".equals(propertyName.toLowerCase()) && !propertyName.contains(".")) {
buf.append(relatedType);
buf.append(".");
fullPropertyName = relatedType + "." + fullPropertyName;
}
fullPropertyName = extendPropertyName(fullPropertyName, null);
properties.add(fullPropertyName);
propertyName = extendPropertyName(propertyName, relatedType);
buf.append(propertyName);
if (i < parts.length - 1) {
buf.append(", ");
}
}
buf.append(")");
} else {
throw new FrameworkException(422, "Invalid notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Invalid notion property expression for property " + source.getPropertyName() + "."));
}
if (properties.isEmpty()) {
throw new FrameworkException(422, "Invalid notion property expression for property " + source.getPropertyName() + ".", new InvalidPropertySchemaToken(entity.getClassName(), source.getPropertyName(), expression, "invalid_property_definition", "Invalid notion property expression for property " + source.getPropertyName() + ", notion must define at least one property."));
}
}
parameters = buf.toString();
}
Aggregations