wfansh hace 6 meses
padre
commit
e44c51bc95

+ 26 - 0
src/main/java/com/wechi/adweb/bridge/google/gtm/dto/GTMWorkspaceDTO.java

@@ -0,0 +1,26 @@
+package com.wechi.adweb.bridge.google.gtm.dto;
+
+import com.wechi.adweb.bridge.google.common.ResourceDTO;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * @author wfansh
+ */
+@Data
+@SuperBuilder
+@ToString(callSuper = true)
+@EqualsAndHashCode(callSuper = true)
+public class GTMWorkspaceDTO extends ResourceDTO {
+
+    private String accountId;
+
+    private String containerId;
+
+    private String description;
+
+    private String fingerprint;
+}

+ 41 - 2
src/main/java/com/wechi/adweb/bridge/google/gtm/service/GTMService.java

@@ -13,6 +13,7 @@ import com.google.auth.oauth2.GoogleCredentials;
 import com.wechi.adweb.bridge.exception.DataException;
 import com.wechi.adweb.bridge.google.gtm.dto.GTMAccountDTO;
 import com.wechi.adweb.bridge.google.gtm.dto.GTMContainerDTO;
+import com.wechi.adweb.bridge.google.gtm.dto.GTMWorkspaceDTO;
 import com.wechi.adweb.bridge.util.JsonUtils;
 
 import lombok.extern.slf4j.Slf4j;
@@ -116,7 +117,10 @@ public class GTMService {
                 gtmContainers.add(gtmContainer);
             }
 
-            log.info("listGTMContainers : {}", JsonUtils.toJson(gtmContainers));
+            log.info(
+                    "listGTMContainers for {} : {}",
+                    accountResourceName,
+                    JsonUtils.toJson(gtmContainers));
             return gtmContainers;
         } catch (IOException e) {
             log.error(e.getMessage());
@@ -156,7 +160,6 @@ public class GTMService {
                     .usageContext(createdContainer.getUsageContext())
                     .fingerprint(container.getFingerprint())
                     .build();
-
         } catch (IOException e) {
             log.error(e.getMessage());
             throw new DataException(e);
@@ -200,4 +203,40 @@ public class GTMService {
             throw new DataException(e);
         }
     }
+
+    public GTMWorkspaceDTO getDefaultWorkspace(String containerResourceName) throws DataException {
+        try {
+            Workspace workspace =
+                    tagManager
+                            .accounts()
+                            .containers()
+                            .workspaces()
+                            .list(containerResourceName)
+                            .execute()
+                            .getWorkspace()
+                            .stream()
+                            .filter(w -> w.getName().equalsIgnoreCase("Default Workspace"))
+                            .findFirst()
+                            .get();
+
+            log.info(
+                    "Get default workspace for {} : {}",
+                    containerResourceName,
+                    JsonUtils.toJson(workspace));
+
+            // Converts and returns.
+            return GTMWorkspaceDTO.builder()
+                    .id(workspace.getWorkspaceId())
+                    .resourceName(workspace.getPath())
+                    .displayName(workspace.getName())
+                    .accountId(workspace.getAccountId())
+                    .containerId(workspace.getContainerId())
+                    .description(workspace.getDescription())
+                    .fingerprint(workspace.getFingerprint())
+                    .build();
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            throw new DataException(e);
+        }
+    }
 }