use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class GenericUpdateManager method updateSingleSchema.
public static boolean updateSingleSchema(ConnectionItem connItem, final MetadataTable newTable, final IMetadataTable oldMetadataTable, Map<String, String> oldTableMap) {
if (connItem == null) {
return false;
}
Map<String, String> schemaRenamedMap = getSchemaRenamedMap(connItem, oldTableMap);
boolean update = !schemaRenamedMap.isEmpty();
if (!update) {
if (newTable != null && oldMetadataTable != null && oldTableMap.containsKey(newTable.getId())) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMetadataManagmentService.class)) {
IMetadataManagmentService service = (IMetadataManagmentService) GlobalServiceRegister.getDefault().getService(IMetadataManagmentService.class);
IMetadataTable newMetadataTable = service.convertMetadataTable(newTable);
update = !oldMetadataTable.sameMetadataAs(newMetadataTable, IMetadataColumn.OPTIONS_NONE);
isAddColumn = isAddColumn(newMetadataTable, oldMetadataTable);
}
}
}
if (update) {
return updateSchema(newTable, connItem, schemaRenamedMap, true, false);
}
return false;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class GenericUpdateManager method getConversionMetadataTables.
public static List<IMetadataTable> getConversionMetadataTables(Connection conn) {
if (conn == null) {
return Collections.emptyList();
}
List<IMetadataTable> tables = new ArrayList<>();
List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(conn, SubContainer.class);
for (MetadataTable metadataTable : metadataTables) {
tables.add(ConvertionHelper.convert(metadataTable));
}
return tables;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class SchemaUtils method createSchema.
public static MetadataTable createSchema(String name, ComponentProperties properties, String schemaPropertyName) {
if (name == null || properties == null || schemaPropertyName == null) {
return null;
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
metadataTable.setId(factory.getNextId());
metadataTable.setName(name);
metadataTable.setLabel(name);
metadataTable.setSourceName(name);
Object schemaObj = ComponentsUtils.getGenericPropertyValue(properties, schemaPropertyName);
if (schemaObj instanceof String) {
Schema avroSchema = new Schema.Parser().parse((String) schemaObj);
convertComponentSchemaIntoTalendSchema(avroSchema, metadataTable);
} else if (schemaObj instanceof Schema) {
convertComponentSchemaIntoTalendSchema((Schema) schemaObj, metadataTable);
}
IMetadataTable iMetadataTable = MetadataToolHelper.convert(metadataTable);
updateComponentSchema(properties, schemaPropertyName, iMetadataTable);
metadataTable = ConvertionHelper.convert(iMetadataTable);
properties.setValue(schemaPropertyName, convertTalendSchemaIntoComponentSchema(metadataTable));
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(properties.toSerialized());
metadataTable.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(schemaPropertyName);
metadataTable.getTaggedValue().add(schemaPropertyTV);
return metadataTable;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateAction method canPerformAction.
/**
* Test if the selected item is a node.
*
* @return true/false
*/
@SuppressWarnings("unchecked")
private boolean canPerformAction() {
if (getSelectedObjects().isEmpty()) {
return false;
}
List parts = getSelectedObjects();
if (parts.size() == 1) {
Object o = parts.get(0);
if (!(o instanceof NodePart)) {
return false;
}
nodePart = (NodePart) o;
if (!(nodePart.getModel() instanceof Node)) {
return false;
}
Node node = (Node) nodePart.getModel();
if (!node.isActivate()) {
return false;
}
if (node.getJobletNode() != null) {
return false;
}
if (curNodeConnector != null && "VALIDATION_REJECT".equals(curNodeConnector.getName())) {
if (node.getProcess() != null && !ComponentCategory.CATEGORY_4_DI.getName().equals(node.getProcess().getComponentsType())) {
return false;
}
}
if (connecType.hasConnectionCategory(IConnectionCategory.EXECUTION_ORDER)) {
if (!(Boolean) node.getPropertyValue(EParameterName.STARTABLE.getName()) || (!node.getProcessStartNode(false).equals(node))) {
if (!node.isELTMapComponent()) {
boolean jobletOk = false;
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && service.isJobletComponent(node)) {
jobletOk = true;
}
}
if (!jobletOk) {
return false;
}
}
}
}
menuList = new ArrayList<String>();
if (curNodeConnector == null) {
curNodeConnector = node.getConnectorFromType(connecType);
if (curNodeConnector == null) {
return false;
}
}
if (curNodeConnector.getMaxLinkOutput() != -1) {
if (curNodeConnector.getCurLinkNbOutput() >= curNodeConnector.getMaxLinkOutput()) {
return false;
}
}
if (curNodeConnector.getMaxLinkOutput() == 0) {
return false;
}
/**
* judge whether to show the table link menu in ELTMap components
*/
if (curNodeConnector.getName().equals(EConnectionType.TABLE.getName())) {
List<? extends IConnection> tableRefs = node.getOutgoingConnections(EConnectionType.TABLE_REF);
if (tableRefs != null && 0 < tableRefs.size()) {
return false;
}
}
if (!curNodeConnector.isMultiSchema()) {
// setText(curNodeConnector.getMenuName());
}
if (curNodeConnector.isMultiSchema()) {
for (int i = 0; i < node.getMetadataList().size(); i++) {
IMetadataTable table = (node.getMetadataList().get(i));
String value = table.getAdditionalProperties().get(ISINPUT);
if (value != null && value.equals(TRUE)) {
continue;
}
String name = table.getTableName();
if (name.equals(node.getUniqueName())) {
continue;
}
if (table.getAttachedConnector() == null || table.getAttachedConnector().equals(curNodeConnector.getName())) {
if (connecType == EConnectionType.TABLE) {
//$NON-NLS-1$ //$NON-NLS-2$
name = table.getLabel() + " (" + name + ")";
}
boolean nameUsed = false;
for (Connection connec : (List<Connection>) node.getOutgoingConnections()) {
if (connec.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
if (connec.getMetadataTable().getTableName().equals(table.getTableName())) {
nameUsed = true;
}
}
}
// if the name is not already in the process adds to the list
if (!nameUsed) {
menuList.add(name);
}
}
}
if ((curNodeConnector.getMaxLinkOutput() == -1 || node.getMetadataList().size() < curNodeConnector.getMaxLinkOutput()) && curNodeConnector.isBuiltIn()) {
menuList.add(getNewOutputMenuName());
}
} else {
String menuName;
boolean addDefaultName = false;
// get linked metadata to connector
IMetadataTable table = null;
for (int i = 0; i < node.getMetadataList().size(); i++) {
table = (node.getMetadataList().get(i));
if (table.getTableName().equals(node.getUniqueName())) {
break;
}
}
// if EBCDIC + single schema mode, only have one output maximum
if (node.getComponent().getName().contains("EBCDIC") && node.checkSchemaForEBCDIC(table) && curNodeConnector.getCurLinkNbOutput() > 0) {
return false;
}
if (connecType == EConnectionType.TABLE) {
addDefaultName = addDefaultName();
menuName = getNewOutputMenuName();
} else {
menuName = curNodeConnector.getMenuName();
}
if (!addDefaultName) {
setText(menuName);
menuList.add(menuName);
}
}
return true;
}
return false;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateAction method getDefaultTableName.
/**
* DOC qzhang Comment method "getDefaultTableName".
*
* @param node
* @param removeQuotes
* @return
*/
private String getDefaultTableName() {
Node node = (Node) nodePart.getModel();
StringBuffer removeQuotes = new StringBuffer();
//$NON-NLS-1$
IElementParameter elementParam = node.getElementParameter("ELT_TABLE_NAME");
//$NON-NLS-1$
IElementParameter schemaParam = node.getElementParameter("ELT_SCHEMA_NAME");
if (node.isELTComponent() && elementParam != null && elementParam.getFieldType().equals(EParameterFieldType.TEXT)) {
String name2 = elementParam.getValue().toString();
if (schemaParam != null) {
String schema = schemaParam.getValue().toString();
if (schema != null) {
schema = TalendTextUtils.removeQuotes(schema);
if (!"".equals(schema)) {
//$NON-NLS-1$
removeQuotes.append(schema);
//$NON-NLS-1$
removeQuotes.append(".");
}
}
}
if (name2 != null) {
name2 = TalendTextUtils.removeQuotes(name2);
List<IMetadataTable> metaList = node.getMetadataList();
if (metaList != null) {
for (IMetadataTable metadataTable : metaList) {
if (metadataTable != null) {
String tName = metadataTable.getTableName();
tName = TalendTextUtils.removeQuotes(tName);
if (tName.equals(name2)) {
String tableLable = metadataTable.getLabel();
if (tableLable != null) {
tableLable = TalendTextUtils.removeQuotes(tableLable);
if (!"".equals(tableLable)) {
name2 = tableLable;
}
}
}
}
}
}
String temp = name2.replaceAll(" ", "");
if ("".equals(temp)) {
name2 = temp;
}
if (!"".equals(name2)) {
//$NON-NLS-1$
removeQuotes.append(name2);
removeQuotes.append(" (");
removeQuotes.append(curNodeConnector.getMenuName());
removeQuotes.append(")");
// removeQuotes = name2 + " (" + curNodeConnector.getMenuName() + ")"; //$NON-NLS-1$ // //$NON-NLS-2$
}
}
// if (removeQuotes != null && node.isELTComponent() && node.getComponent().getName().equals("tELTOracleInput")) { //$NON-NLS-1$
// if (getDefaultSchemaName() != null) {
// String temp = removeQuotes.toString();
// removeQuotes.append(getDefaultSchemaName());
// removeQuotes.append(".");
// removeQuotes.append(temp);
// // removeQuotes = getDefaultSchemaName() + "." + removeQuotes; //$NON-NLS-1$
// }
// }
}
return removeQuotes.toString();
}
Aggregations