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));
}
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());
}
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));
}
}
}
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());
}
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));
}
Aggregations