complete controllers
This commit is contained in:
parent
8e89ec08a7
commit
938deda29b
@ -2,6 +2,8 @@ package ru.ulstu.activity.api;
|
|||||||
|
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface ActivityRepository {
|
public interface ActivityRepository<T> {
|
||||||
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
T save(T t);
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
package ru.ulstu.activity.common.service;
|
|
||||||
|
|
||||||
import ru.ulstu.activity.api.ActivityRepository;
|
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
|
||||||
import ru.ulstu.activity.api.model.ActivityListDto;
|
|
||||||
import ru.ulstu.activity.common.model.AbstractActivity;
|
|
||||||
import ru.ulstu.core.model.response.PageableItems;
|
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
|
||||||
|
|
||||||
public abstract class AbstractActivityService<L extends ActivityListDto, T extends AbstractActivity, D extends ActivityDto> {
|
|
||||||
|
|
||||||
protected ActivityRepository activityRepository;
|
|
||||||
|
|
||||||
public abstract T create(T entity);
|
|
||||||
|
|
||||||
public abstract D create(D entity);
|
|
||||||
|
|
||||||
public abstract T update(T entity);
|
|
||||||
|
|
||||||
public abstract D update(D entity);
|
|
||||||
|
|
||||||
public abstract boolean delete(Integer id);
|
|
||||||
|
|
||||||
public abstract PageableItems<T> findAll(int offset, int count);
|
|
||||||
|
|
||||||
public PageableItems<L> findAllDto(int offset, int count) {
|
|
||||||
return convertPageable(findAll(offset, count), entity -> getActivityListDto(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract L getActivityListDto(T entity);
|
|
||||||
|
|
||||||
protected boolean checkUniqueName(String title, Integer id) {
|
|
||||||
return title.equals(activityRepository.findByNameAndNotId(title, id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,8 @@
|
|||||||
|
package ru.ulstu.activity.common.service;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
|
|
||||||
|
public abstract class ActivityNotificationService<T extends AbstractActivity> {
|
||||||
|
|
||||||
|
public abstract void sendCreateNotification(T entity);
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package ru.ulstu.activity.common.service;
|
||||||
|
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
public abstract class ActivityService<L extends ActivityListDto, T extends AbstractActivity, D extends ActivityDto> {
|
||||||
|
|
||||||
|
protected final ActivityRepository<T> activityRepository;
|
||||||
|
protected final ActivityNotificationService<T> activityNotificationService;
|
||||||
|
protected final PingService pingService;
|
||||||
|
|
||||||
|
protected ActivityService(ActivityRepository activityRepository,
|
||||||
|
ActivityNotificationService<T> activityNotificationService,
|
||||||
|
PingService pingService) {
|
||||||
|
this.activityRepository = activityRepository;
|
||||||
|
this.activityNotificationService = activityNotificationService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public D create(D entityDto) {
|
||||||
|
T newEntity;
|
||||||
|
try {
|
||||||
|
newEntity = copyFromDto(getNewActivity(), entityDto);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return getNewActivityDto(create(newEntity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public T create(T entity) {
|
||||||
|
T newEntity = activityRepository.save(entity);
|
||||||
|
activityNotificationService.sendCreateNotification(newEntity);
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract T update(T entity);
|
||||||
|
|
||||||
|
public abstract D update(D entity);
|
||||||
|
|
||||||
|
public abstract boolean delete(Integer id);
|
||||||
|
|
||||||
|
public abstract T findById(Integer id);
|
||||||
|
|
||||||
|
public abstract PageableItems<T> findAll(int offset, int count);
|
||||||
|
|
||||||
|
public PageableItems<L> findAllDto(int offset, int count) {
|
||||||
|
return convertPageable(findAll(offset, count), entity -> getActivityListDto(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract T copyFromDto(T t, D d) throws IOException;
|
||||||
|
|
||||||
|
protected abstract L getActivityListDto(T entity);
|
||||||
|
|
||||||
|
protected abstract T getNewActivity();
|
||||||
|
|
||||||
|
protected abstract D getNewActivityDto(T entity);
|
||||||
|
|
||||||
|
protected boolean checkUniqueName(String title, Integer id) {
|
||||||
|
return title.equals(activityRepository.findByNameAndNotId(title, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int entityId) {
|
||||||
|
pingService.addPing(findById(entityId));
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,11 @@
|
|||||||
package ru.ulstu.activity.conference;
|
package ru.ulstu.activity.conference.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.activity.api.ActivityController;
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
||||||
@ -11,7 +15,9 @@ import ru.ulstu.activity.conference.service.ConferenceService;
|
|||||||
import ru.ulstu.core.model.response.PageableItems;
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.model.response.Response;
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
public class ConferenceController extends ActivityController<ConferenceListDto, ConferenceDashboardDto, ConferenceDto> {
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
public class ConferenceController implements ActivityController<ConferenceListDto, ConferenceDashboardDto, ConferenceDto> {
|
||||||
|
|
||||||
private final ConferenceService conferenceService;
|
private final ConferenceService conferenceService;
|
||||||
|
|
||||||
@ -34,27 +40,31 @@ public class ConferenceController extends ActivityController<ConferenceListDto,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<ConferenceDto> get(@PathVariable("grant-id") Integer entityId) {
|
@GetMapping("{conference-id}")
|
||||||
return new Response<>(conferenceService.findById(entityId));
|
public Response<ConferenceDto> get(@PathVariable("conference-id") Integer entityId) {
|
||||||
|
return new Response<>(conferenceService.findConferenceById(entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<ConferenceDto> create(ConferenceDto entity) {
|
@PostMapping
|
||||||
return null;
|
public Response<ConferenceDto> create(@RequestBody @Valid ConferenceDto entity) {
|
||||||
|
return new Response<>(conferenceService.create(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<ConferenceDto> update(ConferenceDto entity) {
|
@PutMapping
|
||||||
return null;
|
public Response<ConferenceDto> update(@RequestBody @Valid ConferenceDto entity) {
|
||||||
|
return new Response<>(conferenceService.update(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<Boolean> delete(Integer entityId) {
|
@DeleteMapping("{conference-id}")
|
||||||
return null;
|
public Response<Boolean> delete(@PathVariable("conference-id") Integer entityId) {
|
||||||
|
return new Response<>(conferenceService.delete(entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@PostMapping("ping/{conference-id}")
|
||||||
public void ping(int entityId) {
|
public void ping(@PathVariable("conference-id") int conferenceId) {
|
||||||
|
conferenceService.ping(conferenceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ import ru.ulstu.user.model.User;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ConferenceRepository extends JpaRepository<Conference, Integer>, ActivityRepository {
|
public interface ConferenceRepository extends JpaRepository<Conference, Integer>, ActivityRepository<Conference> {
|
||||||
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
||||||
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC")
|
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC")
|
||||||
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
||||||
|
@ -2,6 +2,7 @@ package ru.ulstu.activity.conference.service;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
import ru.ulstu.activity.conference.model.Conference;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
import ru.ulstu.activity.ping.service.PingService;
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
@ -14,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceNotificationService {
|
public class ConferenceNotificationService extends ActivityNotificationService<Conference> {
|
||||||
|
|
||||||
private final static int YESTERDAY = -1;
|
private final static int YESTERDAY = -1;
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
|
@ -4,8 +4,13 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.activity.common.service.AbstractActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.conference.model.*;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceFilterDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceListDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.activity.conference.repository.ConferenceRepository;
|
import ru.ulstu.activity.conference.repository.ConferenceRepository;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
@ -20,7 +25,6 @@ import ru.ulstu.user.service.UserService;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -30,7 +34,7 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceService extends AbstractActivityService<ConferenceListDto, Conference, ConferenceDto> {
|
public class ConferenceService extends ActivityService<ConferenceListDto, Conference, ConferenceDto> {
|
||||||
|
|
||||||
private final ConferenceRepository conferenceRepository;
|
private final ConferenceRepository conferenceRepository;
|
||||||
private final ConferenceUserService conferenceUserService;
|
private final ConferenceUserService conferenceUserService;
|
||||||
@ -49,7 +53,7 @@ public class ConferenceService extends AbstractActivityService<ConferenceListDto
|
|||||||
PingService pingService,
|
PingService pingService,
|
||||||
ConferenceNotificationService conferenceNotificationService,
|
ConferenceNotificationService conferenceNotificationService,
|
||||||
EventService eventService) {
|
EventService eventService) {
|
||||||
this.activityRepository = conferenceRepository;
|
super(conferenceRepository, conferenceNotificationService, pingService);
|
||||||
this.conferenceRepository = conferenceRepository;
|
this.conferenceRepository = conferenceRepository;
|
||||||
this.conferenceUserService = conferenceUserService;
|
this.conferenceUserService = conferenceUserService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
@ -90,27 +94,6 @@ public class ConferenceService extends AbstractActivityService<ConferenceListDto
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
public ConferenceDto create(ConferenceDto conferenceDto) {
|
|
||||||
Conference newConference;
|
|
||||||
try {
|
|
||||||
newConference = copyFromDto(new Conference(), conferenceDto);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return new ConferenceDto(create(newConference));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
public Conference create(Conference conference) {
|
|
||||||
conference = conferenceRepository.save(conference);
|
|
||||||
conferenceNotificationService.sendCreateNotification(conference);
|
|
||||||
eventService.createFromObject(conference, Collections.emptyList(), false, "конференции");
|
|
||||||
return conference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public ConferenceDto update(ConferenceDto conferenceDto) {
|
public ConferenceDto update(ConferenceDto conferenceDto) {
|
||||||
@ -154,6 +137,16 @@ public class ConferenceService extends AbstractActivityService<ConferenceListDto
|
|||||||
return new ConferenceListDto(entity);
|
return new ConferenceListDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Conference getNewActivity() {
|
||||||
|
return new Conference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ConferenceDto getNewActivityDto(Conference entity) {
|
||||||
|
return new ConferenceDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
conferenceDto.getDeadlines().add(new Deadline());
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
@ -206,19 +199,19 @@ public class ConferenceService extends AbstractActivityService<ConferenceListDto
|
|||||||
return Arrays.asList(ConferenceUser.Deposit.values());
|
return Arrays.asList(ConferenceUser.Deposit.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
protected Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
conference.setUrl(conferenceDto.getUrl());
|
conference.setUrl(conferenceDto.getUrl());
|
||||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
conference.setEndDate(conferenceDto.getEndDate());
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
conference.getPapers().clear();
|
conference.getPapers().clear();
|
||||||
conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findPaperById(paper.getId()) : paperService.create(paper)));
|
conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findById(paper.getId()) : paperService.create(paper)));
|
||||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||||
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||||
conferenceDto.getPaperIds().forEach(paperId ->
|
conferenceDto.getPaperIds().forEach(paperId ->
|
||||||
conference.getPapers().add(paperService.findPaperById(paperId)));
|
conference.getPapers().add(paperService.findById(paperId)));
|
||||||
}
|
}
|
||||||
return conference;
|
return conference;
|
||||||
}
|
}
|
||||||
@ -249,17 +242,11 @@ public class ConferenceService extends AbstractActivityService<ConferenceListDto
|
|||||||
return conferenceRepository.isPaperAttached(paperId);
|
return conferenceRepository.isPaperAttached(paperId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
public ConferenceDto findConferenceById(Integer id) {
|
||||||
public void ping(ConferenceDto conferenceDto) throws IOException {
|
return new ConferenceDto(findById(id));
|
||||||
pingService.addPing(findConferenceById(conferenceDto.getId()));
|
|
||||||
conferenceRepository.updatePingConference(conferenceDto.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto findById(Integer id) {
|
public Conference findById(Integer id) {
|
||||||
return new ConferenceDto(findConferenceById(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Conference findConferenceById(Integer id) {
|
|
||||||
return conferenceRepository.getOne(id);
|
return conferenceRepository.getOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ public class GrantController implements ActivityController<GrantListDto, GrantDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GetMapping
|
@GetMapping("{grant-id}")
|
||||||
public Response<GrantDto> get(@PathVariable("grant-id") Integer entityId) {
|
public Response<GrantDto> get(@PathVariable("grant-id") Integer entityId) {
|
||||||
return new Response<>(grantService.findById(entityId));
|
return new Response<>(grantService.findGrantById(entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,14 +69,14 @@ public class GrantController implements ActivityController<GrantListDto, GrantDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DeleteMapping
|
@DeleteMapping("{grant-id}")
|
||||||
public Response<Boolean> delete(@PathVariable("grant-id") Integer entityId) {
|
public Response<Boolean> delete(@PathVariable("grant-id") Integer entityId) {
|
||||||
return new Response<>(grantService.delete(entityId));
|
return new Response<>(grantService.delete(entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PostMapping("ping/{paper-id}")
|
@PostMapping("ping/{grant-id}")
|
||||||
public void ping(@PathVariable("paper-id") int entityId) {
|
public void ping(@PathVariable("grant-id") int entityId) {
|
||||||
grantService.ping(entityId);
|
grantService.ping(entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import ru.ulstu.activity.grant.model.Grant;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface GrantRepository extends JpaRepository<Grant, Integer>, ActivityRepository {
|
public interface GrantRepository extends JpaRepository<Grant, Integer>, ActivityRepository<Grant> {
|
||||||
|
|
||||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package ru.ulstu.activity.grant.service;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
import ru.ulstu.activity.grant.model.Grant;
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -13,7 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantNotificationService {
|
public class GrantNotificationService extends ActivityNotificationService<Grant> {
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
||||||
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
||||||
|
@ -7,7 +7,7 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.activity.common.service.AbstractActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.activity.file.service.FileService;
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
@ -45,7 +45,7 @@ import static ru.ulstu.activity.grant.model.Grant.GrantStatus.APPLICATION;
|
|||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantService extends AbstractActivityService<GrantListDto, Grant, GrantDto> {
|
public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto> {
|
||||||
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
@ -69,9 +69,9 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
GrantNotificationService grantNotificationService,
|
GrantNotificationService grantNotificationService,
|
||||||
KiasService kiasService,
|
KiasService kiasService,
|
||||||
PingService pingService) {
|
PingService pingService) {
|
||||||
|
super(grantRepository, grantNotificationService, pingService);
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
this.kiasService = kiasService;
|
this.kiasService = kiasService;
|
||||||
this.activityRepository = grantRepository;
|
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
@ -83,7 +83,7 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto getExistGrantById(Integer id) {
|
public GrantDto getExistGrantById(Integer id) {
|
||||||
return new GrantDto(findGrantById(id));
|
return new GrantDto(findById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,16 +97,14 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
return new GrantListDto(entity);
|
return new GrantListDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@Override
|
@Override
|
||||||
public GrantDto create(GrantDto grantDto) {
|
protected Grant getNewActivity() {
|
||||||
Grant newGrant;
|
return new Grant();
|
||||||
try {
|
}
|
||||||
newGrant = copyFromDto(new Grant(), grantDto);
|
|
||||||
} catch (IOException e) {
|
@Override
|
||||||
throw new RuntimeException(e);
|
protected GrantDto getNewActivityDto(Grant entity) {
|
||||||
}
|
return new GrantDto(entity);
|
||||||
return new GrantDto(create(newGrant));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -121,7 +119,7 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public GrantDto update(GrantDto grantDto) {
|
public GrantDto update(GrantDto grantDto) {
|
||||||
Grant grant = findGrantById(grantDto.getId());
|
Grant grant = findById(grantDto.getId());
|
||||||
return new GrantDto(update(grant));
|
return new GrantDto(update(grant));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +145,7 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
protected Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
||||||
grant.setComment(grantDto.getComment());
|
grant.setComment(grantDto.getComment());
|
||||||
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
||||||
grant.setTitle(grantDto.getTitle());
|
grant.setTitle(grantDto.getTitle());
|
||||||
@ -169,7 +167,7 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
}
|
}
|
||||||
grant.getPapers().clear();
|
grant.getPapers().clear();
|
||||||
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
|
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
|
||||||
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findPaperById(paperIds)));
|
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findById(paperIds)));
|
||||||
}
|
}
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
@ -182,7 +180,7 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean delete(Integer grantId) {
|
public boolean delete(Integer grantId) {
|
||||||
Grant grant = findGrantById(grantId);
|
Grant grant = findById(grantId);
|
||||||
if (grant != null) {
|
if (grant != null) {
|
||||||
grantRepository.delete(grant);
|
grantRepository.delete(grant);
|
||||||
return true;
|
return true;
|
||||||
@ -349,16 +347,16 @@ public class GrantService extends AbstractActivityService<GrantListDto, Grant, G
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto findById(Integer id) {
|
public GrantDto findGrantById(Integer id) {
|
||||||
return new GrantDto(grantRepository.getOne(id));
|
return new GrantDto(findById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Grant findGrantById(Integer id) {
|
public Grant findById(Integer id) {
|
||||||
return grantRepository.getOne(id);
|
return grantRepository.getOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int grantId) {
|
public void ping(int grantId) {
|
||||||
pingService.addPing(findGrantById(grantId));
|
pingService.addPing(findById(grantId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class PaperController implements ActivityController<PaperListDto, PaperDa
|
|||||||
|
|
||||||
@GetMapping("{paper-id}")
|
@GetMapping("{paper-id}")
|
||||||
public Response<PaperDto> get(@PathVariable("paper-id") Integer paperId) {
|
public Response<PaperDto> get(@PathVariable("paper-id") Integer paperId) {
|
||||||
return new Response<>(paperService.findById(paperId));
|
return new Response<>(paperService.findPaperById(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@ -4,13 +4,14 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
import ru.ulstu.activity.paper.model.Paper;
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
import ru.ulstu.core.repository.JpaDetachableRepository;
|
import ru.ulstu.core.repository.JpaDetachableRepository;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PaperRepository extends JpaDetachableRepository<Paper, Integer> {
|
public interface PaperRepository extends JpaDetachableRepository<Paper, Integer>, ActivityRepository<Paper> {
|
||||||
|
|
||||||
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
||||||
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
||||||
@ -32,4 +33,7 @@ public interface PaperRepository extends JpaDetachableRepository<Paper, Integer>
|
|||||||
|
|
||||||
@Query("SELECT p FROM Paper p ")
|
@Query("SELECT p FROM Paper p ")
|
||||||
Page<Paper> findAll(Pageable pageable);
|
Page<Paper> findAll(Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT title FROM Paper p WHERE (p.title = :name) AND (:id IS NULL OR p.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ru.ulstu.activity.paper.service;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
import ru.ulstu.activity.paper.model.Paper;
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
import ru.ulstu.core.model.response.PageableItems;
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
@ -13,7 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PaperNotificationService {
|
public class PaperNotificationService extends ActivityNotificationService<Paper> {
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification";
|
private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification";
|
||||||
private final static String TEMPLATE_CREATE = "paperCreateNotification";
|
private final static String TEMPLATE_CREATE = "paperCreateNotification";
|
||||||
|
@ -3,7 +3,7 @@ package ru.ulstu.activity.paper.service;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.activity.common.service.AbstractActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.activity.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
@ -44,7 +44,7 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PaperService extends AbstractActivityService<PaperListDto, Paper, PaperDto> {
|
public class PaperService extends ActivityService<PaperListDto, Paper, PaperDto> {
|
||||||
private final PaperNotificationService paperNotificationService;
|
private final PaperNotificationService paperNotificationService;
|
||||||
private final PaperRepository paperRepository;
|
private final PaperRepository paperRepository;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
@ -63,6 +63,7 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
EventService eventService,
|
EventService eventService,
|
||||||
PingService pingService) {
|
PingService pingService) {
|
||||||
|
super(paperRepository, paperNotificationService, pingService);
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
@ -86,19 +87,21 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
return new PaperListDto(entity);
|
return new PaperListDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Paper getNewActivity() {
|
||||||
|
return new Paper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PaperDto getNewActivityDto(Paper entity) {
|
||||||
|
return new PaperDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
private PageableItems<Paper> findAllActive(int offset, int count) {
|
private PageableItems<Paper> findAllActive(int offset, int count) {
|
||||||
Page<Paper> activePapersPage = paperRepository.findAllWithoutStatuses(new OffsetablePageRequest(offset, count), COMPLETED, FAILED);
|
Page<Paper> activePapersPage = paperRepository.findAllWithoutStatuses(new OffsetablePageRequest(offset, count), COMPLETED, FAILED);
|
||||||
return new PageableItems<>(activePapersPage.getTotalElements(), sortPapers(activePapersPage.getContent()));
|
return new PageableItems<>(activePapersPage.getTotalElements(), sortPapers(activePapersPage.getContent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Paper create(Paper paper) {
|
|
||||||
Paper newPaper = paperRepository.save(paper);
|
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
|
||||||
eventService.createFromPaper(newPaper);
|
|
||||||
return newPaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paper update(Paper paper) {
|
public Paper update(Paper paper) {
|
||||||
paperRepository.save(paper);
|
paperRepository.save(paper);
|
||||||
paperNotificationService.sendCreateNotification(paper, oldAuthors);
|
paperNotificationService.sendCreateNotification(paper, oldAuthors);
|
||||||
@ -106,14 +109,9 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public PaperDto create(PaperDto paperDto) {
|
|
||||||
return new PaperDto(create(copyFromDto(new Paper(), paperDto)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public PaperDto update(PaperDto paperDto) {
|
public PaperDto update(PaperDto paperDto) {
|
||||||
Paper paper = findPaperById(paperDto.getId());
|
Paper paper = findById(paperDto.getId());
|
||||||
oldStatus = paper.getStatus();
|
oldStatus = paper.getStatus();
|
||||||
oldAuthors = new HashSet<>(paper.getAuthors());
|
oldAuthors = new HashSet<>(paper.getAuthors());
|
||||||
|
|
||||||
@ -128,7 +126,7 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
return new PaperDto(update(copyFromDto(paper, paperDto)));
|
return new PaperDto(update(copyFromDto(paper, paperDto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paper copyFromDto(Paper paper, PaperDto paperDto) {
|
protected Paper copyFromDto(Paper paper, PaperDto paperDto) {
|
||||||
paper.setComment(paperDto.getComment());
|
paper.setComment(paperDto.getComment());
|
||||||
paper.setUrl(paperDto.getUrl());
|
paper.setUrl(paperDto.getUrl());
|
||||||
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
||||||
@ -230,11 +228,11 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto findById(Integer paperId) {
|
public PaperDto findPaperById(Integer paperId) {
|
||||||
return new PaperDto(findPaperById(paperId));
|
return new PaperDto(findById(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Paper findPaperById(Integer paperId) {
|
public Paper findById(Integer paperId) {
|
||||||
return paperRepository.findById(paperId)
|
return paperRepository.findById(paperId)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Paper with id=" + paperId + " not found"));
|
.orElseThrow(() -> new EntityNotFoundException("Paper with id=" + paperId + " not found"));
|
||||||
}
|
}
|
||||||
@ -262,9 +260,4 @@ public class PaperService extends AbstractActivityService<PaperListDto, Paper, P
|
|||||||
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
||||||
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void ping(int paperId) {
|
|
||||||
pingService.addPing(findPaperById(paperId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,7 @@ public class PingService {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
public PingService(PingRepository pingRepository,
|
public PingService(PingRepository pingRepository,
|
||||||
UserService userService,
|
UserService userService) {
|
||||||
PingScheduler pingScheduler) {
|
|
||||||
this.pingRepository = pingRepository;
|
this.pingRepository = pingRepository;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class TaskController implements ActivityController<TaskListDto, TaskDashb
|
|||||||
|
|
||||||
@GetMapping("{task-id}")
|
@GetMapping("{task-id}")
|
||||||
public Response<TaskDto> get(@PathVariable("task-id") Integer taskId) {
|
public Response<TaskDto> get(@PathVariable("task-id") Integer taskId) {
|
||||||
return new Response<>(taskService.findById(taskId));
|
return new Response<>(taskService.findTaskById(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ -57,7 +57,7 @@ public class TaskController implements ActivityController<TaskListDto, TaskDashb
|
|||||||
return new Response<>(taskService.update(paperDto));
|
return new Response<>(taskService.update(paperDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{task-id}")
|
@DeleteMapping("{task-id}")
|
||||||
public Response<Boolean> delete(@PathVariable("task-id") Integer taskId) {
|
public Response<Boolean> delete(@PathVariable("task-id") Integer taskId) {
|
||||||
return new Response<>(taskService.delete(taskId));
|
return new Response<>(taskService.delete(taskId));
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,14 @@ package ru.ulstu.activity.students.repository;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
import ru.ulstu.activity.students.model.Task;
|
import ru.ulstu.activity.students.model.Task;
|
||||||
import ru.ulstu.activity.tags.model.Tag;
|
import ru.ulstu.activity.tags.model.Tag;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
public interface TaskRepository extends JpaRepository<Task, Integer>, ActivityRepository<Task> {
|
||||||
|
|
||||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
||||||
List<Task> filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
List<Task> filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||||
@ -23,5 +24,7 @@ public interface TaskRepository extends JpaRepository<Task, Integer> {
|
|||||||
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
||||||
List<Task> findAllYear(@Param("date") Date date);
|
List<Task> findAllYear(@Param("date") Date date);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Task t WHERE (t.title = :name) AND (:id IS NULL OR t.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.students.model.Task;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskNotificationService extends ActivityNotificationService<Task> {
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
public TaskNotificationService(MailService mailService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Task task) {
|
||||||
|
throw new RuntimeException("not implemented yet");
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.activity.common.service.AbstractActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.activity.ping.service.PingService;
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
@ -41,11 +41,9 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TaskService extends AbstractActivityService<TaskListDto, Task, TaskDto> {
|
public class TaskService extends ActivityService<TaskListDto, Task, TaskDto> {
|
||||||
|
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
|
||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
|
private final TaskNotificationService taskNotificationService;
|
||||||
private final SchedulerRepository schedulerRepository;
|
private final SchedulerRepository schedulerRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
@ -54,12 +52,15 @@ public class TaskService extends AbstractActivityService<TaskListDto, Task, Task
|
|||||||
|
|
||||||
|
|
||||||
public TaskService(TaskRepository taskRepository,
|
public TaskService(TaskRepository taskRepository,
|
||||||
|
TaskNotificationService taskNotificationService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
TagService tagService,
|
TagService tagService,
|
||||||
SchedulerRepository schedulerRepository,
|
SchedulerRepository schedulerRepository,
|
||||||
EventService eventService,
|
EventService eventService,
|
||||||
PingService pingService) {
|
PingService pingService) {
|
||||||
|
super(taskRepository, taskNotificationService, pingService);
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
|
this.taskNotificationService = taskNotificationService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
@ -81,6 +82,16 @@ public class TaskService extends AbstractActivityService<TaskListDto, Task, Task
|
|||||||
return new TaskListDto(entity);
|
return new TaskListDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task getNewActivity() {
|
||||||
|
return new Task();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TaskDto getNewActivityDto(Task entity) {
|
||||||
|
return new TaskDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
public List<TaskDto> filter(TaskFilterDto filterDto) {
|
public List<TaskDto> filter(TaskFilterDto filterDto) {
|
||||||
if (filterDto.getOrder().compareTo("new") == 0) {
|
if (filterDto.getOrder().compareTo("new") == 0) {
|
||||||
return convert(taskRepository.filterNew(
|
return convert(taskRepository.filterNew(
|
||||||
@ -111,7 +122,7 @@ public class TaskService extends AbstractActivityService<TaskListDto, Task, Task
|
|||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task copyFromDto(Task task, TaskDto taskDto) throws IOException {
|
protected Task copyFromDto(Task task, TaskDto taskDto) throws IOException {
|
||||||
task.setTitle(taskDto.getTitle());
|
task.setTitle(taskDto.getTitle());
|
||||||
task.setDescription(taskDto.getDescription());
|
task.setDescription(taskDto.getDescription());
|
||||||
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
||||||
@ -283,11 +294,11 @@ public class TaskService extends AbstractActivityService<TaskListDto, Task, Task
|
|||||||
return findAll(offset, count);
|
return findAll(offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskDto findById(Integer taskId) {
|
public TaskDto findTaskById(Integer taskId) {
|
||||||
return new TaskDto(findTaskById(taskId));
|
return new TaskDto(findById(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task findTaskById(Integer taskId) {
|
public Task findById(Integer taskId) {
|
||||||
return taskRepository.findById(taskId)
|
return taskRepository.findById(taskId)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Paper with id=" + taskId + " not found"));
|
.orElseThrow(() -> new EntityNotFoundException("Paper with id=" + taskId + " not found"));
|
||||||
}
|
}
|
||||||
@ -295,6 +306,6 @@ public class TaskService extends AbstractActivityService<TaskListDto, Task, Task
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int taskId) {
|
public void ping(int taskId) {
|
||||||
pingService.addPing(findTaskById(taskId));
|
pingService.addPing(findById(taskId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user