use of org.codice.ddf.admin.common.fields.base.ListFieldImpl in project admin-console-beta by connexta.
the class SourceUtilCommons method getSourceConfigurations.
/**
* Gets the configurations for the given factoryPids using the {@link ConfiguratorFactory}. A mapper is used
* to transform the service properties to a {@link SourceConfigUnionField}. Providing the pid parameter
* will return only the configuration with that pid.
*
* @param factoryPids factory pids to lookup configurations for
* @param mapper a {@link Function} taking a map of string to objects and returning a {@code SourceConfigUnionField}
* @param pid a servicePid to select a single configuration, returns all configs when null or empty
* @return a list of {@code SourceInfoField}s configured in the system
*/
public static ListField<SourceInfoField> getSourceConfigurations(List<String> factoryPids, Function<Map<String, Object>, SourceConfigUnionField> mapper, String pid, ConfiguratorFactory configuratorFactory) {
ListFieldImpl<SourceInfoField> sourceInfoListField = new ListFieldImpl<>(SourceInfoField.class);
ConfigReader configReader = configuratorFactory.getConfigReader();
if (StringUtils.isNotEmpty(pid)) {
SourceConfigUnionField config = mapper.apply(configReader.getConfig(pid));
sourceInfoListField.add(createSourceInfoField(true, config));
populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
return sourceInfoListField;
}
factoryPids.stream().flatMap(factoryPid -> configReader.getManagedServiceConfigs(factoryPid).values().stream()).map(mapper).forEach(config -> sourceInfoListField.add(createSourceInfoField(false, config)));
populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
return sourceInfoListField;
}
use of org.codice.ddf.admin.common.fields.base.ListFieldImpl in project admin-console-beta by connexta.
the class PolicyManagerServiceProperties method contextPolicyServiceToContextPolicyFields.
public ListField<ContextPolicyBin> contextPolicyServiceToContextPolicyFields(ConfiguratorFactory configurator) {
ContextPolicyManager policyManager = configurator.getConfigReader().getServiceReference(ContextPolicyManager.class);
List<ContextPolicyBin> policies = new ArrayList<>();
Collection<ContextPolicy> allPolicies = policyManager.getAllContextPolicies();
for (ContextPolicy policy : allPolicies) {
boolean foundBin = false;
Map<String, String> policyRequiredAttributes = policy.getAllowedAttributes().stream().collect(Collectors.toMap(map -> map.getAttributeName(), map -> map.getAttributeValue()));
//Check if bin containing an identical context policy exists already, if so add the context path to it
for (ContextPolicyBin bin : policies) {
if (bin.realm().equals(policy.getRealm()) && ListUtils.isEqualList(bin.authTypes(), policy.getAuthenticationMethods()) && hasSameRequiredAttributes(bin, policyRequiredAttributes)) {
bin.addContextPath(policy.getContextPath());
foundBin = true;
}
}
if (!foundBin) {
policies.add(new ContextPolicyBin().realm(policy.getRealm()).addClaimsMap(policyRequiredAttributes).authTypes(policy.getAuthenticationMethods()).addContextPath(policy.getContextPath()));
}
}
ListField<ContextPolicyBin> policiesField = new ListFieldImpl<>(ContextPolicyBin.class);
policiesField.addAll(policies);
return policiesField;
}
Aggregations