use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class GenericUIBuilder method createWidgetUIByPropertyType.
private void createWidgetUIByPropertyType(Composite parent, Widget widget) {
NamedThing property = getProperty(widget);
if (property == null) {
return;
}
int hSpan = widget.getOrder();
if (property instanceof PresentationItem) {
PresentationItem item = (PresentationItem) property;
createLabel(parent, item.getDisplayName(), hSpan);
return;
} else if (property instanceof Property) {
Property element = (Property) property;
String displayName = element.getDisplayName();
String type = element.getType();
if (type == null) {
createLabel(parent, displayName, hSpan);
return;
}
if (GenericTypeUtils.isStringType(type)) {
new LabelledText(parent, displayName, hSpan);
} else if (GenericTypeUtils.isBooleanType(type)) {
// nothing
} else {
new LabelledText(parent, element.getDisplayName(), hSpan);
}
}
}
use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class Salesforce620Migration 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 if (nt instanceof ComponentProperties) {
updateSubProperties((ComponentProperties) nt, (ComponentProperties) newProperties.getProperty(nt.getName()));
}
}
}
use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class NewSalesforceWizardMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
ComponentService service = ComponentsUtils.getComponentService();
Properties props = getPropertiesFromFile();
if (item instanceof ConnectionItem) {
boolean modify = false;
GenericConnectionItem genericConnectionItem = null;
ConnectionItem connectionItem = (ConnectionItem) item;
Connection connection = connectionItem.getConnection();
// Init
genericConnectionItem = initGenericConnectionItem(connectionItem);
genericConnectionItem.setTypeName(TYPE_NAME);
GenericConnection genericConnection = initGenericConnection(connection);
initProperty(connectionItem, genericConnectionItem);
ComponentWizard componentWizard = service.getComponentWizard(TYPE_NAME, genericConnectionItem.getProperty().getId());
ComponentProperties componentProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
componentProperties.init();
// Update
modify = updateComponentProperties(connection, componentProperties, props);
//$NON-NLS-1$
NamedThing nt = componentProperties.getProperty("loginType");
if (nt instanceof Property) {
Property property = (Property) nt;
if ("OAuth2".equals(property.getStoredValue())) {
//$NON-NLS-1$
List<?> propertyPossibleValues = property.getPossibleValues();
Object newValue = null;
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals("OAuth")) {
//$NON-NLS-1$
newValue = possibleValue;
break;
}
}
}
if (newValue == null) {
// set default value
newValue = propertyPossibleValues.get(0);
}
property.setValue(newValue);
Property<?> endpoint = componentProperties.getValuedProperty("endpoint");
SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) connection;
//$NON-NLS-1$
componentProperties.setValue("endpoint", sfConnection.getWebServiceUrlTextForOAuth());
}
if (GenericTypeUtils.isEnumType(property)) {
List<?> propertyPossibleValues = ((Property<?>) property).getPossibleValues();
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(property.getStoredValue())) {
property.setStoredValue(possibleValue);
break;
}
}
}
}
}
// set empty value instead of default null value, this will add automatically the double quotes in the job
// when drag&drop metadata
//$NON-NLS-1$ //$NON-NLS-2$
componentProperties.setValue("userPassword.securityKey", "");
//$NON-NLS-1$
Property property = componentProperties.getValuedProperty("userPassword.securityKey");
//$NON-NLS-1$
property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "securityKey");
genericConnection.setCompProperties(componentProperties.toSerialized());
genericConnectionItem.setConnection(genericConnection);
updateMetadataTable(connection, genericConnection, componentProperties);
if (modify) {
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject object = factory.getLastVersion(item.getProperty().getId(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA.getFolder(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
if (object != null) {
factory.deleteObjectPhysical(object);
}
if (genericConnectionItem != null && connectionItem != null) {
factory.create(genericConnectionItem, new Path(connectionItem.getState().getPath()), true);
}
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class NewGenericWizardMigrationTask method updateComponentProperties.
protected boolean updateComponentProperties(Connection oldConnection, ComponentProperties componentProperties, Properties props) {
boolean modified = false;
if (props != null) {
for (Object element : props.keySet()) {
boolean changed = false;
String propsKey = (String) element;
String propsValue = props.getProperty(propsKey);
if (propsValue != null && !"".equals(propsValue.trim())) {
//$NON-NLS-1$
Object value = getValueFromOldConnection(oldConnection, propsValue);
if (value != null) {
NamedThing namedThing = componentProperties.getProperty(propsKey);
if (namedThing != null && namedThing instanceof org.talend.daikon.properties.property.Property) {
org.talend.daikon.properties.property.Property<?> property = (org.talend.daikon.properties.property.Property<?>) namedThing;
if (GenericTypeUtils.isEnumType(property)) {
//$NON-NLS-1$
Object obj = props.get(propsKey + "." + value);
if (obj != null) {
List<?> propertyPossibleValues = property.getPossibleValues();
Object newValue = null;
if (propertyPossibleValues != null) {
for (Object possibleValue : propertyPossibleValues) {
if (possibleValue.toString().equals(obj)) {
newValue = possibleValue;
break;
}
}
}
if (newValue == null) {
// set default value
newValue = propertyPossibleValues.get(0);
}
componentProperties.setValue(propsKey, newValue);
property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
changed = true;
}
}
if (GenericTypeUtils.isBooleanType(property)) {
if (value != null && value instanceof String) {
try {
value = new Boolean((String) value);
} catch (Exception e) {
value = Boolean.FALSE;
}
}
}
if (GenericTypeUtils.isIntegerType(property) && !oldConnection.isContextMode()) {
if (value != null && value instanceof String) {
try {
value = new Integer((String) value);
} catch (Exception e) {
value = 0;
}
}
}
if (property.isFlag(org.talend.daikon.properties.property.Property.Flags.ENCRYPT) && !oldConnection.isContextMode()) {
componentProperties.setValue(propsKey, CryptoHelper.getDefault().decrypt(String.valueOf(value)));
property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
modified = true;
changed = true;
}
if (!changed) {
property.setStoredValue(value);
property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
modified = true;
}
}
}
}
}
}
return modified;
}
use of org.talend.daikon.NamedThing in project tdi-studio-se by Talend.
the class WidgetFieldTypeMappingReaderTest method testGetFieldType.
@Test
public void testGetFieldType() {
//$NON-NLS-1$//$NON-NLS-2$
NamedThing nameAndLabel = new SimpleNamedThing("testName", "testLabel");
//$NON-NLS-1$
Assert.assertEquals("testName", nameAndLabel.getName());
//$NON-NLS-1$
Assert.assertEquals("testLabel", nameAndLabel.getDisplayName());
Assert.assertNull(nameAndLabel.getTitle());
WidgetFieldTypeMappingReader mappingReader = WidgetFieldTypeMappingReader.getInstance();
//$NON-NLS-1$//$NON-NLS-2$
String fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, "java.lang.String");
//$NON-NLS-1$
Assert.assertEquals("TEXT", fieldType);
//$NON-NLS-1$
fieldType = mappingReader.getFieldType("widget.type.default", nameAndLabel, null);
//$NON-NLS-1$
Assert.assertEquals("LABEL", fieldType);
//$NON-NLS-1$//$NON-NLS-2$
fieldType = mappingReader.getFieldType("widget.type.hidden.text", nameAndLabel, "widget.type.hidden.text");
//$NON-NLS-1$
Assert.assertEquals("HIDDEN_TEXT", fieldType);
}
Aggregations