Skip to content
Snippets Groups Projects
Commit f0ac1083 authored by OZGCloud's avatar OZGCloud
Browse files

(auto)configuration of file manager and dummy implementation as fallback

parent db170467
Branches
Tags
No related merge requests found
Showing
with 124 additions and 16 deletions
package de.ozgcloud.apilib.file.dummy;
import java.io.IOException;
import java.io.OutputStream;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import de.ozgcloud.apilib.file.OzgCloudFile;
import de.ozgcloud.apilib.file.OzgCloudFileId;
import de.ozgcloud.apilib.file.OzgCloudFileService;
@Service
@ConditionalOnMissingBean(OzgCloudFileService.class)
public class DummyOzgCloudFileService implements OzgCloudFileService {
private static final byte[] TEST_DATA = "Hello World!".getBytes();
public static final OzgCloudFile DUMMY_FILE = OzgCloudFile.builder()
.id(OzgCloudFileId.from("42"))
.contentType("text/plain")
.size(TEST_DATA.length)
.name("helloWorld.txt")
.build();
@Override
public OzgCloudFile getFile(OzgCloudFileId id) {
return DUMMY_FILE;
}
@Override
public void writeFileDataToStream(OzgCloudFileId id, OutputStream streamToWriteData) {
try {
streamToWriteData.write(TEST_DATA);
} catch (IOException e) {
throw new TechnicalException("Erro wrting dummy data.", e);
}
}
}
...@@ -7,7 +7,7 @@ import java.util.concurrent.TimeUnit; ...@@ -7,7 +7,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import org.springframework.beans.factory.annotation.Autowired; import org.mapstruct.factory.Mappers;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -38,8 +38,7 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService { ...@@ -38,8 +38,7 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService {
@GrpcClient("file-manager") @GrpcClient("file-manager")
private final BinaryFileServiceStub asyncServiceStub; private final BinaryFileServiceStub asyncServiceStub;
@Autowired private final OzgCloudFileMapper mapper = Mappers.getMapper(OzgCloudFileMapper.class);
private final OzgCloudFileMapper mapper;
static final int CHUNK_SIZE = 255 * 1024; static final int CHUNK_SIZE = 255 * 1024;
......
...@@ -11,5 +11,5 @@ public interface OzgCloudFileMapper { ...@@ -11,5 +11,5 @@ public interface OzgCloudFileMapper {
OzgCloudFile fromGrpc(GrpcOzgFile grpcFile); OzgCloudFile fromGrpc(GrpcOzgFile grpcFile);
OzgCloudFileId toOzgCloudFileId(String string); OzgCloudFileId toOzgCloudFileId(String id);
} }
...@@ -10,6 +10,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean ...@@ -10,6 +10,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.errorhandling.NotFoundException; import de.ozgcloud.apilib.errorhandling.NotFoundException;
import de.ozgcloud.apilib.file.dummy.DummyOzgCloudFileService;
import de.ozgcloud.apilib.vorgang.OzgCloudAntragsteller;
import de.ozgcloud.apilib.vorgang.OzgCloudEingang; import de.ozgcloud.apilib.vorgang.OzgCloudEingang;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgang; import de.ozgcloud.apilib.vorgang.OzgCloudVorgang;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangHeader; import de.ozgcloud.apilib.vorgang.OzgCloudVorgangHeader;
...@@ -33,7 +35,10 @@ public class DummyVorgangService implements OzgCloudVorgangService { ...@@ -33,7 +35,10 @@ public class DummyVorgangService implements OzgCloudVorgangService {
.createdAt(ZonedDateTime.now()) .createdAt(ZonedDateTime.now())
.aktenzeichen("ABC-123-04") .aktenzeichen("ABC-123-04")
.build(); .build();
private static final OzgCloudEingang EINGANG_1 = OzgCloudEingang.builder().build(); private static final OzgCloudEingang EINGANG_1 = OzgCloudEingang.builder()
.antragsteller(OzgCloudAntragsteller.builder().build())
.representations(List.of(DummyOzgCloudFileService.DUMMY_FILE))
.build();
private static final String VORGANG_NAME_2 = "Antrag auf Führung eines Kampfhamsters"; private static final String VORGANG_NAME_2 = "Antrag auf Führung eines Kampfhamsters";
private static final String VORGANG_NR_2 = "5678"; private static final String VORGANG_NR_2 = "5678";
......
...@@ -5,6 +5,8 @@ import org.springframework.context.ApplicationListener; ...@@ -5,6 +5,8 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import de.ozgcloud.apilib.file.OzgCloudFileId;
import de.ozgcloud.apilib.file.OzgCloudFileService;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId; import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangService; import de.ozgcloud.apilib.vorgang.OzgCloudVorgangService;
...@@ -13,10 +15,15 @@ class DemoRunner implements ApplicationListener<ContextRefreshedEvent> { ...@@ -13,10 +15,15 @@ class DemoRunner implements ApplicationListener<ContextRefreshedEvent> {
@Autowired @Autowired
private OzgCloudVorgangService vorgangService; private OzgCloudVorgangService vorgangService;
@Autowired
private OzgCloudFileService fileService;
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println(vorgangService.getById(OzgCloudVorgangId.from("647885a50b105b1e4995378e"))); System.out.println(vorgangService.getById(OzgCloudVorgangId.from("647885a50b105b1e4995378e")));
System.out.println(fileService.getFile(OzgCloudFileId.from("630363d5b5816c0d8efd6f19")));
} }
} }
ozgcloud: ozgcloud:
vorgang-manager: vorgang-manager:
address: static://127.0.0.1:9090 address: static://127.0.0.1:9090
negotiation-type: plaintext
file-manager:
address: ${ozgcloud.vorgang-manager.address}
negotiation-type: plaintext
\ No newline at end of file
package de.ozgcloud.client.autoconfigure; package de.ozgcloud.client.autoconfigure;
import org.springframework.beans.factory.annotation.Value; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import de.ozgcloud.apilib.file.dummy.DummyOzgCloudFileService;
import de.ozgcloud.apilib.file.grpc.GrpcOzgCloudFileService;
import de.ozgcloud.apilib.vorgang.dummy.DummyVorgangService; import de.ozgcloud.apilib.vorgang.dummy.DummyVorgangService;
import de.ozgcloud.apilib.vorgang.grpc.GrpcVorgangService; import de.ozgcloud.apilib.vorgang.grpc.GrpcVorgangService;
import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration; import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration;
import net.devh.boot.grpc.client.config.GrpcChannelProperties; import net.devh.boot.grpc.client.config.GrpcChannelProperties;
import net.devh.boot.grpc.client.config.GrpcChannelsProperties; import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
import net.devh.boot.grpc.client.config.NegotiationType;
@AutoConfiguration(before = GrpcClientAutoConfiguration.class) @AutoConfiguration(before = GrpcClientAutoConfiguration.class)
@Import({ GrpcVorgangService.class, DummyVorgangService.class }) @ComponentScan("de.ozgcloud.client.autoconfigure")
@Import({
GrpcVorgangService.class, DummyVorgangService.class,
GrpcOzgCloudFileService.class, DummyOzgCloudFileService.class
})
public class OzgCloudClientAutoConfiguration { public class OzgCloudClientAutoConfiguration {
private static final String CLIENT_NAME_VORGANG_MANAGER = "vorgang-manager"; private static final String CLIENT_NAME_VORGANG_MANAGER = "vorgang-manager";
private static final String CLIENT_NAME_FILE_MANAGER = "file-manager";
@Value("${ozgcloud.vorgang-manager.address:null}") @Autowired
private String address; private OzgCloudVorgangManagerProperties vorgangManagerProperties;
@Autowired
private OzgCloudFileManagerProperties fileManagerProperties;
@Bean @Bean
@ConditionalOnProperty("ozgcloud.vorgang-manager.address") @ConditionalOnProperty("ozgcloud.vorgang-manager.address")
GrpcChannelsProperties channelProperties() { GrpcChannelsProperties channelProperties() {
var properties = new GrpcChannelsProperties(); var properties = new GrpcChannelsProperties();
var clientMap = properties.getClient();
addVorgangManager(clientMap);
addFileManager(clientMap);
return properties;
}
private void addVorgangManager(Map<String, GrpcChannelProperties> clientMap) {
var channelProps = new GrpcChannelProperties(); var channelProps = new GrpcChannelProperties();
channelProps.setAddress(vorgangManagerProperties.getAddress());
channelProps.setNegotiationType(vorgangManagerProperties.getNegotiationType());
properties.getClient().put(CLIENT_NAME_VORGANG_MANAGER, channelProps); clientMap.put(CLIENT_NAME_VORGANG_MANAGER, channelProps);
}
channelProps.setAddress(address); private void addFileManager(Map<String, GrpcChannelProperties> clientMap) {
channelProps.setNegotiationType(NegotiationType.PLAINTEXT); var channelProps = new GrpcChannelProperties();
channelProps.setAddress(fileManagerProperties.getAddress());
channelProps.setNegotiationType(fileManagerProperties.getNegotiationType());
return properties; clientMap.put(CLIENT_NAME_FILE_MANAGER, channelProps);
} }
} }
package de.ozgcloud.client.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import lombok.Setter;
import net.devh.boot.grpc.client.config.NegotiationType;
@Getter
@Setter
@Configuration
@ConfigurationProperties("ozgcloud.file-manager")
public class OzgCloudFileManagerProperties {
/**
* Network-Address of the File-Manager instance, starting with resolving
* protocol. Example for local use: static://127.0.0.1:9090
*/
private String address;
/**
* Negotiation Type for the gRPC connection - possible Values: PLAINTEXT, TLS
*/
private NegotiationType negotiationType = NegotiationType.valueOf("TLS");
}
package de.ozgcloud.client.autoconfigure; package de.ozgcloud.client.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.devh.boot.grpc.client.config.NegotiationType;
@Getter @Getter
@Setter @Setter
@Configuration
@ConfigurationProperties("ozgcloud.vorgang-manager") @ConfigurationProperties("ozgcloud.vorgang-manager")
public class OzgCloudVorgangManagerProperties { public class OzgCloudVorgangManagerProperties {
/** /**
...@@ -17,5 +20,5 @@ public class OzgCloudVorgangManagerProperties { ...@@ -17,5 +20,5 @@ public class OzgCloudVorgangManagerProperties {
/** /**
* Negotiation Type for the gRPC connection - possible Values: PLAINTEXT, TLS * Negotiation Type for the gRPC connection - possible Values: PLAINTEXT, TLS
*/ */
private String negotiationType = "TLS"; private NegotiationType negotiationType = NegotiationType.valueOf("TLS");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment