use of io.apiman.manager.api.beans.plugins.PluginBean in project apiman by apiman.
the class EsMarshalling method unmarshallPlugin.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the plugin
*/
public static PluginBean unmarshallPlugin(Map<String, Object> source) {
if (source == null) {
return null;
}
PluginBean bean = new PluginBean();
bean.setId(asLong(source.get("id")));
bean.setName(asString(source.get("name")));
bean.setDescription(asString(source.get("description")));
bean.setCreatedBy(asString(source.get("createdBy")));
bean.setCreatedOn(asDate(source.get("createdOn")));
bean.setGroupId(asString(source.get("groupId")));
bean.setArtifactId(asString(source.get("artifactId")));
bean.setVersion(asString(source.get("version")));
bean.setType(asString(source.get("type")));
bean.setClassifier(asString(source.get("classifier")));
bean.setDeleted(asBoolean(source.get("deleted")));
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.plugins.PluginBean in project apiman by apiman.
the class PluginResourceImpl method getPolicyForm.
/**
* @see IPluginResource#getPolicyForm(java.lang.Long, java.lang.String)
*/
@Override
public String getPolicyForm(Long pluginId, String policyDefId) throws PluginNotFoundException, PluginResourceNotFoundException, PolicyDefinitionNotFoundException {
// No permission check is needed
PluginBean pbean;
PolicyDefinitionBean pdBean;
try {
pbean = storage.getPlugin(pluginId);
if (pbean == null) {
throw ExceptionFactory.pluginNotFoundException(pluginId);
}
pdBean = storage.getPolicyDefinition(policyDefId);
} catch (AbstractRestException e) {
throw e;
} catch (Exception e) {
throw new SystemErrorException(e);
}
PluginCoordinates coordinates = new PluginCoordinates(pbean.getGroupId(), pbean.getArtifactId(), pbean.getVersion(), pbean.getClassifier(), pbean.getType());
try {
if (pdBean == null) {
throw ExceptionFactory.policyDefNotFoundException(policyDefId);
}
if (pdBean.getPluginId() == null || !pdBean.getPluginId().equals(pbean.getId())) {
throw ExceptionFactory.pluginNotFoundException(pluginId);
}
if (pdBean.getFormType() == PolicyFormType.JsonSchema && pdBean.getForm() != null) {
String formPath = pdBean.getForm();
if (!formPath.startsWith("/")) {
// $NON-NLS-1$
// $NON-NLS-1$
formPath = "META-INF/apiman/policyDefs/" + formPath;
} else {
formPath = formPath.substring(1);
}
Plugin plugin = pluginRegistry.loadPlugin(coordinates);
PluginClassLoader loader = plugin.getLoader();
InputStream resource = null;
try {
resource = loader.getResourceAsStream(formPath);
if (resource == null) {
throw ExceptionFactory.pluginResourceNotFoundException(formPath, coordinates);
}
StringWriter writer = new StringWriter();
IOUtils.copy(resource, writer);
return writer.toString();
} finally {
IOUtils.closeQuietly(resource);
}
} else {
throw ExceptionFactory.pluginResourceNotFoundException(null, coordinates);
}
} catch (AbstractRestException e) {
throw e;
} catch (Throwable t) {
throw new SystemErrorException(t);
}
}
use of io.apiman.manager.api.beans.plugins.PluginBean in project apiman by apiman.
the class StorageImportDispatcher method plugin.
/**
* @see io.apiman.manager.api.exportimport.read.IImportReaderDispatcher#plugin(io.apiman.manager.api.beans.plugins.PluginBean)
*/
@Override
public void plugin(PluginBean plugin) {
try {
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageImportDispatcher.ImportingPlugin") + plugin.getGroupId() + '/' + plugin.getArtifactId() + '/' + plugin.getVersion());
mapPluginIds(plugin);
// Check if the plugin exists,
// if there is more then one plugin of same type (different IDs) a new one will be generated
PluginBean pluginBean = storage.getPlugin(plugin.getGroupId(), plugin.getArtifactId());
if (pluginBean != null) {
// Set the id explicit because the update method will not check if the id really exists
// The update method will create a new plugin if the element not exists!
plugin.setId(pluginBean.getId());
storage.updatePlugin(plugin);
} else {
plugin.setId(null);
storage.createPlugin(plugin);
}
} catch (StorageException e) {
error(e);
}
}
use of io.apiman.manager.api.beans.plugins.PluginBean in project apiman by apiman.
the class StorageImportDispatcher method updatePluginIdInPolicyDefinition.
/**
* Update the pluginID in the policyDefinition to the new generated pluginID
* @param policyDef the policy definition to be updated
* @return updated PolicyDefinitionBean policyDef
*/
private PolicyDefinitionBean updatePluginIdInPolicyDefinition(PolicyDefinitionBean policyDef) {
if (pluginBeanIdMap.containsKey(policyDef.getPluginId())) {
try {
Map.Entry<String, String> pluginCoordinates = pluginBeanIdMap.get(policyDef.getPluginId());
PluginBean plugin = storage.getPlugin(pluginCoordinates.getKey(), pluginCoordinates.getValue());
policyDef.setPluginId(plugin.getId());
} catch (StorageException e) {
error(e);
}
}
return policyDef;
}
use of io.apiman.manager.api.beans.plugins.PluginBean in project apiman by apiman.
the class StorageExporter method exportPlugins.
private void exportPlugins() {
try {
Iterator<PluginBean> iter = storage.getAllPlugins();
writer.startPlugins();
while (iter.hasNext()) {
PluginBean bean = iter.next();
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageExporter.ExportingPlugin") + bean);
writer.writePlugin(bean);
}
writer.endPlugins();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations