|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package common.ecommerce.channel.sdk; |
|
|
|
package common.ecommerce.channel.sdk; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import common.ecommerce.shared.model.ChannelProvider; |
|
|
|
import common.ecommerce.shared.model.Platform; |
|
|
|
import common.ecommerce.shared.model.Platform; |
|
|
|
import common.ecommerce.shared.audit.CallObserver; |
|
|
|
import common.ecommerce.shared.audit.CallObserver; |
|
|
|
import common.ecommerce.shared.audit.CallSupport; |
|
|
|
import common.ecommerce.shared.audit.CallSupport; |
|
|
|
@ -150,21 +151,32 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* <p>注入 {@code callObserver} 后,每次调用也会记一条 {@code capabilities} 记录; |
|
|
|
* <p>注入 {@code callObserver} 后,每次调用也会记一条 {@code capabilities} 记录; |
|
|
|
* 账户或适配器没配好时记 FAILURE,这是上线初期最常见的配置类故障。</p> |
|
|
|
* 账户或适配器没配好时记 FAILURE,这是上线初期最常见的配置类故障。</p> |
|
|
|
* |
|
|
|
* |
|
|
|
* @param key 账户标识;账户未配置时抛 {@link IllegalStateException} |
|
|
|
* @param platform 业务平台;账户未配置时抛 {@link IllegalStateException} |
|
|
|
* @throws IllegalStateException 账户未配置,或该 provider+platform 没有适配器 |
|
|
|
* @throws IllegalStateException 账户未配置,或该平台没有适配器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public CapabilityReport capabilities(AccountKey key) { |
|
|
|
public CapabilityReport capabilities(Platform platform) { |
|
|
|
// 账户都不在时没有 ChannelContext,用 key 自己拼一个最小上下文
|
|
|
|
// 账户不在时 contextFor 会自己拼一个最小上下文用于埋点
|
|
|
|
return CallSupport.observe(callObserver, contextFor(key), "capabilities", |
|
|
|
return CallSupport.observe(callObserver, contextFor(platform), |
|
|
|
|
|
|
|
"capabilities", |
|
|
|
CallSupport.params("capabilities", null), |
|
|
|
CallSupport.params("capabilities", null), |
|
|
|
report -> CallSupport.NO_COUNT, |
|
|
|
report -> CallSupport.NO_COUNT, |
|
|
|
() -> capabilitiesOf(key)); |
|
|
|
() -> capabilitiesOf(platform)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #capabilities(Platform)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
|
|
|
public CapabilityReport capabilities(AccountKey key) { |
|
|
|
|
|
|
|
return capabilities(key.platform()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 能力矩阵的实际实现:账户与适配器都齐了才构造报告。 */ |
|
|
|
/** 能力矩阵的实际实现:账户与适配器都齐了才构造报告。 */ |
|
|
|
private CapabilityReport capabilitiesOf(AccountKey key) { |
|
|
|
private CapabilityReport capabilitiesOf(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return capabilitiesOf(key.platform()); |
|
|
|
return new AdapterCapabilityReport(resolve(key), account); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CapabilityReport capabilitiesOf(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new AdapterCapabilityReport(resolve(platform), account); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -175,9 +187,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public SalesOrders salesOrders(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new SalesOrders(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #salesOrders(Platform)};provider 改由配置决定。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public SalesOrders salesOrders(AccountKey key) { |
|
|
|
public SalesOrders salesOrders(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return salesOrders(key.platform()); |
|
|
|
return new SalesOrders(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -185,9 +203,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时,不是取视图时。</p> |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时,不是取视图时。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public SalesOrders salesOrders(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new SalesOrders(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #salesOrders(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public SalesOrders salesOrders(AccountKey key, ChannelConnection connection) { |
|
|
|
public SalesOrders salesOrders(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return salesOrders(key.platform(), connection); |
|
|
|
return new SalesOrders(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -195,9 +219,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Products products(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Products(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #products(Platform)};provider 改由配置决定。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Products products(AccountKey key) { |
|
|
|
public Products products(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return products(key.platform()); |
|
|
|
return new Products(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -205,21 +235,39 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时,不是取视图时。</p> |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时,不是取视图时。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Products products(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Products(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #products(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Products products(AccountKey key, ChannelConnection connection) { |
|
|
|
public Products products(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return products(key.platform(), connection); |
|
|
|
return new Products(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 结算 / 账单交易明细视图(免连接)。 */ |
|
|
|
/** 结算 / 账单交易明细视图(免连接)。 */ |
|
|
|
|
|
|
|
public Settlements settlements(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Settlements(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #settlements(Platform)};provider 改由配置决定。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Settlements settlements(AccountKey key) { |
|
|
|
public Settlements settlements(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return settlements(key.platform()); |
|
|
|
return new Settlements(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 结算 / 账单交易明细视图。 */ |
|
|
|
/** 结算 / 账单交易明细视图。 */ |
|
|
|
|
|
|
|
public Settlements settlements(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Settlements(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #settlements(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Settlements settlements(AccountKey key, ChannelConnection connection) { |
|
|
|
public Settlements settlements(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return settlements(key.platform(), connection); |
|
|
|
return new Settlements(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -227,9 +275,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public AfterSales afterSales(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new AfterSales(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #afterSales(Platform)};provider 改由配置决定。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public AfterSales afterSales(AccountKey key) { |
|
|
|
public AfterSales afterSales(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return afterSales(key.platform()); |
|
|
|
return new AfterSales(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -238,9 +292,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时;适配器未实现 {@code AfterSaleCapable} |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时;适配器未实现 {@code AfterSaleCapable} |
|
|
|
* 或未声明 {@code RETURNS} 能力时抛 {@code UnsupportedCapabilityException}。</p> |
|
|
|
* 或未声明 {@code RETURNS} 能力时抛 {@code UnsupportedCapabilityException}。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public AfterSales afterSales(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new AfterSales(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #afterSales(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public AfterSales afterSales(AccountKey key, ChannelConnection connection) { |
|
|
|
public AfterSales afterSales(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return afterSales(key.platform(), connection); |
|
|
|
return new AfterSales(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -248,19 +308,31 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Outbounds outbounds(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Outbounds(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #outbounds(Platform)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Outbounds outbounds(AccountKey key) { |
|
|
|
public Outbounds outbounds(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return outbounds(key.platform()); |
|
|
|
return new Outbounds(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 履约 / 出库视图。 |
|
|
|
* 履约 / 出库视图。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p><b>写操作</b>:会改变平台数据。领星没有测试环境,验证阶段禁止调用。</p> |
|
|
|
* <p>能力检查发生在 {@code pull()} 调用时,不是取视图时。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Outbounds outbounds(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Outbounds(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #outbounds(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Outbounds outbounds(AccountKey key, ChannelConnection connection) { |
|
|
|
public Outbounds outbounds(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return outbounds(key.platform(), connection); |
|
|
|
return new Outbounds(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -268,9 +340,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Inbounds inbounds(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Inbounds(resolve(platform), account, newContext(account, connectionOf(platform, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #inbounds(Platform)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Inbounds inbounds(AccountKey key) { |
|
|
|
public Inbounds inbounds(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return inbounds(key.platform()); |
|
|
|
return new Inbounds(resolve(key), account, newContext(account, connectionOf(key, account)), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -280,9 +358,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* 适配器未实现对应接口或未声明能力时抛 |
|
|
|
* 适配器未实现对应接口或未声明能力时抛 |
|
|
|
* {@code UnsupportedCapabilityException}。</p> |
|
|
|
* {@code UnsupportedCapabilityException}。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public Inbounds inbounds(Platform platform, ChannelConnection connection) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return new Inbounds(resolve(platform), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #inbounds(Platform, ChannelConnection)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Inbounds inbounds(AccountKey key, ChannelConnection connection) { |
|
|
|
public Inbounds inbounds(AccountKey key, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return inbounds(key.platform(), connection); |
|
|
|
return new Inbounds(resolve(key), account, newContext(account, connection), callObserver); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -290,9 +374,15 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
* @throws IllegalStateException 未注入 {@code secretProvider},或账户缺端点且适配器无默认地址 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
public List<AggregatorCapable.SubChannel> subChannels(Platform platform) { |
|
|
|
|
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
|
|
|
|
return subChannels(platform, connectionOf(platform, account)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #subChannels(Platform)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public List<AggregatorCapable.SubChannel> subChannels(AccountKey key) { |
|
|
|
public List<AggregatorCapable.SubChannel> subChannels(AccountKey key) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
return subChannels(key.platform()); |
|
|
|
return subChannels(key, connectionOf(key, account)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -303,16 +393,16 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 该 provider 的适配器不是聚合器(未实现 AggregatorCapable) |
|
|
|
* @throws IllegalStateException 该 provider 的适配器不是聚合器(未实现 AggregatorCapable) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<AggregatorCapable.SubChannel> subChannels(AccountKey key, ChannelConnection connection) { |
|
|
|
public List<AggregatorCapable.SubChannel> subChannels(Platform platform, ChannelConnection connection) { |
|
|
|
ChannelAccount account = requireAccount(key); |
|
|
|
ChannelAccount account = requireAccount(platform); |
|
|
|
final PlatformAdapter adapter = resolve(key); |
|
|
|
final PlatformAdapter adapter = resolve(platform); |
|
|
|
final ChannelContext ctx = newContext(account, connection); |
|
|
|
final ChannelContext ctx = newContext(account, connection); |
|
|
|
return CallSupport.observe(callObserver, ctx, "subChannels.list", |
|
|
|
return CallSupport.observe(callObserver, ctx, "subChannels.list", |
|
|
|
CallSupport.params("endpoint", connection.endpointBaseUrl()), |
|
|
|
CallSupport.params("endpoint", connection.endpointBaseUrl()), |
|
|
|
channels -> channels.size(), |
|
|
|
channels -> channels.size(), |
|
|
|
() -> { |
|
|
|
() -> { |
|
|
|
if (!(adapter instanceof AggregatorCapable)) { |
|
|
|
if (!(adapter instanceof AggregatorCapable)) { |
|
|
|
throw new IllegalStateException("adapter is not an aggregator: " + key); |
|
|
|
throw new IllegalStateException("adapter is not an aggregator: " + platform); |
|
|
|
} |
|
|
|
} |
|
|
|
return ((AggregatorCapable) adapter).listSubChannels(ctx); |
|
|
|
return ((AggregatorCapable) adapter).listSubChannels(ctx); |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -378,26 +468,36 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 按 AccountKey 解析适配器;不自动选路、不自动兜底。 |
|
|
|
* 按平台解析适配器;不自动选路、不自动兜底。 |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws IllegalStateException 该 provider + platform 没有注册适配器 |
|
|
|
* @throws IllegalStateException 该平台没有注册适配器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public PlatformAdapter resolve(Platform platform) { |
|
|
|
public PlatformAdapter resolve(AccountKey key) { |
|
|
|
PlatformAdapter adapter = adapters.get(registryKey(platform)); |
|
|
|
PlatformAdapter adapter = adapters.get(registryKey(key)); |
|
|
|
|
|
|
|
if (adapter == null) { |
|
|
|
if (adapter == null) { |
|
|
|
throw new IllegalStateException("no adapter registered for " + key |
|
|
|
throw new IllegalStateException("no adapter registered for " + platform |
|
|
|
+ "; registered: " + adapters.keySet()); |
|
|
|
+ "; registered: " + adapters.keySet()); |
|
|
|
} |
|
|
|
} |
|
|
|
return adapter; |
|
|
|
return adapter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @deprecated 用 {@link #resolve(Platform)}。 */ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
|
|
|
public PlatformAdapter resolve(AccountKey key) { |
|
|
|
|
|
|
|
return resolve(key.platform()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------ internals
|
|
|
|
// ------------------------------------------------------------------ internals
|
|
|
|
|
|
|
|
|
|
|
|
/** 按 provider + platform + omsStoreId 找账户;找不到就是配置缺失,不是运行时错误。 */ |
|
|
|
/** |
|
|
|
private ChannelAccount requireAccount(AccountKey key) { |
|
|
|
* 按平台找接入配置;找不到就是配置缺失,不是运行时错误。 |
|
|
|
return accountRepository.findByKey(key.provider().name(), key.platform().name(), key.omsStoreId()) |
|
|
|
* |
|
|
|
.orElseThrow(() -> new IllegalStateException("channel account not configured: " + key)); |
|
|
|
* <p>报错文案区分「平台没配置」和「平台配了但没适配器」——两者排查方向不同。</p> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private ChannelAccount requireAccount(Platform platform) { |
|
|
|
|
|
|
|
return accountRepository.findByPlatform(platform) |
|
|
|
|
|
|
|
.orElseThrow(() -> new IllegalStateException( |
|
|
|
|
|
|
|
"platform " + platform + " has no channel account configured (findByPlatform returned empty)")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 组装单次调用的上下文:账户 + 连接 + 链路 ID + 时钟。 */ |
|
|
|
/** 组装单次调用的上下文:账户 + 连接 + 链路 ID + 时钟。 */ |
|
|
|
@ -414,7 +514,7 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* @throws IllegalStateException 未注入 secretProvider、账户无端点且适配器无默认地址, |
|
|
|
* @throws IllegalStateException 未注入 secretProvider、账户无端点且适配器无默认地址, |
|
|
|
* 或解析器返回 null |
|
|
|
* 或解析器返回 null |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ChannelConnection connectionOf(AccountKey key, ChannelAccount account) { |
|
|
|
private ChannelConnection connectionOf(Platform platform, ChannelAccount account) { |
|
|
|
if (secretProvider == null) { |
|
|
|
if (secretProvider == null) { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
"ChannelSdk requires a secretProvider for connection-less calls; " |
|
|
|
"ChannelSdk requires a secretProvider for connection-less calls; " |
|
|
|
@ -422,10 +522,10 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
String endpoint = account.endpointBaseUrl(); |
|
|
|
String endpoint = account.endpointBaseUrl(); |
|
|
|
if (endpoint == null || endpoint.trim().isEmpty()) { |
|
|
|
if (endpoint == null || endpoint.trim().isEmpty()) { |
|
|
|
endpoint = resolve(key).defaultEndpointBaseUrl(); |
|
|
|
endpoint = resolve(platform).defaultEndpointBaseUrl(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (endpoint == null || endpoint.trim().isEmpty()) { |
|
|
|
if (endpoint == null || endpoint.trim().isEmpty()) { |
|
|
|
throw new IllegalStateException("no endpoint configured for " + key |
|
|
|
throw new IllegalStateException("no endpoint configured for " + platform |
|
|
|
+ "; set ChannelAccount.endpointBaseUrl or use the ChannelConnection overload"); |
|
|
|
+ "; set ChannelAccount.endpointBaseUrl or use the ChannelConnection overload"); |
|
|
|
} |
|
|
|
} |
|
|
|
ChannelSecret secret = secretProvider.get(account.credentialRef()); |
|
|
|
ChannelSecret secret = secretProvider.get(account.credentialRef()); |
|
|
|
@ -440,17 +540,21 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
* 没有账户也要能埋点的调用({@code capabilities}):成功路径能拿到真实账户, |
|
|
|
* 没有账户也要能埋点的调用({@code capabilities}):成功路径能拿到真实账户, |
|
|
|
* 账户缺失时用 {@link ChannelContext#ofKey} 记一条失败记录,而不是什么都没留。 |
|
|
|
* 账户缺失时用 {@link ChannelContext#ofKey} 记一条失败记录,而不是什么都没留。 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ChannelContext contextFor(AccountKey key) { |
|
|
|
/** |
|
|
|
Optional<ChannelAccount> account = |
|
|
|
* 没有账户也能埋点的上下文:查得到就用真实账户,查不到就用「平台 + 空店铺」的占位 key, |
|
|
|
accountRepository.findByKey(key.provider().name(), key.platform().name(), key.omsStoreId()); |
|
|
|
* 保证失败记录里至少能看到是哪个平台出的问题。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private ChannelContext contextFor(Platform platform) { |
|
|
|
|
|
|
|
Optional<ChannelAccount> account = accountRepository.findByPlatform(platform); |
|
|
|
return account.isPresent() |
|
|
|
return account.isPresent() |
|
|
|
? ChannelContext.ofAccount(account.get(), newRequestId(), clock) |
|
|
|
? ChannelContext.ofAccount(account.get(), newRequestId(), clock) |
|
|
|
: ChannelContext.ofKey(key, newRequestId(), clock); |
|
|
|
: ChannelContext.ofKey(AccountKey.of(ChannelProvider.DIRECT, platform), |
|
|
|
|
|
|
|
newRequestId(), clock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 注册维度:provider + platform。同一组合下只能有一个适配器。 */ |
|
|
|
/** 注册维度:platform。一个平台只允许一个适配器(一平台一渠道)。 */ |
|
|
|
private static String registryKey(AccountKey key) { |
|
|
|
private static String registryKey(Platform platform) { |
|
|
|
return key.provider().name() + '|' + key.platform().name(); |
|
|
|
return platform.name(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------ builder
|
|
|
|
// ------------------------------------------------------------------ builder
|
|
|
|
@ -516,6 +620,14 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 注入密钥查询器。与 {@link #secretProvider(SecretProvider)} 同一个注入点, |
|
|
|
|
|
|
|
* 新名字用于强调「传的是查询器,不是密钥」。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Builder secretLookup(SecretProvider secretProvider) { |
|
|
|
|
|
|
|
return secretProvider(secretProvider); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 注入账户仓库。<b>必需</b>。 |
|
|
|
* 注入账户仓库。<b>必需</b>。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>SDK 用它把 {@link AccountKey} 解析成 {@link ChannelAccount}; |
|
|
|
* <p>SDK 用它把 {@link AccountKey} 解析成 {@link ChannelAccount}; |
|
|
|
@ -527,6 +639,14 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 注入账户查询器(平台 → 配置行)。与 {@link #accountRepository(ChannelAccountRepository)} |
|
|
|
|
|
|
|
* 同一个注入点,新名字用于强调「传的是查询器,不是账户」。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Builder accountLookup(ChannelAccountRepository accountRepository) { |
|
|
|
|
|
|
|
return accountRepository(accountRepository); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 注入时钟,默认 {@link Clock#systemUTC()}。 |
|
|
|
* 注入时钟,默认 {@link Clock#systemUTC()}。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>作用:查询未传 {@code updatedBefore} 时的终点时间,以及幂等记录的时间戳。 |
|
|
|
* <p>作用:查询未传 {@code updatedBefore} 时的终点时间,以及幂等记录的时间戳。 |
|
|
|
@ -615,11 +735,16 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
public Builder register(PlatformAdapter adapter) { |
|
|
|
public Builder register(PlatformAdapter adapter) { |
|
|
|
Objects.requireNonNull(adapter, "adapter"); |
|
|
|
Objects.requireNonNull(adapter, "adapter"); |
|
|
|
for (Platform p : adapter.platforms()) { |
|
|
|
for (Platform p : adapter.platforms()) { |
|
|
|
put(adapter.provider().name() + '|' + p.name(), adapter); |
|
|
|
put(platformKey(p), adapter); |
|
|
|
} |
|
|
|
} |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 注册维度:一个平台只允许一个适配器。 */ |
|
|
|
|
|
|
|
private static String platformKey(Platform p) { |
|
|
|
|
|
|
|
return p.name(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 构建门面。 |
|
|
|
* 构建门面。 |
|
|
|
* |
|
|
|
* |
|
|
|
@ -651,8 +776,10 @@ public final class ChannelSdk implements ProviderResolver { |
|
|
|
private void put(String key, PlatformAdapter adapter) { |
|
|
|
private void put(String key, PlatformAdapter adapter) { |
|
|
|
PlatformAdapter previous = adapters.put(key, adapter); |
|
|
|
PlatformAdapter previous = adapters.put(key, adapter); |
|
|
|
if (previous != null && previous != adapter) { |
|
|
|
if (previous != null && previous != adapter) { |
|
|
|
throw new IllegalStateException("duplicate adapter for " + key |
|
|
|
throw new IllegalStateException("platform " + key |
|
|
|
+ ": " + previous.adapterId() + " / " + adapter.adapterId()); |
|
|
|
+ " is claimed by two adapters: " + previous.adapterId() |
|
|
|
|
|
|
|
+ " / " + adapter.adapterId() |
|
|
|
|
|
|
|
+ " — one platform can only map to one channel"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|