baza danych rozwiniecie
This commit is contained in:
1 parent
99c1aef51c
commit
ffc0dcff67
11 files changed
+291
-34
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package application;
|
||||
|
||||
import application.repositories.RoleRepository;
|
||||
import application.utils.TokensGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -21,7 +20,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
@EnableScheduling
|
||||
public class Config {
|
||||
|
||||
@Scheduled(fixedRate = 500)
|
||||
@Scheduled(fixedRate = 50000)
|
||||
public void generatePassword() {
|
||||
TokensGenerator.generatePassword();
|
||||
}
|
||||
@@ -29,8 +28,6 @@ public class Config {
|
||||
public static void main(String[] args) {
|
||||
|
||||
ConfigurableApplicationContext context = SpringApplication.run(Config.class, args);
|
||||
RoleRepository rr = context.getBean(RoleRepository.class);
|
||||
System.out.print(rr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package application.Services;
|
||||
|
||||
import application.repositories.RoleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
public class RolesService {
|
||||
|
||||
@Autowired
|
||||
private RoleRepository rolesRepository;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package application.controllers;
|
||||
|
||||
import application.model.Role;
|
||||
import application.repositories.RoleRepository;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/roles")
|
||||
public class RoleController {
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@RequestMapping(value = "/add")
|
||||
@ResponseBody
|
||||
public String addRole(@RequestParam String rolename,@RequestParam String password) {
|
||||
Role role = new Role(rolename,password);
|
||||
roleRepository.save(role);
|
||||
return "saved role: "+role.getRoleId();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/{roleId}")
|
||||
public String getRole(@PathVariable("roleId") Long roleId) {
|
||||
Role role = roleRepository.findOne(roleId);
|
||||
return "role: "+role.toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/all")
|
||||
public
|
||||
@ResponseBody
|
||||
String listRolesJson(ModelMap model) throws JSONException {
|
||||
JSONArray roleArray = new JSONArray();
|
||||
for (Role role : roleRepository.findAll()) {
|
||||
JSONObject roleJSON = new JSONObject();
|
||||
roleJSON.put("id", role.getRoleId());
|
||||
roleJSON.put("role", role.getRoleName());
|
||||
roleJSON.put("password", role.getPassword());
|
||||
roleArray.put(roleJSON);
|
||||
}
|
||||
return roleArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/remove/{roleId}")
|
||||
public String removeRole(@PathVariable("roleId") Long roleId) {
|
||||
roleRepository.delete(roleId);
|
||||
return "role deleted: "+roleId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package application.controllers;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
public class TimeSheetController {
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package application.controllers;
|
||||
|
||||
import application.model.Role;
|
||||
import application.model.User;
|
||||
import application.repositories.UserRepository;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value="/users")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@RequestMapping(value = "/add")
|
||||
@ResponseBody
|
||||
public String addUser(@RequestParam String username) {
|
||||
User user = new User();
|
||||
user.setFirstName(username);
|
||||
Set<Role> roles = new HashSet<Role>();
|
||||
roles.add(new Role("lala","lala"));
|
||||
roles.add(new Role("lala1","lala1"));
|
||||
user.setRoles(roles);
|
||||
userRepository.save(user);
|
||||
return "saved user: "+user.getUserId();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/{userId}")
|
||||
public String getUser(@PathVariable("userId") Long userId) {
|
||||
User user = userRepository.findOne(userId);
|
||||
return "user: "+user.toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/all")
|
||||
public
|
||||
@ResponseBody
|
||||
String listUsersJson(ModelMap model) throws JSONException {
|
||||
JSONArray userArray = new JSONArray();
|
||||
for (User user : userRepository.findAll()) {
|
||||
JSONObject userJSON = new JSONObject();
|
||||
userJSON.put("id", user.getUserId());
|
||||
userJSON.put("firstname", user.getFirstName());
|
||||
userArray.put(userJSON);
|
||||
}
|
||||
return userArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/remove/{userId}")
|
||||
public String removeUser(@PathVariable("userId") Long userId) {
|
||||
userRepository.delete(userId);
|
||||
return "user deleted: "+userId;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,53 @@
|
||||
package application.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity(name = "role")
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
@Entity (name = "role")
|
||||
public class Role {
|
||||
@Id
|
||||
@Column(name = "ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
@Basic
|
||||
private String role;
|
||||
|
||||
private String roleName;
|
||||
@Basic
|
||||
private String password;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ManyToMany(mappedBy="roles")
|
||||
private Set<User> users = new HashSet<User>();
|
||||
|
||||
public Role() {
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
public Role(String roleName, String password) {
|
||||
this.roleName = roleName;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRoleName() {
|
||||
|
||||
return roleName;
|
||||
}
|
||||
|
||||
public void setRoleName(String roleName) {
|
||||
this.roleName = roleName;
|
||||
}
|
||||
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package application.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.sql.Time;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
|
||||
@Entity(name = "timeSheet")
|
||||
public class TimeSheet {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Basic
|
||||
private Date date;
|
||||
|
||||
@Basic
|
||||
private Time time;
|
||||
|
||||
@Basic String ActivityType;
|
||||
|
||||
@Basic
|
||||
private Long UserId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Time getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Time time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getActivityType() {
|
||||
return ActivityType;
|
||||
}
|
||||
|
||||
public void setActivityType(String activityType) {
|
||||
ActivityType = activityType;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return UserId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
UserId = userId;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package application.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity(name = "account")
|
||||
public class User {
|
||||
@Id
|
||||
@Column(name = "userId")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private Long userId;
|
||||
|
||||
@Basic
|
||||
private String firstName;
|
||||
@@ -17,15 +20,25 @@ public class User {
|
||||
@Basic
|
||||
private String email;
|
||||
|
||||
@Basic
|
||||
private String role;
|
||||
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
|
||||
@JoinTable(
|
||||
name="User_Role",
|
||||
joinColumns = @JoinColumn( name="User_ID"),
|
||||
inverseJoinColumns = @JoinColumn( name="Role_ID")
|
||||
)
|
||||
private Set<Role> roles = new HashSet<Role>(
|
||||
0);
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
private Set<Role> getRole(){
|
||||
return roles;
|
||||
};
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
@@ -52,11 +65,11 @@ public class User {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
public Set<Role> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
public void setRoles(Set<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,8 @@ package application.repositories;
|
||||
import application.model.Role;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
public interface RoleRepository extends CrudRepository<Role, Long> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package application.repositories;
|
||||
|
||||
import application.model.TimeSheet;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* Created by lukasgol on 21.04.14.
|
||||
*/
|
||||
public interface TimeSheetRepository extends CrudRepository<TimeSheet, Long> {
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@@ -26,6 +27,8 @@ public class Controller_test {
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
//end
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiringInspection")
|
||||
@Autowired
|
||||
@@ -77,11 +80,10 @@ public class Controller_test {
|
||||
JSONArray userArray = new JSONArray();
|
||||
for (User user : userRepository.findAll()) {
|
||||
JSONObject userJSON = new JSONObject();
|
||||
userJSON.put("id", user.getId());
|
||||
userJSON.put("id", user.getUserId());
|
||||
userJSON.put("firstName", user.getFirstName());
|
||||
userJSON.put("lastName", user.getLastName());
|
||||
userJSON.put("email", user.getEmail());
|
||||
userJSON.put("role", user.getRole());
|
||||
userArray.put(userJSON);
|
||||
}
|
||||
return userArray.toString();
|
||||
|
||||
Reference in new issue
Block a user