44 Commits

Author SHA1 Message Date
32ef8a67d9 added outlay 2024-08-19 17:23:41 +02:00
b10765fe89 fixed registration bugs 2024-05-28 23:24:45 +02:00
8522def65c added new main site with currently buggy layout 2024-05-28 18:29:26 +02:00
81d6f79857 added Linda 2024-05-28 17:51:27 +02:00
fbfccd0dfc added text anna 2024-05-28 17:15:32 +02:00
0e57c57ccc forbid spaces in login field, see #16 2024-05-04 14:09:35 +02:00
f0d30ec6ed fixed registration failure checks 2024-04-01 18:04:42 +02:00
7ab500e510 fixed correction of registrations 2024-04-01 15:33:03 +02:00
a373f5e758 finetuning 2024-03-18 19:45:46 +01:00
f577164781 added image of simeon 2024-03-18 19:39:56 +01:00
03eb781a98 added start_booking, see #14 2024-03-16 22:40:36 +01:00
ce819f80de finetuning 2024-03-14 09:28:36 +01:00
1c226caa48 added image of Jörg 2024-03-14 09:25:05 +01:00
1580369794 added about of Jörg 2024-03-14 09:15:47 +01:00
39805aec20 added Simeon about text 2024-03-14 09:02:51 +01:00
0eb90092e7 finetuning 2024-02-24 17:45:50 +01:00
fe8100c59e removed false corrections 2024-02-23 15:38:21 +01:00
e20c24d006 added required price, see #6 2024-02-23 15:36:37 +01:00
72952b9c7b finetuning in layout 2024-02-23 11:50:33 +01:00
8f69320505 show free beds, see #2 2024-02-23 01:24:53 +01:00
5a365b1a37 code cleanup 2024-02-10 11:50:37 +01:00
1d14a13aa6 code cleanup 2023-12-27 13:57:57 +01:00
8e790a7660 corrected privileges, see #11 2023-12-27 11:01:46 +01:00
0d476c6f91 hotfix: corrected consent url 2023-10-26 11:01:59 +02:00
11abda3575 register already known persons 2023-10-25 10:15:23 +02:00
453105419f register already known persons 2023-10-25 10:14:26 +02:00
d4ae63f975 german decimal separator forced 2023-10-21 21:51:26 +02:00
3dd39751af export optimization 2023-10-21 21:46:22 +02:00
e0e972cfe8 added download csv file feature 2023-10-21 18:53:14 +02:00
b3a089d6b3 corrected ant matchers 2023-10-21 13:37:59 +02:00
3147007632 display camplists 2023-10-21 01:24:52 +02:00
5f78b87a87 corrected password url 2023-10-07 11:12:21 +02:00
5f6d71890e corrected link url 2023-10-07 10:56:42 +02:00
f21c7584bd added year to selection of camp in role management 2023-09-28 21:41:37 +02:00
12a325ee03 corrected username check and dropdown size, see #57 2023-09-21 21:32:18 +02:00
497a4dfcf9 registration screen optimized, see #58 2023-09-21 19:54:23 +02:00
f31c433c80 bugfix: allow spaces after user names on login from old registrations 2023-08-27 21:58:40 +02:00
7732d6da25 corrected keycloak urls 2023-08-06 16:05:18 +02:00
b07de9f2bc determine mail correctly 2023-08-06 15:43:44 +02:00
e8354c3f6e jakartarized 2023-08-06 00:10:01 +02:00
4a2d743a23 version display improved 2023-07-29 17:48:41 +02:00
89cfbc6741 see #48 2023-05-13 12:29:25 +02:00
5b861f730f added filter to privilege dropdowns 2023-05-06 20:39:34 +02:00
d1ee923f0a see #45 2023-05-06 17:44:14 +02:00
150 changed files with 4284 additions and 1204 deletions

View File

@ -25,6 +25,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>

View File

@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false

View File

@ -0,0 +1,2 @@
boot.validation.initialized=true
eclipse.preferences.version=1

View File

@ -1,25 +1,20 @@
buildscript {
ext {
springBootVersion = '2.7.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
plugins {
id 'org.springframework.boot' version '3.2.4'
id "io.spring.dependency-management" version "1.1.4"
id 'java'
id 'war'
id 'eclipse'
id 'application'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'application'
group = 'de.jottyfan.camporganizer'
version = '0.5.0'
version = '0.8.5'
description = """CampOrganizer2"""
sourceCompatibility = 17
targetCompatibility = 17
mainClassName = "de.jottyfan.camporganizer.Main"
repositories {
@ -27,64 +22,77 @@ repositories {
maven {
url "https://www.jottyfan.de/libs/"
}
}
ext {
set('keycloakVersion', '21.1.1')
maven {
url "https://repo.maven.apache.org/maven2"
}
}
war {
manifest {
attributes("Implementation-Version": version)
doFirst {
manifest {
attributes("Implementation-Title": project.name,
"Implementation-Version": version,
"Implementation-Timestamp": new Date())
}
}
archiveName = 'CampOrganizer2.war'
version = version
archiveFileName = 'CampOrganizer2.war'
}
dependencies {
implementation 'org.apache.logging.log4j:log4j-api:2.20.0'
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.20.0'
implementation 'org.jooq:jooq:3.19.6'
implementation 'de.jottyfan:COJooq:2024.03.16c'
implementation 'org.webjars:bootstrap:5.2.3'
implementation 'org.webjars:font-awesome:5.15.4'
implementation 'org.webjars:jquery:3.6.4'
implementation 'org.webjars:popper.js:2.9.3'
implementation 'org.webjars:datatables:1.13.2'
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.23.1'
implementation 'org.webjars:bootstrap:5.3.2'
implementation 'org.webjars:font-awesome:6.5.1'
implementation 'org.webjars:jquery:3.7.1'
implementation 'org.webjars:popper.js:2.11.7'
implementation 'org.webjars:datatables:1.13.5'
implementation 'org.webjars:select2:4.0.13'
implementation 'net.sf.biweekly:biweekly:0.6.6'
implementation 'org.keycloak:keycloak-spring-boot-starter'
implementation 'net.sf.biweekly:biweekly:0.6.7'
// for using the keycloak rest interface
implementation 'org.keycloak:keycloak-admin-client:21.1.1'
implementation 'org.jboss.resteasy:resteasy-client:5.0.0.Final'
implementation 'org.keycloak:keycloak-server-spi:24.0.1'
implementation 'org.keycloak:keycloak-admin-client:24.0.1'
implementation 'org.jboss.resteasy:resteasy-client:6.2.6.Final'
// backward compatibility until the complete registration is converted to keycloak
implementation 'org.jasypt:jasypt:1.9.3'
// rss support
implementation 'com.rometools:rome:1.18.0'
implementation 'com.rometools:rome:2.1.0'
// mail support
implementation 'commons-validator:commons-validator:1.7'
implementation 'commons-validator:commons-validator:1.8.0'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation "org.springframework.boot:spring-boot-starter-oauth2-client"
implementation 'org.springframework.security:spring-security-oauth2-authorization-server:1.2.1'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
implementation 'de.jottyfan:COJooq:2023.03'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.0.0'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
implementation 'commons-io:commons-io:2.15.1'
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
dependencyManagement {
imports {
mavenBom "org.keycloak.bom:keycloak-adapter-bom:${keycloakVersion}"
}
test {
useJUnitPlatform()
}
// add version to manifest
springBoot {
buildInfo()
}

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

55
gradlew vendored
View File

@ -1,21 +1,5 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
@ -44,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@ -72,7 +56,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MSYS* | MINGW* )
MINGW* )
msys=true
;;
NONSTOP* )
@ -82,7 +66,6 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -126,11 +109,10 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@ -156,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
i=$((i+1))
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@ -177,9 +159,14 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

1
settings.gradle Normal file
View File

@ -0,0 +1 @@
rootProject.name = 'CampOrganizer2'

View File

@ -0,0 +1,78 @@
package de.jottyfan.camporganizer.config;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
/**
*
* @author jotty
*
*/
@Configuration
public class AuthorizationConfiguration {
private static final String REALM_ACCESS_CLAIM = "realm_access";
private static final String ROLES_CLAIM = "roles";
private static final String RESOURCE_ACCESS_CLAIM = "resource_access";
@Value("${spring.security.oauth2.client.registration.keycloak.client-id}")
private String clientId;
@Bean
GrantedAuthoritiesMapper userAuthoritiesMapperForKeycloak() {
return authorities -> {
Set<GrantedAuthority> mappedAuthorities = new HashSet<>();
var authority = authorities.iterator().next();
boolean isOidc = authority instanceof OidcUserAuthority;
if (isOidc) {
var oidcUserAuthority = (OidcUserAuthority) authority;
var userInfo = oidcUserAuthority.getUserInfo();
if (userInfo.hasClaim(REALM_ACCESS_CLAIM)) {
var realmAccess = userInfo.getClaimAsMap(REALM_ACCESS_CLAIM);
@SuppressWarnings("unchecked")
var roles = (Collection<String>) realmAccess.get(ROLES_CLAIM);
mappedAuthorities.addAll(generateAuthoritiesFromClaim(roles));
}
if (userInfo.hasClaim(RESOURCE_ACCESS_CLAIM)) {
var resourceAccess = userInfo.getClaimAsMap(RESOURCE_ACCESS_CLAIM);
if (resourceAccess.containsKey(clientId)) {
@SuppressWarnings("unchecked")
var roles = (Collection<String>) ((Map<?, ?>) resourceAccess.get(clientId)).get(ROLES_CLAIM);
mappedAuthorities.addAll(generateAuthoritiesFromClaim(roles));
}
}
} else {
var oauth2UserAuthority = (OAuth2UserAuthority) authority;
Map<String, Object> userAttributes = oauth2UserAuthority.getAttributes();
if (userAttributes.containsKey(REALM_ACCESS_CLAIM)) {
@SuppressWarnings("unchecked")
var realmAccess = (Map<String, Object>) userAttributes.get(REALM_ACCESS_CLAIM);
@SuppressWarnings("unchecked")
var roles = (Collection<String>) realmAccess.get(ROLES_CLAIM);
mappedAuthorities.addAll(generateAuthoritiesFromClaim(roles));
}
}
return mappedAuthorities;
};
}
private Collection<GrantedAuthority> generateAuthoritiesFromClaim(Collection<String> roles) {
return roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role)).collect(Collectors.toList());
}
}

View File

@ -1,66 +0,0 @@
package de.jottyfan.camporganizer.config;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
import org.keycloak.adapters.springsecurity.management.HttpSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
/**
*
* @author jotty
*
*/
@KeycloakConfiguration
@ComponentScan(basePackageClasses = KeycloakSpringBootConfigResolver.class)
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}
@Bean
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
@Bean
@Override
@ConditionalOnMissingBean(HttpSessionManager.class)
protected HttpSessionManager httpSessionManager() {
return new HttpSessionManager();
}
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
// @formatter:off
.antMatchers("/dashboard/**", "/business/**", "/confirmation/**").authenticated()
.anyRequest().permitAll();
// @formatter:on
// http.anonymous().disable();
http.csrf().disable();
}
}

View File

@ -0,0 +1,50 @@
package de.jottyfan.camporganizer.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.client.oidc.web.logout.OidcClientInitiatedLogoutSuccessHandler;
import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
/**
*
* @author jotty
*
*/
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfiguration {
@Bean
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new NullAuthenticatedSessionStrategy();
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity sec, InMemoryClientRegistrationRepository crr)
throws Exception {
sec.csrf(o -> o.disable()).anonymous(o -> o.disable())
// @formatter:off
.oauth2Login(o -> o.defaultSuccessUrl("/"))
.logout(o -> o.logoutSuccessHandler(new OidcClientInitiatedLogoutSuccessHandler(crr)))
.authorizeHttpRequests(o -> o.requestMatchers(
AntPathRequestMatcher.antMatcher("/dashboard/**"),
AntPathRequestMatcher.antMatcher("/business/**"),
AntPathRequestMatcher.antMatcher("/confirmation/**"),
AntPathRequestMatcher.antMatcher("/userlogin/**")
).authenticated()
.anyRequest().permitAll())
.oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults()))
.sessionManagement(o -> o.init(sec));
// @formatter:on
return sec.build();
}
}

View File

@ -1,7 +1,6 @@
package de.jottyfan.camporganizer.module.admin;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.security.Principal;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -17,8 +16,13 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import de.jottyfan.camporganizer.module.admin.model.CampBean;
import de.jottyfan.camporganizer.module.admin.model.DocumentBean;
import de.jottyfan.camporganizer.module.admin.model.LocationBean;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import de.jottyfan.camporganizer.module.mail.MailBean;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
/**
*
@ -37,10 +41,10 @@ public class AdminController extends CommonController {
private String from;
@GetMapping("/admin/mail")
public String getMail(Model model, HttpServletRequest request) {
public String getMail(Model model, Principal principal) {
MailBean mailBean = new MailBean();
mailBean.setFrom(from);
mailBean.getTo().add(getCurrentEmail(request));
mailBean.getTo().add(getCurrentEmail(principal));
model.addAttribute("bean", mailBean);
return "/admin/mail";
}
@ -70,7 +74,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/document/edit/{id}")
public String prepareAddDocument(@PathVariable Integer id, Model model, HttpServletRequest request) {
public String prepareAddDocument(@PathVariable("id") Integer id, Model model, HttpServletRequest request) {
model.addAttribute("bean", service.getDocument(id));
return "/admin/document_edit";
}
@ -88,7 +92,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/document/delete/{id}")
public String deleteDocument(@PathVariable Integer id, Model model, HttpServletRequest request) {
public String deleteDocument(@PathVariable("id") Integer id, Model model, HttpServletRequest request) {
service.deleteDocument(id);
return "redirect:/admin/document";
}
@ -107,7 +111,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/location/edit/{id}")
public String prepareAddLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
public String prepareAddLocation(@PathVariable("id") Integer id, Model model, HttpServletRequest request) {
model.addAttribute("bean", service.getLocation(id));
model.addAttribute("documents", service.getLocationDocuments());
return "/admin/location_edit";
@ -128,7 +132,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/location/delete/{id}")
public String deleteLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
public String deleteLocation(@PathVariable("id") Integer id, Model model, HttpServletRequest request) {
service.deleteLocation(id);
return "redirect:/admin/location";
}
@ -150,7 +154,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/camp/edit/{id}")
public String prepareEditCamp(@PathVariable Integer id, Model model, HttpServletRequest request) {
public String prepareEditCamp(@PathVariable("id") Integer id, Model model, HttpServletRequest request) {
model.addAttribute("bean", service.getCamp(id));
model.addAttribute("documents", service.getCampDocuments());
model.addAttribute("locations", service.getLocations());
@ -182,7 +186,7 @@ public class AdminController extends CommonController {
}
@GetMapping("/admin/camp/delete/{id}")
public String deleteCamp(@PathVariable Integer id, Model model, HttpServletRequest request,
public String deleteCamp(@PathVariable("id") Integer id, Model model, HttpServletRequest request,
RedirectAttributes redirect) {
String error = service.deleteCamp(id);
redirect.addAttribute("error", error);

View File

@ -0,0 +1,125 @@
package de.jottyfan.camporganizer.module.admin;
import java.util.List;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.module.admin.model.CampBean;
import de.jottyfan.camporganizer.module.admin.model.CampProfileBean;
import de.jottyfan.camporganizer.module.admin.model.ProfileBean;
import de.jottyfan.camporganizer.module.camplist.CommonController;
/**
*
* @author jotty
*
*/
@Controller
public class AdminPrivilegesController extends CommonController {
@Autowired
private AdminPrivilegesService service;
@GetMapping("/admin/privileges/userbased")
public String getUserbased(Model model) {
model.addAttribute("list", service.getProfiles());
return "/admin/privileges/userbased";
}
@GetMapping("/admin/privileges/rolebased")
public String getRolebased(Model model) {
model.addAttribute("list", service.getAllModules());
return "/admin/privileges/rolebased";
}
@GetMapping("/admin/privileges/campbased")
public String getCampbased(Model model) {
model.addAttribute("list", service.getAllCamps());
return "/admin/privileges/campbased";
}
@GetMapping("/admin/privileges/rolebased/{role}")
public String getRolebased(@PathVariable("role") String role, Model model) {
model.addAttribute("list", service.getAllModules());
model.addAttribute("selected", role);
model.addAttribute("container", service.getPersonCampMappingByModule(EnumModule.valueOf(role)));
model.addAttribute("pagedest", "_admin_privileges_rolebased_" + role);
return "/admin/privileges/rolebased";
}
@GetMapping("/admin/privileges/campbased/{campid}")
public String getCampbased(@PathVariable("campid") Integer campid, Model model) {
List<CampBean> list = service.getAllCamps();
model.addAttribute("list", list);
String campname = "?";
for (CampBean p : list) {
if (p.getPk().equals(campid)) {
campname = p.getFullname();
}
}
model.addAttribute("selected", campname);
model.addAttribute("container", service.getPersonModuleMappingByCamp(campid));
model.addAttribute("pagedest", "_admin_privileges_campbased_" + campid);
return "/admin/privileges/campbased";
}
@GetMapping("/admin/privileges/userbased/{userid}")
public String getUserbased(@PathVariable("userid") Integer userid, Model model) {
List<ProfileBean> list = service.getProfiles();
model.addAttribute("list", list);
String selected = "?";
for (ProfileBean p : list) {
if (p.getPk().equals(userid)) {
selected = p.getFullname();
}
}
model.addAttribute("selected", selected);
model.addAttribute("container", service.getModuleCampMappingByPerson(userid));
model.addAttribute("pagedest", "_admin_privileges_userbased_" + userid);
return "/admin/privileges/userbased";
}
@GetMapping("/admin/privileges/delete/{id}/{pagedest}")
public String deleteFromCampProfile(@PathVariable("id") Integer id, @PathVariable("pagedest") String pagedest) {
service.deleteFromCampProfile(id);
return "redirect:" + pagedest.replace("_", "/");
}
@GetMapping("/admin/privileges/add/{pagedest}")
public String prepareAdd(Model model, @PathVariable("pagedest") String pagedest) {
model.addAttribute("pagedest", pagedest);
model.addAttribute("bean", new CampProfileBean());
model.addAttribute("profiles", service.getProfiles());
model.addAttribute("camps", service.getAllCamps());
model.addAttribute("modules", service.getAllModules());
return "/admin/privileges/add";
}
@PostMapping("/admin/privileges/insert/{pagedest}")
public String insertCampProfile(@Valid @ModelAttribute("bean") CampProfileBean bean, final BindingResult bindingResult, @PathVariable("pagedest") String pagedest, Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("pagedest", pagedest);
model.addAttribute("profiles", service.getProfiles());
model.addAttribute("camps", service.getAllCamps());
model.addAttribute("modules", service.getAllModules());
return "/admin/privileges/add";
}
service.insertIntoCampProfile(bean);
return "redirect:" + pagedest.replace("_", "/");
}
@GetMapping("/admin/privileges/abortinsert/{pagedest}")
public String abortInsert(@PathVariable("pagedest") String pagedest) {
return "redirect:" + pagedest.replace("_", "/");
}
}

View File

@ -0,0 +1,100 @@
package de.jottyfan.camporganizer.module.admin;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.module.admin.model.CampBean;
import de.jottyfan.camporganizer.module.admin.model.CampProfileBean;
import de.jottyfan.camporganizer.module.admin.model.PrivilegesContainerBean;
import de.jottyfan.camporganizer.module.admin.model.ProfileBean;
/**
*
* @author jotty
*
*/
@Service
public class AdminPrivilegesService {
@Autowired
private AdminRepository adminRepository;
/**
* get all camp beans from the database
*
* @return all camp beans; an empty list at least
*/
public List<CampBean> getAllCamps() {
return adminRepository.getAllCamps();
}
/**
* get all profiles from the db
*
* @return the profiles
*/
public List<ProfileBean> getProfiles() {
return adminRepository.getProfiles();
}
/**
* get all roles
*
* @return all roles
*/
public List<String> getAllModules() {
return adminRepository.getAllModules();
}
/**
* get the mapping that contains the form bean for a selected module
*
* @param module the module
* @return the container
*/
public PrivilegesContainerBean getPersonCampMappingByModule(EnumModule module) {
return adminRepository.getPersonCampMappingByModule(module);
}
/**
* get the mapping that contains the form bean for a selected camp
*
* @param camp the camp ID
* @return the container
*/
public PrivilegesContainerBean getPersonModuleMappingByCamp(Integer camp) {
return adminRepository.getPersonModuleMappingByCamp(camp);
}
/**
* get the mapping that contains the form bean for a selected user
*
* @param user the user ID
* @return the container
*/
public PrivilegesContainerBean getModuleCampMappingByPerson(Integer user) {
return adminRepository.getModuleCampMappingByPerson(user);
}
/**
* delete from camp profile
*
* @param id the ID
*/
public void deleteFromCampProfile(Integer id) {
adminRepository.deleteFromCampProfile(id);
}
/**
* add the camp profile to the database
*
* @param bean the bean
*/
public void insertIntoCampProfile(CampProfileBean bean) {
EnumModule m = bean.getModule() == null ? null : EnumModule.valueOf(bean.getModule());
adminRepository.addToCampProfile(bean.getFkCamp(), bean.getFkProfile(), m);
}
}

View File

@ -1,6 +1,7 @@
package de.jottyfan.camporganizer.module.admin;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENT;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENTROLE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION;
@ -12,11 +13,10 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.validation.Valid;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.Condition;
@ -25,12 +25,13 @@ import org.jooq.DeleteConditionStep;
import org.jooq.Field;
import org.jooq.InsertResultStep;
import org.jooq.InsertReturningStep;
import org.jooq.InsertValuesStep11;
import org.jooq.InsertValuesStep16;
import org.jooq.InsertValuesStep3;
import org.jooq.Record4;
import org.jooq.Record5;
import org.jooq.SelectConditionStep;
import org.jooq.SelectSeekStep1;
import org.jooq.SelectSeekStep2;
import org.jooq.SelectWhereStep;
import org.jooq.UpdateConditionStep;
import org.jooq.UpdateSetMoreStep;
@ -43,13 +44,22 @@ import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumDocument;
import de.jottyfan.camporganizer.db.jooq.enums.EnumFiletype;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampprofileRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TDocumentRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TDocumentroleRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TLocationRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TProfileRecord;
import de.jottyfan.camporganizer.module.camplist.LambdaResultWrapper;
import de.jottyfan.camporganizer.module.admin.model.CampBean;
import de.jottyfan.camporganizer.module.admin.model.DocumentBean;
import de.jottyfan.camporganizer.module.admin.model.IntKeyValueBean;
import de.jottyfan.camporganizer.module.admin.model.LocationBean;
import de.jottyfan.camporganizer.module.admin.model.PrivilegesContainerBean;
import de.jottyfan.camporganizer.module.admin.model.ProfileBean;
import de.jottyfan.camporganizer.module.camplist.model.LambdaResultWrapper;
import jakarta.validation.Valid;
/**
*
@ -121,7 +131,9 @@ public class AdminRepository {
// @formatter:on
LOGGER.debug(sql.toString());
List<DocumentBean> list = new ArrayList<>();
for (Record5<Integer, String, EnumDocument, EnumFiletype, EnumCamprole[]> r : sql.fetch()) {
Iterator<Record5<Integer, String, EnumDocument, EnumFiletype, EnumCamprole[]>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record5<Integer, String, EnumDocument, EnumFiletype, EnumCamprole[]> r = i.next();
DocumentBean bean = new DocumentBean();
bean.setPk(r.get(T_DOCUMENT.PK));
bean.setName(r.get(T_DOCUMENT.NAME));
@ -152,7 +164,9 @@ public class AdminRepository {
// @formatter:on
LOGGER.debug(sql.toString());
List<DocumentBean> list = new ArrayList<>();
for (Record4<Integer, String, EnumDocument, EnumFiletype> r : sql.fetch()) {
Iterator<Record4<Integer, String, EnumDocument, EnumFiletype>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, EnumDocument, EnumFiletype> r = i.next();
DocumentBean bean = new DocumentBean();
bean.setPk(r.get(T_DOCUMENT.PK));
bean.setName(r.get(T_DOCUMENT.NAME));
@ -421,10 +435,12 @@ public class AdminRepository {
jooq.transaction(t -> {
LocalDate arriveDate = bean.getArrive();
LocalDate departDate = bean.getDepart();
LocalDate startBookingDate = bean.getStartBooking();
LocalDateTime arrive = arriveDate == null ? null : arriveDate.atStartOfDay();
LocalDateTime depart = departDate == null ? null : departDate.atStartOfDay();
LocalDateTime startBooking = startBookingDate == null ? null : startBookingDate.atStartOfDay();
if (bean.getPk() == null) {
InsertValuesStep11<TCampRecord, LocalDateTime, String, LocalDateTime, Integer, Integer, Integer, Boolean, Integer, Integer, String, String> sql = DSL
InsertValuesStep16<TCampRecord, LocalDateTime, String, LocalDateTime, Integer, Integer, Integer, Boolean, Integer, Integer, String, String, Integer, Integer, Integer, Integer, LocalDateTime> sql = DSL
.using(t)
// @formatter:off
.insertInto(T_CAMP,
@ -438,9 +454,15 @@ public class AdminRepository {
T_CAMP.MAX_AGE,
T_CAMP.MIN_AGE,
T_CAMP.NAME,
T_CAMP.PRICE)
T_CAMP.PRICE,
T_CAMP.BEDS_FEMALE,
T_CAMP.BEDS_MALE,
T_CAMP.BLOCKED_BEDS_FEMALE,
T_CAMP.BLOCKED_BEDS_MALE,
T_CAMP.START_BOOKING)
.values(arrive, bean.getCountries(), depart, bean.getFkDocument(), bean.getFkLocation(), bean.getFkProfile(),
bean.getLockSales() != null ? bean.getLockSales() : false, bean.getMaxAge(), bean.getMinAge(), bean.getName(), bean.getPrice());
bean.getLockSales() != null ? bean.getLockSales() : false, bean.getMaxAge(), bean.getMinAge(), bean.getName(), bean.getPrice(),
bean.getBedsFemale(), bean.getBedsMale(), bean.getBlockedBedsFemale(), bean.getBlockedBedsMale(), startBooking);
// @formatter:on
LOGGER.debug(sql.toString());
sql.execute();
@ -459,6 +481,11 @@ public class AdminRepository {
.set(T_CAMP.MIN_AGE, bean.getMinAge())
.set(T_CAMP.NAME, bean.getName())
.set(T_CAMP.PRICE, bean.getPrice())
.set(T_CAMP.BEDS_FEMALE, bean.getBedsFemale())
.set(T_CAMP.BEDS_MALE, bean.getBedsMale())
.set(T_CAMP.BLOCKED_BEDS_FEMALE, bean.getBlockedBedsFemale())
.set(T_CAMP.BLOCKED_BEDS_MALE, bean.getBlockedBedsMale())
.set(T_CAMP.START_BOOKING, startBooking)
.where(T_CAMP.PK.eq(bean.getPk()));
// @formatter:on
LOGGER.debug(sql.toString());
@ -482,4 +509,166 @@ public class AdminRepository {
}
return list;
}
/**
* get all modules
*
* @return all modules
*/
public List<String> getAllModules() {
List<String> list = new ArrayList<>();
for (EnumModule r : EnumModule.values()) {
list.add(r.getLiteral());
}
return list;
}
/**
* get the mapping that contains the form bean for a selected module
*
* @param module the module
* @return the container
*/
public PrivilegesContainerBean getPersonCampMappingByModule(EnumModule module) {
SelectSeekStep2<Record4<Integer, String, LocalDateTime, String>, LocalDateTime, Integer> sql = jooq
// @formatter:off
.select(T_CAMPPROFILE.PK,
T_CAMP.NAME,
T_CAMP.ARRIVE,
T_PROFILE.FORENAME.concat(" ").concat(T_PROFILE.SURNAME).as(T_PROFILE.USERNAME))
.from(T_CAMPPROFILE)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_CAMPPROFILE.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_CAMPPROFILE.MODULE.eq(module))
.orderBy(T_CAMP.ARRIVE, T_PROFILE.PK);
// @formatter:on
LOGGER.debug(sql.toString());
PrivilegesContainerBean pcb = new PrivilegesContainerBean();
Iterator<Record4<Integer, String, LocalDateTime, String>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, LocalDateTime, String> r = i.next();
Integer fkCampProfile = r.get(T_CAMPPROFILE.PK);
String username = r.get(T_PROFILE.USERNAME);
String campname = r.get(T_CAMP.NAME);
LocalDateTime ldt = r.get(T_CAMP.ARRIVE);
String year = ldt != null ? String.valueOf(ldt.getYear()) : "?";
campname = campname == null ? year : campname.concat(" ").concat(year);
if (pcb.get(username) == null) {
pcb.addKey(username);
}
pcb.add(username, IntKeyValueBean.of(fkCampProfile, campname));
}
return pcb;
}
/**
* get the mapping that contains the form bean for a selected user
*
* @param user the user ID
* @return the container
*/
public PrivilegesContainerBean getModuleCampMappingByPerson(Integer user) {
SelectSeekStep1<Record4<Integer, String, LocalDateTime, EnumModule>, LocalDateTime> sql = jooq
// @formatter:off
.select(T_CAMPPROFILE.PK,
T_CAMP.NAME,
T_CAMP.ARRIVE,
T_CAMPPROFILE.MODULE)
.from(T_CAMPPROFILE)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_CAMPPROFILE.FK_CAMP))
.where(T_CAMPPROFILE.FK_PROFILE.eq(user))
.orderBy(T_CAMP.ARRIVE);
// @formatter:on
LOGGER.debug(sql.toString());
PrivilegesContainerBean pcb = new PrivilegesContainerBean();
Iterator<Record4<Integer, String, LocalDateTime, EnumModule>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, LocalDateTime, EnumModule> r = i.next();
Integer fkCampProfile = r.get(T_CAMPPROFILE.PK);
EnumModule moduleEnum = r.get(T_CAMPPROFILE.MODULE);
String module = moduleEnum == null ? null : moduleEnum.getLiteral();
String campname = r.get(T_CAMP.NAME);
LocalDateTime ldt = r.get(T_CAMP.ARRIVE);
String year = ldt != null ? String.valueOf(ldt.getYear()) : "?";
campname = campname == null ? year : campname.concat(" ").concat(year);
if (pcb.get(module) == null) {
pcb.addKey(module);
}
pcb.add(module, IntKeyValueBean.of(fkCampProfile, campname));
}
return pcb;
}
/**
* get the mapping that contains the form bean for a selected camp
*
* @param camp the camp ID
* @return the container
*/
public PrivilegesContainerBean getPersonModuleMappingByCamp(Integer camp) {
SelectSeekStep2<Record4<Integer, String, String, EnumModule>, String, String> sql = jooq
// @formatter:off
.select(T_CAMPPROFILE.PK,
T_PROFILE.FORENAME,
T_PROFILE.SURNAME,
T_CAMPPROFILE.MODULE)
.from(T_CAMPPROFILE)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_CAMPPROFILE.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_CAMPPROFILE.FK_CAMP.eq(camp))
.orderBy(T_PROFILE.SURNAME, T_PROFILE.FORENAME);
// @formatter:on
LOGGER.debug(sql.toString());
PrivilegesContainerBean pcb = new PrivilegesContainerBean();
Iterator<Record4<Integer, String, String, EnumModule>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, String, EnumModule> r = i.next();
Integer fkCampProfile = r.get(T_CAMPPROFILE.PK);
EnumModule moduleEnum = r.get(T_CAMPPROFILE.MODULE);
String forename = r.get(T_PROFILE.FORENAME);
String surname = r.get(T_PROFILE.SURNAME);
String person = new StringBuilder().append(forename).append(" ").append(surname).toString();
String module = moduleEnum == null ? null : moduleEnum.getLiteral();
if (pcb.get(person) == null) {
pcb.addKey(person);
}
pcb.add(person, IntKeyValueBean.of(fkCampProfile, module));
}
return pcb;
}
/**
* delete entry from camp profile
*
* @param id the pk
*/
public void deleteFromCampProfile(Integer id) {
DeleteConditionStep<TCampprofileRecord> sql = jooq.deleteFrom(T_CAMPPROFILE).where(T_CAMPPROFILE.PK.eq(id));
LOGGER.debug(sql.toString());
sql.execute();
}
/**
* add entry to database
*
* @param fkCamp the camp ID
* @param fkProfile the profile ID
* @param module the module
*/
public void addToCampProfile(Integer fkCamp, Integer fkProfile, EnumModule module) {
InsertReturningStep<TCampprofileRecord> sql = jooq
// @formatter:off
.insertInto(T_CAMPPROFILE,
T_CAMPPROFILE.FK_CAMP,
T_CAMPPROFILE.FK_PROFILE,
T_CAMPPROFILE.MODULE)
.values(fkCamp, fkProfile, module)
.onConflict(T_CAMPPROFILE.FK_CAMP,
T_CAMPPROFILE.FK_PROFILE,
T_CAMPPROFILE.MODULE)
.doNothing();
// @formatter:on
LOGGER.debug(sql.toString());
sql.execute();
}
}

View File

@ -5,7 +5,7 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.T_DOCUMENT;
import java.io.IOException;
import java.util.List;
import javax.validation.Valid;
import jakarta.validation.Valid;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -13,6 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.db.jooq.enums.EnumDocument;
import de.jottyfan.camporganizer.module.admin.model.CampBean;
import de.jottyfan.camporganizer.module.admin.model.DocumentBean;
import de.jottyfan.camporganizer.module.admin.model.LocationBean;
import de.jottyfan.camporganizer.module.admin.model.ProfileBean;
import de.jottyfan.camporganizer.module.mail.MailBean;
import de.jottyfan.camporganizer.module.mail.MailRepository;

View File

@ -1,17 +1,18 @@
package de.jottyfan.camporganizer.module.admin;
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
*
@ -44,6 +45,21 @@ public class CampBean implements Serializable {
private String countries;
@NotNull
private String price;
@NotNull
@Min(value = 0)
private Integer bedsFemale;
@NotNull
@Min(value = 0)
private Integer bedsMale;
@NotNull
@Min(value = 0)
private Integer blockedBedsFemale;
@NotNull
@Min(value = 0)
private Integer blockedBedsMale;
@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startBooking;
/**
* generate a camp bean out of r
@ -58,6 +74,7 @@ public class CampBean implements Serializable {
CampBean bean = new CampBean();
LocalDateTime arrive = r.getArrive();
LocalDateTime depart = r.getDepart();
LocalDateTime startBooking = r.getStartBooking();
bean.setArrive(arrive == null ? null : arrive.toLocalDate());
bean.setCountries(r.getCountries());
bean.setDepart(depart == null ? null : depart.toLocalDate());
@ -70,9 +87,18 @@ public class CampBean implements Serializable {
bean.setName(r.getName());
bean.setPk(r.getPk());
bean.setPrice(r.getPrice());
bean.setBedsFemale(r.getBedsFemale());
bean.setBedsMale(r.getBedsMale());
bean.setBlockedBedsFemale(r.getBlockedBedsFemale());
bean.setBlockedBedsMale(r.getBlockedBedsMale());
bean.setStartBooking(startBooking == null ? null : startBooking.toLocalDate());
return bean;
}
public String getFullname() {
return new StringBuilder().append(name).append(" ").append(arrive == null ? "?" : arrive.format(DateTimeFormatter.ofPattern("yyyy"))).toString();
}
/**
* @return the pk
*/
@ -267,4 +293,74 @@ public class CampBean implements Serializable {
}
this.countries = buf.toString();
}
/**
* @return the bedsFemale
*/
public Integer getBedsFemale() {
return bedsFemale;
}
/**
* @param bedsFemale the bedsFemale to set
*/
public void setBedsFemale(Integer bedsFemale) {
this.bedsFemale = bedsFemale;
}
/**
* @return the bedsMale
*/
public Integer getBedsMale() {
return bedsMale;
}
/**
* @param bedsMale the bedsMale to set
*/
public void setBedsMale(Integer bedsMale) {
this.bedsMale = bedsMale;
}
/**
* @return the blockedBedsFemale
*/
public Integer getBlockedBedsFemale() {
return blockedBedsFemale;
}
/**
* @param blockedBedsFemale the blockedBedsFemale to set
*/
public void setBlockedBedsFemale(Integer blockedBedsFemale) {
this.blockedBedsFemale = blockedBedsFemale;
}
/**
* @return the blockedBedsMale
*/
public Integer getBlockedBedsMale() {
return blockedBedsMale;
}
/**
* @param blockedBedsMale the blockedBedsMale to set
*/
public void setBlockedBedsMale(Integer blockedBedsMale) {
this.blockedBedsMale = blockedBedsMale;
}
/**
* @return the startBooking
*/
public LocalDate getStartBooking() {
return startBooking;
}
/**
* @param startBooking the startBooking to set
*/
public void setStartBooking(LocalDate startBooking) {
this.startBooking = startBooking;
}
}

View File

@ -0,0 +1,80 @@
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
*
* @author jotty
*
*/
public class CampProfileBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pk;
@NotNull
private Integer fkCamp;
@NotNull
private Integer fkProfile;
@NotBlank
private String module;
/**
* @return the pk
*/
public Integer getPk() {
return pk;
}
/**
* @param pk the pk to set
*/
public void setPk(Integer pk) {
this.pk = pk;
}
/**
* @return the fkCamp
*/
public Integer getFkCamp() {
return fkCamp;
}
/**
* @param fkCamp the fkCamp to set
*/
public void setFkCamp(Integer fkCamp) {
this.fkCamp = fkCamp;
}
/**
* @return the fkProfile
*/
public Integer getFkProfile() {
return fkProfile;
}
/**
* @param fkProfile the fkProfile to set
*/
public void setFkProfile(Integer fkProfile) {
this.fkProfile = fkProfile;
}
/**
* @return the module
*/
public String getModule() {
return module;
}
/**
* @param module the module to set
*/
public void setModule(String module) {
this.module = module;
}
}

View File

@ -1,12 +1,12 @@
package de.jottyfan.camporganizer.module.admin;
package de.jottyfan.camporganizer.module.admin.model;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Base64;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.io.IOUtils;
import org.springframework.web.multipart.MultipartFile;

View File

@ -0,0 +1,50 @@
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class IntKeyValueBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer key;
private String value;
public static final IntKeyValueBean of(Integer key, String value) {
IntKeyValueBean bean = new IntKeyValueBean();
bean.setKey(key);
bean.setValue(value);
return bean;
}
/**
* @return the key
*/
public Integer getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(Integer key) {
this.key = key;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
}

View File

@ -1,9 +1,9 @@
package de.jottyfan.camporganizer.module.admin;
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import de.jottyfan.camporganizer.db.jooq.tables.records.TLocationRecord;

View File

@ -0,0 +1,62 @@
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author jotty
*
*/
public class PrivilegesContainerBean implements Serializable {
private static final long serialVersionUID = 1L;
private Map<String, List<IntKeyValueBean>> map;
public PrivilegesContainerBean() {
map = new HashMap<>();
}
/**
* get the content of key
*
* @param key the key
* @return the value
*/
public List<IntKeyValueBean> get(String key) {
return map == null ? null : map.get(key);
}
/**
* add the value to the key
*
* @param key the key
* @param value the value
*/
public void add(String key, IntKeyValueBean value) {
if (get(key) != null) {
map.get(key).add(value);
} else {
throw new NullPointerException("key not found");
}
}
/**
* add the key to this map
*
* @param key
*/
public void addKey(String key) {
map.put(key, new ArrayList<>());
}
/**
* @return the map
*/
public Map<String, List<IntKeyValueBean>> getMap() {
return map;
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.admin;
package de.jottyfan.camporganizer.module.admin.model;
import java.io.Serializable;
@ -27,6 +27,10 @@ public class ProfileBean implements Serializable {
return bean;
}
public String getFullname() {
return new StringBuilder().append(forename).append(" ").append(surname).toString();
}
/**
* @return the pk
*/

View File

@ -1,6 +1,6 @@
package de.jottyfan.camporganizer.module.business.bookings;
import javax.annotation.security.RolesAllowed;
import jakarta.annotation.security.RolesAllowed;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -13,8 +13,8 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import de.jottyfan.camporganizer.module.business.bookings.impl.AddPaymentBean;
import de.jottyfan.camporganizer.module.business.bookings.impl.BookerBean;
import de.jottyfan.camporganizer.module.business.bookings.model.AddPaymentBean;
import de.jottyfan.camporganizer.module.business.bookings.model.BookerBean;
import de.jottyfan.camporganizer.module.camplist.CommonController;
/**
@ -27,7 +27,7 @@ public class BookingsController extends CommonController {
private static final Logger LOGGER = LogManager.getLogger(BookingsController.class);
@Autowired
private IBookingsService bookingsService;
private BookingsService bookingsService;
@GetMapping("/business/bookings")
@RolesAllowed({"business_booking"})
@ -39,7 +39,7 @@ public class BookingsController extends CommonController {
@GetMapping("/business/bookings/{id}")
@RolesAllowed({"business_booking"})
public String getBooking(Model model, @PathVariable Integer id) {
public String getBooking(Model model, @PathVariable("id") Integer id) {
BookerBean bean = bookingsService.getBooker(id, getCurrentUser());
model.addAttribute("booker", bean);
model.addAttribute("addBean", new AddPaymentBean());
@ -48,7 +48,7 @@ public class BookingsController extends CommonController {
@PostMapping("/business/bookings/payment/{id}")
@RolesAllowed({"business_booking"})
public String addPayment(Model model, @ModelAttribute AddPaymentBean bean, @PathVariable Integer id) {
public String addPayment(Model model, @ModelAttribute("bean") AddPaymentBean bean, @PathVariable("id") Integer id) {
Double payment = bean.getPayment();
bookingsService.addPayment(id, payment);
return getBooking(model, id);
@ -56,7 +56,7 @@ public class BookingsController extends CommonController {
@PostMapping("/business/bookings/listpayment/{id}")
@RolesAllowed({"business_booking"})
public String addListPayment(Model model, @ModelAttribute AddPaymentBean bean, @PathVariable Integer id, @RequestParam(defaultValue = "") String search) {
public String addListPayment(Model model, @ModelAttribute("bean") AddPaymentBean bean, @PathVariable("id") Integer id, @RequestParam(defaultValue = "") String search) {
Double payment = bean.getPayment();
bookingsService.addPayment(id, payment);
LOGGER.debug("search is {}", search);

View File

@ -1,13 +1,14 @@
package de.jottyfan.camporganizer.module.business.bookings.impl;
package de.jottyfan.camporganizer.module.business.bookings;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALESPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
@ -25,8 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.EnumConverter;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.module.business.bookings.model.BookerBean;
/**
*
@ -54,14 +57,16 @@ public class BookingsRepository {
.select(T_PERSON.PK, T_PERSON.ACCEPT, T_PERSON.PAID, T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.CREATED, V_CAMP.NAME, V_CAMP.YEAR)
.from(T_PERSON)
.leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_PERSON.FK_CAMP))
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PROFILE.USERNAME.eq(username))
.orderBy(T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.SURNAME, T_PERSON.FORENAME);
// @formatter:on
LOGGER.debug(sql.toString());
List<BookerBean> list = new ArrayList<>();
for (Record r : sql.fetch()) {
Iterator<Record10<Integer, Boolean, BigDecimal, String, String, EnumCamprole, EnumSex, LocalDateTime, String, Double>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record10<Integer, Boolean, BigDecimal, String, String, EnumCamprole, EnumSex, LocalDateTime, String, Double> r = i.next();
String forename = r.get(T_PERSON.FORENAME);
String surname = r.get(T_PERSON.SURNAME);
EnumCamprole role = r.get(T_PERSON.CAMPROLE);
@ -107,8 +112,8 @@ public class BookingsRepository {
V_CAMP.PK)
.from(T_PERSON)
.leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_PERSON.FK_CAMP))
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PROFILE.USERNAME.eq(username))
.and(T_PERSON.PK.eq(id));
// @formatter:on

View File

@ -1,11 +1,11 @@
package de.jottyfan.camporganizer.module.business.bookings.impl;
package de.jottyfan.camporganizer.module.business.bookings;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.business.bookings.IBookingsService;
import de.jottyfan.camporganizer.module.business.bookings.model.BookerBean;
/**
*
@ -13,24 +13,20 @@ import de.jottyfan.camporganizer.module.business.bookings.IBookingsService;
*
*/
@Service
public class BookingsService implements IBookingsService {
public class BookingsService {
@Autowired
private BookingsRepository bookingsGateway;
@Override
public List<BookerBean> getBookers(String username) {
return bookingsGateway.getBookings(username);
}
@Override
public BookerBean getBooker(Integer id, String username) {
return bookingsGateway.getBooking(id, username);
}
@Override
public Integer addPayment(Integer id, Double payment) {
return bookingsGateway.addPayment(id, payment);
}
}

View File

@ -1,38 +0,0 @@
package de.jottyfan.camporganizer.module.business.bookings;
import java.util.List;
import de.jottyfan.camporganizer.module.business.bookings.impl.BookerBean;
/**
*
* @author jotty
*
*/
public interface IBookingsService {
/**
* get the bookers information
*
* @param username the name of the user in this session
* @return the list of bookers; an empty one at least
*/
public List<BookerBean> getBookers(String username);
/**
* get the booker referenced by id
*
* @param id the ID of the booker
* @param username the name of the user in this session
* @return the booker if found; null otherwise
*/
public BookerBean getBooker(Integer id, String username);
/**
* add payment to the paid values of user with id
*
* @param id the ID of the booker
* @param payment the payment (additional value)
* @return number of affected database rows, should be 1
*/
public Integer addPayment(Integer id, Double payment);
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.bookings.impl;
package de.jottyfan.camporganizer.module.business.bookings.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.bookings.impl;
package de.jottyfan.camporganizer.module.business.bookings.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -1,7 +1,5 @@
package de.jottyfan.camporganizer.module.business.business;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@ -18,15 +16,12 @@ import de.jottyfan.camporganizer.module.camplist.CommonController;
public class BusinessController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private IBusinessService indexService;
private BusinessService service;
@GetMapping("/business")
public String getIndex(Model model) {
String username = indexService.getCurrentUser(request);
model.addAttribute("campBudgets", indexService.getCampBudgets(username));
String username = super.getCurrentUser();
model.addAttribute("campBudgets", service.getCampBudgets(username));
return "business/business";
}
}

View File

@ -1,20 +1,22 @@
package de.jottyfan.camporganizer.module.business.business.impl;
package de.jottyfan.camporganizer.module.business.business;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALESPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP_BUDGET;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Record4;
import org.jooq.Record9;
import org.jooq.SelectConditionStep;
@ -24,7 +26,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.module.business.business.model.BusinessBean;
import de.jottyfan.camporganizer.module.business.business.model.CampBudgetBean;
/**
*
@ -55,14 +60,16 @@ public class BusinessRepository {
V_CAMP_BUDGET.FK_CAMP)
.from(V_CAMP_BUDGET)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(V_CAMP_BUDGET.FK_CAMP))
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(V_CAMP_BUDGET.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(V_CAMP_BUDGET.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PROFILE.USERNAME.eq(username))
.orderBy(T_CAMP.ARRIVE);
// @formatter:on
LOGGER.debug(sql.toString());
List<CampBudgetBean> list = new ArrayList<>();
for (Record4<BigDecimal, String, Double, Integer> r : sql.fetch()) {
Iterator<Record4<BigDecimal, String, Double, Integer>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record r = i.next();
BigDecimal b = r.get(V_CAMP_BUDGET.BUDGET);
String n = r.get(V_CAMP_BUDGET.CAMP_NAME);
Double y = r.get(V_CAMP_BUDGET.YEAR);
@ -94,13 +101,15 @@ public class BusinessRepository {
.from(T_PERSON)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_PERSON.FK_CAMP))
.leftJoin(T_LOCATION).on(T_LOCATION.PK.eq(T_CAMP.FK_LOCATION))
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(T_CAMP.PK))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_CAMP.PK)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PROFILE.USERNAME.eq(username));
// @formatter:on
LOGGER.debug(sql.toString());
List<BusinessBean> list = new ArrayList<>();
for (Record9<Integer, String, String, String, String, LocalDateTime, String, BigDecimal, BigDecimal> r : sql.fetch()) {
Iterator<Record9<Integer, String, String, String, String, LocalDateTime, String, BigDecimal, BigDecimal>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record9<Integer, String, String, String, String, LocalDateTime, String, BigDecimal, BigDecimal> r = i.next();
Integer fkPerson = r.get(T_PERSON.PK);
String forename = r.get(T_PERSON.FORENAME);
String surname = r.get(T_PERSON.SURNAME);

View File

@ -0,0 +1,24 @@
package de.jottyfan.camporganizer.module.business.business;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.business.business.model.CampBudgetBean;
/**
*
* @author jotty
*
*/
@Service
public class BusinessService {
@Autowired
private BusinessRepository gateway;
public List<CampBudgetBean> getCampBudgets(String username) {
return gateway.getCampBudgets(username);
}
}

View File

@ -1,30 +0,0 @@
package de.jottyfan.camporganizer.module.business.business;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import de.jottyfan.camporganizer.module.business.business.impl.CampBudgetBean;
/**
*
* @author jotty
*
*/
public interface IBusinessService {
/**
* get the user of this session
*
* @param request the request
* @return the username of the current user
*/
public String getCurrentUser(HttpServletRequest request);
/**
* get a list of all camp budgets of all years
*
* @param username the name of the current user in this session
* @return the list; an empty one at least
*/
public List<CampBudgetBean> getCampBudgets(String username);
}

View File

@ -1,38 +0,0 @@
package de.jottyfan.camporganizer.module.business.business.impl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.jooq.exception.DataAccessException;
import org.keycloak.KeycloakSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.business.business.IBusinessService;
/**
*
* @author jotty
*
*/
@Service
public class BusinessService implements IBusinessService {
@Autowired
private BusinessRepository gateway;
@Override
public String getCurrentUser(HttpServletRequest request) {
KeycloakSecurityContext ksc = (KeycloakSecurityContext) request
.getAttribute(KeycloakSecurityContext.class.getName());
if (ksc == null) {
throw new DataAccessException("no keycloak user in session");
}
return ksc.getIdToken().getPreferredUsername();
}
@Override
public List<CampBudgetBean> getCampBudgets(String username) {
return gateway.getCampBudgets(username);
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.business.impl;
package de.jottyfan.camporganizer.module.business.business.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.business.impl;
package de.jottyfan.camporganizer.module.business.business.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -1,38 +1,29 @@
package de.jottyfan.camporganizer.module.business.camp;
import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import de.jottyfan.camporganizer.module.business.business.IBusinessService;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import jakarta.annotation.security.RolesAllowed;
/**
*
* @author jotty
*
*/
*
* @author jotty
*
*/
@Controller
public class CampController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private IBusinessService indexService;
@Autowired
private ICampService campService;
private CampService campService;
@GetMapping("/business/camp/{id}")
@RolesAllowed({"business"})
public String getCamp(Model model, @PathVariable Integer id) {
String username = indexService.getCurrentUser(request);
@RolesAllowed({ "business" })
public String getCamp(Model model, @PathVariable("id") Integer id) {
String username = super.getCurrentUser();
model.addAttribute("currentUser", username);
model.addAttribute("campId", id);
model.addAttribute("camp", campService.getCamp(id, username));

View File

@ -1,19 +1,19 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALESPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Record6;
import org.jooq.Record8;
import org.jooq.SelectConditionStep;
@ -24,7 +24,10 @@ import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.EnumConverter;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
import de.jottyfan.camporganizer.module.business.camp.model.CampBean;
import de.jottyfan.camporganizer.module.business.camp.model.PersonBean;
/**
*
@ -52,14 +55,16 @@ public class CampRepository {
// @formatter:off
.select(V_CAMP.NAME, V_CAMP.YEAR, V_CAMP.ARRIVE, V_CAMP.DEPART, V_CAMP.LOCATION_NAME, V_CAMP.PRICE)
.from(V_CAMP)
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(V_CAMP.PK))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(V_CAMP.PK)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(V_CAMP.PK.eq(pk))
.and(T_PROFILE.USERNAME.eq(username));
// @formatter:on
LOGGER.debug(sql.toString());
CampBean bean = new CampBean();
for (Record6<String, Double, LocalDateTime, LocalDateTime, String, String> r : sql.fetch()) {
Iterator<Record6<String, Double, LocalDateTime, LocalDateTime, String, String>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record6<String, Double, LocalDateTime, LocalDateTime, String, String> r = i.next();
bean.setName(r.get(V_CAMP.NAME));
bean.setYear(r.get(V_CAMP.YEAR));
bean.setArrive(r.get(V_CAMP.ARRIVE));
@ -83,15 +88,17 @@ public class CampRepository {
// @formatter:off
.select(T_PERSON.PK, T_PERSON.ACCEPT, T_PERSON.PAID, T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.CREATED)
.from(T_PERSON)
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PERSON.FK_CAMP.eq(pk))
.and(T_PROFILE.USERNAME.eq(username))
.orderBy(T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.SURNAME, T_PERSON.FORENAME);
// @formatter:on
LOGGER.debug(sql.toString());
List<PersonBean> list = new ArrayList<>();
for (Record r : sql.fetch()) {
Iterator<Record8<Integer, Boolean, BigDecimal, String, String, EnumCamprole, EnumSex, LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record8<Integer, Boolean, BigDecimal, String, String, EnumCamprole, EnumSex, LocalDateTime> r = i.next();
String forename = r.get(T_PERSON.FORENAME);
String surname = r.get(T_PERSON.SURNAME);
EnumCamprole role = r.get(T_PERSON.CAMPROLE);

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp;
import java.math.BigDecimal;
import java.util.List;
@ -6,7 +6,9 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.business.camp.ICampService;
import de.jottyfan.camporganizer.module.business.camp.model.BookingBean;
import de.jottyfan.camporganizer.module.business.camp.model.CampBean;
import de.jottyfan.camporganizer.module.business.camp.model.PersonBean;
/**
*
@ -14,17 +16,15 @@ import de.jottyfan.camporganizer.module.business.camp.ICampService;
*
*/
@Service
public class CampService implements ICampService {
public class CampService {
@Autowired
private CampRepository campGateway;
@Override
public CampBean getCamp(Integer id, String username) {
return campGateway.getCamp(id, username);
}
@Override
public BookingBean getBookings(Integer id, String username) {
Integer approved = 0;
Integer open = 0;
@ -35,9 +35,9 @@ public class CampService implements ICampService {
if (acceptence == null) {
open += 1;
} else if (acceptence) {
approved +=1;
approved += 1;
} else {
rejected +=1;
rejected += 1;
}
paid = paid.add(p.getPaid() == null ? new BigDecimal(0) : p.getPaid());
}
@ -49,9 +49,7 @@ public class CampService implements ICampService {
return bean;
}
@Override
public List<PersonBean> getBookers(Integer id, String username) {
return campGateway.getBookings(id, username);
}
}

View File

@ -1,43 +0,0 @@
package de.jottyfan.camporganizer.module.business.camp;
import java.util.List;
import de.jottyfan.camporganizer.module.business.camp.impl.BookingBean;
import de.jottyfan.camporganizer.module.business.camp.impl.CampBean;
import de.jottyfan.camporganizer.module.business.camp.impl.PersonBean;
/**
*
* @author jotty
*
*/
public interface ICampService {
/**
* get the camp bean of id
*
* @param id the id of the camp
* @param username the name of the user in this session
* @return the camp bean if found; null otherwise
*/
public CampBean getCamp(Integer id, String username);
/**
* get the booking information for camp with id
*
* @param id the id of the camp
* @param username the name of the user in this session
* @return a booking bean
*/
public BookingBean getBookings(Integer id, String username);
/**
* get the bookers information for camp with id
*
* @param id the id of the camp
* @param username the name of the user in this session
* @return the list of bookers; an empty one at least
*/
public List<PersonBean> getBookers(Integer id, String username);
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -1,11 +1,11 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp.model;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.camporganizer.module.business.privileges.impl.ProfileBean;
import de.jottyfan.camporganizer.module.business.privileges.model.ProfileBean;
/**
*

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.camp.impl;
package de.jottyfan.camporganizer.module.business.camp.model;
import java.io.Serializable;
import java.math.BigDecimal;

View File

@ -0,0 +1,66 @@
package de.jottyfan.camporganizer.module.business.outlay;
import java.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.module.business.outlay.model.OutlayBean;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import jakarta.annotation.security.RolesAllowed;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Controller
@RolesAllowed({ "business_outlay" })
public class OutlayController extends CommonController {
@Autowired
private OutlayService service;
@GetMapping("/business/outlay")
public String getOutlayDashboard(Model model, Principal principal) {
model.addAttribute("list", service.getListOfUser(super.getCurrentUser(principal)));
return "/business/outlay/list";
}
@GetMapping("/business/outlay/add")
public String loadAddMask(Model model, Principal principal) {
model.addAttribute("bean", new OutlayBean().withUser(super.getCurrentUser(principal)));
model.addAttribute("camps", service.getAllCamps());
return "/business/outlay/editor";
}
@GetMapping("/business/outlay/edit/{id}")
public String loadAddMask(@PathVariable("id") Integer id, Model model, Principal principal) {
model.addAttribute("bean", service.getBeanIfAllowedFor(super.getCurrentUser(principal), id));
model.addAttribute("camps", service.getAllCamps());
return "/business/outlay/editor";
}
@PostMapping("/business/outlay/save")
public String save(@Valid @ModelAttribute("bean") OutlayBean bean, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute("camps", service.getAllCamps());
return "/business/outlay/editor";
}
service.save(bean);
return "redirect:/business/outlay";
}
@GetMapping("/business/outlay/delete/{id}")
public String delete(@PathVariable("id") Integer id, Principal principal) {
service.deleteIfAllowedFor(super.getCurrentUser(principal), id);
return "redirect:/business/outlay";
}
}

View File

@ -0,0 +1,191 @@
package de.jottyfan.camporganizer.module.business.outlay;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALES;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.DeleteConditionStep;
import org.jooq.InsertValuesStep8;
import org.jooq.Record10;
import org.jooq.Record4;
import org.jooq.Record7;
import org.jooq.SelectConditionStep;
import org.jooq.SelectSeekStep1;
import org.jooq.UpdateConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.tables.records.TSalesRecord;
import de.jottyfan.camporganizer.module.business.outlay.model.CampBean;
import de.jottyfan.camporganizer.module.business.outlay.model.OutlayBean;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Repository
@Transactional(transactionManager = "transactionManager")
public class OutlayRepository {
private static final Logger LOGGER = LogManager.getLogger(OutlayRepository.class);
@Autowired
private DSLContext jooq;
/**
* get all camps from the database
*
* @return a list of camps; an empty list at least
*/
public List<CampBean> getAllCamps() {
SelectSeekStep1<Record4<Integer, String, LocalDateTime, String>, LocalDateTime> sql = jooq
// @formatter:off
.select(T_CAMP.PK, T_CAMP.NAME, T_CAMP.ARRIVE, T_LOCATION.NAME)
.from(T_CAMP)
.leftJoin(T_LOCATION).on(T_LOCATION.PK.eq(T_CAMP.FK_LOCATION))
.orderBy(T_CAMP.ARRIVE.desc());
// @formatter:on
LOGGER.trace(sql.toString());
List<CampBean> list = new ArrayList<>();
Iterator<Record4<Integer, String, LocalDateTime, String>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, LocalDateTime, String> r = i.next();
String name = String
.format("%s %s %d", r.get(T_CAMP.NAME), r.get(T_LOCATION.NAME), r.get(T_CAMP.ARRIVE).getYear()).trim();
list.add(CampBean.of(r.get(T_CAMP.PK)).withCampname(name));
}
return list;
}
public List<OutlayBean> getListOf(String username) {
SelectConditionStep<Record7<Integer, String, String, LocalDateTime, String, BigDecimal, LocalDateTime>> sql = jooq
// @formatter:off
.select(T_SALES.PK,
T_SALES.TRADER,
T_CAMP.NAME,
T_CAMP.ARRIVE,
T_LOCATION.NAME,
T_SALES.CASH,
T_SALES.BUYDATE)
.from(T_SALES)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_SALES.FK_CAMP))
.leftJoin(T_LOCATION).on(T_LOCATION.PK.eq(T_CAMP.FK_LOCATION))
.where(T_SALES.PROVIDER.eq(username));
// @formatter:on
LOGGER.trace(sql);
List<OutlayBean> list = new ArrayList<>();
Iterator<Record7<Integer, String, String, LocalDateTime, String, BigDecimal, LocalDateTime>> i = sql.fetch()
.iterator();
while (i.hasNext()) {
Record7<Integer, String, String, LocalDateTime, String, BigDecimal, LocalDateTime> r = i.next();
String campname = String
.format("%s %s %d", r.get(T_CAMP.NAME), r.get(T_LOCATION.NAME), r.get(T_CAMP.ARRIVE).getYear()).trim();
OutlayBean bean = new OutlayBean();
bean.setId(r.get(T_SALES.PK));
bean.setTrader(r.get(T_SALES.TRADER));
bean.setCampname(campname);
bean.setCash(r.get(T_SALES.CASH));
bean.setBuydate(r.get(T_SALES.BUYDATE));
list.add(bean);
}
return list;
}
public void addBean(@Valid OutlayBean bean) {
InsertValuesStep8<TSalesRecord, LocalDateTime, BigDecimal, Integer, String, String, String, String, String> sql = jooq
// @formatter:off
.insertInto(T_SALES,
T_SALES.BUYDATE,
T_SALES.CASH,
T_SALES.FK_CAMP,
T_SALES.INCREDIENTS,
T_SALES.PROVIDER,
T_SALES.RECIPENOTE,
T_SALES.RECIPENUMBER,
T_SALES.TRADER)
.values(bean.getBuydate(), bean.getCash(), bean.getFkCamp(), bean.getIngredients(), bean.getProvider(), bean.getRecipenote(), bean.getRecipenumber(), bean.getTrader());
// @formatter:on
LOGGER.trace(sql);
sql.execute();
}
public void updateBean(@Valid OutlayBean bean) {
UpdateConditionStep<TSalesRecord> sql = jooq
// @formatter:off
.update(T_SALES)
.set(T_SALES.BUYDATE, bean.getBuydate())
.set(T_SALES.CASH, bean.getCash())
.set(T_SALES.FK_CAMP, bean.getFkCamp())
.set(T_SALES.INCREDIENTS, bean.getIngredients())
.set(T_SALES.PROVIDER, bean.getProvider())
.set(T_SALES.RECIPENOTE, bean.getRecipenote())
.set(T_SALES.RECIPENUMBER, bean.getRecipenumber())
.set(T_SALES.TRADER, bean.getTrader())
.where(T_SALES.PK.eq(bean.getId()));
// @formatter:on
LOGGER.trace(sql);
sql.execute();
}
public OutlayBean getBeanIfAllowedFor(String username, Integer id) {
SelectConditionStep<Record10<Integer, String, Integer, BigDecimal, LocalDateTime, String, String, String, String, String>> sql = jooq
// @formatter:off
.select(T_SALES.PK,
T_SALES.TRADER,
T_SALES.FK_CAMP,
T_SALES.CASH,
T_SALES.BUYDATE,
T_SALES.INCREDIENTS,
T_SALES.PROVIDER,
T_SALES.RECIPENOTE,
T_SALES.RECIPENUMBER,
T_SALES.TRADER)
.from(T_SALES)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_SALES.FK_CAMP))
.leftJoin(T_LOCATION).on(T_LOCATION.PK.eq(T_CAMP.FK_LOCATION))
.where(T_SALES.PROVIDER.eq(username))
.and(T_SALES.PK.eq(id));
// @formatter:on
LOGGER.trace(sql);
Record10<Integer, String, Integer, BigDecimal, LocalDateTime, String, String, String, String, String> r = sql
.fetchOne();
if (r == null) {
return null;
} else {
OutlayBean bean = new OutlayBean();
bean.setId(r.get(T_SALES.PK));
bean.setBuydate(r.get(T_SALES.BUYDATE));
bean.setCash(r.get(T_SALES.CASH));
bean.setFkCamp(r.get(T_SALES.FK_CAMP));
bean.setIngredients(r.get(T_SALES.INCREDIENTS));
bean.setProvider(r.get(T_SALES.PROVIDER));
bean.setRecipenote(r.get(T_SALES.RECIPENOTE));
bean.setRecipenumber(r.get(T_SALES.RECIPENUMBER));
bean.setTrader(r.get(T_SALES.TRADER));
return bean;
}
}
public void deleteBeanIfAllowedFor(String username, Integer id) {
DeleteConditionStep<TSalesRecord> sql = jooq
// @formatter:off
.deleteFrom(T_SALES)
.where(T_SALES.PROVIDER.eq(username))
.and(T_SALES.PK.eq(id));
// @formatter:off
LOGGER.trace(sql);
sql.execute();
}
}

View File

@ -0,0 +1,46 @@
package de.jottyfan.camporganizer.module.business.outlay;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.business.outlay.model.CampBean;
import de.jottyfan.camporganizer.module.business.outlay.model.OutlayBean;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Service
public class OutlayService {
@Autowired
private OutlayRepository repository;
public List<OutlayBean> getListOfUser(String username) {
return repository.getListOf(username);
}
public List<CampBean> getAllCamps() {
return repository.getAllCamps();
}
public void save(@Valid OutlayBean bean) {
if (bean.getId() != null) {
repository.updateBean(bean);
} else {
repository.addBean(bean);
}
}
public OutlayBean getBeanIfAllowedFor(String username, Integer id) {
return repository.getBeanIfAllowedFor(username, id);
}
public void deleteIfAllowedFor(String username, Integer id) {
repository.deleteBeanIfAllowedFor(username, id);
}
}

View File

@ -0,0 +1,51 @@
package de.jottyfan.camporganizer.module.business.outlay.model;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class CampBean implements Serializable {
private static final long serialVersionUID = 1L;
private final Integer id;
private String campname;
private CampBean(Integer id) {
super();
this.id = id;
}
public static final CampBean of(Integer id) {
return new CampBean(id);
}
public CampBean withCampname(String campname) {
this.campname = campname;
return this;
}
/**
* @return the campname
*/
public String getCampname() {
return campname;
}
/**
* @param campname the campname to set
*/
public void setCampname(String campname) {
this.campname = campname;
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
}

View File

@ -0,0 +1,180 @@
package de.jottyfan.camporganizer.module.business.outlay.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
*
* @author jotty
*
*/
public class OutlayBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
@NotBlank
private String trader;
@NotNull
private Integer fkCamp;
private String campname;
private String provider;
@NotNull
private BigDecimal cash;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss")
private LocalDateTime buydate;
private String recipenumber;
private String recipenote;
private String ingredients;
public OutlayBean withUser(String provider) {
this.provider = provider;
return this;
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the trader
*/
public String getTrader() {
return trader;
}
/**
* @param trader the trader to set
*/
public void setTrader(String trader) {
this.trader = trader;
}
/**
* @return the campname
*/
public String getCampname() {
return campname;
}
/**
* @param campname the campname to set
*/
public void setCampname(String campname) {
this.campname = campname;
}
/**
* @return the cash
*/
public BigDecimal getCash() {
return cash;
}
/**
* @param cash the cash to set
*/
public void setCash(BigDecimal cash) {
this.cash = cash;
}
/**
* @return the buydate
*/
public LocalDateTime getBuydate() {
return buydate;
}
/**
* @param buydate the buydate to set
*/
public void setBuydate(LocalDateTime buydate) {
this.buydate = buydate;
}
/**
* @return the provider
*/
public String getProvider() {
return provider;
}
/**
* @param provider the provider to set
*/
public void setProvider(String provider) {
this.provider = provider;
}
/**
* @return the recipenumber
*/
public String getRecipenumber() {
return recipenumber;
}
/**
* @param recipenumber the recipenumber to set
*/
public void setRecipenumber(String recipenumber) {
this.recipenumber = recipenumber;
}
/**
* @return the recipenote
*/
public String getRecipenote() {
return recipenote;
}
/**
* @param recipenote the recipenote to set
*/
public void setRecipenote(String recipenote) {
this.recipenote = recipenote;
}
/**
* @return the ingredients
*/
public String getIngredients() {
return ingredients;
}
/**
* @param ingredients the ingredients to set
*/
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
/**
* @return the fkCamp
*/
public Integer getFkCamp() {
return fkCamp;
}
/**
* @param fkCamp the fkCamp to set
*/
public void setFkCamp(Integer fkCamp) {
this.fkCamp = fkCamp;
}
}

View File

@ -0,0 +1,64 @@
package de.jottyfan.camporganizer.module.business.privileges;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.module.business.privileges.model.BusinessPrivilegesBean;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import jakarta.annotation.security.RolesAllowed;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Controller
public class BusinessPrivilegesController extends CommonController {
@Autowired
private BusinessPrivilegesService service;
@GetMapping("/business/privileges")
@RolesAllowed({ "admin" })
public String getIndex(Model model) {
String username = super.getCurrentUser();
model.addAttribute("currentUser", username);
model.addAttribute("privileges", service.getPrivileges());
model.addAttribute("profiles", service.getProfiles(EnumCamprole.director, EnumCamprole.teacher));
model.addAttribute("bean", new BusinessPrivilegesBean());
return "business/privileges";
}
@PostMapping("/business/privileges/add")
@RolesAllowed({ "admin" })
public String getAdd(@Valid @ModelAttribute("bean") BusinessPrivilegesBean bean, BindingResult br, Model model) {
if (br.hasErrors()) {
String username = super.getCurrentUser();
model.addAttribute("currentUser", username);
model.addAttribute("privileges", service.getPrivileges());
model.addAttribute("profiles", service.getProfiles(EnumCamprole.director, EnumCamprole.teacher));
return "business/privileges";
}
service.add(bean);
return "redirect:/business/privileges";
}
@GetMapping("/business/privileges/delete")
@RolesAllowed({ "admin" })
public String getDelete(@RequestParam("fkCamp") Integer fkCamp, @RequestParam("fkProfile") Integer fkProfile,
Model model) {
BusinessPrivilegesBean bean = new BusinessPrivilegesBean();
bean.setFkCamp(fkCamp);
bean.setFkProfile(fkProfile);
service.remove(bean, super.getCurrentUser());
return "redirect:/business/privileges";
}
}

View File

@ -1,8 +1,8 @@
package de.jottyfan.camporganizer.module.business.privileges.impl;
package de.jottyfan.camporganizer.module.business.privileges;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALESPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.time.LocalDateTime;
@ -23,7 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.tables.records.TSalesprofileRecord;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampprofileRecord;
import de.jottyfan.camporganizer.module.business.privileges.model.BusinessPrivilegesBean;
import de.jottyfan.camporganizer.module.business.privileges.model.ProfileBean;
/**
*
@ -32,25 +35,25 @@ import de.jottyfan.camporganizer.db.jooq.tables.records.TSalesprofileRecord;
*/
@Repository
@Transactional(transactionManager = "transactionManager")
public class PrivilegesRepository {
private static final Logger LOGGER = LogManager.getLogger(PrivilegesRepository.class);
public class BusinessPrivilegesRepository {
private static final Logger LOGGER = LogManager.getLogger(BusinessPrivilegesRepository.class);
@Autowired
private DSLContext jooq;
public List<PrivilegesBean> getPrivileges() {
public List<BusinessPrivilegesBean> getPrivileges() {
SelectSeekStep3<Record8<String, String, LocalDateTime, String, Integer, Integer, String, Double>, LocalDateTime, String, String> sql = jooq
// @formatter:off
.select(T_PROFILE.FORENAME, T_PROFILE.SURNAME, T_PROFILE.DUEDATE, T_PROFILE.USERNAME, T_PROFILE.PK, V_CAMP.PK, V_CAMP.NAME, V_CAMP.YEAR)
.from(V_CAMP)
.leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(V_CAMP.PK))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_SALESPROFILE.FK_PROFILE))
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(V_CAMP.PK)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.orderBy(V_CAMP.ARRIVE, T_PROFILE.SURNAME, T_PROFILE.FORENAME);
// @formatter:on
LOGGER.debug(sql.toString());
List<PrivilegesBean> list = new ArrayList<>();
List<BusinessPrivilegesBean> list = new ArrayList<>();
for (Record8<String, String, LocalDateTime, String, Integer, Integer, String, Double> r : sql.fetch()) {
PrivilegesBean bean = new PrivilegesBean();
BusinessPrivilegesBean bean = new BusinessPrivilegesBean();
bean.setCampName(r.get(V_CAMP.NAME));
bean.setCampYear(r.get(V_CAMP.YEAR));
bean.setFkCamp(r.get(V_CAMP.PK));
@ -91,25 +94,26 @@ public class PrivilegesRepository {
return list;
}
public Integer add(PrivilegesBean bean) {
InsertReturningStep<TSalesprofileRecord> sql = jooq
public Integer add(BusinessPrivilegesBean bean) {
InsertReturningStep<TCampprofileRecord> sql = jooq
// @formatter:off
.insertInto(T_SALESPROFILE, T_SALESPROFILE.FK_CAMP, T_SALESPROFILE.FK_PROFILE)
.values(bean.getFkCamp(), bean.getFkProfile())
.onConflict(T_SALESPROFILE.FK_CAMP, T_SALESPROFILE.FK_PROFILE)
.insertInto(T_CAMPPROFILE, T_CAMPPROFILE.FK_CAMP, T_CAMPPROFILE.FK_PROFILE, T_CAMPPROFILE.MODULE)
.values(bean.getFkCamp(), bean.getFkProfile(), EnumModule.business)
.onConflict(T_CAMPPROFILE.FK_CAMP, T_CAMPPROFILE.FK_PROFILE, T_CAMPPROFILE.MODULE)
.doNothing();
// @formatter:on
LOGGER.debug(sql.toString());
return sql.execute();
}
public Integer remove(PrivilegesBean bean, String currentUser) {
DeleteConditionStep<TSalesprofileRecord> sql = jooq
public Integer remove(BusinessPrivilegesBean bean, String currentUser) {
DeleteConditionStep<TCampprofileRecord> sql = jooq
// @formatter:off
.deleteFrom(T_SALESPROFILE)
.where(T_SALESPROFILE.FK_CAMP.eq(bean.getFkCamp()))
.and(T_SALESPROFILE.FK_PROFILE.eq(bean.getFkProfile()))
.and(T_SALESPROFILE.FK_PROFILE.notIn(jooq
.deleteFrom(T_CAMPPROFILE)
.where(T_CAMPPROFILE.MODULE.eq(EnumModule.business))
.and(T_CAMPPROFILE.FK_CAMP.eq(bean.getFkCamp()))
.and(T_CAMPPROFILE.FK_PROFILE.eq(bean.getFkProfile()))
.and(T_CAMPPROFILE.FK_PROFILE.notIn(jooq
.select(T_PROFILE.PK)
.from(T_PROFILE)
.where(T_PROFILE.USERNAME.eq(currentUser))));

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.privileges.impl;
package de.jottyfan.camporganizer.module.business.privileges;
import java.util.HashMap;
import java.util.HashSet;
@ -10,7 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.module.business.camp.impl.CampBean;
import de.jottyfan.camporganizer.module.business.camp.model.CampBean;
import de.jottyfan.camporganizer.module.business.privileges.model.BusinessPrivilegesBean;
import de.jottyfan.camporganizer.module.business.privileges.model.ProfileBean;
/**
*
@ -18,14 +20,14 @@ import de.jottyfan.camporganizer.module.business.camp.impl.CampBean;
*
*/
@Service
public class PrivilegesService {
public class BusinessPrivilegesService {
@Autowired
private PrivilegesRepository gateway;
private BusinessPrivilegesRepository gateway;
public Map<Integer, CampBean> getPrivileges() {
List<PrivilegesBean> list = gateway.getPrivileges();
List<BusinessPrivilegesBean> list = gateway.getPrivileges();
Map<Integer, CampBean> camps = new HashMap<>();
for (PrivilegesBean bean : list) {
for (BusinessPrivilegesBean bean : list) {
CampBean campBean = camps.get(bean.getFkCamp());
if (campBean == null) {
campBean = new CampBean();
@ -53,11 +55,11 @@ public class PrivilegesService {
return gateway.getProfiles(allowed == null ? null : set);
}
public void add(PrivilegesBean bean) {
public void add(BusinessPrivilegesBean bean) {
gateway.add(bean);
}
public void remove(PrivilegesBean bean, String currentUser) {
public void remove(BusinessPrivilegesBean bean, String currentUser) {
gateway.remove(bean, currentUser);
}
}

View File

@ -1,65 +0,0 @@
package de.jottyfan.camporganizer.module.business.privileges;
import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.module.business.business.IBusinessService;
import de.jottyfan.camporganizer.module.business.privileges.impl.PrivilegesBean;
import de.jottyfan.camporganizer.module.business.privileges.impl.PrivilegesService;
import de.jottyfan.camporganizer.module.camplist.CommonController;
/**
*
* @author jotty
*
*/
@Controller
public class PrivilegesController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private PrivilegesService privilegesService;
@Autowired
private IBusinessService indexService;
@GetMapping("/business/privileges")
@RolesAllowed({ "admin" })
public String getIndex(Model model) {
String username = indexService.getCurrentUser(request);
model.addAttribute("currentUser", username);
model.addAttribute("privileges", privilegesService.getPrivileges());
model.addAttribute("profiles", privilegesService.getProfiles(EnumCamprole.director, EnumCamprole.teacher));
model.addAttribute("bean", new PrivilegesBean());
return "business/privileges";
}
@PostMapping("/business/privileges/add")
@RolesAllowed({ "admin" })
public String getAdd(@ModelAttribute PrivilegesBean bean, Model model) {
privilegesService.add(bean);
return getIndex(model);
}
@GetMapping("/business/privileges/delete")
@RolesAllowed({ "admin" })
public String getDelete(@PathParam(value = "fkCamp") Integer fkCamp,
@PathParam(value = "fkProfile") Integer fkProfile, Model model) {
PrivilegesBean bean = new PrivilegesBean();
bean.setFkCamp(fkCamp);
bean.setFkProfile(fkProfile);
privilegesService.remove(bean, indexService.getCurrentUser(request));
return getIndex(model);
}
}

View File

@ -1,21 +1,25 @@
package de.jottyfan.camporganizer.module.business.privileges.impl;
package de.jottyfan.camporganizer.module.business.privileges.model;
import java.io.Serializable;
import java.time.LocalDateTime;
import jakarta.validation.constraints.NotNull;
/**
*
* @author jotty
*
*/
public class PrivilegesBean implements Serializable {
public class BusinessPrivilegesBean implements Serializable {
private static final long serialVersionUID = 1L;
private String forename;
private String surname;
private String username;
private LocalDateTime duedate;
@NotNull
private Integer fkProfile;
@NotNull
private Integer fkCamp;
private String campName;
private Double campYear;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.business.privileges.impl;
package de.jottyfan.camporganizer.module.business.privileges.model;
import java.io.Serializable;
import java.time.LocalDateTime;

View File

@ -1,7 +1,6 @@
package de.jottyfan.camporganizer.module.camplist;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -12,7 +11,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.module.registration.KeycloakRepository;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
/**
*
@ -23,32 +24,25 @@ import de.jottyfan.camporganizer.module.registration.KeycloakRepository;
public class CamplistController extends CommonController {
private static final Logger LOGGER = LogManager.getLogger(CamplistController.class);
@Autowired
private HttpServletRequest request;
@Autowired
private KeycloakRepository keycloak;
@Autowired
private CamplistService service;
@GetMapping("/camplist")
public String index(Model model) {
public String index(Model model, Principal principal) {
model.addAttribute("camps", service.getAllCamps(true));
return super.isLoggedIn(request) ? dashboard(model) : "/camplist";
return super.isLoggedIn(principal) ? dashboard(model) : "/camplist";
}
@GetMapping("/dashboard")
public String dashboard(Model model) {
model.addAttribute("mybookings", service.getBookingsOf(super.getCurrentUser(request)));
model.addAttribute("mybookings", service.getBookingsOf(super.getCurrentUser()));
model.addAttribute("bookingBean", new BookingBean());
model.addAttribute("keycloakProfileUrl", keycloak.getUserClientUrl());
model.addAttribute("camps", service.getAllCamps(true));
return "/dashboard";
}
@PostMapping("/dashboard/update")
public String updateBooking(Model model, @ModelAttribute BookingBean bean) {
public String updateBooking(Model model, @ModelAttribute("b") BookingBean bean) {
service.update(bean);
return dashboard(model);
}

View File

@ -12,6 +12,7 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -26,6 +27,7 @@ import org.jooq.Record2;
import org.jooq.SelectOrderByStep;
import org.jooq.SelectSeekStep1;
import org.jooq.SelectSeekStep2;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@ -34,6 +36,8 @@ import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumDocument;
import de.jottyfan.camporganizer.db.jooq.tables.TProfile;
import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import de.jottyfan.camporganizer.module.camplist.model.DocumentBean;
/**
*
@ -42,8 +46,8 @@ import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord;
*/
@Repository
@Transactional(transactionManager = "transactionManager")
public class CamplistGateway {
private static final Logger LOGGER = LogManager.getLogger(CamplistGateway.class);
public class CamplistRepository {
private static final Logger LOGGER = LogManager.getLogger(CamplistRepository.class);
@Autowired
private DSLContext jooq;
@ -91,13 +95,15 @@ public class CamplistGateway {
.leftJoin(T_PERSON).on(T_PERSON.FK_PROFILE.eq(T_PROFILE.PK))
.leftJoin(REGISTRATOR).on(REGISTRATOR.PK.eq(T_PERSON.FK_REGISTRATOR))
.leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_PERSON.FK_CAMP))
.where(T_PROFILE.USERNAME.eq(username))
.where(DSL.trim(T_PROFILE.USERNAME).eq(username == null ? null : username.trim()))
.and(T_PERSON.PK.isNotNull())
.orderBy(V_CAMP.ARRIVE.desc(), T_PERSON.CREATED);
// @formatter:on
LOGGER.debug(sql.toString());
List<BookingBean> list = new ArrayList<>();
for (Record r : sql.fetch()) {
Iterator<Record> i = sql.fetch().iterator();
while (i.hasNext()) {
Record r = i.next();
Integer fkCamp = r.get(T_PERSON.FK_CAMP);
BookingBean bean = new BookingBean();
bean.setPk(r.get(T_PERSON.PK));
@ -181,7 +187,9 @@ public class CamplistGateway {
// @formatter:on
LOGGER.debug(sql.toString());
Map<Integer, String> map = new HashMap<>(); // no duplicate on using a map
for (Record r : sql.fetch()) {
Iterator<Record2<String, Integer>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record2<String, Integer> r = i.next();
map.put(r.get(T_DOCUMENT.PK), r.get(T_DOCUMENT.NAME));
}
List<DocumentBean> list = new ArrayList<>();

View File

@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import de.jottyfan.camporganizer.module.dashboard.DashboardRepository;
/**
@ -24,7 +25,7 @@ import de.jottyfan.camporganizer.module.dashboard.DashboardRepository;
public class CamplistService {
@Autowired
private CamplistGateway gateway;
private CamplistRepository gateway;
@Autowired
private DashboardRepository dashboardGateway;

View File

@ -1,57 +1,92 @@
package de.jottyfan.camporganizer.module.camplist;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import org.keycloak.KeycloakSecurityContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.ModelAttribute;
import de.jottyfan.camporganizer.module.registration.KeycloakRepository;
/**
*
* @author jotty
*
*/
public abstract class CommonController {
private static final Logger LOGGER = LogManager.getLogger();
@Autowired
private HttpServletRequest request;
private KeycloakRepository keycloak;
/**
* try to get current keycloak user
*
* @param request the request
* @param principal the principal
* @return the preferred username or null
*/
public String getCurrentUser(HttpServletRequest request) {
KeycloakSecurityContext ksc = (KeycloakSecurityContext) request
.getAttribute(KeycloakSecurityContext.class.getName());
return ksc == null ? null : ksc.getIdToken().getPreferredUsername();
public String getCurrentUser(Principal principal) {
return principal == null ? null : principal.getName();
}
/**
* try to get th currnt keycloak email
*
* @param request the request
* @param principal the principal
* @return the email or null
*/
public String getCurrentEmail(HttpServletRequest request) {
KeycloakSecurityContext ksc = (KeycloakSecurityContext) request
.getAttribute(KeycloakSecurityContext.class.getName());
return ksc == null ? null : ksc.getIdToken().getEmail();
public String getCurrentEmail(Principal principal) {
if (principal instanceof OAuth2AuthenticationToken) {
OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal;
if (token != null) {
OAuth2User user = token.getPrincipal();
if (user != null) {
return user.getAttribute("email");
}
}
} else {
LOGGER.error("could not find email for {}", principal);
}
return null;
}
@ModelAttribute("currentUser")
public String getCurrentUser() {
return getCurrentUser(request);
SecurityContext context = SecurityContextHolder.getContext();
if (context != null) {
Authentication authentication = context.getAuthentication();
if (authentication != null) {
DefaultOidcUser dou = (DefaultOidcUser) authentication.getPrincipal();
return dou == null ? null : dou.getName();
}
}
return null;
}
@ModelAttribute("keycloakProfileUrl")
public String getKeycloakProfileUrl() {
return keycloak.getUserClientUrl();
}
@ModelAttribute("keycloakPasswordUrl")
public String getKeycloakPasswordUrl() {
return keycloak.getPasswordClientUrl();
}
/**
* return true if the user has a valid keycloak session token
*
* @param request the request
* @param principal the principal
* @return true or false
*/
public boolean isLoggedIn(HttpServletRequest request) {
return getCurrentUser(request) != null;
public boolean isLoggedIn(Principal principal) {
return getCurrentUser(principal) != null;
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.camplist;
package de.jottyfan.camporganizer.module.camplist.model;
import java.io.Serializable;
import java.time.LocalDate;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.camplist;
package de.jottyfan.camporganizer.module.camplist.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.camplist;
package de.jottyfan.camporganizer.module.camplist.model;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.camplist;
package de.jottyfan.camporganizer.module.camplist.model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;

View File

@ -0,0 +1,52 @@
package de.jottyfan.camporganizer.module.confirmation.board;
import java.io.IOException;
import java.security.Principal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import jakarta.servlet.http.HttpServletResponse;
/**
*
* @author jotty
*
*/
@Controller
public class ConfirmationBoardController extends CommonController {
@Autowired
private ConfirmationBoardService service;
@GetMapping("/confirmation/board")
public String getBoard(Model model, Principal principal) {
model.addAttribute("camps", service.loadCampList(super.getCurrentUser(principal)));
return "/confirmation/board";
}
@GetMapping("/confirmation/board/camp/{id}")
public String getCamplist(Model model, @PathVariable("id") Integer id, Principal principal) {
model.addAttribute("campId", id);
model.addAttribute("campStartDate", service.getCampStartDate(super.getCurrentUser(principal), id));
model.addAttribute("persons", service.loadPersonList(super.getCurrentUser(principal), id));
return "/confirmation/camplist";
}
@GetMapping("/confirmation/board/download/{id}")
public void getCsvOfAll(@PathVariable("id") Integer id, Principal principal, HttpServletResponse response)
throws IOException {
response.setContentType("text/csv");
String filename = String.format("camplist_%d_%s.csv", id,
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")));
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.getWriter().write(service.getDownloadCsvOfAll(super.getCurrentUser(principal), id));
response.flushBuffer();
}
}

View File

@ -0,0 +1,140 @@
package de.jottyfan.camporganizer.module.confirmation.board;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Record2;
import org.jooq.Record6;
import org.jooq.SelectConditionStep;
import org.jooq.SelectSeekStep1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
import de.jottyfan.camporganizer.module.confirmation.board.model.CampBean;
import de.jottyfan.camporganizer.module.confirmation.board.model.PersonBean;
import de.jottyfan.camporganizer.module.confirmation.confirmation.ConfirmationRepository;
/**
*
* @author jotty
*
*/
@Repository
public class ConfirmationBoardRepository {
private static final Logger LOGGER = LogManager.getLogger(ConfirmationRepository.class);
@Autowired
private DSLContext jooq;
/**
* get a list of camps that the user has access to
*
* @param username the username
* @return the list of camps; might be an empty list
*/
public List<CampBean> getCamps(String username) {
SelectSeekStep1<Record6<String, Double, Boolean, String, Integer, LocalDateTime>, LocalDateTime> sql = jooq
// @formatter:off
.select(V_CAMP.NAME, V_CAMP.YEAR, V_CAMP.IS_OVER, V_CAMP.LOCATION_NAME, V_CAMP.PK, V_CAMP.ARRIVE)
.from(T_PROFILE)
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_PROFILE.eq(T_PROFILE.PK)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.registration))
.leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_CAMPPROFILE.FK_CAMP))
.where(T_PROFILE.USERNAME.eq(username))
.orderBy(V_CAMP.ARRIVE);
// @formatter:on
LOGGER.trace(sql);
List<CampBean> list = new ArrayList<>();
Iterator<Record6<String, Double, Boolean, String, Integer, LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record6<String, Double, Boolean, String, Integer, LocalDateTime> r = i.next();
CampBean bean = new CampBean();
bean.setPkCamp(r.get(V_CAMP.PK));
bean.setName(r.get(V_CAMP.NAME));
bean.setYear(r.get(V_CAMP.YEAR));
bean.setLocationName(r.get(V_CAMP.LOCATION_NAME));
bean.setIsOver(r.get(V_CAMP.IS_OVER));
list.add(bean);
}
return list;
}
/**
* get the list of persons for this camp; restrict by the user privilege
*
* @param username the user that needs access to this data
* @param campId the ID of the camp
* @return the list of persons; an empty list at least
*/
public List<PersonBean> getPersons(String username, Integer campId) {
SelectConditionStep<Record> sql = jooq
// @formatter:off
.select(T_PERSON.fields())
.from(T_PERSON)
.innerJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.registration))
.innerJoin(T_PROFILE).on(T_PROFILE.USERNAME.eq(username)).and(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE))
.where(T_PERSON.FK_CAMP.eq(campId));
// @formatter:on
LOGGER.trace(sql);
List<PersonBean> list = new ArrayList<>();
Iterator<Record> i = sql.fetch().iterator();
while (i.hasNext()) {
Record r = i.next();
PersonBean bean = new PersonBean();
bean.setAccept(r.get(T_PERSON.ACCEPT));
bean.setBirthDate(r.get(T_PERSON.BIRTHDATE));
bean.setCamprole(r.get(T_PERSON.CAMPROLE) == null ? null : r.get(T_PERSON.CAMPROLE).getLiteral());
bean.setCity(r.get(T_PERSON.CITY));
bean.setComment(r.get(T_PERSON.COMMENT));
bean.setConsentCatalogPhoto(r.get(T_PERSON.CONSENT_CATALOG_PHOTO));
bean.setCreated(r.get(T_PERSON.CREATED));
bean.setEmail(r.get(T_PERSON.EMAIL));
bean.setForename(r.get(T_PERSON.FORENAME));
bean.setPaid(r.get(T_PERSON.PAID) == null ? null : r.get(T_PERSON.PAID).doubleValue());
bean.setPhone(r.get(T_PERSON.PHONE));
bean.setSex(r.get(T_PERSON.SEX) == null ? null : (r.get(T_PERSON.SEX).equals(EnumSex.male) ? "männlich" : "weiblich"));
bean.setStreet(r.get(T_PERSON.STREET));
bean.setSurname(r.get(T_PERSON.SURNAME));
bean.setZip(r.get(T_PERSON.ZIP));
list.add(bean);
}
return list;
}
/**
* get the camp start date of campId if username is allowed to
*
* @param username the user
* @param campId the ID of the camp
* @return the camp start time or null
*/
public LocalDateTime getCampStartDate(String username, Integer campId) {
SelectConditionStep<Record2<String, LocalDateTime>> sql = jooq
// @formatter:off
.select(V_CAMP.NAME, V_CAMP.ARRIVE)
.from(T_PROFILE)
.leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_PROFILE.eq(T_PROFILE.PK)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.registration))
.leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_CAMPPROFILE.FK_CAMP))
.where(T_PROFILE.USERNAME.eq(username))
.and(V_CAMP.PK.eq(campId));
// @formatter:on
LOGGER.trace(sql);
Iterator<Record2<String, LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
return i.next().get(V_CAMP.ARRIVE);
}
return null;
}
}

View File

@ -0,0 +1,41 @@
package de.jottyfan.camporganizer.module.confirmation.board;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.confirmation.board.model.CampBean;
import de.jottyfan.camporganizer.module.confirmation.board.model.PersonBean;
/**
*
* @author jotty
*
*/
@Service
public class ConfirmationBoardService {
@Autowired
private ConfirmationBoardRepository repository;
@Autowired
private List2CSVService csvService;
public List<CampBean> loadCampList(String username) {
return repository.getCamps(username);
}
public List<PersonBean> loadPersonList(String username, Integer campId) {
return repository.getPersons(username, campId);
}
public String getDownloadCsvOfAll(String username, Integer campId) {
List<PersonBean> list = repository.getPersons(username, campId);
return csvService.toCsv(list);
}
public Object getCampStartDate(String username, Integer campId) {
return repository.getCampStartDate(username, campId);
}
}

View File

@ -0,0 +1,73 @@
package de.jottyfan.camporganizer.module.confirmation.board;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.confirmation.board.model.PersonBean;
/**
*
* @author jotty
*
*/
@Service
public class List2CSVService {
private static final String QUOTE = "\"";
private static final String SEP = ";";
private StringBuilder append(StringBuilder buf, String s) {
return buf.append(s == null || s.isEmpty() ? SEP : String.format("%s%s%s%s", QUOTE, s, QUOTE, SEP));
}
private StringBuilder append(StringBuilder buf, Double d) {
return buf.append(d == null ? SEP : new Formatter(Locale.GERMAN).format("%.2f%s", d, SEP));
}
private StringBuilder append(StringBuilder buf, Boolean b) {
return buf.append(b == null ? SEP : String.format("%s%s%s%s", QUOTE, b ? "ja" : "nein", QUOTE, SEP));
}
private StringBuilder append(StringBuilder buf, LocalDateTime l) {
return buf.append(l == null ? SEP
: String.format("%s%s%s%s", QUOTE, l.format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")), QUOTE, SEP));
}
private StringBuilder append(StringBuilder buf, LocalDate l) {
return buf.append(l == null ? SEP
: String.format("%s%s%s%s", QUOTE, l.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")), QUOTE, SEP));
}
public String toCsv(List<PersonBean> list) {
StringBuilder buf = new StringBuilder();
String title = String.format(
"Bezahlt%sVorname%sNachname%sStrasse%sPLZ%sOrt%sTelefon%sEmail%sGeschlecht%sRolle%sGeburtsdatum%sAnmeldestatus%sAnmeldedatum%sFotoeinverständnis%sKommentar\n",
SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP);
buf.append(title);
for (PersonBean bean : list) {
append(buf, bean.getPaid());
append(buf, bean.getForename());
append(buf, bean.getSurname());
append(buf, bean.getStreet());
append(buf, bean.getZip());
append(buf, bean.getCity());
append(buf, bean.getPhone());
append(buf, bean.getEmail());
append(buf, bean.getSex());
append(buf, bean.getCamprolle());
append(buf, bean.getBirthDate());
append(buf, bean.getAccept());
append(buf, bean.getCreated());
append(buf, bean.getConsentCatalogPhoto());
append(buf, bean.getComment());
buf.append("\n");
}
return buf.toString();
}
}

View File

@ -0,0 +1,91 @@
package de.jottyfan.camporganizer.module.confirmation.board.model;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class CampBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pkCamp;
private String name;
private Double year;
private String locationName;
private Boolean isOver;
public String getTitle() {
return String.format("%s %4.0f", name, year);
}
/**
* @return the pkCamp
*/
public Integer getPkCamp() {
return pkCamp;
}
/**
* @param pkCamp the pkCamp to set
*/
public void setPkCamp(Integer pkCamp) {
this.pkCamp = pkCamp;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the year
*/
public Double getYear() {
return year;
}
/**
* @param year the year to set
*/
public void setYear(Double year) {
this.year = year;
}
/**
* @return the locationName
*/
public String getLocationName() {
return locationName;
}
/**
* @param locationName the locationName to set
*/
public void setLocationName(String locationName) {
this.locationName = locationName;
}
/**
* @return the isOver
*/
public Boolean getIsOver() {
return isOver;
}
/**
* @param isOver the isOver to set
*/
public void setIsOver(Boolean isOver) {
this.isOver = isOver;
}
}

View File

@ -0,0 +1,267 @@
package de.jottyfan.camporganizer.module.confirmation.board.model;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
/**
*
* @author jotty
*
*/
public class PersonBean implements Serializable {
private static final long serialVersionUID = 1L;
private String forename;
private String surname;
private String street;
private String zip;
private String city;
private String phone;
private String email;
private LocalDate birthDate;
private String camprole;
private Boolean accept;
private LocalDateTime created;
private String sex;
private Double paid;
private String comment;
private Boolean consentCatalogPhoto;
public String getAge(LocalDate relation) {
if (relation == null) {
return "?";
} else {
Period period = Period.between(birthDate, relation);
Integer years = period == null ? null : period.getYears();
return years == null ? "?" : years.toString();
}
}
public String getCamprolle() {
if ("student".equals(camprole)) {
return "Teilnehmer";
} else if ("teacher".equals(camprole)) {
return "Mitarbeiter";
} else if ("director".equals(camprole)) {
return "Leitung";
} else if ("feeder".equals(camprole)) {
return "Küche";
} else if ("observer".equals(camprole)) {
return "Mitarbeiterkind";
} else {
return null;
}
}
/**
* @return the forename
*/
public String getForename() {
return forename;
}
/**
* @param forename the forename to set
*/
public void setForename(String forename) {
this.forename = forename;
}
/**
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* @param surname the surname to set
*/
public void setSurname(String surname) {
this.surname = surname;
}
/**
* @return the street
*/
public String getStreet() {
return street;
}
/**
* @param street the street to set
*/
public void setStreet(String street) {
this.street = street;
}
/**
* @return the zip
*/
public String getZip() {
return zip;
}
/**
* @param zip the zip to set
*/
public void setZip(String zip) {
this.zip = zip;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the phone
*/
public String getPhone() {
return phone;
}
/**
* @param phone the phone to set
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the birthDate
*/
public LocalDate getBirthDate() {
return birthDate;
}
/**
* @param birthDate the birthDate to set
*/
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
/**
* @return the camprole
*/
public String getCamprole() {
return camprole;
}
/**
* @param camprole the camprole to set
*/
public void setCamprole(String camprole) {
this.camprole = camprole;
}
/**
* @return the accept
*/
public Boolean getAccept() {
return accept;
}
/**
* @param accept the accept to set
*/
public void setAccept(Boolean accept) {
this.accept = accept;
}
/**
* @return the created
*/
public LocalDateTime getCreated() {
return created;
}
/**
* @param created the created to set
*/
public void setCreated(LocalDateTime created) {
this.created = created;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @return the paid
*/
public Double getPaid() {
return paid;
}
/**
* @param paid the paid to set
*/
public void setPaid(Double paid) {
this.paid = paid;
}
/**
* @return the comment
*/
public String getComment() {
return comment;
}
/**
* @param comment the comment to set
*/
public void setComment(String comment) {
this.comment = comment;
}
/**
* @return the consentCatalogPhoto
*/
public Boolean getConsentCatalogPhoto() {
return consentCatalogPhoto;
}
/**
* @param consentCatalogPhoto the consentCatalogPhoto to set
*/
public void setConsentCatalogPhoto(Boolean consentCatalogPhoto) {
this.consentCatalogPhoto = consentCatalogPhoto;
}
}

View File

@ -3,15 +3,13 @@ package de.jottyfan.camporganizer.module.confirmation.confirmation;
import java.time.LocalDate;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import de.jottyfan.camporganizer.module.confirmation.confirmation.impl.CampOverviewBean;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.CampOverviewBean;
/**
*
@ -22,14 +20,11 @@ import de.jottyfan.camporganizer.module.confirmation.confirmation.impl.CampOverv
public class ConfirmationController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private IConfirmationService indexService;
private ConfirmationService indexService;
@GetMapping("/confirmation")
public String getIndex(Model model) {
List<CampOverviewBean> campoverview = indexService.getCampOverview(request);
List<CampOverviewBean> campoverview = indexService.getCampOverview(super.getCurrentUser());
CampOverviewBean campoverviewsummary = new CampOverviewBean(LocalDate.now(), "summary");
for (CampOverviewBean bean : campoverview) {
campoverviewsummary.setApproved(bean.getApproved() + campoverviewsummary.getApproved());
@ -38,9 +33,9 @@ public class ConfirmationController extends CommonController {
}
model.addAttribute("campoverview", campoverview);
model.addAttribute("campoverviewsummary", campoverviewsummary);
model.addAttribute("untouched", indexService.getUntouched(request));
model.addAttribute("approved", indexService.getApproved(request));
model.addAttribute("rejected", indexService.getRejected(request));
model.addAttribute("untouched", indexService.getUntouched(super.getCurrentUser()));
model.addAttribute("approved", indexService.getApproved(super.getCurrentUser()));
model.addAttribute("rejected", indexService.getRejected(super.getCurrentUser()));
return "confirmation/confirmation";
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation.impl;
package de.jottyfan.camporganizer.module.confirmation.confirmation;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
@ -10,6 +10,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -30,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumModule;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.BookingBean;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.CampOverviewBean;
/**
*
@ -69,7 +72,9 @@ public class ConfirmationRepository {
// @formatter:on
LOGGER.debug(sql.toString());
Map<LocalDateTime, CampOverviewBean> map = new HashMap<>();
for (Record4<Integer, Boolean, String, LocalDateTime> r : sql.fetch()) {
Iterator<Record4<Integer, Boolean, String, LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, Boolean, String, LocalDateTime> r = i.next();
Integer count = r.get(COUNT, Integer.class);
Boolean accept = r.get(T_PERSON.ACCEPT);
String campname = r.get(T_CAMP.NAME);
@ -114,7 +119,9 @@ public class ConfirmationRepository {
// @formatter:on
LOGGER.debug(sql.toString());
List<BookingBean> list = new ArrayList<>();
for (Record7<Integer, String, String, String, LocalDateTime, EnumCamprole, LocalDateTime> r : sql.fetch()) {
Iterator<Record7<Integer, String, String, String, LocalDateTime, EnumCamprole, LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record7<Integer, String, String, String, LocalDateTime, EnumCamprole, LocalDateTime> r = i.next();
String forename = r.get(T_PERSON.FORENAME);
String surname = r.get(T_PERSON.SURNAME);
String campname = r.get(T_CAMP.NAME);
@ -190,7 +197,9 @@ public class ConfirmationRepository {
// @formatter:on
LOGGER.debug(sql.toString());
List<BookingBean> list = new ArrayList<>();
for (Record8<Integer, String, String, EnumCamprole, String, Double, String, Boolean> r : sql.fetch()) {
Iterator<Record8<Integer, String, String, EnumCamprole, String, Double, String, Boolean>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record8<Integer, String, String, EnumCamprole, String, Double, String, Boolean> r = i.next();
Integer pkPerson = r.get(T_PERSON.PK);
String forename = r.get(T_PERSON.FORENAME);
String surname = r.get(T_PERSON.SURNAME);

View File

@ -0,0 +1,55 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.BookingBean;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.CampOverviewBean;
/**
*
* @author jotty
*
*/
@Service
public class ConfirmationService {
@Autowired
private ConfirmationRepository gateway;
public List<CampOverviewBean> getCampOverview(String currentUser) {
return gateway.getCampOverviewBeans(currentUser);
}
public List<BookingBean> getUntouched(String currentUser) {
return gateway.getUntouched(currentUser);
}
public List<BookingBean> getApproved(String currentUser) {
return gateway.getApproved(currentUser);
}
public List<BookingBean> getRejected(String currentUser) {
return gateway.getRejected(currentUser);
}
public String search(String needle, String linkURL, String currentUser) {
StringBuilder buf = new StringBuilder(
"<table class=\"table table-striped\"><thead><tr><th>Dabei</th><th>Name</th><th>Freizeit</th><th>Rolle</th></tr><tbody>");
for (BookingBean bean : gateway.getSearchResult(needle, currentUser)) {
String acceptHtml = "";
if (bean.getAccept() == null) {
acceptHtml = "<i class=\"fas fa-question framed framed-orange\"></i>";
} else if (bean.getAccept()) {
acceptHtml = "<i class=\"fas fa-check framed framed-green\"></i>";
} else {
acceptHtml = "<i class=\"fas fa-ban framed framed-red\"></i>";
}
buf.append(String.format("<tr><td>%s</td><td><a href=\"%s/%d\">%s</a></td><td>%s</td><td>%s</td></tr>",
acceptHtml, linkURL, bean.getPkPerson(), bean.getFullname(), bean.getCamp(), bean.getRolename()));
}
buf.append("</tbody></table>");
return buf.toString();
}
}

View File

@ -1,65 +0,0 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import de.jottyfan.camporganizer.module.confirmation.confirmation.impl.BookingBean;
import de.jottyfan.camporganizer.module.confirmation.confirmation.impl.CampOverviewBean;
/**
*
* @author jotty
*
*/
public interface IConfirmationService {
/**
* get the user of this session
*
* @param request the request
* @return the username of the current user
*/
public String getCurrentUser(HttpServletRequest request);
/**
* get a list of the camps and its booking status
*
* @param request the request
* @return the camp overview beans
*/
public List<CampOverviewBean> getCampOverview(HttpServletRequest request);
/**
* get a list of bookings that have not yet been worked on
*
* @param request the request
* @return the list of untouched bookings
*/
public List<BookingBean> getUntouched(HttpServletRequest request);
/**
* get a list of approved bookings
*
* @param request the request
* @return the list of approved bookings
*/
public List<BookingBean> getApproved(HttpServletRequest request);
/**
* get a list of rejected bookings
*
* @param request the request
* @return the list of rejected bookings
*/
public List<BookingBean> getRejected(HttpServletRequest request);
/**
* get the result of a search for needle in the database
*
* @param needle the needle; may be a name of anything
* @param linkURL the URL of the link for clicking on the found entity
* @param request the request
* @return the result in html format (for now)
*/
public String search(String needle, String linkURL, HttpServletRequest request);
}

View File

@ -1,31 +1,32 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import jakarta.servlet.http.HttpServletRequest;
/**
*
* @author jotty
*
*/
@Controller
public class SearchController {
public class SearchController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private IConfirmationService service;
private ConfirmationService service;
@GetMapping("/confirmation/search")
@ResponseBody
public String search(@PathParam(value = "needle") String needle, Model model) {
return service.search(needle, request.getRequestURI().replace("search", "person"), request);
public String search(@RequestParam("needle") String needle, Model model) {
return service.search(needle, request.getRequestURI().replace("search", "person"), super.getCurrentUser());
}
}

View File

@ -1,73 +0,0 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation.impl;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.jooq.exception.DataAccessException;
import org.keycloak.KeycloakSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.confirmation.confirmation.IConfirmationService;
/**
*
* @author jotty
*
*/
@Service
public class ConfirmationService implements IConfirmationService {
@Autowired
private ConfirmationRepository gateway;
@Override
public String getCurrentUser(HttpServletRequest request) {
KeycloakSecurityContext ksc = (KeycloakSecurityContext) request
.getAttribute(KeycloakSecurityContext.class.getName());
if (ksc == null) {
throw new DataAccessException("no keycloak user in session");
}
return ksc.getIdToken().getPreferredUsername();
}
@Override
public List<CampOverviewBean> getCampOverview(HttpServletRequest request) {
return gateway.getCampOverviewBeans(getCurrentUser(request));
}
@Override
public List<BookingBean> getUntouched(HttpServletRequest request) {
return gateway.getUntouched(getCurrentUser(request));
}
@Override
public List<BookingBean> getApproved(HttpServletRequest request) {
return gateway.getApproved(getCurrentUser(request));
}
@Override
public List<BookingBean> getRejected(HttpServletRequest request) {
return gateway.getRejected(getCurrentUser(request));
}
@Override
public String search(String needle, String linkURL, HttpServletRequest request) {
StringBuilder buf = new StringBuilder(
"<table class=\"table table-striped\"><thead><tr><th>Dabei</th><th>Name</th><th>Freizeit</th><th>Rolle</th></tr><tbody>");
for (BookingBean bean : gateway.getSearchResult(needle, getCurrentUser(request))) {
String acceptHtml = "";
if (bean.getAccept() == null) {
acceptHtml = "<i class=\"fas fa-question framed framed-orange\"></i>";
} else if (bean.getAccept()) {
acceptHtml = "<i class=\"fas fa-check framed framed-green\"></i>";
} else {
acceptHtml = "<i class=\"fas fa-ban framed framed-red\"></i>";
}
buf.append(String.format("<tr><td>%s</td><td><a href=\"%s/%d\">%s</a></td><td>%s</td><td>%s</td></tr>",
acceptHtml, linkURL, bean.getPkPerson(), bean.getFullname(), bean.getCamp(), bean.getRolename()));
}
buf.append("</tbody></table>");
return buf.toString();
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation.impl;
package de.jottyfan.camporganizer.module.confirmation.confirmation.model;
import java.io.Serializable;
import java.time.LocalDate;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation.impl;
package de.jottyfan.camporganizer.module.confirmation.confirmation.model;
import java.io.Serializable;
import java.time.LocalDate;

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.confirmation.impl;
package de.jottyfan.camporganizer.module.confirmation.confirmation.model;
import java.io.Serializable;

View File

@ -1,19 +1,17 @@
package de.jottyfan.camporganizer.module.confirmation.person;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import de.jottyfan.camporganizer.module.confirmation.confirmation.IConfirmationService;
import de.jottyfan.camporganizer.module.confirmation.person.impl.PersonBean;
import de.jottyfan.camporganizer.module.confirmation.person.impl.PersonService;
import de.jottyfan.camporganizer.module.confirmation.person.model.PersonBean;
import jakarta.validation.Valid;
/**
*
@ -23,28 +21,30 @@ import de.jottyfan.camporganizer.module.confirmation.person.impl.PersonService;
@Controller
public class PersonController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private IConfirmationService confirmationService;
@Autowired
private PersonService personService;
@GetMapping("/confirmation/person/{pk}")
public String getIndex(Model model, @PathVariable Integer pk) {
String username = confirmationService.getCurrentUser(request);
public String getIndex(Model model, @PathVariable("pk") Integer pk) {
String username = super.getCurrentUser();
model.addAttribute("currentUser", username);
model.addAttribute("person", personService.getPerson(username, pk));
model.addAttribute("camps", personService.getCamps(username));
model.addAttribute("annotations", personService.getAnnotations(pk));
model.addAttribute("campPrice", personService.getCampPrice(pk));
return "confirmation/person";
}
@PostMapping("/confirmation/person/update")
public String doUpdate(@ModelAttribute PersonBean bean, Model model) {
String username = confirmationService.getCurrentUser(request);
public String doUpdate(@Valid @ModelAttribute("person") PersonBean bean, BindingResult bindingResult, Model model) {
String username = super.getCurrentUser();
if (bindingResult.hasErrors()) {
model.addAttribute("currentUser", username);
model.addAttribute("camps", personService.getCamps(username));
model.addAttribute("annotations", personService.getAnnotations(bean.getPk()));
model.addAttribute("campPrice", personService.getCampPrice(bean.getPk()));
return "confirmation/person";
}
personService.updatePerson(bean, username);
return "redirect:/confirmation";
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.person.impl;
package de.jottyfan.camporganizer.module.confirmation.person;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMPPROFILE;
@ -12,6 +12,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
@ -19,6 +20,7 @@ import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.InsertValuesStep2;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record11;
import org.jooq.Record4;
import org.jooq.SelectConditionStep;
@ -36,7 +38,9 @@ import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TProfileRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TRssRecord;
import de.jottyfan.camporganizer.module.camplist.LambdaResultWrapper;
import de.jottyfan.camporganizer.module.camplist.model.LambdaResultWrapper;
import de.jottyfan.camporganizer.module.confirmation.person.model.CampBean;
import de.jottyfan.camporganizer.module.confirmation.person.model.PersonBean;
import de.jottyfan.camporganizer.module.mail.MailBean;
import de.jottyfan.camporganizer.module.mail.MailRepository;
@ -76,7 +80,9 @@ public class PersonRepository {
// @formatter:on
LOGGER.debug(sql.toString());
List<CampBean> list = new ArrayList<>();
for (Record r : sql.fetch()) {
Iterator<Record4<Integer, String, LocalDateTime, String>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record4<Integer, String, LocalDateTime, String> r = i.next();
CampBean bean = new CampBean();
bean.setPk(r.get(T_CAMP.PK));
bean.setName(r.get(T_CAMP.NAME));
@ -107,7 +113,9 @@ public class PersonRepository {
.and(T_PROFILE.USERNAME.eq(username));
// @formatter:on
LOGGER.debug(sql.toString());
for (Record r : sql.fetch()) {
Iterator<Record> i = sql.fetch().iterator();
while (i.hasNext()) {
Record r = i.next();
PersonBean bean = new PersonBean();
bean.setPk(pk);
bean.setAccept(r.get(T_PERSON.ACCEPT));
@ -126,6 +134,7 @@ public class PersonRepository {
bean.setSex(r.get(T_PERSON.SEX));
bean.setStreet(r.get(T_PERSON.STREET));
bean.setZip(r.get(T_PERSON.ZIP));
bean.setRequiredPrice(r.get(T_PERSON.REQUIRED_PRICE));
return bean;
}
return null;
@ -180,6 +189,7 @@ public class PersonRepository {
.set(T_PERSON.ACCEPT, bean.getAccept())
.set(T_PERSON.CAMPROLE, bean.getCamprole())
.set(T_PERSON.FK_REGISTRATOR, fkRegistrator)
.set(T_PERSON.REQUIRED_PRICE, bean.getRequiredPrice())
.where(T_PERSON.PK.eq(bean.getPk()));
// @formatter:on
LOGGER.debug(sql3.toString());
@ -293,7 +303,11 @@ public class PersonRepository {
// @formatter:on
LOGGER.debug(sql.toString());
StringBuilder buf = new StringBuilder();
for (Record r : sql.fetch()) {
Iterator<Record11<LocalDate, LocalDateTime, EnumCamprole, LocalDateTime, LocalDateTime, Integer, Integer, String, String, String, String>> i = sql
.fetch().iterator();
while (i.hasNext()) {
Record11<LocalDate, LocalDateTime, EnumCamprole, LocalDateTime, LocalDateTime, Integer, Integer, String, String, String, String> r = i
.next();
LocalDate birthdate = r.get(T_PERSON.BIRTHDATE);
LocalDateTime arrive = r.get(T_CAMP.ARRIVE);
LocalDateTime depart = r.get(T_CAMP.DEPART);
@ -309,7 +323,7 @@ public class PersonRepository {
if (bookerForename == null && bookerSurname == null) {
buf.append(String.format("angemeldet ohne Registrierung am %s\n", createdString));
} else {
buf.append(String.format("angemeldet von %s %s am %s\n", bookerForename, bookerSurname, createdString));
buf.append(String.format("angemeldet von %s %s am %s\n", bookerForename, bookerSurname, createdString));
}
if (registratorForename != null || registratorSurname != null) {
buf.append(String.format("bearbeitet von %s %s\n", registratorForename, registratorSurname));
@ -330,4 +344,22 @@ public class PersonRepository {
}
return buf.toString();
}
/**
* get the price information of the camp that the person is registered for
*
* @param pkPerson the ID of the person
* @return the camp price information
*/
public String getCampprice(Integer pkPerson) {
SelectConditionStep<Record1<String>> sql = jooq
// @formatter:off
.select(T_CAMP.PRICE)
.from(T_PERSON)
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_PERSON.FK_CAMP))
.where(T_PERSON.PK.eq(pkPerson));
// @formatter:on
LOGGER.trace(sql);
return sql.fetchOne(T_CAMP.PRICE);
}
}

View File

@ -1,10 +1,13 @@
package de.jottyfan.camporganizer.module.confirmation.person.impl;
package de.jottyfan.camporganizer.module.confirmation.person;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.confirmation.person.model.CampBean;
import de.jottyfan.camporganizer.module.confirmation.person.model.PersonBean;
/**
*
* @author jotty
@ -30,4 +33,14 @@ public class PersonService {
public String getAnnotations(Integer pk) {
return gateway.getAnnotations(pk);
}
/**
* get the price of the camp
*
* @param pk the ID of the person, not the camp
* @return the camp price
*/
public String getCampPrice(Integer pk) {
return gateway.getCampprice(pk);
}
}

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.confirmation.person.impl;
package de.jottyfan.camporganizer.module.confirmation.person.model;
import java.io.Serializable;
import java.time.LocalDateTime;

View File

@ -1,6 +1,7 @@
package de.jottyfan.camporganizer.module.confirmation.person.impl;
package de.jottyfan.camporganizer.module.confirmation.person.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -8,6 +9,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
import jakarta.validation.constraints.DecimalMin;
/**
*
@ -15,7 +17,7 @@ import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
*
*/
public class PersonBean implements Serializable {
private static final long serialVersionUID = 2L;
private static final long serialVersionUID = 3L;
private Integer pk;
private String forename;
@ -35,6 +37,8 @@ public class PersonBean implements Serializable {
private EnumSex sex;
private Integer fkRegistrator;
private String comment;
@DecimalMin(value = "0")
private BigDecimal requiredPrice;
/**
* @return the forename
@ -273,4 +277,18 @@ public class PersonBean implements Serializable {
public void setPk(Integer pk) {
this.pk = pk;
}
/**
* @return the requiredPrice
*/
public BigDecimal getRequiredPrice() {
return requiredPrice;
}
/**
* @param requiredPrice the requiredPrice to set
*/
public void setRequiredPrice(BigDecimal requiredPrice) {
this.requiredPrice = requiredPrice;
}
}

View File

@ -21,8 +21,8 @@ import de.jottyfan.camporganizer.db.jooq.enums.EnumFiletype;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersondocumentRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TRssRecord;
import de.jottyfan.camporganizer.module.camplist.BookingBean;
import de.jottyfan.camporganizer.module.camplist.LambdaResultWrapper;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import de.jottyfan.camporganizer.module.camplist.model.LambdaResultWrapper;
/**
*
@ -57,7 +57,7 @@ public class DashboardRepository {
.set(T_PERSON.COMMENT, bean.getComment())
.where(T_PERSON.PK.eq(bean.getPk()));
// @formatter:on
LOGGER.debug(sql.toString());
LOGGER.trace(sql.toString());
return sql.execute();
}

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import javax.servlet.http.Part;
import jakarta.servlet.http.Part;
import org.apache.commons.io.IOUtils;

View File

@ -2,7 +2,7 @@ package de.jottyfan.camporganizer.module.document;
import java.util.Base64;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
@ -10,9 +10,8 @@ import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import de.jottyfan.camporganizer.module.camplist.CommonController;
@ -28,8 +27,8 @@ public class DocumentController extends CommonController {
@Autowired
private DocumentService service;
@RequestMapping(path = "/document/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource> getDocument(@PathVariable Integer id, HttpServletResponse response) {
@GetMapping("/document/{id}")
public ResponseEntity<Resource> getDocument(@PathVariable("id") Integer id, HttpServletResponse response) {
DownloadBean bean = service.getDocument(id);
if (bean != null) {
byte[] decoded = Base64.getDecoder().decode(bean.getContent());

View File

@ -2,7 +2,7 @@ package de.jottyfan.camporganizer.module.ical;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -19,7 +19,7 @@ import de.jottyfan.camporganizer.module.camplist.CommonController;
public class ICalController extends CommonController {
@Autowired
private IICalService service;
private ICalService service;
/**
* generate the ical response stream

View File

@ -1,4 +1,4 @@
package de.jottyfan.camporganizer.module.ical.impl;
package de.jottyfan.camporganizer.module.ical;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION;
@ -6,6 +6,7 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import org.apache.logging.log4j.LogManager;
@ -56,7 +57,9 @@ public class ICalRepository {
LOGGER.debug(sql.toString());
ICalendar ical = new ICalendar();
ical.getTimezoneInfo().setDefaultTimezone(TimezoneAssignment.download(TimeZone.getTimeZone("Europe/Berlin"), false));
for (Record5<String, LocalDateTime, LocalDateTime, String, String> r : sql.fetch()) {
Iterator<Record5<String, LocalDateTime, LocalDateTime, String, String>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record5<String, LocalDateTime, LocalDateTime, String, String> r = i.next();
VEvent event = new VEvent();
Summary summary = event.setSummary(r.get(T_CAMP.NAME));
summary.setLanguage("de");

View File

@ -1,15 +1,13 @@
package de.jottyfan.camporganizer.module.ical.impl;
package de.jottyfan.camporganizer.module.ical;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import biweekly.Biweekly;
import biweekly.ICalendar;
import de.jottyfan.camporganizer.module.ical.IICalService;
import jakarta.servlet.http.HttpServletResponse;
/**
*
@ -17,12 +15,11 @@ import de.jottyfan.camporganizer.module.ical.IICalService;
*
*/
@Service
public class ICalService implements IICalService {
public class ICalService {
@Autowired
private ICalRepository gateway;
@Override
public Boolean generate(HttpServletResponse response) throws IOException {
ICalendar ical = gateway.getIcal();
String content = Biweekly.write(ical).go();
@ -37,5 +34,4 @@ public class ICalService implements IICalService {
return true;
}
}

View File

@ -1,23 +0,0 @@
package de.jottyfan.camporganizer.module.ical;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author jotty
*
*/
public interface IICalService {
/**
* generate the ical
*
* @param response the response for the output stream
*
* @return true if successful, false otherwise
* @throws IOException on io errors
*/
public Boolean generate(HttpServletResponse response) throws IOException;
}

View File

@ -5,8 +5,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
/**
*

View File

@ -3,8 +3,8 @@ package de.jottyfan.camporganizer.module.mail;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -2,8 +2,8 @@ package de.jottyfan.camporganizer.module.migration;
import java.io.Serializable;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.util.password.StrongPasswordEncryptor;

View File

@ -1,6 +1,6 @@
package de.jottyfan.camporganizer.module.migration;
import javax.validation.Valid;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -1,6 +1,6 @@
package de.jottyfan.camporganizer.module.migration;
import javax.validation.Valid;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -3,8 +3,8 @@ package de.jottyfan.camporganizer.module.registration;
import java.util.Arrays;
import java.util.Collections;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -27,7 +27,7 @@ import org.springframework.stereotype.Repository;
public class KeycloakRepository {
private final static Logger LOGGER = LogManager.getLogger(KeycloakRepository.class);
@Value("${keycloak.resource}")
@Value("${keycloak.client-id}")
private String keycloakClientId;
@Value("${keycloak.auth-server-url}")
@ -53,6 +53,15 @@ public class KeycloakRepository {
return String.format("%s/realms/%s/account/", url, keycloakRealm);
}
/**
* get the url of the user password client
*
* @return the url of the user password client
*/
public String getPasswordClientUrl() {
return String.format("%s%s", getUserClientUrl(), "#/security/signingin");
}
/**
* register the login in keycloak
*

View File

@ -1,11 +1,12 @@
package de.jottyfan.camporganizer.module.registration;
import javax.validation.Valid;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
@ -13,6 +14,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.camporganizer.db.EnumConverter;
import de.jottyfan.camporganizer.module.camplist.CommonController;
import de.jottyfan.camporganizer.module.registration.model.CampBean;
import de.jottyfan.camporganizer.module.registration.model.RegistrationBean;
import jakarta.validation.Valid;
/**
*
@ -21,6 +25,7 @@ import de.jottyfan.camporganizer.module.camplist.CommonController;
*/
@Controller
public class RegistrationController extends CommonController {
private static final Logger LOGGER = LogManager.getLogger(RegistrationController.class);
@Autowired
private RegistrationService service;
@ -36,40 +41,72 @@ public class RegistrationController extends CommonController {
model.addAttribute("bean", bean);
model.addAttribute("sexes", EnumConverter.getSexes());
model.addAttribute("roles", EnumConverter.getRoles());
model.addAttribute("wellknown", service.getWellKnownRegistrations(getCurrentUser()));
return "/registration/registration";
} else {
return "/registration/isover";
}
}
/**
* userlogin is protected and leads the request to the keycloak login mask if not yet logged in
*
* @param fkCamp the ID of the camp
* @param model the model
* @return hen registration page
*/
@GetMapping("/userlogin/registration/{fkCamp}")
public String loginIndex(@PathVariable(name = "fkCamp", required = true) Integer fkCamp, Model model) {
return index(fkCamp, model);
}
@PostMapping("/registration/register")
public String register(@Valid @ModelAttribute("bean") RegistrationBean bean, final BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
for (ObjectError error : bindingResult.getAllErrors()) {
LOGGER.error("found {}", error);
}
CampBean campBean = service.getCamp(bean.getFkCamp());
model.addAttribute("camp", campBean);
model.addAttribute("sexes", EnumConverter.getSexes());
model.addAttribute("roles", EnumConverter.getRoles());
String currentUser = getCurrentUser();
if (currentUser != null) {
model.addAttribute("wellknown", service.getWellKnownRegistrations(currentUser));
}
return "/registration/registration";
}
Boolean result = service.register(bean, getCurrentUser());
return result ? "/registration/success" : "/error";
Integer result = service.register(bean, getCurrentUser());
if (result < 1) {
LOGGER.error("added less than 1 row on registering {}", bean);
CampBean campBean = service.getCamp(bean.getFkCamp());
model.addAttribute("camp", campBean);
model.addAttribute("sexes", EnumConverter.getSexes());
model.addAttribute("roles", EnumConverter.getRoles());
String currentUser = getCurrentUser();
if (currentUser != null) {
model.addAttribute("wellknown", service.getWellKnownRegistrations(currentUser));
}
return "/registration/registration";
}
return "/registration/success";
}
@GetMapping("/registration/cancel/{id}")
public String cancellation(@PathVariable Integer id, final Model model) {
public String cancellation(@PathVariable("id") Integer id, final Model model) {
model.addAttribute("bean", service.getBooking(id));
return "/registration/cancellation";
}
@GetMapping("/registration/remove/{id}")
public String remove(@PathVariable Integer id, final Model model) {
public String remove(@PathVariable("id") Integer id, final Model model) {
service.removeBooking(id);
return "redirect:/dashboard";
}
@GetMapping("/registration/toggleconsent/{id}")
public String toggleConsent(@PathVariable Integer id, final Model model) {
public String toggleConsent(@PathVariable("id") Integer id, final Model model) {
service.toggleConsent(id);
return "redirect:/dashboard";
}

View File

@ -6,11 +6,15 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSONDOCUMENT;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILEROLE;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_RSS;
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
@ -19,14 +23,14 @@ import org.jasypt.util.password.StrongPasswordEncryptor;
import org.jooq.DSLContext;
import org.jooq.DeleteConditionStep;
import org.jooq.InsertResultStep;
import org.jooq.InsertValuesStep12;
import org.jooq.InsertValuesStep13;
import org.jooq.InsertReturningStep;
import org.jooq.InsertValuesStep2;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record2;
import org.jooq.Record5;
import org.jooq.Record7;
import org.jooq.Record9;
import org.jooq.SelectConditionStep;
import org.jooq.UpdateConditionStep;
import org.jooq.exception.DataAccessException;
@ -38,13 +42,16 @@ import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersondocumentRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TProfileRecord;
import de.jottyfan.camporganizer.db.jooq.tables.records.TRssRecord;
import de.jottyfan.camporganizer.module.camplist.BookingBean;
import de.jottyfan.camporganizer.module.camplist.LambdaResultWrapper;
import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import de.jottyfan.camporganizer.module.camplist.model.LambdaResultWrapper;
import de.jottyfan.camporganizer.module.registration.model.CampBean;
import de.jottyfan.camporganizer.module.registration.model.ProfileBean;
import de.jottyfan.camporganizer.module.registration.model.RegistrationBean;
/**
*
@ -66,15 +73,17 @@ public class RegistrationRepository {
* @return the camp bean or null
*/
public CampBean getCamp(Integer pk) {
SelectConditionStep<TCampRecord> sql = jooq.selectFrom(T_CAMP).where(T_CAMP.PK.eq(pk));
LOGGER.debug(sql.toString());
TCampRecord r = sql.fetchOne();
SelectConditionStep<VCampRecord> sql = jooq.selectFrom(V_CAMP).where(V_CAMP.PK.eq(pk));
LOGGER.trace(sql.toString());
VCampRecord r = sql.fetchOne();
if (r != null) {
CampBean bean = new CampBean();
bean.setPk(r.getPk());
bean.setName(r.getName());
LocalDateTime arrive = r.getArrive();
bean.setYear(arrive == null ? null : arrive.getYear());
bean.setBookingHasStarted(r.getBookingHasStarted());
bean.setStartBooking(r.getStartBooking());
return bean;
} else {
return null;
@ -91,9 +100,9 @@ public class RegistrationRepository {
SelectConditionStep<TProfileRecord> sql = jooq
// @formatter:off
.selectFrom(T_PROFILE)
.where(T_PROFILE.USERNAME.eq(login));
.where(DSL.lower(T_PROFILE.USERNAME).eq(login));
// @formatter:on
LOGGER.debug(sql);
LOGGER.trace(sql);
return sql.fetch().size() < 1;
}
@ -102,15 +111,16 @@ public class RegistrationRepository {
* registerInKeycloak is true
*
* @param bean the bean
* @return true or false
* @return number of data base rows; should be > 0
*/
public Boolean register(RegistrationBean bean) {
public Integer register(RegistrationBean bean) {
LambdaResultWrapper lrw = new LambdaResultWrapper();
jooq.transaction(t -> {
if (bean.getLogin() != null && !bean.getLogin().isEmpty()) {
Boolean loginNotYetInUse = isLoginNotYetInUse(bean.getLogin());
Boolean loginNotYetInUse = isLoginNotYetInUse(bean.getLogin().toLowerCase());
if (bean.getRegisterInKeycloak() && !loginNotYetInUse) {
throw new DataAccessException("login already in use: " + bean.getLogin());
LOGGER.error("login already in use: {}", bean.getLogin().toLowerCase());
throw new DataAccessException("login already in use: " + bean.getLogin().toLowerCase());
}
Integer fkProfile = null;
if (loginNotYetInUse) {
@ -124,10 +134,10 @@ public class RegistrationRepository {
T_PROFILE.PASSWORD,
T_PROFILE.DUEDATE,
T_PROFILE.UUID)
.values(bean.getForename(), bean.getSurname(), bean.getLogin(), oldPassword, LocalDateTime.now().plus(356, ChronoUnit.DAYS), UUID.nameUUIDFromBytes(bean.getLogin().getBytes()).toString())
.values(bean.getForename(), bean.getSurname(), bean.getLogin().toLowerCase(), oldPassword, LocalDateTime.now().plus(356, ChronoUnit.DAYS), UUID.nameUUIDFromBytes(bean.getLogin().getBytes()).toString())
.returning(T_PROFILE.PK);
// @formatter:on
LOGGER.debug(sql1.toString());
LOGGER.trace(sql1.toString());
fkProfile = sql1.fetchOne().getPk();
InsertValuesStep2<TRssRecord, String, String> sql2 = jooq
@ -144,15 +154,14 @@ public class RegistrationRepository {
// @formatter:off
.select(T_PROFILE.PK)
.from(T_PROFILE)
.where(T_PROFILE.USERNAME.eq(bean.getLogin()));
.where(DSL.lower(T_PROFILE.USERNAME).eq(bean.getLogin().toLowerCase()));
// @formatter:on
LOGGER.debug(sql1.toString());
LOGGER.trace(sql1.toString());
fkProfile = sql1.fetchOne().get(T_PROFILE.PK);
}
// register the person for camp participation
InsertValuesStep13<TPersonRecord, String, String, EnumSex, LocalDate, String, String, String, String, String, EnumCamprole, Integer, String, Integer> sql2 = DSL
.using(t)
// @formatter:off
InsertReturningStep<TPersonRecord> sql2 = DSL.using(t)
// @formatter:off
.insertInto(T_PERSON,
T_PERSON.FORENAME,
T_PERSON.SURNAME,
@ -169,15 +178,16 @@ public class RegistrationRepository {
T_PERSON.FK_PROFILE)
.values(bean.getForename(), bean.getSurname(), bean.getSex(),
bean.getBirthDate(), bean.getStreet(), bean.getZip(), bean.getCity(), bean.getEmail(),
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment(), fkProfile);
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment(), fkProfile)
.onConflict(T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.BIRTHDATE, T_PERSON.FK_CAMP)
.doNothing();
// @formatter:on
LOGGER.debug(sql2.toString());
LOGGER.trace(sql2.toString());
lrw.add(sql2.execute());
// register the login for the portal
} else {
InsertValuesStep12<TPersonRecord, String, String, EnumSex, LocalDate, String, String, String, String, String, EnumCamprole, Integer, String> sql = DSL
.using(t)
// @formatter:off
InsertReturningStep<TPersonRecord> sql = DSL.using(t)
// @formatter:off
.insertInto(T_PERSON,
T_PERSON.FORENAME,
T_PERSON.SURNAME,
@ -193,13 +203,15 @@ public class RegistrationRepository {
T_PERSON.COMMENT)
.values(bean.getForename(), bean.getSurname(), bean.getSex(),
bean.getBirthDate(), bean.getStreet(), bean.getZip(), bean.getCity(), bean.getEmail(),
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment());
bean.getPhone(), bean.getCampRole(), bean.getFkCamp(), bean.getComment())
.onConflict(T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.BIRTHDATE, T_PERSON.FK_CAMP)
.doNothing();
// @formatter:on
LOGGER.debug(sql.toString());
LOGGER.trace(sql.toString());
lrw.add(sql.execute());
}
});
return lrw.getCounter() > 0;
return lrw.getCounter();
}
/**
@ -222,7 +234,7 @@ public class RegistrationRepository {
.leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_PERSON.FK_CAMP))
.where(T_PERSON.PK.eq(id));
// @formatter:on
LOGGER.debug(sql.toString());
LOGGER.trace(sql.toString());
Record7<Integer, String, String, EnumCamprole, String, LocalDateTime, LocalDateTime> r = sql.fetchOne();
if (r != null) {
BookingBean bean = new BookingBean();
@ -255,7 +267,7 @@ public class RegistrationRepository {
.leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_PERSON.FK_PROFILE))
.where(T_PERSON.PK.eq(id));
// @formatter:on
LOGGER.debug(sql0.toString());
LOGGER.trace(sql0.toString());
Record5<String, String, String, String, LocalDateTime> r = sql0.fetchOne();
if (r == null) {
throw new DataAccessException("no such entry in t_person with id = " + id);
@ -276,11 +288,11 @@ public class RegistrationRepository {
DeleteConditionStep<TPersondocumentRecord> sql1 = DSL.using(t).deleteFrom(T_PERSONDOCUMENT)
.where(T_PERSONDOCUMENT.FK_PERSON.eq(id));
LOGGER.debug(sql1.toString());
LOGGER.trace(sql1.toString());
sql1.execute();
DeleteConditionStep<TPersonRecord> sql2 = DSL.using(t).deleteFrom(T_PERSON).where(T_PERSON.PK.eq(id));
LOGGER.debug(sql2.toString());
LOGGER.trace(sql2.toString());
lrw.add(sql2.execute());
InsertValuesStep2<TRssRecord, String, String> sql3 = DSL.using(t)
@ -290,7 +302,7 @@ public class RegistrationRepository {
T_RSS.RECIPIENT)
.values(rssMessage.toString(), "registrator");
// @formatter:on
LOGGER.debug("{}", sql3.toString());
LOGGER.trace("{}", sql3.toString());
sql3.execute();
});
return lrw.getCounter();
@ -309,9 +321,10 @@ public class RegistrationRepository {
.from(T_CAMP)
.where(T_CAMP.PK.eq(fkCamp));
// @formatter:on
LOGGER.debug(sql.toString());
for (Record1<LocalDateTime> r : sql.fetch()) {
LocalDateTime depart = r.get(T_CAMP.DEPART);
LOGGER.trace(sql.toString());
Iterator<Record1<LocalDateTime>> i = sql.fetch().iterator();
while (i.hasNext()) {
LocalDateTime depart = i.next().get(T_CAMP.DEPART);
LocalDateTime now = LocalDateTime.now();
return now.isBefore(depart);
}
@ -332,7 +345,7 @@ public class RegistrationRepository {
.set(T_PERSON.FK_PROFILE, (Integer) null)
.where(T_PERSON.FK_PROFILE.eq(bean.getPk()));
// @formatter:off
LOGGER.debug("{}", sql.toString());
LOGGER.trace("{}", sql.toString());
sql.execute();
DeleteConditionStep<?> sql1 = DSL.using(t)
@ -345,7 +358,7 @@ public class RegistrationRepository {
.where(T_PROFILE.USERNAME.eq(bean.getUsername())
)));
// @formatter:on
LOGGER.debug("{}", sql1.toString());
LOGGER.trace("{}", sql1.toString());
sql1.execute();
DeleteConditionStep<?> sql2 = DSL.using(t)
@ -353,7 +366,7 @@ public class RegistrationRepository {
.deleteFrom(T_PROFILE)
.where(T_PROFILE.USERNAME.eq(bean.getUsername()));
// @formatter:on
LOGGER.debug("{}", sql2.toString());
LOGGER.trace("{}", sql2.toString());
sql2.execute();
InsertValuesStep2<TRssRecord, String, String> sql3 = DSL.using(t)
@ -363,7 +376,7 @@ public class RegistrationRepository {
T_RSS.RECIPIENT)
.values(new StringBuilder(bean.getFullname()).append(" hat sich vom Portal CampOrganizer2 abgemeldet.").toString(), "admin");
// @formatter:on
LOGGER.debug("{}", sql3.toString());
LOGGER.trace("{}", sql3.toString());
sql3.execute();
});
}
@ -382,7 +395,7 @@ public class RegistrationRepository {
.set(T_PERSON.CONSENT_CATALOG_PHOTO, consent)
.where(T_PERSON.PK.eq(id));
// @formatter:on
LOGGER.debug("{}", sql.toString());
LOGGER.trace("{}", sql.toString());
sql.execute();
}
@ -404,7 +417,7 @@ public class RegistrationRepository {
.from(T_CAMP)
.where(T_CAMP.PK.eq(fkCamp));
// @formatter:on
LOGGER.debug(sql.toString());
LOGGER.trace(sql.toString());
Record r = sql.fetchOne();
Integer minTeacherAge = r.get(T_CAMP.MAX_AGE) + 2; // by default, we need 2 years older teachers at least
DayToSecond currentTeacherAge = r.get("teacherAge", DayToSecond.class);
@ -415,4 +428,70 @@ public class RegistrationRepository {
return true;
}
}
/**
* get the person information of already registered people
*
* @param currentUser the user that registered people
* @return the list of found registrations, may be an empty list; if currentUser is null, return null.
*/
public List<RegistrationBean> getRegistrations(String currentUser) {
SelectConditionStep<Record9<String, String, String, String, String, String, String, EnumSex, LocalDate>> sql = jooq
// @formatter:off
.selectDistinct(T_PERSON.FORENAME,
T_PERSON.SURNAME,
T_PERSON.STREET,
T_PERSON.ZIP,
T_PERSON.CITY,
T_PERSON.PHONE,
T_PERSON.EMAIL,
T_PERSON.SEX,
T_PERSON.BIRTHDATE)
.from(T_PERSON)
.innerJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_PERSON.FK_PROFILE))
.where(DSL.lower(T_PROFILE.USERNAME).eq(currentUser == null ? null : currentUser.toLowerCase()));
// @formatter:on
LOGGER.trace(sql);
List<RegistrationBean> list = new ArrayList<>();
Iterator<Record9<String, String, String, String, String, String, String, EnumSex, LocalDate>> i = sql.fetch().iterator();
while (i.hasNext()) {
Record9<String, String, String, String, String, String, String, EnumSex, LocalDate> r = i.next();
RegistrationBean bean = new RegistrationBean();
bean.setForename(r.get(T_PERSON.FORENAME));
bean.setSurname(r.get(T_PERSON.SURNAME));
bean.setStreet(r.get(T_PERSON.STREET));
bean.setZip(r.get(T_PERSON.ZIP));
bean.setCity(r.get(T_PERSON.CITY));
bean.setPhone(r.get(T_PERSON.PHONE));
bean.setEmail(r.get(T_PERSON.EMAIL));
bean.setSex(r.get(T_PERSON.SEX));
bean.setBirthDate(r.get(T_PERSON.BIRTHDATE));
list.add(bean);
}
return list;
}
/**
* returns true if and only if this combination of registration has already been done
*
* @param forename the forename
* @param surname the surname
* @param birthDate the birth date
* @param campId the ID of the camp
* @return true or false
*/
public Boolean checkAlreadyRegistered(String forename, String surname, LocalDate birthDate, Integer campId) {
SelectConditionStep<Record1<Integer>> sql = jooq
// @formatter:off
.select(T_PERSON.PK)
.from(T_PERSON)
.where(T_PERSON.FORENAME.eq(forename))
.and(T_PERSON.SURNAME.eq(surname))
.and(T_PERSON.BIRTHDATE.eq(birthDate))
.and(T_PERSON.FK_CAMP.eq(campId));
// @formatter:on
LOGGER.trace(sql);
Iterator<Integer> i = sql.fetch(T_PERSON.PK).iterator();
return i.hasNext();
}
}

View File

@ -1,9 +1,15 @@
package de.jottyfan.camporganizer.module.registration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.camporganizer.module.camplist.BookingBean;
import de.jottyfan.camporganizer.module.camplist.model.BookingBean;
import de.jottyfan.camporganizer.module.registration.model.AlreadyKnownPersonBean;
import de.jottyfan.camporganizer.module.registration.model.CampBean;
import de.jottyfan.camporganizer.module.registration.model.RegistrationBean;
/**
*
@ -14,7 +20,7 @@ import de.jottyfan.camporganizer.module.camplist.BookingBean;
public class RegistrationService {
@Autowired
private RegistrationRepository gateway;
private RegistrationRepository repository;
@Autowired
private KeycloakRepository keycloak;
@ -26,7 +32,7 @@ public class RegistrationService {
* @return true or false
*/
public Boolean campIsNotYetOver(Integer fkCamp) {
return gateway.campIsNotYetOver(fkCamp);
return repository.campIsNotYetOver(fkCamp);
}
/**
@ -36,23 +42,24 @@ public class RegistrationService {
* @return the camp bean or null
*/
public CampBean getCamp(Integer fkCamp) {
return gateway.getCamp(fkCamp);
return repository.getCamp(fkCamp);
}
/**
* register the person for a camp; if registerInKeycloak, do so also
*
* @param bean the bean
* @return true if successful, false otherwise
* @return number of database rows; should be > 0
*/
public Boolean register(RegistrationBean bean, String currentUser) {
public Integer register(RegistrationBean bean, String currentUser) {
if (currentUser != null) {
bean.setRegisterInKeycloak(false); // already registered
bean.setLogin(currentUser);
}
Boolean result = gateway.register(bean);
if (result && bean.getRegisterInKeycloak()) {
keycloak.register(bean.getForename(), bean.getSurname(), bean.getLogin(), bean.getPassword(), bean.getEmail());
Integer result = repository.register(bean);
if (result > 0 && bean.getRegisterInKeycloak()) {
keycloak.register(bean.getKcForename(), bean.getKcSurname(), bean.getLogin(), bean.getPassword(),
bean.getKcEmail());
}
return result;
}
@ -64,7 +71,7 @@ public class RegistrationService {
* @return the booking bean or null
*/
public BookingBean getBooking(Integer id) {
return gateway.getBooking(id);
return repository.getBooking(id);
}
/**
@ -73,10 +80,37 @@ public class RegistrationService {
* @param id the id of the booking (t_person.pk)
*/
public Boolean removeBooking(Integer id) {
return gateway.removeBooking(id) > 0;
return repository.removeBooking(id) > 0;
}
public void toggleConsent(Integer id) {
gateway.toggleConsent(id);
repository.toggleConsent(id);
}
/**
* get already registered entries from the database
*
* @param currentUser the name of the current user; may be null
* @return the list or null if current user is null
*/
public List<AlreadyKnownPersonBean> getWellKnownRegistrations(String currentUser) {
if (currentUser == null) {
return null;
} else {
List<RegistrationBean> r = repository.getRegistrations(currentUser);
if (r == null) {
return null;
} else {
List<AlreadyKnownPersonBean> list = new ArrayList<>();
for (RegistrationBean b : r) {
AlreadyKnownPersonBean bean = new AlreadyKnownPersonBean();
bean.setSource(b);
bean.setOption(String.format("%s %s, %s, %s %s, %s, %s", b.getForename(), b.getSurname(), b.getStreet(),
b.getZip(), b.getCity(), b.getEmail(), b.getPhone()));
list.add(bean);
}
return list;
}
}
}
}

View File

@ -0,0 +1,51 @@
package de.jottyfan.camporganizer.module.registration.model;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import com.nimbusds.jose.shaded.gson.Gson;
/**
*
* @author jotty
*
*/
public class AlreadyKnownPersonBean implements Serializable {
private static final long serialVersionUID = 1L;
private String option;
private RegistrationBean source;
public String getJson() {
Map<String, String> map = new HashMap<>();
map.put("forename", source.getForename());
map.put("surname", source.getSurname());
map.put("street", source.getStreet());
map.put("zip", source.getZip());
map.put("city", source.getCity());
map.put("phone", source.getPhone());
map.put("email", source.getEmail());
map.put("sex", source.getSex() == null ? null : source.getSex().getLiteral());
map.put("birthDate",
source.getBirthDate() == null ? null : source.getBirthDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
return new Gson().toJson(map);
}
public String getOption() {
return option;
}
public void setOption(String json) {
this.option = json;
}
public RegistrationBean getSource() {
return source;
}
public void setSource(RegistrationBean source) {
this.source = source;
}
}

Some files were not shown because too many files have changed in this diff Show More