spamModerationLevel in Google java api - java

So I'm lookign into ways to edit some of less visible setting s on a google group, in specific the one found in:
Access Settings > Settings > Moderation > Spam Messages
This setting is what I believe is spamModerationLevel in the Group settings api.
I've tested changing other settings with the same code sucesfully, but that particular attribute does not change.
This works:
DirectoryUtils client = new DirectoryUtils(); //class with my google api methods
Directory directory = client.getDirectory(); //directory instance
Group group = client.retrieveGroup(directory, "api-test"); //api-test being the group I'm testing with
group.set("name", "Testing name change");
Group modified = directory.groups().update(group.getEmail(), group).execute();
With that my group name changes with no problems. For testing the set() method I didnt use the api's setName() which does the same but now I know set() works. Now if i try this:
group.set("spamModerationLevel", "ALLOW");
Group modified = directory.groups().update(group.getEmail(), group).execute();
The group stays the same with no change to the settings I was looking to change.
I've noticed during debugging, the "group" variable has an added spamModerationLevel attribute after the set() command but when execute() returns teh group as "modified", it looks the same as "group" before the change.
Is there a way to do this change through the API that I'm missing?
Thanks,
Stephen

Related

How to enable the Barcode recognization in Abbyy Fine Reader Engine 12?

Barcode recognition is disabled by default in Abbyy Fine Reader Engine 12.
In order to enable it, I need to set the DetectBarcodes property of the PageAnalysisParams Object to TRUE.
Can anyone please help me, how can I set this property true in my java code sdk?
This is the property which we have to set:
public native void setDetectBarcodes(boolean arg0);
How can we call the native function from the java code?
Because calling directly with the object it is giving error.
Error: The local variable pageAnalysisParams may not have been initializedJava(536870963)
To get/initalize an instance of IPageAnalysisParams you can:
IPageAnalysisParams pageAnalysisParams = engine.CreatePageAnalysisParams();
You can also obtain an instance from "document processing params", like:
IDocumentProcessingParams documentparams = engine.CreateDocumentProcessingParams();
IPageAnalysisParams pageAnalysisParams = documentparams.getPageProcessingParams().getPageAnalysisParams();
source: https://github.com/search?q=IPageAnalysisParams&type=code
Looking at the public code samples, you should:
Obtain an instance of IDocumentProcessingParams (dpParams).
Tune that object (and sub-objects(page analysis params)).
And pass that to: document.Process(dpParams);
As #xerx593 suggested, programatically tuning document processing params is a perfectly valid answer.
Another valid answer is to use a configuration file, for example custom_barcode_profile.ini, and fill it according to your needs. This allows you to have better control and readibility over your profiles:
...
[PageAnalysisParams]
DetectBarcodes = TRUE
...
Use your ABBYY SDK documentation and/or ABBYY java wrapper classes to fine tune other parameters, then instead of using document.Process(dpParams);, instantiate an engine object and pass your custom_barcode_profile.ini file to it:
IEngine engine = Engine.InitializeEngine(<your sdk & license params>);
engine.LoadProfile("custom_barcode_profile.ini");
IFRDocument document = engine.CreateFRDocument();
document.AddImageFile("document.png", null, null);
document.Process(null);
document.Export("result.xml", FileExportFormatEnum.FEF_XML, null);
You cannot programatically "mix" multiple predefined profiles into one, you need to add parameters to a custom profile or even create another one and pass it to your engine object.
To enable table detection in the profile we defined later, look for parameters that affects table detection in the documentation, such as DetectTables, and add it to your custom profile:
...
[PageAnalysisParams]
DetectBarcodes = TRUE
DetectTables = TRUE
...

How to list all root folder and shares on the Google Drive API v3 while paging and using order by?

I've seen a few questions about this but none cover my scenario.
Basically what I want is to use tokens to do paging and also list all folders and files in the root folder including shared files and folders.
This appears to be working, but once I add orderBy it doesn't work well. It works ok with sorting if I remove or sharedWithMe = true but once I add it it like the shared items aren't sorted.
What am I doing wrong?
This is my code (Kotlin and on Android):
val response =
gDriveClient.files()
.list()
.setSpaces("drive")
.setCorpora("user")
.setFields("files(id, name, size, modifiedTime, mimeType, parents, quotaBytesUsed),nextPageToken")
.setQ("('root' in parents or sharedWithMe = true) and trashed = false")
.setOrderBy("folder,name")
.setPageSize(params.loadSize)
.setPageToken(token)
Unfortunately, the behaviour you are experiencing seems to be a bug as your query and request is formatted correctly and necessary to obtain exactly what you were looking for. I have reported this behaviour here : https://issuetracker.google.com/issues/174476354 . Please consider starring the report to indicate that this is also affecting you.
Workaround
A possible workaround to this would be to order and filter your response after the request has been executed which unfortunately will not let you perform the request with pagination for your specific purpose (as for ordering everything you would need all the files).
References
Drive.Files.list()
Query parameter sharedWithMe

Set user and group rights to document in XWiki

I'm writing a java component which build all the pages in a wiki. What would be the best way to assign the user rights or groups which may view the page or spaces from within the java service component?
Really struggling to find details on this in the API.
You are finding no details in the API, because the Rights API is only about reading rights information, not setting rights
If you want to set permissions on pages programatically, and you can assume that the default permission handler is in place (which both the UI and the code to create new users in XWiki does, so it seems not too unreasonbale), you can create them as objects in the pages.
Permissions are set by adding objects of type "XWiki.XWikiRights" to the pages
these objects have the following attributes:
groups : a string containing a comma separated list of group references (e.g. XWiki.XWikiAdminGroup,XWiki.XWikiAllGroup for the default admin and "all members" group)
users : a string containing a comma separated list of user references (e.g. xwiki:XWiki.Admin,XWiki.Admin would describe the main wiki admin and the "Admin" account in the local wiki
levels : a string containing a comma separated list of permissions who ate affected by this entry, e.g. view,comment,edit
allow : an integer which should have two values: 1 means the entry is an "allow this right", 0 means it is a "deny these rights"
The groups and users fields can be empty, though usually one of them is filled with data. The levels and allow must be set with some values.
One example how a permission is set on a page is the (internal) method XWiki.protectUserPage which sets the permissions on a newly create user in the way this user can edit ones one profile page:
public void protectUserPage(String userName, String userRights, XWikiDocument doc, XWikiContext context)
throws XWikiException
{
DocumentReference rightClassReference = getRightsClass(context).getDocumentReference();
EntityReference relativeRightClassReference =
rightClassReference.removeParent(rightClassReference.getWikiReference());
// Allow users to edit their own profiles
BaseObject newuserrightsobject = doc.newXObject(relativeRightClassReference, context);
newuserrightsobject.setLargeStringValue("users", userName);
newuserrightsobject.setStringValue("levels", userRights);
newuserrightsobject.setIntValue("allow", 1);
}
Here the first few lines are slightly more complicated to make sure the XWiki.XWikiRights class page is present and properly initialized; without harm you should be able to do something simpler like:
BaseObject newrightsobject = doc.newObject("XWiki.XWikiRights", context);
The userRights is usually edit here (it was only that while looking for the code that I found out this is actually configurable ...); userName is the full name of the users profile page here (e.g XWiki.NewUser)
The actual full code can be viewed at github e.g. for the 7.2 release:
https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-7.2/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/XWiki.java#L3366
Finally to distinguish between rights only given to a specific page, and rights given to a page and all its subpages: if you want a rights object to be valid for subpages, too, do not add it to the page itself, but create a special subpage with name WebPreferences and add an object of type XWiki.XWikiGlobalRights (with the same fields) to that page.
Some further pointers:
for more details how the access rights work, see http://platform.xwiki.org/xwiki/bin/view/AdminGuide/Access+Rights especially the reference section: "An overview of permissions"
If you have installed the "Admin Tools" extension, you can view the "ShowRights" page to see all right objects in you wiki.

Creating Roles Programmatically for each User Group

I want to create a Role for each User Group within my portal so that I can grant specific access to many users at once, depending on what groups they belong to.
Using Liferay API, is there any way to programmatically add a Role for each User Group that exists within the Portal?
This would be more efficient than adding each role individually through the UI.
Something like
for(i = 0; i < userGroups.size(); i++){
roles.add(userGroups[i].getName());
}
If possible, I'd like to then assign the same User Group to that Role within the same method, otherwise the role would know nothing of the associated user group:
roles.assignUserGroup(userGroups[i]);
Anyone accomplished a task similar to this?
Linked Liferay Forum Post http://liferay.com/community/forums/-/message_boards/message/46355079
In short you need to create a Role with a similar name as that of the UserGroups you have and then assign the UserGroup to that Role.
You can do that programmatically with Liferay's API, since that is how liferay also creates the different types of Roles and assigns users, user-groups etc to the role.
You just need to dig into to the source code to do this. Check source code for RoleLocalServiceImpl, UserGroupLocalServiceImpl and GroupLocalServiceImpl.
I am providing the steps for Liferay v6.2, there should not be much change in 6.0 and 6.1:
Fetch all the UserGroups using UserGroupLocalServiceUtil.getUserGroups(companyId)
Loop through it as you have done:
for (UserGroup userGroup : userGroups) {
... // steps to follow
}
Get the name of the UserGroup: userGroup.getName()
Create a Role using RoleLocalServiceUtil.addRole( ... ) and assign the userGroup to role using GroupLocalServiceUtil.addRoleGroups( ... )
for (UserGroup userGroup : userGroups) {
String userGroupName = userGroup.getName();
// for locale specific title (optional, can be null)
Map<Locale, String> titleMap = new HashMap<Locale, String>();
titleMap.put(Locale.ENGLISH, userGroupName);
// for locale specific description (optional, can be null)
Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
titleMap.put(Locale.ENGLISH, "Role created for UserGroup - " + userGroupName);
int type = RoleConstants.TYPE_REGULAR;
// adding the role
Role role = RoleLocalServiceUtil.addRole(userId, Role.class.getName(), 0, userGroupName, titleMap, descriptionMap, type, null, null);
// assigning the UserGroup to the role
GroupLocalServiceUtil.addRoleGroups(role.getRoleId(), new long[]{userGroup.getGroupId()}); // need to pass groupId and not userGroupId
}
Now were would you write this code-snippet? There are various places depending upon what requirement you have:
Custom plugin portlet with a UI to execute this code. (better if required periodically)
Custom plugin action-hook and the code goes inside a StartUpAction, executes the code when the hook is being deployed. Hook should be undeployed or else will run everytime the hook is deployed. (better for one time use)
Custom plugin upgrade hook, executes the code during deployment once based on the upgrade condition. (better for one time use)
Use Beanshell, Server Administration → Script → Select Beanshell → Paste the code-snippet → Execute. You need to have the proper import statements and then just the code-snippet and you are good to go. For an example of Beanshell usage you can check my other answer. (better for one time use)
Even after all this you would still have to take the pains to give permission to each role ;-)
Hope this helps though.

Change file owner group under Linux with java.nio.Files

I have a Linux server and I'm running an image resize job in Java for multiple websites on my server. The website files are owned by different OS users/groups. Newly created thumbnails/previews are owned by the user running the resize job. Now I was googleing around how to change the file owner of newly created previews/thumbnails in my resize program and came across this:
java.nio.file.Files.setOwner(Path path, UserPrincipal owner);
This would really solve my problem if it was Windows, but since a Linux file has a user and a group as owner I'm a bit in trouble. Unfortunately given method seems to only change the user ownership of the file. The group ownership remains with the group of the user running my Java resize job.
The websites are owned by different groups, so adding my resize job user to one group is no option. I also want to avoid system calls with ProcessBuilder and execute a chown on my files.
I do need to point out that the created files (preview/thumbnail) can be accessed via the website and it is not mission critical to change the group ownership, but I wanted it to be as clean as possible.
Any suggestions how I can change the group ownership of a file in Linux only using Java?
Thanks Jim Garrison for pointing me in the correct direction. Here the code, which finally solved the problem for me.
Retrieve the group owner of a file
File originalFile = new File("original.jpg"); // just as an example
GroupPrincipal group = Files.readAttributes(originalFile.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group();
Set the group owner of a file
File targetFile = new File("target.jpg");
Files.getFileAttributeView(targetFile.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).setGroup(group);
I missed a complete solution, here it comes (combination of other answers and comments):
Path p = Paths.get("your file's Path");
String group = "GROUP_NAME";
UserPrincipalLookupService lookupService = FileSystems.getDefault()
.getUserPrincipalLookupService();
GroupPrincipal group = lookupService.lookupPrincipalByGroupName(group);
Files.getFileAttributeView(p, PosixFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS).setGroup(group);
Be aware that only the owner of a file can change its group and only to a group he is a member of...
Take a look at the package java.nio.file.attributes and classPosixFilePermissions. This is where you can manipulate group permissions.
The purpose of this response is to elevate one of the comments received in response to the original posting to a full response level, so that it is more prominently displayed.
Here is what worked for us:
// newUser and newGroup are strings.
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(newUser);
GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(newgroup);
Files.setAttribute(filePath, "posix:owner", userPrincipal, LinkOption.NOFOLLOW_LINKS);
Files.setAttribute(filePath, "posix:group", groupPrincipal, LinkOption.NOFOLLOW_LINKS);
Additionally we had to run the Java program as a superuser.

Categories

Resources