Commit 8f78a3da authored by Arild Trygve Aae's avatar Arild Trygve Aae

Henter data fra Brønnøysund

parent 0ea28594
Pipeline #23896 skipped with stages
......@@ -11,20 +11,21 @@
<version>0.0.1</version>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<!-- <version>1.5.1.RELEASE</version> -->
<relativePath /> <!-- lookup parent from reposictory -->
</parent>
<repositories>
<repository>
<id>nexus.nsd.no</id>
<url>https://nexus.nsd.no/repository/maven-releases/</url>
</repository>
</repositories>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<!-- <version>1.5.1.RELEASE</version> -->
<relativePath /> <!-- lookup parent from reposictory -->
</parent>
<repositories>
<repository>
<id>nexus.nsd.no</id>
<url>https://nexus.nsd.no/repository/maven-releases/</url>
</repository>
</repositories>
<properties>
<java.version>1.8</java.version>
......@@ -35,176 +36,179 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jettison/jettison -->
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.1.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core ok -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.jettison/jettison -->
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.15.Final</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.1.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core ok -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.9.8</version>
</dependency>
</dependencies>
......
package brsund_hent_data;
import org.slf4j.Logger;
import brsund_hent_data.jdbc.JdbcFellesService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.TimeZone;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.*;
import java.util.logging.Logger;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
@SpringBootApplication
@EnableJpaAuditing
@PropertySource("classpath:application.properties")
//@EnableAutoConfiguration
public class Dbh_api_brsund_register_centre_App {
static {
// dotenv = Dotenv.configure().ignoreIfMissing().load();
System.setProperty("logback.config", "logback.xml");
}
private static final Logger logger = LoggerFactory.getLogger(Dbh_api_brsund_register_centre_App.class);
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;
public static void main(String[] args) {
try {
@SpringBootApplication
public class Dbh_api_brsund_register_centre_App implements CommandLineRunner {
logger.info("Starter henting av data") ;
SpringApplication app = new SpringApplication(Dbh_api_brsund_register_centre_App.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
@Autowired
JdbcTemplate jdbcTemplate;
} catch (Exception e) {
public static void main(String[] args) {
SpringApplication.run(Dbh_api_brsund_register_centre_App.class, args);
}
}
@Override
public void run(String... args) throws Exception {
hentOrganisasjonerListe();
}
void hentOrganisasjonerListe() throws Exception {
// private static final Logger logger = LoggerFactory.getLogger(JdbcFellesServiceImpl.class);
String fnr = "";
String sql = "";
String uri1 = "https://data.brreg.no/enhetsregisteret/api/enheter/";
String soek = "";
RestTemplate restTemplate = new RestTemplate();
List<Map<String, Object>> mapResult = null;
ObjectMapper objectMapper = new ObjectMapper();
//sql += " go ";
sql += "Select DISTINCT instkode, instnavn, fnr From dbo.ORG_INST WHERE (eierskap=2 or insttype = '93')";
sql += " AND gyld_til='99999'";
List<Map<String, Object>> data = null;
// System.out.println(" SQL: " + sql);
data = jdbcTemplate.queryForList(sql);
for (Map<String, Object> data1 : data) {
fnr = data1.get("fnr") .toString().trim();
fnr = fnr.replace(" ","");
soek = uri1 + fnr;
System.out.println(" Søker på: " + soek);
try {
String result = restTemplate.getForObject(soek, String.class);
Map<String,String> resultMap = new HashMap<String,String>();
ObjectMapper mapperObj = new ObjectMapper();
System.out.println("Input Json: "+result);
try {
JsonNode jsonNodeInn = objectMapper.valueToTree(result);
//
System.out.println("Output Map: "+ jsonNodeInn.asText());
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println (" BBBBBBBBBBBBBBBBBBBBBBBBB: " + result);
e.printStackTrace();
}
System.out.println ("Resultat av søk: " + result);
} catch (Exception e) {
System.out.println(" Finner ikke: " + soek + " " + e.getMessage());
}
}
return;
}
}
......@@ -6,6 +6,6 @@ import java.util.List;
public interface JdbcFellesService {
List<String> hentOrganisasjonerListe() throws InvalidResultSetAccessException, Exception;
void hentOrganisasjonerListe() throws Exception;
}
package brsund_hent_data.jdbc;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import static com.google.common.base.Strings.isNullOrEmpty;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.jetbrains.annotations.NotNull;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jca.cci.InvalidResultSetAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;
@Repository("JdbcFellesService")
......@@ -44,44 +30,49 @@ public class JdbcFellesServiceImpl implements JdbcFellesService {
@Autowired
JdbcTemplate jdbcTemplate;
private static final Logger logger = LoggerFactory.getLogger(JdbcFellesServiceImpl.class);
// private static final Logger logger = LoggerFactory.getLogger(JdbcFellesServiceImpl.class);
@Autowired
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<String> hentOrganisasjonerListe() throws InvalidResultSetAccessException, Exception {
List<String> listOfValue = new ArrayList<String>();
@Override
public void hentOrganisasjonerListe() throws Exception {
System.out.println(" CCCCCCCCCCCCCCCCCCCCC hentOrganisasjonerListe: ");
String fnr = "";
int iFnr = 0;
String sql = "use dbh; ";
// String sql = "use dbh; ";
String sql = "";
System.out.println(" CCCCCCCCCCCCCCCCCCCCC hentOrganisasjonerListe: ");
final String uri1 = " https://data.brreg.no/enhetsregisteret/api/enheter/997039149";
String soek = "";
RestTemplate restTemplate = new RestTemplate();
sql += " go ";
//sql += " go ";
sql += "Select DISTINCT instkode, instnavn, fnr From dbo.ORG_INST WHERE (eierskap=2 or insttype = '93')";
sql += " AND gyld_til='9999'";
List<Map<String, Object>> data = null;
try {
List<Map<String, Object>> data = null;
System.out.println(" SQL: " + sql);
data = jdbcTemplate.queryForList(sql);
for (Map<String, Object> data1 : data) {
fnr = data1.get("fnr") .toString().trim();
fnr = fnr.replace(" ","");
soek = uri1;
soek.replaceAll("997039149",fnr);
System.out.println(" Søker på: " + soek);
String result = restTemplate.getForObject(soek, String.class);
System.out.println(result);
}
} catch (Exception e) {
return null;
System.out.println ("Exception MMMMMMMMMM ");
return;
}
data = null;
// System.out.println("Lister ut verdier: " + listOfValue);
return listOfValue;
return;
}