|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
|
import ru.ulstu.activity.service.ActivityService;
|
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
|
import ru.ulstu.deadline.service.DeadlineService;
|
|
|
|
|
import ru.ulstu.file.model.FileDataDto;
|
|
|
|
@ -26,6 +27,7 @@ import ru.ulstu.user.service.UserService;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
@ -53,6 +55,7 @@ public class GrantService extends BaseService {
|
|
|
|
|
private final GrantNotificationService grantNotificationService;
|
|
|
|
|
private final KiasService kiasService;
|
|
|
|
|
private final PingService pingService;
|
|
|
|
|
private final ActivityService activityService;
|
|
|
|
|
|
|
|
|
|
public GrantService(GrantRepository grantRepository,
|
|
|
|
|
FileService fileService,
|
|
|
|
@ -63,7 +66,8 @@ public class GrantService extends BaseService {
|
|
|
|
|
EventService eventService,
|
|
|
|
|
GrantNotificationService grantNotificationService,
|
|
|
|
|
KiasService kiasService,
|
|
|
|
|
PingService pingService) {
|
|
|
|
|
PingService pingService,
|
|
|
|
|
ActivityService activityService) {
|
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
|
this.kiasService = kiasService;
|
|
|
|
|
this.baseRepository = grantRepository;
|
|
|
|
@ -75,6 +79,7 @@ public class GrantService extends BaseService {
|
|
|
|
|
this.eventService = eventService;
|
|
|
|
|
this.grantNotificationService = grantNotificationService;
|
|
|
|
|
this.pingService = pingService;
|
|
|
|
|
this.activityService = activityService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GrantDto getExistGrantById(Integer id) {
|
|
|
|
@ -95,6 +100,7 @@ public class GrantService extends BaseService {
|
|
|
|
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
|
|
|
|
newGrant = grantRepository.save(newGrant);
|
|
|
|
|
eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
|
|
|
|
|
activityService.createActivity(new ArrayList<>(newGrant.getAuthors()), newGrant.getCommonActivityState());
|
|
|
|
|
grantNotificationService.sendCreateNotification(newGrant);
|
|
|
|
|
return newGrant;
|
|
|
|
|
}
|
|
|
|
@ -137,6 +143,7 @@ public class GrantService extends BaseService {
|
|
|
|
|
Grant grant = findById(grantDto.getId());
|
|
|
|
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
|
|
|
|
User oldLeader = grant.getLeader();
|
|
|
|
|
Grant.GrantStatus oldStatus = grant.getStatus();
|
|
|
|
|
for (FileDataDto file : grantDto.getFiles().stream()
|
|
|
|
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
|
|
|
|
.collect(toList())) {
|
|
|
|
@ -158,6 +165,9 @@ public class GrantService extends BaseService {
|
|
|
|
|
if (grant.getLeader() != oldLeader) {
|
|
|
|
|
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
|
|
|
|
|
}
|
|
|
|
|
if(grant.getStatus() != oldStatus) {
|
|
|
|
|
activityService.createActivity(new ArrayList<>(grant.getAuthors()), grant.getCommonActivityState());
|
|
|
|
|
}
|
|
|
|
|
eventService.updateGrantDeadlines(grant);
|
|
|
|
|
return grant.getId();
|
|
|
|
|
}
|
|
|
|
|