Last active
August 29, 2015 14:18
-
-
Save penguinbroker/bc4493e7e6def45da291 to your computer and use it in GitHub Desktop.
clean slide uris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package migrations | |
import global.{ComponentRegistry, DaoRegistry} | |
import com.amazonaws.services.dynamodbv2.model.AttributeValue | |
import java.net.URI | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
object SlideUriMigration extends DatabaseMigration with DaoRegistry { | |
val TableName = "slide" | |
private val embedlyUrlCol = "embedlyUrl" | |
def execute = | |
modifyRows(TableName)(cleanUris) | |
private def cleanUris(attributes: Map[String, AttributeValue]): Map[String, AttributeValue] = { | |
val uri = attributes.get(embedlyUrlCol).map(_.getS) | |
uri map { u => | |
try { | |
val url = new URI(u) | |
attributes | |
} catch { | |
case e: Exception => attributes - embedlyUrlCol | |
} | |
} getOrElse attributes | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment