How to solve "BetaAnalyticsDataClient cannot be resolved"? - google-analytics-api

I tried sample source at Google Analytics Data API (GA4), there is code as below:
import com.google.analytics.data.v1beta.BetaAnalyticsDataClient;
....
try (BetaAnalyticsDataClient analyticsData = BetaAnalyticsDataClient.create()) {
RunReportRequest request = RunReportRequest.newBuilder()
.setProperty("properties/" + propertyId)
.addDimensions(Dimension.newBuilder().setName("city"))
.addMetrics(Metric.newBuilder().setName("activeUsers"))
.addDateRanges(DateRange.newBuilder().setStartDate("2020-03-31").setEndDate("today"))
.build();
...
Though I import jar files with
compile 'com.google.api.grpc:proto-google-analytics-data-v1beta:0.10.2'
compile 'com.google.apis:google-api-services-analyticsdata:v1beta-rev20220504-1.32.1'
I still got error "BetaAnalyticsDataClient cannot be resolved", how can I solve this problem?

Related

Mask Headers in spring restdocs

So I was trying to follow this example:
Spring REST Docs: how to replace parameters
What I'm trying to do is to mask the JWT token in the header of my request and I have an OperationPreprocessor that looks like this:
import org.springframework.http.HttpHeaders
import org.springframework.restdocs.operation.OperationRequest
import org.springframework.restdocs.operation.OperationRequestFactory
import org.springframework.restdocs.operation.OperationResponse
import org.springframework.restdocs.operation.preprocess.OperationPreprocessor
class AuthHeaderPreprocessor implements OperationPreprocessor {
#Override
OperationRequest preprocess(OperationRequest request) {
HttpHeaders headers = new HttpHeaders()
headers.putAll(request.getHeaders())
headers.set('Authorization', 'Bearer 12345')
return new OperationRequestFactory().create(
request.getUri(),
request.getMethod(),
request.getContent(),
headers,
request.getParameters(),
request.getParts()
)
}
#Override
OperationResponse preprocess(OperationResponse response) {
return response
}
}
When I run the test they run without error but I don't see any change to the header. I'm using the OperationPreprocessor like this
RestAssuredRestDocumentation.document(
'event-list', preprocessRequest(new AuthHeaderPreprocessor()), ...
Any ideas what I may be missing.
The code I had actually worked and is a good example of how to filter headers. For some reason when testing it initially I wasn't working, but that seems like it was maybe just something cached in the build not getting cleared, as it works now.

Scala: Http client read http response

I am using httpClient lib to do some REST API calls using scala. I am able to post the data.
I am using following code to read the content. However, When I run on Spark Databricks Cluster it give me error.
val entity = response.getEntity
var content = ""
if (entity != null) {
val inputStream = entity.getContent
content = io.Source.fromInputStream(inputStream).getLines.mkString
inputStream.close()
}
Error
error: object Source is not a member of package io
content = io.Source.fromInputStream(inputStream).getLines.mkString
is there a way I can fix this error, or a different way to read HTTP response content.
Please try to import scala.io.Source
OR use the completed package name like this:
content = scala.io.Source.fromInputStream(inputStream).getLines.mkString

Error On Using Route53 ChangeResourceRecordSets

I'm currently using Grails 2.4.5 and used AmazonWebService plugin for grails 2.4.5
I'm trying to create a new recordset on route53 using this plugin.
On my BuildConfig.groovy I used this plugin fro aws web services.
compile ":aws-sdk:1.10.44"
I need your help guys regarding route53 change resource record sets.
I got an error below when I tried to change route53 resource record sets.
Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6). Stacktrace follows:
Message: Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6)
This is my code.
import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional
#Transactional
class AwsRoute53Service {
AmazonWebService amazonWebService
ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53
AliasTarget target = new AliasTarget('hostedZoneIDHere', 'app.sample.com.')
target.setEvaluateTargetHealth(true)
List<ResourceRecord> resourceRecords = new ArrayList<>()
resourceRecords.add(new ResourceRecord('dNSNameHere'))
ResourceRecordSet recordSet = new ResourceRecordSet('app.sample.com.', RRType.A)
recordSet.setAliasTarget(target)
recordSet.setResourceRecords(resourceRecords)
recordSet.setTrafficPolicyInstanceId('simple')
List<Change> changes = new ArrayList<>()
changes.add(new Change(ChangeAction.CREATE, recordSet))
ChangeBatch changeBatch = new ChangeBatch(changes)
ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest('hostedZoneIDHere', changeBatch)
return route53Client.changeResourceRecordSets(request)
}
}
Can you tell me what is the problem with the setup?
I would be glad if you can help me with my problem right now.
Thank you guys.
I already solve this problem. below is the working code.
import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional
#Transactional
class AwsRoute53Service {
private static final String DOMAIN_NAME_SERVER = "${System.env.DOMAIN_NAME_SERVER}"
private static final String HOSTED_ZONE_ID = "${System.env.HOSTED_ZONE_ID}"
AmazonWebService amazonWebService
ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53
GetHostedZoneResult hostedZoneResult = route53Client.getHostedZone(new GetHostedZoneRequest(HOSTED_ZONE_ID))
HostedZone hostedZone = hostedZoneResult.getHostedZone()
ResourceRecordSet resourceRecordSet = new ResourceRecordSet()
.withName('dNSName')
.withType(RRType.CNAME)
.withTTL(60)
.withResourceRecords([
new ResourceRecord().withValue(DOMAIN_NAME_SERVER)
])
ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest()
.withHostedZoneId(hostedZone.id)
.withChangeBatch(
new ChangeBatch()
.withChanges([
new Change()
.withAction(ChangeAction.CREATE)
.withResourceRecordSet(resourceRecordSet)
])
)
return route53Client.changeResourceRecordSets(request)
}
}

Jira Script Runner - Mail is not sent by Post Function of Create Transition

we have a Project in Jira which we use as an inbox for Email. Not all people sending emails are users in JIRA (and they shall not be). Nevertheless, we would like to inform then on having received the Email. The emailaddress is part of the Issue description.
I am aware of some plugins out there but instead of replacing the Mailhandlers, I am trying to write a groovy script for JIRA adapting this code which I want to post into a Post Function on the CREATE transition of a workflow.
The following code works fine when I grab an existing Test-Issue and run the script in the console:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
if (true) {
IssueManager issueManager = componentManager.getIssueManager()
Issue issue = issueManager.getIssueObject("IN-376")
def grabEmail = {
(((it.split( "\\[Created via e-mail received from:")[1]).split("<")[1]).split(">")[0])
}
String senderAddress = grabEmail("${issue.description}")
Email email = new Email(senderAddress)
email.setSubject("JIRA Ticket erstellt: ${issue.summary}")
String content = "Content ----> by Issue2 ${issue.description}"
email.setBody(content)
mailServer.send(email)
}
}
Alas, it will not run in the Post Function like this:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
//import com.atlassian.jira.issue.IssueManager
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
if (true) {
//IssueManager issueManager = componentManager.getIssueManager()
//Issue issue = issueManager.getIssueObject("IN-376")
def grabEmail = {
(((it.split( "\\[Created via e-mail received from:")[1]).split("<")[1]).split(">")[0])
}
String senderAddress = grabEmail("${issue.description}")
Email email = new Email(senderAddress)
email.setSubject("JIRA Ticket erstellt: ${issue.summary}")
String content = "Content ----> by Issue2 ${issue.description}"
email.setBody(content)
mailServer.send(email)
}
}
I have no idea why the second code breaks since the code this is based on uses issue also as if it is implicitly defined. This Post function is the last to run.
I would also find hints as to debugging this problem helpful.
Thank you!
I'll post my comment as an answer: I did not find an error in any of the logs, then. Maybe I oversaw it, sorry, but I have changed a lot of config by now (installing JEMH trial) so I can not reproduce. Strangely enough, the message gets sent right now, so I have that ill feeling that I had some config in the Notifications Scheme wrong.
Thanks everyone for the help and time.

How to call an exist format function within eclipse for the code file which i created by my plugin?

I wrote an eclipse plugin which can be used create JavaScript file with template codes in it.
Currently i am using JavaScript Development Tools, it includes the formatter feature.
What i want is, once my plugin created a new JavaScript file(it's written in one line without formatted), I want to call the formatter function in my plugin to format the code immediately.
Is it possible to do this?
I am using org.eclipse.wst.jsdt.feature plugin.
The usage of formatting JavaScript code programmatically is the same as the way to do with Java code.
as following:
Map<?, ?> setting = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
CodeFormatter formatter = ToolFactory.createCodeFormatter(setting);
TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, js,
0, js.length(), 0, StringUtil.NEW_LINE);
if (edit == null)
return js;
IDocument doc = new Document(js);
try {
edit.apply(doc);
} catch (Exception e) {
e.printStackTrace();
return js;
}
return doc.get();
The thing you need mention is, you need import following package from org.eclipse.wst.jsdt.
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.wst.jsdt.core.ToolFactory;
import org.eclipse.wst.jsdt.core.formatter.CodeFormatter;
import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants;