protected EntityState readEntityState( DefaultEntityStoreUnitOfWork unitOfWork, Reader entityState )
throws EntityStoreException
{
try
{
Module module = unitOfWork.module();
JSONDeserializer deserializer = new JSONDeserializer( module );
JSONObject jsonObject = new JSONObject( new JSONTokener( entityState ) );
EntityStatus status = EntityStatus.LOADED;
String version = jsonObject.getString( "version" );
long modified = jsonObject.getLong( "modified" );
String identity = jsonObject.getString( "identity" );
// Check if version is correct
String currentAppVersion = jsonObject.optString( MapEntityStore.JSONKeys.application_version.name(),
"0.0" );
if( !currentAppVersion.equals( application.version() ) )
{
if( migration != null )
{
migration.migrate( jsonObject, application.version(), this );
}
else
{
// Do nothing - set version to be correct
jsonObject.put( MapEntityStore.JSONKeys.application_version.name(), application.version() );
}
LoggerFactory.getLogger( MapEntityStoreMixin.class )
.debug(
"Updated version nr on " + identity + " from " + currentAppVersion + " to " + application.version() );
// State changed
status = EntityStatus.UPDATED;
}
String type = jsonObject.getString( "type" );
EntityDescriptor entityDescriptor = module.entityDescriptor( type );
if( entityDescriptor == null )
{
throw new EntityTypeNotFoundException( type );
}