Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/io/khasang/pm/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ public CatDao catDao() {
}

@Bean
public ProjectDao projectDao() {return new ProjectDaoImpl(Project.class);
public ProjectDao projectDao() {
return new ProjectDaoImpl(Project.class);
}

@Bean
public DocumentDao documentDao(){
return new DocumentDaoImpl(Document.class);
}

@Bean
public RoleDao roleDao() {
return new RoleDaoImpl(Role.class);
}

@Bean
public EmployeeDao employeeDao(){
return new EmployeeDaoImpl(Employee.class);
Expand All @@ -46,4 +52,4 @@ public EmployeeDao employeeDao(){
public ChildDocumentDao childDocumentDao() {
return new ChildDocumentDaoImpl(ChildDocument.class);
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/io/khasang/pm/controller/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public String getHelloPage() {
return "cat";
}

@RequestMapping("/role")
public String getRole() {
return "role";
}

@RequestMapping("/childDocument")
public String getСhildDocumentPage() {
return "childdocument";
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/io/khasang/pm/controller/RoleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.khasang.pm.controller;

import io.khasang.pm.entity.Role;
import io.khasang.pm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {
private RoleService roleService;

@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public Role addRole(@RequestBody Role role){
return roleService.add(role);
}

@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
@ResponseBody
public Role getById(@PathVariable("id") long id) {
return roleService.getById(id);
}

@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public List<Role> getAll(){
return roleService.getAll();
}

@Autowired
public void setRoleService(RoleService roleService){
this.roleService = roleService;
}
}
6 changes: 6 additions & 0 deletions src/main/java/io/khasang/pm/dao/RoleDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.khasang.pm.dao;

import io.khasang.pm.entity.Role;

public interface RoleDao extends BasicDao<Role> {
}
10 changes: 10 additions & 0 deletions src/main/java/io/khasang/pm/dao/impl/RoleDaoImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.khasang.pm.dao.impl;

import io.khasang.pm.dao.RoleDao;
import io.khasang.pm.entity.Role;

public class RoleDaoImpl extends BasicDaoImpl<Role> implements RoleDao {
public RoleDaoImpl(Class<Role> entityClass) {
super(entityClass);
}
}
37 changes: 37 additions & 0 deletions src/main/java/io/khasang/pm/entity/Login.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.khasang.pm.entity;

import javax.persistence.*;

@Entity
@Table(name = "login")
public class Login {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String description;

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 getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
51 changes: 51 additions & 0 deletions src/main/java/io/khasang/pm/entity/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.khasang.pm.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "roles")
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private String name;
private String description;

public List<Login> getLogin() {
return login;
}

public void setLogin(List<Login> login) {
this.login = login;
}

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<Login> login = new ArrayList<>();

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 getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/khasang/pm/service/RoleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.khasang.pm.service;

import io.khasang.pm.entity.Role;

import java.util.List;

public interface RoleService {
Role add(Role role);
Role getById(long id);
List<Role> getAll();
}
34 changes: 34 additions & 0 deletions src/main/java/io/khasang/pm/service/impl/RoleServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.khasang.pm.service.impl;

import io.khasang.pm.dao.RoleDao;
import io.khasang.pm.entity.Role;
import io.khasang.pm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {
private RoleDao roleDao;

@Override
public Role add(Role role) {
return roleDao.add(role);
}

@Override
public Role getById(long id) {
return roleDao.getById(id);
}

@Override
public List<Role> getAll() {
return roleDao.getAll();
}

@Autowired
public void setRoleDao (RoleDao roleDao){
this.roleDao = roleDao;
}
}
109 changes: 109 additions & 0 deletions src/main/webapp/WEB-INF/views/role.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<title>Title</title>
</head>
<script>
var service = 'http://localhost:8080/role'
var RestGetAll = function () {
$.ajax({
type: 'GET',
url: service + '/all',
dataType: 'json',
accept: 'json',
contentType: 'application/json;utf-8',
async: false,
success: function (result) {
$('#response').html(JSON.stringify(result))
},
error: function (jqXHR, testStatus, errorThrown) {
$('#response').html(JSON.stringify(jqXHR))
}
});
};
var RestGet = function (id) {
$.ajax({
type: 'GET',
url: service + '/get/' + id,
dataType: 'json',
accept: 'json',
contentType: 'application/json;utf-8',
async: false,
success: function (result) {
$('#response').html(JSON.stringify(result))
},
error: function (jqXHR, testStatus, errorThrown) {
$('#response').html(JSON.stringify(jqXHR))
}
});
};
var RestPost = function (name, description, time, presult) {
var JSONObject = {
'name': name,
'description': description,
'time': time,
'result': presult
};
$.ajax({
type: 'POST',
url: service + '/add',
dataType: 'json',
data: JSON.stringify(JSONObject),
accept: 'json',
contentType: 'application/json;utf-8',
async: false,
success: function (result) {
$('#response').html(JSON.stringify(result))
},
error: function (jqXHR, testStatus, errorThrown) {
$('#response').html(JSON.stringify(jqXHR))
}
});
};
</script>

<body>
<h1>Role Menu</h1>

<table class="table">
<tr>
<th>Request type</th>
<th>URL</th>
<th>Value</th>
</tr>
<tr>
<td>Get All roles - <code><strong>GET</strong></code></td>
<td>/role/all</td>
<td>
<button type="button" onclick="RestGetAll()">try</button>
</td>
</tr>
<tr>
<td>Get role by id - <code><strong>GET</strong></code></td>
<td>/role/get/{id}</td>
<td>
id: <input id="getRoleByID" value="1"/>
<button type="button" onclick="RestGet($('#getRoleByID').val())">try</button>
</td>
</tr>
<tr>
<td>add new role - <code><strong>POST</strong></code></td>
<td>/role/add</td>
<td>
name: <input id="roleName" value="testRole"/>
description: <input id="roleDescription" value="someRole"/>
<button type="button" onclick="RestPost($('#roleName').val(), $('#roleDescription').val())">try</button>
</td>
</tr>
</table>

<div class="panel panel-default">
<div class="page-heading">
<strong>RESPONSE></strong>
</div>
<div class="panel-body" id="response"></div>
</div>
</body>
</html>
Loading