|
|
@@ -3,14 +3,17 @@ package cn.reghao.autodop.dmaster.app.repository.orchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppCompileRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppPackRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppUpdateRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.SelectOption;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -24,36 +27,223 @@ public class AppRepository {
|
|
|
private AppPackRepository packRepository;
|
|
|
private AppOrchestrationRepository orchestrationRepository;
|
|
|
private ProjectOrchestrationRepository projRepository;
|
|
|
+ private NotificationRepository notificationRepository;
|
|
|
|
|
|
public AppRepository(AppUpdateRepository updateRepository,
|
|
|
AppCompileRepository compileRepository,
|
|
|
AppPackRepository packRepository,
|
|
|
ProjectOrchestrationRepository projRepository,
|
|
|
- AppOrchestrationRepository orchestrationRepository) {
|
|
|
+ AppOrchestrationRepository orchestrationRepository,
|
|
|
+ NotificationRepository notificationRepository) {
|
|
|
this.updateRepository = updateRepository;
|
|
|
this.compileRepository = compileRepository;
|
|
|
this.packRepository = packRepository;
|
|
|
this.orchestrationRepository = orchestrationRepository;
|
|
|
this.projRepository = projRepository;
|
|
|
+ this.notificationRepository = notificationRepository;
|
|
|
}
|
|
|
|
|
|
- public AppBuildVO appBuilds() {
|
|
|
+ public BuildConfig buildConfig() {
|
|
|
List<AppUpdate> appUpdates = updateRepository.findAll();
|
|
|
List<AppCompile> appCompiles = compileRepository.findAll();
|
|
|
List<AppPack> appPacks = packRepository.findAll();
|
|
|
+ List<Notification> notifications = notificationRepository.findAll();
|
|
|
|
|
|
- AppBuildVO appBuildVO = new AppBuildVO();
|
|
|
- appBuildVO.setAppUpdates(appUpdates);
|
|
|
- appBuildVO.setAppCompiles(appCompiles);
|
|
|
- appBuildVO.setAppPacks(appPacks);
|
|
|
+ List<SelectOption> updateOptions = new ArrayList<>();
|
|
|
+ convertToAppUpdates(appUpdates, updateOptions);
|
|
|
+ List<SelectOption> compileOptions = new ArrayList<>();
|
|
|
+ convertToAppCompiles(appCompiles, compileOptions);
|
|
|
+ List<SelectOption> packOptions = new ArrayList<>();
|
|
|
+ convertToAppPacks(appPacks, packOptions);
|
|
|
+ List<SelectOption> notificationOptions = new ArrayList<>();
|
|
|
+ convertToNotifications(notifications, notificationOptions);
|
|
|
|
|
|
- return appBuildVO;
|
|
|
+ BuildConfig buildConfig = new BuildConfig();
|
|
|
+ buildConfig.setAppUpdates(updateOptions);
|
|
|
+ buildConfig.setAppCompiles(compileOptions);
|
|
|
+ buildConfig.setAppPacks(packOptions);
|
|
|
+ buildConfig.setNotifications(notificationOptions);
|
|
|
+
|
|
|
+ return buildConfig;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToAppUpdates(List<AppUpdate> appUpdates, List<SelectOption> options) {
|
|
|
+ Map<String, Integer> keys1 = new HashMap<>();
|
|
|
+ Map<String, Integer> keys2 = new HashMap<>();
|
|
|
+ Map<String, Integer> keys3 = new HashMap<>();
|
|
|
+ for (AppUpdate appUpdate : appUpdates) {
|
|
|
+ String repoType = appUpdate.getRepoType();
|
|
|
+ String repoName = appUpdate.getRepoName();
|
|
|
+ String username = appUpdate.getUsername();
|
|
|
+
|
|
|
+ Integer index1 = keys1.get(repoType);
|
|
|
+ Integer index2 = keys2.get(repoType + repoName);
|
|
|
+ Integer index3 = keys3.get(repoType + repoName + username);
|
|
|
+ if (index3 == null) {
|
|
|
+ if (index2 == null) {
|
|
|
+ if (index1 == null) {
|
|
|
+ SelectOption option1 = new SelectOption();
|
|
|
+ option1.setValue(repoType);
|
|
|
+ options.add(option1);
|
|
|
+ keys1.put(repoType, options.size()-1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(repoName);
|
|
|
+ List<SelectOption> list2 = new ArrayList<>();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(repoType + repoName, list2.size()-1);
|
|
|
+
|
|
|
+ SelectOption option3 = new SelectOption();
|
|
|
+ option3.setValue(username);
|
|
|
+ List<SelectOption> list3 = new ArrayList<>();
|
|
|
+ list3.add(option3);
|
|
|
+ option2.setChildren(list3);
|
|
|
+ keys3.put(repoType + repoName + username, list3.size()-1);
|
|
|
+ } else {
|
|
|
+ SelectOption option1 = options.get(index1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(repoName);
|
|
|
+ List<SelectOption> list2 = new ArrayList<>();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(repoType + repoName, list2.size()-1);
|
|
|
+
|
|
|
+ SelectOption option3 = new SelectOption();
|
|
|
+ option3.setValue(username);
|
|
|
+ List<SelectOption> list3 = new ArrayList<>();
|
|
|
+ list3.add(option3);
|
|
|
+ option2.setChildren(list3);
|
|
|
+ keys3.put(repoType + repoName + username, list3.size()-1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SelectOption option1 = options.get(index1);
|
|
|
+ SelectOption option2 = option1.getChildren().get(index2);
|
|
|
+
|
|
|
+ SelectOption option3 = new SelectOption();
|
|
|
+ option3.setValue(username);
|
|
|
+ List<SelectOption> list3 = new ArrayList<>();
|
|
|
+ list3.add(option3);
|
|
|
+ option2.setChildren(list3);
|
|
|
+ keys3.put(repoType + repoName + username, list3.size()-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToAppCompiles(List<AppCompile> appCompiles, List<SelectOption> options) {
|
|
|
+ Map<String, Integer> keys1 = new HashMap<>();
|
|
|
+ Map<String, Integer> keys2 = new HashMap<>();
|
|
|
+ for (AppCompile appCompile : appCompiles) {
|
|
|
+ String compilerType = appCompile.getCompilerType();
|
|
|
+ String compilerName = appCompile.getCompilerName();
|
|
|
+
|
|
|
+ Integer index1 = keys1.get(compilerType);
|
|
|
+ Integer index2 = keys2.get(compilerType + compilerName);
|
|
|
+ if (index2 == null) {
|
|
|
+ if (index1 == null) {
|
|
|
+ SelectOption option1 = new SelectOption();
|
|
|
+ option1.setValue(compilerType);
|
|
|
+ options.add(option1);
|
|
|
+ keys1.put(compilerType, options.size()-1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(compilerName);
|
|
|
+ List<SelectOption> list2 = new ArrayList<>();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(compilerType + compilerName, list2.size()-1);
|
|
|
+ } else {
|
|
|
+ SelectOption option1 = options.get(index1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(compilerName);
|
|
|
+ List<SelectOption> list2 = option1.getChildren();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(compilerType + compilerName, list2.size()-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToAppPacks(List<AppPack> appPacks, List<SelectOption> options) {
|
|
|
+ Map<String, Integer> keys1 = new HashMap<>();
|
|
|
+ Map<String, Integer> keys2 = new HashMap<>();
|
|
|
+ for (AppPack appPack : appPacks) {
|
|
|
+ String packerType = appPack.getPackerType();
|
|
|
+ String packerName = appPack.getPackerName();
|
|
|
+
|
|
|
+ Integer index1 = keys1.get(packerType);
|
|
|
+ Integer index2 = keys2.get(packerType + packerName);
|
|
|
+ if (index2 == null) {
|
|
|
+ if (index1 == null) {
|
|
|
+ SelectOption option1 = new SelectOption();
|
|
|
+ option1.setValue(packerType);
|
|
|
+ options.add(option1);
|
|
|
+ keys1.put(packerType, options.size()-1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(packerName);
|
|
|
+ List<SelectOption> list2 = new ArrayList<>();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(packerType + packerName, list2.size()-1);
|
|
|
+ } else {
|
|
|
+ SelectOption option1 = options.get(index1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(packerName);
|
|
|
+ List<SelectOption> list2 = option1.getChildren();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(packerType + packerName, list2.size()-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertToNotifications(List<Notification> notifications, List<SelectOption> options) {
|
|
|
+ Map<String, Integer> keys1 = new HashMap<>();
|
|
|
+ Map<String, Integer> keys2 = new HashMap<>();
|
|
|
+ for (Notification notification : notifications) {
|
|
|
+ String notifierType = notification.getNotifierType();
|
|
|
+ String notifierName = notification.getNotifierName();
|
|
|
+
|
|
|
+ Integer index1 = keys1.get(notifierType);
|
|
|
+ Integer index2 = keys2.get(notifierType + notifierName);
|
|
|
+ if (index2 == null) {
|
|
|
+ if (index1 == null) {
|
|
|
+ SelectOption option1 = new SelectOption();
|
|
|
+ option1.setValue(notifierType);
|
|
|
+ options.add(option1);
|
|
|
+ keys1.put(notifierType, options.size()-1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(notifierName);
|
|
|
+ List<SelectOption> list2 = new ArrayList<>();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(notifierType + notifierName, list2.size()-1);
|
|
|
+ } else {
|
|
|
+ SelectOption option1 = options.get(index1);
|
|
|
+
|
|
|
+ SelectOption option2 = new SelectOption();
|
|
|
+ option2.setValue(notifierName);
|
|
|
+ List<SelectOption> list2 = option1.getChildren();
|
|
|
+ list2.add(option2);
|
|
|
+ option1.setChildren(list2);
|
|
|
+ keys2.put(notifierType + notifierName, list2.size()-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void projIds(AppBuildVO appBuildVO) {
|
|
|
- List<String> projIds = projRepository.findAll().stream()
|
|
|
- .map(ProjOrchestration::getProjId)
|
|
|
+ public void projs(BuildConfig buildConfig) {
|
|
|
+ List<SelectOption> projs = projRepository.findAll().stream()
|
|
|
+ .map(proj -> new SelectOption(proj.getProjId(), proj.getDescription()))
|
|
|
.collect(Collectors.toList());
|
|
|
- appBuildVO.setProjIds(projIds);
|
|
|
+ buildConfig.setProjs(projs);
|
|
|
}
|
|
|
}
|