use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsMarshalling method unmarshallPolicies.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the policy beans
*/
@SuppressWarnings("unchecked")
public static PoliciesBean unmarshallPolicies(Map<String, Object> source) {
if (source == null) {
return null;
}
PoliciesBean bean = new PoliciesBean();
bean.setOrganizationId(asString(source.get("organizationId")));
bean.setEntityId(asString(source.get("entityId")));
bean.setEntityVersion(asString(source.get("entityVersion")));
bean.setType(asEnum(source.get("type"), PolicyType.class));
List<Map<String, Object>> policies = (List<Map<String, Object>>) source.get("policies");
if (policies != null) {
for (Map<String, Object> policyMap : policies) {
PolicyBean policy = new PolicyBean();
policy.setOrganizationId(bean.getOrganizationId());
policy.setEntityId(bean.getEntityId());
policy.setEntityVersion(bean.getEntityVersion());
policy.setType(bean.getType());
policy.setConfiguration(asString(policyMap.get("configuration")));
policy.setCreatedBy(asString(policyMap.get("createdBy")));
policy.setCreatedOn(asDate(policyMap.get("createdOn")));
PolicyDefinitionBean def = new PolicyDefinitionBean();
def.setId(asString(policyMap.get("definitionId")));
// Note: this is a placeholder that needs to be resolved later.
policy.setDefinition(def);
policy.setId(asLong(policyMap.get("id")));
policy.setModifiedBy(asString(policyMap.get("modifiedBy")));
policy.setModifiedOn(asDate(policyMap.get("modifiedOn")));
policy.setName(asString(policyMap.get("name")));
policy.setOrderIndex(asInt(policyMap.get("orderIndex")));
bean.getPolicies().add(policy);
}
}
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method createClientVersion.
/**
* @see io.apiman.manager.api.core.IStorage#createClientVersion(io.apiman.manager.api.beans.clients.ClientVersionBean)
*/
@Override
public void createClientVersion(ClientVersionBean version) throws StorageException {
ClientBean client = version.getClient();
String id = id(client.getOrganization().getId(), client.getId(), version.getVersion());
indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_VERSION, id, EsMarshalling.marshall(version));
PoliciesBean policies = PoliciesBean.from(PolicyType.Client, client.getOrganization().getId(), client.getId(), version.getVersion());
indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_POLICIES, id, EsMarshalling.marshall(policies));
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method updatePolicy.
/**
* @see io.apiman.manager.api.core.IStorage#updatePolicy(io.apiman.manager.api.beans.policies.PolicyBean)
*/
@Override
public void updatePolicy(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);
List<PolicyBean> policyBeans = policies.getPolicies();
boolean found = false;
if (policyBeans != null) {
for (PolicyBean policyBean : policyBeans) {
if (policyBean.getId().equals(policy.getId())) {
policyBean.setConfiguration(policy.getConfiguration());
policyBean.setModifiedBy(policy.getModifiedBy());
policyBean.setModifiedOn(policy.getModifiedOn());
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 createApiVersion.
/**
* @see io.apiman.manager.api.core.IStorage#createApiVersion(io.apiman.manager.api.beans.apis.ApiVersionBean)
*/
@Override
public void createApiVersion(ApiVersionBean version) throws StorageException {
ApiBean api = version.getApi();
String id = id(api.getOrganization().getId(), api.getId(), version.getVersion());
indexEntity(INDEX_MANAGER_POSTFIX_API_VERSION, id, EsMarshalling.marshall(version));
PoliciesBean policies = PoliciesBean.from(PolicyType.Api, api.getOrganization().getId(), api.getId(), version.getVersion());
indexEntity(INDEX_MANAGER_POSTFIX_API_POLICIES, id, EsMarshalling.marshall(policies));
}
use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.
the class EsStorage method getPolicy.
/**
* @see io.apiman.manager.api.core.IStorage#getPolicy(io.apiman.manager.api.beans.policies.PolicyType, java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
*/
@Override
public PolicyBean getPolicy(PolicyType type, String organizationId, String entityId, String version, Long id) throws StorageException {
String docType = getPoliciesDocType(type);
String pid = id(organizationId, entityId, version);
Map<String, Object> source = getEntity(docType, pid);
if (source == null) {
return null;
}
PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
if (policies == null)
return null;
List<PolicyBean> policyBeans = policies.getPolicies();
if (policyBeans != null) {
for (PolicyBean policyBean : policyBeans) {
if (policyBean.getId().equals(id)) {
PolicyDefinitionBean def = getPolicyDefinition(policyBean.getDefinition().getId());
policyBean.setDefinition(def);
return policyBean;
}
}
}
return null;
}
Aggregations