Search in sources :

Example 51 with PropertyMap

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();
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) DatabaseService(org.structr.api.DatabaseService) LinkedList(java.util.LinkedList) PropertyMap(org.structr.core.property.PropertyMap) LinkedList(java.util.LinkedList) List(java.util.List) ShadowDocument(org.structr.web.entity.dom.ShadowDocument) DOMNode(org.structr.web.entity.dom.DOMNode)

Example 52 with PropertyMap

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Image(org.structr.web.entity.Image) MagicMatch(net.sf.jmimemagic.MagicMatch)

Example 53 with PropertyMap

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;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap)

Example 54 with PropertyMap

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) SchemaMethodParameter(org.structr.core.entity.SchemaMethodParameter)

Example 55 with PropertyMap

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;
}
Also used : SchemaProperty(org.structr.core.entity.SchemaProperty) PropertyMap(org.structr.core.property.PropertyMap)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15