-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
220 additions
and
3 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/ru/martha/autotesting/controller/ProjectsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package ru.martha.autotesting.controller; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import ru.martha.autotesting.entity.Project; | ||
import ru.martha.autotesting.service.TesterService; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.faces.application.FacesMessage; | ||
import javax.faces.bean.ManagedBean; | ||
import javax.faces.bean.ManagedProperty; | ||
import javax.faces.bean.ViewScoped; | ||
import javax.faces.context.FacesContext; | ||
import java.io.Serializable; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@ManagedBean | ||
@ViewScoped | ||
public class ProjectsController implements Serializable { | ||
|
||
@ManagedProperty("#{testerServiceImpl}") | ||
@Setter | ||
private TesterService testerService; | ||
|
||
@Getter | ||
private List<Project> projects; | ||
|
||
@Getter | ||
@Setter | ||
private Project selectedProject; | ||
|
||
@Setter | ||
@Getter | ||
private boolean isEditMode; | ||
|
||
@Setter | ||
@Getter | ||
private boolean isNewProject; | ||
|
||
@PostConstruct | ||
private void init() { | ||
projects = testerService.getAllProjects(); | ||
} | ||
|
||
public void onProjectSelected() { | ||
isEditMode = false; | ||
} | ||
|
||
public void createProject() { | ||
selectedProject = new Project(); | ||
selectedProject.setCreationDate(new Date()); | ||
projects.add(selectedProject); | ||
isNewProject = true; | ||
isEditMode = true; | ||
} | ||
|
||
public void cancelCreateProject() { | ||
selectedProject = null; | ||
projects = testerService.getAllProjects(); | ||
isEditMode = false; | ||
isNewProject = false; | ||
} | ||
|
||
public void saveProject() { | ||
try { | ||
testerService.createOrUpdateProject(selectedProject); | ||
projects = testerService.getAllProjects(); | ||
isEditMode = false; | ||
isNewProject = false; | ||
} catch (Exception e) { | ||
FacesMessage message = new FacesMessage("Произошла ошибка при сохранении"); | ||
message.setSeverity(FacesMessage.SEVERITY_ERROR); | ||
FacesContext.getCurrentInstance().addMessage(null, message); | ||
} | ||
} | ||
|
||
public void removeProject() { | ||
try { | ||
testerService.removeProject(selectedProject); | ||
selectedProject = null; | ||
projects = testerService.getAllProjects(); | ||
} catch (Exception e) { | ||
FacesMessage message = new FacesMessage("Произошла ошибка при удалении"); | ||
message.setSeverity(FacesMessage.SEVERITY_ERROR); | ||
FacesContext.getCurrentInstance().addMessage(null, message); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ru/martha/autotesting/service/TesterService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.martha.autotesting.service; | ||
|
||
import ru.martha.autotesting.entity.Project; | ||
import ru.martha.autotesting.entity.ProjectVersion; | ||
|
||
import java.util.List; | ||
|
||
public interface TesterService { | ||
List<Project> getAllProjects(); | ||
List<ProjectVersion> getProjectVersions(Project project); | ||
void createOrUpdateProject(Project project); | ||
void removeProject(Project project); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/ru/martha/autotesting/service/impl/TesterServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ru.martha.autotesting.service.impl; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import ru.martha.autotesting.entity.Project; | ||
import ru.martha.autotesting.entity.ProjectVersion; | ||
import ru.martha.autotesting.repository.ProjectsRepository; | ||
import ru.martha.autotesting.service.TesterService; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional | ||
public class TesterServiceImpl implements TesterService { | ||
|
||
@Autowired | ||
private ProjectsRepository projectsRepository; | ||
|
||
@Override | ||
public List<Project> getAllProjects() { | ||
return projectsRepository.findAll(); | ||
} | ||
|
||
@Override | ||
public List<ProjectVersion> getProjectVersions(Project project) { | ||
return projectsRepository.getOne(project.getId()).getVersions(); | ||
} | ||
|
||
@Override | ||
public void createOrUpdateProject(Project project) { | ||
projectsRepository.save(project); | ||
} | ||
|
||
@Override | ||
public void removeProject(Project project) { | ||
projectsRepository.delete(project); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters