Search in sources :

Example 6 with Relation

use of org.talend.core.model.relationship.Relation in project tdi-studio-se by Talend.

the class VersionManagementPage method versionLatest.

private void versionLatest() {
    List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
    tableList.addAll(checkedObjects);
    for (ItemVersionObject object : checkedObjects) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsJobRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), 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 (!tableList.contains(relat)) {
                                    tableList.add(relat);
                                    checkAllVerSionLatest(tableList, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    removeItemElements(checkedObjects);
    checkedObjects.clear();
    checkedObjects.addAll(tableList);
    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)

Example 7 with Relation

use of org.talend.core.model.relationship.Relation in project tdi-studio-se by Talend.

the class VersionManagementPage method selectAllDependencies.

private void selectAllDependencies() {
    List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
    tableList.addAll(checkedObjects);
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
    for (ItemVersionObject object : checkedObjects) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), RelationshipItemBuilder.JOB_RELATION);
            for (Relation relation : relations) {
                IRepositoryViewObject obj = null;
                try {
                    if (RelationshipItemBuilder.ROUTINE_RELATION.equals(relation.getType())) {
                        obj = RoutinesUtil.getRoutineFromName(relation.getId());
                    } else {
                        obj = factory.getLastVersion(relation.getId());
                    }
                    if (obj != null) {
                        for (ItemVersionObject obj2 : versionObjects) {
                            if (obj2.getItem() == obj.getProperty().getItem()) {
                                ItemVersionObject relat = obj2;
                                if (!tableList.contains(relat)) {
                                    tableList.add(relat);
                                    checkAllVerSionLatest(tableList, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    removeItemElements(checkedObjects);
    checkedObjects.clear();
    checkedObjects.addAll(tableList);
    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) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with Relation

use of org.talend.core.model.relationship.Relation in project tdi-studio-se by Talend.

the class TosTokenCollector method collectProjectDetails.

private JSONObject collectProjectDetails() throws PersistenceException, JSONException {
    JSONObject jObject = new JSONObject();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    JSONObject repoStats = new JSONObject();
    // metadata
    for (DynaEnum type : ERepositoryObjectType.values()) {
        if (type instanceof ERepositoryObjectType && ((ERepositoryObjectType) type).isResourceItem()) {
            try {
                List<IRepositoryViewObject> all = factory.getAll(currentProject, (ERepositoryObjectType) type);
                int nb = all.size();
                if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_PATTERN_ELEMENT.equals(type) || ERepositoryObjectType.TDQ_RULES.equals(type) || "TDQ_SOURCE_FILE_ELEMENT".equals(type.getType())) {
                    //$NON-NLS-1$
                    continue;
                }
                if (ERepositoryObjectType.ROUTINES.equals(type)) {
                    nb = 0;
                    List<IRepositoryViewObject> newList = new ArrayList<IRepositoryViewObject>();
                    for (IRepositoryViewObject object : all) {
                        RoutineItem rItem = (RoutineItem) object.getProperty().getItem();
                        if (!rItem.isBuiltIn()) {
                            nb++;
                            newList.add(object);
                        }
                    }
                    all = newList;
                }
                if (ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        SQLPatternItem spItem = (SQLPatternItem) object.getProperty().getItem();
                        if (!spItem.isSystem()) {
                            nb++;
                        }
                    }
                }
                if ("MDM.DataModel".equals(type.getType())) {
                    //$NON-NLS-1$
                    nb = 0;
                    for (IRepositoryViewObject object : all) {
                        String path = object.getProperty().getItem().getState().getPath();
                        if (!"System".equals(path)) {
                            //$NON-NLS-1$
                            nb++;
                        }
                    }
                }
                if (nb > 0) {
                    JSONObject typeStats = new JSONObject();
                    //$NON-NLS-1$
                    typeStats.put("nb", nb);
                    if (ERepositoryObjectType.getAllTypesOfProcess().contains(type)) {
                        JSONObject jobDetails = new JSONObject();
                        collectJobDetails(all, jobDetails);
                        //$NON-NLS-1$
                        typeStats.put("details", jobDetails);
                    }
                    if (ERepositoryObjectType.ROUTINES.equals(type) || //$NON-NLS-1$
                    ((ERepositoryObjectType) type).getFolder().startsWith("metadata/") || ERepositoryObjectType.CONTEXT.equals(type) || type.equals(ERepositoryObjectType.JOBLET)) {
                        int nbUsed = 0;
                        for (IRepositoryViewObject object : all) {
                            List<Relation> relations = RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getId());
                            relations.addAll(RelationshipItemBuilder.getInstance().getItemsHaveRelationWith(object.getLabel()));
                            if (relations.size() > 0) {
                                nbUsed++;
                            }
                        }
                        //$NON-NLS-1$
                        typeStats.put("nb.used", nbUsed);
                    }
                    if (ERepositoryObjectType.METADATA_CONNECTIONS.equals(type)) {
                        JSONObject objects = new JSONObject();
                        for (IRepositoryViewObject object : all) {
                            DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
                            String dbType = ((DatabaseConnection) item.getConnection()).getDatabaseType();
                            int nbDbTypes = 1;
                            if (objects.has(dbType)) {
                                nbDbTypes = objects.getInt(dbType);
                                nbDbTypes++;
                            }
                            objects.put(dbType, nbDbTypes);
                        }
                        //$NON-NLS-1$
                        typeStats.put("types", objects);
                    }
                    repoStats.put(type.getType(), typeStats);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    //$NON-NLS-1$
    jObject.put(PROJECTS.getKey(), repoStats);
    jObject.put(TYPE.getKey(), ProjectManager.getInstance().getProjectType(currentProject));
    int nbRef = ProjectManager.getInstance().getAllReferencedProjects().size();
    if (nbRef > 0) {
        jObject.put("nb.refProjects", nbRef);
    }
    return jObject;
}
Also used : DynaEnum(org.talend.core.model.repository.DynaEnum) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) JSONException(us.monoid.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Project(org.talend.core.model.general.Project) Relation(org.talend.core.model.relationship.Relation) JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 9 with Relation

use of org.talend.core.model.relationship.Relation in project tdi-studio-se by Talend.

the class MapperSchemaTypeItemRelationshipHandler method collect.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.core.model.relationship.AbstractItemRelationshipHandler#collect(org.talend.core.model.properties.Item)
     */
@Override
protected Set<Relation> collect(Item baseItem) {
    ProcessType processType = getProcessType(baseItem);
    if (processType == null) {
        return Collections.emptySet();
    }
    Set<Relation> relationSet = new HashSet<Relation>();
    // handle tMap schema relations...
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
        IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
        for (Object o : processType.getNode()) {
            if (o instanceof NodeType) {
                NodeType currentNode = (NodeType) o;
                AbstractExternalData nodeData = currentNode.getNodeData();
                if (nodeData != null) {
                    List<String> schemaIds = service.getRepositorySchemaIds(nodeData);
                    if (schemaIds != null && schemaIds.size() > 0) {
                        for (String schemaId : schemaIds) {
                            Relation addedRelation = new Relation();
                            addedRelation.setId(schemaId);
                            addedRelation.setType(RelationshipItemBuilder.SCHEMA_RELATION);
                            addedRelation.setVersion(RelationshipItemBuilder.LATEST_VERSION);
                            relationSet.add(addedRelation);
                        }
                    }
                }
            }
        }
    }
    return relationSet;
}
Also used : IDesignerMapperService(org.talend.core.service.IDesignerMapperService) AbstractExternalData(org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) Relation(org.talend.core.model.relationship.Relation) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) HashSet(java.util.HashSet)

Example 10 with Relation

use of org.talend.core.model.relationship.Relation in project tdi-studio-se by Talend.

the class SqlTemplateParameterRelationshipHandler method collect.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.relationship.AbstractParameterRelationshipHandler#collect(java.util.Map,
     * java.util.Map)
     */
@Override
protected Set<Relation> collect(Map<String, ElementParameterType> parametersMap, Map<?, ?> options) {
    Set<Relation> relationSet = new HashSet<Relation>();
    //$NON-NLS-1$
    ElementParameterType sqlpatternParamType = parametersMap.get("SQLPATTERN_VALUE");
    // only for SQL Patterns
    if (sqlpatternParamType != null) {
        for (Object o3 : sqlpatternParamType.getElementValue()) {
            if (o3 instanceof ElementValueType && "SQLPATTERNLIST".equals(((ElementValueType) o3).getElementRef())) {
                //$NON-NLS-1$
                Relation addedRelation = new Relation();
                addedRelation.setId(((ElementValueType) o3).getValue());
                addedRelation.setType(RelationshipItemBuilder.SQLPATTERN_RELATION);
                addedRelation.setVersion(RelationshipItemBuilder.LATEST_VERSION);
                relationSet.add(addedRelation);
            }
        }
    }
    return relationSet;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Relation(org.talend.core.model.relationship.Relation) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) HashSet(java.util.HashSet)

Aggregations

Relation (org.talend.core.model.relationship.Relation)10 PersistenceException (org.talend.commons.exception.PersistenceException)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 ArrayList (java.util.ArrayList)5 ItemVersionObject (org.talend.repository.model.ItemVersionObject)4 HashSet (java.util.HashSet)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BidiMap (org.apache.commons.collections.BidiMap)1 TableItem (org.eclipse.swt.widgets.TableItem)1 PartInitException (org.eclipse.ui.PartInitException)1 Project (org.talend.core.model.general.Project)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 Item (org.talend.core.model.properties.Item)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1