use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method execute.
/**
* this function is moved from the method updateGraphicalNodes.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof Process) {
Process process = (Process) job;
Object parameter = result.getParameter();
// update property change events
if (parameter instanceof PropertyChangeEvent) {
PropertyChangeEvent evt = (PropertyChangeEvent) parameter;
updatePropertyChangeEvents(process, evt);
} else {
//
IUpdateItemType updateType = result.getUpdateType();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case JOBLET_RENAMED:
if (!(parameter instanceof List)) {
return;
}
List<Object> params = (List<Object>) parameter;
if (params.size() != 3) {
return;
}
final String oldName = (String) params.get(1);
final String newName = (String) params.get(2);
updateRenaming(process, oldName, newName);
break;
case RELOAD:
List<Node> jobletNodes = (List<Node>) result.getUpdateObject();
if (jobletNodes != null && !jobletNodes.isEmpty()) {
for (Node node : jobletNodes) {
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
if (newComponent == null) {
continue;
}
// node loaded is from loading in the check.
// need to get the instance from process, or this process will be done with wrong
// instance
// of node.
Node currentNode = getOriginalNodeFromProcess(node);
boolean neesPro = needPropagate(currentNode);
if (currentNode.isJoblet() || currentNode.isMapReduce()) {
// maybe no need modify
List<IElementParameter> tempList = new ArrayList<IElementParameter>(currentNode.getElementParameters());
if (result.isNeedReloadJoblet()) {
reloadNode(currentNode, newComponent);
}
if (currentNode.getNodeContainer() instanceof AbstractJobletContainer) {
for (IElementParameter para : tempList) {
currentNode.getElementParameter(para.getName()).setValue(para.getValue());
}
((AbstractJobletContainer) currentNode.getNodeContainer()).updateJobletNodes(true);
}
} else {
reloadNode(currentNode, newComponent);
}
propagate(currentNode, neesPro);
}
process.checkProcess();
}
break;
case JOBLET_SCHEMA:
updateSchema(process, (Node) result.getUpdateObject());
break;
default:
}
}
// else { // for extension
}
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updateRenaming.
@SuppressWarnings("unchecked")
private void updateRenaming(Process process, final String oldName, final String newName) {
if (process == null || oldName == null || newName == null) {
return;
}
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(newName, process.getComponentsType());
if (newComponent == null) {
return;
}
for (Node node : (List<Node>) process.getGraphicalNodes()) {
if (node.getComponent().getName().equals(newName) || node.getComponent().getName().equals(oldName)) {
reloadNode(node, newComponent);
}
}
process.checkProcess();
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updatePropertyChangeEvents.
@SuppressWarnings("unchecked")
private void updatePropertyChangeEvents(Process process, PropertyChangeEvent evt) {
if (process == null || evt == null) {
return;
}
String propertyName = evt.getPropertyName();
Object updateObject = result.getUpdateObject();
Set<String> jobletNodeNames = new HashSet<String>();
if (updateObject != null) {
if (!(updateObject instanceof List)) {
return;
}
for (INode jobletNode : (List<INode>) updateObject) {
jobletNodeNames.add(jobletNode.getComponent().getName());
}
}
if (propertyName.equals(IComponentConstants.NORMAL)) {
for (Node node : (List<Node>) process.getGraphicalNodes()) {
/*
* if jobletNodes==null, will reload all component. Or, olny reload the fixed node.
*/
if (updateObject != null && !jobletNodeNames.contains(node.getComponent().getName())) {
continue;
}
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
if (newComponent == null) {
continue;
}
reloadNode(node, newComponent);
}
process.checkProcess();
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updateGraphicalNodesSchema.
/**
* qzhang Comment method "updateGraphicalNodesSchema".
*
* this method is moved from class AbstractTalendEditor.
*
* @param evt
*/
@SuppressWarnings("unchecked")
private void updateGraphicalNodesSchema(Process process, PropertyChangeEvent evt) {
if (!(evt.getSource() instanceof INode)) {
return;
}
INode sourceNode = (INode) evt.getSource();
String componentName = sourceNode.getComponent().getName();
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(componentName, process.getComponentsType());
if (newComponent == null) {
return;
}
Object[] newMetadataTables = (Object[]) evt.getNewValue();
List<IMetadataTable> newInputTableList = (List<IMetadataTable>) newMetadataTables[0];
List<IMetadataTable> newOutputTableList = (List<IMetadataTable>) newMetadataTables[1];
for (Node node : (List<Node>) process.getGraphicalNodes()) {
if (node.getComponent().getName().equals(componentName)) {
List<IElementParameter> outputElemParams = new ArrayList<IElementParameter>();
IElementParameter outputElemParam = null;
List<? extends IElementParameter> elementParameters = node.getElementParameters();
for (IElementParameter elementParameter : elementParameters) {
if (EParameterFieldType.SCHEMA_TYPE.equals(elementParameter.getFieldType())) {
outputElemParams.add(elementParameter);
}
}
ChangeMetadataCommand command;
List<? extends IConnection> incomingConnections = node.getIncomingConnections();
if (incomingConnections.size() <= 1) {
for (int i = 0; i < incomingConnections.size(); i++) {
IConnection connection = incomingConnections.get(i);
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
if (newInputMetadataTable != null && !metadataTable.sameMetadataAs(newInputMetadataTable)) {
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, newInputMetadataTable);
command.execute(Boolean.FALSE);
}
}
} else {
for (IElementParameter param : node.getElementParameters()) {
if (param.isShow(node.getElementParameters()) && param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
IMetadataTable table = node.getMetadataFromConnector(param.getContext());
IElementParameter connParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
if (table != null && connParam != null && !StringUtils.isEmpty((String) connParam.getValue())) {
for (IConnection connection : incomingConnections) {
if (connection.isActivate() && connection.getName().equals(connParam.getValue())) {
if (!table.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_KEY | IMetadataColumn.OPTIONS_IGNORE_NULLABLE | IMetadataColumn.OPTIONS_IGNORE_COMMENT | IMetadataColumn.OPTIONS_IGNORE_PATTERN | IMetadataColumn.OPTIONS_IGNORE_DBCOLUMNNAME | IMetadataColumn.OPTIONS_IGNORE_DBTYPE | IMetadataColumn.OPTIONS_IGNORE_DEFAULT | IMetadataColumn.OPTIONS_IGNORE_BIGGER_SIZE)) {
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, table);
command.execute(Boolean.FALSE);
}
}
}
}
}
}
}
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
for (int i = 0; i < outgoingConnections.size(); i++) {
IConnection connection = outgoingConnections.get(i);
Node target = (Node) connection.getTarget();
IMetadataTable metadataTable = connection.getMetadataTable();
if (metadataTable != null) {
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
if (newOutputMetadataTable != null && !metadataTable.sameMetadataAs(newOutputMetadataTable)) {
IElementParameter elementParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(target, elementParam, target.getMetadataFromConnector(metadataTable.getAttachedConnector()), newOutputMetadataTable);
command.execute(Boolean.FALSE);
}
}
}
List<IMetadataTable> metadataList = node.getMetadataList();
for (IMetadataTable metadataTable : metadataList) {
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
outputElemParam = UpdateManagerUtils.getElemParam(outputElemParams, metadataTable.getAttachedConnector());
if (outputElemParam != null && newInputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newInputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newInputMetadataTable, metadataFromConnector);
} else if (outputElemParam != null && newOutputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newOutputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newOutputMetadataTable, metadataFromConnector);
}
}
}
}
}
use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.
the class ValidationRulesUtil method getComponentsFromItemId.
/**
* DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
* TalendEditorDropTargetListener.
*
* @param itemId
* @param type
* @param quickCreateInput
* @param quickCreateOutput
* @return
*/
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject obj = null;
try {
obj = factory.getLastVersion(itemId);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (obj == null) {
return null;
}
Item item = obj.getProperty().getItem();
if (item == null) {
return null;
}
EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
String componentName = null;
if (item instanceof JobletProcessItem) {
// joblet
componentName = item.getProperty().getLabel();
} else if (name == null) {
return null;
} else {
// tRunjob
componentName = name.getDefaultComponentName();
}
// tRunJob is special from our rules
if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
} else {
// for database, file, webservices, saleforce ...
List<IComponent> neededComponents = filterNeededComponents(item, type);
IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
return component;
}
}
Aggregations