diff --git a/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java index b70a780..91c3bf4 100644 --- a/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java +++ b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java @@ -1,42 +1,43 @@ package ru.ulstu.paper.model; import java.util.ArrayList; +import java.util.List; public class AutoCompleteData { - ArrayList authors = new ArrayList<>(); - ArrayList publicationTitles = new ArrayList<>(); - ArrayList publishers = new ArrayList<>(); - ArrayList journalOrCollectionTitles = new ArrayList<>(); + private List authors = new ArrayList<>(); + private List publicationTitles = new ArrayList<>(); + private List publishers = new ArrayList<>(); + private List journalOrCollectionTitles = new ArrayList<>(); - public ArrayList getAuthors() { + public List getAuthors() { return authors; } - public void setAuthors(ArrayList authors) { + public void setAuthors(List authors) { this.authors = authors; } - public ArrayList getPublicationTitles() { + public List getPublicationTitles() { return publicationTitles; } - public void setPublicationTitles(ArrayList publicationTitles) { + public void setPublicationTitles(List publicationTitles) { this.publicationTitles = publicationTitles; } - public ArrayList getPublishers() { + public List getPublishers() { return publishers; } - public void setPublishers(ArrayList publishers) { + public void setPublishers(List publishers) { this.publishers = publishers; } - public ArrayList getJournalOrCollectionTitles() { + public List getJournalOrCollectionTitles() { return journalOrCollectionTitles; } - public void setJournalOrCollectionTitles(ArrayList journalOrCollectionTitles) { + public void setJournalOrCollectionTitles(List journalOrCollectionTitles) { this.journalOrCollectionTitles = journalOrCollectionTitles; } } diff --git a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java index 1d4321b..942a5b8 100644 --- a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java @@ -4,20 +4,20 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import ru.ulstu.paper.model.Reference; -import java.util.ArrayList; +import java.util.List; public interface ReferenceRepository extends JpaRepository { void deleteById(Integer id); @Query("SELECT DISTINCT r.authors FROM Reference r") - ArrayList findDistinctAuthors(); + List findDistinctAuthors(); @Query("SELECT DISTINCT r.publicationTitle FROM Reference r") - ArrayList findDistinctPublicationTitles(); + List findDistinctPublicationTitles(); @Query("SELECT DISTINCT r.publisher FROM Reference r") - ArrayList findDistinctPublishers(); + List findDistinctPublishers(); @Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''") - ArrayList findDistinctJournalOrCollectionTitles(); + List findDistinctJournalOrCollectionTitles(); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index cfb1a0a..2393af4 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -146,13 +146,7 @@ public class PaperService { @Transactional public Reference updateReference(ReferenceDto referenceDto) { Reference updateReference = referenceRepository.findOne(referenceDto.getId()); - updateReference.setAuthors(referenceDto.getAuthors()); - updateReference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle()); - updateReference.setPages(referenceDto.getPages()); - updateReference.setPublicationTitle(referenceDto.getPublicationTitle()); - updateReference.setPublicationYear(referenceDto.getPublicationYear()); - updateReference.setPublisher(referenceDto.getPublisher()); - updateReference.setReferenceType(referenceDto.getReferenceType()); + copyFromDto(updateReference, referenceDto); referenceRepository.save(updateReference); return updateReference; } @@ -160,17 +154,21 @@ public class PaperService { @Transactional public Reference createReference(ReferenceDto referenceDto) { Reference newReference = new Reference(); - newReference.setAuthors(referenceDto.getAuthors()); - newReference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle()); - newReference.setPages(referenceDto.getPages()); - newReference.setPublicationTitle(referenceDto.getPublicationTitle()); - newReference.setPublicationYear(referenceDto.getPublicationYear()); - newReference.setPublisher(referenceDto.getPublisher()); - newReference.setReferenceType(referenceDto.getReferenceType()); + copyFromDto(newReference, referenceDto); newReference = referenceRepository.save(newReference); return newReference; } + private Reference copyFromDto(Reference reference, ReferenceDto referenceDto) { + reference.setAuthors(referenceDto.getAuthors()); + reference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle()); + reference.setPages(referenceDto.getPages()); + reference.setPublicationTitle(referenceDto.getPublicationTitle()); + reference.setPublicationYear(referenceDto.getPublicationYear()); + reference.setPublisher(referenceDto.getPublisher()); + reference.setReferenceType(referenceDto.getReferenceType()); + return reference; + } @Transactional public Integer update(PaperDto paperDto) throws IOException {