org.jboss.hal.meta.description.ResourceDescriptionAddressProcessor Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2022 Red Hat
*
* 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
*
* https://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.
*/
package org.jboss.hal.meta.description;
import java.util.List;
import java.util.function.Function;
import org.jboss.hal.dmr.ResourceAddress;
import static java.util.stream.Collectors.toList;
/**
* Function which takes a resource address and replaces specific values with "*". Applied to addresses from the r-r-d result
* before they are {@linkplain ResourceDescriptionRegistry#add(ResourceAddress, ResourceDescription, boolean)} added} to the
* resource description registry.
*
* The following parts of a resource address are modified by this function:
*
* - {@code host} (only if segments > 1)
* - {@code server-group}
* - {@code server} (if it's the 2nd segment of the address)
* - {@code server-config} (if it's the 2nd segment of the address)
*
*
* Examples:
*
*
* /host=primary/server-config=server-one → /host=*/server-config=*
* /host=primary/server=server-one/subsystem=data-sources → /host=*/server=*/subsystem=data-sources
* /server-group=main-server-group → /server-group=*
* /subsystem=mail/mail-session=foo/server=bar → /subsystem=mail/mail-session=foo/server=bar
*
*/
public class ResourceDescriptionAddressProcessor implements Function {
@Override
public ResourceAddress apply(ResourceAddress address) {
ResourceAddress modified = new ResourceAddress();
if (address != null && !address.isEmpty()) {
List segments = address.asPropertyList().stream()
.map(property -> new String[] { property.getName(), property.getValue().asString() })
.collect(toList());
SegmentProcessor.process(segments, segment -> modified.add(segment[0], segment[1]));
}
return modified;
}
}