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( JSONKeys.MANY_ASSOCIATIONS );
Map<QualifiedName, List<EntityReference>> manyAssociations = new HashMap<>();
for( AssociationDescriptor manyAssociationType : entityDescriptor.state().manyAssociations() )
{
List<EntityReference> references = new ArrayList<>();
try
{
JSONArray jsonValues = manyAssocs.getJSONArray( manyAssociationType.qualifiedName().name() );
for( int i = 0; i < jsonValues.length(); i++ )
{
Object jsonValue = jsonValues.getString( i );
EntityReference value = jsonValue == JSONObject.NULL
? null
: EntityReference.parseEntityReference( (String) jsonValue );
references.add( value );
}
manyAssociations.put( manyAssociationType.qualifiedName(), references );
}
catch( JSONException e )
{
// ManyAssociation not found, default to empty one
manyAssociations.put( manyAssociationType.qualifiedName(), references );
}
}
JSONObject namedAssocs = jsonObject.getJSONObject( JSONKeys.NAMED_ASSOCIATIONS );
Map<QualifiedName, Map<String, EntityReference>> namedAssociations = new HashMap<>();
for( AssociationDescriptor namedAssociationType : entityDescriptor.state().namedAssociations() )
{
Map<String, EntityReference> references = new LinkedHashMap<>();
try
{
JSONObject jsonValues = namedAssocs.getJSONObject( namedAssociationType.qualifiedName().name() );
JSONArray names = jsonValues.names();
if( names != null )
{
for( int idx = 0; idx < names.length(); idx++ )
{
String name = names.getString( idx );
Object value = jsonValues.get( name );
EntityReference ref = value == JSONObject.NULL
? null
: EntityReference.parseEntityReference( (String) value );
references.put( name, ref );
}
}