Search in sources :

Example 26 with Folder

use of org.talend.core.model.repository.Folder in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testCreateFolderViewObject.

@Test
public void testCreateFolderViewObject() throws Exception {
    boolean isSystem = false;
    String folderName = "folderName";
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager mockProjectManager = mock(ProjectManager.class);
    Project mockProject = mock(Project.class);
    IProject mockIProject = mock(IProject.class);
    when(ProjectManager.getInstance()).thenReturn(mockProjectManager);
    when(ProjectManager.getInstance().getCurrentProject()).thenReturn(mockProject);
    IFolder mockFolder = mock(IFolder.class);
    PowerMockito.mockStatic(ResourceUtils.class);
    when(ResourceUtils.getProject(mockProject)).thenReturn(mockIProject);
    when(mockIProject.getFolder(Mockito.anyString())).thenReturn(mockFolder);
    when(mockFolder.exists()).thenReturn(false);
    PowerMockito.doNothing().when(ResourceUtils.class, "createFolder", mockFolder);
    ItemState mockItemState = mock(ItemState.class);
    when(mockItemState.getPath()).thenReturn("mocked_path");
    Item mockParentItem = mock(Item.class);
    when(mockParentItem.getState()).thenReturn(mockItemState);
    String processFolder = "process";
    PowerMockito.mockStatic(ERepositoryObjectType.class);
    ERepositoryObjectType mockType = mock(ERepositoryObjectType.class);
    when(mockType.getType()).thenReturn("mockType");
    when(ERepositoryObjectType.getFolderName(mockType)).thenReturn(processFolder);
    PowerMockito.mockStatic(ProxyRepositoryFactory.class);
    ProxyRepositoryFactory proxyRepositoryFactory = mock(ProxyRepositoryFactory.class);
    when(ProxyRepositoryFactory.getInstance()).thenReturn(proxyRepositoryFactory);
    Folder mockTalendFolder = mock(Folder.class);
    when(proxyRepositoryFactory.createFolder(any(Project.class), any(ERepositoryObjectType.class), any(IPath.class), anyString())).thenReturn(mockTalendFolder);
    IRepositoryViewObject folderViewObject = RepositoryResourceUtil.createFolderViewObject(mockType, folderName, mockParentItem, isSystem);
    assertNotNull(folderViewObject);
    verify(proxyRepositoryFactory, times(1)).createFolder(any(Project.class), any(ERepositoryObjectType.class), any(IPath.class), anyString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Folder(org.talend.core.model.repository.Folder) IFolder(org.eclipse.core.resources.IFolder) IProject(org.eclipse.core.resources.IProject) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFolder(org.eclipse.core.resources.IFolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with Folder

use of org.talend.core.model.repository.Folder in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method buildRepositoryViewObjectSystemFolder.

/**
 * create a RepositoryViewObject which is a system folder.
 *
 * @param tProject
 * @param author
 * @param type
 * @return
 */
public static IRepositoryViewObject buildRepositoryViewObjectSystemFolder(org.talend.core.model.properties.Project emfProject, User author, ERepositoryObjectType type) {
    ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
    FolderItem folderItem = PropertiesFactory.eINSTANCE.createFolderItem();
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    itemState.setItemRelated(folderItem);
    folderItem.setState(itemState);
    folderItem.setParent(emfProject);
    folderItem.setType(FolderType.STABLE_SYSTEM_FOLDER_LITERAL);
    folderItem.setProperty(property);
    property.setAuthor(author);
    property.setCreationDate(new Date());
    property.setId(StringUtilities.getRandomString(26));
    property.setItem(folderItem);
    property.setLabel(type.getFolder());
    property.setMaxInformationLevel(InformationLevel.DEBUG_LITERAL);
    // $NON-NLS-1$
    property.setOldStatusCode("");
    // $NON-NLS-1$
    property.setVersion("0.1");
    return new Folder(property, type);
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) ItemState(org.talend.core.model.properties.ItemState) Folder(org.talend.core.model.repository.Folder) IFolder(org.eclipse.core.resources.IFolder) Property(org.talend.core.model.properties.Property) Date(java.util.Date)

Example 28 with Folder

use of org.talend.core.model.repository.Folder in project tdq-studio-se by Talend.

the class DQStructureManager method createDQStructureUnit.

/**
 * DOC zhao Comment method "createDQStructureUnit".
 */
private void createDQStructureUnit() {
    RepositoryNodeBuilder instance = RepositoryNodeBuilder.getInstance();
    Plugin plugin = CorePlugin.getDefault();
    try {
        IProject project = ResourceManager.getRootProject();
        if (!project.exists()) {
            project = createNewProject(ResourceManager.getRootProjectName());
        }
        if (!project.getFolder(EResourceConstant.DB_CONNECTIONS.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.METADATA, Path.EMPTY, EResourceConstant.DB_CONNECTIONS.getName());
        }
        if (!project.getFolder(EResourceConstant.FILEDELIMITED.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.METADATA, Path.EMPTY, EResourceConstant.FILEDELIMITED.getName());
        }
        if (!project.getFolder(EResourceConstant.ANALYSIS.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_DATA_PROFILING, Path.EMPTY, EResourceConstant.ANALYSIS.getName());
        }
        if (PluginChecker.isTDQLoaded()) {
            if (!project.getFolder(EResourceConstant.REPORTS.getPath()).exists()) {
                ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_DATA_PROFILING, Path.EMPTY, EResourceConstant.REPORTS.getName());
            }
            // Added 20150421 TDQ-9605
            if (!project.getFolder(EResourceConstant.HADOOP_CLUSTER.getPath()).exists() && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.METADATA, Path.EMPTY, EResourceConstant.HADOOP_CLUSTER.getName());
            }
        }
        if (!project.getFolder(EResourceConstant.PATTERNS.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.PATTERNS.getName());
        }
        if (!project.getFolder(EResourceConstant.RULES.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.RULES.getName());
        }
        Folder rulesSQLFoler = null;
        if (!project.getFolder(EResourceConstant.RULES_SQL.getPath()).exists()) {
            rulesSQLFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_RULES, Path.EMPTY, EResourceConstant.RULES_SQL.getName());
        } else {
            rulesSQLFoler = instance.getObjectFolder(EResourceConstant.RULES_SQL);
        }
        rulesSQLFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_RULES_SQL.getFolder());
        Folder rulesMatchLFoler = null;
        if (!project.getFolder(EResourceConstant.RULES_MATCHER.getPath()).exists()) {
            rulesMatchLFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_RULES, Path.EMPTY, EResourceConstant.RULES_MATCHER.getName());
        } else {
            rulesMatchLFoler = instance.getObjectFolder(EResourceConstant.RULES_MATCHER);
        }
        rulesMatchLFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_RULES_MATCHER.getFolder());
        Folder rulesParserFoler = null;
        if (!project.getFolder(EResourceConstant.RULES_PARSER.getPath()).exists()) {
            if (PluginChecker.isTDQLoaded()) {
                rulesParserFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_RULES, Path.EMPTY, EResourceConstant.RULES_PARSER.getName());
            }
        } else {
            rulesParserFoler = instance.getObjectFolder(EResourceConstant.RULES_PARSER);
        }
        if (rulesParserFoler != null) {
            rulesParserFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_RULES_PARSER.getFolder());
        }
        if (!project.getFolder(EResourceConstant.EXCHANGE.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.EXCHANGE.getName());
        }
        if (!project.getFolder(EResourceConstant.INDICATORS.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.INDICATORS.getName());
        }
        Folder systemIndicatorFoler = null;
        if (!project.getFolder(EResourceConstant.SYSTEM_INDICATORS.getPath()).exists()) {
            systemIndicatorFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_INDICATOR_ELEMENT, Path.EMPTY, EResourceConstant.SYSTEM_INDICATORS.getName());
        } else {
            systemIndicatorFoler = instance.getObjectFolder(EResourceConstant.SYSTEM_INDICATORS);
        }
        systemIndicatorFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_SYSTEM_INDICATORS.getFolder());
        if (!project.getFolder(EResourceConstant.USER_DEFINED_INDICATORS.getPath()).exists()) {
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_INDICATOR_ELEMENT, Path.EMPTY, EResourceConstant.USER_DEFINED_INDICATORS.getName());
        }
        if (!project.getFolder(EResourceConstant.USER_DEFINED_INDICATORS_LIB.getPath()).exists()) {
            // MOD zhsne 18724: Java UDI enhancements add lib folder under UDI folder.
            ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_USERDEFINE_INDICATORS, Path.EMPTY, EResourceConstant.USER_DEFINED_INDICATORS_LIB.getName());
        }
        if (PluginChecker.isTDQLoaded()) {
            if (!project.getFolder(EResourceConstant.JRXML_TEMPLATE.getPath()).exists()) {
                ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.JRXML_TEMPLATE.getName());
            }
            if (!project.getFolder(EResourceConstant.CONTEXT.getPath()).exists()) {
                ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.CONTEXT, Path.EMPTY, EResourceConstant.CONTEXT.getName());
            }
        }
        Folder patternRegexFoler = null;
        if (!project.getFolder(EResourceConstant.PATTERN_REGEX.getPath()).exists()) {
            patternRegexFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_PATTERN_ELEMENT, Path.EMPTY, EResourceConstant.PATTERN_REGEX.getName());
        } else {
            patternRegexFoler = instance.getObjectFolder(EResourceConstant.PATTERN_REGEX);
        }
        patternRegexFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_PATTERN_REGEX.getFolder());
        Folder patternSQLFoler = null;
        if (!project.getFolder(EResourceConstant.PATTERN_SQL.getPath()).exists()) {
            patternSQLFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_PATTERN_ELEMENT, Path.EMPTY, EResourceConstant.PATTERN_SQL.getName());
        } else {
            patternSQLFoler = instance.getObjectFolder(EResourceConstant.PATTERN_SQL);
        }
        patternSQLFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_PATTERN_SQL.getFolder());
        Folder sourceFileFoler = null;
        if (!project.getFolder(EResourceConstant.SOURCE_FILES.getPath()).exists()) {
            sourceFileFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_LIBRARIES, Path.EMPTY, EResourceConstant.SOURCE_FILES.getName());
        } else {
            sourceFileFoler = instance.getObjectFolder(EResourceConstant.SOURCE_FILES);
        }
        sourceFileFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getFolder());
        // use the tos create folder API
        if (systemIndicatorFoler != null && patternRegexFoler != null && patternSQLFoler != null && sourceFileFoler != null && rulesSQLFoler != null) {
            copyFilesToFolder(plugin, SYSTEM_INDICATOR_PATH, true, systemIndicatorFoler, null, ERepositoryObjectType.TDQ_SYSTEM_INDICATORS);
            copyFilesToFolder(plugin, PATTERN_PATH, true, patternRegexFoler, null, ERepositoryObjectType.TDQ_PATTERN_REGEX);
            copyFilesToFolder(plugin, SQL_LIKE_PATH, true, patternSQLFoler, null, ERepositoryObjectType.TDQ_PATTERN_SQL);
            copyFilesToFolder(plugin, DEMO_PATH, true, sourceFileFoler, null, ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT);
            copyFilesToFolder(plugin, RULES_PATH, true, rulesSQLFoler, null, ERepositoryObjectType.TDQ_RULES_SQL);
        }
        if (rulesParserFoler != null) {
            copyFilesToFolder(plugin, RULES_PARSER, true, rulesParserFoler, null, ERepositoryObjectType.TDQ_RULES_PARSER);
        }
        WorkspaceVersionHelper.storeVersion();
        // MOD qiongli 2011-12-6 TDQ-4095,make the definition file commit to svn with the DQ struct files.move
        // this code from DQRespositoryView.initWorkspace()
        IFile defFile = ResourceManager.getLibrariesFolder().getFile(DefinitionHandler.FILENAME);
        if (!defFile.exists()) {
            DefinitionHandler handler = DefinitionHandler.getInstance();
            // TDQ-4714 update the aggregateDefinitions tag for some indicator definition.
            handler.updateAggregates();
        }
        ResourceService.refreshStructure();
    } catch (Exception ex) {
        ExceptionHandler.process(ex);
        ProxyRepositoryManager.getInstance().save();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Folder(org.talend.core.model.repository.Folder) IFolder(org.eclipse.core.resources.IFolder) RepositoryNodeBuilder(org.talend.dataprofiler.core.ui.views.provider.RepositoryNodeBuilder) DefinitionHandler(org.talend.dq.indicators.definitions.DefinitionHandler) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) PersistenceException(org.talend.commons.exception.PersistenceException) CorePlugin(org.talend.dataprofiler.core.CorePlugin) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Plugin(org.eclipse.core.runtime.Plugin)

Example 29 with Folder

use of org.talend.core.model.repository.Folder in project tdq-studio-se by Talend.

the class CreateMatchRuleFolderTask method doExecute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.migration.AMigrationTask#doExecute()
     */
@Override
protected boolean doExecute() throws Exception {
    Folder rulesMatchFoler = ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.TDQ_RULES, Path.EMPTY, EResourceConstant.RULES_MATCHER.getName());
    rulesMatchFoler.getProperty().getItem().getState().setPath(ERepositoryObjectType.TDQ_RULES_SQL.getFolder());
    return ResourceManager.getRulesMatcherFolder().exists();
}
Also used : Folder(org.talend.core.model.repository.Folder)

Example 30 with Folder

use of org.talend.core.model.repository.Folder in project tdq-studio-se by Talend.

the class RepositoryNodeBuilder method createRepositoryNodeSubSystemFolder.

/**
 * create repository node for sub system folder
 *
 * @param node create repository node
 * @param resConstant sub folder type
 * @return sub node
 * @throws PersistenceException
 */
public RepositoryNode createRepositoryNodeSubSystemFolder(RepositoryNode node, EResourceConstant resConstant, org.talend.core.model.general.Project currentProject) throws PersistenceException {
    IRepositoryViewObject folder = null;
    ERepositoryObjectType repositoryObjectType = retrieveRepObjectTypeByPath(resConstant.getPath());
    FolderItem folderItem = ProxyRepositoryFactory.getInstance().getFolderItem(currentProject, repositoryObjectType, Path.EMPTY);
    if (folderItem != null) {
        folder = new Folder(folderItem.getProperty(), repositoryObjectType);
    } else {
        folder = ProxyRepositoryFactory.getInstance().createFolder(retrieveRepObjectTypeByPath(getParentPath(resConstant.getPath())), Path.EMPTY, resConstant.getName());
    }
    return createRepositoryNode(folder, node, resConstant, currentProject);
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFolder(org.eclipse.core.resources.IFolder) Folder(org.talend.core.model.repository.Folder)

Aggregations

Folder (org.talend.core.model.repository.Folder)45 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)34 IFolder (org.eclipse.core.resources.IFolder)16 FolderItem (org.talend.core.model.properties.FolderItem)10 ArrayList (java.util.ArrayList)9 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 IPath (org.eclipse.core.runtime.IPath)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)7 PersistenceException (org.talend.commons.exception.PersistenceException)5 File (java.io.File)4 IContainer (org.eclipse.core.resources.IContainer)4 IProject (org.eclipse.core.resources.IProject)4 Path (org.eclipse.core.runtime.Path)4 Item (org.talend.core.model.properties.Item)4 IFile (org.eclipse.core.resources.IFile)3 Project (org.talend.core.model.general.Project)3 ItemState (org.talend.core.model.properties.ItemState)3 Property (org.talend.core.model.properties.Property)3 IOException (java.io.IOException)2