use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class GenericContextHandler method exportContext.
@Override
public boolean exportContext(ConnectionItem connectionItem) {
boolean isContextMode = connectionItem.getConnection().isContextMode();
if (isContextMode) {
ConnectionContextHelper.openInConetxtModeDialog();
} else {
String defaultContextName = ConnectionContextHelper.convertContextLabel(connectionItem.getProperty().getLabel());
if (StringUtils.isEmpty(defaultContextName)) {
//$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.openError(DisplayUtils.getDefaultShell(), Messages.getString("GenericContextHandler.wizardTitle"), Messages.getString("GenericContextHandler.defineConnectionName"));
}
Set<IConnParamName> contextParams = getContextParams();
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = ConnectionContextHelper.exportAsContext(defaultContextName, connectionItem, contextParams);
if (variableModels != null) {
Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
while (contextItor.hasNext()) {
ContextItem contextItem = contextItor.next();
List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
if (contextItem != null && apaptModels.size() == 0) {
// create
if (ConnectionContextHelper.contextManager instanceof JobContextManager) {
Map<String, String> map = ((JobContextManager) ConnectionContextHelper.contextManager).getNameMap();
// set properties for context mode
ConnectionContextHelper.setPropertiesForContextMode(defaultContextName, connectionItem, contextItem, contextParams, map);
}
} else {
// set properties for exist context
ConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, contextParams, variableModels);
}
}
}
return true;
}
return false;
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class GenericContextUtil method setPropertiesForExistContextMode.
public static void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
if (connection == null) {
return;
}
if (connection instanceof GenericConnection) {
GenericConnection genericConn = (GenericConnection) connection;
ComponentProperties componentProperties = getComponentProperties(genericConn);
ContextItem currentContext = null;
for (IConnParamName param : paramSet) {
if (param instanceof GenericConnParamName) {
String genericVariableName = null;
GenericConnParamName genericParam = (GenericConnParamName) param;
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(genericParam.getName())) {
genericVariableName = model.getName();
break;
}
}
}
}
if (genericVariableName != null) {
genericVariableName = getCorrectVariableName(currentContext, genericVariableName, genericParam);
matchContextForAttribues(componentProperties, genericParam, genericVariableName);
}
}
}
updateComponentProperties(genericConn, componentProperties);
}
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method getRepositoryContext.
private static ISelection getRepositoryContext(final String contextNameOrId, boolean isId) {
if (contextNameOrId == null || "".equals(contextNameOrId.trim())) {
//$NON-NLS-1$
return null;
}
if (isId && RepositoryNode.NO_ID.equals(contextNameOrId.trim())) {
return null;
}
IRepositoryViewObject contextObject = null;
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
if (contextObjectList != null) {
for (IRepositoryViewObject object : contextObjectList) {
Item item = object.getProperty().getItem();
if (item != null && item instanceof ContextItem) {
String itemNameOrId = null;
if (isId) {
itemNameOrId = item.getProperty().getId();
} else {
itemNameOrId = item.getProperty().getLabel();
}
if (contextNameOrId.equals(itemNameOrId)) {
contextObject = object;
break;
}
}
}
}
} catch (PersistenceException e) {
//
}
StructuredSelection selection = new StructuredSelection();
if (contextObject != null) {
RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(contextObject);
if (repositoryNode != null) {
selection = new StructuredSelection(repositoryNode);
}
}
return selection;
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setPropertiesForExistContextMode.
public static void setPropertiesForExistContextMode(ConnectionItem connectionItem, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
if (connectionItem == null) {
return;
}
ContextItem selItem = null;
if (map.keySet().size() == 1) {
selItem = map.keySet().iterator().next();
}
Connection conn = connectionItem.getConnection();
if (conn instanceof JSONFileConnection) {
setJSONFilePropertiesForExistContextMode((JSONFileConnection) conn, paramSet, map);
}
// set connection for context mode
connectionItem.getConnection().setContextMode(true);
connectionItem.getConnection().setContextId(selItem.getProperty().getId());
connectionItem.getConnection().setContextName(selItem.getDefaultContext());
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class ReplaceJavaKeywordsNameForContextMigrationTask method getReplacedNamesAndReplaceContextVars.
/**
*
* ggu Comment method "getReplacedNamesAndReplaceContextVars".
*
* get the replaced names, and replace the context variables at the same time.
*/
@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getReplacedNamesAndReplaceContextVars() {
// id to map(oldName to newName)
Map<String, Map<String, String>> contextIdNamesMap = new HashMap<String, Map<String, String>>();
List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
if (allContextItem != null) {
for (ContextItem contextItem : allContextItem) {
boolean changed = false;
boolean first = true;
Set<String> varNames = null;
for (ContextType contextType : (List<ContextType>) contextItem.getContext()) {
if (first) {
varNames = ContextUtils.getContextVarNames(contextType);
}
// oldName to newName
Map<String, String> nameMap = new HashMap<String, String>();
final String contextId = contextItem.getProperty().getId();
for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
String oldName = paramType.getName();
if (first) {
if (ContextUtils.isJavaKeyWords(oldName)) {
// is java keywords
String newName = getNewName(varNames, oldName);
nameMap.put(newName, oldName);
paramType.setName(newName);
changed = true;
}
} else {
String newName = getContextNewNameFromMap(contextIdNamesMap, contextId, oldName);
if (newName != null) {
// is java keywords
paramType.setName(newName);
changed = true;
}
}
}
if (first && !nameMap.isEmpty()) {
contextIdNamesMap.put(contextId, nameMap);
}
first = false;
}
if (changed) {
// save
try {
factory.save(contextItem, true);
} catch (PersistenceException e) {
//
}
}
}
}
return contextIdNamesMap;
}
Aggregations