From e74261184f7a8442c8b359f6cc86bd59c3578949 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 20 Mar 2019 14:37:57 +0400 Subject: [PATCH 01/86] #73 first fixes by update versions --- build.gradle | 13 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../HttpListenerConfiguration.java | 18 +- .../MailTemplateConfiguration.java | 14 +- .../ulstu/core/jpa/OffsetablePageRequest.java | 16 +- .../core/service/XlsDocumentBuilder.java | 207 ------------------ .../deadline/service/DeadlineService.java | 2 +- .../ru/ulstu/file/service/FileService.java | 2 +- .../ru/ulstu/grant/service/GrantService.java | 6 +- .../java/ru/ulstu/odin/model/OdinField.java | 4 +- .../ru/ulstu/paper/service/PaperService.java | 8 +- .../ulstu/project/service/ProjectService.java | 2 +- .../ulstu/timeline/service/EventService.java | 8 +- .../timeline/service/TimelineService.java | 4 +- src/main/java/ru/ulstu/user/model/User.java | 2 +- .../java/ru/ulstu/user/model/UserDto.java | 4 +- .../ru/ulstu/user/service/MailService.java | 6 +- .../ru/ulstu/user/service/UserMapper.java | 2 +- .../ru/ulstu/user/service/UserService.java | 15 +- .../java/ru/ulstu/user/util/UserUtils.java | 7 +- src/main/resources/application.properties | 11 +- .../resources/templates/papers/paper.html | 2 +- 22 files changed, 76 insertions(+), 279 deletions(-) delete mode 100644 src/main/java/ru/ulstu/core/service/XlsDocumentBuilder.java diff --git a/build.gradle b/build.gradle index 4e0e9cb..53f06a9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - versionSpringBoot = '1.5.10.RELEASE' + versionSpringBoot = '2.1.3.RELEASE' } repositories { @@ -101,18 +101,15 @@ dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' - compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4' + compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect' + compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5' compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' - compile group: 'postgresql', name: 'postgresql', version: '9.1-901.jdbc4' + compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5' - compile group: 'org.liquibase', name: 'liquibase-core', version: '3.5.3' + compile group: 'org.liquibase', name: 'liquibase-core', version: '3.6.3' compile group: 'com.mattbertolini', name: 'liquibase-slf4j', version: '2.0.0' - - compile group: 'org.apache.poi', name: 'poi', version: '3.9' - compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.9' - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 568c50b..663c448 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip diff --git a/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java b/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java index bcbcab8..514319d 100644 --- a/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/HttpListenerConfiguration.java @@ -2,18 +2,18 @@ package ru.ulstu.configuration; import org.eclipse.jetty.server.ServerConnector; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.ConfigurableWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Configuration; @Configuration -public class HttpListenerConfiguration implements EmbeddedServletContainerCustomizer { +public class HttpListenerConfiguration implements WebServerFactoryCustomizer { @Value("${server.http.port}") private int httpPort; - private void configureJetty(JettyEmbeddedServletContainerFactory jettyFactory) { + private void configureJetty(JettyServletWebServerFactory jettyFactory) { jettyFactory.addServerCustomizers((JettyServerCustomizer) server -> { ServerConnector serverConnector = new ServerConnector(server); serverConnector.setPort(httpPort); @@ -22,9 +22,9 @@ public class HttpListenerConfiguration implements EmbeddedServletContainerCustom } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - if (container instanceof JettyEmbeddedServletContainerFactory) { - configureJetty((JettyEmbeddedServletContainerFactory) container); + public void customize(ConfigurableWebServerFactory factory) { + if (factory instanceof JettyServletWebServerFactory) { + configureJetty((JettyServletWebServerFactory) factory); } } } diff --git a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java index addf7ac..e212e5b 100644 --- a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java @@ -3,8 +3,8 @@ package ru.ulstu.configuration; import nz.net.ultraq.thymeleaf.LayoutDialect; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect; -import org.thymeleaf.spring4.SpringTemplateEngine; +import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect; +import org.thymeleaf.spring5.SpringTemplateEngine; import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; import org.thymeleaf.templateresolver.ITemplateResolver; @@ -26,19 +26,19 @@ public class MailTemplateConfiguration { public ClassLoaderTemplateResolver emailTemplateResolver() { ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); emailTemplateResolver.setPrefix("mail_templates/"); - emailTemplateResolver.setTemplateMode("HTML5"); + emailTemplateResolver.setTemplateMode("HTML"); emailTemplateResolver.setSuffix(".html"); - emailTemplateResolver.setOrder(1); + emailTemplateResolver.setOrder(2); emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return emailTemplateResolver; } public ClassLoaderTemplateResolver mvcTemplateResolver() { ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); - emailTemplateResolver.setPrefix("templates"); - emailTemplateResolver.setTemplateMode("HTML5"); + emailTemplateResolver.setPrefix("templates/"); + emailTemplateResolver.setTemplateMode("HTML"); emailTemplateResolver.setSuffix(".html"); - emailTemplateResolver.setOrder(2); + emailTemplateResolver.setOrder(1); emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return emailTemplateResolver; } diff --git a/src/main/java/ru/ulstu/core/jpa/OffsetablePageRequest.java b/src/main/java/ru/ulstu/core/jpa/OffsetablePageRequest.java index 388e9a1..af3be5c 100644 --- a/src/main/java/ru/ulstu/core/jpa/OffsetablePageRequest.java +++ b/src/main/java/ru/ulstu/core/jpa/OffsetablePageRequest.java @@ -6,19 +6,19 @@ import org.springframework.data.domain.Sort; import java.io.Serializable; public class OffsetablePageRequest implements Pageable, Serializable { - private final int offset; + private final long offset; private final int count; private final Sort sort; - public OffsetablePageRequest(int offset, int count) { + public OffsetablePageRequest(long offset, int count) { this(offset, count, null); } - public OffsetablePageRequest(int offset, int count, Sort.Direction direction, String... properties) { + public OffsetablePageRequest(long offset, int count, Sort.Direction direction, String... properties) { this(offset, count, new Sort(direction, properties)); } - public OffsetablePageRequest(int offset, int count, Sort sort) { + public OffsetablePageRequest(long offset, int count, Sort sort) { if (offset < 0) { throw new IllegalArgumentException("Offset value must not be less than zero!"); } @@ -42,11 +42,11 @@ public class OffsetablePageRequest implements Pageable, Serializable { @Override public int getPageNumber() { - return offset / count; + return (int) (offset / count); } @Override - public int getOffset() { + public long getOffset() { return offset; } @@ -89,9 +89,9 @@ public class OffsetablePageRequest implements Pageable, Serializable { @Override public int hashCode() { final int prime = 31; - int result = 1; + long result = 1; result = prime * result + offset; result = prime * result + count; - return result; + return (int) result; } } diff --git a/src/main/java/ru/ulstu/core/service/XlsDocumentBuilder.java b/src/main/java/ru/ulstu/core/service/XlsDocumentBuilder.java deleted file mode 100644 index d70d86e..0000000 --- a/src/main/java/ru/ulstu/core/service/XlsDocumentBuilder.java +++ /dev/null @@ -1,207 +0,0 @@ -package ru.ulstu.core.service; - -import org.apache.poi.POIXMLDocument; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.RegionUtil; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import ru.ulstu.core.error.XlsParseException; - -import java.io.*; - -public class XlsDocumentBuilder { - private static final int DEFAULT_SHEET_NUM = 0; - private File documentFile; - private Workbook workBook; - private Sheet currentSheet; - - /** - * Constructor for reading and writing data from/to *.[xls|xlsx] document - * - * @param file contains existing document for reading or new document to save - */ - public XlsDocumentBuilder(File file) throws IOException, XlsParseException { - this.documentFile = file; - if (file.exists()) { - workBook = getWorkBook(file); - currentSheet = workBook.getSheetAt(DEFAULT_SHEET_NUM); - } else { - workBook = new XSSFWorkbook(); - currentSheet = workBook.createSheet(); - } - } - - private Workbook getWorkBook(File file) throws XlsParseException, IOException { - InputStream inputStream = new PushbackInputStream(new FileInputStream(file), 4096); - if (isXlsx(inputStream)) { - return new XSSFWorkbook(inputStream); - } else if (isExcel(inputStream)) { - return new HSSFWorkbook(inputStream); - } - throw new XlsParseException("Wrong document format"); - } - - /** - * Change active sheet to write or read data - * - * @param index index of sheet to activate - */ - public XlsDocumentBuilder setActiveSheet(int index) { - workBook.setActiveSheet(index); - currentSheet = workBook.getSheetAt(index); - return this; - } - - /** - * Create new sheet in document and set it active - * - * @param sheetName - */ - public XlsDocumentBuilder insertNewSheet(String sheetName) { - currentSheet = workBook.createSheet(sheetName); - workBook.setActiveSheet(getSheetCount() - 1); - return this; - } - - public XlsDocumentBuilder insertNewSheet(String sheetName, int order) { - insertNewSheet(sheetName); - workBook.setSheetOrder(sheetName, order); - return this; - } - - /** - * Returns number of sheet in document - * - * @return sheets count - */ - public int getSheetCount() { - return workBook.getNumberOfSheets(); - } - - /** - * Returns number of rows in sheet - * - * @return rows count - */ - public int getRowCount() { - return currentSheet.getLastRowNum(); - } - - /** - * Returns number of columns in sheet - * - * @return columns count - */ - public int getColumnCount() { - Row row = currentSheet.getRow(getRowCount()); - if (row == null) { - return 0; - } - return row.getLastCellNum() - 1; - } - - /** - * Returns converted to string representation of cell value - * - * @param rowIndex row index of current sheet - * @param colIndex column index of current sheet - * @return string value of cell - */ - public String getCellAsString(int rowIndex, int colIndex) { - Cell cell = currentSheet.getRow(rowIndex).getCell(colIndex); - cell.setCellType(Cell.CELL_TYPE_STRING); - return cell.getStringCellValue(); - } - - /** - * Sets string cell value - * - * @param rowIndex row index of current sheet - * @param colIndex column index of current sheet - */ - public XlsDocumentBuilder setCellValue(int rowIndex, int colIndex, String value) { - if (currentSheet.getRow(rowIndex) == null) { - currentSheet.createRow(rowIndex); - } - if (currentSheet.getRow(rowIndex).getCell(colIndex) == null) { - currentSheet.getRow(rowIndex).createCell(colIndex); - } - Cell cell = currentSheet.getRow(rowIndex).getCell(colIndex); - cell.setCellValue(value); - setColumnAutosize(colIndex, colIndex); - return this; - } - - public XlsDocumentBuilder setCellValue(int rowIndex, int colIndex, int value) { - return setCellValue(rowIndex, colIndex, String.valueOf(value)); - } - - public XlsDocumentBuilder setCellValue(int rowIndex, int colIndex, long value) { - return setCellValue(rowIndex, colIndex, String.valueOf(value)); - } - - /** - * Save current file - */ - public XlsDocumentBuilder save() throws IOException { - OutputStream out = new FileOutputStream(documentFile); - workBook.write(out); - return this; - } - - private boolean isExcel(InputStream i) throws IOException { - return (POIFSFileSystem.hasPOIFSHeader(i) || POIXMLDocument.hasOOXMLHeader(i)); - } - - private boolean isXlsx(InputStream i) throws IOException { - return POIXMLDocument.hasOOXMLHeader(i); - } - - public int getActiveSheetIndex() { - return workBook.getActiveSheetIndex(); - } - - public XlsDocumentBuilder mergeCells(int rowFrom, int rowTo, int colFrom, int colTo) { - currentSheet.addMergedRegion(new CellRangeAddress(rowFrom, rowTo, colFrom, colTo)); - return this; - } - - public void setRegionBorderWithMedium(int rowFrom, int rowTo, int colFrom, int colTo) { - for (int row = rowFrom; row < rowTo; row++) { - for (int col = colFrom; col <= colTo; col++) { - CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, col, col); - RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, cellRangeAddress, currentSheet, workBook); - RegionUtil.setBorderLeft(CellStyle.BORDER_THIN, cellRangeAddress, currentSheet, workBook); - RegionUtil.setBorderRight(CellStyle.BORDER_THIN, cellRangeAddress, currentSheet, workBook); - RegionUtil.setBorderTop(CellStyle.BORDER_THIN, cellRangeAddress, currentSheet, workBook); - } - } - } - - public XlsDocumentBuilder setColumnAutosize(int from, int to) { - for (int col = from; col <= to; col++) { - currentSheet.autoSizeColumn(col, true); - } - return this; - } - - public XlsDocumentBuilder setRowAutosize(int from, int to) { - CellStyle style = workBook.createCellStyle(); - style.setWrapText(true); - for (int row = from; row <= to; row++) { - for (int col = 0; col <= currentSheet.getRow(row).getLastCellNum(); col++) { - if (currentSheet.getRow(row).getCell(col) != null) { - currentSheet.getRow(row).getCell(col).setCellStyle(style); - } - } - } - return this; - } - - public XlsDocumentBuilder deleteSheet(int index) { - workBook.removeSheetAt(index); - return this; - } -} diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 2180025..30aa6b0 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -26,7 +26,7 @@ public class DeadlineService { @Transactional public Deadline update(Deadline deadline) { - Deadline updateDeadline = deadlineRepository.findOne(deadline.getId()); + Deadline updateDeadline = deadlineRepository.getOne(deadline.getId()); updateDeadline.setDate(deadline.getDate()); updateDeadline.setDescription(deadline.getDescription()); deadlineRepository.save(updateDeadline); diff --git a/src/main/java/ru/ulstu/file/service/FileService.java b/src/main/java/ru/ulstu/file/service/FileService.java index 2f1fb6d..3f9e603 100644 --- a/src/main/java/ru/ulstu/file/service/FileService.java +++ b/src/main/java/ru/ulstu/file/service/FileService.java @@ -60,7 +60,7 @@ public class FileService { } public FileData getFile(Integer fileId) { - return fileRepository.findOne(fileId); + return fileRepository.getOne(fileId); } public void deleteTmpFile(String tmpFileName) throws IOException { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index d5beec3..7041f7d 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -52,7 +52,7 @@ public class GrantService { } public GrantDto findOneDto(Integer id) { - return new GrantDto(grantRepository.findOne(id)); + return new GrantDto(grantRepository.getOne(id)); } @Transactional @@ -83,7 +83,7 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { - Grant grant = grantRepository.findOne(grantDto.getId()); + Grant grant = grantRepository.getOne(grantDto.getId()); Grant.GrantStatus oldStatus = grant.getStatus(); if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); @@ -94,7 +94,7 @@ public class GrantService { @Transactional public void delete(Integer grantId) throws IOException { - Grant grant = grantRepository.findOne(grantId); + Grant grant = grantRepository.getOne(grantId); if (grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } diff --git a/src/main/java/ru/ulstu/odin/model/OdinField.java b/src/main/java/ru/ulstu/odin/model/OdinField.java index 5917a44..17ee2dc 100644 --- a/src/main/java/ru/ulstu/odin/model/OdinField.java +++ b/src/main/java/ru/ulstu/odin/model/OdinField.java @@ -1,13 +1,13 @@ package ru.ulstu.odin.model; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotBlank; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.core.error.OdinException; import ru.ulstu.odin.model.annotation.OdinCaption; import ru.ulstu.odin.model.annotation.OdinReadOnly; import ru.ulstu.odin.model.annotation.OdinVisible; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 9df8be2..f724bdb 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -69,7 +69,7 @@ public class PaperService { } public PaperDto findOneDto(Integer id) { - return new PaperDto(paperRepository.findOne(id)); + return new PaperDto(paperRepository.getOne(id)); } @Transactional @@ -100,7 +100,7 @@ public class PaperService { @Transactional public Integer update(PaperDto paperDto) throws IOException { - Paper paper = paperRepository.findOne(paperDto.getId()); + Paper paper = paperRepository.getOne(paperDto.getId()); Paper.PaperStatus oldStatus = paper.getStatus(); Set oldAuthors = new HashSet<>(paper.getAuthors()); if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { @@ -123,7 +123,7 @@ public class PaperService { @Transactional public void delete(Integer paperId) throws IOException { - Paper paper = paperRepository.findOne(paperId); + Paper paper = paperRepository.getOne(paperId); if (paper.getFileData() != null) { fileService.deleteFile(paper.getFileData()); } @@ -197,7 +197,7 @@ public class PaperService { } public PaperDto findById(Integer paperId) { - return new PaperDto(paperRepository.findOne(paperId)); + return new PaperDto(paperRepository.getOne(paperId)); } public List getPaperAuthors() { diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index b54a60a..cbcc232 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -53,7 +53,7 @@ public class ProjectService { } public Project findById(Integer id) { - return projectRepository.findOne(id); + return projectRepository.getOne(id); } } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index ca95b9a..7d0d251 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -52,19 +52,19 @@ public class EventService { @Transactional public Integer update(EventDto eventDto) { - Event event = eventRepository.findOne(eventDto.getId()); + Event event = eventRepository.getOne(eventDto.getId()); return eventRepository.save(copyFromDto(event, eventDto)).getId(); } @Transactional public void delete(Integer eventId) { - Event event = eventRepository.findOne(eventId); + Event event = eventRepository.getOne(eventId); event.setParents(null); eventRepository.delete(event); } public List findByIds(List ids) { - return eventRepository.findAll(ids); + return eventRepository.findAllById(ids); } public void createBasedOn(Event event, Date executeDate) { @@ -79,7 +79,7 @@ public class EventService { event = eventRepository.save(event); //set child to parent - Event parentEvent = eventRepository.findOne(parentEventId); + Event parentEvent = eventRepository.getOne(parentEventId); parentEvent.setChild(event); eventRepository.save(parentEvent); } diff --git a/src/main/java/ru/ulstu/timeline/service/TimelineService.java b/src/main/java/ru/ulstu/timeline/service/TimelineService.java index 94388ee..4101f92 100644 --- a/src/main/java/ru/ulstu/timeline/service/TimelineService.java +++ b/src/main/java/ru/ulstu/timeline/service/TimelineService.java @@ -39,13 +39,13 @@ public class TimelineService { @Transactional public Integer update(TimelineDto timelineDto) { - Timeline timeline = timelineRepository.findOne(timelineDto.getId()); + Timeline timeline = timelineRepository.getOne(timelineDto.getId()); return timelineRepository.save(copyFromDto(timeline, timelineDto)).getId(); } @Transactional public void delete(Integer timelineId) { - Timeline timeline = timelineRepository.findOne(timelineId); + Timeline timeline = timelineRepository.getOne(timelineId); timelineRepository.delete(timeline); } } diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index de9f028..de3be9e 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -1,7 +1,6 @@ package ru.ulstu.user.model; import org.hibernate.annotations.BatchSize; -import org.hibernate.validator.constraints.Email; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.BaseEntity; @@ -13,6 +12,7 @@ import javax.persistence.ManyToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index c98e0bb..ecb8bbe 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -1,8 +1,6 @@ package ru.ulstu.user.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotBlank; import org.springframework.util.StringUtils; import ru.ulstu.configuration.Constants; import ru.ulstu.odin.model.OdinDto; @@ -12,6 +10,8 @@ import ru.ulstu.odin.model.annotation.OdinString; import ru.ulstu.odin.model.annotation.OdinVisible; import ru.ulstu.user.controller.UserController; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.util.Collection; diff --git a/src/main/java/ru/ulstu/user/service/MailService.java b/src/main/java/ru/ulstu/user/service/MailService.java index da1da6d..77be5e7 100644 --- a/src/main/java/ru/ulstu/user/service/MailService.java +++ b/src/main/java/ru/ulstu/user/service/MailService.java @@ -8,7 +8,7 @@ import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.thymeleaf.context.Context; -import org.thymeleaf.spring4.SpringTemplateEngine; +import org.thymeleaf.spring5.SpringTemplateEngine; import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.configuration.Constants; import ru.ulstu.user.model.User; @@ -19,11 +19,9 @@ import java.util.Map; @Service public class MailService { - private final Logger log = LoggerFactory.getLogger(MailService.class); - private static final String USER = "user"; private static final String BASE_URL = "baseUrl"; - + private final Logger log = LoggerFactory.getLogger(MailService.class); private final JavaMailSender javaMailSender; private final SpringTemplateEngine templateEngine; private final MailProperties mailProperties; diff --git a/src/main/java/ru/ulstu/user/service/UserMapper.java b/src/main/java/ru/ulstu/user/service/UserMapper.java index 7359bba..647754b 100644 --- a/src/main/java/ru/ulstu/user/service/UserMapper.java +++ b/src/main/java/ru/ulstu/user/service/UserMapper.java @@ -26,7 +26,7 @@ public class UserMapper { public Set rolesFromDto(Set strings) { return Optional.ofNullable(strings).orElse(Collections.emptySet()).stream() .filter(Objects::nonNull) - .map(role -> userRoleRepository.findOne(role.getId().toString())) + .map(role -> userRoleRepository.getOne(role.getId().toString())) .filter(Objects::nonNull) .collect(Collectors.toSet()); } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 25d8e95..e318401 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.password.PasswordEncoder; @@ -163,7 +164,7 @@ public class UserService implements UserDetailsService { userDto.getId())) { throw new UserLoginExistsException(userDto.getLogin()); } - User user = userRepository.findOne(userDto.getId()); + User user = userRepository.getOne(userDto.getId()); if (user == null) { throw new UserNotFoundException(userDto.getId().toString()); } @@ -215,7 +216,7 @@ public class UserService implements UserDetailsService { userDto.getId())) { throw new UserEmailExistsException(userDto.getEmail()); } - User user = userRepository.findOne(userDto.getId()); + User user = userRepository.getOne(userDto.getId()); if (user == null) { throw new UserNotFoundException(userDto.getId().toString()); } @@ -234,7 +235,7 @@ public class UserService implements UserDetailsService { if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) { throw new UserPasswordsNotValidOrNotMatchException(); } - final String login = UserUtils.getCurrentUserLogin(); + final String login = UserUtils.getCurrentUserLogin(SecurityContextHolder.getContext()); final User user = userRepository.findOneByLoginIgnoreCase(login); if (user == null) { throw new UserNotFoundException(login); @@ -280,7 +281,7 @@ public class UserService implements UserDetailsService { } public UserDto deleteUser(Integer userId) { - final User user = userRepository.findOne(userId); + final User user = userRepository.getOne(userId); if (user == null) { throw new UserNotFoundException(userId.toString()); } @@ -309,15 +310,15 @@ public class UserService implements UserDetailsService { } public List findByIds(List ids) { - return userRepository.findAll(ids); + return userRepository.findAllById(ids); } public User findById(Integer id) { - return userRepository.findOne(id); + return userRepository.getOne(id); } public User getCurrentUser() { - String login = UserUtils.getCurrentUserLogin(); + String login = UserUtils.getCurrentUserLogin(SecurityContextHolder.getContext()); User user = userRepository.findOneByLoginIgnoreCase(login); if (user == null) { throw new UserNotFoundException(login); diff --git a/src/main/java/ru/ulstu/user/util/UserUtils.java b/src/main/java/ru/ulstu/user/util/UserUtils.java index de585a5..377db6e 100644 --- a/src/main/java/ru/ulstu/user/util/UserUtils.java +++ b/src/main/java/ru/ulstu/user/util/UserUtils.java @@ -17,12 +17,15 @@ public class UserUtils { return RandomStringUtils.randomNumeric(DEF_COUNT); } - public static String getCurrentUserLogin() { - final SecurityContext securityContext = SecurityContextHolder.getContext(); + public static String getCurrentUserLogin(SecurityContext securityContext) { if (securityContext == null) { return null; } final Authentication authentication = securityContext.getAuthentication(); + + if (authentication == null) { + return "admin"; + } if (authentication.getPrincipal() instanceof UserDetails) { final UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal(); return springSecurityUser.getUsername(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fb1b116..62e6bbc 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -27,10 +27,15 @@ spring.datasource.username=postgres spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect +pring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true # Liquibase Settings -liquibase.drop-first=false -liquibase.enabled=true -liquibase.change-log=classpath:db/changelog-master.xml +#liquibase.drop-first=false +#liquibase.enabled=true +#liquibase.change-log=classpath:db/changelog-master.xml +spring.liquibase.change-log=classpath:db/changelog-master.xml +spring.liquibase.drop-first=false +spring.liquibase.enabled=true # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index a5ff6b5..6792be2 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -67,7 +67,7 @@ th:onclick="|$('#deadlines${rowStat.index}\\.description').val(''); $('#deadlines${rowStat.index}\\.date').val(''); $('#addDeadline').click();|"> + aria-hidden="true"> From 1487affb8e29bc5e65fc1326e58f5517f41c45f7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 20 Mar 2019 19:20:28 +0400 Subject: [PATCH 02/86] #73 fix deprecated annotations and classes --- .../java/ru/ulstu/configuration/ApplicationProperties.java | 3 ++- src/main/java/ru/ulstu/configuration/MvcConfiguration.java | 4 ++-- src/main/java/ru/ulstu/grant/model/Grant.java | 2 +- src/main/java/ru/ulstu/grant/model/GrantDto.java | 2 +- src/main/java/ru/ulstu/odin/model/OdinStringField.java | 2 +- src/main/java/ru/ulstu/paper/model/Paper.java | 2 +- src/main/java/ru/ulstu/paper/model/PaperDto.java | 2 +- src/main/java/ru/ulstu/project/model/Project.java | 2 +- src/main/java/ru/ulstu/project/model/ProjectDto.java | 2 +- src/main/java/ru/ulstu/timeline/model/Event.java | 2 +- src/main/java/ru/ulstu/timeline/model/EventDto.java | 2 +- src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java | 2 +- src/main/java/ru/ulstu/user/service/UserService.java | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java index 8615cb2..339bcb7 100644 --- a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java +++ b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java @@ -1,10 +1,11 @@ package ru.ulstu.configuration; -import org.hibernate.validator.constraints.NotBlank; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; +import javax.validation.constraints.NotBlank; + @Component @ConfigurationProperties(prefix = "ng-tracker") @Validated diff --git a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java index 3e8d66f..f9e887f 100644 --- a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java @@ -3,10 +3,10 @@ package ru.ulstu.configuration; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -public class MvcConfiguration extends WebMvcConfigurerAdapter { +public class MvcConfiguration implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/{articlename:\\w+}"); diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 685a1d5..09c2cdf 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -1,6 +1,5 @@ package ru.ulstu.grant.model; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; @@ -14,6 +13,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Comparator; diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index fb29164..1d0a43c 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -2,10 +2,10 @@ package ru.ulstu.grant.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.project.model.ProjectDto; +import javax.validation.constraints.NotEmpty; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ru/ulstu/odin/model/OdinStringField.java b/src/main/java/ru/ulstu/odin/model/OdinStringField.java index 5157d7e..498b375 100644 --- a/src/main/java/ru/ulstu/odin/model/OdinStringField.java +++ b/src/main/java/ru/ulstu/odin/model/OdinStringField.java @@ -1,9 +1,9 @@ package ru.ulstu.odin.model; -import org.hibernate.validator.constraints.Email; import ru.ulstu.odin.model.annotation.OdinString; import ru.ulstu.odin.model.annotation.OdinString.OdinStringType; +import javax.validation.constraints.Email; import javax.validation.constraints.Size; import java.lang.reflect.Field; diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index c09fd28..685a901 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -2,7 +2,6 @@ package ru.ulstu.paper.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; @@ -22,6 +21,7 @@ import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 3405768..c828381 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -3,10 +3,10 @@ package ru.ulstu.paper.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.user.model.UserDto; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 06722a1..896c53d 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -1,6 +1,5 @@ package ru.ulstu.project.model; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; @@ -8,6 +7,7 @@ import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index db7fc75..65f4365 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -2,9 +2,9 @@ package ru.ulstu.project.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import javax.validation.constraints.NotEmpty; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 290f136..f64963d 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -1,6 +1,5 @@ package ru.ulstu.timeline.model; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.user.model.User; @@ -16,6 +15,7 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 9e70a9d..b053d36 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -2,9 +2,9 @@ package ru.ulstu.timeline.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.user.model.UserDto; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java b/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java index 33d84bc..6da2813 100644 --- a/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java +++ b/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java @@ -1,8 +1,8 @@ package ru.ulstu.user.model; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.configuration.Constants; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Size; import java.util.Objects; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index e318401..198ffcd 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -94,7 +94,7 @@ public class UserService implements UserDetailsService { @Transactional(readOnly = true) public PageableItems getAllUsers(int offset, int count) { - final Page page = userRepository.findAll(new OffsetablePageRequest(offset, count, new Sort("id"))); + final Page page = userRepository.findAll(new OffsetablePageRequest(offset, count, Sort.by("id"))); return new PageableItems<>(page.getTotalElements(), userMapper.userEntitiesToUserListDtos(page.getContent())); } From 9bd954ea9b16904a183747d5b286be76072b9501 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 20 Mar 2019 20:31:46 +0400 Subject: [PATCH 03/86] #73 fix new thymeleaf syntax --- .../configuration/MailTemplateConfiguration.java | 15 +-------------- src/main/resources/templates/activate.html | 2 +- src/main/resources/templates/admin/commits.html | 2 +- src/main/resources/templates/admin/userList.html | 2 +- .../resources/templates/admin/userSessions.html | 2 +- .../templates/conferences/conference.html | 2 +- .../templates/conferences/conferences.html | 2 +- src/main/resources/templates/error/403.html | 2 +- src/main/resources/templates/error/404.html | 2 +- src/main/resources/templates/error/500.html | 2 +- .../resources/templates/grants/dashboard.html | 2 +- src/main/resources/templates/grants/grant.html | 5 ++--- src/main/resources/templates/grants/grants.html | 2 +- src/main/resources/templates/index.html | 2 +- src/main/resources/templates/load.html | 2 +- src/main/resources/templates/login.html | 2 +- .../resources/templates/papers/dashboard.html | 2 +- src/main/resources/templates/papers/paper.html | 4 ++-- src/main/resources/templates/papers/papers.html | 2 +- src/main/resources/templates/reset.html | 2 +- src/main/resources/templates/resetRequest.html | 2 +- src/main/resources/templates/timeline.html | 2 +- 22 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java index e212e5b..31de65c 100644 --- a/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MailTemplateConfiguration.java @@ -17,7 +17,6 @@ public class MailTemplateConfiguration { final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.addTemplateResolver(templateResolver); templateEngine.addTemplateResolver(emailTemplateResolver()); - templateEngine.addTemplateResolver(mvcTemplateResolver()); templateEngine.addDialect(new LayoutDialect()); templateEngine.addDialect(sec); return templateEngine; @@ -25,22 +24,10 @@ public class MailTemplateConfiguration { public ClassLoaderTemplateResolver emailTemplateResolver() { ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); - emailTemplateResolver.setPrefix("mail_templates/"); + emailTemplateResolver.setPrefix("/mail_templates/"); emailTemplateResolver.setTemplateMode("HTML"); emailTemplateResolver.setSuffix(".html"); - emailTemplateResolver.setOrder(2); emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); return emailTemplateResolver; } - - public ClassLoaderTemplateResolver mvcTemplateResolver() { - ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver(); - emailTemplateResolver.setPrefix("templates/"); - emailTemplateResolver.setTemplateMode("HTML"); - emailTemplateResolver.setSuffix(".html"); - emailTemplateResolver.setOrder(1); - emailTemplateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name()); - return emailTemplateResolver; - } - } diff --git a/src/main/resources/templates/activate.html b/src/main/resources/templates/activate.html index b20a284..d06cdc8 100644 --- a/src/main/resources/templates/activate.html +++ b/src/main/resources/templates/activate.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/admin/commits.html b/src/main/resources/templates/admin/commits.html index a8b8e85..9b2f115 100644 --- a/src/main/resources/templates/admin/commits.html +++ b/src/main/resources/templates/admin/commits.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/admin/userList.html b/src/main/resources/templates/admin/userList.html index b47f720..911601f 100644 --- a/src/main/resources/templates/admin/userList.html +++ b/src/main/resources/templates/admin/userList.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/admin/userSessions.html b/src/main/resources/templates/admin/userSessions.html index 2c3405a..12d3a61 100644 --- a/src/main/resources/templates/admin/userSessions.html +++ b/src/main/resources/templates/admin/userSessions.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 078e697..713c533 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index ab9fd31..b81d33c 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html index d850fa9..a80b444 100644 --- a/src/main/resources/templates/error/403.html +++ b/src/main/resources/templates/error/403.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html index 7233d72..8f1d80b 100644 --- a/src/main/resources/templates/error/404.html +++ b/src/main/resources/templates/error/404.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/error/500.html b/src/main/resources/templates/error/500.html index d42e7b4..f89b83a 100644 --- a/src/main/resources/templates/error/500.html +++ b/src/main/resources/templates/error/500.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/grants/dashboard.html b/src/main/resources/templates/grants/dashboard.html index b469875..12079d4 100644 --- a/src/main/resources/templates/grants/dashboard.html +++ b/src/main/resources/templates/grants/dashboard.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml"> diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index fc2878d..fe4d755 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -63,8 +63,7 @@ + $('#addDeadline').click();|"> diff --git a/src/main/resources/templates/grants/grants.html b/src/main/resources/templates/grants/grants.html index 83083a0..627d589 100644 --- a/src/main/resources/templates/grants/grants.html +++ b/src/main/resources/templates/grants/grants.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th=""> diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 40a1281..a4dbe74 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/load.html b/src/main/resources/templates/load.html index 70c6314..dbd991a 100644 --- a/src/main/resources/templates/load.html +++ b/src/main/resources/templates/load.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 9d87073..48e325e 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml"> diff --git a/src/main/resources/templates/papers/dashboard.html b/src/main/resources/templates/papers/dashboard.html index b7849f7..b677c84 100644 --- a/src/main/resources/templates/papers/dashboard.html +++ b/src/main/resources/templates/papers/dashboard.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml"> diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 6792be2..14befa7 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -67,7 +67,7 @@ th:onclick="|$('#deadlines${rowStat.index}\\.description').val(''); $('#deadlines${rowStat.index}\\.date').val(''); $('#addDeadline').click();|"> + aria-hidden="true"> diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index a797d26..d07ca07 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}" xmlns:th=""> diff --git a/src/main/resources/templates/reset.html b/src/main/resources/templates/reset.html index 232e260..c2dd78f 100644 --- a/src/main/resources/templates/reset.html +++ b/src/main/resources/templates/reset.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/resetRequest.html b/src/main/resources/templates/resetRequest.html index 2adab37..ef960f4 100644 --- a/src/main/resources/templates/resetRequest.html +++ b/src/main/resources/templates/resetRequest.html @@ -2,7 +2,7 @@ + layout:decorate="~{default}"> diff --git a/src/main/resources/templates/timeline.html b/src/main/resources/templates/timeline.html index 5eda9f3..0fdaddd 100644 --- a/src/main/resources/templates/timeline.html +++ b/src/main/resources/templates/timeline.html @@ -1,7 +1,7 @@ + layout:decorate="~{default}"> From 993a034527569b3aa180a5914dfbff6b14c8feb6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 20 Mar 2019 20:32:10 +0400 Subject: [PATCH 04/86] #73 restore authentication --- src/main/java/ru/ulstu/user/util/UserUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/ru/ulstu/user/util/UserUtils.java b/src/main/java/ru/ulstu/user/util/UserUtils.java index 377db6e..8524c74 100644 --- a/src/main/java/ru/ulstu/user/util/UserUtils.java +++ b/src/main/java/ru/ulstu/user/util/UserUtils.java @@ -23,9 +23,6 @@ public class UserUtils { } final Authentication authentication = securityContext.getAuthentication(); - if (authentication == null) { - return "admin"; - } if (authentication.getPrincipal() instanceof UserDetails) { final UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal(); return springSecurityUser.getUsername(); From 167de9bf656fec34bed94f7526c34504b2f97427 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 20 Mar 2019 20:35:24 +0400 Subject: [PATCH 05/86] #73 fix deprecated parameters --- src/main/resources/application.properties | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 62e6bbc..75bd2a4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,12 +2,11 @@ spring.main.banner-mode=off server.port=8443 server.http.port=8080 -spring.http.multipart.maxFileSize=20MB -spring.http.multipart.maxRequestSize=20MB +multipart.maxFileSize=20MB +multipart.maxRequestSize=20MB # Thymeleaf Settings spring.thymeleaf.cache=false # SSL Settings -security.require-ssl=true server.ssl.key-store=classpath:sample.jks server.ssl.key-store-password=secret server.ssl.key-password=password @@ -25,14 +24,9 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres spring.datasource.password=postgres -spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect -pring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false # Liquibase Settings -#liquibase.drop-first=false -#liquibase.enabled=true -#liquibase.change-log=classpath:db/changelog-master.xml spring.liquibase.change-log=classpath:db/changelog-master.xml spring.liquibase.drop-first=false spring.liquibase.enabled=true From 8fbce550286d4dcd6ba02dce5104690653f8cdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Wed, 17 Apr 2019 11:04:35 +0300 Subject: [PATCH 06/86] #86 projects main page --- .../project/controller/ProjectController.java | 39 +++++++++++++++++++ .../ulstu/project/service/ProjectService.java | 9 +++++ src/main/resources/templates/index.html | 2 +- .../templates/projects/dashboard.html | 24 ++++++++++++ .../fragments/projectNavigationFragment.html | 26 +++++++++++++ .../templates/projects/projects.html | 33 ++++++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/project/controller/ProjectController.java create mode 100644 src/main/resources/templates/projects/dashboard.html create mode 100644 src/main/resources/templates/projects/fragments/projectNavigationFragment.html create mode 100644 src/main/resources/templates/projects/projects.html diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java new file mode 100644 index 0000000..5b5eb4a --- /dev/null +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -0,0 +1,39 @@ +package ru.ulstu.project.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.model.ProjectDto; +import ru.ulstu.project.service.ProjectService; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static liquibase.util.StringUtils.isEmpty; + +@Controller() +@RequestMapping(value = "/projects") +@ApiIgnore +public class ProjectController { + private final ProjectService projectService; + + public ProjectController(ProjectService projectService) { + this.projectService = projectService; + } + + @GetMapping("/dashboard") + public void getDashboard(ModelMap modelMap) { + modelMap.put("projects", projectService.findAllDto()); + } + + @GetMapping("/projects") + public void getProjects(ModelMap modelMap) { + modelMap.put("projects", projectService.findAllDto()); + } +} diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index b54a60a..78a9d3c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -2,6 +2,7 @@ package ru.ulstu.project.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -10,9 +11,11 @@ import ru.ulstu.project.repository.ProjectRepository; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; +import static ru.ulstu.core.util.StreamApiUtils.convert; @Service public class ProjectService { + private final static int MAX_DISPLAY_SIZE = 40; private final ProjectRepository projectRepository; private final DeadlineService deadlineService; @@ -27,6 +30,12 @@ public class ProjectService { return projectRepository.findAll(); } + public List findAllDto() { + List projects = convert(findAll(), ProjectDto::new); + projects.forEach(projectDto -> projectDto.setTitle(StringUtils.abbreviate(projectDto.getTitle(), MAX_DISPLAY_SIZE))); + return projects; + } + @Transactional public Project create(ProjectDto projectDto) { Project newProject = copyFromDto(new Project(), projectDto); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 2d86945..6ca1c12 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -46,7 +46,7 @@
- +
diff --git a/src/main/resources/templates/projects/dashboard.html b/src/main/resources/templates/projects/dashboard.html new file mode 100644 index 0000000..882c202 --- /dev/null +++ b/src/main/resources/templates/projects/dashboard.html @@ -0,0 +1,24 @@ + + + + + +
+
+
+
+

Проекты

+
+
+
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectNavigationFragment.html b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html new file mode 100644 index 0000000..c26d8b8 --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html @@ -0,0 +1,26 @@ + + + + + + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/projects.html b/src/main/resources/templates/projects/projects.html new file mode 100644 index 0000000..0336770 --- /dev/null +++ b/src/main/resources/templates/projects/projects.html @@ -0,0 +1,33 @@ + + + + + +
+
+ +
+
+
+
+

Проекты

+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ + From 09cae66ca4126465f503c71ee4766c4cb1596d2d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 23 Apr 2019 12:38:15 +0400 Subject: [PATCH 07/86] fix image --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0effceb..1901408 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: romanov73/is:ng-tracker-container +image: romanov73/is:ng-tracker-container-11 variables: GRADLE_OPTS: "-Dorg.gradle.daemon=false" From e16b1da7613a1b20b1cce97d1962d695d905f980 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 23 Apr 2019 12:46:17 +0400 Subject: [PATCH 08/86] fix script --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1901408..b064dce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,11 +6,11 @@ variables: before_script: - service postgresql stop - service postgresql start - - eval $(ssh-agent -s) - - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null - - mkdir -p ~/.ssh - - chmod 700 ~/.ssh - - git log --pretty="%cn;%cd;%s" > src/main/resources/commits.log + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - git log --pretty="%cn;%cd;%s" > src/main/resources/commits.log build: stage: build From 955bdaa4381945dc8e1d34120ec26ed5089367cb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 23 Apr 2019 13:55:59 +0400 Subject: [PATCH 09/86] fix repository method --- src/main/java/ru/ulstu/project/service/ProjectService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index e2feef4..115f5ae 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -67,7 +67,7 @@ public class ProjectService { project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); project.setTitle(projectDto.getTitle()); if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) { - project.setGrant(grantRepository.findOne(projectDto.getGrant().getId())); + project.setGrant(grantRepository.getOne(projectDto.getGrant().getId())); } project.setRepository(projectDto.getRepository()); project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines())); From 9393fbe326c2e5c6260dc0c557f8a7465e566b7a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 26 Apr 2019 09:46:38 +0400 Subject: [PATCH 10/86] fix deprecated imports --- src/main/java/ru/ulstu/conference/model/Conference.java | 2 +- src/main/java/ru/ulstu/conference/model/ConferenceDto.java | 2 +- src/main/java/ru/ulstu/students/model/Task.java | 2 +- src/main/java/ru/ulstu/students/model/TaskDto.java | 2 +- src/main/java/ru/ulstu/tags/model/Tag.java | 2 +- src/main/java/ru/ulstu/timeline/model/Event.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index e252e4d..9831a0e 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -2,7 +2,6 @@ package ru.ulstu.conference.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.hibernate.validator.constraints.NotBlank; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; @@ -20,6 +19,7 @@ import javax.persistence.OrderBy; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 2e2f13b..5eca110 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -2,13 +2,13 @@ package ru.ulstu.conference.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index c4d7409..5646ef3 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -2,7 +2,6 @@ package ru.ulstu.students.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.tags.model.Tag; @@ -20,6 +19,7 @@ import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/students/model/TaskDto.java b/src/main/java/ru/ulstu/students/model/TaskDto.java index 941a6df..5071dab 100644 --- a/src/main/java/ru/ulstu/students/model/TaskDto.java +++ b/src/main/java/ru/ulstu/students/model/TaskDto.java @@ -3,10 +3,10 @@ package ru.ulstu.students.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.tags.model.Tag; +import javax.validation.constraints.NotEmpty; import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/tags/model/Tag.java b/src/main/java/ru/ulstu/tags/model/Tag.java index aed000f..460e9b0 100644 --- a/src/main/java/ru/ulstu/tags/model/Tag.java +++ b/src/main/java/ru/ulstu/tags/model/Tag.java @@ -2,12 +2,12 @@ package ru.ulstu.tags.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.core.model.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Size; @Entity diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index ef0a4b8..f8fd179 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -1,6 +1,5 @@ package ru.ulstu.timeline.model; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; @@ -17,6 +16,7 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.List; From 4d2d7fa1133834c574ab616ebbb5d55b2bc49d60 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 26 Apr 2019 09:47:41 +0400 Subject: [PATCH 11/86] fix lambda --- src/main/java/ru/ulstu/conference/model/ConferenceDto.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 5eca110..6264f62 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -3,6 +3,7 @@ package ru.ulstu.conference.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; @@ -88,8 +89,8 @@ public class ConferenceDto { this.beginDate = conference.getBeginDate(); this.endDate = conference.getEndDate(); this.deadlines = conference.getDeadlines(); - this.userIds = convert(conference.getUsers(), user -> user.getId()); - this.paperIds = convert(conference.getPapers(), paper -> paper.getId()); + this.userIds = convert(conference.getUsers(), BaseEntity::getId); + this.paperIds = convert(conference.getPapers(), BaseEntity::getId); this.users = conference.getUsers(); this.papers = conference.getPapers(); } From ee55e08feee4ea20dfa52403996f0659cd42f1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 6 May 2019 17:43:20 +0300 Subject: [PATCH 12/86] #98 project tasks deadline edited --- .../conference/service/ConferenceService.java | 3 +- .../ru/ulstu/deadline/model/Deadline.java | 35 ++++++++++++++++--- .../ru/ulstu/grant/service/GrantService.java | 2 +- .../ru/ulstu/paper/service/PaperService.java | 2 +- .../project/controller/ProjectController.java | 7 ++++ .../ru/ulstu/project/model/ProjectDto.java | 9 +++++ .../ulstu/project/service/ProjectService.java | 7 ++++ .../db/changelog-20190506_000000-schema.xml | 13 +++++++ src/main/resources/db/changelog-master.xml | 1 + .../resources/templates/projects/project.html | 8 +++-- 10 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/db/changelog-20190506_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..b42f981 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -267,7 +267,8 @@ public class ConferenceService { } public 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()); return newDeadline; } diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 148697c..9ab9acd 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -20,21 +20,30 @@ public class Deadline extends BaseEntity { @DateTimeFormat(pattern = "yyyy-MM-dd") private Date date; + private String executor; + private Boolean done; + public Deadline() { } - public Deadline(Date deadlineDate, String description) { + public Deadline(Date deadlineDate, String description, String executor, Boolean done) { this.date = deadlineDate; this.description = description; + this.executor = executor; + this.done = done; } @JsonCreator public Deadline(@JsonProperty("id") Integer id, @JsonProperty("description") String description, - @JsonProperty("date") Date date) { + @JsonProperty("date") Date date, + @JsonProperty("executor") String executor, + @JsonProperty("done") Boolean done) { this.setId(id); this.description = description; this.date = date; + this.executor = executor; + this.done = done; } public String getDescription() { @@ -53,6 +62,22 @@ public class Deadline extends BaseEntity { this.date = date; } + public String getExecutor() { + return executor; + } + + public void setExecutor(String executor) { + this.executor = executor; + } + + public Boolean getDone() { + return done; + } + + public void setDone(Boolean done) { + this.done = done; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -67,11 +92,13 @@ public class Deadline extends BaseEntity { Deadline deadline = (Deadline) o; return getId().equals(deadline.getId()) && description.equals(deadline.description) && - date.equals(deadline.date); + date.equals(deadline.date) && + executor.equals(deadline.executor) && + done.equals(deadline.done); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), description, date); + return Objects.hash(super.hashCode(), description, date, executor, done); } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 9cff4b6..0837b49 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -141,7 +141,7 @@ public class GrantService { grant.setComment("Комментарий к гранту 1"); grant.setProject(projectId); grant.setStatus(APPLICATION); - grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); grant.getAuthors().add(user); grant.setLeader(user); grant.getPapers().add(paper); diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index f98997d..1188c28 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -173,7 +173,7 @@ public class PaperService { Paper paper = new Paper(); paper.setTitle(title); paper.getAuthors().add(user); - paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); paper.setCreateDate(new Date()); paper.setUpdateDate(new Date()); paper.setStatus(DRAFT); diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index ae09658..14b8736 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -79,6 +79,13 @@ public class ProjectController { return "/projects/project"; } + @PostMapping(value = "/project", params = "removeDeadline") + public String removeDeadline(ProjectDto projectDto, + @RequestParam(value = "removeDeadline") Integer deadlineId) { + projectService.removeDeadline(projectDto, deadlineId); + return "/projects/project"; + } + @GetMapping("/delete/{project-id}") public String delete(@PathVariable("project-id") Integer projectId) throws IOException { projectService.delete(projectId); diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 4e03365..319609c 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -20,6 +20,7 @@ public class ProjectDto { private GrantDto grant; private String repository; private String applicationFileName; + private List removedDeadlineIds = new ArrayList<>(); public ProjectDto() { } @@ -121,4 +122,12 @@ public class ProjectDto { public void setApplicationFileName(String applicationFileName) { this.applicationFileName = applicationFileName; } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 247624d..4a79e6c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -104,6 +104,13 @@ public class ProjectService { } } + public void removeDeadline(ProjectDto projectDto, Integer deadlineId) { + if (projectDto.getDeadlines().get(deadlineId).getId() != null) { + projectDto.getRemovedDeadlineIds().add(projectDto.getDeadlines().get(deadlineId).getId()); + } + projectDto.getDeadlines().remove((int) deadlineId); + } + public Project findById(Integer id) { return projectRepository.findOne(id); } diff --git a/src/main/resources/db/changelog-20190506_000000-schema.xml b/src/main/resources/db/changelog-20190506_000000-schema.xml new file mode 100644 index 0000000..cd5a59b --- /dev/null +++ b/src/main/resources/db/changelog-20190506_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..3b455a8 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index dc3fa6d..cd49319 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -73,14 +73,18 @@
-
+
-
+
+
+ +
-
+
-
+
-
+
-
- -
+
+
+
+ +
+
+
From 4025aa67ca1720d75cdda18dcf4221868470f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 6 May 2019 21:51:58 +0300 Subject: [PATCH 14/86] #98 project completion added --- .../java/ru/ulstu/project/model/Project.java | 16 ++++++++ .../ru/ulstu/project/model/ProjectDto.java | 41 ++++++++++++++++++- .../db/changelog-20190506_000001-schema.xml | 17 ++++++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/public/css/project.css | 5 +++ .../resources/templates/projects/project.html | 15 +++---- 6 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/db/changelog-20190506_000001-schema.xml create mode 100644 src/main/resources/public/css/project.css diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index c971c4b..acf0d0f 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -5,17 +5,22 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Entity public class Project extends BaseEntity { @@ -62,6 +67,9 @@ public class Project extends BaseEntity { @JoinColumn(name = "file_id") private FileData application; + @ManyToMany(fetch = FetchType.EAGER) + private Set executors = new HashSet<>(); + public String getTitle() { return title; } @@ -117,4 +125,12 @@ public class Project extends BaseEntity { public void setApplication(FileData application) { this.application = application; } + + public Set getExecutors() { + return executors; + } + + public void setExecutors(Set executors) { + this.executors = executors; + } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 319609c..0f86e1a 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -3,11 +3,17 @@ package ru.ulstu.project.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; +import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.user.model.UserDto; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static ru.ulstu.core.util.StreamApiUtils.convert; public class ProjectDto { private Integer id; @@ -21,6 +27,10 @@ public class ProjectDto { private String repository; private String applicationFileName; private List removedDeadlineIds = new ArrayList<>(); + private Set executorIds; + private Set executors; + + private final static int MAX_EXECUTORS_LENGTH = 40; public ProjectDto() { } @@ -36,7 +46,9 @@ public class ProjectDto { @JsonProperty("description") String description, @JsonProperty("grant") GrantDto grant, @JsonProperty("repository") String repository, - @JsonProperty("deadlines") List deadlines) { + @JsonProperty("deadlines") List deadlines, + @JsonProperty("executorIds") Set executorIds, + @JsonProperty("executors") Set executors) { this.id = id; this.title = title; this.status = status; @@ -45,6 +57,8 @@ public class ProjectDto { this.repository = repository; this.deadlines = deadlines; this.applicationFileName = null; + this.executorIds = executorIds; + this.executors = executors; } @@ -57,6 +71,8 @@ public class ProjectDto { this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); + this.executorIds = convert(project.getExecutors(), user -> user.getId()); + this.executors = convert(project.getExecutors(), UserDto::new); } public Integer getId() { @@ -130,4 +146,27 @@ public class ProjectDto { public void setRemovedDeadlineIds(List removedDeadlineIds) { this.removedDeadlineIds = removedDeadlineIds; } + + public Set getExecutorIds() { + return executorIds; + } + + public void setExecutorIds(Set executorIds) { + this.executorIds = executorIds; + } + + public Set getExecutors() { + return executors; + } + + public void setExecutors(Set executors) { + this.executors = executors; + } + + public String getExecutorsString() { + return StringUtils.abbreviate(executors + .stream() + .map(executor -> executor.getLastName()) + .collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH); + } } diff --git a/src/main/resources/db/changelog-20190506_000001-schema.xml b/src/main/resources/db/changelog-20190506_000001-schema.xml new file mode 100644 index 0000000..e28d009 --- /dev/null +++ b/src/main/resources/db/changelog-20190506_000001-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 3b455a8..051c953 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -39,4 +39,5 @@ + \ No newline at end of file diff --git a/src/main/resources/public/css/project.css b/src/main/resources/public/css/project.css new file mode 100644 index 0000000..24e12ea --- /dev/null +++ b/src/main/resources/public/css/project.css @@ -0,0 +1,5 @@ +.div-deadline-done { + width: 60%; + height: 100%; + float: right; +} \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 2a0b7cf..8385694 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -3,7 +3,7 @@ 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"> - + @@ -90,17 +90,18 @@ aria-hidden="true">
-
-

Incorrect title

-
-
-
+
+
+ +
+

Incorrect title

Date: Mon, 6 May 2019 22:10:40 +0300 Subject: [PATCH 15/86] #98 deadline edited --- src/main/java/ru/ulstu/deadline/model/Deadline.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 5a05ea1..9ab9acd 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -66,7 +66,9 @@ public class Deadline extends BaseEntity { return executor; } - public void setExecutor(String executor) { this.executor = executor; } + public void setExecutor(String executor) { + this.executor = executor; + } public Boolean getDone() { return done; From b1e101c94036eb56b7d6c9d67667179433ae0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 7 May 2019 13:34:00 +0300 Subject: [PATCH 16/86] #101 db event edited --- .../db/changelog-20190507_000000-schema.xml | 14 ++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 15 insertions(+) create mode 100644 src/main/resources/db/changelog-20190507_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190507_000000-schema.xml b/src/main/resources/db/changelog-20190507_000000-schema.xml new file mode 100644 index 0000000..6962e7d --- /dev/null +++ b/src/main/resources/db/changelog-20190507_000000-schema.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..65a07c2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file From 279cc0e18a876ee6bf70fc06087680162cbd45ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 7 May 2019 14:00:24 +0300 Subject: [PATCH 17/86] #101 project model edited --- src/main/java/ru/ulstu/project/model/Project.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index c971c4b..a596b76 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -5,11 +5,13 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.timeline.model.Event; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -62,6 +64,10 @@ public class Project extends BaseEntity { @JoinColumn(name = "file_id") private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(name = "project_id") + private List events = new ArrayList<>(); + public String getTitle() { return title; } @@ -117,4 +123,12 @@ public class Project extends BaseEntity { public void setApplication(FileData application) { this.application = application; } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } } From f960d4de1b78cd9a8cd01ea43bdd6304fcc7d844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Fri, 17 May 2019 11:30:26 +0300 Subject: [PATCH 18/86] #98 deadline model edited --- src/main/java/ru/ulstu/deadline/model/Deadline.java | 5 +++++ src/main/java/ru/ulstu/grant/service/GrantService.java | 2 +- src/main/java/ru/ulstu/paper/service/PaperService.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 9ab9acd..5ab9f47 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -26,6 +26,11 @@ public class Deadline extends BaseEntity { public Deadline() { } + public Deadline(Date deadlineDate, String description) { + this.date = deadlineDate; + this.description = description; + } + public Deadline(Date deadlineDate, String description, String executor, Boolean done) { this.date = deadlineDate; this.description = description; diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index c06a71c..45f9b2f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -164,7 +164,7 @@ public class GrantService { grant.setComment("Комментарий к гранту 1"); grant.setProject(projectId); grant.setStatus(APPLICATION); - grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); + grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); grant.getAuthors().add(user); grant.setLeader(user); grant.getPapers().add(paper); diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0a60c92..db810f5 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -173,7 +173,7 @@ public class PaperService { Paper paper = new Paper(); paper.setTitle(title); paper.getAuthors().add(user); - paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); + paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); paper.setCreateDate(new Date()); paper.setUpdateDate(new Date()); paper.setStatus(DRAFT); From d7c4e6b22264bbd76b35fae997fb8fbfeb328d1c Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Tue, 21 May 2019 02:09:07 +0400 Subject: [PATCH 19/86] #91 base users dashboard --- .../repository/ConferenceRepository.java | 4 + .../conference/service/ConferenceService.java | 4 + .../service/ConferenceUserService.java | 2 - .../user/controller/UserMvcController.java | 5 + .../java/ru/ulstu/user/model/UserInfoNow.java | 50 ++++++++++ .../repository/UserSessionRepository.java | 3 + .../ru/ulstu/user/service/UserService.java | 37 ++++++- .../user/service/UserSessionService.java | 6 ++ .../utils/timetable/TimetableService.java | 97 +++++++++++++++++++ .../ru/ulstu/utils/timetable/model/Day.java | 27 ++++++ .../ulstu/utils/timetable/model/Lesson.java | 27 ++++++ .../ulstu/utils/timetable/model/Response.java | 16 +++ .../timetable/model/TimetableResponse.java | 22 +++++ .../ru/ulstu/utils/timetable/model/Week.java | 16 +++ .../resources/templates/users/dashboard.html | 24 +++++ .../fragments/userDashboardFragment.html | 18 ++++ 16 files changed, 355 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/UserInfoNow.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/TimetableService.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/model/Day.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/model/Lesson.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/model/Response.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java create mode 100644 src/main/java/ru/ulstu/utils/timetable/model/Week.java create mode 100644 src/main/resources/templates/users/dashboard.html create mode 100644 src/main/resources/templates/users/fragments/userDashboardFragment.html diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 2b0a428..8f9e05f 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -29,4 +29,8 @@ public interface ConferenceRepository extends JpaRepository @Override @Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ") String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); + + @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + + "AND (u.participation = 'INTRAMURAL') AND (c.beginDate <= CURRENT_DATE) AND (c.endDate >= CURRENT_DATE)") + Conference findActiveByUser(@Param("user") User user); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38ce659..1a5db52 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -306,4 +306,8 @@ public class ConferenceService extends BaseService { .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + public Conference getActiveConferenceByUser(User user) { + return conferenceRepository.findActiveByUser(user); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java index f771b2a..16842c1 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceUserService.java @@ -43,6 +43,4 @@ public class ConferenceUserService { newUser = conferenceUserRepository.save(newUser); return newUser; } - - } diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 5bcbd13..d283a21 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -48,4 +48,9 @@ public class UserMvcController extends OdinController { User user = userSessionService.getUserBySessionId(sessionId); modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto)); } + + @GetMapping("/dashboard") + public void getUsersDashboard(ModelMap modelMap) { + modelMap.addAttribute("users", userService.getUsersInfo()); + } } diff --git a/src/main/java/ru/ulstu/user/model/UserInfoNow.java b/src/main/java/ru/ulstu/user/model/UserInfoNow.java new file mode 100644 index 0000000..7d69c56 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/UserInfoNow.java @@ -0,0 +1,50 @@ +package ru.ulstu.user.model; + +import ru.ulstu.conference.model.Conference; +import ru.ulstu.utils.timetable.model.Lesson; + +public class UserInfoNow { + private Lesson lesson; + private Conference conference; + private User user; + private boolean isOnline; + + public UserInfoNow(Lesson lesson, Conference conference, User user, boolean isOnline) { + this.lesson = lesson; + this.conference = conference; + this.user = user; + this.isOnline = isOnline; + } + + public Lesson getLesson() { + return lesson; + } + + public void setLesson(Lesson lesson) { + this.lesson = lesson; + } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public boolean isOnline() { + return isOnline; + } + + public void setOnline(boolean online) { + isOnline = online; + } +} diff --git a/src/main/java/ru/ulstu/user/repository/UserSessionRepository.java b/src/main/java/ru/ulstu/user/repository/UserSessionRepository.java index b922e4f..5319245 100644 --- a/src/main/java/ru/ulstu/user/repository/UserSessionRepository.java +++ b/src/main/java/ru/ulstu/user/repository/UserSessionRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.user.repository; import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserSession; import java.util.Date; @@ -10,4 +11,6 @@ public interface UserSessionRepository extends JpaRepository findAllByLogoutTimeIsNullAndLoginTimeBefore(Date date); + + List findAllByUserAndLogoutTimeIsNullAndLoginTimeBefore(User user, Date date); } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index c889caa..334fbf5 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -3,6 +3,7 @@ package ru.ulstu.user.service; import com.google.common.collect.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.mail.MailException; @@ -13,6 +14,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.core.error.EntityIdIsNullException; import ru.ulstu.core.jpa.OffsetablePageRequest; @@ -30,6 +32,7 @@ import ru.ulstu.user.error.UserResetKeyError; import ru.ulstu.user.error.UserSendingMailException; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; +import ru.ulstu.user.model.UserInfoNow; import ru.ulstu.user.model.UserListDto; import ru.ulstu.user.model.UserResetPasswordDto; import ru.ulstu.user.model.UserRole; @@ -38,8 +41,13 @@ import ru.ulstu.user.model.UserRoleDto; import ru.ulstu.user.repository.UserRepository; import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.util.UserUtils; +import ru.ulstu.utils.timetable.TimetableService; +import ru.ulstu.utils.timetable.model.Lesson; import javax.mail.MessagingException; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -62,19 +70,27 @@ public class UserService implements UserDetailsService { private final UserMapper userMapper; private final MailService mailService; private final ApplicationProperties applicationProperties; + private final TimetableService timetableService; + private final ConferenceService conferenceService; + private final UserSessionService userSessionService; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, UserRoleRepository userRoleRepository, UserMapper userMapper, MailService mailService, - ApplicationProperties applicationProperties) { + ApplicationProperties applicationProperties, + @Lazy ConferenceService conferenceRepository, + @Lazy UserSessionService userSessionService) throws ParseException { this.userRepository = userRepository; this.passwordEncoder = passwordEncoder; this.userRoleRepository = userRoleRepository; this.userMapper = userMapper; this.mailService = mailService; this.applicationProperties = applicationProperties; + this.conferenceService = conferenceRepository; + this.timetableService = new TimetableService(); + this.userSessionService = userSessionService; } private User getUserByEmail(String email) { @@ -341,4 +357,23 @@ public class UserService implements UserDetailsService { throw new UserSendingMailException(email); } } + + public List getUsersInfo() { + List usersInfoNow = new ArrayList<>(); + for (User user : userRepository.findAll()) { + Lesson lesson = null; + try { + lesson = timetableService.getCurrentLesson(user.getUserAbbreviate()); + } catch (IOException e) { + e.printStackTrace(); + } + usersInfoNow.add(new UserInfoNow( + lesson, + conferenceService.getActiveConferenceByUser(user), + user, + userSessionService.isOnline(user)) + ); + } + return usersInfoNow; + } } diff --git a/src/main/java/ru/ulstu/user/service/UserSessionService.java b/src/main/java/ru/ulstu/user/service/UserSessionService.java index ae289d0..17a7f5b 100644 --- a/src/main/java/ru/ulstu/user/service/UserSessionService.java +++ b/src/main/java/ru/ulstu/user/service/UserSessionService.java @@ -14,6 +14,8 @@ import ru.ulstu.user.model.UserSession; import ru.ulstu.user.model.UserSessionListDto; import ru.ulstu.user.repository.UserSessionRepository; +import java.util.Date; + import static ru.ulstu.core.util.StreamApiUtils.convert; @Service @@ -58,4 +60,8 @@ public class UserSessionService { public User getUserBySessionId(String sessionId) { return userSessionRepository.findOneBySessionId(sessionId).getUser(); } + + public boolean isOnline(User user) { + return !userSessionRepository.findAllByUserAndLogoutTimeIsNullAndLoginTimeBefore(user, new Date()).isEmpty(); + } } diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java new file mode 100644 index 0000000..f17ea86 --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -0,0 +1,97 @@ +package ru.ulstu.utils.timetable; + +import com.fasterxml.jackson.databind.ObjectMapper; +import ru.ulstu.utils.timetable.model.Lesson; +import ru.ulstu.utils.timetable.model.TimetableResponse; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +public class TimetableService { + private static final String TIMETABLE_URL = "http://timetable.athene.tech"; + private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm"); + + private long[] lessonsStarts = new long[]{ + lessonTimeFormat.parse("8:00:00").getTime(), + lessonTimeFormat.parse("9:40:00").getTime(), + lessonTimeFormat.parse("11:30:00").getTime(), + lessonTimeFormat.parse("13:10:00").getTime(), + lessonTimeFormat.parse("14:50:00").getTime(), + lessonTimeFormat.parse("16:30:00").getTime(), + lessonTimeFormat.parse("18:10:00").getTime(), + }; + + public TimetableService() throws ParseException { } + + private int getCurrentDay() { + Calendar calendar = Calendar.getInstance(); + int day = calendar.get(Calendar.DAY_OF_WEEK); + return (day + 5) % 7; + } + + private int getCurrentLessonNumber() { + long lessonDuration = 90 * 60000; + Date now = new Date(); + long timeNow = now.getTime() % (24 * 60 * 60 * 1000L); + for (int i = 0; i < lessonsStarts.length; i++) { + if (timeNow > lessonsStarts[i] && timeNow < lessonsStarts[i] + lessonDuration) { + return i; + } + } + return -1; + } + + private int getCurrentWeek() { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + return (cal.get(Calendar.WEEK_OF_YEAR) + 1) % 2; + } + + private TimetableResponse getTimetableForUser(String userFIO) throws IOException { + URL url = new URL(TIMETABLE_URL + "/api/1.0/timetable?filter=" + URLEncoder.encode(userFIO, "UTF-8")); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuilder content = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + return new ObjectMapper().readValue(content.toString(), TimetableResponse.class); + } + + public Lesson getCurrentLesson(String userFio) throws IOException { + TimetableResponse response = getTimetableForUser(userFio); + int lessonNumber = getCurrentLessonNumber(); + if (lessonNumber < 0) { + return null; + } + + List lessons = response + .getResponse() + .getWeeks() + .get(getCurrentWeek()) + .getDays() + .get(getCurrentDay()) + .getLessons() + .get(lessonNumber); + + if (lessons.size() == 0) { + return null; + } + return new ObjectMapper().convertValue(lessons.get(0), Lesson.class); + } +} diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Day.java b/src/main/java/ru/ulstu/utils/timetable/model/Day.java new file mode 100644 index 0000000..f548462 --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/model/Day.java @@ -0,0 +1,27 @@ +package ru.ulstu.utils.timetable.model; + +import java.util.List; + + +public class Day { + + private Integer day; + private List> lessons = null; + + public Integer getDay() { + return day; + } + + public void setDay(Integer day) { + this.day = day; + } + + public List> getLessons() { + return lessons; + } + + public void setLessons(List> lessons) { + this.lessons = lessons; + } +} + diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java new file mode 100644 index 0000000..e651e1a --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java @@ -0,0 +1,27 @@ +package ru.ulstu.utils.timetable.model; + +public class Lesson { + private String group; + private String nameOfLesson; + private String teacher; + private String room; + + public Lesson() { + } + + public String getGroup() { + return group; + } + + public String getNameOfLesson() { + return nameOfLesson; + } + + public String getTeacher() { + return teacher; + } + + public String getRoom() { + return room; + } +} diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Response.java b/src/main/java/ru/ulstu/utils/timetable/model/Response.java new file mode 100644 index 0000000..b5b9e97 --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/model/Response.java @@ -0,0 +1,16 @@ +package ru.ulstu.utils.timetable.model; + +import java.util.List; + +public class Response { + + private List weeks = null; + + public List getWeeks() { + return weeks; + } + + public void setWeeks(List weeks) { + this.weeks = weeks; + } +} diff --git a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java new file mode 100644 index 0000000..118c979 --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java @@ -0,0 +1,22 @@ +package ru.ulstu.utils.timetable.model; + +public class TimetableResponse { + private Response response; + private String error; + + public Response getResponse() { + return response; + } + + public void setResponse(Response response) { + this.response = response; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } +} diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Week.java b/src/main/java/ru/ulstu/utils/timetable/model/Week.java new file mode 100644 index 0000000..19f3c50 --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/model/Week.java @@ -0,0 +1,16 @@ +package ru.ulstu.utils.timetable.model; + +import java.util.List; + +public class Week { + + private List days = null; + + public List getDays() { + return days; + } + + public void setDays(List days) { + this.days = days; + } +} diff --git a/src/main/resources/templates/users/dashboard.html b/src/main/resources/templates/users/dashboard.html new file mode 100644 index 0000000..8236734 --- /dev/null +++ b/src/main/resources/templates/users/dashboard.html @@ -0,0 +1,24 @@ + + + + + + +
+
+
+
+

Пользователи

+
+
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/users/fragments/userDashboardFragment.html b/src/main/resources/templates/users/fragments/userDashboardFragment.html new file mode 100644 index 0000000..267bbf8 --- /dev/null +++ b/src/main/resources/templates/users/fragments/userDashboardFragment.html @@ -0,0 +1,18 @@ + + + + + + +
+
+
+

+

+

+

Онлайн

+
+
+
+ + \ No newline at end of file From ecda92326be467704b9e4e51128ee4440bc4ba45 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 16:04:51 +0400 Subject: [PATCH 20/86] #103 create blank classes --- src/test/java/grant/GrantPage.java | 10 ++++++++++ src/test/java/grant/GrantsDashboardPage.java | 10 ++++++++++ src/test/java/grant/GrantsPage.java | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/test/java/grant/GrantPage.java create mode 100644 src/test/java/grant/GrantsDashboardPage.java create mode 100644 src/test/java/grant/GrantsPage.java diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java new file mode 100644 index 0000000..a0eee3c --- /dev/null +++ b/src/test/java/grant/GrantPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java new file mode 100644 index 0000000..02939e1 --- /dev/null +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsDashboardPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java new file mode 100644 index 0000000..9d8d6cf --- /dev/null +++ b/src/test/java/grant/GrantsPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} From b1c090b0eaf5411ab8d75cb209e2f3143bedecb2 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:11:06 +0400 Subject: [PATCH 21/86] #103 add selenium-support library --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 38de2c7..bd3f6e8 100644 --- a/build.gradle +++ b/build.gradle @@ -127,5 +127,6 @@ dependencies { 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-support', version: '3.3.1' } \ No newline at end of file From 16885cc94f41a50fb9dae5ce7e1de64dfd68e575 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:12:30 +0400 Subject: [PATCH 22/86] #103 update overriding method --- src/test/java/grant/GrantsDashboardPage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java index 02939e1..036e785 100644 --- a/src/test/java/grant/GrantsDashboardPage.java +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -1,10 +1,11 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; public class GrantsDashboardPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); } } From 3e9bbb35840e11c06176be961109df1e55d2bcbe Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:15:04 +0400 Subject: [PATCH 23/86] #103 create tests for create, update and delete functions --- src/test/java/IndexGrantTest.java | 92 +++++++++++++++++++++++++++++ src/test/java/grant/GrantPage.java | 40 ++++++++++++- src/test/java/grant/GrantsPage.java | 30 +++++++++- 3 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/test/java/IndexGrantTest.java diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java new file mode 100644 index 0000000..064b2c7 --- /dev/null +++ b/src/test/java/IndexGrantTest.java @@ -0,0 +1,92 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import core.PageObject; +import core.TestTemplate; +import grant.GrantPage; +import grant.GrantsDashboardPage; +import grant.GrantsPage; +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 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 IndexGrantTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), + new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), + new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void createNewGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newGrantName = "test grant" + (new Date()); + grantPage.setTitle(newGrantName); + String deadlineDate = new Date().toString(); + String deadlineDescription = "test deadline description"; + grantPage.setDeadline(deadlineDate, 0, deadlineDescription); + grantPage.setLeader(); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName)); + } + + @Test + public void createBlankGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + + grantPage.saveGrant(); + + Assert.assertTrue(grantPage.checkBlankFields()); + } + + @Test + public void updateGrantTitle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String newGrantTitle = "test " + (new Date()); + grantPage.setTitle(newGrantTitle); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle)); + } + + @Test + public void deleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } +} diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index a0eee3c..1754db5 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -1,10 +1,48 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; public class GrantPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setTitle(String name) { + driver.findElement(By.id("title")).clear(); + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getTitle() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void setDeadline(String date, Integer i, String description) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setLeader() { + WebElement webElement = driver.findElement(By.id("leaderId")); + Select selectLeader = new Select(webElement); + selectLeader.selectByVisibleText("Романов"); + } + + public void saveGrant() { + driver.findElement(By.id("sendMessageButton")).click(); + } + + public boolean checkBlankFields() { + if (driver.findElements(By.className("alert-danger")).size() > 0) { + return true; + } + return false; } } diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java index 9d8d6cf..68f50db 100644 --- a/src/test/java/grant/GrantsPage.java +++ b/src/test/java/grant/GrantsPage.java @@ -1,10 +1,38 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class GrantsPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getGrantsList() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public boolean findGrantByTitle(String grantTitle) { + return getGrantsList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(grantTitle)); + } + + public void deleteFirst() throws InterruptedException { + WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div")); + findDeleteButton.click(); + Thread.sleep(3000); + WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]")); + grant.click(); + WebElement ok = driver.findElement(By.id("dataConfirmOK")); + ok.click(); + } + + public void getFirstGrant() { + driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); } } From 47131f1fb777c3ecbf087dbf67bbc9dcb8948046 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 23 May 2019 13:43:18 +0400 Subject: [PATCH 24/86] #103 add tests for papers --- src/test/java/IndexGrantTest.java | 30 ++++++++++++++++++++++- src/test/java/grant/GrantPage.java | 38 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java index 064b2c7..c633cfa 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/IndexGrantTest.java @@ -81,7 +81,6 @@ public class IndexGrantTest extends TestTemplate { @Test public void deleteGrant() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -89,4 +88,33 @@ public class IndexGrantTest extends TestTemplate { grantsPage.deleteFirst(); Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); } + + @Test + public void attachPaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer countPapers = grantPage.getAttachedPapers().size(); + + Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); + } + + @Test + public void deletePaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer oldCountPapers = grantPage.getAttachedPapers().size(); + if (oldCountPapers == 0) { + oldCountPapers = grantPage.attachPaper().size(); + } + + Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 1754db5..809e22f 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -5,6 +5,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; +import java.util.List; + public class GrantPage extends PageObject { @Override public String getSubTitle() { @@ -45,4 +47,40 @@ public class GrantPage extends PageObject { } return false; } + + public List getAttachedPapers() { + try { + return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); + } catch (Exception ex) { + return null; + } + } + + public List attachPaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + if (selectedOptions.size() >= allOptions.size()) { + for (int i = 0; i < allOptions.size(); i++) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } + } + } else { + select.selectByVisibleText(allOptions.get(0).getText()); + selectedOptions.add(allOptions.get(0)); + return selectedOptions; + } + return null; + } + + public List deletePaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + select.deselectByVisibleText(select.getFirstSelectedOption().getText()); + return select.getAllSelectedOptions(); + } } From 308da4113d395005204741494b71d85bcf252271 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 24 May 2019 13:26:02 +0400 Subject: [PATCH 25/86] fix week number calculation --- .../ru/ulstu/utils/timetable/TimetableService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java index aa49fed..d65e276 100644 --- a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -3,6 +3,7 @@ package ru.ulstu.utils.timetable; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +import ru.ulstu.core.util.DateUtils; import ru.ulstu.utils.timetable.errors.TimetableClientException; import ru.ulstu.utils.timetable.model.Lesson; import ru.ulstu.utils.timetable.model.TimetableResponse; @@ -50,9 +51,15 @@ public class TimetableService { } private int getCurrentWeek() { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - return (cal.get(Calendar.WEEK_OF_YEAR) + 1) % 2; + Date currentDate = Calendar.getInstance().getTime(); + currentDate = DateUtils.clearTime(currentDate); + + Calendar firstJan = Calendar.getInstance(); + firstJan.set(Calendar.MONTH, 0); + firstJan.set(Calendar.DAY_OF_MONTH, 1); + + return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) + + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); } private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException { From 193b2b3a3255f45274f299364e8c398f9f1ce3ad Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sat, 25 May 2019 14:03:43 +0400 Subject: [PATCH 26/86] #91 using RestTemplate & show error on timetable loading exception --- .../user/controller/UserMvcController.java | 2 +- .../ru/ulstu/user/service/UserService.java | 12 +++-- .../utils/timetable/TimetableService.java | 46 ++++++++----------- .../errors/TimetableClientException.java | 7 +++ .../ru/ulstu/utils/timetable/model/Day.java | 9 ++-- .../ulstu/utils/timetable/model/Lesson.java | 5 +- .../ulstu/utils/timetable/model/Response.java | 3 +- .../timetable/model/TimetableResponse.java | 2 +- .../ru/ulstu/utils/timetable/model/Week.java | 6 ++- src/main/resources/application.properties | 4 +- .../resources/templates/users/dashboard.html | 13 +++++- 11 files changed, 62 insertions(+), 47 deletions(-) create mode 100644 src/main/java/ru/ulstu/utils/timetable/errors/TimetableClientException.java diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index d283a21..044bde8 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -51,6 +51,6 @@ public class UserMvcController extends OdinController { @GetMapping("/dashboard") public void getUsersDashboard(ModelMap modelMap) { - modelMap.addAttribute("users", userService.getUsersInfo()); + modelMap.addAllAttributes(userService.getUsersInfo()); } } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 334fbf5..b022866 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -42,10 +42,10 @@ import ru.ulstu.user.repository.UserRepository; import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.util.UserUtils; import ru.ulstu.utils.timetable.TimetableService; +import ru.ulstu.utils.timetable.errors.TimetableClientException; import ru.ulstu.utils.timetable.model.Lesson; import javax.mail.MessagingException; -import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; @@ -358,14 +358,16 @@ public class UserService implements UserDetailsService { } } - public List getUsersInfo() { + public Map getUsersInfo() { List usersInfoNow = new ArrayList<>(); + String err = ""; + for (User user : userRepository.findAll()) { Lesson lesson = null; try { lesson = timetableService.getCurrentLesson(user.getUserAbbreviate()); - } catch (IOException e) { - e.printStackTrace(); + } catch (TimetableClientException e) { + err = "Не удалось загрузить расписание"; } usersInfoNow.add(new UserInfoNow( lesson, @@ -374,6 +376,6 @@ public class UserService implements UserDetailsService { userSessionService.isOnline(user)) ); } - return usersInfoNow; + return ImmutableMap.of("users", usersInfoNow, "error", err); } } diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java index f17ea86..aa49fed 100644 --- a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -1,15 +1,12 @@ package ru.ulstu.utils.timetable; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import ru.ulstu.utils.timetable.errors.TimetableClientException; import ru.ulstu.utils.timetable.model.Lesson; import ru.ulstu.utils.timetable.model.TimetableResponse; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -17,10 +14,10 @@ import java.util.Date; import java.util.List; public class TimetableService { - private static final String TIMETABLE_URL = "http://timetable.athene.tech"; + private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s"; private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm"); - private long[] lessonsStarts = new long[]{ + private long[] lessonsStarts = new long[] { lessonTimeFormat.parse("8:00:00").getTime(), lessonTimeFormat.parse("9:40:00").getTime(), lessonTimeFormat.parse("11:30:00").getTime(), @@ -30,7 +27,8 @@ public class TimetableService { lessonTimeFormat.parse("18:10:00").getTime(), }; - public TimetableService() throws ParseException { } + public TimetableService() throws ParseException { + } private int getCurrentDay() { Calendar calendar = Calendar.getInstance(); @@ -42,6 +40,7 @@ public class TimetableService { long lessonDuration = 90 * 60000; Date now = new Date(); long timeNow = now.getTime() % (24 * 60 * 60 * 1000L); + for (int i = 0; i < lessonsStarts.length; i++) { if (timeNow > lessonsStarts[i] && timeNow < lessonsStarts[i] + lessonDuration) { return i; @@ -56,31 +55,26 @@ public class TimetableService { return (cal.get(Calendar.WEEK_OF_YEAR) + 1) % 2; } - private TimetableResponse getTimetableForUser(String userFIO) throws IOException { - URL url = new URL(TIMETABLE_URL + "/api/1.0/timetable?filter=" + URLEncoder.encode(userFIO, "UTF-8")); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("GET"); + private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException { + RestTemplate restTemplate = new RestTemplate(); + return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class); + } - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuilder content = new StringBuilder(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); + public Lesson getCurrentLesson(String userFio) { + TimetableResponse response; + try { + response = getTimetableForUser(userFio); + } catch (RestClientException e) { + e.printStackTrace(); + throw new TimetableClientException(userFio); } - in.close(); - - return new ObjectMapper().readValue(content.toString(), TimetableResponse.class); - } - public Lesson getCurrentLesson(String userFio) throws IOException { - TimetableResponse response = getTimetableForUser(userFio); int lessonNumber = getCurrentLessonNumber(); if (lessonNumber < 0) { return null; } - List lessons = response + List lessons = response .getResponse() .getWeeks() .get(getCurrentWeek()) diff --git a/src/main/java/ru/ulstu/utils/timetable/errors/TimetableClientException.java b/src/main/java/ru/ulstu/utils/timetable/errors/TimetableClientException.java new file mode 100644 index 0000000..4723bda --- /dev/null +++ b/src/main/java/ru/ulstu/utils/timetable/errors/TimetableClientException.java @@ -0,0 +1,7 @@ +package ru.ulstu.utils.timetable.errors; + +public class TimetableClientException extends RuntimeException { + public TimetableClientException(String message) { + super(message); + } +} diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Day.java b/src/main/java/ru/ulstu/utils/timetable/model/Day.java index f548462..e4e37f9 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Day.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Day.java @@ -1,12 +1,13 @@ package ru.ulstu.utils.timetable.model; +import java.util.ArrayList; import java.util.List; -public class Day { +public class Day { private Integer day; - private List> lessons = null; + private List> lessons = new ArrayList<>(); public Integer getDay() { return day; @@ -16,11 +17,11 @@ public class Day { this.day = day; } - public List> getLessons() { + public List> getLessons() { return lessons; } - public void setLessons(List> lessons) { + public void setLessons(List> lessons) { this.lessons = lessons; } } diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java index e651e1a..b1b1707 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java @@ -1,14 +1,11 @@ package ru.ulstu.utils.timetable.model; -public class Lesson { +public class Lesson { private String group; private String nameOfLesson; private String teacher; private String room; - public Lesson() { - } - public String getGroup() { return group; } diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Response.java b/src/main/java/ru/ulstu/utils/timetable/model/Response.java index b5b9e97..dfd3a84 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Response.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Response.java @@ -1,10 +1,11 @@ package ru.ulstu.utils.timetable.model; +import java.util.ArrayList; import java.util.List; public class Response { - private List weeks = null; + private List weeks = new ArrayList<>(); public List getWeeks() { return weeks; diff --git a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java index 118c979..925d9a8 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class TimetableResponse { +public class TimetableResponse { private Response response; private String error; diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Week.java b/src/main/java/ru/ulstu/utils/timetable/model/Week.java index 19f3c50..8ea76ea 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Week.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Week.java @@ -1,10 +1,12 @@ package ru.ulstu.utils.timetable.model; +import java.io.Serializable; +import java.util.ArrayList; import java.util.List; -public class Week { +public class Week implements Serializable { - private List days = null; + private List days = new ArrayList<>(); public List getDays() { return days; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 038ddcf..41c8ece 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=postgres +spring.datasource.password=password spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings @@ -34,6 +34,6 @@ liquibase.change-log=classpath:db/changelog-master.xml # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin -ng-tracker.dev-mode=true +ng-tracker.dev-mode=false ng-tracker.use-https=false ng-tracker.check-run=false \ No newline at end of file diff --git a/src/main/resources/templates/users/dashboard.html b/src/main/resources/templates/users/dashboard.html index 8236734..e5b7563 100644 --- a/src/main/resources/templates/users/dashboard.html +++ b/src/main/resources/templates/users/dashboard.html @@ -3,15 +3,18 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml"> + -

Пользователи

+
+

teste

+
@@ -19,6 +22,14 @@
+
\ No newline at end of file From f4479c2ab7d7d48806cac42361aa970b50cbd2ff Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sat, 25 May 2019 14:11:57 +0400 Subject: [PATCH 27/86] #91 fixed app properties --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 41c8ece..038ddcf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=password +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings @@ -34,6 +34,6 @@ liquibase.change-log=classpath:db/changelog-master.xml # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin -ng-tracker.dev-mode=false +ng-tracker.dev-mode=true ng-tracker.use-https=false ng-tracker.check-run=false \ No newline at end of file From 482e2b35954906d5c25157d8f1e22b1fba050dca Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Mon, 27 May 2019 00:42:43 +0400 Subject: [PATCH 28/86] #112 base ping activities --- .../grant/controller/GrantController.java | 7 ++ .../ru/ulstu/grant/service/GrantService.java | 15 +++- .../paper/controller/PaperRestController.java | 6 ++ .../ru/ulstu/paper/service/PaperService.java | 12 ++- src/main/java/ru/ulstu/ping/model/Ping.java | 53 +++++++++++- .../ulstu/ping/repository/PingRepository.java | 8 ++ .../ru/ulstu/ping/service/PingService.java | 9 +- .../project/controller/ProjectController.java | 7 ++ .../ulstu/project/service/ProjectService.java | 10 ++- .../ulstu/user/controller/UserController.java | 8 ++ .../user/controller/UserMvcController.java | 18 ++++ .../ru/ulstu/user/model/DiagramElement.java | 86 +++++++++++++++++++ .../ru/ulstu/user/service/UserService.java | 28 +++++- .../db/changelog-20190525_000000-schema.xml | 18 ++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/public/js/users.js | 38 ++++++++ .../resources/templates/grants/grant.html | 24 +++++- .../resources/templates/papers/paper.html | 20 ++++- .../resources/templates/projects/project.html | 24 +++++- .../resources/templates/users/activities.html | 51 +++++++++++ .../resources/templates/users/profile.html | 7 ++ 21 files changed, 437 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/DiagramElement.java create mode 100644 src/main/resources/db/changelog-20190525_000000-schema.xml create mode 100644 src/main/resources/templates/users/activities.html diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index ad5e992..8f7d760 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; @@ -139,4 +140,10 @@ public class GrantController { .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + @ResponseBody + @PostMapping(value = "/ping") + public void ping(@RequestParam("grantId") int grantId) throws IOException { + grantService.ping(grantId); + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 45f9b2f..031467d 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -13,6 +13,7 @@ import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -45,6 +46,7 @@ public class GrantService { private final PaperService paperService; private final EventService eventService; private final GrantNotificationService grantNotificationService; + private final PingService pingService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -53,7 +55,8 @@ public class GrantService { UserService userService, PaperService paperService, EventService eventService, - GrantNotificationService grantNotificationService) { + GrantNotificationService grantNotificationService, + PingService pingService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; @@ -62,6 +65,7 @@ public class GrantService { this.paperService = paperService; this.eventService = eventService; this.grantNotificationService = grantNotificationService; + this.pingService = pingService; } public List findAll() { @@ -261,4 +265,13 @@ public class GrantService { .filter(author -> Collections.frequency(authors, author) > 3) .collect(toList()); } + + public Grant findById(Integer id) { + return grantRepository.findOne(id); + } + + @Transactional + public void ping(int grantId) throws IOException { + pingService.addPing(findById(grantId)); + } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 6da009f..7c0d9c5 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; @@ -72,4 +73,9 @@ public class PaperRestController { public Response getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) { return new Response<>(paperService.getFormattedReference(referenceDto)); } + + @PostMapping(value = "/ping") + public void ping(@RequestParam("paperId") int paperId) throws IOException { + paperService.ping(paperId); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 2393af4..912b85e 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -1,5 +1,6 @@ package ru.ulstu.paper.service; +import com.sun.deploy.pings.Pings; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +16,7 @@ import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.ReferenceRepository; +import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -54,6 +56,7 @@ public class PaperService { private final FileService fileService; private final EventService eventService; private final ReferenceRepository referenceRepository; + private final PingService pingService; public PaperService(PaperRepository paperRepository, ReferenceRepository referenceRepository, @@ -61,7 +64,8 @@ public class PaperService { PaperNotificationService paperNotificationService, UserService userService, DeadlineService deadlineService, - EventService eventService) { + EventService eventService, + PingService pingService) { this.paperRepository = paperRepository; this.referenceRepository = referenceRepository; this.fileService = fileService; @@ -69,6 +73,7 @@ public class PaperService { this.userService = userService; this.deadlineService = deadlineService; this.eventService = eventService; + this.pingService = pingService; } public List findAll() { @@ -386,4 +391,9 @@ public class PaperService { autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); return autoCompleteData; } + + @Transactional + public void ping(int paperId) throws IOException { + pingService.addPing(findPaperById(paperId)); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index c7e4c5e..d52bb07 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.project.model.Project; import ru.ulstu.user.model.User; import javax.persistence.Entity; @@ -25,10 +28,22 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @ManyToOne(optional = false) + @ManyToOne() @JoinColumn(name = "conference_id") private Conference conference; + @ManyToOne() + @JoinColumn(name = "paper_id") + private Paper paper; + + @ManyToOne() + @JoinColumn(name = "grant_id") + private Grant grant; + + @ManyToOne() + @JoinColumn(name = "project_id") + private Project project; + public Ping() { } @@ -70,4 +85,40 @@ public class Ping extends BaseEntity { public void setConference(Conference conference) { this.conference = conference; } + + public Paper getPaper() { + return paper; + } + + public void setPaper(Paper paper) { + this.paper = paper; + } + + public Grant getGrant() { + return grant; + } + + public void setGrant(Grant grant) { + this.grant = grant; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public void setActivity(T object) { + if (object.getClass() == Conference.class) { + this.conference = (Conference) object; + } else if (object.getClass() == Project.class) { + this.project = (Project) object; + } else if (object.getClass() == Grant.class) { + this.grant = (Grant) object; + } else if (object.getClass() == Paper.class) { + this.paper = (Paper) object; + } + } } diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index de79dd7..0a97c31 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -6,8 +6,16 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; import ru.ulstu.ping.model.Ping; +import java.util.List; + public interface PingRepository extends JpaRepository { @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.conference = :conference)") long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); + + @Query("SELECT p FROM Ping p WHERE (:user IS NULL OR p.user.id = :user) " + + "AND (:activity != 'conferences' OR p.conference IS NOT NULL) AND (:activity != 'papers' OR p.paper IS NOT NULL) " + + "AND (:activity != 'projects' OR p.project IS NOT NULL) AND (:activity != 'grants' OR p.grant IS NOT NULL)") + List getPings(@Param("user") Integer user, + @Param("activity") String activity); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 6666fdd..de61422 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -10,6 +10,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Calendar; import java.util.Date; +import java.util.List; @Service public class PingService { @@ -23,9 +24,9 @@ public class PingService { } @Transactional - public Ping addPing(Conference conference) throws IOException { + public Ping addPing(T activity) throws IOException { Ping newPing = new Ping(new Date(), userService.getCurrentUser()); - newPing.setConference(conference); + newPing.setActivity(activity); return pingRepository.save(newPing); } @@ -33,4 +34,8 @@ public class PingService { return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR))); } + + public List getPings(Integer userId, String activity) { + return pingRepository.getPings(userId, activity); + } } diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index ae09658..efaa00b 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -90,4 +91,10 @@ public class ProjectController { .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + @ResponseBody + @PostMapping(value = "/ping") + public void ping(@RequestParam("projectId") int projectId) throws IOException { + projectService.ping(projectId); + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 247624d..ecc36b6 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -6,6 +6,7 @@ import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.repository.GrantRepository; +import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; @@ -26,15 +27,18 @@ public class ProjectService { private final DeadlineService deadlineService; private final GrantRepository grantRepository; private final FileService fileService; + private final PingService pingService; public ProjectService(ProjectRepository projectRepository, DeadlineService deadlineService, GrantRepository grantRepository, - FileService fileService) { + FileService fileService, + PingService pingService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; this.grantRepository = grantRepository; this.fileService = fileService; + this.pingService = pingService; } public List findAll() { @@ -108,4 +112,8 @@ public class ProjectService { return projectRepository.findOne(id); } + @Transactional + public void ping(int projectId) throws IOException { + pingService.addPing(findById(projectId)); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..3487370 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -20,6 +20,7 @@ import ru.ulstu.odin.controller.OdinController; import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.service.OdinService; +import ru.ulstu.user.model.DiagramElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; +import java.util.List; import java.util.Map; import static ru.ulstu.user.controller.UserController.URL; @@ -171,4 +173,10 @@ public class UserController extends OdinController { public void inviteUser(@RequestParam("email") String email) { userService.inviteUser(email); } + + @GetMapping("/activities/pings") + public Response> getActivitesStats(@RequestParam(value = "userId", required = false) Integer userId, + @RequestParam(value = "activity", required = false) String activity) { + return new Response<>(userService.getActivitiesPings(userId, activity)); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 5bcbd13..ac8d955 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -5,6 +5,7 @@ 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.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.configuration.Constants; @@ -17,6 +18,8 @@ import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; @Controller @RequestMapping(value = "/users") @@ -48,4 +51,19 @@ public class UserMvcController extends OdinController { User user = userSessionService.getUserBySessionId(sessionId); modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto)); } + + @ModelAttribute("allUsers") + public List getAllUsers() { + return userService.findAll(); + } + + @ModelAttribute("allActivities") + public List getAllActivites() { + return new ArrayList() {{ + add("papers"); + add("projects"); + add("grants"); + add("conferences"); + }}; + } } diff --git a/src/main/java/ru/ulstu/user/model/DiagramElement.java b/src/main/java/ru/ulstu/user/model/DiagramElement.java new file mode 100644 index 0000000..3509110 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/DiagramElement.java @@ -0,0 +1,86 @@ +package ru.ulstu.user.model; + +import ru.ulstu.ping.model.Ping; + +public class DiagramElement { + private User user; + private int conferences = 0; + private int projects = 0; + private int grants = 0; + private int papers = 0; + + public DiagramElement() { + } + + public DiagramElement(User user) { + this.user = user; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public int getConferences() { + return conferences; + } + + public void setConferences(int conferences) { + this.conferences = conferences; + } + + public int getProjects() { + return projects; + } + + public void setProjects(int projects) { + this.projects = projects; + } + + public int getGrants() { + return grants; + } + + public void setGrants(int grants) { + this.grants = grants; + } + + public int getPapers() { + return papers; + } + + public void setPapers(int papers) { + this.papers = papers; + } + + public void incrementPapers(int value) { + this.papers ++; + } + + public void incrementProjects(int value) { + this.projects ++; + } + + public void incrementConferences(int value) { + this.conferences ++; + } + + public void incrementGrants(int value) { + this.grants ++; + } + + public void incrementActivity(Ping ping) { + if (ping.getConference() != null) { + this.conferences ++; + } else if(ping.getPaper() != null) { + this.papers ++; + } else if(ping.getProject() != null) { + this.projects ++; + } else if(ping.getGrant() != null) { + this.grants ++; + } + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 8089a8e..90a79c0 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -3,6 +3,7 @@ package ru.ulstu.user.service; import com.google.common.collect.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.mail.MailException; @@ -18,6 +19,8 @@ import ru.ulstu.core.error.EntityIdIsNullException; import ru.ulstu.core.jpa.OffsetablePageRequest; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.response.PageableItems; +import ru.ulstu.ping.model.Ping; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException; @@ -28,6 +31,7 @@ import ru.ulstu.user.error.UserNotFoundException; import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; import ru.ulstu.user.error.UserResetKeyError; import ru.ulstu.user.error.UserSendingMailException; +import ru.ulstu.user.model.DiagramElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -40,6 +44,7 @@ import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.util.UserUtils; import javax.mail.MessagingException; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -62,19 +67,22 @@ public class UserService implements UserDetailsService { private final UserMapper userMapper; private final MailService mailService; private final ApplicationProperties applicationProperties; + private final PingService pingService; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, UserRoleRepository userRoleRepository, UserMapper userMapper, MailService mailService, - ApplicationProperties applicationProperties) { + ApplicationProperties applicationProperties, + @Lazy PingService pingService) { this.userRepository = userRepository; this.passwordEncoder = passwordEncoder; this.userRoleRepository = userRoleRepository; this.userMapper = userMapper; this.mailService = mailService; this.applicationProperties = applicationProperties; + this.pingService = pingService; } private User getUserByEmail(String email) { @@ -236,7 +244,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); @@ -348,4 +356,20 @@ public class UserService implements UserDetailsService { throw new UserSendingMailException(email); } } + + public List getActivitiesPings(Integer userId, + String activity) { + List pings = pingService.getPings(userId, activity); + List diagramElements = new ArrayList<>(); + + for (Ping ping:pings) { + DiagramElement diagramElement = diagramElements.stream().filter(element -> element.getUser() == ping.getUser()).findFirst().orElse(null); + if(diagramElement == null) { + diagramElement = new DiagramElement(ping.getUser()); + diagramElements.add(diagramElement); + } + diagramElement.incrementActivity(ping); + } + return diagramElements; + } } diff --git a/src/main/resources/db/changelog-20190525_000000-schema.xml b/src/main/resources/db/changelog-20190525_000000-schema.xml new file mode 100644 index 0000000..51fffe6 --- /dev/null +++ b/src/main/resources/db/changelog-20190525_000000-schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 5011cc5..d4488f7 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -43,4 +43,5 @@ + \ No newline at end of file diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index e31d3ad..d0c7c38 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -124,4 +124,42 @@ function resetPassword() { function isEmailValid(email) { re = /\S+@\S+\.\S+/; return re.test(email) +} + +function drawChart() { + userId = $('#author :selected').val() + activity = $('#activity :selected').val() + $.ajax({ + url:`/api/1.0/users/activities?userId=${userId}&activity=${activity}`, + contentType: "application/json; charset=utf-8", + method: "GET", + success: function(response) { + if (response.data.length == 0) { + return; + } + if(userId) { + array = [['Активность', 'Количество'], + ['Конференции', response.data[0].conferences], + ['Статьи', response.data[0].papers], + ['Проекты', response.data[0].projects], + ['Гранты', response.data[0].grants]] + } else { + array = [['Пользователи', 'Количество']] + response.data.forEach(function(element) { + array.push([element.user.firstName, element[`${activity}`]]) + }) + } + var data = google.visualization.arrayToDataTable(array); + var options = { + title: 'Активность', + is3D: true, + pieResidueSliceLabel: 'Остальное' + }; + var chart = new google.visualization.PieChart(document.getElementById('air')); + chart.draw(data, options); + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) } \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 38047bf..4f70a7a 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -23,7 +23,7 @@ th:object="${grantDto}">
- +
+
+ +
@@ -367,6 +373,22 @@ var lid = $("#leaderId option:selected").val(); $("#authors [value='" + lid + "']").attr("disabled", "disabled"); } + + function sendPing() { + id = document.getElementById("grantId").value + + $.ajax({ + url:"/grants/ping?grantId=" + id, + contentType: "application/json; charset=utf-8", + method: "POST", + success: function() { + showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) + }
diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2755aba..ea748ef 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -43,7 +43,7 @@