Skip to content

Commit 5d7b594

Browse files
committed
build: moved connectors to core
1 parent 9f40124 commit 5d7b594

39 files changed

+2329
-0
lines changed

core/riot-faker/gradle.properties

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Copyright 2022-2023 The RIOT authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
project_description = RIOT Faker
19+
automatic.module.name = com.redis.riot.faker

core/riot-faker/riot-faker.gradle

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2020-2023 The RIOT authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
dependencies {
19+
implementation 'org.springframework.batch:spring-batch-infrastructure'
20+
api group: 'net.datafaker', name: 'datafaker', version: datafakerVersion
21+
}
22+
23+
compileJava {
24+
options.compilerArgs += ["-AprojectPath=${project.group}/${project.name}"]
25+
}
26+
27+
if (!(project.findProperty('automatic.module.name.skip') ?: false).toBoolean()) {
28+
jar {
29+
manifest {
30+
attributes('Automatic-Module-Name': project.findProperty('automatic.module.name'))
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.redis.riot.faker;
2+
3+
import java.util.AbstractMap;
4+
import java.util.HashMap;
5+
import java.util.LinkedHashMap;
6+
import java.util.Locale;
7+
import java.util.Map;
8+
import java.util.Map.Entry;
9+
import java.util.stream.Collectors;
10+
11+
import org.springframework.batch.item.ItemReader;
12+
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
13+
import org.springframework.util.Assert;
14+
import org.springframework.util.ClassUtils;
15+
16+
import net.datafaker.Faker;
17+
18+
/**
19+
* {@link ItemReader} that generates HashMaps using Faker.
20+
*
21+
* @author Julien Ruaux
22+
*/
23+
public class FakerItemReader extends AbstractItemCountingItemStreamItemReader<Map<String, Object>> {
24+
25+
public static final Locale DEFAULT_LOCALE = Locale.getDefault();
26+
27+
private Map<String, String> expressions = new LinkedHashMap<>();
28+
private Locale locale = DEFAULT_LOCALE;
29+
30+
private Faker faker;
31+
private Map<String, String> fields;
32+
33+
public FakerItemReader() {
34+
setName(ClassUtils.getShortName(getClass()));
35+
}
36+
37+
public void setLocale(Locale locale) {
38+
this.locale = locale;
39+
}
40+
41+
public void setExpressions(Map<String, String> fields) {
42+
this.expressions = fields;
43+
}
44+
45+
@Override
46+
protected synchronized void doOpen() throws Exception {
47+
Assert.notEmpty(expressions, "No field specified");
48+
if (fields == null) {
49+
fields = expressions.entrySet().stream().map(this::normalizeField)
50+
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
51+
}
52+
faker = new Faker(locale);
53+
}
54+
55+
private Entry<String, String> normalizeField(Entry<String, String> field) {
56+
if (field.getValue().startsWith("#{")) {
57+
return field;
58+
}
59+
return new AbstractMap.SimpleEntry<>(field.getKey(), "#{" + field.getValue() + "}");
60+
}
61+
62+
@Override
63+
protected Map<String, Object> doRead() throws Exception {
64+
Map<String, Object> map = new HashMap<>();
65+
fields.forEach((k, v) -> map.put(k, faker.expression(v)));
66+
return map;
67+
}
68+
69+
@Override
70+
protected synchronized void doClose() {
71+
faker = null;
72+
}
73+
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.redis.riot.faker;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
import org.springframework.batch.item.ExecutionContext;
11+
import org.springframework.batch.item.ItemReader;
12+
13+
class FakerReaderTests {
14+
15+
public static <T> List<T> readAll(ItemReader<T> reader) throws Exception {
16+
List<T> list = new ArrayList<>();
17+
T element;
18+
while ((element = reader.read()) != null) {
19+
list.add(element);
20+
}
21+
return list;
22+
}
23+
24+
@Test
25+
void fakerReader() throws Exception {
26+
int count = 100;
27+
FakerItemReader reader = new FakerItemReader();
28+
Map<String, String> fields = new LinkedHashMap<>();
29+
fields.put("firstName", "Name.first_name");
30+
fields.put("lastName", "Name.last_name");
31+
reader.setExpressions(fields);
32+
reader.setMaxItemCount(count);
33+
reader.open(new ExecutionContext());
34+
List<Map<String, Object>> items = readAll(reader);
35+
reader.close();
36+
Assertions.assertEquals(count, items.size());
37+
Assertions.assertTrue(items.get(0).containsKey("firstName"));
38+
Assertions.assertTrue(items.get(0).containsKey("lastName"));
39+
}
40+
41+
}

core/riot-file/gradle.properties

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Copyright 2022-2023 The RIOT authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
project_description = RIOT File
19+
automatic.module.name = com.redis.riot.file

core/riot-file/riot-file.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2020-2023 The RIOT authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
dependencies {
19+
implementation 'org.springframework.batch:spring-batch-infrastructure'
20+
api 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
21+
api 'org.springframework:spring-oxm'
22+
api group: 'io.awspring.cloud', name: 'spring-cloud-aws-starter-s3', version: awsVersion
23+
api group: 'com.google.cloud', name: 'spring-cloud-gcp-starter-storage', version: gcpVersion
24+
}
25+
26+
compileJava {
27+
options.compilerArgs += ["-AprojectPath=${project.group}/${project.name}"]
28+
}
29+
30+
if (!(project.findProperty('automatic.module.name.skip') ?: false).toBoolean()) {
31+
jar {
32+
manifest {
33+
attributes('Automatic-Module-Name': project.findProperty('automatic.module.name'))
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.redis.riot.file;
2+
3+
import java.io.IOException;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import org.springframework.core.io.Resource;
8+
9+
public abstract class AbstractRegistry<T> {
10+
11+
private final Map<String, FileType> extensions = new HashMap<>();
12+
private final Map<FileType, T> factories = new HashMap<>();
13+
14+
public void register(FileType fileType, T factory) {
15+
factories.put(fileType, factory);
16+
if (fileType != null) {
17+
for (String extension : fileType.getExtensions()) {
18+
extensions.put(extension, fileType);
19+
}
20+
}
21+
}
22+
23+
protected T factory(Resource resource, FileOptions options) throws IOException {
24+
FileType fileType = fileType(resource, options);
25+
if (fileType == null) {
26+
throw new UnknownFileTypeException(resource.getFilename());
27+
}
28+
T factory = factories.get(fileType);
29+
if (factory == null) {
30+
new UnsupportedFileTypeException(fileType);
31+
}
32+
return factory;
33+
}
34+
35+
private FileType fileType(Resource resource, FileOptions options) {
36+
if (options.getFileType() == null) {
37+
return extensions.get(Files.extension(resource.getFilename()));
38+
}
39+
return options.getFileType();
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.redis.riot.file;
2+
3+
import lombok.ToString;
4+
5+
@ToString
6+
public class AwsCredentials {
7+
8+
private String accessKey;
9+
10+
private String secretKey;
11+
12+
public String getAccessKey() {
13+
return accessKey;
14+
}
15+
16+
public void setAccessKey(String accessKey) {
17+
this.accessKey = accessKey;
18+
}
19+
20+
public String getSecretKey() {
21+
return secretKey;
22+
}
23+
24+
public void setSecretKey(String secretKey) {
25+
this.secretKey = secretKey;
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.redis.riot.file;
2+
3+
import java.net.URI;
4+
import java.util.Optional;
5+
6+
import lombok.ToString;
7+
import software.amazon.awssdk.regions.Region;
8+
9+
@ToString
10+
public class AwsOptions {
11+
12+
private AwsCredentials credentials = new AwsCredentials();
13+
private Optional<Region> region = Optional.empty();
14+
private Optional<URI> endpoint = Optional.empty();
15+
16+
public AwsCredentials getCredentials() {
17+
return credentials;
18+
}
19+
20+
public void setCredentials(AwsCredentials credentials) {
21+
this.credentials = credentials;
22+
}
23+
24+
public Optional<Region> getRegion() {
25+
return region;
26+
}
27+
28+
public void setRegion(Region region) {
29+
this.region = Optional.ofNullable(region);
30+
}
31+
32+
public Optional<URI> getEndpoint() {
33+
return endpoint;
34+
}
35+
36+
public void setEndpoint(URI endpoint) {
37+
this.endpoint = Optional.ofNullable(endpoint);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)