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 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.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class Salesforce620WizardMigration method updateSubProperties.
/**
* DOC nrousseau Comment method "updateSubProperties".
*
* @param properties
* @param newProperties
*/
private void updateSubProperties(ComponentProperties properties, ComponentProperties newProperties) {
if (newProperties == null) {
return;
}
for (NamedThing nt : properties.getProperties()) {
if (nt instanceof Property) {
Property property = (Property) nt;
Object storedValue = property.getStoredValue();
if (storedValue instanceof String) {
String stringValue = (String) storedValue;
if (ContextParameterUtils.isContainContextParam(stringValue)) {
continue;
}
Property newProperty = (Property) newProperties.getProperty(property.getName());
if (newProperty != null) {
if (GenericTypeUtils.isBooleanType(newProperty)) {
if (stringValue.isEmpty()) {
property.setValue(Boolean.FALSE);
} else {
property.setValue(new Boolean(stringValue));
}
} else if (GenericTypeUtils.isEnumType(newProperty) && (!(newProperty instanceof EnumProperty))) {
property.setStoredValue(TalendQuoteUtils.removeQuotes(stringValue));
} else if (GenericTypeUtils.isEnumType(newProperty)) {
List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(storedValue)) {
property.setStoredValue(possibleValue);
break;
}
}
}
}
}
} else {
Property newProperty = (Property) newProperties.getProperty(property.getName());
if (GenericTypeUtils.isBooleanType(newProperty)) {
// value can only be null (so false)
property.setValue(Boolean.FALSE);
}
}
} else if (nt instanceof ComponentProperties) {
updateSubProperties((ComponentProperties) nt, (ComponentProperties) newProperties.getProperty(nt.getName()));
}
}
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class GenericConnectionUtilTest method testSynNamePropertyWithItem.
@Test
public void testSynNamePropertyWithItem() {
//$NON-NLS-1$
String namePropertyValue = "test";
//$NON-NLS-1$
TestProperties props = (TestProperties) new TestProperties("test").init();
props.name.setValue(namePropertyValue);
String serializedProps = props.toSerialized();
GenericConnectionItem testItem = createTestItem(namePropertyValue, serializedProps);
GenericConnection testConn = (GenericConnection) testItem.getConnection();
boolean itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
assertFalse(itemChanged);
ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(serializedProps, testConn);
assertEquals(namePropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
//$NON-NLS-1$
String newPropertyValue = "test1";
testItem.getProperty().setLabel(newPropertyValue);
itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
assertTrue(itemChanged);
componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(testConn.getCompProperties(), testConn);
assertEquals(newPropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class GenericDragAndDropHandlerTest method testIsGenericRepositoryValue.
@Test
public void testIsGenericRepositoryValue() {
Connection connection = mock(Connection.class);
AbstractDragAndDropServiceHandler abstractDragAndDropServiceHandler = mock(AbstractDragAndDropServiceHandler.class);
List<ComponentProperties> componentProsList = new ArrayList<>();
boolean isGenericRepositoryValue = abstractDragAndDropServiceHandler.isGenericRepositoryValue(componentProsList, //$NON-NLS-1$
"paramName1");
assertEquals(false, isGenericRepositoryValue);
connection = mock(GenericConnection.class);
GenericDragAndDropHandler genericDragAndDropHandler = mock(GenericDragAndDropHandler.class);
when(genericDragAndDropHandler.canHandle(connection)).thenReturn(true);
//$NON-NLS-1$
isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(null, "paramName2");
assertEquals(false, isGenericRepositoryValue);
// PowerMockito.mockStatic(ComponentsUtils.class);
// ComponentProperties mockComponentProperties = mock(ComponentProperties.class);
// when(ComponentsUtils.getComponentPropertiesFromSerialized(null)).thenReturn(mockComponentProperties);
// List<Property> propertyValues = new ArrayList<Property>();
// Property element = ComponentPropertyFactory.newReturnsProperty();
// propertyValues.add(element);
// when(ComponentsUtils.getAllValuedProperties(mockComponentProperties)).thenReturn(propertyValues);
// isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(connection, "QueryMode");//$NON-NLS-1$
// assertEquals(true, isGenericRepositoryValue);
}
Aggregations