http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/Relation.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/Relation.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/Relation.java deleted file mode 100644 index b19bc15..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/Relation.java +++ /dev/null @@ -1,53 +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 org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; - -import java.util.Collection; - -/** - * Represents the relationship from one vertex to another via an edge. - */ -public interface Relation { - /** - * Traverse the relation. - * - * @param vWrapper vertex to start traversal from - * - * @return results of the traversal - */ - Collection<RelationSet> traverse(VertexWrapper vWrapper); - - /** - * Get the pipe representation of the traversal. - * - * @return pipe representation - */ - Pipe asPipe(); - - /** - * Get the associated resource definition. - * - * @return associated resource definition - */ - ResourceDefinition getResourceDefinition(); -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationProjection.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationProjection.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationProjection.java deleted file mode 100644 index e435628..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationProjection.java +++ /dev/null @@ -1,69 +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.PipeFunction; -import com.tinkerpop.pipes.transform.TransformFunctionPipe; -import org.apache.atlas.catalog.ResourceComparator; -import org.apache.atlas.catalog.VertexWrapper; - -import java.util.*; - -/** - * Projection based on a relation. - */ -public class RelationProjection extends Projection { - - private Relation relation; - public RelationProjection(String name, final Collection<String> fields, final Relation relation, Cardinality cardinality) { - super(name, cardinality, new TransformFunctionPipe<>( - new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() { - @Override - public Collection<ProjectionResult> compute(VertexWrapper start) { - Collection<ProjectionResult> projectionResults = new ArrayList<>(); - - for (RelationSet relationSet : relation.traverse(start)) { - Collection<Map<String, Object>> propertyMaps = new ArrayList<>(); - - for (VertexWrapper vWrapper : relationSet.getVertices()) { - Map<String, Object> propertyMap = new TreeMap<>(new ResourceComparator()); - propertyMaps.add(propertyMap); - - if (fields.isEmpty()) { - for (String property : vWrapper.getPropertyKeys()) { - propertyMap.put(property, vWrapper.<String>getProperty(property)); - } - } else { - for (String property : fields) { - propertyMap.put(property, vWrapper.<String>getProperty(property)); - } - } - } - projectionResults.add(new ProjectionResult(relationSet.getName(), start, propertyMaps)); - } - return projectionResults; - } - })); - this.relation = relation; - } - - public Relation getRelation() { - return relation; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationSet.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationSet.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationSet.java deleted file mode 100644 index 4adf861..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/RelationSet.java +++ /dev/null @@ -1,45 +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.*; - -/** - * Encapsulates the response of a relation traversal. - */ -public class RelationSet { - - private final String m_name; - private final Collection<VertexWrapper> m_vertices; - - public RelationSet(String name, Collection<VertexWrapper> vertices) { - m_name = name; - m_vertices = vertices; - } - - public String getName() { - return m_name; - } - - public Collection<VertexWrapper> getVertices() { - return Collections.unmodifiableCollection(m_vertices); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/projection/TagRelation.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/TagRelation.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/TagRelation.java deleted file mode 100644 index cdd1ad1..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/TagRelation.java +++ /dev/null @@ -1,77 +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 com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.filter.FilterFunctionPipe; -import org.apache.atlas.catalog.TermVertexWrapper; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.EntityTagResourceDefinition; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/** - * Relation for adjacent Tag vertices. - */ -public class TagRelation extends BaseRelation { - private static ResourceDefinition resourceDefinition = new EntityTagResourceDefinition(); - @Override - public Collection<RelationSet> traverse(VertexWrapper vWrapper) { - Vertex v = vWrapper.getVertex(); - Collection<VertexWrapper> vertices = new ArrayList<>(); - for (Edge e : v.getEdges(Direction.OUT)) { - if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) { - VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN)); - if (trait.getPropertyKeys().contains("available_as_tag") && ! isDeleted(trait.getVertex())) { - vertices.add(trait); - } - } - } - return Collections.singletonList(new RelationSet("tags", vertices)); - } - - @Override - public Pipe asPipe() { - return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() { - @Override - public Boolean compute(Edge edge) { - String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - if (edge.getLabel().startsWith(name)) { - VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN)); - return v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex()); - } else { - return false; - } - } - }); - } - - @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/TraitRelation.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/projection/TraitRelation.java b/catalog/src/main/java/org/apache/atlas/catalog/projection/TraitRelation.java deleted file mode 100644 index d0f75f3..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/projection/TraitRelation.java +++ /dev/null @@ -1,80 +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 com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.filter.FilterFunctionPipe; -import org.apache.atlas.catalog.TermVertexWrapper; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.EntityTagResourceDefinition; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/** - * Trait specific relation. - */ -//todo: combine with TagRelation -public class TraitRelation extends BaseRelation { - //todo: for now using entity tag resource definition - private static ResourceDefinition resourceDefinition = new EntityTagResourceDefinition(); - - @Override - public Collection<RelationSet> traverse(VertexWrapper vWrapper) { - Vertex v = vWrapper.getVertex(); - Collection<VertexWrapper> vertices = new ArrayList<>(); - for (Edge e : v.getEdges(Direction.OUT)) { - if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) { - VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN)); - if (! trait.getPropertyKeys().contains("available_as_tag") && ! isDeleted(trait.getVertex())) { - vertices.add(trait); - } - } - } - return Collections.singletonList(new RelationSet("traits", vertices)); - } - - @Override - public Pipe asPipe() { - return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() { - @Override - public Boolean compute(Edge edge) { - String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - if (edge.getLabel().startsWith(name)) { - VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN)); - return ! v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex()); - } else { - return false; - } - } - }); - } - - @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/query/AlwaysQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AlwaysQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AlwaysQueryExpression.java deleted file mode 100644 index d120bc4..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AlwaysQueryExpression.java +++ /dev/null @@ -1,46 +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.query; - -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.VertexWrapper; - -/** - * Query expression which always returns true. - */ -public class AlwaysQueryExpression extends BaseQueryExpression { - protected AlwaysQueryExpression() { - super(null, null, null); - } - - @Override - public Pipe asPipe() { - return null; - } - - @Override - public boolean evaluate(VertexWrapper vWrapper) { - return ! negate; - } - - @Override - public boolean evaluate(Object value) { - return true; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityQuery.java deleted file mode 100644 index d6b737c..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityQuery.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.query; - -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -/** - * Entity resource query. - */ -public class AtlasEntityQuery extends BaseQuery { - public AtlasEntityQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, Request request) { - super(queryExpression, resourceDefinition, request); - } - - protected Pipe getQueryPipe() { - return new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY). - hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy"); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityTagQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityTagQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityTagQuery.java deleted file mode 100644 index 3e301f3..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasEntityTagQuery.java +++ /dev/null @@ -1,86 +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.query; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.filter.FilterFunctionPipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.TermVertexWrapper; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.EntityTagResourceDefinition; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -import java.util.HashMap; -import java.util.Map; - -/** - * Entity Tag resource query. - */ -public class AtlasEntityTagQuery extends BaseQuery { - private final String guid; - - public AtlasEntityTagQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, String guid, Request request) { - super(queryExpression, resourceDefinition, request); - this.guid = guid; - } - - @Override - protected Pipe getQueryPipe() { - GremlinPipeline p; - if (guid.equals("*")) { - p = new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY). - hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy").outE(); - } else { - p = new GremlinPipeline().has(Constants.GUID_PROPERTY_KEY, guid).outE(); - } - //todo: this is basically the same pipeline used in TagRelation.asPipe() - p.add(new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() { - @Override - public Boolean compute(Edge edge) { - String type = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY); - VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN)); - return edge.getLabel().startsWith(type) && v.getPropertyKeys().contains("available_as_tag"); - } - })); - - return p.inV(); - } - - //todo: duplication of effort with resource definition - @Override - protected void addHref(VertexWrapper vWrapper, Map<String, Object> filteredPropertyMap) { - Map<String, Object> map = new HashMap<>(filteredPropertyMap); - if (guid.equals("*")) { - map.put(EntityTagResourceDefinition.ENTITY_GUID_PROPERTY, vWrapper.getVertex().getEdges(Direction.IN). - iterator().next().getVertex(Direction.OUT).getProperty(Constants.GUID_PROPERTY_KEY)); - } else { - map.put(EntityTagResourceDefinition.ENTITY_GUID_PROPERTY, guid); - } - - String href = resourceDefinition.resolveHref(map); - if (href != null) { - filteredPropertyMap.put("href", href); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasQuery.java deleted file mode 100644 index 4930ab0..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasQuery.java +++ /dev/null @@ -1,47 +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.query; - -import org.apache.atlas.catalog.exception.ResourceNotFoundException; - -import java.util.Collection; -import java.util.Map; - -/** - * Query functionality. - */ -public interface AtlasQuery { - /** - * Execute the query. - * - * @return collection of property maps, one per matching resource - * @throws ResourceNotFoundException if an explicitly specified resource doesn't exist - */ - Collection<Map<String, Object>> execute() throws ResourceNotFoundException; - - /** - * Execute the query and update the results with the provided properties. - * - * @param updateProperties properties name/values to update on query results - * - * @return collection of property maps, one per matching resource - * @throws ResourceNotFoundException if an explicitly specified resource doesn't exist - */ - Collection<Map<String, Object>> execute(Map<String, Object> updateProperties) throws ResourceNotFoundException; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTaxonomyQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTaxonomyQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTaxonomyQuery.java deleted file mode 100644 index df3e8da..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTaxonomyQuery.java +++ /dev/null @@ -1,38 +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.query; - -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.definition.ResourceDefinition; - -/** - * Taxonomy resource query. - */ -public class AtlasTaxonomyQuery extends BaseQuery { - public AtlasTaxonomyQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, Request request) { - super(queryExpression, resourceDefinition, request); - } - - @Override - protected Pipe getQueryPipe() { - return new GremlinPipeline().has("__typeName", "Taxonomy"); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTermQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTermQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTermQuery.java deleted file mode 100644 index f064037..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/AtlasTermQuery.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.query; - -import com.thinkaurelius.titan.core.attribute.Text; -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.TermPath; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; - -/** - * Term resource query. - */ -public class AtlasTermQuery extends BaseQuery { - private final TermPath termPath; - - public AtlasTermQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, TermPath termPath, Request request) { - super(queryExpression, resourceDefinition, request); - this.termPath = termPath; - } - - @Override - protected Pipe getQueryPipe() { - GremlinPipeline p; - if (termPath.getTaxonomyName().equals("*")) { - p = new GremlinPipeline().has("Taxonomy.name").out(); - } else { - p = new GremlinPipeline().has("Taxonomy.name", termPath.getTaxonomyName()).out(). - has(Constants.ENTITY_TYPE_PROPERTY_KEY, Text.PREFIX, termPath.getFullyQualifiedName()); - } - return p; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQuery.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQuery.java b/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQuery.java deleted file mode 100644 index ff48020..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQuery.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.query; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; - -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.catalog.exception.ResourceNotFoundException; -import org.apache.atlas.catalog.projection.Projection; -import org.apache.atlas.catalog.projection.ProjectionResult; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.graph.AtlasGraphProvider; -import org.apache.atlas.repository.graphdb.AtlasElement; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.typesystem.persistence.Id; - -import com.tinkerpop.blueprints.Compare; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.filter.PropertyFilterPipe; - -/** - * Base Query implementation. - */ -public abstract class BaseQuery implements AtlasQuery { - protected final QueryExpression queryExpression; - protected final ResourceDefinition resourceDefinition; - protected final Request request; - - public BaseQuery(QueryExpression queryExpression, ResourceDefinition resourceDefinition, Request request) { - this.queryExpression = queryExpression; - this.resourceDefinition = resourceDefinition; - this.request = request; - } - - public Collection<Map<String, Object>> execute() throws ResourceNotFoundException { - Collection<Map<String, Object>> resultMaps = new ArrayList<>(); - - try { - for (Vertex vertex : executeQuery()) { - resultMaps.add(processPropertyMap(wrapVertex(vertex))); - } - getGraph().commit(); - } catch (Throwable t) { - getGraph().rollback(); - throw t; - } - return resultMaps; - } - - @Override - public Collection<Map<String, Object>> execute(Map<String, Object> updateProperties) - throws ResourceNotFoundException { - - Collection<Map<String, Object>> resultMaps = new ArrayList<>(); - try { - for (Vertex vertex : executeQuery()) { - VertexWrapper vWrapper = wrapVertex(vertex); - for (Map.Entry<String, Object> property : updateProperties.entrySet()) { - vWrapper.setProperty(property.getKey(), property.getValue()); - vWrapper.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis()); - } - resultMaps.add(processPropertyMap(vWrapper)); - } - getGraph().commit(); - } catch (Throwable e) { - getGraph().rollback(); - throw e; - } - return resultMaps; - } - - private List<Vertex> executeQuery() { - GremlinPipeline pipeline = buildPipeline().as("root"); - Pipe expressionPipe = queryExpression.asPipe(); - - // AlwaysQuery returns null for pipe - return expressionPipe == null ? pipeline.toList() : - pipeline.add(expressionPipe).back("root").toList(); - } - - protected GremlinPipeline buildPipeline() { - GremlinPipeline pipeline = getRootVertexPipeline(); - Pipe queryPipe = getQueryPipe(); - if (queryPipe != null) { - pipeline.add(queryPipe); - } - pipeline.add(getNotDeletedPipe()); - return pipeline; - } - - protected abstract Pipe getQueryPipe(); - - protected GremlinPipeline getRootVertexPipeline() { - return new GremlinPipeline(unWrapVertices()); - } - - protected Iterable<Object> unWrapVertices() { - final Iterable<AtlasVertex> vertices = getGraph().getVertices(); - - Iterable<Object> vertexIterable = new Iterable<Object>() { - Iterator<Object> iterator = new Iterator<Object>() { - Iterator<AtlasVertex> wrapperIterator = vertices.iterator(); - - @Override - public boolean hasNext() { - return wrapperIterator.hasNext(); - } - - @Override - public Object next() { - if (hasNext()) { - return ((AtlasElement) wrapperIterator.next().getV()).getWrappedElement(); - } else { - throw new NoSuchElementException(); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Remove not supported"); - } - }; - - @Override - public Iterator<Object> iterator() { - return iterator; - } - }; - return vertexIterable; - } - - protected Pipe getNotDeletedPipe() { - return new PropertyFilterPipe(Constants.STATE_PROPERTY_KEY, Compare.EQUAL, - Id.EntityState.ACTIVE.name()); - } - - protected Map<String, Object> processPropertyMap(VertexWrapper vertex) { - Map<String, Object> propertyMap = resourceDefinition.filterProperties( - request, vertex.getPropertyMap()); - addHref(vertex, propertyMap); - - return request.getCardinality() == Request.Cardinality.INSTANCE ? - applyProjections(vertex, propertyMap) : - propertyMap; - } - - protected void addHref(VertexWrapper vWrapper, Map<String, Object> filteredPropertyMap) { - String href = resourceDefinition.resolveHref(filteredPropertyMap); - if (href != null) { - filteredPropertyMap.put("href", href); - } - } - - protected Map<String, Object> applyProjections(VertexWrapper vertex, Map<String, Object> propertyMap) { - for (Projection p : resourceDefinition.getProjections().values()) { - for (ProjectionResult projectionResult : p.values(vertex)) { - if (p.getCardinality() == Projection.Cardinality.MULTIPLE) { - propertyMap.put(projectionResult.getName(), projectionResult.getPropertyMaps()); - } else { - for (Map<String, Object> projectionMap : projectionResult.getPropertyMaps()) { - propertyMap.put(projectionResult.getName(), projectionMap); - } - } - } - } - return propertyMap; - } - - protected QueryExpression getQueryExpression() { - return queryExpression; - } - - protected ResourceDefinition getResourceDefinition() { - return resourceDefinition; - } - - protected Request getRequest() { - return request; - } - - // Underlying method is synchronized and caches the graph in a static field - protected AtlasGraph getGraph() { - return AtlasGraphProvider.getGraphInstance(); - } - - protected VertexWrapper wrapVertex(Vertex v) { - return new VertexWrapper(v, resourceDefinition); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQueryExpression.java deleted file mode 100644 index 2364ee5..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/BaseQueryExpression.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.query; - -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.filter.FilterFunctionPipe; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; - -import java.util.Collection; -import java.util.HashSet; - -/** - * Base query expression class. - */ -public abstract class BaseQueryExpression implements QueryExpression { - protected String m_field; - protected final String m_expectedValue; - protected final ResourceDefinition resourceDefinition; - protected boolean negate = false; - protected Collection<String> properties = new HashSet<>(); - - protected BaseQueryExpression(String field, String expectedValue, ResourceDefinition resourceDefinition) { - m_field = field; - if (field != null) { - properties.add(field); - } - m_expectedValue = expectedValue; - this.resourceDefinition = resourceDefinition; - } - - @Override - public boolean evaluate(VertexWrapper vWrapper) { - return negate ^ evaluate(vWrapper.getProperty(m_field)); - } - - @Override - public Collection<String> getProperties() { - return properties; - } - - @Override - public boolean evaluate(Object value) { - // subclasses which don't override evaluate(VertexWrapper) should implement this - return false; - } - - //todo: use 'has' instead of closure where possible for performance - public Pipe asPipe() { - return new FilterFunctionPipe(new PipeFunction<Vertex, Boolean>() { - @Override - public Boolean compute(Vertex vertex) { - return evaluate(new VertexWrapper(vertex, resourceDefinition)); - } - }); - } - - @Override - public String getField() { - return m_field; - } - - @Override - public String getExpectedValue() { - return m_expectedValue; - } - - @Override - public void setField(String field) { - m_field = field; - } - - @Override - public void setNegate() { - this.negate = true; - } - - @Override - public boolean isNegate() { - return negate; - } - - @Override - public boolean isProjectionExpression() { - return getField() != null && getField().contains(QueryFactory.PATH_SEP_TOKEN); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/BooleanQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/BooleanQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/BooleanQueryExpression.java deleted file mode 100644 index b4d759a..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/BooleanQueryExpression.java +++ /dev/null @@ -1,141 +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.query; - -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.filter.AndFilterPipe; -import com.tinkerpop.pipes.filter.OrFilterPipe; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; - -import java.util.*; - -/** - * Expression where operands are other expressions and operator is logical AND or OR - */ -public class BooleanQueryExpression extends BaseQueryExpression { - private final BooleanClause[] clauses; - private final QueryFactory queryFactory; - - public BooleanQueryExpression(BooleanQuery query, ResourceDefinition resourceDefinition, QueryFactory queryFactory) { - super(null, null, resourceDefinition); - clauses = query.getClauses(); - this.queryFactory = queryFactory; - } - - @Override - public Pipe asPipe() { - Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses = groupClauses(); - - Pipe andPipe = null; - Collection<Pipe> andPipes = processAndClauses(groupedClauses); - andPipes.addAll(processNotClauses(groupedClauses)); - if (! andPipes.isEmpty()) { - andPipe = new AndFilterPipe(andPipes.toArray(new Pipe[andPipes.size()])); - } - - Collection<Pipe> orPipes = processOrClauses(groupedClauses); - if (! orPipes.isEmpty()) { - if (andPipe != null) { - orPipes.add(andPipe); - } - return new OrFilterPipe(orPipes.toArray(new Pipe[orPipes.size()])); - } else { - return andPipe; - } - } - - private Map<BooleanClause.Occur, Collection<BooleanClause>> groupClauses() { - Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses = new HashMap<>(); - for (BooleanClause clause : clauses) { - BooleanClause.Occur occur = resolveClauseOccur(clause); - Collection<BooleanClause> clauseGrouping = groupedClauses.get(occur); - if (clauseGrouping == null) { - clauseGrouping = new ArrayList<>(); - groupedClauses.put(occur, clauseGrouping); - } - clauseGrouping.add(clause); - } - return groupedClauses; - } - - private BooleanClause.Occur resolveClauseOccur(BooleanClause clause) { - BooleanClause.Occur occur = clause.getOccur(); - if (negate) { - switch (occur) { - case SHOULD: - occur = BooleanClause.Occur.MUST_NOT; - break; - case MUST: - occur = BooleanClause.Occur.SHOULD; - break; - case MUST_NOT: - occur = BooleanClause.Occur.SHOULD; - break; - } - } - return occur; - } - - private Collection<Pipe> processAndClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) { - Collection<BooleanClause> andClauses = groupedClauses.get(BooleanClause.Occur.MUST); - Collection<Pipe> andPipes = new ArrayList<>(); - if (andClauses != null) { - for (BooleanClause andClause : andClauses) { - QueryExpression queryExpression = queryFactory.create(andClause.getQuery(), resourceDefinition); - properties.addAll(queryExpression.getProperties()); - andPipes.add(queryExpression.asPipe()); - } - } - return andPipes; - } - - - private Collection<Pipe> processOrClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) { - Collection<BooleanClause> shouldClauses = groupedClauses.get(BooleanClause.Occur.SHOULD); - Collection<Pipe> orPipes = new ArrayList<>(); - if (shouldClauses != null) { - for (BooleanClause shouldClause : shouldClauses) { - QueryExpression queryExpression = queryFactory.create(shouldClause.getQuery(), resourceDefinition); - // don't negate expression if we negated MUST_NOT -> SHOULD - if (negate && shouldClause.getOccur() != BooleanClause.Occur.MUST_NOT) { - queryExpression.setNegate(); - } - properties.addAll(queryExpression.getProperties()); - orPipes.add(queryExpression.asPipe()); - } - } - return orPipes; - } - - private Collection<Pipe> processNotClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) { - Collection<BooleanClause> notClauses = groupedClauses.get(BooleanClause.Occur.MUST_NOT); - Collection<Pipe> notPipes = new ArrayList<>(); - if (notClauses != null) { - for (BooleanClause notClause : notClauses) { - QueryExpression queryExpression = queryFactory.create(notClause.getQuery(), resourceDefinition); - queryExpression.setNegate(); - properties.addAll(queryExpression.getProperties()); - notPipes.add(queryExpression.asPipe()); - } - } - return notPipes; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/PrefixQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/PrefixQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/PrefixQueryExpression.java deleted file mode 100644 index 6b43667..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/PrefixQueryExpression.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.query; - -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.search.PrefixQuery; - -/** - * Expression that evaluates whether a property starts with a prefix. - */ -public class PrefixQueryExpression extends BaseQueryExpression { - - // query 'f*' results in a PrefixQuery - public PrefixQueryExpression(PrefixQuery query, ResourceDefinition resourceDefinition) { - super(query.getPrefix().field(), query.getPrefix().text(), resourceDefinition); - } - - @Override - public boolean evaluate(Object value) { - return value != null && String.valueOf(value).startsWith(getExpectedValue()); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/ProjectionQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/ProjectionQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/ProjectionQueryExpression.java deleted file mode 100644 index b915877..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/ProjectionQueryExpression.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.query; - -import com.thinkaurelius.titan.core.attribute.Text; -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; -import com.tinkerpop.pipes.PipeFunction; -import com.tinkerpop.pipes.filter.FilterFunctionPipe; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.catalog.projection.ProjectionResult; -import org.apache.atlas.catalog.projection.Relation; - -import java.util.*; - -/** - * Query expression wrapper which handles projection queries. - */ -public class ProjectionQueryExpression extends BaseQueryExpression { - - private final QueryExpression underlyingExpression; - private final ResourceDefinition resourceDefinition; - - private final String[] fieldSegments; - - protected ProjectionQueryExpression(QueryExpression underlyingExpression, ResourceDefinition resourceDefinition) { - super(underlyingExpression.getField(), underlyingExpression.getExpectedValue(), resourceDefinition); - - this.underlyingExpression = underlyingExpression; - this.resourceDefinition = resourceDefinition; - this.fieldSegments = getField().split(QueryFactory.PATH_SEP_TOKEN); - } - - @Override - public Pipe asPipe() { - //todo: encapsulate all of this path logic including path sep escaping and normalizing - final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN); - final String edgeToken = getField().substring(0, sepIdx); - GremlinPipeline pipeline = new GremlinPipeline(); - - Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]); - if (relation != null) { - pipeline = pipeline.outE(); - pipeline.add(relation.asPipe()).inV(); - } else { - if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) { - return super.asPipe(); - } else { - //todo: default Relation implementation - pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV(); - } - } - //todo: set resource definition from relation on underlying expression where appropriate - String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length()); - underlyingExpression.setField(childFieldName); - - Pipe childPipe; - if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) { - childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe(); - } else { - childPipe = underlyingExpression.asPipe(); - } - pipeline.add(childPipe); - - return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline; - } - - @Override - public boolean evaluate(VertexWrapper vWrapper) { - boolean result = false; - Iterator<ProjectionResult> projectionIterator = resourceDefinition.getProjections(). - get(fieldSegments[0]).values(vWrapper).iterator(); - - while (! result && projectionIterator.hasNext()) { - ProjectionResult projectionResult = projectionIterator.next(); - for (Map<String, Object> propertyMap : projectionResult.getPropertyMaps()) { - Object val = propertyMap.get(fieldSegments[1]); - if (val != null && underlyingExpression.evaluate(QueryFactory.escape(val))) { - result = true; - break; - } - } - } - return negate ^ result; - } - - private static class ExcludePipeFunction implements PipeFunction<Object, Boolean> { - private final GremlinPipeline excludePipeline; - - public ExcludePipeFunction(GremlinPipeline excludePipeline) { - this.excludePipeline = excludePipeline; - } - - @Override - public Boolean compute(Object vertices) { - GremlinPipeline p = new GremlinPipeline(Collections.singleton(vertices)); - p.add(excludePipeline); - return p.gather().toList().isEmpty(); - } - } - - protected QueryExpression getUnderlyingExpression() { - return underlyingExpression; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/QueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/QueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/QueryExpression.java deleted file mode 100644 index c53b94b..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/QueryExpression.java +++ /dev/null @@ -1,99 +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.query; - -import com.tinkerpop.pipes.Pipe; -import org.apache.atlas.catalog.VertexWrapper; - -import java.util.Collection; - -/** - * Represents a query expression. - */ -public interface QueryExpression { - /** - * Evaluate the expression based on properties of the provied vertex. - * - * @param vWrapper vertex wrapper that expression is applied to - * @return result of expression evaluation - */ - boolean evaluate(VertexWrapper vWrapper); - - /** - * Evaluate the expression based on the provided value. - * - * @param value value used to evaluate expression - * @return - */ - boolean evaluate(Object value); - - /** - * Get the complete set of properties which are contained in the expression. - * - * @return collection of expression properties - */ - Collection<String> getProperties(); - - /** - * Get the pipe representation of the expression. - * - * @return pipe representation - */ - Pipe asPipe(); - - /** - * Negate the expression. - */ - void setNegate(); - - /** - * Get the negate status of the expression. - * - * @return true if the expression is negated, false otherwise - */ - boolean isNegate(); - - /** - * Determine whether the expression is being applied to a projection. - * - * @return true if expression is being applied to a projection, false otherwise - */ - boolean isProjectionExpression(); - - /** - * Get the field name used in the expression. - * - * @return expression field name or null if there is no field name - */ - String getField(); - - /** - * Set the expressions field name. - * - * @param fieldName field name - */ - void setField(String fieldName); - - /** - * Get the expected value for the expression. - * - * @return expected value or null if there isn't a expected value - */ - String getExpectedValue(); -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/QueryFactory.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/QueryFactory.java b/catalog/src/main/java/org/apache/atlas/catalog/query/QueryFactory.java deleted file mode 100644 index a4fd4ad..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/QueryFactory.java +++ /dev/null @@ -1,183 +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.query; - -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.TermPath; -import org.apache.atlas.catalog.definition.*; -import org.apache.atlas.catalog.exception.CatalogRuntimeException; -import org.apache.atlas.catalog.exception.InvalidQueryException; -import org.apache.lucene.analysis.core.KeywordAnalyzer; -import org.apache.lucene.queryparser.classic.ParseException; -import org.apache.lucene.queryparser.classic.QueryParser; -import org.apache.lucene.sandbox.queries.regex.RegexQuery; -import org.apache.lucene.search.*; -import org.apache.lucene.util.Version; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; - -/** - * Factory used to create QueryAdapter instances. - */ -public class QueryFactory { - private static final Logger LOG = LoggerFactory.getLogger(QueryFactory.class); - public static final String PATH_SEP_TOKEN = "__slash__"; - - private final Map<Class<? extends Query>, ExpressionCreateFunction<? extends Query>> - expressionCreateFunctions = new HashMap<>(); - - public QueryFactory() { - registerExpressionCreateFunctions(); - } - - public AtlasQuery createTaxonomyQuery(Request request) throws InvalidQueryException { - ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition(); - QueryExpression queryExpression = create(request, taxonomyDefinition); - return new AtlasTaxonomyQuery(queryExpression, taxonomyDefinition, request); - } - - public AtlasQuery createTermQuery(Request request) throws InvalidQueryException { - ResourceDefinition termDefinition = new TermResourceDefinition(); - QueryExpression queryExpression = create(request, termDefinition); - TermPath termPath = request.getProperty("termPath"); - return new AtlasTermQuery(queryExpression, termDefinition, termPath, request); - } - - public AtlasQuery createEntityQuery(Request request) throws InvalidQueryException { - ResourceDefinition entityDefinition = new EntityResourceDefinition(); - QueryExpression queryExpression = create(request, entityDefinition); - return new AtlasEntityQuery(queryExpression, entityDefinition, request); - } - - public AtlasQuery createEntityTagQuery(Request request) throws InvalidQueryException { - ResourceDefinition entityTagDefinition = new EntityTagResourceDefinition(); - QueryExpression queryExpression = create(request, entityTagDefinition); - String guid = request.getProperty("id"); - return new AtlasEntityTagQuery(queryExpression, entityTagDefinition, guid, request); - } - - private QueryExpression create(Request request, ResourceDefinition resourceDefinition) throws InvalidQueryException { - String queryString; - if (request.getCardinality() == Request.Cardinality.INSTANCE) { - String idPropertyName = resourceDefinition.getIdPropertyName(); - queryString = String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName)); - } else { - queryString = request.getQueryString(); - } - - QueryExpression queryExpression; - if (queryString != null && !queryString.isEmpty()) { - QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer()); - queryParser.setLowercaseExpandedTerms(false); - queryParser.setAllowLeadingWildcard(true); - Query query; - try { - query = queryParser.parse((String) escape(queryString)); - } catch (ParseException e) { - throw new InvalidQueryException(e.getMessage()); - } - LOG.info("LuceneQuery: {}", query); - queryExpression = create(query, resourceDefinition); - } else { - queryExpression = new AlwaysQueryExpression(); - } - // add query properties to request so that they are returned - request.addAdditionalSelectProperties(queryExpression.getProperties()); - return queryExpression; - } - - @SuppressWarnings("unchecked") - protected <T extends Query> QueryExpression create(T query, ResourceDefinition resourceDefinition) { - if (! expressionCreateFunctions.containsKey(query.getClass())) { - throw new CatalogRuntimeException("Query type currently not supported: " + query.getClass(), 400); - } - //todo: fix generic typing - ExpressionCreateFunction expressionCreateFunction = expressionCreateFunctions.get(query.getClass()); - return expressionCreateFunction.createExpression(query, resourceDefinition); - - } - - // "escapes" characters as necessary for lucene parser - //todo: currently '/' characters are blindly being replaced but this will not allow regex queries to be used - protected static Object escape(Object val) { - if (val instanceof String) { - return ((String)val).replaceAll("/", PATH_SEP_TOKEN); - } else { - return val; - } - } - - private abstract static class ExpressionCreateFunction<T extends Query> { - QueryExpression createExpression(T query, ResourceDefinition resourceDefinition) { - QueryExpression expression = create(query, resourceDefinition); - return expression.isProjectionExpression() ? - new ProjectionQueryExpression(expression, resourceDefinition) : - expression; - } - - protected abstract QueryExpression create(T query, ResourceDefinition resourceDefinition); - } - - private void registerExpressionCreateFunctions() { - expressionCreateFunctions.put(WildcardQuery.class, new ExpressionCreateFunction<WildcardQuery>() { - @Override - public QueryExpression create(WildcardQuery query, ResourceDefinition definition) { - return new WildcardQueryExpression(query, definition); - } - }); - - expressionCreateFunctions.put(PrefixQuery.class, new ExpressionCreateFunction<PrefixQuery>() { - @Override - public QueryExpression create(PrefixQuery query, ResourceDefinition definition) { - return new PrefixQueryExpression(query, definition); - } - }); - - expressionCreateFunctions.put(TermQuery.class, new ExpressionCreateFunction<TermQuery>() { - @Override - public QueryExpression create(TermQuery query, ResourceDefinition definition) { - return new TermQueryExpression(query, definition); - } - }); - - expressionCreateFunctions.put(TermRangeQuery.class, new ExpressionCreateFunction<TermRangeQuery>() { - @Override - public QueryExpression create(TermRangeQuery query, ResourceDefinition definition) { - return new TermRangeQueryExpression(query, definition); - } - }); - - expressionCreateFunctions.put(RegexQuery.class, new ExpressionCreateFunction<RegexQuery>() { - @Override - public QueryExpression create(RegexQuery query, ResourceDefinition definition) { - return new RegexQueryExpression(query, definition); - } - }); - - expressionCreateFunctions.put(BooleanQuery.class, new ExpressionCreateFunction<BooleanQuery>() { - @Override - public QueryExpression create(BooleanQuery query, ResourceDefinition definition) { - return new BooleanQueryExpression(query, definition, QueryFactory.this); - } - }); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/RegexQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/RegexQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/RegexQueryExpression.java deleted file mode 100644 index c28d4d5..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/RegexQueryExpression.java +++ /dev/null @@ -1,41 +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.query; - -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.sandbox.queries.regex.RegexQuery; - -import java.util.regex.Pattern; - -/** - * Query expression which evaluates a property against a regular expression. - */ -public class RegexQueryExpression extends BaseQueryExpression { - - public RegexQueryExpression(RegexQuery query, ResourceDefinition resourceDefinition) { - super(query.getField(), query.getTerm().text(), resourceDefinition); - - } - - @Override - public boolean evaluate(Object value) { - Pattern p = Pattern.compile(getExpectedValue()); - return value != null && p.matcher(String.valueOf(value)).matches(); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/TermQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/TermQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/TermQueryExpression.java deleted file mode 100644 index a790866..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/TermQueryExpression.java +++ /dev/null @@ -1,52 +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.query; - -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.search.TermQuery; - -import java.util.Collection; - -/** - * Query expression which evaluates whether a property equals a value. - */ -public class TermQueryExpression extends BaseQueryExpression { - - public TermQueryExpression(TermQuery query, ResourceDefinition resourceDefinition) { - super(query.getTerm().field(), query.getTerm().text(), resourceDefinition); - } - - @Override - public boolean evaluate(Object value) { - String expectedValue = getExpectedValue(); - if (value == null) { - return expectedValue.equals("null"); - //todo: refactor; we shouldn't need to use instanceof/cast here - } else if (value instanceof Collection) { - return ((Collection)value).contains(expectedValue); - } else { - return expectedValue.equals(QueryFactory.escape(String.valueOf(value))); - } - } - - public String getExpectedValue() { - return m_expectedValue; - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/TermRangeQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/TermRangeQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/TermRangeQueryExpression.java deleted file mode 100644 index 44cfb72..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/TermRangeQueryExpression.java +++ /dev/null @@ -1,61 +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.query; - -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.search.TermRangeQuery; -import org.apache.lucene.util.BytesRef; - -/** - * Query expression which evaluates whether a property value is within a range. - */ -//todo: for month and year which are expressed via a single digit, must ensure that -//todo: a leading '0' is provided. For example, "2016-1-5" must be converted to "2016-01-05". -//todo: Month and day values aren't currently validated. -public class TermRangeQueryExpression extends BaseQueryExpression { - private final BytesRef m_lowerTerm; - private final BytesRef m_upperTerm; - private final boolean m_lowerInclusive; - private final boolean m_upperInclusive; - - public TermRangeQueryExpression(TermRangeQuery query, ResourceDefinition resourceDefinition) { - super(query.getField(), null, resourceDefinition); - m_lowerTerm = query.getLowerTerm(); - m_upperTerm = query.getUpperTerm(); - m_lowerInclusive = query.includesLower(); - m_upperInclusive = query.includesUpper(); - } - - @Override - public boolean evaluate(Object value) { - BytesRef valueBytes = new BytesRef(String.valueOf(value)); - return compareLowerBound(valueBytes) && compareUpperBound(valueBytes); - } - - private boolean compareLowerBound(BytesRef valueBytes) { - return m_lowerTerm == null || (m_lowerInclusive ? valueBytes.compareTo(m_lowerTerm) > 0 : - valueBytes.compareTo(m_lowerTerm) >= 0); - } - - private boolean compareUpperBound(BytesRef valueBytes) { - return m_upperTerm == null || (m_upperInclusive ? valueBytes.compareTo(m_upperTerm) < 0 : - valueBytes.compareTo(m_upperTerm) <= 0); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/main/java/org/apache/atlas/catalog/query/WildcardQueryExpression.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/atlas/catalog/query/WildcardQueryExpression.java b/catalog/src/main/java/org/apache/atlas/catalog/query/WildcardQueryExpression.java deleted file mode 100644 index 689891f..0000000 --- a/catalog/src/main/java/org/apache/atlas/catalog/query/WildcardQueryExpression.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.query; - -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.lucene.search.WildcardQuery; - -import java.util.regex.Pattern; - -/** - * Query expression which evaluates values with wildcards. - * This differs from PrefixQueryExpression which handles expressions which end with a wildcard. - */ -public class WildcardQueryExpression extends BaseQueryExpression { - - public WildcardQueryExpression(WildcardQuery query, ResourceDefinition resourceDefinition) { - super(query.getTerm().field(), query.getTerm().text(), resourceDefinition); - } - - @Override - public boolean evaluate(Object value) { - // replace '*' with ".*" - // replace '?' with '.' - String regex = getExpectedValue().replaceAll("\\*", ".*").replaceAll("\\?", "."); - return Pattern.compile(regex).matcher(String.valueOf(value)).matches(); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/test/java/org/apache/atlas/catalog/CollectionRequestTest.java ---------------------------------------------------------------------- diff --git a/catalog/src/test/java/org/apache/atlas/catalog/CollectionRequestTest.java b/catalog/src/test/java/org/apache/atlas/catalog/CollectionRequestTest.java deleted file mode 100644 index a228546..0000000 --- a/catalog/src/test/java/org/apache/atlas/catalog/CollectionRequestTest.java +++ /dev/null @@ -1,74 +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.testng.annotations.Test; - -import java.util.*; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -/** - * Unit tests for CollectionRequest. - */ -public class CollectionRequestTest { - @Test - public void testNoProperties() { - String query = "name:foo*"; - Request request = new CollectionRequest(null, query); - - assertEquals(Request.Cardinality.COLLECTION, request.getCardinality()); - assertTrue(request.getQueryProperties().isEmpty()); - assertNull(request.getProperty("foo")); - assertTrue(request.getAdditionalSelectProperties().isEmpty()); - } - - @Test - public void testWithProperties() { - String query = "name:foo*"; - Map<String, Object> properties = new HashMap<>(); - properties.put("foo", "fooValue"); - properties.put("someBoolean", true); - Request request = new CollectionRequest(properties, query); - - assertEquals(Request.Cardinality.COLLECTION, request.getCardinality()); - assertEquals(properties, request.getQueryProperties()); - assertEquals("fooValue", request.getProperty("foo")); - assertTrue(request.<Boolean>getProperty("someBoolean")); - assertNull(request.getProperty("other")); - assertTrue(request.getAdditionalSelectProperties().isEmpty()); - } - - @Test - public void testSelectProperties() { - String query = "name:foo*"; - Request request = new CollectionRequest(null, query); - Collection<String> additionalSelectProps = new ArrayList<>(); - additionalSelectProps.add("foo"); - additionalSelectProps.add("bar"); - request.addAdditionalSelectProperties(additionalSelectProps); - Collection<String> requestAdditionalSelectProps = request.getAdditionalSelectProperties(); - assertEquals(2, requestAdditionalSelectProps.size()); - assertTrue(requestAdditionalSelectProps.contains("foo")); - assertTrue(requestAdditionalSelectProps.contains("bar")); - - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/test/java/org/apache/atlas/catalog/DefaultDateFormatterTest.java ---------------------------------------------------------------------- diff --git a/catalog/src/test/java/org/apache/atlas/catalog/DefaultDateFormatterTest.java b/catalog/src/test/java/org/apache/atlas/catalog/DefaultDateFormatterTest.java deleted file mode 100644 index bbc98c5..0000000 --- a/catalog/src/test/java/org/apache/atlas/catalog/DefaultDateFormatterTest.java +++ /dev/null @@ -1,41 +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.testng.annotations.Test; - -import java.util.Calendar; -import java.util.GregorianCalendar; - -import static org.testng.Assert.assertEquals; - -/** - * Unit tests for DefaultDateFormatter. - */ -public class DefaultDateFormatterTest { - @Test - public void test() { - Calendar calendar = new GregorianCalendar(2016, 0, 20, 5, 10, 15); - long millis = calendar.getTimeInMillis(); - - DefaultDateFormatter dateFormatter = new DefaultDateFormatter(); - // month starts at 0 so we need to add 1 - assertEquals("2016-01-20:05:10:15", dateFormatter.format(millis)); - } -}
