use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class ComponentsUtilsTest method testGetFormalPossibleValues.
@Test
public void testGetFormalPossibleValues() {
ComponentService componentService = ComponentsUtils.getComponentService();
//$NON-NLS-1$
ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
Form form = props.getForm(Form.MAIN);
Element element = new FakeElement(form.getName());
Widget testWidget = null;
Property testProperty = null;
Collection<Widget> widgets = form.getWidgets();
Iterator<Widget> widgetsIterator = widgets.iterator();
while (widgetsIterator.hasNext()) {
Widget widget = widgetsIterator.next();
NamedThing content = widget.getContent();
if (content instanceof Property) {
testWidget = widget;
testProperty = (Property) content;
break;
}
}
assertNotNull(testWidget);
assertNotNull(testProperty);
// Test NamedThing type
List<NamedThing> namedThings = new ArrayList<>();
namedThings.add(new SimpleNamedThing("p1", "Test P1"));
namedThings.add(new SimpleNamedThing("p2", "Test P2"));
namedThings.add(new SimpleNamedThing("p3", "Test P3"));
testProperty.setPossibleValues(namedThings);
GenericElementParameter param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testProperty.getPossibleValues());
List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(3, possibleValues.size());
namedThings.retainAll(possibleValues);
assertEquals(3, namedThings.size());
// Test Integer type which is not support yet
List<Integer> ints = new ArrayList<>();
ints.add(1);
ints.add(2);
ints.add(3);
testProperty.setPossibleValues(ints);
param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testProperty.getPossibleValues());
possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(0, possibleValues.size());
// Test StringProperty
testWidget = null;
StringProperty testStringProperty = null;
widgetsIterator = widgets.iterator();
while (widgetsIterator.hasNext()) {
Widget widget = widgetsIterator.next();
NamedThing content = widget.getContent();
if (content instanceof StringProperty) {
testWidget = widget;
testStringProperty = (StringProperty) content;
break;
}
}
assertNotNull(testWidget);
assertNotNull(testStringProperty);
testStringProperty.setPossibleNamedThingValues(namedThings);
param = new GenericElementParameter(element, props, form, testWidget, componentService);
param.setPossibleValues(testStringProperty.getPossibleValues());
possibleValues = ComponentsUtils.getFormalPossibleValues(param);
assertEquals(3, possibleValues.size());
List<String> pvNames = new ArrayList<>();
for (NamedThing pv : possibleValues) {
pvNames.add(pv.getName());
}
for (NamedThing nt : namedThings) {
assertTrue(pvNames.contains(nt.getName()));
}
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class ComponentsUtilsTest method testGetParametersFromForm.
@Test
public void testGetParametersFromForm() {
//$NON-NLS-1$
ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
Form form = props.getForm(Form.MAIN);
/*
* Test wizard
*/
Element element = new FakeElement(form.getName());
// Test readonly case
List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
for (ElementParameter parameter : parameters) {
assertFalse(parameter.isReadOnly());
}
element.setReadOnly(true);
parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
for (ElementParameter parameter : parameters) {
assertTrue(parameter.isReadOnly());
}
/*
* Test component
*/
// Test parameter initialization case (mainly to test ComponentsUtils.getParameterValue() method).
checkParameterInitializationStatus(true);
checkParameterInitializationStatus(false);
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class ComponentsUtilsTest method checkParameterInitializationStatus.
private void checkParameterInitializationStatus(boolean isInitializing) {
INode node = createSFTestNode();
ComponentProperties props = node.getComponentProperties();
props.setValueEvaluator(null);
Form form = props.getForm(Form.ADVANCED);
List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(node, isInitializing, null, props, form);
checkParameterInitializationStatus(parameters, isInitializing);
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class ComponentTest method testGetCodegenPropInfosWithoutReferenceObject.
@Test
public void testGetCodegenPropInfosWithoutReferenceObject() {
//$NON-NLS-1$
ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
List<CodegenPropInfo> propInfos = component.getCodegenPropInfos(props);
for (CodegenPropInfo propInfo : propInfos) {
Properties properties = propInfo.props;
if (properties instanceof ComponentReferenceProperties) {
ComponentReferenceProperties crp = (ComponentReferenceProperties) properties;
assertEquals(Boolean.TRUE, crp.componentInstanceId.getTaggedValue(IGenericConstants.ADD_QUOTES));
assertEquals(Boolean.TRUE, crp.referenceDefinitionName.getTaggedValue(IGenericConstants.ADD_QUOTES));
//please see ComponentRefController class, the reference will be set when some ui action happen, so expect the value is null as no any ui action here
assertNull(crp.getReference());
}
}
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class RepositoryChangeMetadataCommand method execute.
@Override
public void execute() {
node.setPropertyValue(propName, newPropValue);
String mainSchemaParamName = DesignerUtilities.getMainSchemaParameterName(node);
if (mainSchemaParamName.equals(propName)) {
IElementParameter elementParameter = node.getElementParameter(propName);
if (elementParameter != null) {
IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
if (schemaTypeParam != null) {
if (newPropValue != null && !"".equals(newPropValue)) {
//$NON-NLS-1$
schemaTypeParam.setValue(EmfComponent.REPOSITORY);
} else {
schemaTypeParam.setValue(EmfComponent.BUILTIN);
}
}
}
}
if (node.isExternalNode() && !node.isELTComponent()) {
for (IElementParameter parameter : node.getElementParameters()) {
if (parameter.getFieldType() == EParameterFieldType.TABLE) {
if (!node.getMetadataList().isEmpty() && !node.getMetadataList().get(0).sameMetadataAs(newOutputMetadata)) {
parameter.setValue(new ArrayList<Map<String, Object>>());
}
}
}
}
// ELT Input/output component need add the schema conetxt in Context Mode
if (node.isELTComponent()) {
//$NON-NLS-1$
IElementParameter schemaParam = node.getElementParameter("ELT_SCHEMA_NAME");
if (schemaParam != null && schemaParam.getValue() != null && newPropValue != null && connection != null && connection.isContextMode() && ContextParameterUtils.isContainContextParam(schemaParam.getValue().toString())) {
ConnectionItem connectionItem = MetadataToolHelper.getConnectionItemFromRepository(newPropValue.toString());
ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
}
}
// IElementParameter schemaTypeParameter =
// node.getElementParameter(propName).getParentParameter().getChildParameters().get(
// EParameterName.SCHEMA_TYPE.getName());
// IElementParameter repositorySchemaTypeParameter = node.getElementParameter(propName).getParentParameter()
// .getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
// String schemaType = (String) schemaTypeParameter.getValue();
// bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
// if (schemaType != null && schemaType.equals(EmfComponent.REPOSITORY)) {
// repositorySchemaTypeParameter.setShow(true);
// if (newRepositoryIdValue != null) {
// oldRepositoryIdValue = (String) repositorySchemaTypeParameter.getValue();
// repositorySchemaTypeParameter.setValue(newRepositoryIdValue);
// }
// } else {
// repositorySchemaTypeParameter.setShow(false);
// }
// Xstream Cdc Type Mode
boolean isXstreamCdcTypeMode = false;
if (connection != null && connection instanceof DatabaseConnection) {
String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
isXstreamCdcTypeMode = true;
}
}
node.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName()).setValue(true);
String componentName = node.getComponent().getName();
if (newOutputMetadata != null) {
Map<String, String> addMap = newOutputMetadata.getAdditionalProperties();
if (addMap.get(TaggedValueHelper.SYSTEMTABLENAME) != null && componentName.equals("tAS400CDC")) {
//$NON-NLS-1$
setDBTableFieldValue(node, addMap.get(TaggedValueHelper.SYSTEMTABLENAME), oldOutputMetadata.getTableName());
} else if (isXstreamCdcTypeMode) {
IElementParameter elementParameter = node.getElementParameter(propName);
if (elementParameter != null) {
if (oracleCdcComponent[0].equals(componentName) || oracleCdcComponent[1].equals(componentName)) {
IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
if (schemaTypeParam != null) {
schemaTypeParam.setValue(EmfComponent.BUILTIN);
if (schemaParam != null && schemaParam.getValue() != null && schemaParam.getValue() instanceof IMetadataTable) {
newOutputMetadata.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
}
if (oracleCdcComponent[1].equals(componentName)) {
newOutputMetadata.setListColumns(new ArrayList<IMetadataColumn>());
}
}
}
}
setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
} else {
setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
}
//$NON-NLS-1$
IElementParameter parameter = node.getElementParameter("SAP_FUNCTION");
if (parameter != null) {
setSAPFunctionName(node, parameter.getValue() == null ? null : (String) parameter.getValue());
}
if (newPropValue instanceof String) {
if (orginalTable != null && orginalTable instanceof SAPBWTable) {
String innerIOType = ((SAPBWTable) orginalTable).getInnerIOType();
String sourceSysName = ((SAPBWTable) orginalTable).getSourceSystemName();
IElementParameter schemaTypeParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
IMetadataTable metadataTable = null;
if (schemaTypeParam != null) {
metadataTable = node.getMetadataFromConnector(schemaTypeParam.getContext());
}
if (metadataTable != null) {
if (innerIOType != null) {
//$NON-NLS-1$
IElementParameter param = node.getElementParameter("INFO_OBJECT_TYPE");
if (param != null) {
param.setValue(innerIOType);
metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE, innerIOType);
}
}
if (sourceSysName != null) {
//$NON-NLS-1$
IElementParameter param = node.getElementParameter("SOURCE_SYSTEM_NAME");
if (param != null) {
param.setValue(TalendTextUtils.addQuotes(sourceSysName));
metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_DATASOURCE_SOURCESYSNAME, sourceSysName);
}
}
}
}
}
setTableRelevantParameterValues();
if (getConnection() != null) {
// for salesforce
IElementParameter param = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (param != null && EmfComponent.REPOSITORY.equals(param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue())) {
IElementParameter module = node.getElementParameter("module.moduleName");
if (module != null) {
String repositoryValue = module.getRepositoryValue();
if (repositoryValue == null) {
List<ComponentProperties> componentProperties = null;
IGenericWizardService wizardService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
}
if (wizardService != null && wizardService.isGenericConnection(getConnection())) {
componentProperties = wizardService.getAllComponentProperties(getConnection(), null);
}
repositoryValue = String.valueOf(RepositoryToComponentProperty.getGenericRepositoryValue(getConnection(), componentProperties, module.getName()));
}
if (repositoryValue != null) {
Object objectValue = RepositoryToComponentProperty.getValue(getConnection(), repositoryValue, newOutputMetadata, node.getComponent().getName());
if (objectValue != null) {
module.setValue(objectValue);
}
}
}
}
}
}
super.setConnection(connection);
super.execute();
String propertyType = (String) node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
if (propertyType != null) {
if (propertyType.equals(EmfComponent.REPOSITORY)) {
String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
if (lastVersion == null) {
return;
}
Item item = lastVersion.getProperty().getItem();
if (item instanceof ConnectionItem) {
List<? extends IElementParameter> elementParameters = new ArrayList(node.getElementParameters());
for (IElementParameter param : elementParameters) {
if (param.getRepositoryValue() != null && !param.getRepositoryValue().equals("")) {
//$NON-NLS-1$
boolean isCustomSfConn = false;
if (item instanceof SalesforceSchemaConnectionItem) {
SalesforceSchemaConnection sfConn = (SalesforceSchemaConnection) ((SalesforceSchemaConnectionItem) item).getConnection();
isCustomSfConn = sfConn.isUseCustomModuleName();
}
if (//$NON-NLS-1$
param.getRepositoryValue().equals("TYPE") || (param.getRepositoryValue().equals("MODULENAME") && item instanceof SalesforceSchemaConnectionItem && !isCustomSfConn)) {
//$NON-NLS-1$
continue;
}
if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
//$NON-NLS-1$
List<Map<String, Object>> table = (List<Map<String, Object>>) node.getPropertyValue(param.getName());
IMetadataTable metaTable = node.getMetadataList().get(0);
RepositoryToComponentProperty.getTableXmlFileValue(((ConnectionItem) item).getConnection(), //$NON-NLS-1$
"XML_MAPPING", //$NON-NLS-1$
param, table, newOutputMetadata);
param.setRepositoryValueUsed(true);
} else {
if (connection != null && (xmlComponent[0].equals(componentName) || xmlComponent[1].equals(componentName) || xmlComponent[2].equals(componentName)) && connection instanceof XmlFileConnection && XmlUtil.isXSDFile(TalendQuoteUtils.removeQuotes(((XmlFileConnection) connection).getXmlFilePath())) && param.getRepositoryValue().equals("FILE_PATH")) {
// do nothing
} else {
Object value = RepositoryToComponentProperty.getValue(((ConnectionItem) item).getConnection(), param.getRepositoryValue(), newOutputMetadata);
if (value != null) {
param.setValue(value);
}
}
}
}
}
}
}
}
node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
}
Aggregations