com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinitionDateRangeType Java Examples
The following examples show how to use
com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinitionDateRangeType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReportQueryBuilderTest.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** Tests building a report query with enum date range. */ @Test public void testBuildWithEnumDateRange() { String expectedAwql = "SELECT CampaignId, CampaignName FROM CLICK_PERFORMANCE_REPORT " + "DURING THIS_WEEK_MON_TODAY"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.CLICK_PERFORMANCE_REPORT) .during(ReportDefinitionDateRangeType.THIS_WEEK_MON_TODAY) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
Example #2
Source File: ReportProcessor.java From aw-reporting with Apache License 2.0 | 6 votes |
/** * Instantiates the report definition, setting all the correct formats. * * @param reportDefinitionReportType the report definition type. * @param dateRangeType the date range type. * @param selector the selector containing the report properties. * @return the {@code ReportDefinition} */ protected ReportDefinition instantiateReportDefinition( ReportDefinitionReportType reportDefinitionReportType, ReportDefinitionDateRangeType dateRangeType, Selector selector) { // Create the Report Definition ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setReportName( REPORT_PREFIX + reportDefinitionReportType.value() + " " + System.currentTimeMillis()); reportDefinition.setDateRangeType(dateRangeType); reportDefinition.setReportType(reportDefinitionReportType); reportDefinition.setDownloadFormat(DownloadFormat.GZIPPED_CSV); reportDefinition.setSelector(selector); return reportDefinition; }
Example #3
Source File: ReportQueryBuilderImpl.java From googleads-java-lib with Apache License 2.0 | 5 votes |
@Override public ReportQuery.Builder during(Enum<?> dateRange) { checkNotNull(dateRange, "The date range cannot be null."); this.startDate = null; this.endDate = null; this.dateRange = (ReportDefinitionDateRangeType) dateRange; return builder; }
Example #4
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 5 votes |
/** * Parse DateRange in ReportDefinitionDateRangeType enum string. */ private static DateRangeAndType parseEnumFormat(final String dateRange) { try { ReportDefinitionDateRangeType type = ReportDefinitionDateRangeType.valueOf(dateRange); return parseEnumFormat(type); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unknown DateRange type: " + dateRange); } }
Example #5
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 5 votes |
/** * Parse DateRange in "yyyyMMdd,yyyyMMdd" format. */ private static DateRangeAndType parseCustomFormat(final String dateRange) { String[] dates = dateRange.split(","); Preconditions.checkArgument(dates.length == 2, "Unknown DateRange format: '%s.'", dateRange); // Just throws exception if argument is not in proper format "yyyyMMdd" LocalDate startDate = DATE_FORMMATER.parseLocalDate(dates[0].trim()); LocalDate endDate = DATE_FORMMATER.parseLocalDate(dates[1].trim()); return new DateRangeAndType(startDate, endDate, ReportDefinitionDateRangeType.CUSTOM_DATE); }
Example #6
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 5 votes |
/** * Factory method to create a DateRange instance, with overwriting / alteration of values. */ public static DateRangeAndType fromValues(LocalDate startDate, LocalDate endDate, ReportDefinitionDateRangeType type) { if (startDate != null && endDate != null) { // Overwrite type to custom if start date & end date are provided. return new DateRangeAndType(startDate, endDate, ReportDefinitionDateRangeType.CUSTOM_DATE); } else if (type != null && type != ReportDefinitionDateRangeType.CUSTOM_DATE) { // Overwrite the provided start/end date if type is custom. return parseEnumFormat(type); } else { throw new IllegalArgumentException( "Must provide either: 'startDate' and 'endData', or 'type'."); } }
Example #7
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 5 votes |
/** * Make constructor private so it can only be created by factory method. */ private DateRangeAndType( LocalDate startDate, LocalDate endDate, ReportDefinitionDateRangeType type) { this.startDate = Preconditions.checkNotNull(startDate, "Argument 'startDate' cannot be null."); this.endDate = Preconditions.checkNotNull(endDate, "Argument 'endDate' cannot be null."); this.type = Preconditions.checkNotNull(type, "Argument 'type' cannot be null."); Preconditions.checkArgument( !endDate.isBefore(startDate), "Start date must be before or equal to end date."); }
Example #8
Source File: ReportProcessor.java From aw-reporting with Apache License 2.0 | 5 votes |
/** * Adjusts the date range in case of a custom date type. The adjustment do not apply for certain * reports, like {@code CAMPAIGN_NEGATIVE_KEYWORDS_PERFORMANCE_REPORT}. * * @param reportDefinitionReportType the report type. * @param dateRangeAndType the date range and type. * @param selector the selector with the properties. */ protected void adjustDateRange( ReportDefinitionReportType reportDefinitionReportType, DateRangeAndType dateRangeAndType, Selector selector) { if (dateRangeAndType.getType().equals(ReportDefinitionDateRangeType.CUSTOM_DATE) && csvReportEntitiesMapping.supportsDateRange(reportDefinitionReportType)) { selector.setDateRange(dateRangeAndType.getDateRange()); } }
Example #9
Source File: ReportDownloaderTest.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Invokes {@link ReportDownloader#downloadReport(ReportDefinition)} or * {@link ReportDownloader#downloadReport(String, DownloadFormat)}, depending on whether this * instance is configured to use AWQL. * * @param downloadFormat the DownloadFormat for the request * @param rawResponse the response to return from the mocked ad hoc helper */ private ReportDownloadResponse downloadReport(DownloadFormat downloadFormat, RawReportDownloadResponse rawResponse, String expectedErrorText) throws ReportException, ReportDownloadResponseException { if (rawResponse.getHttpStatus() == 200) { // Response indicates success, so return a ReportDownloadResponse. when( adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenReturn(new ReportDownloadResponse(rawResponse)); } else { // Response indicates failure, so throw an exception. when( adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenThrow(new Builder().build(rawResponse.getHttpStatus(), expectedErrorText)); } if (isUseAwql) { return reportDownloader.downloadReport(AWQL_REQUEST, downloadFormat); } else { ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setSelector(new Selector()); reportDefinition .getSelector() .getFields() .addAll(Arrays.asList("CampaignId", "CampaignName", "Impressions")); reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.LAST_7_DAYS); reportDefinition.setReportName("Custom report"); reportDefinition.setReportType(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT); return reportDownloader.downloadReport(reportDefinition); } }
Example #10
Source File: AdvancedCreateCredentialFromScratch.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Runs the example. * * @param adWordsServices the services factory. * @param session the session. * @param reportFile the output file for the report contents. * @throws DetailedReportDownloadResponseException if the report request failed with a detailed * error from the reporting service. * @throws ReportDownloadResponseException if the report request failed with a general error from * the reporting service. * @throws ReportException if the report request failed due to a transport layer error. * @throws IOException if the report's contents could not be written to {@code reportFile}. */ public static void runExample( AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException { // Get the CampaignService. CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class); // Create selector to retrieve the first 100 campaigns. Selector selector = new Selector(); selector.setFields(new String[] {"Id", "Name"}); Paging paging = new Paging(); paging.setStartIndex(0); paging.setNumberResults(100); // Get the first page of campaigns. CampaignPage page = campaignService.get(selector); System.out.printf("Found %d total campaigns.%n", page.getTotalNumEntries()); // Display campaigns. if (page.getEntries() != null) { for (Campaign campaign : page.getEntries()) { System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId()); } } else { System.out.println("No campaigns were found."); } // Create selector. com.google.api.ads.adwords.lib.jaxb.v201809.Selector reportSelector = new com.google.api.ads.adwords.lib.jaxb.v201809.Selector(); reportSelector.getFields().addAll(Arrays.asList( "CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "Impressions", "Clicks", "Cost")); // Create report definition. ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis()); reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.YESTERDAY); reportDefinition.setReportType(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT); reportDefinition.setDownloadFormat(DownloadFormat.CSV); reportDefinition.setSelector(reportSelector); ReportingConfiguration reportingConfig = new ReportingConfiguration.Builder() // Enable to allow rows with zero impressions to show. .includeZeroImpressions(false) .build(); session.setReportingConfiguration(reportingConfig); ReportDownloadResponse response = new ReportDownloader(session).downloadReport(reportDefinition); FileOutputStream fos = new FileOutputStream(new File(reportFile)); Streams.copy(response.getInputStream(), fos); fos.close(); System.out.printf("Report successfully downloaded: %s%n", reportFile); }
Example #11
Source File: DownloadCriteriaReportWithSelector.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Runs the example. * * @param adWordsServices the services factory. * @param session the session. * @param reportFile the output file for the report contents. * @throws DetailedReportDownloadResponseException if the report request failed with a detailed * error from the reporting service. * @throws ReportDownloadResponseException if the report request failed with a general error from * the reporting service. * @throws ReportException if the report request failed due to a transport layer error. * @throws IOException if the report's contents could not be written to {@code reportFile}. */ public static void runExample( AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException { // Create selector. Selector selector = new Selector(); selector.getFields().addAll(Arrays.asList("CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "FinalUrls", "Impressions", "Clicks", "Cost")); // Create report definition. ReportDefinition reportDefinition = new ReportDefinition(); reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis()); reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.YESTERDAY); reportDefinition.setReportType(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT); reportDefinition.setDownloadFormat(DownloadFormat.CSV); // Optional: Set the reporting configuration of the session to suppress header, column name, or // summary rows in the report output. You can also configure this via your ads.properties // configuration file. See AdWordsSession.Builder.from(Configuration) for details. // In addition, you can set whether you want to explicitly include or exclude zero impression // rows. ReportingConfiguration reportingConfiguration = new ReportingConfiguration.Builder() .skipReportHeader(false) .skipColumnHeader(false) .skipReportSummary(false) // Enable to allow rows with zero impressions to show. .includeZeroImpressions(false) .build(); session.setReportingConfiguration(reportingConfiguration); reportDefinition.setSelector(selector); ReportDownloaderInterface reportDownloader = adWordsServices.getUtility(session, ReportDownloaderInterface.class); // Set the property api.adwords.reportDownloadTimeout or call // ReportDownloader.setReportDownloadTimeout to set a timeout (in milliseconds) // for CONNECT and READ in report downloads. ReportDownloadResponse response = reportDownloader.downloadReport(reportDefinition); response.saveToFile(reportFile); System.out.printf("Report successfully downloaded to: %s%n", reportFile); }
Example #12
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 4 votes |
public ReportDefinitionDateRangeType getType() { return type; }
Example #13
Source File: DownloadCriteriaReportWithAwql.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Runs the example. * * @param adWordsServices the services factory. * @param session the session. * @param reportFile the output file for the report contents. * @throws DetailedReportDownloadResponseException if the report request failed with a detailed * error from the reporting service. * @throws ReportDownloadResponseException if the report request failed with a general error from * the reporting service. * @throws ReportException if the report request failed due to a transport layer error. * @throws IOException if the report's contents could not be written to {@code reportFile}. */ public static void runExample( AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException { // Create query. ReportQuery query = new ReportQuery.Builder() .fields( "CampaignId", "AdGroupId", "Id", "Criteria", "CriteriaType", "Impressions", "Clicks", "Cost") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Status").in("ENABLED", "PAUSED") .during(ReportDefinitionDateRangeType.LAST_7_DAYS) .build(); // Optional: Set the reporting configuration of the session to suppress header, column name, or // summary rows in the report output. You can also configure this via your ads.properties // configuration file. See AdWordsSession.Builder.from(Configuration) for details. // In addition, you can set whether you want to explicitly include or exclude zero impression // rows. ReportingConfiguration reportingConfiguration = new ReportingConfiguration.Builder() .skipReportHeader(false) .skipColumnHeader(false) .skipReportSummary(false) // Set to false to exclude rows with zero impressions. .includeZeroImpressions(true) .build(); session.setReportingConfiguration(reportingConfiguration); ReportDownloaderInterface reportDownloader = adWordsServices.getUtility(session, ReportDownloaderInterface.class); // Set the property api.adwords.reportDownloadTimeout or call // ReportDownloader.setReportDownloadTimeout to set a timeout (in milliseconds) // for CONNECT and READ in report downloads. ReportDownloadResponse response = reportDownloader.downloadReport(query.toString(), DownloadFormat.CSV); response.saveToFile(reportFile); System.out.printf("Report successfully downloaded to: %s%n", reportFile); }
Example #14
Source File: DateRangeAndType.java From aw-reporting with Apache License 2.0 | 4 votes |
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. */ private static DateRangeAndType parseEnumFormat(ReportDefinitionDateRangeType type) { LocalDate today = LocalDate.now(); LocalDate startDate; LocalDate endDate; switch (type) { case TODAY: startDate = endDate = today; break; case YESTERDAY: startDate = endDate = today.minusDays(1); break; case LAST_7_DAYS: startDate = today.minusDays(7); endDate = today.minusDays(1); break; case LAST_WEEK: LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek(); startDate = lastWeekProp.withMinimumValue(); endDate = lastWeekProp.withMaximumValue(); break; case THIS_MONTH: LocalDate.Property thisMonthProp = today.dayOfMonth(); startDate = thisMonthProp.withMinimumValue(); endDate = thisMonthProp.withMaximumValue(); break; case LAST_MONTH: LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth(); startDate = lastMonthProp.withMinimumValue(); endDate = lastMonthProp.withMaximumValue(); break; case LAST_14_DAYS: startDate = today.minusDays(14); endDate = today.minusDays(1); break; case LAST_30_DAYS: startDate = today.minusDays(30); endDate = today.minusDays(1); break; case THIS_WEEK_SUN_TODAY: // Joda-Time uses the ISO standard Monday to Sunday week. startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue(); endDate = today; break; case THIS_WEEK_MON_TODAY: startDate = today.dayOfWeek().withMinimumValue(); endDate = today; break; case LAST_WEEK_SUN_SAT: startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue(); endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1); break; // Don't support the following enums case LAST_BUSINESS_WEEK: case ALL_TIME: case CUSTOM_DATE: default: throw new IllegalArgumentException("Unsupported DateRange type: " + type.value()); } return new DateRangeAndType(startDate, endDate, type); }
Example #15
Source File: DateRange.java From adwords-alerting with Apache License 2.0 | 4 votes |
/** * Parse DateRange in ReportDefinitionDateRangeType enum format. */ private static DateRange parseEnumFormat(String dateRange) { ReportDefinitionDateRangeType dateRangeType; try { dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unknown DateRange type: " + dateRange); } LocalDate today = LocalDate.now(); LocalDate startDate; LocalDate endDate; switch (dateRangeType) { case TODAY: startDate = endDate = today; break; case YESTERDAY: startDate = endDate = today.minusDays(1); break; case LAST_7_DAYS: startDate = today.minusDays(7); endDate = today.minusDays(1); break; case LAST_WEEK: LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek(); startDate = lastWeekProp.withMinimumValue(); endDate = lastWeekProp.withMaximumValue(); break; case THIS_MONTH: LocalDate.Property thisMonthProp = today.dayOfMonth(); startDate = thisMonthProp.withMinimumValue(); endDate = thisMonthProp.withMaximumValue(); break; case LAST_MONTH: LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth(); startDate = lastMonthProp.withMinimumValue(); endDate = lastMonthProp.withMaximumValue(); break; case LAST_14_DAYS: startDate = today.minusDays(14); endDate = today.minusDays(1); break; case LAST_30_DAYS: startDate = today.minusDays(30); endDate = today.minusDays(1); break; case THIS_WEEK_SUN_TODAY: // Joda-Time uses the ISO standard Monday to Sunday week. startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue(); endDate = today; break; case THIS_WEEK_MON_TODAY: startDate = today.dayOfWeek().withMinimumValue(); endDate = today; break; case LAST_WEEK_SUN_SAT: startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue(); endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1); break; // Don't support the following enums case LAST_BUSINESS_WEEK: case ALL_TIME: case CUSTOM_DATE: default: throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange); } return new DateRange(startDate, endDate); }
Example #16
Source File: DateRangeAndTypeTest.java From aw-reporting with Apache License 2.0 | 4 votes |
@Test public void testOverwritingType() { DateRangeAndType custom = DateRangeAndType.fromValues(date, date, null); assertEquals("Type must be correct", ReportDefinitionDateRangeType.CUSTOM_DATE, custom.getType()); }
Example #17
Source File: DateRangeAndTypeTest.java From aw-reporting with Apache License 2.0 | 4 votes |
@Test public void testOverritingDates() { DateRangeAndType last7Days = DateRangeAndType.fromValues(null, null, ReportDefinitionDateRangeType.LAST_7_DAYS); testDateRange(last7Days, "20130925", "20131001"); }
Example #18
Source File: DateRangeAndTypeTest.java From aw-reporting with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testInvalidValues2() { DateRangeAndType.fromValues(null, date, ReportDefinitionDateRangeType.CUSTOM_DATE); }