mirror of
https://github.com/Calciumdibromid/CaBr2_Java
synced 2025-10-06 02:32:40 +02:00
Prepare for more Client Implementations (#56)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package de.obermui.cabr2.cli;
|
||||
|
||||
import de.obermui.cabr2.clients.GESTIS;
|
||||
import de.obermui.cabr2.clients.*;
|
||||
import de.obermui.cabr2.intern.Sheet2Html;
|
||||
import de.obermui.cabr2.intern.html2pdf;
|
||||
import de.obermui.cabr2.models.Personal;
|
||||
@@ -22,10 +22,12 @@ public class MainCLI {
|
||||
|
||||
SafetyDataSheet sheet = new SafetyDataSheet();
|
||||
|
||||
Client client = new GESTIS();
|
||||
|
||||
boolean next = true;
|
||||
while (next) {
|
||||
|
||||
String[] content = GESTIS.SimpleSearch(query, false);
|
||||
String[] content = client.SimpleSearch(query, false);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
System.out.println(i + ":\t" + content[i]);
|
||||
}
|
||||
@@ -36,7 +38,7 @@ public class MainCLI {
|
||||
System.out.println("invalid number: '" + i + "'");
|
||||
continue;
|
||||
}
|
||||
Substance s = GESTIS.getSubstance(content[i], null);
|
||||
Substance s = client.GetSubstance(content[i], null);
|
||||
if (s.CAS != null) {
|
||||
sheet.addSubstance(s);
|
||||
}
|
||||
|
18
src/de/obermui/cabr2/clients/Client.java
Normal file
18
src/de/obermui/cabr2/clients/Client.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package de.obermui.cabr2.clients;
|
||||
|
||||
import de.obermui.cabr2.models.Substance;
|
||||
import de.obermui.cabr2.models.SubstanceShort;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Client {
|
||||
// GetSubstance return Substance based on ZVG and have a fallback to name
|
||||
Substance GetSubstance(String name, String ZVG);
|
||||
|
||||
// Search return list of Substances (SubstanceShort) based on a keyword
|
||||
// if exact is true it will look only for exact matches
|
||||
List<SubstanceShort> Search(String keyword, boolean exact);
|
||||
|
||||
// SimpleSearch works similar to Search but only return names of substances in a string list
|
||||
String[] SimpleSearch(String keyword, boolean exact);
|
||||
}
|
@@ -19,11 +19,12 @@ import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GESTIS {
|
||||
public class GESTIS implements Client {
|
||||
private static final String gestis_en = "http://gestis-en.itrust.de";
|
||||
private static final String gestis_de = "http://gestis.itrust.de";
|
||||
|
||||
public static String[] SimpleSearch(String keyword, boolean exact) {
|
||||
@Override
|
||||
public String[] SimpleSearch(String keyword, boolean exact) {
|
||||
|
||||
keyword = keyword.trim();
|
||||
if (!exact) {
|
||||
@@ -51,7 +52,8 @@ public class GESTIS {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<SubstanceShort> Search(String keyword, boolean exact) {
|
||||
@Override
|
||||
public List<SubstanceShort> Search(String keyword, boolean exact) {
|
||||
List<SubstanceShort> result = new ArrayList<>();
|
||||
|
||||
if (!exact) {
|
||||
@@ -126,7 +128,8 @@ public class GESTIS {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Substance getSubstance(String name, String ZVG) {
|
||||
@Override
|
||||
public Substance GetSubstance(String name, String ZVG) {
|
||||
Substance s = new Substance();
|
||||
|
||||
if (ZVG == null) {
|
||||
@@ -339,7 +342,7 @@ public class GESTIS {
|
||||
}
|
||||
|
||||
private static String getZVGfromName(String name) {
|
||||
List<SubstanceShort> s = Search(name, true);
|
||||
List<SubstanceShort> s = new GESTIS().Search(name, true);
|
||||
if (s.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
@@ -57,9 +57,14 @@ public class SearchSelectWindow implements ActionListener {
|
||||
jlist_substances.setModel(listModel);
|
||||
|
||||
selected = new ArrayList<>();
|
||||
|
||||
if (Ctx.sheet == null) {
|
||||
Ctx.sheet = new SafetyDataSheet();
|
||||
}
|
||||
if (Ctx.client == null) {
|
||||
Ctx.client = new GESTIS();
|
||||
}
|
||||
|
||||
l_searchResult = new ArrayList<>();
|
||||
|
||||
fm.setContentPane(SearchSelectPanel);
|
||||
@@ -70,7 +75,7 @@ public class SearchSelectWindow implements ActionListener {
|
||||
Dialogs.infoBox(this.fm, "Kein Suchbegriff eingegeben", "Error: no keyword");
|
||||
return;
|
||||
}
|
||||
List<SubstanceShort> result = GESTIS.Search(tf_search.getText(), false);
|
||||
List<SubstanceShort> result = Ctx.client.Search(tf_search.getText(), false);
|
||||
listModel.clear();
|
||||
l_searchResult.clear();
|
||||
l_searchResult.addAll(result);
|
||||
@@ -132,7 +137,7 @@ public class SearchSelectWindow implements ActionListener {
|
||||
}
|
||||
|
||||
// get the whole substance data from GESTIS
|
||||
Substance sub = GESTIS.getSubstance(slectedSub.Name, slectedSub.ZVG);
|
||||
Substance sub = Ctx.client.GetSubstance(slectedSub.Name, slectedSub.ZVG);
|
||||
if ((sub.CAS == null || sub.CAS.length() == 0) && (sub.ZVG == null || sub.ZVG.length() == 0)) {
|
||||
Dialogs.infoBox(this.fm, "Ein Fehler trat beim laden der GESTIS daten auf", "Error: gestis return unexpected");
|
||||
return;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package de.obermui.cabr2.gui;
|
||||
|
||||
import de.obermui.cabr2.clients.Client;
|
||||
import de.obermui.cabr2.models.SafetyDataSheet;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -13,4 +14,6 @@ public class ctx {
|
||||
protected SafetyDataSheet sheet;
|
||||
|
||||
protected String lastSavedFileDir;
|
||||
|
||||
protected Client client;
|
||||
}
|
||||
|
Reference in New Issue
Block a user