Skip to content

Commit

Permalink
Code cleanup based on SonarQube :)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoDojkic committed Aug 14, 2024
1 parent 7605bd4 commit 4524550
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.diogonunes.jcolor.Attribute;
import com.google.common.util.concurrent.Uninterruptibles;
import dev.markodojkic.softwaredevelopmentsimulation.model.TechnicalTask;
import dev.markodojkic.softwaredevelopmentsimulation.util.Utilities;
import jakarta.annotation.PostConstruct;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
Expand All @@ -16,7 +15,7 @@
import java.util.logging.Logger;

import static com.diogonunes.jcolor.Ansi.colorize;
import static dev.markodojkic.softwaredevelopmentsimulation.util.Utilities.DATE_TIME_FORMATTER;
import static dev.markodojkic.softwaredevelopmentsimulation.util.Utilities.*;

@MessageEndpoint
public class DeveloperImpl {
Expand Down Expand Up @@ -49,7 +48,7 @@ public void init(){
@ServiceActivator(inputChannel = "trivialTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask trivialTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 2), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 2), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on trivial technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -62,7 +61,7 @@ public TechnicalTask trivialTaskHandler(TechnicalTask technicalTask) {
@ServiceActivator(inputChannel = "normalTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask normalTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 4), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 4), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on normal technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -75,7 +74,7 @@ public TechnicalTask normalTaskHandler(TechnicalTask technicalTask) {
@ServiceActivator(inputChannel = "minorTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask minorTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 6), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 6), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on minor technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -88,7 +87,7 @@ public TechnicalTask minorTaskHandler(TechnicalTask technicalTask) {
@ServiceActivator(inputChannel = "majorTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask majorTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 8), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 8), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on major technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -101,7 +100,7 @@ public TechnicalTask majorTaskHandler(TechnicalTask technicalTask) {
@ServiceActivator(inputChannel = "criticalTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask criticalTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 10), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 10), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on critical technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -114,7 +113,7 @@ public TechnicalTask criticalTaskHandler(TechnicalTask technicalTask) {
@ServiceActivator(inputChannel = "blockerTechnicalTask.intermediate", outputChannel = "doneTechnicalTasks.output")
public TechnicalTask blockerTaskHandler(TechnicalTask technicalTask) {
sendToJiraCreatedTaskInfo(technicalTask);
Uninterruptibles.sleepUninterruptibly(Utilities.SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 12), TimeUnit.MILLISECONDS);
Uninterruptibles.sleepUninterruptibly(SECURE_RANDOM.nextLong(technicalTask.getAssignee().getExperienceCoefficient(), technicalTask.getAssignee().getExperienceCoefficient() * 12), TimeUnit.MILLISECONDS);
sendToJiraSetStatusToInProgressInfo(technicalTask);
logger.log(Level.INFO, () -> colorize(String.format("%n###Developer %s started working on blocker technical task %s",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId()), Attribute.TEXT_COLOR(0), Attribute.BACK_COLOR(technicalTask.getPriority().getAnsiColorCode())));
Expand All @@ -125,13 +124,13 @@ public TechnicalTask blockerTaskHandler(TechnicalTask technicalTask) {
}

private void sendToJiraCreatedTaskInfo(TechnicalTask technicalTask) {
Utilities.getIGateways().sendToJiraActivityStream(String.format(CHANGED_THE_ASSIGNEE_TO_FORMAT,
getIGateways().sendToJiraActivityStream(String.format(CHANGED_THE_ASSIGNEE_TO_FORMAT,
technicalTask.getReporter().getDisplayName(), technicalTask.getAssignee().getDisplayName(), technicalTask.getId(), technicalTask.getName(), technicalTask.getCreatedOn().plusSeconds(getArtificialOffsetInSeconds(technicalTask.getCreatedOn()) + 10).format(DATE_TIME_FORMATTER)).concat(String.format(CREATED_TASK_FORMAT,
technicalTask.getReporter().getDisplayName(), technicalTask.getId(), technicalTask.getName(), technicalTask.getCreatedOn().plusSeconds(getArtificialOffsetInSeconds(technicalTask.getCreatedOn())).format(DATE_TIME_FORMATTER))).replaceFirst(".$", ""));
}

private void sendToJiraSetStatusToInProgressInfo(TechnicalTask technicalTask) {
Utilities.getIGateways().sendToJiraActivityStream(String.format(CHANGED_STATUS_TO_IN_PROGRESS_FORMAT,
getIGateways().sendToJiraActivityStream(String.format(CHANGED_STATUS_TO_IN_PROGRESS_FORMAT,
technicalTask.getAssignee().getDisplayName(), technicalTask.getId(), technicalTask.getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER)).replaceFirst(".$", ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import dev.markodojkic.softwaredevelopmentsimulation.util.DataProvider;
import dev.markodojkic.softwaredevelopmentsimulation.util.EpicNotDoneException;
import dev.markodojkic.softwaredevelopmentsimulation.util.UserStoryNotDoneException;
import dev.markodojkic.softwaredevelopmentsimulation.util.Utilities;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -76,14 +75,14 @@ public List<UserStory> assignUserStoriesAndPrepareTechnicalTasks(Message<Epic> e
return userStory;
}).toList());

Utilities.getIGateways().sendToJiraActivityStream(jiraEpicCreatedOutput.get().replaceFirst(".$", ""));
getIGateways().sendToJiraActivityStream(jiraEpicCreatedOutput.get().replaceFirst(".$", ""));

new Thread(() -> inProgressEpic.send(epicMessage)).start();

if(Utilities.getTotalEpicsCount() != -1) {
Utilities.addEpicForSaving(epic);
Utilities.setTotalEpicsCount(Utilities.getTotalEpicsCount() - 1);
if(Utilities.getTotalEpicsCount() == 0) Utilities.saveEpics();
if(getTotalEpicsCount() != -1) {
addEpicForSaving(epic);
setTotalEpicsCount(getTotalEpicsCount() - 1);
if(getTotalEpicsCount() == 0) saveEpics();
}

return epic.getUserStories();
Expand Down Expand Up @@ -118,18 +117,18 @@ public UserStory sendToDoneUserStory(UserStory userStory) throws UserStoryNotDon
@ServiceActivator(inputChannel = "doneEpics.output")
public void printDoneEpic(Message<Epic> epicMessage) {
if(epicMessage != null) {
Utilities.getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on EPIC: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDone\033[21m\033[24m ◴ %s$",
getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on EPIC: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDone\033[21m\033[24m ◴ %s$",
epicMessage.getPayload().getAssignee().getDisplayName(), epicMessage.getPayload().getId(), epicMessage.getPayload().getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER)).replaceFirst(".$", "")); // 9 - STRIKE-THROUGH, 29 - RESET STRIKE-THROUGH
logger.log(Level.INFO, "{0} finished - Current count: {1}", new String[]{epicMessage.getPayload().getId(), String.valueOf(IN_PROGRESS_EPICS_COUNT.decrementAndGet())});
DataProvider.getAvailableDevelopmentTeamIds().push(epicMessage.getHeaders().get(ASSIGNED_DEVELOPMENT_TEAM_POSITION_NUMBER, Integer.class));
if(IN_PROGRESS_EPICS_COUNT.get() < Utilities.getTotalDevelopmentTeamsPresent()) controlBusInput.send(MessageBuilder.withPayload("@assignEpicFlow.start()").build());
if(IN_PROGRESS_EPICS_COUNT.get() < getTotalDevelopmentTeamsPresent()) controlBusInput.send(MessageBuilder.withPayload("@assignEpicFlow.start()").build());
}
}

@ServiceActivator(inputChannel = "doneSprintUserStories.output")
public void updateUserStoryStatus(UserStory userStory){
if(userStory != null) {
Utilities.getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on US: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDONE\033[21m\033[24m ◴ %s$",
getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on US: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDONE\033[21m\033[24m ◴ %s$",
userStory.getAssignee().getDisplayName(), userStory.getId(), userStory.getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER)).concat(String.format("\033[1m%s\033[21m\033[24m logged '%.0fh' on US: \033[3m\033[1m%s\033[21m\033[24m - %s\033[23m ◴ %s$",
userStory.getAssignee().getDisplayName(), Math.abs(Math.ceil((double) (UUID.nameUUIDFromBytes(userStory.getId().getBytes(StandardCharsets.UTF_8)).hashCode() % 1000) / userStory.getAssignee().getExperienceCoefficient())), userStory.getId(), userStory.getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER))).replaceFirst(".$", ""));

Expand All @@ -140,7 +139,7 @@ public void updateUserStoryStatus(UserStory userStory){
@ServiceActivator(inputChannel = "doneTechnicalTasks.output")
public void updateTechnicalTaskStatus(TechnicalTask technicalTask){
if(technicalTask != null) {
Utilities.getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on TASK: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDONE\033[21m\033[24m ◴ %s$",
getIGateways().sendToJiraActivityStream(String.format("\033[1m%s\033[21m\033[24m changed the status to Done on TASK: \033[3m\033[1m\033[9m%s\033[21m\033[24m\033[29m - %s\033[23m with resolution \033[1mDONE\033[21m\033[24m ◴ %s$",
technicalTask.getAssignee().getDisplayName(), technicalTask.getId(), technicalTask.getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER)).concat(String.format("\033[1m%s\033[21m\033[24m logged '%.0fh' on TASK: \033[3m\033[1m%s\033[21m\033[24m - %s\033[23m ◴ %s$",
technicalTask.getAssignee().getDisplayName(), Math.ceil((double) Math.abs(ChronoUnit.SECONDS.between(ZonedDateTime.now(), technicalTask.getCreatedOn())) / technicalTask.getAssignee().getExperienceCoefficient()), technicalTask.getId(), technicalTask.getName(), ZonedDateTime.now().format(DATE_TIME_FORMATTER))).replaceFirst(".$", Strings.EMPTY));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.markodojkic.softwaredevelopmentsimulation.interfaces.IGateways;
import dev.markodojkic.softwaredevelopmentsimulation.model.DevelopmentTeamCreationParameters;
import dev.markodojkic.softwaredevelopmentsimulation.util.Utilities;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;

import static dev.markodojkic.softwaredevelopmentsimulation.util.DataProvider.setupDataProvider;
import static dev.markodojkic.softwaredevelopmentsimulation.util.DataProvider.updateDevelopmentTeamsSetup;
import static dev.markodojkic.softwaredevelopmentsimulation.util.Utilities.*;

@EnableConfigurationProperties
@SpringBootApplication
Expand All @@ -19,13 +19,13 @@ public class SoftwareDevelopmentSimulationApp
public static void main(String[] args)
{
ConfigurableApplicationContext configurableApplicationContext = new SpringApplication(SoftwareDevelopmentSimulationApp.class).run(args);
Utilities.setIGateways(configurableApplicationContext.getBean(IGateways.class));
Utilities.setObjectMapper(configurableApplicationContext.getBean(ObjectMapper.class));
setIGateways(configurableApplicationContext.getBean(IGateways.class));
setObjectMapper(configurableApplicationContext.getBean(ObjectMapper.class));

setupDataProvider(false);
updateDevelopmentTeamsSetup(new DevelopmentTeamCreationParameters());

Utilities.getIGateways().sendToInfo("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024$I hope you will enjoy using my spring integration web based application");
getIGateways().sendToInfo("Welcome to Software development simulator™ Developed by Ⓒ Marko Dojkić 2024$I hope you will enjoy using my spring integration web based application");

//TODO: Correct JIRA activity stream timings
//TODO: Fix issue with carousel that button (i.e. carousel item is below scroll container when scrolled and thus not interactable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.thymeleaf.util.StringUtils;
import org.springframework.util.StringUtils;

@AllArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Utilities {
now.format(DateTimeFormatter.ofPattern("HH.mm.ss")));
}

public void loadPredefinedTasks(List<Epic> predefinedEpics){
public static void loadPredefinedTasks(List<Epic> predefinedEpics){
AtomicReference<String> jiraEpicCreatedOutput = new AtomicReference<>(Strings.EMPTY);
predefinedEpics.forEach(epic -> jiraEpicCreatedOutput.set(String.format("\033[1m%s\033[21m\033[24m created EPIC: \033[3m\033[1m%s\033[21m\033[24m - %s\033[23m ◴ %s$",
epic.getReporter().getDisplayName(), epic.getId(), epic.getName(), epic.getCreatedOn().format(DATE_TIME_FORMATTER)).concat(jiraEpicCreatedOutput.get())));
Expand Down Expand Up @@ -200,7 +200,7 @@ public static void saveEpics(){
Files.createDirectories(parentDirectory.resolve(folderName));

Files.writeString(parentDirectory.resolve(folderName.concat("/sessionData.json")), objectMapper.writeValueAsString(epicsForSaving));
Files.writeString(parentDirectory.resolve(folderName.concat("/developersData.json")), objectMapper.writeValueAsString(DataProvider.getCurrentDevelopmentTeamsSetup()));
Files.writeString(parentDirectory.resolve(folderName.concat("/developersData.json")), objectMapper.writeValueAsString(getCurrentDevelopmentTeamsSetup()));
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
Expand Down
Loading

0 comments on commit 4524550

Please sign in to comment.