wfansh 6 kuukautta sitten
vanhempi
commit
623c30ff4f

+ 3 - 0
src/main/java/com/wechi/adweb/bridge/google/analytics/dto/GAAccountDTO.java

@@ -1,5 +1,6 @@
 package com.wechi.adweb.bridge.google.analytics.dto;
 
+import lombok.Builder;
 import lombok.Data;
 
 import org.apache.commons.lang3.StringUtils;
@@ -8,7 +9,9 @@ import org.apache.commons.lang3.StringUtils;
  * @author wfansh
  */
 @Data
+@Builder
 public class GAAccountDTO {
+
     private String id;
 
     private String name;

+ 3 - 0
src/main/java/com/wechi/adweb/bridge/google/analytics/dto/GADataStreamDTO.java

@@ -1,12 +1,15 @@
 package com.wechi.adweb.bridge.google.analytics.dto;
 
+import lombok.Builder;
 import lombok.Data;
 
 /**
  * @author wfansh
  */
 @Data
+@Builder
 public class GADataStreamDTO {
+
     private String id;
 
     private String name;

+ 2 - 0
src/main/java/com/wechi/adweb/bridge/google/analytics/dto/GAPropertyDTO.java

@@ -1,5 +1,6 @@
 package com.wechi.adweb.bridge.google.analytics.dto;
 
+import lombok.Builder;
 import lombok.Data;
 
 import java.util.List;
@@ -8,6 +9,7 @@ import java.util.List;
  * @author wfansh
  */
 @Data
+@Builder
 public class GAPropertyDTO {
 
     private String id;

+ 48 - 41
src/main/java/com/wechi/adweb/bridge/google/analytics/service/GAAdminService.java

@@ -60,12 +60,14 @@ public class GAAdminService {
             ListAccountsRequest request = ListAccountsRequest.getDefaultInstance();
 
             for (Account account : analyticsAdminServiceClient.listAccounts(request).iterateAll()) {
-                GAAccountDTO gaAccount = new GAAccountDTO();
-                gaAccount.setId(parseId(account.getName()));
-                gaAccount.setName(account.getName());
-                gaAccount.setDisplayName(account.getDisplayName());
-                gaAccount.setCreateTime(account.getCreateTime().getSeconds());
-                gaAccount.setUpdateTime(account.getUpdateTime().getSeconds());
+                GAAccountDTO gaAccount =
+                        GAAccountDTO.builder()
+                                .id(parseId(account.getName()))
+                                .name(account.getName())
+                                .displayName(account.getDisplayName())
+                                .createTime(account.getCreateTime().getSeconds())
+                                .updateTime(account.getUpdateTime().getSeconds())
+                                .build();
 
                 // Adds into the list;
                 gaAccounts.add(gaAccount);
@@ -92,25 +94,26 @@ public class GAAdminService {
 
             for (Property property :
                     analyticsAdminServiceClient.listProperties(request).iterateAll()) {
-                GAPropertyDTO gaProperty = new GAPropertyDTO();
-                gaProperty.setId(parseId(property.getName()));
-                gaProperty.setName(property.getName());
-                gaProperty.setDisplayName(property.getDisplayName());
-                gaProperty.setPropertyType(property.getPropertyType().toString());
-                gaProperty.setAccount(property.getAccount());
-                gaProperty.setParent(property.getParent());
-                gaProperty.setIndustryCategory(property.getIndustryCategory().toString());
-                gaProperty.setTimeZone(property.getTimeZone());
-                gaProperty.setCurrencyCode(property.getCurrencyCode());
-                gaProperty.setServiceLevel(property.getServiceLevel().toString());
-                gaProperty.setCreateTime(property.getCreateTime().getSeconds());
-                gaProperty.setUpdateTime(property.getUpdateTime().getSeconds());
-
-                // Sets the data streams associated with this property.
-                gaProperty.setDataStreams(
-                        withDataStreams
-                                ? listGADataStreams(property.getName())
-                                : Collections.EMPTY_LIST);
+                GAPropertyDTO gaProperty =
+                        GAPropertyDTO.builder()
+                                .id(parseId(property.getName()))
+                                .name(property.getName())
+                                .displayName(property.getDisplayName())
+                                .propertyType(property.getPropertyType().toString())
+                                .account(property.getAccount())
+                                .parent(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(
+                                        withDataStreams
+                                                ? listGADataStreams(property.getName())
+                                                : Collections.EMPTY_LIST)
+                                .build();
 
                 // Adds into the list;
                 gaProperties.add(gaProperty);
@@ -143,14 +146,16 @@ public class GAAdminService {
 
             for (DataStream dataStream :
                     analyticsAdminServiceClient.listDataStreams(request).iterateAll()) {
-                GADataStreamDTO gaDataStream = new GADataStreamDTO();
-                gaDataStream.setId(parseId(dataStream.getName()));
-                gaDataStream.setName(dataStream.getName());
-                gaDataStream.setDisplayName(dataStream.getDisplayName());
-                gaDataStream.setProperty(propertyName);
-                gaDataStream.setStreamMeasurementId(
-                        dataStream.getWebStreamData().getMeasurementId());
-                gaDataStream.setStreamDefaultUrl(dataStream.getWebStreamData().getDefaultUri());
+                GADataStreamDTO gaDataStream =
+                        GADataStreamDTO.builder()
+                                .id(parseId(dataStream.getName()))
+                                .name(dataStream.getName())
+                                .displayName(dataStream.getDisplayName())
+                                .property(propertyName)
+                                .streamMeasurementId(
+                                        dataStream.getWebStreamData().getMeasurementId())
+                                .streamDefaultUrl(dataStream.getWebStreamData().getDefaultUri())
+                                .build();
 
                 // Adds into the list;
                 gaDataStreams.add(gaDataStream);
@@ -191,14 +196,16 @@ public class GAAdminService {
                             createdProperty.getName(), dataStream);
             log.info("Created data stream {}", JsonFormat.printer().print(createdProperty));
 
-            GADataStreamDTO gaDataStream = new GADataStreamDTO();
-            gaDataStream.setId(parseId(createdDataStream.getName()));
-            gaDataStream.setName(createdDataStream.getName());
-            gaDataStream.setDisplayName(createdDataStream.getDisplayName());
-            gaDataStream.setProperty(createdProperty.getName());
-            gaDataStream.setStreamMeasurementId(
-                    createdDataStream.getWebStreamData().getMeasurementId());
-            gaDataStream.setStreamDefaultUrl(createdDataStream.getWebStreamData().getDefaultUri());
+            GADataStreamDTO gaDataStream =
+                    GADataStreamDTO.builder()
+                            .id(parseId(createdDataStream.getName()))
+                            .name(createdDataStream.getName())
+                            .displayName(createdDataStream.getDisplayName())
+                            .property(createdProperty.getName())
+                            .streamMeasurementId(
+                                    createdDataStream.getWebStreamData().getMeasurementId())
+                            .streamDefaultUrl(createdDataStream.getWebStreamData().getDefaultUri())
+                            .build();
 
             return gaDataStream;
         } catch (IOException e) {