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
|
||||
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
|
||||
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;
|
||||
|
||||
import ru.ulstu.core.navigation.Page;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
|
||||
@ -8,14 +9,13 @@ import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class PaperView implements Serializable {
|
||||
public class PaperView {
|
||||
@Inject
|
||||
private PaperService paperService;
|
||||
|
||||
@ -43,4 +43,9 @@ public class PaperView implements Serializable {
|
||||
public List<Paper.PaperType> getPaperTypes() {
|
||||
return Arrays.asList(Paper.PaperType.values());
|
||||
}
|
||||
|
||||
public String save() {
|
||||
paperService.save(paper);
|
||||
return Page.PAPER_LIST;
|
||||
}
|
||||
}
|
||||
|
@ -103,17 +103,13 @@ public class PaperService {
|
||||
@Transactional
|
||||
public Integer create(PaperDto paperDto) throws IOException {
|
||||
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
||||
newPaper = paperRepository.save(newPaper);
|
||||
paperNotificationService.sendCreateNotification(newPaper);
|
||||
eventService.createFromPaper(newPaper);
|
||||
return newPaper.getId();
|
||||
return create(newPaper).getId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Paper create(Paper paper) {
|
||||
Paper newPaper = paperRepository.save(paper);
|
||||
paperNotificationService.sendCreateNotification(newPaper);
|
||||
eventService.createFromPaper(newPaper);
|
||||
return newPaper;
|
||||
}
|
||||
|
||||
@ -206,6 +202,26 @@ public class PaperService {
|
||||
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
|
||||
public void delete(Integer 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) {
|
||||
return new PaperDto(paperRepository.getOne(paperId));
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
itemValue="#{type}"/>
|
||||
</p:selectOneMenu>
|
||||
</h:panelGrid>
|
||||
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"/>
|
||||
</p:panel>
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
|
@ -18,6 +18,7 @@ logging.level.com.gargoylesoftware.htmlunit=ERROR
|
||||
#jsf
|
||||
joinfaces.primefaces.theme=casablanca
|
||||
joinfaces.primefaces.font-awesome=true
|
||||
joinfaces.mojarra.enable-restore-view11-compatibility=true
|
||||
# Mail Settings
|
||||
spring.mail.host=smtp.yandex.ru
|
||||
spring.mail.port=465
|
||||
|
Loading…
Reference in New Issue
Block a user