Skip to content

added custom definitions configuration service #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.jackrabbit.api.JackrabbitSession;
Expand Down Expand Up @@ -193,9 +195,13 @@ private void updateScriptProperties(Script script, ExecutionMode mode, boolean s

@Override
public Map<String, String> getPredefinedDefinitions() {
Map<String, String> predefinedDefinitions = new HashMap<>();
definitionsProviders.forEach(provider -> predefinedDefinitions.putAll(provider.getPredefinedDefinitions()));
return predefinedDefinitions;
return definitionsProviders.stream()
.flatMap(provider -> provider.getPredefinedDefinitions().entrySet().stream())
.collect(Collectors.toMap(
Map.Entry::getKey, Map.Entry::getValue,
(first, second) -> first,
() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)
));
}

private ActionExecutor createExecutor(ExecutionMode mode, ResourceResolver resolver) throws RepositoryException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*-
* ========================LICENSE_START=================================
* AEM Permission Management
* %%
* Copyright (C) 2013 Wunderman Thompson Technology
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package com.cognifide.apm.core.services;

import com.cognifide.apm.api.services.DefinitionsProvider;
import com.cognifide.apm.core.Property;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@Component(
immediate = true,
property = {
Property.DESCRIPTION + "APM Custom Definitions Provider",
Property.VENDOR
}
)
@Designate(ocd = CustomDefinitionsProvider.Configuration.class, factory = true)
public class CustomDefinitionsProvider implements DefinitionsProvider {

private Map<String, String> predefinedDefinitions;

@Activate
public void activate(Configuration config) {
predefinedDefinitions = Arrays.stream(config.definitions())
.map(definition -> definition.split("="))
.map(StringUtils::stripAll)
.filter(StringUtils::isNoneEmpty)
.filter(parts -> parts.length == 2)
.collect(Collectors.toMap(parts -> parts[0], parts -> parts[1], (first, second) -> first));
}

@Override
public Map<String, String> getPredefinedDefinitions() {
return predefinedDefinitions;
}

@ObjectClassDefinition(name = "AEM Permission Management - Custom Definitions Configuration")
public @interface Configuration {

@AttributeDefinition(name = "Definitions", description = "format: key=value")
String[] definitions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* =========================LICENSE_END==================================
*/
package com.cognifide.apm.core.scripts;
package com.cognifide.apm.core.services;

import com.cognifide.apm.api.services.DefinitionsProvider;
import java.util.HashMap;
Expand Down
Loading