status = EntityStatus.UPDATED;
}
String type = jsonObject.getString( "type" );
EntityDescriptor entityDescriptor = module.entityDescriptor( type );
if( entityDescriptor == null )
{
throw new EntityTypeNotFoundException( type );
}
Map<QualifiedName, Object> properties = new HashMap<QualifiedName, Object>();
JSONObject props = jsonObject.getJSONObject( "properties" );
for( PropertyDescriptor propertyDescriptor : entityDescriptor.state().properties() )
{
Object jsonValue;
try
{
jsonValue = props.get( propertyDescriptor.qualifiedName().name() );
}
catch( JSONException e )
{
// Value not found, default it
Object initialValue = propertyDescriptor.initialValue( module );
properties.put( propertyDescriptor.qualifiedName(), initialValue );
status = EntityStatus.UPDATED;
continue;
}
if( jsonValue == JSONObject.NULL )
{
properties.put( propertyDescriptor.qualifiedName(), null );
}
else
{
Object value = deserializer.deserialize( jsonValue, propertyDescriptor.valueType() );
properties.put( propertyDescriptor.qualifiedName(), value );
}
}
Map<QualifiedName, EntityReference> associations = new HashMap<QualifiedName, EntityReference>();
JSONObject assocs = jsonObject.getJSONObject( "associations" );
for( AssociationDescriptor associationType : entityDescriptor.state().associations() )
{
try
{
Object jsonValue = assocs.get( associationType.qualifiedName().name() );
EntityReference value = jsonValue == JSONObject.NULL ? null : EntityReference.parseEntityReference(
(String) jsonValue );
associations.put( associationType.qualifiedName(), value );
}
catch( JSONException e )
{
// Association not found, default it to null
associations.put( associationType.qualifiedName(), null );
status = EntityStatus.UPDATED;
}
}
JSONObject manyAssocs = jsonObject.getJSONObject( "manyassociations" );
Map<QualifiedName, List<EntityReference>> manyAssociations = new HashMap<QualifiedName, List<EntityReference>>();
for( AssociationDescriptor manyAssociationType : entityDescriptor.state().manyAssociations() )
{
List<EntityReference> references = new ArrayList<EntityReference>();
try
{
JSONArray jsonValues = manyAssocs.getJSONArray( manyAssociationType.qualifiedName().name() );