workin on document creation: frontend work

This commit is contained in:
2025-07-09 23:49:01 +02:00
parent 003899f75d
commit d68dc991d0
11 changed files with 271 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ public class Constants {
private Constants(){}
public static final Pattern POST_CODE = compile("(.*\\w+.*)\n(.*\\d+.*)\n(\\d{5}) (\\w+)",DOTALL);
public static final String CONTACTS = "contacts";
public static final String CUSTOMER_NUMBER_PREFIX = "customer_number_prefix";
public static final String DECIMAL_SEPARATOR = "decimal_separator";
@@ -77,7 +78,6 @@ public class Constants {
public static final String PATH_ADD_TIME = "add_time";
public static final String PATH_COMPANIES = "companies";
public static final String PATH_COMPANY = "company";
public static final String PATH_CONTACTS = "contacts";
public static final String PATH_DOCUMENT = "document";
public static final String PATH_PDF = "pdf";
public static final String PATH_POSITIONS = "positions";
@@ -94,4 +94,5 @@ public class Constants {
public static final String COMPANIES = "companies";
public static final String COMPANY = "company";
public static final String CUSTOMERS = "customers";
}

View File

@@ -5,8 +5,7 @@ import static de.srsoftware.tools.MimeType.MIME_FORM_URL;
import static de.srsoftware.umbrella.core.Constants.ERROR_MISSING_FIELD;
import static de.srsoftware.umbrella.core.Paths.LIST;
import static de.srsoftware.umbrella.core.Util.request;
import static de.srsoftware.umbrella.documents.Constants.COMPANIES;
import static de.srsoftware.umbrella.documents.Constants.COMPANY;
import static de.srsoftware.umbrella.documents.Constants.*;
import static java.lang.System.Logger.Level.WARNING;
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
@@ -23,6 +22,10 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import de.srsoftware.umbrella.documents.model.Type;
import org.json.JSONArray;
import org.json.JSONObject;
public class DocumentApi extends BaseHandler {
@@ -47,6 +50,8 @@ public class DocumentApi extends BaseHandler {
var head = path.pop();
return switch (head){
case COMPANIES -> getCompanies(ex,user.get(),token.orElse(null));
case CONTACTS -> getContacts(ex,user.get(),token.orElse(null));
case PATH_TYPES -> getDocTypes(ex);
case null, default -> super.doGet(path,ex);
};
} catch (UmbrellaException e) {
@@ -75,6 +80,15 @@ public class DocumentApi extends BaseHandler {
return sendContent(ex,getLegacyCompanies(ex,user,token));
}
private boolean getContacts(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException {
return sendContent(ex,getLegacyContacts(ex,user,token));
}
private boolean getDocTypes(HttpExchange ex) throws UmbrellaException, IOException {
var types = db.listTypes();
var map = types.values().stream().collect(Collectors.toMap(Type::id, Type::name));
return sendContent(ex,map);
}
private HashMap<Long, Map<String, Object>> getLegacyCompanies(HttpExchange ex, UmbrellaUser umbrellaUser, Token token) throws IOException, UmbrellaException {
var location = config.get("company.baseUrl").map(s -> s+"/json").orElseThrow(() -> new UmbrellaException(500,"umbrella.modules.company.baseUrl not configured!"));
var resp = request(location, token.asMap(),MIME_FORM_URL,null);
@@ -84,6 +98,13 @@ public class DocumentApi extends BaseHandler {
return result;
}
private JSONArray getLegacyContacts(HttpExchange ex, UmbrellaUser umbrellaUser, Token token) throws IOException, UmbrellaException {
var location = config.get("contact.baseUrl").map(s -> s+"/json").orElseThrow(() -> new UmbrellaException(500,"umbrella.modules.company.baseUrl not configured!"));
var resp = request(location, token.asMap(),MIME_FORM_URL,null);
if (!(resp instanceof String s && s.startsWith("["))) throw new UmbrellaException(500,"{0} did not return JSON Array!",location);
return new JSONArray(s);
}
private boolean listDocuments(HttpExchange ex, UmbrellaUser user, Token token) throws UmbrellaException {
try {
var json = json(ex);

View File

@@ -264,8 +264,8 @@ public final class Document implements Mappable {
return Map.of(
ID, id,
NUMBER, number,
"type", format("<? {0} ?>", type.name()),
STATE, Map.of(NAME,format("<? {0} ?>", state),ID,state.code),
"type", type.name(),
STATE, Map.of(NAME,state.toString(),ID,state.code),
DATE, date,
FIELD_CURRENCY, currency,
FIELD_CUSTOMER, customer.toMap(),