use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.
the class AtlasStructDefStoreV1 method updateByName.
@Override
public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef);
}
validateType(structDef);
AtlasType type = typeRegistry.getType(structDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
if (vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
}
AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType) type, vertex, typeDefStore);
AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
AtlasStructDef ret = toStructDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.updateByName({}, {}): {}", name, structDef, ret);
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method deleteTypesDef.
@Override
@GraphTransaction
public void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
}
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
List<Object> preDeleteStructDefs = new ArrayList<>();
List<Object> preDeleteClassifiDefs = new ArrayList<>();
List<Object> preDeleteEntityDefs = new ArrayList<>();
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
if (StringUtils.isNotBlank(structDef.getGuid())) {
preDeleteStructDefs.add(structDefStore.preDeleteByGuid(structDef.getGuid()));
} else {
preDeleteStructDefs.add(structDefStore.preDeleteByName(structDef.getName()));
}
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
if (StringUtils.isNotBlank(classifiDef.getGuid())) {
preDeleteClassifiDefs.add(classifiDefStore.preDeleteByGuid(classifiDef.getGuid()));
} else {
preDeleteClassifiDefs.add(classifiDefStore.preDeleteByName(classifiDef.getName()));
}
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
if (StringUtils.isNotBlank(entityDef.getGuid())) {
preDeleteEntityDefs.add(entityDefStore.preDeleteByGuid(entityDef.getGuid()));
} else {
preDeleteEntityDefs.add(entityDefStore.preDeleteByName(entityDef.getName()));
}
}
}
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
int i = 0;
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
if (StringUtils.isNotBlank(structDef.getGuid())) {
structDefStore.deleteByGuid(structDef.getGuid(), preDeleteStructDefs.get(i));
} else {
structDefStore.deleteByName(structDef.getName(), preDeleteStructDefs.get(i));
}
i++;
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
int i = 0;
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
if (StringUtils.isNotBlank(classifiDef.getGuid())) {
classifiDefStore.deleteByGuid(classifiDef.getGuid(), preDeleteClassifiDefs.get(i));
} else {
classifiDefStore.deleteByName(classifiDef.getName(), preDeleteClassifiDefs.get(i));
}
i++;
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
int i = 0;
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
if (StringUtils.isNotBlank(entityDef.getGuid())) {
entityDefStore.deleteByGuid(entityDef.getGuid(), preDeleteEntityDefs.get(i));
} else {
entityDefStore.deleteByName(entityDef.getName(), preDeleteEntityDefs.get(i));
}
i++;
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
if (StringUtils.isNotBlank(enumDef.getGuid())) {
enumDefStore.deleteByGuid(enumDef.getGuid());
} else {
enumDefStore.deleteByName(enumDef.getName());
}
}
}
// Remove all from
ttr.removeTypesDef(typesDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method updateGraphStore.
private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
AtlasTypesDef ret = new AtlasTypesDef();
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
ret.getEnumDefs().add(enumDefStore.update(enumDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
ret.getStructDefs().add(structDefStore.update(structDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
ret.getClassificationDefs().add(classifiDefStore.update(classifiDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
ret.getEntityDefs().add(entityDefStore.update(entityDef));
}
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method createUpdateTypesDef.
@Override
@GraphTransaction
public AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeDefGraphStore.createUpdateTypesDef({}, {})", typesToCreate, typesToUpdate);
}
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
if (!typesToUpdate.isEmpty()) {
ttr.updateTypesWithNoRefResolve(typesToUpdate);
}
// Translate any NOT FOUND errors to BAD REQUEST
tryTypeCreation(typesToCreate, ttr);
AtlasTypesDef ret = addToGraphStore(typesToCreate, ttr);
if (!typesToUpdate.isEmpty()) {
AtlasTypesDef updatedTypes = updateGraphStore(typesToUpdate, ttr);
if (CollectionUtils.isNotEmpty(updatedTypes.getEnumDefs())) {
for (AtlasEnumDef enumDef : updatedTypes.getEnumDefs()) {
ret.getEnumDefs().add(enumDef);
}
}
if (CollectionUtils.isNotEmpty(updatedTypes.getStructDefs())) {
for (AtlasStructDef structDef : updatedTypes.getStructDefs()) {
ret.getStructDefs().add(structDef);
}
}
if (CollectionUtils.isNotEmpty(updatedTypes.getClassificationDefs())) {
for (AtlasClassificationDef classificationDef : updatedTypes.getClassificationDefs()) {
ret.getClassificationDefs().add(classificationDef);
}
}
if (CollectionUtils.isNotEmpty(updatedTypes.getEntityDefs())) {
for (AtlasEntityDef entityDef : updatedTypes.getEntityDefs()) {
ret.getEntityDefs().add(entityDef);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeDefGraphStore.createUpdateTypesDef({}, {}): {}", typesToCreate, typesToUpdate, ret);
}
return ret;
}
Aggregations