|
| 1 | +/* |
| 2 | + * Copyright (c) 2013 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | + |
| 15 | +package com.google.api.services.samples.dfareporting.cmdline; |
| 16 | + |
| 17 | +import com.google.api.services.dfareporting.Dfareporting; |
| 18 | +import com.google.api.services.dfareporting.model.CompatibleFields; |
| 19 | +import com.google.api.services.dfareporting.model.Dimension; |
| 20 | +import com.google.api.services.dfareporting.model.Metric; |
| 21 | +import com.google.api.services.dfareporting.model.Report; |
| 22 | +import com.google.api.services.dfareporting.model.ReportCompatibleFields; |
| 23 | + |
| 24 | +/** |
| 25 | + * This example fetches and displays the compatible fields for the given standard report. There |
| 26 | + * are two reasons why metrics and/or dimensions may be incompatible with your report: |
| 27 | + * |
| 28 | + * <ul><li>Your user profile doesn't have permission to view those fields</li> |
| 29 | + * <li>Your report contains a field which is incompatible with certain other fields</li></ul> |
| 30 | + * |
| 31 | + * Tags: compatibleFields.query |
| 32 | + * |
| 33 | + * @author [email protected] (Joseph DiLallo) |
| 34 | + */ |
| 35 | +public class GetCompatibleFields { |
| 36 | + |
| 37 | + /** |
| 38 | + * Fetches and displays the compatible fields for the given standard report. |
| 39 | + * |
| 40 | + * @param reporting Dfareporting service object on which to run the requests. |
| 41 | + * @param userProfileId The ID number of the DFA user profile to run this request as. |
| 42 | + * @param report Displays additional fields compatible with this report. |
| 43 | + */ |
| 44 | + public static void run(Dfareporting reporting, Long userProfileId, Report report) |
| 45 | + throws Exception { |
| 46 | + System.out.println("================================================================="); |
| 47 | + System.out.printf("Getting compatible fields for standard report with ID %s%n", |
| 48 | + report.getId()); |
| 49 | + System.out.println("================================================================="); |
| 50 | + |
| 51 | + CompatibleFields compatibleFields = reporting.reports().compatibleFields() |
| 52 | + .query(userProfileId, report).execute(); |
| 53 | + |
| 54 | + // Since this is a standard report, we check the "reportCompatibleFields" property. |
| 55 | + // For other reports, we would check that report type's specific property. |
| 56 | + ReportCompatibleFields standardReportCompatibleFields = |
| 57 | + compatibleFields.getReportCompatibleFields(); |
| 58 | + |
| 59 | + for (Dimension compatibleDimension : standardReportCompatibleFields.getDimensions()) { |
| 60 | + System.out.printf("Dimension \"%s\" is compatible.%n", compatibleDimension.getName()); |
| 61 | + } |
| 62 | + |
| 63 | + for (Metric compatibleMetric : standardReportCompatibleFields.getMetrics()) { |
| 64 | + System.out.printf("Metric \"%s\" is compatible.%n", compatibleMetric.getName()); |
| 65 | + } |
| 66 | + |
| 67 | + for (Dimension compatibleDimension : standardReportCompatibleFields.getDimensionFilters()) { |
| 68 | + System.out.printf("Dimension Filter \"%s\" is compatible.%n", compatibleDimension.getName()); |
| 69 | + } |
| 70 | + |
| 71 | + for (Metric compatibleMetric : standardReportCompatibleFields.getPivotedActivityMetrics()) { |
| 72 | + System.out.printf("Pivoted Activity Metric \"%s\" is compatible.%n", |
| 73 | + compatibleMetric.getName()); |
| 74 | + } |
| 75 | + |
| 76 | + System.out.println(); |
| 77 | + } |
| 78 | +} |
0 commit comments