Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e987b0

Browse files
committed
first commit
0 parents  commit 0e987b0

File tree

150 files changed

+8315
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+8315
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/target/
2+
.classpath
3+
.project
4+
mvnw
5+
mvnw.cmd
6+
.mvn
7+
.settings

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# LeaveSystem
2+
The is leave system app for SAP Anywhere

pom.xml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.sapanywhere.app</groupId>
7+
<artifactId>humanresource</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>humanresource</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.2.7.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-jpa</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-security</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.h2database</groupId>
42+
<artifactId>h2</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-test</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>commons-beanutils</groupId>
55+
<artifactId>commons-beanutils</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>commons-codec</groupId>
59+
<artifactId>commons-codec</artifactId>
60+
<version>1.10</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.commons</groupId>
64+
<artifactId>commons-io</artifactId>
65+
<version>1.3.2</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.sun.mail</groupId>
69+
<artifactId>javax.mail</artifactId>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.springframework</groupId>
73+
<artifactId>spring-context-support</artifactId>
74+
</dependency>
75+
</dependencies>
76+
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-maven-plugin</artifactId>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
86+
87+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.sapanywhere.app;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
6+
7+
@EnableJpaRepositories
8+
@SpringBootApplication
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.sapanywhere.app.configuration;
2+
3+
import org.springframework.cache.CacheManager;
4+
import org.springframework.cache.annotation.EnableCaching;
5+
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
@Configuration
10+
@EnableCaching
11+
public class CacheConfiguration {
12+
13+
@Bean
14+
public CacheManager cacheManager() {
15+
return new ConcurrentMapCacheManager("workhours", "workday","leaveTypes");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.sapanywhere.app.configuration;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.mail.javamail.JavaMailSender;
7+
import org.springframework.mail.javamail.JavaMailSenderImpl;
8+
9+
import com.sapanywhere.app.properties.MailProperties;
10+
11+
@Configuration
12+
public class MailConfiguration {
13+
14+
@Autowired
15+
private MailProperties mailProperties;
16+
17+
@Bean
18+
public JavaMailSender mailSender() {
19+
20+
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
21+
mailSender.setHost(this.mailProperties.getHost());
22+
mailSender.setPort(this.mailProperties.getPort());
23+
mailSender.setUsername(this.mailProperties.getUsername());
24+
mailSender.setPassword(this.mailProperties.getPassword());
25+
mailSender.setProtocol(this.mailProperties.getProtocol());
26+
return mailSender;
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.sapanywhere.app.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
6+
7+
@Configuration
8+
public class MailTemplateConfiguration {
9+
10+
@Bean
11+
public ClassLoaderTemplateResolver emailTemplateResolver() {
12+
ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
13+
emailTemplateResolver.setPrefix("mail/");
14+
emailTemplateResolver.setSuffix(".html");
15+
emailTemplateResolver.setTemplateMode("HTML5");
16+
emailTemplateResolver.setCharacterEncoding("UTF-8");
17+
emailTemplateResolver.setOrder(1);
18+
emailTemplateResolver.setCacheable(false);
19+
return emailTemplateResolver;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.sapanywhere.app.configuration;
2+
3+
import java.util.Locale;
4+
5+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6+
import org.springframework.context.MessageSource;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
10+
import org.springframework.validation.Validator;
11+
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
12+
import org.springframework.web.servlet.LocaleResolver;
13+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
14+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
15+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
16+
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
17+
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
18+
19+
@Configuration
20+
@EnableAutoConfiguration
21+
public class MvcConfiguration extends WebMvcConfigurerAdapter {
22+
23+
@Override
24+
public void addViewControllers(ViewControllerRegistry registry) {
25+
registry.addViewController("/").setViewName("index");
26+
registry.addViewController("index").setViewName("index");
27+
}
28+
29+
@Bean
30+
public LocaleResolver localeResolver() {
31+
SessionLocaleResolver slr = new SessionLocaleResolver();
32+
slr.setDefaultLocale(Locale.US);
33+
return slr;
34+
}
35+
36+
@Bean
37+
public LocaleChangeInterceptor localeChangeInterceptor() {
38+
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
39+
lci.setParamName("lang");
40+
return lci;
41+
}
42+
43+
@Override
44+
public void addInterceptors(InterceptorRegistry registry) {
45+
registry.addInterceptor(localeChangeInterceptor());
46+
}
47+
48+
@Bean(name = "messageSource")
49+
public MessageSource messageSource() {
50+
ReloadableResourceBundleMessageSource bean = new ReloadableResourceBundleMessageSource();
51+
bean.setBasename("classpath:/messages");
52+
bean.setDefaultEncoding("UTF-8");
53+
return bean;
54+
}
55+
56+
@Bean(name = "validator")
57+
public LocalValidatorFactoryBean validator() {
58+
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
59+
bean.setValidationMessageSource(messageSource());
60+
return bean;
61+
}
62+
63+
@Override
64+
public Validator getValidator() {
65+
return validator();
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.sapanywhere.app.configuration;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.autoconfigure.security.SecurityProperties;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.core.annotation.Order;
7+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
8+
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
9+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12+
import com.sapanywhere.app.service.UserDetailsService;
13+
14+
@Configuration
15+
@EnableGlobalMethodSecurity(prePostEnabled = true)
16+
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
17+
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
18+
19+
@Autowired
20+
private UserDetailsService userDetailsService;
21+
22+
@Override
23+
protected void configure(HttpSecurity httpSecurity) throws Exception {
24+
httpSecurity.csrf().disable();
25+
httpSecurity.headers().frameOptions().disable();
26+
27+
httpSecurity.authorizeRequests().antMatchers("/libs/**").permitAll();
28+
httpSecurity.authorizeRequests().antMatchers("/css/**").permitAll();
29+
httpSecurity.authorizeRequests().antMatchers("/js/**").permitAll();
30+
httpSecurity.authorizeRequests().antMatchers("/imgs/**").permitAll();
31+
httpSecurity.authorizeRequests().antMatchers("/oauth/**").permitAll();
32+
httpSecurity.authorizeRequests().antMatchers("/404.html").permitAll();
33+
httpSecurity.authorizeRequests().antMatchers("/500.html").permitAll();
34+
httpSecurity.authorizeRequests().antMatchers("/", "/index").permitAll();
35+
36+
httpSecurity.authorizeRequests().antMatchers("/login.html").permitAll();
37+
httpSecurity.authorizeRequests().antMatchers("/register.html").permitAll();
38+
httpSecurity.authorizeRequests().antMatchers("/user/register").permitAll();
39+
40+
httpSecurity.authorizeRequests().anyRequest().authenticated().and()
41+
.formLogin().loginPage("/login")
42+
.usernameParameter("userEmail")
43+
.passwordParameter("password")
44+
.failureUrl("/login.html?error")
45+
.defaultSuccessUrl("/overview.html")
46+
.permitAll()
47+
.and()
48+
.logout().logoutUrl("/logout").logoutSuccessUrl("/").permitAll();
49+
}
50+
51+
@Autowired
52+
public void configureGlobal(AuthenticationManagerBuilder auth)
53+
throws Exception {
54+
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.sapanywhere.app.controller;
2+
3+
import org.apache.log4j.Logger;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.security.web.bind.annotation.AuthenticationPrincipal;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.ui.Model;
8+
import org.springframework.validation.BindingResult;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestMethod;
12+
import com.sapanywhere.app.exception.BusinessException;
13+
import com.sapanywhere.app.model.calendar.CalendarPage;
14+
import com.sapanywhere.app.model.calendar.HolidayForm;
15+
import com.sapanywhere.app.service.HolidayService;
16+
import com.sapanywhere.app.service.user.UserInfo;
17+
18+
@Controller
19+
public class CalendarController {
20+
21+
private static Logger logger = Logger.getLogger(CalendarController.class);
22+
23+
@Autowired
24+
private HolidayService holidayService;
25+
26+
@RequestMapping(value = "/calendar.html", method = RequestMethod.GET)
27+
public String indexPage(Model model) {
28+
logger.info("load calendar.html");
29+
CalendarPage calendarPage = new CalendarPage(
30+
this.holidayService.findAllHolidaysThisYear());
31+
model.addAttribute(calendarPage);
32+
return "/calendar/index";
33+
}
34+
35+
@RequestMapping(value = "/createHoliday.html", method = RequestMethod.GET)
36+
public String createPage(HolidayForm holidayForm) {
37+
logger.info("load createHoliday.html");
38+
return "/calendar/create";
39+
}
40+
41+
@RequestMapping(value = "/createHoliday", method = RequestMethod.POST)
42+
public String createHoliday(HolidayForm holidayForm, BindingResult result) {
43+
if (result.hasErrors()) {
44+
return "/calendar/create";
45+
}
46+
try {
47+
this.holidayService.create(holidayForm.parse());
48+
} catch (BusinessException ex) {
49+
result.reject(ex.getCode());
50+
return "/calendar/create";
51+
}
52+
return "redirect:/calendar.html";
53+
}
54+
55+
@RequestMapping(value = "/holiday({id:[0-9]+})", method = RequestMethod.DELETE)
56+
public void deleteHoliday(@PathVariable Long id,
57+
@AuthenticationPrincipal UserInfo userInfo){
58+
this.holidayService.delete(id, userInfo.getUser());
59+
}
60+
}

0 commit comments

Comments
 (0)