use of org.talend.components.api.component.ConnectorTopology in project tdi-studio-se by Talend.
the class Component method getModulesNeeded.
@Override
public List<ModuleNeeded> getModulesNeeded(INode node) {
List<ModuleNeeded> componentImportNeedsList = new ArrayList<>();
ConnectorTopology topology = null;
if (node != null) {
boolean hasInput = !NodeUtil.getIncomingConnections(node, IConnectionCategory.DATA).isEmpty();
boolean hasOutput = !NodeUtil.getOutgoingConnections(node, IConnectionCategory.DATA).isEmpty();
if (hasInput && hasOutput) {
topology = ConnectorTopology.INCOMING_AND_OUTGOING;
} else if (hasInput) {
topology = ConnectorTopology.INCOMING;
} else if (hasOutput) {
topology = ConnectorTopology.OUTGOING;
} else {
topology = ConnectorTopology.NONE;
}
} else {
Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
if (!topologies.isEmpty()) {
topology = topologies.iterator().next();
}
}
RuntimeInfo runtimeInfo = null;
try {
runtimeInfo = componentDefinition.getRuntimeInfo(ExecutionEngine.DI, node == null ? null : node.getComponentProperties(), topology);
} catch (Exception e) {
if (node == null) {
// not handled, must because the runtime info must have a node configuration (properties are null)
} else {
ExceptionHandler.process(e);
}
}
if (runtimeInfo != null) {
if (runtimeInfo instanceof JarRuntimeInfo) {
JarRuntimeInfo currentRuntimeInfo = (JarRuntimeInfo) runtimeInfo;
JarRuntimeInfo localRuntimeInfo = new JarRuntimeInfo(//$NON-NLS-1$
currentRuntimeInfo.getJarUrl().toString().replace(//$NON-NLS-1$
"mvn:", //$NON-NLS-1$ //$NON-NLS-2$
"mvn:" + MavenConstants.LOCAL_RESOLUTION_URL + "!"), currentRuntimeInfo.getDepTxtPath(), currentRuntimeInfo.getRuntimeClassName());
runtimeInfo = localRuntimeInfo;
}
final Bundle bundle = FrameworkUtil.getBundle(componentDefinition.getClass());
for (URL mvnUri : runtimeInfo.getMavenUrlDependencies()) {
//$NON-NLS-1$
ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, mvnUri.toString());
componentImportNeedsList.add(moduleNeeded);
if (bundle != null) {
// update module location
try {
final MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(moduleNeeded.getMavenUri());
final String moduleFileName = artifact.getFileName();
final File bundleFile = BundleFileUtil.getBundleFile(bundle, moduleFileName);
if (bundleFile != null && bundleFile.exists()) {
// FIXME, better install the embed jars from bundle directly in this way.
moduleNeeded.setModuleLocaion(ExtensionModuleManager.URIPATH_PREFIX + bundle.getSymbolicName() + '/' + moduleFileName);
}
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
}
}
ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/slf4j-log4j12-1.7.2/6.0.0");
componentImportNeedsList.add(moduleNeeded);
moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/talend-codegen-utils/0.17.0-SNAPSHOT");
componentImportNeedsList.add(moduleNeeded);
return componentImportNeedsList;
}
use of org.talend.components.api.component.ConnectorTopology in project tdi-studio-se by Talend.
the class Component method createConnectors.
@Override
public List<INodeConnector> createConnectors(INode parentNode) {
List<INodeConnector> listConnector = new ArrayList<>();
ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false);
if (inputConnectors.isEmpty()) {
INodeConnector connector = null;
connector = addStandardType(listConnector, EConnectionType.FLOW_MAIN, parentNode);
connector.setMaxLinkInput(0);
connector.setMaxLinkOutput(0);
} else {
for (Connector connector : inputConnectors) {
addGenericType(listConnector, EConnectionType.FLOW_MAIN, connector.getName(), parentNode, componentProperties, false);
}
}
Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true);
List<? extends Connector> sortedOutputConnectors = new ArrayList<>(outputConnectors);
sortedOutputConnectors.sort(new Comparator<Connector>() {
@Override
public int compare(Connector o1, Connector o2) {
if (Connector.MAIN_NAME.equals(o1.getName())) {
return -1;
}
if (Connector.MAIN_NAME.equals(o2.getName())) {
return 1;
}
return 0;
}
});
for (Connector connector : sortedOutputConnectors) {
EConnectionType type = EConnectionType.FLOW_MAIN;
if (Connector.REJECT_NAME.equals(connector.getName())) {
type = EConnectionType.REJECT;
}
addGenericType(listConnector, type, connector.getName(), parentNode, componentProperties, true);
}
addStandardType(listConnector, EConnectionType.RUN_IF, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_COMPONENT_ERROR, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_OK, parentNode);
addStandardType(listConnector, EConnectionType.ON_SUBJOB_ERROR, parentNode);
Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
createIterateConnectors(topologies, listConnector, parentNode);
for (int i = 0; i < EConnectionType.values().length; i++) {
EConnectionType currentType = EConnectionType.values()[i];
if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
continue;
}
boolean exists = false;
for (INodeConnector curNodeConn : listConnector) {
if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
exists = true;
if (currentType == EConnectionType.FLOW_MAIN) {
curNodeConn.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
curNodeConn.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
}
}
}
if (!exists) {
// will add by default all connectors not defined in
NodeConnector nodeConnector = new NodeConnector(parentNode);
nodeConnector.setDefaultConnectionType(currentType);
nodeConnector.setName(currentType.getName());
nodeConnector.setBaseSchema(currentType.getName());
nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
nodeConnector.setLinkName(currentType.getDefaultLinkName());
nodeConnector.setMenuName(currentType.getDefaultMenuName());
if ((currentType == EConnectionType.PARALLELIZE) || (currentType == EConnectionType.SYNCHRONIZE)) {
nodeConnector.setMaxLinkInput(1);
} else {
nodeConnector.setMaxLinkInput(0);
}
nodeConnector.setMaxLinkOutput(0);
nodeConnector.setMinLinkInput(0);
nodeConnector.setMinLinkOutput(0);
listConnector.add(nodeConnector);
}
}
return listConnector;
}
use of org.talend.components.api.component.ConnectorTopology in project components by Talend.
the class ConnectorTypologyTest method shouldMapAllTypologies.
@Test
public void shouldMapAllTypologies() throws Exception {
// given
final ConnectorTopology[] topologies = ConnectorTopology.values();
// when
for (ConnectorTopology expected : topologies) {
// then
final ConnectorTypology dto = ConnectorTypology.from(expected);
assertNotNull(dto);
assertEquals(expected, dto.getTopology());
}
}
Aggregations