Skip to content

Commit

Permalink
0.15.0:
Browse files Browse the repository at this point in the history
- Integrieren von Testmöglichkeiten für alle gewünschten  Pipeline-Operationen
- Aufruf der Tests von Weboberfläche
  • Loading branch information
basketmc committed Jun 22, 2023
1 parent 3400771 commit 64ff1cd
Show file tree
Hide file tree
Showing 30 changed files with 420 additions and 1,452 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
```
```

## [0.15.0]

### Added
```
- Integrieren von Testmöglichkeiten für alle gewünschten Pipeline-Operationen
- Aufruf der Tests von Weboberfläche
```

### Changed
```
```

### Fixed
```
```

## [0.14.1]

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>net.sberg</groupId>
<artifactId>openkim</artifactId>
<version>0.14.1</version>
<version>0.15.0</version>
<name>openkim</name>
<description>Open KIM Client Modul</description>

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/net/sberg/openkim/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/pop3log").setViewName("log/pop3log");
registry.addViewController("/smtplog").setViewName("log/smtplog");
registry.addViewController("/login").setViewName("login");
registry.addViewController("/mailanalyzer").setViewName("mailanalyzer/mailanalyzer");
registry.addViewController("/signencrypt").setViewName("signencrypt/signencrypt");
registry.addViewController("/decryptverify").setViewName("decryptverify/decryptverify");
registry.addViewController("/sendreceive").setViewName("sendreceive/sendreceive");
registry.addViewController("/pipelineoperationtest").setViewName("pipelineoperationtest/pipelineoperationtest");
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sberg/openkim/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public SecurityFilterChain defaultFilterChain(HttpSecurity http) throws Exceptio
.requestMatchers("/", "/konfiguration/**,", "/minimalkonfiguration/**",
"/openkimkeystore/**", "/konnektor/**", "/log/**", "/pop3log/**", "/smtplog/**",
"/dashboard/**", "/konnvzd/**", "/konnwebservice/**", "/konnntp/**",
"/mailanalyzer/**", "/signencrypt/**", "/decryptverify/**", "/sendreceive/**",
"/user/**")
"/pipelineoperationtest/**", "/user/**")
.hasAnyRole(EnumAuthRole.ROLE_ADMIN.getSuffix(), EnumAuthRole.ROLE_MONITORING.getSuffix())
.anyRequest().authenticated()
)
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/net/sberg/openkim/pipeline/PipelineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import jakarta.annotation.PostConstruct;
import net.sberg.openkim.pipeline.operation.IPipelineOperation;
import net.sberg.openkim.pipeline.operation.PipelineOperationLabel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class PipelineService {
Expand Down Expand Up @@ -36,12 +38,7 @@ public Class getOperationClass(String key) throws Exception {
throw new IllegalStateException("no operation available: "+key);
}

public List<IPipelineOperation> getOperations(List<String> keys) throws Exception {
List<IPipelineOperation> operations = new ArrayList<>();
for (Iterator<String> iterator = keys.iterator(); iterator.hasNext(); ) {
String key = iterator.next();
operations.add(getOperation(key));
}
return operations;
public List<PipelineOperationLabel> getTestableOperations() throws Exception {
return operationMap.keySet().stream().filter(s -> operationMap.get(s).isTestable()).map(s -> operationMap.get(s).createLabel()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import net.sberg.openkim.pipeline.PipelineService;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand All @@ -40,6 +42,10 @@ public default String getVendor() {
public default BiConsumer<DefaultPipelineOperationContext, Exception> getDefaultFailConsumer() {
return (context, e) -> {
context.setEnvironmentValue(getName(), ENV_EXCEPTION, e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
context.getLogger().logLine(sw.toString());
};
}
public default boolean hasError(DefaultPipelineOperationContext defaultPipelineOperationContext, String... prefixes) {
Expand All @@ -51,4 +57,16 @@ public default boolean hasError(DefaultPipelineOperationContext defaultPipelineO
return false;
}
public default void initialize(PipelineService pipelineService) throws Exception {}
public default boolean isTestable() {
return false;
}
public default String getHrText() {
return getOperationKey();
}
public default PipelineOperationLabel createLabel() {
PipelineOperationLabel label = new PipelineOperationLabel();
label.setLabel(getHrText());
label.setId(getOperationKey());
return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package net.sberg.openkim.testtool;
package net.sberg.openkim.pipeline.operation;

import lombok.Data;

@Data
public class MailAnalyzerResult {
public class PipelineOperationLabel {
private String id;
private String mailContent;
private String mailAnalyzedContent;
private String mailFilename;
private String label;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public class GetJobNumberOperation implements IPipelineOperation {

public static final String ENV_GET_JOB_NUMBER_RESPONSE = "getJobNumberResponse";

@Override
public boolean isTestable() {
return true;
}

@Override
public String getHrText() {
return "Hole eine Jobnumber vom Konnektor";
}

@Override
public String getName() {
return NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2023 sberg it-systeme GmbH
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package net.sberg.openkim.pipeline.operation.test;

import net.sberg.openkim.konfiguration.Konfiguration;
import net.sberg.openkim.konfiguration.KonfigurationService;
import net.sberg.openkim.konnektor.Konnektor;
import net.sberg.openkim.log.DefaultLogger;
import net.sberg.openkim.log.DefaultLoggerContext;
import net.sberg.openkim.log.LogService;
import net.sberg.openkim.pipeline.PipelineService;
import net.sberg.openkim.pipeline.operation.DefaultPipelineOperationContext;
import net.sberg.openkim.pipeline.operation.IPipelineOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.util.Map;

@Controller
public class PipelineOperationTestController {

private static final Logger log = LoggerFactory.getLogger(PipelineOperationTestController.class);

@Autowired
private LogService logService;
@Autowired
private PipelineService pipelineService;
@Autowired
private KonfigurationService konfigurationService;

@RequestMapping(value = "/pipelineoperationtest/uebersicht", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
public String uebersicht(Model model) throws Exception {
model.addAttribute("ops", pipelineService.getTestableOperations());
return "pipelineoperationtest/pipelineoperationtestFormular";
}

@RequestMapping(value = "/pipelineoperationtest/lade/{opId}", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
public String ladeOpIdForm(Model model, @PathVariable String opId) throws Exception {
model.addAttribute("konnektoren", konfigurationService.getKonfiguration().getKonnektoren());
model.addAttribute("opId", opId);
return "pipelineoperationtest/"+opId.replaceAll("\\.","_")+"_Formular";
}

@RequestMapping(value = "/pipelineoperationtest/execute", method = RequestMethod.POST, consumes = {"multipart/form-data"})
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public String execute(MultipartHttpServletRequest multipartRequest) throws Exception {
Map<String, String[]> multipartRequestParams = multipartRequest.getParameterMap();
Konfiguration konfiguration = konfigurationService.getKonfiguration();
Konnektor konnektor = null;
if (multipartRequestParams.containsKey("konnektorId")) {
konnektor = konfiguration.extractKonnektor(multipartRequestParams.get("konnektorId")[0], false);
}
if (konnektor == null) {
if (!multipartRequestParams.containsKey("withKonnektor") || Boolean.valueOf(multipartRequestParams.get("withKonnektor")[0])) {
return "Konnektor kann nicht gefunden werden";
}
}
DefaultLoggerContext defaultLoggerContext = new DefaultLoggerContext();
DefaultLogger logger = logService.createLogger(
defaultLoggerContext
.buildHtmlMode(true)
.buildKonnektor(konnektor)
.buildMandantId(konfiguration.getMandantId())
.buildClientSystemId(konfiguration.getClientSystemId())
.buildWorkplaceId(konfiguration.getWorkplaceId())
.buildKonfiguration(konfiguration)
);
IPipelineOperation pipelineOperation = pipelineService.getOperation(multipartRequestParams.get("opId")[0]);
DefaultPipelineOperationContext defaultPipelineOperationContext = new DefaultPipelineOperationContext(logger);
multipartRequestParams.keySet().stream().forEach(key -> {
defaultPipelineOperationContext.setEnvironmentValue(pipelineOperation.getName(), key, multipartRequestParams.get(key)[0]);
});

pipelineOperation.execute(
defaultPipelineOperationContext,
pipelineOperation.getDefaultOkConsumer(),
pipelineOperation.getDefaultFailConsumer()
);

logService.removeLogger(logger.getId());
return logger.getLogContentAsStr();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2023 sberg it-systeme GmbH
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package net.sberg.openkim.pipeline.operation.test;

import net.sberg.openkim.common.metrics.DefaultMetricFactory;
import net.sberg.openkim.konnektor.Konnektor;
import net.sberg.openkim.log.DefaultLogger;
import net.sberg.openkim.pipeline.PipelineOperation;
import net.sberg.openkim.pipeline.operation.DefaultPipelineOperationContext;
import net.sberg.openkim.pipeline.operation.IPipelineOperation;
import org.apache.james.metrics.api.TimeMetric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

@PipelineOperation
public class TestOperation implements IPipelineOperation {

private static final Logger log = LoggerFactory.getLogger(TestOperation.class);
public static final String NAME = "Test";

public static final String ENV_NAME = "name";

@Override
public boolean isTestable() {
return true;
}

@Override
public String getHrText() {
return "Testoperation";
}

@Override
public String getName() {
return NAME;
}

@Override
public Consumer<DefaultPipelineOperationContext> getDefaultOkConsumer() {
return context -> {
context.getLogger().logLine("Test war erfolgreich!!!");
};
}

@Override
public void execute(DefaultPipelineOperationContext defaultPipelineOperationContext, Consumer<DefaultPipelineOperationContext> okConsumer, BiConsumer<DefaultPipelineOperationContext, Exception> failConsumer) {
TimeMetric timeMetric = null;

DefaultLogger logger = defaultPipelineOperationContext.getLogger();
Konnektor konnektor = logger.getDefaultLoggerContext().getKonnektor();

try {
DefaultMetricFactory metricFactory = new DefaultMetricFactory(logger);
timeMetric = metricFactory.timer(NAME);
Thread.sleep(5000);
defaultPipelineOperationContext.getLogger().logLine("Hallo "+defaultPipelineOperationContext.getEnvironmentValue(NAME, ENV_NAME)+" danke für die 5 Sekunden Wartezeit");
timeMetric.stopAndPublish();
okConsumer.accept(defaultPipelineOperationContext);
} catch (Exception e) {
log.error("error on executing the TestOperation for the konnektor: " + konnektor.getIp(), e);
if (timeMetric != null) {
timeMetric.stopAndPublish();
}
failConsumer.accept(defaultPipelineOperationContext, e);
}
}
}
Loading

0 comments on commit 64ff1cd

Please sign in to comment.