public void onReceive(Object message) {
if(message instanceof String) {
ActorRef metadataPersist = getContext().actorFor("/user/ckanMetadataPersist");
ActorRef resourceFetcher = getContext().actorFor("/user/ckanResourceFetcher");
ActorRef zipResourceFetcher = getContext().actorFor("/user/ckanZipResourceFetcher");
String url = (String) message;
try {
String response = new Resty().text(url).toString();
Metadata metadata = new Gson().fromJson(response, Metadata.class);
metadataPersist.tell(metadata, getSelf());
for(MetadataResource resource : metadata.resources) {
resource.metadata_name = metadata.name;
if(metadata.extras != null) {
if(metadata.extras.containsKey("encoding")) {
resource.encoding = metadata.extras.get("encoding");
}
}
if(resource.format.toLowerCase().equals("zip")) {
zipResourceFetcher.tell(resource, getSelf());
} else {
resourceFetcher.tell(resource, getSelf());
}
}