use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method deletePolicy.
/**
* @see io.apiman.manager.api.core.IStorage#deletePolicy(io.apiman.manager.api.beans.policies.PolicyBean)
*/
@Override
public void deletePolicy(PolicyBean policy) throws StorageException {
String docType = getPoliciesDocType(policy.getType());
String pid = id(policy.getOrganizationId(), policy.getEntityId(), policy.getEntityVersion());
Map<String, Object> source = getEntity(docType, pid);
if (source == null) {
// $NON-NLS-1$
throw new StorageException("Policy not found.");
}
PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
// $NON-NLS-1$
if (policies == null)
throw new StorageException("Policy not found.");
List<PolicyBean> policyBeans = policies.getPolicies();
boolean found = false;
if (policyBeans != null) {
for (PolicyBean policyBean : policyBeans) {
if (policyBean.getId().equals(policy.getId())) {
policies.getPolicies().remove(policyBean);
found = true;
break;
}
}
}
if (found) {
updateEntity(docType, pid, EsMarshalling.marshall(policies));
} else {
// $NON-NLS-1$
throw new StorageException("Policy not found.");
}
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method createPolicy.
/**
* @see io.apiman.manager.api.core.IStorage#createPolicy(io.apiman.manager.api.beans.policies.PolicyBean)
*/
@Override
public void createPolicy(PolicyBean policy) throws StorageException {
String docType = getPoliciesDocType(policy.getType());
String id = id(policy.getOrganizationId(), policy.getEntityId(), policy.getEntityVersion());
Map<String, Object> source = getEntity(docType, id);
if (source == null) {
// $NON-NLS-1$
throw new StorageException("Failed to create policy (missing PoliciesBean).");
}
PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
policy.setId(generateGuid());
policies.getPolicies().add(policy);
orderPolicies(policies);
updateEntity(docType, id, EsMarshalling.marshall(policies));
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method reorderPolicies.
/**
* @see io.apiman.manager.api.core.IStorage#reorderPolicies(io.apiman.manager.api.beans.policies.PolicyType, java.lang.String, java.lang.String, java.lang.String, java.util.List)
*/
@Override
public void reorderPolicies(PolicyType type, String organizationId, String entityId, String entityVersion, List<Long> newOrder) throws StorageException {
String docType = getPoliciesDocType(type);
String pid = id(organizationId, entityId, entityVersion);
Map<String, Object> source = getEntity(docType, pid);
if (source == null) {
return;
}
PoliciesBean policiesBean = EsMarshalling.unmarshallPolicies(source);
List<PolicyBean> policies = policiesBean.getPolicies();
List<PolicyBean> reordered = new ArrayList<>(policies.size());
for (Long policyId : newOrder) {
ListIterator<PolicyBean> iterator = policies.listIterator();
while (iterator.hasNext()) {
PolicyBean policyBean = iterator.next();
if (policyBean.getId().equals(policyId)) {
iterator.remove();
reordered.add(policyBean);
break;
}
}
}
// remaining at the end of the list.
for (PolicyBean policyBean : policies) {
reordered.add(policyBean);
}
policiesBean.setPolicies(reordered);
updateEntity(docType, pid, EsMarshalling.marshall(policiesBean));
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method getPolicies.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getPolicies(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.PolicyType)
*/
@Override
public List<PolicySummaryBean> getPolicies(String organizationId, String entityId, String version, PolicyType type) throws StorageException {
try {
String docType = getPoliciesDocType(type);
String pid = id(organizationId, entityId, version);
List<PolicySummaryBean> rval = new ArrayList<>();
Map<String, Object> source = getEntity(docType, pid);
if (source == null) {
return rval;
}
PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
if (policies == null)
return rval;
List<PolicyBean> policyBeans = policies.getPolicies();
if (policyBeans != null) {
for (PolicyBean policyBean : policyBeans) {
PolicyDefinitionBean def = getPolicyDefinition(policyBean.getDefinition().getId());
policyBean.setDefinition(def);
PolicyTemplateUtil.generatePolicyDescription(policyBean);
PolicySummaryBean psb = new PolicySummaryBean();
psb.setCreatedBy(policyBean.getCreatedBy());
psb.setCreatedOn(policyBean.getCreatedOn());
psb.setDescription(policyBean.getDescription());
psb.setIcon(def.getIcon());
psb.setId(policyBean.getId());
psb.setName(policyBean.getName());
psb.setPolicyDefinitionId(def.getId());
rval.add(psb);
}
}
return rval;
} catch (Exception e) {
throw new StorageException(e);
}
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method getAllPolicies.
/**
* @see io.apiman.manager.api.core.IStorage#getAllPolicies(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.PolicyType)
*/
@Override
public Iterator<PolicyBean> getAllPolicies(String organizationId, String entityId, String version, PolicyType type) throws StorageException {
try {
String docType = getPoliciesDocType(type);
String pid = id(organizationId, entityId, version);
Map<String, Object> source = getEntity(docType, pid);
PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
if (policies == null || policies.getPolicies() == null) {
return new ArrayList<PolicyBean>().iterator();
}
List<PolicyBean> policyBeans = policies.getPolicies();
// TODO resolve the policy def, since we know we'll only have the definition ID here
for (PolicyBean policyBean : policyBeans) {
PolicyDefinitionBean def = getPolicyDefinition(policyBean.getDefinition().getId());
if (def != null) {
policyBean.setDefinition(def);
}
}
return policyBeans.iterator();
} catch (Exception e) {
throw new StorageException(e);
}
}
Aggregations