Search in sources :

Example 16 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class UnifyPasswordEncryption4DBConnectionMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        Connection connection = ((DatabaseConnectionItem) item).getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) connection;
            try {
                if (!dbConn.isContextMode()) {
                    String pass = dbConn.getPassword();
                    String rawPass = null;
                    try {
                        rawPass = PasswordEncryptUtil.decryptPassword(pass);
                    } catch (Exception e) {
                        // MOD xqliu 2010-07-07 bug 13826
                        rawPass = ConnectionHelper.getDecryptPassword(pass);
                    // ~ 13826
                    }
                    // decrypt the old password.
                    dbConn.setRawPassword(rawPass);
                    factory.save(item, true);
                    return ExecutionResult.SUCCESS_NO_ALERT;
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 17 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class TosTokenCollector method collectProjectDetails.

private JSONObject collectProjectDetails() throws PersistenceException, JSONException {
    JSONObject jObject = new JSONObject();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    JSONObject repoStats = new JSONObject();
    // metadata
    for (DynaEnum type : ERepositoryObjectType.values()) {
        if (type instanceof ERepositoryObjectType && ((ERepositoryObjectType) type).isResourceItem()) {
            try {
                List<IRepositoryViewObject> all = factory.getAll(currentProject, (ERepositoryObjectType) type);
                int nb = all.size();
                if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_PATTERN_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_RULES.equals(type) || "TDQ_SOURCE_FILE_ELEMENT".equals(type.getType())) {
                    //$NON-NLS-1$
                    continue;
                }
                if (ERepositoryObjectType.ROUTINES.equals(type)) {
                    nb = 0;
                    List<IRepositoryViewObject> newList = new ArrayList<IRepositoryViewObject>();
                    for (IRepositoryViewObject object : all) {
                        RoutineItem rItem = (RoutineItem) object.getProperty().getItem();
                        if (!rItem.isBuiltIn()) {
                            nb++;
                            newList.add(object);
                        }
                    }
                    all = newList;
                }
                if (ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        SQLPatternItem spItem = (SQLPatternItem) object.getProperty().getItem();
                        if (!spItem.isSystem()) {
                            nb++;
                        }
                    }
                }
                if ("MDM.DataModel".equals(type.getType())) {
                    //$NON-NLS-1$
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        String path = object.getProperty().getItem().getState().getPath();
                        if (!"System".equals(path)) {
                            //$NON-NLS-1$
                            nb++;
                        }
                    }
                }
                if (nb > 0) {
                    JSONObject typeStats = new JSONObject();
                    //$NON-NLS-1$
                    typeStats.put("nb", nb);
                    if (ERepositoryObjectType.getAllTypesOfProcess().contains(type)) {
                        JSONObject jobDetails = new JSONObject();
                        collectJobDetails(all, jobDetails);
                        //$NON-NLS-1$
                        typeStats.put("details", jobDetails);
                    }
                    if (ERepositoryObjectType.ROUTINES.equals(type) || //$NON-NLS-1$
                    ((ERepositoryObjectType) type).getFolder().startsWith("metadata/") || ERepositoryObjectType.CONTEXT.equals(type) || type.equals(ERepositoryObjectType.JOBLET)) {
                        int nbUsed = 0;
                        for (IRepositoryViewObject object : all) {
                            List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getId());
                            relations.addAll(RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getLabel()));
                            if (relations.size() > 0) {
                                nbUsed++;
                            }
                        }
                        //$NON-NLS-1$
                        typeStats.put("nb.used", nbUsed);
                    }
                    if (ERepositoryObjectType.METADATA_CONNECTIONS.equals(type)) {
                        JSONObject objects = new JSONObject();
                        for (IRepositoryViewObject object : all) {
                            DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
                            String dbType = ((DatabaseConnection) item.getConnection()).getDatabaseType();
                            int nbDbTypes = 1;
                            if (objects.has(dbType)) {
                                nbDbTypes = objects.getInt(dbType);
                                nbDbTypes++;
                            }
                            objects.put(dbType, nbDbTypes);
                        }
                        //$NON-NLS-1$
                        typeStats.put("types", objects);
                    }
                    repoStats.put(type.getType(), typeStats);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    //$NON-NLS-1$
    jObject.put(PROJECTS.getKey(), repoStats);
    jObject.put(TYPE.getKey(), ProjectManager.getInstance().getProjectType(currentProject));
    int nbRef = ProjectManager.getInstance().getAllReferencedProjects().size();
    if (nbRef > 0) {
        jObject.put("nb.refProjects", nbRef);
    }
    return jObject;
}
Also used : DynaEnum(org.talend.core.model.repository.DynaEnum) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) JSONException(us.monoid.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Project(org.talend.core.model.general.Project) Relation(org.talend.core.model.relationship.Relation) JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 18 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class DbTableController method getExistConnection.

/**
     * DOC zli Comment method "getExistConnection".
     * 
     * @return
     */
private DatabaseConnection getExistConnection() {
    String implicitRepositoryId = getImplicitRepositoryId();
    String statsLogPrositoryId = getStatsLogRepositoryId();
    if (implicitRepositoryId != null || statsLogPrositoryId != null) {
        // jobsetting view load the exist db info from current selected category
        String repId = null;
        if (EComponentCategory.EXTRA.equals(section)) {
            repId = implicitRepositoryId;
        } else if (EComponentCategory.STATSANDLOGS.equals(section)) {
            repId = statsLogPrositoryId;
        }
        if (repId != null) {
            IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
            try {
                IRepositoryViewObject lastVersion = proxyRepositoryFactory.getLastVersion(repId);
                if (lastVersion != null) {
                    Item item = lastVersion.getProperty().getItem();
                    if (item instanceof DatabaseConnectionItem) {
                        DatabaseConnection connection = (DatabaseConnection) ((DatabaseConnectionItem) item).getConnection();
                        return connection;
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return null;
}
Also used : Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 19 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class UpdateNodeParameterCommand method updateProperty.

@SuppressWarnings("unchecked")
private void updateProperty() {
    Object updateObject = result.getUpdateObject();
    if (updateObject == null) {
        return;
    }
    if (updateObject instanceof Node) {
        // opened job
        Node node = (Node) updateObject;
        boolean update = false;
        // added by wzhang for bug 9302
        boolean isXsdPath = false;
        Object parameter = result.getParameter();
        IElementParameter curPropertyParam = null;
        //$NON-NLS-1$
        String parentParamName = "PROPERTY";
        ConnectionItem connectionItem = null;
        if (parameter instanceof ConnectionItem) {
            if (parameter instanceof XmlFileConnectionItem) {
                String filePath = ((XmlFileConnection) ((XmlFileConnectionItem) parameter).getConnection()).getXmlFilePath();
                if (filePath != null) {
                    if (XmlUtil.isXSDFile(filePath)) {
                        isXsdPath = true;
                    }
                }
            }
            connectionItem = (ConnectionItem) result.getParameter();
            for (IElementParameter param : node.getElementParameters()) {
                if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE && param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue().equals(connectionItem.getProperty().getId())) {
                    curPropertyParam = param;
                    parentParamName = curPropertyParam.getName();
                    if (connectionItem != null) {
                        ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
                    }
                    break;
                }
            }
        }
        if (result.getResultType() == EUpdateResult.UPDATE) {
            // upgrade from repository
            if (result.isChecked() && connectionItem != null) {
                List<? extends IElementParameter> elemParameters = new ArrayList<>(node.getElementParameters());
                for (IElementParameter param : elemParameters) {
                    String repositoryValue = param.getRepositoryValue();
                    if (param.getRepositoryValue() == null || (curPropertyParam != null && param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(curPropertyParam.getName()))) {
                        continue;
                    }
                    if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                        continue;
                    }
                    if ((repositoryValue != null) && (param.isShow(node.getElementParameters()) || node.getComponentProperties() != null || (node instanceof INode && ((INode) node).getComponent().getName().equals("tAdvancedFileOutputXML")) || (node instanceof INode && ((INode) node).getComponent().getName().equals("tESBProviderRequest")))) {
                        //$NON-NLS-1$
                        if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
                            continue;
                        }
                        if (param.getFieldType().equals(EParameterFieldType.FILE) && isXsdPath) {
                            continue;
                        }
                        IMetadataTable table = null;
                        if (!node.getMetadataList().isEmpty()) {
                            table = node.getMetadataList().get(0);
                        }
                        Object objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), repositoryValue, table);
                        if (objectValue == null || "".equals(objectValue)) {
                            if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                                IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
                                if (service != null) {
                                    String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                                    if (node.getComponent().getName().startsWith("tESB")) {
                                        if (propertyValue.contains(" - ")) {
                                            propertyValue = propertyValue.split(" - ")[0];
                                        }
                                    }
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
                                    if (lastVersion != null) {
                                        Item item = lastVersion.getProperty().getItem();
                                        if (item != null) {
                                            Object objectValueFromESB = service.getValue(item, repositoryValue, node);
                                            if (objectValueFromESB != null) {
                                                objectValue = objectValueFromESB;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (param.getName().equals(EParameterName.CDC_TYPE_MODE.getName())) {
                            //
                            String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                            Item item = null;
                            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
                            if (lastVersion != null) {
                                item = lastVersion.getProperty().getItem();
                            }
                            if (item != null && PluginChecker.isCDCPluginLoaded()) {
                                ICDCProviderService service = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
                                if (service != null) {
                                    try {
                                        List<IRepositoryViewObject> all;
                                        all = CorePlugin.getDefault().getProxyRepositoryFactory().getAll(ERepositoryObjectType.METADATA_CONNECTIONS);
                                        for (IRepositoryViewObject obj : all) {
                                            Item tempItem = obj.getProperty().getItem();
                                            if (tempItem instanceof DatabaseConnectionItem) {
                                                String cdcLinkId = service.getCDCConnectionLinkId((DatabaseConnectionItem) tempItem);
                                                if (cdcLinkId != null && item.getProperty().getId().equals(cdcLinkId)) {
                                                    objectValue = RepositoryToComponentProperty.getValue(((DatabaseConnectionItem) tempItem).getConnection(), repositoryValue, node.getMetadataList().get(0));
                                                }
                                            }
                                        }
                                    } catch (PersistenceException e) {
                                        ExceptionHandler.process(e);
                                    }
                                }
                            }
                        }
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
                            IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
                            boolean paramChanged = jsonService.changeFilePathFromRepository(connectionItem.getConnection(), param, node, objectValue);
                            if (paramChanged) {
                                continue;
                            }
                        }
                        if (objectValue != null) {
                            if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
                                boolean found = false;
                                String[] items = param.getListRepositoryItems();
                                for (int i = 0; (i < items.length) && (!found); i++) {
                                    if (objectValue.equals(items[i])) {
                                        found = true;
                                        node.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                                    }
                                }
                            } else {
                                // update tFileInputExcel job
                                if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
                                    String name = param.getName();
                                    if (name.equals("ROOT") || name.equals("LOOP") || name.equals("GROUP") && objectValue instanceof List) {
                                        param.setValue(objectValue);
                                    } else if (param.getName().equals("SHEETLIST") && objectValue instanceof List) {
                                        List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
                                        if (paramMaps == null) {
                                            paramMaps = new ArrayList<Map<String, Object>>();
                                            node.setPropertyValue(param.getName(), paramMaps);
                                        } else {
                                            // hywang add for 9537
                                            List<Map<String, Object>> objectValueList = (List<Map<String, Object>>) objectValue;
                                            if (paramMaps.size() < objectValueList.size()) {
                                                paramMaps.clear();
                                                for (int i = 0; i < objectValueList.size(); i++) {
                                                    Map<String, Object> map = objectValueList.get(i);
                                                    paramMaps.add(map);
                                                }
                                            } else {
                                                String value = null;
                                                List<String> repNames = new ArrayList<String>();
                                                for (int i = 0; i < objectValueList.size(); i++) {
                                                    repNames.add(objectValueList.get(i).get("SHEETNAME").toString());
                                                }
                                                for (int j = 0; j < paramMaps.size(); j++) {
                                                    Map<String, Object> map = paramMaps.get(j);
                                                    value = map.get("SHEETNAME").toString();
                                                    if (!repNames.contains(value)) {
                                                        paramMaps.remove(j);
                                                    }
                                                }
                                            }
                                        }
                                    } else if ((name.equals("HADOOP_ADVANCED_PROPERTIES") || name.equals("ADVANCED_PROPERTIES") || name.equals("HBASE_PARAMETERS") || name.equals("SAP_PROPERTIES") && objectValue instanceof List)) {
                                        List<HashMap<String, Object>> oldValue = (List<HashMap<String, Object>>) param.getValue();
                                        for (HashMap<String, Object> map : oldValue) {
                                            if (map.get("BUILDIN") != null && !map.get("BUILDIN").equals("") && Boolean.valueOf(String.valueOf(map.get("BUILDIN")))) {
                                                ((List<HashMap<String, Object>>) objectValue).add(map);
                                            }
                                        }
                                        param.setValue(objectValue);
                                    } else // it in jobs
                                    if (param.getName().equals("DRIVER_JAR") && objectValue instanceof List) {
                                        param.setValue(objectValue);
                                    }
                                } else {
                                    node.setPropertyValue(param.getName(), objectValue);
                                }
                            }
                        } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && UpdatesConstants.XML_MAPPING.equals(repositoryValue)) {
                            RepositoryToComponentProperty.getTableXMLMappingValue(connectionItem.getConnection(), (List<Map<String, Object>>) param.getValue(), node);
                        } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getName().equals("PARAMS")) {
                            objectValue = RepositoryToComponentProperty.getValue(connectionItem.getConnection(), "PARAMS", node.getMetadataList().get(0));
                            List<Map<String, Object>> paramMaps = (List<Map<String, Object>>) param.getValue();
                            if (paramMaps == null) {
                                paramMaps = new ArrayList<Map<String, Object>>();
                            } else {
                                paramMaps.clear();
                            }
                            if (objectValue != null) {
                                List<String> objectValueList = (List<String>) objectValue;
                                for (int i = 0; i < objectValueList.size(); i++) {
                                    Map<String, Object> map = new HashedMap();
                                    map.put("VALUE", TalendTextUtils.addQuotes(objectValueList.get(i)));
                                    paramMaps.add(map);
                                }
                            }
                        } else if (node.getComponentProperties() != null && objectValue == null) {
                            // for new framework, still save the null value in component
                            node.setPropertyValue(param.getName(), objectValue);
                        }
                        if (!("tMDMReceive".equals(node.getComponent().getName()) && "XPATH_PREFIX".equals(//$NON-NLS-1$ //$NON-NLS-2$
                        param.getRepositoryValue()))) {
                            param.setRepositoryValueUsed(true);
                            param.setReadOnly(true);
                            update = true;
                        }
                    }
                }
            } else {
                // Added TDQ-11688 20170309 yyin
                ITDQPatternService service = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
                    service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
                }
                if (service != null && (service.isSinglePatternNode(node) || service.isMultiPatternNode(node)) && parameter != null && parameter instanceof IElementParameter) {
                    IElementParameter elementParameter = node.getElementParameter(((IElementParameter) parameter).getName());
                    if (elementParameter != null && !elementParameter.getValue().equals(((IElementParameter) parameter).getValue())) {
                        elementParameter.setValue(((IElementParameter) parameter).getValue());
                    }
                    update = true;
                    Object regexValue = null;
                    Object parameterValue = ((IElementParameter) parameter).getValue();
                    if ("PATTERN_REGEX".equals(((IElementParameter) parameter).getName())) {
                        regexValue = parameterValue;
                    } else if ("SCHEMA_PATTERN_CHECK".equals(((IElementParameter) parameter).getName())) {
                        List<Map<String, String>> multiPatternList = ((List<Map<String, String>>) parameterValue);
                        for (Map<String, String> patternMap : multiPatternList) {
                            regexValue = patternMap.get("PATTERN_REGEX");
                            if (regexValue == null) {
                                patternMap.put("PATTERN_PROPERTY", EmfComponent.BUILTIN);
                            }
                        }
                    }
                    if (regexValue == null || regexValue.toString().isEmpty()) {
                        update = false;
                    }
                }
            }
        }
        if (!update) {
            // bult-in
            String propertyName = parentParamName + ":" + EParameterName.PROPERTY_TYPE.getName();
            if (this.result.getParameter() instanceof IElementParameter) {
                IElementParameter parentParam = ((IElementParameter) this.result.getParameter()).getParentParameter();
                if (parentParam != null) {
                    parentParamName = parentParam.getName();
                    propertyName = parentParam.getName() + ":" + parentParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getName();
                }
            }
            node.setPropertyValue(propertyName, EmfComponent.BUILTIN);
            for (IElementParameter param : node.getElementParameters()) {
                if (param.getRepositoryValue() == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(parentParamName)) {
                    continue;
                }
                if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                    continue;
                }
                if (param.isShow(node.getElementParameters())) {
                    if (param.getName().equals(EParameterName.PROPERTY_TYPE.getName()) || param.getFieldType() == EParameterFieldType.MEMO_SQL) {
                        continue;
                    }
                    param.setRepositoryValueUsed(false);
                    param.setReadOnly(false);
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) ITDQPatternService(org.talend.core.ITDQPatternService) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) IJsonFileService(org.talend.core.service.IJsonFileService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IESBService(org.talend.core.IESBService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) HashedMap(org.apache.commons.collections.map.HashedMap) ICDCProviderService(org.talend.core.ui.ICDCProviderService) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap)

Example 20 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class AbstractJobSettingsPage method updateProjectSetting.

public void updateProjectSetting() {
    String[] split = getRepositoryPropertyName().split(":");
    String parentParamName = split[0];
    Element elementParams = elem;
    IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
    if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
        if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
            DatabaseConnection connection = null;
            String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
            if (lastVersion != null && lastVersion.getProperty() != null) {
                Item item = lastVersion.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    connection = (DatabaseConnection) dbItem.getConnection();
                }
            }
            if (connection != null) {
                boolean sameValues = true;
                for (IElementParameter param : elementParams.getElementParameters()) {
                    String repositoryValue = param.getRepositoryValue();
                    if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
                        Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
                        if (repValue == null) {
                            continue;
                        }
                        if (repositoryValue.equals(UpdatesConstants.TYPE)) {
                            // datebase type
                            boolean found = false;
                            String[] list = param.getListRepositoryItems();
                            for (int i = 0; (i < list.length) && (!found); i++) {
                                if (repValue.equals(list[i])) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                sameValues = false;
                                break;
                            }
                        } else {
                            // check the value
                            if (!param.getValue().equals(repValue)) {
                                sameValues = false;
                                break;
                            }
                        }
                    }
                }
                if (!sameValues) {
                    boolean ok = MessageDialog.openQuestion(getShell(), getDisplayName(), "Connection has been changed , do you want to change value from repository ?");
                    if (ok) {
                        ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, getRepositoryPropertyName(), id);
                        changeValuesFromRepository.execute();
                        isConnectionChanged = true;
                    }
                }
            } else {
                MessageDialog.openInformation(getShell(), getDisplayName(), "Connection has been deleted ,change to build in automaticlly");
                ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, getPropertyTypeName(), EmfComponent.BUILTIN);
                changeValuesFromRepository1.execute();
                isConnectionChanged = true;
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) Element(org.talend.core.model.process.Element) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)50 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)40 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 PersistenceException (org.talend.commons.exception.PersistenceException)16 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 Item (org.talend.core.model.properties.Item)13 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 ArrayList (java.util.ArrayList)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Query (org.talend.core.model.metadata.builder.connection.Query)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 INode (org.talend.core.model.process.INode)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)6 ContextItem (org.talend.core.model.properties.ContextItem)6 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 List (java.util.List)5 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)5