use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.
the class ContractService method aggregateContractPolicies.
/**
* Aggregates the API, client, and plan policies into a single ordered list.
*/
public List<Policy> aggregateContractPolicies(ContractSummaryBean contractBean) {
try {
List<Policy> policies = new ArrayList<>();
PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
for (PolicyType policyType : types) {
String org, id, ver;
switch(policyType) {
case Client:
{
org = contractBean.getClientOrganizationId();
id = contractBean.getClientId();
ver = contractBean.getClientVersion();
break;
}
case Plan:
{
org = contractBean.getApiOrganizationId();
id = contractBean.getPlanId();
ver = contractBean.getPlanVersion();
break;
}
case Api:
{
org = contractBean.getApiOrganizationId();
id = contractBean.getApiId();
ver = contractBean.getApiVersion();
break;
}
default:
{
// $NON-NLS-1$
throw new RuntimeException("Missing case for switch!");
}
}
List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
for (PolicySummaryBean policySummaryBean : clientPolicies) {
PolicyBean policyBean = storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId());
Policy policy = new Policy();
policy.setPolicyJsonConfig(policyBean.getConfiguration());
policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
policies.add(policy);
}
}
return policies;
} catch (Exception e) {
throw ExceptionFactory.actionException(Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getClientId() + "->" + contractBean.getApiDescription()), // $NON-NLS-1$ //$NON-NLS-2$
e);
}
}
use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.
the class StorageImportDispatcher method aggregateContractPolicies.
/**
* Aggregates the api, client, and plan policies into a single ordered list.
* @param contractBean
* @param clientInfo
*/
private List<Policy> aggregateContractPolicies(ContractBean contractBean, EntityInfo clientInfo) throws StorageException {
List<Policy> policies = new ArrayList<>();
PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
for (PolicyType policyType : types) {
String org, id, ver;
switch(policyType) {
case Client:
{
org = clientInfo.organizationId;
id = clientInfo.id;
ver = clientInfo.version;
break;
}
case Plan:
{
org = contractBean.getApi().getApi().getOrganization().getId();
id = contractBean.getPlan().getPlan().getId();
ver = contractBean.getPlan().getVersion();
break;
}
case Api:
{
org = contractBean.getApi().getApi().getOrganization().getId();
id = contractBean.getApi().getApi().getId();
ver = contractBean.getApi().getVersion();
break;
}
default:
{
// $NON-NLS-1$
throw new RuntimeException("Missing case for switch!");
}
}
Iterator<PolicyBean> clientPolicies = storage.getAllPolicies(org, id, ver, policyType);
while (clientPolicies.hasNext()) {
PolicyBean policyBean = clientPolicies.next();
Policy policy = new Policy();
policy.setPolicyJsonConfig(policyBean.getConfiguration());
policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
policies.add(policy);
}
}
return policies;
}
use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.
the class ContractService method aggregateContractPolicies.
public List<PolicyBean> aggregateContractPolicies(ContractBean contractBean) {
try {
List<PolicyBean> policies = new ArrayList<>();
PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
for (PolicyType policyType : types) {
String org, id, ver;
switch(policyType) {
case Client:
{
org = contractBean.getClient().getClient().getOrganization().getId();
id = contractBean.getClient().getClient().getId();
ver = contractBean.getClient().getVersion();
break;
}
case Plan:
{
org = contractBean.getPlan().getPlan().getOrganization().getId();
id = contractBean.getPlan().getPlan().getId();
ver = contractBean.getPlan().getVersion();
break;
}
case Api:
{
org = contractBean.getApi().getApi().getOrganization().getId();
id = contractBean.getApi().getApi().getId();
ver = contractBean.getApi().getVersion();
break;
}
default:
{
// $NON-NLS-1$
throw new RuntimeException("Missing case for switch!");
}
}
List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
for (PolicySummaryBean policySummaryBean : clientPolicies) {
policies.add(storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId()));
}
}
return policies;
} catch (Exception e) {
throw ExceptionFactory.actionException(// $NON-NLS-1$ //$NON-NLS-2$
Messages.i18n.format("ErrorAggregatingPolicies", e));
}
}
use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.
the class ActionResourceImpl method aggregateContractPolicies.
/**
* Aggregates the API, client, and plan policies into a single ordered list.
* @param contractBean
*/
private List<Policy> aggregateContractPolicies(ContractSummaryBean contractBean) {
try {
List<Policy> policies = new ArrayList<>();
PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
for (PolicyType policyType : types) {
String org, id, ver;
switch(policyType) {
case Client:
{
org = contractBean.getClientOrganizationId();
id = contractBean.getClientId();
ver = contractBean.getClientVersion();
break;
}
case Plan:
{
org = contractBean.getApiOrganizationId();
id = contractBean.getPlanId();
ver = contractBean.getPlanVersion();
break;
}
case Api:
{
org = contractBean.getApiOrganizationId();
id = contractBean.getApiId();
ver = contractBean.getApiVersion();
break;
}
default:
{
// $NON-NLS-1$
throw new RuntimeException("Missing case for switch!");
}
}
List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
try {
storage.beginTx();
for (PolicySummaryBean policySummaryBean : clientPolicies) {
PolicyBean policyBean = storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId());
Policy policy = new Policy();
policy.setPolicyJsonConfig(policyBean.getConfiguration());
policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
policies.add(policy);
}
} finally {
storage.rollbackTx();
}
}
return policies;
} catch (Exception e) {
throw ExceptionFactory.actionException(Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getClientId() + "->" + contractBean.getApiDescription()), // $NON-NLS-1$ //$NON-NLS-2$
e);
}
}
Aggregations