<commit_before>package org.jboss.as.console.client.shared.subsys.messaging;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.shared.BeanFactory;
import org.jboss.as.console.client.shared.dispatch.AsyncCommand;
import org.jboss.as.console.client.shared.dispatch.DispatchAsync;
import org.jboss.as.console.client.shared.dispatch.impl.DMRAction;
import org.jboss.as.console.client.shared.dispatch.impl.DMRResponse;
import org.jboss.as.console.client.shared.subsys.messaging.model.ConnectionFactory;
import org.jboss.as.console.client.shared.subsys.messaging.model.JMSEndpoint;
import org.jboss.as.console.client.shared.subsys.messaging.model.Queue;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;

import java.util.ArrayList;
import java.util.List;

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

/**
 * @author <NAME>
 * @date 12/10/11
 */
public class LoadJMSCmd implements AsyncCommand<AggregatedJMSModel> {

    private DispatchAsync dispatcher;
    private BeanFactory factory;

    public LoadJMSCmd(DispatchAsync dispatcher, BeanFactory factory) {
        this.dispatcher = dispatcher;
        this.factory = factory;
    }

    @Override
    public void execute(AsyncCallback<AggregatedJMSModel> topicsAndQueuesAsyncCallback) {
        throw new RuntimeException("Use overridden method instead!");
    }

    public void execute(ModelNode address, final AsyncCallback<AggregatedJMSModel> callback) {
        ModelNode operation = new ModelNode();
        operation.get(OP).set(READ_RESOURCE_OPERATION);
        operation.get(RECURSIVE).set(Boolean.TRUE);
        operation.get(ADDRESS).set(address);

        dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() {
            @Override
            public void onSuccess(DMRResponse result) {
                ModelNode response = result.get();
                ModelNode payload = response.get("result").asObject();

                List<ConnectionFactory> factories = parseFactories(payload);
                List<Queue> queues = parseQueues(payload);
                List<JMSEndpoint> topics = parseTopics(payload);

                AggregatedJMSModel model = new AggregatedJMSModel(factories, queues, topics);
                callback.onSuccess(model);
            }
        });
    }

    private List<ConnectionFactory> parseFactories(ModelNode response) {

        List<ConnectionFactory> factoryModels = new ArrayList<ConnectionFactory>();

        try {

            // factories
            List<Property> factories = response.get("connection-factory").asPropertyList();


            for(Property factoryProp : factories)
            {
                String name = factoryProp.getName();

                ModelNode factoryValue = factoryProp.getValue();
                String jndi = factoryValue.get("entries").asList().get(0).asString();

                ConnectionFactory factoryModel = factory.connectionFactory().as();
                factoryModel.setName(name);
                factoryModel.setJndiName(jndi);

                factoryModels.add(factoryModel);
            }




        } catch (Throwable e) {
            Console.error("Failed to parse response: " + e.getMessage());
        }

        return factoryModels;
    }


    private List<Queue> parseQueues(ModelNode response) {

        List<Property> propList = response.get("jms-queue").asPropertyList();
        List<Queue> queues = new ArrayList<Queue>(propList.size());

        for(Property prop : propList)
        {
            Queue queue = factory.queue().as();
            queue.setName(prop.getName());

            ModelNode propValue = prop.getValue();
            String jndi = propValue.get("entries").asList().get(0).asString();
            queue.setJndiName(jndi);

            if(propValue.hasDefined("durable"))
                queue.setDurable(propValue.get("durable").asBoolean());

            if(propValue.hasDefined("selector"))
                queue.setSelector(propValue.get("selector").asString());

            queues.add(queue);
        }

        return queues;

    }

    private List<JMSEndpoint> parseTopics(ModelNode response) {
        List<Property> propList = response.get("jms-topic").asPropertyList();
        List<JMSEndpoint> topics = new ArrayList<JMSEndpoint>(propList.size());

        for(Property prop : propList)
        {
            JMSEndpoint topic = factory.topic().as();
            topic.setName(prop.getName());

            ModelNode propValue = prop.getValue();
            String jndi = propValue.get("entries").asList().get(0).asString();
            topic.setJndiName(jndi);

            topics.add(topic);
        }
<commit_msg>parsing of mms destinations was broken (choked on empty results)<commit_after>package org.jboss.as.console.client.shared.subsys.messaging;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.shared.BeanFactory;
import org.jboss.as.console.client.shared.dispatch.AsyncCommand;
import org.jboss.as.console.client.shared.dispatch.DispatchAsync;
import org.jboss.as.console.client.shared.dispatch.impl.DMRAction;
import org.jboss.as.console.client.shared.dispatch.impl.DMRResponse;
import org.jboss.as.console.client.shared.subsys.messaging.model.ConnectionFactory;
import org.jboss.as.console.client.shared.subsys.messaging.model.JMSEndpoint;
import org.jboss.as.console.client.shared.subsys.messaging.model.Queue;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;

import java.util.ArrayList;
import java.util.List;

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

/**
 * @author <NAME>
 * @date 12/10/11
 */
public class LoadJMSCmd implements AsyncCommand<AggregatedJMSModel> {

    private DispatchAsync dispatcher;
    private BeanFactory factory;

    public LoadJMSCmd(DispatchAsync dispatcher, BeanFactory factory) {
        this.dispatcher = dispatcher;
        this.factory = factory;
    }

    @Override
    public void execute(AsyncCallback<AggregatedJMSModel> topicsAndQueuesAsyncCallback) {
        throw new RuntimeException("Use overridden method instead!");
    }

    public void execute(ModelNode address, final AsyncCallback<AggregatedJMSModel> callback) {
        ModelNode operation = new ModelNode();
        operation.get(OP).set(READ_RESOURCE_OPERATION);
        operation.get(RECURSIVE).set(Boolean.TRUE);
        operation.get(ADDRESS).set(address);

        dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() {
            @Override
            public void onSuccess(DMRResponse result) {
                ModelNode response = result.get();
                ModelNode payload = response.get("result").asObject();

                List<ConnectionFactory> factories = parseFactories(payload);
                List<Queue> queues = parseQueues(payload);
                List<JMSEndpoint> topics = parseTopics(payload);

                AggregatedJMSModel model = new AggregatedJMSModel(factories, queues, topics);
                callback.onSuccess(model);
            }
        });
    }

    private List<ConnectionFactory> parseFactories(ModelNode response) {

        List<ConnectionFactory> factoryModels = new ArrayList<ConnectionFactory>();

        try {

            // factories
            List<Property> factories = response.get("connection-factory").asPropertyList();


            for(Property factoryProp : factories)
            {
                String name = factoryProp.getName();

                ModelNode factoryValue = factoryProp.getValue();
                String jndi = factoryValue.get("entries").asList().get(0).asString();

                ConnectionFactory factoryModel = factory.connectionFactory().as();
                factoryModel.setName(name);
                factoryModel.setJndiName(jndi);

                factoryModels.add(factoryModel);
            }




        } catch (Throwable e) {
            Console.error("Failed to parse response: " + e.getMessage());
        }

        return factoryModels;
    }


    private List<Queue> parseQueues(ModelNode response) {

        List<Queue> queues = new ArrayList<Queue>();

        if(response.hasDefined("jms-queue")) {
            List<Property> propList = response.get("jms-queue").asPropertyList();

            for(Property prop : propList)
            {
                Queue queue = factory.queue().as();
                queue.setName(prop.getName());

                ModelNode propValue = prop.getValue();
                String jndi = propValue.get("entries").asList().get(0).asString();
                queue.setJndiName(jndi);

                if(propValue.hasDefined("durable"))
                    queue.setDurable(propValue.get("durable").asBoolean());

                if(propValue.hasDefined("selector"))
                    queue.setSelector(propValue.get("selector").asString());

                queues.add(queue);
            }
        }

        return queues;

    }

    private List<JMSEndpoint> parseTopics(ModelNode response) {
        List<JMSEndpoint> topics = new ArrayList<JMSEndpoint>();

        if(response.hasDefined("jms-topic"))
        {
            List<Property> propList = response.get("jms-topic").asPropertyList();

            for(Property prop : propList)
            {
                JMSEndpoint topic = factory.topic().as();
                topic.setName(prop.getName());

                ModelNode propValue = prop.getValue();
                String jndi = propValue.get("entries").asList().get(0).asString();
                topic.setJndiName(jndi);

                topics.add(topic);
            }
        }

{'fraction_non_alphanumeric': 0.11358372772127681, 'fraction_numerical': 0.00181250629342463, 'mean_word_length': 2.6461086637298092, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '423224', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2657, 'n_words': 439}