Search in sources :

Example 41 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tesb-studio-se by Talend.

the class AssignJobAction method assign.

public boolean assign(IRepositoryNode jobNode) {
    if (jobNode == null) {
        return false;
    }
    IRepositoryViewObject repositoryObject = jobNode.getObject();
    final Item item = repositoryObject.getProperty().getItem();
    // judge the job whether had T_ESB_PROVIDER_REQUEST
    ProcessItem processItem = (ProcessItem) item;
    NodeType providerNode = null;
    for (Object obj : processItem.getProcess().getNode()) {
        NodeType node = (NodeType) obj;
        if (CreateNewJobAction.T_ESB_PROVIDER_REQUEST.equals(node.getComponentName())) {
            providerNode = node;
            break;
        }
    }
    if (null == providerNode) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.AssignJobAction_WarningTitle, Messages.AssignJobAction_WarningMessage);
        return false;
    }
    try {
        String jobID = item.getProperty().getId();
        String jobName = item.getProperty().getLabel();
        String operationName = repositoryNode.getObject().getLabel();
        String portName = repositoryNode.getParent().getObject().getLabel();
        ServiceItem serviceItem = (ServiceItem) repositoryNode.getParent().getParent().getObject().getProperty().getItem();
        List<ServicePort> listPort = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
        for (ServicePort port : listPort) {
            if (port.getName().equals(portName)) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (operation.getLabel().equals(operationName)) {
                        // should not change the job name
                        // String jobNewName = port.getName() + "_" + operation.getName();
                        // if (resetJobname(item, jobNewName)) {
                        // jobName = jobNewName;
                        // }
                        operation.setReferenceJobId(jobID);
                        operation.setLabel(operation.getName() + "-" + jobName);
                        break;
                    }
                }
                break;
            }
        }
        IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
        Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) repositoryNode.getObject()).getName(), portName);
        for (Object paramObj : providerNode.getElementParameter()) {
            ElementParameterType param = (ElementParameterType) paramObj;
            String name = param.getName();
            if (serviceParameters.containsKey(name)) {
                param.setValue(serviceParameters.get(name));
            }
        }
        IProcess2 process = null;
        IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
        List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
        for (IProcess2 processOpen : processes) {
            if (processOpen.getProperty().getItem() == processItem) {
                process = processOpen;
                break;
            }
        }
        if (process == null) {
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            IProcess proc = service.getProcessFromProcessItem(processItem);
            if (proc instanceof IProcess2) {
                process = (IProcess2) proc;
            }
        }
        if (process != null) {
            List<? extends INode> nodelist = process.getGraphicalNodes();
            for (INode node : nodelist) {
                if (node.getComponent().getName().equals("tESBProviderRequest")) {
                    repositoryChange(repositoryNode, node);
                }
            }
            processItem.setProcess(process.saveXmlFile());
        }
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        factory.save(processItem);
        factory.save(serviceItem);
        return true;
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return false;
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) INode(org.talend.core.model.process.INode) IFile(org.eclipse.core.resources.IFile) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IEditorReference(org.eclipse.ui.IEditorReference) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PortRepositoryObject(org.talend.repository.services.utils.PortRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) OperationRepositoryObject(org.talend.repository.services.utils.OperationRepositoryObject) ServiceItem(org.talend.repository.services.model.services.ServiceItem)

Example 42 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tesb-studio-se by Talend.

the class AssignJobAction method init.

@Override
protected void init(RepositoryNode node) {
    ERepositoryObjectType nodeType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
    if (!currentNodeType.equals(nodeType)) {
        return;
    }
    IProxyRepositoryFactory proxyFactory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    try {
        proxyFactory.updateLockStatus();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    IRepositoryViewObject repositoryViewObject = node.getObject();
    ERepositoryStatus status = proxyFactory.getStatus(repositoryViewObject);
    if (!status.isEditable() && !status.isPotentiallyEditable()) {
        setEnabled(false);
    } else {
        //not enabled if the operation doesn't define in binding
        if (!WSDLUtils.isOperationInBinding(node)) {
            setEnabled(false);
            return;
        }
        setEnabled(true);
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 43 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tesb-studio-se by Talend.

the class ESBService method refreshOperationLabel.

@Override
public void refreshOperationLabel(String jobID) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        List<IRepositoryViewObject> repList = factory.getAll(getServicesType());
        for (IRepositoryViewObject obj : repList) {
            ServiceItem item = (ServiceItem) obj.getProperty().getItem();
            ServiceConnection conn = (ServiceConnection) item.getConnection();
            for (ServicePort port : conn.getServicePort()) {
                for (ServiceOperation operation : port.getServiceOperation()) {
                    if (operation.getReferenceJobId() != null && operation.getReferenceJobId().endsWith(jobID)) {
                        operation.setLabel(operation.getName());
                        operation.setReferenceJobId(null);
                        factory.save(item);
                        return;
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 44 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tesb-studio-se by Talend.

the class ESBService method editJobName.

@Override
public void editJobName(String originaleObjectLabel, String newLabel) {
    IProxyRepositoryFactory proxyRepositoryFactory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    Project project = ProjectManager.getInstance().getCurrentProject();
    List<IRepositoryViewObject> service = null;
    try {
        service = proxyRepositoryFactory.getAll(project, ESBRepositoryNodeType.SERVICES, true);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (service != null && service.size() > 0) {
        for (IRepositoryViewObject Object : service) {
            boolean flag = false;
            ServiceItem item = (ServiceItem) Object.getProperty().getItem();
            ServiceConnection serviceConnection = (ServiceConnection) item.getConnection();
            List<ServicePort> servicePorts = serviceConnection.getServicePort();
            for (ServicePort port : servicePorts) {
                List<ServiceOperation> serviceOperations = port.getServiceOperation();
                for (ServiceOperation operation : serviceOperations) {
                    String originaleItemLabel = operation.getLabel();
                    if (originaleItemLabel.contains("-")) {
                        String[] array = originaleItemLabel.split("-");
                        if (originaleObjectLabel.equals(array[1])) {
                            operation.setLabel(array[0] + "-" + newLabel);
                            flag = true;
                        }
                    }
                }
            }
            if (flag) {
                try {
                    proxyRepositoryFactory.save(item);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
// RepositoryManager.refresh(ESBRepositoryNodeType.SERVICES);
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) Project(org.talend.core.model.general.Project) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 45 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tesb-studio-se by Talend.

the class ESBService method deleteOldRelation.

@Override
public void deleteOldRelation(String jobID) {
    boolean portBreak = false;
    boolean serviceBreak = false;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        for (IRepositoryViewObject viewObject : factory.getAll(ERepositoryObjectType.SERVICESOPERATION)) {
            ServiceItem serviceItem = (ServiceItem) viewObject.getProperty().getItem();
            ServiceConnection serviceConnection = (ServiceConnection) serviceItem.getConnection();
            List<ServicePort> ports = serviceConnection.getServicePort();
            for (ServicePort port : ports) {
                List<ServiceOperation> operations = port.getServiceOperation();
                for (ServiceOperation operation : operations) {
                    String referenceJobId = operation.getReferenceJobId();
                    if (jobID.equals(referenceJobId)) {
                        operation.setLabel(operation.getName());
                        operation.setReferenceJobId(null);
                        portBreak = true;
                        break;
                    }
                }
                if (portBreak) {
                    serviceBreak = true;
                    break;
                }
            }
            if (serviceBreak) {
                factory.save(serviceItem, null);
                break;
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)194 PersistenceException (org.talend.commons.exception.PersistenceException)118 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)72 Item (org.talend.core.model.properties.Item)49 Property (org.talend.core.model.properties.Property)36 ArrayList (java.util.ArrayList)35 ConnectionItem (org.talend.core.model.properties.ConnectionItem)33 RepositoryNode (org.talend.repository.model.RepositoryNode)31 ProcessItem (org.talend.core.model.properties.ProcessItem)26 CoreException (org.eclipse.core.runtime.CoreException)21 IElementParameter (org.talend.core.model.process.IElementParameter)21 IRepositoryService (org.talend.repository.model.IRepositoryService)21 Connection (org.talend.core.model.metadata.builder.connection.Connection)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)20 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)19 List (java.util.List)18 IFile (org.eclipse.core.resources.IFile)17 Project (org.talend.core.model.general.Project)15 RoutineItem (org.talend.core.model.properties.RoutineItem)15 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)15