Search in sources :

Example 56 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class ImportItemUtil method checkItem.

private boolean checkItem(ItemRecord itemRecord, boolean overwrite) {
    boolean result = false;
    try {
        Item item = itemRecord.getItem();
        if (item instanceof TDQItem) {
            // hide tdq first
            return false;
        }
        ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
        if (itemType == null) {
            //$NON-NLS-1$
            itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
            // can't import this item.
            return false;
        }
        cache.initialize(itemType);
        boolean isAllowMultipleName = (itemType == ERepositoryObjectType.SQLPATTERNS || itemType == ERepositoryObjectType.METADATA_FILE_XML);
        String itemPath = null;
        if (item.getState() != null) {
            itemPath = item.getState().getPath();
        } else {
            itemRecord.addError(Messages.getString("ImportItemUtil.unsupportItem"));
            return false;
        }
        boolean nameAvailable = true;
        IRepositoryViewObject itemWithSameId = null;
        IRepositoryViewObject itemWithSameName = null;
        // take care, in cache it's RepositoryViewObject, not RepositoryObject
        for (IRepositoryViewObject current : cache.getItemsFromRepository().get(itemType)) {
            final Property property = itemRecord.getProperty();
            if (property != null) {
                if (property.getLabel() != null && property.getLabel().equalsIgnoreCase(current.getLabel()) && property.getId() != current.getId()) {
                    // repository.
                    if (!isAllowMultipleName || current.getPath().equals(itemPath)) {
                        nameAvailable = false;
                    }
                    // elements
                    if (!nameAvailable) {
                        itemWithSameName = current;
                    }
                }
                if (property.getId() != null && property.getId().equalsIgnoreCase(current.getId())) {
                    itemWithSameId = current;
                }
            }
        }
        itemRecord.setExistingItemWithSameId(itemWithSameId);
        boolean idAvailable = itemWithSameId == null;
        boolean isSystem = false;
        // we do not import built in routines
        if (item.eClass().equals(PropertiesPackage.eINSTANCE.getRoutineItem())) {
            RoutineItem routineItem = (RoutineItem) item;
            if (routineItem.isBuiltIn()) {
                isSystem = true;
            }
        }
        // we do not import system sql patterns
        if (item.eClass().equals(PropertiesPackage.eINSTANCE.getSQLPatternItem())) {
            SQLPatternItem sqlPatternItem = (SQLPatternItem) item;
            if (sqlPatternItem.isSystem()) {
                isSystem = true;
            }
        }
        if (isSystem) {
            itemRecord.addError(Messages.getString("RepositoryUtil.isSystem"));
            return false;
        }
        if (nameAvailable) {
            if (idAvailable) {
                if (!isSystem) {
                    result = true;
                }
            /*
                       * else { itemRecord.addError(Messages.getString("RepositoryUtil.isSystemRoutine")); //$NON-NLS-1$
                       * }
                       */
            } else {
                // same id but different name,no need to care overwrite cause the item will be considered as a
                // different one,see bug 20445
                itemRecord.setState(State.ID_EXISTED);
                // if (overwrite) {
                // result = true;
                // } else {
                // see bug 0005222: [Import items] [Errors and Warnings]
                // id is already in use
                result = true;
            // RepositoryNode nodeWithSameId = RepositoryNodeUtilities.getRepositoryNode(itemWithSameId);
            // IPath path = getPath(nodeWithSameId);
            // itemRecord.addError(Messages.getString(
            //                                "RepositoryUtil.idUsed", itemWithSameId.getLabel(), path.toOSString())); //$NON-NLS-1$
            // }
            }
        } else {
            if (idAvailable) {
                // same name but different id
                itemRecord.setState(State.NAME_EXISTED);
                if (!isSystem && overwrite) {
                    // if anything system, don't replace the source item if same name.
                    // if not from system, can overwrite.
                    itemRecord.setExistingItemWithSameId(itemWithSameName);
                    result = true;
                }
                // if item is locked, cannot overwrite
                if (result && overwrite && itemWithSameName != null) {
                    ERepositoryStatus status = itemWithSameName.getRepositoryStatus();
                    if (status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
                        //$NON-NLS-1$
                        itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
                        return false;
                    }
                }
            } else {
                // same name and same id
                itemRecord.setState(State.NAME_AND_ID_EXISTED);
                if (overwrite) {
                    result = true;
                }
                if (!isSystem && overwrite && !itemWithSameName.getProperty().getLabel().equals(itemWithSameId.getProperty().getLabel())) {
                    // if anything system, don't replace the source item if same name.
                    // if not from system, can overwrite.
                    itemRecord.setExistingItemWithSameId(itemWithSameName);
                    result = true;
                }
            }
            if (!result && !isSystem) {
                //$NON-NLS-1$
                itemRecord.addError(Messages.getString("RepositoryUtil.nameUsed"));
            }
        }
        if (result && overwrite && itemRecord.getState() == State.NAME_AND_ID_EXISTED) {
            // if item is locked, cannot overwrite
            if (checkIfLocked(itemRecord)) {
                //$NON-NLS-1$
                itemRecord.addError(Messages.getString("RepositoryUtil.itemLocked"));
                result = false;
            }
        }
    } catch (Exception e) {
        log.error("Error when checking item :" + itemRecord.getPath(), e);
    }
    return result;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TDQItem(org.talend.core.model.properties.TDQItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 57 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class QueryNodeTester method findParentItemType.

@Override
public ERepositoryObjectType findParentItemType(RepositoryNode repositoryNode) {
    final ERepositoryObjectType objectType = repositoryNode.getObjectType();
    if (objectType == ERepositoryObjectType.METADATA_CON_QUERY) {
        final IRepositoryViewObject object = repositoryNode.getObject();
        if (object != null && object instanceof QueryRepositoryObject) {
            final QueryRepositoryObject queryObj = (QueryRepositoryObject) object;
            final IRepositoryViewObject viewObject = queryObj.getViewObject();
            if (viewObject != null) {
                return viewObject.getRepositoryObjectType();
            }
        }
    }
    return null;
}
Also used : QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 58 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class SchemaColumnNodeTester method findParentItemType.

@Override
public ERepositoryObjectType findParentItemType(RepositoryNode repositoryNode) {
    final ERepositoryObjectType objectType = repositoryNode.getObjectType();
    if (objectType == ERepositoryObjectType.METADATA_CON_COLUMN) {
        final IRepositoryViewObject object = repositoryNode.getObject();
        if (object != null && object instanceof MetadataColumnRepositoryObject) {
            final MetadataColumnRepositoryObject columnObj = (MetadataColumnRepositoryObject) object;
            final IRepositoryViewObject itemObj = columnObj.getViewObject();
            if (itemObj != null) {
                return itemObj.getRepositoryObjectType();
            }
        }
    }
    return null;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 59 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class PaletteSettingPage method addUsedComponents.

private void addUsedComponents(Set<IComponent> components, List<IRepositoryViewObject> allProcess, ComponentCategory category) {
    for (IRepositoryViewObject object : allProcess) {
        Item item = object.getProperty().getItem();
        List parameters = null;
        ProcessType processType = null;
        if (item instanceof ProcessItem) {
            processType = ((ProcessItem) item).getProcess();
        } else if (item instanceof JobletProcessItem) {
            processType = ((JobletProcessItem) item).getJobletProcess();
        }
        if (processType != null) {
            for (Object oNode : processType.getNode()) {
                NodeType node = (NodeType) oNode;
                IComponent component = ComponentsFactoryProvider.getInstance().get(node.getComponentName(), category.getName());
                if (component != null && component.getComponentType() == EComponentType.EMF) {
                    components.add(component);
                }
            }
            if (processType.getParameters() != null) {
                // occurs actually only in joblets
                parameters = processType.getParameters().getElementParameter();
            }
        }
        if (parameters != null) {
            // used in stats&log and implicite
            Set<IComponent> inStatsLogsAndImplicit = getComponentsInStatsLogsAndImplicit(parameters);
            if (inStatsLogsAndImplicit != null) {
                components.addAll(inStatsLogsAndImplicit);
            }
        }
    }
}
Also used : RootPaletteItem(org.talend.repository.preference.palettesettings.RootPaletteItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) FolderPaletteItem(org.talend.repository.preference.palettesettings.FolderPaletteItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) List(java.util.List) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 60 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class AbstractVersionManagementProjectSettingPage method selectSubjob.

protected void selectSubjob() {
    List<ItemVersionObject> jobList = new ArrayList<ItemVersionObject>();
    for (ItemVersionObject object : checkedObjects) {
        if (MavenVersionUtils.isHasSubjobType(ERepositoryObjectType.getItemType(object.getItem()))) {
            jobList.add(object);
        }
    }
    for (ItemVersionObject object : jobList) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsJobRelatedTo(object.getRepositoryNode().getId(), object.getItem().getProperty().getVersion(), RelationshipItemBuilder.JOB_RELATION);
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = FACTORY.getLastVersion(relation.getId());
                    if (obj != null) {
                        for (ItemVersionObject obj2 : versionObjects) {
                            if (obj2.getItem() == obj.getProperty().getItem()) {
                                ItemVersionObject relat = obj2;
                                if (!checkedObjects.contains(relat)) {
                                    checkedObjects.add(relat);
                                    checkAllVerSionLatest(checkedObjects, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    refreshTableItems();
    refreshCheckedTreeView();
}
Also used : Relation(org.talend.core.model.relationship.Relation) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Aggregations

IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)222 PersistenceException (org.talend.commons.exception.PersistenceException)115 Item (org.talend.core.model.properties.Item)86 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)67 ArrayList (java.util.ArrayList)63 ConnectionItem (org.talend.core.model.properties.ConnectionItem)54 ProcessItem (org.talend.core.model.properties.ProcessItem)54 RepositoryNode (org.talend.repository.model.RepositoryNode)50 IElementParameter (org.talend.core.model.process.IElementParameter)43 Property (org.talend.core.model.properties.Property)43 IRepositoryNode (org.talend.repository.model.IRepositoryNode)33 List (java.util.List)32 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)32 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)31 INode (org.talend.core.model.process.INode)30 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)25 Node (org.talend.designer.core.ui.editor.nodes.Node)25 Connection (org.talend.core.model.metadata.builder.connection.Connection)23 CoreException (org.eclipse.core.runtime.CoreException)17 RoutineItem (org.talend.core.model.properties.RoutineItem)17