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;
}
}
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);
}
Aggregations