Search in sources :

Example 1 with PluginBean

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;
}
Also used : PluginBean(io.apiman.manager.api.beans.plugins.PluginBean)

Example 2 with PluginBean

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);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) PluginCoordinates(io.apiman.common.plugin.PluginCoordinates) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) NewPluginBean(io.apiman.manager.api.beans.plugins.NewPluginBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) PluginNotFoundException(io.apiman.manager.api.rest.exceptions.PluginNotFoundException) PluginResourceNotFoundException(io.apiman.manager.api.rest.exceptions.PluginResourceNotFoundException) InvalidPluginException(io.apiman.manager.api.core.exceptions.InvalidPluginException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) IOException(java.io.IOException) PluginAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PluginAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) Plugin(io.apiman.common.plugin.Plugin) PluginClassLoader(io.apiman.common.plugin.PluginClassLoader)

Example 3 with PluginBean

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);
    }
}
Also used : PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 4 with PluginBean

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;
}
Also used : PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 5 with PluginBean

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);
    }
}
Also used : PluginBean(io.apiman.manager.api.beans.plugins.PluginBean)

Aggregations

PluginBean (io.apiman.manager.api.beans.plugins.PluginBean)10 StorageException (io.apiman.manager.api.core.exceptions.StorageException)7 NewPluginBean (io.apiman.manager.api.beans.plugins.NewPluginBean)4 InvalidPluginException (io.apiman.manager.api.core.exceptions.InvalidPluginException)4 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)4 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)4 PluginAlreadyExistsException (io.apiman.manager.api.rest.exceptions.PluginAlreadyExistsException)4 PluginNotFoundException (io.apiman.manager.api.rest.exceptions.PluginNotFoundException)4 PluginResourceNotFoundException (io.apiman.manager.api.rest.exceptions.PluginResourceNotFoundException)4 PolicyDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)4 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)4 IOException (java.io.IOException)4 PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)3 Plugin (io.apiman.common.plugin.Plugin)2 PluginCoordinates (io.apiman.common.plugin.PluginCoordinates)2 PluginClassLoader (io.apiman.common.plugin.PluginClassLoader)1 PolicyDefinitionSummaryBean (io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean)1 IStorageQuery (io.apiman.manager.api.core.IStorageQuery)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1