use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class UpdateJobletContextInJobMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
List<ContextType> contexts = processItem.getProcess().getContext();
if (contexts.size() > 1) {
boolean isModified = false;
for (ContextType context1 : contexts) {
List<ContextParameterType> params1 = context1.getContextParameter();
for (ContextParameterType param1 : params1) {
String id = param1.getRepositoryContextId();
if (id != null) {
for (ContextType context2 : contexts) {
if (context2 != context1) {
List<ContextParameterType> params2 = context2.getContextParameter();
for (ContextParameterType param2 : params2) {
if (param2.getName().equals(param1.getName()) && param2.getRepositoryContextId() == null) {
param2.setRepositoryContextId(id);
isModified = true;
break;
}
}
}
}
}
}
}
if (isModified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class UnifyPasswordEncryption4ContextMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ContextItem) {
List<ContextType> contextTypeList = ((ContextItem) item).getContext();
boolean modify = false;
if (contextTypeList != null) {
for (ContextType type : contextTypeList) {
List<ContextParameterType> paramTypes = type.getContextParameter();
if (paramTypes != null) {
for (ContextParameterType param : paramTypes) {
try {
String value = param.getValue();
if (value != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
String rawPassword = PasswordEncryptUtil.decryptPassword(value);
param.setRawValue(rawPassword);
modify = true;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
}
}
if (modify) {
try {
factory.save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileStep2Form method initialize.
/**
*
* Initialize value, forceFocus first field.
*/
@Override
protected void initialize() {
availableJSONTreeViewer = new TreeViewer(availableJSONTree);
currentReadbyMode = this.wizard.getReadbyMode();
initTreePopulator();
checkFieldsValue();
if (jsonXPathLoopDescriptor == null) {
if (getConnection().getSchema() != null && !getConnection().getSchema().isEmpty()) {
jsonXPathLoopDescriptor = getConnection().getSchema().get(0);
jsonFilePath = getConnection().getJSONFilePath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
jsonFilePath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, jsonFilePath));
}
} else {
jsonXPathLoopDescriptor = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
getConnection().getSchema().add(jsonXPathLoopDescriptor);
// jsonXPathLoopDescriptor.setConnection(getConnection());
}
}
loopModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor);
if (jsonXPathLoopDescriptor.getLimitBoucle() == null) {
jsonXPathLoopDescriptor.setLimitBoucle(-1);
XmlArray.setLimitToDefault();
jsonXPathLoopDescriptor.setLimitBoucle(XmlArray.getRowLimit());
}
treePopulator.populateTree(wizard.getTempJsonPath(), treeNode);
fieldsModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor.getSchemaTargets());
fieldsTableEditorView.getTableViewerCreator().layout();
if (isContextMode()) {
adaptFormToEditable();
}
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileStep3Form method refreshMetaDataTable.
/**
* DOC ocarbone Comment method "refreshMetaData".
*
* @param csvArray
*/
public void refreshMetaDataTable(final CsvArray csvArray, List<SchemaTarget> schemaTarget, Boolean flag) {
informationLabel.setText(" " + "Guess successful");
List mcolumns = new ArrayList();
mcolumns.addAll(tableEditorView.getMetadataEditor().getMetadataColumnList());
// clear all items
tableEditorView.getMetadataEditor().removeAll();
List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
}
if (csvArray == null || csvArray.getRows().isEmpty()) {
return;
} else {
List<String[]> csvRows = csvArray.getRows();
String[] fields = csvRows.get(0);
int numberOfCol = fields.length;
// define the label to the metadata width the content of the first row
int firstRowToExtractMetadata = 0;
// the first rows is used to define the label of any metadata
String[] label = new String[numberOfCol];
for (int i = 0; i < numberOfCol; i++) {
label[i] = DEFAULT_LABEL + i;
if (firstRowToExtractMetadata == 0) {
if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
label[i] = MetadataToolHelper.validateColumnName(label[i], i);
}
}
// if (firstRowToExtractMetadata == 1) {
// String value = fields.get(i).getValue();
// if (!value.equals("")) {
// label[i] = value;
// }
// }
}
for (int i = 0; i < numberOfCol; i++) {
// define the first currentType and assimile it to globalType
String globalType = null;
int lengthValue = 0;
int precisionValue = 0;
int current = firstRowToExtractMetadata;
while (globalType == null) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "id_String";
} else {
globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "id_String"; //$NON-NLS-1$
// }
}
} else {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "String";
} else {
globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "String"; //$NON-NLS-1$
// }
}
}
}
// for another lines
for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
fields = csvRows.get(f);
if (fields.length > i) {
String value = fields[i];
if (!value.equals("")) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
}
} else {
if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
}
}
if (lengthValue < value.length()) {
lengthValue = value.length();
}
int positionDecimal = 0;
if (value.indexOf(',') > -1) {
positionDecimal = value.lastIndexOf(',');
precisionValue = lengthValue - positionDecimal;
} else if (value.indexOf('.') > -1) {
positionDecimal = value.lastIndexOf('.');
precisionValue = lengthValue - positionDecimal;
}
} else {
IPreferenceStore preferenceStore = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
preferenceStore = designerCoreUiService.getPreferenceStore();
}
if (preferenceStore != null && preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
//$NON-NLS-1$
globalType = preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
if (preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
//$NON-NLS-1$
lengthValue = Integer.parseInt(preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
}
}
}
}
}
// define the metadataColumn to field i
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
// hshen bug7249
//$NON-NLS-1$
metadataColumn.setPattern("\"dd-MM-yyyy\"");
// Convert javaType to TalendType
String talendType = null;
talendType = globalType;
if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
metadataColumn.setPrecision(precisionValue);
} else {
metadataColumn.setPrecision(0);
}
metadataColumn.setTalendType(talendType);
metadataColumn.setLength(lengthValue);
// Check the label and add it to the table
metadataColumn.setLabel(tableEditorView.getMetadataEditor().getNextGeneratedColumnName(label[i]));
columns.add(i, metadataColumn);
}
}
if (!flag) {
for (int i = 0; i < columns.size(); i++) {
for (int j = 0; j < mcolumns.size(); j++) {
if (columns.get(i).getLabel().equals(((MetadataColumn) mcolumns.get(j)).getLabel())) {
columns.remove(i);
columns.add(i, (MetadataColumn) mcolumns.get(j));
}
}
}
}
tableEditorView.getMetadataEditor().addAll(columns);
checkFieldsValue();
tableEditorView.getTableViewerCreator().layout();
tableEditorView.getTableViewerCreator().getTable().deselectAll();
informationLabel.setText("Click to update schema preview");
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONWizard method resetMetadata.
private void resetMetadata(List<SchemaTarget> schemaTarget, boolean flag) {
// TODO
JSONFileConnection connection2 = JSONConnectionContextUtils.getJSONOriginalValueConnection(connection, this.connectionItem, connection.isContextMode(), true);
ProcessDescription processDescription = JSONShadowProcessHelper.getProcessDescription(connection2, getTempJsonPath());
CsvArray csvArray = null;
try {
if (EJsonReadbyMode.JSONPATH.getValue().equals(getReadbyMode())) {
//$NON-NLS-1$
csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_JSON");
} else {
//$NON-NLS-1$
csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_XML");
}
} catch (CoreException e) {
ExceptionHandler.process(e);
}
List<MetadataColumn> newColumns = new ArrayList<MetadataColumn>();
String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
}
if (file != null) {
// prepareColumnsFromXSD(file, newColumns, schemaTarget);
return;
}
if (csvArray == null || csvArray.getRows().isEmpty()) {
return;
} else {
List<String[]> csvRows = csvArray.getRows();
String[] fields = csvRows.get(0);
int numberOfCol = fields.length;
// define the label to the metadata width the content of the first row
int firstRowToExtractMetadata = 0;
// the first rows is used to define the label of any metadata
String[] label = new String[numberOfCol];
for (int i = 0; i < numberOfCol; i++) {
label[i] = DEFAULT_LABEL + i;
if (firstRowToExtractMetadata == 0) {
if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
label[i] = MetadataToolHelper.validateColumnName(label[i], i);
}
}
}
for (int i = 0; i < numberOfCol; i++) {
// define the first currentType and assimile it to globalType
String globalType = null;
int lengthValue = 0;
int precisionValue = 0;
int current = firstRowToExtractMetadata;
while (globalType == null) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "id_String";
} else {
globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "id_String"; //$NON-NLS-1$
// }
}
} else {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "String";
} else {
globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "String"; //$NON-NLS-1$
// }
}
}
}
// for another lines
for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
fields = csvRows.get(f);
if (fields.length > i) {
String value = fields[i];
if (!value.equals("")) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
}
} else {
if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
}
}
if (lengthValue < value.length()) {
lengthValue = value.length();
}
int positionDecimal = 0;
if (value.indexOf(',') > -1) {
positionDecimal = value.lastIndexOf(',');
precisionValue = lengthValue - positionDecimal;
} else if (value.indexOf('.') > -1) {
positionDecimal = value.lastIndexOf('.');
precisionValue = lengthValue - positionDecimal;
}
} else {
IPreferenceStore corePreferenceStore = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
corePreferenceStore = designerCoreUiService.getPreferenceStore();
}
if (corePreferenceStore != null && corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
//$NON-NLS-1$
globalType = corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
if (corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
//$NON-NLS-1$
lengthValue = Integer.parseInt(corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
}
}
}
}
}
// define the metadataColumn to field i
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
// hshen bug7249
//$NON-NLS-1$
metadataColumn.setPattern("\"dd-MM-yyyy\"");
// Convert javaType to TalendType
String talendType = null;
talendType = globalType;
if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
metadataColumn.setPrecision(precisionValue);
} else {
metadataColumn.setPrecision(0);
}
metadataColumn.setTalendType(talendType);
metadataColumn.setLength(lengthValue);
metadataColumn.setLabel(label[i]);
newColumns.add(i, metadataColumn);
}
}
EList columns = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0].getColumns();
if (!flag) {
for (int i = 0; i < newColumns.size(); i++) {
for (int j = 0; j < columns.size(); j++) {
if (newColumns.get(i).getLabel().equals(((MetadataColumn) columns.get(j)).getLabel())) {
newColumns.remove(i);
newColumns.add(i, (MetadataColumn) columns.get(j));
}
}
}
}
columns.clear();
columns.addAll(newColumns);
}
Aggregations