Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Update ProjectMetadataService
Browse files Browse the repository at this point in the history
This commit updates the ProjectMetadataService to use the new domain
model and repositories.
We're also adding a new SupportPolicy processor that calculates the
support policy EOL dates on the model before persisting it to the
database.

See gh-964
  • Loading branch information
bclozel committed Sep 21, 2020
1 parent 70dd61a commit 65f9d72
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 117 deletions.

This file was deleted.

This file was deleted.

@@ -0,0 +1,85 @@
package sagan.site.projects;

import java.util.List;

import sagan.blog.PostFormat;
import sagan.site.projects.support.SupportPolicyProjectGenerationsProcessor;
import sagan.site.blog.PostContentRenderer;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class ProjectMetadataService {

private static final Sort sortBySortOrderAndId = new Sort("display.sortOrder", "id");

private final ProjectRepository repository;

private final ProjectGroupRepository groupRepository;

private final ReleaseRepository releaseRepository;

private final SupportPolicyProjectGenerationsProcessor supportPolicyProcessor;

private final PostContentRenderer renderer;

public ProjectMetadataService(ProjectRepository repository, ProjectGroupRepository groupRepository,
ReleaseRepository releaseRepository, SupportPolicyProjectGenerationsProcessor supportPolicyProcessor, PostContentRenderer postContentRenderer) {
this.repository = repository;
this.groupRepository = groupRepository;
this.releaseRepository = releaseRepository;
this.supportPolicyProcessor = supportPolicyProcessor;
this.renderer = postContentRenderer;
}

public Project fetchFullProject(String id) {
return this.repository.fetchFullProject(id);
}

public List<Project> fetchActiveProjectsTree() {
return this.repository.findDistinctByStatusAndParentProjectIsNull(SupportStatus.ACTIVE, sortBySortOrderAndId);
}

public List<Project> fetchAllProjects() {
return this.repository.findAll(sortBySortOrderAndId);
}

public List<Project> fetchTopLevelProjectsWithGroups() {
return this.repository.findTopLevelProjectsWithGroup();
}

public Project save(Project project) {
project.getReleases().forEach(rel -> rel.setCurrent(false));
project.getReleases().stream()
.sorted(Release::compareTo)
.filter(Release::isGeneralAvailability)
.findFirst().ifPresent(rel -> rel.setCurrent(true));
this.supportPolicyProcessor.updateSupportPolicyDates(project.getGenerations());
String bootConfigHtml = this.renderer.render(project.getBootConfig().getSource(), PostFormat.ASCIIDOC);
project.getBootConfig().setHtml(bootConfigHtml);
String overviewHtml = this.renderer.render(project.getOverview().getSource(), PostFormat.ASCIIDOC);
project.getOverview().setHtml(overviewHtml);
return this.repository.save(project);
}

public void delete(String id) {
this.repository.delete(id);
}

public List<ProjectGroup> getAllGroups() {
return this.groupRepository.findAll();
}

public ProjectGroup findGroup(String name) {
return this.groupRepository.findByNameIgnoreCase(name);
}

public Release findRelease(String projectId, Version version) {
return this.releaseRepository.findRelease(projectId, version);
}

public Release findCurrentRelease(String projectId) {
return this.releaseRepository.findCurrentRelease(projectId);
}
}
@@ -0,0 +1,47 @@
package sagan.site.projects.support;

import java.time.Period;
import java.util.SortedSet;

import sagan.site.projects.ProjectGeneration;

import org.springframework.stereotype.Component;

/**
* Process a list of {@link ProjectGeneration} and updates support policy dates by looking
* at the available generations and their initial release dates.
*
* @see <a href="https://tanzu.vmware.com/support/oss">Tanzu official OSS support policy.</a>
* @see <a href="https://tanzu.vmware.com/support/lifecycle_policy">Tanzu official Commercial support policy</a>
*/
@Component
public class SupportPolicyProjectGenerationsProcessor {

/**
* Open Source Community Project Minor Releases will be supported a minimum of
* 12 months from the date such Release was made available.
*/
private static Period TWELVE_MONTHS = Period.ofMonths(12);

/**
* Open Source Community Project Major Releases will be supported with an additional
* 18 months after the following Major/Minor release was made available.
*/
private static Period EIGHTEEN_MONTHS = Period.ofMonths(18);

/**
* Open Source Community Project Major Releases will be supported a minimum of
* 18 months from the date such Release was made available.
*/
public void updateSupportPolicyDates(SortedSet<ProjectGeneration> generations) {
ProjectGeneration previousGeneration = null;
for (ProjectGeneration currentGeneration : generations) {
currentGeneration.setOssSupportPolicyEndDate(currentGeneration.getInitialReleaseDate().plus(TWELVE_MONTHS));
if (previousGeneration != null && currentGeneration.isReleased()) {
previousGeneration.setCommercialSupportPolicyEndDate(currentGeneration.getInitialReleaseDate().plus(EIGHTEEN_MONTHS));
}
previousGeneration = currentGeneration;
}
}

}
@@ -0,0 +1,61 @@
package sagan.site.projects.support;

import java.time.LocalDate;
import java.time.Period;
import java.util.TreeSet;

import org.junit.Test;
import sagan.site.projects.ProjectGeneration;

import static org.assertj.core.api.Assertions.assertThat;


/**
* Tests for {@link SupportPolicyProjectGenerationsProcessor}
*/
public class SupportPolicyProjectGenerationsProcessorTests {

private final SupportPolicyProjectGenerationsProcessor processor = new SupportPolicyProjectGenerationsProcessor();

@Test
public void shouldUpdateOssSupportPolicy() {
TreeSet<ProjectGeneration> generations = new TreeSet<>();
ProjectGeneration twoOneX = new ProjectGeneration("2.1.x", LocalDate.parse("2020-01-15"));
generations.add(twoOneX);
this.processor.updateSupportPolicyDates(generations);

assertThat(twoOneX.getOssSupportPolicyEndDate()).isEqualTo(LocalDate.parse("2021-01-15"));
assertThat(twoOneX.getCommercialSupportPolicyEndDate()).isNull();
}

@Test
public void shouldUpdateCommercialSupportPolicy() {
TreeSet<ProjectGeneration> generations = new TreeSet<>();
ProjectGeneration twoOneX = new ProjectGeneration("2.1.x", LocalDate.parse("2019-01-15"));
ProjectGeneration twoTwoX = new ProjectGeneration("2.2.x", LocalDate.parse("2019-07-02"));
generations.add(twoOneX);
generations.add(twoTwoX);
this.processor.updateSupportPolicyDates(generations);

assertThat(twoOneX.getOssSupportPolicyEndDate()).isEqualTo(LocalDate.parse("2020-01-15"));
assertThat(twoOneX.getCommercialSupportPolicyEndDate()).isEqualTo(LocalDate.parse("2021-01-02"));
assertThat(twoTwoX.getOssSupportPolicyEndDate()).isEqualTo(LocalDate.parse("2020-07-02"));
assertThat(twoTwoX.getCommercialSupportPolicyEndDate()).isNull();
}

@Test
public void shouldNotUpdateCommercialSupportPolicyIfNotReleased() {
TreeSet<ProjectGeneration> generations = new TreeSet<>();
ProjectGeneration twoOneX = new ProjectGeneration("2.1.x", LocalDate.parse("2020-01-15"));
ProjectGeneration twoTwoX = new ProjectGeneration("2.2.x", LocalDate.now().plus(Period.ofMonths(1)));
generations.add(twoOneX);
generations.add(twoTwoX);
this.processor.updateSupportPolicyDates(generations);

assertThat(twoOneX.getOssSupportPolicyEndDate()).isEqualTo(LocalDate.parse("2021-01-15"));
assertThat(twoOneX.getCommercialSupportPolicyEndDate()).isNull();
assertThat(twoTwoX.getOssSupportPolicyEndDate()).isEqualTo(LocalDate.now().plus(Period.ofMonths(13)));
assertThat(twoTwoX.getCommercialSupportPolicyEndDate()).isNull();
}

}

0 comments on commit 65f9d72

Please sign in to comment.