Search in sources :

Example 11 with EMFUtil

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;
}
Also used : EMFUtil(org.talend.commons.emf.EMFUtil) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 12 with EMFUtil

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) URI(org.eclipse.emf.common.util.URI) FilenameFilter(java.io.FilenameFilter) EMFUtil(org.talend.commons.emf.EMFUtil) File(java.io.File) Property(org.talend.core.model.properties.Property)

Example 13 with EMFUtil

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;
}
Also used : Status(org.talend.core.model.properties.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ReturnCode(org.talend.utils.sugars.ReturnCode) User(org.talend.core.model.properties.User) ILibrariesService(org.talend.core.model.general.ILibrariesService) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EMFUtil(org.talend.commons.emf.EMFUtil) PersistenceException(org.talend.commons.exception.PersistenceException) IMavenUIService(org.talend.core.runtime.services.IMavenUIService) Location(org.eclipse.osgi.service.datalocation.Location)

Example 14 with EMFUtil

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());
    }
}
Also used : Status(org.talend.core.model.properties.Status) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) User(org.talend.core.model.properties.User) EMFUtil(org.talend.commons.emf.EMFUtil) PersistenceException(org.talend.commons.exception.PersistenceException) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager)

Example 15 with EMFUtil

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);
    }
}
Also used : SumIndicator(org.talend.dataquality.indicators.SumIndicator) SQLException(java.sql.SQLException) BlankCountIndicator(org.talend.dataquality.indicators.BlankCountIndicator) MedianIndicator(org.talend.dataquality.indicators.MedianIndicator) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) ModeIndicator(org.talend.dataquality.indicators.ModeIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) QueryExpression(orgomg.cwm.foundation.datatypes.QueryExpression) MeanIndicator(org.talend.dataquality.indicators.MeanIndicator) CwmResource(org.talend.model.emf.CwmResource) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) MaxLengthIndicator(org.talend.dataquality.indicators.MaxLengthIndicator) Connection(java.sql.Connection) CwmResource(org.talend.model.emf.CwmResource) Resource(org.eclipse.emf.ecore.resource.Resource) MinLengthIndicator(org.talend.dataquality.indicators.MinLengthIndicator) TypedProperties(org.talend.utils.properties.TypedProperties) TimeTracer(org.talend.utils.time.TimeTracer) AverageLengthIndicator(org.talend.dataquality.indicators.AverageLengthIndicator) EMFUtil(org.talend.commons.emf.EMFUtil) File(java.io.File)

Aggregations

EMFUtil (org.talend.commons.emf.EMFUtil)18 Resource (org.eclipse.emf.ecore.resource.Resource)11 File (java.io.File)8 URI (org.eclipse.emf.common.util.URI)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 IProject (org.eclipse.core.resources.IProject)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 Project (org.talend.core.model.general.Project)6 Status (org.talend.core.model.properties.Status)6 User (org.talend.core.model.properties.User)6 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)6 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)6 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)6 EObject (org.eclipse.emf.ecore.EObject)5 IPath (org.eclipse.core.runtime.IPath)2 Property (org.talend.core.model.properties.Property)2 ByteArrayResource (org.talend.core.model.properties.helper.ByteArrayResource)2 FrequencyIndicator (org.talend.dataquality.indicators.FrequencyIndicator)2 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1