Skip to content

Commit

Permalink
cleanup code (Issue #171)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Feb 10, 2025
1 parent d26c178 commit ff81058
Showing 1 changed file with 8 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,14 @@ public void searchSachkonto() {
if (phrase == null) {
return;
}

logger.fine("search prase '" + phrase + "'");
if (phrase == null || phrase.length() < 2) {
return;
}

logger.finest(".......trigger searchSachkonto: " + phrase);

logger.fine("search for=" + phrase);

// DATEV Sachkonten suchen
// optional use clientID from workitem
if (workflowController.getWorkitem().hasItem(DatevService.ITEM_DATEV_CLIENT_ID)) {
String temp_clientID = workflowController.getWorkitem()
.getItemValueString(DatevService.ITEM_DATEV_CLIENT_ID);
dataList = searchEntity(phrase, "kontenbeschriftungen", temp_clientID);
} else {
// standard suche
dataList = searchEntity(phrase, "kontenbeschriftungen", null);
}
dataList = searchEntity(phrase, "kontenbeschriftungen");

for (ItemCollection dbtr : dataList) {
String kontoNumber = dbtr.getItemValueString("_konto");
String display = kontoNumber + " - " + dbtr.getItemValueString("_kontobeschriftung");
Expand All @@ -139,7 +127,6 @@ public void searchSachkonto() {
display = display.replace("'", "");
searchResult.add(new DatevSearchEntry(kontoNumber, display, buildSachkontoJsonData(dbtr)));
}

}

/**
Expand All @@ -154,7 +141,6 @@ public void searchSachkonto() {
* }
*/
public void searchCdtr() {
String client = null;
List<ItemCollection> dataList = null;
searchResult = new ArrayList<DatevSearchEntry>();
// get the param from faces context....
Expand All @@ -168,35 +154,18 @@ public void searchCdtr() {
if (phrase == null || phrase.length() < 2) {
return;
}

logger.finest(".......trigger datev search...");
client = workflowController.getWorkitem().getItemValueString(DatevService.ITEM_DATEV_CLIENT_ID);
logger.fine("search for=" + phrase);
dataList = searchEntity(phrase, "debitoren/kreditoren", client);

dataList = searchEntity(phrase, "debitoren/kreditoren");
for (ItemCollection dbtr : dataList) {
// displayname = konto.getItemValueString("_konto") + " " +
// konto.getItemValueString("_kurzbezeichnung");
String dbtrNo = dbtr.getItemValueString("_konto");
// resolve name
String name = dbtr.getItemValueString("_name_(adressattyp_unternehmen)");
if (name.isEmpty()) {
name = dbtr.getItemValueString("_name_(adressattyp_keine_angabe)");
}
if (name.isEmpty()) {
name = dbtr.getItemValueString("_name_(adressattyp_natürl_person)");
}
if (name.isEmpty()) {
name = dbtr.getItemValueString("_kurzbezeichnung");
}
String name = dbtr.getItemValueString("_name");
dbtr.setItemValue("_name", name);

String display = dbtrNo + " - " + name;
display = display.replace("\"", "");
display = display.replace("'", "");
searchResult.add(new DatevSearchEntry(dbtrNo, display, buildCdtrJsonData(dbtr)));
}

}

/**
Expand All @@ -217,7 +186,6 @@ public List<DatevSearchEntry> getSearchResult() {
* @return
*/
private String buildSachkontoJsonData(ItemCollection konto) {

JsonObjectBuilder objectBuilder = Json.createObjectBuilder(). //
add("konto", jsonVal(konto.getItemValueString("_konto"))). //
add("name", jsonVal(konto.getItemValueString("_kontobeschriftung")));
Expand All @@ -240,7 +208,6 @@ private String buildSachkontoJsonData(ItemCollection konto) {
* @return
*/
private String buildCdtrJsonData(ItemCollection cdtr) {

JsonObjectBuilder objectBuilder = Json.createObjectBuilder(). //
add("konto", jsonVal(cdtr.getItemValueString("_konto"))). //
add("name", jsonVal(cdtr.getItemValueString("_name"))). //
Expand Down Expand Up @@ -298,27 +265,18 @@ public static String jsonVal(String val) {
* (_datev_client_id)
* @return - list of matching profiles
*/
public List<ItemCollection> searchEntity(String phrase, String type, String clientID) {
public List<ItemCollection> searchEntity(String phrase, String type) {

List<ItemCollection> searchResult = new ArrayList<ItemCollection>();

if (phrase == null || phrase.isEmpty())
if (phrase == null || phrase.isEmpty()) {
return searchResult;

}
Collection<ItemCollection> col = null;
try {
phrase = phrase.trim();
// phrase = LuceneSearchService.escapeSearchTerm(phrase);
phrase = schemaService.normalizeSearchTerm(phrase);
String sQuery = "(type:\"" + type + "\"";

// restrict to client id?
if (clientID != null && !clientID.isEmpty()) {
sQuery += " AND _datev_client_id:\"" + clientID + "\"";
}

sQuery += ")";

String sQuery = "(type:\"" + type + "\")";
sQuery += " AND (" + phrase + "*)";

logger.finest("searchprofile: " + sQuery);
Expand All @@ -329,15 +287,11 @@ public List<ItemCollection> searchEntity(String phrase, String type, String clie
} catch (Exception e) {
logger.warning(" lucene error - " + e.getMessage());
}

for (ItemCollection kreditor : col) {
searchResult.add(kreditor);
}
// sort by txtname..
Collections.sort(searchResult, new ItemCollectionComparator("txtname", true));

return searchResult;

}

}

0 comments on commit ff81058

Please sign in to comment.