use of org.jboss.hal.meta.AddressTemplate in project console by hal.
the class ModclusterPresenter method addLoadProviderDynamic.
public void addLoadProviderDynamic() {
String id = Ids.build("load-provider-dynamic", FORM, ADD);
AddressTemplate template = LOAD_PROVIDER_DYNAMIC_TEMPLATE.replaceWildcards(proxyName);
crud.addSingleton(id, Names.LOAD_PROVIDER_DYNAMIC, template, address -> reload());
}
use of org.jboss.hal.meta.AddressTemplate in project console by hal.
the class FormProcessor method process.
@Override
public void process(VariableElement field, Element element, String selector, MbuiViewContext context) {
String title = element.getAttributeValue(XmlTags.TITLE);
boolean autoSave = Boolean.parseBoolean(element.getAttributeValue(XmlTags.AUTO_SAVE));
String addHandler = element.getAttributeValue(XmlTags.ADD_HANDLER);
boolean reset = Boolean.parseBoolean(element.getAttributeValue(XmlTags.RESET));
boolean includeRuntime = Boolean.parseBoolean(element.getAttributeValue(XmlTags.INCLUDE_RUNTIME));
boolean singleton = XmlTags.SINGLETON_FORM.equalsIgnoreCase(element.getName());
String onSave = element.getAttributeValue(XmlTags.ON_SAVE);
String prepareReset = element.getAttributeValue(XmlTags.PREPARE_RESET);
String nameResolver = element.getAttributeValue(XmlTags.NAME_RESOLVER);
MetadataInfo metadata = findMetadata(field, element, context);
AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
if (autoSave && !Strings.isNullOrEmpty(onSave)) {
processor.error(field, "Please choose either auto-save or on-save not both.");
} else if (autoSave) {
if (title == null) {
title = new LabelBuilder().label(template.lastName());
}
if (nameResolver != null && !ExpressionParser.isExpression(nameResolver)) {
processor.error(field, "Name resolver in form#%s has to be an expression.", selector);
}
if ("*".equals(template.lastValue()) && nameResolver == null) {
processor.error(field, "Auto save is enabled for form#%s and related metadata address ends in \"*\", " + "but no name resolver is is provided.", selector);
}
} else if (!Strings.isNullOrEmpty(onSave)) {
if (!ExpressionParser.isExpression(onSave)) {
processor.error(field, "on-save handler in form#%s has to be an expression.", selector);
}
}
FormInfo formInfo = new FormInfo(field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title, addHandler, autoSave, onSave, reset, prepareReset, nameResolver, includeRuntime, singleton);
context.addFormInfo(formInfo);
org.jdom2.Element attributesContainer = element.getChild(XmlTags.ATTRIBUTES);
if (attributesContainer != null) {
List<Element> groupElements = attributesContainer.getChildren(XmlTags.GROUP);
if (groupElements.isEmpty()) {
processAttributes(field, attributesContainer).forEach(formInfo::addAttribute);
} else {
Map<String, Element> excludes = new HashMap<>();
Map<String, FormInfo.Group> groupsById = new HashMap<>();
// round one: process groups
for (Element groupElement : groupElements) {
String id = groupElement.getAttributeValue(XmlTags.ID);
String name = groupElement.getAttributeValue(XmlTags.NAME);
String groupTitle = groupElement.getAttributeValue(XmlTags.TITLE);
FormInfo.Group group = new FormInfo.Group(id, name, groupTitle);
groupElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> group.addAttribute(processAttribute(field, attributeElement)));
formInfo.addGroup(group);
if (id != null) {
groupsById.put(id, group);
}
Element excludeElement = groupElement.getChild(XmlTags.EXCLUDE);
if (id != null && excludeElement != null) {
excludes.put(id, excludeElement);
}
}
// round two: process group excludes (which might reference other groups)
excludes.forEach((id, excludeElement) -> {
FormInfo.Group group = groupsById.get(id);
if (group != null) {
excludeElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> {
String name = attributeElement.getAttributeValue(XmlTags.NAME);
if (name != null) {
group.exclude(name);
}
});
excludeElement.getChildren(XmlTags.GROUP).forEach(groupElement -> {
String excludedGroupId = groupElement.getAttributeValue(XmlTags.ID);
if (excludedGroupId != null && groupsById.get(excludedGroupId) != null) {
FormInfo.Group excludedGroup = groupsById.get(excludedGroupId);
group.exclude(excludedGroup);
}
});
}
});
}
}
}
use of org.jboss.hal.meta.AddressTemplate in project console by hal.
the class DataTableProcessor method process.
@Override
public void process(VariableElement field, Element element, String selector, MbuiViewContext context) {
MetadataInfo metadata = findMetadata(field, element, context);
AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
String title = element.getAttributeValue(XmlTags.TITLE);
if (title == null) {
title = new LabelBuilder().label(template.lastName());
}
DataTableInfo tableInfo = new DataTableInfo(field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title);
context.addDataTableInfo(tableInfo);
// actions
org.jdom2.Element actionsContainer = element.getChild(XmlTags.ACTIONS);
if (actionsContainer != null) {
for (org.jdom2.Element actionElement : actionsContainer.getChildren(XmlTags.ACTION)) {
String handler = actionElement.getAttributeValue(XmlTags.HANDLER);
String handlerRef = actionElement.getAttributeValue(XmlTags.HANDLER_REF);
String actionTitle = actionElement.getAttributeValue(XmlTags.TITLE);
String scope = actionElement.getAttributeValue(XmlTags.SCOPE);
String constraint = actionElement.getAttributeValue(XmlTags.CONSTRAINT);
String nameResolver = actionElement.getAttributeValue(XmlTags.NAME_RESOLVER);
Element attributesContainer = actionElement.getChild(XmlTags.ATTRIBUTES);
if (handler != null && handlerRef != null) {
processor.error(field, "Multiple handlers specified for table#%s. Please specify only one of \"handler\" or \"handler-ref\".", selector);
}
if (handler != null) {
if (!ExpressionParser.isExpression(handler)) {
processor.error(field, "Invalid handler \"%s\" in data-table#%s: handler has to be an expression.", handler, selector);
}
if (actionTitle == null) {
processor.error(field, "Invalid handler \"%s\" in data-table#%s: Title is mandatory.", handler, selector);
}
}
if (handlerRef != null && HandlerRef.referenceFor(handlerRef) == null) {
String knownHandlerRefs = Stream.of(HandlerRef.values()).map(HandlerRef::getRef).collect(joining(", "));
processor.error(field, "Unknown handler-ref \"%s\" in data-table#%s: Please choose one of %s.", handlerRef, selector, knownHandlerRefs);
}
if (!HandlerRef.ADD_RESOURCE.getRef().equals(handlerRef) && attributesContainer != null) {
processor.warning(field, "Attributes specified for handler-ref \"%s\" in data-table#%s: " + "Attributes are only processed for \"%s\".", handlerRef, selector, HandlerRef.ADD_RESOURCE.name());
}
if (nameResolver != null && !ExpressionParser.isExpression(nameResolver)) {
processor.error(field, "Name resolver in data-table#%s has to be an expression.", selector);
}
if (HandlerRef.REMOVE_RESOURCE.getRef().equals(handlerRef) && "*".equals(template.lastValue()) && nameResolver == null) {
processor.error(field, "\"%s\" handler-ref specified for data-table#%s and related metadata address ends in \"*\", " + "but no name resolver is is provided.", HandlerRef.REMOVE_RESOURCE.getRef(), selector);
}
if (scope != null && !XmlTags.SELECTED.equals(scope)) {
processor.error(field, "Unknown scope \"%s\" in handler-ref \"%s\" in data-table#%s: Only \"selected\" is supported.", scope, handlerRef, selector);
}
if (constraint != null) {
if (ADD.equals(constraint)) {
constraint = Constraint.executable(AddressTemplate.of(metadata.getTemplate()), ADD).data();
} else if (REMOVE.equals(constraint)) {
constraint = Constraint.executable(AddressTemplate.of(metadata.getTemplate()), REMOVE).data();
}
}
DataTableInfo.Action action = new DataTableInfo.Action(handlerRef != null ? handlerRef : handler, actionTitle, scope, constraint, nameResolver);
tableInfo.addAction(action);
if (attributesContainer != null) {
processAttributes(field, attributesContainer).forEach(action::addAttribute);
}
}
}
// columns
org.jdom2.Element columnsContainer = element.getChild(XmlTags.COLUMNS);
if (columnsContainer != null) {
for (org.jdom2.Element columnElement : columnsContainer.getChildren(XmlTags.COLUMN)) {
String name = columnElement.getAttributeValue(XmlTags.NAME);
String value = columnElement.getAttributeValue(XmlTags.VALUE);
if (name == null) {
processor.error(field, "Invalid column \"%s\" in data-table#%s: name is mandatory.", xmlAsString(columnElement), selector);
}
if (value != null) {
if (!ExpressionParser.isExpression(value)) {
processor.error(field, "Invalid column \"%s\" in data-table#%s: value has to be an expression.", xmlAsString(columnElement), selector);
}
}
DataTableInfo.Column column = new DataTableInfo.Column(name, value);
tableInfo.addColumn(column);
}
}
}
use of org.jboss.hal.meta.AddressTemplate in project console by hal.
the class CreateRrdOperationsTest method mixed.
@Test
public void mixed() {
AddressTemplate nothingPresent = AddressTemplate.of("nothing=present");
AddressTemplate descriptionPresent = AddressTemplate.of("description=present");
AddressTemplate securityContextPresent = AddressTemplate.of("securityContext=present");
AddressTemplate allPresent = AddressTemplate.of("all=present");
LookupResult lookupResult = new LookupResult(Sets.newHashSet(nothingPresent, descriptionPresent, securityContextPresent, allPresent));
lookupResult.markMetadataPresent(descriptionPresent, RESOURCE_DESCRIPTION_PRESENT);
lookupResult.markMetadataPresent(securityContextPresent, SECURITY_CONTEXT_PRESENT);
lookupResult.markMetadataPresent(allPresent, RESOURCE_DESCRIPTION_PRESENT);
lookupResult.markMetadataPresent(allPresent, SECURITY_CONTEXT_PRESENT);
List<Operation> inputs = rrdOps.create(new LookupContext(lookupResult), false, false);
assertEquals(3, inputs.size());
Operation operation = findOperation(inputs, nothingPresent);
assertEquals(COMBINED_DESCRIPTIONS, operation.get(ACCESS_CONTROL).asString());
assertTrue(operation.get(OPERATIONS).asBoolean());
operation = findOperation(inputs, descriptionPresent);
assertEquals("trim-descriptions", operation.get(ACCESS_CONTROL).asString());
assertTrue(operation.get(OPERATIONS).asBoolean());
operation = findOperation(inputs, securityContextPresent);
assertFalse(operation.get(ACCESS_CONTROL).isDefined());
assertTrue(operation.get(OPERATIONS).asBoolean());
}
use of org.jboss.hal.meta.AddressTemplate in project console by hal.
the class ResourceDescriptionTemplateProcessorTest method simple.
@Test
public void simple() throws Exception {
AddressTemplate input = AddressTemplate.of("/foo=bar");
AddressTemplate expected = AddressTemplate.of("/foo=bar");
AddressTemplate result = processor.apply(input);
assertEquals(expected, result);
}
Aggregations