http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/TaxonomyResourceProvider.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/TaxonomyResourceProvider.java b/catalog/src/main/java/org/apache/atlas/catalog/TaxonomyResourceProvider.java deleted file mode 100644 index b59dcae..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/TaxonomyResourceProvider.java +++ /dev/null @@ -1,215 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog; - -import org.apache.atlas.ApplicationProperties; -import org.apache.atlas.AtlasException; -import org.apache.atlas.catalog.definition.TaxonomyResourceDefinition; -import org.apache.atlas.catalog.exception.*; -import org.apache.atlas.catalog.query.AtlasQuery; -import org.apache.commons.configuration.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * Provider for taxonomy resources. - */ -public class TaxonomyResourceProvider extends BaseResourceProvider implements ResourceProvider { - private static final Logger LOG = LoggerFactory.getLogger(TaxonomyResourceProvider.class); - public static final String DEFAULT_TAXONOMY_NAME = "Catalog"; - public static final String DEFAULT_TAXONOMY_DESCRIPTION = "Business Catalog"; - - public static final String NAMESPACE_ATTRIBUTE_NAME = "taxonomy.namespace"; - - // Taxonomy Term type - public static final String TAXONOMY_TERM_TYPE = "TaxonomyTerm"; - - // Taxonomy Namespace - public static final String TAXONOMY_NS = "atlas.taxonomy"; - - private final TermResourceProvider termResourceProvider; - - // This is a cached value to prevent checking for taxonomy objects in every API call. - // It is updated once per lifetime of the application. - // TODO: If a taxonomy is deleted outside of this application, this value is not updated - // TODO: and there is no way in which a taxonomy will be auto-created. - // TODO: Assumption is that if a taxonomy is deleted externally, it will be created externally as well. - private static boolean taxonomyAutoInitializationChecked = false; - - public TaxonomyResourceProvider(AtlasTypeSystem typeSystem) { - super(typeSystem, new TaxonomyResourceDefinition()); - termResourceProvider = new TermResourceProvider(typeSystem); - } - - @Override - public Result getResourceById(Request request) throws ResourceNotFoundException { - synchronized (TaxonomyResourceProvider.class) { - createDefaultTaxonomyIfNeeded(); - } - return doGetResourceById(request); - } - - @Override - public Result getResources(Request request) throws InvalidQueryException, ResourceNotFoundException { - synchronized (TaxonomyResourceProvider.class) { - createDefaultTaxonomyIfNeeded(); - } - return doGetResources(request); - } - - @Override - public void createResource(Request request) - throws InvalidPayloadException, ResourceAlreadyExistsException { - - // not checking for default taxonomy in create per requirements - resourceDefinition.validateCreatePayload(request); - synchronized (TaxonomyResourceProvider.class) { - ensureTaxonomyDoesntExist(request); - doCreateResource(request); - } - } - - @Override - public Collection<String> createResources(Request request) throws InvalidQueryException, ResourceNotFoundException { - throw new UnsupportedOperationException( - "Creating multiple Taxonomies in a request is not currently supported"); - } - - @Override - public void deleteResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException { - String taxonomyId = getResourceId(request); - getTermResourceProvider().deleteChildren(taxonomyId, new TermPath(request.<String>getProperty("name"))); - typeSystem.deleteEntity(resourceDefinition, request); - } - - @Override - public void updateResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException { - resourceDefinition.validateUpdatePayload(request); - - AtlasQuery atlasQuery; - try { - atlasQuery = queryFactory.createTaxonomyQuery(request); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Unable to compile internal Term query: " + e, e); - } - - synchronized (TaxonomyResourceProvider.class) { - createDefaultTaxonomyIfNeeded(); - if (atlasQuery.execute(request.getUpdateProperties()).isEmpty()) { - throw new ResourceNotFoundException(String.format("Taxonomy '%s' not found.", - request.getQueryProperties().get("name"))); - } - } - } - - private String getResourceId(Request request) throws ResourceNotFoundException { - request.addAdditionalSelectProperties(Collections.singleton("id")); - // will result in expected ResourceNotFoundException if taxonomy doesn't exist - Result result = getResourceById(request); - return String.valueOf(result.getPropertyMaps().iterator().next().get("id")); - } - - //todo: this is currently required because the expected exception isn't thrown by the Atlas repository - //todo: when an attempt is made to create an entity that already exists - // must be called from within class monitor - private void ensureTaxonomyDoesntExist(Request request) throws ResourceAlreadyExistsException { - try { - doGetResourceById(request); - throw new ResourceAlreadyExistsException(String.format("Taxonomy '%s' already exists.", - request.getProperty("name"))); - } catch (ResourceNotFoundException e) { - // expected case - } - } - - // must be called from within class monitor - private Result doGetResourceById(Request request) throws ResourceNotFoundException { - AtlasQuery atlasQuery; - try { - atlasQuery = queryFactory.createTaxonomyQuery(request); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Unable to compile internal Taxonomy query: " + e, e); - } - - Collection<Map<String, Object>> resultSet = atlasQuery.execute(); - if (resultSet.isEmpty()) { - throw new ResourceNotFoundException(String.format("Taxonomy '%s' not found.", - request.getProperty(resourceDefinition.getIdPropertyName()))); - } - return new Result(resultSet); - } - - // must be called from within class monitor - private Result doGetResources(Request request) throws InvalidQueryException, ResourceNotFoundException { - AtlasQuery atlasQuery = queryFactory.createTaxonomyQuery(request); - return new Result(atlasQuery.execute()); - } - - // must be called from within class monitor - private void doCreateResource(Request request) throws ResourceAlreadyExistsException { - typeSystem.createEntity(resourceDefinition, request); - taxonomyAutoInitializationChecked = true; - } - - // must be called from within class monitor - private void createDefaultTaxonomyIfNeeded() { - if (! autoInitializationChecked()) { - try { - LOG.info("Checking if default taxonomy needs to be created."); - // if any business taxonomy has been created, don't create one more - hence searching to - // see if any taxonomy exists. - if (doGetResources(new CollectionRequest(null, null)).getPropertyMaps().isEmpty()) { - LOG.info("No taxonomies found - going to create default taxonomy."); - Map<String, Object> requestProperties = new HashMap<>(); - String defaultTaxonomyName = DEFAULT_TAXONOMY_NAME; - try { - Configuration configuration = ApplicationProperties.get(); - defaultTaxonomyName = configuration.getString("atlas.taxonomy.default.name", - defaultTaxonomyName); - } catch (AtlasException e) { - LOG.warn("Unable to read Atlas configuration, will use {} as default taxonomy name", - defaultTaxonomyName, e); - } - requestProperties.put("name", defaultTaxonomyName); - requestProperties.put("description", DEFAULT_TAXONOMY_DESCRIPTION); - - doCreateResource(new InstanceRequest(requestProperties)); - LOG.info("Successfully created default taxonomy {}.", defaultTaxonomyName); - } else { - taxonomyAutoInitializationChecked = true; - LOG.info("Some taxonomy exists, not creating default taxonomy"); - } - } catch (InvalidQueryException | ResourceNotFoundException e) { - LOG.error("Unable to query for existing taxonomies due to internal error.", e); - } catch (ResourceAlreadyExistsException e) { - LOG.info("Attempted to create default taxonomy and it already exists."); - } - } - } - - protected boolean autoInitializationChecked() { - return taxonomyAutoInitializationChecked; - } - - protected TermResourceProvider getTermResourceProvider() { - return termResourceProvider; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/TermPath.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/TermPath.java b/catalog/src/main/java/org/apache/atlas/catalog/TermPath.java deleted file mode 100644 index 3252227..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/TermPath.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog; - -/** - * Term path information. - */ -//todo: split between Term and TermPath -public class TermPath { - private final String m_taxonomy; - private final String m_fqn; - private final String m_name; - private final String[] m_paths; - - public TermPath(String fullyQualifiedName) { - m_fqn = fullyQualifiedName; - //todo: validation - int idx = fullyQualifiedName.indexOf('.'); - if (idx != -1) { - m_taxonomy = fullyQualifiedName.substring(0, idx); - m_name = fullyQualifiedName.substring(idx + 1); - m_paths = m_name.split("\\."); - } else { - m_taxonomy = fullyQualifiedName; - m_name = null; - m_paths = new String[0]; - } - } - - public TermPath(String taxonomyName, String termName) { - m_taxonomy = taxonomyName; - m_name = termName != null && termName.isEmpty() ? null : termName; - - if (m_name != null) { - m_fqn = String.format("%s.%s", taxonomyName, termName); - m_paths = termName.split("\\."); - } else { - m_fqn = taxonomyName; - m_paths = new String[0]; - } - } - - /** - * Get the absolute term name which is in the form of TAXONOMY_NAME.TERM_NAME - * - * @return absolute term name which includes the taxonomy name - */ - public String getFullyQualifiedName() { - return m_fqn; - } - - /** - * Get the term name. This differs from the absolute name in that it doesn't - * include the taxonomy name. - * - * @return the term name - */ - public String getName() { - return m_name; - } - - /** - * Get the short name for the term which doesn't include any taxonomy or parent information. - * @return term short name - */ - public String getShortName() { - return m_paths[m_paths.length - 1]; - } - - public String getPath() { - if (m_name == null) { - return "/"; - } else { - int idx = m_fqn.indexOf('.'); - int lastIdx = m_fqn.lastIndexOf('.'); - - return idx == lastIdx ? "/" : - m_fqn.substring(idx, lastIdx).replaceAll("\\.", "/"); - } - } - - public TermPath getParent() { - //todo: if this is the root path, throw exception - return new TermPath(m_taxonomy, m_name.substring(0, m_name.lastIndexOf('.'))); - } - - - public String getTaxonomyName() { - return m_taxonomy; - } - - public String[] getPathSegments() { - return m_paths; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/TermResourceProvider.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/TermResourceProvider.java b/catalog/src/main/java/org/apache/atlas/catalog/TermResourceProvider.java deleted file mode 100644 index 3202d04..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/TermResourceProvider.java +++ /dev/null @@ -1,252 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog; - -import org.apache.atlas.catalog.definition.TermResourceDefinition; -import org.apache.atlas.catalog.exception.*; -import org.apache.atlas.catalog.query.AtlasQuery; - -import java.util.*; - -/** - * Provider for Term resources. - */ -public class TermResourceProvider extends BaseResourceProvider implements ResourceProvider { - private ResourceProvider taxonomyResourceProvider; - private ResourceProvider entityResourceProvider; - private ResourceProvider entityTagResourceProvider; - - public TermResourceProvider(AtlasTypeSystem typeSystem) { - super(typeSystem, new TermResourceDefinition()); - } - - @Override - public Result getResourceById(Request request) throws ResourceNotFoundException { - //todo: shouldn't need to add this here - request.getQueryProperties().put("name", request.<TermPath>getProperty("termPath").getFullyQualifiedName()); - AtlasQuery atlasQuery; - try { - atlasQuery = queryFactory.createTermQuery(request); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Unable to compile internal Term query: " + e, e); - } - Collection<Map<String, Object>> results = atlasQuery.execute(); - if (results.isEmpty()) { - throw new ResourceNotFoundException(String.format("Term '%s' not found.", - request.<TermPath>getProperty("termPath").getFullyQualifiedName())); - } - return new Result(results); - } - - public Result getResources(Request request) - throws InvalidQueryException, ResourceNotFoundException { - - TermPath termPath = request.getProperty("termPath"); - String queryString = doQueryStringConversions(termPath, request.getQueryString()); - Request queryRequest = new CollectionRequest(request.getQueryProperties(), queryString); - AtlasQuery atlasQuery = queryFactory.createTermQuery(queryRequest); - Collection<Map<String, Object>> result = atlasQuery.execute(); - return new Result(result); - } - - public void createResource(Request request) - throws InvalidPayloadException, ResourceAlreadyExistsException, ResourceNotFoundException { - - TermPath termPath = (TermPath) request.getQueryProperties().remove("termPath"); - String qualifiedTermName = termPath.getFullyQualifiedName(); - request.getQueryProperties().put("name", qualifiedTermName); - resourceDefinition.validateCreatePayload(request); - - // get taxonomy - Request taxonomyRequest = new InstanceRequest( - Collections.<String, Object>singletonMap("name", termPath.getTaxonomyName())); - taxonomyRequest.addAdditionalSelectProperties(Collections.singleton("id")); - Result taxonomyResult = getTaxonomyResourceProvider().getResourceById(taxonomyRequest); - Map<String, Object> taxonomyPropertyMap = taxonomyResult.getPropertyMaps().iterator().next(); - - // ensure that parent exists if not a root level term - if (! termPath.getPath().equals("/")) { - Map<String, Object> parentProperties = new HashMap<>(request.getQueryProperties()); - parentProperties.put("termPath", termPath.getParent()); - getResourceById(new InstanceRequest(parentProperties)); - } - - typeSystem.createTraitType(resourceDefinition, qualifiedTermName, - request.<String>getProperty("description")); - - typeSystem.createTraitInstance(String.valueOf(taxonomyPropertyMap.get("id")), - qualifiedTermName, request.getQueryProperties()); - } - - @Override - public Collection<String> createResources(Request request) throws InvalidQueryException, ResourceNotFoundException { - throw new UnsupportedOperationException("Creating multiple Terms in a request is not currently supported"); - } - - @Override - public void updateResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException { - resourceDefinition.validateUpdatePayload(request); - String termName = request.<TermPath>getProperty("termPath").getFullyQualifiedName(); - request.getQueryProperties().put("name", termName); - AtlasQuery atlasQuery; - try { - atlasQuery = queryFactory.createTermQuery(request); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Unable to compile internal Term query: " + e, e); - } - Map<String, Object> updateProperties = request.getUpdateProperties(); - Collection<Map<String, Object>> results = atlasQuery.execute(updateProperties); - if (results.isEmpty()) { - throw new ResourceNotFoundException(String.format("Term '%s' not found.", - termName)); - } - // only the term 'description' property is set on entity tags - if (updateProperties.containsKey("description")) { - // 'description' property is being updated so we need to update tags - String tagQueryString = String.format("name:%s", termName); - Request tagRequest = new CollectionRequest( - Collections.<String, Object>singletonMap("id", "*"), tagQueryString, null); - AtlasQuery tagQuery; - try { - tagQuery = queryFactory.createEntityTagQuery(tagRequest); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Unable to compile internal Entity Tag query: " + e, e); - } - tagQuery.execute(Collections.singletonMap("description", updateProperties.get("description"))); - } - } - - @Override - public void deleteResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException { - // will result in expected ResourceNotFoundException if term doesn't exist - getResourceById(request); - - TermPath termPath = (TermPath) request.getQueryProperties().get("termPath"); - String taxonomyId = getTaxonomyId(termPath); - deleteChildren(taxonomyId, termPath); - deleteTerm(taxonomyId, termPath); - } - - protected void deleteChildren(String taxonomyId, TermPath termPath) - throws ResourceNotFoundException, InvalidPayloadException { - - TermPath collectionTermPath = new TermPath(termPath.getFullyQualifiedName() + "."); - Request queryRequest = new CollectionRequest(Collections.<String, Object>singletonMap("termPath", - collectionTermPath), null); - - AtlasQuery collectionQuery; - try { - collectionQuery = queryFactory.createTermQuery(queryRequest); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException("Failed to compile internal predicate: " + e, e); - } - - Collection<Map<String, Object>> children = collectionQuery.execute(); - for (Map<String, Object> childMap : children) { - deleteTerm(taxonomyId, new TermPath(String.valueOf(childMap.get("name")))); - } - } - - private void deleteTerm(String taxonomyId, TermPath termPath) - throws ResourceNotFoundException, InvalidPayloadException { - - String fullyQualifiedName = termPath.getFullyQualifiedName(); - deleteEntityTagsForTerm(fullyQualifiedName); - - // delete term instance associated with the taxonomy - typeSystem.deleteTag(taxonomyId, fullyQualifiedName); - //todo: Currently no way to delete type via MetadataService or MetadataRepository - } - - private void deleteEntityTagsForTerm(String fullyQualifiedName) throws ResourceNotFoundException { - String entityQueryStr = String.format("tags/name:%s", fullyQualifiedName); - Request entityRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), entityQueryStr); - Result entityResult; - try { - entityResult = getEntityResourceProvider().getResources(entityRequest); - } catch (InvalidQueryException e) { - throw new CatalogRuntimeException(String.format( - "Failed to compile internal predicate for query '%s': %s", entityQueryStr, e), e); - } - - for (Map<String, Object> entityResultMap : entityResult.getPropertyMaps()) { - Map<String, Object> tagRequestProperties = new HashMap<>(); - tagRequestProperties.put("id", String.valueOf(entityResultMap.get("id"))); - tagRequestProperties.put("name", fullyQualifiedName); - try { - getEntityTagResourceProvider().deleteResourceById(new InstanceRequest(tagRequestProperties)); - } catch (InvalidPayloadException e) { - throw new CatalogRuntimeException( - "An internal error occurred while trying to delete an entity tag: " + e, e); - } - } - } - - private String getTaxonomyId(TermPath termPath) throws ResourceNotFoundException { - Request taxonomyRequest = new InstanceRequest(Collections.<String, Object>singletonMap( - "name", termPath.getTaxonomyName())); - taxonomyRequest.addAdditionalSelectProperties(Collections.singleton("id")); - // will result in proper ResourceNotFoundException if taxonomy doesn't exist - Result taxonomyResult = getTaxonomyResourceProvider().getResourceById(taxonomyRequest); - - Map<String, Object> taxonomyResultMap = taxonomyResult.getPropertyMaps().iterator().next(); - return String.valueOf(taxonomyResultMap.get("id")); - } - - //todo: add generic support for pre-query modification of expected value - //todo: similar path parsing code is used in several places in this class - private String doQueryStringConversions(TermPath termPath, String queryStr) throws InvalidQueryException { - String hierarchyPathProp = "hierarchy/path"; - // replace "." - if (queryStr != null && queryStr.contains(String.format("%s:.", hierarchyPathProp))) { - //todo: regular expression replacement - queryStr = queryStr.replaceAll(String.format("%s:.", hierarchyPathProp), - String.format("%s:%s", hierarchyPathProp, termPath.getPath())); - } - return queryStr; - } - - protected synchronized ResourceProvider getTaxonomyResourceProvider() { - if (taxonomyResourceProvider == null) { - taxonomyResourceProvider = new TaxonomyResourceProvider(typeSystem); - } - return taxonomyResourceProvider; - } - - protected synchronized ResourceProvider getEntityResourceProvider() { - if (entityResourceProvider == null) { - entityResourceProvider = new EntityResourceProvider(typeSystem); - } - return entityResourceProvider; - } - - protected synchronized ResourceProvider getEntityTagResourceProvider() { - if (entityTagResourceProvider == null) { - entityTagResourceProvider = new EntityTagResourceProvider(typeSystem); - } - return entityTagResourceProvider; - } -} - - - - - - - http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/TermVertexWrapper.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/TermVertexWrapper.java b/catalog/src/main/java/org/apache/atlas/catalog/TermVertexWrapper.java deleted file mode 100644 index 14fcca7..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/TermVertexWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog; - -import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.catalog.definition.EntityTagResourceDefinition; - -/** - * Wrapper for term vertices. - */ -public class TermVertexWrapper extends VertexWrapper { - - public TermVertexWrapper(Vertex v) { - super(v, new EntityTagResourceDefinition()); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/VertexWrapper.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/VertexWrapper.java b/catalog/src/main/java/org/apache/atlas/catalog/VertexWrapper.java deleted file mode 100644 index 966a3ae..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/VertexWrapper.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog; - -import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -import java.util.*; - -/** - * Wrapper for vertices which provides additional information. - */ -public class VertexWrapper { - private final Vertex vertex; - private final String vertexType; - private final Set<String> removedProperties = new HashSet<>(); - private final PropertyMapper propertyMapper; - private final Map<String, PropertyValueFormatter> propertyValueFormatters; - protected ResourceComparator resourceComparator = new ResourceComparator(); - - public VertexWrapper(Vertex v, ResourceDefinition resourceDefinition) { - this(v, resourceDefinition.getPropertyMapper(), resourceDefinition.getPropertyValueFormatters()); - } - - public VertexWrapper(Vertex v, - PropertyMapper mapper, - Map<String, PropertyValueFormatter> formatters) { - vertex = v; - vertexType = getVertexType(v); - propertyMapper = mapper; - propertyValueFormatters = formatters; - } - - public Vertex getVertex() { - return vertex; - } - - public <T> T getProperty(String name) { - T val; - if (removedProperties.contains(name)) { - val = null; - } else { - val = vertex.getProperty(propertyMapper.toFullyQualifiedName(name, vertexType)); - if (propertyValueFormatters.containsKey(name)) { - //todo: fix typing of property mapper - val = (T) propertyValueFormatters.get(name).format(val); - } - } - return val; - } - - public void setProperty(String name, Object value) { - vertex.setProperty(propertyMapper.toFullyQualifiedName(name, vertexType), value); - } - - public Collection<String> getPropertyKeys() { - Collection<String> propertyKeys = new TreeSet<>(resourceComparator); - - for (String p : vertex.getPropertyKeys()) { - String cleanName = propertyMapper.toCleanName(p, vertexType); - if (! removedProperties.contains(cleanName)) { - propertyKeys.add(cleanName); - } - } - return propertyKeys; - } - - public Map<String, Object> getPropertyMap() { - Map<String, Object> props = new TreeMap<>(resourceComparator); - for (String p : vertex.getPropertyKeys()) { - String cleanName = propertyMapper.toCleanName(p, vertexType); - if (! removedProperties.contains(cleanName)) { - Object val = vertex.getProperty(p); - if (propertyValueFormatters.containsKey(cleanName)) { - val = propertyValueFormatters.get(cleanName).format(val); - } - props.put(cleanName, val); - } - } - return props; - } - - public void removeProperty(String name) { - removedProperties.add(name); - } - - public boolean isPropertyRemoved(String name) { - return removedProperties.contains(name); - } - - public String toString() { - return String.format("VertexWrapper[name=%s]", getProperty("name")); - } - - private String getVertexType(Vertex v) { - return v.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/BaseResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/BaseResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/BaseResourceDefinition.java deleted file mode 100644 index 6a67b25..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/BaseResourceDefinition.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.catalog.*; -import org.apache.atlas.catalog.exception.CatalogRuntimeException; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.Relation; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.TypeSystem; - -import java.util.*; - -/** - * Base class for resource definitions. - */ -public abstract class BaseResourceDefinition implements ResourceDefinition { - protected static final TypeSystem typeSystem = TypeSystem.getInstance(); - - protected final Set<String> instanceProperties = new HashSet<>(); - protected final Set<String> collectionProperties = new HashSet<>(); - protected Map<String, AttributeDefinition> propertyDefs = new HashMap<>(); - protected Map<String, AttributeInfo> properties = new HashMap<>(); - - protected final Map<String, Projection> projections = new HashMap<>(); - protected final Map<String, Relation> relations = new HashMap<>(); - - protected final PropertyMapper propertyMapper; - protected final Map<String, PropertyValueFormatter> propertyValueFormatters = new HashMap<>(); - - - public BaseResourceDefinition() { - DefaultDateFormatter defaultDateFormatter = new DefaultDateFormatter(); - registerPropertyValueFormatter("creation_time", defaultDateFormatter); - registerPropertyValueFormatter("modified_time", defaultDateFormatter); - - this.propertyMapper = createPropertyMapper(); - } - - @Override - public void validateCreatePayload(Request request) throws InvalidPayloadException { - Collection<String> propKeys = new HashSet<>(request.getQueryProperties().keySet()); - Collection<String> missingProperties = new HashSet<>(); - for (AttributeInfo property : properties.values()) { - String name = property.name; - if (property.multiplicity == Multiplicity.REQUIRED) { - if (request.getProperty(name) == null) { - missingProperties.add(name); - } - } - propKeys.remove(name); - } - if (! missingProperties.isEmpty() || ! propKeys.isEmpty()) { - throw new InvalidPayloadException(missingProperties, propKeys); - } - //todo: property type validation - } - - @Override - public void validateUpdatePayload(Request request) throws InvalidPayloadException { - Collection<String> updateKeys = new HashSet<>(request.getUpdateProperties().keySet()); - Collection<String> validProperties = new HashSet<>(properties.keySet()); - // currently updating 'name' property for any resource is unsupported - validProperties.remove("name"); - updateKeys.removeAll(validProperties); - - if (! updateKeys.isEmpty()) { - throw new InvalidPayloadException(Collections.<String>emptySet(), updateKeys); - } - } - - @Override - public Collection<AttributeDefinition> getPropertyDefinitions() { - return propertyDefs.values(); - } - - @Override - public Map<String, Object> filterProperties(Request request, Map<String, Object> propertyMap) { - Request.Cardinality cardinality = request.getCardinality(); - Collection<String> requestProperties = request.getAdditionalSelectProperties(); - Iterator<Map.Entry<String, Object>> propIter = propertyMap.entrySet().iterator(); - while(propIter.hasNext()) { - Map.Entry<String, Object> propEntry = propIter.next(); - String prop = propEntry.getKey(); - if (! requestProperties.contains(prop)) { - if (cardinality == Request.Cardinality.COLLECTION) { - if (! collectionProperties.contains(prop)) { - propIter.remove(); - } - } else { - if (! instanceProperties.isEmpty() && ! instanceProperties.contains(prop)) { - propIter.remove(); - } - } - } - } - return propertyMap; - } - - @Override - public Map<String, Projection> getProjections() { - return projections; - } - - @Override - public Map<String, Relation> getRelations() { - return relations; - } - - - @Override - public synchronized PropertyMapper getPropertyMapper() { - return propertyMapper; - } - - @Override - public Map<String, PropertyValueFormatter> getPropertyValueFormatters() { - return propertyValueFormatters; - } - - protected void registerProperty(AttributeDefinition propertyDefinition) { - try { - propertyDefs.put(propertyDefinition.name, propertyDefinition); - properties.put(propertyDefinition.name, new AttributeInfo(typeSystem, propertyDefinition, null)); - } catch (AtlasException e) { - throw new CatalogRuntimeException("Unable to create attribute: " + propertyDefinition.name, e); - } - } - - protected void registerPropertyValueFormatter(String property, PropertyValueFormatter valueFormatter) { - propertyValueFormatters.put(property, valueFormatter); - } - - /** - * Create a new property mapper instance. - * Should be overridden in children where the default implementation isn't sufficient. - * - * @return a new property mapper instance - */ - protected PropertyMapper createPropertyMapper() { - return new DefaultPropertyMapper(); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityResourceDefinition.java deleted file mode 100644 index 052a21d..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityResourceDefinition.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.transform.TransformFunctionPipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.projection.*; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -/** - * Entity resource definition. - */ -public class EntityResourceDefinition extends BaseResourceDefinition { - public EntityResourceDefinition() { - collectionProperties.add("name"); - collectionProperties.add("id"); - collectionProperties.add("type"); - - RelationProjection tagProjection = getTagProjection(); - projections.put("tags", tagProjection); - RelationProjection traitProjection = getTraitProjection(); - projections.put("traits", traitProjection); - projections.put("default", getDefaultRelationProjection()); - - relations.put(tagProjection.getName(), tagProjection.getRelation()); - relations.put(traitProjection.getName(), traitProjection.getRelation()); - } - - @Override - public String getIdPropertyName() { - return "id"; - } - - // not meaningful for entities - @Override - public String getTypeName() { - return null; - } - - @Override - public void validateCreatePayload(Request request) throws InvalidPayloadException { - // no op for entities as we don't currently create entities and - // each entity type is different - } - - @Override - public String resolveHref(Map<String, Object> properties) { - Object id = properties.get("id"); - return id == null ? null : String.format("v1/entities/%s", id); - } - - private RelationProjection getTagProjection() { - Relation traitRelation = new TagRelation(); - RelationProjection tagProjection = new RelationProjection("tags", Collections.singleton("name"), - traitRelation, Projection.Cardinality.MULTIPLE); - tagProjection.addPipe(new TransformFunctionPipe<>( - new PipeFunction<Collection<ProjectionResult>, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(Collection<ProjectionResult> results) { - for (ProjectionResult result : results) { - for (Map<String, Object> properties : result.getPropertyMaps()) { - properties.put("href", String.format("v1/entities/%s/tags/%s", - result.getStartingVertex().getProperty("id"), properties.get("name"))); - } - } - return results; - } - })); - return tagProjection; - } - - private RelationProjection getTraitProjection() { - return new RelationProjection("traits", Collections.<String>emptySet(), - new TraitRelation(), Projection.Cardinality.MULTIPLE); - } - - private RelationProjection getDefaultRelationProjection() { - Relation genericRelation = new GenericRelation(this); - RelationProjection relationProjection = new RelationProjection( - "relations", - Arrays.asList("type", "id", "name"), - genericRelation, Projection.Cardinality.MULTIPLE); - - relationProjection.addPipe(new TransformFunctionPipe<>( - new PipeFunction<Collection<ProjectionResult>, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(Collection<ProjectionResult> results) { - for (ProjectionResult result : results) { - for (Map<String, Object> properties : result.getPropertyMaps()) { - properties.put("href", String.format("v1/entities/%s", properties.get("id"))); - } - } - return results; - } - })); - return relationProjection; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityTagResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityTagResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityTagResourceDefinition.java deleted file mode 100644 index c5a4213..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/EntityTagResourceDefinition.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.transform.TransformFunctionPipe; -import org.apache.atlas.catalog.DefaultPropertyMapper; -import org.apache.atlas.catalog.PropertyMapper; -import org.apache.atlas.catalog.ResourceComparator; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.ProjectionResult; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.utils.TypesUtil; - -import java.util.*; - -/** - * Entity Tag resource definition. - */ -public class EntityTagResourceDefinition extends BaseResourceDefinition { - public static final String ENTITY_GUID_PROPERTY = "entity-guid"; - - public EntityTagResourceDefinition() { - registerProperty(TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE)); - - instanceProperties.add("name"); - instanceProperties.add("description"); - instanceProperties.add("creation_time"); - - collectionProperties.add("name"); - collectionProperties.add("description"); - - projections.put("terms", getTermProjection()); - } - - @Override - public String getIdPropertyName() { - return "name"; - } - - //not meaningful for entity tags - @Override - public String getTypeName() { - return null; - } - - @Override - public String resolveHref(Map<String, Object> properties) { - return String.format("v1/entities/%s/tags/%s", properties.get(ENTITY_GUID_PROPERTY), properties.get("name")); - } - - private Projection getTermProjection() { - return new Projection("term", Projection.Cardinality.SINGLE, - new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(VertexWrapper start) { - Map<String, Object> map = new TreeMap<>(new ResourceComparator()); - - StringBuilder sb = new StringBuilder(); - sb.append("v1/taxonomies/"); - - String fullyQualifiedName = start.getVertex().getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - String[] paths = fullyQualifiedName.split("\\."); - // first path segment is the taxonomy - sb.append(paths[0]); - - for (int i = 1; i < paths.length; ++i) { - String path = paths[i]; - if (path != null && !path.isEmpty()) { - sb.append("/terms/"); - sb.append(path); - } - } - - map.put("href", sb.toString()); - return Collections.singleton(new ProjectionResult("term", start, - Collections.singleton(map))); - } - })); - } - - @Override - protected PropertyMapper createPropertyMapper() { - return new DefaultPropertyMapper(Collections.singletonMap(Constants.ENTITY_TYPE_PROPERTY_KEY, "name"), - Collections.singletonMap("name", Constants.ENTITY_TYPE_PROPERTY_KEY)); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/ResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/ResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/ResourceDefinition.java deleted file mode 100644 index a797f0b..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/ResourceDefinition.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import org.apache.atlas.catalog.PropertyMapper; -import org.apache.atlas.catalog.PropertyValueFormatter; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.Relation; -import org.apache.atlas.typesystem.types.AttributeDefinition; - -import java.util.Collection; -import java.util.Map; - -/** - * Resource definition. - */ -public interface ResourceDefinition { - /** - * The type name of the resource. - * - * @return the resources type name - */ - String getTypeName(); - - /** - * Validate a user create request payload. - * - * @param request user create request - * - * @throws InvalidPayloadException if the request payload is invalid in any way - */ - void validateCreatePayload(Request request) throws InvalidPayloadException; - - /** - * Validate a user update request payload. - * - * @param request user update request - * - * @throws InvalidPayloadException if the request payload is invalid in any way - */ - void validateUpdatePayload(Request request) throws InvalidPayloadException; - - /** - * Get the name of the resources id property. - * - * @return the id property name - */ - String getIdPropertyName(); - - /** - * Get the property definitions for the resource. - * - * @return resource property definitions - */ - //todo: abstract usage of AttributeDefinition - Collection<AttributeDefinition> getPropertyDefinitions(); - - /** - * Filter out properties which shouldn't be returned in the result. - * The passed in map is directly modified as well as returned. - * - * @param request user request - * @param propertyMap property map to filter - * - * @return the filtered property map - */ - Map<String, Object> filterProperties(Request request, Map<String, Object> propertyMap); - - /** - * Generate an href for the resource from the provided resource property map. - * - * @param properties resource property map - * - * @return a URL to be used as an href property value for the resource - */ - String resolveHref(Map<String, Object> properties); - - /** - * Get map of resource projections. - * - * @return map of resource projections - */ - Map<String, Projection> getProjections(); - - /** - * Get map of resource relations. - * - * @return map of resource relations - */ - Map<String, Relation> getRelations(); - - /** - * Get the property mapper associated with the resource. - * - * @return associated property mapper - */ - PropertyMapper getPropertyMapper(); - - /** - * Get the registered property value formatters. - * @return map of property name to property value formatter - */ - Map<String, PropertyValueFormatter> getPropertyValueFormatters(); -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/TaxonomyResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/TaxonomyResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/TaxonomyResourceDefinition.java deleted file mode 100644 index 434a189..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/TaxonomyResourceDefinition.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.transform.TransformFunctionPipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.TaxonomyResourceProvider; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.ProjectionResult; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.utils.TypesUtil; - -import java.util.*; - -/** - * Taxonomy resource definition. - */ -public class TaxonomyResourceDefinition extends BaseResourceDefinition { - public TaxonomyResourceDefinition() { - registerProperty(TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); - registerProperty(TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE)); - registerProperty(TypesUtil.createOptionalAttrDef(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, DataTypes.STRING_TYPE)); - - //todo: combine with above registrations - instanceProperties.add("name"); - instanceProperties.add("description"); - instanceProperties.add("creation_time"); - - collectionProperties.add("name"); - collectionProperties.add("description"); - - projections.put("terms", getTermsProjection()); - } - - @Override - public void validateCreatePayload(Request request) throws InvalidPayloadException { - super.validateCreatePayload(request); - if (String.valueOf(request.getQueryProperties().get("name")).contains(".")) { - throw new InvalidPayloadException("The \"name\" property may not contain the character '.'"); - } - } - - @Override - public String getTypeName() { - return "Taxonomy"; - } - - @Override - public String getIdPropertyName() { - return "name"; - } - - @Override - public String resolveHref(Map<String, Object> properties) { - return String.format("v1/taxonomies/%s", properties.get("name")); - } - - private Projection getTermsProjection() { - final String termsProjectionName = "terms"; - return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, - new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() { - private String baseHref = "v1/taxonomies/"; - @Override - public Collection<ProjectionResult> compute(VertexWrapper v) { - Map<String, Object> map = new HashMap<>(); - map.put("href", baseHref + v.getProperty("name") + "/terms"); - return Collections.singleton(new ProjectionResult(termsProjectionName, v, - Collections.singleton(map))); - } - })); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/definition/TermResourceDefinition.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/definition/TermResourceDefinition.java b/catalog/src/main/java/org/apache/atlas/catalog/definition/TermResourceDefinition.java deleted file mode 100644 index 51ef65a..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/definition/TermResourceDefinition.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.definition; - -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.transform.TransformFunctionPipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.ResourceComparator; -import org.apache.atlas.catalog.TermPath; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.ProjectionResult; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.typesystem.types.*; -import org.apache.atlas.typesystem.types.utils.TypesUtil; - -import java.util.*; - -/** - * Term resource definition. - */ -public class TermResourceDefinition extends BaseResourceDefinition { - public TermResourceDefinition() { - registerProperty(TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE)); - registerProperty(TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE)); - registerProperty(TypesUtil.createOptionalAttrDef("available_as_tag", DataTypes.BOOLEAN_TYPE)); - registerProperty(TypesUtil.createOptionalAttrDef("acceptable_use", DataTypes.STRING_TYPE)); - - instanceProperties.add("name"); - instanceProperties.add("description"); - instanceProperties.add("creation_time"); - instanceProperties.add("available_as_tag"); - instanceProperties.add("acceptable_use"); - - collectionProperties.add("name"); - collectionProperties.add("description"); - - projections.put("terms", getSubTermProjection()); - projections.put("hierarchy", getHierarchyProjection()); - } - - @Override - public void validateCreatePayload(Request request) throws InvalidPayloadException { - super.validateCreatePayload(request); - - String name = request.getProperty("name"); - // name will be in the fully qualified form: taxonomyName.termName - if (! name.contains(".")) { - throw new InvalidPayloadException("Term name must be in the form 'taxonomyName.termName.subTermName'"); - } - - if (! request.getQueryProperties().containsKey("available_as_tag")) { - request.getQueryProperties().put("available_as_tag", true); - } - } - - @Override - public String getTypeName() { - return "Term"; - } - - @Override - public String getIdPropertyName() { - return "name"; - } - - //todo - @Override - public String resolveHref(Map<String, Object> properties) { - StringBuilder sb = new StringBuilder(); - sb.append("v1/taxonomies/"); - - TermPath termPath = new TermPath(String.valueOf(properties.get("name"))); - String[] paths = termPath.getPathSegments(); - sb.append(termPath.getTaxonomyName()); - - for (String path : paths) { - //todo: shouldn't need to check for null or empty after TermPath addition - if (path != null && !path.isEmpty()) { - sb.append("/terms/"); - sb.append(path); - } - } - - return sb.toString(); - } - - private Projection getHierarchyProjection() { - final String projectionName = "hierarchy"; - return new Projection(projectionName, Projection.Cardinality.SINGLE, - new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(VertexWrapper start) { - Map<String, Object> map = new TreeMap<>(new ResourceComparator()); - - TermPath termPath = new TermPath(start.getVertex().<String>getProperty( - Constants.ENTITY_TYPE_PROPERTY_KEY)); - - map.put("path", termPath.getPath()); - map.put("short_name", termPath.getShortName()); - map.put("taxonomy", termPath.getTaxonomyName()); - - return Collections.singleton(new ProjectionResult(projectionName, start, - Collections.singleton(map))); - } - })); - - } - - private Projection getSubTermProjection() { - //todo: combine with other term projections - final String termsProjectionName = "terms"; - return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, - new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(VertexWrapper start) { - Map<String, Object> map = new TreeMap<>(new ResourceComparator()); - - StringBuilder sb = new StringBuilder(); - sb.append("v1/taxonomies/"); - - TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY)); - String[] paths = termPath.getPathSegments(); - sb.append(termPath.getTaxonomyName()); - - for (String path : paths) { - //todo: shouldn't need to check for null or empty after TermPath addition - if (path != null && !path.isEmpty()) { - sb.append("/terms/"); - sb.append(path); - } - } - sb.append("/terms"); - - map.put("href", sb.toString()); - return Collections.singleton(new ProjectionResult(termsProjectionName, start, - Collections.singleton(map))); - } - })); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogException.java deleted file mode 100644 index 7bb2f7b..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogException.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -/** - * Base checked catalog exception. - */ -public class CatalogException extends Exception { - - private int status; - - public CatalogException(String message, int status) { - super(message); - this.status = status; - } - - public int getStatus() { - return status; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogRuntimeException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogRuntimeException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogRuntimeException.java deleted file mode 100644 index 51fd7af..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/CatalogRuntimeException.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -/** - * Base runtime catalog exception. - */ -public class CatalogRuntimeException extends RuntimeException { - int statusCode = 500; - - public CatalogRuntimeException(Exception e) { - super("", e); - } - - public CatalogRuntimeException(String message, Exception e) { - super(message, e); - } - - public CatalogRuntimeException(String message, int statusCode) { - super(message); - this.statusCode = statusCode; - } - - public int getStatusCode() { - return statusCode; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidPayloadException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidPayloadException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidPayloadException.java deleted file mode 100644 index 34c5ab5..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidPayloadException.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -import java.util.Collection; - -/** - * Exception used for invalid API payloads. - */ -public class InvalidPayloadException extends CatalogException { - private final static String baseMsg = "Invalid Request."; - private final static String missingMsg = " The following required properties are missing: %s."; - private final static String unknownMsg = " The following properties are not supported: %s"; - - public InvalidPayloadException(Collection<String> missingProperties, Collection<String> unknownProperties) { - super(baseMsg + (!missingProperties.isEmpty() ? String.format(missingMsg, missingProperties): "") + - (!unknownProperties.isEmpty() ? String.format(unknownMsg, unknownProperties): ""), 400); - } - - public InvalidPayloadException(String msg) { - super(msg, 400); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidQueryException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidQueryException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidQueryException.java deleted file mode 100644 index a7abe23..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/InvalidQueryException.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -/** - * Exception for invalid user query. - */ -public class InvalidQueryException extends CatalogException { - public InvalidQueryException(String message) { - super("Unable to parse query: " + message, 400); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceAlreadyExistsException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceAlreadyExistsException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceAlreadyExistsException.java deleted file mode 100644 index d7670c1..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceAlreadyExistsException.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -/** - * Exception used when an attempt is made to create a resource which already exists. - */ -public class ResourceAlreadyExistsException extends CatalogException { - public ResourceAlreadyExistsException(String message) { - super(message, 409); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceNotFoundException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceNotFoundException.java b/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceNotFoundException.java deleted file mode 100644 index 0307137..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/exception/ResourceNotFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.exception; - -/** - * Exception used when an explicitly requested resource doesn't exist. - */ -public class ResourceNotFoundException extends CatalogException { - public ResourceNotFoundException(String message) { - super(message, 404); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/BaseRelation.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/BaseRelation.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/BaseRelation.java deleted file mode 100644 index 03f4f50..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/BaseRelation.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.projection; - -import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.typesystem.persistence.Id; - -/** - * Provides functionality common across implementations. - */ -public abstract class BaseRelation implements Relation { - protected boolean isDeleted(Vertex v) { - return ! Id.EntityState.ACTIVE.name().equals( - v.<String>getProperty(Constants.STATE_PROPERTY_KEY)); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/GenericRelation.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/GenericRelation.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/GenericRelation.java deleted file mode 100644 index 2cccd81..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/GenericRelation.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.projection; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * Represents a generic relation - */ -public class GenericRelation extends BaseRelation { - private final ResourceDefinition resourceDefinition; - - public GenericRelation(ResourceDefinition resourceDefinition) { - this.resourceDefinition = resourceDefinition; - } - - @Override - public Collection<RelationSet> traverse(VertexWrapper vWrapper) { - Collection<RelationSet> relations = new ArrayList<>(); - Vertex v = vWrapper.getVertex(); - String vertexType = v.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - Map<String, Collection<VertexWrapper>> vertexMap = new HashMap<>(); - for (Edge e : v.getEdges(Direction.OUT)) { - String edgeLabel = e.getLabel(); - String edgePrefix = String.format("%s%s.", Constants.INTERNAL_PROPERTY_KEY_PREFIX, vertexType); - if (edgeLabel.startsWith(edgePrefix)) { - Vertex adjacentVertex = e.getVertex(Direction.IN); - if (! isDeleted(adjacentVertex)) { - VertexWrapper relationVertex = new VertexWrapper(adjacentVertex, resourceDefinition); - String relationName = edgeLabel.substring(edgePrefix.length()); - Collection<VertexWrapper> vertices = vertexMap.get(relationName); - if (vertices == null) { - vertices = new ArrayList<>(); - vertexMap.put(relationName, vertices); - } - vertices.add(relationVertex); - } - } - } - for (Map.Entry<String, Collection<VertexWrapper>> entry : vertexMap.entrySet()) { - relations.add(new RelationSet(entry.getKey(), entry.getValue())); - } - return relations; - } - - @Override - public Pipe asPipe() { - return null; - } - - @Override - public ResourceDefinition getResourceDefinition() { - return resourceDefinition; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/Projection.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/Projection.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/Projection.java deleted file mode 100644 index daa1351..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/Projection.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.projection; - -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.util.Pipeline; -import org.apache.atlas.catalog.VertexWrapper; - -import java.util.Collection; -import java.util.Collections; - -/** - * Projection representation. - * Used to project properties onto a resource from another source. - */ -public class Projection { - public enum Cardinality {SINGLE, MULTIPLE} - - private final String m_name; - private final Cardinality m_cardinality; - protected Pipeline<VertexWrapper, Collection<ProjectionResult>> m_pipeline = new Pipeline<>(); - - public Projection(String name, Cardinality cardinality) { - m_name = name; - m_cardinality = cardinality; - } - - public Projection(String name, Cardinality cardinality, Pipe<VertexWrapper, Collection<ProjectionResult>> pipe) { - m_name = name; - m_cardinality = cardinality; - m_pipeline.addPipe(pipe); - } - - public Collection<ProjectionResult> values(VertexWrapper start) { - m_pipeline.setStarts(Collections.singleton(start)); - return m_pipeline.iterator().next(); - } - - public void addPipe(Pipe<Collection<ProjectionResult>, Collection<ProjectionResult>> p) { - m_pipeline.addPipe(p); - } - - public String getName() { - return m_name; - } - - public Cardinality getCardinality() { - return m_cardinality; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/ProjectionResult.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/ProjectionResult.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/ProjectionResult.java deleted file mode 100644 index 7b12e2d..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/ProjectionResult.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.apache.atlas.catalog.projection; - -import org.apache.atlas.catalog.VertexWrapper; - -import java.util.Collection; -import java.util.Map; - -/** - * Result of a projection. - */ -public class ProjectionResult { - private final VertexWrapper m_startVertex; - private final String m_name; - private final Collection<Map<String, Object>> m_propertyMaps; - - public ProjectionResult(String name, VertexWrapper startingVertex, Collection<Map<String, Object>> propertyMaps) { - m_name = name; - m_startVertex = startingVertex; - m_propertyMaps = propertyMaps; - } - - public String getName() { - return m_name; - } - - public VertexWrapper getStartingVertex() { - return m_startVertex; - } - - public Collection<Map<String, Object>> getPropertyMaps() { - return m_propertyMaps; - } -}
