Search in sources :

Example 46 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class RemoveBinFolderMigrationTask method execute.

@Override
public ExecutionResult execute(Project project) {
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
    IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
    for (ERepositoryObjectType type : getTypes()) {
        IFolder folder = null;
        if (type != null && type.hasFolder()) {
            try {
                IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
                if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
                    continue;
                }
                folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                for (IResource current : ResourceUtils.getMembers(folder)) {
                    if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
                        for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
                            if (fileCurrent instanceof IFile) {
                                if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
                                    Property property = null;
                                    try {
                                        property = xmiResourceManager.loadProperty(fileCurrent);
                                    } catch (RuntimeException e) {
                                        // property will be null
                                        ExceptionHandler.process(e);
                                    }
                                    if (property != null) {
                                        // restore folder if doesn't exist anymore.
                                        Item propertyItem = property.getItem();
                                        propertyItem.getState().setDeleted(true);
                                        EmfHelper.saveResource(propertyItem.eResource());
                                        String oldPath = propertyItem.getState().getPath();
                                        IPath path = new Path(oldPath);
                                        factory.createParentFoldersRecursively(project, type, path, true);
                                        FolderItem folderItem = factory.getFolderItem(project, type, path);
                                        propertyItem.setParent(folderItem);
                                        String name = fileCurrent.getName().replace(".properties", "");
                                        // take all the files starting by the same name
                                        IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                                        for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
                                            if (filesToMove.getName().startsWith(name)) {
                                                IPath originalPath = filesToMove.getFullPath();
                                                IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
                                                if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
                                                    // if the file exists in both bin and target directory, delete
                                                    // the one from bin.
                                                    filesToMove.delete(true, new NullProgressMonitor());
                                                } else {
                                                    ResourceUtils.moveResource(filesToMove, finalPath);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
                        if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
                            try {
                                ((IFolder) current).delete(true, null);
                            } catch (CoreException e) {
                            // not catched, not important if can delete or not
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            } catch (CoreException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    // }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) FolderItem(org.talend.core.model.properties.FolderItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 47 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class ReadRoutineAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    if (repositoryNode == null && getSelection() != null) {
        repositoryNode = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    }
    RoutineItem routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
    Property updatedProperty = null;
    try {
        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(routineItem)), routineItem.getProperty().getId()).getProperty();
    // repositoryNode.getObject().setProperty(updatedProperty);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
    try {
        openRoutineEditor(routineItem, true);
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : Project(org.talend.core.model.general.Project) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) RoutineItem(org.talend.core.model.properties.RoutineItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property)

Example 48 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class DateSection method getCommitDate.

protected Date getCommitDate() {
    Property property = getObject().getProperty();
    if (property == null || property.getItem() == null) {
        return null;
    }
    Item item = property.getItem();
    ItemState state = item.getState();
    return state.getCommitDate();
}
Also used : Item(org.talend.core.model.properties.Item) ItemState(org.talend.core.model.properties.ItemState) Property(org.talend.core.model.properties.Property)

Example 49 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class BDJobReArchieveCreator method create.

public void create(File file, boolean isExport) {
    if (file == null || !file.exists() || (isExport && !file.isFile()) || fatherProcessItem == null) {
        return;
    }
    // check
    if (!isMRWithHDInsight() && !isFatJar()) {
        return;
    }
    Property property = processItem.getProperty();
    Property fatherProperty = fatherProcessItem.getProperty();
    String label = property.getLabel();
    String fatherLabel = fatherProperty.getLabel();
    String version = property.getVersion();
    JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(file.getAbsolutePath(), label);
    String jobJarName = JavaResourcesHelper.getJobJarName(property.getLabel(), property.getVersion()) + FileExtensions.JAR_FILE_SUFFIX;
    try {
        if (isExport) {
            // If we are in an export context, we first unzip the archive, then we modify the jar.
            // create temp folders.
            // clean temp folder
            creator.deleteTempFiles();
            //$NON-NLS-1$ //$NON-NLS-2$
            File zipTmpFolder = new File(creator.getTmpFolder(), "zip-" + label + "_" + version);
            //$NON-NLS-1$ //$NON-NLS-2$
            File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
            zipTmpFolder.mkdirs();
            jarTmpFolder.mkdirs();
            // unzip the files.
            FilesUtils.unzip(file.getAbsolutePath(), zipTmpFolder.getAbsolutePath());
            // same the the job pom assembly for package.
            File originalJarFile = new File(zipTmpFolder, fatherLabel + '/' + jobJarName);
            modifyJar(originalJarFile, jarTmpFolder, creator, jobJarName, zipTmpFolder, property);
            ZipToFile.zipFile(zipTmpFolder.getAbsolutePath(), file.getAbsolutePath());
        } else {
            // If we are in a local context, we just have to modify the jar.
            // clean temp folder
            creator.deleteTempFiles();
            //$NON-NLS-1$ //$NON-NLS-2$
            File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
            jarTmpFolder.mkdirs();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
                File targetFolder = new File(talendProcessJavaProject.getTargetFolder().getLocationURI());
                // In a local mode, the routines/beans/udfs jars are not in the lib folder. We then copy them.
                // Copy routines and rename it to match the
                // "JavaUtils.ROUTINE_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX" name
                Set<FilterInfo> codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.ROUTINE_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.ROUTINE_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                // Copy beans and rename it to match the "JavaUtils.BEANS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
                // name
                codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.BEANS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.BEANS_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                // Copy udfs and rename it to match the
                // "JavaUtils.PIGUDFS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
                // name
                codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.PIGUDFS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.PIGUDFS_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                modifyJar(new File(file, jobJarName), jarTmpFolder, creator, jobJarName, talendProcessJavaProject.getLibFolder().getParent().getLocation().toFile(), property);
            } else {
                //$NON-NLS-1$
                CommonExceptionHandler.log("Unable to update the job jar because the RunProcessService is not registered.");
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        // when debug, keep the files first. because when build again. will do clean also.
        if (!CommonsPlugin.isDebugMode()) {
            creator.deleteTempFiles();
        }
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) Property(org.talend.core.model.properties.Property) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) FilterInfo(org.talend.utils.files.FilterInfo) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 50 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class ChangeValuesFromRepositoryTest method setUp.

/**
     * DOC Administrator Comment method "setUp".
     *
     * @throws java.lang.Exception
     */
@Before
public void setUp() throws Exception {
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    IProcess2 process = new Process(property);
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    IComponent targetCom = ComponentsFactoryProvider.getInstance().get("tMysqlOutput", ComponentCategory.CATEGORY_4_DI.getName());
    elem = new Node(sourceCom, process);
    elem.setLabel("tMysqlInput_1");
    target = new Node(targetCom, process);
    IMetadataTable table = createSimpleMetadata();
    table.setAttachedConnector("FLOW");
    List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
    metadataList.add(table);
    elem.setMetadataList(metadataList);
    Connection conn = new Connection(elem, target, EConnectionType.FLOW_MAIN, "FLOW", "metaName", "row1", false);
    List<Connection> connList = new ArrayList<Connection>();
    connList.add(conn);
    target.setIncomingConnections(connList);
    elem.setOutgoingConnections(connList);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IProcess2(org.talend.core.model.process.IProcess2) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) Property(org.talend.core.model.properties.Property) Before(org.junit.Before)

Aggregations

Property (org.talend.core.model.properties.Property)147 PersistenceException (org.talend.commons.exception.PersistenceException)56 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)48 Item (org.talend.core.model.properties.Item)46 ProcessItem (org.talend.core.model.properties.ProcessItem)39 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)36 Node (org.talend.designer.core.ui.editor.nodes.Node)28 Process (org.talend.designer.core.ui.editor.process.Process)23 RepositoryNode (org.talend.repository.model.RepositoryNode)22 IElementParameter (org.talend.core.model.process.IElementParameter)21 ConnectionItem (org.talend.core.model.properties.ConnectionItem)21 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)21 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)19 INode (org.talend.core.model.process.INode)19 IComponent (org.talend.core.model.components.IComponent)15 Connection (org.talend.core.model.metadata.builder.connection.Connection)14 IProcess2 (org.talend.core.model.process.IProcess2)14 List (java.util.List)12 IFile (org.eclipse.core.resources.IFile)12