Ver Fonte

Refactor

wfansh há 6 meses atrás
pai
commit
d4b4866888

+ 1 - 1
src/main/java/com/wechi/adweb/bridge/exception/BadRequestException.java

@@ -10,7 +10,7 @@ import lombok.Data;
 @Data
 public class BadRequestException extends Exception {
 
-    private OpenAPIRequest apiRequest;
+    private OpenAPIRequest<?> apiRequest;
 
     public BadRequestException(OpenAPIRequest<?> apiRequest) {
         this.apiRequest = apiRequest;

+ 14 - 18
src/main/java/com/wechi/adweb/bridge/google/analytics/service/GAAdminService.java

@@ -52,12 +52,12 @@ public class GAAdminService {
     }
 
     public List<GAAccountDTO> listGAAccounts() throws DataException {
-        List<GAAccountDTO> gaAccounts = Lists.newArrayList();
         try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
                 AnalyticsAdminServiceClient.create(adminServiceSettings)) {
+            List<GAAccountDTO> gaAccounts = Lists.newArrayList();
+
             // Initializes the list request with default settings.
             ListAccountsRequest request = ListAccountsRequest.getDefaultInstance();
-
             for (Account account : analyticsAdminServiceClient.listAccounts(request).iterateAll()) {
                 GAAccountDTO gaAccount =
                         GAAccountDTO.builder()
@@ -82,9 +82,10 @@ public class GAAdminService {
 
     public List<GAPropertyDTO> listGAProperties(String accountResourceName, boolean withDataStreams)
             throws DataException {
-        List<GAPropertyDTO> gaProperties = Lists.newArrayList();
         try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
                 AnalyticsAdminServiceClient.create(adminServiceSettings)) {
+            List<GAPropertyDTO> gaProperties = Lists.newArrayList();
+
             // Initializes the list request with account resource name filter.
             // See
             // https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1beta/properties/list#http-request
@@ -92,7 +93,6 @@ public class GAAdminService {
                     ListPropertiesRequest.newBuilder()
                             .setFilter("ancestor:" + accountResourceName)
                             .build();
-
             for (Property property :
                     analyticsAdminServiceClient.listProperties(request).iterateAll()) {
                 GAPropertyDTO gaProperty =
@@ -142,13 +142,13 @@ public class GAAdminService {
 
     public List<GADataStreamDTO> listGADataStreams(String propertyResourceName)
             throws DataException {
-        List<GADataStreamDTO> gaDataStreams = Lists.newArrayList();
         try (AnalyticsAdminServiceClient analyticsAdminServiceClient =
                 AnalyticsAdminServiceClient.create(adminServiceSettings)) {
+            List<GADataStreamDTO> gaDataStreams = Lists.newArrayList();
+
             // Initializes the list request with parent property.
             ListDataStreamsRequest request =
                     ListDataStreamsRequest.newBuilder().setParent(propertyResourceName).build();
-
             for (DataStream dataStream :
                     analyticsAdminServiceClient.listDataStreams(request).iterateAll()) {
                 GADataStreamDTO gaDataStream =
@@ -204,18 +204,14 @@ public class GAAdminService {
                             createdProperty.getName(), dataStream);
             log.info("Created data stream {}", JsonFormat.printer().print(createdProperty));
 
-            GADataStreamDTO gaDataStream =
-                    GADataStreamDTO.builder()
-                            .id(parseId(createdDataStream.getName()))
-                            .resourceName(createdDataStream.getName())
-                            .displayName(createdDataStream.getDisplayName())
-                            .property(createdProperty.getName())
-                            .streamMeasurementId(
-                                    createdDataStream.getWebStreamData().getMeasurementId())
-                            .streamDefaultUrl(createdDataStream.getWebStreamData().getDefaultUri())
-                            .build();
-
-            return gaDataStream;
+            return GADataStreamDTO.builder()
+                    .id(parseId(createdDataStream.getName()))
+                    .resourceName(createdDataStream.getName())
+                    .displayName(createdDataStream.getDisplayName())
+                    .property(createdProperty.getName())
+                    .streamMeasurementId(createdDataStream.getWebStreamData().getMeasurementId())
+                    .streamDefaultUrl(createdDataStream.getWebStreamData().getDefaultUri())
+                    .build();
         } catch (IOException e) {
             log.error(e.getMessage());
             throw new DataException(e);