use of org.talend.core.exception.TalendInternalPersistenceException in project tdq-studio-se by Talend.
the class ExportConnectionToTOSAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
if (packList.isEmpty()) {
return;
}
for (Package pack : packList) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
DatabaseConnection tdDataProvider = (DatabaseConnection) ConnectionHelper.getTdDataProvider(pack);
ConnectionItem connectionItem = initConnectionItem(tdDataProvider, pack);
DatabaseConnection exportedConn = (DatabaseConnection) connectionItem.getConnection();
Property connectionProperty = initConnectionProperty(exportedConn, pack);
connectionProperty.setId(factory.getNextId());
connectionItem.setProperty(connectionProperty);
try {
// $NON-NLS-1$
factory.create(connectionItem, new Path(""));
openSuccessInformation();
} catch (TalendInternalPersistenceException e1) {
// MessageDialog.openError(null, DefaultMessagesImpl.getString("ExportConnectionToTOSAction.error"), e1.getMessage());//$NON-NLS-1$
} catch (PersistenceException e) {
// $NON-NLS-1$
MessageDialog.openError(null, DefaultMessagesImpl.getString("ExportConnectionToTOSAction.error"), e.getMessage());
log.error(e.getMessage(), e);
}
}
refreshViewerAndNode();
}
use of org.talend.core.exception.TalendInternalPersistenceException in project tdq-studio-se by Talend.
the class ImportFactory method importToStucture.
/**
* DOC xqliu Comment method "importToStucture".
*
* @param importObject
* @param selectionFolder
* @param type
* @param skip
* @param rename
* @param importItemName
* @return
*/
public static List<ReturnCode> importToStucture(ImportObject importObject, IFolder selectionFolder, ExpressionType type, boolean skip, boolean rename, String importItemName) {
List<ReturnCode> importEvent = new ArrayList<ReturnCode>();
// MOD qiongli 2012-12-20 TDQ-5899(issue 2),should get all patterns from Pattern folder.
Set<String> names = PatternUtilities.getNestFolderPatternNames(new HashSet<String>(), ResourceManager.getPatternFolder());
File importFile = importObject.getObjFile();
String fileExtName = getFileExtName(importFile);
if (FileUtils.isCSV(fileExtName)) {
try {
CSVReader reader = FileUtils.createCSVReader(importFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
reader.setSkipEmptyRecords(true);
reader.readHeaders();
while (reader.readNext()) {
String name = reader.get(PatternToExcelEnum.Label.getLiteral());
if (names.contains(name)) {
if (skip) {
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.patternInported", name), // $NON-NLS-1$
false));
continue;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + new Date() + ")";
}
}
PatternParameters patternParameters = new ImportFactory().new PatternParameters();
patternParameters.name = name;
patternParameters.auther = reader.get(PatternToExcelEnum.Author.getLiteral());
patternParameters.description = reader.get(PatternToExcelEnum.Description.getLiteral());
patternParameters.purpose = reader.get(PatternToExcelEnum.Purpose.getLiteral());
patternParameters.relativePath = reader.get(PatternToExcelEnum.RelativePath.getLiteral());
for (PatternLanguageType languagetype : PatternLanguageType.values()) {
String cellStr = reader.get(languagetype.getExcelEnum().getLiteral());
if (cellStr != null && !cellStr.equals("")) {
// $NON-NLS-1$
patternParameters.regex.put(languagetype.getLiteral(), cellStr);
}
}
try {
TypedReturnCode<Object> create = createAndStorePattern(patternParameters, selectionFolder, type);
if (create.isOk()) {
names.add(name);
importEvent.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importPattern", // $NON-NLS-1$
name, selectionFolder.getProjectRelativePath().toString()), true));
} else {
throw new TalendInternalPersistenceException(create.getMessage());
}
} catch (Exception e) {
// $NON-NLS-1$
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.SaveFailed", name), false));
}
}
reader.close();
} catch (Exception e) {
log.error(e, e);
// $NON-NLS-1$
importEvent.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importFailed"), false));
}
}
importObject.copyJarFiles();
// ADD xqliu 2012-04-27 TDQ-5149
checkImportEvent(importItemName, importEvent);
// ~ TDQ-5149
return importEvent;
}
use of org.talend.core.exception.TalendInternalPersistenceException in project tdq-studio-se by Talend.
the class ImportFactory method importIndicatorToStucture.
/**
* DOC xqliu Comment method "importIndicatorToStucture".
*
* @param importObject
* @param selectionFolder
* @param skip
* @param rename
* @param importItemName
* @return
*/
public static List<ReturnCode> importIndicatorToStucture(ImportObject importObject, IFolder selectionFolder, boolean skip, boolean rename, String importItemName) {
List<ReturnCode> information = new ArrayList<ReturnCode>();
Set<String> names = UDIHelper.getAllIndicatorNames(selectionFolder);
File importFile = importObject.getObjFile();
String fileExtName = getFileExtName(importFile);
if (FileUtils.isCSV(fileExtName)) {
String name = PluginConstant.EMPTY_STRING;
try {
CSVReader reader = FileUtils.createCSVReader(importFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
reader.setSkipEmptyRecords(true);
reader.readHeaders();
// $NON-NLS-1$
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmssSSS");
while (reader.readNext()) {
name = reader.get(PatternToExcelEnum.Label.getLiteral());
if (names.contains(name)) {
if (skip) {
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.Imported", name), false));
continue;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + simpleDateFormat.format(new Date()) + Math.random() + ")";
}
}
UDIParameters udiParameters = new ImportFactory().new UDIParameters();
udiParameters.name = name;
udiParameters.auther = reader.get(PatternToExcelEnum.Author.getLiteral());
udiParameters.description = reader.get(PatternToExcelEnum.Description.getLiteral());
udiParameters.purpose = reader.get(PatternToExcelEnum.Purpose.getLiteral());
udiParameters.relativePath = reader.get(PatternToExcelEnum.RelativePath.getLiteral());
udiParameters.category = reader.get(PatternToExcelEnum.Category.getLiteral());
udiParameters.javaClassName = reader.get(PatternToExcelEnum.JavaClassName.getLiteral());
udiParameters.javaJarPath = reader.get(PatternToExcelEnum.JavaJarPath.getLiteral());
String[] headers = reader.getHeaders();
String[] columnsValue = reader.getValues();
HashMap<String, String> record = new HashMap<String, String>();
for (int i = 0; i < headers.length; i++) {
// TDQ-6714: fix when there is no regexp for the imported udi (csv) file.
if (i >= columnsValue.length) {
// $NON-NLS-1$
record.put(headers[i], "");
} else {
if (columnsValue[i] != null && columnsValue[i].length() > 0) {
record.put(headers[i], columnsValue[i]);
}
}
}
for (PatternLanguageType languagetype : PatternLanguageType.values()) {
String cellStr = record.get(languagetype.getExcelEnum().getLiteral());
if (cellStr != null && !cellStr.equals("\"\"")) {
// $NON-NLS-1$
udiParameters.regex.put(languagetype.getLiteral(), trimQuote(cellStr));
}
}
udiParameters.setParaMap(buildIndDefPara(record));
TypedReturnCode<Object> create = createAndStoreUDI(udiParameters, selectionFolder);
if (create.isOk()) {
names.add(name);
// add the suscess message to display.
information.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importedSucess", ((TDQItem) create.getObject()).getProperty().getDisplayName(), selectionFolder.getProjectRelativePath().toString()), true));
} else {
throw new TalendInternalPersistenceException(create.getMessage());
}
}
reader.close();
} catch (Exception e) {
log.error(e, e);
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importedFailed", name), false));
}
}
// MOD qiongli 2011-11-28 TDQ-4038.consider to import the definition file.
if (FactoriesUtil.DEFINITION.equalsIgnoreCase(fileExtName)) {
String propFilePath = importFile.getPath().replaceFirst(PluginConstant.DOT_STRING + fileExtName, PluginConstant.DOT_STRING + FactoriesUtil.PROPERTIES_EXTENSION);
File propFile = new File(propFilePath);
// just import the definition file which have the realted Property file.
if (!propFile.exists()) {
return information;
}
String name = importFile.getName();
try {
if (names.contains(name)) {
if (skip) {
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.Imported", name), false));
return information;
}
if (rename) {
// $NON-NLS-1$ //$NON-NLS-2$
name = name + "(" + new Date() + Math.random() + ")";
}
}
IFile elementFile = selectionFolder.getFile(name);
if (!elementFile.exists()) {
elementFile.create(new FileInputStream(importFile), false, null);
ModelElement modelElement = ModelElementFileFactory.getModelElement(elementFile);
if (modelElement != null) {
ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(modelElement, selectionFolder);
DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
names.add(name);
information.add(new ReturnCode(// $NON-NLS-1$
DefaultMessagesImpl.getString(// $NON-NLS-1$
"ImportFactory.importedSucess", name), true));
}
}
} catch (Exception e) {
log.error(e);
// $NON-NLS-1$
information.add(new ReturnCode(DefaultMessagesImpl.getString("ImportFactory.importedFailed", name), false));
}
}
importObject.copyJarFiles();
// ADD xqliu 2012-04-27 TDQ-5149
checkImportEvent(importItemName, information);
// ~ TDQ-5149
return information;
}
Aggregations