Search in sources :

Example 1 with ItemState

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

the class BusinessDiagramEditor method isLastVersion.

@Override
public boolean isLastVersion(Item item) {
    if (lastVersion != null) {
        return lastVersion;
    }
    if (item.getProperty() != null) {
        try {
            List<IRepositoryViewObject> allVersion = null;
            ItemState state = item.getState();
            ERepositoryObjectType type = ERepositoryObjectType.BUSINESS_PROCESS;
            if (type != null && state != null && state.getPath() != null) {
                allVersion = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAllVersion(item.getProperty().getId(), state.getPath(), type);
            } else {
                allVersion = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAllVersion(item.getProperty().getId());
            }
            if (allVersion == null || allVersion.isEmpty()) {
                return false;
            }
            String lastVersion = VersionUtils.DEFAULT_VERSION;
            for (IRepositoryViewObject object : allVersion) {
                if (VersionUtils.compareTo(object.getVersion(), lastVersion) > 0) {
                    lastVersion = object.getVersion();
                }
            }
            if (VersionUtils.compareTo(item.getProperty().getVersion(), lastVersion) == 0) {
                return true;
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
    return false;
}
Also used : ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 2 with ItemState

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

the class VersionManagementPage method updateItemsVersion.

@Override
protected void updateItemsVersion() {
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items version", checkedObjects.size());
                    Map<String, String> versions = new HashMap<String, String>();
                    for (int i = 0; i < checkedObjects.size(); i++) {
                        ItemVersionObject object = checkedObjects.get(i);
                        versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
                    }
                    for (ItemVersionObject object : checkedObjects) {
                        IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                        if (repositoryObject != null && repositoryObject.getProperty() != null) {
                            if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
                                final Item item = object.getItem();
                                Property itemProperty = item.getProperty();
                                itemProperty.setVersion(object.getNewVersion());
                                monitor.subTask(itemProperty.getLabel());
                                try {
                                    // for bug 12853 ,version management doesn't work for joblet because eResource
                                    // is null
                                    IRepositoryViewObject obj = null;
                                    if (itemProperty.eResource() == null) {
                                        ItemState state = item.getState();
                                        if (state != null && state.getPath() != null) {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
                                        } else {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId());
                                        }
                                    }
                                    if (obj != null) {
                                        // obj.setVersion(object.getNewVersion());
                                        FACTORY.save(project, obj.getProperty());
                                        builder.addOrUpdateItem(obj.getProperty().getItem(), true);
                                    } else {
                                        String id = itemProperty.getId();
                                        FACTORY.save(project, itemProperty);
                                        if (versionLatest.getSelection()) {
                                            builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
                                        }
                                        builder.addOrUpdateItem(item, true);
                                    }
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                            }
                        }
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ItemState(org.talend.core.model.properties.ItemState) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) Property(org.talend.core.model.properties.Property)

Example 3 with ItemState

use of org.talend.core.model.properties.ItemState 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 4 with ItemState

use of org.talend.core.model.properties.ItemState in project tesb-studio-se by Talend.

the class RouteResourcesHelper method getClasspathUrl.

public static String getClasspathUrl(Item item) {
    String classPathUrl;
    ItemState state = item.getState();
    String path = state.getPath();
    if (path != null && !path.isEmpty()) {
        classPathUrl = path + "/" + getFileName(item);
    } else {
        classPathUrl = getFileName(item);
    }
    return classPathUrl;
}
Also used : ItemState(org.talend.core.model.properties.ItemState)

Example 5 with ItemState

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

the class FixUnevenItemContextParametersMigrationTaskTest method createTempProcessItem.

private ProcessItem createTempProcessItem() throws PersistenceException {
    ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
    Property myProperty = PropertiesFactory.eINSTANCE.createProperty();
    myProperty.setId(ProxyRepositoryFactory.getInstance().getNextId());
    ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    itemState.setPath("");
    processItem.setState(itemState);
    processItem.setProperty(myProperty);
    myProperty.setLabel("myJob");
    myProperty.setVersion("0.1");
    processItem.setProcess(TalendFileFactory.eINSTANCE.createProcessType());
    ProxyRepositoryFactory.getInstance().create(processItem, new Path(""));
    return processItem;
}
Also used : Path(org.eclipse.core.runtime.Path) ProcessItem(org.talend.core.model.properties.ProcessItem) ItemState(org.talend.core.model.properties.ItemState) Property(org.talend.core.model.properties.Property)

Aggregations

ItemState (org.talend.core.model.properties.ItemState)10 Property (org.talend.core.model.properties.Property)7 Path (org.eclipse.core.runtime.Path)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 Item (org.talend.core.model.properties.Item)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 EObject (org.eclipse.emf.ecore.EObject)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TableItem (org.eclipse.swt.widgets.TableItem)1