use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method prepareEmfTreeFromMdm.
private void prepareEmfTreeFromMdm(MDMConnection connection, String selectedConcept) throws Exception {
if (connection == null || selectedConcept == null) {
return;
}
EList<Concept> schemas = connection.getSchemas();
Concept selected = null;
for (int i = 0; i < schemas.size(); i++) {
Concept concept = schemas.get(i);
if (selectedConcept.equals(concept.getLabel())) {
selected = concept;
break;
}
}
if (selected != null) {
IMDMProviderService service = (IMDMProviderService) GlobalServiceRegister.getDefault().getService(IMDMProviderService.class);
if (service != null) {
boolean initConcepts = service.initConcepts(connection);
if (initConcepts) {
if (!MdmConceptType.OUTPUT.equals(selected.getConceptType())) {
String prefix = service.getXPathPrefixValue(selected);
prefix = TalendTextUtils.removeQuotes(prefix);
absoluteXPathQuery = selected.getLoopExpression();
EList<ConceptTarget> conceptTargets = selected.getConceptTargets();
if (conceptTargets == null || absoluteXPathQuery == null) {
return;
}
this.schemaTargets = conceptTargets;
// find corresponding metadata table
Set<MetadataTable> metadataTables = ConnectionHelper.getTables(connection);
for (MetadataTable table : metadataTables) {
if (selected.getLabel() != null && selected.getLabel().equals(table.getLabel())) {
metadataTable = table;
break;
}
}
List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), absoluteXPathQuery, true);
TreeNode pNode = schemaNode;
if (MdmConceptType.RECEIVE.equals(selected.getConceptType())) {
List<FOXTreeNode> updateNodesList = TreeUtil.parseMDMUpdateReport(shell, true);
schemaNode.getChildren().clear();
if (updateNodesList == null) {
if (prefix != null && !"".equals(prefix)) {
String[] preValues = prefix.split(XmlMapUtil.XPATH_SEPARATOR);
for (String value : preValues) {
if (!"".equals(value)) {
TreeNode createTreeNode = createModel();
createTreeNode.setName(value);
createTreeNode.setNodeType(NodeType.ELEMENT);
createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
createTreeNode.setXpath(XmlMapUtil.getXPath(pNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
pNode.getChildren().add(createTreeNode);
pNode = createTreeNode;
}
}
absoluteXPathQuery = prefix + absoluteXPathQuery;
}
} else {
//$NON-NLS-1$
TreeNode rootNode = createDefaultTreeNode(pNode, "exchange");
//$NON-NLS-1$
TreeNode reportNode = createDefaultTreeNode(rootNode, "report");
//$NON-NLS-1$
TreeNode itemNode = createDefaultTreeNode(rootNode, "item");
// parse the update content..
prepareEmfTree(updateNodesList, reportNode, true);
pNode = itemNode;
//$NON-NLS-1$
absoluteXPathQuery = "/exchange/item" + absoluteXPathQuery;
}
} else {
schemaNode.getChildren().clear();
}
prepareEmfTree(list, pNode);
} else {
List<FOXTreeNode> list = TreeUtil.getFoxTreeNodesForXmlMap(getTempTemplateXSDFile().getAbsolutePath(), selected.getRoot().get(0).getXMLPath(), true);
schemaNode.getChildren().clear();
root = selected.getRoot();
loop = selected.getLoop();
group = selected.getGroup();
groupElements = new ArrayList<TreeNode>();
prepareModelFromOutput(list, schemaNode);
if (loopNode != null) {
fillGroup(loopNode, groupElements);
} else {
if (!schemaNode.getChildren().isEmpty()) {
schemaNode.getChildren().get(0).setLoop(true);
}
}
}
}
}
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class NewDelimitedFileWizardMigrationTask method updateMetadataTable.
@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
boolean modified = false;
if (oldConnection == null || genericConnection == null || componentProperties == null) {
return modified;
}
Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
Set<MetadataTable> newTables = new HashSet<>(tables);
for (MetadataTable metaTable : newTables) {
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(componentProperties.toSerialized());
metaTable.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(SCHEMA);
metaTable.getTaggedValue().add(schemaPropertyTV);
((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
componentProperties.setValue(SCHEMA, schema);
modified = true;
}
return modified;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class NewSalesforceWizardMigrationTask method updateMetadataTable.
@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
boolean modified = false;
if (oldConnection == null || genericConnection == null || componentProperties == null) {
return modified;
}
Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
Set<MetadataTable> newTables = new HashSet<>();
newTables.addAll(tables);
for (MetadataTable metaTable : newTables) {
try {
Object object = ReflectionUtils.newInstance(REFLECTION_SALESFORCE_MODULE_PROPERTIES, componentProperties.getClass().getClassLoader(), new Object[] { metaTable.getName() });
if (object != null && object instanceof ComponentProperties) {
ComponentProperties salesforceModuleProperties = (ComponentProperties) object;
//$NON-NLS-1$
salesforceModuleProperties.getProperties("connection").copyValuesFrom(componentProperties, true, false);
//$NON-NLS-1$
NamedThing tmp = salesforceModuleProperties.getProperty("moduleName");
//$NON-NLS-1$
((Property) tmp).setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "moduleName");
((Property) tmp).setValue(metaTable.getLabel());
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(salesforceModuleProperties.toSerialized());
metaTable.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(SCHEMA_SCHEMA);
metaTable.getTaggedValue().add(schemaPropertyTV);
Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
salesforceModuleProperties.setValue(SCHEMA_SCHEMA, schema);
((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
modified = true;
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
return modified;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class GenericRepositoryContentHandler method newSchemaWizard.
@Override
public IWizard newSchemaWizard(IWorkbench workbench, boolean creation, IRepositoryViewObject object, MetadataTable metadataTable, String[] existingNames, boolean forceReadOnly) {
if (object == null) {
return null;
}
IWorkbench wb = workbench;
if (wb == null) {
wb = PlatformUI.getWorkbench();
}
MetadataTable table = metadataTable;
if (table == null && object instanceof MetadataTableRepositoryObject) {
MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
table = metaTableRepObj.getTable();
}
if (table == null) {
return null;
}
ConnectionItem connectionItem = (ConnectionItem) object.getProperty().getItem();
table = SchemaUtils.getMetadataTable(connectionItem.getConnection(), table.getLabel(), table.eContainer().getClass());
return new GenericSchemaWizard(wb, creation, object, connectionItem, table, forceReadOnly);
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class DetecteViewImpactAction method init.
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
* org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
// try to check via extension point first.
boolean canWork = UpdateManagerProviderDetector.INSTANCE.validateAction(viewer, selection);
if (canWork) {
setEnabled(true);
return;
}
canWork = !selection.isEmpty() && selection.size() == 1;
if (canWork) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (factory.isUserReadOnlyOnCurrentProject()) {
canWork = false;
} else {
Object o = selection.getFirstElement();
RepositoryNode node = (RepositoryNode) o;
ENodeType nodeType = node.getType();
switch(nodeType) {
case REPOSITORY_ELEMENT:
ERepositoryObjectType objectType = node.getObjectType();
/*
* TESB-6415 if it's "CAMEL" product, then is disable
*/
if (objectType != null) {
String[] products = objectType.getProducts();
if (products != null && products.length == 1 && "CAMEL".equals(products[0])) {
setEnabled(false);
return;
}
}
if (objectType == ERepositoryObjectType.METADATA_CON_TABLE) {
IRepositoryViewObject repositoryObject = node.getObject();
if (repositoryObject != null) {
Item item2 = repositoryObject.getProperty().getItem();
if (item2 instanceof DatabaseConnectionItem) {
DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
CDCConnection cdcConns = connection.getCdcConns();
if (cdcConns != null) {
if (repositoryObject instanceof MetadataTableRepositoryObject) {
MetadataTable table = ((MetadataTableRepositoryObject) repositoryObject).getTable();
String tableType = table.getTableType();
canWork = RepositoryConstants.TABLE.equals(tableType);
break;
}
}
}
}
canWork = true;
} else if (objectType == ERepositoryObjectType.METADATA_CON_QUERY || objectType == ERepositoryObjectType.METADATA_CONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_DELIMITED || objectType == ERepositoryObjectType.METADATA_FILE_POSITIONAL || objectType == ERepositoryObjectType.METADATA_FILE_REGEXP || objectType == ERepositoryObjectType.METADATA_FILE_XML || objectType == ERepositoryObjectType.METADATA_FILE_LDIF || objectType == ERepositoryObjectType.METADATA_FILE_EXCEL || objectType == ERepositoryObjectType.METADATA_SAPCONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_EBCDIC || objectType == ERepositoryObjectType.METADATA_FILE_HL7 || objectType == ERepositoryObjectType.METADATA_VALIDATION_RULES || objectType == ERepositoryObjectType.METADATA_FILE_FTP || objectType == ERepositoryObjectType.METADATA_FILE_BRMS || objectType == ERepositoryObjectType.METADATA_MDMCONNECTION || objectType == ERepositoryObjectType.CONTEXT || objectType == ERepositoryObjectType.JOBLET) {
canWork = true;
} else if (objectType == ERepositoryObjectType.BUSINESS_PROCESS || objectType == ERepositoryObjectType.PROCESS || objectType == ERepositoryObjectType.ROUTINES || objectType == ERepositoryObjectType.PIG_UDF || objectType == ERepositoryObjectType.JOB_SCRIPT || objectType == ERepositoryObjectType.SQLPATTERNS || objectType == ERepositoryObjectType.JOB_DOC || objectType == ERepositoryObjectType.JOBLET_DOC || objectType == ERepositoryObjectType.DOCUMENTATION || objectType == ERepositoryObjectType.PROCESS_MR || objectType == ERepositoryObjectType.METADATA_CON_COLUMN || (ERepositoryObjectType.TEST_CONTAINER != null && objectType == ERepositoryObjectType.TEST_CONTAINER)) {
canWork = false;
} else {
Object obj = selection.getFirstElement();
RepositoryNode nodeObj = (RepositoryNode) obj;
Item item = nodeObj.getObject().getProperty().getItem();
if (item instanceof ConnectionItem) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
if (service != null) {
boolean flag = service.isServiceItem(item.eClass().getClassifierID());
if (flag) {
canWork = false;
break;
}
}
}
}
for (IRepositoryContentHandler handler : RepositoryContentManager.getHandlers()) {
ERepositoryObjectType stype = handler.getRepositoryObjectType(item);
if (stype == objectType) {
canWork = true;
break;
}
}
if (RepositoryContentManager.getHandlers().size() < 0) {
canWork = false;
}
}
break;
default:
canWork = false;
}
RepositoryNode parent = node.getParent();
if (canWork && parent != null && parent.isBin()) {
canWork = false;
}
if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
canWork = false;
}
}
}
setEnabled(canWork);
}
Aggregations