diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index d98ba98..6da009f 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -12,6 +12,7 @@ import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -66,4 +67,9 @@ public class PaperRestController { public Response> getFormattedPaperList() { return new Response<>(paperService.getFormattedPaperList()); } + + @PostMapping("/getFormattedReference") + public Response getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) { + return new Response<>(paperService.getFormattedReference(referenceDto)); + } } diff --git a/src/main/java/ru/ulstu/paper/model/ReferenceDto.java b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java new file mode 100644 index 0000000..8d71ae5 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java @@ -0,0 +1,129 @@ +package ru.ulstu.paper.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ReferenceDto { + public enum ReferenceType { + ARTICLE("Статья"), + BOOK("Книга"); + + private String typeName; + + ReferenceType(String name) { + this.typeName = name; + } + + public String getTypeName() { + return typeName; + } + } + + public enum FormatStandard { + GOST("ГОСТ"), + SPRINGER("Springer"); + + private String standardName; + + FormatStandard(String name) { + this.standardName = name; + } + + public String getStandardName() { + return standardName; + } + } + + private String authors; + private String publicationTitle; + private Integer publicationYear; + private String publisher; + private String pages; + private String journalOrCollectionTitle; + private ReferenceType referenceType; + private FormatStandard formatStandard; + + @JsonCreator + public ReferenceDto( + @JsonProperty("authors") String authors, + @JsonProperty("publicationTitle") String publicationTitle, + @JsonProperty("publicationYear") Integer publicationYear, + @JsonProperty("publisher") String publisher, + @JsonProperty("pages") String pages, + @JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle, + @JsonProperty("referenceType") ReferenceType referenceType, + @JsonProperty("formatStandard") FormatStandard formatStandard) { + this.authors = authors; + this.publicationTitle = publicationTitle; + this.publicationYear = publicationYear; + this.publisher = publisher; + this.pages = pages; + this.journalOrCollectionTitle = journalOrCollectionTitle; + this.referenceType = referenceType; + this.formatStandard = formatStandard; + } + + public String getAuthors() { + return authors; + } + + public void setAuthors(String authors) { + this.authors = authors; + } + + public String getPublicationTitle() { + return publicationTitle; + } + + public void setPublicationTitle(String publicationTitle) { + this.publicationTitle = publicationTitle; + } + + public Integer getPublicationYear() { + return publicationYear; + } + + public void setPublicationYear(Integer publicationYear) { + this.publicationYear = publicationYear; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPages() { + return pages; + } + + public void setPages(String pages) { + this.pages = pages; + } + + public String getJournalOrCollectionTitle() { + return journalOrCollectionTitle; + } + + public void setJournalOrCollectionTitle(String journalOrCollectionTitle) { + this.journalOrCollectionTitle = journalOrCollectionTitle; + } + + public ReferenceType getReferenceType() { + return referenceType; + } + + public void setReferenceType(ReferenceType referenceType) { + this.referenceType = referenceType; + } + + public FormatStandard getFormatStandard() { + return formatStandard; + } + + public void setFormatStandard(FormatStandard formatStandard) { + this.formatStandard = formatStandard; + } +} diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 325e377..3db7c84 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -10,12 +10,14 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.text.MessageFormat; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -32,6 +34,9 @@ import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED; import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; import static ru.ulstu.paper.model.Paper.PaperType.OTHER; +import static ru.ulstu.paper.model.ReferenceDto.FormatStandard.GOST; +import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE; +import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK; @Service public class PaperService { @@ -272,4 +277,30 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public String getFormattedReference(ReferenceDto referenceDto) { + return referenceDto.getFormatStandard() == GOST + ? getGostReference(referenceDto) + : getSpringerReference(referenceDto); + } + + public String getGostReference(ReferenceDto referenceDto) { + return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.", + referenceDto.getAuthors(), + referenceDto.getPublicationTitle(), + StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", + referenceDto.getPublicationYear().toString(), + referenceDto.getPages(), + StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + "."); + } + + public String getSpringerReference(ReferenceDto referenceDto) { + return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}", + referenceDto.getAuthors(), + referenceDto.getPublicationYear().toString(), + referenceDto.getPublicationTitle(), + referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "", + StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", + referenceDto.getPages()); + } } diff --git a/src/main/resources/db/changelog-20190428_000000-schema.xml b/src/main/resources/db/changelog-20190428_000000-schema.xml new file mode 100644 index 0000000..b44691d --- /dev/null +++ b/src/main/resources/db/changelog-20190428_000000-schema.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index f5a1451..6f8e878 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -35,4 +35,5 @@ + \ No newline at end of file diff --git a/src/main/resources/mail_templates/paperCreateNotification.html b/src/main/resources/mail_templates/paperCreateNotification.html index 2758143..82362bd 100644 --- a/src/main/resources/mail_templates/paperCreateNotification.html +++ b/src/main/resources/mail_templates/paperCreateNotification.html @@ -12,9 +12,11 @@

Вам нужно поработать над статьей "Title".

-

- Срок исполнения: . -

+
+

+ Срок исполнения: . +

+

Regards,