use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.
static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
if (jsonConn == null) {
return;
}
String jsonVariableName = null;
for (IConnParamName param : paramSet) {
if (param instanceof EParamName) {
EParamName jsonParam = (EParamName) param;
if (map != null && map.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(jsonParam.name())) {
jsonVariableName = model.getName();
break;
}
}
}
}
if (jsonConn.isInputModel()) {
switch(jsonParam) {
case FilePath:
jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case Encoding:
jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case XPathQuery:
EList schema = jsonConn.getSchema();
if (schema != null) {
if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
default:
}
} else {
if (jsonParam.equals(EParamName.OutputFilePath)) {
jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
}
}
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method exportAsContext.
/**
*
* ggu Comment method "exportAsContext".
*
*/
public static Map<ContextItem, List<ConectionAdaptContextVariableModel>> exportAsContext(ConnectionItem connItem, Set<IConnParamName> paramSet) {
if (connItem == null) {
return null;
}
List<IContextParameter> varList = createContextParameters(connItem, paramSet);
if (varList == null || varList.isEmpty()) {
return null;
}
String contextName = convertContextLabel(connItem.getProperty().getLabel());
ISelection selection = getRepositoryContext(contextName, false);
if (selection == null) {
return null;
}
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableContextMap = new HashMap();
List<ConectionAdaptContextVariableModel> models = new ArrayList<ConectionAdaptContextVariableModel>();
Set<String> connectionVaribles = getConnVariables(connItem, paramSet);
ContextModeWizard contextWizard = new ContextModeWizard(contextName, selection.isEmpty(), selection, varList, connectionVaribles);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), contextWizard);
if (dlg.open() == Window.OK) {
ContextItem contextItem = contextWizard.getContextItem();
models = contextWizard.getAdaptModels();
if (contextItem != null) {
variableContextMap.put(contextItem, models);
}
contextManager = contextWizard.getContextManager();
if (contextItem != null) {
contextItem.getProperty().setLabel(contextName);
}
return variableContextMap;
}
return null;
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class ReadQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
DatabaseConnectionItem dbConnectionItem = null;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
}
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(true);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(true);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
refresh(repositoryNode);
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class EditQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject nodeObject = repositoryNode.getObject();
boolean locked = false;
if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
locked = true;
}
}
// Avoid to delete node which is locked.
if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
final String title = "Impossible to edit queries";
String nodeName = nodeObject.getRepositoryObjectType().getLabel();
final String message = "item is already locked by another user.";
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
dialog.open();
}
});
return;
}
DatabaseConnectionItem dbConnectionItem = null;
boolean readOnly = false;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
//$NON-NLS-1$
connParameters.setQuery("");
}
IRepositoryView viewPart = getViewPart();
Display display = null;
if (viewPart != null) {
display = viewPart.getViewer().getControl().getDisplay();
} else {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(readOnly);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(readOnly);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
IRepositoryView view = getViewPart();
if (view != null) {
view.refreshView();
}
}
use of org.talend.core.model.properties.ContextItem in project tdi-studio-se by Talend.
the class AddContextCommentValueMigrationTaskTest method createTempContextItem.
private ContextItem createTempContextItem() throws PersistenceException {
ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
Property myProperty = PropertiesFactory.eINSTANCE.createProperty();
myProperty.setId(ProxyRepositoryFactory.getInstance().getNextId());
ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
itemState.setDeleted(false);
itemState.setPath("");
contextItem.setState(itemState);
contextItem.setProperty(myProperty);
myProperty.setLabel("context1");
myProperty.setVersion("0.1");
ProxyRepositoryFactory.getInstance().create(contextItem, new Path(""));
return contextItem;
}
Aggregations