From a904c61ad88e4cc06f9f35db0d0d2a3545fda1c3 Mon Sep 17 00:00:00 2001 From: satishc1 Date: Mon, 5 Mar 2018 10:17:50 -0500 Subject: [PATCH 1/2] Fix remote create options (#2062) --- api/pom.xml | 5 ++ .../service/CollectorServiceAspect.java | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 api/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java diff --git a/api/pom.xml b/api/pom.xml index cedfaf040b..060eb396e7 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -97,6 +97,11 @@ org.springframework.security spring-security-ldap + + + org.springframework.boot + spring-boot-starter-aop + diff --git a/api/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java b/api/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java new file mode 100644 index 0000000000..4282238e8a --- /dev/null +++ b/api/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java @@ -0,0 +1,61 @@ +package com.capitalone.dashboard.service; + +import com.capitalone.dashboard.model.Collector; +import com.capitalone.dashboard.model.CollectorItem; +import com.capitalone.dashboard.model.CollectorType; +import com.capitalone.dashboard.repository.CollectorRepository; +import com.capitalone.dashboard.util.GitHubParsedUrl; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Aspect +@Component +public class CollectorServiceAspect { + + private static final Logger LOGGER = LoggerFactory.getLogger(CollectorServiceAspect.class); + + private final CollectorRepository collectorRepository; + + @Autowired + public CollectorServiceAspect(CollectorRepository collectorRepository) { + this.collectorRepository = collectorRepository; + } + + private boolean isGit(Collector collector) { + String name = collector.getName().toUpperCase(); + boolean isGit = true; + switch (name) { + case "GITHUB": + isGit = true; + break; + case "SUBVERSION": + isGit = false; + break; + default: + isGit = true; + break; + } + return isGit; + } + + private void normalizeOptions(CollectorItem item, Map uniqueOptions) { + Collector collector = collectorRepository.findOne(item.getCollectorId()); + if (collector.getCollectorType() == CollectorType.SCM && isGit(collector)) { + String repoUrl = (String)uniqueOptions.get("url"); + GitHubParsedUrl gitHubParsed = new GitHubParsedUrl(repoUrl); + uniqueOptions.put("url", gitHubParsed.getUrl()); + } + } + + @Before("execution(* com.capitalone.dashboard.service.CollectorService.createCollectorItemSelectOptions (com.capitalone.dashboard.model.CollectorItem, java.util.Map, java.util.Map)) && args(item, allOptions, uniqueOptions)") + public void normalizeCreateItem(CollectorItem item, Map allOptions, Map uniqueOptions) { + LOGGER.debug("normalizeCreateItem " + item.getNiceName()); + normalizeOptions(item, uniqueOptions); + } +} From af0858e4ad70c3decd93605195734b81bdd49bcb Mon Sep 17 00:00:00 2001 From: nireeshT Date: Mon, 5 Mar 2018 10:49:07 -0500 Subject: [PATCH 2/2] Repo widget - Get SCM type from collectorItems (#2059) * Generic search for collector-items * Generic search for collector-items * Generic search for collector-items * Get scmType from collectorItems * Get scmType from collectorItems --- UI/src/components/widgets/repo/config.js | 49 +++++++++--------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/UI/src/components/widgets/repo/config.js b/UI/src/components/widgets/repo/config.js index bd8c527a54..f8aa2c0526 100644 --- a/UI/src/components/widgets/repo/config.js +++ b/UI/src/components/widgets/repo/config.js @@ -13,33 +13,28 @@ var ctrl = this; var widgetConfig = modalData.widgetConfig; - ctrl.repoOptions = [{ - name: 'GitHub', - value: 'GitHub' - }, { - name: 'Subversion', - value: 'Subversion' - },{ - name: 'Bitbucket', - value: 'Bitbucket' - }, { - name: 'Gitlab', - value: 'Gitlab' - }]; - - if (!widgetConfig.options.scm) { - ctrl.repoOption=""; - } - else - { - var myindex; + // Request collectors + collectorData.collectorsByType('scm').then(processCollectorsResponse); + + function processCollectorsResponse(data) { + ctrl.collectors = data; - for (var v = 0; v < ctrl.repoOptions.length; v++) { - if (ctrl.repoOptions[v].name === widgetConfig.options.scm.name) { - myindex = v; + ctrl.repoOptions =[]; + _(data).forEach(function (collector) { + ctrl.repoOptions.push({name:collector.name,value:collector.name}); + }); + var collector = modalData.dashboard.application.components[0].collectorItems.SCM; + var scmType = collector!=null? collector[0].options.scm: null; + var myIndex; + if(scmType!=null){ + for (var v = 0; v < ctrl.repoOptions.length; v++) { + if (ctrl.repoOptions[v].name.toUpperCase() === scmType.toUpperCase()) { + myIndex = v; + } } + ctrl.repoOption=ctrl.repoOptions[myIndex]; } - ctrl.repoOption=ctrl.repoOptions[myindex]; + } ctrl.repoUrl = removeGit(widgetConfig.options.url); @@ -54,12 +49,7 @@ // public methods ctrl.submit = submitForm; - // Request collecters - collectorData.collectorsByType('scm').then(processCollectorsResponse); - function processCollectorsResponse(data) { - ctrl.collectors = data; - } /* * function submitForm(valid, url) { ctrl.submitted = true; if (valid && @@ -191,7 +181,6 @@ name : "repo", options : { id : widgetConfig.options.id, - scm : ctrl.repoOption, url : removeGit(ctrl.repoUrl), branch : ctrl.gitBranch, userID : getNonNullString(ctrl.repouser),