diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6709891..fb4c0ed 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ checkRun: checkStyle: stage: test - script: ./gradlew check + script: ./gradlew check -x test deploy: stage: deploy diff --git a/.gitlab/issue_templates/feature.md b/.gitlab/issue_templates/feature.md index 932d386..c9e1757 100644 --- a/.gitlab/issue_templates/feature.md +++ b/.gitlab/issue_templates/feature.md @@ -1,50 +1,46 @@ -## Краткое описание задачи -``` -Что требуется сделать -``` - -## `Опционально` Список верстаемых страниц -``` -Будут затронуты страницы: -* page1.html -* page2.html -* page3.html -``` - -## `Опционально` Список затрагиваемых модулей -``` -При реализации задачи потребуется также реализовать методы контроллера -``` - -## `Опционально` Список реализуемых функций -``` -После выполнения задачи станет доступным: -* просмотр `entity_name` -* редактирование `entity_name` -* валидация `entity_name` -``` - -## `Опционально` Сценарии работы -``` -Сценарий просмотра: -1. Зайти на главную страницу приложения -2. Перейти в раздел `section_name` -3. Перейти к списку `entity_name` -4. Выбрать нужную `entity_name` и нажать на нее - -Сценарий редактирования: -1. Зайти на главную страницу приложения -2. Перейти в раздел `section_name` -3. Перейти к списку `entity_name` -4. Выбрать нужную `entity_name` и нажать на нее -5. Внести нужные правки в поля и сохранить -``` - -## Описание конечного результата, дающего возможность проверки выполнения задачи: компоненты проекта, сценарии работы -``` -* Сверстаны страницы page1.hml, page2.hml, page3.hml -* Реализован контроллер для обслуживания страниц -* Сохранение в БД еще не реализовано -* Валидация происходит по полям `field1, field2` -* Сценарий просмотра проверяется при ручном внечении записей в БД -``` \ No newline at end of file +## Краткое описание задачи + +Что требуется сделать + + +## `Опционально` Список верстаемых страниц + +Будут затронуты страницы: +* page1.html +* page2.html +* page3.html + +## `Опционально` Список затрагиваемых модулей + +При реализации задачи потребуется также реализовать методы контроллера + + +## `Опционально` Список реализуемых функций + +После выполнения задачи станет доступным: +* просмотр `entity_name` +* редактирование `entity_name` +* валидация `entity_name` + +## `Опционально` Сценарии работы + +Сценарий просмотра: +1. Зайти на главную страницу приложения +2. Перейти в раздел `section_name` +3. Перейти к списку `entity_name` +4. Выбрать нужную `entity_name` и нажать на нее + +Сценарий редактирования: +1. Зайти на главную страницу приложения +2. Перейти в раздел `section_name` +3. Перейти к списку `entity_name` +4. Выбрать нужную `entity_name` и нажать на нее +5. Внести нужные правки в поля и сохранить + +## Описание конечного результата, дающего возможность проверки выполнения задачи: компоненты проекта, сценарии работы + +* Сверстаны страницы page1.hml, page2.hml, page3.hml +* Реализован контроллер для обслуживания страниц +* Сохранение в БД еще не реализовано +* Валидация происходит по полям `field1, field2` +* Сценарий просмотра проверяется при ручном внечении записей в БД diff --git a/build.gradle b/build.gradle index ffc7d0a..38de2c7 100644 --- a/build.gradle +++ b/build.gradle @@ -114,9 +114,6 @@ dependencies { compile group: 'org.liquibase', name: 'liquibase-core', version: '3.5.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' @@ -125,8 +122,10 @@ dependencies { compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1' compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' - compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0' - compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0' + compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0' + compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' + testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' + } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/core/error/XlsLoadException.java b/src/main/java/ru/ulstu/core/error/XlsLoadException.java deleted file mode 100644 index 372731f..0000000 --- a/src/main/java/ru/ulstu/core/error/XlsLoadException.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.core.error; - -public class XlsLoadException extends Exception { - public XlsLoadException(String s) { - super(s); - } -} diff --git a/src/main/java/ru/ulstu/core/error/XlsParseException.java b/src/main/java/ru/ulstu/core/error/XlsParseException.java deleted file mode 100644 index fe8c4b3..0000000 --- a/src/main/java/ru/ulstu/core/error/XlsParseException.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.core.error; - -public class XlsParseException extends Exception { - public XlsParseException(String s) { - super(s); - } -} diff --git a/src/main/java/ru/ulstu/core/service/TreeService.java b/src/main/java/ru/ulstu/core/service/TreeService.java deleted file mode 100644 index 1e3d4a0..0000000 --- a/src/main/java/ru/ulstu/core/service/TreeService.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.ulstu.core.service; - -import org.springframework.stereotype.Service; -import ru.ulstu.core.model.TreeDto; -import ru.ulstu.core.model.TreeEntity; - -import java.util.List; -import java.util.function.Predicate; - -@Service -public class TreeService { - public TreeDto getTree(String rootName, List rootItems) { - return addChildNode(new TreeDto(rootName), rootItems, element -> true); - } - - public TreeDto getTree(String rootName, List rootItems, Predicate filterPredicate) { - return addChildNode(new TreeDto(rootName), rootItems, filterPredicate); - } - - private TreeDto addChildNode(TreeDto currentRoot, List children, Predicate filterPredicate) { - if (children != null) { - children.stream() - .filter(filterPredicate) - .forEach(item -> { - TreeDto newNode = new TreeDto(item); - currentRoot.getChildren().add(addChildNode(newNode, item.getChildren(), filterPredicate)); - }); - } - return currentRoot; - } -} 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/file/model/FileData.java b/src/main/java/ru/ulstu/file/model/FileData.java index e5b3277..08445a3 100644 --- a/src/main/java/ru/ulstu/file/model/FileData.java +++ b/src/main/java/ru/ulstu/file/model/FileData.java @@ -19,6 +19,9 @@ public class FileData extends BaseEntity { private byte[] data; + @Column(name = "is_latex_attach") + private boolean isLatexAttach; + public String getName() { return name; } @@ -50,4 +53,12 @@ public class FileData extends BaseEntity { public void setData(byte[] data) { this.data = data; } + + public boolean isLatexAttach() { + return isLatexAttach; + } + + public void setLatexAttach(boolean latexAttach) { + isLatexAttach = latexAttach; + } } diff --git a/src/main/java/ru/ulstu/file/model/FileDataDto.java b/src/main/java/ru/ulstu/file/model/FileDataDto.java index 919cd80..65ef275 100644 --- a/src/main/java/ru/ulstu/file/model/FileDataDto.java +++ b/src/main/java/ru/ulstu/file/model/FileDataDto.java @@ -9,6 +9,7 @@ public class FileDataDto { private String fileName; private String tmpFileName; private boolean deleted; + private boolean isLatexAttach; public FileDataDto() { } @@ -16,17 +17,20 @@ public class FileDataDto { @JsonCreator public FileDataDto(@JsonProperty("id") Integer id, @JsonProperty("name") String name, + @JsonProperty("isLatexAttach") boolean isLatexAttach, @JsonProperty("fileName") String fileName, @JsonProperty("tmpFileName") String tmpFileName) { this.id = id; this.name = name; this.fileName = fileName; this.tmpFileName = tmpFileName; + this.isLatexAttach = isLatexAttach; } public FileDataDto(FileData fileData) { this.id = fileData.getId(); this.name = fileData.getName(); + this.isLatexAttach = fileData.isLatexAttach(); } public FileDataDto(String fileName, String tmpFileName) { @@ -73,4 +77,19 @@ public class FileDataDto { this.deleted = deleted; } + public boolean isLatexAttach() { + return isLatexAttach; + } + + public boolean getIsLatexAttach() { + return isLatexAttach; + } + + public void setLatexAttach(boolean latexAttach) { + isLatexAttach = latexAttach; + } + + public void setIsLatexAttach(boolean latexAttach) { + isLatexAttach = latexAttach; + } } diff --git a/src/main/java/ru/ulstu/file/service/FileService.java b/src/main/java/ru/ulstu/file/service/FileService.java index ad9f946..3a0a87c 100644 --- a/src/main/java/ru/ulstu/file/service/FileService.java +++ b/src/main/java/ru/ulstu/file/service/FileService.java @@ -6,7 +6,10 @@ import org.springframework.web.multipart.MultipartFile; import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.repostory.FileRepository; +import ru.ulstu.paper.model.PaperDto; +import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -15,6 +18,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import static java.nio.charset.StandardCharsets.UTF_8; @@ -107,6 +111,7 @@ public class FileService { private FileData copyFromDto(FileData fileData, FileDataDto fileDataDto) { fileData.setName(fileDataDto.getName()); + fileData.setLatexAttach(fileDataDto.isLatexAttach()); return fileData; } @@ -118,4 +123,27 @@ public class FileService { public FileDataDto createFromMultipartFile(MultipartFile multipartFile) throws IOException { return new FileDataDto(multipartFile.getOriginalFilename(), uploadToTmpDir(multipartFile)); } + + public void createLatexAttachs(PaperDto paper) throws IOException { + for (FileDataDto fileDataDto : paper.getFiles() + .stream() + .filter(f -> f.isLatexAttach() && !f.isDeleted()) + .collect(Collectors.toList())) { + if (fileDataDto.getId() == null) { + File oldFile = getTmpFilePath(fileDataDto.getTmpFileName()).toFile(); + File renamed = getTmpFilePath(fileDataDto.getName()).toFile(); + oldFile.renameTo(renamed); + } else { + Files.write(getTmpFilePath(fileDataDto.getName()), fileRepository.findOne(fileDataDto.getId()).getData()); + } + } + } + + public File createLatexFile(PaperDto paper) throws IOException { + BufferedWriter writer = Files.newBufferedWriter(getTmpFilePath(paper.getTitle() + ".tex")); + writer.write(paper.getLatexText()); + writer.close(); + + return getTmpFilePath(paper.getTitle() + ".tex").toFile(); + } } diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index a7dc948..0731188 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; +import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -24,7 +25,6 @@ import static org.springframework.util.StringUtils.isEmpty; import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE; import static ru.ulstu.core.controller.Navigation.GRANT_PAGE; import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @@ -57,27 +57,42 @@ public class GrantController { } @PostMapping(value = "/grant", params = "save") - public String save(@Valid GrantDto grantDto, Errors errors) throws IOException { + public String save(@Valid GrantDto grantDto, Errors errors) + throws IOException { filterEmptyDeadlines(grantDto); if (grantDto.getDeadlines().isEmpty()) { - errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); + errors.rejectValue("deadlines", "errorCode", "Не может быть пусто"); + } + if (grantDto.getLeaderId().equals(-1)) { + errors.rejectValue("leaderId", "errorCode", "Укажите руководителя"); + } + if (errors.hasErrors()) { + return GRANT_PAGE; } - hasErrors(errors, GRANT_PAGE); grantService.save(grantDto); return String.format(REDIRECT_TO, GRANTS_PAGE); } + @PostMapping(value = "/grant", params = "filterUsers") + public String filterUsers() { + return GRANT_PAGE; + } + @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantDto.getDeadlines().add(new Deadline()); return GRANT_PAGE; } @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) { - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantService.createProject(grantDto); return GRANT_PAGE; } @@ -93,6 +108,11 @@ public class GrantController { return grantService.getGrantStatuses(); } + @ModelAttribute("allAuthors") + public List getAllAuthors(GrantDto grantDto) { + return grantService.getGrantAuthors(grantDto); + } + private void filterEmptyDeadlines(GrantDto grantDto) { grantDto.setDeadlines(grantDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 685a1d5..9b1e8fe 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -2,28 +2,35 @@ package ru.ulstu.grant.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.project.model.Project; +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.persistence.OrderBy; import javax.persistence.Table; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; @Entity @Table(name = "grants") -public class Grant extends BaseEntity { +public class Grant extends BaseEntity implements UserContainer { public enum GrantStatus { APPLICATION("Заявка"), ON_COMPETITION("Отправлен на конкурс"), @@ -52,6 +59,7 @@ public class Grant extends BaseEntity { @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "grant_id") + @OrderBy("date") private List deadlines = new ArrayList<>(); //Описание гранта @@ -67,6 +75,14 @@ public class Grant extends BaseEntity { @JoinColumn(name = "project_id") private Project project; + @ManyToMany(fetch = FetchType.EAGER) + private Set authors = new HashSet<>(); + + @NotNull + @ManyToOne + @JoinColumn(name = "leader_id") + private User leader; + public GrantStatus getStatus() { return status; } @@ -115,6 +131,27 @@ public class Grant extends BaseEntity { this.project = project; } + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + + @Override + public Set getUsers() { + return getAuthors(); + } + + public User getLeader() { + return leader; + } + + public void setLeader(User leader) { + this.leader = leader; + } + public Optional getNextDeadline() { return deadlines .stream() diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index fb29164..aa8634b 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -2,14 +2,22 @@ package ru.ulstu.grant.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.project.model.ProjectDto; +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 GrantDto { + private final static int MAX_AUTHORS_LENGTH = 60; + private Integer id; @NotEmpty private String title; @@ -18,6 +26,12 @@ public class GrantDto { private String comment; private String applicationFileName; private ProjectDto project; + private Set authorIds; + private Set authors; + private Integer leaderId; + private boolean wasLeader; + private boolean hasAge; + private boolean hasDegree; public GrantDto() { deadlines.add(new Deadline()); @@ -29,7 +43,13 @@ public class GrantDto { @JsonProperty("status") Grant.GrantStatus status, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, - @JsonProperty("project") ProjectDto project) { + @JsonProperty("project") ProjectDto project, + @JsonProperty("authorIds") Set authorIds, + @JsonProperty("authors") Set authors, + @JsonProperty("leader") Integer leaderId, + @JsonProperty("wasLeader") boolean wasLeader, + @JsonProperty("hasAge") boolean hasAge, + @JsonProperty("hasDegree") boolean hasDegree) { this.id = id; this.title = title; this.status = status; @@ -37,6 +57,11 @@ public class GrantDto { this.comment = comment; this.applicationFileName = null; this.project = project; + this.authors = authors; + this.leaderId = leaderId; + this.wasLeader = wasLeader; + this.hasAge = hasAge; + this.hasDegree = hasDegree; } public GrantDto(Grant grant) { @@ -47,6 +72,12 @@ public class GrantDto { this.comment = grant.getComment(); this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject()); this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName(); + this.authorIds = convert(grant.getAuthors(), user -> user.getId()); + this.authors = convert(grant.getAuthors(), UserDto::new); + this.leaderId = grant.getLeader().getId(); + this.wasLeader = false; + this.hasAge = false; + this.hasDegree = false; } public Integer getId() { @@ -104,4 +135,59 @@ public class GrantDto { public void setApplicationFileName(String applicationFileName) { this.applicationFileName = applicationFileName; } + + public Set getAuthorIds() { + return authorIds; + } + + public void setAuthorIds(Set authorIds) { + this.authorIds = authorIds; + } + + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + + public String getAuthorsString() { + return StringUtils.abbreviate(authors + .stream() + .map(author -> author.getLastName()) + .collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH); + } + + public Integer getLeaderId() { + return leaderId; + } + + public void setLeaderId(Integer leaderId) { + this.leaderId = leaderId; + } + + public boolean isWasLeader() { + return wasLeader; + } + + public void setWasLeader(boolean wasLeader) { + this.wasLeader = wasLeader; + } + + public boolean isHasAge() { + return hasAge; + } + + public void setHasAge(boolean hasAge) { + this.hasAge = hasAge; + } + + public boolean isHasDegree() { + return hasDegree; + } + + public void setHasDegree(boolean hasDegree) { + this.hasDegree = hasDegree; + } } diff --git a/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java b/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java deleted file mode 100644 index 34676d6..0000000 --- a/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.ulstu.grant.model; - -public class GrantStatusDto { - private final String id; - private final String name; - - public GrantStatusDto(Grant.GrantStatus status) { - this.id = status.name(); - this.name = status.getStatusName(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 92dec43..44c2cc0 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -3,6 +3,9 @@ package ru.ulstu.grant.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.grant.model.Grant; +import java.util.List; + public interface GrantRepository extends JpaRepository { + List findByStatus(Grant.GrantStatus status); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index d5beec3..8427da3 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -12,11 +12,14 @@ import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -30,15 +33,18 @@ public class GrantService { private final ProjectService projectService; private final DeadlineService deadlineService; private final FileService fileService; + private final UserService userService; public GrantService(GrantRepository grantRepository, FileService fileService, DeadlineService deadlineService, - ProjectService projectService) { + ProjectService projectService, + UserService userService) { this.grantRepository = grantRepository; - this.projectService = projectService; this.fileService = fileService; this.deadlineService = deadlineService; + this.projectService = projectService; + this.userService = userService; } public List findAll() { @@ -73,6 +79,13 @@ public class GrantService { if (grantDto.getApplicationFileName() != null) { grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName())); } + grant.getAuthors().clear(); + if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { + grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); + } + if (grantDto.getLeaderId() != null) { + grant.setLeader(userService.findById(grantDto.getLeaderId())); + } return grant; } @@ -84,7 +97,6 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); - Grant.GrantStatus oldStatus = grant.getStatus(); if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } @@ -98,7 +110,6 @@ public class GrantService { if (grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } - //возможно при удалении гранта будет удаляться и проект, к нему привязанный grantRepository.delete(grant); } @@ -107,13 +118,15 @@ public class GrantService { } @Transactional - public Grant create(String title, Project projectId, Date deadlineDate) { + public Grant create(String title, Project projectId, Date deadlineDate, User user) { Grant grant = new Grant(); grant.setTitle(title); grant.setComment("Комментарий к гранту 1"); grant.setProject(projectId); grant.setStatus(APPLICATION); grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + grant.getAuthors().add(user); + grant.setLeader(user); grant = grantRepository.save(grant); return grant; } @@ -125,4 +138,22 @@ public class GrantService { update(grantDto); } } + + public List getGrantAuthors(GrantDto grantDto) { + List filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree()); + if (grantDto.isWasLeader()) { + filteredUsers = filteredUsers + .stream() + .filter(getCompletedGrantLeaders()::contains) + .collect(Collectors.toList()); + } + return filteredUsers; + } + + private List getCompletedGrantLeaders() { + return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) + .stream() + .map(Grant::getLeader) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 27fec4e..ad30822 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,5 +1,8 @@ package ru.ulstu.paper.controller; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; @@ -13,17 +16,20 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; +import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.springframework.util.StringUtils.isEmpty; @@ -32,9 +38,11 @@ import static org.springframework.util.StringUtils.isEmpty; @ApiIgnore public class PaperController { private final PaperService paperService; + private final LatexService latexService; - public PaperController(PaperService paperService) { + public PaperController(PaperService paperService, LatexService latexService) { this.paperService = paperService; + this.latexService = latexService; } @GetMapping("/papers") @@ -111,6 +119,14 @@ public class PaperController { return years; } + @PostMapping("/generatePdf") + public ResponseEntity getPdfFile(PaperDto paper) throws IOException, InterruptedException { + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Disposition", "attachment; filename='" + + URLEncoder.encode(paper.getTitle() + ".pdf", UTF_8.toString()) + "'"); + return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK); + } + private void filterEmptyDeadlines(PaperDto paperDto) { paperDto.setDeadlines(paperDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 1d7e468..c7f7fcf 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -91,6 +91,9 @@ public class Paper extends BaseEntity implements UserContainer { @ManyToMany(fetch = FetchType.EAGER) private Set authors = new HashSet<>(); + @Column(name = "latex_text") + private String latexText; + public PaperStatus getStatus() { return status; } @@ -179,6 +182,14 @@ public class Paper extends BaseEntity implements UserContainer { this.url = url; } + public String getLatexText() { + return latexText; + } + + public void setLatexText(String latexText) { + this.latexText = latexText; + } + @Override public Set getUsers() { return getAuthors(); diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 182b12c..7ddc0e0 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -4,8 +4,8 @@ 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.file.model.FileDataDto; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.user.model.UserDto; import javax.validation.constraints.Size; @@ -36,6 +36,7 @@ public class PaperDto { private Set authorIds; private Set authors; private Integer filterAuthorId; + private String latexText; public PaperDto() { deadlines.add(new Deadline()); @@ -49,6 +50,7 @@ public class PaperDto { @JsonProperty("updateDate") Date updateDate, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, + @JsonProperty("latex_text") String latexText, @JsonProperty("url") String url, @JsonProperty("locked") Boolean locked, @JsonProperty("files") List files, @@ -62,6 +64,7 @@ public class PaperDto { this.deadlines = deadlines; this.comment = comment; this.url = url; + this.latexText = latexText; this.locked = locked; this.files = files; this.authors = authors; @@ -76,6 +79,7 @@ public class PaperDto { this.deadlines = paper.getDeadlines(); this.comment = paper.getComment(); this.url = paper.getUrl(); + this.latexText = paper.getLatexText(); this.locked = paper.getLocked(); this.files = convert(paper.getFiles(), FileDataDto::new); this.authorIds = convert(paper.getAuthors(), user -> user.getId()); @@ -178,6 +182,14 @@ public class PaperDto { this.url = url; } + public String getLatexText() { + return latexText; + } + + public void setLatexText(String latexText) { + this.latexText = latexText; + } + public String getAuthorsString() { return StringUtils.abbreviate(authors .stream() diff --git a/src/main/java/ru/ulstu/paper/service/LatexService.java b/src/main/java/ru/ulstu/paper/service/LatexService.java new file mode 100644 index 0000000..6bf5226 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/service/LatexService.java @@ -0,0 +1,72 @@ +package ru.ulstu.paper.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.file.service.FileService; +import ru.ulstu.paper.model.PaperDto; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Files; + +@Service +public class LatexService { + private String errorMessage; + private File pdfFile; + private FileService fileService; + private final String pdfLatexError = "Errors occurred while executing pdfLaTeX."; + private final String bibtexError = "Errors occurred while executing bibtex."; + + public LatexService(FileService fileService) { + this.fileService = fileService; + } + + public byte[] generatePdfFromLatexFile(PaperDto paper) throws IOException, InterruptedException { + fileService.createLatexAttachs(paper); + File tex = fileService.createLatexFile(paper); + + if (!generate(paper.getTitle(), tex.getParentFile())) { + throw new IOException(errorMessage); + } + + return Files.readAllBytes(pdfFile.toPath()); + } + + private int startProcess(String[] args, File dir, String message) throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder(args); + processBuilder.redirectErrorStream(true); + processBuilder.directory(dir); + + Process process = processBuilder.start(); + InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); + + try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + while ((bufferedReader.readLine()) != null) ; + } + + int exitCode = process.waitFor(); + if (exitCode != 0) { + errorMessage = message + " Exit value of the process: " + exitCode; + } + return exitCode; + } + + private boolean generate(String filename, File dir) throws IOException, InterruptedException { + startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, pdfLatexError); + startProcess(new String[]{"bibtex", filename}, dir, bibtexError); + if (startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, pdfLatexError) != 0) + return false; + return checkPdf(filename, dir); + } + + private boolean checkPdf(String filename, File dir) { + pdfFile = new File(dir.getAbsolutePath() + File.separator + filename + ".pdf"); + + if (pdfFile.isFile()) return true; + else { + errorMessage = "The pdf file could not be created."; + return false; + } + } +} diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 6c27c6e..a10d941 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -95,6 +95,7 @@ public class PaperService { private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException { paper.setComment(paperDto.getComment()); paper.setUrl(paperDto.getUrl()); + paper.setLatexText(paperDto.getLatexText()); paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate()); paper.setLocked(paperDto.getLocked()); paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus()); 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..3244ccb --- /dev/null +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -0,0 +1,49 @@ +package ru.ulstu.project.controller; + +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.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.model.ProjectDto; +import ru.ulstu.project.service.ProjectService; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.List; + +@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()); + } + + @GetMapping("/project") + public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + if (id != null && id > 0) { + modelMap.put("projectDto", projectService.findOneDto(id)); + } else { + modelMap.put("projectDto", new ProjectDto()); + } + } + + @ModelAttribute("allStatuses") + public List getProjectStatuses() { + return projectService.getProjectStatuses(); + } +} diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 06722a1..2e0e86c 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -3,24 +3,60 @@ package ru.ulstu.project.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.Grant; import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; @Entity public class Project extends BaseEntity { + public enum ProjectStatus { + APPLICATION("Заявка"), + ON_COMPETITION("Отправлен на конкурс"), + SUCCESSFUL_PASSAGE("Успешное прохождение"), + IN_WORK("В работе"), + COMPLETED("Завершен"), + FAILED("Провалены сроки"); + + private String statusName; + + ProjectStatus(String statusName) { + this.statusName = statusName; + } + + public String getStatusName() { + return statusName; + } + } @NotBlank private String title; + @Enumerated(value = EnumType.STRING) + private ProjectStatus status = ProjectStatus.APPLICATION; + + @NotNull + private String description; + @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private List deadlines = new ArrayList<>(); + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "grant_id") + private Grant grant; + + @NotNull + private String repository; + public String getTitle() { return title; } @@ -29,6 +65,38 @@ public class Project extends BaseEntity { this.title = title; } + public ProjectStatus getStatus() { + return status; + } + + public void setStatus(ProjectStatus status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Grant getGrant() { + return grant; + } + + public void setGrant(Grant grant) { + this.grant = grant; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + public List getDeadlines() { return deadlines; } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index db7fc75..6c83d59 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -4,6 +4,7 @@ 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.grant.model.GrantDto; import java.util.ArrayList; import java.util.List; @@ -13,8 +14,11 @@ public class ProjectDto { @NotEmpty private String title; - + private Project.ProjectStatus status; + private String description; private List deadlines = new ArrayList<>(); + private GrantDto grant; + private String repository; public ProjectDto() { } @@ -26,9 +30,17 @@ public class ProjectDto { @JsonCreator public ProjectDto(@JsonProperty("id") Integer id, @JsonProperty("title") String title, + @JsonProperty("status") Project.ProjectStatus status, + @JsonProperty("description") String description, + @JsonProperty("grant") GrantDto grant, + @JsonProperty("repository") String repository, @JsonProperty("deadlines") List deadlines) { this.id = id; this.title = title; + this.status = status; + this.description = description; + this.grant = grant; + this.repository = repository; this.deadlines = deadlines; } @@ -36,6 +48,10 @@ public class ProjectDto { public ProjectDto(Project project) { this.id = project.getId(); this.title = project.getTitle(); + this.status = project.getStatus(); + this.description = project.getDescription(); + this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); + this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); } @@ -55,6 +71,38 @@ public class ProjectDto { this.title = title; } + public Project.ProjectStatus getStatus() { + return status; + } + + public void setStatus(Project.ProjectStatus status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public GrantDto getGrant() { + return grant; + } + + public void setGrant(GrantDto grant) { + this.grant = grant; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + public List getDeadlines() { return deadlines; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index b54a60a..99d8919 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -2,17 +2,21 @@ 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; import ru.ulstu.project.repository.ProjectRepository; +import java.util.Arrays; 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 +31,20 @@ 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; + } + + public ProjectDto findOneDto(Integer id) { + return new ProjectDto(projectRepository.findOne(id)); + } + + public List getProjectStatuses() { + return Arrays.asList(Project.ProjectStatus.values()); + } + @Transactional public Project create(ProjectDto projectDto) { Project newProject = copyFromDto(new Project(), projectDto); diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index 06f407b..7946f04 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -7,6 +7,8 @@ import ru.ulstu.core.model.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; @@ -85,6 +87,28 @@ public class User extends BaseEntity { @BatchSize(size = 20) private Set roles; + @Column(name = "birth_date") + @Temporal(TemporalType.TIMESTAMP) + private Date birthDate; + + public enum UserDegree { + CANDIDATE("Кандидат технических наук"), + DOCTOR("Доктор технических наук"); + + private String degreeName; + + UserDegree(String degreeName) { + this.degreeName = degreeName; + } + + public String getDegreeName() { + return degreeName; + } + } + + @Enumerated(value = EnumType.STRING) + private UserDegree degree; + public User() { roles = new HashSet<>(); activated = false; @@ -189,6 +213,22 @@ public class User extends BaseEntity { this.patronymic = patronymic; } + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + public UserDegree getDegree() { + return degree; + } + + public void setDegree(UserDegree degree) { + this.degree = degree; + } + public String getUserAbbreviate() { return String.format(USER_ABBREVIATE_TEMPLATE, lastName == null ? "" : lastName, diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index c98e0bb..39ff913 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -15,6 +15,7 @@ import ru.ulstu.user.controller.UserController; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.util.Collection; +import java.util.Date; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; @@ -70,6 +71,10 @@ public class UserDto implements OdinDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; + private Date birthDate; + + private User.UserDegree degree; + public UserDto() { activated = false; roles = new LinkedHashSet<>(); @@ -86,6 +91,8 @@ public class UserDto implements OdinDto { this.roles.addAll(user.getRoles().stream() .map(UserRoleDto::new) .collect(Collectors.toList())); + this.birthDate = user.getBirthDate(); + this.degree = user.getDegree(); } public Integer getId() { @@ -163,6 +170,22 @@ public class UserDto implements OdinDto { return passwordConfirm; } + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + public User.UserDegree getDegree() { + return degree; + } + + public void setDegree(User.UserDegree degree) { + this.degree = degree; + } + @JsonIgnore public boolean isPasswordsValid() { if (StringUtils.isEmpty(password) || StringUtils.isEmpty(passwordConfirm)) { @@ -188,6 +211,8 @@ public class UserDto implements OdinDto { ", roles=" + roles + ", password='" + password + '\'' + ", passwordConfirm='" + passwordConfirm + '\'' + + ", birthDate='" + birthDate + '\'' + + ", degree='" + degree + '\'' + '}'; } } diff --git a/src/main/java/ru/ulstu/user/repository/UserRepository.java b/src/main/java/ru/ulstu/user/repository/UserRepository.java index 2edc8aa..afcdd69 100644 --- a/src/main/java/ru/ulstu/user/repository/UserRepository.java +++ b/src/main/java/ru/ulstu/user/repository/UserRepository.java @@ -2,6 +2,8 @@ package ru.ulstu.user.repository; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.user.model.User; import java.util.Date; @@ -25,4 +27,11 @@ public interface UserRepository extends JpaRepository { @EntityGraph(attributePaths = "roles") User findOneWithRolesByLogin(String login); + + @Query("SELECT u FROM User u " + + "WHERE (YEAR(CURRENT_DATE) - YEAR(u.birthDate) < 35 OR :hasAge = FALSE) " + + "AND (u.degree = 'CANDIDATE' OR :hasDegree = FALSE)" + + "ORDER BY u.lastName") + List filterByAgeAndDegree(@Param("hasAge") boolean hasAge, + @Param("hasDegree") boolean hasDegree); } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 25d8e95..c98e4b7 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -324,4 +324,8 @@ public class UserService implements UserDetailsService { } return user; } + + public List filterByAgeAndDegree(boolean hasDegree, boolean hasAge) { + return userRepository.filterByAgeAndDegree(hasDegree, hasAge); + } } diff --git a/src/main/resources/db/changelog-20190323_000001-schema.xml b/src/main/resources/db/changelog-20190323_000001-schema.xml new file mode 100644 index 0000000..1ab3efb --- /dev/null +++ b/src/main/resources/db/changelog-20190323_000001-schema.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190402_000000-schema.xml b/src/main/resources/db/changelog-20190402_000000-schema.xml new file mode 100644 index 0000000..1bbb256 --- /dev/null +++ b/src/main/resources/db/changelog-20190402_000000-schema.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190404_000000-schema.xml b/src/main/resources/db/changelog-20190404_000000-schema.xml new file mode 100644 index 0000000..0f45e31 --- /dev/null +++ b/src/main/resources/db/changelog-20190404_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190418_000000-schema.xml b/src/main/resources/db/changelog-20190418_000000-schema.xml new file mode 100644 index 0000000..31cf21c --- /dev/null +++ b/src/main/resources/db/changelog-20190418_000000-schema.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 58bbdeb..32651bc 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -25,5 +25,9 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/drivers/chromedriver b/src/main/resources/drivers/chromedriver new file mode 100644 index 0000000..02ff671 Binary files /dev/null and b/src/main/resources/drivers/chromedriver differ diff --git a/src/main/resources/drivers/chromedriver.exe b/src/main/resources/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/src/main/resources/drivers/chromedriver.exe differ diff --git a/src/main/resources/drivers/geckodriver b/src/main/resources/drivers/geckodriver new file mode 100644 index 0000000..ba1da8c Binary files /dev/null and b/src/main/resources/drivers/geckodriver differ diff --git a/src/main/resources/drivers/geckodriver.exe b/src/main/resources/drivers/geckodriver.exe new file mode 100644 index 0000000..6208aa8 Binary files /dev/null and b/src/main/resources/drivers/geckodriver.exe differ diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css new file mode 100644 index 0000000..2c95628 --- /dev/null +++ b/src/main/resources/public/css/grant.css @@ -0,0 +1,12 @@ +.div-deadline-date { + padding-right: 0px; +} + +.form-deadline-date{ + padding-right: 3px; +} + +.div-deadline-description{ + padding-left: 5px; + padding-right: 5px; +} \ No newline at end of file diff --git a/src/main/resources/public/css/paper.css b/src/main/resources/public/css/paper.css index 6e61d0c..824209f 100644 --- a/src/main/resources/public/css/paper.css +++ b/src/main/resources/public/css/paper.css @@ -1,5 +1,9 @@ -#files-list .row > div:nth-child(6) { +#files-list .row > div:nth-child(7) { display: flex; justify-content: center; flex-direction: column; +} + +.nav-tabs { + margin-bottom: 20px; } \ No newline at end of file diff --git a/src/main/resources/public/js/core.js b/src/main/resources/public/js/core.js index bf6fb77..58e68f4 100644 --- a/src/main/resources/public/js/core.js +++ b/src/main/resources/public/js/core.js @@ -3,6 +3,7 @@ var urlFileUpload = "/api/1.0/files/uploadTmpFile"; var urlFileDownload = "/api/1.0/files/download/"; +var urlPdfGenerating = "/papers/generatePdf"; var urlFileDownloadTmp = "/api/1.0/files/download-tmp/"; /* exported MessageTypesEnum */ diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 1048897..dda0e8d 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -9,7 +9,7 @@ - + - +
diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index fc2878d..75dec37 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -3,13 +3,12 @@ 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"> - +
- -
+
@@ -17,6 +16,7 @@
+