Skip to content

Commit

Permalink
#51 add new resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanakaryo authored and tanakaryo committed Feb 18, 2024
1 parent 1562241 commit 6f1daa6
Show file tree
Hide file tree
Showing 23 changed files with 763 additions and 0 deletions.
Binary file added services/cloud-build/app1/conv-file/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions services/cloud-build/app1/conv-file/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

node_modules
#!include:.gitignore
33 changes: 33 additions & 0 deletions services/cloud-build/app1/conv-file/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
30 changes: 30 additions & 0 deletions services/cloud-build/app1/conv-file/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
steps:
# clean install
- name: gcr.io/cloud-builders/mvn
entrypoint: mvn
args:
- "clean"
- "install"
- "-DskipTests=true"
# test
- name: gcr.io/cloud-builders/mvn
entrypoint: mvn
args: ['test']
# cloudfunction deploy
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
args:
- gcloud
- functions
- deploy
- feed-fmt-conv-fn
- --gen2
- --runtime=java17
- --region=asia-northeast1
- --service-account=437530287615-compute@developer.gserviceaccount.com
- --source=.
- --entry-point=com.myapp.convfl.function.FeedFmtConverterFn
- --memory=512MB
- --trigger-event-filters=type=google.cloud.storage.object.v1.finalized
- --trigger-event-filters=bucket=testcfneventjp20240129
- --set-env-vars=UPLOADBKT=testuploadcfneventjp20240130
- --set-env-vars=PROJECTID=dataflowtest002
103 changes: 103 additions & 0 deletions services/cloud-build/app1/conv-file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp.convfl</groupId>
<artifactId>conv-file</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>conv-file</name>

<properties>
<java.version>17</java.version>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.20.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Required for Function primitives -->
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.32.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloudevent-types</artifactId>
<version>0.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-csv -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.11.0</version>
<configuration>
<functionTarget>com.myapp.convfl.function.FeedFmtConverterFn</functionTarget>
</configuration>
</plugin>
</plugins>
</build>
</project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.myapp.convfl.constants;

/**
* 共通定数クラス
*
* 特定ビジネス,ドメインに依存しない定数を定義
*/
public class CommonConstants {

/**
* コンストラクタ
*/
private CommonConstants() {
}

// Directory-Separator
public static final String DIR_SEPARATOR = "/";

// Line-Separator
public static final String LINE_SEPARATOR_CRLF = "\r\n";

// Column-Separator
public static final String COLUMN_SEPARATOR_COMMA = ",";

// Colum-Quotation
public static final char COLUMN_QUOTE_DOUBLE = '"';

// File-Extention
public static final String FILE_EXT_CSV = ".csv";
public static final String FILE_EXT_JSON = ".json";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.myapp.convfl.exif;

import org.apache.commons.lang3.StringUtils;

import com.myapp.convfl.constants.CommonConstants;

/**
* External Feed Interface difinition class.
* フィードデータ 外部インターフェース情報定義クラス
*/
public class ExternalFeedIfDefinition implements IfDefinition {

/** 出力対象項目 */
private String[] outputColumns;

/** 改行文字 */
private String lineSeparator;

/** 項目区切り文字 */
private String columnSeparator;

/** 項目囲い文字 */
private char columnQuote;

/** ヘッダーレコード */
private String headerRecord;

/**
* コンストラクタ
*
* @param outputColumns 出力対象項目
* @param lineSeparator 改行文字
* @param columnSeparator 項目区切り文字
* @param columnQuote ヘッダーレコード
*/
public ExternalFeedIfDefinition(String[] outputColumns, String lineSeparator,
String columnSeparator, char columnQuote) {
this.outputColumns = outputColumns;
this.lineSeparator = lineSeparator;
this.columnSeparator = columnSeparator;
this.columnQuote = columnQuote;
}

/**
* ヘッダーレコード取得
*
* @return ヘッダーレコード
*/
public String getHeaderRecord() {
// 作成済みの場合はメンバ変数を返却
if (StringUtils.isNotEmpty(this.headerRecord)) {
return this.headerRecord;
}

// データがない場合生成する
StringBuilder sb = new StringBuilder();
for (String column : this.outputColumns) {
sb.append(this.columnQuote)
.append(column)
.append(this.columnQuote)
.append(this.columnSeparator);
}
this.headerRecord = StringUtils.removeEnd(sb.toString(), this.columnSeparator) + this.lineSeparator;
return headerRecord;
}

/**
* 項目並び順を取得
*
* @return 項目並び順(String配列)
*/
public String[] getColumnsOrder() {
// 基本的にヘッダーレコードと同じ並び順となる想定
return this.outputColumns;
}

/**
* 出力ファイル拡張子を取得
*
* @return 出力ファイル拡張子
*/
public String getOutputFileExt() {
// Feedは全てCSVとなる想定
return CommonConstants.FILE_EXT_CSV;
}

@Override
public String getLineSeparator() {
return this.lineSeparator;
}

@Override
public String getColumnSeparator() {
return this.columnSeparator;
}

@Override
public char getColumnQuote() {
return this.columnQuote;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.myapp.convfl.exif;

/**
* Interface definition class
*/
public interface IfDefinition {

/**
* Get line separator.
*
* @return line Separator
*/
String getLineSeparator();

/**
* Get column separator.
*
* @return column separator
*/
String getColumnSeparator();

/**
* Get column quotation.
*
* @return column quotation
*/
char getColumnQuote();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.myapp.convfl.factory;

import org.apache.commons.lang3.StringUtils;

import com.myapp.convfl.constants.CommonConstants;
import com.myapp.convfl.type.FeedType;

/**
* FeedTypeFactory
*
* FeedType生成クラス
*/
public final class FeedTypeFactory {

/** FeedNameに該当する文字配列の番号 */
private static final int NUMBER_OF_FEED_NAME = 1;

/**
* FeedTypeオブジェクトを生成・提供する
*
* @param gcsFileName CloudStorageファイル名
* @return FeedTypeオブジェクト
*/
public static FeedType getFeedType(String gcsFileName) {

// CloudStorageファイル名分割
String[] splitedDataName = StringUtils.split(gcsFileName, CommonConstants.DIR_SEPARATOR);

// フィードタイプ取得
return FeedType.valueOf(new String(splitedDataName[NUMBER_OF_FEED_NAME]).toUpperCase());
}
}
Loading

0 comments on commit 6f1daa6

Please sign in to comment.