use of org.structr.web.entity.AbstractFile in project structr by structr.
the class CMISNavigationService method getFolderParent.
@Override
public ObjectData getFolderParent(final String repositoryId, final String folderId, final String propertyFilter, final ExtensionsData extension) {
final App app = StructrApp.getInstance();
ObjectData result = null;
try (final Tx tx = app.tx()) {
final AbstractFile graphObject = app.get(AbstractFile.class, folderId);
if (graphObject != null) {
final Folder parent = graphObject.getParent();
if (parent != null) {
result = CMISObjectWrapper.wrap(parent, propertyFilter, false);
}
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
if (result != null) {
return result;
}
return null;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class CMISNavigationService method getChildrenQuery.
public Query<AbstractFile> getChildrenQuery(final App app, final String folderId) throws FrameworkException {
final Query<AbstractFile> query = app.nodeQuery(AbstractFile.class).sort(AbstractNode.name);
final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
query.and(hasParent, false).and(isThumbnail, false);
} else {
final Folder folder = app.get(Folder.class, folderId);
if (folder != null) {
query.and(parent, folder).and(isThumbnail, false);
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
return query;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class CMISObjectService method createFolder.
@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
String uuid = null;
try (final Tx tx = app.tx()) {
final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
// check if type exists
if (type != null) {
// check that base type is cmis:folder
final BaseTypeId baseTypeId = getBaseTypeId(type);
if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
// create folder
final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
// find and set parent if it exists
if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
final Folder parent = app.get(Folder.class, folderId);
if (parent != null) {
newFolder.setParent(parent);
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
uuid = newFolder.getUuid();
} else {
throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
}
} else {
throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
}
tx.success();
} catch (Throwable t) {
throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
}
return uuid;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class FileSyncWatchEventListener method handle.
// ----- private methods -----
private FolderAndFile handle(final Path root, final Path relativePath, final Path path, final boolean create) throws FrameworkException {
// identify mounted folder object
final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
final Folder folder = StructrApp.getInstance().nodeQuery(Folder.class).and(mountTargetKey, root.toString()).getFirst();
if (folder != null) {
final String mountFolderPath = folder.getProperty(StructrApp.key(Folder.class, "path"));
if (mountFolderPath != null) {
final Path relativePathParent = relativePath.getParent();
if (relativePathParent == null) {
return new FolderAndFile(folder, getOrCreate(folder, path, relativePath, create));
} else {
final String pathRelativeToRoot = folder.getPath() + "/" + relativePathParent.toString();
final Folder parentFolder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), pathRelativeToRoot);
final AbstractFile file = getOrCreate(parentFolder, path, relativePath, create);
return new FolderAndFile(folder, file);
}
} else {
logger.warn("Cannot handle watch event, folder {} has no path", folder.getUuid());
}
}
return null;
}
use of org.structr.web.entity.AbstractFile 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