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

Henter regnskapdata for oppgitte fnr

parent 0b3e73fd
Pipeline #24026 skipped with stages
......@@ -69,47 +69,48 @@ import org.springframework.web.client.RestTemplate;
private void hentSelskapPrivate() throws IOException {
String fileNameLevert = "C:\\Data\\selskap_private_levert_json.data";
String fileNameIkkeLevert = "C:\\Data\\selskap_private_Ikke_levert_json.data";
String fileNameFeil = "C:\\Data\\selskap_private_feil_json.data";
// String fileNameFeil = "C:\\Data\\selskap_private_feil_json.data";
String sql = "Select DISTINCT instkode, instnavn, fnr From dbo.ORG_INST ";
sql += " WHERE eierskap=2";
sql += " AND gyld_til='99999'";
// System.out.println(" NNNNNNNNNNNNNNNNNNN 1 " + sql );
String uri1 = "https://data.brreg.no/enhetsregisteret/api/enheter/";
handleData(fileNameLevert,fileNameIkkeLevert, fileNameFeil,sql, uri1);
handleData(fileNameLevert,fileNameIkkeLevert, sql, uri1);
}
private void hentStudentsamskipnader() throws IOException {
String fileNameLevert = "C:\\Data\\selskap_studentsamskipander_levert_json.data";
String fileNameIkkeLevert = "C:\\Data\\selskap_studentsamskipander_Ikke_levert_json.data";
String fileNameFeil = "C:\\Data\\selskap_studentskip_feil.data";
// String fileNameFeil = "C:\\Data\\selskap_studentskip_feil.data";
String sql = "Select DISTINCT instkode, instnavn, fnr From dbo.ORG_INST ";
sql += "WHERE insttype = '93'";
sql += " AND gyld_til='99999'";
// System.out.println(" NNNNNNNNNNNNNNNNNNN 2 " + sql );
String uri1 = "https://data.brreg.no/enhetsregisteret/api/enheter/";
handleData(fileNameLevert,fileNameIkkeLevert,fileNameFeil, sql, uri1);
handleData(fileNameLevert,fileNameIkkeLevert, sql, uri1);
}
private void hentOrgEidAvInst() throws IOException {
String fileNameLevert = "C:\\Data\\selskap_org_eid_av_inst_levert_json.data";
String fileNameIkkeLevert = "C:\\Data\\selskap_org_eid_av_inst_Ikke_levert_json.data";
String fileNameFeil = "C:\\Data\\selskap_org_inst_eid_feil_json.data";
// String fileNameFeil = "C:\\Data\\selskap_org_inst_eid_feil_json.data";
String sql = "Select DISTINCT NAMN_NO, Foretaksnr ";
sql += "From selskap..ORGEINING ";
sql += " where Foretaksnr is not null";
// System.out.println(" NNNNNNNNNNNNNNNNNNN 3 " + sql );
String uri1 = "https://data.brreg.no/enhetsregisteret/api/enheter/";
handleData(fileNameLevert,fileNameIkkeLevert,fileNameFeil, sql, uri1);
handleData(fileNameLevert,fileNameIkkeLevert, sql, uri1);
}
private void handleData(String fileNameLevert,String fileNameIkkeLevert, String fileNameFeil, String sql, String uri1) throws IOException {
// private void handleData(String fileNameLevert,String fileNameIkkeLevert, String fileNameFeil, String sql, String uri1) throws IOException {
private void handleData(String fileNameLevert,String fileNameIkkeLevert, String sql, String uri1) throws IOException {
String soek = "";
String fnr = "";
BufferedWriter writerLevert = new BufferedWriter(new FileWriter(fileNameLevert, false));
BufferedWriter writerIkkeLevert = new BufferedWriter(new FileWriter(fileNameIkkeLevert, false));
BufferedWriter writerFeilLogg = new BufferedWriter(new FileWriter(fileNameFeil, false));
// BufferedWriter writerFeilLogg = new BufferedWriter(new FileWriter(fileNameFeil, false));
PrintStream o = new PrintStream(new File("C:\\Data\\feilfil.data"));
PrintStream console = System.out;
System.setOut(o);
RestTemplate restTemplate = new RestTemplate();
List<Map<String, Object>> mapResult = null;
ObjectMapper objectMapper = new ObjectMapper();
......@@ -159,76 +160,30 @@ import org.springframework.web.client.RestTemplate;
}
} catch (HttpClientErrorException ce) {
appendToFile(ce,fileNameFeil,soek);
System.out.println(" Exception failce1: " + soek + " " + ce.getMessage());
// e.printStackTrace();
System.out.println(" Exception failce1: " + soek + " " + ce.getMessage());
}catch (HttpServerErrorException se) {
appendToFile(se,fileNameFeil,soek);
System.out.println(" Exception failse1: " + soek + " " + se.getMessage());
System.out.println(" Exception faile1: " + soek + " " + se.getMessage());
}catch (Exception e) {
appendToFile(e,fileNameFeil,soek);
System.out.println(" Exception faile1: " + soek + " " + e.getMessage());
System.out.println(" Exception faile1: " + soek + " " + e.getMessage());
}
// System.out.println ("Resultat av søk: " + result);
} catch (HttpClientErrorException ce) {
appendToFile(ce,fileNameFeil,soek);
// skrivFilException(writerFeilLogg, soek, fileNameFeil,e);
System.out.println(" Exception feilce2: " + soek + " " + ce.getMessage());
// e.printStackTrace();
} catch (HttpClientErrorException cie) {
System.out.println(" Exception failcie2: " + soek + " " + cie.getMessage());
}catch (HttpServerErrorException se) {
appendToFile(se,fileNameFeil,soek);
// skrivFilException(writerFeilLogg, soek, fileNameFeil,e);
System.out.println(" Exception feilse2: " + soek + " " + se.getMessage());
// e.printStackTrace();
System.out.println(" Exception failese2: " + soek + " " + se.getMessage());
}catch (Exception e) {
appendToFile(e,fileNameFeil,soek);
// e.printStackTrace();
//System.setOut(console);
System.out.println(" Exception faileE2: " + soek + " " + e.getMessage());
}
}
}
public static void appendToFile(Exception e,String filename,String soek) {
try {
FileWriter fstream = new FileWriter(filename, true);
BufferedWriter out = new BufferedWriter(fstream);
PrintWriter pWriter = new PrintWriter(out, true);
e.printStackTrace( pWriter);
}
catch (Exception ie) {
throw new RuntimeException("Could not write Exception to file", ie);
}
void skrivFil(BufferedWriter writer,JSONObject jsonObject, String filename) throws Exception {
JSONObject output;
writer.append(jsonObject.toString());
writer.newLine();
}
void skrivFil(BufferedWriter writer,JSONObject jsonObject, String filename) {
JSONObject output;
try {
writer.append(jsonObject.toString());
writer.newLine();
} catch (IOException e) {
System.out.println(" Feil ved skriv til fil: " + filename + " " + e.getMessage());
e.printStackTrace();
}
}
void skrivFilException(BufferedWriter writer2,String streng, String filename,Exception e) {
try {
streng = "Feil ved kontakt med Br.sund: " + streng;
System.out.println ("Hei 1 " + streng);
// writer2.append(streng);
// writer2.newLine();
FileWriter fstream = new FileWriter(filename);
BufferedWriter out = new BufferedWriter(fstream);
PrintWriter pWriter = new PrintWriter(out, true);
e.printStackTrace(pWriter);
} catch (IOException ie) {
e.printStackTrace();
}
}
}
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