Search in sources :

Example 6 with JSONException

use of org.talend.utils.json.JSONException in project tdi-studio-se by Talend.

the class LoginProjectPage method saveLastUsedProjectAndBranch.

private void saveLastUsedProjectAndBranch() {
    Project project = getProject();
    loginHelper.getPrefManipulator().setLastProject(project.getLabel());
    if (loginHelper.isRemoteConnection(getConnection())) {
        String branch = getBranch();
        if (branch == null) {
            branch = SVNConstant.EMPTY;
        }
        try {
            loginHelper.getPrefManipulator().setLastSVNBranch(//$NON-NLS-1$
            new JSONObject(project.getEmfProject().getUrl()).getString("location"), //$NON-NLS-1$
            project.getTechnicalLabel(), branch);
        } catch (JSONException e) {
            ExceptionHandler.process(e);
        }
    } else {
        try {
            String jsonStr = project.getEmfProject().getUrl();
            if (jsonStr != null && !jsonStr.isEmpty()) {
                String lastLogonBranch = loginHelper.getPrefManipulator().getLastSVNBranch(new JSONObject(jsonStr).getString("location"), //$NON-NLS-1$
                project.getTechnicalLabel());
                ProjectManager.getInstance().setMainProjectBranch(project, lastLogonBranch);
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Project(org.talend.core.model.general.Project) JSONObject(org.talend.utils.json.JSONObject) JSONException(org.talend.utils.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 7 with JSONException

use of org.talend.utils.json.JSONException in project tdi-studio-se by Talend.

the class MyExtensionAction method run.

public void run(IIntroSite site, Properties params) {
    if (params != null) {
        Object actionType = params.get(ContentConstants.KEY_TYPE);
        if (ContentConstants.UPLOAD_MY_EXTENSION.equals(actionType)) {
            try {
                String values = (String) params.get(ContentConstants.EXTENSIONVALUES);
                if (values != null) {
                    List<VersionRevision> versionRevisions = ExchangeManager.getInstance().getVersionRevisions();
                    ComponentExtension extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                    setValuesForExension(extension, values, versionRevisions);
                    ExchangeManager.getInstance().setSelectedExtension(extension);
                    InsertionExtensionAction uploadAction = new InsertionExtensionAction(extension);
                    uploadAction.run();
                }
            } catch (JSONException e) {
                ExceptionHandler.process(e);
            }
        } else if (ContentConstants.UPDATE_MY_EXTENSION.equals(actionType) || ContentConstants.MODIFY_MY_EXTENSION.equals(actionType)) {
            try {
                String values = (String) params.get(ContentConstants.EXTENSIONVALUES);
                if (values != null) {
                    List<VersionRevision> versionRevisions = ExchangeManager.getInstance().getVersionRevisions();
                    ComponentExtension selectedExtension = ExchangeManager.getInstance().getSelectedExtension();
                    setValuesForExension(selectedExtension, values, versionRevisions);
                    if (ContentConstants.UPDATE_MY_EXTENSION.equals(actionType)) {
                        UploadRevisionAction uploadAction = new UploadRevisionAction(selectedExtension);
                        uploadAction.run();
                    } else {
                        ModifyExtensionAction modifyAction = new ModifyExtensionAction();
                        modifyAction.run();
                    }
                }
            } catch (JSONException e) {
                ExceptionHandler.process(e);
            }
        } else if (ContentConstants.UPLOAD_NEW_VERSION_ACTION.equals(actionType) || ContentConstants.MODIFY_ACTION.equals(actionType)) {
            Object object = params.get(ContentConstants.KEY_EXTENSION_ID);
            String key = null;
            if (object instanceof String) {
                key = (String) object;
            }
            ComponentExtension componentExtension = MyExchangeContentProvider.componentMap.get(key);
            if (componentExtension != null) {
                ExchangeManager.getInstance().setSelectedExtension(componentExtension);
                if (ContentConstants.UPLOAD_NEW_VERSION_ACTION.equals(actionType)) {
                    ExchangeManager.getInstance().generateXHTMLPage(ContentConstants.UL_UPLOAD_EXTENSION_VERSION, new String[] { ContentConstants.LAST_AVAILABLE_VERSION });
                } else {
                    ExchangeManager.getInstance().generateXHTMLPage(ContentConstants.UL_MODIFY_MY_EXTENSION_PAGE, new String[] { ContentConstants.EXTENSION_LABEL });
                }
            }
        } else if (ContentConstants.DELETE_ACTION.equals(actionType)) {
            Object object = params.get(ContentConstants.KEY_EXTENSION_ID);
            String key = null;
            if (object instanceof String) {
                key = (String) object;
            }
            ComponentExtension componentExtension = MyExchangeContentProvider.componentMap.get(key);
            ExchangeManager.getInstance().setSelectedExtension(componentExtension);
            if (componentExtension != null) {
                final DeleteExtensionAction delAction = new DeleteExtensionAction(componentExtension);
                if (delAction != null) {
                    delAction.run();
                }
            }
        }
    }
}
Also used : UploadRevisionAction(org.talend.designer.components.exchange.ui.actions.UploadRevisionAction) ModifyExtensionAction(org.talend.designer.components.exchange.ui.actions.ModifyExtensionAction) InsertionExtensionAction(org.talend.designer.components.exchange.ui.actions.InsertionExtensionAction) JSONException(org.talend.utils.json.JSONException) JSONObject(org.talend.utils.json.JSONObject) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension) List(java.util.List) VersionRevision(org.talend.designer.components.exchange.model.VersionRevision) DeleteExtensionAction(org.talend.designer.components.exchange.ui.actions.DeleteExtensionAction)

Example 8 with JSONException

use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.

the class NoSQLRepositoryContextHandler method createContextParameters.

@Override
public List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    List<IContextParameter> varList = new ArrayList<IContextParameter>();
    if (connection instanceof NoSQLConnection) {
        NoSQLConnection conn = (NoSQLConnection) connection;
        JavaType javaType = null;
        if (conn == null || prefixName == null || paramSet == null || paramSet.isEmpty()) {
            return Collections.emptyList();
        }
        for (Map.Entry<String, String> attr : ((NoSQLConnection) connection).getAttributes()) {
            if (INoSQLCommonAttributes.PASSWORD.equals(attr)) {
                javaType = JavaTypesManager.PASSWORD;
            }
        }
        String paramPrefix = prefixName + ConnectionContextHelper.LINE;
        String paramName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof EHadoopParamName) {
                EHadoopParamName noSqlParam = (EHadoopParamName) param;
                paramName = paramPrefix + noSqlParam;
                switch(noSqlParam) {
                    case Server:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.HOST), javaType);
                        break;
                    case Port:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.PORT), javaType);
                        break;
                    case Keyspace:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.DATABASE), javaType);
                        break;
                    case Database:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.DATABASE), javaType);
                        break;
                    case Databasepath:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INeo4jAttributes.DATABASE_PATH), javaType);
                        break;
                    case ServerUrl:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INeo4jAttributes.SERVER_URL), javaType);
                        break;
                    case UserName:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.USERNAME), javaType);
                        break;
                    case Password:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(INoSQLCommonAttributes.PASSWORD), JavaTypesManager.PASSWORD);
                        break;
                    case ConnectionString:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.CONN_STRING), javaType);
                        break;
                    case Keystore:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.X509_CERT), javaType);
                        break;
                    case KeystorePass:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.X509_CERT_KEYSTORE_PASSWORD), JavaTypesManager.PASSWORD);
                        break;
                    case Truststore:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.X509_CERT_AUTH), javaType);
                        break;
                    case TruststorePass:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.X509_CERT_AUTH_TRUSTSTORE_PASSWORD), JavaTypesManager.PASSWORD);
                        break;
                    case AuthenticationDatabase:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.AUTHENTICATION_DATABASE), javaType);
                        break;
                    case UserPrincipal:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.KRB_USER_PRINCIPAL), javaType);
                        break;
                    case Realm:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.KRB_REALM), javaType);
                        break;
                    case KDCServer:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getAttributes().get(IMongoDBAttributes.KRB_KDC), javaType);
                        break;
                    case ReplicaSets:
                        String replicaSets = conn.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
                        if (StringUtils.isNotEmpty(replicaSets)) {
                            try {
                                JSONArray jsa = new JSONArray(replicaSets);
                                for (int i = 0; i < jsa.length(); i++) {
                                    JSONObject jso = jsa.getJSONObject(i);
                                    String hostParamName = paramPrefix + EHadoopParamName.ReplicaHost.name() + ConnectionContextHelper.LINE + (i + 1);
                                    String portParamName = paramPrefix + EHadoopParamName.ReplicaPort.name() + ConnectionContextHelper.LINE + (i + 1);
                                    String hostValue = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
                                    String portValue = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
                                    ConnectionContextHelper.createParameters(varList, hostParamName, hostValue, JavaTypesManager.STRING);
                                    ConnectionContextHelper.createParameters(varList, portParamName, portValue, JavaTypesManager.INTEGER);
                                }
                            } catch (JSONException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        break;
                    default:
                }
            }
        }
    }
    return varList;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) IContextParameter(org.talend.core.model.process.IContextParameter) JavaType(org.talend.core.model.metadata.types.JavaType) JSONObject(org.talend.utils.json.JSONObject) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) Map(java.util.Map)

Example 9 with JSONException

use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.

the class NoSQLRepositoryContextHandler method matchContextForAttribues.

@Override
protected void matchContextForAttribues(Connection conn, IConnParamName param, String noSqlVariableName) {
    NoSQLConnection noSqlConn = (NoSQLConnection) conn;
    EHadoopParamName noSqlParam = (EHadoopParamName) param;
    switch(noSqlParam) {
        case Server:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.HOST, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case ConnectionString:
            noSqlConn.getAttributes().put(IMongoDBAttributes.CONN_STRING, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Port:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.PORT, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Database:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Keyspace:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Databasepath:
            noSqlConn.getAttributes().put(INeo4jAttributes.DATABASE_PATH, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case ServerUrl:
            noSqlConn.getAttributes().put(INeo4jAttributes.SERVER_URL, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case UserName:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.USERNAME, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Password:
            noSqlConn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Keystore:
            noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case KeystorePass:
            noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_KEYSTORE_PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Truststore:
            noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case TruststorePass:
            noSqlConn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH_TRUSTSTORE_PASSWORD, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case AuthenticationDatabase:
            noSqlConn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_DATABASE, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case UserPrincipal:
            noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_USER_PRINCIPAL, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case Realm:
            noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_REALM, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case KDCServer:
            noSqlConn.getAttributes().put(IMongoDBAttributes.KRB_KDC, ContextParameterUtils.getNewScriptCode(noSqlVariableName, LANGUAGE));
            break;
        case ReplicaSets:
            String replicaSets = noSqlConn.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
            try {
                JSONArray jsa = new JSONArray(replicaSets);
                for (int i = 0; i < jsa.length(); i++) {
                    JSONObject jso = jsa.getJSONObject(i);
                    int paramNum = i + 1;
                    String hostParamName = noSqlVariableName + ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaHost, paramNum);
                    String portParamName = noSqlVariableName + ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaPort, paramNum);
                    jso.put(IMongoConstants.REPLICA_HOST_KEY, ContextParameterUtils.getNewScriptCode(hostParamName, LANGUAGE));
                    jso.put(IMongoConstants.REPLICA_PORT_KEY, ContextParameterUtils.getNewScriptCode(portParamName, LANGUAGE));
                }
                noSqlConn.getAttributes().put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
            } catch (JSONException e) {
                ExceptionHandler.process(e);
            }
            break;
        default:
    }
}
Also used : JSONObject(org.talend.utils.json.JSONObject) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection)

Example 10 with JSONException

use of org.talend.utils.json.JSONException in project tbd-studio-se by Talend.

the class NoSQLRepositoryContextHandler method setPropertiesForExistContextMode.

@Override
public void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
    if (connection == null) {
        return;
    }
    if (connection instanceof NoSQLConnection) {
        NoSQLConnection noSqlConn = (NoSQLConnection) connection;
        ContextItem currentContext = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof EHadoopParamName) {
                String noSqlVariableName = null;
                EHadoopParamName noSqlParam = (EHadoopParamName) param;
                if (noSqlParam == EHadoopParamName.ReplicaSets) {
                    String replicaSets = noSqlConn.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
                    try {
                        JSONArray jsa = new JSONArray(replicaSets);
                        for (int i = 0; i < jsa.length(); i++) {
                            JSONObject jso = jsa.getJSONObject(i);
                            int paramNum = i + 1;
                            String hostParamName = ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaHost, paramNum);
                            String portParamName = ExtendedNodeConnectionContextUtils.getReplicaParamName(EHadoopParamName.ReplicaPort, paramNum);
                            String hostVariableName = null;
                            String portVariableName = null;
                            if (adaptMap != null && adaptMap.size() > 0) {
                                for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                                    currentContext = entry.getKey();
                                    List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                                    for (ConectionAdaptContextVariableModel model : modelList) {
                                        if (model.getValue().equals(hostParamName)) {
                                            hostVariableName = model.getName();
                                        } else if (model.getValue().equals(portParamName)) {
                                            portVariableName = model.getName();
                                        }
                                        if (hostVariableName != null && portVariableName != null) {
                                            break;
                                        }
                                    }
                                }
                            }
                            if (hostVariableName != null && portVariableName != null) {
                                hostVariableName = getCorrectVariableName(currentContext, hostVariableName, hostParamName);
                                portVariableName = getCorrectVariableName(currentContext, portVariableName, portParamName);
                                jso.put(IMongoConstants.REPLICA_HOST_KEY, ContextParameterUtils.getNewScriptCode(hostVariableName, LANGUAGE));
                                jso.put(IMongoConstants.REPLICA_PORT_KEY, ContextParameterUtils.getNewScriptCode(portVariableName, LANGUAGE));
                            }
                        }
                        noSqlConn.getAttributes().put(IMongoDBAttributes.REPLICA_SET, jsa.toString());
                    } catch (JSONException e) {
                        ExceptionHandler.process(e);
                    }
                } else {
                    if (adaptMap != null && adaptMap.size() > 0) {
                        for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                            currentContext = entry.getKey();
                            List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                            for (ConectionAdaptContextVariableModel model : modelList) {
                                if (model.getValue().equals(noSqlParam.name())) {
                                    noSqlVariableName = model.getName();
                                    break;
                                }
                            }
                        }
                    }
                    if (noSqlVariableName != null) {
                        noSqlVariableName = getCorrectVariableName(currentContext, noSqlVariableName, noSqlParam);
                        matchContextForAttribues(noSqlConn, noSqlParam, noSqlVariableName);
                    }
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) JSONObject(org.talend.utils.json.JSONObject) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) ArrayList(java.util.ArrayList) List(java.util.List) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) Map(java.util.Map)

Aggregations

JSONException (org.talend.utils.json.JSONException)26 JSONObject (org.talend.utils.json.JSONObject)21 JSONArray (org.talend.utils.json.JSONArray)14 Project (org.talend.core.model.general.Project)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 PersistenceException (org.talend.commons.exception.PersistenceException)4 NoSQLConnection (org.talend.repository.model.nosql.NoSQLConnection)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ConnectionBean (org.talend.core.model.general.ConnectionBean)3 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)3 Iterator (java.util.Iterator)2 SystemException (org.talend.commons.exception.SystemException)2 Context (org.talend.core.context.Context)2 RepositoryContext (org.talend.core.context.RepositoryContext)2 User (org.talend.core.model.properties.User)2 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2