Skip to content

Commit 0382afb

Browse files
committed
Code improvements and bug fixes
1 parent dd83add commit 0382afb

File tree

9 files changed

+159
-248
lines changed

9 files changed

+159
-248
lines changed

src/main/java/dev/markodojkic/softwaredevelopmentsimulation/DeveloperImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public TechnicalTask trivialTaskHandler(TechnicalTask technicalTask) {
3232
* 0.01
3333
+ 1500)
3434
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
35-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on trivial technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
35+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on trivial technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
3636
return technicalTask;
3737
}
3838

@@ -48,7 +48,7 @@ public TechnicalTask normalTaskHandler(TechnicalTask technicalTask) {
4848
* 0.02
4949
+ 1500)
5050
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
51-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on normal technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
51+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on normal technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
5252
return technicalTask;
5353
}
5454

@@ -64,7 +64,7 @@ public TechnicalTask minorTaskHandler(TechnicalTask technicalTask) {
6464
* 0.03
6565
+ 1500)
6666
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
67-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on minor technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
67+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on minor technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
6868
return technicalTask;
6969
}
7070

@@ -80,7 +80,7 @@ public TechnicalTask majorTaskHandler(TechnicalTask technicalTask) {
8080
* 0.04
8181
+ 1500)
8282
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
83-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on major technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
83+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on major technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
8484
return technicalTask;
8585
}
8686

@@ -96,7 +96,7 @@ public TechnicalTask criticalTaskHandler(TechnicalTask technicalTask) {
9696
* 0.05
9797
+ 1500)
9898
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
99-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on critical technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
99+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on critical technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
100100
return technicalTask;
101101
}
102102

@@ -112,7 +112,7 @@ public TechnicalTask blockerTaskHandler(TechnicalTask technicalTask) {
112112
* 0.06
113113
+ 1500)
114114
, System.getProperty(SPRING_PROFILES_ACTIVE, "").equals(TEST) ? TimeUnit.NANOSECONDS : TimeUnit.MILLISECONDS);
115-
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s finished working on blocker technical task %s", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
115+
logger.log(Level.INFO, () -> colorize(String.format("%n</> Developer %s finished working on blocker technical task %s </>", technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
116116
return technicalTask;
117117
}
118118

src/main/java/dev/markodojkic/softwaredevelopmentsimulation/SoftwareDevelopmentSimulationApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static void main(String[] args) {
2828
updateDevelopmentTeamsSetup(new DevelopmentTeamCreationParameters());
2929

3030
try {
31-
getIGateways().sendToInfo(String.format("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024%nSize occupied by appliaction user data is: %.2f KB%nI hope you will enjoy using my spring integration web-based application", (double) Files.size(getCurrentApplicationDataPath()) / 1024));
31+
getIGateways().sendToInfo(String.format("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024%nSize occupied by application user data is: %.2f KB%nI hope you will enjoy using my spring integration web-based application", (double) Files.size(getCurrentApplicationDataPath()) / 1024));
3232
} catch (IOException e) {
33-
getIGateways().sendToInfo(String.format("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024%nSize occupied by appliaction user data is: %.2f KB%nI hope you will enjoy using my spring integration web-based application", 0.00));
33+
getIGateways().sendToInfo(String.format("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024%nSize occupied by application user data is: %.2f KB%nI hope you will enjoy using my spring integration web-based application", 0.00));
3434
}
3535
}
3636
}

src/main/java/dev/markodojkic/softwaredevelopmentsimulation/flow/FileHandlingFlow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.context.annotation.Bean;
66
import org.springframework.context.annotation.Configuration;
77
import org.springframework.integration.dsl.IntegrationFlow;
8+
import org.springframework.integration.dsl.StandardIntegrationFlow;
89
import org.springframework.integration.file.FileHeaders;
910
import org.springframework.integration.file.dsl.Files;
1011
import org.springframework.integration.file.support.FileExistsMode;
@@ -31,7 +32,7 @@ public IntegrationFlow errorLogFileFlow(@Qualifier("errorChannel.logFile.input")
3132
return configureLogFileFlow(logFileMessageChannel, "errorChannel.log");
3233
}
3334

34-
private IntegrationFlow configureLogFileFlow(MessageChannel logFileMessageChannel, String fileName) {
35+
private StandardIntegrationFlow configureLogFileFlow(MessageChannel logFileMessageChannel, String fileName) {
3536
return IntegrationFlow.from(logFileMessageChannel)
3637
.enrichHeaders(h -> h
3738
.header(FileHeaders.FILENAME, fileName)
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.markodojkic.softwaredevelopmentsimulation.flow;
22

3+
import org.springframework.integration.dsl.StandardIntegrationFlow;
34
import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
@@ -12,29 +13,27 @@
1213
@SuppressWarnings("unchecked")
1314
public class MQTTFlow {
1415
@Bean(name = "infoOutputMQTTFlow")
15-
public IntegrationFlow infoOutputMQTTFlow(MqttPahoMessageHandler rabbitMQMessageHandler){
16-
return IntegrationFlow.from("information.mqtt.input")
17-
//Unchecked cast cannot be resolved since Message<String> throws ClassCastException
18-
.transform(Message.class, message -> MessageBuilder.fromMessage(message)
19-
.setHeader(MqttHeaders.TOPIC, "information-printout-topic")
20-
.build()).handle(rabbitMQMessageHandler).get();
16+
public IntegrationFlow infoOutputMQTTFlow(MqttPahoMessageHandler mqttMessageHandler) {
17+
return createMQTTFlow("information.mqtt.input", "information-printout-topic", mqttMessageHandler);
2118
}
2219

2320
@Bean(name = "jiraActivityStreamOutputMQTTFlow")
24-
public IntegrationFlow jiraActivityStreamOutputMQTTFlow(MqttPahoMessageHandler rabbitMQMessageHandler){
25-
return IntegrationFlow.from("jiraActivityStream.mqtt.input")
26-
.transform(Message.class, message -> MessageBuilder.fromMessage(message)
27-
.setHeader(MqttHeaders.TOPIC, "java-activity-stream-printout-topic")
28-
.build()).handle(rabbitMQMessageHandler).get();
21+
public IntegrationFlow jiraActivityStreamOutputMQTTFlow(MqttPahoMessageHandler mqttMessageHandler) {
22+
return createMQTTFlow("jiraActivityStream.mqtt.input", "java-activity-stream-printout-topic", mqttMessageHandler);
2923
}
3024

3125
@Bean(name = "errorOutputMQTTFlow")
32-
public IntegrationFlow errorOutputMQTTFlow(MqttPahoMessageHandler rabbitMQMessageHandler){
33-
rabbitMQMessageHandler.setDefaultTopic("error-printout-topic");
26+
public IntegrationFlow errorOutputMQTTFlow(MqttPahoMessageHandler mqttMessageHandler) {
27+
return createMQTTFlow("errorChannel.mqtt.input", "error-printout-topic", mqttMessageHandler);
28+
}
3429

35-
return IntegrationFlow.from("errorChannel.mqtt.input")
36-
.transform(Message.class, message -> MessageBuilder.fromMessage(message)
37-
.setHeader(MqttHeaders.TOPIC, "error-printout-topic")
38-
.build()).handle(rabbitMQMessageHandler).get();
30+
private StandardIntegrationFlow createMQTTFlow(String inputChannelName, String topic, MqttPahoMessageHandler mqttMessageHandler) {
31+
return IntegrationFlow.from(inputChannelName)
32+
.transform(Message.class, message ->
33+
MessageBuilder.fromMessage(message)
34+
.setHeader(MqttHeaders.TOPIC, topic)
35+
.build())
36+
.handle(mqttMessageHandler)
37+
.get();
3938
}
4039
}

src/main/java/dev/markodojkic/softwaredevelopmentsimulation/flow/PrintoutFlow.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,31 @@
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.integration.dsl.IntegrationFlow;
7+
import org.springframework.integration.dsl.StandardIntegrationFlow;
78
import org.springframework.integration.handler.LoggingHandler;
89
import org.springframework.messaging.MessageChannel;
910

1011
@Configuration
1112
public class PrintoutFlow {
12-
private static final String PRINTER_TRANSFORMER_BEAN = "printerTransformer";
13-
1413
@Bean
1514
public IntegrationFlow informationPrintoutFlow(@Qualifier("information.mqtt.input") MessageChannel mqttMessageChannel, @Qualifier("information.logFile.input") MessageChannel logFileMessageChannel) {
16-
return IntegrationFlow.from("information.input")
17-
.transform(PRINTER_TRANSFORMER_BEAN, "infoOutput")
18-
.log(LoggingHandler.Level.INFO, message -> System.lineSeparator().concat(message.getPayload().toString()))
19-
.handle(message -> {
20-
mqttMessageChannel.send(message);
21-
logFileMessageChannel.send(message);
22-
}).get();
15+
return configurePrintoutFlow("information.input", "infoOutput", mqttMessageChannel, logFileMessageChannel, LoggingHandler.Level.INFO);
2316
}
2417

2518
@Bean
2619
public IntegrationFlow jiraActivityStreamPrintoutFlow(@Qualifier("jiraActivityStream.mqtt.input") MessageChannel mqttMessageChannel, @Qualifier("jiraActivityStream.logFile.input") MessageChannel logFileMessageChannel) {
27-
return IntegrationFlow.from("jiraActivityStream.input")
28-
.transform(PRINTER_TRANSFORMER_BEAN, "jiraActivityStreamOutput")
29-
.log(LoggingHandler.Level.INFO, message -> System.lineSeparator().concat(message.getPayload().toString()))
30-
.handle(message -> {
31-
mqttMessageChannel.send(message);
32-
logFileMessageChannel.send(message);
33-
}).get();
20+
return configurePrintoutFlow("jiraActivityStream.input", "jiraActivityStreamOutput", mqttMessageChannel, logFileMessageChannel, LoggingHandler.Level.INFO);
3421
}
3522

3623
@Bean
3724
public IntegrationFlow errorPrintoutFlow(@Qualifier("errorChannel.mqtt.input") MessageChannel mqttMessageChannel, @Qualifier("errorChannel.logFile.input") MessageChannel logFileMessageChannel) {
38-
return IntegrationFlow.from("errorChannel")
39-
.transform(PRINTER_TRANSFORMER_BEAN, "errorOutput")
40-
.log(LoggingHandler.Level.ERROR, message -> System.lineSeparator().concat(message.getPayload().toString()))
25+
return configurePrintoutFlow("errorChannel", "errorOutput", mqttMessageChannel, logFileMessageChannel, LoggingHandler.Level.ERROR);
26+
}
27+
28+
private StandardIntegrationFlow configurePrintoutFlow(String inputMessageChannel, String transformerMethod, MessageChannel mqttMessageChannel, MessageChannel logFileMessageChannel, LoggingHandler.Level loggingLevel) {
29+
return IntegrationFlow.from(inputMessageChannel)
30+
.transform("printerTransformer", transformerMethod)
31+
.log(loggingLevel, message -> System.lineSeparator().concat(message.getPayload().toString()))
4132
.handle(message -> {
4233
mqttMessageChannel.send(message);
4334
logFileMessageChannel.send(message);

0 commit comments

Comments
 (0)