Search in sources :

Example 1 with Parameter

use of org.craftercms.commons.plugin.model.Parameter in project commons by craftercms.

the class PluginDescriptorReaderImplTest method testParameters.

@Test
public void testParameters() throws IOException, PluginException {
    Parameter param = new Parameter();
    param.setLabel("Optional Key");
    param.setName("optionalKey");
    param.setRequired(false);
    param.setType(Parameter.Type.PASSWORD);
    try (InputStream is = descriptorParams.getInputStream()) {
        PluginDescriptor descriptor = reader.read(is);
        assertNull(descriptor.getBlueprint());
        assertNotNull(descriptor.getPlugin());
        Plugin plugin = descriptor.getPlugin();
        assertNotNull(plugin.getParameters());
        assertEquals(3, plugin.getParameters().size());
        assertEquals("AWS Access Key", plugin.getParameters().get(0).getLabel());
        assertEquals("awsAccessKey", plugin.getParameters().get(0).getName());
        assertEquals(param, plugin.getParameters().get(2));
    }
}
Also used : PluginDescriptor(org.craftercms.commons.plugin.model.PluginDescriptor) InputStream(java.io.InputStream) Parameter(org.craftercms.commons.plugin.model.Parameter) Plugin(org.craftercms.commons.plugin.model.Plugin) Test(org.junit.Test)

Example 2 with Parameter

use of org.craftercms.commons.plugin.model.Parameter in project studio by craftercms.

the class SitesServiceInternalImpl method validateBlueprintParameters.

@Override
public void validateBlueprintParameters(final PluginDescriptor descriptor, final Map<String, String> params) throws MissingPluginParameterException {
    Plugin plugin = descriptor.getPlugin();
    if (CollectionUtils.isEmpty(plugin.getParameters())) {
        logger.debug("There are no parameters defined for blueprint: {0}", plugin.getId());
        return;
    }
    for (Parameter param : plugin.getParameters()) {
        logger.debug("Checking parameter {0} for blueprint {1}", param.getName(), plugin.getId());
        if (param.isRequired()) {
            if (!params.containsKey(param.getName()) || StringUtils.isEmpty(params.get(param.getName()))) {
                throw new MissingPluginParameterException(descriptor, param);
            }
        } else {
            params.putIfAbsent(param.getName(), param.getDefaultValue());
        }
    }
    logger.debug("All required parameters are present for blueprint: {0}", plugin.getId());
}
Also used : Parameter(org.craftercms.commons.plugin.model.Parameter) MissingPluginParameterException(org.craftercms.studio.api.v2.exception.MissingPluginParameterException) Plugin(org.craftercms.commons.plugin.model.Plugin)

Aggregations

Parameter (org.craftercms.commons.plugin.model.Parameter)2 Plugin (org.craftercms.commons.plugin.model.Plugin)2 InputStream (java.io.InputStream)1 PluginDescriptor (org.craftercms.commons.plugin.model.PluginDescriptor)1 MissingPluginParameterException (org.craftercms.studio.api.v2.exception.MissingPluginParameterException)1 Test (org.junit.Test)1