Search in sources :

Example 16 with IStruct

use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.

the class HookMessageDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    HookMessageDeserializer deserializer = new HookMessageDeserializer();
    Referenceable entity = EntityNotificationImplTest.getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    HookNotification.EntityUpdateRequest message = new HookNotification.EntityUpdateRequest("user1", entity);
    String json = AbstractNotification.getMessageJson(message);
    HookNotification.HookNotificationMessage deserializedMessage = deserializer.deserialize(json);
    assertEquals(deserializedMessage.getType(), message.getType());
    assertEquals(deserializedMessage.getUser(), message.getUser());
    assertTrue(deserializedMessage instanceof HookNotification.EntityUpdateRequest);
    HookNotification.EntityUpdateRequest deserializedEntityUpdateRequest = (HookNotification.EntityUpdateRequest) deserializedMessage;
    Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
    assertEquals(deserializedEntity.getId(), entity.getId());
    assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
    assertEquals(deserializedEntity.getTraits(), entity.getTraits());
    assertEquals(deserializedEntity.getTrait(traitName), entity.getTrait(traitName));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) EntityNotificationImplTest(org.apache.atlas.notification.entity.EntityNotificationImplTest) Test(org.testng.annotations.Test)

Example 17 with IStruct

use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.

the class EntityNotificationImplTest method testGetAllTraits.

@Test
public void testGetAllTraits() throws Exception {
    Referenceable entity = getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    EntityNotificationImpl entityNotification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, traitInfo);
    assertEquals(traitInfo, entityNotification.getAllTraits());
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 18 with IStruct

use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.

the class ObjectGraphTraversal method processStruct.

void processStruct(Object val) throws AtlasException {
    if (val == null || !(val instanceof IStruct)) {
        return;
    }
    IStruct i = (IStruct) val;
    IConstructableType type = typeSystem.getDataType(IConstructableType.class, i.getTypeName());
    for (Map.Entry<String, AttributeInfo> e : type.fieldMapping().fields.entrySet()) {
        AttributeInfo aInfo = e.getValue();
        String attrName = e.getKey();
        if (aInfo.dataType().getTypeCategory() != DataTypes.TypeCategory.PRIMITIVE) {
            processValue(aInfo.dataType(), i.get(attrName));
        }
    }
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 19 with IStruct

use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.

the class ClassType method createInstanceWithTraits.

public ITypedReferenceableInstance createInstanceWithTraits(Id id, AtlasSystemAttributes systemAttributes, Referenceable r, String... traitNames) throws AtlasException {
    ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<>();
    if (traitNames != null) {
        for (String t : traitNames) {
            TraitType tType = typeSystem.getDataType(TraitType.class, t);
            IStruct iTraitObject = r == null ? null : r.getTrait(t);
            ITypedStruct trait = iTraitObject == null ? tType.createInstance() : tType.convert(iTraitObject, Multiplicity.REQUIRED);
            b.put(t, trait);
        }
    }
    return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), systemAttributes, fieldMapping, new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts], fieldMapping.numInts == 0 ? null : new int[fieldMapping.numInts], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ImmutableMap(com.google.common.collect.ImmutableMap) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) IStruct(org.apache.atlas.typesystem.IStruct)

Example 20 with IStruct

use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.

the class EntityMessageDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    EntityMessageDeserializer deserializer = new EntityMessageDeserializer();
    Referenceable entity = EntityNotificationImplTest.getEntity("id");
    String traitName = "MyTrait";
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    EntityNotificationImpl notification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, traitInfo);
    String json = AbstractNotification.getMessageJson(notification);
    EntityNotification deserializedNotification = deserializer.deserialize(json);
    assertEquals(deserializedNotification.getOperationType(), notification.getOperationType());
    assertEquals(deserializedNotification.getEntity().getId(), notification.getEntity().getId());
    assertEquals(deserializedNotification.getEntity().getTypeName(), notification.getEntity().getTypeName());
    assertEquals(deserializedNotification.getEntity().getTraits(), notification.getEntity().getTraits());
    assertEquals(deserializedNotification.getEntity().getTrait(traitName), notification.getEntity().getTrait(traitName));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

IStruct (org.apache.atlas.typesystem.IStruct)34 Struct (org.apache.atlas.typesystem.Struct)16 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)11 Referenceable (org.apache.atlas.typesystem.Referenceable)11 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)10 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)8 HashMap (java.util.HashMap)7 TraitType (org.apache.atlas.typesystem.types.TraitType)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 Map (java.util.Map)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ArrayList (java.util.ArrayList)3 AtlasException (org.apache.atlas.AtlasException)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 List (java.util.List)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2