Search in sources :

Example 26 with IProxyRepositoryFactory

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

the class NewRoutineWizard method performFinish.

/**
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        updateRoutineContent();
        property.setId(repositoryFactory.getNextId());
        //changed by hqzhang for TDI-19527, label=displayName
        property.setLabel(property.getDisplayName());
        repositoryFactory.create(routineItem, mainPage.getDestinationPath());
    } catch (PersistenceException e) {
        //$NON-NLS-1$ //$NON-NLS-2$
        MessageDialog.openError(getShell(), Messages.getString("NewProcessWizard.failureTitle"), "");
        ExceptionHandler.process(e);
    }
    return routineItem != null;
}
Also used : PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 27 with IProxyRepositoryFactory

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

the class ServiceMetadataDialog method okPressed.

/* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
@Override
protected void okPressed() {
    EMap<String, String> props = serviceConnection.getAdditionalInfo();
    if (props != null) {
        props.put(USE_SAM, Boolean.toString(isUseSam()));
        props.put(USE_SL, Boolean.toString(isUseSL()));
        props.put(SECURITY_BASIC, Boolean.toString(getSecurityBasic()));
        props.put(SECURITY_SAML, Boolean.toString(getSecuritySAML()));
        props.put(AUTHORIZATION, Boolean.toString(getAuthorization()));
        props.put(ENCRYPTION, Boolean.toString(getEncryption()));
        props.put(USE_SERVICE_REGISTRY, Boolean.toString(getUseServiceRegistry()));
        props.put(LOG_MESSAGES, Boolean.toString(isLogMessages()));
        props.put(WSDL_SCHEMA_VALIDATION, Boolean.toString(isWsdlSchemaValidation()));
        props.put(USE_BUSINESS_CORRELATION, Boolean.toString(useBusinessCorrelation));
        if (isUseSL()) {
            slCustomProperties = new HashMap<String, String>(customPropertiesTable.getPropertiesMap());
            // remove old custom properties
            List<String> props2delete = new ArrayList<String>();
            for (String propKey : props.keySet()) {
                if (propKey.startsWith(SL_CUSTOM_PROP_PREFIX)) {
                    props2delete.add(propKey);
                }
            }
            for (String propKey : props2delete) {
                props.removeKey(propKey);
            }
            // set new custom properties
            for (Map.Entry<String, String> prop : slCustomProperties.entrySet()) {
                props.put(SL_CUSTOM_PROP_PREFIX + prop.getKey(), prop.getValue());
            }
        }
    }
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        factory.save(serviceItem);
    } catch (PersistenceException e) {
        e.printStackTrace();
    }
    super.okPressed();
}
Also used : ArrayList(java.util.ArrayList) PersistenceException(org.talend.commons.exception.PersistenceException) HashMap(java.util.HashMap) Map(java.util.Map) EMap(org.eclipse.emf.common.util.EMap) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 28 with IProxyRepositoryFactory

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

the class OpenWSDLPage method finish.

public boolean finish() {
    // changed by hqzhang for TDI-19527, label=displayName
    final String label = item.getProperty().getDisplayName();
    item.getProperty().setLabel(label);
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(final IProgressMonitor monitor) throws CoreException {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
                if (creation) {
                    item.getProperty().setId(factory.getNextId());
                    factory.create(item, getDestinationPath());
                    repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
                }
                ((ServiceConnection) item.getConnection()).setWSDLPath(path);
                ((ServiceConnection) item.getConnection()).getServicePort().clear();
                final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
                final InputStream is;
                if (null == path) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // create new WSDL file from template
                    TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
                    is = new ByteArrayInputStream(baos.toByteArray());
                } else {
                    //$NON-NLS-1$
                    String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
                    Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
                    is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
                    for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
                        String filename = wsdl.getKey();
                        IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
                        if (!importedWsdl.exists()) {
                            importedWsdl.create(wsdl.getValue(), true, monitor);
                        } else {
                            importedWsdl.setContents(wsdl.getValue(), 0, monitor);
                        }
                        createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
                    }
                }
                // store WSDL in service
                if (!fileWsdl.exists()) {
                    fileWsdl.create(is, true, monitor);
                } else {
                    fileWsdl.setContents(is, 0, monitor);
                }
                // create reference to wsdl
                //$NON-NLS-1$
                createReferenceResources("wsdl");
                // path
                definition = WSDLUtils.getDefinition(fileWsdl);
                populateModelFromWsdl(factory, definition, item, repositoryNode);
                factory.save(item);
                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
            } catch (Exception e) {
                //delete the node if any exception during the creation
                if (creation) {
                    try {
                        factory.save(item);
                        factory.deleteObjectPhysical(repositoryNode.getObject());
                    } catch (PersistenceException e1) {
                        throw getCoreException("WDSL creation failed", e1);
                    }
                }
                //throw the exception
                if (e instanceof CoreException) {
                    throw (CoreException) e;
                }
                if (e instanceof InvocationTargetException) {
                    throw getCoreException("WDSL creation failed", e.getCause());
                }
                throw getCoreException("WDSL creation failed", e);
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        // we use the workspace scheduling rule to lock all
        ISchedulingRule schedulingRule = workspace.getRoot();
        // workspace modifications during the run.
        // the update of the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    // open wsdl editor
    OpenWSDLEditorAction action = new OpenWSDLEditorAction();
    action.setServiceItem(item);
    action.run();
    // import schemas if required
    if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
        PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
        try {
            getContainer().run(true, true, publishMetadataRunnable);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
            setErrorMessage("Populate schema to repository: " + message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    return true;
}
Also used : ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) OpenWSDLEditorAction(org.talend.repository.services.action.OpenWSDLEditorAction) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) PublishMetadataRunnable(org.talend.repository.services.action.PublishMetadataRunnable) Map(java.util.Map)

Example 29 with IProxyRepositoryFactory

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

the class OpenJobAction method removeReferenecJobId.

protected static void removeReferenecJobId(IRepositoryNode node) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        String parentPortName = node.getParent().getObject().getLabel();
        ServiceItem serviceItem = (ServiceItem) node.getParent().getParent().getObject().getProperty().getItem();
        List<ServicePort> listPort = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
        for (ServicePort port : listPort) {
            if (port.getName().equals(parentPortName)) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (operation.getLabel().equals(node.getObject().getLabel())) {
                        operation.setReferenceJobId(null);
                        operation.setLabel(operation.getName());
                        factory.save(node.getObject().getProperty().getItem());
                    }
                }
                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) 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 30 with IProxyRepositoryFactory

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

the class EditQueriesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (factory.isUserReadOnlyOnCurrentProject()) {
        canWork = false;
    }
    if (canWork) {
        Object o = selection.getFirstElement();
        repositoryNode = (RepositoryNode) o;
        switch(repositoryNode.getType()) {
            case REPOSITORY_ELEMENT:
                if (repositoryNode.getObject().getRepositoryStatus() == ERepositoryStatus.DELETED || repositoryNode.getObject().getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
                    canWork = false;
                }
                // Studio does not support this action for impala, TBD-3827.
                if (!isUnderDBConnection(repositoryNode)) {
                    canWork = false;
                }
                if (repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CONNECTIONS && repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CON_QUERY && repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CON_TABLE) {
                    canWork = false;
                } else {
                    // for cdc
                    if (PluginChecker.isCDCPluginLoaded()) {
                        ICDCProviderService cdcService = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
                        if (cdcService != null && cdcService.isSubscriberTableNode(repositoryNode)) {
                            canWork = false;
                            break;
                        }
                    }
                    IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
                    if (!repFactory.isPotentiallyEditable(repositoryNode.getObject())) {
                        canWork = false;
                        break;
                    }
                }
                if (canWork) {
                    Item item = repositoryNode.getObject().getProperty().getItem();
                    if (item instanceof DatabaseConnectionItem) {
                        DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                        DatabaseConnection dbConn = (DatabaseConnection) dbItem.getConnection();
                        String dbType = dbConn.getDatabaseType();
                        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.HBASE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.MAPRDB.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.IMPALA.getXmlName().equalsIgnoreCase(dbType)) {
                            canWork = false;
                            break;
                        }
                    }
                }
                break;
            default:
                canWork = false;
        }
        if (canWork && (!ProjectManager.getInstance().isInCurrentMainProject(repositoryNode) || !isLastVersion(repositoryNode))) {
            canWork = false;
        }
    }
    setEnabled(canWork);
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ICDCProviderService(org.talend.core.ui.ICDCProviderService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

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