All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.openesb.rest.utils.Mapper Maven / Gradle / Ivy

package net.openesb.rest.utils;

import com.sun.jbi.management.descriptor.Consumes;
import com.sun.jbi.management.descriptor.Jbi;
import com.sun.jbi.management.descriptor.Provides;
import com.sun.jbi.management.descriptor.Services;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.openesb.rest.api.model.ui.Assembly;
import net.openesb.rest.api.model.ui.Endpoint;

public final class Mapper {

    private Mapper() {
        
    }

    public static Assembly getCasa(String name, Jbi jbi) {

        Assembly casa = new Assembly();
        casa.setName(name);
        casa.setProcesses(new ArrayList());

        Map> mapConsumes = new HashMap>();
        Map> mapProvides = new HashMap>();

        Services services = jbi.getServices();

        //Extract process consumes
        List consumes = services.getConsumes();
        for (Consumes consume : consumes) {
            net.openesb.rest.api.model.ui.Consumes wrapper = new net.openesb.rest.api.model.ui.Consumes(consume);
            List processConsumes = mapConsumes.get(wrapper.getProcessName());
            if (processConsumes == null) {
                processConsumes = new ArrayList();
            }
            processConsumes.add(consume);
            mapConsumes.put(wrapper.getProcessName(), processConsumes);
        }

        //Extract process provide
        List provides = services.getProvides();
        for (Provides provide : provides) {
            net.openesb.rest.api.model.ui.Provides wrapper = new net.openesb.rest.api.model.ui.Provides(provide);
            List processProvides = mapProvides.get(wrapper.getProcessName());
            if (processProvides == null) {
                processProvides = new ArrayList();
            }
            processProvides.add(provide);
            mapProvides.put(wrapper.getProcessName(), processProvides);
        }


        Set processNames = new HashSet();
        processNames.addAll(mapProvides.keySet());
        processNames.addAll(mapConsumes.keySet());

        for (String processName : processNames) {
            net.openesb.rest.api.model.ui.Process process = new net.openesb.rest.api.model.ui.Process();
            casa.getProcesses().add(process);
            process.setName(processName);

            List processConsumes = mapConsumes.get(processName);
            process.setOutputs(new ArrayList());

            if (processConsumes != null) {
                for (Consumes processConsume : processConsumes) {
                   net.openesb.rest.api.model.ui.Consumes wrapper = 
                            new net.openesb.rest.api.model.ui.Consumes(processConsume);
                    
                    Endpoint endpoint = new Endpoint();
                    endpoint.setName(wrapper.getDisplayName());
                    process.getOutputs().add(endpoint);

                    //Connector identifier elements
                    endpoint.setConnectionPoint(ConnectionPointBuilder.getConnectionPoint(processConsume));

                }
            }

            List processProvides = mapProvides.get(processName);
            process.setInputs(new ArrayList());

            if (processProvides != null) {
                for (Provides processProvide : processProvides) {
                    net.openesb.rest.api.model.ui.Provides wrapper = 
                            new net.openesb.rest.api.model.ui.Provides(processProvide);
                    
                    Endpoint endpoint = new Endpoint();
                    endpoint.setName(wrapper.getDisplayName());
                    process.getInputs().add(endpoint);

                    //Connector identifier elements
                    endpoint.setConnectionPoint(ConnectionPointBuilder.getConnectionPoint(processProvide));
                }
            }
        }

        return casa;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy