metric service verbessert

This commit is contained in:
Ralph Soika 2025-01-19 22:55:55 +01:00
parent 01cec74af6
commit 8fad186e39
12 changed files with 347 additions and 148 deletions

View file

@ -1,8 +1,15 @@
# Versionen # Versionen
### 1.3.1 (Development - Office-Workflow 5.0.4 )
- Mulit Currecy Feature für Ausgangsrechnungen
- Neue Analyse Boards
- Neue SOA
- Neues Mahnwesen
### 1.3.0 (Development - Office-Workflow 5.0.2 )
### 1.3.0
- Migration auf Imixs-Office-Workflow 5.0.2 - Migration auf Imixs-Office-Workflow 5.0.2
- Upgrade Imixs-Workflow 6.7 - Upgrade Imixs-Workflow 6.7

View file

@ -82,10 +82,23 @@ services:
EXIM_PASSWORD: "www149.your-server.de:webmaster@imixs.com:$MAILPASSWORD" EXIM_PASSWORD: "www149.your-server.de:webmaster@imixs.com:$MAILPASSWORD"
EXIM_ALLOWED_SENDERS: "10.0.0.0/8:172.18.0.0/12:192.168.0.0/16" EXIM_ALLOWED_SENDERS: "10.0.0.0/8:172.18.0.0/12:192.168.0.0/16"
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheusdata:/prometheus/
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes: volumes:
dbdata: dbdata:
prometheusdata:

View file

@ -0,0 +1,220 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 1,
"links": [],
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "ee5zvwsdjb400f"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"fixedColor": "green",
"mode": "fixed"
},
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
},
"unit": "locale"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 23,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"text": {
"titleSize": 16,
"valueSize": 30
},
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "11.3.2",
"targets": [
{
"disableTextWrap": false,
"editorMode": "code",
"exemplar": false,
"expr": "sum by(department, currency) (application_dbtr_balance{department=~\".+\"})",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"interval": "",
"legendFormat": "{{department}} {{currency}}",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Debitoren - Saldo",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "ee5zvwsdjb400f"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 4
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "11.3.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "ee5zvwsdjb400f"
},
"disableTextWrap": false,
"editorMode": "code",
"exemplar": false,
"expr": "sum by(department) (application_dbtr_balance{department=~\".+\"})",
"fullMetaSearch": false,
"includeNullMetadata": true,
"legendFormat": "__auto",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Kreditor",
"type": "timeseries"
}
],
"preload": false,
"schemaVersion": 40,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "AGL",
"uid": "ce5zwc5vzt5hce",
"version": 14,
"weekStart": ""
}

View file

@ -0,0 +1,22 @@
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'imixs-monitor'
scrape_configs:
# Prometheus itself
# - job_name: 'prometheus'
# scrape_interval: 5s
# static_configs:
# - targets: ['localhost:9090']
# Imixs-Office-Workflow Job (Wildfly Metrics)
- job_name: 'imixs'
scrape_interval: 60s
metrics_path: /metrics
static_configs:
- targets: ['app:9990']

View file

@ -34,8 +34,9 @@ public class InvoiceOutgoingPlugin extends AbstractPlugin {
String dbtrNumber = workitem.getItemValueString("dbtr.number"); String dbtrNumber = workitem.getItemValueString("dbtr.number");
ItemCollection debitor = kreditorService.findDebitor(dbtrNumber); ItemCollection debitor = kreditorService.findDebitor(dbtrNumber);
if (debitor != null) { if (debitor != null) {
// update mail // update mail and country
workitem.setItemValue("dbtr.mail", debitor.getItemValueString("cdtr.mail")); workitem.setItemValue("dbtr.mail", debitor.getItemValueString("cdtr.mail"));
workitem.setItemValue("invoice.country", debitor.getItemValueString("_vendor_country"));
} }
String img = ""; String img = "";

View file

@ -361,6 +361,8 @@ public class InvoicePlugin extends AbstractPlugin {
// search the kreditor // search the kreditor
ItemCollection cdtr = kreditorService.findCreditorDebitor(cdtrNumber); ItemCollection cdtr = kreditorService.findCreditorDebitor(cdtrNumber);
if (cdtr != null) { if (cdtr != null) {
// update country
workitem.setItemValue("invoice.country", cdtr.getItemValueString("_vendor_country"));
// Prüfen ob wir die IBAN schon kennen // Prüfen ob wir die IBAN schon kennen
if (iban.equals(cdtr.getItemValueString("cdtr.iban")) && bic.equals(cdtr.getItemValueString("cdtr.bic"))) { if (iban.equals(cdtr.getItemValueString("cdtr.iban")) && bic.equals(cdtr.getItemValueString("cdtr.bic"))) {
return; return;

View file

@ -496,7 +496,7 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
// Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese // Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese
// Rechnung // Rechnung
String country = dbtrItemCol.getItemValueString("_VENDOR_COUNTRY"); String country = dbtrItemCol.getItemValueString("_VENDOR_COUNTRY");
datevWorkitem.setItemValue("dbtr.country", country); datevWorkitem.setItemValue("invoice.country", country);
if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch") || country.equalsIgnoreCase("at")) { if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch") || country.equalsIgnoreCase("at")) {
datevWorkitem.setItemValue("invoice.language", "DE"); datevWorkitem.setItemValue("invoice.language", "DE");
} else { } else {
@ -506,27 +506,6 @@ public class DatevCargosoftImportAdapter implements SignalAdapter {
// Jezt noch das Space mapping // Jezt noch das Space mapping
mahnlaufService.mapInvoiceTextToSpace(datevWorkitem, spacePosMappings); mahnlaufService.mapInvoiceTextToSpace(datevWorkitem, spacePosMappings);
// // dazu kucken wir in alle spaces den config wert 'pos.mapping'
// String text = datevWorkitem.getItemValueString("invoice.text");
// if (!text.isEmpty()) {
// boolean found = false;
// for (Map.Entry<String, List<String>> entry : spacePosMappings.entrySet()) {
// List<String> expressionsList = entry.getValue();
// for (String expr : expressionsList) {
// Pattern p = Pattern.compile(expr);
// Matcher m = p.matcher(text);
// if (m.find()) {
// // we have a match
// datevWorkitem.setItemValue("space.ref", entry.getKey());
// found = true;
// break;
// }
// }
// if (found) {
// break;
// }
// }
// }
// Processe die Invoice // Processe die Invoice
datevWorkitem.model(INITIAL_MODEL_VERSION_INVOICE).task(INITIAL_TASK_ID_INVOICE) datevWorkitem.model(INITIAL_MODEL_VERSION_INVOICE).task(INITIAL_TASK_ID_INVOICE)

View file

@ -3,7 +3,6 @@ package com.alexanderlogistics.metrics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -20,6 +19,7 @@ import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.QueryException; import org.imixs.workflow.exceptions.QueryException;
import com.alexanderlogistics.InvoiceUtil; import com.alexanderlogistics.InvoiceUtil;
import com.alexanderlogistics.KreditorDebitorService;
import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
@ -30,7 +30,7 @@ import jakarta.inject.Inject;
/** /**
* Dieser Service reagiert auch ProcessingEvents und speichert/aktualisiert die * Dieser Service reagiert auch ProcessingEvents und speichert/aktualisiert die
* zugehörige Creditor Metric Entity (type=metric.debitor). * zugehörige Creditor Metric Entity (type=metric.creditor).
* <p> * <p>
* Beim Rechnungseingang gilt eine Rechnung als Bezahlt wenn diese einen finalen * Beim Rechnungseingang gilt eine Rechnung als Bezahlt wenn diese einen finalen
* Status erreicht hat (>=5800) * Status erreicht hat (>=5800)
@ -68,6 +68,9 @@ public class MetricCreditorService {
@Inject @Inject
DocumentService documentService; DocumentService documentService;
@Inject
KreditorDebitorService kreditorDebitorService;
@Inject @Inject
MetricDataService metricDataService; MetricDataService metricDataService;
@ -139,7 +142,7 @@ public class MetricCreditorService {
* @throws PluginException * @throws PluginException
*/ */
public ItemCollection getMetricByInvoice(ItemCollection invoice) throws PluginException { public ItemCollection getMetricByInvoice(ItemCollection invoice) throws PluginException {
String metricKey = buildKeyByInvoice(invoice); String metricKey = MetricDataService.buildKeyByInvoice(invoice);
ItemCollection metricData = metricCache.get(metricKey); ItemCollection metricData = metricCache.get(metricKey);
if (metricData == null) { if (metricData == null) {
metricData = loadMetric(invoice); metricData = loadMetric(invoice);
@ -180,40 +183,6 @@ public class MetricCreditorService {
return Collections.unmodifiableList(new ArrayList<>(metricCache.keySet())); return Collections.unmodifiableList(new ArrayList<>(metricCache.keySet()));
} }
/**
* Builds the metric hash key by the invoice attributes. The returned key can be
* used for caching the metric.
*
* @param invoice - The invoice ItemCollection containing the necessary
* attributes
* @return A unique hash string based on the invoice attributes
* @throws IllegalArgumentException if the invoice is null
*/
private static String buildKeyByInvoice(ItemCollection invoice) {
// Validate input
Objects.requireNonNull(invoice, "Invoice must not be null");
String cdtrNumber = invoice.getItemValueString("cdtr.number");
if (cdtrNumber.startsWith("D") || cdtrNumber.startsWith("K")) {
cdtrNumber = cdtrNumber.substring(1);
}
String cdtrName = invoice.getItemValueString("cdtr.name");
String currency = invoice.getItemValueString("invoice.currency");
String department = invoice.getItemValueString("space.name");
// Concatenate the values and create a hash
String combinedValue = String.format("%s::%s::%s::%s",
cdtrNumber,
cdtrName,
currency,
department);
String hash = String.valueOf(combinedValue.hashCode());
// a hash can start with '-' which we need to avoid and create a alphanumeric
// key instead!
return "HASH" + hash;
}
/** /**
* This method loads a metric entity for a given invoice workitem. If no metric * This method loads a metric entity for a given invoice workitem. If no metric
* entity exits, the method * entity exits, the method
@ -224,20 +193,20 @@ public class MetricCreditorService {
* @throws PluginException * @throws PluginException
*/ */
private ItemCollection loadMetric(ItemCollection invoice) throws PluginException { private ItemCollection loadMetric(ItemCollection invoice) throws PluginException {
ItemCollection debitorMetric = null; ItemCollection creditorMetric = null;
try { try {
String metricKey = buildKeyByInvoice(invoice); String metricKey = MetricDataService.buildKeyByInvoice(invoice);
String query = "(type:" + TYPE_METRIC_CREDITOR + ") AND (name:" + metricKey + ")"; String query = "(type:" + TYPE_METRIC_CREDITOR + ") AND (name:" + metricKey + ")";
List<ItemCollection> result = documentService.find(query, 1, 0, "$modified", true); List<ItemCollection> result = documentService.find(query, 1, 0, "$modified", true);
if (result.size() > 0) { if (result.size() > 0) {
debitorMetric = result.get(0); creditorMetric = result.get(0);
} }
} catch (IllegalArgumentException | QueryException e) { } catch (IllegalArgumentException | QueryException e) {
throw new PluginException(PluginException.class.getName(), throw new PluginException(PluginException.class.getName(),
"Failed to load metric object for invoice " + invoice.getUniqueID() + ": ", e.getMessage(), e); "Failed to load metric object for invoice " + invoice.getUniqueID() + ": ", e.getMessage(), e);
} }
return debitorMetric; return creditorMetric;
} }
/** /**
@ -250,41 +219,35 @@ public class MetricCreditorService {
* @return * @return
*/ */
private ItemCollection createMetaData(ItemCollection invoice) { private ItemCollection createMetaData(ItemCollection invoice) {
String key = buildKeyByInvoice(invoice); String key = MetricDataService.buildKeyByInvoice(invoice);
ItemCollection metricData = new ItemCollection(); ItemCollection metricData = new ItemCollection();
metricData.setType(TYPE_METRIC_CREDITOR); metricData.setType(TYPE_METRIC_CREDITOR);
metricData.setItemValue("name", key); metricData.setItemValue("name", key);
metricData.setItemValue("country", invoice.getItemValueString("invoice.country"));
String cdtrNumber = invoice.getItemValueString("cdtr.number"); metricData.setItemValue("currency", invoice.getItemValueString("invoice.currency"));
if (cdtrNumber.startsWith("D") || cdtrNumber.startsWith("K")) { metricData.setItemValue("department", invoice.getItemValueString("space.name"));
cdtrNumber = cdtrNumber.substring(1);
}
metricData.setItemValue("cdtr.number", cdtrNumber);
metricData.setItemValue("cdtr.name", invoice.getItemValueString("cdtr.name"));
metricData.setItemValue("invoice.currency", invoice.getItemValueString("invoice.currency"));
metricData.setItemValue("space.name", invoice.getItemValueString("space.name"));
return metricData; return metricData;
} }
/** /**
* Helper method to register a gauge for a debitor * Helper method to register a gauge for a creditor
* *
* @param cdtrNumber - the creditor number * @param cdtrNumber - the creditor number
* @param cdtrName - the creditor name * @param cdtrName - the creditor name
*/ */
private void updateGauge(ItemCollection metricData) { private void updateGauge(ItemCollection metricData) {
String cdtrNumber = metricData.getItemValueString("cdtr.number");
String cdtrName = metricData.getItemValueString("cdtr.name");
String metricKey = metricData.getItemValueString("name"); String metricKey = metricData.getItemValueString("name");
String country = metricData.getItemValueString("country");
String department = metricData.getItemValueString("department");
String currency = metricData.getItemValueString("currency");
// Prüfen ob Gauge bereits registriert ist // Prüfen ob Gauge bereits registriert ist
if (registeredGauges.add(metricKey)) { // returns true newly added if (registeredGauges.add(metricKey)) { // returns true newly added
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
tags.add(new Tag("type", "cdtr")); tags.add(new Tag("type", "cdtr"));
tags.add(new Tag("number", cdtrNumber)); tags.add(new Tag("country", country));
tags.add(new Tag("name", cdtrName)); tags.add(new Tag("currency", currency));
tags.add(new Tag("currency", metricData.getItemValueString("invoice.currency"))); tags.add(new Tag("department", department));
tags.add(new Tag("department", metricData.getItemValueString("space.name"))); logger.info("register new metric for department: " + department +
logger.info("register new metric for creditor: " + cdtrNumber +
", " + metricData.getItemValueString(ITEM_SALDO) + ", " + metricData.getItemValueString(ITEM_SALDO) +
" " + metricData.getItemValueString("invoice.currency")); " " + metricData.getItemValueString("invoice.currency"));
Metadata metadata = Metadata.builder() Metadata metadata = Metadata.builder()
@ -297,7 +260,7 @@ public class MetricCreditorService {
() -> metricCache.get(metricKey).getItemValueDouble(ITEM_SALDO), () -> metricCache.get(metricKey).getItemValueDouble(ITEM_SALDO),
tags.toArray(new Tag[0])); tags.toArray(new Tag[0]));
} else { } else {
logger.fine("Gauge already registered for creditor: " + cdtrNumber); logger.fine("Cdtr Gauge already registered for department: " + department);
} }
} }
@ -343,13 +306,10 @@ public class MetricCreditorService {
// vorgang ist archiviert oder gelöscht worden => saldo = 0! // vorgang ist archiviert oder gelöscht worden => saldo = 0!
invoiceTotal = 0.0; invoiceTotal = 0.0;
} }
// is the metric new? // subtract only if metric saldo exists
if (!metricData.hasItem(ITEM_SALDO)) { if (metricData.hasItem(ITEM_SALDO)) {
// init metric with the total value!
metricData.setItemValue(ITEM_SALDO, invoiceTotal);
} else {
double lastSaldo = metricData.getItemValueDouble(ITEM_SALDO); double lastSaldo = metricData.getItemValueDouble(ITEM_SALDO);
metricData.setItemValue(ITEM_SALDO, lastSaldo - invoiceTotal); metricData.setItemValue(ITEM_SALDO, InvoiceUtil.round(lastSaldo - invoiceTotal));
} }
} }

View file

@ -1,5 +1,7 @@
package com.alexanderlogistics.metrics; package com.alexanderlogistics.metrics;
import java.util.Objects;
import org.imixs.workflow.ItemCollection; import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.DocumentService; import org.imixs.workflow.engine.DocumentService;
@ -46,4 +48,32 @@ public class MetricDataService {
return dirtyInvoice; return dirtyInvoice;
} }
/**
* Builds the metric hash key by the invoice attributes. The returned key can be
* used for caching the metric.
*
* @param invoice - The invoice ItemCollection containing the necessary
* attributes
* @return A unique hash string based on the invoice attributes
* @throws IllegalArgumentException if the invoice is null
*/
public static String buildKeyByInvoice(ItemCollection invoice) {
// Validate input
Objects.requireNonNull(invoice, "Invoice must not be null");
String country = invoice.getItemValueString("invoice.country");
String currency = invoice.getItemValueString("invoice.currency");
String department = invoice.getItemValueString("space.name");
// Concatenate the values and create a hash
String combinedValue = String.format("%s::%s::%s",
country,
currency,
department);
String hash = String.valueOf(combinedValue.hashCode());
// a hash can start with '-' which we need to avoid and create a alphanumeric
// key instead!
return "HASH" + hash;
}
} }

View file

@ -3,7 +3,6 @@ package com.alexanderlogistics.metrics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -133,7 +132,7 @@ public class MetricDebitorService {
* @throws PluginException * @throws PluginException
*/ */
public ItemCollection getMetricByInvoice(ItemCollection invoice) throws PluginException { public ItemCollection getMetricByInvoice(ItemCollection invoice) throws PluginException {
String metricKey = buildKeyByInvoice(invoice); String metricKey = MetricDataService.buildKeyByInvoice(invoice);
ItemCollection metricData = metricCache.get(metricKey); ItemCollection metricData = metricCache.get(metricKey);
if (metricData == null) { if (metricData == null) {
metricData = loadMetric(invoice); metricData = loadMetric(invoice);
@ -174,37 +173,6 @@ public class MetricDebitorService {
return Collections.unmodifiableList(new ArrayList<>(metricCache.keySet())); return Collections.unmodifiableList(new ArrayList<>(metricCache.keySet()));
} }
/**
* Builds the metric hash key by the invoice attributes. The returned key can be
* used for caching the metric.
*
* @param invoice - The invoice ItemCollection containing the necessary
* attributes
* @return A unique hash string based on the invoice attributes
* @throws IllegalArgumentException if the invoice is null
*/
private static String buildKeyByInvoice(ItemCollection invoice) {
// Validate input
Objects.requireNonNull(invoice, "Invoice must not be null");
String dbtrNumber = invoice.getItemValueString("dbtr.number");
String dbtrName = invoice.getItemValueString("dbtr.name");
String currency = invoice.getItemValueString("invoice.currency");
String department = invoice.getItemValueString("space.name");
// Concatenate the values and create a hash
String combinedValue = String.format("%s::%s::%s::%s",
dbtrNumber,
dbtrName,
currency,
department);
String hash = String.valueOf(combinedValue.hashCode());
// a hash can start with '-' which we need to avoid and create a alphanumeric
// key instead!
return "HASH" + hash;
}
/** /**
* This method loads a metric entity for a given invoice workitem. If no metric * This method loads a metric entity for a given invoice workitem. If no metric
* entity exits, the method * entity exits, the method
@ -217,7 +185,7 @@ public class MetricDebitorService {
private ItemCollection loadMetric(ItemCollection invoice) throws PluginException { private ItemCollection loadMetric(ItemCollection invoice) throws PluginException {
ItemCollection debitorMetric = null; ItemCollection debitorMetric = null;
try { try {
String metricKey = buildKeyByInvoice(invoice); String metricKey = MetricDataService.buildKeyByInvoice(invoice);
String query = "(type:" + TYPE_METRIC_DEBITOR + ") AND (name:" + metricKey + ")"; String query = "(type:" + TYPE_METRIC_DEBITOR + ") AND (name:" + metricKey + ")";
List<ItemCollection> result = documentService.find(query, 1, 0, "$modified", true); List<ItemCollection> result = documentService.find(query, 1, 0, "$modified", true);
if (result.size() > 0) { if (result.size() > 0) {
@ -240,38 +208,38 @@ public class MetricDebitorService {
* @return * @return
*/ */
private ItemCollection createMetaData(ItemCollection invoice) { private ItemCollection createMetaData(ItemCollection invoice) {
String key = buildKeyByInvoice(invoice); String key = MetricDataService.buildKeyByInvoice(invoice);
ItemCollection metricData = new ItemCollection(); ItemCollection metricData = new ItemCollection();
metricData.setType(TYPE_METRIC_DEBITOR); metricData.setType(TYPE_METRIC_DEBITOR);
metricData.setItemValue("name", key); metricData.setItemValue("name", key);
metricData.setItemValue("dbtr.number", invoice.getItemValueString("dbtr.number")); metricData.setItemValue("country", invoice.getItemValueString("invoice.country"));
metricData.setItemValue("dbtr.name", invoice.getItemValueString("dbtr.name")); metricData.setItemValue("currency", invoice.getItemValueString("invoice.currency"));
metricData.setItemValue("invoice.currency", invoice.getItemValueString("invoice.currency")); metricData.setItemValue("department", invoice.getItemValueString("space.name"));
metricData.setItemValue("space.name", invoice.getItemValueString("space.name"));
return metricData; return metricData;
} }
/** /**
* Helper method to register a gauge for a debitor * Helper method to register a gauge for a debitor
* *
* @param dbtrNumber - the debitor number * @param metricData - the metricData ItemCollection
* @param dbtrName - the debitor name
*/ */
private void updateGauge(ItemCollection metricData) { private void updateGauge(ItemCollection metricData) {
String dbtrNumber = metricData.getItemValueString("dbtr.number"); // String dbtrNumber = metricData.getItemValueString("dbtr.number");
String dbtrName = metricData.getItemValueString("dbtr.name"); // String dbtrName = metricData.getItemValueString("dbtr.name");
String country = metricData.getItemValueString("country");
String department = metricData.getItemValueString("department");
String currency = metricData.getItemValueString("currency");
String metricKey = metricData.getItemValueString("name"); String metricKey = metricData.getItemValueString("name");
// Prüfen ob Gauge bereits registriert ist // Prüfen ob Gauge bereits registriert ist
if (registeredGauges.add(metricKey)) { // returns true newly added if (registeredGauges.add(metricKey)) { // returns true newly added
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
tags.add(new Tag("type", "dbtr")); tags.add(new Tag("type", "dbtr"));
tags.add(new Tag("number", dbtrNumber)); tags.add(new Tag("country", country));
tags.add(new Tag("name", dbtrName)); tags.add(new Tag("currency", currency));
tags.add(new Tag("currency", metricData.getItemValueString("invoice.currency"))); tags.add(new Tag("department", department));
tags.add(new Tag("department", metricData.getItemValueString("space.name"))); logger.info("register new metric for department: " + department +
logger.info("register new metric for debitor: " + dbtrNumber +
", " + metricData.getItemValueString(ITEM_SALDO) + ", " + metricData.getItemValueString(ITEM_SALDO) +
" " + metricData.getItemValueString("invoice.currency")); " " + currency);
Metadata metadata = Metadata.builder() Metadata metadata = Metadata.builder()
.withName("dbtr.balance") .withName("dbtr.balance")
.withDescription("Debitor Balance") .withDescription("Debitor Balance")
@ -282,7 +250,7 @@ public class MetricDebitorService {
() -> metricCache.get(metricKey).getItemValueDouble(ITEM_SALDO), () -> metricCache.get(metricKey).getItemValueDouble(ITEM_SALDO),
tags.toArray(new Tag[0])); tags.toArray(new Tag[0]));
} else { } else {
logger.fine("Gauge already registered for debitor: " + dbtrNumber); logger.fine("Gauge already registered for department: " + department);
} }
} }
@ -328,11 +296,8 @@ public class MetricDebitorService {
// vorgang ist archiviert oder gelöscht worden => saldo = 0! // vorgang ist archiviert oder gelöscht worden => saldo = 0!
invoiceTotal = 0.0; invoiceTotal = 0.0;
} }
// is the metric new? // subtract only if metric saldo exists
if (!metricData.hasItem(ITEM_SALDO)) { if (metricData.hasItem(ITEM_SALDO)) {
// init metric with the total value!
metricData.setItemValue(ITEM_SALDO, InvoiceUtil.round(invoiceTotal));
} else {
double lastSaldo = metricData.getItemValueDouble(ITEM_SALDO); double lastSaldo = metricData.getItemValueDouble(ITEM_SALDO);
metricData.setItemValue(ITEM_SALDO, InvoiceUtil.round(lastSaldo - invoiceTotal)); metricData.setItemValue(ITEM_SALDO, InvoiceUtil.round(lastSaldo - invoiceTotal));
} }

View file

@ -426,7 +426,7 @@ public class CargosoftXMLEAkteImportService {
// Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese // Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese
// Rechnung // Rechnung
String country = cdtr.getItemValueString("_VENDOR_COUNTRY"); String country = cdtr.getItemValueString("_VENDOR_COUNTRY");
workitem.setItemValue("cdtr.country", country); workitem.setItemValue("invoice.country", country);
if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch") if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch")
|| country.equalsIgnoreCase("at")) { || country.equalsIgnoreCase("at")) {
workitem.setItemValue("invoice.language", "DE"); workitem.setItemValue("invoice.language", "DE");

View file

@ -457,7 +457,7 @@ public class CargosoftXMLInvoiceImportService {
// Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese // Anhand der Creditoren Stammdaten errrechnen wir die Sprache für diese
// Rechnung // Rechnung
String country = dbtr.getItemValueString("_VENDOR_COUNTRY"); String country = dbtr.getItemValueString("_VENDOR_COUNTRY");
workitem.setItemValue("dbtr.country", country); workitem.setItemValue("invoice.country", country);
if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch") if (country.equalsIgnoreCase("de") || country.equalsIgnoreCase("ch")
|| country.equalsIgnoreCase("at")) { || country.equalsIgnoreCase("at")) {
workitem.setItemValue("invoice.language", "DE"); workitem.setItemValue("invoice.language", "DE");