#98 changelog edited
This commit is contained in:
commit
4bb4fd6bca
@ -126,6 +126,6 @@ dependencies {
|
|||||||
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
||||||
|
|
||||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
||||||
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'
|
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'
|
||||||
|
|
||||||
}
|
}
|
@ -18,6 +18,6 @@ fi
|
|||||||
|
|
||||||
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
||||||
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
||||||
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 >> /home/user/logfile_$ARTIFACT_NAME" &
|
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 --ng-tracker.dev-mode=false >> /home/user/logfile_$ARTIFACT_NAME" &
|
||||||
sleep 10
|
sleep 10
|
||||||
echo "is deployed"
|
echo "is deployed"
|
@ -42,12 +42,12 @@ public class Conference extends BaseEntity {
|
|||||||
@Column(name = "begin_date")
|
@Column(name = "begin_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date beginDate;
|
private Date beginDate = new Date();
|
||||||
|
|
||||||
@Column(name = "end_date")
|
@Column(name = "end_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate;
|
private Date endDate = new Date();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "conference_id", unique = true)
|
@JoinColumn(name = "conference_id", unique = true)
|
||||||
|
@ -14,6 +14,7 @@ import javax.validation.constraints.Size;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@ -219,4 +220,33 @@ public class ConferenceDto extends NameContainer {
|
|||||||
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ConferenceDto that = (ConferenceDto) o;
|
||||||
|
return ping == that.ping &&
|
||||||
|
disabledTakePart == that.disabledTakePart &&
|
||||||
|
Objects.equals(id, that.id) &&
|
||||||
|
Objects.equals(title, that.title) &&
|
||||||
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(url, that.url) &&
|
||||||
|
Objects.equals(deadlines, that.deadlines) &&
|
||||||
|
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
||||||
|
Objects.equals(userIds, that.userIds) &&
|
||||||
|
Objects.equals(paperIds, that.paperIds) &&
|
||||||
|
Objects.equals(papers, that.papers) &&
|
||||||
|
Objects.equals(notSelectedPapers, that.notSelectedPapers) &&
|
||||||
|
Objects.equals(users, that.users);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds,
|
||||||
|
userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import ru.ulstu.deadline.service.DeadlineService;
|
|||||||
import ru.ulstu.name.BaseService;
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -64,7 +65,7 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
public ConferenceDto getExistConferenceById(Integer id) {
|
||||||
ConferenceDto conferenceDto = findOneDto(id);
|
ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.findOne(id));
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
||||||
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
@ -72,7 +73,7 @@ public class ConferenceService extends BaseService {
|
|||||||
|
|
||||||
public ConferenceDto getNewConference() {
|
public ConferenceDto getNewConference() {
|
||||||
ConferenceDto conferenceDto = new ConferenceDto();
|
ConferenceDto conferenceDto = new ConferenceDto();
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<Integer>()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<>()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,14 +88,11 @@ public class ConferenceService extends BaseService {
|
|||||||
return conferences;
|
return conferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto findOneDto(Integer id) {
|
|
||||||
return new ConferenceDto(conferenceRepository.findOne(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
|
public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
conferenceDto.setName(conferenceDto.getTitle());
|
conferenceDto.setName(conferenceDto.getTitle());
|
||||||
filterEmptyDeadlines(conferenceDto);
|
filterEmptyDeadlines(conferenceDto);
|
||||||
checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
||||||
|
checkEmptyFieldsOfDates(conferenceDto, errors);
|
||||||
checkUniqueName(conferenceDto,
|
checkUniqueName(conferenceDto,
|
||||||
errors,
|
errors,
|
||||||
conferenceDto.getId(),
|
conferenceDto.getId(),
|
||||||
@ -114,16 +112,16 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(ConferenceDto conferenceDto) throws IOException {
|
public Conference create(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
||||||
newConference = conferenceRepository.save(newConference);
|
newConference = conferenceRepository.save(newConference);
|
||||||
conferenceNotificationService.sendCreateNotification(newConference);
|
conferenceNotificationService.sendCreateNotification(newConference);
|
||||||
eventService.createFromConference(newConference);
|
eventService.createFromConference(newConference);
|
||||||
return newConference.getId();
|
return newConference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(ConferenceDto conferenceDto) throws IOException {
|
public Conference update(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
||||||
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
|
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
|
||||||
.map(this::copyDeadline)
|
.map(this::copyDeadline)
|
||||||
@ -137,50 +135,56 @@ public class ConferenceService extends BaseService {
|
|||||||
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
||||||
}
|
}
|
||||||
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
return conference.getId();
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer conferenceId) {
|
public boolean delete(Integer conferenceId) {
|
||||||
if (conferenceRepository.exists(conferenceId)) {
|
if (conferenceRepository.exists(conferenceId)) {
|
||||||
eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId));
|
eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId));
|
||||||
conferenceRepository.delete(conferenceId);
|
conferenceRepository.delete(conferenceId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeadline(ConferenceDto conferenceDto) {
|
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
conferenceDto.getDeadlines().add(new Deadline());
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
||||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
||||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPaper(ConferenceDto conferenceDto) {
|
public ConferenceDto addPaper(ConferenceDto conferenceDto) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
||||||
paper.setStatus(Paper.PaperStatus.DRAFT);
|
paper.setStatus(Paper.PaperStatus.DRAFT);
|
||||||
|
|
||||||
conferenceDto.getPapers().add(paper);
|
conferenceDto.getPapers().add(paper);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
||||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
||||||
if (removedPaper.getId() != null) {
|
if (removedPaper.getId() != null) {
|
||||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||||
}
|
}
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException {
|
||||||
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
||||||
conferenceDto.setDisabledTakePart(true);
|
conferenceDto.setDisabledTakePart(true);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
private List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllNotSelect(paperIds);
|
return paperService.findAllNotSelect(paperIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +218,7 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
private boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
||||||
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +233,7 @@ public class ConferenceService extends BaseService {
|
|||||||
return convert(findAllActive(), ConferenceDto::new);
|
return convert(findAllActive(), ConferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Conference> findAllActive() {
|
private List<Conference> findAllActive() {
|
||||||
return conferenceRepository.findAllActive(new Date());
|
return conferenceRepository.findAllActive(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,12 +242,13 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(ConferenceDto conferenceDto) throws IOException {
|
public Ping ping(ConferenceDto conferenceDto) throws IOException {
|
||||||
pingService.addPing(findOne(conferenceDto.getId()));
|
Ping ping = pingService.addPing(findOne(conferenceDto.getId()));
|
||||||
conferenceRepository.updatePingConference(conferenceDto.getId());
|
conferenceRepository.updatePingConference(conferenceDto.getId());
|
||||||
|
return ping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conference findOne(Integer conferenceId) {
|
private Conference findOne(Integer conferenceId) {
|
||||||
return conferenceRepository.findOne(conferenceId);
|
return conferenceRepository.findOne(conferenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +274,7 @@ public class ConferenceService extends BaseService {
|
|||||||
modelMap.addAttribute("offshoreSales", offshoreSales);
|
modelMap.addAttribute("offshoreSales", offshoreSales);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
private void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
||||||
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
||||||
conferenceNotificationService.updateDeadlineNotification(conference);
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
return;
|
return;
|
||||||
@ -283,9 +288,8 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Deadline copyDeadline(Deadline oldDeadline) {
|
private Deadline copyDeadline(Deadline oldDeadline) {
|
||||||
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription(),
|
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
||||||
oldDeadline.getExecutor(), oldDeadline.getDone());
|
|
||||||
newDeadline.setId(oldDeadline.getId());
|
newDeadline.setId(oldDeadline.getId());
|
||||||
return newDeadline;
|
return newDeadline;
|
||||||
}
|
}
|
||||||
@ -298,6 +302,12 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkEmptyFieldsOfDates(ConferenceDto conferenceDto, Errors errors) {
|
||||||
|
if (conferenceDto.getBeginDate() == null || conferenceDto.getEndDate() == null) {
|
||||||
|
errors.rejectValue("beginDate", "errorCode", "Даты должны быть заполнены");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
public void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
||||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
||||||
|
@ -21,6 +21,8 @@ public class ApplicationProperties {
|
|||||||
|
|
||||||
private boolean checkRun;
|
private boolean checkRun;
|
||||||
|
|
||||||
|
private String debugEmail;
|
||||||
|
|
||||||
public boolean isUseHttps() {
|
public boolean isUseHttps() {
|
||||||
return useHttps;
|
return useHttps;
|
||||||
}
|
}
|
||||||
@ -60,4 +62,12 @@ public class ApplicationProperties {
|
|||||||
public void setCheckRun(boolean checkRun) {
|
public void setCheckRun(boolean checkRun) {
|
||||||
this.checkRun = checkRun;
|
this.checkRun = checkRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDebugEmail() {
|
||||||
|
return debugEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebugEmail(String debugEmail) {
|
||||||
|
this.debugEmail = debugEmail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String MAIL_ACTIVATE = "Account activation";
|
public static final String MAIL_ACTIVATE = "Account activation";
|
||||||
public static final String MAIL_RESET = "Password reset";
|
public static final String MAIL_RESET = "Password reset";
|
||||||
|
public static final String MAIL_INVITE = "Account registration";
|
||||||
|
public static final String MAIL_CHANGE_PASSWORD = "Password has been changed";
|
||||||
|
|
||||||
public static final int MIN_PASSWORD_LENGTH = 6;
|
public static final int MIN_PASSWORD_LENGTH = 6;
|
||||||
|
public static final int MAX_PASSWORD_LENGTH = 32;
|
||||||
|
|
||||||
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
||||||
|
|
||||||
@ -17,4 +21,5 @@ public class Constants {
|
|||||||
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
||||||
public static final String PASSWORD_RESET_PAGE = "/reset";
|
public static final String PASSWORD_RESET_PAGE = "/reset";
|
||||||
|
|
||||||
|
public static final int RESET_KEY_LENGTH = 6;
|
||||||
}
|
}
|
@ -104,7 +104,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers("/css/**")
|
.antMatchers("/css/**")
|
||||||
.antMatchers("/js/**")
|
.antMatchers("/js/**")
|
||||||
.antMatchers("/templates/**")
|
.antMatchers("/templates/**")
|
||||||
.antMatchers("/webjars/**");
|
.antMatchers("/webjars/**")
|
||||||
|
.antMatchers("/img/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -20,6 +20,7 @@ import ru.ulstu.user.error.UserNotActivatedException;
|
|||||||
import ru.ulstu.user.error.UserNotFoundException;
|
import ru.ulstu.user.error.UserNotFoundException;
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -34,11 +35,6 @@ public class AdviceController {
|
|||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("currentUser")
|
|
||||||
public String getCurrentUser() {
|
|
||||||
return userService.getCurrentUser().getUserAbbreviate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModelAttribute("flashMessage")
|
@ModelAttribute("flashMessage")
|
||||||
public String getFlashMessage() {
|
public String getFlashMessage() {
|
||||||
return null;
|
return null;
|
||||||
@ -112,4 +108,9 @@ public class AdviceController {
|
|||||||
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
||||||
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(UserSendingMailException.class)
|
||||||
|
public ResponseExtended<String> handleUserSendingMailException(Throwable e) {
|
||||||
|
return handleException(ErrorConstants.USER_SENDING_MAIL_EXCEPTION, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,15 @@ public enum ErrorConstants {
|
|||||||
VALIDATION_ERROR(2, "Validation error"),
|
VALIDATION_ERROR(2, "Validation error"),
|
||||||
USER_ID_EXISTS(100, "New user can't have id"),
|
USER_ID_EXISTS(100, "New user can't have id"),
|
||||||
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
||||||
USER_EMAIL_EXISTS(102, "User with same email already exists"),
|
USER_EMAIL_EXISTS(102, "Пользователь с таким почтовым ящиком уже существует"),
|
||||||
USER_LOGIN_EXISTS(103, "User with same login already exists"),
|
USER_LOGIN_EXISTS(103, "Пользователь с таким логином уже существует"),
|
||||||
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "User passwords is not valid or not match"),
|
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "Пароли введены неверно"),
|
||||||
USER_NOT_FOUND(105, "User is not found"),
|
USER_NOT_FOUND(105, "Аккаунт не найден"),
|
||||||
USER_NOT_ACTIVATED(106, "User is not activated"),
|
USER_NOT_ACTIVATED(106, "User is not activated"),
|
||||||
USER_RESET_ERROR(107, "Invalid reset key"),
|
USER_RESET_ERROR(107, "Некорректный ключ подтверждения"),
|
||||||
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
||||||
FILE_UPLOAD_ERROR(110, "File upload error");
|
FILE_UPLOAD_ERROR(110, "File upload error"),
|
||||||
|
USER_SENDING_MAIL_EXCEPTION(111, "Во время отправки приглашения пользователю произошла ошибка");
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
private String message;
|
private String message;
|
||||||
|
@ -11,6 +11,6 @@ public class Response<D> extends ResponseEntity<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response(ErrorConstants error) {
|
public Response(ErrorConstants error) {
|
||||||
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.OK);
|
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ import ru.ulstu.core.model.ErrorConstants;
|
|||||||
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
||||||
|
|
||||||
public ResponseExtended(ErrorConstants error, E errorData) {
|
public ResponseExtended(ErrorConstants error, E errorData) {
|
||||||
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.OK);
|
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,11 @@ public class Deadline extends BaseEntity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Deadline deadline = (Deadline) o;
|
Deadline deadline = (Deadline) o;
|
||||||
|
if (getId() == null && deadline.getId() == null &&
|
||||||
|
description == null && deadline.description == null &&
|
||||||
|
date == null && deadline.date == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return getId().equals(deadline.getId()) &&
|
return getId().equals(deadline.getId()) &&
|
||||||
description.equals(deadline.description) &&
|
description.equals(deadline.description) &&
|
||||||
date.equals(deadline.date) &&
|
date.equals(deadline.date) &&
|
||||||
|
@ -2,8 +2,15 @@ package ru.ulstu.deadline.repository;
|
|||||||
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
value = "SELECT date FROM Deadline d WHERE (d.grant_id = ?1) AND (d.date = ?2)",
|
||||||
|
nativeQuery = true)
|
||||||
|
Date findByGrantIdAndDate(Integer grantId, Date date);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.repository.DeadlineRepository;
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -50,4 +51,8 @@ public class DeadlineService {
|
|||||||
public void remove(Integer deadlineId) {
|
public void remove(Integer deadlineId) {
|
||||||
deadlineRepository.delete(deadlineId);
|
deadlineRepository.delete(deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
|
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,7 @@ import springfox.documentation.annotations.ApiIgnore;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
||||||
@ -45,7 +43,7 @@ public class GrantController {
|
|||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("grants", grantService.findAllDto());
|
modelMap.put("grants", grantService.findAllActiveDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/grant")
|
@GetMapping("/grant")
|
||||||
@ -62,17 +60,9 @@ public class GrantController {
|
|||||||
@PostMapping(value = "/grant", params = "save")
|
@PostMapping(value = "/grant", params = "save")
|
||||||
public String save(@Valid GrantDto grantDto, Errors errors)
|
public String save(@Valid GrantDto grantDto, Errors errors)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
filterEmptyDeadlines(grantDto);
|
if (!grantService.save(grantDto, errors)) {
|
||||||
if (grantDto.getDeadlines().isEmpty()) {
|
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
|
||||||
}
|
|
||||||
if (grantDto.getLeaderId().equals(-1)) {
|
|
||||||
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
|
||||||
}
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
grantService.save(grantDto);
|
|
||||||
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +79,7 @@ public class GrantController {
|
|||||||
|
|
||||||
@PostMapping(value = "/grant", params = "addDeadline")
|
@PostMapping(value = "/grant", params = "addDeadline")
|
||||||
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
||||||
filterEmptyDeadlines(grantDto);
|
grantService.filterEmptyDeadlines(grantDto);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
@ -133,10 +123,4 @@ public class GrantController {
|
|||||||
public List<PaperDto> getAllPapers() {
|
public List<PaperDto> getAllPapers() {
|
||||||
return grantService.getAllUncompletedPapers();
|
return grantService.getAllUncompletedPapers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(GrantDto grantDto) {
|
|
||||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
COMPLETED("Завершен"),
|
COMPLETED("Завершен"),
|
||||||
FAILED("Провалены сроки"),
|
FAILED("Провалены сроки"),
|
||||||
LOADED_FROM_KIAS("Загружен автоматически");
|
LOADED_FROM_KIAS("Загружен автоматически"),
|
||||||
|
SKIPPED("Не интересует");
|
||||||
|
|
||||||
private String statusName;
|
private String statusName;
|
||||||
|
|
||||||
@ -62,14 +63,14 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private GrantStatus status = GrantStatus.APPLICATION;
|
private GrantStatus status = GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "grant_id")
|
@JoinColumn(name = "grant_id")
|
||||||
@OrderBy("date")
|
@OrderBy("date")
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "grant_id", unique = true)
|
@JoinColumn(name = "grant_id", unique = true)
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<FileData> files = new ArrayList<>();
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
@ -6,18 +6,20 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class GrantDto {
|
public class GrantDto extends NameContainer {
|
||||||
private final static int MAX_AUTHORS_LENGTH = 60;
|
private final static int MAX_AUTHORS_LENGTH = 60;
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -95,6 +97,12 @@ public class GrantDto {
|
|||||||
this.papers = convert(grant.getPapers(), PaperDto::new);
|
this.papers = convert(grant.getPapers(), PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GrantDto(String grantTitle, Date deadLineDate) {
|
||||||
|
this.title = grantTitle;
|
||||||
|
deadlines.add(new Deadline(deadLineDate, "Окончание приёма заявок"));
|
||||||
|
status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
50
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
50
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package ru.ulstu.grant.page;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class KiasPage {
|
||||||
|
private final static String KIAS_GRANT_DATE_FORMAT = "dd.MM.yyyy HH:mm";
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
public KiasPage(WebDriver webDriver) {
|
||||||
|
this.driver = webDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean goToNextPage() {
|
||||||
|
try {
|
||||||
|
if (driver.findElements(By.id("js-ctrlNext")).size() > 0) {
|
||||||
|
driver.findElement(By.id("js-ctrlNext")).click();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getPageOfGrants() {
|
||||||
|
WebElement listContest = driver.findElement(By.tagName("tBody"));
|
||||||
|
List<WebElement> grants = listContest.findElements(By.cssSelector("tr.tr"));
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantTitle(WebElement grant) {
|
||||||
|
return grant.findElement(By.cssSelector("td.tertiary")).findElement(By.tagName("a")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date parseDeadLineDate(WebElement grantElement) throws ParseException {
|
||||||
|
String deadlineDate = getFirstDeadline(grantElement); //10.06.2019 23:59
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(KIAS_GRANT_DATE_FORMAT);
|
||||||
|
return formatter.parse(deadlineDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFirstDeadline(WebElement grantElement) {
|
||||||
|
return grantElement.findElement(By.xpath("./td[5]")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,23 @@
|
|||||||
package ru.ulstu.grant.repository;
|
package ru.ulstu.grant.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.repository.query.Param;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.name.BaseRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface GrantRepository extends JpaRepository<Grant, Integer> {
|
public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepository {
|
||||||
|
|
||||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||||
|
|
||||||
|
Grant findByTitle(String title);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
||||||
|
List<Grant> findAllActive();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantScheduler {
|
public class GrantScheduler {
|
||||||
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
@ -27,4 +30,15 @@ public class GrantScheduler {
|
|||||||
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
||||||
|
public void loadGrantsFromKias() {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias started");
|
||||||
|
try {
|
||||||
|
grantService.createFromKias();
|
||||||
|
} catch (ParseException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias finished");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
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 ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
@ -10,6 +13,7 @@ import ru.ulstu.file.service.FileService;
|
|||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
@ -21,12 +25,14 @@ import ru.ulstu.user.model.User;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
@ -34,8 +40,8 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|||||||
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantService {
|
public class GrantService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 50;
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
@ -45,6 +51,7 @@ public class GrantService {
|
|||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final GrantNotificationService grantNotificationService;
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final KiasService kiasService;
|
||||||
|
|
||||||
public GrantService(GrantRepository grantRepository,
|
public GrantService(GrantRepository grantRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
@ -53,8 +60,11 @@ public class GrantService {
|
|||||||
UserService userService,
|
UserService userService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
EventService eventService,
|
EventService eventService,
|
||||||
GrantNotificationService grantNotificationService) {
|
GrantNotificationService grantNotificationService,
|
||||||
|
KiasService kiasService) {
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
|
this.kiasService = kiasService;
|
||||||
|
this.baseRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
@ -69,9 +79,7 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<GrantDto> findAllDto() {
|
public List<GrantDto> findAllDto() {
|
||||||
List<GrantDto> grants = convert(findAll(), GrantDto::new);
|
return convert(findAll(), GrantDto::new);
|
||||||
grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return grants;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto findOneDto(Integer id) {
|
public GrantDto findOneDto(Integer id) {
|
||||||
@ -176,12 +184,58 @@ public class GrantService {
|
|||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(GrantDto grantDto) throws IOException {
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
||||||
|
grantDto.setName(grantDto.getTitle());
|
||||||
|
filterEmptyDeadlines(grantDto);
|
||||||
|
checkEmptyDeadlines(grantDto, errors);
|
||||||
|
checkEmptyLeader(grantDto, errors);
|
||||||
|
checkUniqueName(grantDto, errors, grantDto.getId(), "title", "Грант с таким именем уже существует");
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (isEmpty(grantDto.getId())) {
|
if (isEmpty(grantDto.getId())) {
|
||||||
create(grantDto);
|
create(grantDto);
|
||||||
} else {
|
} else {
|
||||||
update(grantDto);
|
update(grantDto);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveFromKias(GrantDto grantDto) throws IOException {
|
||||||
|
grantDto.setName(grantDto.getTitle());
|
||||||
|
String title = checkUniqueName(grantDto, grantDto.getId()); //проверка уникальности имени
|
||||||
|
if (title != null) {
|
||||||
|
Grant grantFromDB = grantRepository.findByTitle(title); //грант с таким же названием из бд
|
||||||
|
if (checkSameDeadline(grantDto, grantFromDB.getId())) { //если дедайны тоже совпадают
|
||||||
|
return false;
|
||||||
|
} else { //иначе грант уже был в системе, но в другом году, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else { //иначе такого гранта ещё нет, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyLeader(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getLeaderId().equals(-1)) {
|
||||||
|
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyDeadlines(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getDeadlines().isEmpty()) {
|
||||||
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSameDeadline(GrantDto grantDto, Integer id) {
|
||||||
|
Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас
|
||||||
|
if (deadlineService.findByGrantIdAndDate(id, date).compareTo(date) == 0) { //если есть такая строка с датой
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getGrantAuthors(GrantDto grantDto) {
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
||||||
@ -216,11 +270,7 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> getAllUncompletedPapers() {
|
public List<PaperDto> getAllUncompletedPapers() {
|
||||||
List<PaperDto> papers = paperService.findAllNotCompleted();
|
return paperService.findAllNotCompleted();
|
||||||
papers.stream()
|
|
||||||
.forEach(paper ->
|
|
||||||
paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return papers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachPaper(GrantDto grantDto) {
|
public void attachPaper(GrantDto grantDto) {
|
||||||
@ -261,4 +311,29 @@ public class GrantService {
|
|||||||
.filter(author -> Collections.frequency(authors, author) > 3)
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void filterEmptyDeadlines(GrantDto grantDto) {
|
||||||
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
||||||
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void createFromKias() throws IOException, ParseException {
|
||||||
|
for (GrantDto grantDto : kiasService.getNewGrantsDto()) {
|
||||||
|
if (saveFromKias(grantDto)) {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias new grant was loaded");
|
||||||
|
} else {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias grant wasn't loaded, cause it's already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> findAllActiveDto() {
|
||||||
|
return convert(findAllActive(), GrantDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Grant> findAllActive() {
|
||||||
|
return grantRepository.findAllActive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
92
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
92
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.grant.page.KiasPage;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class KiasService {
|
||||||
|
private final static String BASE_URL = "https://www.rfbr.ru/rffi/ru/contest_search?CONTEST_STATUS_ID=%s&CONTEST_TYPE=%s&CONTEST_YEAR=%s";
|
||||||
|
private final static String CONTEST_STATUS_ID = "1";
|
||||||
|
private final static String CONTEST_TYPE = "-1";
|
||||||
|
|
||||||
|
private final static String DRIVER_LOCATION = "drivers/%s";
|
||||||
|
private final static String WINDOWS_DRIVER = "chromedriver.exe";
|
||||||
|
private final static String LINUX_DRIVER = "chromedriver";
|
||||||
|
private final static String DRIVER_TYPE = "webdriver.chrome.driver";
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public KiasService(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getNewGrantsDto() throws ParseException {
|
||||||
|
WebDriver webDriver = getDriver();
|
||||||
|
Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId();
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
for (Integer year : generateGrantYears()) {
|
||||||
|
webDriver.get(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year));
|
||||||
|
grants.addAll(getKiasGrants(webDriver));
|
||||||
|
}
|
||||||
|
grants.forEach(grantDto -> grantDto.setLeaderId(leaderId));
|
||||||
|
webDriver.quit();
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getKiasGrants(WebDriver webDriver) throws ParseException {
|
||||||
|
List<GrantDto> newGrants = new ArrayList<>();
|
||||||
|
KiasPage kiasPage = new KiasPage(webDriver);
|
||||||
|
do {
|
||||||
|
newGrants.addAll(getGrantsFromPage(kiasPage));
|
||||||
|
} while (kiasPage.goToNextPage()); //проверка существования следующей страницы с грантами
|
||||||
|
return newGrants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GrantDto> getGrantsFromPage(KiasPage kiasPage) throws ParseException {
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
for (WebElement grantElement : kiasPage.getPageOfGrants()) {
|
||||||
|
GrantDto grantDto = new GrantDto(
|
||||||
|
kiasPage.getGrantTitle(grantElement),
|
||||||
|
kiasPage.parseDeadLineDate(grantElement));
|
||||||
|
grants.add(grantDto);
|
||||||
|
}
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> generateGrantYears() {
|
||||||
|
return Arrays.asList(Calendar.getInstance().get(Calendar.YEAR),
|
||||||
|
Calendar.getInstance().get(Calendar.YEAR) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebDriver getDriver() {
|
||||||
|
System.setProperty(DRIVER_TYPE, getDriverExecutablePath());
|
||||||
|
final ChromeOptions chromeOptions = new ChromeOptions();
|
||||||
|
chromeOptions.addArguments("--headless");
|
||||||
|
return new ChromeDriver(chromeOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDriverExecutablePath() {
|
||||||
|
return KiasService.class.getClassLoader().getResource(
|
||||||
|
String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDriverExecutable(boolean isWindows) {
|
||||||
|
return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWindows() {
|
||||||
|
return System.getProperty("os.name").toLowerCase().contains("windows");
|
||||||
|
}
|
||||||
|
}
|
@ -13,4 +13,11 @@ public abstract class BaseService {
|
|||||||
errors.rejectValue(checkField, "errorCode", errorMessage);
|
errors.rejectValue(checkField, "errorCode", errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String checkUniqueName(NameContainer nameContainer, Integer id) {
|
||||||
|
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
||||||
|
return baseRepository.findByNameAndNotId(nameContainer.getName(), id);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.service.LatexService;
|
import ru.ulstu.paper.service.LatexService;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -105,6 +107,15 @@ public class PaperController {
|
|||||||
return "/papers/paper";
|
return "/papers/paper";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/paper", params = "addReference")
|
||||||
|
public String addReference(@Valid PaperDto paperDto, Errors errors) {
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return "/papers/paper";
|
||||||
|
}
|
||||||
|
paperDto.getReferences().add(new ReferenceDto());
|
||||||
|
return "/papers/paper";
|
||||||
|
}
|
||||||
|
|
||||||
@ModelAttribute("allStatuses")
|
@ModelAttribute("allStatuses")
|
||||||
public List<Paper.PaperStatus> getPaperStatuses() {
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
||||||
return paperService.getPaperStatuses();
|
return paperService.getPaperStatuses();
|
||||||
@ -129,6 +140,16 @@ public class PaperController {
|
|||||||
return years;
|
return years;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allFormatStandards")
|
||||||
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
||||||
|
return paperService.getFormatStandards();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allReferenceTypes")
|
||||||
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
||||||
|
return paperService.getReferenceTypes();
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/generatePdf")
|
@PostMapping("/generatePdf")
|
||||||
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
|
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
@ -137,6 +158,16 @@ public class PaperController {
|
|||||||
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
|
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getFormattedReferences")
|
||||||
|
public ResponseEntity<String> getFormattedReferences(PaperDto paperDto) {
|
||||||
|
return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("autocompleteData")
|
||||||
|
public AutoCompleteData getAutocompleteData() {
|
||||||
|
return paperService.getAutoCompleteData();
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(PaperDto paperDto) {
|
private void filterEmptyDeadlines(PaperDto paperDto) {
|
||||||
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AutoCompleteData {
|
||||||
|
private List<String> authors = new ArrayList<>();
|
||||||
|
private List<String> publicationTitles = new ArrayList<>();
|
||||||
|
private List<String> publishers = new ArrayList<>();
|
||||||
|
private List<String> journalOrCollectionTitles = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<String> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(List<String> authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublicationTitles() {
|
||||||
|
return publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitles(List<String> publicationTitles) {
|
||||||
|
this.publicationTitles = publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublishers() {
|
||||||
|
return publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishers(List<String> publishers) {
|
||||||
|
this.publishers = publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getJournalOrCollectionTitles() {
|
||||||
|
return journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitles(List<String> journalOrCollectionTitles) {
|
||||||
|
this.journalOrCollectionTitles = journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,7 @@ import java.util.Comparator;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -122,6 +123,11 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
@ManyToMany(mappedBy = "papers")
|
@ManyToMany(mappedBy = "papers")
|
||||||
private List<Grant> grants;
|
private List<Grant> grants;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "paper_id", unique = true)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<Reference> references = new ArrayList<>();
|
||||||
|
|
||||||
public PaperStatus getStatus() {
|
public PaperStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -247,6 +253,14 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
return getAuthors();
|
return getAuthors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Reference> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<Reference> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Deadline> getNextDeadline() {
|
public Optional<Deadline> getNextDeadline() {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
@ -264,4 +278,36 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
.findAny()
|
.findAny()
|
||||||
.isPresent();
|
.isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!super.equals(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Paper paper = (Paper) o;
|
||||||
|
return Objects.equals(title, paper.title) &&
|
||||||
|
status == paper.status &&
|
||||||
|
type == paper.type &&
|
||||||
|
Objects.equals(deadlines, paper.deadlines) &&
|
||||||
|
Objects.equals(comment, paper.comment) &&
|
||||||
|
Objects.equals(url, paper.url) &&
|
||||||
|
Objects.equals(locked, paper.locked) &&
|
||||||
|
Objects.equals(events, paper.events) &&
|
||||||
|
Objects.equals(files, paper.files) &&
|
||||||
|
Objects.equals(authors, paper.authors) &&
|
||||||
|
Objects.equals(latexText, paper.latexText) &&
|
||||||
|
Objects.equals(conferences, paper.conferences) &&
|
||||||
|
Objects.equals(grants, paper.grants);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ public class PaperDto {
|
|||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
private Integer filterAuthorId;
|
private Integer filterAuthorId;
|
||||||
private String latexText;
|
private String latexText;
|
||||||
|
private List<ReferenceDto> references = new ArrayList<>();
|
||||||
|
private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST;
|
||||||
|
|
||||||
public PaperDto() {
|
public PaperDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
@ -57,7 +59,9 @@ public class PaperDto {
|
|||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors) {
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
|
@JsonProperty("references") List<ReferenceDto> references,
|
||||||
|
@JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -71,6 +75,8 @@ public class PaperDto {
|
|||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
|
this.references = references;
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto(Paper paper) {
|
public PaperDto(Paper paper) {
|
||||||
@ -88,6 +94,7 @@ public class PaperDto {
|
|||||||
this.files = convert(paper.getFiles(), FileDataDto::new);
|
this.files = convert(paper.getFiles(), FileDataDto::new);
|
||||||
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||||
|
this.references = convert(paper.getReferences(), ReferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -216,4 +223,20 @@ public class PaperDto {
|
|||||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
public void setFilterAuthorId(Integer filterAuthorId) {
|
||||||
this.filterAuthorId = filterAuthorId;
|
this.filterAuthorId = filterAuthorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<ReferenceDto> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.FormatStandard getFormatStandard() {
|
||||||
|
return formatStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormatStandard(ReferenceDto.FormatStandard formatStandard) {
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
88
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
88
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Reference extends BaseEntity {
|
||||||
|
|
||||||
|
private String authors;
|
||||||
|
|
||||||
|
@Column(name = "publication_title")
|
||||||
|
private String publicationTitle;
|
||||||
|
|
||||||
|
@Column(name = "publication_year")
|
||||||
|
private Integer publicationYear;
|
||||||
|
|
||||||
|
private String publisher;
|
||||||
|
|
||||||
|
private String pages;
|
||||||
|
|
||||||
|
@Column(name = "journal_or_collection_title")
|
||||||
|
private String journalOrCollectionTitle;
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
@Column(name = "reference_type")
|
||||||
|
private ReferenceDto.ReferenceType referenceType = ReferenceDto.ReferenceType.ARTICLE;
|
||||||
|
|
||||||
|
public String getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(String authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicationTitle() {
|
||||||
|
return publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitle(String publicationTitle) {
|
||||||
|
this.publicationTitle = publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPublicationYear() {
|
||||||
|
return publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationYear(Integer publicationYear) {
|
||||||
|
this.publicationYear = publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher() {
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher(String publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPages(String pages) {
|
||||||
|
this.pages = pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJournalOrCollectionTitle() {
|
||||||
|
return journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitle(String journalOrCollectionTitle) {
|
||||||
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.ReferenceType getReferenceType() {
|
||||||
|
return referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceType(ReferenceDto.ReferenceType referenceType) {
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,6 +34,7 @@ public class ReferenceDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
private String authors;
|
private String authors;
|
||||||
private String publicationTitle;
|
private String publicationTitle;
|
||||||
private Integer publicationYear;
|
private Integer publicationYear;
|
||||||
@ -42,9 +43,11 @@ public class ReferenceDto {
|
|||||||
private String journalOrCollectionTitle;
|
private String journalOrCollectionTitle;
|
||||||
private ReferenceType referenceType;
|
private ReferenceType referenceType;
|
||||||
private FormatStandard formatStandard;
|
private FormatStandard formatStandard;
|
||||||
|
private boolean deleted;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ReferenceDto(
|
public ReferenceDto(
|
||||||
|
@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("authors") String authors,
|
@JsonProperty("authors") String authors,
|
||||||
@JsonProperty("publicationTitle") String publicationTitle,
|
@JsonProperty("publicationTitle") String publicationTitle,
|
||||||
@JsonProperty("publicationYear") Integer publicationYear,
|
@JsonProperty("publicationYear") Integer publicationYear,
|
||||||
@ -52,7 +55,9 @@ public class ReferenceDto {
|
|||||||
@JsonProperty("pages") String pages,
|
@JsonProperty("pages") String pages,
|
||||||
@JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle,
|
@JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle,
|
||||||
@JsonProperty("referenceType") ReferenceType referenceType,
|
@JsonProperty("referenceType") ReferenceType referenceType,
|
||||||
@JsonProperty("formatStandard") FormatStandard formatStandard) {
|
@JsonProperty("formatStandard") FormatStandard formatStandard,
|
||||||
|
@JsonProperty("isDeleted") boolean deleted) {
|
||||||
|
this.id = id;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.publicationTitle = publicationTitle;
|
this.publicationTitle = publicationTitle;
|
||||||
this.publicationYear = publicationYear;
|
this.publicationYear = publicationYear;
|
||||||
@ -61,6 +66,22 @@ public class ReferenceDto {
|
|||||||
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
this.referenceType = referenceType;
|
this.referenceType = referenceType;
|
||||||
this.formatStandard = formatStandard;
|
this.formatStandard = formatStandard;
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto(Reference reference) {
|
||||||
|
this.id = reference.getId();
|
||||||
|
this.authors = reference.getAuthors();
|
||||||
|
this.publicationTitle = reference.getPublicationTitle();
|
||||||
|
this.publicationYear = reference.getPublicationYear();
|
||||||
|
this.publisher = reference.getPublisher();
|
||||||
|
this.pages = reference.getPages();
|
||||||
|
this.journalOrCollectionTitle = reference.getJournalOrCollectionTitle();
|
||||||
|
this.referenceType = reference.getReferenceType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto() {
|
||||||
|
referenceType = ReferenceType.ARTICLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthors() {
|
public String getAuthors() {
|
||||||
@ -126,4 +147,20 @@ public class ReferenceDto {
|
|||||||
public void setFormatStandard(FormatStandard formatStandard) {
|
public void setFormatStandard(FormatStandard formatStandard) {
|
||||||
this.formatStandard = formatStandard;
|
this.formatStandard = formatStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.paper.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ReferenceRepository extends JpaRepository<Reference, Integer> {
|
||||||
|
void deleteById(Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.authors FROM Reference r")
|
||||||
|
List<String> findDistinctAuthors();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publicationTitle FROM Reference r")
|
||||||
|
List<String> findDistinctPublicationTitles();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publisher FROM Reference r")
|
||||||
|
List<String> findDistinctPublishers();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''")
|
||||||
|
List<String> findDistinctJournalOrCollectionTitles();
|
||||||
|
}
|
@ -7,11 +7,14 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
import ru.ulstu.paper.model.ReferenceDto;
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
|
import ru.ulstu.paper.repository.ReferenceRepository;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
@ -39,6 +42,7 @@ import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE;
|
|||||||
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class PaperService {
|
public class PaperService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
||||||
@ -49,14 +53,17 @@ public class PaperService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final ReferenceRepository referenceRepository;
|
||||||
|
|
||||||
public PaperService(PaperRepository paperRepository,
|
public PaperService(PaperRepository paperRepository,
|
||||||
|
ReferenceRepository referenceRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
PaperNotificationService paperNotificationService,
|
PaperNotificationService paperNotificationService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
EventService eventService) {
|
EventService eventService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
|
this.referenceRepository = referenceRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
@ -117,6 +124,7 @@ public class PaperService {
|
|||||||
paper.setTitle(paperDto.getTitle());
|
paper.setTitle(paperDto.getTitle());
|
||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
|
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
||||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
.filter(f -> !f.isDeleted())
|
.filter(f -> !f.isDeleted())
|
||||||
.collect(toList())));
|
.collect(toList())));
|
||||||
@ -127,6 +135,41 @@ public class PaperService {
|
|||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
||||||
|
return references
|
||||||
|
.stream()
|
||||||
|
.filter(reference -> !reference.getDeleted())
|
||||||
|
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Reference updateReference(ReferenceDto referenceDto) {
|
||||||
|
Reference updateReference = referenceRepository.findOne(referenceDto.getId());
|
||||||
|
copyFromDto(updateReference, referenceDto);
|
||||||
|
referenceRepository.save(updateReference);
|
||||||
|
return updateReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Reference createReference(ReferenceDto referenceDto) {
|
||||||
|
Reference newReference = new Reference();
|
||||||
|
copyFromDto(newReference, referenceDto);
|
||||||
|
newReference = referenceRepository.save(newReference);
|
||||||
|
return newReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Reference copyFromDto(Reference reference, ReferenceDto referenceDto) {
|
||||||
|
reference.setAuthors(referenceDto.getAuthors());
|
||||||
|
reference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle());
|
||||||
|
reference.setPages(referenceDto.getPages());
|
||||||
|
reference.setPublicationTitle(referenceDto.getPublicationTitle());
|
||||||
|
reference.setPublicationYear(referenceDto.getPublicationYear());
|
||||||
|
reference.setPublisher(referenceDto.getPublisher());
|
||||||
|
reference.setReferenceType(referenceDto.getReferenceType());
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(PaperDto paperDto) throws IOException {
|
public Integer update(PaperDto paperDto) throws IOException {
|
||||||
Paper paper = paperRepository.findOne(paperDto.getId());
|
Paper paper = paperRepository.findOne(paperDto.getId());
|
||||||
@ -139,6 +182,11 @@ public class PaperService {
|
|||||||
fileService.delete(file.getId());
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
paperRepository.save(copyFromDto(paper, paperDto));
|
paperRepository.save(copyFromDto(paper, paperDto));
|
||||||
|
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
||||||
|
.filter(f -> f.getDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
referenceRepository.deleteById(referenceDto.getId());
|
||||||
|
}
|
||||||
eventService.updatePaperDeadlines(paper);
|
eventService.updatePaperDeadlines(paper);
|
||||||
|
|
||||||
paper.getAuthors().forEach(author -> {
|
paper.getAuthors().forEach(author -> {
|
||||||
@ -168,6 +216,14 @@ public class PaperService {
|
|||||||
return Arrays.asList(Paper.PaperType.values());
|
return Arrays.asList(Paper.PaperType.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
||||||
|
return Arrays.asList(ReferenceDto.FormatStandard.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
||||||
|
return Arrays.asList(ReferenceDto.ReferenceType.values());
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(String title, User user, Date deadlineDate) {
|
public Paper create(String title, User user, Date deadlineDate) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
@ -287,12 +343,23 @@ public class PaperService {
|
|||||||
: getSpringerReference(referenceDto);
|
: getSpringerReference(referenceDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFormattedReferences(PaperDto paperDto) {
|
||||||
|
return String.join("\r\n", paperDto.getReferences()
|
||||||
|
.stream()
|
||||||
|
.filter(r -> !r.getDeleted())
|
||||||
|
.map(r -> {
|
||||||
|
r.setFormatStandard(paperDto.getFormatStandard());
|
||||||
|
return getFormattedReference(r);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
public String getGostReference(ReferenceDto referenceDto) {
|
public String getGostReference(ReferenceDto referenceDto) {
|
||||||
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
||||||
referenceDto.getAuthors(),
|
referenceDto.getAuthors(),
|
||||||
referenceDto.getPublicationTitle(),
|
referenceDto.getPublicationTitle(),
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
referenceDto.getPublicationYear().toString(),
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
referenceDto.getPages(),
|
referenceDto.getPages(),
|
||||||
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
||||||
}
|
}
|
||||||
@ -300,7 +367,7 @@ public class PaperService {
|
|||||||
public String getSpringerReference(ReferenceDto referenceDto) {
|
public String getSpringerReference(ReferenceDto referenceDto) {
|
||||||
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
||||||
referenceDto.getAuthors(),
|
referenceDto.getAuthors(),
|
||||||
referenceDto.getPublicationYear().toString(),
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
referenceDto.getPublicationTitle(),
|
referenceDto.getPublicationTitle(),
|
||||||
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
@ -310,4 +377,13 @@ public class PaperService {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AutoCompleteData getAutoCompleteData() {
|
||||||
|
AutoCompleteData autoCompleteData = new AutoCompleteData();
|
||||||
|
autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors());
|
||||||
|
autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles());
|
||||||
|
autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles());
|
||||||
|
autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers());
|
||||||
|
return autoCompleteData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ public class PingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addPing(Conference conference) throws IOException {
|
public Ping addPing(Conference conference) throws IOException {
|
||||||
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
newPing.setConference(conference);
|
newPing.setConference(conference);
|
||||||
pingRepository.save(newPing);
|
return pingRepository.save(newPing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer countPingYesterday(Conference conference, Calendar calendar) {
|
public Integer countPingYesterday(Conference conference, Calendar calendar) {
|
||||||
|
@ -10,6 +10,7 @@ import ru.ulstu.tags.model.Tag;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -135,6 +136,29 @@ public class TaskDto {
|
|||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TaskDto taskDto = (TaskDto) o;
|
||||||
|
return Objects.equals(id, taskDto.id) &&
|
||||||
|
Objects.equals(title, taskDto.title) &&
|
||||||
|
Objects.equals(description, taskDto.description) &&
|
||||||
|
status == taskDto.status &&
|
||||||
|
Objects.equals(deadlines, taskDto.deadlines) &&
|
||||||
|
Objects.equals(tagIds, taskDto.tagIds) &&
|
||||||
|
Objects.equals(tags, taskDto.tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, status, deadlines, createDate, updateDate, tagIds, tags);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTagsString() {
|
public String getTagsString() {
|
||||||
return StringUtils.abbreviate(tags
|
return StringUtils.abbreviate(tags
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -108,7 +108,7 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer taskId) throws IOException {
|
public boolean delete(Integer taskId) throws IOException {
|
||||||
if (taskRepository.exists(taskId)) {
|
if (taskRepository.exists(taskId)) {
|
||||||
Task scheduleTask = taskRepository.findOne(taskId);
|
Task scheduleTask = taskRepository.findOne(taskId);
|
||||||
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
||||||
@ -116,7 +116,9 @@ public class TaskService {
|
|||||||
schedulerRepository.delete(sch.getId());
|
schedulerRepository.delete(sch.getId());
|
||||||
}
|
}
|
||||||
taskRepository.delete(taskId);
|
taskRepository.delete(taskId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,14 +130,14 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyMainPart(Task newTask, Task task) {
|
private void copyMainPart(Task newTask, Task task) {
|
||||||
newTask.setTitle(task.getTitle());
|
newTask.setTitle(task.getTitle());
|
||||||
newTask.setTags(tagService.saveOrCreate(task.getTags()));
|
newTask.setTags(tagService.saveOrCreate(task.getTags()));
|
||||||
newTask.setCreateDate(new Date());
|
newTask.setCreateDate(new Date());
|
||||||
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task copyTaskWithNewDates(Task task) {
|
private Task copyTaskWithNewDates(Task task) {
|
||||||
Task newTask = new Task();
|
Task newTask = new Task();
|
||||||
copyMainPart(newTask, task);
|
copyMainPart(newTask, task);
|
||||||
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
||||||
@ -157,7 +159,7 @@ public class TaskService {
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task copyTaskWithNewYear(Task task) {
|
private Task copyTaskWithNewYear(Task task) {
|
||||||
Task newTask = new Task();
|
Task newTask = new Task();
|
||||||
copyMainPart(newTask, task);
|
copyMainPart(newTask, task);
|
||||||
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));
|
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));
|
||||||
@ -184,7 +186,7 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void generateYearTasks() {
|
public List<Task> generateYearTasks() {
|
||||||
Set<Tag> tags = checkRepeatingTags(false);
|
Set<Tag> tags = checkRepeatingTags(false);
|
||||||
List<Task> tasks = new ArrayList<>();
|
List<Task> tasks = new ArrayList<>();
|
||||||
tags.forEach(tag -> {
|
tags.forEach(tag -> {
|
||||||
@ -200,7 +202,9 @@ public class TaskService {
|
|||||||
Task newTask = copyTaskWithNewYear(task);
|
Task newTask = copyTaskWithNewYear(task);
|
||||||
taskRepository.save(newTask);
|
taskRepository.save(newTask);
|
||||||
});
|
});
|
||||||
|
return tasks;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,8 +249,9 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void createPeriodTask(Scheduler scheduler) {
|
public Task createPeriodTask(Scheduler scheduler) {
|
||||||
Task newTask = copyTaskWithNewDates(scheduler.getTask());
|
Task newTask = copyTaskWithNewDates(scheduler.getTask());
|
||||||
taskRepository.save(newTask);
|
taskRepository.save(newTask);
|
||||||
|
return newTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ public class Event extends BaseEntity {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
private List<User> recipients = new ArrayList<User>();
|
private List<User> recipients = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "child_id")
|
@JoinColumn(name = "child_id")
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.user.controller;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
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;
|
||||||
@ -19,6 +20,7 @@ import ru.ulstu.odin.controller.OdinController;
|
|||||||
import ru.ulstu.odin.model.OdinMetadata;
|
import ru.ulstu.odin.model.OdinMetadata;
|
||||||
import ru.ulstu.odin.model.OdinVoid;
|
import ru.ulstu.odin.model.OdinVoid;
|
||||||
import ru.ulstu.odin.service.OdinService;
|
import ru.ulstu.odin.service.OdinService;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
import ru.ulstu.user.model.UserResetPasswordDto;
|
import ru.ulstu.user.model.UserResetPasswordDto;
|
||||||
@ -28,8 +30,12 @@ import ru.ulstu.user.model.UserSessionListDto;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
import ru.ulstu.user.service.UserSessionService;
|
import ru.ulstu.user.service.UserSessionService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static ru.ulstu.user.controller.UserController.URL;
|
import static ru.ulstu.user.controller.UserController.URL;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -141,30 +147,28 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
|||||||
return new Response<>(userService.activateUser(activationKey));
|
return new Response<>(userService.activateUser(activationKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add page for user edit (user-profile)
|
|
||||||
@PostMapping("/change-information")
|
|
||||||
public Response<UserDto> changeInformation(@Valid @RequestBody UserDto userDto) {
|
|
||||||
log.debug("REST: UserController.changeInformation( {} )", userDto.getLogin());
|
|
||||||
return new Response<>(userService.updateUserInformation(userDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add page for user password change (user-profile)
|
|
||||||
@PostMapping("/change-password")
|
|
||||||
public Response<UserDto> changePassword(@Valid @RequestBody UserDto userDto) {
|
|
||||||
log.debug("REST: UserController.changePassword( {} )", userDto.getLogin());
|
|
||||||
return new Response<>(userService.changeUserPassword(userDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(PASSWORD_RESET_REQUEST_URL)
|
@PostMapping(PASSWORD_RESET_REQUEST_URL)
|
||||||
public Response<Boolean> requestPasswordReset(@RequestParam("email") String email) {
|
public void requestPasswordReset(@RequestParam("email") String email) {
|
||||||
log.debug("REST: UserController.requestPasswordReset( {} )", email);
|
log.debug("REST: UserController.requestPasswordReset( {} )", email);
|
||||||
return new Response<>(userService.requestUserPasswordReset(email));
|
userService.requestUserPasswordReset(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(PASSWORD_RESET_URL)
|
@PostMapping(PASSWORD_RESET_URL)
|
||||||
public Response<Boolean> finishPasswordReset(@RequestParam("key") String key,
|
public Response<Boolean> finishPasswordReset(@RequestBody UserResetPasswordDto userResetPasswordDto) {
|
||||||
@RequestBody UserResetPasswordDto userResetPasswordDto) {
|
log.debug("REST: UserController.requestPasswordReset( {} )", userResetPasswordDto.getResetKey());
|
||||||
log.debug("REST: UserController.requestPasswordReset( {} )", key);
|
return new Response<>(userService.completeUserPasswordReset(userResetPasswordDto));
|
||||||
return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto));
|
}
|
||||||
|
|
||||||
|
@PostMapping("/changePassword")
|
||||||
|
public void changePassword(@RequestBody Map<String, String> payload, HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
User user = userSessionService.getUserBySessionId(sessionId);
|
||||||
|
userService.changeUserPassword(user, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/invite")
|
||||||
|
public void inviteUser(@RequestParam("email") String email) {
|
||||||
|
userService.inviteUser(email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package ru.ulstu.user.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.odin.controller.OdinController;
|
||||||
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.model.UserListDto;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
import ru.ulstu.user.service.UserSessionService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/users")
|
||||||
|
public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(UserMvcController.class);
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
private final UserSessionService userSessionService;
|
||||||
|
|
||||||
|
public UserMvcController(UserService userService,
|
||||||
|
UserSessionService userSessionService) {
|
||||||
|
super(UserListDto.class, UserDto.class);
|
||||||
|
this.userService = userService;
|
||||||
|
this.userSessionService = userSessionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/profile")
|
||||||
|
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserBySessionId(sessionId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/profile")
|
||||||
|
public void updateUserProfile(ModelMap modelMap, HttpServletRequest request, UserDto userDto) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
User user = userSessionService.getUserBySessionId(sessionId);
|
||||||
|
modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto));
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.user.error;
|
package ru.ulstu.user.error;
|
||||||
|
|
||||||
public class UserPasswordsNotValidOrNotMatchException extends RuntimeException {
|
public class UserPasswordsNotValidOrNotMatchException extends RuntimeException {
|
||||||
public UserPasswordsNotValidOrNotMatchException() {
|
public UserPasswordsNotValidOrNotMatchException(String message) {
|
||||||
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.user.error;
|
||||||
|
|
||||||
|
public class UserSendingMailException extends RuntimeException {
|
||||||
|
public UserSendingMailException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ import java.util.Set;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class User extends BaseEntity {
|
public class User extends BaseEntity {
|
||||||
private final static String USER_ABBREVIATE_TEMPLATE = "%s %s%s";
|
private final static String USER_ABBREVIATE_TEMPLATE = "%s %s %s";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Pattern(regexp = Constants.LOGIN_REGEX)
|
@Pattern(regexp = Constants.LOGIN_REGEX)
|
||||||
@ -232,7 +232,7 @@ public class User extends BaseEntity {
|
|||||||
public String getUserAbbreviate() {
|
public String getUserAbbreviate() {
|
||||||
return String.format(USER_ABBREVIATE_TEMPLATE,
|
return String.format(USER_ABBREVIATE_TEMPLATE,
|
||||||
lastName == null ? "" : lastName,
|
lastName == null ? "" : lastName,
|
||||||
firstName == null ? "" : firstName.substring(0, 1) + ".",
|
firstName == null ? "" : firstName.substring(0, 1),
|
||||||
patronymic == null ? "" : patronymic.substring(0, 1) + ".");
|
patronymic == null ? "" : patronymic.substring(0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ public class UserResetPasswordDto {
|
|||||||
@Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50)
|
@Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50)
|
||||||
private String passwordConfirm;
|
private String passwordConfirm;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
@Size(min = Constants.RESET_KEY_LENGTH)
|
||||||
|
private String resetKey;
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
@ -25,4 +29,8 @@ public class UserResetPasswordDto {
|
|||||||
public boolean isPasswordsValid() {
|
public boolean isPasswordsValid() {
|
||||||
return Objects.equals(password, passwordConfirm);
|
return Objects.equals(password, passwordConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getResetKey() {
|
||||||
|
return resetKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package ru.ulstu.user.service;
|
package ru.ulstu.user.service;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.autoconfigure.mail.MailProperties;
|
import org.springframework.boot.autoconfigure.mail.MailProperties;
|
||||||
|
import org.springframework.mail.MailException;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@ -13,17 +15,16 @@ import ru.ulstu.configuration.ApplicationProperties;
|
|||||||
import ru.ulstu.configuration.Constants;
|
import ru.ulstu.configuration.Constants;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MailService {
|
public class MailService {
|
||||||
private final Logger log = LoggerFactory.getLogger(MailService.class);
|
|
||||||
|
|
||||||
private static final String USER = "user";
|
private static final String USER = "user";
|
||||||
private static final String BASE_URL = "baseUrl";
|
private static final String BASE_URL = "baseUrl";
|
||||||
|
private final Logger log = LoggerFactory.getLogger(MailService.class);
|
||||||
private final JavaMailSender javaMailSender;
|
private final JavaMailSender javaMailSender;
|
||||||
private final SpringTemplateEngine templateEngine;
|
private final SpringTemplateEngine templateEngine;
|
||||||
private final MailProperties mailProperties;
|
private final MailProperties mailProperties;
|
||||||
@ -38,23 +39,23 @@ public class MailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void sendEmail(String to, String subject, String content) {
|
public void sendEmail(String to, String subject, String content) throws MessagingException, MailException {
|
||||||
log.debug("Send email to '{}' with subject '{}'", to, subject);
|
log.debug("Send email to '{}' with subject '{}'", to, subject);
|
||||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||||
try {
|
|
||||||
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, StandardCharsets.UTF_8.name());
|
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, StandardCharsets.UTF_8.name());
|
||||||
message.setTo(to);
|
message.setTo(to);
|
||||||
message.setFrom(mailProperties.getUsername());
|
message.setFrom(mailProperties.getUsername());
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
message.setText(content, true);
|
message.setText(content, true);
|
||||||
|
modifyForDebug(message, subject);
|
||||||
javaMailSender.send(mimeMessage);
|
javaMailSender.send(mimeMessage);
|
||||||
log.debug("Sent email to User '{}'", to);
|
log.debug("Sent email to User '{}'", to);
|
||||||
} catch (Exception e) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.warn("Email could not be sent to user '{}'", to, e);
|
|
||||||
} else {
|
|
||||||
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void modifyForDebug(MimeMessageHelper message, String originalSubject) throws MessagingException {
|
||||||
|
if (!StringUtils.isEmpty(applicationProperties.getDebugEmail())) {
|
||||||
|
message.setTo(applicationProperties.getDebugEmail());
|
||||||
|
message.setSubject("To " + applicationProperties.getDebugEmail() + "; " + originalSubject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,17 @@ public class MailService {
|
|||||||
context.setVariable(USER, user);
|
context.setVariable(USER, user);
|
||||||
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
String content = templateEngine.process(templateName, context);
|
String content = templateEngine.process(templateName, context);
|
||||||
|
try {
|
||||||
sendEmail(user.getEmail(), subject, content);
|
sendEmail(user.getEmail(), subject, content);
|
||||||
|
} catch (
|
||||||
|
Exception e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.warn("Email could not be sent to user '{}'", user.getEmail(), e);
|
||||||
|
} else {
|
||||||
|
log.warn("Email could not be sent to user '{}': {}", user.getEmail(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo: выделить сервис нотификаций
|
//Todo: выделить сервис нотификаций
|
||||||
@ -75,7 +86,26 @@ public class MailService {
|
|||||||
context.setVariable(USER, user);
|
context.setVariable(USER, user);
|
||||||
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
String content = templateEngine.process(templateName, context);
|
String content = templateEngine.process(templateName, context);
|
||||||
|
try {
|
||||||
sendEmail(user.getEmail(), subject, content);
|
sendEmail(user.getEmail(), subject, content);
|
||||||
|
} catch (
|
||||||
|
Exception e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.warn("Email could not be sent to user '{}'", user.getEmail(), e);
|
||||||
|
} else {
|
||||||
|
log.warn("Email could not be sent to user '{}': {}", user.getEmail(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void sendEmailFromTemplate(Map<String, Object> variables, String templateName, String subject, String email)
|
||||||
|
throws MessagingException {
|
||||||
|
Context context = new Context();
|
||||||
|
variables.entrySet().forEach(entry -> context.setVariable(entry.getKey(), entry.getValue()));
|
||||||
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
|
String content = templateEngine.process(templateName, context);
|
||||||
|
sendEmail(email, subject, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@ -83,8 +113,16 @@ public class MailService {
|
|||||||
sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE);
|
sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
public void sendPasswordResetMail(User user) throws MessagingException, MailException {
|
||||||
public void sendPasswordResetMail(User user) {
|
|
||||||
sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET);
|
sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendInviteMail(Map<String, Object> variables, String email) throws MessagingException, MailException {
|
||||||
|
sendEmailFromTemplate(variables, "userInviteEmail", Constants.MAIL_INVITE, email);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void sendChangePasswordMail(User user) {
|
||||||
|
sendEmailFromTemplate(user, "passwordChangeEmail", Constants.MAIL_CHANGE_PASSWORD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package ru.ulstu.user.service;
|
package ru.ulstu.user.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.mail.MailException;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@ -25,6 +27,7 @@ import ru.ulstu.user.error.UserNotActivatedException;
|
|||||||
import ru.ulstu.user.error.UserNotFoundException;
|
import ru.ulstu.user.error.UserNotFoundException;
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
@ -36,10 +39,12 @@ import ru.ulstu.user.repository.UserRepository;
|
|||||||
import ru.ulstu.user.repository.UserRoleRepository;
|
import ru.ulstu.user.repository.UserRoleRepository;
|
||||||
import ru.ulstu.user.util.UserUtils;
|
import ru.ulstu.user.util.UserUtils;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -48,6 +53,8 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UserService implements UserDetailsService {
|
public class UserService implements UserDetailsService {
|
||||||
|
private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка";
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
@ -122,7 +129,7 @@ public class UserService implements UserDetailsService {
|
|||||||
throw new UserEmailExistsException(userDto.getEmail());
|
throw new UserEmailExistsException(userDto.getEmail());
|
||||||
}
|
}
|
||||||
if (!userDto.isPasswordsValid()) {
|
if (!userDto.isPasswordsValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
User user = userMapper.userDtoToUserEntity(userDto);
|
User user = userMapper.userDtoToUserEntity(userDto);
|
||||||
user.setActivated(false);
|
user.setActivated(false);
|
||||||
@ -192,10 +199,10 @@ public class UserService implements UserDetailsService {
|
|||||||
: roles);
|
: roles);
|
||||||
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
||||||
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
||||||
log.debug("Changed password for User: {}", user.getLogin());
|
log.debug("Changed password for User: {}", user.getLogin());
|
||||||
@ -205,46 +212,28 @@ public class UserService implements UserDetailsService {
|
|||||||
return userMapper.userEntityToUserDto(user);
|
return userMapper.userEntityToUserDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDto updateUserInformation(UserDto userDto) {
|
public UserDto updateUserInformation(User user, UserDto updateUser) {
|
||||||
if (userDto.getId() == null) {
|
user.setFirstName(updateUser.getFirstName());
|
||||||
throw new EntityIdIsNullException();
|
user.setLastName(updateUser.getLastName());
|
||||||
}
|
user.setEmail(updateUser.getEmail());
|
||||||
if (!Objects.equals(
|
user.setLogin(updateUser.getLogin());
|
||||||
Optional.ofNullable(getUserByEmail(userDto.getEmail()))
|
|
||||||
.map(BaseEntity::getId).orElse(userDto.getId()),
|
|
||||||
userDto.getId())) {
|
|
||||||
throw new UserEmailExistsException(userDto.getEmail());
|
|
||||||
}
|
|
||||||
User user = userRepository.findOne(userDto.getId());
|
|
||||||
if (user == null) {
|
|
||||||
throw new UserNotFoundException(userDto.getId().toString());
|
|
||||||
}
|
|
||||||
user.setFirstName(userDto.getFirstName());
|
|
||||||
user.setLastName(userDto.getLastName());
|
|
||||||
user.setEmail(userDto.getEmail());
|
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
log.debug("Updated Information for User: {}", user.getLogin());
|
log.debug("Updated Information for User: {}", user.getLogin());
|
||||||
return userMapper.userEntityToUserDto(user);
|
return userMapper.userEntityToUserDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDto changeUserPassword(UserDto userDto) {
|
public void changeUserPassword(User user, Map<String, String> payload) {
|
||||||
if (userDto.getId() == null) {
|
if (!payload.get("password").equals(payload.get("confirmPassword"))) {
|
||||||
throw new EntityIdIsNullException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
if (!passwordEncoder.matches(payload.get("oldPassword"), user.getPassword())) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("Старый пароль введен неправильно");
|
||||||
}
|
}
|
||||||
final String login = UserUtils.getCurrentUserLogin();
|
user.setPassword(passwordEncoder.encode(payload.get("password")));
|
||||||
final User user = userRepository.findOneByLoginIgnoreCase(login);
|
|
||||||
if (user == null) {
|
|
||||||
throw new UserNotFoundException(login);
|
|
||||||
}
|
|
||||||
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
|
||||||
}
|
|
||||||
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
|
||||||
log.debug("Changed password for User: {}", user.getLogin());
|
log.debug("Changed password for User: {}", user.getLogin());
|
||||||
return userMapper.userEntityToUserDto(userRepository.save(user));
|
userRepository.save(user);
|
||||||
|
|
||||||
|
mailService.sendChangePasswordMail(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestUserPasswordReset(String email) {
|
public boolean requestUserPasswordReset(String email) {
|
||||||
@ -258,23 +247,30 @@ public class UserService implements UserDetailsService {
|
|||||||
user.setResetKey(UserUtils.generateResetKey());
|
user.setResetKey(UserUtils.generateResetKey());
|
||||||
user.setResetDate(new Date());
|
user.setResetDate(new Date());
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
|
try {
|
||||||
mailService.sendPasswordResetMail(user);
|
mailService.sendPasswordResetMail(user);
|
||||||
|
} catch (MessagingException | MailException e) {
|
||||||
|
throw new UserSendingMailException(email);
|
||||||
|
}
|
||||||
log.debug("Created Reset Password Request for User: {}", user.getLogin());
|
log.debug("Created Reset Password Request for User: {}", user.getLogin());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean completeUserPasswordReset(String key, UserResetPasswordDto userResetPasswordDto) {
|
public boolean completeUserPasswordReset(UserResetPasswordDto userResetPasswordDto) {
|
||||||
if (!userResetPasswordDto.isPasswordsValid()) {
|
if (!userResetPasswordDto.isPasswordsValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("Пароли не совпадают");
|
||||||
}
|
}
|
||||||
User user = userRepository.findOneByResetKey(key);
|
User user = userRepository.findOneByResetKey(userResetPasswordDto.getResetKey());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new UserResetKeyError(key);
|
throw new UserResetKeyError(userResetPasswordDto.getResetKey());
|
||||||
}
|
}
|
||||||
user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword()));
|
user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword()));
|
||||||
user.setResetKey(null);
|
user.setResetKey(null);
|
||||||
user.setResetDate(null);
|
user.setResetDate(null);
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
|
|
||||||
|
mailService.sendChangePasswordMail(user);
|
||||||
|
|
||||||
log.debug("Reset Password for User: {}", user.getLogin());
|
log.debug("Reset Password for User: {}", user.getLogin());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -328,4 +324,32 @@ public class UserService implements UserDetailsService {
|
|||||||
public List<User> filterByAgeAndDegree(boolean hasDegree, boolean hasAge) {
|
public List<User> filterByAgeAndDegree(boolean hasDegree, boolean hasAge) {
|
||||||
return userRepository.filterByAgeAndDegree(hasDegree, hasAge);
|
return userRepository.filterByAgeAndDegree(hasDegree, hasAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void inviteUser(String email) throws UserSendingMailException {
|
||||||
|
if (userRepository.findOneByEmailIgnoreCase(email) != null) {
|
||||||
|
throw new UserEmailExistsException(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
String password = UserUtils.generatePassword();
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setPassword(passwordEncoder.encode(password));
|
||||||
|
user.setLogin(email);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setFirstName("user");
|
||||||
|
user.setLastName("user");
|
||||||
|
user.setActivated(true);
|
||||||
|
userRepository.save(user);
|
||||||
|
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("password", password, "email", email);
|
||||||
|
try {
|
||||||
|
mailService.sendInviteMail(variables, email);
|
||||||
|
} catch (MessagingException | MailException e) {
|
||||||
|
throw new UserSendingMailException(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User findOneByLoginIgnoreCase(String login) {
|
||||||
|
return userRepository.findOneByLoginIgnoreCase(login);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,8 @@ public class UserSessionService {
|
|||||||
userSessionRepository.save(userSession);
|
userSessionRepository.save(userSession);
|
||||||
log.debug("User session {} closed", sessionId);
|
log.debug("User session {} closed", sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUserBySessionId(String sessionId) {
|
||||||
|
return userSessionRepository.findOneBySessionId(sessionId).getUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
|
||||||
public class UserUtils {
|
public class UserUtils {
|
||||||
private static final int DEF_COUNT = 20;
|
private static final int DEF_COUNT = 20;
|
||||||
@ -32,4 +33,8 @@ public class UserUtils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generatePassword() {
|
||||||
|
return RandomStringUtils.randomAscii(Constants.MIN_PASSWORD_LENGTH, Constants.MAX_PASSWORD_LENGTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +35,6 @@ liquibase.change-log=classpath:db/changelog-master.xml
|
|||||||
ng-tracker.base-url=http://127.0.0.1:8080
|
ng-tracker.base-url=http://127.0.0.1:8080
|
||||||
ng-tracker.undead-user-login=admin
|
ng-tracker.undead-user-login=admin
|
||||||
ng-tracker.dev-mode=true
|
ng-tracker.dev-mode=true
|
||||||
|
ng-tracker.debug_email=
|
||||||
ng-tracker.use-https=false
|
ng-tracker.use-https=false
|
||||||
ng-tracker.check-run=false
|
ng-tracker.check-run=false
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="tanya" id="20190520_000000-1">
|
||||||
|
<dropColumn columnName="applicationFileName" tableName="grants"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
27
src/main/resources/db/changelog-20190523_000000-schema.xml
Normal file
27
src/main/resources/db/changelog-20190523_000000-schema.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="masha" id="20190523_000000-1">
|
||||||
|
<createTable tableName="reference">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="authors" type="varchar(255)"/>
|
||||||
|
<column name="publication_title" type="varchar(255)"/>
|
||||||
|
<column name="publication_year" type="integer"/>
|
||||||
|
<column name="paper_id" type="integer"/>
|
||||||
|
<column name="publisher" type="varchar(255)"/>
|
||||||
|
<column name="pages" type="varchar(255)"/>
|
||||||
|
<column name="journal_or_collection_title" type="varchar(255)"/>
|
||||||
|
<column name="reference_type" type="varchar(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_reference" tableName="reference"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="reference" baseColumnNames="paper_id"
|
||||||
|
constraintName="fk_reference_paper_id" referencedTableName="paper"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -45,4 +45,6 @@
|
|||||||
<include file="db/changelog-20190507_000001-schema.xml"/>
|
<include file="db/changelog-20190507_000001-schema.xml"/>
|
||||||
<include file="db/changelog-20190511_000000-schema.xml"/>
|
<include file="db/changelog-20190511_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190517_000001-schema.xml"/>
|
<include file="db/changelog-20190517_000001-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190520_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190523_000000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
21
src/main/resources/mail_templates/passwordChangeEmail.html
Normal file
21
src/main/resources/mail_templates/passwordChangeEmail.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Password reset</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Dear <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Your password has been changed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>Balance Team.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,23 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<title>Password reset</title>
|
<title>Восстановление пароля</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>
|
<p>
|
||||||
Dear <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
Дорогой <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
For your account a password reset was requested, please click on the URL below to
|
Ваш ключ для восстановления пароля <span th:text="${user.resetKey}"></span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a th:href="@{|${baseUrl}/reset?key=${user.resetKey}|}"
|
С уважением,
|
||||||
th:text="@{|${baseUrl}/reset?key=${user.resetKey}|}">Reset Link</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Regards,
|
|
||||||
<br/>
|
<br/>
|
||||||
<em>Balance Team.</em>
|
<em>Balance Team.</em>
|
||||||
</p>
|
</p>
|
||||||
|
21
src/main/resources/mail_templates/userInviteEmail.html
Normal file
21
src/main/resources/mail_templates/userInviteEmail.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Account activation</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Аккаунт в системе NG-Tracker был создан. <br />
|
||||||
|
Данные для входа: <br />
|
||||||
|
Логин - <span th:text="${email}"></span> <br />
|
||||||
|
Пароль - <span th:text="${password}"></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>Balance Team.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
src/main/resources/public/css/base.css
Normal file
3
src/main/resources/public/css/base.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.loader {
|
||||||
|
padding-left:50%
|
||||||
|
}
|
@ -23,11 +23,17 @@ body {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.conference-row .d-flex .text-decoration:nth-child(1) {
|
.conference-row .d-flex .text-decoration:nth-child(1) {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.conference-row .d-flex .text-decoration span.h6.float-left.m-2 {
|
||||||
|
max-width: 470px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
.conference-row .d-flex .icon-delete {
|
.conference-row .d-flex .icon-delete {
|
||||||
width: 29px;
|
width: 29px;
|
||||||
height: 29px;
|
height: 29px;
|
||||||
|
@ -7,3 +7,34 @@
|
|||||||
.nav-tabs {
|
.nav-tabs {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nav-references label, #nav-references select, #nav-references input {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references .collapse-heading {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 5px 15px;
|
||||||
|
background-color: #efefef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references .collapse-heading a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references a:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references #formattedReferencesArea {
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-autocomplete {
|
||||||
|
max-height: 200px;
|
||||||
|
max-width: 400px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
BIN
src/main/resources/public/img/main/ajax-loader.gif
Normal file
BIN
src/main/resources/public/img/main/ajax-loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 673 B |
@ -4,6 +4,7 @@
|
|||||||
var urlFileUpload = "/api/1.0/files/uploadTmpFile";
|
var urlFileUpload = "/api/1.0/files/uploadTmpFile";
|
||||||
var urlFileDownload = "/api/1.0/files/download/";
|
var urlFileDownload = "/api/1.0/files/download/";
|
||||||
var urlPdfGenerating = "/papers/generatePdf";
|
var urlPdfGenerating = "/papers/generatePdf";
|
||||||
|
var urlReferencesFormatting = "/papers/getFormattedReferences";
|
||||||
var urlFileDownloadTmp = "/api/1.0/files/download-tmp/";
|
var urlFileDownloadTmp = "/api/1.0/files/download-tmp/";
|
||||||
|
|
||||||
/* exported MessageTypesEnum */
|
/* exported MessageTypesEnum */
|
||||||
|
127
src/main/resources/public/js/users.js
Normal file
127
src/main/resources/public/js/users.js
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
function changePassword() {
|
||||||
|
oldPassword = $("#oldPassword").val()
|
||||||
|
password = $("#password").val()
|
||||||
|
confirmPassword = $("#confirmPassword").val()
|
||||||
|
|
||||||
|
if ([oldPassword.length, password.length, confirmPassword.length].includes(0)) {
|
||||||
|
showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password != confirmPassword) {
|
||||||
|
showFeedbackMessage("Повторный пароль введен неверно", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:"/api/1.0/users/changePassword",
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
data: JSON.stringify({
|
||||||
|
"oldPassword": oldPassword,
|
||||||
|
"password": password,
|
||||||
|
"confirmPassword": confirmPassword,
|
||||||
|
}),
|
||||||
|
method: "POST",
|
||||||
|
success: function() {
|
||||||
|
$("#closeModalPassword").click();
|
||||||
|
showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS)
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(errorData) {
|
||||||
|
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function inviteUser() {
|
||||||
|
email = $("#email").val();
|
||||||
|
if (!isEmailValid(email)) {
|
||||||
|
showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:"/api/1.0/users/invite?email=" + email,
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
method: "POST",
|
||||||
|
success: function() {
|
||||||
|
$("#closeModalInvite").click();
|
||||||
|
showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS)
|
||||||
|
},
|
||||||
|
error: function(errorData) {
|
||||||
|
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestResetPassword() {
|
||||||
|
email = $("#emailReset").val()
|
||||||
|
|
||||||
|
if (!isEmailValid(email)) {
|
||||||
|
showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#dvloader").show();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:"/api/1.0/users/password-reset-request?email=" + email,
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
method: "POST",
|
||||||
|
success: function() {
|
||||||
|
showFeedbackMessage("Проверочный код был отправлен на указанный почтовый ящик", MessageTypesEnum.SUCCESS)
|
||||||
|
$("#passwordNew").show()
|
||||||
|
$("#passwordConfirm").show()
|
||||||
|
$("#btnReset").show()
|
||||||
|
$("#resetKey").show()
|
||||||
|
$("#emailReset").hide()
|
||||||
|
$("#btnSend").hide()
|
||||||
|
$("#dvloader").hide()
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(errorData) {
|
||||||
|
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||||
|
$("#dvloader").hide()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetPassword() {
|
||||||
|
passwordNew = $("#passwordNew").val();
|
||||||
|
passwordConfirm = $("#passwordConfirm").val();
|
||||||
|
resetKey = $("#resetKey").val();
|
||||||
|
|
||||||
|
if ([passwordNew, passwordConfirm, resetKey].includes("")) {
|
||||||
|
showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passwordNew != passwordConfirm) {
|
||||||
|
showFeedbackMessage("Пароли не совпадают", MessageTypesEnum.WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:"/api/1.0/users/password-reset",
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
method: "POST",
|
||||||
|
data: JSON.stringify({
|
||||||
|
"password": passwordNew,
|
||||||
|
"passwordConfirm": passwordConfirm,
|
||||||
|
"resetKey": resetKey,
|
||||||
|
}),
|
||||||
|
success: function() {
|
||||||
|
showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS)
|
||||||
|
window.location.href = "/login"
|
||||||
|
},
|
||||||
|
error: function(errorData) {
|
||||||
|
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isEmailValid(email) {
|
||||||
|
re = /\S+@\S+\.\S+/;
|
||||||
|
return re.test(email)
|
||||||
|
}
|
@ -42,12 +42,20 @@
|
|||||||
placeholder="http://"/>
|
placeholder="http://"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p th:if="${#fields.hasErrors('url')}" th:errors="*{url}"
|
||||||
|
class="alert alert-danger">Incorrect description</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="description">Описание:</label>
|
<label for="description">Описание:</label>
|
||||||
<textarea class="form-control" rows="8" th:field="*{description}" id="description">
|
<textarea class="form-control" rows="8" th:field="*{description}" id="description">
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p th:if="${#fields.hasErrors('description')}" th:errors="*{description}"
|
||||||
|
class="alert alert-danger">Incorrect description</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="deadlines">Дедлайны:</label>
|
<label for="deadlines">Дедлайны:</label>
|
||||||
<div class="deadline-list form-control list-group" id="deadlines">
|
<div class="deadline-list form-control list-group" id="deadlines">
|
||||||
@ -65,6 +73,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
||||||
class="alert alert-danger">Incorrect title</p>
|
class="alert alert-danger">Incorrect title</p>
|
||||||
<p class="help-block text-danger"></p>
|
<p class="help-block text-danger"></p>
|
||||||
@ -94,6 +103,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p th:if="${#fields.hasErrors('beginDate') || #fields.hasErrors('endDate')}"
|
||||||
|
th:errors="*{beginDate}"
|
||||||
|
class="alert alert-danger">Incorrect date</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="members">Участники:</label>
|
<label for="members">Участники:</label>
|
||||||
@ -123,7 +136,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group d-flex justify-content-between flex-wrap">
|
<div class="form-group d-flex justify-content-between flex-wrap">
|
||||||
<!--<input type="hidden" th:value="*{ping}" th:name="ping"/>-->
|
|
||||||
<input id="ping-button" class="btn btn-primary"
|
<input id="ping-button" class="btn btn-primary"
|
||||||
type="submit" name="pingConference" value="Ping участникам"
|
type="submit" name="pingConference" value="Ping участникам"
|
||||||
th:disabled="*{id == null ? 'true' : 'false'}"/>
|
th:disabled="*{id == null ? 'true' : 'false'}"/>
|
||||||
|
@ -24,24 +24,24 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
<!--chart example-->
|
<!--chart example-->
|
||||||
<nav>
|
<!--<nav>-->
|
||||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
<!--<div class="nav nav-tabs" id="nav-tab" role="tablist">-->
|
||||||
<a class="nav-item nav-link active" id="nav-main-tab" data-toggle="tab"
|
<!--<a class="nav-item nav-link active" id="nav-main-tab" data-toggle="tab"-->
|
||||||
href="#nav-stat1" role="tab" aria-controls="nav-stat1" aria-selected="true">Стат1</a>
|
<!--href="#nav-stat1" role="tab" aria-controls="nav-stat1" aria-selected="true">Стат1</a>-->
|
||||||
<a class="nav-item nav-link" id="nav-latex-tab" data-toggle="tab"
|
<!--<a class="nav-item nav-link" id="nav-latex-tab" data-toggle="tab"-->
|
||||||
href="#nav-stat2" role="tab" aria-controls="nav-stat2" aria-selected="false">Стат2</a>
|
<!--href="#nav-stat2" role="tab" aria-controls="nav-stat2" aria-selected="false">Стат2</a>-->
|
||||||
</div>
|
<!--</div>-->
|
||||||
</nav>
|
<!--</nav>-->
|
||||||
<div class="tab-content" id="nav-tabContent">
|
<!--<div class="tab-content" id="nav-tabContent">-->
|
||||||
<div class="tab-pane fade show active" id="nav-stat1" role="tabpanel"
|
<!--<div class="tab-pane fade show active" id="nav-stat1" role="tabpanel"-->
|
||||||
aria-labelledby="nav-main-tab">
|
<!--aria-labelledby="nav-main-tab">-->
|
||||||
<div id="salesByType" style="width:100%; height:400px;"></div>
|
<!--<div id="salesByType" style="width:100%; height:400px;"></div>-->
|
||||||
</div>
|
<!--</div>-->
|
||||||
<div class="tab-pane fade" id="nav-stat2" role="tabpanel"
|
<!--<div class="tab-pane fade" id="nav-stat2" role="tabpanel"-->
|
||||||
aria-labelledby="nav-profile-tab">
|
<!--aria-labelledby="nav-profile-tab">-->
|
||||||
<div id="salesByRegion" style="width:100%; height:400px;"></div>
|
<!--<div id="salesByRegion" style="width:100%; height:400px;"></div>-->
|
||||||
</div>
|
<!--</div>-->
|
||||||
</div>
|
<!--</div>-->
|
||||||
<!--chart example-->
|
<!--chart example-->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -61,13 +61,24 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a>
|
<a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item dropdown">
|
||||||
<a class="nav-link js-scroll-trigger" href="/logout">Выход</a>
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
|
||||||
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
|
Профиль
|
||||||
|
</a>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="/users/profile">Личный кабинет</a>
|
||||||
|
<a class="dropdown-item" href="/logout">Выход</a>
|
||||||
|
<a class="dropdown-item" data-toggle="modal" href="invite.html" data-target="#inviteModal">Пригласить</a>
|
||||||
|
<a class="dropdown-item" data-toggle="modal" data-target="#changePasswordModal">Сменить пароль</a>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
<div th:replace="users/inviteModal"/>
|
||||||
|
<div th:replace="users/changePassword"/>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<ul id="messages" class="feedback-panel">
|
<ul id="messages" class="feedback-panel">
|
||||||
@ -108,6 +119,7 @@
|
|||||||
/*]]>*/
|
/*]]>*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<th:block layout:fragment="scripts">
|
<th:block layout:fragment="scripts">
|
||||||
</th:block>
|
</th:block>
|
||||||
@ -142,6 +154,7 @@
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
})(document, window, "yandex_metrika_callbacks2");
|
})(document, window, "yandex_metrika_callbacks2");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<noscript>
|
<noscript>
|
||||||
<div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt=""/></div>
|
<div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt=""/></div>
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<span th:replace="grants/fragments/grantStatusFragment :: grantStatus(grantStatus=${grant.status})"/>
|
<span th:replace="grants/fragments/grantStatusFragment :: grantStatus(grantStatus=${grant.status})"/>
|
||||||
<a th:href="@{'grant?id='+${grant.id}}">
|
<a th:href="@{'grant?id='+${grant.id}}">
|
||||||
<span class="h6" th:text="${grant.title}"/>
|
<span class="h6" th:if="${#strings.length(grant.title) > 50}" th:text="${#strings.substring(grant.title, 0, 50)} + '...'" th:title="${grant.title}"/>
|
||||||
|
<span class="h6" th:if="${#strings.length(grant.title) le 50}" th:text="${grant.title}" th:title="${grant.title}"/>
|
||||||
<span class="text-muted" th:text="${grant.authorsString}"/>
|
<span class="text-muted" th:text="${grant.authorsString}"/>
|
||||||
</a>
|
</a>
|
||||||
<input class="id-class" type="hidden" th:value="${grant.id}"/>
|
<input class="id-class" type="hidden" th:value="${grant.id}"/>
|
||||||
|
@ -186,47 +186,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-control list-group div-selected-papers" id="selected-papers">
|
<div class="form-control list-group div-selected-papers" id="selected-papers">
|
||||||
<div th:each="paper, rowStat : *{papers}">
|
<div th:each="paper, rowStat : *{papers}">
|
||||||
<input type="hidden" th:field="*{papers[__${rowStat.index}__].id}"/>
|
<div th:replace="papers/fragments/paperLineFragment :: paperLine(paper=${paper})"/>
|
||||||
<div class="col">
|
|
||||||
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
|
|
||||||
<img class="icon-paper" src="/img/conference/paper.png"/>
|
|
||||||
<span th:text="*{papers[__${rowStat.index}__].title}">
|
|
||||||
Название статьи
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<label>Статус: </label>
|
|
||||||
<span th:text="*{papers[__${rowStat.index}__].status.statusName}">
|
|
||||||
Статус статьи
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<!--
|
|
||||||
<div class="col" th:unless="${#lists.isEmpty(paper.grants)}">
|
|
||||||
<label>Гранты: </label>
|
|
||||||
<div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}"
|
|
||||||
th:remove="tag">
|
|
||||||
<div th:unless="${grant.id}==*{id}" th:remove="tag">
|
|
||||||
<li>
|
|
||||||
<a th:href="@{'/grants/grant?id=' + ${grant.id} + ''}">
|
|
||||||
<span th:text="${grant.title} "></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col" th:unless="${#lists.isEmpty(paper.conferences)}">
|
|
||||||
<label>Конференции: </label>
|
|
||||||
<div th:each="conference, conferenceRowStat : *{papers[__${rowStat.index}__].conferences}"
|
|
||||||
th:remove="tag">
|
|
||||||
<li>
|
|
||||||
<a th:href="@{'/conferences/conference?id=' + ${conference.id} + ''}">
|
|
||||||
<span th:text="${conference.title}"></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
|
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
|
||||||
<a th:href="@{'paper?id='+${paper.id}}">
|
<a th:href="@{'paper?id='+${paper.id}}">
|
||||||
<span class="h6" th:text="${paper.title}"/>
|
<span class="h6" th:if="${#strings.length(paper.title)} > 50" th:text="${#strings.substring(paper.title, 0, 50) + '...'}" th:title="${paper.title}"/>
|
||||||
|
<span class="h6" th:if="${#strings.length(paper.title) le 50}" th:text="${paper.title}" th:title="${paper.title}"/>
|
||||||
<span class="text-muted" th:text="${paper.authorsString}"/>
|
<span class="text-muted" th:text="${paper.authorsString}"/>
|
||||||
</a>
|
</a>
|
||||||
<input class="id-class" type="hidden" th:value="${paper.id}"/>
|
<input class="id-class" type="hidden" th:value="${paper.id}"/>
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="../css/paper.css"/>
|
<link rel="stylesheet" href="../css/paper.css"/>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
|
||||||
|
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@ -31,6 +35,9 @@
|
|||||||
href="#nav-main" role="tab" aria-controls="nav-main" aria-selected="true">Статья</a>
|
href="#nav-main" role="tab" aria-controls="nav-main" aria-selected="true">Статья</a>
|
||||||
<a class="nav-item nav-link" id="nav-latex-tab" data-toggle="tab"
|
<a class="nav-item nav-link" id="nav-latex-tab" data-toggle="tab"
|
||||||
href="#nav-latex" role="tab" aria-controls="nav-latex" aria-selected="false">Latex</a>
|
href="#nav-latex" role="tab" aria-controls="nav-latex" aria-selected="false">Latex</a>
|
||||||
|
<a class="nav-item nav-link" id="nav-references-tab" data-toggle="tab"
|
||||||
|
href="#nav-references" role="tab" aria-controls="nav-references"
|
||||||
|
aria-selected="false">References</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="tab-content" id="nav-tabContent">
|
<div class="tab-content" id="nav-tabContent">
|
||||||
@ -103,13 +110,15 @@
|
|||||||
class="alert alert-danger">Incorrect title</p>
|
class="alert alert-danger">Incorrect title</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary"
|
<input type="submit" id="addDeadline" name="addDeadline"
|
||||||
|
class="btn btn-primary"
|
||||||
value="Добавить
|
value="Добавить
|
||||||
дедлайн"/>
|
дедлайн"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Авторы:</label>
|
<label>Авторы:</label>
|
||||||
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
<select class="selectpicker form-control" multiple="true"
|
||||||
|
data-live-search="true"
|
||||||
title="-- Выберите авторов --"
|
title="-- Выберите авторов --"
|
||||||
th:field="*{authorIds}">
|
th:field="*{authorIds}">
|
||||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||||
@ -167,6 +176,125 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane fade" id="nav-references" role="tabpanel"
|
||||||
|
aria-labelledby="nav-profile-tab">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>References:</label>
|
||||||
|
<th:block th:each="reference, rowStat : *{references}">
|
||||||
|
<div class="row" th:id="|reference${rowStat.index}|"
|
||||||
|
th:style="${reference.deleted} ? 'display: none;' :''">
|
||||||
|
|
||||||
|
<div class="form-group col-11">
|
||||||
|
<a data-toggle="collapse"
|
||||||
|
th:href="${'#collapseReference'+rowStat.index}"
|
||||||
|
aria-expanded="false">
|
||||||
|
<div class="collapse-heading"
|
||||||
|
th:text="${(reference.referenceType.toString() == 'ARTICLE'?'Статья':'Книга') +'. '
|
||||||
|
+(reference.publicationTitle==null?'':reference.publicationTitle+'. ')+(reference.authors==null?'':reference.authors+'. ') }">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
|
<a class="btn btn-danger float-right"
|
||||||
|
th:onclick="|$('#references${rowStat.index}\\.deleted').val('true'); $('#reference${rowStat.index}').hide(); |"><span
|
||||||
|
aria-hidden="true"><i class="fa fa-times"/></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="collapse" th:id="${'collapseReference'+rowStat.index}">
|
||||||
|
<input type="hidden"
|
||||||
|
th:field="*{references[__${rowStat.index}__].id}"/>
|
||||||
|
<input type="hidden"
|
||||||
|
th:field="*{references[__${rowStat.index}__].deleted}"/>
|
||||||
|
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Вид публикации:</label>
|
||||||
|
<select class="form-control col-7"
|
||||||
|
th:field="*{references[__${rowStat.index}__].referenceType}">
|
||||||
|
<option th:each="type : ${allReferenceTypes}"
|
||||||
|
th:value="${type}"
|
||||||
|
th:text="${type.typeName}">Type
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Авторы:</label>
|
||||||
|
<input type="text"
|
||||||
|
class="form-control col-7 autocomplete author"
|
||||||
|
name="authors"
|
||||||
|
th:field="*{references[__${rowStat.index}__].authors}"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4 ">Название публикации:</label>
|
||||||
|
<input type="text"
|
||||||
|
class="form-control col-7 autocomplete publicationTitle"
|
||||||
|
name="publicationTitle"
|
||||||
|
th:field="*{references[__${rowStat.index}__].publicationTitle}"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Год издания:</label>
|
||||||
|
<input type="number" class="form-control col-7 "
|
||||||
|
name="publicationYear"
|
||||||
|
th:field="*{references[__${rowStat.index}__].publicationYear}"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Издательство:</label>
|
||||||
|
<input type="text"
|
||||||
|
class="form-control col-7 autocomplete publisher"
|
||||||
|
name="publisher"
|
||||||
|
th:field="*{references[__${rowStat.index}__].publisher}"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Страницы:</label>
|
||||||
|
<input type="text" class="form-control col-7" name="pages"
|
||||||
|
th:field="*{references[__${rowStat.index}__].pages}"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12">
|
||||||
|
<label class="col-4">Название журнала или сборника статей
|
||||||
|
конференции:</label>
|
||||||
|
<input type="text"
|
||||||
|
class="form-control col-7 autocomplete journalOrCollectionTitle"
|
||||||
|
name="journalOrCollectionTitle"
|
||||||
|
th:field="*{references[__${rowStat.index}__].journalOrCollectionTitle}"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</th:block>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="submit" id="addReference" name="addReference"
|
||||||
|
class="btn btn-primary"
|
||||||
|
value="Добавить источник"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-12 form-group">
|
||||||
|
<label for="formatStandard">Стандарт форматирования:</label>
|
||||||
|
|
||||||
|
<select class="form-control" th:field="*{formatStandard}"
|
||||||
|
id="formatStandard">
|
||||||
|
<option th:each="standard : ${allFormatStandards}"
|
||||||
|
th:value="${standard}"
|
||||||
|
th:text="${standard.standardName}">standard
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 form-group">
|
||||||
|
<button id="formatBtn" class="btn btn-primary text-uppercase"
|
||||||
|
onclick="getFormattedReferences()"
|
||||||
|
type="button">
|
||||||
|
Форматировать
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<textarea class="form-control"
|
||||||
|
id="formattedReferencesArea"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 offset-md-1 col-sm-12 offset-sm-0">
|
<div class="col-md-4 offset-md-1 col-sm-12 offset-sm-0">
|
||||||
@ -379,6 +507,63 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFormattedReferences() {
|
||||||
|
|
||||||
|
var formData = new FormData(document.forms.paperform);
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", urlReferencesFormatting);
|
||||||
|
console.log(formData);
|
||||||
|
xhr.send(formData);
|
||||||
|
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (this.status == 200) {
|
||||||
|
console.debug(this.response);
|
||||||
|
$('#formattedReferencesArea').val(this.response);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
showFeedbackMessage("Ошибка при форматировании списка литературы", MessageTypesEnum.DANGER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
/*<![CDATA[*/
|
||||||
|
|
||||||
|
var autoCompleteData = /*[[${autocompleteData}]]*/ 'default';
|
||||||
|
console.log(autoCompleteData);
|
||||||
|
|
||||||
|
|
||||||
|
$(".autocomplete.author").autocomplete({
|
||||||
|
source: autoCompleteData.authors,
|
||||||
|
minLength: 0,
|
||||||
|
}).focus(function () {
|
||||||
|
$(this).autocomplete("search");
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".autocomplete.publicationTitle").autocomplete({
|
||||||
|
source: autoCompleteData.publicationTitles,
|
||||||
|
minLength: 0,
|
||||||
|
}).focus(function () {
|
||||||
|
$(this).autocomplete("search");
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".autocomplete.publisher").autocomplete({
|
||||||
|
source: autoCompleteData.publishers,
|
||||||
|
minLength: 0,
|
||||||
|
}).focus(function () {
|
||||||
|
$(this).autocomplete("search");
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".autocomplete.journalOrCollectionTitle").autocomplete({
|
||||||
|
source: autoCompleteData.journalOrCollectionTitles,
|
||||||
|
minLength: 0,
|
||||||
|
}).focus(function () {
|
||||||
|
$(this).autocomplete("search");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*]]>*/
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,57 +1,59 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en"
|
<html lang="en"
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
layout:decorator="default">
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
|
<script src="/js/users.js"></script>
|
||||||
|
<link rel="stylesheet" href="../css/base.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav layout:fragment="navbar">
|
<nav layout:fragment="navbar">
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
<a class="navbar-brand" href="/"><span class="ui-menuitem-text"><i
|
<a class="navbar-brand" href="/"><span class="ui-menuitem-text"><i
|
||||||
class="fa fa-plane fa-4" aria-hidden="true"></i> Balance</span></a>
|
class="fa fa-plane fa-4" aria-style="display:none"></i> Balance</span></a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container" layout:fragment="content">
|
<div layout:fragment="content">
|
||||||
<form id="reset-form" method="post" class="margined-top-10">
|
<section class="bg-light" id="portfolio">
|
||||||
<fieldset>
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-md-center">
|
||||||
|
<div class="col-lg-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="email" name="email" id="email" class="form-control"
|
<input type="text" name="email" id="emailReset" class="form-control"
|
||||||
placeholder="E-Mail" required="true" autofocus="autofocus"/>
|
placeholder="E-Mail"/>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-success btn-block">Сбросить пароль</button>
|
<div class="form-group">
|
||||||
|
<input type="password" name="email" id="passwordNew" class="form-control"
|
||||||
|
placeholder="Новый пароль" style="display:none"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="password" name="email" id="passwordConfirm" class="form-control"
|
||||||
|
placeholder="Подтвердите пароль" style="display:none"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" name="email" id="resetKey" class="form-control"
|
||||||
|
placeholder="Код подтверждения" style="display:none"/>
|
||||||
|
</div>
|
||||||
|
<div id="dvloader" class="loader" style="display:none"><img src="../img/main/ajax-loader.gif" /></div>
|
||||||
|
<button id="btnSend" type="button" onclick="requestResetPassword()"
|
||||||
|
class="btn btn-success btn-block">
|
||||||
|
Отправить код подтверждения
|
||||||
|
</button>
|
||||||
|
<button id="btnReset" style="display:none" type="button" onclick="resetPassword()"
|
||||||
|
class="btn btn-success btn-block">
|
||||||
|
Сбросить
|
||||||
|
пароль
|
||||||
|
</button>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
<a href="/login">Вернуться к странице входа</a>
|
<a href="/login">Вернуться к странице входа</a>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<th:block layout:fragment="data-scripts">
|
|
||||||
<script type="text/javascript">
|
|
||||||
/*<![CDATA[*/
|
|
||||||
$(document).ready(function () {
|
|
||||||
$("#reset-form").submit(function () {
|
|
||||||
var email = $("#email").val();
|
|
||||||
if (isEmpty(email)) {
|
|
||||||
showFeedbackMessage("Адрес электронной почты не задан", MessageTypesEnum.DANGER);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
postToRest(urlUsersPasswordResetRequest + "?email=" + email, null,
|
|
||||||
function () {
|
|
||||||
showFeedbackMessage("Запрос на смену пароля отправлен");
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
$("#email").val("");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
/*]]>*/
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</th:block>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
36
src/main/resources/templates/users/changePassword.html
Normal file
36
src/main/resources/templates/users/changePassword.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:fragment="headerfiles">
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<script type='text/javascript' src="js/users.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="changePasswordModal" class="modal fade text-center">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="label">Пригласить пользователя</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input class="form-control" id="oldPassword" type="password"
|
||||||
|
placeholder="Старый пароль" required="required" name="oldPassword"/>
|
||||||
|
<br/>
|
||||||
|
<input class="form-control" id="password" type="password"
|
||||||
|
placeholder="Новый пароль" required="required" name="password"/>
|
||||||
|
<br/>
|
||||||
|
<input class="form-control" id="confirmPassword" type="password"
|
||||||
|
placeholder="Подтверждение нового пароля" required="required" name="confirmPassword"/>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="closeModalPassword" type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="changePassword()" class="btn btn-primary">Сохранить</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
31
src/main/resources/templates/users/inviteModal.html
Normal file
31
src/main/resources/templates/users/inviteModal.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:fragment="headerfiles">
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<script src="js/users.js"></script>
|
||||||
|
<script src="js/core.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="inviteModal" class="modal fade text-center">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="label">Пригласить пользователя</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<input class="form-control" id="email" type="text"
|
||||||
|
placeholder="Email" name="email"/>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="closeModalInvite" type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="inviteUser()" class="btn btn-primary">Отправить приглашение</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
75
src/main/resources/templates/users/profile.html
Normal file
75
src/main/resources/templates/users/profile.html
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="../css/grant.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="container" layout:fragment="content">
|
||||||
|
<section id="ewrq">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<h2 class="section-heading text-uppercase">Личный кабинет</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr/>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<form id="profile-form" method="post" th:action="@{'/users/profile'}"
|
||||||
|
th:object="${userDto}">
|
||||||
|
<input type="hidden" name="id" th:field="*{id}"/>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="firstName">Имя:</label>
|
||||||
|
<input class="form-control" id="firstName" type="text"
|
||||||
|
placeholder="Имя"
|
||||||
|
th:field="*{firstName}"/>
|
||||||
|
<p th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"
|
||||||
|
class="alert alert-danger">Incorrect firstName</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="lastName">Фамилия:</label>
|
||||||
|
<input class="form-control" id="lastName" type="text"
|
||||||
|
placeholder="lastName"
|
||||||
|
th:field="*{lastName}"/>
|
||||||
|
<p th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"
|
||||||
|
class="alert alert-danger">Incorrect lastName</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email:</label>
|
||||||
|
<input class="form-control" id="email" type="text"
|
||||||
|
placeholder="Email"
|
||||||
|
th:field="*{email}"/>
|
||||||
|
<p th:if="${#fields.hasErrors('email')}" th:errors="*{email}"
|
||||||
|
class="alert alert-danger">Incorrect email</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="login">Логин:</label>
|
||||||
|
<input class="form-control" id="login" type="text"
|
||||||
|
placeholder="Login"
|
||||||
|
th:field="*{login}"/>
|
||||||
|
<p th:if="${#fields.hasErrors('login')}" th:errors="*{login}"
|
||||||
|
class="alert alert-danger">Incorrect email</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button id="sendMessageButton" name="save"
|
||||||
|
class="btn btn-success text-uppercase"
|
||||||
|
type="submit">
|
||||||
|
Сохранить
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -26,7 +26,7 @@ import java.util.Map;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
public class IndexConferenceTest extends TestTemplate {
|
public class ConferenceTest extends TestTemplate {
|
||||||
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"),
|
new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"),
|
||||||
new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"),
|
new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"),
|
214
src/test/java/StudentTaskTest.java
Normal file
214
src/test/java/StudentTaskTest.java
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import core.PageObject;
|
||||||
|
import core.TestTemplate;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import ru.ulstu.NgTrackerApplication;
|
||||||
|
import ru.ulstu.configuration.ApplicationProperties;
|
||||||
|
import students.TaskPage;
|
||||||
|
import students.TasksDashboardPage;
|
||||||
|
import students.TasksPage;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
|
public class StudentTaskTest extends TestTemplate {
|
||||||
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
|
new TasksPage(), Arrays.asList("Список задач", "/students/tasks"),
|
||||||
|
new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"),
|
||||||
|
new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0")
|
||||||
|
);
|
||||||
|
|
||||||
|
private final String tag = "ATag";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testACreateTask() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 2);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey());
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
String taskName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
taskPage.setName(taskName);
|
||||||
|
taskPage.addDeadlineDate("01.01.2020", 0);
|
||||||
|
taskPage.addDeadlineDescription("Description", 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTask(taskName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBEditTaskName() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
String taskNewName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
taskPage.removeName();
|
||||||
|
taskPage.setName(taskNewName);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTask(taskNewName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCDeleteTask() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
Integer size = tasksPage.getTasks().size();
|
||||||
|
tasksPage.deleteFirstTask();
|
||||||
|
Thread.sleep(3000);
|
||||||
|
tasksPage.submit();
|
||||||
|
|
||||||
|
Assert.assertEquals(size - 1, tasksPage.getTasks().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDAddDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
Integer deadnum = taskPage.getDeadNum();
|
||||||
|
|
||||||
|
String descr = "Description";
|
||||||
|
String date = "06.06.2019";
|
||||||
|
String dateValue = "2019-06-06";
|
||||||
|
|
||||||
|
taskPage.clickAddDeadline();
|
||||||
|
taskPage.addDeadlineDescription(descr, deadnum);
|
||||||
|
taskPage.addDeadlineDate(date, deadnum);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertTrue(taskPage.hasDeadline(descr, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEEditDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
|
||||||
|
String descr = "DescriptionTwo";
|
||||||
|
String date = "12.12.2019";
|
||||||
|
String dateValue = "2019-12-12";
|
||||||
|
|
||||||
|
taskPage.clearDeadlineDate(0);
|
||||||
|
taskPage.clearDeadlineDescription(0);
|
||||||
|
taskPage.addDeadlineDescription(descr, 0);
|
||||||
|
taskPage.addDeadlineDate(date, 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertTrue(taskPage.hasDeadline(descr, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFDeleteDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
Integer deadNum = taskPage.getDeadNum();
|
||||||
|
|
||||||
|
taskPage.deleteDeadline();
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertEquals(deadNum - 1, (int) taskPage.getDeadNum());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGCreateTaskWithTag() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 2);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey());
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
String taskName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
taskPage.setName(taskName);
|
||||||
|
taskPage.setTag(tag);
|
||||||
|
Thread.sleep(1000);
|
||||||
|
taskPage.addDeadlineDate("01.01.2020", 0);
|
||||||
|
taskPage.addDeadlineDescription("Description", 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTaskByTag(taskName, tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHFindTagInFilter() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTag(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIFilterByTag() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
tasksPage.selectTag(tag);
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTasksByTag(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJFilterByStatus() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
tasksPage.selectStatus();
|
||||||
|
Assert.assertTrue(tasksPage.findAllStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
11
src/test/java/grant/KiasPage.java
Normal file
11
src/test/java/grant/KiasPage.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package grant;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
|
||||||
|
public class KiasPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h1")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,289 @@
|
|||||||
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ConferenceServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ConferenceRepository conferenceRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
DeadlineService deadlineService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ConferenceUserService conferenceUserService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
PaperService paperService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EventService eventService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ConferenceNotificationService conferenceNotificationService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
PingService pingService;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
ConferenceService conferenceService;
|
||||||
|
|
||||||
|
private final static Integer ID = 1;
|
||||||
|
private final static Integer INDEX = 0;
|
||||||
|
private final static String NAME = "Name";
|
||||||
|
private final static String DESCRIPTION = "Desc";
|
||||||
|
private final static boolean TRUE = true;
|
||||||
|
private final static Integer YEAR = 2019;
|
||||||
|
private final static Sort SORT = new Sort(Sort.Direction.DESC, "beginDate");
|
||||||
|
|
||||||
|
private List<Conference> conferences;
|
||||||
|
private List<Deadline> deadlines;
|
||||||
|
private List<Paper> papers;
|
||||||
|
private List<ConferenceUser> conferenceUsers;
|
||||||
|
|
||||||
|
private Conference conferenceWithId;
|
||||||
|
|
||||||
|
private Paper paperWithId;
|
||||||
|
private Paper paperWithoutId;
|
||||||
|
|
||||||
|
private ConferenceDto conferenceDto;
|
||||||
|
private User user;
|
||||||
|
private Deadline deadline;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
conferences = new ArrayList<>();
|
||||||
|
conferenceWithId = new Conference();
|
||||||
|
|
||||||
|
conferenceWithId.setId(ID);
|
||||||
|
conferenceWithId.setTitle(NAME);
|
||||||
|
conferenceWithId.setDescription(DESCRIPTION);
|
||||||
|
|
||||||
|
paperWithId = new Paper();
|
||||||
|
paperWithId.setId(1);
|
||||||
|
paperWithId.setTitle(NAME);
|
||||||
|
|
||||||
|
paperWithoutId = new Paper();
|
||||||
|
paperWithoutId.setTitle(NAME);
|
||||||
|
|
||||||
|
papers = new ArrayList<>();
|
||||||
|
papers.add(paperWithId);
|
||||||
|
papers.add(paperWithoutId);
|
||||||
|
|
||||||
|
deadlines = new ArrayList<>();
|
||||||
|
deadline = new Deadline(new Date(), DESCRIPTION);
|
||||||
|
deadline.setId(ID);
|
||||||
|
deadlines.add(deadline);
|
||||||
|
|
||||||
|
ConferenceUser conferenceUser = new ConferenceUser();
|
||||||
|
conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE);
|
||||||
|
conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL);
|
||||||
|
user = new User();
|
||||||
|
user.setFirstName(NAME);
|
||||||
|
conferenceUser.setUser(user);
|
||||||
|
|
||||||
|
conferenceUsers = new ArrayList<>();
|
||||||
|
conferenceUsers.add(conferenceUser);
|
||||||
|
|
||||||
|
conferences.add(conferenceWithId);
|
||||||
|
conferenceDto = new ConferenceDto(conferenceWithId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getExistConferenceById() {
|
||||||
|
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
||||||
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId);
|
||||||
|
newConferenceDto.setNotSelectedPapers(papers);
|
||||||
|
newConferenceDto.setDisabledTakePart(!TRUE);
|
||||||
|
ConferenceDto result = conferenceService.getExistConferenceById(ID);
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getId(), result.getId());
|
||||||
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNewConference() {
|
||||||
|
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
||||||
|
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.setNotSelectedPapers(papers);
|
||||||
|
ConferenceDto result = conferenceService.getNewConference();
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getId(), result.getId());
|
||||||
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
when(conferenceRepository.findAll(SORT)).thenReturn(conferences);
|
||||||
|
|
||||||
|
assertEquals(Collections.singletonList(conferenceWithId), conferenceService.findAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void create() throws IOException {
|
||||||
|
when(paperService.findPaperById(ID)).thenReturn(paperWithId);
|
||||||
|
when(paperService.create(new Paper())).thenReturn(paperWithoutId);
|
||||||
|
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
||||||
|
when(conferenceUserService.saveOrCreate(new ArrayList<>())).thenReturn(conferenceUsers);
|
||||||
|
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
||||||
|
|
||||||
|
conferenceDto.setPapers(papers);
|
||||||
|
conferenceDto.setDeadlines(deadlines);
|
||||||
|
conferenceDto.setUsers(conferenceUsers);
|
||||||
|
conferenceDto.getPaperIds().add(ID);
|
||||||
|
|
||||||
|
Conference newConference = new Conference();
|
||||||
|
newConference.setId(ID);
|
||||||
|
newConference.setTitle(NAME);
|
||||||
|
newConference.setDescription(DESCRIPTION);
|
||||||
|
newConference.setPapers(papers);
|
||||||
|
newConference.getPapers().add(paperWithId);
|
||||||
|
newConference.setDeadlines(deadlines);
|
||||||
|
newConference.setUsers(conferenceUsers);
|
||||||
|
|
||||||
|
assertEquals(newConference, conferenceService.create(conferenceDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
when(conferenceRepository.exists(ID)).thenReturn(true);
|
||||||
|
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
||||||
|
assertTrue(conferenceService.delete(ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addDeadline() {
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.getDeadlines().add(new Deadline());
|
||||||
|
conferenceDto.getDeadlines().clear();
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeDeadline() throws IOException {
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.getRemovedDeadlineIds().add(ID);
|
||||||
|
conferenceDto.getDeadlines().add(deadline);
|
||||||
|
ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX);
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines());
|
||||||
|
assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPaper() {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.getPapers().add(paperWithoutId);
|
||||||
|
conferenceDto.getPapers().clear();
|
||||||
|
ConferenceDto result = conferenceService.addPaper(conferenceDto);
|
||||||
|
result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removePaper() throws IOException {
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.getNotSelectedPapers().add(paperWithId);
|
||||||
|
newConferenceDto.getPapers().add(paperWithoutId);
|
||||||
|
conferenceDto.getPapers().add(paperWithId);
|
||||||
|
conferenceDto.getPapers().add(paperWithoutId);
|
||||||
|
ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX);
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
||||||
|
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void takePart() throws IOException {
|
||||||
|
when(userService.getCurrentUser()).thenReturn(user);
|
||||||
|
|
||||||
|
ConferenceDto newConferenceDto = new ConferenceDto();
|
||||||
|
newConferenceDto.setUsers(conferenceUsers);
|
||||||
|
newConferenceDto.setDisabledTakePart(TRUE);
|
||||||
|
conferenceDto.getPapers().clear();
|
||||||
|
ConferenceDto result = conferenceService.takePart(conferenceDto);
|
||||||
|
|
||||||
|
assertEquals(newConferenceDto.getUsers(), result.getUsers());
|
||||||
|
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllUsers() {
|
||||||
|
List<User> users = Collections.singletonList(user);
|
||||||
|
when(userService.findAll()).thenReturn(users);
|
||||||
|
assertEquals(users, conferenceService.getAllUsers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filter() {
|
||||||
|
when(userService.findById(ID)).thenReturn(user);
|
||||||
|
when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences);
|
||||||
|
|
||||||
|
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
|
||||||
|
conferenceFilterDto.setFilterUserId(ID);
|
||||||
|
conferenceFilterDto.setYear(YEAR);
|
||||||
|
|
||||||
|
assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAttachedToConference() {
|
||||||
|
when(conferenceRepository.isPaperAttached(ID)).thenReturn(TRUE);
|
||||||
|
|
||||||
|
assertTrue(conferenceService.isAttachedToConference(ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ping() throws IOException {
|
||||||
|
Ping ping = new Ping();
|
||||||
|
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
||||||
|
when(pingService.addPing(conferenceWithId)).thenReturn(ping);
|
||||||
|
when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX);
|
||||||
|
|
||||||
|
assertEquals(ping, conferenceService.ping(conferenceDto));
|
||||||
|
}
|
||||||
|
}
|
216
src/test/java/ru/ulstu/students/service/TaskServiceTest.java
Normal file
216
src/test/java/ru/ulstu/students/service/TaskServiceTest.java
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
package ru.ulstu.students.service;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.students.model.Scheduler;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
|
import ru.ulstu.students.model.TaskDto;
|
||||||
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
|
import ru.ulstu.students.repository.SchedulerRepository;
|
||||||
|
import ru.ulstu.students.repository.TaskRepository;
|
||||||
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
import ru.ulstu.tags.service.TagService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class TaskServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
TaskRepository taskRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SchedulerRepository schedulerRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private TagService tagService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
DeadlineService deadlineService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EventService eventService;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
TaskService taskService;
|
||||||
|
|
||||||
|
private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate");
|
||||||
|
private final static Integer ID = 1;
|
||||||
|
private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK;
|
||||||
|
private final static String TITLE = "title";
|
||||||
|
private final static String DESCR = "descr";
|
||||||
|
private final static String TAG = "tag";
|
||||||
|
private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0));
|
||||||
|
|
||||||
|
private List<Task> tasks;
|
||||||
|
private List<Tag> tags;
|
||||||
|
private Task task;
|
||||||
|
private Task taskForSchedule;
|
||||||
|
private TaskDto taskDto;
|
||||||
|
private Tag tag;
|
||||||
|
private Deadline deadline;
|
||||||
|
private List<Deadline> deadlines;
|
||||||
|
private Scheduler scheduler;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
|
tasks = new ArrayList<>();
|
||||||
|
task = new Task();
|
||||||
|
|
||||||
|
task.setId(ID);
|
||||||
|
task.setTitle(TITLE);
|
||||||
|
task.setDescription(DESCR);
|
||||||
|
|
||||||
|
|
||||||
|
tag = new Tag();
|
||||||
|
tag.setId(ID);
|
||||||
|
tag.setTagName(TAG);
|
||||||
|
|
||||||
|
deadlines = new ArrayList<>();
|
||||||
|
deadline = new Deadline(new Date(), DESCR);
|
||||||
|
deadline.setId(ID);
|
||||||
|
deadlines.add(deadline);
|
||||||
|
|
||||||
|
task.setDeadlines(deadlines);
|
||||||
|
|
||||||
|
tags = new ArrayList<>();
|
||||||
|
tags.add(tag);
|
||||||
|
|
||||||
|
tasks.add(task);
|
||||||
|
taskDto = new TaskDto(task);
|
||||||
|
|
||||||
|
taskForSchedule = new Task();
|
||||||
|
taskForSchedule.setTitle(TITLE);
|
||||||
|
taskForSchedule.setDescription(DESCR);
|
||||||
|
|
||||||
|
scheduler = new Scheduler();
|
||||||
|
scheduler.setDate(new Date());
|
||||||
|
scheduler.setTask(taskForSchedule);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
|
||||||
|
when(taskRepository.findAll(SORT)).thenReturn(tasks);
|
||||||
|
assertEquals(Collections.singletonList(task), taskService.findAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filter() {
|
||||||
|
when(tagService.findById(ID)).thenReturn(tag);
|
||||||
|
when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks);
|
||||||
|
|
||||||
|
TaskFilterDto taskFilterDto = new TaskFilterDto();
|
||||||
|
taskFilterDto.setTag(ID);
|
||||||
|
taskFilterDto.setOrder("new");
|
||||||
|
taskFilterDto.setStatus(STATUS);
|
||||||
|
|
||||||
|
assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void create() throws IOException {
|
||||||
|
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
|
||||||
|
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
||||||
|
when(taskRepository.save(new Task())).thenReturn(task);
|
||||||
|
eventService.createFromTask(new Task());
|
||||||
|
|
||||||
|
taskDto.setTags(tags);
|
||||||
|
taskDto.setDeadlines(deadlines);
|
||||||
|
|
||||||
|
Task newTask = new Task();
|
||||||
|
task.setId(ID);
|
||||||
|
task.setTitle(TITLE);
|
||||||
|
task.setDescription(DESCR);
|
||||||
|
task.setTags(tags);
|
||||||
|
task.setDeadlines(deadlines);
|
||||||
|
|
||||||
|
assertEquals(task.getId(), taskService.create(taskDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() throws IOException {
|
||||||
|
when(taskRepository.exists(ID)).thenReturn(true);
|
||||||
|
when(taskRepository.findOne(ID)).thenReturn(task);
|
||||||
|
when(schedulerRepository.findOneByTask(task)).thenReturn(null);
|
||||||
|
|
||||||
|
assertTrue(taskService.delete(ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateYearTasks() {
|
||||||
|
when(tagService.getTags()).thenReturn(tags);
|
||||||
|
tasks.get(0).setTags(tags);
|
||||||
|
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
||||||
|
tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
|
||||||
|
when(taskRepository.findByTag(tag)).thenReturn(tasks);
|
||||||
|
|
||||||
|
Task newTask = new Task();
|
||||||
|
newTask.setTitle(tasks.get(0).getTitle());
|
||||||
|
newTask.setTags(tasks.get(0).getTags());
|
||||||
|
newTask.setCreateDate(new Date());
|
||||||
|
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
||||||
|
|
||||||
|
Deadline newDeadline = new Deadline();
|
||||||
|
newDeadline.setId(ID);
|
||||||
|
newDeadline.setDescription(deadline.getDescription());
|
||||||
|
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
||||||
|
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
||||||
|
newTask.setDeadlines(Arrays.asList(newDeadline));
|
||||||
|
|
||||||
|
when(taskRepository.save(newTask)).thenReturn(task);
|
||||||
|
|
||||||
|
assertEquals(Arrays.asList(task), taskService.generateYearTasks());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkRepeatingTags() {
|
||||||
|
when(tagService.getTags()).thenReturn(tags);
|
||||||
|
tasks.get(0).setTags(tags);
|
||||||
|
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
||||||
|
|
||||||
|
assertEquals(new HashSet<Tag>(Arrays.asList(tag)), taskService.checkRepeatingTags(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createPeriodTask() {
|
||||||
|
Task newTask = new Task();
|
||||||
|
newTask.setTitle(scheduler.getTask().getTitle());
|
||||||
|
newTask.setTags(scheduler.getTask().getTags());
|
||||||
|
newTask.setCreateDate(new Date());
|
||||||
|
|
||||||
|
Deadline newDeadline = new Deadline();
|
||||||
|
newDeadline.setId(ID);
|
||||||
|
newDeadline.setDescription(deadline.getDescription());
|
||||||
|
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
||||||
|
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
||||||
|
newTask.setDeadlines(Arrays.asList(newDeadline));
|
||||||
|
|
||||||
|
when(taskRepository.save(newTask)).thenReturn(taskForSchedule);
|
||||||
|
|
||||||
|
assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler));
|
||||||
|
}
|
||||||
|
}
|
81
src/test/java/students/TaskPage.java
Normal file
81
src/test/java/students/TaskPage.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TaskPage extends PageObject {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h3")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
driver.findElement(By.id("title")).sendKeys(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
driver.findElement(By.id("sendMessageButton")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeadlineDate(String deadDate, Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeadlineDescription(String deadDescr, Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).sendKeys(deadDescr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeName() {
|
||||||
|
driver.findElement(By.id("title")).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return driver.findElement(By.id("id")).getAttribute("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDeadNum() {
|
||||||
|
return driver.findElements(By.cssSelector("#task-form .form-group:nth-of-type(5) .row")).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clickAddDeadline() {
|
||||||
|
driver.findElement(By.cssSelector("#addDeadline")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getDeadlines() {
|
||||||
|
return driver.findElements(By.cssSelector(".form-group:nth-of-type(5) .row"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDeadline() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"task-form\"]/div/div[1]/div[5]/div[1]/div[3]/a")).click();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearDeadlineDate(Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(Keys.DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearDeadlineDescription(Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDeadline(String deadDescr, String deadValue) {
|
||||||
|
return getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(webElement -> {
|
||||||
|
return webElement.findElement(By.cssSelector("input[type=\"text\"]")).getAttribute("value").equals(deadDescr)
|
||||||
|
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(deadValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(String tag) {
|
||||||
|
driver.findElement(By.className("input-tag-name")).sendKeys(tag);
|
||||||
|
driver.findElement(By.className("input-tag-name")).sendKeys(Keys.ENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
10
src/test/java/students/TasksDashboardPage.java
Normal file
10
src/test/java/students/TasksDashboardPage.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
|
||||||
|
public class TasksDashboardPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
75
src/test/java/students/TasksPage.java
Normal file
75
src/test/java/students/TasksPage.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TasksPage extends PageObject {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h3")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getTasks() {
|
||||||
|
return driver.findElements(By.cssSelector("span.h6"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getTaskRows() {
|
||||||
|
return driver.findElements(By.className("task-row"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goToFirstTask() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTask(String taskName) {
|
||||||
|
return getTasks().stream()
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(taskName));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFirstTask() {
|
||||||
|
js.executeScript("$('a[data-confirm]').click();");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void submit() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"dataConfirmOK\"]")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTag(String tag) {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag);
|
||||||
|
return driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul")).findElement(By.className("text")).getText().equals(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTaskByTag(String name, String tag) {
|
||||||
|
return getTasks().stream()
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(name)
|
||||||
|
&& webElement.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]/span[3]")).getText().equals(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTasksByTag(String tag) {
|
||||||
|
return getTaskRows().stream()
|
||||||
|
.allMatch(webElement -> webElement.findElement(By.cssSelector("span.text-muted")).getText().equals(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectTag(String tag) {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag);
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul/li/a")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void selectStatus() {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[1]/div/div/ul/li[2]/a")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findAllStatus() {
|
||||||
|
return getTaskRows().stream()
|
||||||
|
.allMatch(webElement -> webElement.findElement(By.cssSelector("div i.text-primary")).isDisplayed());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user