use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method getPlatformResource.
private Resource getPlatformResource(String anaPropertyFile) {
try {
EMFUtil util = new EMFUtil();
ResourceSet resourceSet = util.getResourceSet();
URI uri = URI.createPlatformPluginURI("/org.talend.cwm.management.test" + anaPropertyFile, true);
return resourceSet.getResource(uri, true);
} catch (NullPointerException e) {
fail("Can not find the file: " + anaPropertyFile);
e.printStackTrace();
}
return null;
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class SqlSourceFileUpdateTask method doExecute.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
File rawFile = getWorkspacePath().append(TDQ_SOURCE_FILE_PATH).toFile();
EMFUtil emfUtil = new EMFUtil();
if (rawFile.exists() && rawFile.isDirectory()) {
ArrayList<File> fileList = new ArrayList<File>();
getAllFilesFromFolder(rawFile, fileList, new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.endsWith(SQL_EXT)) {
return true;
}
return false;
}
});
// $NON-NLS-1$
log.info("-----------Updating sql source file task ---------------");
int counter = 0;
for (File sqlFile : fileList) {
// $NON-NLS-1$
log.info(counter + ". Updating: " + sqlFile.getAbsolutePath());
// $NON-NLS-1$
String fileNamePart = FileUtils.getName(sqlFile) + "_" + VersionUtils.DEFAULT_VERSION;
IPath newSQLPath = new Path(sqlFile.getAbsolutePath()).removeLastSegments(1).append(fileNamePart).addFileExtension(SQL_EXT);
Property property = createProperty(sqlFile);
TDQFileItem item = (TDQFileItem) property.getItem();
URI itemResourceURI = URI.createFileURI(newSQLPath.toString());
Resource itemResource = new ByteArrayResource(itemResourceURI);
itemResource.getContents().add(item.getContent());
URI propertyResourceURI = itemResourceURI.trimFileExtension().appendFileExtension(PROP_EXT);
Resource propertyResource = emfUtil.getResourceSet().createResource(propertyResourceURI);
propertyResource.getContents().add(item.getProperty());
propertyResource.getContents().add(item.getState());
propertyResource.getContents().add(item);
EMFUtil.saveResource(itemResource);
EMFUtil.saveResource(propertyResource);
sqlFile.delete();
counter++;
}
emfUtil = null;
}
return true;
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class CorePlugin method initProxyRepository.
/**
* DOC zshen Comment method "initProxyRepository".
*/
public ReturnCode initProxyRepository() {
ReturnCode rc = new ReturnCode();
Project project = null;
RepositoryContext repositoryContext = (RepositoryContext) org.talend.core.runtime.CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
if (repositoryContext != null) {
project = repositoryContext.getProject();
User user = repositoryContext.getUser();
ReponsitoryContextBridge.initialized(project.getEmfProject(), user);
} else {
// else project is null, then we are in TOP only
Location instanceLoc = Platform.getInstanceLocation();
try {
if (instanceLoc.isLocked()) {
// $NON-NLS-1$
rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.workspaceInUse"));
rc.setOk(false);
return rc;
} else {
instanceLoc.lock();
}
} catch (IOException e) {
log.error(e, e);
}
ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
if (repository == null) {
// $NON-NLS-1$
log.fatal(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
// $NON-NLS-1$
rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
rc.setOk(false);
return rc;
}
proxyRepository.setRepositoryFactoryFromProvider(repository);
try {
proxyRepository.checkAvailability();
proxyRepository.initialize();
XmiResourceManager xmiResourceManager = proxyRepository.getRepositoryFactoryFromProvider().getResourceManager();
IProject rootProject = ResourceManager.getRootProject();
if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
// Initialize TDQ EMF model packages.
new EMFUtil();
project = new Project(xmiResourceManager.loadProject(rootProject));
} else {
// $NON-NLS-1$
String username = "talend@talend.com";
// $NON-NLS-1$
String password = "talend@talend.com";
User user = PropertiesFactoryImpl.eINSTANCE.createUser();
user.setLogin(username);
user.setPassword(password.getBytes());
String projectName = ResourceManager.getRootProjectName();
String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
// MOD zshen create project by proxyRepository
checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
project = proxyRepository.getRepositoryFactoryFromProvider().createProject(user, password, projectInfor);
}
if (project != null) {
initRepositoryContext(project);
// add status
// $NON-NLS-1$
String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
proxyRepository.setTechnicalStatus(statusList);
// 'maven_user_settings.xml').before set, must check user setting first.
if (org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
if (mavenUIService != null) {
mavenUIService.checkUserSettings(new NullProgressMonitor());
mavenUIService.updateMavenResolver(false);
mavenUIService.addMavenConfigurationChangeListener();
}
}
// deploy libraries and maven index here
if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
ILibrariesService librariesService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
if (librariesService != null) {
librariesService.syncLibraries();
// TDQ-9529 check libararies install status at here,so that
// "Optional third-party libraries" is displayed in the "Additional Talend Package"
// dialog.
librariesService.checkLibraries();
}
}
}
CWMPlugin.getDefault().createLibFolderIfNotExist();
// TDQ-11348 the readOnlyUser property is false for TOP.
// $NON-NLS-1$
System.getProperties().put("ReadOnlyUser", new Boolean(false).toString());
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
rc.setMessage(e.getMessage());
rc.setOk(false);
return rc;
}
}
return rc;
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method initProxyRepository.
/**
* DOC talend Comment method "initProxyRepository".
*/
public static void initProxyRepository(IProject rootProject) {
Project project = null;
ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
if (repository == null) {
log.fatal(DefaultMessagesImpl.getString(// $NON-NLS-1$
"No local Repository found! Probably due to a missing plugin in the product."));
}
proxyRepository.setRepositoryFactoryFromProvider(repository);
try {
proxyRepository.checkAvailability();
proxyRepository.setFullLogonFinished(false);
// proxyRepository.initialize();
XmiResourceManager xmiResourceManager = new XmiResourceManager();
if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
// Initialize TDQ EMF model packages.
new EMFUtil();
project = new Project(xmiResourceManager.loadProject(rootProject));
} else {
User user = org.talend.core.model.properties.impl.PropertiesFactoryImpl.eINSTANCE.createUser();
// $NON-NLS-1$
user.setLogin("talend@talend.com");
// $NON-NLS-1$
user.setPassword("talend@talend.com".getBytes());
String projectName = rootProject.getName();
String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
// MOD zshen create project by proxyRepository
checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
project = proxyRepository.getRepositoryFactoryFromProvider().createProject(projectInfor);
}
if (project != null) {
initRepositoryContext(project);
// add status
// $NON-NLS-1$
String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
proxyRepository.setTechnicalStatus(statusList);
}
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class IndicatorEvaluationMain method main.
/**
* DOC scorreia Comment method "main".
*
* @param args
*/
public static void main(String[] args) {
TypedProperties connectionParams = PropertiesLoader.getProperties(IndicatorEvaluator.class, "db.properties");
String driverClassName = connectionParams.getProperty("driver");
String dbUrl = connectionParams.getProperty("url");
try {
TimeTracer tt = new TimeTracer("Indicator evaluation", null);
tt.start();
// create connection
Connection connection = ConnectionUtils.createConnection(dbUrl, driverClassName, connectionParams);
String database = "test";
String tableName = "my_test";
// --- columns to analyze
String[] columnsArray = new String[] { // 0
"my_int", // 1
"my_double", // 2
"my_text", // 4
"my_date", // 3
"my_string", // 5
"my_int_null" };
List<String> columns = Arrays.asList(columnsArray);
// store in file
File file = new File("out/columnTest_0.1.ana");
EMFUtil util = new EMFUtil();
Resource resource = util.getResourceSet().createResource(URI.createFileURI(file.getAbsolutePath()));
rContents = resource.getContents();
evaluator.setConnection(connection);
// --- create indicators
RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
NullCountIndicator nullCountIndicator = IndicatorsFactory.eINSTANCE.createNullCountIndicator();
DistinctCountIndicator distinctCountIndicator = IndicatorsFactory.eINSTANCE.createDistinctCountIndicator();
DistinctCountIndicator distinctCountIndicator2 = IndicatorsFactory.eINSTANCE.createDistinctCountIndicator();
UniqueCountIndicator uniqueCountIndicator = IndicatorsFactory.eINSTANCE.createUniqueCountIndicator();
DuplicateCountIndicator duplicateCountIndicator = IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator();
BlankCountIndicator blankCountIndicator = IndicatorsFactory.eINSTANCE.createBlankCountIndicator();
MinLengthIndicator minLengthIndicator = IndicatorsFactory.eINSTANCE.createMinLengthIndicator();
MaxLengthIndicator maxLengthIndicator = IndicatorsFactory.eINSTANCE.createMaxLengthIndicator();
AverageLengthIndicator averageLengthIndicator = IndicatorsFactory.eINSTANCE.createAverageLengthIndicator();
AverageLengthIndicator averageLengthIndicator2 = IndicatorsFactory.eINSTANCE.createAverageLengthIndicator();
ModeIndicator modeIndicator = IndicatorsFactory.eINSTANCE.createModeIndicator();
FrequencyIndicator textFrequencyIndicator = IndicatorsFactory.eINSTANCE.createFrequencyIndicator();
// store in freq indic
// textFrequencyIndicator.setDistinctCountIndicator(distinctCountIndicator);
// textFrequencyIndicator.setDistinctCountIndicator(distinctCountIndicator2);
// textFrequencyIndicator.setUniqueCountIndicator(uniqueCountIndicator);
// textFrequencyIndicator.setDuplicateCountIndicator(duplicateCountIndicator);
// textFrequencyIndicator.setModeIndicator(modeIndicator);
MeanIndicator doubleMeanIndicator = IndicatorsFactory.eINSTANCE.createMeanIndicator();
MeanIndicator integerMeanIndicator = IndicatorsFactory.eINSTANCE.createMeanIndicator();
MedianIndicator medianIndicator = IndicatorsFactory.eINSTANCE.createMedianIndicator();
SumIndicator integerSumIndicator = IndicatorsFactory.eINSTANCE.createSumIndicator();
addIndicator(columnsArray[0], medianIndicator);
addIndicator(columnsArray[1], doubleMeanIndicator);
addIndicator(columnsArray[2], blankCountIndicator);
addIndicator(columnsArray[5], nullCountIndicator);
// addIndicator(columnsArray[2], textFrequencyIndicator);
// addIndicator(columnsArray[2], distinctCountIndicator); // probably not useful?
// addIndicator(columnsArray[2], uniqueCountIndicator); // probably not useful?
// addIndicator(columnsArray[2], duplicateCountIndicator); // probably not useful?
// addIndicator(columnsArray[2], modeIndicator); // probably not useful?
addIndicator(columnsArray[3], rowCountIndicator);
addIndicator(columnsArray[5], integerSumIndicator);
addIndicator(columnsArray[5], integerMeanIndicator);
addIndicator(columnsArray[2], averageLengthIndicator);
addIndicator(columnsArray[3], averageLengthIndicator2);
addIndicator(columnsArray[3], minLengthIndicator);
addIndicator(columnsArray[3], maxLengthIndicator);
// build query on columns
// TODO scorreia add filter somewhere here...
String selectCols = sqlSelectColumns(database, tableName, columns);
// --- create a description of the column set
QueryExpression queryExpression = DatatypesFactory.eINSTANCE.createQueryExpression();
queryExpression.setBody(selectCols);
// TODO scorreia externalize this as a constant
queryExpression.setLanguage("SQL");
tt.start("compute");
evaluator.setFetchSize(10000);
evaluator.evaluateIndicators(selectCols, true);
tt.end("compute");
// Print indicators the median
System.out.println("Median=" + medianIndicator.getMedian());
System.out.println("# Unique values= " + textFrequencyIndicator.getUniqueValueCount());
System.out.println("# Distinct values= " + textFrequencyIndicator.getDistinctValueCount());
for (String col : columns) {
printIndicators(evaluator.getIndicators(col));
}
tt.start("save");
util.save();
tt.end("saved in " + file.getAbsolutePath());
tt.end();
CwmResource cwmR = (CwmResource) resource;
String id = cwmR.getID(medianIndicator);
System.out.println("ecore util.getId= " + EcoreUtil.getID(medianIndicator));
System.out.println("uuId= " + id);
// test reload this file
// LoadSerialData.main(args);
} catch (SQLException e) {
// TODO Auto-generated catch block
log.error(e, e);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
log.error(e, e);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
log.error(e, e);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
log.error(e, e);
}
}
Aggregations