altered contact/add in order to make use of the new contact backend instead of the legacy API
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -3,8 +3,6 @@ package de.srsoftware.umbrella.contact;
|
|||||||
|
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.core.model.Contact;
|
import de.srsoftware.umbrella.core.model.Contact;
|
||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ContactDb {
|
public interface ContactDb {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import static de.srsoftware.umbrella.contact.Constants.*;
|
|||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
|
||||||
import static java.lang.System.Logger.Level.ERROR;
|
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
|
||||||
import de.srsoftware.tools.jdbc.Query;
|
import de.srsoftware.tools.jdbc.Query;
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ import static de.srsoftware.umbrella.core.Constants.*;
|
|||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
|
|
||||||
import de.srsoftware.tools.Mappable;
|
import de.srsoftware.tools.Mappable;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public record Contact(long id, String vcard) implements Mappable {
|
public record Contact(long id, String vcard) implements Mappable {
|
||||||
public static Contact of(ResultSet rs) throws SQLException {
|
public static Contact of(ResultSet rs) throws SQLException {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import static de.srsoftware.document.mustang.Constants.KEY_PDF;
|
|||||||
import static de.srsoftware.document.mustang.Constants.KEY_PRODUCER;
|
import static de.srsoftware.document.mustang.Constants.KEY_PRODUCER;
|
||||||
import static de.srsoftware.document.mustang.Constants.KEY_TEMPLATE;
|
import static de.srsoftware.document.mustang.Constants.KEY_TEMPLATE;
|
||||||
import static de.srsoftware.document.zugferd.data.UnitCode.*;
|
import static de.srsoftware.document.zugferd.data.UnitCode.*;
|
||||||
import static de.srsoftware.tools.MimeType.MIME_FORM_URL;
|
|
||||||
import static de.srsoftware.tools.MimeType.MIME_PDF;
|
import static de.srsoftware.tools.MimeType.MIME_PDF;
|
||||||
import static de.srsoftware.tools.Optionals.isSet;
|
import static de.srsoftware.tools.Optionals.isSet;
|
||||||
import static de.srsoftware.tools.Strings.escapeHtmlEntities;
|
import static de.srsoftware.tools.Strings.escapeHtmlEntities;
|
||||||
@@ -26,7 +25,6 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
|||||||
import static de.srsoftware.umbrella.core.Paths.*;
|
import static de.srsoftware.umbrella.core.Paths.*;
|
||||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.Util.request;
|
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
import static de.srsoftware.umbrella.core.model.Document.State.NEW;
|
import static de.srsoftware.umbrella.core.model.Document.State.NEW;
|
||||||
import static de.srsoftware.umbrella.core.model.Document.State.SENT;
|
import static de.srsoftware.umbrella.core.model.Document.State.SENT;
|
||||||
@@ -67,7 +65,6 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class DocumentApi extends BaseHandler implements DocumentService {
|
public class DocumentApi extends BaseHandler implements DocumentService {
|
||||||
@@ -141,7 +138,6 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
|||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
var head = path.pop();
|
var head = path.pop();
|
||||||
return switch (head){
|
return switch (head){
|
||||||
case CONTACTS -> getContacts(ex,user.get(),token.orElse(null));
|
|
||||||
case PATH_TYPES -> getDocTypes(ex);
|
case PATH_TYPES -> getDocTypes(ex);
|
||||||
case STATES -> getDocStates(ex);
|
case STATES -> getDocStates(ex);
|
||||||
case null -> super.doGet(path,ex);
|
case null -> super.doGet(path,ex);
|
||||||
@@ -207,10 +203,6 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getContacts(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException {
|
|
||||||
return sendContent(ex,getLegacyContacts(ex,user,token));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean getDocStates(HttpExchange ex) throws IOException {
|
private boolean getDocStates(HttpExchange ex) throws IOException {
|
||||||
var map = Stream.of(Document.State.values()).collect(toMap(Document.State::code, Document.State::name));
|
var map = Stream.of(Document.State.values()).collect(toMap(Document.State::code, Document.State::name));
|
||||||
return sendContent(ex,map);
|
return sendContent(ex,map);
|
||||||
@@ -376,13 +368,6 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
|||||||
return sendContent(ex,content.bytes());
|
return sendContent(ex,content.bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONArray getLegacyContacts(HttpExchange ex, UmbrellaUser umbrellaUser, Token token) throws IOException, UmbrellaException {
|
|
||||||
var location = config.get("umbrella.modules.contact.baseUrl").map(s -> s+"/json").orElseThrow(() -> new UmbrellaException(500,"umbrella.modules.contact.baseUrl not configured!"));
|
|
||||||
var resp = request(location, token.asMap(),MIME_FORM_URL,null);
|
|
||||||
if (!(resp instanceof String s && s.startsWith("["))) throw new UmbrellaException(500,"{0} did not return JSON Array!",location);
|
|
||||||
return new JSONArray(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Long, Document> list(long companyId) throws UmbrellaException{
|
public Map<Long, Document> list(long companyId) throws UmbrellaException{
|
||||||
return db.listDocs(companyId);
|
return db.listDocs(companyId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ package de.srsoftware.umbrella.documents.model;
|
|||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
|
|
||||||
import de.srsoftware.tools.Mappable;
|
import de.srsoftware.tools.Mappable;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class CustomerSettings implements Mappable {
|
public class CustomerSettings implements Mappable {
|
||||||
private static final System.Logger LOG = System.getLogger(CustomerSettings.class.getSimpleName());
|
private static final System.Logger LOG = System.getLogger(CustomerSettings.class.getSimpleName());
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import {onMount} from 'svelte';
|
import {onMount} from 'svelte';
|
||||||
|
|
||||||
import {api} from '../urls.svelte.js';
|
import {api} from '../urls.svelte.js';
|
||||||
|
import {addr, email, extra, fn, name, org} from '../vcard.js';
|
||||||
import {t} from '../translations.svelte.js';
|
import {t} from '../translations.svelte.js';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -14,10 +15,40 @@
|
|||||||
let value = 0;
|
let value = 0;
|
||||||
|
|
||||||
async function loadContacts(){
|
async function loadContacts(){
|
||||||
const url = api('document/contacts');
|
const url = api('contact/list');
|
||||||
const resp = await fetch(url,{ credentials: 'include'});
|
const resp = await fetch(url,{ credentials: 'include'});
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
contacts = await resp.json();
|
const json = await resp.json();
|
||||||
|
contacts = Object.values(json).map(contact => {
|
||||||
|
contact.ADR = addr(contact.vcard);
|
||||||
|
contact.EMAIL = email(contact.vcard);
|
||||||
|
contact.N = name(contact.vcard);
|
||||||
|
contact.FN = fn(contact.vcard);
|
||||||
|
contact.ORG = org(contact.vcard);
|
||||||
|
const extras = contact.vcard.match(/^X-.*:.+/gm);
|
||||||
|
for (let ex of extras){
|
||||||
|
ex = extra(ex);
|
||||||
|
switch (ex.name){
|
||||||
|
case 'CUSTOMER-NUMBER':
|
||||||
|
contact.customer_number = ex.value;
|
||||||
|
break;
|
||||||
|
case 'TAX-NUMBER':
|
||||||
|
contact.tax_id = ex.value;
|
||||||
|
break;
|
||||||
|
case 'BANK-ACCOUNT':
|
||||||
|
contact.bank_account = ex.value;
|
||||||
|
break;
|
||||||
|
case 'COURT':
|
||||||
|
contact.local_court = ex.value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete contact.vcard;
|
||||||
|
console.log(contact);
|
||||||
|
return contact;
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
message = await resp.text();
|
message = await resp.text();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,11 +36,11 @@
|
|||||||
<span class="symbol {home?'':'inactive'}" onclick={toggleHome}></span>
|
<span class="symbol {home?'':'inactive'}" onclick={toggleHome}></span>
|
||||||
<span class="symbol {work?'':'inactive'}" onclick={toggleWork} ></span>
|
<span class="symbol {work?'':'inactive'}" onclick={toggleWork} ></span>
|
||||||
</div>
|
</div>
|
||||||
<LineEditor type="span" editable={true} value={address.box} onSet={newVal => onSet(address.box,newVal)} title={t('post_box')} />
|
<LineEditor type="span" editable={true} value={address.box} onSet={newVal => onSet(address.box,newVal)} title={t('post_box')} />
|
||||||
<LineEditor type="span" editable={true} value={address.ext} onSet={newVal => onSet(address.ext,newVal)} title={t('extended_address')} />
|
<LineEditor type="span" editable={true} value={address.ext} onSet={newVal => onSet(address.ext,newVal)} title={t('extended_address')} />
|
||||||
<LineEditor type="span" editable={true} value={address.street} onSet={newVal => onSet(address.street,newVal)} title={t('street')} />
|
<LineEditor type="span" editable={true} value={address.street} onSet={newVal => onSet(address.street,newVal)} title={t('street')} />
|
||||||
<LineEditor type="span" editable={true} value={address.code} onSet={newVal => onSet(address.code,newVal)} title={t('post_code')} />
|
<LineEditor type="span" editable={true} value={address.post_code} onSet={newVal => onSet(address.post_code,newVal)} title={t('post_code')} />
|
||||||
<LineEditor type="span" editable={true} value={address.loc} onSet={newVal => onSet(address.loc,newVal)} title={t('locality')} />
|
<LineEditor type="span" editable={true} value={address.locality} onSet={newVal => onSet(address.locality,newVal)} title={t('locality')} />
|
||||||
<LineEditor type="span" editable={true} value={address.region} onSet={newVal => onSet(address.region,newVal)} title={t('region')} />
|
<LineEditor type="span" editable={true} value={address.region} onSet={newVal => onSet(address.region,newVal)} title={t('region')} />
|
||||||
<LineEditor type="span" editable={true} value={address.country} onSet={newVal => onSet(address.country,newVal)} title={t('country')} />
|
<LineEditor type="span" editable={true} value={address.country} onSet={newVal => onSet(address.country,newVal)} title={t('country')} />
|
||||||
</div>
|
</div>
|
||||||
@@ -68,9 +68,9 @@
|
|||||||
if (contact.ADR.locality) addr += contact.ADR.post_code + " "+ contact.ADR.locality + "\n";
|
if (contact.ADR.locality) addr += contact.ADR.post_code + " "+ contact.ADR.locality + "\n";
|
||||||
if (contact.ADR.county) addr += contact.ADR.country+"\n";
|
if (contact.ADR.county) addr += contact.ADR.country+"\n";
|
||||||
document.customer.name = addr;
|
document.customer.name = addr;
|
||||||
document.customer.tax_id = contact['X-TAX-NUMBER'];
|
document.customer.tax_id = contact.tax_id;
|
||||||
document.customer.id = contact['X-CUSTOMER-NUMBER'];
|
document.customer.id = contact.customer_number;
|
||||||
document.customer.email = contact.EMAIL.val;
|
document.customer.email = contact.EMAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit(){
|
async function submit(){
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ export function addr(vcard){
|
|||||||
adr.box = parts[0];
|
adr.box = parts[0];
|
||||||
adr.ext = parts[1];
|
adr.ext = parts[1];
|
||||||
adr.street = parts[2];
|
adr.street = parts[2];
|
||||||
adr.loc = parts[3];
|
adr.locality = parts[3];
|
||||||
adr.region = parts[4];
|
adr.region = parts[4];
|
||||||
adr.code = parts[5];
|
adr.post_code = parts[5];
|
||||||
adr.country = parts[6];
|
adr.country = parts[6];
|
||||||
}
|
}
|
||||||
return adr;
|
return adr;
|
||||||
|
|||||||
Reference in New Issue
Block a user