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));
}
}
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());
}
Aggregations