Last active
October 19, 2016 09:41
-
-
Save kote-che/6d72044fd14e7e467652240f58fe92cc to your computer and use it in GitHub Desktop.
Biiling
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
package ua.org.kote; | |
import javax.persistence.*; | |
@Entity | |
@Table(name = "Address") | |
public class Address { | |
@Id | |
@GeneratedValue | |
private Long id; | |
private String country; | |
private String city; | |
private String street; | |
private String house; | |
private String apartment; | |
} |
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
package ua.org.kote; | |
import java.util.List; | |
public interface AdvDAO { | |
List<CDR> callsList(); | |
List<CDR> callsList(String pattern); | |
List<Client> clientList(); | |
List<Client> clientList(String pattern); | |
//void add(nt adv); | |
//void delete(long id); | |
//byte[] getPhoto(long id); | |
} |
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
package ua.org.kote; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import javax.persistence.EntityManager; | |
import javax.persistence.Query; | |
import java.util.List; | |
public class AdvDAOImpl implements AdvDAO { | |
@Autowired | |
private EntityManager entityManager; | |
public List<CDR> callsList(){ | |
Query query = entityManager.createQuery("SELECT c FROM CDR c", CDR.class); | |
return (List<CDR>) query.getResultList(); | |
} | |
public List<CDR> callsList(String pattern){ | |
Query query = entityManager.createQuery("SELECT c FROM CDR c where c.accountcode = :pattern", CDR.class); | |
return (List<CDR>) query.getResultList(); | |
} | |
public List<Client> clientList(){ | |
Query query = entityManager.createQuery("SELECT cli FROM Client cli", Client.class); | |
return (List<Client>) query.getResultList(); | |
} | |
public List<Client> clientList(String pattern){ | |
Query query = entityManager.createQuery("SELECT cli FROM Client cli where cli.first_name = :pattern", Client.class); | |
return (List<Client>) query.getResultList(); | |
} | |
} |
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
package ua.org.kote; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.web.multipart.commons.CommonsMultipartResolver; | |
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |
import org.springframework.web.servlet.view.JstlView; | |
import org.springframework.web.servlet.view.UrlBasedViewResolver; | |
import javax.persistence.EntityManager; | |
import javax.persistence.EntityManagerFactory; | |
import javax.persistence.Persistence; | |
@Configuration | |
@ComponentScan("ua.org.kote") | |
@EnableWebMvc | |
public class AppConfig { | |
@Bean | |
public EntityManager entityManager(){ | |
EntityManagerFactory emf = Persistence.createEntityManagerFactory("AsteriskJPA"); | |
return emf.createEntityManager(); | |
} | |
@Bean | |
public AdvDAO advDAO() { | |
return new AdvDAOImpl(); | |
} | |
@Bean | |
public UrlBasedViewResolver setupViewResolver() { | |
UrlBasedViewResolver resolver = new UrlBasedViewResolver(); | |
resolver.setPrefix("/WEB-INF/pages/"); | |
resolver.setSuffix(".jsp"); | |
resolver.setViewClass(JstlView.class); | |
resolver.setOrder(1); | |
return resolver; | |
} | |
@Bean | |
public CommonsMultipartResolver multipartResolver() { | |
return new CommonsMultipartResolver(); | |
} | |
} |
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
package ua.org.kote; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.annotation.Bean; | |
@SpringBootApplication | |
public class Application { | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@Bean | |
public CommandLineRunner demo(final UserService userService) { | |
return new CommandLineRunner() { | |
@Override | |
public void run(String... strings) throws Exception { | |
userService.addUser(new AuthUsers("admin", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", UserRole.ADMIN)); | |
userService.addUser(new AuthUsers("user", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", UserRole.USER)); | |
} | |
}; | |
} | |
} |
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
package ua.org.kote; | |
import javax.persistence.*; | |
@Entity | |
public class AuthUsers { | |
@Id | |
@GeneratedValue | |
private long id; | |
private String login; | |
private String password; | |
@Enumerated(EnumType.STRING) | |
private UserRole role; | |
private String email; | |
public AuthUsers(String login, String password, UserRole role){ | |
this.login = login; | |
this.password = password; | |
this.role = role; | |
} | |
public AuthUsers(){} | |
public long getId(){return id;} | |
public void setId(long id){this.id = id;} | |
public String getLogin(){return login;} | |
public void setLogin(String login){this.login = login;} | |
public String getPassword(){return password;} | |
public void setPassword(String password){this.password = password;} | |
public String getEmail(){return email;} | |
public void setEmail(String email){this.email = email;} | |
public UserRole getRole(){return role;} | |
public void setRole(UserRole role){this.role = role;} | |
} |
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
package ua.org.kote; | |
import javax.persistence.*; | |
import java.util.Date; | |
@Entity | |
@Table(name = "cdr") | |
public class CDR { | |
@Id | |
@GeneratedValue | |
private long id; | |
private Date calldate; | |
private String clid; | |
private String src; | |
private String dst; | |
private String dcontext; | |
private String channel; | |
private String dstchannel; | |
private String lastapp; | |
private String lastdata; | |
private Integer duration; | |
private Integer billsec; | |
private String disposition; | |
private Integer amaflags; | |
private String accountcode; | |
private String userfield; | |
public CDR(){} | |
public long getId() {return id;} | |
public Date getCalldate() {return calldate;} | |
public String getClid(){return clid;} | |
public String getSrc(){return src;} | |
public String getDst(){return dst;} | |
public String getDcontext(){return dcontext;} | |
public String getChannel(){return channel;} | |
public String getDstchannel(){return dstchannel;} | |
public String getLastapp(){return lastapp;} | |
public String getLastdata(){return lastdata;} | |
public Integer getDuration(){return duration;} | |
public Integer getBillsec(){return billsec;} | |
public String getDisposition(){return disposition;} | |
public Integer getAmaflags(){return amaflags;} | |
public String getAccountcode(){return accountcode;} | |
public String getUserfield(){return userfield;} | |
} |
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
package ua.org.kote; | |
import javax.persistence.*; | |
@Entity | |
@Table(name = "Client") | |
public class Client { | |
@Id | |
@GeneratedValue | |
private Long id; | |
private String first_name; | |
private String last_name; | |
private String e_mail; | |
private Integer address_id; | |
public Client(){} | |
public Long getId(){return id;} | |
public String getFirst_name(){return first_name;} | |
public String getLast_name(){return last_name;} | |
public String getE_mail(){return e_mail;} | |
public Integer getAddress_id(){return address_id;} | |
} |
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
package ua.org.kote; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.*; | |
import org.springframework.web.multipart.MultipartFile; | |
import org.springframework.web.servlet.ModelAndView; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; | |
@Controller | |
@RequestMapping("/Billing") | |
public class MainController { | |
@Autowired | |
private AdvDAO advDAO; | |
@RequestMapping("/") | |
public ModelAndView callsList(){ | |
return new ModelAndView("index","calls",advDAO.callsList()); | |
} | |
@RequestMapping("/clientinfo") | |
public ModelAndView clientInfo(){ | |
return new ModelAndView("client_info","clients",advDAO.clientList()); | |
} | |
} |
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion> | |
4.0.0 | |
</modelVersion> | |
<groupId> | |
Billing-group-id | |
</groupId> | |
<artifactId> | |
Billing-artifact-id | |
</artifactId> | |
<version> | |
1.0-SNAPSHOT | |
</version> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId> | |
org.apache.maven.plugins | |
</groupId> | |
<artifactId> | |
maven-compiler-plugin | |
</artifactId> | |
<configuration> | |
<source> | |
1.6 | |
</source> | |
<target> | |
1.6 | |
</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<packaging> | |
jar | |
</packaging> | |
<name> | |
Billing-artifact-id | |
</name> | |
<url> | |
http://maven.apache.org | |
</url> | |
<properties> | |
<project.build.sourceEncoding> | |
UTF-8 | |
</project.build.sourceEncoding> | |
<!-- Strart class for spring --> | |
<start-class> | |
ua.org.kote.Application | |
</start-class> | |
<java.version> | |
1.8 | |
</java.version> | |
</properties> | |
<parent> | |
<groupId> | |
org.springframework.boot | |
</groupId> | |
<artifactId> | |
spring-boot-starter-parent | |
</artifactId> | |
<version> | |
1.3.2.RELEASE | |
</version> | |
</parent> | |
<dependencies> | |
<!-- DB info --> | |
<dependency> | |
<groupId> | |
mysql | |
</groupId> | |
<artifactId> | |
mysql-connector-java | |
</artifactId> | |
<version> | |
5.1.34 | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.hibernate | |
</groupId> | |
<artifactId> | |
hibernate-core | |
</artifactId> | |
<version> | |
4.3.11.Final | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.hibernate | |
</groupId> | |
<artifactId> | |
hibernate-entitymanager | |
</artifactId> | |
<version> | |
4.3.11.Final | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.hibernate | |
</groupId> | |
<artifactId> | |
hibernate-validator | |
</artifactId> | |
<version> | |
4.2.0.Final | |
</version> | |
</dependency> | |
<!-- Javax jstl and servlet --> | |
<dependency> | |
<groupId> | |
javax.servlet | |
</groupId> | |
<artifactId> | |
jstl | |
</artifactId> | |
<version> | |
1.2 | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
javax.servlet | |
</groupId> | |
<artifactId> | |
javax.servlet-api | |
</artifactId> | |
<version> | |
3.1.0 | |
</version> | |
</dependency> | |
<!-- Spring --> | |
<dependency> | |
<groupId> | |
org.springframework | |
</groupId> | |
<artifactId> | |
spring-core | |
</artifactId> | |
<version> | |
4.1.2.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework | |
</groupId> | |
<artifactId> | |
spring-context | |
</artifactId> | |
<version> | |
4.1.2.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework | |
</groupId> | |
<artifactId> | |
spring-webmvc | |
</artifactId> | |
<version> | |
4.1.2.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework.boot | |
</groupId> | |
<artifactId> | |
spring-boot-starter-web | |
</artifactId> | |
<version> | |
1.3.2.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework.boot | |
</groupId> | |
<artifactId> | |
spring-boot-starter-data-jpa | |
</artifactId> | |
<version> | |
1.3.2.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework.boot | |
</groupId> | |
<artifactId> | |
spring-boot-starter-jdbc | |
</artifactId> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework.security | |
</groupId> | |
<artifactId> | |
spring-security-web | |
</artifactId> | |
<version> | |
4.1.0.RELEASE | |
</version> | |
</dependency> | |
<dependency> | |
<groupId> | |
org.springframework.security | |
</groupId> | |
<artifactId> | |
spring-security-config | |
</artifactId> | |
<version> | |
4.1.0.RELEASE | |
</version> | |
</dependency> | |
<!-- File upload --> | |
<dependency> | |
<groupId> | |
commons-fileupload | |
</groupId> | |
<artifactId> | |
commons-fileupload | |
</artifactId> | |
<version> | |
1.3.1 | |
</version> | |
</dependency> | |
</dependencies> | |
</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
package ua.org.kote; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; | |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
import org.springframework.security.core.userdetails.UserDetailsService; | |
@Configuration | |
@EnableWebSecurity | |
public class SecurityConfig extends WebSecurityConfigurerAdapter{ | |
} |
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
package ua.org.kote; | |
import javax.persistence.*; | |
@Entity | |
@Table(name = "Sip_account") | |
public class Sip_account { | |
@Id | |
@GeneratedValue | |
private Long id; | |
private Integer account_id; | |
private String sip_account; | |
private String sip_accountcode; | |
private String note; | |
} |
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
package ua.org.kote; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.jpa.repository.Query; | |
import org.springframework.data.repository.query.Param; | |
public interface UserRepository extends JpaRepository<AuthUsers, Long>{ | |
@Query("SELECT u FROM CustomUser u where u.login = :login") | |
AuthUsers findByLogin(@Param("login") String login); | |
} |
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
package ua.org.kote; | |
/** | |
* Created by kote on 17.10.2016. | |
*/ | |
public enum UserRole { | |
ADMIN, USER; | |
@Override | |
public String toString() { | |
return "ROLE_" + name(); | |
} | |
} |
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
package ua.org.kote; | |
/** | |
* Created by kote on 17.10.2016. | |
*/ | |
public interface UserService { | |
AuthUsers getUserByLogin(String login); | |
void addUser(AuthUsers authUsers); | |
void updateUser(AuthUsers authUsers); | |
} |
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
package ua.org.kote; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import org.springframework.transaction.annotation.Transactional; | |
@Service | |
public class UserServiceImpl implements UserService { | |
@Autowired | |
private UserRepository userRepository; | |
@Override | |
@Transactional(readOnly = true) | |
public AuthUsers getUserByLogin(String login) { | |
return userRepository.findByLogin(login); | |
} | |
@Override | |
@Transactional | |
public void addUser(AuthUsers customUser) { | |
userRepository.save(customUser); | |
} | |
@Override | |
@Transactional | |
public void updateUser(AuthUsers customUser) { | |
userRepository.save(customUser); | |
} | |
} |
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
package ua.org.kote; | |
import org.springframework.web.WebApplicationInitializer; | |
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | |
import org.springframework.web.servlet.DispatcherServlet; | |
import javax.servlet.ServletContext; | |
import javax.servlet.ServletException; | |
import javax.servlet.ServletRegistration; | |
public class WebInitializer implements WebApplicationInitializer { | |
@Override | |
public void onStartup(ServletContext servletContext) throws ServletException{ | |
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); | |
ctx.register(AppConfig.class); | |
ctx.setServletContext(servletContext); | |
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); | |
servlet.addMapping("/"); | |
servlet.setLoadOnStartup(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment