<commit_before>/*
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * 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.
 */
package org.jboss.as.console.client.shared.subsys.elytron.ui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.shared.subsys.elytron.store.ElytronStore;
import org.jboss.as.console.client.v3.dmr.AddressTemplate;
import org.jboss.as.console.client.v3.dmr.ResourceDescription;
import org.jboss.ballroom.client.rbac.SecurityContext;
import org.jboss.dmr.client.Property;
import org.jboss.gwt.circuit.Dispatcher;

/**
 * @author <NAME> <<EMAIL>>
 */
public class PolicyView extends ElytronGenericResourceView {

    private GenericListComplexAttribute customPolicy;
    private GenericListComplexAttribute jaccPolicy;

    public PolicyView(final Dispatcher circuit,
            final ResourceDescription resourceDescription,
            final SecurityContext securityContext, final String title,
            final AddressTemplate addressTemplate) {
        super(circuit, resourceDescription, securityContext, title, addressTemplate);
        excludesFormAttributes("custom-policy", "jacc-policy");

    }

    @Override
    public Map<String, Widget> additionalTabDetails() {
        Map<String, Widget> additionalWidgets = new HashMap<>();
        customPolicy = new GenericListComplexAttribute(circuit, resourceDescription, securityContext, ElytronStore.POLICY_ADDRESS, "custom-policy");
        jaccPolicy = new GenericListComplexAttribute(circuit, resourceDescription, securityContext, ElytronStore.POLICY_ADDRESS, "jacc-policy");
        additionalWidgets.put("Custom Policy", customPolicy.asWidget());
        additionalWidgets.put("JACC Policy", jaccPolicy.asWidget());
        return additionalWidgets;
    }

    @Override
    public void update(final List<Property> models) {
        super.update(models);
        if (models.isEmpty()) {
            customPolicy.clearValues();
            jaccPolicy.clearValues();
        }
    }

    @Override
    protected void selectTableItem(final Property prop) {
        if (prop != null) {
            customPolicy.update(prop);
            jaccPolicy.update(prop);
        } else {
            customPolicy.clearValues();
            jaccPolicy.clearValues();
        }
    }

}<commit_msg>HAL-1365 - Not possible to add Elytron policy resource using web console https://issues.jboss.org/browse/HAL-1365<commit_after>/*
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * 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.
 */
package org.jboss.as.console.client.shared.subsys.elytron.ui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.shared.subsys.elytron.store.ElytronStore;
import org.jboss.as.console.client.v3.dmr.AddressTemplate;
import org.jboss.as.console.client.v3.dmr.ResourceDescription;
import org.jboss.ballroom.client.rbac.SecurityContext;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;
import org.jboss.gwt.circuit.Dispatcher;

import static org.jboss.dmr.client.ModelDescriptionConstants.NAME;

/**
 * @author <NAME> <<EMAIL>>
 */
public class PolicyView extends ElytronGenericResourceView {

    private static final String CUSTOM_POLICY = "custom-policy";
    private static final String JACC_POLICY = "jacc-policy";
    private static final String DEFAULT_POLICY = "default-policy";
    private GenericListComplexAttribute customPolicy;
    private GenericListComplexAttribute jaccPolicy;

    public PolicyView(final Dispatcher circuit,
            final ResourceDescription resourceDescription,
            final SecurityContext securityContext, final String title,
            final AddressTemplate addressTemplate) {
        super(circuit, resourceDescription, securityContext, title, addressTemplate);
        excludesFormAttributes(CUSTOM_POLICY, JACC_POLICY);

    }

    @Override
    public Map<String, Widget> additionalTabDetails() {
        Map<String, Widget> additionalWidgets = new HashMap<>();
        customPolicy = new GenericListComplexAttribute(circuit, resourceDescription, securityContext,
                ElytronStore.POLICY_ADDRESS, CUSTOM_POLICY);
        jaccPolicy = new GenericListComplexAttribute(circuit, resourceDescription, securityContext,
                ElytronStore.POLICY_ADDRESS, JACC_POLICY);
        additionalWidgets.put("Custom Policy", customPolicy.asWidget());
        additionalWidgets.put("JACC Policy", jaccPolicy.asWidget());
        return additionalWidgets;
    }

    protected void onAddCallbackBeforeSubmit(final ModelNode payload) {
        ModelNode policyName = payload.get(NAME);
        // set the defaul-policy if user didn't set in UI
        if (!payload.hasDefined(DEFAULT_POLICY)) {
            payload.get(DEFAULT_POLICY).set(policyName);
        }
        // add a policy to the list of jacc-policy.
        // r-r-d doesn't requires a jacc-policy, but a policy resource cannot be added with no jacc-policy/custom-policy
        ModelNode jaccPolicy = new ModelNode();
        jaccPolicy.get(NAME).set(policyName);
        payload.get(JACC_POLICY).add(jaccPolicy);
    }

    @Override
    public void update(final List<Property> models) {
        super.update(models);
        if (models.isEmpty()) {
            customPolicy.clearValues();
            jaccPolicy.clearValues();
        }
    }

    @Override
    protected void selectTableItem(final Property prop) {
        if (prop != null) {
            customPolicy.update(prop);
            jaccPolicy.update(prop);
        } else {
            customPolicy.clearValues();
            jaccPolicy.clearValues();
        }
    }

}
{'fraction_non_alphanumeric': 0.09264145411902668, 'fraction_numerical': 0.005277044854881266, 'mean_word_length': 3.45075016307893, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6893407', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1824, 'n_words': 490}