Search in sources :

Example 1 with CasReferenceProperty

use of org.apereo.cas.metadata.CasReferenceProperty in project cas by apereo.

the class CasDocumentationApplication method main.

public static void main(final String[] args) throws Exception {
    var options = new Options();
    var dt = new Option("d", "data", true, "Data directory");
    dt.setRequired(true);
    options.addOption(dt);
    var ver = new Option("v", "version", true, "Project version");
    ver.setRequired(true);
    options.addOption(ver);
    var root = new Option("r", "root", true, "Project root directory");
    root.setRequired(true);
    options.addOption(root);
    var ft = new Option("f", "filter", true, "Property filter pattern");
    ft.setRequired(false);
    options.addOption(ft);
    var act = new Option("a", "actuators", true, "Generate data for actuator endpoints");
    act.setRequired(false);
    options.addOption(act);
    var tp = new Option("tp", "thirdparty", true, "Generate data for third party");
    tp.setRequired(false);
    options.addOption(tp);
    var sp = new Option("sp", "serviceproperties", true, "Generate data for registered services properties");
    sp.setRequired(false);
    options.addOption(sp);
    var feats = new Option("ft", "features", true, "Generate data for feature toggles and descriptors");
    feats.setRequired(false);
    options.addOption(feats);
    new HelpFormatter().printHelp("CAS Documentation", options);
    var cmd = new DefaultParser().parse(options, args);
    var dataDirectory = cmd.getOptionValue("data");
    var projectVersion = cmd.getOptionValue("version");
    var projectRootDirectory = cmd.getOptionValue("root");
    var propertyFilter = cmd.getOptionValue("filter", ".+");
    var results = CasConfigurationMetadataCatalog.query(ConfigurationMetadataCatalogQuery.builder().queryType(ConfigurationMetadataCatalogQuery.QueryTypes.CAS).queryFilter(property -> RegexUtils.find(propertyFilter, property.getName())).build());
    var groups = new HashMap<String, Set<CasReferenceProperty>>();
    results.properties().stream().filter(property -> StringUtils.isNotBlank(property.getModule())).peek(property -> {
        var desc = cleanDescription(property);
        property.setDescription(desc);
    }).forEach(property -> {
        if (groups.containsKey(property.getModule())) {
            groups.get(property.getModule()).add(property);
        } else {
            var values = new TreeSet<CasReferenceProperty>();
            values.add(property);
            groups.put(property.getModule(), values);
        }
    });
    var dataPath = new File(dataDirectory, projectVersion);
    if (dataPath.exists()) {
        FileUtils.deleteQuietly(dataPath);
    }
    dataPath.mkdirs();
    groups.forEach((key, value) -> {
        var destination = new File(dataPath, key);
        destination.mkdirs();
        var configFile = new File(destination, "config.yml");
        CasConfigurationMetadataCatalog.export(configFile, value);
    });
    var thirdparty = cmd.getOptionValue("thirdparty", "true");
    if (StringUtils.equalsIgnoreCase("true", thirdparty)) {
        exportThirdPartyConfiguration(dataPath, propertyFilter);
    }
    var registeredServicesProps = cmd.getOptionValue("serviceproperties", "true");
    if (StringUtils.equalsIgnoreCase("true", registeredServicesProps)) {
        exportRegisteredServiceProperties(dataPath);
    }
    exportTemplateViews(projectRootDirectory, dataPath);
    exportThemeProperties(projectRootDirectory, dataPath);
    var actuators = cmd.getOptionValue("actuators", "true");
    if (StringUtils.equalsIgnoreCase("true", actuators)) {
        exportActuatorEndpoints(dataPath);
    }
    var features = cmd.getOptionValue("features", "true");
    if (StringUtils.equalsIgnoreCase("true", features)) {
        exportFeatureToggles(dataPath);
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) PathVariable(org.springframework.web.bind.annotation.PathVariable) RandomUtils(org.apereo.cas.util.RandomUtils) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation) LoggerFactory(org.slf4j.LoggerFactory) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) DefaultParser(org.apache.commons.cli.DefaultParser) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Method(java.lang.reflect.Method) PostMapping(org.springframework.web.bind.annotation.PostMapping) Unchecked(org.jooq.lambda.Unchecked) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) ClasspathHelper(org.reflections.util.ClasspathHelper) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) Annotation(java.lang.annotation.Annotation) Pattern(java.util.regex.Pattern) RegisteredServiceProperty(org.apereo.cas.services.RegisteredServiceProperty) Options(org.apache.commons.cli.Options) ClassPathResource(org.springframework.core.io.ClassPathResource) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) WriteOperation(org.springframework.boot.actuate.endpoint.annotation.WriteOperation) HelpFormatter(org.apache.commons.cli.HelpFormatter) TreeSet(java.util.TreeSet) DeleteOperation(org.springframework.boot.actuate.endpoint.annotation.DeleteOperation) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Operation(io.swagger.v3.oas.annotations.Operation) HttpServletRequest(javax.servlet.http.HttpServletRequest) GetMapping(org.springframework.web.bind.annotation.GetMapping) Option(org.apache.commons.cli.Option) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) CasReferenceProperty(org.apereo.cas.metadata.CasReferenceProperty) RegExUtils(org.apache.commons.lang3.RegExUtils) Logger(org.slf4j.Logger) Properties(java.util.Properties) Endpoint(org.springframework.boot.actuate.endpoint.annotation.Endpoint) HttpServletResponse(javax.servlet.http.HttpServletResponse) ConfigurationMetadataCatalogQuery(org.apereo.cas.metadata.ConfigurationMetadataCatalogQuery) ConditionalOnFeature(org.apereo.cas.util.spring.boot.ConditionalOnFeature) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) RegexUtils(org.apereo.cas.util.RegexUtils) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) CasFeatureEnabledCondition(org.apereo.cas.util.spring.boot.CasFeatureEnabledCondition) CasConfigurationMetadataCatalog(org.apereo.cas.metadata.CasConfigurationMetadataCatalog) Selector(org.springframework.boot.actuate.endpoint.annotation.Selector) Options(org.apache.commons.cli.Options) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) Option(org.apache.commons.cli.Option) CasReferenceProperty(org.apereo.cas.metadata.CasReferenceProperty) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)1 File (java.io.File)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DefaultParser (org.apache.commons.cli.DefaultParser)1