use of org.structr.core.app.App in project structr by structr.
the class CMISObjectService method getContentStream.
@Override
public ContentStream getContentStream(final String repositoryId, final String objectId, final String streamId, final BigInteger offset, final BigInteger length, final ExtensionsData extension) {
final App app = StructrApp.getInstance();
ContentStreamImpl result = null;
try (final Tx tx = app.tx()) {
final File file = app.get(File.class, objectId);
if (file != null) {
return new CMISContentStream(file, offset, length);
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
if (result != null) {
return result;
}
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
use of org.structr.core.app.App in project structr by structr.
the class CMISObjectService method getObjectByPath.
@Override
public ObjectData getObjectByPath(final String repositoryId, final String path, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
final App app = StructrApp.getInstance();
ObjectData result = null;
try (final Tx tx = app.tx()) {
final AbstractFile file = app.nodeQuery(AbstractFile.class).and(pathKey, path).getFirst();
if (file != null) {
result = CMISObjectWrapper.wrap(file, propertyFilter, includeAllowableActions);
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
if (result != null) {
return result;
}
throw new CmisObjectNotFoundException("Object with path " + path + " does not exist");
}
use of org.structr.core.app.App in project structr by structr.
the class CMISObjectService method bulkUpdateProperties.
@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, final List<BulkUpdateObjectIdAndChangeToken> objectIdsAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, final ExtensionsData extension) {
final List<BulkUpdateObjectIdAndChangeToken> result = new LinkedList<>();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
for (final BulkUpdateObjectIdAndChangeToken token : objectIdsAndChangeTokens) {
final AbstractNode obj = app.get(AbstractNode.class, token.getId());
if (obj != null) {
final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
if (propertyMap != null) {
obj.setProperties(securityContext, propertyMap);
}
result.add(token);
}
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
return result;
}
use of org.structr.core.app.App in project structr by structr.
the class CMISObjectService method deleteObject.
@Override
public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final Principal principal = securityContext.getUser(false);
final AbstractNode obj = app.get(AbstractNode.class, objectId);
if (obj != null) {
if (principal.isGranted(Permission.delete, securityContext)) {
if (obj.isNode()) {
// getSyncNode() returns the node or null
app.delete(obj.getSyncNode());
} else {
// getSyncRelationship() return the relationship or null
app.delete(obj.getSyncRelationship());
}
} else {
throw new CmisPermissionDeniedException("Cannot delete object with ID " + objectId);
}
} else {
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
}
use of org.structr.core.app.App in project structr by structr.
the class DirectoryWatchService method startService.
@Override
public void startService() throws Exception {
try {
final Path dir = Paths.get(Settings.FilesPath.getValue());
this.watchService = dir.getFileSystem().newWatchService();
logger.info("Watch service successfully registered");
} catch (IOException ioex) {
ioex.printStackTrace();
}
final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx(false, false, false)) {
// find all folders with mount targets and mount them
for (final Folder folder : app.nodeQuery(Folder.class).notBlank(mountTargetKey).getAsList()) {
mountFolder(folder);
}
tx.success();
}
running = true;
this.start();
}
Aggregations