Skip to content

Commit

Permalink
refactor(pipelineTemplates): Use shared strings (#303)
Browse files Browse the repository at this point in the history
For template type and source prefix used shared strins.
  • Loading branch information
beckje01 authored and robzienert committed Mar 12, 2018
1 parent 7c04dea commit d1495bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static com.netflix.spinnaker.front50.model.pipeline.Pipeline.TYPE_TEMPLATED;
import static com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX;

@RestController
@RequestMapping("pipelineTemplates")
public class PipelineTemplateController {
Expand Down Expand Up @@ -110,7 +113,7 @@ List<String> getDependentConfigs(String templateId, boolean recursive) {

pipelineDAO.all()
.stream()
.filter(pipeline -> pipeline.getType() != null && pipeline.getType().equals("templatedPipeline"))
.filter(pipeline -> pipeline.getType() != null && pipeline.getType().equals(TYPE_TEMPLATED))
.forEach(templatedPipeline -> {
String source;
try {
Expand All @@ -131,10 +134,10 @@ List<String> getDependentConfigs(String templateId, boolean recursive) {

private List<String> convertAllTemplateIdsToSources(String rootTemplateId, boolean recursive) {
List<String> templateIds = new ArrayList<>();
templateIds.add("spinnaker://" + rootTemplateId);
templateIds.add(SPINNAKER_PREFIX + rootTemplateId);
if (recursive) {
for (String id : getDependentTemplates(rootTemplateId, Optional.empty())) {
templateIds.add("spinnaker://" + id);
templateIds.add(SPINNAKER_PREFIX + id);
}
}
return templateIds;
Expand Down Expand Up @@ -165,7 +168,7 @@ List<String> getDependentTemplates(String templateId, Optional<Collection<Pipeli
final Collection<PipelineTemplate> pipelineTemplates = templates.orElse(getPipelineTemplateDAO().all());
pipelineTemplates.forEach(template -> {
if (template.getSource() != null
&& template.getSource().equalsIgnoreCase("spinnaker://" + templateId)) {
&& template.getSource().equalsIgnoreCase(SPINNAKER_PREFIX + templateId)) {
dependentTemplateIds.add(template.getId());
dependentTemplateIds.addAll(getDependentTemplates(template.getId(), Optional.of(pipelineTemplates)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO
import spock.lang.Specification
import spock.lang.Subject

import static com.netflix.spinnaker.front50.model.pipeline.Pipeline.TYPE_TEMPLATED;
import static com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX;

class PipelineTemplateControllerSpec extends Specification {
def pipelineDAO = Mock(PipelineDAO)
def pipelineTemplateDAO = Mock(PipelineTemplateDAO)
Expand All @@ -42,11 +45,11 @@ class PipelineTemplateControllerSpec extends Specification {
id: "myTemplate"
)
def pipeline = new Pipeline(
type: "templatedPipeline",
type: TYPE_TEMPLATED,
config: [
pipeline: [
template: [
source: "spinnaker://myTemplate"
source: SPINNAKER_PREFIX + "myTemplate"
]
]
]
Expand All @@ -66,7 +69,7 @@ class PipelineTemplateControllerSpec extends Specification {
def templateId = "myTemplate"
def pipelineTemplate = new PipelineTemplate(
id: "myDependentTemplate",
source: "spinnaker://myTemplate"
source: SPINNAKER_PREFIX + "myTemplate"
)

when:
Expand All @@ -84,11 +87,11 @@ class PipelineTemplateControllerSpec extends Specification {
)
def childTemplate = new PipelineTemplate(
id: 'childTemplate',
source: 'spinnaker://rootTemplate'
source: SPINNAKER_PREFIX + 'rootTemplate'
)
def grandchildTemplate = new PipelineTemplate(
id: 'grandchildTemplate',
source: 'spinnaker://childTemplate'
source: SPINNAKER_PREFIX + 'childTemplate'
)
def unrelatedTemplate = new PipelineTemplate(
id: 'unrelatedTemplate'
Expand Down

0 comments on commit d1495bf

Please sign in to comment.