Merge branch '108-references-formatting' into 'dev'
Resolve "Форматирование списка литературы" Closes #108 See merge request romanov73/ng-tracker!78
This commit is contained in:
commit
1fe2f5469b
@ -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<List<String>> getFormattedPaperList() {
|
||||
return new Response<>(paperService.getFormattedPaperList());
|
||||
}
|
||||
|
||||
@PostMapping("/getFormattedReference")
|
||||
public Response<String> getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) {
|
||||
return new Response<>(paperService.getFormattedReference(referenceDto));
|
||||
}
|
||||
}
|
||||
|
129
src/main/java/ru/ulstu/paper/model/ReferenceDto.java
Normal file
129
src/main/java/ru/ulstu/paper/model/ReferenceDto.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user