test master 변경
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
package com.eactive.testmaster.server.controller;
|
||||
|
||||
import com.eactive.testmaster.server.dto.ServerDTO;
|
||||
import com.eactive.testmaster.server.dto.ServerSearch;
|
||||
import com.eactive.testmaster.server.entity.Server;
|
||||
import com.eactive.testmaster.server.mapper.ServerMapper;
|
||||
import com.eactive.testmaster.server.service.ServerMgmtService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/mgmt/servers")
|
||||
public class ServerMgmtController {
|
||||
|
||||
private final ServerMgmtService serverMgmtService;
|
||||
|
||||
private final ServerMapper serverMapper;
|
||||
|
||||
private final Validator validator;
|
||||
|
||||
public ServerMgmtController(ServerMgmtService serverMgmtService, ServerMapper serverMapper, Validator validator) {
|
||||
this.serverMgmtService = serverMgmtService;
|
||||
this.serverMapper = serverMapper;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
public static final String SERVER = "server";
|
||||
|
||||
public static final String SERVER_EDIT = "page/servers/serverEdit";
|
||||
|
||||
public static final String SERVER_LIST_VIEW = "redirect:/mgmt/servers/list_view.do";
|
||||
|
||||
@GetMapping("/list_view.do")
|
||||
public String listView(@ModelAttribute("serverSearch") ServerSearch serverSearch,
|
||||
ModelMap model,
|
||||
Pageable pageable) {
|
||||
|
||||
Page<Server> page = serverMgmtService.findAll(serverSearch.buildSpecification(), pageable);
|
||||
model.addAttribute("page", page);
|
||||
model.addAttribute("pageable", pageable);
|
||||
model.addAttribute("modelSearch", serverSearch);
|
||||
|
||||
return "page/servers/serverList";
|
||||
}
|
||||
|
||||
@GetMapping("/create_view.do")
|
||||
public String createView(ModelMap model) {
|
||||
ServerDTO defaultServer = new ServerDTO();
|
||||
model.addAttribute(SERVER, defaultServer);
|
||||
return SERVER_EDIT;
|
||||
}
|
||||
|
||||
@GetMapping("/update_view.do")
|
||||
public String updateView(ModelMap model, @RequestParam("id") Long id) {
|
||||
Server found = serverMgmtService.findById(id);
|
||||
ServerDTO server = serverMapper.map(found);
|
||||
model.addAttribute(SERVER, server);
|
||||
return SERVER_EDIT;
|
||||
}
|
||||
|
||||
@PostMapping("/register.do")
|
||||
public String register(@ModelAttribute(SERVER) ServerDTO dto,
|
||||
BindingResult bindingResult,
|
||||
ModelMap model) {
|
||||
|
||||
if (dto == null) {
|
||||
return "redirect:/mgmt/servers/create_view.do";
|
||||
}
|
||||
|
||||
validator.validate(dto, bindingResult);
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute(SERVER, dto);
|
||||
return SERVER_EDIT;
|
||||
}
|
||||
|
||||
Server server = serverMapper.map(dto);
|
||||
serverMgmtService.create(server);
|
||||
return SERVER_LIST_VIEW;
|
||||
}
|
||||
|
||||
@PostMapping("/update.do")
|
||||
public String update(@ModelAttribute(SERVER) ServerDTO dto,
|
||||
BindingResult bindingResult,
|
||||
ModelMap model) {
|
||||
|
||||
if (StringUtils.isEmpty(dto.getId().toString())) {
|
||||
return SERVER_LIST_VIEW;
|
||||
}
|
||||
|
||||
validator.validate(dto, bindingResult);
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute(SERVER, dto);
|
||||
return SERVER_EDIT;
|
||||
}
|
||||
|
||||
Server updated = serverMapper.map(dto);
|
||||
serverMgmtService.update(dto.getId(), updated);
|
||||
return SERVER_LIST_VIEW;
|
||||
}
|
||||
|
||||
@PostMapping("/delete.do")
|
||||
public String delete(@RequestParam("checkedIdForDel") List<String> checkedIdForDel) {
|
||||
for (String id : checkedIdForDel) {
|
||||
serverMgmtService.delete(Long.parseLong(id));
|
||||
}
|
||||
return SERVER_LIST_VIEW;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.eactive.testmaster.server.dto;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public class ServerDTO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@NotEmpty
|
||||
private String name;
|
||||
|
||||
@NotEmpty
|
||||
private String scheme = "http";
|
||||
|
||||
@NotEmpty
|
||||
private String hostname;
|
||||
|
||||
@NotEmpty
|
||||
private String basePath = "/";
|
||||
|
||||
private Integer port = 80;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public void setScheme(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.eactive.testmaster.server.dto;
|
||||
|
||||
import com.eactive.testmaster.common.search.BaseSearch;
|
||||
import com.eactive.testmaster.common.search.ColumnSearchModel;
|
||||
import com.eactive.testmaster.common.search.SearchCondition;
|
||||
import com.eactive.testmaster.common.search.SearchModel;
|
||||
import com.eactive.testmaster.server.entity.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ServerSearch implements BaseSearch<Server> {
|
||||
|
||||
private String name;
|
||||
|
||||
private String hostname;
|
||||
|
||||
private String basePath;
|
||||
|
||||
private String port;
|
||||
|
||||
@Override
|
||||
public List<SearchModel> buildSearchCondition() {
|
||||
List<SearchModel> models = new ArrayList<>();
|
||||
|
||||
if (StringUtils.isNotEmpty(name)) {
|
||||
models.add(new ColumnSearchModel("name", SearchCondition.LIKE, name));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(hostname)) {
|
||||
models.add(new ColumnSearchModel("hostname", SearchCondition.LIKE, hostname));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(basePath)) {
|
||||
models.add(new ColumnSearchModel("basePath", SearchCondition.LIKE, basePath));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(port)) {
|
||||
models.add(new ColumnSearchModel("port", SearchCondition.EQUAL, Integer.parseInt(port)));
|
||||
}
|
||||
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.eactive.testmaster.server.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "SERVER")
|
||||
public class Server {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String scheme;
|
||||
|
||||
private String hostname;
|
||||
|
||||
private String basePath;
|
||||
|
||||
private Integer port;
|
||||
|
||||
@Column(name = "IS_ENABLED", columnDefinition = "boolean default true")
|
||||
private boolean enabled;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public void setScheme(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public String getFullHostAddress() {
|
||||
return scheme + "://" + hostname + (port == null ? "" : ":" + port) + basePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.eactive.testmaster.server.entity;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ServerRepository extends JpaRepository<Server, Long>, JpaSpecificationExecutor<Server> {
|
||||
|
||||
|
||||
List<Server> findAllByEnabledIs(boolean enabled);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.eactive.testmaster.server.mapper;
|
||||
|
||||
|
||||
import com.eactive.testmaster.common.exception.NotFoundException;
|
||||
import com.eactive.testmaster.server.dto.ServerDTO;
|
||||
import com.eactive.testmaster.server.entity.Server;
|
||||
import com.eactive.testmaster.server.entity.ServerRepository;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Mapper(componentModel = "spring",
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Component
|
||||
public class ServerMapper {
|
||||
|
||||
@Autowired
|
||||
ServerRepository serverRepository;
|
||||
|
||||
public Server mapById(Long id) {
|
||||
if (id == null || id == 0) return null;
|
||||
return serverRepository.findById(id).orElseThrow(() -> new NotFoundException("Server[" + id + "] not found"));
|
||||
}
|
||||
|
||||
public Long mapById(Server server) {
|
||||
if (server == null) return null;
|
||||
return server.getId();
|
||||
}
|
||||
|
||||
public ServerDTO map(Server server) {
|
||||
if (server == null) return null;
|
||||
ServerDTO dto = new ServerDTO();
|
||||
|
||||
dto.setId(server.getId());
|
||||
dto.setName(server.getName());
|
||||
dto.setHostname(server.getHostname());
|
||||
dto.setPort(server.getPort());
|
||||
dto.setScheme(server.getScheme());
|
||||
dto.setBasePath(server.getBasePath());
|
||||
dto.setEnabled(server.isEnabled());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
public Server map(ServerDTO dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
Server server = new Server();
|
||||
|
||||
server.setId(dto.getId());
|
||||
server.setName(dto.getName());
|
||||
server.setHostname(dto.getHostname());
|
||||
server.setPort(dto.getPort());
|
||||
server.setScheme(dto.getScheme());
|
||||
server.setBasePath(dto.getBasePath());
|
||||
server.setEnabled(dto.isEnabled());
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.eactive.testmaster.server.service;
|
||||
|
||||
import com.eactive.testmaster.common.exception.NotFoundException;
|
||||
import com.eactive.testmaster.server.entity.Server;
|
||||
import com.eactive.testmaster.server.entity.ServerRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class ServerMgmtService {
|
||||
|
||||
@Autowired
|
||||
private ServerRepository serverRepository;
|
||||
|
||||
public Page<Server> findAll(Specification<Server> serverSpecification, Pageable pageable) {
|
||||
return serverRepository.findAll(serverSpecification, pageable);
|
||||
}
|
||||
|
||||
public Server findById(Long id) {
|
||||
return serverRepository.findById(id).orElseThrow(() -> new NotFoundException("Server Not Found"));
|
||||
}
|
||||
|
||||
public void create(Server server) {
|
||||
serverRepository.save(server);
|
||||
}
|
||||
|
||||
public void update(Long id, Server updated) {
|
||||
Server server = serverRepository.findById(id).orElseThrow(() -> new NotFoundException("Server Not Found"));
|
||||
|
||||
server.setName(updated.getName());
|
||||
server.setScheme(updated.getScheme());
|
||||
server.setHostname(updated.getHostname());
|
||||
server.setBasePath(updated.getBasePath());
|
||||
server.setPort(updated.getPort());
|
||||
server.setEnabled(updated.isEnabled());
|
||||
|
||||
serverRepository.save(server);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
serverRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user