use of org.structr.core.property.PropertyMap in project structr by structr.
the class UiSyncCommand method doImport.
private void doImport(final String fileName) throws FrameworkException {
final App app = StructrApp.getInstance();
final DatabaseService graphDb = app.getDatabaseService();
SyncCommand.importFromFile(graphDb, securityContext, fileName, true);
// import done, now the ShadowDocument needs some special care. :(
try (final Tx tx = app.tx()) {
final List<ShadowDocument> shadowDocuments = app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getAsList();
if (shadowDocuments.size() > 1) {
final PropertyKey<List<DOMNode>> elementsKey = StructrApp.key(Page.class, "elements");
final List<DOMNode> collectiveChildren = new LinkedList<>();
// sort by node id (higher node ID is newer entity)
Collections.sort(shadowDocuments, new Comparator<ShadowDocument>() {
@Override
public int compare(final ShadowDocument t1, final ShadowDocument t2) {
return Long.valueOf(t2.getId()).compareTo(t1.getId());
}
});
final ShadowDocument previousShadowDoc = shadowDocuments.get(0);
final ShadowDocument newShadowDoc = shadowDocuments.get(1);
// collect children of both shadow documents
collectiveChildren.addAll(previousShadowDoc.getProperty(elementsKey));
collectiveChildren.addAll(newShadowDoc.getProperty(elementsKey));
// delete old shadow document
app.delete(previousShadowDoc);
// add children to new shadow document
newShadowDoc.setProperties(securityContext, new PropertyMap(elementsKey, collectiveChildren));
}
tx.success();
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class ImageConverter method convert.
// ~--- methods --------------------------------------------------------
@Override
public Object convert(final Object source) {
if (source == null) {
return false;
}
try {
Image img = null;
try {
if (source instanceof byte[]) {
byte[] data = (byte[]) source;
MagicMatch match = Magic.getMagicMatch(data);
String mimeType = match.getMimeType();
if (keyAndClass != null) {
img = (Image) ImageHelper.createFile(securityContext, data, mimeType, keyAndClass.getCls());
} else {
ImageHelper.setImageData((Image) currentObject, data, mimeType);
}
} else if (source instanceof String) {
String sourceString = (String) source;
if (StringUtils.isNotBlank(sourceString)) {
if (keyAndClass != null) {
// UUID?
if (sourceString.length() == 32) {
img = (Image) ImageHelper.transformFile(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);
}
if (img == null) {
img = (Image) ImageHelper.createFileBase64(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);
}
} else {
ImageHelper.decodeAndSetFileData((Image) currentObject, sourceString);
ImageHelper.updateMetadata((Image) currentObject);
}
}
}
} catch (Throwable t) {
logger.warn("Cannot create image node from given data", t);
}
if (img != null) {
// manual indexing of UUID needed here to avoid a 404 in the following setProperty call
img.updateInIndex();
currentObject.setProperties(securityContext, new PropertyMap(keyAndClass.getPropertyKey(), img));
}
} catch (Throwable t) {
logger.warn("Cannot create image node from given data", t);
}
return null;
}
use of org.structr.core.property.PropertyMap 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.property.PropertyMap in project structr by structr.
the class StructrParameterDefinition method createDatabaseSchema.
// ----- package methods -----
SchemaMethodParameter createDatabaseSchema(final App app, final SchemaMethod schemaMethod, final int index) throws FrameworkException {
final PropertyMap getOrCreateProperties = new PropertyMap();
final PropertyMap updateProperties = new PropertyMap();
getOrCreateProperties.put(SchemaMethodParameter.name, getName());
getOrCreateProperties.put(SchemaMethodParameter.schemaMethod, schemaMethod);
SchemaMethodParameter parameter = app.nodeQuery(SchemaMethodParameter.class).and(getOrCreateProperties).getFirst();
if (parameter == null) {
parameter = app.create(SchemaMethodParameter.class, getOrCreateProperties);
}
updateProperties.put(SchemaMethodParameter.parameterType, type);
updateProperties.put(SchemaMethodParameter.index, index);
// update properties
parameter.setProperties(SecurityContext.getSuperUserInstance(), updateProperties);
// return modified property
return parameter;
}
use of org.structr.core.property.PropertyMap 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;
}
Aggregations