working on backend-side translations
This commit is contained in:
@@ -223,7 +223,7 @@ public class CompanyModule extends BaseHandler implements CompanyService {
|
||||
var json = json(ex);
|
||||
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
|
||||
var keys = Arrays.asList(key.split(" "));
|
||||
var companies = companyDb.find(user.id(),keys);
|
||||
var companies = companyDb.find(user,keys);
|
||||
return sendContent(ex,mapValues(companies));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,22 +8,25 @@ import static de.srsoftware.tools.jdbc.Query.Dialect.SQLITE;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.company.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.COMPANY_ID;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
||||
import static java.lang.System.Logger.Level.ERROR;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.company.api.CompanyDb;
|
||||
import de.srsoftware.umbrella.core.BaseDb;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Company;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SqliteDb extends BaseDb implements CompanyDb {
|
||||
@@ -141,15 +144,15 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
var next = last+1;
|
||||
return prefix+next; // TODO: currently not taking growing number lengths into account, this should be resolved!
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to load customer number settings for company {0}",companyId);
|
||||
throw databaseException(FAILED_TO_LOAD_CUSTOMER_NUM_SETTINGS,companyId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Long, Company> find(long userId, Collection<String> keys) {
|
||||
public HashMap<Long, Company> find(UmbrellaUser user, Collection<String> keys) {
|
||||
try {
|
||||
var query = select(DISTINCT).from(TABLE_COMPANIES).leftJoin(ID,TABLE_COMPANIES_USERS,COMPANY_ID)
|
||||
.where(USER_ID,equal(userId));
|
||||
.where(USER_ID,equal(user.id()));
|
||||
for (var key : keys){
|
||||
query.where(format("CONCAT({0},\" \",{1},\" \",{2},\" \",{3},\" \",{4})",NAME,ADDRESS,EMAIL,PHONE,BANK_ACCOUNT),like("%"+key+"%"));
|
||||
}
|
||||
@@ -162,7 +165,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
rs.close();
|
||||
return companies;
|
||||
} catch (SQLException ex){
|
||||
throw databaseException("Failed to search in company database!");
|
||||
throw databaseException(FAILED_TO_SEARCH_DB, ModuleRegistry.translator().translate(user.language(),COMPANY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +181,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
rs.close();
|
||||
return companies;
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to load companies for user {0}",userId);
|
||||
throw databaseException(FAILED_TO_LOAD_USER_COMPANIES,userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,10 +192,10 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
Company company = null;
|
||||
if (rs.next()) company = Company.of(rs);
|
||||
rs.close();
|
||||
if (company == null) throw new UmbrellaException("Could not load company {0}",companyId);
|
||||
if (company == null) throw databaseException(FAILED_TO_LOAD_COMPANY,companyId);
|
||||
return company;
|
||||
} catch (SQLException e){
|
||||
throw databaseException("Could not load company {0}",companyId);
|
||||
throw databaseException(FAILED_TO_LOAD_COMPANY,companyId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +227,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
return company;
|
||||
}
|
||||
} catch (SQLException e){
|
||||
throw UmbrellaException.databaseException("Failed to save {0}…",company.name());
|
||||
throw databaseException(FAILED_TO_STORE_ENTITY,company.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +241,7 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
try {
|
||||
update(TABLE_COMPANIES).set(LAST_CUSTOMER_NUMBER,CUSTOMER_NUMBER_PREFIX).where(ID,equal(companyId)).prepare(db).apply(number,prefix).close();
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to update customer number counter for company {0}", companyId);
|
||||
throw databaseException(FAILED_TO_UPDATE_ENTITY, LAST_CUSTOMER_NUMBER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.srsoftware.umbrella.company.api;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Company;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -14,7 +16,7 @@ public interface CompanyDb {
|
||||
|
||||
void dropUser(long company_id, long user_id);
|
||||
|
||||
HashMap<Long, Company> find(long userId, Collection<String> keys);
|
||||
HashMap<Long, Company> find(UmbrellaUser userId, Collection<String> keys);
|
||||
|
||||
Collection<Long> getMembers(long companyId) throws UmbrellaException;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user