Using liferay 6.2 api to insert images in document library. The code also moves images from one folder to another folder
But After moving the images their folders do not get guest view permissions and images can't be viewed.
I have two groups (sites) -
GroupA
GroupB
GroupA user creates folders, inserts files and also moves files.
GroupB user should be able to see the files.
All the folders and files are created under Global scope in document library.
public void moveFilesToFolder(final HttpServletRequest request, final List<DLFileEntry> filesToMove, final DLFolder toFolder)
throws Exception {
final ServiceContext sc = ServiceContextFactory.getInstance(request);
sc.setWorkflowAction(WorkflowConstants.STATUS_APPROVED);
sc.setAddGuestPermissions(true);
sc.setAddGroupPermissions(true);
for (final DLFileEntry file : filesToMove) {
DLAppServiceUtil.moveFileEntry(file.getFileEntryId(), toFolder.getFolderId(), sc)
}
// update folders to have guest permissions
DLAppLocalServiceUtil.updateFolder(toFolder.getFolderId(), toFolder.getParentFolderId(), toFolder.getName(),
toFolder.getDescription(), sc);
}
This doesn't seem to work and guest permissions are not set for all the users. The weird behavior is that when the user who performed the move operation looks at the permissions from UI, gues view permission is checked but for any other user the permission is not checked.
As per suggestions below I have used DLAppServiceUtil to move files. But It doesnt change status of file to approved from draft.
Also what is the correct method to use to copy files? There is no method in DLAppServiceUtil to copy files from one folder to another
Anybody knows how to solve this issue?
Using DLAppLocalServiceUtil and DLFileEntryServiceUtil is not the right way. Thery bypass permissions updating and right repository managment.
Use DLAppServiceUtil instead to move and to update.
Related
I have a doubt, how I can delete a folder on Android 11 (or 10)?
Have much answers here on Stack how to do it, but nothing of worked.
This code worked for me on Android 5:
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
On newest versions of Android it not work. I noticed that there are applications that can to do this, so I imagine it is possible. Any answer about it?
Android has done much to change its permission models around file access since Android 10 and 11. The preferred approach is to use Scoped Storage APIs.
Many of the old file read/write permissions are on life support and will no longer work. If they do continue to work, then must justify to Google why you need them, and then go through a security approval by Google. You will only be granted approval if you app is classified as a file browser application, or the like.
Basically, the new model is to use Android's file browsers to gain access to read/write/update a particular file that the user selects, and defer the rest of the file management to Google's first-party applications. The access you get is based on what the user selected in the first-party file browser. You are then handed a URI back to your application with the proper permissions to perform the intended action, such as read/write/etc...
You may find this video useful:
https://www.youtube.com/watch?v=RjyYCUW-9tY
Have you tried Context.deleteFile() ?
getApplicationContext().deleteFile(filename);
Android 11,
I'm trying to create a publicly accessible folder I can store my media files within, which will contain 1 folder and 1 text file per game type (there could be many), I do not want any other application to have access to the root folder for the exception of file explorers, as the user 'could' have content inside the folder that is R18 restricted or might not, I'm not in control of what content goes in there, it would be nice if I could provide that so that a child doesn't in mistakenly bump into the content while looking for pictures on the device for barnie.
I found some code on GitHub that did just the above on Android 10 and works flawlessly for Android 10, but cannot find anything but blue pills about it when it comes to Android 11, help in the form of example code would be great, yes I know targeting only Android 11 limits me but I'd rather live with the limit than play with many different versions of code.
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
}
startActivityForResult(intent, OPEN_FOLDER_REQUEST_CODE)
EDIT 2
After some hacking around, because 'startActivityForResult(Intent!, Int): Unit' is deprecated. Deprecated in Java, I end up with this, results is a URI, can I now use this to pass files to other API calls now?
pref = getSharedPreferences("myPref", Context.MODE_PRIVATE)
var userFolderData: String? = pref.getString("userFolderData", "")
if (userFolderData=="") {
val getUserFolderData =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
mytools.debug(it.toString())
pref.edit().putString("userFolderData",it.toString()).apply()
userFolderData = it.toString()
}
getUserFolderData.launch("".toUri())
}
mytools.debug("userFolderData = ${userFolderData}")
EDIT 3
So I ran a test on the URI returned; always the same story not matter what I do, yes that's pretty ugly hack but it's the easiest way I can find to test it.
ivtitleimage.setImageURI("content://com.android.externalstorage.documents/document/primary%3ATest%2FMelsDeck%2Fbendover01.jpg".toUri())
31833-31833/com.example.cardgamexxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cardgamexxx, PID: 31833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cardgamexxx/com.example.cardgamexxx.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{5a390cf 31833:com.example.cardgamexxx/u0a741} (pid=31833, uid=10741) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
EDIT 4
Right, so user selects folder/creates one with registerForActivityResult code above, I place files in it with Cx File Explorer and automagically drum roll! ...
I do not have read access to the file placed there, anyway thought I'd comment here as I don't want people stumbling on the post and thinking this works, because it doesn't.
On an Android 11 device your app can only create folders on root of external storage in the classic way if it has requested 'all files acces'.
Or it can use Storage Access Framework and for instance ACTION_OPEN_DOCUMENT_TREE to let the user create a folder in root of external storage and then select it.
When a java program executes, it creates a file in the directory that the program is located, I want the user to be able to dictate directory.Is it possible to do this? My intentions for the code are in the comments.Read the comments. This is not a duplicate because I also ask if changing the directory in the batch will change the directory that the java program executes in.
public static void main(String[] args) {
//open and run batch to navigate to desired directory
//conditional tests to see if in desired directory and then backs up using cd ..
//get input,batch file navigates to the directory that was entered
sozdatNovyFayl(getFileName());
//get name,create file,(self defined functions, already implemented)
}
Could somebody point me in the right direction on how to implement this. Is it possible to change the directory that application is working in from the one where it exists?
I have an Eclipse RCP application for which I need to create a file browser view. I want to pass it a root (some location on the local computer) and the view should populate all the files and folders at that location. Currently I am using CNF in my view hence,
public class CurrDirExplorerView extends CommonNavigator
I have overriden the getInitialInput() to return a custom root object which contains a directory path in it. I am using java.io.File since IResources are linked to the workspace. I have created an element object which is like a wrapper class for the java.io.File and returns the name etc for supporting the label and content providers. My view displays all the folders and files at the location specified in my root object but since they are not IResources, when I double-click on a file, it does not open up in the editor.
Is there any way to do this?
CommonNavigator has a protected method:
protected void handleDoubleClick(DoubleClickEvent anEvent);
unfortunatelly its javadoc says "This method is for internal use only", however still avail if there is no better option.
Other way would be: getCommonViewer(), which has addDoubleClickListener() and you will be able to define your own logic for handling doubleclick. Hope this helps.
There is a global Preference (see picture) that is used by the Navigator. If you want to preset this preference you have to set the preference key (boolean) OPEN_ON_SINGLE_CLICK in the preferencestore of bundle org.eclipse.ui.workbench
We are using NetBeans Platform 7.0.1, and have implemented support for a new language using this (now “obsolete”) tutorial.
Since all our contents are stored in a database, and not on files, we open them like this:
FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject fo = fs.getRoot().createData(fileName, fileExtension);
… write contents from database to `fo` ….
DataObject data = MyMultiDataObject.find(fo);
EditorCookie.Observable cookie = data.getCookie(EditorCookie.Observable.class);
cookie.open();
… forces undock of editor window …
And, in our layer.xml, have added a custom button to Save that sends the content back to the database.
However, when the user closes the file (by either closing the tab or the window), we haven’t figured a way of saving it.
Adding a PropertyChangeListener to the Cookie and watching for PROP_DOCUMENT (and newValue() == null) seems to do the trick for when the window is closed. But how does one get the return value from the confirmation window (I’m referring to when the file is closed after changes, the message File xxx.xxx is modified. Save it?)?
Well, it seems we've been approaching the problem in the wrong way.
Since we are opening the file in-memory, it was suggested in the netbeans-dev list that we should listen for changes in the file itself, by using
fo.addFileChangeListener(new CustomFileChangeListener());
public class CustomFileChangeListener implements FileChangeListener {
#Override
public void fileChanged(FileEvent fe) {
... file has been saved in the editor, sync with database ...
}
}
And keep it synchronized that way, taking advantage of the built-in NetBeans Platform "save" functionality.