Convert Permission Mask to Roles for GetPermissionCollection - java

We have a requirement where we need to check if a user has "Upload" access to a folder in Sharepoint document library. For that, I am using the "GetPermissionCollection" method of Permissions webservice on the document library. The response I get is of below format:
I am not able to convert the Permission mask to role. I am doing this in Java and I dont have SPBasePermissions class.
Is there a way in Java to convert the Mask into role?
Thanks in advance

Yes, you just need to do bitwise operations against it. You will need to hardwire the bitmask for the permissions you care about, but this should be safe enough since these do not change in SharePoint 2010.

I found this link:
Permission/Deny Mask in SharePoint
which says something about this bitwise AND.
You should also use this link:
http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx
which Enums the Masks for the permissions.
I also made an javascript example that can help you...
however you will have to convert it into java
I used JQuery, SPServices js (http://spservices.codeplex.com/)
and this link for the masks codes
http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx
I Hope this helps you, I did this because I was needing it also, however it may also help others.
You need to replace the LIST NAME HERE with the name of the list, and find out which is the mask for upload.
The script will spit everyone that has access to a list, and say if they can read, add, change and delete things. Hopes this helps you.
$('#divid').html('Working...').SPServices({
operation: "GetPermissionCollection",
objectName: 'LIST NAME HERE',
objectType: "List",
completefunc: function (xData, Status) {
var out = "<ul>";
$(xData.responseXML).find("Permission").each(function () {
if ($(this).attr("MemberIsUser") === "True") {
out += "<li>User: " + $(this).attr("UserLogin") + "</li>";
} else {
out += "<li>Group: " + $(this).attr("GroupName") + "</li>";
}
var readmask = 0x0000000000000001;
var addmask = 0x0000000000000002;
var editmask = 0x0000000000000004;
var deletemask = 0x0000000000000008;
out += "<li>Mask: " + $(this).attr("Mask") + "</li>";
var canread = readmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canadd = addmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canedit = editmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var candelete = deletemask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
out += "<li>Can Read: " + canread + "</li>";
out += "<li>Can Add: " + canadd + "</li>";
out += "<li>Can Edit: " + canedit + "</li>";
out += "<li>Can Delete: " + candelete + "</li>";
});
out += "</ul>";
$('divid').html(out);
}
});

Related

How to read all google adwords targeting options using AWQL or Selectors?

For example, I want to read Age Ranges, Genders, Operating Systems, etc, which are supported in google adwords. I want to read the above said targeting options using either AWQL or Selector?
I am able to read those targeting options using ConstantDataService.
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
ConstantDataServiceInterface constantDataService =
adWordsServices.get(this.session, ConstantDataServiceInterface.class);
AgeRange []ageRanges = constantDataService.getAgeRangeCriterion();
for(AgeRange a : ageRanges) {
System.out.println(a.getId() + " :: " + a.getAgeRangeType() + " :: " + a.getCriterionType() + " :: " + a.getType());
}
But I am unable to apply filters. I saw that I can apply filters if I use AWQL or Selector? I tried the following
AdGroupCriterionServiceInterface adGroupCriterionService =
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
.fields("Id", "AgeRangeType")
.build();
int PAGE_SIZE = 100;
ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupCriterionField.Id, AdGroupCriterionField.AgeRangeType).limit(0, PAGE_SIZE).build();
// Set selector paging = the most important change is to set numberResults to 0.
AdGroupCriterionPage page = null;
do {
serviceQuery.nextPage(page);
page = adGroupCriterionService.query(serviceQuery.toString());
if (page.getEntries() != null) {
for (AdGroupCriterion criterion : page.getEntries()) {
System.out.printf("Campaign with name '%s' and ID %d was found.%n", criterion.getAdGroupCriterionType(),
criterion.getCriterion());
}
} else {
System.out.println("No criterion were found.");
}
} while(serviceQuery.hasNext(page));
but not working as expected.
Can someone tell me how to read targeting options using AWQL or Selector?

Convert the format of a date in Java/Typescript for searchpurposes

I search for a while now, but I didn't found what I need to solve my problem.
First of,I have a "add reminder page" in my app to add reminder with some inputs and the date / time:
<ion-row>
<ion-col>
<ion-label class="ion-label-links" >{{"Datum"|translate}}</ion-label>
</ion-col>
<ion-col text-right>
<ion-label class="ion-label-reminder-rechts">{{"Uhrzeit"|translate}}</ion-label>
</ion-col>
</ion-row>
<ion-row class="schnurr">
<ion-col>
<ion-datetime class="ion-input-reminder" displayFormat="DD.MM.YYYY" [(ngModel)]="reminder.myDate" ></ion-datetime>
</ion-col>
<ion-col>
<ion-datetime text-right class="ion-input-reminder-r" displayFormat="HH:mm" minuteValues="0,5,10,15,20,25,30,35,40,45,50,55" [(ngModel)]="reminder.myTime" ></ion-datetime>
</ion-col>
</ion-row>
And I set a standard date/time with this function:
formatLocalDate() {
var now = new Date(),
tzo = -now.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function(num) {
var norm = Math.abs(Math.floor(num));
return (norm < 10 ? '0' : '') + norm;
};
return now.getFullYear()
+ '-' + pad(now.getMonth()+1)
+ '-' + pad(now.getDate())
+ 'T' + pad(now.getHours())
+ ':' + pad(now.getMinutes())
+ ':' + pad(now.getSeconds())
+ dif + pad(tzo / 60)
+ ':' + pad(tzo % 60);
}
Okay, everything is fine. I Save the record in my couchDb and it looks like this:
2017-07-05T09:18:24+02:00
Now the problem with this kind of format is that I implemented a search field but the usual format here is "dd.mm.yyyy" and not the ISO format, so I formated the output in my app like this:
<br><font size="1">{{item.doc.myDate | date:'dd.MM.yyyy, HH:mm'}} Uhr</font>
but if I search for that item, it doesn't work, because the variable is still in the old format.
My search is looking like this:
.....
<ion-item *ngIf="!searchvariable || item.doc.xName.toLowerCase().includes(this.searchvariable)
|| item.doc.myDate.toDateString().includes(this.searchvariable)" class="ion-item1" tappable (click)="openReminder(reminder.doc)" style="background-color: oldlace">
{{item.doc.myDate.toDateString()}}
......
The search is working for everything but the date. (because of the formatproblems)
Is there a possibility to do something like "reminder.myDate.format(xxx)" or something like this?
I mean, it's possible to alter the output, is there a similar way for my search?!
Btw. I have to format the date with this function, otherwise I get errors because the datepicker needs this format.
Thank you!

download cover art from musicbrainz with java

I am struggling for a couple of hours now on how to link a discid to a musicbrainz mbid.
So, using dietmar-steiner / JMBDiscId
JMBDiscId discId = new JMBDiscId();
if (discId.init(PropertyFinder.getProperty("libdiscid.path")))
{
String musicBrainzDiscID = discId.getDiscId(PropertyFinder.getProperty("cdrom.path"));
}
or musicbrainzws2-java
Disc controller = new Disc();
String drive = PropertyFinder.getProperty("cdrom.path");
try {
DiscWs2 disc =controller.lookUp(drive);
log.info("DISC: " + disc.getDiscId() + " match: " + disc.getReleases().size() + " releases");
....
I can extract a discid for freedb or musicbrainz easily (more or less), but I have not found a way on calculating the id I that I need to download cover art via the CoverArtArchiveClient from last.fm.
CoverArtArchiveClient client = new DefaultCoverArtArchiveClient();
try
{
UUID mbid = UUID.fromString("mbid to locate release");
fm.last.musicbrainz.coverart.CoverArt coverArt = client.getByMbid(mbid);
Theoretically, I assume, I could you the data collected by musicbrainzws2-java to trigger a search, and then use the mbid from the result ... but that cannot be the best option to do.
I am happy about any push into the right direction...
Cheers,
Ed.
You don't calculate the MBID. The MBID is attached on every entity you retrieve from MusicBrainz.
When getting releases by DiscID you get a list. Each entry is a release and has an MBID, accessible with getId():
for (ReleaseWs2 rel : disc.getReleases()){
log.info("MBID: " + rel.getId() + ", String: " + rel.toString());
}
You then probably want to try the CoverArtArchive (CAA) for every release and take the first cover art you get.
Unfortunately I don't know of any API documentation for musicbrainzws2 on the web. I recommend running javadoc on all source files.

delete call logs not working on HTC

i m trying to delete call logs of some selected numbers , code will be run successfully with required results on emulator and two other devices (Q-Mobile A500 & Sony Ericson X10i) that i have available for testing while client test on HTC one its not working
here is my code
String num, queryString = null;
number = number.replace(" ", "");
number = number.replace("-", "");
if (number.length() > 10) {
num = number.substring(number.length() - 10, number.length());
queryString = " LIKE '%" + num + "%'";
} else {
queryString = "=" + number;
}
// String queryString = "NUMBER=" + number;
Uri allCalls = Uri.parse("content://call_log/calls");
context.getContentResolver().delete(allCalls,
android.provider.CallLog.Calls.NUMBER + queryString, null);
context.getContentResolver().delete(
android.provider.CallLog.Calls.CONTENT_URI,
android.provider.CallLog.Calls.NUMBER + queryString, null);
i m trying to delete with both queries results are same but its cant work on HTC one
You should delete your call log by call id may be this will help.
int id = Activity_Name.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);
if (id == 1) {
/*delete your call log*/
}
may be through id you can resolve your issue.
try this
context.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,
android.provider.CallLog.Calls.NUMBER+"=?", new String[] {queryString});
I figured out the error:
On HTC One it is necessary to aquire the permission to wirte call logs:
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
When compiling for a targetSdkVersion of 15 or lower this permission is granted automatically, but for higher targetSdkVersion this permission must be explicitly requested in the manifest.

DJ Native Swing javascript command problems

Using DJ Native Swing it is possible to show a web page within a java application. When you do this it is also possible to communicate from the browser to the java runtime environment using the "command" protocol. The documentation has a code snippet which demonstrates it's usage:
function sendCommand( command ){
var s = 'command://' + encodeURIComponent( command );
for( var i = 1; i < arguments.length; s+= '&' + encodeURIComponent( arguments[i++] ) );
window.location = s;
}
As it looks here it seems to be a regular GET request to an url using the command protocol instead of http. Although when I create and image, script tag or just and ajax get request there is no response and the breakpoint in the java runtime isn't triggered.
I don't want to set the window.location because I don't want to navigate away from the page I am currently at. Using the link to navigate to a command url does work though but it also navigates away from the current page. The page uses OpenLayers and dojo. (I have also tried dojo.io.script)
After some work I have found a neat way to communicate with the java runtime which doesn't trigger a refresh of the page every time there is communication. It is inspired on the way JSONP works to get around the cross domain restriction in most browsers these days. Because an iFrame will also trigger a command:// url it possible to do a JSONP like action using this technique. The code on the client side (browser):
dojo.provide( "nmpo.io.java" );
dojo.require( "dojo.io.script" );
nmpo.io.java = dojo.delegate( dojo.io.script, {
attach: function(/*String*/id, /*String*/url, /*Document?*/frameDocument){
// summary:
// creates a new tag pointing to the specified URL and
// adds it to the document.
// description:
// Attaches the script element to the DOM. Use this method if you
// just want to attach a script to the DOM and do not care when or
// if it loads.
var frame = dojo.create( "iframe", {
id: id,
frameborder: 0,
framespacing: 0
}, dojo.body( ) );
dojo.style( frame, { display: "none" } );
dojo.attr( frame, { src: url } );
return frame;
},
_makeScriptDeferred: function(/*Object*/args){
//summary:
// sets up a Deferred object for an IO request.
var dfd = dojo._ioSetArgs(args, this._deferredCancel, this._deferredOk, this._deferredError);
var ioArgs = dfd.ioArgs;
ioArgs.id = dojo._scopeName + "IoScript" + (this._counter++);
ioArgs.canDelete = false;
//Special setup for jsonp case
ioArgs.jsonp = args.callbackParamName || args.jsonp;
if(ioArgs.jsonp){
//Add the jsonp parameter.
ioArgs.query = ioArgs.query || "";
if(ioArgs.query.length > 0){
ioArgs.query += "&";
}
ioArgs.query += ioArgs.jsonp
+ "="
+ (args.frameDoc ? "parent." : "")
+ "nmpo.io.java.jsonp_" + ioArgs.id + "._jsonpCallback";
ioArgs.frameDoc = args.frameDoc;
//Setup the Deferred to have the jsonp callback.
ioArgs.canDelete = true;
dfd._jsonpCallback = this._jsonpCallback;
this["jsonp_" + ioArgs.id] = dfd;
}
return dfd; // dojo.Deferred
}
});
When a request is sent to the java runtime a callback argument will be supplied and a webBrowser.executeJavascript( callbackName + "(" + json + ");" ); action can be executed to trigger the callback in the browser.
Usage example client:
dojo.require( "nmpo.io.java" );
nmpo.io.java.get({
// For some reason the first paramater (the one after the '?') is never in the
// paramater array in the java runtime. As a work around we stick in a dummy.
url: "command://sum?_",
callbackParamName: "callback",
content: {
numbers: [ 1, 2, 3, 4, 5 ].join( "," )
},
load: function( result ){
console.log( "A result was returned, the sum was [ " + result.result + " ]" );
}
});
Usage example java:
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
#Override
public void commandReceived(WebBrowserCommandEvent e) {
// Check if you have the right command here, left out for the example
// Parse the paramaters into a Hashtable or something, also left out for the example
int sum = 0;
for( String number : arguments.get( "numbers" ).split( "," ) ){
sum += Integer.parseInt( number );
}
// Execute the javascript callback like would happen with a regular JSONP call.
webBrowser.executeJavascript( arguments.get( "callback" ) + "({ result: " + sum + " });" );
}
});
Also with IE in the frame I can highly recommend using firebug lite, the dev tools for IE are not available.

Categories