save paper
This commit is contained in:
parent
7587ff7a51
commit
5755cf2f92
5
src/main/java/ru/ulstu/core/navigation/Page.java
Normal file
5
src/main/java/ru/ulstu/core/navigation/Page.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package ru.ulstu.core.navigation;
|
||||||
|
|
||||||
|
public class Page {
|
||||||
|
public static final String PAPER_LIST = "/paper/papers.xhtml";
|
||||||
|
}
|
@ -16,6 +16,6 @@ public class PaperStatusConverter implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
||||||
return ((Paper.PaperStatus) value).getStatusName();
|
return ((Paper.PaperStatus) value).name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ public class PaperTypeConverter implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
||||||
return ((Paper.PaperType) value).getTypeName();
|
return ((Paper.PaperType) value).name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
|
import ru.ulstu.core.navigation.Page;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
|
||||||
@ -8,14 +9,13 @@ import javax.faces.context.FacesContext;
|
|||||||
import javax.faces.view.ViewScoped;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Named
|
@Named
|
||||||
@ViewScoped
|
@ViewScoped
|
||||||
public class PaperView implements Serializable {
|
public class PaperView {
|
||||||
@Inject
|
@Inject
|
||||||
private PaperService paperService;
|
private PaperService paperService;
|
||||||
|
|
||||||
@ -43,4 +43,9 @@ public class PaperView implements Serializable {
|
|||||||
public List<Paper.PaperType> getPaperTypes() {
|
public List<Paper.PaperType> getPaperTypes() {
|
||||||
return Arrays.asList(Paper.PaperType.values());
|
return Arrays.asList(Paper.PaperType.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String save() {
|
||||||
|
paperService.save(paper);
|
||||||
|
return Page.PAPER_LIST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,17 +103,13 @@ public class PaperService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(PaperDto paperDto) throws IOException {
|
public Integer create(PaperDto paperDto) throws IOException {
|
||||||
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
||||||
newPaper = paperRepository.save(newPaper);
|
return create(newPaper).getId();
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
|
||||||
eventService.createFromPaper(newPaper);
|
|
||||||
return newPaper.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(Paper paper) {
|
public Paper create(Paper paper) {
|
||||||
Paper newPaper = paperRepository.save(paper);
|
Paper newPaper = paperRepository.save(paper);
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
paperNotificationService.sendCreateNotification(newPaper);
|
||||||
eventService.createFromPaper(newPaper);
|
|
||||||
return newPaper;
|
return newPaper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +202,26 @@ public class PaperService {
|
|||||||
return paper.getId();
|
return paper.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Integer update(Paper newPaper) {
|
||||||
|
Paper oldPaper = paperRepository.getOne(newPaper.getId());
|
||||||
|
Paper.PaperStatus oldStatus = oldPaper.getStatus();
|
||||||
|
Set<User> oldAuthors = new HashSet<>(oldPaper.getAuthors());
|
||||||
|
|
||||||
|
newPaper = paperRepository.save(newPaper);
|
||||||
|
for (User author : newPaper.getAuthors()) {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
paperNotificationService.sendCreateNotification(newPaper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPaper.getStatus() != oldStatus) {
|
||||||
|
paperNotificationService.statusChangeNotification(newPaper, oldStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newPaper.getId();
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer paperId) {
|
public void delete(Integer paperId) {
|
||||||
Paper paper = paperRepository.getOne(paperId);
|
Paper paper = paperRepository.getOne(paperId);
|
||||||
@ -292,6 +308,14 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save(Paper paper) {
|
||||||
|
if (isEmpty(paper.getId())) {
|
||||||
|
create(paper);
|
||||||
|
} else {
|
||||||
|
update(paper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PaperDto findById(Integer paperId) {
|
public PaperDto findById(Integer paperId) {
|
||||||
return new PaperDto(paperRepository.getOne(paperId));
|
return new PaperDto(paperRepository.getOne(paperId));
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
itemValue="#{type}"/>
|
itemValue="#{type}"/>
|
||||||
</p:selectOneMenu>
|
</p:selectOneMenu>
|
||||||
</h:panelGrid>
|
</h:panelGrid>
|
||||||
|
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"/>
|
||||||
</p:panel>
|
</p:panel>
|
||||||
</ui:define>
|
</ui:define>
|
||||||
</ui:composition>
|
</ui:composition>
|
||||||
|
@ -18,6 +18,7 @@ logging.level.com.gargoylesoftware.htmlunit=ERROR
|
|||||||
#jsf
|
#jsf
|
||||||
joinfaces.primefaces.theme=casablanca
|
joinfaces.primefaces.theme=casablanca
|
||||||
joinfaces.primefaces.font-awesome=true
|
joinfaces.primefaces.font-awesome=true
|
||||||
|
joinfaces.mojarra.enable-restore-view11-compatibility=true
|
||||||
# Mail Settings
|
# Mail Settings
|
||||||
spring.mail.host=smtp.yandex.ru
|
spring.mail.host=smtp.yandex.ru
|
||||||
spring.mail.port=465
|
spring.mail.port=465
|
||||||
|
Loading…
Reference in New Issue
Block a user