use of org.talend.daikon.properties.property.Property 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.daikon.properties.property.Property in project tdi-studio-se by Talend.
the class GenericConnectionUtil method synNamePropertyWithItem.
/**
* Syncronize the value of <code>name</code> property between component properties and connection item.
*
* @param item the item which name property belong to.
* @return return true if property is updated, otherwise return false;
*/
public static boolean synNamePropertyWithItem(GenericConnectionItem item) {
GenericConnection connection = (GenericConnection) item.getConnection();
String compPropertiesStr = connection.getCompProperties();
if (compPropertiesStr == null) {
return false;
}
ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(compPropertiesStr, connection);
if (componentProperties == null) {
return false;
}
Property nameProperty = (Property) componentProperties.getProperty(IGenericConstants.NAME_PROPERTY);
if (nameProperty == null) {
return false;
}
Object namePropertyVal = nameProperty.getValue();
String newName = item.getProperty().getLabel();
if (newName != null && !newName.equals(namePropertyVal)) {
nameProperty.setValue(newName);
connection.setCompProperties(componentProperties.toSerialized());
return true;
}
return false;
}
use of org.talend.daikon.properties.property.Property 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.daikon.properties.property.Property in project components by Talend.
the class ComponentDefinitionTest method testReturnProperties.
@Test
public void testReturnProperties() {
TestComponentDefinition tcd = new TestComponentDefinition();
Property[] props = tcd.getReturnProperties();
assertEquals("return1", props[0].getName());
assertEquals(5, props.length);
// Make sure i18N works
assertEquals("Error Message", props[1].getDisplayName());
assertEquals("Number of line", props[2].getDisplayName());
assertEquals("Number of success", props[3].getDisplayName());
assertEquals("Number of reject", props[4].getDisplayName());
}
use of org.talend.daikon.properties.property.Property in project components by Talend.
the class TSplunkEventCollectorTestIT method testAfterExtendedOutput.
@Test
public void testAfterExtendedOutput() throws Throwable {
ComponentProperties props;
props = new TSplunkEventCollectorDefinition().createProperties();
ComponentTestUtils.checkSerialize(props, errorCollector);
Property<Boolean> extendedOutput = (Property<Boolean>) props.getProperty("extendedOutput");
assertEquals(true, extendedOutput.getValue());
Form advForm = props.getForm(Form.ADVANCED);
assertFalse(advForm.getWidget("eventsBatchSize").isHidden());
extendedOutput.setValue(false);
props = checkAndAfter(advForm, "extendedOutput", props);
advForm = props.getForm(Form.ADVANCED);
assertTrue(advForm.isRefreshUI());
assertTrue(advForm.getWidget("eventsBatchSize").isHidden());
}
Aggregations