Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions component-studio-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@
<version>${studio.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.talend.studio</groupId>
<artifactId>org.talend.repository</artifactId>
<version>${studio.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.talend.studio</groupId>
<artifactId>org.talend.repository.view</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def dependencies = [
'org.talend.common.ui.runtime',
'org.talend.maven.resolver',
'org.talend.core.repository',
'org.talend.repository',
'org.talend.repository.view',
'org.talend.repository.view.di',
'org.talend.designer.core.generic',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.talend.sdk.component.studio.metadata;

import java.util.HashMap;
import java.util.Map;

import org.talend.core.model.components.IComponent;
Expand All @@ -30,6 +31,12 @@ public class TaCoKitCache {

private Map<String, ConfigTypeNode> configTypeNodeMapCache;

/**
* Stores family ConfigTypeNode. A key represents family name. Value - family ConfigTypeNode
* It is initialized and filled up lazily
*/
private Map<String, ConfigTypeNode> familyConfigTypes;

public TaCoKitCache() {
// nothing to do
}
Expand All @@ -45,6 +52,61 @@ public ConfigTypeNode getFamilyNode(final ConfigTypeNode configNode) {
return getFamilyNode(getConfigTypeNodeMap().get(parentId));
}

/**
* Retrieves ConfigTypeNode from cache for specified parameters
*
* @param familyName ConfigTypeNode family name
* @param nodeName ConfigTypeNode name
* @param configurationType ConfigTypeNode type, either dataset or datastore
* @return ConfigTypeNode for specified parameters
*/
public ConfigTypeNode getConfigTypeNode(final String familyName, final String nodeName,
final String configurationType) {
if (familyConfigTypes == null) {
fillFamilyConfig();
}
return findConfigTypeNode(familyConfigTypes.get(familyName), nodeName, configurationType);
}

/**
* Finds only family ConfigTypeNode and puts them to {@link #familyConfigTypes}
*/
private void fillFamilyConfig() {
Map<String, ConfigTypeNode> allNodes = getConfigTypeNodeMap();
familyConfigTypes = new HashMap<>();
allNodes.values().stream().filter(c -> c.getParentId() == null).forEach(
c -> familyConfigTypes.put(c.getName(), c));
}

/**
* Finds required ConfigTypeNode by its name and configuration types (dataset or datastore) in ConfigTypeNode tree.
*
* @param current a node which is visited
* @param nodeName a node name of required ConfigTypeNode
* @param configurationType configuration type of required ConfigTypeNode. It makes sense,
* when datastore and dataset may have the same name within one component family
* @return required ConfigTypeNode
*/
private ConfigTypeNode findConfigTypeNode(final ConfigTypeNode current, final String nodeName,
final String configurationType) {
// node is found
if (current.getName().equals(nodeName) && current.getConfigurationType().equals(configurationType)) {
return current;
}
// it is leaf, but node wasn't found in this branch
if (current.getEdges().isEmpty()) {
return null;
}
for (String edge : current.getEdges()) {
ConfigTypeNode node = findConfigTypeNode(configTypeNodeMapCache.get(edge), nodeName, configurationType);
if (node != null) {
return node;
}
}
// node wasn't found at all
return null;
}

public ConfigTypeNodes getConfigTypeNodes() {
if (configTypeNodesCache == null) {
configTypeNodesCache = Lookups.client().v1().configurationType().getRepositoryModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.talend.core.model.properties.Property;
import org.talend.core.model.repository.AbstractRepositoryContentHandler;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.model.repository.IRepositoryTypeProcessor;
import org.talend.core.model.repository.IRepositoryViewObject;
import org.talend.core.model.repository.RepositoryViewObject;
import org.talend.core.repository.model.ProxyRepositoryFactory;
Expand Down Expand Up @@ -160,6 +161,31 @@ public ERepositoryObjectType getRepositoryObjectType(final Item item) {
return type;
}

/**
* Checks whether {@code repositoryType} belongs to TaCoKit and creates RepositoryTypeProcessor if it is true
* RepositoryTypeProcessor implements repository tree filtering logic, which allows to show only repository nodes,
* which are related to the component, in repository review dialog.
*
* @param repositoryType a String, which represents supported repository nodes types
* @return RepositoryTypeProcessor or null, it repository type doesn't belong to TaCoKit
*/
@Override
public IRepositoryTypeProcessor getRepositoryTypeProcessor(final String repositoryType) {
if (isTaCoKitRepositoryType(repositoryType)) {
if (repositoryType.contains("|")) {
return new TaCoKitTypeProcessor(repositoryType.split("\\|"));
} else {
return new TaCoKitTypeProcessor(new String[] { repositoryType });
}
} else {
return null;
}
}

private boolean isTaCoKitRepositoryType(final String repositoryType) {
return repositoryType != null && repositoryType.startsWith(TaCoKitConst.METADATA_TACOKIT_PREFIX);
}

@Override
public IImage getIcon(final ERepositoryObjectType type) {
if (TaCoKitUtil.isTaCoKitType(type)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (C) 2006-2018 Talend Inc. - www.talend.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.talend.sdk.component.studio.metadata.handler;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.jface.viewers.Viewer;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.repository.model.IRepositoryNode.EProperties;
import org.talend.repository.model.RepositoryNode;
import org.talend.repository.ui.processor.MultiTypesProcessor;
import org.talend.sdk.component.studio.metadata.node.TaCoKitFamilyRepositoryNode;

/**
* TaCoKit specific TypeProcessor. TypeProcessor filters repository in Repository Review dialog.
* It allows to show only nodes related to component
*/
public class TaCoKitTypeProcessor extends MultiTypesProcessor {

public TaCoKitTypeProcessor(final String[] repositoryTypes) {
super(repositoryTypes);
}

/**
* Returns repository object types supported by current component
*
* @return types supported by the component
*/
@Override
protected List<ERepositoryObjectType> getTypes() {
return Arrays.stream(getRepositoryTypes()).map(ERepositoryObjectType::getTypeFromKey).collect(
Collectors.toList());
}

@Override
protected boolean selectRepositoryNode(final Viewer viewer, final RepositoryNode parentNode,
final RepositoryNode node) {
if (node instanceof TaCoKitFamilyRepositoryNode) {
TaCoKitFamilyRepositoryNode tacokitNode = (TaCoKitFamilyRepositoryNode) node;
ERepositoryObjectType type = tacokitNode.getChildrenObjectType();
for (String repositoryType : getRepositoryTypes()) {
if (repositoryType.startsWith(type.getKey())) {
return true;
}
}
}
ERepositoryObjectType nodeObjectType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
if (getShowRootTypes().contains(nodeObjectType)) {
return true;
}
return false;
}

}
Loading