Cognos 8 SDK: How to get Subgroups of a Group? - cognos

I try to get the Subgroup of a Group in the standard Cognos Namespace.
Quering the Contentstore to get ALL groups works fine.
The standard methodes to get "members" of objects return the users or only the "root" group (the group I want the subgroups of). Nothing else....
Am I doing something wrong or is it just "not to be done" ?

I found a way of doing it:
Assuming you have the searchpath for the group you want the subgroups of.
Query the contentstore for it with following PropEnum:
PropEnum[] props = {
PropEnum.defaultName,
PropEnum.searchPath,
PropEnum.members };
As result you get a BaseClass[] object (with only one element though...).
Import com.cognos.developer.schemas.bibus._3.Group <--- this is part of the Cognos SDK libraries and
now you can cast the object[0] to Group.
object.getMembers().getValue()[] is an array of all members INCLUDING groups, roles, accounts.
In java it looks like this (query for the object already done):
Group group = (Group)object[0];
BaseClass obj = null;
for (int i = 0; i < group.getMembers().getValue().length; i++){
obj = group.getMembers().getValue();
System.out.println(obj.getSearchPath().getValue());
}

Related

Is there an efficient way for getting the rarest role of a member discord.js

I have implemented a feature that shows people their rarest role (the role that the least people have). I did it by looping through each of their roles and checking how many people have the role. As it turns out, if you have over like 50 roles, it delays the bots response visibly, so I was wondering if there is a more efficient way of doing the same thing. My code is here:
const rolesOfMember = member._roles
for(const role in rolesOfMember) {
var membersHavingCurrentRole = message.guild.roles.cache.get(rolesOfMember[role]).members.size
if(membersHavingCurrentRole < membersHavingRarestRole) {
membersHavingRarestRole = membersHavingCurrentRole
rarestRoleID = rolesOfMember[role]
} else if(membersHavingCurrentRole == membersHavingRarestRole) {
var rarestRole = message.guild.roles.cache.get(rarestRoleID)
var currentRole = message.guild.roles.cache.get(rolesOfMember[role])
if(rarestRole.comparePositionTo(currentRole) < 0) {
membersHavingRarestRole = membersHavingCurrentRole
rarestRoleID = rolesOfMember[role]
}
}
}
Well, one way to simplify your code would be to not have to call message.guild.roles.cache.get() 3 or so times for every role that the member has, especially if they're going to have 50+ roles. In fact, we could eliminate the need for your member._roles object entirely, and therefore eliminate the need for the for/in loop. Here's an example (tested and works):
var rolesOfMember = message.member.roles.cache;
var rarestRole = rolesOfMember.sort((roleA, roleB) => roleA.members.size - roleB.members.size).first();
var rarestRoleID = rarestRole.id;
In this example, I first get the Collection of all of the roles that the member has. Then, I use the Collection.sort() method to sort the roles based on how many members have each role in the guild (from least to greatest, so in other words from rarest to most common). Since the first role in this sorted Collection will be the rarest role that the user has, I simply call Collection.first() on the sorted Collection in order to retrieve the first and rarest Role. From there, you can use rarestRole however you'd like, I simply retrieve the role's ID and store it in a variable in my example.
You can also alter the sorting function however you'd like in order to consider the case in which two roles have the same amount of people who have them.
Relevant resources:
https://discord.js.org/#/docs/main/stable/class/Role?scrollTo=members
https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=sort

Fabric js select object in group

Is it possible to select a single object from a group created like this?
var r = new fabric.Rect(...);
var l = new fabric.Line(...);
var roadGroup = new fabric.Group([r,l],{ ... });
So I want to have a group, but select objects l or r separately.
The simple answer is yes, but you should make sure you take into account the purpose of a group.
To get a handle on an object that is wrapped in a group you can do something like this:
var r = roadGroup._objects[0];
var l = roadGroup._objects[1];
To select a child of a group try something like this:
fabricCanvas.setActiveObject(roadGroup._objects[0]);
soapbox:
The purpose of creating a group is to treat several objects as if they were a single one. The purpose of selecting an object is to allow user interactions with an object. If you want your user to interact with a portion of a group, you might want to consider not grouping them in the first place, or else un-grouping them prior to selecting the child object.
/soapbox
I believe _objects is to be used internally only and may thus change in the future.
To me it group.item(indexOfItem) seems to be the way
So I had this scenario where I have multiple images in a box. Those all images move along with the box (as a group) but user should also be able to select an individual image and move it.
Basically I wanted to select individual objects (in my case images) of group, I did it like this:
groupImages.forEach(image => image.on('mousedown', function (e) {
var group = e.target;
if (group && group._objects) {
var thisImage = group._objects.indexOf(image);
var item = group._objects[thisImage];//.find(image);
canvas.setActiveObject(item);
}
}));
groupImages could be list of objects which you want to select individually.

The Requested Resources was not found or you do not have sufficient permissions to view it

Dynamics crm when retrieving value and updating it into another entity it showing like
The Requested Resources was not found or you do not have sufficient permissions to view it
i specified update ids like
enobj.Id=(Guid)context.OutputParameters["id"];
message:create
service :update on another entity
this is my code:
Query Expression query = new Query Expression();
query.EntityName = en.LogicalName;
query.ColumnSet = new ColumnSet("new_amount");
var x = service.RetrieveMultiple(query);
Entity enobj = new Entity("new_product");
int i = 0;
foreach (var item in x.Entities)
{
i = i + (int)item.Attributes["new_amount"];
enobj.Attributes["new_grandtotal"] = i;
}
enobj.Id=(Guid)context.OutputParameters["id"];
// en.Id = enobj.Id;
enobj.Id = en.Id;
service.Update(enobj);
message:create
service :update
i have two entites product and productlineitems
in productlineitems iam creating a record with the field amount 50 after creating that value.iam updating on product entity.
again i create productlineitem 2 with the value some 90.iam adding 50+90 =140
again lineitem 3 with the value. iam taking that on product entity
message:create --- productlineitems
service :update --- product
I think you are trying to update Product with Product Line Id. Try the following:
Replace
enobj.Id = en.Id;
With
// set the field name (key) based on what you got in system
enobj.Id = (Guid)en["new_productid"];
Also, Calling Context is set to Current user. So make sure that user have permissions to update Product.

Getting RoleCollection as a string

We can get the roles of an SPUser by SPUser.Roles. But it will return SPRoleCollection. If we want to list all the roles we need to loop that.
For example an User has "Full Control","Read","Design" we need to loop the SPRoleCollection object.
How can i get all the roles as a string with ',' separator?
As a rough guess, try:
var user = SPUser // However you get the user.
var roles = Sring.Join(",", (from r in user.Roles select r.Name).ToArray()));
Though if you're using SharePoint 2010, the Name property is obsolete apparently.

How can I set up a Lucene index in Sitecore that handles security correctly?

I have a number of different roles in Sitecore. And I have set security permissions on my content items so that different roles can only access certain content items. It seems that Lucene will just index all of the content. And when I query Lucene it doesn't pay any attention to the security. Is there any way to get Lucene to only return items that the current Extranet user has access to?
Thanks,
Corey
Not to my knowledge. But when working through the Hits collection, you would normally have a loop similar to this:
for ( int i = 0; i < hits.Length() && i < Context.Current.Settings.MaxSearchResultsToProcess; i++ )
{
Item item = Index.GetItem( hits.Doc( i ), Context.Current.Database );
if ( item != null )
{
indexResultater.Add( item );
}
}
And since this runs in context of your current user, no results would be added to your results if the user cannot access them.

Resources