Commit e71472ed authored by Arild Trygve Aae's avatar Arild Trygve Aae

Closer files

parent fd3b8088
Pipeline #24029 skipped with stages
package brsund_hent_data;
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.apache.tomcat.util.http.fileupload.FileUtils;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.json.CDL;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
import java.io.*;
import java.util.*;
import org.json.CDL;
import java.util.logging.Logger;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
......@@ -99,6 +84,7 @@ import org.springframework.web.client.RestTemplate;
String uri1 = "https://data.brreg.no/enhetsregisteret/api/enheter/";
handleData(fileNameLevert,fileNameIkkeLevert, sql, uri1);
}
// private void handleData(String fileNameLevert,String fileNameIkkeLevert, String fileNameFeil, String sql, String uri1) throws IOException {
......@@ -180,10 +166,13 @@ private void handleData(String fileNameLevert,String fileNameIkkeLevert, String
}
}
writerLevert.close();
writerIkkeLevert.close();
}
void skrivFil(BufferedWriter writer,JSONObject jsonObject, String filename) throws Exception {
JSONObject output;
writer.append(jsonObject.toString());
writer.newLine();
}
}
package brsund_hent_data.jdbc;
import org.springframework.jdbc.InvalidResultSetAccessException;
import java.util.List;
public interface JdbcFellesService {
void hentOrganisasjonerListe() throws Exception;
}
package brsund_hent_data.jdbc;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;
@Repository("JdbcFellesService")
@Transactional(readOnly=true)
public class JdbcFellesServiceImpl implements JdbcFellesService {
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
String loggnow = ft.format(dNow);
@Autowired
JdbcTemplate jdbcTemplate;
// private static final Logger logger = LoggerFactory.getLogger(JdbcFellesServiceImpl.class);
@Autowired
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void hentOrganisasjonerListe() throws Exception {
System.out.println(" CCCCCCCCCCCCCCCCCCCCC hentOrganisasjonerListe: ");
String fnr = "";
int iFnr = 0;
// 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 += "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 {
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) {
System.out.println ("Exception MMMMMMMMMM ");
return;
}
return;
}
}
/*
select instkode, instnavn, fnr
from ORG_INST
where (eierskap=2 or insttype = '93')
and gyld_til='99999'
use dbh;
//Institusjoner
select instkode, instnavn, fnr
from ORG_INST
where eierskap=2
and gyld_til='99999'
union
select instkode, instnavn, fnr
from ORG_INST
where insttype='93'
and gyld_til='99999'
use selskap;
go
select Foretaksnr, NAMN_NO
from selskap..ORGEINING
where Foretaksnr is not null and Foretaksnr != ' ' //Selskap eigd av institusjon.
*/
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment