Skip to content

Commit

Permalink
Jatkettu Spring Boot -muutoksia
Browse files Browse the repository at this point in the history
  • Loading branch information
augustk committed Nov 14, 2024
1 parent f042234 commit 6e60b11
Show file tree
Hide file tree
Showing 292 changed files with 53,636 additions and 49,236 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package db.migration;

import fi.vm.sade.tarjonta.service.search.IndexDataUtils;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

import fi.vm.sade.tarjonta.service.search.IndexDataUtils;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.slf4j.Logger;
Expand All @@ -15,81 +14,99 @@

public class V046__addAlkamiskausiAndVuosi extends BaseJavaMigration {

private static final Logger LOG = LoggerFactory.getLogger(V046__addAlkamiskausiAndVuosi.class);

String koulutusModuuliTotQuery = "SELECT * FROM koulutusmoduuli_toteutus kt WHERE alkamiskausi IS NULL";

public void migrate(Context context) throws Exception {
LOG.info("RUNNING V046 MIGRATION...");
System.out.print("RUNNING V046 MIGRATION...");
JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
List<QueryResult> results = jdbcTemplate.query(koulutusModuuliTotQuery,new RowMapper<QueryResult>() {
@Override
public QueryResult mapRow(ResultSet resultSet, int i) throws SQLException {
private static final Logger LOG = LoggerFactory.getLogger(V046__addAlkamiskausiAndVuosi.class);

String koulutusModuuliTotQuery =
"SELECT * FROM koulutusmoduuli_toteutus kt WHERE alkamiskausi IS NULL";

public void migrate(Context context) throws Exception {
LOG.info("RUNNING V046 MIGRATION...");
System.out.print("RUNNING V046 MIGRATION...");
JdbcTemplate jdbcTemplate =
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
List<QueryResult> results =
jdbcTemplate.query(
koulutusModuuliTotQuery,
new RowMapper<QueryResult>() {
@Override
public QueryResult mapRow(ResultSet resultSet, int i) throws SQLException {
QueryResult result = new QueryResult();

result.setAlkamisPvm(resultSet.getDate("koulutuksen_alkamis_pvm"));
result.setOid(resultSet.getString("oid"));
result.setId(resultSet.getInt("id"));

return result;
}
});
LOG.debug("UPDATING {} rows",results.size());
System.out.println("UPDATING " + results.size() + " ROWS");
for (QueryResult result : results) {
updateKomoto(result, jdbcTemplate);
}
}
});
LOG.debug("UPDATING {} rows", results.size());
System.out.println("UPDATING " + results.size() + " ROWS");
for (QueryResult result : results) {
updateKomoto(result, jdbcTemplate);
}

private void updateKomoto(QueryResult result, JdbcTemplate jdbcTemplate) {
try {
if (result.getAlkamisPvm() != null ) {
String kausi = IndexDataUtils.parseKausiKoodi(result.getAlkamisPvm());
String vuosi = IndexDataUtils.parseYear(result.getAlkamisPvm());
String updateSql = "UPDATE koulutusmoduuli_toteutus SET alkamiskausi = '" + kausi + "' , alkamisvuosi = " + vuosi +" WHERE id = " +result.getId();
System.out.println("UPDATING WITH SQL : " + updateSql);
jdbcTemplate.update(updateSql);
LOG.info("Updated row {} with values {}", result.getId(),kausi + " " +vuosi);
System.out.println("UPDATE ROW " + result.getId() + " WITH VALUES : " + kausi + " " + vuosi);
} else {
System.out.println("ROW " + result.getId() + " HAD ALKAMISPVM NULL. NOT UPDATED");
}
} catch (Exception exp ){
LOG.warn("SOMETHING WENT WRONG IN V046-migration, with row {} EXCEPTION : {}", result.getId(),exp.toString());
System.out.println("SOMETHING WENT WRONG IN V046-migration, with row : " + result.getId() + " EXCEPTION : " + exp.toString());
}

private void updateKomoto(QueryResult result, JdbcTemplate jdbcTemplate) {
try {
if (result.getAlkamisPvm() != null) {
String kausi = IndexDataUtils.parseKausiKoodi(result.getAlkamisPvm());
String vuosi = IndexDataUtils.parseYear(result.getAlkamisPvm());
String updateSql =
"UPDATE koulutusmoduuli_toteutus SET alkamiskausi = '"
+ kausi
+ "' , alkamisvuosi = "
+ vuosi
+ " WHERE id = "
+ result.getId();
System.out.println("UPDATING WITH SQL : " + updateSql);
jdbcTemplate.update(updateSql);
LOG.info("Updated row {} with values {}", result.getId(), kausi + " " + vuosi);
System.out.println(
"UPDATE ROW " + result.getId() + " WITH VALUES : " + kausi + " " + vuosi);
} else {
System.out.println("ROW " + result.getId() + " HAD ALKAMISPVM NULL. NOT UPDATED");
}
} catch (Exception exp) {
LOG.warn(
"SOMETHING WENT WRONG IN V046-migration, with row {} EXCEPTION : {}",
result.getId(),
exp.toString());
System.out.println(
"SOMETHING WENT WRONG IN V046-migration, with row : "
+ result.getId()
+ " EXCEPTION : "
+ exp.toString());
}
}

class QueryResult {
class QueryResult {

private String oid;
private int id;
private Date alkamisPvm;
private String oid;
private int id;
private Date alkamisPvm;

public String getOid() {
return oid;
}

public String getOid() {
return oid;
}

public void setOid(String oid) {
this.oid = oid;
}
public void setOid(String oid) {
this.oid = oid;
}

public int getId() {
return id;
}
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
public void setId(int id) {
this.id = id;
}

public Date getAlkamisPvm() {
return alkamisPvm;
}
public Date getAlkamisPvm() {
return alkamisPvm;
}

public void setAlkamisPvm(Date alkamisPvm) {
this.alkamisPvm = alkamisPvm;
}
public void setAlkamisPvm(Date alkamisPvm) {
this.alkamisPvm = alkamisPvm;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
/*
* Copyright (c) 2014 The Finnish Board of Education - Opetushallitus
*
*
* This program is free software: Licensed under the EUPL, Version 1.1 or - as
* soon as they will be approved by the European Commission - subsequent versions
* of the EUPL (the "Licence");
*
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at: http://www.osor.eu/eupl/
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* European Union Public Licence for more details.
*/
package fi.vm.sade.tarjonta.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Spring configuraatio Json serialisoinnille (jackson)
*/
/** Spring configuraatio Json serialisoinnille (jackson) */
@Configuration
public class JSonSerializationConfig {

@Bean
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
return mapper;
}

@Bean(name="tarjontaJacksonJsonProvider")
public JacksonJaxbJsonProvider getJsonProvider(ObjectMapper mapper) {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(mapper);
@Bean
public ObjectMapper getObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
return mapper;
}

return provider;
}
@Bean(name = "tarjontaJacksonJsonProvider")
public JacksonJaxbJsonProvider getJsonProvider(ObjectMapper mapper) {
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(mapper);

return provider;
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
package fi.vm.sade.tarjonta.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import fi.vm.sade.oid.generator.OIDGenerator;
import fi.vm.sade.oid.generator.impl.RandomLuhnOIDGenerator;
import fi.vm.sade.tarjonta.service.OidService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@ComponentScan(basePackages = { "fi.vm.sade.oid.dao" })
@ComponentScan(basePackages = {"fi.vm.sade.oid.dao"})
@Configuration
public class OidConfig {

public OidConfig() {
System.out.println("OidConfig init()");
}
@Bean
public OIDGenerator getGenerator() {
return new RandomLuhnOIDGenerator();
}
@Bean
public OidService getOidService(){
return new OidService();
}
public OidConfig() {
System.out.println("OidConfig init()");
}

@Bean
public OIDGenerator getGenerator() {
return new RandomLuhnOIDGenerator();
}

@Bean
public OidService getOidService() {
return new OidService();
}

// @Bean
// @Autowired
// public OIDGeneratorFactory getFactory(OIDGenerator defaultGenerator) {
// OIDGeneratorFactory factory = new OIDGeneratorFactory();
// factory.setDefaultGenerator(defaultGenerator);
// return factory;
// }
//
// @Bean
// public OIDService getOidService() {
// OIDServiceImpl oid = new OIDServiceImpl();
// return oid;
// }
// @Bean
// @Autowired
// public OIDGeneratorFactory getFactory(OIDGenerator defaultGenerator) {
// OIDGeneratorFactory factory = new OIDGeneratorFactory();
// factory.setDefaultGenerator(defaultGenerator);
// return factory;
// }
//
// @Bean
// public OIDService getOidService() {
// OIDServiceImpl oid = new OIDServiceImpl();
// return oid;
// }

}
Loading

0 comments on commit 6e60b11

Please sign in to comment.