Search in sources :

Example 16 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.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) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) 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 17 with EMFUtil

use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.

the class ItemRecordTest method initProxyRepository.

/**
 * DOC talend Comment method "initProxyRepository".
 */
private void initProxyRepository(IProject rootProject) {
    Project project = null;
    // $NON-NLS-1$
    log.debug("##############ProxyRepositoryFactory.getInstance()");
    ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
    // $NON-NLS-1$
    log.debug("##############RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID)");
    IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
    proxyRepository.setRepositoryFactoryFromProvider(repository);
    try {
        // $NON-NLS-1$
        log.debug("##############proxyRepository.checkAvailability()");
        proxyRepository.checkAvailability();
        // $NON-NLS-1$
        log.debug("##############proxyRepository.initialize()");
        try {
            proxyRepository.initialize();
        } catch (Exception e) {
            log.error(e, e);
        }
        proxyRepository.logOffProject();
        XmiResourceManager xmiResourceManager = new XmiResourceManager();
        // $NON-NLS-1$
        log.debug("##############rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()");
        if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
            // Initialize TDQ EMF model packages.
            // $NON-NLS-1$
            log.debug("##############Project name is " + rootProject.getName());
            new EMFUtil();
            project = new Project(xmiResourceManager.loadProject(rootProject));
            // $NON-NLS-1$
            log.debug("############## after loadProject Project name is " + project.getTechnicalLabel());
        } 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();
            // $NON-NLS-1$
            log.debug("##############default project is not exist then create new project which is  " + projectName);
            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) {
        ExceptionHandler.process(e);
        Assert.fail(e.getMessage());
    } catch (Exception e) {
        log.error(e, e);
        // $NON-NLS-1$
        log.debug("##############exception message is  " + 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) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 18 with EMFUtil

use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.

the class UpdatePathProperty method doExecute.

/*
     * (non-Jsdoc)
     * 
     * @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    boolean ok = true;
    EMFUtil emfUtil = new EMFUtil();
    for (File file : fileList) {
        if (file.isFile()) {
            URI uri = URI.createFileURI(file.getAbsolutePath());
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug("---------Translate " + uri.toString());
            }
            Property property = null;
            try {
                Resource resource = emfUtil.getResourceSet().getResource(uri, true);
                for (EObject object : resource.getContents()) {
                    if (object instanceof Property) {
                        property = (Property) object;
                        break;
                    }
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                log.warn(DefaultMessagesImpl.getString("UpdatePathProperty_UpdateFailed", file.getAbsolutePath()), e);
                ok = false;
            }
            if (property != null) {
                try {
                    saveObject(emfUtil, file, uri, property);
                } catch (Exception e) {
                    // $NON-NLS-1$
                    log.error(DefaultMessagesImpl.getString("UpdatePathProperty_UpdateError", property, file, uri), e);
                    ok = false;
                }
            }
        }
    }
    return ok;
}
Also used : EMFUtil(org.talend.commons.emf.EMFUtil) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) File(java.io.File) URI(org.eclipse.emf.common.util.URI) Property(org.talend.core.model.properties.Property)

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