Commit f8fe0945 by Suma Shivaprasad

ATLAS-1223 Type REST API v2 implementation (apoorvnaik via sumasai)

parent 0d01f356
......@@ -88,4 +88,5 @@ public final class Constants {
private Constants() {
}
}
......@@ -30,7 +30,7 @@
<packaging>jar</packaging>
<properties>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<checkstyle.failOnViolation>false</checkstyle.failOnViolation>
</properties>
<dependencies>
......
......@@ -27,6 +27,8 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.apache.atlas.model.SearchFilter.SortType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
......@@ -36,6 +38,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PList<T> implements java.io.Serializable {
private static final long serialVersionUID = 1L;
......
......@@ -26,6 +26,8 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
......@@ -35,7 +37,12 @@ import javax.xml.bind.annotation.XmlRootElement;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class SearchFilter {
public static final String PARAM_TYPE = "type";
public static final String PARAM_SUPERTYPE = "supertype";
public static final String PARAM_NOT_SUPERTYPE = "notSupertype";
/**
* to specify whether the result should be sorted? If yes, whether asc or desc.
*/
......
......@@ -21,6 +21,8 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -40,6 +42,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasClassification extends AtlasStruct implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -73,6 +76,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasClassification.class)
public static class AtlasClassifications extends PList<AtlasClassification> {
private static final long serialVersionUID = 1L;
......
......@@ -22,6 +22,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -42,6 +44,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasEntity extends AtlasStruct implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -218,6 +221,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasEntity.class)
public static class AtlasEntities extends PList<AtlasEntity> {
private static final long serialVersionUID = 1L;
......
......@@ -21,6 +21,8 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -39,6 +41,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasObjectId implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -145,6 +148,7 @@ public class AtlasObjectId implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasObjectId.class)
public static class AtlasObjectIds extends PList<AtlasObjectId> {
private static final long serialVersionUID = 1L;
......
......@@ -26,6 +26,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -47,6 +49,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasStruct implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -170,6 +173,7 @@ public class AtlasStruct implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasStruct.class)
public static class AtlasStructs extends PList<AtlasStruct> {
private static final long serialVersionUID = 1L;
......
......@@ -23,6 +23,8 @@ import java.util.Collection;
import java.util.Date;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.collections.CollectionUtils;
......@@ -41,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class AtlasBaseTypeDef implements java.io.Serializable {
private static final long serialVersionUID = 1L;
......@@ -238,7 +241,7 @@ public abstract class AtlasBaseTypeDef implements java.io.Serializable {
sb = new StringBuilder();
}
sb.append(", AtlasBaseTypeDef{");
sb.append("AtlasBaseTypeDef{");
sb.append("guid='").append(guid).append('\'');
sb.append(", createdBy='").append(createdBy).append('\'');
sb.append(", updatedBy='").append(updatedBy).append('\'');
......
......@@ -17,11 +17,12 @@
*/
package org.apache.atlas.model.typedef;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -42,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasClassificationDef extends AtlasStructDef implements java.io.Serializable {
private static final long serialVersionUID = 1L;
......@@ -94,9 +96,9 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
}
if (CollectionUtils.isEmpty(superTypes)) {
this.superTypes = Collections.emptySet();
this.superTypes = new HashSet<String>();
} else {
this.superTypes = Collections.unmodifiableSet(new HashSet<String>(superTypes));
this.superTypes = new HashSet<String>(superTypes);
}
}
......@@ -112,7 +114,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
s.add(typeName);
this.superTypes = Collections.unmodifiableSet(s);
this.superTypes = s;
}
}
......@@ -124,7 +126,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
s.remove(typeName);
this.superTypes = Collections.unmodifiableSet(s);
this.superTypes = s;
}
}
......@@ -181,6 +183,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasClassificationDef.class)
public static class AtlasClassificationDefs extends PList<AtlasClassificationDef> {
private static final long serialVersionUID = 1L;
......
......@@ -17,11 +17,12 @@
*/
package org.apache.atlas.model.typedef;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -42,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializable {
private static final long serialVersionUID = 1L;
......@@ -91,9 +93,9 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
}
if (CollectionUtils.isEmpty(superTypes)) {
this.superTypes = Collections.emptySet();
this.superTypes = new HashSet<String>();
} else {
this.superTypes = Collections.unmodifiableSet(new HashSet<String>(superTypes));
this.superTypes = new HashSet<String>(superTypes);
}
}
......@@ -109,7 +111,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
s.add(typeName);
this.superTypes = Collections.unmodifiableSet(s);
this.superTypes = s;
}
}
......@@ -121,7 +123,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
s.remove(typeName);
this.superTypes = Collections.unmodifiableSet(s);
this.superTypes = s;
}
}
......@@ -178,6 +180,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasEntityDef.class)
public static class AtlasEntityDefs extends PList<AtlasEntityDef> {
private static final long serialVersionUID = 1L;
......
......@@ -20,6 +20,8 @@ package org.apache.atlas.model.typedef;
import java.io.Serializable;
import java.util.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -41,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -101,7 +104,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
if (CollectionUtils.isEmpty(elementDefs)) {
this.elementDefs = Collections.emptyList();
this.elementDefs = new ArrayList<AtlasEnumElementDef>();
} else {
// if multiple elements with same value are present, keep only the last entry
List<AtlasEnumElementDef> tmpList = new ArrayList<AtlasEnumElementDef>(elementDefs.size());
......@@ -124,7 +127,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
Collections.reverse(tmpList);
this.elementDefs = Collections.unmodifiableList(tmpList);
this.elementDefs = tmpList;
}
}
......@@ -154,7 +157,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
tmpList.add(new AtlasEnumElementDef(elementDef));
this.elementDefs = Collections.unmodifiableList(tmpList);
this.elementDefs = tmpList;
}
public void removeElement(String elemValue) {
......@@ -171,7 +174,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
}
this.elementDefs = Collections.unmodifiableList(tmpList);
this.elementDefs = tmpList;
}
}
......@@ -247,6 +250,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class AtlasEnumElementDef implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -348,6 +352,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasEnumDef.class)
public static class AtlasEnumDefs extends PList<AtlasEnumDef> {
private static final long serialVersionUID = 1L;
......
......@@ -25,6 +25,8 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
......@@ -46,6 +48,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -91,7 +94,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
if (CollectionUtils.isEmpty(attributeDefs)) {
this.attributeDefs = Collections.emptyList();
this.attributeDefs = new ArrayList<AtlasAttributeDef>();
} else {
// if multiple attributes with same name are present, keep only the last entry
List<AtlasAttributeDef> tmpList = new ArrayList<AtlasAttributeDef>(attributeDefs.size());
......@@ -114,7 +117,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
Collections.reverse(tmpList);
this.attributeDefs = Collections.unmodifiableList(tmpList);
this.attributeDefs = tmpList;
}
}
......@@ -140,7 +143,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
tmpList.add(new AtlasAttributeDef(attributeDef));
this.attributeDefs = Collections.unmodifiableList(tmpList);
this.attributeDefs = tmpList;
}
public void removeAttribute(String attrName) {
......@@ -156,7 +159,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
}
this.attributeDefs = Collections.unmodifiableList(tmpList);
this.attributeDefs = tmpList;
}
}
......@@ -233,6 +236,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class AtlasAttributeDef implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -414,6 +418,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasStructDef.class)
public static class AtlasStructDefs extends PList<AtlasStructDef> {
private static final long serialVersionUID = 1L;
......
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.model.typedef;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasTypesDef {
private List<AtlasEnumDef> enumDefs;
private List<AtlasStructDef> structDefs;
private List<AtlasClassificationDef> classificationDefs;
private List<AtlasEntityDef> entityDefs;
public AtlasTypesDef() {
enumDefs = new ArrayList<>();
structDefs = new ArrayList<>();
classificationDefs = new ArrayList<>();
entityDefs = new ArrayList<>();
}
public AtlasTypesDef(List<AtlasEnumDef> enumDefs, List<AtlasStructDef> structDefs,
List<AtlasClassificationDef> classificationDefs,
List<AtlasEntityDef> entityDefs) {
this.enumDefs = enumDefs;
this.structDefs = structDefs;
this.classificationDefs = classificationDefs;
this.entityDefs = entityDefs;
}
public List<AtlasEnumDef> getEnumDefs() {
return enumDefs;
}
public void setEnumDefs(List<AtlasEnumDef> enumDefs) {
this.enumDefs = enumDefs;
}
public List<AtlasStructDef> getStructDefs() {
return structDefs;
}
public void setStructDefs(List<AtlasStructDef> structDefs) {
this.structDefs = structDefs;
}
public List<AtlasClassificationDef> getClassificationDefs() {
return classificationDefs;
}
public void setClassificationDefs(List<AtlasClassificationDef> classificationDefs) {
this.classificationDefs = classificationDefs;
}
public List<AtlasEntityDef> getEntityDefs() {
return entityDefs;
}
public void setEntityDefs(List<AtlasEntityDef> entityDefs) {
this.entityDefs = entityDefs;
}
}
......@@ -15,8 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.api;
package org.apache.atlas.store;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
......@@ -28,13 +27,26 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import java.util.List;
/**
* API to work with CRUD of Atlas types - enum/struct/classification/entity.
* Interface to persistence store of TypeDef
*/
public interface AtlasApiTypes {
public interface AtlasTypeDefStore {
void init() throws AtlasBaseException;
/***********************/
/** EnumDef operation **/
/***********************/
AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> createEnumDefs(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException;
List<AtlasEnumDef> getAllEnumDefs() throws AtlasBaseException;
AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException;
AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException;
......@@ -49,9 +61,15 @@ public interface AtlasApiTypes {
AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException;
/*************************/
/** StructDef operation **/
/*************************/
AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> createStructDefs(List<AtlasStructDef> structDefs) throws AtlasBaseException;
List<AtlasStructDef> getAllStructDefs() throws AtlasBaseException;
AtlasStructDef getStructDefByName(String name) throws AtlasBaseException;
AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException;
......@@ -67,17 +85,24 @@ public interface AtlasApiTypes {
AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException;
/*********************************/
/** ClassificationDef operation **/
/*********************************/
AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> createClassificationDefs(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
List<AtlasClassificationDef> getAllClassificationDefs() throws AtlasBaseException;
AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException;
AtlasClassificationDef getClassificationDefByGuid(String guid) throws AtlasBaseException;
AtlasClassificationDef updateClassificationDefByName(String name, AtlasClassificationDef classificationDef)
throws AtlasBaseException;
throws AtlasBaseException;
AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef)
throws AtlasBaseException;
throws AtlasBaseException;
void deleteClassificationDefByName(String name) throws AtlasBaseException;
......@@ -86,19 +111,34 @@ public interface AtlasApiTypes {
AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException;
AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException;
/*************************/
/** EntityDef operation **/
/*************************/
AtlasEntityDef createEntityDefs(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
List<AtlasEntityDef> getAllEntityDefs() throws AtlasBaseException;
AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException;
AtlasEntityDef getEntityDefByIdByGuid(String guid) throws AtlasBaseException;
AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException;
AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
void deleteEntityDef(String name) throws AtlasBaseException;
void deleteEntityDefByName(String name) throws AtlasBaseException;
void deleteEntityDefByGuid(String guid) throws AtlasBaseException;
AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException;
/***** Bulk Operations *****/
AtlasTypesDef createTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
AtlasTypesDef updateTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException;
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.type;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP;
import org.apache.commons.lang.StringUtils;
import java.util.HashSet;
import java.util.Set;
/**
* Utility methods for AtlasType/AtlasTypeDef.
*/
public class AtlasTypeUtil {
private static final Set<String> ATLAS_BUILTIN_TYPENAMES = new HashSet<String>();
static {
for (String typeName : AtlasBaseTypeDef.ATLAS_BUILTIN_TYPES) {
ATLAS_BUILTIN_TYPENAMES.add(typeName);
}
}
public static Set<String> getReferencedTypeNames(String typeName) {
Set<String> ret = new HashSet<String>();
getReferencedTypeNames(typeName, ret);
return ret;
}
public static boolean isBuiltInType(String typeName) {
return ATLAS_BUILTIN_TYPENAMES.contains(typeName);
}
private static void getReferencedTypeNames(String typeName, Set<String> referencedTypeNames) {
if (StringUtils.isNotBlank(typeName) && !referencedTypeNames.contains(typeName)) {
if (typeName.startsWith(ATLAS_TYPE_ARRAY_PREFIX) && typeName.endsWith(ATLAS_TYPE_ARRAY_SUFFIX)) {
int startIdx = ATLAS_TYPE_ARRAY_PREFIX.length();
int endIdx = typeName.length() - ATLAS_TYPE_ARRAY_SUFFIX.length();
String elementTypeName = typeName.substring(startIdx, endIdx);
getReferencedTypeNames(elementTypeName, referencedTypeNames);
} else if (typeName.startsWith(ATLAS_TYPE_MAP_PREFIX) && typeName.endsWith(ATLAS_TYPE_MAP_SUFFIX)) {
int startIdx = ATLAS_TYPE_MAP_PREFIX.length();
int endIdx = typeName.length() - ATLAS_TYPE_MAP_SUFFIX.length();
String[] keyValueTypes = typeName.substring(startIdx, endIdx).split(ATLAS_TYPE_MAP_KEY_VAL_SEP, 2);
String keyTypeName = keyValueTypes.length > 0 ? keyValueTypes[0] : null;
String valueTypeName = keyValueTypes.length > 1 ? keyValueTypes[1] : null;
getReferencedTypeNames(keyTypeName, referencedTypeNames);
getReferencedTypeNames(valueTypeName, referencedTypeNames);
} else {
referencedTypeNames.add(typeName);
}
}
}
}
......@@ -1760,6 +1760,8 @@
<exclude>**/atlas.data/**</exclude>
<exclude>**/${sys:atlas.data}/**</exclude>
<exclude>**/policy-store.txt</exclude>
<exclude>**/*rebel*.xml</exclude>
<exclude>**/*rebel*.xml.bak</exclude>
</excludes>
</configuration>
<executions>
......
......@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1223 Type REST API v2 implementation (apoorvnaik via sumasai)
ATLAS-1210 patch file to add "position" attribute to hive_column type (sarath.kum4r@gmail.com via sumasai)
ATLAS-694 Update Atlas code to use graph abstraction layer (jnhagelb via sumasai)
ATLAS-1215 Atlas UI not working in firefox due to fix in ATLAS-1199 (kevalbhatt)
......
......@@ -34,6 +34,11 @@
<dependencies>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-intg</artifactId>
</dependency>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-typesystem</artifactId>
</dependency>
......
......@@ -18,6 +18,11 @@
package org.apache.atlas;
import com.google.inject.Binder;
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
import org.aopalliance.intercept.MethodInterceptor;
import org.apache.atlas.discovery.DataSetLineageService;
import org.apache.atlas.discovery.DiscoveryService;
......@@ -31,6 +36,7 @@ import org.apache.atlas.repository.audit.EntityAuditRepository;
import org.apache.atlas.repository.graph.DeleteHandler;
import org.apache.atlas.repository.graph.GraphBackedMetadataRepository;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
import org.apache.atlas.repository.typestore.GraphBackedTypeStore;
import org.apache.atlas.repository.typestore.ITypeStore;
import org.apache.atlas.service.Service;
......@@ -38,17 +44,13 @@ import org.apache.atlas.services.DefaultMetadataService;
import org.apache.atlas.services.IBootstrapTypesRegistrar;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.services.ReservedTypesRegistrar;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.typesystem.types.TypeSystem;
import org.apache.atlas.typesystem.types.TypeSystemProvider;
import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.apache.atlas.util.AtlasRepositoryConfiguration;
import org.apache.commons.configuration.Configuration;
import com.google.inject.Binder;
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
/**
* Guice module for Repository module.
*/
......@@ -65,6 +67,7 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
// bind the ITypeStore interface to an implementation
bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton();
bind(AtlasTypeDefStore.class).to(AtlasTypeDefGraphStoreV1.class).asEagerSingleton();
//GraphBackedSearchIndexer must be an eager singleton to force the search index creation to happen before
//we try to restore the type system (otherwise we'll end up running queries
......
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasClassificationDef
*/
public interface AtlasClassificationDefStore {
AtlasClassificationDef create(AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> create(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
List<AtlasClassificationDef> getAll() throws AtlasBaseException;
AtlasClassificationDef getByName(String name) throws AtlasBaseException;
AtlasClassificationDef getByGuid(String guid) throws AtlasBaseException;
AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException;
AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> update(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
AtlasClassificationDefs search(SearchFilter filter) throws AtlasBaseException;
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasEntityDef
*/
public interface AtlasEntityDefStore {
AtlasEntityDef create(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> create(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
List<AtlasEntityDef> getAll() throws AtlasBaseException;
AtlasEntityDef getByName(String name) throws AtlasBaseException;
AtlasEntityDef getByGuid(String guid) throws AtlasBaseException;
AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> update(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
AtlasEntityDefs search(SearchFilter filter) throws AtlasBaseException;
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasEnumDef
*/
public interface AtlasEnumDefStore {
AtlasEnumDef create(AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> create(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException;
List<AtlasEnumDef> getAll() throws AtlasBaseException;
AtlasEnumDef getByName(String name) throws AtlasBaseException;
AtlasEnumDef getByGuid(String guid) throws AtlasBaseException;
AtlasEnumDef updateByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException;
AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> update(List<AtlasEnumDef> enumDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
AtlasEnumDefs search(SearchFilter filter) throws AtlasBaseException;
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import java.util.List;
/**
* Interface for graph persistence store for AtlasStructDef
*/
public interface AtlasStructDefStore {
AtlasStructDef create(AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> create(List<AtlasStructDef> structDefs) throws AtlasBaseException;
List<AtlasStructDef> getAll() throws AtlasBaseException;
AtlasStructDef getByName(String name) throws AtlasBaseException;
AtlasStructDef getByGuid(String guid) throws AtlasBaseException;
AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> update(List<AtlasStructDef> structDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
AtlasStructDefs search(SearchFilter filter) throws AtlasBaseException;
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasElement;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashMap;
/**
* Utility methods for Graph.
*/
public class AtlasGraphUtilsV1 {
private static final Logger LOG = LoggerFactory.getLogger(AtlasGraphUtilsV1.class);
public static final String PROPERTY_PREFIX = Constants.INTERNAL_PROPERTY_KEY_PREFIX + "type.";
public static final String SUPERTYPE_EDGE_LABEL = PROPERTY_PREFIX + ".supertype";
public static final String VERTEX_TYPE = "typeSystem";
public static final BiMap<String, String> RESERVED_CHARS_ENCODE_MAP =
HashBiMap.create(new HashMap<String, String>() {{
put("{", "_o");
put("}", "_c");
put("\"", "_q");
put("$", "_d");
put("%", "_p");
}});
public static String getPropertyKey(AtlasBaseTypeDef typeDef) {
return getPropertyKey(typeDef.getName());
}
public static String getPropertyKey(AtlasBaseTypeDef typeDef, String child) {
return getPropertyKey(typeDef.getName(), child);
}
public static String getPropertyKey(String typeName) {
return PROPERTY_PREFIX + typeName;
}
public static String getPropertyKey(String typeName, String child) {
return PROPERTY_PREFIX + typeName + "." + child;
}
public static String getIdFromVertex(AtlasVertex vertex) {
return vertex.<String>getProperty(Constants.GUID_PROPERTY_KEY, String.class);
}
public static String getTypeName(AtlasVertex instanceVertex) {
return instanceVertex.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY, String.class);
}
public static String getEdgeLabel(String fromNode, String toNode) {
return PROPERTY_PREFIX + "edge." + fromNode + "." + toNode;
}
public static String encodePropertyKey(String key) {
String ret = key;
if (StringUtils.isNotBlank(key)) {
for (String str : RESERVED_CHARS_ENCODE_MAP.keySet()) {
ret = ret.replace(str, RESERVED_CHARS_ENCODE_MAP.get(str));
}
}
return ret;
}
public static String decodePropertyKey(String key) {
String ret = key;
if (StringUtils.isNotBlank(key)) {
for (String encodedStr : RESERVED_CHARS_ENCODE_MAP.values()) {
ret = ret.replace(encodedStr, RESERVED_CHARS_ENCODE_MAP.inverse().get(encodedStr));
}
}
return ret;
}
public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> setProperty({}, {}, {})", toString(element), propertyName, value);
}
propertyName = encodePropertyKey(propertyName);
Object existingValue = element.getProperty(propertyName, Object.class);
if (value == null || (value instanceof Collection && ((Collection)value).isEmpty())) {
if (existingValue != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Removing property {} from {}", propertyName, toString(element));
}
element.removeProperty(propertyName);
}
} else {
if (!value.equals(existingValue)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting property {} in {}", propertyName, toString(element));
}
element.setProperty(propertyName, value);
}
}
}
public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType) {
Object property = element.getProperty(encodePropertyKey(propertyName), returnType);
if (LOG.isDebugEnabled()) {
LOG.debug("getProperty({}, {}) ==> {}", toString(element), propertyName, returnType.cast(property));
}
return returnType.cast(property);
}
private static <T extends AtlasElement> String toString(T element) {
if (element instanceof AtlasVertex) {
return toString((AtlasVertex) element);
} else if (element instanceof AtlasEdge) {
return toString((AtlasEdge)element);
}
return element.toString();
}
public static String toString(AtlasVertex vertex) {
if(vertex == null) {
return "vertex[null]";
} else {
if (LOG.isDebugEnabled()) {
return getVertexDetails(vertex);
} else {
return String.format("vertex[id=%s]", vertex.getId().toString());
}
}
}
public static String toString(AtlasEdge edge) {
if(edge == null) {
return "edge[null]";
} else {
if (LOG.isDebugEnabled()) {
return getEdgeDetails(edge);
} else {
return String.format("edge[id=%s]", edge.getId().toString());
}
}
}
public static String getVertexDetails(AtlasVertex vertex) {
return String.format("vertex[id=%s type=%s guid=%s]",
vertex.getId().toString(), getTypeName(vertex), getIdFromVertex(vertex));
}
public static String getEdgeDetails(AtlasEdge edge) {
return String.format("edge[id=%s label=%s from %s -> to %s]", edge.getId(), edge.getLabel(),
toString(edge.getOutVertex()), toString(edge.getInVertex()));
}
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.util;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.PredicateUtils;
import org.apache.commons.collections.functors.NotPredicate;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.List;
public class FilterUtil {
public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
List<Predicate> predicates = new ArrayList<>();
final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE);
final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);
// Add filter for the type/category
if (StringUtils.isNotBlank(type)) {
predicates.add(getTypePredicate(type));
}
// Add filter for the supertype
if (StringUtils.isNotBlank(supertype)) {
predicates.add(getSuperTypePredicate(supertype));
}
// Add filter for the supertype negation
if (StringUtils.isNotBlank(notSupertype)) {
predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
}
return PredicateUtils.allPredicate(predicates);
}
private static Predicate getSuperTypePredicate(final String supertype) {
return new Predicate() {
private boolean isClassificationDef(Object o) {
return o instanceof AtlasClassificationDef;
}
private boolean isEntityDef(Object o) {
return o instanceof AtlasEntityDef;
}
@Override
public boolean evaluate(Object o) {
return (isClassificationDef(o) &&
((AtlasClassificationDef) o).getSuperTypes().contains(supertype))||
(isEntityDef(o) &&
((AtlasEntityDef)o).getSuperTypes().contains(supertype));
}
};
}
private static Predicate getTypePredicate(final String type) {
return new Predicate() {
@Override
public boolean evaluate(Object o) {
if (o instanceof AtlasBaseTypeDef) {
switch (type.toUpperCase()) {
case "CLASS":
case "ENTITY":
return o instanceof AtlasEntityDef;
case "TRAIT":
case "CLASSIFICATION":
return o instanceof AtlasClassificationDef;
case "STRUCT":
return o instanceof AtlasStructDef;
case "ENUM":
return o instanceof AtlasEnumDef;
default:
// This shouldn't have happened
return false;
}
} else {
return false;
}
}
};
}
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.util;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.typesystem.types.HierarchicalType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class TypeDefSorter {
private static final Logger LOG = LoggerFactory.getLogger(TypeDefSorter.class);
public static <T extends AtlasStructDef> List<T> sortTypes(List<T> types) {
Map<String, T> typesByName = new HashMap<>();
for (T type : types) {
typesByName.put(type.getName(), type);
}
List<T> result = new ArrayList<>(types.size());
Set<T> processed = new HashSet<>();
for (T type : types) {
addToResult(type, result, processed, typesByName);
}
return result;
}
private static <T extends AtlasStructDef> void addToResult(T type, List<T> result,
Set<T> processed,
Map<String, T> typesByName) {
if (processed.contains(type)) {
return;
}
processed.add(type);
Set<String> superTypeNames = new HashSet<>();
try {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
superTypeNames.addAll(classificationDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
}
try {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
superTypeNames.addAll(entityDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
}
for (String superTypeName : superTypeNames) {
// Recursively add any supertypes first to the result.
T superType = typesByName.get(superTypeName);
if (superType != null) {
addToResult(superType, result, processed, typesByName);
}
}
result.add(type);
}
}
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.web.rest.module;
import com.google.inject.AbstractModule;
import org.apache.atlas.type.AtlasTypeRegistry;
/**
* @author anaik
*/
public class RestModule extends AbstractModule {
@Override
protected void configure() {
bind(AtlasTypeRegistry.class).to(AtlasTypeRegistry.class).asEagerSingleton();
}
}
......@@ -27,7 +27,7 @@
<context-param>
<param-name>guice.packages</param-name>
<param-value>
org.apache.atlas.web.resources,org.apache.atlas.web.params
org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest
</param-value>
</context-param>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment