Search in sources :

Example 56 with ProxyRepositoryFactory

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

the class ChangeDefaultSparkSerializer method changeSparkConfiguration.

private void changeSparkConfiguration(ProcessType processType, Item item) throws PersistenceException {
    boolean modified = false;
    final ParametersType parameters = processType.getParameters();
    if (parameters != null) {
        EList elementParameters = parameters.getElementParameter();
        ElementParameterType property = TalendFileFactory.eINSTANCE.createElementParameterType();
        //$NON-NLS-1$
        property.setName("CUSTOMIZE_SPARK_SERIALIZER");
        //$NON-NLS-1$
        property.setField("CHECK");
        //$NON-NLS-1$
        property.setValue("true");
        elementParameters.add(property);
        property = TalendFileFactory.eINSTANCE.createElementParameterType();
        //$NON-NLS-1$
        property.setName("SPARK_SERIALIZER");
        //$NON-NLS-1$
        property.setField("TEXT");
        //$NON-NLS-1$
        property.setValue("\"org.apache.spark.serializer.JavaSerializer\"");
        elementParameters.add(property);
        for (int i = 0; i < elementParameters.size(); i++) {
            ElementParameterType param = (ElementParameterType) elementParameters.get(i);
            if ("ADVANCED_SETTINGS_CHECK".equals(param.getName())) {
                //$NON-NLS-1$ 
                //$NON-NLS-1$
                param.setValue("true");
                modified = true;
                break;
            }
        }
    }
    if (modified) {
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        factory.save(item, true);
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) EList(org.eclipse.emf.common.util.EList) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 57 with ProxyRepositoryFactory

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

the class RemoveUseHadoopPropertiesFortMRConfiguration method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType != null) {
        boolean modified = false;
        final ParametersType parameters = processType.getParameters();
        if (parameters != null) {
            EList elementParameters = parameters.getElementParameter();
            for (int i = 0; i < elementParameters.size(); i++) {
                ElementParameterType param = (ElementParameterType) elementParameters.get(i);
                if ("USE_HADOOP_PROPERTIES".equals(param.getName())) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    if ("false".equalsIgnoreCase(param.getValue())) {
                        for (int j = 0; j < elementParameters.size(); j++) {
                            ElementParameterType hadoopProps = (ElementParameterType) elementParameters.get(j);
                            if ("HADOOP_ADVANCED_PROPERTIES".equalsIgnoreCase(hadoopProps.getName())) {
                                hadoopProps.getElementValue().clear();
                            }
                        }
                    }
                    elementParameters.remove(param);
                    modified = true;
                    break;
                }
            }
        }
        if (modified) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 58 with ProxyRepositoryFactory

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

the class ChangeLocalModeForSparkConfiguration method execute.

@Override
public ExecutionResult execute(Item item) {
    try {
        ProcessType processType = getProcessType(item);
        if (processType != null) {
            final ParametersType parameters = processType.getParameters();
            if (parameters != null) {
                boolean modified = false;
                EList<ElementParameterType> elementParameters = parameters.getElementParameter();
                for (int i = 0; i < elementParameters.size(); i++) {
                    ElementParameterType param = elementParameters.get(i);
                    if ("SPARK_MODE".equals(param.getName())) {
                        //$NON-NLS-1$
                        modified = true;
                        ElementParameterType property = TalendFileFactory.eINSTANCE.createElementParameterType();
                        //$NON-NLS-1$
                        property.setName("SPARK_LOCAL_MODE");
                        //$NON-NLS-1$
                        property.setField("CHECK");
                        //$NON-NLS-1$
                        property.setValue("false");
                        if ("LOCAL".equalsIgnoreCase(param.getValue())) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            param.setValue("CLUSTER");
                            //$NON-NLS-1$
                            property.setValue("true");
                        }
                        elementParameters.add(property);
                        break;
                    }
                }
                if (modified) {
                    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    factory.save(item, true);
                    return ExecutionResult.SUCCESS_NO_ALERT;
                }
            }
        }
    } catch (PersistenceException e) {
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 59 with ProxyRepositoryFactory

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

the class QueryGuessCommandTest method generateNewTeradataQuery2.

@Test
public void generateNewTeradataQuery2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
    ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
    String propertyId = repFactory.getNextId();
    try {
        DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
        connection.setSID("myschema");
        Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
        connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
        connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
        //$NON-NLS-1$
        connectionProperty.setStatusCode("");
        connectionProperty.setId(propertyId);
        connectionProperty.setLabel("test_connection");
        ConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
        connectionItem.setProperty(connectionProperty);
        connectionItem.setConnection(connection);
        repFactory.create(connectionItem, new Path(""));
        node = Mockito.mock(INode.class);
        connection.setContextMode(true);
        TdTable table = RelationalFactory.eINSTANCE.createTdTable();
        table.setName("tableName");
        table.setLabel("tableLabel");
        TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
        column1.setName("id");
        TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
        column2.setName("name");
        table.getColumns().add(column1);
        table.getColumns().add(column2);
        metadataTable = ConvertionHelper.convert(table);
        ElementParameter parameter = new ElementParameter(node);
        parameter.setName("DBTABLE");
        parameter.setValue(table.getName());
        Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
        Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
        ElementParameter connectionId = new ElementParameter(node);
        connectionId.setValue(connectionProperty.getId());
        Mockito.when(node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())).thenReturn(connectionId);
        // test case 1
        String schema = "";
        String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
        String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
        QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
        Method method = command.getClass().getDeclaredMethod("generateNewQuery");
        method.setAccessible(true);
        String queryString = (String) method.invoke(command);
        Assert.assertEquals(expectedQuery, queryString);
    } catch (Exception e) {
        throw e;
    } finally {
        IRepositoryViewObject lastVersion = repFactory.getLastVersion(propertyId);
        if (lastVersion != null) {
            repFactory.deleteObjectPhysical(lastVersion);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) TdTable(org.talend.cwm.relational.TdTable) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) TdColumn(org.talend.cwm.relational.TdColumn) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 60 with ProxyRepositoryFactory

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

the class KarafJavaScriptForESBWithMavenManager method analysisMavenModule.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void analysisMavenModule(Item item) {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamelRoutes(item)) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<String> mavenModules = getMavenModules();
            mavenModules.clear();
            talendJobsMap.clear();
            EList nodes = ((CamelProcessItem) item).getProcess().getNode();
            for (NodeType node : (List<NodeType>) nodes) {
                if ("cTalendJob".equals(node.getComponentName())) {
                    //$NON-NLS-1$
                    String talendJobId = null;
                    String talendJobVersion = null;
                    String talendJobContextGroup = null;
                    EList elementParameters = node.getElementParameter();
                    for (ElementParameterType paramType : (List<ElementParameterType>) elementParameters) {
                        if ("SELECTED_JOB_NAME:PROCESS_TYPE_PROCESS".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobId = paramType.getValue();
                        } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_VERSION".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobVersion = paramType.getValue();
                        } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_CONTEXT".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobContextGroup = paramType.getValue();
                        }
                        if (talendJobId != null && talendJobVersion != null && talendJobContextGroup != null) {
                            // found
                            break;
                        }
                    }
                    if (talendJobId != null) {
                        if (talendJobVersion == null) {
                            talendJobVersion = RelationshipItemBuilder.LATEST_VERSION;
                        }
                        if (talendJobContextGroup == null) {
                            talendJobContextGroup = IContext.DEFAULT;
                        }
                        IRepositoryViewObject foundObject = null;
                        try {
                            if (RelationshipItemBuilder.LATEST_VERSION.equals(talendJobVersion)) {
                                foundObject = factory.getLastVersion(talendJobId);
                            } else {
                                // find out the fixing version
                                List<IRepositoryViewObject> allVersionObjects = factory.getAllVersion(talendJobId);
                                if (allVersionObjects != null) {
                                    for (IRepositoryViewObject obj : allVersionObjects) {
                                        if (obj.getVersion().equals(talendJobVersion)) {
                                            foundObject = obj;
                                            break;
                                        }
                                    }
                                }
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        if (foundObject != null) {
                            Property property = foundObject.getProperty();
                            if (property != null) {
                                talendJobsMap.put(talendJobId, foundObject);
                                talendJobContextGroupsMap.put(talendJobId, talendJobContextGroup);
                            // we do not export the referenced jobs literally,
                            // but get them for build from the Maven repository.
                            // Thus, we must not add module declarations for them.
                            // mavenModules.add(TALEND_JOBS_PATH + property.getLabel());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.talend.core.model.properties.Property)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)74 PersistenceException (org.talend.commons.exception.PersistenceException)32 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 EList (org.eclipse.emf.common.util.EList)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Project (org.talend.core.model.general.Project)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 ArrayList (java.util.ArrayList)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Path (org.eclipse.core.runtime.Path)6 EConnectionType (org.talend.core.model.process.EConnectionType)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 List (java.util.List)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5