-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backlog#10): implement notification to call projects for news
- Loading branch information
Showing
19 changed files
with
157 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/fr/lesprojetscagnottes/core/notification/model/NotificationName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package fr.lesprojetscagnottes.core.notification.model; | ||
|
||
public enum NotificationName { | ||
CAMPAIGN_STARTED, CAMPAIGN_REMINDER,PROJECT_PUBLISHED | ||
CAMPAIGN_STARTED, CAMPAIGN_REMINDER,PROJECT_PUBLISHED,PROJECT_CALL_FOR_NEWS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/fr/lesprojetscagnottes/core/project/scheduler/ProjectScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package fr.lesprojetscagnottes.core.project.scheduler; | ||
|
||
import fr.lesprojetscagnottes.core.common.date.DateUtils; | ||
import fr.lesprojetscagnottes.core.news.entity.NewsEntity; | ||
import fr.lesprojetscagnottes.core.news.service.NewsService; | ||
import fr.lesprojetscagnottes.core.notification.model.NotificationName; | ||
import fr.lesprojetscagnottes.core.notification.service.NotificationService; | ||
import fr.lesprojetscagnottes.core.project.entity.ProjectEntity; | ||
import fr.lesprojetscagnottes.core.project.model.ProjectStatus; | ||
import fr.lesprojetscagnottes.core.project.repository.ProjectRepository; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
|
||
@Component | ||
@Slf4j | ||
public class ProjectScheduler { | ||
|
||
@Value("${fr.lesprojetscagnottes.web.url}") | ||
private String webUrl; | ||
|
||
private final NewsService newsService; | ||
|
||
private final NotificationService notificationService; | ||
|
||
private final ProjectRepository projectRepository; | ||
|
||
@Autowired | ||
public ProjectScheduler(NewsService newsService, | ||
NotificationService notificationService, | ||
ProjectRepository projectRepository) { | ||
this.newsService = newsService; | ||
this.notificationService = notificationService; | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Scheduled(cron = "${fr.lesprojetscagnottes.core.schedule.newsproject}") | ||
public void notifyCallForNews() { | ||
log.info("Calling for news has started"); | ||
Set<ProjectStatus> status = new LinkedHashSet<>(); | ||
status.add(ProjectStatus.IN_PROGRESS); | ||
LocalDateTime now = LocalDateTime.now(); | ||
LocalDateTime nowMinus2Months = now.minusMonths(2); | ||
Date nowMinus2MonthsDate = DateUtils.asDate(nowMinus2Months); | ||
Set<ProjectEntity> projects = projectRepository.findAllByStatusInAndLastStatusUpdateLessThan(status, nowMinus2MonthsDate); | ||
projects.forEach(project -> { | ||
NewsEntity news = newsService.findFirstByProjectIdAndCreatedAtGreaterThanOrderByCreatedAtDesc(project.getId(), nowMinus2MonthsDate); | ||
if(news == null) { | ||
Map<String, Object> model = new HashMap<>(); | ||
model.put("_user_email_", project.getLeader().getEmail()); | ||
model.put("_organization_id_", project.getOrganization().getId()); | ||
model.put("user_fullname", project.getLeader().getFullname()); | ||
model.put("project_title", project.getTitle()); | ||
model.put("project_url", webUrl + "/projects/" + project.getId()); | ||
notificationService.create(NotificationName.PROJECT_CALL_FOR_NEWS, model, project.getOrganization().getId()); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--liquibase formatted sql | ||
|
||
--changeset lesprojetscagnottes:add-project-last_status_update | ||
ALTER TABLE projects | ||
ADD last_status_update timestamp without time zone DEFAULT now(); | ||
UPDATE projects SET last_status_update = updated_at; | ||
--rollback alter table projects drop column last_status_update; |
Oops, something went wrong.