|
| 1 | +package com.cognifide.apm.core.services; |
| 2 | + |
| 3 | +import com.cognifide.apm.api.services.DefinitionsProvider; |
| 4 | +import com.cognifide.apm.core.Property; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.stream.Collectors; |
| 8 | +import org.apache.commons.lang3.StringUtils; |
| 9 | +import org.osgi.service.component.annotations.Activate; |
| 10 | +import org.osgi.service.component.annotations.Component; |
| 11 | +import org.osgi.service.metatype.annotations.AttributeDefinition; |
| 12 | +import org.osgi.service.metatype.annotations.Designate; |
| 13 | +import org.osgi.service.metatype.annotations.ObjectClassDefinition; |
| 14 | + |
| 15 | +@Component( |
| 16 | + immediate = true, |
| 17 | + property = { |
| 18 | + Property.DESCRIPTION + "APM Custom Definitions Provider", |
| 19 | + Property.VENDOR |
| 20 | + } |
| 21 | +) |
| 22 | +@Designate(ocd = CustomDefinitionsProvider.Configuration.class, factory = true) |
| 23 | +public class CustomDefinitionsProvider implements DefinitionsProvider { |
| 24 | + |
| 25 | + private Map<String, String> predefinedDefinitions; |
| 26 | + |
| 27 | + @Activate |
| 28 | + public void activate(Configuration config) { |
| 29 | + predefinedDefinitions = Arrays.stream(config.definitions()) |
| 30 | + .map(definition -> definition.split("=")) |
| 31 | + .map(parts -> StringUtils.stripAll(parts)) |
| 32 | + .filter(parts -> StringUtils.isNoneEmpty(parts)) |
| 33 | + .filter(parts -> parts.length == 2) |
| 34 | + .collect(Collectors.toMap(parts -> parts[0], parts -> parts[1], (a, b) -> b); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public Map<String, String> getPredefinedDefinitions() { |
| 39 | + return predefinedDefinitions; |
| 40 | + } |
| 41 | + |
| 42 | + @ObjectClassDefinition(name = "AEM Permission Management - Custom Definitions Configuration") |
| 43 | + public @interface Configuration { |
| 44 | + |
| 45 | + @AttributeDefinition(name = "Definitions", description = "format: key=value") |
| 46 | + String[] definitions(); |
| 47 | + } |
| 48 | +} |
0 commit comments