How to get the group members fro Google Group - google-admin-sdk

I am triying to create a service to list all groups from my domain and members inside the group. I am able to print the group names with the below code , Can anyone suggest on how to get the group members ?
Directory.Groups.List request = directory.groups().list();
request.setDomain("mydomain.com");
//request.setQuery("name:'manu'");
com.google.api.services.admin.directory.model.Groups currentPage = request.execute();
List<com.google.api.services.admin.directory.model.Group> allGroups = new ArrayList<com.google.api.services.admin.directory.model.Group>();
System.out.println("Group size--"+currentPage.getGroups().size());
for (int i = 0; i < currentPage.getGroups().size()-1; i++) {
System.out.println("Name----"+currentPage.getGroups().get(i).getName());
System.out.println("Name----"+currentPage.getGroups().get(i).getDirectMembersCount());
}

Related

Metric filter patter with variables

I am trying to define a metric filter for my vpc flow logs and wanted the pattern to formed by a data source result. I have defined a data source to return all enis of given subnets and I want to loop over the result set and construct one metric filter for those enis. but the for_each is creating a metric filter for each eni.
I can't figure out a way to adjust the code such that I can write something like
(interfaceid=$value1 || interfaceid=$value2 || ...) in the filter pattern. any help will be much appreciated.
data "aws_network_interfaces" "ENI_List" {
filter {
name = "subnet-id"
values = ["subnet-A", "subnet-B", "subnet-C"]
}
}
Below is my metric filter. I want to be able to use each eni in the data.aws_network_interfaces.ENI_List.ids result set in my pattern like below
resource "aws_cloudwatch_log_metric_filter" "EUN_Network_Filter" {
for_each = toset("${data.aws_network_interfaces.ENI_List.ids}")
name = "EUN_DC_Network_Traffic_Monitoring"
pattern = "[version, accountid, (interfaceid=${each.value}), srcaddr, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, logstatus=NODATA]"
log_group_name = "VPC_Flow_Log_Group" # "${data.aws_cloudwatch_log_group.vpc_flow_log_group}"
metric_transformation {
name = "EUN_Network"
namespace = "EUN_Network_Traffic"
value = "1"
}
}
Well, you could create the following local value with combination of formatlist and join:
locals {
interfaceids_str = join(" || ", formatlist("interfaceid=%s", var.enis))
}
then
resource "aws_cloudwatch_log_metric_filter" "EUN_Network_Filter" {
name = "EUN_DC_Network_Traffic_Monitoring"
pattern = "[version, accountid, (${local.interfaceids_str}), srcaddr, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, logstatus=NODATA]"
log_group_name = "VPC_Flow_Log_Group" # "${data.aws_cloudwatch_log_group.vpc_flow_log_group}"
metric_transformation {
name = "EUN_Network"
namespace = "EUN_Network_Traffic"
value = "1"
}
}

PowerBi Api - How to get GroupId and DatasetId of Dashboard via API

I have been reading https://powerbi.microsoft.com/en-us/blog/announcing-data-refresh-apis-in-the-power-bi-service/
In this post, it mentions "To get the group ID and dataset ID, you can make a separate API call".
Does anybody know how to do this from the dashboard URL, or do I have to embed the group id and dataset id in my app alongside the dashboard URL???
To get the group ID and dataset ID, you can make a separate API call.
This sentence isn't related to a dashboard, because in one dashboard you can put visuals showing data from many different datasets. These different API calls are Get Groups (to get list of groups, find the one you want and read it's id) and Get Datasets In Group (to find the dataset you are looking for and read it's id).
But you should already know the groupId anyway, because the dashboard is in the same group.
Eventually, you can get datasetId from particular tile using Get Tiles In Group, but I do not know a way to list tiles in dashboard using the Rest API.
This is a C# project code to get the dataset id from Power BI.
Use the below method to call the 'Get' API and fetch you the dataset Id.
public void GetDatasetDetails()
{
HttpResponseMessage response = null;
HttpContent responseContent = null;
string strContent = "";
PowerBIDataset ds = null;
string serviceURL = "https://api.powerbi.com/v1.0/myorg/admin/datasets";
Console.WriteLine("");
Console.WriteLine("- Retrieving data from: " + serviceURL);
response = client.GetAsync(serviceURL).Result;
Console.WriteLine(" - Response code received: " + response.StatusCode);
try
{
responseContent = response.Content;
strContent = responseContent.ReadAsStringAsync().Result;
if (strContent.Length > 0)
{
Console.WriteLine(" - De-serializing DataSet details...");
// Parse the JSON string into objects and store in DataTable
JavaScriptSerializer js = new JavaScriptSerializer();
js.MaxJsonLength = 2147483647; // Set the maximum json document size to the max
ds = js.Deserialize<PowerBIDataset>(strContent);
if (ds != null)
{
if (ds.value != null)
{
foreach (PowerBIDatasetValue item in ds.value)
{
string datasetID = "";
string datasetName = "";
string datasetWeburl = "";
if (item.id != null)
{
datasetID = item.id;
}
if (item.name != null)
{
datasetName = item.name;
}
if (item.qnaEmbedURL != null)
{
datasetWeburl = item.qnaEmbedURL;
}
// Output the dataset Data
Console.WriteLine("");
Console.WriteLine("----------------------------------------------------------------------------------");
Console.WriteLine("");
Console.WriteLine("Dataset ID: " + datasetID);
Console.WriteLine("Dataset Name: " + datasetName);
Console.WriteLine("Dataset Web Url: " + datasetWeburl);
} // foreach
} // ds.value
} // ds
}
else
{
Console.WriteLine(" - No content received.");
}
}
catch (Exception ex)
{
Console.WriteLine(" - API Access Error: " + ex.ToString());
}
}
points to remember:
Make sure these classes exist in your project
PowerBIDataset is a class with List
PowerBIDatasetValue is a class with id, name and webUrl (all string data type) data members
provide below constants in your project class
const string ApplicationID = "747d78cd-xxxx-xxxx-xxxx-xxxx";
// Native Azure AD App ClientID -- Put your Client ID here
const string UserName = "user2#xxxxxxxxxxxx.onmicrosoft.com";
// Put your Active Directory / Power BI Username here (note this is not a secure place to store this!)
const string Password = "xyxxyx";
// Put your Active Directory / Power BI Password here (note this is not secure pace to store this! this is a sample only)
call this GetDatasetDetails() method in the Main method of your project class
and finally
use the below 'Get' API to get the Group Id
https://api.powerbi.com/v1.0/myorg/groups

Remove all duplicate and the original elements from a list

I have a list of sObject elements. I want to remove the duplicate element having the same record name along with the original record .
Like suppose if I have a list of element having record names as
Chair1,Chair2,Chair3,Chair4,Chair5,Chair6,Chair7,Chair1,Chair2
I want to print a list having only the elements that have no duplicates.For this case I should get the list Chair3,Chair4,Chair5,Chair6,Chair7.
I am using the below code to achieve this functionality.But I am getting thw records as : Chair1,Chair2,Chair3,Chair4,Chair5,Chair6,Chair7.
In ideal case we should not get the records Chair1,Chair2 as these already have duplicate records.
List <Chair__c> chairList = [SELECT
ID,
Name
FROM Chair__c
ORDER BY Name ASC];
System.debug('chairListOrderbyName::'+chairList);
List <String> chairNameList = new List <String>();
for(Integer i = 0; i < chairList.size();i++) {
for(Integer j = 0;j < chairList.size();j++) {
if(chairList[i].Name.equalsIgnoreCase(chairList[j].Name) && i != j) {
chairList.remove(i);
chairList.remove(j);
}
}
}
System.debug('chairList::'+chairList);
If names is really all you need you could do it with pure SOQL using GROUP BY and HAVING. Something like
SELECT Name
FROM Chair__c
GROUP BY Name
HAVING COUNT(Id) = 1 // only unique entries
If you need full sObjects then I'd make a helper Set<String> and loop through results. If name isn't in the set - add it. But if it already is there -> remove it!
Actually let's make it Map, similar idea...
Map<Set, Chair__c> chairs = new Map<Set, Chair__c>();
for(Chair__c c : [SELECT ...]){
if(chairs.containsKey(c.Name)){
chairs.remove(c.Name);
} else {
chairs.put(c.Name, c);
}
}
System.debug(JSON.serializePretty(chairs));
System.debug(chairs.values());
Try using a Set<String> instead of List<String>.Refer below solution
List <Chair__c> chairList = [SELECT
ID,
Name
FROM Chair__c
ORDER BY Name ASC];
Set<String> chairNameSet = new Set<String>();
for(String item: chairList ) {
chairNameSet.add(item);
}

Gmail App search criteria

I have the following search criteria working very well in Gmail:
user#domain from:/mail delivery/ || /postmaster/ ||/Undeliverable/
I am trying to write Goole Apps code to return the same results. Here is the code:
var thread=GmailApp.search("user#domain from:/mail delivery/ || /postmaster/ ||/Undeliverable/ ");
I am getting different results. I am new to both Regex and Google Apps.
Try Amit Agarwal's tutorial on Gmail Search with Google Apps Script which includes Using Regular Expressions to Find Anything in your Gmail Mailbox:
function Search() {
var sheet = SpreadsheetApp.getActiveSheet();
var row = 2;
// Clear existing search results
sheet.getRange(2, 1, sheet.getMaxRows() - 1, 4).clearContent();
// Which Gmail Label should be searched?
var label = sheet.getRange("F3").getValue();
// Get the Regular Expression Search Pattern
var pattern = sheet.getRange("F4").getValue();
// Retrieve all threads of the specified label
var threads = GmailApp.search("in:" + label);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var m = 0; m < messages.length; m++) {
var msg = messages[m].getBody();
// Does the message content match the search pattern?
if (msg.search(pattern) !== -1) {
// Format and print the date of the matching message
sheet.getRange(row,1).setValue(
Utilities.formatDate(messages[m].getDate(),"GMT","yyyy-MM-dd"));
// Print the sender's name and email address
sheet.getRange(row,2).setValue(messages[m].getFrom());
// Print the message subject
sheet.getRange(row,3).setValue(messages[m].getSubject());
// Print the unique URL of the Gmail message
var id = "https://mail.google.com/mail/u/0/#all/"
+ messages[m].getId();
sheet.getRange(row,4).setFormula(
'=hyperlink("' + id + '", "View")');
// Move to the next row
row++;
}
}
}
}

Codeigniter routing how to permit null parameter

I want paginate my index http:localhost/mysite/home but if I write only this http:localhost/mysite/home the page said: "page not found", but if I write http:localhost/mysite/home/3 its work! how to I can configure my routing to get null parameters? I tried with (:any) and (num) but not work
My route file is:
$route['404_override'] = 'welcome/no_found';
$route['home/'] = "welcome/home/$1";
My controller:
$config['base_url'] = base_url().'/mysite/home';
$config['total_rows'] = $this->mtestmodel->countNews();
$config['per_page'] = 2;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['paginator']=$this->pagination->create_links();
$data['news']=$this->mtestmodel->show_news( $config['per_page'],intval($to) );
//$to is a parameter in url base_url()/mysite/home/3
Change your route.php file to the following:
$route['404_override'] = 'welcome/no_found';
$route['home/(:num)'] = "welcome/home/$1";
$route['home'] = "welcome/home";
This way, your application will catch both requests (http://localhost/mysite/home and http://localhost/mysite/home/3), and will send them both to your controller.
You should then be able to access your $to variable (which has been passed as the first argument into your controller's function) or use $this->uri->segment(2) instead.
e.g.
public function home($to = 0) {
$config['base_url'] = base_url().'/mysite/home';
$config['total_rows'] = $this->mtestmodel->countNews();
$config['per_page'] = 2;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['paginator'] = $this->pagination->create_links();
$data['news'] = $this->mtestmodel->show_news( $config['per_page'],intval($to) );
}
Hope that helps!