@Override public ITypedReferenceableInstance createInstance() throws AtlasException { return createInstance((String[]) null); }
public ITypedReferenceableInstance createInstance(Id id, AtlasSystemAttributes systemAttributes, String... traitNames) throws AtlasException{ return createInstanceWithTraits(id, systemAttributes, null, traitNames); }
if (val instanceof ITypedReferenceableInstance) { ITypedReferenceableInstance tr = (ITypedReferenceableInstance) val; if (!tr.getTypeName().equals(getName())) { return valType.convert(val, m); Id id = null; if (!s.typeName.equals(getName())) { return valType.convert(s, m); r != null ? createInstanceWithTraits(id, null, r, r.getTraits().toArray(new String[0])) : createInstance(id); validateId(((ReferenceableInstance) val).getId()); return (ReferenceableInstance) val; } else {
ITypedReferenceableInstance typedR = clsType.convert(r, Multiplicity.REQUIRED); Assert.assertEquals(typedR.toString(), "{\n" + "\tid : (type: t4, id: <unassigned>)\n" +
ownerType.toString(); ITypedReferenceableInstance ownerInstance = ownerType.createInstance(); ITypedReferenceableInstance valueInstance = valueType.createInstance();
@SuppressWarnings("rawtypes") @Test public void testSimpleModel() throws AtlasException { TypeSystem ts = TypeSystem.getInstance(); HierarchicalType a = new ClassType(ts, "a", null, ImmutableSet.<String>of(), 0); HierarchicalType b = new ClassType(ts, "B", null, ImmutableSet.of("a"), 0); HierarchicalType c = new ClassType(ts, "C", null, ImmutableSet.of("B"), 0); List<HierarchicalType> unsortedTypes = Arrays.asList(c, a, b); List<HierarchicalType> sortedTypes = HierarchicalTypeDependencySorter.sortTypes(unsortedTypes); Assert.assertEquals(sortedTypes.size(), 3); Assert.assertEquals(sortedTypes.indexOf(a), 0); Assert.assertEquals(sortedTypes.indexOf(b), 1); Assert.assertEquals(sortedTypes.indexOf(c), 2); }
@Override public void updateSignatureHash(MessageDigest digester, Object val) throws AtlasException { if( !(val instanceof ITypedReferenceableInstance)) { throw new IllegalArgumentException("Unexpected value type " + val.getClass().getSimpleName() + ". Expected instance of ITypedStruct"); } digester.update(getName().getBytes(Charset.forName("UTF-8"))); if(fieldMapping.fields != null && val != null) { IReferenceableInstance typedValue = (IReferenceableInstance) val; if(fieldMapping.fields.values() != null) { for (AttributeInfo aInfo : fieldMapping.fields.values()) { Object attrVal = typedValue.get(aInfo.name); if (attrVal != null) { aInfo.dataType().updateSignatureHash(digester, attrVal); } } } } } }
private void validateAndSetupSuperTypes() throws AtlasException { for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { validateSuperTypes(TraitType.class, traitDef); TraitType traitType = getDataType(TraitType.class, traitDef.typeName); traitType.setupSuperTypesGraph(); } for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { validateSuperTypes(ClassType.class, classDef); ClassType classType = getDataType(ClassType.class, classDef.typeName); classType.setupSuperTypesGraph(); } }
@Override public String getSignatureHash(MessageDigest digester) throws AtlasException { ClassType classType = TypeSystem.getInstance().getDataType(ClassType.class, getTypeName()); classType.updateSignatureHash(digester, this); byte[] digest = digester.digest(); return SHA256Utils.toString(digest); } }
if (val instanceof ITypedReferenceableInstance) { ITypedReferenceableInstance tr = (ITypedReferenceableInstance) val; if (!tr.getTypeName().equals(getName())) { return valType.convert(val, m); Id id = null; if (!s.typeName.equals(getName())) { return valType.convert(s, m); r != null ? createInstanceWithTraits(id, null, r, r.getTraits().toArray(new String[0])) : createInstance(id); validateId(((ReferenceableInstance) val).getId()); return (ReferenceableInstance) val; } else {
Referenceable hrDept = createDeptEg1(ts); ClassType deptType = ts.getDataType(ClassType.class, "Department"); ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
ownerType.toString(); ITypedReferenceableInstance ownerInstance = ownerType.createInstance(); ITypedReferenceableInstance valueInstance = valueType.createInstance();
@SuppressWarnings("rawtypes") @Test public void testSimpleModel() throws AtlasException { TypeSystem ts = TypeSystem.getInstance(); HierarchicalType a = new ClassType(ts, "a", null, ImmutableSet.<String>of(), 0); HierarchicalType b = new ClassType(ts, "B", null, ImmutableSet.of("a"), 0); HierarchicalType c = new ClassType(ts, "C", null, ImmutableSet.of("B"), 0); List<HierarchicalType> unsortedTypes = Arrays.asList(c, a, b); List<HierarchicalType> sortedTypes = HierarchicalTypeDependencySorter.sortTypes(unsortedTypes); Assert.assertEquals(sortedTypes.size(), 3); Assert.assertEquals(sortedTypes.indexOf(a), 0); Assert.assertEquals(sortedTypes.indexOf(b), 1); Assert.assertEquals(sortedTypes.indexOf(c), 2); }
@Override public void updateSignatureHash(MessageDigest digester, Object val) throws AtlasException { if( !(val instanceof ITypedReferenceableInstance)) { throw new IllegalArgumentException("Unexpected value type " + val.getClass().getSimpleName() + ". Expected instance of ITypedStruct"); } digester.update(getName().getBytes(Charset.forName("UTF-8"))); if(fieldMapping.fields != null && val != null) { IReferenceableInstance typedValue = (IReferenceableInstance) val; if(fieldMapping.fields.values() != null) { for (AttributeInfo aInfo : fieldMapping.fields.values()) { Object attrVal = typedValue.get(aInfo.name); if (attrVal != null) { aInfo.dataType().updateSignatureHash(digester, attrVal); } } } } } }
private void validateAndSetupSuperTypes() throws AtlasException { for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { validateSuperTypes(TraitType.class, traitDef); TraitType traitType = getDataType(TraitType.class, traitDef.typeName); traitType.setupSuperTypesGraph(); } for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { validateSuperTypes(ClassType.class, classDef); ClassType classType = getDataType(ClassType.class, classDef.typeName); classType.setupSuperTypesGraph(); } }
@Override public String getSignatureHash(MessageDigest digester) throws AtlasException { ClassType classType = TypeSystem.getInstance().getDataType(ClassType.class, getTypeName()); classType.updateSignatureHash(digester, this); byte[] digest = digester.digest(); return SHA256Utils.toString(digest); } }
@Override public ITypedReferenceableInstance createInstance() throws AtlasException { return createInstance((String[]) null); }
Referenceable hrDept = createDeptEg1(ts); ClassType deptType = ts.getDataType(ClassType.class, "Department"); ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
@SuppressWarnings("rawtypes") @Test public void testLargerModel() throws Exception { TypeSystem ts = TypeSystem.getInstance(); HierarchicalType testObjectType = new ClassType(ts, "TestObject", null, ImmutableSet.<String>of(), 0); HierarchicalType testDataSetType = new ClassType(ts, "TestDataSet", null, ImmutableSet.of("TestObject"), 0); HierarchicalType testColumnType = new ClassType(ts, "TestColumn", null, ImmutableSet.of("TestObject"), 0); HierarchicalType testRelationalDataSetType = new ClassType(ts, "TestRelationalDataSet", null, ImmutableSet.of("TestDataSet"), 0); HierarchicalType testTableType = new ClassType(ts, "Table", null, ImmutableSet.of("TestDataSet"), 0); HierarchicalType testDataFileType = new ClassType(ts, "TestDataFile", null, ImmutableSet.of("TestRelationalDataSet"), 0); HierarchicalType testDocumentType = new ClassType(ts, "TestDocument", null, ImmutableSet.of("TestDataSet"), 0); HierarchicalType testAnnotationType = new ClassType(ts, "TestAnnotation", null, ImmutableSet.<String>of(), 0); HierarchicalType myNewAnnotationType = new ClassType(ts, "MyNewAnnotation", null, ImmutableSet.of("TestAnnotation"), 0); List<HierarchicalType> unsortedTypes = Arrays.asList(testTableType, testColumnType, myNewAnnotationType, testDataSetType, testDataFileType, testAnnotationType, testRelationalDataSetType, testObjectType, testDocumentType); List<HierarchicalType> sortedTypes = HierarchicalTypeDependencySorter.sortTypes(unsortedTypes); // Verify that super types were sorted before their subtypes. Assert.assertTrue(sortedTypes.indexOf(testObjectType) < sortedTypes.indexOf(testDataSetType)); Assert.assertTrue(sortedTypes.indexOf(testObjectType) < sortedTypes.indexOf(testColumnType)); Assert.assertTrue(sortedTypes.indexOf(testDataSetType) < sortedTypes.indexOf(testRelationalDataSetType)); Assert.assertTrue(sortedTypes.indexOf(testDataSetType) < sortedTypes.indexOf(testDocumentType)); Assert.assertTrue(sortedTypes.indexOf(testDataSetType) < sortedTypes.indexOf(testTableType)); Assert.assertTrue(sortedTypes.indexOf(testRelationalDataSetType) < sortedTypes.indexOf(testDataFileType)); Assert.assertTrue(sortedTypes.indexOf(testAnnotationType) < sortedTypes.indexOf(myNewAnnotationType)); } }