Skip to content

Commit 56055ce

Browse files
authored
Merge pull request #6 from tanakaryo/Feat-00003
#4 add new resource.
2 parents 2c4b52b + 9fe739c commit 56055ce

23 files changed

+763
-0
lines changed
6 KB
Binary file not shown.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
node_modules
17+
#!include:.gitignore
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
steps:
2+
# clean install
3+
- name: gcr.io/cloud-builders/mvn
4+
entrypoint: mvn
5+
args:
6+
- "clean"
7+
- "install"
8+
- "-DskipTests=true"
9+
# test
10+
- name: gcr.io/cloud-builders/mvn
11+
entrypoint: mvn
12+
args: ['test']
13+
# cloudfunction deploy
14+
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
15+
args:
16+
- gcloud
17+
- functions
18+
- deploy
19+
- feed-fmt-conv-fn
20+
- --gen2
21+
- --runtime=java17
22+
- --region=asia-northeast1
23+
- --service-account=437530287615-compute@developer.gserviceaccount.com
24+
- --source=.
25+
- --entry-point=com.myapp.convfl.function.FeedFmtConverterFn
26+
- --memory=512MB
27+
- --trigger-event-filters=type=google.cloud.storage.object.v1.finalized
28+
- --trigger-event-filters=bucket=testcfneventjp20240129
29+
- --set-env-vars=UPLOADBKT=testuploadcfneventjp20240130
30+
- --set-env-vars=PROJECTID=dataflowtest002

java/feature1/app1/conv-file/pom.xml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
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">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.myapp.convfl</groupId>
6+
<artifactId>conv-file</artifactId>
7+
<packaging>jar</packaging>
8+
<version>1.0-SNAPSHOT</version>
9+
<name>conv-file</name>
10+
11+
<properties>
12+
<java.version>17</java.version>
13+
<maven.compiler.target>17</maven.compiler.target>
14+
<maven.compiler.source>17</maven.compiler.source>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.google.cloud</groupId>
21+
<artifactId>libraries-bom</artifactId>
22+
<version>26.20.0</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>3.8.1</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<!-- Required for Function primitives -->
37+
<dependency>
38+
<groupId>com.google.cloud.functions</groupId>
39+
<artifactId>functions-framework-api</artifactId>
40+
<version>1.1.0</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.google.cloud</groupId>
45+
<artifactId>google-cloud-storage</artifactId>
46+
<version>2.32.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.google.cloud</groupId>
50+
<artifactId>google-cloudevent-types</artifactId>
51+
<version>0.14.0</version>
52+
</dependency>
53+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-api</artifactId>
57+
<version>2.0.12</version>
58+
</dependency>
59+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
60+
<dependency>
61+
<groupId>org.projectlombok</groupId>
62+
<artifactId>lombok</artifactId>
63+
<version>1.18.30</version>
64+
<scope>provided</scope>
65+
</dependency>
66+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
67+
<dependency>
68+
<groupId>org.apache.commons</groupId>
69+
<artifactId>commons-lang3</artifactId>
70+
<version>3.14.0</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.fasterxml.jackson.core</groupId>
74+
<artifactId>jackson-core</artifactId>
75+
<version>2.16.1</version>
76+
</dependency>
77+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
78+
<dependency>
79+
<groupId>com.fasterxml.jackson.core</groupId>
80+
<artifactId>jackson-databind</artifactId>
81+
<version>2.16.1</version>
82+
</dependency>
83+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-csv -->
84+
<dependency>
85+
<groupId>com.fasterxml.jackson.dataformat</groupId>
86+
<artifactId>jackson-dataformat-csv</artifactId>
87+
<version>2.16.1</version>
88+
</dependency>
89+
</dependencies>
90+
91+
<build>
92+
<plugins>
93+
<plugin>
94+
<groupId>com.google.cloud.functions</groupId>
95+
<artifactId>function-maven-plugin</artifactId>
96+
<version>0.11.0</version>
97+
<configuration>
98+
<functionTarget>com.myapp.convfl.function.FeedFmtConverterFn</functionTarget>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</project>
6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.myapp.convfl.constants;
2+
3+
/**
4+
* 共通定数クラス
5+
*
6+
* 特定ビジネス,ドメインに依存しない定数を定義
7+
*/
8+
public class CommonConstants {
9+
10+
/**
11+
* コンストラクタ
12+
*/
13+
private CommonConstants() {
14+
}
15+
16+
// Directory-Separator
17+
public static final String DIR_SEPARATOR = "/";
18+
19+
// Line-Separator
20+
public static final String LINE_SEPARATOR_CRLF = "\r\n";
21+
22+
// Column-Separator
23+
public static final String COLUMN_SEPARATOR_COMMA = ",";
24+
25+
// Colum-Quotation
26+
public static final char COLUMN_QUOTE_DOUBLE = '"';
27+
28+
// File-Extention
29+
public static final String FILE_EXT_CSV = ".csv";
30+
public static final String FILE_EXT_JSON = ".json";
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.myapp.convfl.exif;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
import com.myapp.convfl.constants.CommonConstants;
6+
7+
/**
8+
* External Feed Interface difinition class.
9+
* フィードデータ 外部インターフェース情報定義クラス
10+
*/
11+
public class ExternalFeedIfDefinition implements IfDefinition {
12+
13+
/** 出力対象項目 */
14+
private String[] outputColumns;
15+
16+
/** 改行文字 */
17+
private String lineSeparator;
18+
19+
/** 項目区切り文字 */
20+
private String columnSeparator;
21+
22+
/** 項目囲い文字 */
23+
private char columnQuote;
24+
25+
/** ヘッダーレコード */
26+
private String headerRecord;
27+
28+
/**
29+
* コンストラクタ
30+
*
31+
* @param outputColumns 出力対象項目
32+
* @param lineSeparator 改行文字
33+
* @param columnSeparator 項目区切り文字
34+
* @param columnQuote ヘッダーレコード
35+
*/
36+
public ExternalFeedIfDefinition(String[] outputColumns, String lineSeparator,
37+
String columnSeparator, char columnQuote) {
38+
this.outputColumns = outputColumns;
39+
this.lineSeparator = lineSeparator;
40+
this.columnSeparator = columnSeparator;
41+
this.columnQuote = columnQuote;
42+
}
43+
44+
/**
45+
* ヘッダーレコード取得
46+
*
47+
* @return ヘッダーレコード
48+
*/
49+
public String getHeaderRecord() {
50+
// 作成済みの場合はメンバ変数を返却
51+
if (StringUtils.isNotEmpty(this.headerRecord)) {
52+
return this.headerRecord;
53+
}
54+
55+
// データがない場合生成する
56+
StringBuilder sb = new StringBuilder();
57+
for (String column : this.outputColumns) {
58+
sb.append(this.columnQuote)
59+
.append(column)
60+
.append(this.columnQuote)
61+
.append(this.columnSeparator);
62+
}
63+
this.headerRecord = StringUtils.removeEnd(sb.toString(), this.columnSeparator) + this.lineSeparator;
64+
return headerRecord;
65+
}
66+
67+
/**
68+
* 項目並び順を取得
69+
*
70+
* @return 項目並び順(String配列)
71+
*/
72+
public String[] getColumnsOrder() {
73+
// 基本的にヘッダーレコードと同じ並び順となる想定
74+
return this.outputColumns;
75+
}
76+
77+
/**
78+
* 出力ファイル拡張子を取得
79+
*
80+
* @return 出力ファイル拡張子
81+
*/
82+
public String getOutputFileExt() {
83+
// Feedは全てCSVとなる想定
84+
return CommonConstants.FILE_EXT_CSV;
85+
}
86+
87+
@Override
88+
public String getLineSeparator() {
89+
return this.lineSeparator;
90+
}
91+
92+
@Override
93+
public String getColumnSeparator() {
94+
return this.columnSeparator;
95+
}
96+
97+
@Override
98+
public char getColumnQuote() {
99+
return this.columnQuote;
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.myapp.convfl.exif;
2+
3+
/**
4+
* Interface definition class
5+
*/
6+
public interface IfDefinition {
7+
8+
/**
9+
* Get line separator.
10+
*
11+
* @return line Separator
12+
*/
13+
String getLineSeparator();
14+
15+
/**
16+
* Get column separator.
17+
*
18+
* @return column separator
19+
*/
20+
String getColumnSeparator();
21+
22+
/**
23+
* Get column quotation.
24+
*
25+
* @return column quotation
26+
*/
27+
char getColumnQuote();
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.myapp.convfl.factory;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
import com.myapp.convfl.constants.CommonConstants;
6+
import com.myapp.convfl.type.FeedType;
7+
8+
/**
9+
* FeedTypeFactory
10+
*
11+
* FeedType生成クラス
12+
*/
13+
public final class FeedTypeFactory {
14+
15+
/** FeedNameに該当する文字配列の番号 */
16+
private static final int NUMBER_OF_FEED_NAME = 1;
17+
18+
/**
19+
* FeedTypeオブジェクトを生成・提供する
20+
*
21+
* @param gcsFileName CloudStorageファイル名
22+
* @return FeedTypeオブジェクト
23+
*/
24+
public static FeedType getFeedType(String gcsFileName) {
25+
26+
// CloudStorageファイル名分割
27+
String[] splitedDataName = StringUtils.split(gcsFileName, CommonConstants.DIR_SEPARATOR);
28+
29+
// フィードタイプ取得
30+
return FeedType.valueOf(new String(splitedDataName[NUMBER_OF_FEED_NAME]).toUpperCase());
31+
}
32+
}

0 commit comments

Comments
 (0)