UI FIX: null=>empty for: Schedule.propertyName, Schedule.propertyType

This commit is contained in:
Patrick Haßel 2021-10-29 12:07:09 +02:00
parent e8f3380793
commit 8d8b5513a2
3 changed files with 33 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import {validateBooleanNotNull, validateListOrEmpty, validateNumberNotNull, validateStringNotEmptyNotNull} from "../validators"; import {validateBooleanNotNull, validateListOrEmpty, validateNumberNotNull, validateStringNotEmptyNotNull, validateStringNullToEmpty} from "../validators";
import {ScheduleEntry} from "./entry/ScheduleEntry"; import {ScheduleEntry} from "./entry/ScheduleEntry";
export class Schedule { export class Schedule {
@ -19,8 +19,8 @@ export class Schedule {
validateNumberNotNull(json['id']), validateNumberNotNull(json['id']),
validateBooleanNotNull(json['enabled']), validateBooleanNotNull(json['enabled']),
validateStringNotEmptyNotNull(json['name']), validateStringNotEmptyNotNull(json['name']),
validateStringNotEmptyNotNull(json['propertyName']), validateStringNullToEmpty(json['propertyName']),
validateStringNotEmptyNotNull(json['propertyType']), validateStringNullToEmpty(json['propertyType']),
validateListOrEmpty(json['entries'], ScheduleEntry.fromJson, ScheduleEntry.compare), validateListOrEmpty(json['entries'], ScheduleEntry.fromJson, ScheduleEntry.compare),
); );
} }

View File

@ -27,6 +27,20 @@ export function validateNumberAllowNull(value: any): number | null {
return validateNumberNotNull(value); return validateNumberNotNull(value);
} }
export function validateStringEmptyToNull(value: any): string | null {
if (value === null || value === undefined || value === '') {
return null;
}
return validateStringNotEmptyNotNull(value);
}
export function validateStringNullToEmpty(value: any): string {
if (value === null || value === undefined || value === '') {
return '';
}
return validateStringNotEmptyNotNull(value);
}
export function validateStringNotEmptyNotNull(value: any): string { export function validateStringNotEmptyNotNull(value: any): string {
if (!(typeof value === 'string')) { if (!(typeof value === 'string')) {
throw new Error("Not a string: " + value); throw new Error("Not a string: " + value);
@ -37,13 +51,6 @@ export function validateStringNotEmptyNotNull(value: any): string {
return value; return value;
} }
export function validateStringNotEmpty_AllowNull(value: any): string | null {
if (value === null || value === undefined || value === '') {
return null;
}
return validateStringNotEmptyNotNull(value);
}
function validateDateNotNull(value: any): Date { function validateDateNotNull(value: any): Date {
const number: number = Date.parse(value); const number: number = Date.parse(value);
if (isNaN(number)) { if (isNaN(number)) {

View File

@ -6,10 +6,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ -29,11 +32,24 @@ public class WebConfig extends WebSecurityConfigurerAdapter implements WebMvcCon
http.authorizeRequests().anyRequest().permitAll(); http.authorizeRequests().anyRequest().permitAll();
} }
@Override
public void configure(WebSecurity web) {
web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
}
@Bean @Bean
public PasswordEncoder passwordEncoder() { public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
final StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowUrlEncodedSlash(true);
firewall.setAllowSemicolon(true);
return firewall;
}
@Override @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowCredentials(true).allowedOrigins("http://localhost:4200").allowedMethods("*"); registry.addMapping("/**").allowCredentials(true).allowedOrigins("http://localhost:4200").allowedMethods("*");