|
@@ -6,7 +6,6 @@ import com.google.analytics.admin.v1beta.*;
|
|
|
import com.google.api.client.util.Lists;
|
|
|
import com.google.api.gax.core.FixedCredentialsProvider;
|
|
|
import com.google.auth.oauth2.GoogleCredentials;
|
|
|
-import com.google.protobuf.util.JsonFormat;
|
|
|
import com.wechi.adweb.bridge.exception.DataException;
|
|
|
import com.wechi.adweb.bridge.google.analytics.dto.GAAccountDTO;
|
|
|
import com.wechi.adweb.bridge.google.analytics.dto.GADataStreamDTO;
|
|
@@ -62,7 +61,6 @@ public class GAAdminService {
|
|
|
GAAccountDTO gaAccount =
|
|
|
GAAccountDTO.builder()
|
|
|
.id(parseId(account.getName()))
|
|
|
- .resourceName(account.getName())
|
|
|
.displayName(account.getDisplayName())
|
|
|
.createTime(account.getCreateTime().getSeconds())
|
|
|
.updateTime(account.getUpdateTime().getSeconds())
|
|
@@ -177,6 +175,38 @@ public class GAAdminService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public GAPropertyDTO getProperty(String propertyResourceName) throws DataException {
|
|
|
+ try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
|
|
|
+ AnalyticsAdminServiceClient.create(adminServiceSettings)) {
|
|
|
+ Property property = analyticsAdminServiceClient.getProperty(propertyResourceName);
|
|
|
+
|
|
|
+ // Converts and returns.
|
|
|
+ GAPropertyDTO gaProperty =
|
|
|
+ GAPropertyDTO.builder()
|
|
|
+ .id(parseId(property.getName()))
|
|
|
+ .resourceName(property.getName())
|
|
|
+ .displayName(property.getDisplayName())
|
|
|
+ .propertyType(property.getPropertyType().toString())
|
|
|
+ .accountResourceName(property.getAccount())
|
|
|
+ .parentResourceName(property.getParent())
|
|
|
+ .industryCategory(property.getIndustryCategory().toString())
|
|
|
+ .timeZone(property.getTimeZone())
|
|
|
+ .currencyCode(property.getCurrencyCode())
|
|
|
+ .serviceLevel(property.getServiceLevel().toString())
|
|
|
+ .createTime(property.getCreateTime().getSeconds())
|
|
|
+ .updateTime(property.getUpdateTime().getSeconds())
|
|
|
+ // Sets the data streams associated with this property.
|
|
|
+ .dataStreams(listDataStreams(property.getName()))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ log.info("getProperty : {}", JsonUtils.toJson(gaProperty));
|
|
|
+ return gaProperty;
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new DataException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public GAPropertyDTO createPropertyWithDataStream(
|
|
|
String accountResourceName, String displayName, String url) throws DataException {
|
|
|
try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
|
|
@@ -189,7 +219,6 @@ public class GAAdminService {
|
|
|
.setTimeZone(DEFAULT_TIMEZONE)
|
|
|
.build();
|
|
|
Property createdProperty = analyticsAdminServiceClient.createProperty(property);
|
|
|
- log.info("Created property {}", JsonFormat.printer().print(createdProperty));
|
|
|
|
|
|
// 2. Creates the data stream.
|
|
|
DataStream dataStream =
|
|
@@ -202,7 +231,6 @@ public class GAAdminService {
|
|
|
DataStream createdDataStream =
|
|
|
analyticsAdminServiceClient.createDataStream(
|
|
|
createdProperty.getName(), dataStream);
|
|
|
- log.info("Created data stream {}", JsonFormat.printer().print(createdProperty));
|
|
|
|
|
|
// 3. Converts and returns.
|
|
|
GADataStreamDTO gaDataStream =
|
|
@@ -216,21 +244,28 @@ public class GAAdminService {
|
|
|
.streamDefaultUrl(createdDataStream.getWebStreamData().getDefaultUri())
|
|
|
.build();
|
|
|
|
|
|
- return GAPropertyDTO.builder()
|
|
|
- .id(parseId(createdProperty.getName()))
|
|
|
- .resourceName(createdProperty.getName())
|
|
|
- .displayName(createdProperty.getDisplayName())
|
|
|
- .propertyType(createdProperty.getPropertyType().toString())
|
|
|
- .accountResourceName(createdProperty.getAccount())
|
|
|
- .parentResourceName(createdProperty.getParent())
|
|
|
- .industryCategory(createdProperty.getIndustryCategory().toString())
|
|
|
- .timeZone(createdProperty.getTimeZone())
|
|
|
- .currencyCode(createdProperty.getCurrencyCode())
|
|
|
- .serviceLevel(createdProperty.getServiceLevel().toString())
|
|
|
- .createTime(createdProperty.getCreateTime().getSeconds())
|
|
|
- .updateTime(createdProperty.getUpdateTime().getSeconds())
|
|
|
- .dataStreams(Collections.singletonList(gaDataStream))
|
|
|
- .build();
|
|
|
+ GAPropertyDTO gaProperty =
|
|
|
+ GAPropertyDTO.builder()
|
|
|
+ .id(parseId(createdProperty.getName()))
|
|
|
+ .resourceName(createdProperty.getName())
|
|
|
+ .displayName(createdProperty.getDisplayName())
|
|
|
+ .propertyType(createdProperty.getPropertyType().toString())
|
|
|
+ .accountResourceName(createdProperty.getAccount())
|
|
|
+ .parentResourceName(createdProperty.getParent())
|
|
|
+ .industryCategory(createdProperty.getIndustryCategory().toString())
|
|
|
+ .timeZone(createdProperty.getTimeZone())
|
|
|
+ .currencyCode(createdProperty.getCurrencyCode())
|
|
|
+ .serviceLevel(createdProperty.getServiceLevel().toString())
|
|
|
+ .createTime(createdProperty.getCreateTime().getSeconds())
|
|
|
+ .updateTime(createdProperty.getUpdateTime().getSeconds())
|
|
|
+ .dataStreams(Collections.singletonList(gaDataStream))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ log.info(
|
|
|
+ "createPropertyWithDataStream for {} : {}",
|
|
|
+ accountResourceName,
|
|
|
+ JsonUtils.toJson(gaProperty));
|
|
|
+ return gaProperty;
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new DataException(e);
|
|
@@ -241,7 +276,7 @@ public class GAAdminService {
|
|
|
try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
|
|
|
AnalyticsAdminServiceClient.create(adminServiceSettings)) {
|
|
|
analyticsAdminServiceClient.deleteProperty(propertyResourceName);
|
|
|
- log.info("Deleted property {}", propertyResourceName);
|
|
|
+ log.info("deleteProperty {}", propertyResourceName);
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw new DataException(e);
|