use of org.structr.core.entity.SchemaProperty in project structr by structr.
the class SchemaHelper method extractViews.
public static void extractViews(final Schema entity, final Map<String, Set<String>> views, final Set<String> relPropertyNames, final ErrorBuffer errorBuffer) throws FrameworkException {
final PropertyContainer propertyContainer = entity.getPropertyContainer();
final ConfigurationProvider config = StructrApp.getConfiguration();
Class superClass = config.getNodeEntityClass(entity.getSuperclassName());
if (superClass == null) {
superClass = config.getRelationshipEntityClass(entity.getSuperclassName());
}
if (superClass == null) {
superClass = AbstractNode.class;
}
for (final String rawViewName : getViews(propertyContainer)) {
if (!rawViewName.startsWith("___") && propertyContainer.hasProperty(rawViewName)) {
final String value = propertyContainer.getProperty(rawViewName).toString();
final String[] parts = value.split("[,\\s]+");
final String viewName = rawViewName.substring(2);
if (entity instanceof AbstractSchemaNode) {
final List<String> nonGraphProperties = new LinkedList<>();
final List<SchemaProperty> properties = new LinkedList<>();
final AbstractSchemaNode schemaNode = (AbstractSchemaNode) entity;
final App app = StructrApp.getInstance();
if (app.nodeQuery(SchemaView.class).and(SchemaView.schemaNode, schemaNode).and(AbstractNode.name, viewName).getFirst() == null) {
// add parts to view, overrides defaults (because of clear() above)
for (int i = 0; i < parts.length; i++) {
String propertyName = parts[i].trim();
while (propertyName.startsWith("_")) {
propertyName = propertyName.substring(1);
}
// append this as a workaround to include remote properties
if (propertyName.endsWith("Property")) {
propertyName = propertyName.substring(0, propertyName.length() - "Property".length());
}
final SchemaProperty propertyNode = app.nodeQuery(SchemaProperty.class).and(SchemaProperty.schemaNode, schemaNode).andName(propertyName).getFirst();
if (propertyNode != null) {
properties.add(propertyNode);
} else {
nonGraphProperties.add(propertyName);
}
}
app.create(SchemaView.class, new NodeAttribute<>(SchemaView.schemaNode, schemaNode), new NodeAttribute<>(SchemaView.schemaProperties, properties), new NodeAttribute<>(SchemaView.name, viewName), new NodeAttribute<>(SchemaView.nonGraphProperties, StringUtils.join(nonGraphProperties, ",")));
schemaNode.removeProperty(new StringProperty(rawViewName));
}
}
}
}
final List<SchemaView> schemaViews = entity.getSchemaViews();
if (schemaViews != null) {
for (final SchemaView schemaView : schemaViews) {
final String nonGraphProperties = schemaView.getProperty(SchemaView.nonGraphProperties);
final String viewName = schemaView.getName();
// clear view before filling it again
Set<String> view = views.get(viewName);
if (view == null) {
view = new LinkedHashSet<>();
views.put(viewName, view);
}
final List<SchemaProperty> schemaProperties = schemaView.getProperty(SchemaView.schemaProperties);
for (final SchemaProperty property : schemaProperties) {
if (property.getProperty(SchemaProperty.isBuiltinProperty) && !property.getProperty(SchemaProperty.isDynamic)) {
view.add(SchemaHelper.cleanPropertyName(property.getPropertyName()));
} else {
view.add(SchemaHelper.cleanPropertyName(property.getPropertyName() + "Property"));
}
}
// add properties that are not part of the graph
if (StringUtils.isNotBlank(nonGraphProperties)) {
for (final String propertyName : nonGraphProperties.split("[, ]+")) {
if (SchemaHelper.isDynamic(entity.getClassName(), propertyName)) {
view.add(SchemaHelper.cleanPropertyName(propertyName + "Property"));
} else if (relPropertyNames.contains(propertyName)) {
view.add(SchemaHelper.cleanPropertyName(propertyName) + "Property");
} else if (basePropertyNames.contains(propertyName)) {
view.add(SchemaHelper.cleanPropertyName(propertyName));
} else {
logger.warn("Unknown property {} in non-graph properties, ignoring.", propertyName);
SchemaHelper.isDynamic(entity.getClassName(), propertyName);
}
}
}
final String order = schemaView.getProperty(SchemaView.sortOrder);
if (order != null) {
applySortOrder(view, order);
}
}
}
}
use of org.structr.core.entity.SchemaProperty in project structr by structr.
the class StructrNumberProperty method createDatabaseSchema.
@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
final PropertyMap properties = new PropertyMap();
properties.put(SchemaProperty.propertyType, Type.Double.name());
if (minimum != null && maximum != null) {
final StringBuilder range = new StringBuilder();
if (exclusiveMinimum) {
range.append("]");
} else {
range.append("[");
}
range.append(minimum);
range.append(",");
range.append(maximum);
if (exclusiveMaximum) {
range.append("[");
} else {
range.append("]");
}
properties.put(SchemaProperty.format, range.toString());
}
property.setProperties(SecurityContext.getSuperUserInstance(), properties);
return property;
}
use of org.structr.core.entity.SchemaProperty in project structr by structr.
the class StructrPasswordProperty method createDatabaseSchema.
@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
final PropertyMap properties = new PropertyMap();
properties.put(SchemaProperty.propertyType, Type.Password.name());
properties.put(SchemaProperty.format, getFormat());
properties.put(SchemaProperty.contentType, getContentType());
property.setProperties(SecurityContext.getSuperUserInstance(), properties);
return property;
}
use of org.structr.core.entity.SchemaProperty in project structr by structr.
the class StructrStringArrayProperty method createDatabaseSchema.
@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
property.setProperty(SchemaProperty.propertyType, Type.StringArray.name());
return property;
}
use of org.structr.core.entity.SchemaProperty in project structr by structr.
the class StructrStringProperty method createDatabaseSchema.
@Override
SchemaProperty createDatabaseSchema(final App app, final AbstractSchemaNode schemaNode) throws FrameworkException {
final SchemaProperty property = super.createDatabaseSchema(app, schemaNode);
final PropertyMap properties = new PropertyMap();
properties.put(SchemaProperty.propertyType, Type.String.name());
properties.put(SchemaProperty.format, getFormat());
properties.put(SchemaProperty.contentType, getContentType());
property.setProperties(SecurityContext.getSuperUserInstance(), properties);
return property;
}
Aggregations