Skip to content

Commit

Permalink
fixed genspec
Browse files Browse the repository at this point in the history
  • Loading branch information
oplekal committed Dec 31, 2024
1 parent 19560dc commit 0e31038
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 170 deletions.
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ sync_localisations:
# Generoi openapi-kuvauksen
gen_openapi:
@cd eperusteet/eperusteet-service/ \
&& mvn verify -DskipTests -Pspringdoc -Dspring-boot.run.profiles=default,dev \
&& mvn verify -Pspringdoc \
&& cp target/openapi/eperusteet.spec.json ../../generated

# Generoi julkinen openapikuvaus
gen_openapi_ext:
@cd eperusteet/eperusteet-service/ \
&& mvn clean compile -P generate-openapi-ext \
&& mvn verify -Pspringdoc-ext \
&& cp target/openapi/eperusteet-ext.spec.json ../../generated

# Generoi lista puutteellisista osaamisaloista
Expand Down
280 changes: 173 additions & 107 deletions eperusteet/eperusteet-service/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package fi.vm.sade.eperusteet.config;

import fi.vm.sade.eperusteet.hibernate.HibernateInterceptor;
import fi.vm.sade.eperusteet.repository.version.JpaWithVersioningRepositoryFactoryBean;
import fi.vm.sade.eperusteet.service.security.PermissionEvaluator;
import jakarta.persistence.EntityManager;
import jakarta.validation.ValidatorFactory;
import org.flywaydb.core.Flyway;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.id.enhanced.SingleNamingStrategy;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
Expand All @@ -25,11 +24,9 @@
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;

import javax.sql.DataSource;
Expand Down Expand Up @@ -57,9 +54,6 @@ public class DefaultConfigs {
@Autowired
private DataSource dataSource;

// @Autowired
// private ValidatorFactory validatorFactory;

@Bean
public TaskExecutor defaultExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand All @@ -83,11 +77,6 @@ public DefaultMethodSecurityExpressionHandler expressionHandler() {
return expressionHandler;
}

// @Bean
// public LocalValidatorFactoryBean validator() {
// return new LocalValidatorFactoryBean();
// }

@Bean(initMethod = "migrate")
public Flyway flyway() {
return Flyway.configure()
Expand All @@ -97,19 +86,6 @@ public Flyway flyway() {
.load();
}

// @Bean
// public HibernateInterceptor hibernateInterceptor() {
// return new HibernateInterceptor();
// }

// @Bean
// public ResourceBundleMessageSource messageSource() {
// ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
// messageSource.setDefaultEncoding("UTF-8");
// messageSource.setBasename("messages");
// return messageSource;
// }

@Bean
public MessageSource messageSource() {
return new ResourceBundleMessageSource() {
Expand All @@ -134,16 +110,11 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
props.put("jakarta.persistence.sharedCache.mode", "ENABLE_SELECTIVE");
props.put("org.hibernate.envers.audit_strategy", "org.hibernate.envers.strategy.internal.DefaultAuditStrategy");
// props.put("jakarta.persistence.validation.factory", validator());
// props.put(AvailableSettings.JAKARTA_VALIDATION_FACTORY, validatorFactory);
props.put("org.hibernate.envers.revision_listener", "fi.vm.sade.eperusteet.service.impl.AuditRevisionListener");
props.put("hibernate.jdbc.batch_size", 20);
props.put("hibernate.jdbc.fetch_size", 20);
props.put(AvailableSettings.ID_DB_STRUCTURE_NAMING_STRATEGY, "legacy");
// props.put("hibernate.ejb.interceptor", hibernateInterceptor());
props.put("hibernate.id.new_generator_mappings", false);
props.put(AvailableSettings.ID_DB_STRUCTURE_NAMING_STRATEGY, SingleNamingStrategy.STRATEGY_NAME);
entityManagerFactory.setJpaPropertyMap(props);
// entityManagerFactory.setMappingResources("hibernate-typedefs.hbm.xml");
return entityManagerFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void configurePathMatch(PathMatchConfigurer matcher) {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/ui/").setViewName("forward:/ui/index.html");
registry.addRedirectViewController("/ui", "/ui/");
// registry.addRedirectViewController("/swagger", "/swagger-ui/index.html");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package fi.vm.sade.eperusteet.config;

import com.fasterxml.jackson.databind.type.SimpleType;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.Schema;
import org.springdoc.core.customizers.OpenApiCustomiser;
import org.springdoc.core.customizers.PropertyCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.ResolvableType;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@Configuration
//@EnableSwagger2
@Profile("!test")
//@Profile("!test")
public class SwaggerConfig {

// @Bean
Expand Down Expand Up @@ -75,4 +71,30 @@ public PropertyCustomizer enumPropertyCustomizer() {
return schema;
};
}

@Bean
public GroupedOpenApi externalOpenApi() {
return GroupedOpenApi.builder()
.group("external")
.packagesToScan("fi.vm.sade.eperusteet.resource.julkinen")
.pathsToMatch("/api/external/**")
.build();
}

// @Bean
// public OpenApiCustomiser customOpenApi() {
// return openApi -> {
// // Define the base path of the controller to keep visible
// String visibleControllerBasePath = "/api/external";
//
// // Filter paths to only include the ones that match the desired controller
// openApi.setPaths(openApi.getPaths().entrySet().stream()
// .filter(entry -> entry.getKey().startsWith(visibleControllerBasePath))
// .collect(
// Paths::new,
// (paths, entry) -> paths.addPathItem(entry.getKey(), entry.getValue()),
// HashMap::putAll
// ));
// };
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/buildversion.txt").permitAll()
.requestMatchers(HttpMethod.GET, "/api/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api-docs").permitAll()
.requestMatchers(HttpMethod.GET, "/api-docs/**").permitAll()
.requestMatchers(HttpMethod.GET, "/").permitAll()
.requestMatchers(HttpMethod.POST, "/api/dokumentit/pdf/**").permitAll()
.anyRequest().authenticated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public Reference(String id) {
this.id = id;
}

public String getId() {
return id;
}

@JsonValue
public Object getId() {
public Object getJsonValue() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public class DokumenttiController {
@ResponseBody
@Operation(summary = "luo dokumentti")
public ResponseEntity<DokumenttiDto> createDokumentti(
@RequestParam("perusteId") final long perusteId,
@RequestParam(value = "kieli", defaultValue = "fi") final String kieli,
@RequestParam(value = "suoritustapakoodi") final String suoritustapakoodi,
@RequestParam(value = "version", defaultValue = "uusi") final String version
@RequestParam long perusteId,
@RequestParam String kieli,
@RequestParam String suoritustapakoodi,
@RequestParam(defaultValue = "uusi") final String version
) throws DokumenttiException {
HttpStatus status = HttpStatus.BAD_REQUEST;

Expand Down Expand Up @@ -128,9 +128,9 @@ public ResponseEntity<Object> getDokumentti(
@RequestMapping(value = "/peruste", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Long> getDokumenttiId(
@RequestParam final Long perusteId,
@RequestParam(defaultValue = "fi") final String kieli,
@RequestParam(value = "suoritustapa", defaultValue = "naytto") final String suoritustapa
@RequestParam Long perusteId,
@RequestParam String kieli,
@RequestParam(defaultValue = "naytto") final String suoritustapa
) {
Suoritustapakoodi s = Suoritustapakoodi.of(suoritustapa);
Long dokumenttiId = service.getDokumenttiId(perusteId, Kieli.of(kieli), s, GeneratorVersion.UUSI);
Expand All @@ -141,8 +141,8 @@ public ResponseEntity<Long> getDokumenttiId(
@ResponseBody
public ResponseEntity<Long> getKVLiiteDokumenttiId(
@RequestParam final Long perusteId,
@RequestParam(defaultValue = "fi") final String kieli,
@RequestParam(value = "suoritustapa", defaultValue = "naytto") final String suoritustapa
@RequestParam final String kieli,
@RequestParam(defaultValue = "naytto") final String suoritustapa
) {
Suoritustapakoodi s = Suoritustapakoodi.of(suoritustapa);
Long dokumenttiId = service.getDokumenttiId(perusteId, Kieli.of(kieli), s, GeneratorVersion.KVLIITE);
Expand All @@ -152,10 +152,10 @@ public ResponseEntity<Long> getKVLiiteDokumenttiId(
@RequestMapping(method = RequestMethod.GET, params = "perusteId")
@ResponseBody
public ResponseEntity<DokumenttiDto> getLatestDokumentti(
@RequestParam("perusteId") final Long perusteId,
@RequestParam(defaultValue = "fi") final String kieli,
@RequestParam("suoritustapa") final String suoritustapa,
@RequestParam(defaultValue = "") final String version
@RequestParam final Long perusteId,
@RequestParam final String kieli,
@RequestParam final String suoritustapa,
@RequestParam final String version
) {
try {
Kieli kielikoodi = Kieli.of(kieli);
Expand Down Expand Up @@ -185,8 +185,8 @@ public ResponseEntity<DokumenttiDto> queryDokumenttiTila(@PathVariable("dokument
@RequestMapping(value = "/julkaistu", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<DokumenttiDto> getJulkaistuDokumentti(
@RequestParam() final Long perusteId,
@RequestParam() final String kieli,
@RequestParam final Long perusteId,
@RequestParam final String kieli,
@RequestParam(required = false) final Integer revision
) {
return ResponseEntity.ok(service.getJulkaistuDokumentti(perusteId, Kieli.of(kieli), revision));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import fi.vm.sade.eperusteet.service.JulkaisutService;
import fi.vm.sade.eperusteet.service.OsaamismerkkiService;
import fi.vm.sade.eperusteet.service.PerusteService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spring.datasource.hikari.validation-timeout=20000
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.jcache.JCacheRegionFactory
spring.jpa.properties.hibernate.id.db_structure_naming_strategy=legacy
hibernate.javax.cache.uri=classpath:eperusteet-hibernate-ehcache.xml

#cas
Expand All @@ -47,7 +46,6 @@ spring.servlet.multipart.max-file-size: 10MB
spring.servlet.multipart.max-request-size: 10MB

springdoc.packagesToScan=fi.vm.sade.eperusteet.resource
springdoc.pathsToMatch=/api/**
springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.path=/swagger
springdoc.api-docs.path=/api-docs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SELECT setval('hibernate_sequence', (with pk_list as (select tbl_ns.nspname as table_schema,
tbl.relname as table_name,
cons.conname as pk_name,
col.attname as pk_column
from pg_class tbl
join pg_constraint cons on tbl.oid = cons.conrelid and cons.contype = 'p'
join pg_namespace tbl_ns on tbl_ns.oid = tbl.relnamespace
join pg_attribute col
on col.attrelid = tbl.oid and col.attnum = cons.conkey[1]
join pg_type typ on typ.oid = col.atttypid
where col.attname = 'id'
and typ.typname not in ('uuid')),
maxvals as (select table_schema,
table_name,
pk_column,
(xpath('/row/max/text()',
query_to_xml(format('select max(%I) from %I.%I',
pk_column, table_schema,
table_name), true, true, ''))
)[1]::text as max_val
from pk_list)
select max(max_val::integer)
from maxvals
where pk_column = 'id') + 100)
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<entry key="org.hibernate.envers.allow_identifier_reuse" value="true"/>
<entry key="jakarta.persistence.validation.factory" value-ref="validator"/>
<!-- <entry key="hibernate.ejb.interceptor" value-ref="hibernateInterceptor" />-->
<entry key="hibernate.id.db_structure_naming_strategy" value="legacy"/>
<entry key="hibernate.id.db_structure_naming_strategy" value="single"/>
</map>
</property>
<!-- <property name="mappingResources">-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<entry key="org.hibernate.envers.allow_identifier_reuse" value="true"/>
<!-- <entry key="jakarta.persistence.validation.factory" value-ref="validator"/>-->
<!-- <entry key="hibernate.session_factory.interceptor" value-ref="hibernateInterceptor" />-->
<entry key="hibernate.id.db_structure_naming_strategy" value="legacy"/>
<entry key="hibernate.id.db_structure_naming_strategy" value="single"/>
</map>
</property>
<property name="mappingResources">
Expand Down
6 changes: 5 additions & 1 deletion generated/eperusteet-ext.spec.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generated/eperusteet.spec.json

Large diffs are not rendered by default.

0 comments on commit 0e31038

Please sign in to comment.