Search in sources :

Example 16 with Relation

use of org.structr.core.entity.Relation in project structr by structr.

the class JarConfigurationProvider method findNearestMatchingRelationClass.

/**
 * Find the most specialized relation class matching the given
 * parameters.
 *
 * If no direct match is found (source and target type are equal), we
 * count the levels of inheritance, including interfaces.
 *
 * @param sourceTypeName
 * @param relType
 * @param targetTypeName
 * @param rel
 * @param candidate
 * @return class
 */
private Class findNearestMatchingRelationClass(final String sourceTypeName, final String relType, final String targetTypeName) {
    final Class sourceType = getNodeEntityClass(sourceTypeName);
    final Class targetType = getNodeEntityClass(targetTypeName);
    final Map<Integer, Class> candidates = new TreeMap<>();
    for (final Class candidate : getRelationClassCandidatesForRelType(relType)) {
        final Relation rel = instantiate(candidate);
        final int distance = getDistance(rel.getSourceType(), sourceType, -1) + getDistance(rel.getTargetType(), targetType, -1);
        if (distance >= 2000) {
            candidates.put(distance - 2000, candidate);
        }
    }
    if (candidates.isEmpty()) {
        return null;
    } else {
        final Entry<Integer, Class> candidateEntry = candidates.entrySet().iterator().next();
        final Class c = candidateEntry.getValue();
        combinedTypeRelationClassCache.put(getCombinedType(sourceTypeName, relType, targetTypeName), c);
        return c;
    }
}
Also used : Relation(org.structr.core.entity.Relation) TreeMap(java.util.TreeMap)

Example 17 with Relation

use of org.structr.core.entity.Relation in project structr by structr.

the class DeployCommand method exportFileConfiguration.

private void exportFileConfiguration(final AbstractFile abstractFile, final Map<String, Object> config) {
    if (abstractFile.isVisibleToPublicUsers()) {
        putIf(config, "visibleToPublicUsers", true);
    }
    if (abstractFile.isVisibleToAuthenticatedUsers()) {
        putIf(config, "visibleToAuthenticatedUsers", true);
    }
    if (abstractFile instanceof File) {
        final File file = (File) abstractFile;
        if (file.isTemplate()) {
            putIf(config, "isTemplate", true);
        }
    }
    putIf(config, "type", abstractFile.getProperty(File.type));
    putIf(config, "contentType", abstractFile.getProperty(StructrApp.key(File.class, "contentType")));
    putIf(config, "cacheForSeconds", abstractFile.getProperty(StructrApp.key(File.class, "cacheForSeconds")));
    putIf(config, "useAsJavascriptLibrary", abstractFile.getProperty(StructrApp.key(File.class, "useAsJavascriptLibrary")));
    putIf(config, "includeInFrontendExport", abstractFile.getProperty(StructrApp.key(File.class, "includeInFrontendExport")));
    putIf(config, "basicAuthRealm", abstractFile.getProperty(StructrApp.key(File.class, "basicAuthRealm")));
    putIf(config, "enableBasicAuth", abstractFile.getProperty(StructrApp.key(File.class, "enableBasicAuth")));
    if (abstractFile instanceof Image) {
        final Image image = (Image) abstractFile;
        putIf(config, "isThumbnail", image.isThumbnail());
        putIf(config, "isImage", image.isImage());
        putIf(config, "width", image.getWidth());
        putIf(config, "height", image.getHeight());
    }
    if (abstractFile instanceof AbstractMinifiedFile) {
        if (abstractFile instanceof MinifiedCssFile) {
            final MinifiedCssFile mcf = (MinifiedCssFile) abstractFile;
            putIf(config, "lineBreak", mcf.getLineBreak());
        }
        if (abstractFile instanceof MinifiedJavaScriptFile) {
            final MinifiedJavaScriptFile mjf = (MinifiedJavaScriptFile) abstractFile;
            putIf(config, "optimizationLevel", mjf.getOptimizationLevel());
        }
        final Class<Relation> relType = StructrApp.getConfiguration().getRelationshipEntityClass("AbstractMinifiedFileMINIFICATIONFile");
        final PropertyKey<Integer> positionKey = StructrApp.key(relType, "position");
        final Map<Integer, String> minifcationSources = new TreeMap<>();
        for (Relation minificationSourceRel : AbstractMinifiedFile.getSortedRelationships((AbstractMinifiedFile) abstractFile)) {
            final File file = (File) minificationSourceRel.getTargetNode();
            minifcationSources.put(minificationSourceRel.getProperty(positionKey), file.getPath());
        }
        putIf(config, "minificationSources", minifcationSources);
    }
    // export all dynamic properties
    for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(abstractFile.getClass(), PropertyView.All)) {
        // only export dynamic (=> additional) keys
        if (!key.isPartOfBuiltInSchema()) {
            putIf(config, key.jsonName(), abstractFile.getProperty(key));
        }
    }
    exportOwnershipAndSecurity(abstractFile, config);
}
Also used : Image(org.structr.web.entity.Image) TreeMap(java.util.TreeMap) MinifiedCssFile(org.structr.web.entity.MinifiedCssFile) Relation(org.structr.core.entity.Relation) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) MinifiedJavaScriptFile(org.structr.web.entity.MinifiedJavaScriptFile) AbstractFile(org.structr.web.entity.AbstractFile) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) MinifiedCssFile(org.structr.web.entity.MinifiedCssFile) File(org.structr.web.entity.File) MinifiedJavaScriptFile(org.structr.web.entity.MinifiedJavaScriptFile) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

Relation (org.structr.core.entity.Relation)17 FrameworkException (org.structr.common.error.FrameworkException)7 App (org.structr.core.app.App)6 StructrApp (org.structr.core.app.StructrApp)6 PropertyMap (org.structr.core.property.PropertyMap)5 PropertyKey (org.structr.core.property.PropertyKey)4 LinkedList (java.util.LinkedList)3 GraphObject (org.structr.core.GraphObject)3 GraphObjectMap (org.structr.core.GraphObjectMap)3 RestMethodResult (org.structr.rest.RestMethodResult)3 Image (org.structr.web.entity.Image)3 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 SecurityContext (org.structr.common.SecurityContext)2 Result (org.structr.core.Result)2 AbstractNode (org.structr.core.entity.AbstractNode)2 NodeInterface (org.structr.core.graph.NodeInterface)2 Tx (org.structr.core.graph.Tx)2