use of org.structr.web.entity.AbstractFile in project structr by structr.
the class FileImportVisitor method handleDeferredFiles.
public void handleDeferredFiles() {
final Class<Relation> relType = StructrApp.getConfiguration().getRelationshipEntityClass("AbstractMinifiedFileMINIFICATIONFile");
final PropertyKey<Integer> positionKey = StructrApp.key(relType, "position");
if (!this.deferredFiles.isEmpty()) {
for (File file : this.deferredFiles) {
try (final Tx tx = app.tx(true, false, false)) {
// set properties from files.json
final PropertyMap fileProperties = getPropertiesForFileOrFolder(file.getPath());
final PropertyKey<Map<String, String>> sourcesPropertyKey = new GenericProperty("minificationSources");
Map<String, String> sourcesConfig = fileProperties.get(sourcesPropertyKey);
fileProperties.remove(sourcesPropertyKey);
file.unlockSystemPropertiesOnce();
file.setProperties(securityContext, fileProperties);
for (String positionString : sourcesConfig.keySet()) {
final Integer position = Integer.parseInt(positionString);
final String sourcePath = sourcesConfig.get(positionString);
final AbstractFile source = FileHelper.getFileByAbsolutePath(securityContext, sourcePath);
if (source != null) {
app.create(app.get(AbstractMinifiedFile.class, file.getUuid()), (File) source, relType, new PropertyMap(positionKey, position));
} else {
logger.warn("Source file {} for minified file {} at position {} not found - please verify that it is included in the export", sourcePath, file.getPath(), positionString);
}
}
tx.success();
} catch (FrameworkException fxe) {
}
}
}
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class PathProperty method searchRecursively.
private void searchRecursively(final App app, final Folder parent, final SourceSearchAttribute attr, final ArrayList<String> parts) throws FrameworkException {
final String currentPart = parts.remove(0);
final List<AbstractFile> res = app.nodeQuery(AbstractFile.class).and(StructrApp.key(AbstractFile.class, "parent"), (parent == null) ? null : parent).and(AbstractFile.name, currentPart).getAsList();
if (parts.isEmpty()) {
for (final AbstractFile fileOrFolder : res) {
attr.addToResult(fileOrFolder);
}
} else {
for (final AbstractFile folder : res) {
searchRecursively(app, (Folder) folder, attr, (ArrayList<String>) parts.clone());
}
}
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class SSHTest method createFTPFile.
protected File createFTPFile(final String path, final String name) throws FrameworkException {
PropertyMap props = new PropertyMap();
props.put(StructrApp.key(File.class, "name"), name);
props.put(StructrApp.key(File.class, "size"), 0L);
props.put(StructrApp.key(File.class, "owner"), ftpUser);
File file = (File) createTestNodes(File.class, 1, props).get(0);
if (StringUtils.isNotBlank(path)) {
AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
if (parent != null && parent instanceof Folder) {
Folder parentFolder = (Folder) parent;
file.setParent(parentFolder);
}
}
logger.info("FTP file {} created successfully.", file);
return file;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class SSHTest method createFTPDirectory.
protected Folder createFTPDirectory(final String path, final String name) throws FrameworkException {
PropertyMap props = new PropertyMap();
props.put(Folder.name, name);
props.put(Folder.owner, ftpUser);
Folder dir = (Folder) createTestNodes(Folder.class, 1, props).get(0);
if (StringUtils.isNotBlank(path)) {
AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
if (parent != null && parent instanceof Folder) {
Folder parentFolder = (Folder) parent;
dir.setParent(parentFolder);
}
}
logger.info("FTP directory {} created successfully.", dir);
return dir;
}
use of org.structr.web.entity.AbstractFile in project structr by structr.
the class FileOrFolder method mkdir.
@Override
public boolean mkdir() {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
logger.info("mkdir() Folder");
AbstractFile existing = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newPath);
if (existing != null) {
logger.warn("File {} already exists.", newPath);
return false;
}
final Folder parentFolder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, StringUtils.substringBeforeLast(newPath, "/"));
try {
Folder newFolder = (Folder) app.command(CreateNodeCommand.class).execute(new NodeAttribute(AbstractNode.type, Folder.class.getSimpleName()), new NodeAttribute(AbstractNode.owner, owner.getStructrUser()), new NodeAttribute(AbstractNode.name, getName()));
if (parentFolder != null) {
newFolder.setParent(parentFolder);
}
} catch (FrameworkException ex) {
logger.error("", ex);
return false;
}
tx.success();
return true;
} catch (FrameworkException ex) {
logger.error("", ex);
return false;
}
}
Aggregations