Search in sources :

Example 1 with JsIgnore

use of jsinterop.annotations.JsIgnore in project console by hal.

the class ModelNodeHelper method asEnumValue.

@JsIgnore
public static <E extends Enum<E>> E asEnumValue(ModelNode modelNode, Function<String, E> valueOf, E defaultValue) {
    E value = defaultValue;
    String converted = LOWER_HYPHEN.to(UPPER_UNDERSCORE, modelNode.asString());
    try {
        value = valueOf.apply(converted);
    } catch (IllegalArgumentException ignored) {
    }
    return value;
}
Also used : UPPER_UNDERSCORE(com.google.common.base.CaseFormat.UPPER_UNDERSCORE) JsIgnore(jsinterop.annotations.JsIgnore)

Example 2 with JsIgnore

use of jsinterop.annotations.JsIgnore in project console by hal.

the class Metadata method forOperation.

@JsIgnore
public Metadata forOperation(String name) {
    ModelNode payload = new ModelNode();
    payload.get(DESCRIPTION).set(failSafeGet(description, OPERATIONS + "/" + name + "/" + DESCRIPTION));
    payload.get(ATTRIBUTES).set(failSafeGet(description, OPERATIONS + "/" + name + "/" + REQUEST_PROPERTIES));
    SecurityContext parentContext = this.securityContext.get();
    SecurityContext operationContext = new SecurityContext(new ModelNode()) {

        @Override
        public boolean isReadable() {
            return parentContext.isExecutable(name);
        }

        @Override
        public boolean isWritable() {
            return parentContext.isExecutable(name);
        }

        @Override
        public boolean isReadable(String attribute) {
            // if the operation is executable all of its request properties are readable as well
            return isReadable();
        }

        @Override
        public boolean isWritable(String attribute) {
            // if the operation is executable all of its request properties are writable as well
            return isWritable();
        }

        @Override
        public boolean isExecutable(String operation) {
            return parentContext.isExecutable(operation);
        }
    };
    return new Metadata(template, () -> operationContext, new ResourceDescription(payload), capabilities);
}
Also used : ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) StaticResourceDescription(org.jboss.hal.meta.description.StaticResourceDescription) SecurityContext(org.jboss.hal.meta.security.SecurityContext) ModelNode(org.jboss.hal.dmr.ModelNode) JsIgnore(jsinterop.annotations.JsIgnore)

Example 3 with JsIgnore

use of jsinterop.annotations.JsIgnore in project console by hal.

the class Metadata method forComplexAttribute.

/**
 * Creates a new metadata instance based on this metadata with the attributes taken from the specified complex attribute.
 * The resource description will only include the attributes but no operations!
 *
 * @param prefixLabel if {@code true} the labels of the attributes of the complex attribute are prefixed with name of the
 *        complex attribute.
 */
@JsIgnore
public Metadata forComplexAttribute(String name, boolean prefixLabel) {
    ModelNode payload = new ModelNode();
    payload.get(DESCRIPTION).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + DESCRIPTION));
    payload.get(REQUIRED).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + REQUIRED));
    payload.get(NILLABLE).set(failSafeGet(description, ATTRIBUTES + "/" + name + "/" + NILLABLE));
    Property complexAttribute = description.findAttribute(ATTRIBUTES, name);
    if (complexAttribute != null && complexAttribute.getValue().hasDefined(VALUE_TYPE)) {
        complexAttribute.getValue().get(VALUE_TYPE).asPropertyList().forEach(nestedProperty -> {
            // The nested name is *always* just the nested property name,
            // since it's used when building the DMR operations
            String nestedName = nestedProperty.getName();
            ModelNode nestedDescription = nestedProperty.getValue();
            // up by LabelBuilder.label(Property)
            if (prefixLabel) {
                nestedDescription.get(HAL_LABEL).set(name + "-" + nestedProperty.getName());
            }
            payload.get(ATTRIBUTES).get(nestedName).set(nestedDescription);
        });
    }
    SecurityContext parentContext = this.securityContext.get();
    SecurityContext attributeContext = new SecurityContext(new ModelNode()) {

        @Override
        public boolean isReadable() {
            return parentContext.isReadable(name);
        }

        @Override
        public boolean isWritable() {
            return parentContext.isWritable(name);
        }

        @Override
        public boolean isReadable(String attribute) {
            // if the complex attribute is readable all nested attributes are readable as well
            return isReadable();
        }

        @Override
        public boolean isWritable(String attribute) {
            // if the complex attribute is writable all nested attributes are writable as well
            return isWritable();
        }

        @Override
        public boolean isExecutable(String operation) {
            return parentContext.isExecutable(operation);
        }
    };
    return new Metadata(template, () -> attributeContext, new ResourceDescription(payload), capabilities);
}
Also used : ResourceDescription(org.jboss.hal.meta.description.ResourceDescription) StaticResourceDescription(org.jboss.hal.meta.description.StaticResourceDescription) SecurityContext(org.jboss.hal.meta.security.SecurityContext) ModelNode(org.jboss.hal.dmr.ModelNode) JsProperty(jsinterop.annotations.JsProperty) Property(org.jboss.hal.dmr.Property) JsIgnore(jsinterop.annotations.JsIgnore)

Example 4 with JsIgnore

use of jsinterop.annotations.JsIgnore in project console by hal.

the class ComplexAttributeOperations method add.

// ------------------------------------------------------ (c)reate operation
/**
 * Writes the payload to the complex attribute in the specified resource. After the resource has been updated, a success
 * message is fired and the specified callback is executed.
 *
 * @param resource the resource name
 * @param complexAttribute the name of the complex attribute
 * @param type the human readable name of the complex attribute
 * @param template the address template which is resolved against the current statement context and the resource name to get
 *        the resource address for the operation
 * @param payload the optional payload for the complex attribute (may be null or undefined)
 * @param callback the callback executed after the resource has been added
 */
@JsIgnore
public void add(String resource, String complexAttribute, String type, AddressTemplate template, @Nullable ModelNode payload, Callback callback) {
    ResourceAddress address = template.resolve(statementContext, resource);
    add(complexAttribute, type, address, payload, callback);
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) JsIgnore(jsinterop.annotations.JsIgnore)

Example 5 with JsIgnore

use of jsinterop.annotations.JsIgnore in project console by hal.

the class ComplexAttributeOperations method save.

/**
 * Writes the changed values to the list-type complex attribute. After the complex attribute has been saved a standard
 * success message is fired and the specified callback is executed.
 * <p>
 * If the change set is empty, a warning message is fired and the specified callback is executed.
 *
 * @param complexAttribute the name of the complex attribute
 * @param type the human readable name of the complex attribute
 * @param index the index for the list-type complex attribute
 * @param address the fq address for the operation
 * @param changedValues the changed values / payload for the operation
 * @param metadata the metadata for the complex attribute
 * @param callback the callback executed after the resource has been saved
 */
@JsIgnore
public void save(String complexAttribute, String type, int index, ResourceAddress address, Map<String, Object> changedValues, Metadata metadata, Callback callback) {
    Composite operations = operationFactory(complexAttribute, index).fromChangeSet(address, changedValues, metadata);
    crud.save(operations, resources.messages().modifySingleResourceSuccess(type), callback);
}
Also used : Composite(org.jboss.hal.dmr.Composite) JsIgnore(jsinterop.annotations.JsIgnore)

Aggregations

JsIgnore (jsinterop.annotations.JsIgnore)41 ModelNode (org.jboss.hal.dmr.ModelNode)11 Composite (org.jboss.hal.dmr.Composite)10 Operation (org.jboss.hal.dmr.Operation)10 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)9 Map (java.util.Map)7 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)6 CustomEventInit (elemental2.dom.CustomEventInit)6 Set (java.util.Set)6 JsProperty (jsinterop.annotations.JsProperty)6 JsType (jsinterop.annotations.JsType)5 AddResourceDialog (org.jboss.hal.core.mbui.dialog.AddResourceDialog)5 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)5 CompositeResult (org.jboss.hal.dmr.CompositeResult)5 Property (org.jboss.hal.dmr.Property)5 Iterables (com.google.common.collect.Iterables)4 EventBus (com.google.web.bindery.event.shared.EventBus)4 Collectors.toSet (java.util.stream.Collectors.toSet)4 StreamSupport.stream (java.util.stream.StreamSupport.stream)4 Nullable (javax.annotation.Nullable)4