Merge branch 'feature/translation' into dev
This commit is contained in:
@@ -4,9 +4,10 @@ package de.srsoftware.umbrella.core;
|
||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||
import static de.srsoftware.tools.jdbc.Query.replaceInto;
|
||||
import static de.srsoftware.tools.jdbc.Query.update;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.TABLE_SETTINGS;
|
||||
import static java.lang.System.Logger.Level.ERROR;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.TABLE_SETTINGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.failedToCreateTable;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.failedToReadFromTable;
|
||||
import static java.lang.System.Logger.Level.INFO;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
@@ -37,8 +38,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_SETTINGS,e);
|
||||
throw new RuntimeException(e);
|
||||
throw failedToCreateTable(TABLE_SETTINGS).causedBy(e);
|
||||
}
|
||||
|
||||
var version = 0;
|
||||
@@ -49,8 +49,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
|
||||
return version;
|
||||
} catch (SQLException e) {
|
||||
LOG.log(ERROR,ERROR_READ_TABLE,DB_VERSION,TABLE_SETTINGS,e);
|
||||
throw new RuntimeException(e);
|
||||
throw failedToReadFromTable(DB_VERSION,TABLE_SETTINGS).causedBy(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.nullable;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.translator;
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.net.HttpURLConnection.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.tools.Path;
|
||||
@@ -74,13 +72,10 @@ public abstract class BaseHandler extends PathHandler {
|
||||
|
||||
public boolean send(HttpExchange ex, UmbrellaException e) throws IOException {
|
||||
var cause = e.getCause();
|
||||
String lang = languages(ex).stream().findFirst().orElse(null);
|
||||
var translatedMessage = translator().translate(lang,e.getMessage());
|
||||
if (cause != null){
|
||||
var msg = "en".equals(lang) ? translatedMessage : translator().translate("en",e.getMessage());
|
||||
LOG.log(ERROR,format(msg,e.fills()),cause);
|
||||
}
|
||||
return sendContent(ex,e.statusCode(),format(translatedMessage,e.fills()));
|
||||
String lang = languages(ex).stream().findFirst().orElse("en");
|
||||
var translatedMessage = e.message().translate(lang);
|
||||
if (cause != null) LOG.log(ERROR,translatedMessage,cause);
|
||||
return sendContent(ex,e.statusCode(),translatedMessage);
|
||||
}
|
||||
|
||||
public boolean unauthorized(HttpExchange ex) throws IOException {
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private Constants(){}
|
||||
|
||||
public static final String ACTION = "action";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String ALLOWED_STATES = "allowed_states";
|
||||
public static final String ATTACHMENTS = "attachments";
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
public static final String BODY = "body";
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
|
||||
public static final String CACHE_CONTROL = "Cache-Control";
|
||||
public static final String CODE = "code";
|
||||
public static final String COMMENT = "comment";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String COMPANY_ID = "company_id";
|
||||
public static final String CONNECTION = "Connection";
|
||||
public static final String CONTENT = "content";
|
||||
public static final String CONTENT_DISPOSITION = "Content-Disposition";
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
public static final String CUSTOMER_NUMBER_PREFIX = "customer_number_prefix";
|
||||
|
||||
public static final String DATA = "data";
|
||||
public static final String DB_VERSION = "db_version";
|
||||
public static final String DATE = "date";
|
||||
public static final String DECIMALS = "decimals";
|
||||
public static final String DECIMAL_SEPARATOR = "decimal_separator";
|
||||
public static final String DELETED = "deleted";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String DOMAIN = "domain";
|
||||
public static final String DROP_MEMBER = "drop_member";
|
||||
public static final String DUE_DATE = "due_date";
|
||||
public static final String DURATION = "duration";
|
||||
|
||||
public static final String EMAIL = "email";
|
||||
public static final String END_TIME = "end_time";
|
||||
public static final String ENTITY_ID = "entity_id";
|
||||
public static final String ERROR_FAILED_CREATE_TABLE = "Failed to create \"{0}\" table!";
|
||||
public static final String ERROR_INVALID_FIELD = "Expected {0} to be {1}!";
|
||||
public static final String ERROR_MISSING_CONFIG = "Config is missing value for {0}!";
|
||||
public static final String ERROR_MISSING_FIELD = "Json is missing {0} field!";
|
||||
public static final String ERROR_READ_TABLE = "Failed to read {0} from {1} table";
|
||||
public static final String EST_TIME = "est_time";
|
||||
public static final String ESTIMATED_TIME = "estimated_time";
|
||||
public static final String EXPIRATION = "expiration";
|
||||
|
||||
public static final String FALLBACK_LANG = "de";
|
||||
|
||||
public static final String FROM = "from";
|
||||
public static final String FULLTEXT = "fulltext";
|
||||
|
||||
public static final String GET = "GET";
|
||||
public static final String GUEST_ALLOWED = "guest_allowed";
|
||||
|
||||
public static final String HASH = "hash";
|
||||
|
||||
public static final String ID = "id";
|
||||
|
||||
public static final String JSONARRAY = "json array";
|
||||
public static final String JSONOBJECT = "json object";
|
||||
|
||||
public static final String KEEP_ALIVE = "keep-alive";
|
||||
public static final String KEY = "key";
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
public static final String LAST_CUSTOMER_NUMBER = "last_customer_number";
|
||||
public static final String LIMIT = "limit";
|
||||
public static final String LOCATION = "location";
|
||||
public static final String LOCATION_ID = "location_id";
|
||||
public static final String LOGIN = "login";
|
||||
|
||||
public static final String MEMBERS = "members";
|
||||
public static final String MESSAGES = "messages";
|
||||
public static final String MODULE = "module";
|
||||
|
||||
public static final String NAME = "name";
|
||||
public static final String NEW_MEMBER = "new_member";
|
||||
public static final String MIME = "mime";
|
||||
public static final String NO_CACHE = "no-cache";
|
||||
public static final String NO_INDEX = "no_index";
|
||||
public static final String NONE = "none";
|
||||
public static final String NOTE = "note";
|
||||
public static final String NUMBER = "number";
|
||||
|
||||
public static final String OFFSET = "offset";
|
||||
public static final String OPTIONAL = "optional";
|
||||
public static final String OWNER = "owner";
|
||||
public static final String OWNER_NUMBER = "owner_number";
|
||||
|
||||
public static final String PARENT_LOCATION_ID = "parent_location_id";
|
||||
public static final String PARENT_TASK_ID = "parent_task_id";
|
||||
public static final String PASS = "pass";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PATH = "path";
|
||||
public static final String PERMISSION = "permission";
|
||||
public static final String POST = "POST";
|
||||
public static final String PRIORITY = "priority";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
public static final String RECEIVERS = "receivers";
|
||||
public static final String REDIRECT = "redirect";
|
||||
public static final String RENDERED = "rendered";
|
||||
public static final String REQUIRED_TASKS_IDS = "required_tasks_ids";
|
||||
|
||||
public static final String SENDER = "sender";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SHOW_CLOSED = "show_closed";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String START_DATE = "start_date";
|
||||
public static final String START_TIME = "start_time";
|
||||
public static final String STATE = "state";
|
||||
public static final String STATUS = "status";
|
||||
public static final String STATUS_CODE = "code";
|
||||
public static final String STRING = "string";
|
||||
public static final String SUBJECT = "subject";
|
||||
|
||||
public static final String TABLE_SETTINGS = "settings";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TAG_COLORS = "tag_colors";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASK_IDS = "task_ids";
|
||||
public static final String TAX = "tax";
|
||||
public static final String TAX_RATE = "tax_rate";
|
||||
public static final String TEMPLATE = "template";
|
||||
public static final String TEXT = "text";
|
||||
public static final String THOUSANDS_SEPARATOR = "thousands_separator";
|
||||
public static final String THEME = "theme";
|
||||
public static final String TITLE = "title";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
public static final String TO = "to";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String TOTAL_PRIO = "total_prio";
|
||||
public static final String TYPE = "type";
|
||||
|
||||
public static final String UMBRELLA = "Umbrella";
|
||||
public static final String UNIT = "unit";
|
||||
public static final String URI = "uri";
|
||||
public static final String URL = "url";
|
||||
public static final String USER = "user";
|
||||
public static final String USERS = "users";
|
||||
public static final String USER_ID = "user_id";
|
||||
public static final String USER_LIST = "user_list";
|
||||
public static final String USES = "uses";
|
||||
public static final String UTF8 = UTF_8.displayName();
|
||||
|
||||
public static final String VALUE = "value";
|
||||
public static final String VCARD = "vcard";
|
||||
public static final String VERSION = "version";
|
||||
public static final String VERSIONS = "versions";
|
||||
|
||||
public static final String WIKI = "wiki";
|
||||
}
|
||||
@@ -2,38 +2,42 @@
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
public class Errors {
|
||||
public static final String FAILED_TO_ADD_COLUMN = "failed_to_add_column";
|
||||
public static final String FAILED_TO_ADD_PROPERTY_TO_ITEM = "failed_to_add_prop_to_item";
|
||||
public static final String FAILED_TO_ASSIGN_USER_TO_COMPANY = "failed_to_assign_user_to_company";
|
||||
public static final String FAILED_TO_ASSIGN_CONTACT_TO_USER = "failed_to_assign_contact_to_user";
|
||||
public static final String FAILED_TO_CHECK_ENTITY_AVAILABLE = "failed_to_check_entity_available";
|
||||
public static final String FAILED_TO_CHECK_FILE_PERMISSIONS = "failed_to_check_file_permissions";
|
||||
public static final String FAILED_TO_CREATE_STATE = "failed_to_create_state";
|
||||
public static final String FAILED_TO_CREATE_TABLE = "failed_to_create_table";
|
||||
public static final String FAILED_TO_DROP_ENTITY = "failed_to_drop_entity";
|
||||
public static final String FAILED_TO_DROP_ENTITY_OF_ENTITY = "failed_to_drop_entity_from_entity";
|
||||
public static final String FAILED_TO_DROP_NOTES = "failed_to_drop_notes";
|
||||
public static final String FAILED_TO_GET_FREE_ID = "failed_to_get_free_id";
|
||||
public static final String FAILED_TO_LIST_ENTITIES = "failed_to_list_entities";
|
||||
public static final String FAILED_TO_LOAD_CHILD_LOCATIONS = "failed_to_load_child_locations";
|
||||
public static final String FAILED_TO_LOAD_ENTITY_MEMBERS = "failed_to_load_entity_members";
|
||||
public static final String FAILED_TO_LOAD_ENTITIES_OF_OWNER = "failed_to_load_entities_of_owner";
|
||||
public static final String FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS = "failed_to_load_customer_number_settings";
|
||||
public static final String FAILED_TO_LOAD_CUSTOMER_PRICE = "failed_to_load_customer_price";
|
||||
public static final String FAILED_TO_LOAD_CUSTOMER_SETTINGS = "failed_to_load_customer_settings";
|
||||
public static final String FAILED_TO_LOAD_ENTITY = "failed_to_load_entity";
|
||||
public static final String FAILED_TO_LOAD_ENTITY_BY_ID = "failed_to_load_entity_by_id";
|
||||
public static final String FAILED_TO_LOAD_USER_SETTINGS = "failed_to_load_user_settings";
|
||||
public static final String FAILED_TO_MOVE = "failed_to_move";
|
||||
public static final String FAILED_TO_READ_LAST_DOCID = "failed_to_read_last_docId";
|
||||
public static final String FAILED_TO_SEARCH_DB = "failed_to_search_db";
|
||||
public static final String FAILED_TO_STORE_ENTITY = "failed_to_store_entity";
|
||||
public static final String FAILED_TO_SWITCH_POSITIONS = "failed_to_switch_positions";
|
||||
public static final String FAILED_TO_UPDATE_COLUMN = "failed_to_update_column";
|
||||
public static final String FAILED_TO_UPDATE_ENTITY = "failed_to_update_entity";
|
||||
public static final String FAILED_TO_UPDATE_TABLE = "failed_to_update_table";
|
||||
public static final String MISSING_NEW_ITEM_ID = "missing_new_item_id";
|
||||
public static final String NO_BOOKMARK_FOR_URLID = "no_bookmark_for_urlid";
|
||||
public static final String UNEXPECTED_ITEM_ID_FORMAT = "unexpected_item_id_format";
|
||||
public static final String UNKNOWN_ITEM_LOCATION = "unknown_item_location";
|
||||
public static final String ADDRESS_MISSING = "{object} address does not contain street address / post code / city";
|
||||
|
||||
public static final String FAILED_TO_ADD_COLUMN = "Failed to add {name} column to {table} table";
|
||||
public static final String FAILED_TO_ADD_PROPERTY_TO_ITEM = "Failed to add new property to item {object}";
|
||||
public static final String FAILED_TO_ASSIGN_A_TO_B = "Failed to assign {a} to {b}.";
|
||||
public static final String FAILED_TO_CHECK_ENTITY_AVAILABLE = "Failed to check availability of {object}";
|
||||
public static final String FAILED_TO_CHECK_FILE_PERMISSIONS = "Failed to check file permissions!";
|
||||
public static final String FAILED_TO_CREATE_STATE = "Failed to create custom state!";
|
||||
public static final String FAILED_TO_CREATE_TABLE = "Failed to create table `{name}`";
|
||||
public static final String FAILED_TO_DROP_OBJECT = "Failed to drop {object}!";
|
||||
public static final String FAILED_TO_DROP_ENTITY_OF_ENTITY = "Failed to drop {dropped_type} {object} from {related_type} {related}!";
|
||||
public static final String FAILED_TO_DROP_NOTES = "Failed to delete notes of ({module} {id})";
|
||||
public static final String FAILED_TO_GET_FREE_ID = "Failed to query free ID";
|
||||
public static final String FAILED_TO_LIST_ENTITIES = "Failed to list {type}";
|
||||
public static final String FAILED_TO_LOAD_CHILD_LOCATIONS = "Failed to load child locations for {parent}";
|
||||
public static final String FAILED_TO_LOAD_OBJECT_MEMBERS = "Failed to load members of {object}";
|
||||
public static final String FAILED_TO_LOAD_ENTITIES_OF_OWNER = "Failed to load {type} of {owner}!";
|
||||
public static final String FAILED_TO_LOAD_CUSTOMER_PRICE = "Failed to load customer price (company: {company}, customer: {customer}, item: {item})";
|
||||
public static final String FAILED_TO_LOAD_CUSTOMER_SETTINGS = "Failed to load customer settings (company: {company}, document type: {type})";
|
||||
public static final String FAILED_TO_LOAD_OBJECT = "Failed to load {object}!";
|
||||
public static final String FAILED_TO_LOAD_OBJECT_BY_ID = "Failed to load {object} by id (id)!";
|
||||
public static final String FAILED_TO_MOVE = "Failed to move {old} to {new}!";
|
||||
public static final String FAILED_TO_READ_FROM_TABLE = "Failed to read {field} from {table}!";
|
||||
public static final String FAILED_TO_READ_LAST_DOCID = "Failed to read last document id";
|
||||
public static final String FAILED_TO_SEARCH_DB = "Failed to search in {module} db";
|
||||
public static final String FAILED_TO_STORE_OBJECT = "Failed to store {object}";
|
||||
public static final String FAILED_TO_SWITCH_POSITIONS = "Failed to switch positions {a} and {b} of document {document}";
|
||||
public static final String FAILED_TO_UPDATE_COLUMN = "Failed to update column {old} → {new} of {table}";
|
||||
public static final String FAILED_TO_UPDATE_OBJECT = "Failed to update {object} in database";
|
||||
public static final String INVALID_EMAIL = "\"{email}\" is not a valid email address!";
|
||||
public static final String INVALID_FIELD = "Expected {field} to be {expected}!";
|
||||
public static final String INVALID_URL = "\"{url}\" is not a valid URL!";
|
||||
public static final String MISSING_CONFIG = "Config is missing value for {key}!";
|
||||
public static final String MISSING_FIELD = "Json is missing {field} field!";
|
||||
public static final String MISSING_NEW_ITEM_ID = "Old item id ({id}) has no new counterpart!";
|
||||
public static final String NO_MEMBER = "You are not a member of {object}!";
|
||||
public static final String UNEXPECTED_ITEM_ID_FORMAT = "Expected old item ID to be of the form ss:dd:dd, encountered {object}!";
|
||||
public static final String UNKNOWN_ITEM_LOCATION = "Item {object} of {owner} refers to location {location}, which is unknown!";
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
public class Field{
|
||||
public static final String AMOUNT = "amount";
|
||||
public static final String BANK_ACCOUNT = "bank_account";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String COMPANY_ID = "company_id";
|
||||
public static final String COURT = "court";
|
||||
public static final String CURRENCY = "currency";
|
||||
public static final String CUSTOMER = "customer";
|
||||
public static final String CUSTOMER_EMAIL = "customer_email";
|
||||
public static final String CUSTOMER_NUMBER = "customer_number";
|
||||
public static final String CUSTOMER_TAX_NUMBER = "customer_tax_number";
|
||||
public static final String DEFAULT_HEADER = "default_header";
|
||||
public static final String DEFAULT_FOOTER = "default_footer";
|
||||
public static final String DEFAULT_MAIL = "type_mail_text";
|
||||
public static final String DELIVERY = "delivery";
|
||||
public static final String DELIVERY_DATE = "delivery_date";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENT_ID = "document_id";
|
||||
public static final String DOC_TYPE_ID = "document_type_id";
|
||||
public static final String END_TIME = "end_time";
|
||||
public static final String FOOTER = "footer";
|
||||
public static final String GROSS_SUM = "gross_sum";
|
||||
public static final String HEAD = "head";
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEM_CODE = "item_code";
|
||||
public static final String NET_PRICE = "net_price";
|
||||
public static final String NET_SUM = "net_sum";
|
||||
public static final String NEXT_TYPE = "next_type_id";
|
||||
public static final String PHONE = "phone";
|
||||
public static final String POS = "pos";
|
||||
public static final String POSITIONS = "positions";
|
||||
public static final String PRICE = "single_price";
|
||||
public static final String PRICE_FORMAT = "price_format";
|
||||
public static final String START_TIME = "start_time";
|
||||
public static final String TASKS = "tasks";
|
||||
public static final String TAX_NUMBER = "tax_number";
|
||||
public static final String TAX = "tax";
|
||||
public static final String TAX_ID = "tax_id";
|
||||
public static final String TEMPLATE_ID = "template_id";
|
||||
public static final String TIME_ID = "time_id";
|
||||
public static final String TYPE = "type";
|
||||
public static final String TYPE_ID = "type_id";
|
||||
public static final String TYPE_NUMBER = "type_number";
|
||||
public static final String TYPE_PREFIX = "type_prefix";
|
||||
public static final String TYPE_SUFFIX = "type_suffix";
|
||||
public static final String UNIT = "unit";
|
||||
public static final String UNIT_PRICE = "unit_price";
|
||||
}
|
||||
@@ -3,8 +3,12 @@ package de.srsoftware.umbrella.core;
|
||||
|
||||
import static de.srsoftware.tools.MimeType.MIME_FORM_URL;
|
||||
import static de.srsoftware.tools.MimeType.MIME_JSON;
|
||||
import static de.srsoftware.tools.PathHandler.GET;
|
||||
import static de.srsoftware.tools.PathHandler.POST;
|
||||
import static de.srsoftware.tools.Strings.hex;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Errors.INVALID_URL;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.serverError;
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@@ -14,6 +18,7 @@ import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.tools.Query;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Hash;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
@@ -117,7 +122,7 @@ public class Util {
|
||||
url = new URI(location).toURL();
|
||||
} catch (Exception e) {
|
||||
LOG.log(WARNING,"{0} is not a valid url",location,e);
|
||||
throw new UmbrellaException(500,"{0} is not a valid url",location).causedBy(e);
|
||||
throw serverError(INVALID_URL,URL,location).causedBy(e);
|
||||
}
|
||||
return request(url,data,postMime,auth);
|
||||
}
|
||||
@@ -160,13 +165,13 @@ public class Util {
|
||||
var is = conn.getErrorStream();
|
||||
is.transferTo(bos);
|
||||
is.close();
|
||||
throw new UmbrellaException(500, bos.toString(UTF_8));
|
||||
throw new UmbrellaException(500, Translatable.t(bos.toString(UTF_8)));
|
||||
}
|
||||
} catch (UmbrellaException e){
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
LOG.log(WARNING,"Request to {0} failed: {1}",target,e.getMessage());
|
||||
throw new UmbrellaException(500,"Request to {0} failed!",target).causedBy(e);
|
||||
throw new UmbrellaException(500, Translatable.t("Request to {url} failed!",URL,target)).causedBy(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.api;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
|
||||
public interface Owner extends Mappable {
|
||||
|
||||
@@ -16,5 +16,6 @@ public interface Translator {
|
||||
}
|
||||
return translate(language, parts[0], fills);
|
||||
}
|
||||
|
||||
public String translate(String language, String text, Map<String,String> fills);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private Constants(){
|
||||
// prevent instantiation
|
||||
}
|
||||
public static final String FALLBACK_LANG = "de";
|
||||
public static final String HOME = "home";
|
||||
public static final String JSONARRAY = "json array";
|
||||
public static final String JSONOBJECT = "json object";
|
||||
public static final String KEEP_ALIVE = "keep-alive";
|
||||
public static final String NO_CACHE = "no-cache";
|
||||
public static final String NONE = "none";
|
||||
public static final String TABLE_SETTINGS = "settings";
|
||||
public static final String UMBRELLA = "Umbrella";
|
||||
public static final String UTF8 = UTF_8.displayName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
public class Field {
|
||||
public static final String ACTION = "action";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String ALLOWED_STATES = "allowed_states";
|
||||
public static final String AMOUNT = "amount";
|
||||
public static final String ATTACHMENTS = "attachments";
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
public static final String BANK_ACCOUNT = "bank_account";
|
||||
public static final String BODY = "body";
|
||||
|
||||
public static final String CACHE_CONTROL = "Cache-Control";
|
||||
public static final String CODE = "code";
|
||||
public static final String COMMENT = "comment";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String COMPANY_ID = "company_id";
|
||||
public static final String CONNECTION = "Connection";
|
||||
public static final String CONTENT = "content";
|
||||
public static final String CONTENT_DISPOSITION = "Content-Disposition";
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
public static final String COURT = "court";
|
||||
public static final String CURRENCY = "currency";
|
||||
public static final String CUSTOMER = "customer";
|
||||
public static final String CUSTOMER_EMAIL = "customer_email";
|
||||
public static final String CUSTOMER_NUMBER = "customer_number";
|
||||
public static final String CUSTOMER_NUMBER_PREFIX = "customer_number_prefix";
|
||||
public static final String CUSTOMER_TAX_NUMBER = "customer_tax_number";
|
||||
|
||||
public static final String DATA = "data";
|
||||
public static final String DB_VERSION = "db_version";
|
||||
public static final String DATE = "date";
|
||||
public static final String DECIMALS = "decimals";
|
||||
public static final String DECIMAL_SEPARATOR = "decimal_separator";
|
||||
public static final String DEFAULT_HEADER = "default_header";
|
||||
public static final String DEFAULT_FOOTER = "default_footer";
|
||||
public static final String DEFAULT_MAIL = "type_mail_text";
|
||||
public static final String DELETED = "deleted";
|
||||
public static final String DELIVERY = "delivery";
|
||||
public static final String DELIVERY_DATE = "delivery_date";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENT_ID = "document_id";
|
||||
public static final String DOC_TYPE_ID = "document_type_id";
|
||||
public static final String DOMAIN = "domain";
|
||||
public static final String DROP_MEMBER = "drop_member";
|
||||
public static final String DUE_DATE = "due_date";
|
||||
public static final String DURATION = "duration";
|
||||
|
||||
public static final String EMAIL = "email";
|
||||
public static final String END_TIME = "end_time";
|
||||
public static final String ENTITY_ID = "entity_id";
|
||||
public static final String EST_TIME = "est_time";
|
||||
public static final String EXPECTED = "expected";
|
||||
public static final String EXPIRATION = "expiration";
|
||||
|
||||
public static final String FIELD = "field";
|
||||
public static final String FOOTER = "footer";
|
||||
public static final String FROM = "from";
|
||||
public static final String FULLTEXT = "fulltext";
|
||||
|
||||
public static final String GROSS_SUM = "gross_sum";
|
||||
public static final String GUEST_ALLOWED = "guest_allowed";
|
||||
|
||||
public static final String HASH = "hash";
|
||||
public static final String HEAD = "head";
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEM_CODE = "item_code";
|
||||
|
||||
public static final String KEY = "key";
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
public static final String LAST_CUSTOMER_NUMBER = "last_customer_number";
|
||||
public static final String LIMIT = "limit";
|
||||
public static final String LOCATION = "location";
|
||||
public static final String LOCATION_ID = "location_id";
|
||||
public static final String LOCATIONS = "locations";
|
||||
public static final String LOGIN = "login";
|
||||
public static final String MEMBERS = "members";
|
||||
public static final String MIME = "mime";
|
||||
public static final String MODULE = "module";
|
||||
|
||||
public static final String NAME = "name";
|
||||
public static final String NEW_MEMBER = "new_member";
|
||||
public static final String NET_PRICE = "net_price";
|
||||
public static final String NET_SUM = "net_sum";
|
||||
public static final String NEXT_TYPE = "next_type_id";
|
||||
public static final String NO_INDEX = "no_index";
|
||||
public static final String NOTE = "note";
|
||||
public static final String NUMBER = "number";
|
||||
|
||||
public static final String OBJECT = "object";
|
||||
public static final String OFFSET = "offset";
|
||||
public static final String OPTIONAL = "optional";
|
||||
public static final String OWNER = "owner";
|
||||
public static final String OWNER_NUMBER = "owner_number";
|
||||
|
||||
public static final String PARENT_LOCATION_ID = "parent_location_id";
|
||||
public static final String PARENT_TASK_ID = "parent_task_id";
|
||||
public static final String PASS = "pass";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PATH = "path";
|
||||
public static final String PERMISSION = "permission";
|
||||
public static final String PHONE = "phone";
|
||||
public static final String POS = "pos";
|
||||
public static final String POSITIONS = "positions";
|
||||
public static final String PRICE = "single_price";
|
||||
public static final String PRICE_FORMAT = "price_format";
|
||||
public static final String PRIORITY = "priority";
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String PROPERTIES = "properties";
|
||||
|
||||
public static final String RECEIVERS = "receivers";
|
||||
public static final String REDIRECT = "redirect";
|
||||
public static final String RENDERED = "rendered";
|
||||
public static final String REQUIRED_TASKS_IDS = "required_tasks_ids";
|
||||
|
||||
public static final String SENDER = "sender";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SHOW_CLOSED = "show_closed";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String START_DATE = "start_date";
|
||||
public static final String START_TIME = "start_time";
|
||||
public static final String STATE = "state";
|
||||
public static final String STATUS = "status";
|
||||
public static final String STATUS_CODE = "code";
|
||||
public static final String SUBJECT = "subject";
|
||||
|
||||
public static final String TABLE = "table";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TAG_COLORS = "tag_colors";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASK_IDS = "task_ids";
|
||||
public static final String TASKS = "tasks";
|
||||
public static final String TAX = "tax";
|
||||
public static final String TAX_ID = "tax_id";
|
||||
public static final String TAX_NUMBER = "tax_number";
|
||||
public static final String TAX_RATE = "tax_rate";
|
||||
public static final String TEMPLATE = "template";
|
||||
public static final String TEMPLATE_ID = "template_id";
|
||||
public static final String TEXT = "text";
|
||||
public static final String THOUSANDS_SEPARATOR = "thousands_separator";
|
||||
public static final String THEME = "theme";
|
||||
public static final String TIME_ID = "time_id";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
public static final String TITLE = "title";
|
||||
public static final String TO = "to";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String TOTAL_PRIO = "total_prio";
|
||||
public static final String TYPE = "type";
|
||||
public static final String TYPE_ID = "type_id";
|
||||
|
||||
public static final String UNIT = "unit";
|
||||
public static final String UNIT_PRICE = "unit_price";
|
||||
public static final String URI = "uri";
|
||||
public static final String URL = "url";
|
||||
public static final String USER = "user";
|
||||
public static final String USERS = "users";
|
||||
public static final String USER_ID = "user_id";
|
||||
public static final String USER_LIST = "user_list";
|
||||
|
||||
public static final String VALUE = "value";
|
||||
public static final String VCARD = "vcard";
|
||||
public static final String VERSION = "version";
|
||||
public static final String VERSIONS = "versions";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
public class Module {
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String TASK = "task";
|
||||
public static final String USER = "user";
|
||||
public static final String WIKI = "wiki";
|
||||
}
|
||||
+26
-3
@@ -1,26 +1,49 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core;
|
||||
package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
public class Paths {
|
||||
private Paths(){};
|
||||
public class Path {
|
||||
private Path(){};
|
||||
|
||||
public static final String ADD = "add";
|
||||
public static final String AVAILABLE = "available";
|
||||
public static final String CSS = "css";
|
||||
public static final String COMMON_TEMPLATES = "common_templates";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String CONNECTED = "connected";
|
||||
|
||||
public static final String ITEM = "item";
|
||||
|
||||
public static final String JSON = "json";
|
||||
|
||||
public static final String LEGACY = "legacy";
|
||||
public static final String LIST = "list";
|
||||
public static final String LOCATION = "location";
|
||||
public static final String LOCATIONS = "locations";
|
||||
public static final String LOGIN = "login";
|
||||
|
||||
public static final String LOGOUT = "logout";
|
||||
public static final String PAGE = "page";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
public static final String REDIRECT = "redirect";
|
||||
|
||||
public static final String SEARCH = "search";
|
||||
public static final String SERVICE = "service";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String STATES = "states";
|
||||
public static final String STARTED = "started";
|
||||
public static final String STATE = "state";
|
||||
public static final String STOP = "stop";
|
||||
public static final String SUBMIT = "submit";
|
||||
|
||||
public static final String TAGGED = "tagged";
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
public static final String USER = "user";
|
||||
public static final String USES = "uses";
|
||||
public static final String VIEW = "view";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.constants;
|
||||
|
||||
/**
|
||||
* This is a collection of messages that appear throughout the project
|
||||
*/
|
||||
public class Text {
|
||||
public static final String BOOLEAN = "Boolean";
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String COMPANIES = "companies";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String COMPANY_WITH_ID = "company ({id})";
|
||||
public static final String CONTACT = "Contact";
|
||||
public static final String CONTACTS = "contacts";
|
||||
public static final String CONTACT_WITH_ID = "contact ({id})";
|
||||
public static final String CUSTOMER = "customer";
|
||||
public static final String CUSTOMER_SETTINGS = "customer settings";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENTS = "documents";
|
||||
public static final String DOCUMENT_TYPE_ID = "document type id";
|
||||
public static final String DOCUMENT_WITH_ID = "document ({id})";
|
||||
public static final String INVALID_DB_CODE = "Encountered invalid dbCode: {code}";
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEMS = "items";
|
||||
public static final String LOCATION = "location";
|
||||
public static final String LOCATIONS = "locations";
|
||||
public static final String LOGIN_SERVICE = "login service";
|
||||
public static final String LONG = "Long";
|
||||
public static final String NOTE = "note";
|
||||
public static final String NOTE_WITH_ID = "note ({id})";
|
||||
public static final String NUMBER = "number";
|
||||
public static final String PATH = "path";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROJECT_WITH_ID = "project ({id})";
|
||||
public static final String PROPERTY = "property";
|
||||
public static final String SENDER = "sender";
|
||||
public static final String SESSION = "session";
|
||||
public static final String SERVICE_WITH_ID = "service ({id})";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String STRING = "string";
|
||||
public static final String TABLE_WITH_NAME = "table {name}";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASKS = "tasks";
|
||||
public static final String TIME_WITH_ID = "time ({id})";
|
||||
public static final String TYPE = "type";
|
||||
public static final String USER_WITH_ID = "user ({id})";
|
||||
public static final String WIKI_PAGE = "wiki page";
|
||||
public static final String WIKI_PAGES = "wiki pages";
|
||||
public static final String UNIT = "unit";
|
||||
public static final String T_UNIT_PRICE = "unit price";
|
||||
public static final String USER = "user";
|
||||
public static final String USERS = "users";
|
||||
|
||||
}
|
||||
@@ -1,78 +1,125 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.exceptions;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||
import static java.lang.System.Logger.Level.ERROR;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
|
||||
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
||||
import static java.text.MessageFormat.format;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.net.HttpURLConnection.*;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
|
||||
|
||||
|
||||
public class UmbrellaException extends RuntimeException{
|
||||
private final int statusCode;
|
||||
private Object[] fills;
|
||||
private final Translatable message;
|
||||
|
||||
public UmbrellaException(String message, Object ... fills){
|
||||
this(HTTP_SERVER_ERROR,message,fills);
|
||||
}
|
||||
|
||||
public UmbrellaException(int statusCode, String message, Object ... fills){
|
||||
super(message);
|
||||
this.fills = fills;
|
||||
public UmbrellaException(int statusCode, Translatable message){
|
||||
super(message.toString());
|
||||
this.statusCode = statusCode;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public UmbrellaException(int statusCode, String rawMessage, Object ... args){
|
||||
this(statusCode, Translatable.t(rawMessage,args));
|
||||
}
|
||||
|
||||
public static final UmbrellaException badRequest(String rawMessage, Object ... args){
|
||||
return new UmbrellaException(HTTP_BAD_REQUEST,rawMessage,args);
|
||||
}
|
||||
|
||||
public UmbrellaException causedBy(Exception e) {
|
||||
initCause(e);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static UmbrellaException databaseException(String message, Object... fills) {
|
||||
System.getLogger("Configuration").log(WARNING,message,fills);
|
||||
return new UmbrellaException(message,fills);
|
||||
public static UmbrellaException databaseException(String rawMessage, Object ... args) {
|
||||
return new UmbrellaException(HTTP_SERVER_ERROR,rawMessage,args);
|
||||
}
|
||||
|
||||
public Object[] fills(){
|
||||
return fills;
|
||||
public static UmbrellaException failedToCreateTable(String tableName){
|
||||
return databaseException(FAILED_TO_CREATE_TABLE, NAME,tableName);
|
||||
}
|
||||
|
||||
public static UmbrellaException forbidden(String message, Object... fills) {
|
||||
return new UmbrellaException(HTTP_FORBIDDEN,message,fills);
|
||||
public static UmbrellaException failedToDropObject(Object object){
|
||||
return databaseException(FAILED_TO_DROP_OBJECT, OBJECT,object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return format(super.getMessage(),fills);
|
||||
public static UmbrellaException failedToDropObjectFromObject(String typeOfDropped, Object dropped, Object typeOfRelated, Object related){
|
||||
return databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,
|
||||
"dropped_type",typeOfDropped,
|
||||
OBJECT,dropped,
|
||||
"related_type", typeOfRelated,
|
||||
"related",related);
|
||||
}
|
||||
|
||||
public static UmbrellaException invalidFieldException(String field, String expected){
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE, ERROR_INVALID_FIELD, field, expected);
|
||||
public static UmbrellaException failedToLoadMembers(Object object){
|
||||
return databaseException(FAILED_TO_LOAD_OBJECT_MEMBERS, OBJECT,object);
|
||||
}
|
||||
|
||||
public static UmbrellaException failedToLoadObject(Object object){
|
||||
return databaseException(FAILED_TO_LOAD_OBJECT, OBJECT,object);
|
||||
}
|
||||
|
||||
public static UmbrellaException failedToLoadObject(Object object, Object id){
|
||||
return databaseException(FAILED_TO_LOAD_OBJECT_BY_ID, OBJECT,object, ID,id);
|
||||
}
|
||||
|
||||
public static UmbrellaException failedToStoreObject(Object object){
|
||||
return databaseException(FAILED_TO_STORE_OBJECT, OBJECT,object);
|
||||
}
|
||||
|
||||
public static UmbrellaException failedToReadFromTable(String field, String table){
|
||||
return databaseException(FAILED_TO_READ_FROM_TABLE, FIELD,field, TABLE,table);
|
||||
}
|
||||
|
||||
public static UmbrellaException failedToSearchDb(Translatable module){
|
||||
return databaseException(FAILED_TO_SEARCH_DB, MODULE, module);
|
||||
}
|
||||
|
||||
public static UmbrellaException forbidden(String rawMessage, Object ... args) {
|
||||
return new UmbrellaException(HTTP_FORBIDDEN,rawMessage,args);
|
||||
}
|
||||
|
||||
public static UmbrellaException invalidField(String field, Object expected){
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE, INVALID_FIELD, FIELD, field, EXPECTED, expected);
|
||||
}
|
||||
|
||||
public Translatable message(){
|
||||
return message;
|
||||
}
|
||||
|
||||
public static UmbrellaException missingConfig(String key){
|
||||
return new UmbrellaException(HTTP_SERVER_ERROR,MISSING_CONFIG, KEY,key);
|
||||
}
|
||||
|
||||
|
||||
public static UmbrellaException missingConfigException(String field){
|
||||
System.getLogger("Configuration").log(ERROR,ERROR_MISSING_CONFIG, field);
|
||||
return new UmbrellaException(ERROR_MISSING_CONFIG, field);
|
||||
public static UmbrellaException missingField(String field){
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE, MISSING_FIELD, FIELD,field);
|
||||
}
|
||||
|
||||
|
||||
public static UmbrellaException missingFieldException(String field){
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE, ERROR_MISSING_FIELD, field);
|
||||
public static UmbrellaException notAmember(Object object){
|
||||
return forbidden(NO_MEMBER, OBJECT,object);
|
||||
}
|
||||
|
||||
public static UmbrellaException notFound(String message, Object... fills) {
|
||||
return new UmbrellaException(HTTP_NOT_FOUND,message,fills);
|
||||
public static UmbrellaException notFound(String rawMessage, Object ... args) {
|
||||
return new UmbrellaException(HTTP_NOT_FOUND,rawMessage,args);
|
||||
}
|
||||
|
||||
public static UmbrellaException serverError(String rawMessage, Object ... args){
|
||||
return new UmbrellaException(HTTP_SERVER_ERROR,rawMessage,args);
|
||||
}
|
||||
|
||||
public int statusCode(){
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public static UmbrellaException unprocessable(String message, Object... fills) {
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE,message,fills);
|
||||
public static UmbrellaException unauthorized(String rawMessage, Object ... args) {
|
||||
return new UmbrellaException(HTTP_UNAUTHORIZED,rawMessage,args);
|
||||
}
|
||||
|
||||
public static UmbrellaException unprocessable(String rawMessage, Object ... args) {
|
||||
return new UmbrellaException(HTTP_UNPROCESSABLE,rawMessage, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.STRING;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.util.Arrays;
|
||||
@@ -29,11 +30,11 @@ public record Attachment(String name, String mime, byte[] content) {
|
||||
|
||||
public static <T> Attachment of(JSONObject json) throws UmbrellaException {
|
||||
for (var key : Set.of(NAME, MIME, DATA)) {
|
||||
if (!json.has(key)) throw missingFieldException(key);
|
||||
if (!json.has(key)) throw missingField(key);
|
||||
}
|
||||
if (!(json.get(NAME) instanceof String name)) throw invalidFieldException(NAME,STRING);
|
||||
if (!(json.get(MIME) instanceof String mime)) throw invalidFieldException(MIME,STRING);
|
||||
if (!(json.get(DATA) instanceof String data)) throw invalidFieldException(DATA,STRING);
|
||||
if (!(json.get(NAME) instanceof String name)) throw invalidField(NAME,t(STRING));
|
||||
if (!(json.get(MIME) instanceof String mime)) throw invalidField(MIME,t(STRING));
|
||||
if (!(json.get(DATA) instanceof String data)) throw invalidField(DATA,t(STRING));
|
||||
return new Attachment(name,mime, BASE64.decode(data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
@@ -28,7 +28,7 @@ public record Bookmark(long urlId, String url, String comment, LocalDateTime tim
|
||||
return Map.of(
|
||||
ID, urlId,
|
||||
URL, url,
|
||||
COMMENT, Map.of(SOURCE,comment,RENDERED,markdown(comment)),
|
||||
COMMENT, mapMarkdown(comment),
|
||||
TAGS, tags,
|
||||
TIMESTAMP, timestamp.withNano(0)
|
||||
);
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.emptyIfNull;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.TYPE;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.COMPANY;
|
||||
import static java.util.Map.entry;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
@@ -147,19 +145,19 @@ public class Company implements Mappable, Owner {
|
||||
public Company patch(JSONObject json) {
|
||||
for (var key : json.keySet()){
|
||||
switch (key){
|
||||
case NAME: name = json.getString(NAME); break;
|
||||
case ADDRESS: address = json.getString(ADDRESS); break;
|
||||
case COURT: court = json.getString(COURT); break;
|
||||
case TAX_NUMBER: taxId = json.getString(TAX_NUMBER); break;
|
||||
case PHONE: phone = json.getString(PHONE); break;
|
||||
case DECIMAL_SEPARATOR: decimalSeparator = json.getString(DECIMAL_SEPARATOR); break;
|
||||
case THOUSANDS_SEPARATOR: thousandsSeparator = json.getString(THOUSANDS_SEPARATOR); break;
|
||||
case LAST_CUSTOMER_NUMBER: lastCustomerNumber = json.getLong(LAST_CUSTOMER_NUMBER); break;
|
||||
case DECIMALS: decimals = json.getInt(DECIMALS); break;
|
||||
case CUSTOMER_NUMBER_PREFIX: customerNumberPrefix = json.getString(CUSTOMER_NUMBER_PREFIX); break;
|
||||
case CURRENCY: currency = json.getString(CURRENCY); break;
|
||||
case EMAIL: email = json.getString(EMAIL); break;
|
||||
case BANK_ACCOUNT: bankAccount = json.getString(BANK_ACCOUNT); break;
|
||||
case NAME: name = json.getString(key); break;
|
||||
case ADDRESS: address = json.getString(key); break;
|
||||
case COURT: court = json.getString(key); break;
|
||||
case TAX_NUMBER: taxId = json.getString(key); break;
|
||||
case PHONE: phone = json.getString(key); break;
|
||||
case DECIMAL_SEPARATOR: decimalSeparator = json.getString(key); break;
|
||||
case THOUSANDS_SEPARATOR: thousandsSeparator = json.getString(key); break;
|
||||
case LAST_CUSTOMER_NUMBER: lastCustomerNumber = json.getLong(key); break;
|
||||
case DECIMALS: decimals = json.getInt(key); break;
|
||||
case CUSTOMER_NUMBER_PREFIX: customerNumberPrefix = json.getString(key); break;
|
||||
case CURRENCY: currency = json.getString(key); break;
|
||||
case EMAIL: email = json.getString(key); break;
|
||||
case BANK_ACCOUNT: bankAccount = json.getString(key); break;
|
||||
default: key = null;
|
||||
}
|
||||
if (key != null) dirtyFields.add(key);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
@@ -31,8 +31,8 @@ public class Contact implements Mappable{
|
||||
}
|
||||
|
||||
public Contact patch(JSONObject json) {
|
||||
if (!(json.get(FROM) instanceof String from)) throw missingFieldException(FROM);
|
||||
if (!(json.get(TO) instanceof String to)) throw missingFieldException(TO);
|
||||
if (!(json.get(FROM) instanceof String from)) throw missingField(FROM);
|
||||
if (!(json.get(TO) instanceof String to)) throw missingField(TO);
|
||||
return new Contact(id,vcard.replace(from, to));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.emptyIfNull;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.FALLBACK_LANG;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -68,9 +68,9 @@ public final class Customer implements Mappable {
|
||||
}
|
||||
|
||||
public static Customer of(JSONObject json) throws UmbrellaException {
|
||||
if (!json.has(ID) || !(json.get(ID) instanceof String id)) throw missingFieldException(ID);
|
||||
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
|
||||
if (!json.has(EMAIL) || !(json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
|
||||
if (!json.has(ID) || !(json.get(ID) instanceof String id)) throw missingField(ID);
|
||||
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingField(NAME);
|
||||
if (!json.has(EMAIL) || !(json.get(EMAIL) instanceof String email)) throw missingField(EMAIL);
|
||||
var taxId = json.has(TAX_ID) && json.get(TAX_ID) instanceof String tid ? tid : null;
|
||||
var lang = json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String l ? l : FALLBACK_LANG;
|
||||
return new Customer(id,name,email,taxId,lang);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
import de.srsoftware.umbrella.core.api.Owner;
|
||||
import java.sql.ResultSet;
|
||||
@@ -69,10 +69,10 @@ public class DbLocation extends Location {
|
||||
parentLocationId = json.getLong(field);
|
||||
break;
|
||||
case NAME:
|
||||
name = json.getString(NAME);
|
||||
name = json.getString(field);
|
||||
break;
|
||||
case DESCRIPTION:
|
||||
description = json.getString(DESCRIPTION);
|
||||
description = json.getString(field);
|
||||
break;
|
||||
default:
|
||||
known = false;
|
||||
@@ -93,7 +93,7 @@ public class DbLocation extends Location {
|
||||
if (description == null) description = "";
|
||||
map.put(OWNER,owner.toMap());
|
||||
map.put(NAME,name);
|
||||
map.put(DESCRIPTION,Map.of(SOURCE,description,RENDERED,markdown(description)));
|
||||
map.put(DESCRIPTION,mapMarkdown(description));
|
||||
if (parentLocationId != null) map.put(PARENT_LOCATION_ID,parentLocationId);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.emptyIfNull;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.Field.TYPE;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.util.Optional.empty;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
@@ -205,7 +202,7 @@ public final class Document implements Mappable {
|
||||
case HEAD: head = json.getString(key); break;
|
||||
case NUMBER: number = json.getString(key); break;
|
||||
case SENDER: if (json.get(key) instanceof JSONObject nested) sender.patch(nested); break;
|
||||
case STATE: state = State.of(json.getInt(key)).orElseThrow(() -> new UmbrellaException(HTTP_UNPROCESSABLE,"Invalid state")); break;
|
||||
case STATE: state = State.of(json.getInt(key)).orElseThrow(() -> new UmbrellaException(HTTP_UNPROCESSABLE, Translatable.t("Invalid state"))); break;
|
||||
case POS: if (json.get(key) instanceof JSONObject nested) positions.patch(nested); break;
|
||||
case TEMPLATE: if (json.get(key) instanceof String templateId) template = templateId; break;
|
||||
default: key = null;
|
||||
@@ -279,7 +276,7 @@ public final class Document implements Mappable {
|
||||
ID, id,
|
||||
NUMBER, number,
|
||||
"type", type.name(),
|
||||
STATE, Map.of(NAME,state.toString(),ID,state.code),
|
||||
STATE, Map.of(NAME,state.toString(), ID,state.code),
|
||||
DATE, date,
|
||||
CURRENCY, currency,
|
||||
CUSTOMER, customer.toMap(),
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.allSet;
|
||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||
import static de.srsoftware.umbrella.core.Errors.INVALID_EMAIL;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.EMAIL;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.badRequest;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.util.Objects;
|
||||
@@ -12,7 +14,7 @@ public class EmailAddress {
|
||||
|
||||
public EmailAddress(String addr) throws UmbrellaException {
|
||||
var parts = addr.split("@");
|
||||
if (parts.length != 2 || !allSet(parts[0],parts[1])) throw new UmbrellaException(HTTP_BAD_REQUEST,"\"{0}\" is not a valid email address",addr);
|
||||
if (parts.length != 2 || !allSet(parts[0],parts[1])) throw badRequest(INVALID_EMAIL, EMAIL,addr);
|
||||
email = addr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONARRAY;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONOBJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.RECEIVERS;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -34,14 +36,14 @@ public class Envelope {
|
||||
* @throws UmbrellaException
|
||||
*/
|
||||
public static Envelope from(JSONObject json) throws UmbrellaException {
|
||||
if (!json.has(RECEIVERS)) throw missingFieldException(RECEIVERS);
|
||||
if (!json.has(RECEIVERS)) throw missingField(RECEIVERS);
|
||||
var message = Message.from(json);
|
||||
var obj = json.get(RECEIVERS);
|
||||
if (obj instanceof JSONObject) obj = new JSONArray(List.of(obj));
|
||||
if (!(obj instanceof JSONArray receiverList)) throw invalidFieldException(RECEIVERS, JSONARRAY);
|
||||
if (!(obj instanceof JSONArray receiverList)) throw invalidField(RECEIVERS, t(JSONARRAY));
|
||||
var receivers = new HashSet<User>();
|
||||
for (var o : receiverList){
|
||||
if (!(o instanceof JSONObject receiverData)) throw invalidFieldException("entries of "+ RECEIVERS, JSONOBJECT);
|
||||
if (!(o instanceof JSONObject receiverData)) throw invalidField("entries of "+ RECEIVERS, t(JSONOBJECT));
|
||||
receivers.add(User.of(receiverData));
|
||||
}
|
||||
return new Envelope(message,receivers);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.api.Owner;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
@@ -75,7 +76,7 @@ public class Item implements Mappable {
|
||||
var owner = OwnerRef.of(rs);
|
||||
var ownerNumber = rs.getLong(OWNER_NUMBER);
|
||||
var location = Location.of(rs);
|
||||
var code = rs.getString(CODE);
|
||||
var code = rs.getString(Field.CODE);
|
||||
var name = rs.getString(NAME);
|
||||
var description = rs.getString(DESCRIPTION);
|
||||
return new Item(id, owner, ownerNumber, location, code, name, description);
|
||||
@@ -97,7 +98,7 @@ public class Item implements Mappable {
|
||||
for (var field : json.keySet()){
|
||||
var known = true;
|
||||
switch (field) {
|
||||
case CODE:
|
||||
case Field.CODE:
|
||||
code = json.getString(field);
|
||||
break;
|
||||
case NAME:
|
||||
@@ -124,7 +125,7 @@ public class Item implements Mappable {
|
||||
map.put(OWNER,owner.toMap());
|
||||
map.put(ID,id);
|
||||
map.put(LOCATION,location.toMap());
|
||||
map.put(CODE,code);
|
||||
map.put(Field.CODE,code);
|
||||
map.put(NAME,name);
|
||||
map.put(DESCRIPTION,mapMarkdown(description));
|
||||
map.put(OWNER_NUMBER,ownerNumber);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.ID;
|
||||
import static de.srsoftware.umbrella.core.Constants.LOCATION_ID;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.stockService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.ID;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.LOCATION_ID;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.PERMISSION;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.USER;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.isSet;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONOBJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.STRING;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -21,21 +23,21 @@ public record Message(UmbrellaUser sender, String subject, String body, Map<Stri
|
||||
|
||||
public static Message from(JSONObject json) throws UmbrellaException {
|
||||
for (var key : Set.of(SENDER, SUBJECT, BODY)) {
|
||||
if (!json.has(key)) throw missingFieldException(key);
|
||||
if (!json.has(key)) throw missingField(key);
|
||||
}
|
||||
if (!(json.get(SENDER) instanceof JSONObject senderObject)) throw invalidFieldException(SENDER, JSONOBJECT);
|
||||
if (!(json.get(SUBJECT) instanceof String subject && isSet(subject))) throw invalidFieldException(SUBJECT,STRING);
|
||||
if (!(json.get(BODY) instanceof String body && isSet(body))) throw invalidFieldException(BODY,STRING);
|
||||
if (!(json.get(SENDER) instanceof JSONObject senderObject)) throw invalidField(SENDER, t(JSONOBJECT));
|
||||
if (!(json.get(SUBJECT) instanceof String subject && isSet(subject))) throw invalidField(SUBJECT,t(STRING));
|
||||
if (!(json.get(BODY) instanceof String body && isSet(body))) throw invalidField(BODY,t(STRING));
|
||||
|
||||
var user = UmbrellaUser.of(senderObject);
|
||||
if (!(user instanceof UmbrellaUser sender)) throw new UmbrellaException(400,"Sender is not an umbrella user!");
|
||||
if (!(user instanceof UmbrellaUser sender)) throw new UmbrellaException(400, t("Sender is not an umbrella user!"));
|
||||
var attachments = new ArrayList<Attachment>();
|
||||
if (json.has(ATTACHMENTS)){
|
||||
var jsonAttachments = json.get(ATTACHMENTS);
|
||||
if (jsonAttachments instanceof JSONObject obj) jsonAttachments = new JSONArray(List.of(obj));
|
||||
if (jsonAttachments instanceof JSONArray arr){
|
||||
for (var att : arr){
|
||||
if (!(att instanceof JSONObject o)) throw new UmbrellaException(400,"Attachments contains entry that is not an object: {}",att);
|
||||
if (!(att instanceof JSONObject o)) throw new UmbrellaException(400, t("Attachments contains entry that is not an object: {entry}","entry",att));
|
||||
var attachment = Attachment.of(o);
|
||||
attachments.add(attachment);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
@@ -72,7 +72,7 @@ public class Note implements Mappable {
|
||||
MODULE,module,
|
||||
ENTITY_ID,entityId,
|
||||
USER_ID,authorId,
|
||||
TEXT,Map.of(RENDERED,markdown(text),SOURCE,text),
|
||||
TEXT,mapMarkdown(text),
|
||||
TIMESTAMP,timestamp.withNano(0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.ID;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.companyService;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.USER;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.INVALID_DB_CODE;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
|
||||
import de.srsoftware.umbrella.core.api.Owner;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
@@ -20,12 +23,12 @@ public class OwnerRef implements Owner {
|
||||
|
||||
public OwnerRef(String dbCode){
|
||||
var parts = dbCode.split(":");
|
||||
if (parts.length != 2) throw unprocessable("Encountered invalid dbCode: {0}",dbCode);
|
||||
if (parts.length != 2) throw unprocessable(INVALID_DB_CODE, Field.CODE,dbCode);
|
||||
type = parts[0];
|
||||
try {
|
||||
id = Long.parseLong(parts[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw unprocessable("Encountered invalid dbCode: {0}",dbCode);
|
||||
throw unprocessable(INVALID_DB_CODE, Field.CODE,dbCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +62,7 @@ public class OwnerRef implements Owner {
|
||||
return switch (type){
|
||||
case COMPANY -> companyService().get(id());
|
||||
case USER -> userService().loadUser(id());
|
||||
case null, default -> throw unprocessable("Encountered invalid owner type: {0}",type);
|
||||
case null, default -> throw unprocessable("Encountered invalid owner type: {type}", TYPE,type);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.CODE;
|
||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.NAME;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,7 +36,7 @@ public enum Permission implements Mappable {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(NAME,name(),CODE,code);
|
||||
return Map.of(NAME,name(), Field.CODE,code);
|
||||
}
|
||||
|
||||
public boolean mayWrite() {
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.TAX;
|
||||
import static de.srsoftware.umbrella.core.Field.UNIT;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.util.*;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.END_TIME;
|
||||
import static de.srsoftware.umbrella.core.Field.START_TIME;
|
||||
import static de.srsoftware.umbrella.core.Field.TAX;
|
||||
import static de.srsoftware.umbrella.core.Field.UNIT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
import de.srsoftware.tools.Pair;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,7 +20,7 @@ public class PositionList extends HashMap<Integer,Position> {
|
||||
}
|
||||
|
||||
public Position addItem(JSONObject item) {
|
||||
var itemCode = item.getString(CODE);
|
||||
var itemCode = item.getString(Field.CODE);
|
||||
var unit = item.getString(UNIT);
|
||||
var name = item.getString(NAME);
|
||||
var description = item.getString(DESCRIPTION);
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.nullable;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.model.Status.PREDEFINED;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
@@ -138,7 +139,7 @@ public class Project implements Mappable {
|
||||
map.put(MEMBERS,memberMap);
|
||||
var stateMap = new HashMap<Integer,String>();
|
||||
for (var state : allowedStates) stateMap.put(state.code(),state.name());
|
||||
map.put(ALLOWED_STATES,stateMap);
|
||||
map.put(Field.ALLOWED_STATES,stateMap);
|
||||
map.put(TAG_COLORS,tagColors);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -65,10 +64,10 @@ public final class Sender implements Mappable {
|
||||
}
|
||||
|
||||
public static Sender of(JSONObject json) throws UmbrellaException {
|
||||
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
|
||||
if (!json.has(BANK_ACCOUNT) || !(json.get(BANK_ACCOUNT) instanceof String bankAccount)) throw missingFieldException(BANK_ACCOUNT);
|
||||
if (!json.has(TAX_ID) || !(json.get(TAX_ID) instanceof String taxId)) throw missingFieldException(TAX_ID);
|
||||
if (!json.has(COURT) || !(json.get(COURT) instanceof String court)) throw missingFieldException(COURT);
|
||||
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingField(NAME);
|
||||
if (!json.has(BANK_ACCOUNT) || !(json.get(BANK_ACCOUNT) instanceof String bankAccount)) throw missingField(BANK_ACCOUNT);
|
||||
if (!json.has(TAX_ID) || !(json.get(TAX_ID) instanceof String taxId)) throw missingField(TAX_ID);
|
||||
if (!json.has(COURT) || !(json.get(COURT) instanceof String court)) throw missingField(COURT);
|
||||
return new Sender(name,bankAccount,taxId,court);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.NAME;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.STATUS;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@@ -26,7 +28,7 @@ public record Status(String name, int code) implements Mappable {
|
||||
case "started" -> STARTED;
|
||||
case "complete" -> COMPLETE;
|
||||
case "cancelled" -> CANCELLED;
|
||||
case null, default -> throw invalidFieldException(STATUS,"one of: "+PREDEFINED.stream().map(Status::name).collect(Collectors.joining(", ")));
|
||||
case null, default -> throw invalidField(STATUS,"one of: "+PREDEFINED.stream().map(Status::name).collect(Collectors.joining(", ")));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,11 +44,11 @@ public record Status(String name, int code) implements Mappable {
|
||||
}
|
||||
|
||||
public static Status of(ResultSet rs) throws SQLException {
|
||||
return new Status(rs.getString(NAME),rs.getInt(CODE));
|
||||
return new Status(rs.getString(NAME),rs.getInt(Field.CODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(NAME,name,CODE,code);
|
||||
return Map.of(NAME,name, Field.CODE,code);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
@@ -130,25 +130,25 @@ public class Task implements Mappable {
|
||||
}
|
||||
|
||||
public static Task of(JSONObject json){
|
||||
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number prjId)) throw missingFieldException(PROJECT_ID);
|
||||
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number prjId)) throw missingField(PROJECT_ID);
|
||||
Long parentTaskId = json.has(PARENT_TASK_ID) && json.get(PARENT_TASK_ID) instanceof Number ptid ? ptid.longValue() : null;
|
||||
|
||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name && !name.isBlank())) throw missingFieldException(NAME);
|
||||
if (!json.has(DESCRIPTION)) throw missingFieldException(DESCRIPTION);
|
||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name && !name.isBlank())) throw missingField(NAME);
|
||||
if (!json.has(DESCRIPTION)) throw missingField(DESCRIPTION);
|
||||
var description = switch (json.get(DESCRIPTION)){
|
||||
case String d -> d;
|
||||
case JSONObject j -> j.getString(SOURCE);
|
||||
default -> throw invalidFieldException(json.get(DESCRIPTION).getClass().getSimpleName(),"String or JSON");
|
||||
default -> throw invalidField(json.get(DESCRIPTION).getClass().getSimpleName(),"String or JSON");
|
||||
};
|
||||
|
||||
var status = Status.OPEN.code();
|
||||
if (json.has(STATUS) && json.get(STATUS) instanceof JSONObject state){
|
||||
if (state.get(CODE) instanceof Number code) status = code.intValue();
|
||||
if (state.get(Field.CODE) instanceof Number code) status = code.intValue();
|
||||
}
|
||||
Double estimatedTime = null;
|
||||
if (json.has(ESTIMATED_TIME)) {
|
||||
if (json.get(ESTIMATED_TIME) instanceof Number est) estimatedTime = est.doubleValue();
|
||||
if (json.get(ESTIMATED_TIME) instanceof String est) try {
|
||||
if (json.has(EST_TIME)) {
|
||||
if (json.get(EST_TIME) instanceof Number est) estimatedTime = est.doubleValue();
|
||||
if (json.get(EST_TIME) instanceof String est) try {
|
||||
estimatedTime = Double.parseDouble(est);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class Task implements Mappable {
|
||||
var showClosed = json.has(SHOW_CLOSED) && json.get(SHOW_CLOSED) instanceof Boolean sc ? sc : false;
|
||||
var noIndex = json.has(NO_INDEX) && json.get(NO_INDEX) instanceof Boolean ni ? ni : false;
|
||||
var priority = json.has(PRIORITY) && json.get(PRIORITY) instanceof Number pr ? prjId.intValue() : 0;
|
||||
if (!(json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject)) throw missingFieldException(MEMBERS);
|
||||
if (!(json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject)) throw missingField(MEMBERS);
|
||||
return new Task(0,prjId.longValue(),parentTaskId,name,description,status,estimatedTime,startDate,dueDate,showClosed,noIndex,new HashMap<>(),priority);
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class Task implements Mappable {
|
||||
switch (key){
|
||||
case DESCRIPTION: description = json.getString(key); break;
|
||||
case DUE_DATE: dueDate = json.isNull(DUE_DATE) || json.getString(DUE_DATE).isBlank() ? null : LocalDate.parse(json.getString(DUE_DATE)); break;
|
||||
case ESTIMATED_TIME: estimatedTime = json.isNull(ESTIMATED_TIME) ? null : json.getDouble(ESTIMATED_TIME); break;
|
||||
case EST_TIME: estimatedTime = json.isNull(EST_TIME) ? null : json.getDouble(EST_TIME); break;
|
||||
case MEMBERS: continue;
|
||||
case NAME: name = json.getString(key); break;
|
||||
case NO_INDEX: noIndex = json.getBoolean(NO_INDEX); break;
|
||||
@@ -242,7 +242,7 @@ public class Task implements Mappable {
|
||||
map.put(NAME, name);
|
||||
map.put(DESCRIPTION, mapMarkdown(description));
|
||||
map.put(STATUS, status);
|
||||
map.put(ESTIMATED_TIME, estimatedTime);
|
||||
map.put(EST_TIME, estimatedTime);
|
||||
map.put(START_DATE,start);
|
||||
map.put(DUE_DATE,dueDate);
|
||||
map.put(NO_INDEX,noIndex);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -127,13 +128,13 @@ public class Time implements Mappable{
|
||||
if (json.has(START_TIME) && json.get(START_TIME) instanceof Number st) start = st.longValue();
|
||||
if (json.has(END_TIME) && json.get(END_TIME) instanceof Number e) end = e.longValue();
|
||||
if (end == 0) end = null;
|
||||
if (end != null && end < start) throw invalidFieldException(END_TIME,"after start_time");
|
||||
if (end != null && end < start) throw invalidField(END_TIME,"after start_time");
|
||||
if (json.has(STATE)) {
|
||||
var o = json.get(STATE);
|
||||
try {
|
||||
switch (o) {
|
||||
case JSONObject nested:
|
||||
state = State.of(nested.getInt(CODE));
|
||||
state = State.of(nested.getInt(Field.CODE));
|
||||
break;
|
||||
case String stateName:
|
||||
state = State.valueOf(stateName);
|
||||
@@ -142,10 +143,10 @@ public class Time implements Mappable{
|
||||
state = State.of(stateCode.intValue());
|
||||
break;
|
||||
default:
|
||||
throw invalidFieldException(STATE, "state name or code");
|
||||
throw invalidField(STATE, t("state name or code"));
|
||||
}
|
||||
} catch (Exception e){
|
||||
throw unprocessable("\"{0}\" is not a valid state name or code!",o);
|
||||
throw unprocessable("\"{value}\" is not a valid state name or code!",VALUE,o);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
@@ -193,7 +194,7 @@ public class Time implements Mappable{
|
||||
map.put(DESCRIPTION,mapMarkdown(description));
|
||||
map.put(START_TIME,start);
|
||||
map.put(END_TIME,end);
|
||||
map.put(STATE,Map.of(STATUS_CODE,state.code,NAME,state.name()));
|
||||
map.put(STATE,Map.of(STATUS_CODE,state.code, NAME,state.name()));
|
||||
map.put(DURATION,end == null ? null : (end - start)/3600d);
|
||||
map.put(TASK_IDS,taskIds);
|
||||
return map;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.TOKEN;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TOKEN;
|
||||
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.AddableMap;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Translatable {
|
||||
private final String message;
|
||||
private Map<String, Object> fills;
|
||||
private final HashMap<String,String> translated = new HashMap<>();
|
||||
|
||||
public Translatable(String message, Map<String,Object> fills){
|
||||
this.fills = fills;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static Map<String,Object> argMap(Object ... args){
|
||||
var map = new HashMap<String,Object>();
|
||||
int i = 0;
|
||||
while (i+1<args.length){
|
||||
map.put(args[i].toString(),args[i+1]);
|
||||
i++;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return translate(null);
|
||||
}
|
||||
|
||||
public static Translatable t(String message, Object ... args){
|
||||
return t(message,argMap(args));
|
||||
}
|
||||
|
||||
public static Translatable t(String message, Map<String, Object> args){
|
||||
return new Translatable(message,args);
|
||||
}
|
||||
|
||||
public String translate(String language){
|
||||
var translation = language != null ? translated.get(language) : null;
|
||||
if (translation == null){
|
||||
var translatedFills = new HashMap<String,String>();
|
||||
if (fills != null) {
|
||||
for (var entry : fills.entrySet()) {
|
||||
var o = entry.getValue();
|
||||
var val = switch (o) {
|
||||
case Translatable tr -> tr.translate(language);
|
||||
case String s -> s;
|
||||
default -> o.toString();
|
||||
};
|
||||
translatedFills.put(entry.getKey(), val);
|
||||
}
|
||||
}
|
||||
translation = ModuleRegistry.translator().translate(language,message,translatedFills);
|
||||
if (translation != null) translated.put(language,translation);
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,11 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.api.Owner;
|
||||
import de.srsoftware.umbrella.core.constants.Module;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -63,6 +64,6 @@ public class UmbrellaUser extends User implements Mappable, Owner {
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return USER;
|
||||
return Module.USER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.EMAIL;
|
||||
import static de.srsoftware.umbrella.core.Constants.LANGUAGE;
|
||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
||||
import static de.srsoftware.umbrella.core.Constants.THEME;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -38,9 +34,9 @@ public class User {
|
||||
public static User of(JSONObject json) throws UmbrellaException {
|
||||
if (json.has(USER)) json = json.getJSONObject(USER);
|
||||
|
||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
|
||||
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
|
||||
if (!(json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String lang)) throw missingFieldException(LANGUAGE);
|
||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingField(NAME);
|
||||
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingField(EMAIL);
|
||||
if (!(json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String lang)) throw missingField(LANGUAGE);
|
||||
|
||||
var addr = new EmailAddress(email);
|
||||
if (json.has(ID) && json.get(ID) instanceof Number id) {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidFieldException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.JSONOBJECT;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.BOOLEAN;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.STRING;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||
import static java.lang.String.join;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.api.UserService;
|
||||
@@ -77,29 +81,29 @@ public class WikiPage implements Mappable {
|
||||
var val = json.get(key);
|
||||
switch (key){
|
||||
case ID:
|
||||
throw unprocessable("{0} cannot be altered!",ID);
|
||||
throw unprocessable("{field} cannot be altered!", FIELD, ID);
|
||||
case CONTENT:
|
||||
if (!(val instanceof String s)) throw invalidFieldException(CONTENT,"String");
|
||||
if (!(val instanceof String s)) throw invalidField(CONTENT,t(STRING));
|
||||
content(s);
|
||||
break;
|
||||
case GUEST_ALLOWED:
|
||||
if (!(val instanceof Boolean b)) throw invalidFieldException(GUEST_ALLOWED,"Boolean");
|
||||
if (!(val instanceof Boolean b)) throw invalidField(GUEST_ALLOWED, t(BOOLEAN));
|
||||
guestAllowed(b);
|
||||
break;
|
||||
case MEMBERS:
|
||||
if (!(val instanceof JSONObject membersJson)) throw invalidFieldException(MEMBERS,"Json");
|
||||
if (!(val instanceof JSONObject membersJson)) throw invalidField(MEMBERS,t(JSONOBJECT));
|
||||
for (var uid : membersJson.keySet()){
|
||||
var userId = Long.parseLong(uid);
|
||||
var user = users.loadUser(userId);
|
||||
if (!(membersJson.get(uid) instanceof JSONObject memberJSON)) throw invalidFieldException(MEMBERS+"."+uid,"Json");
|
||||
if (!(membersJson.get(uid) instanceof JSONObject memberJSON)) throw invalidField(MEMBERS +"."+uid,t(JSONOBJECT));
|
||||
var p = memberJSON.get(PERMISSION);
|
||||
if (p == JSONObject.NULL){
|
||||
members.remove(userId);
|
||||
dirtyFields.add(MEMBERS);
|
||||
break;
|
||||
}
|
||||
if (!(p instanceof JSONObject perm)) throw invalidFieldException(String.join(".",MEMBERS,uid,PERMISSION),"Json");
|
||||
if (!(perm.get(NAME) instanceof String permName)) throw invalidFieldException(String.join(".",MEMBERS,uid,PERMISSION,NAME),"String");
|
||||
if (!(p instanceof JSONObject perm)) throw invalidField(join(".", MEMBERS,uid, PERMISSION),t(JSONOBJECT));
|
||||
if (!(perm.get(NAME) instanceof String permName)) throw invalidField(join(".", MEMBERS,uid, PERMISSION, NAME),t(STRING));
|
||||
var permission = Permission.valueOf(permName);
|
||||
var member = new Member(user,permission);
|
||||
var existing = members.get(userId);
|
||||
@@ -110,7 +114,7 @@ public class WikiPage implements Mappable {
|
||||
}
|
||||
break;
|
||||
case TITLE:
|
||||
if (!(val instanceof String t)) throw invalidFieldException(TITLE,"String");
|
||||
if (!(val instanceof String t)) throw invalidField(TITLE,t(STRING));
|
||||
title(t);
|
||||
break;
|
||||
}
|
||||
@@ -144,7 +148,7 @@ public class WikiPage implements Mappable {
|
||||
|
||||
return Map.of(
|
||||
ID,id,
|
||||
CONTENT,Map.of(SOURCE,content,RENDERED,markdown(content)),
|
||||
CONTENT,mapMarkdown(content),
|
||||
GUEST_ALLOWED,guestAllowed,
|
||||
MEMBERS,memberMap,
|
||||
TITLE,title,
|
||||
|
||||
Reference in New Issue
Block a user