use of org.structr.core.property.Property in project structr by structr.
the class BulkFixNodePropertiesCommand method execute.
@Override
public void execute(Map<String, Object> attributes) throws FrameworkException {
final String propertyName = (String) attributes.get("name");
final String entityTypeName = (String) attributes.get("type");
if (entityTypeName != null) {
final Class type = SchemaHelper.getEntityClassForRawType(entityTypeName);
if (type != null) {
final DatabaseService db = StructrApp.getInstance(securityContext).getDatabaseService();
final NodeFactory factory = new NodeFactory(securityContext);
final Iterator<AbstractNode> nodeIterator = Iterables.map(factory, db.getNodesByLabel(entityTypeName)).iterator();
logger.info("Trying to fix properties of all {} nodes", type.getSimpleName());
long nodeCount = bulkGraphOperation(securityContext, nodeIterator, 100, "FixNodeProperties", new BulkGraphOperation<AbstractNode>() {
private void fixProperty(AbstractNode node, Property propertyToFix) {
Node databaseNode = node.getNode();
if (databaseNode.hasProperty(propertyToFix.dbName())) {
// check value with property converter
PropertyConverter converter = propertyToFix.databaseConverter(securityContext, node);
if (converter != null) {
try {
Object value = databaseNode.getProperty(propertyToFix.dbName());
converter.revert(value);
} catch (ClassCastException cce) {
// exception, needs fix
String databaseName = propertyToFix.dbName();
Object databaseValue = databaseNode.getProperty(databaseName);
Object correctedValue = propertyToFix.fixDatabaseProperty(databaseValue);
if (databaseValue != null && correctedValue != null) {
try {
// try to set database value to corrected value
databaseNode.setProperty(databaseName, correctedValue);
} catch (Throwable t) {
logger.warn("Unable to fix property {} of {} with UUID {} which is of type {}", new Object[] { propertyToFix.dbName(), type.getSimpleName(), node.getUuid(), databaseValue != null ? databaseValue.getClass() : "null" });
}
}
} catch (Throwable t) {
// log exceptions of other types
logger.warn("", t);
}
}
}
}
@Override
public void handleGraphObject(SecurityContext securityContext, AbstractNode node) {
if (propertyName != null) {
PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(type, propertyName);
if (key != null) {
// needs type cast to Property to use fixDatabaseProperty method
if (key instanceof Property) {
fixProperty(node, (Property) key);
}
}
} else {
for (PropertyKey key : node.getPropertyKeys(PropertyView.All)) {
// needs type cast to Property to use fixDatabaseProperty method
if (key instanceof Property) {
fixProperty(node, (Property) key);
}
}
}
}
});
logger.info("Fixed {} nodes", nodeCount);
return;
}
}
logger.info("Unable to determine property and/or entity type to fix.");
}
use of org.structr.core.property.Property in project structr by structr.
the class DOMElement method updateFromNode.
public static void updateFromNode(final DOMElement node, final DOMNode newNode) throws FrameworkException {
if (newNode instanceof DOMElement) {
final PropertyKey<String> tagKey = StructrApp.key(DOMElement.class, "tag");
final PropertyMap properties = new PropertyMap();
for (Property htmlProp : node.getHtmlAttributes()) {
properties.put(htmlProp, newNode.getProperty(htmlProp));
}
// copy tag
properties.put(tagKey, newNode.getProperty(tagKey));
node.setProperties(node.getSecurityContext(), properties);
}
}
use of org.structr.core.property.Property in project structr by structr.
the class ImportGPXFunction method readProperties.
private void readProperties(final Element child, final GraphObjectMap item) {
final String tagName = child.getTagName();
final Property property = fieldMapping.get(tagName);
if (property != null) {
final Class valueType = property.valueType();
if (valueType != null) {
switch(valueType.getSimpleName()) {
case "Double":
storeDouble(child, item, property);
break;
case "String":
storeString(child, item, property);
break;
case "Integer":
storeInt(child, item, property);
break;
}
}
} else {
if ("author".equals(tagName)) {
final GraphObjectMap author = readPoint(child);
if (!author.isEmpty()) {
item.put(authorProperty, author);
}
}
}
}
Aggregations