<repo_name>joaoambrosio/WeatherStation<file_sep>/MapReduce/src/DynamoSearch.java
import java.util.HashMap;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodb.model.AttributeValue;
import com.amazonaws.services.dynamodb.model.ComparisonOperator;
import com.amazonaws.services.dynamodb.model.Condition;
import com.amazonaws.services.dynamodb.model.ScanRequest;
import com.amazonaws.services.dynamodb.model.ScanResult;

public class DynamoSearch {

	static AmazonDynamoDBClient dynamoDB;
	
	private static void init() throws Exception {
        AWSCredentials credentials = new PropertiesCredentials(DynamoSearch.class.getResourceAsStream("AwsCredentials.properties"));

        dynamoDB = new AmazonDynamoDBClient(credentials);
    }
	
	public static void main(String[] args) throws Exception {
		
		long startTime = System.nanoTime();
		
        init();
        
        try {
            String tableName = "weatherstation";
            String key;
         
            key = "2012-10-25:Lisboa";
            HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
            Condition condition = new Condition().withComparisonOperator(ComparisonOperator.CONTAINS.toString()).withAttributeValueList(new AttributeValue(key));
            scanFilter.put("cityEvent", condition);
            ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
            ScanResult scanResult = dynamoDB.scan(scanRequest);
            System.out.println("Key scanned: " + key + ", with content: " + scanResult);

        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }
        
		long endTime = System.nanoTime();
		double totalTime = ((endTime - startTime) / 1000000);
		System.out.println("Total time: " + totalTime + ".");
	}
}<file_sep>/MapReduce/src/S3Search.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;

public class S3Search {

	public static void main(String[] args) throws IOException {

		long startTime = System.nanoTime();

		AmazonS3 s3 = new AmazonS3Client(new PropertiesCredentials(S3Search.class.getResourceAsStream("AwsCredentials.properties")));

		String bucketName = "weatherstationobjects";
		String key;

		try {
			key = "2012-10-25:Lisboa";
			S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
			System.out.println("Key scanned: " + key + ", with content:");
			displayTextInputStream(object.getObjectContent());

		} catch (AmazonServiceException ase) {
			System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, but was rejected with an error response for some reason.");
			System.out.println("Error Message:    " + ase.getMessage());
			System.out.println("HTTP Status Code: " + ase.getStatusCode());
			System.out.println("AWS Error Code:   " + ase.getErrorCode());
			System.out.println("Error Type:       " + ase.getErrorType());
			System.out.println("Request ID:       " + ase.getRequestId());
		} catch (AmazonClientException ace) {
			System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with S3, " + "such as not being able to access the network.");
			System.out.println("Error Message: " + ace.getMessage());
		}

		long endTime = System.nanoTime();
		double totalTime = ((endTime - startTime) / 1000000);
		System.out.println("Total time: " + totalTime + ".");
	}

	private static void displayTextInputStream(InputStream input) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(input));
		while (true) {
			String line = reader.readLine();
			if (line == null) break;

			System.out.println("    " + line);
		}
		System.out.println();
	}
}<file_sep>/README.md
WeatherStation
==============

Weather Station for Cloud Computing project.