// Path: core/src/main/java/org/n52/supervisor/checks/AbstractServiceCheckRunner.java
// public abstract class AbstractServiceCheckRunner implements CheckRunner {
// 
//     protected static final DateFormat ISO8601LocalFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:SS.SSS");
// 
//     private static Logger log = LoggerFactory.getLogger(AbstractServiceCheckRunner.class);
// 
//     protected Client client = new Client();
// 
//     private final List<CheckResult> results = new ArrayList<CheckResult>();
// 
//     protected ServiceCheck check;
// 
//     private ResultDatabase rd;
// 
//     public AbstractServiceCheckRunner(final ServiceCheck check) {
//         this.check = check;
//     }
// 
//     @Override
//     public synchronized void addResult(final CheckResult result) {
//         results.add(result);
//         log.debug("Result added: " + result);
//     }
// 
//     public synchronized void clearResults() {
//     	log.debug("Clearing {} results",results.size());
//         results.clear();
//     }
// 
//     protected ServiceCheckResult createNegativeResult(final String text) {
//     	ResultType type = CheckResult.ResultType.NEGATIVE;
//     	final ServiceCheckResult result = createResult(text, type);
//         return result;
//     }
// 
//     
//     protected ServiceCheckResult createPositiveResult(final String text) {
//     	ResultType type = CheckResult.ResultType.POSITIVE;
//     	final ServiceCheckResult result = createResult(text, type);
//         return result;
//     }
//     
//     protected ServiceCheckResult createResult(final String text, ResultType type) {
// 		final ServiceCheckResult result = new ServiceCheckResult(
//     			ID_GENERATOR.generate(),
//     			check.getIdentifier(),
//     			text,
//     			new Date(),
//     			type,
//     			check.getServiceIdentifier());
// 		return result;
// 	}
// 
//     @Override
//     public Check getCheck() {
//         return check;
//     }
// 
//     @Override
//     public synchronized Collection<CheckResult> getResults() {
//         return results;
//     }
//     
//     @Override
//     public synchronized Collection<CheckResult> getAndClearResults() {
//     	List<CheckResult> copy = new ArrayList<CheckResult>(this.results);
//     	results.clear();
//     	return copy;
//     }
// 
//     @Override
//     public void notifyFailure() {
//         log.info("Check FAILED: {}", this);
// 
//         if (check.getNotificationEmail() == null) {
//             log.error("Can not notify via email, is null!");
//         } else {
//             final Collection<CheckResult> failures = new ArrayList<CheckResult>();
//             
//             synchronized (this) {
//             	for (final CheckResult r : results) {
//                     if (r.getType().equals(CheckResult.ResultType.NEGATIVE)) {
//     					failures.add(r);
//     				}
//                 }	
// 			}
// 
//             final Notification n = new EmailNotification(check, failures);
//             submitNotification(n);
//         }
//     }
// 
//     @Override
//     public void notifySuccess() {
//         log.info("Check SUCCESSFUL: {}", this);
//     }
// 
//     protected boolean saveAndReturnNegativeResult(final String text) {
//         final ServiceCheckResult r = createNegativeResult(text);
//         addResult(r);
//         return false;
//     }
// 
//     @Override
//     public void setCheck(final Check c) throws UnsupportedCheckException {
//         if (c instanceof ServiceCheck) {
//             final ServiceCheck sc = (ServiceCheck) c;
//             check = sc;
//         } else {
// 			throw new UnsupportedCheckException();
// 		}
//     }
// 
//     @Override
//     public void setResultDatabase(final ResultDatabase rd) {
//         this.rd = rd;
//     }
// 
// 	public void submitNotification(Notification n) {
// 		SendEmailTask set = new SendEmailTask(
//         		SupervisorProperties.instance().getAdminEmail(), rd);
//         set.addNotification(n);
//         set.execute();
// 	}
// 
// 	public List<CheckResult> getLatestDatabaseResults() {
// 		return rd.getLatestResults();
// 	}
// 
// }


import org.n52.supervisor.checks.AbstractServiceCheckRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.codehaus.jackson.map.ObjectMapper;
/**
 * ﻿Copyright (C) 2013 - 2014 52°North Initiative for Geospatial Open Source Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.supervisor.checks.json;




@XmlRootElement
public class EnviroCarAggregationChecker extends BaseEnviroCarChecker {
    
    private static final Logger logger = LoggerFactory.getLogger(EnviroCarAggregationChecker.class);
    
    private String apiTrackUrl;
    private String aggregationTrackUrl;
    
	public static void main(String[] args) {
		String u1 = "https://envirocar.org/api/stable/tracks?limit=250&page=0";
		String u2 = "http://ags.dev.52north.org:8080/point-aggregation/aggregatedTracks";

		EnviroCarAggregationChecker checker = new EnviroCarAggregationChecker(u1, u2, null);
		boolean result = checker.new Runner().check();
	}
    
    public EnviroCarAggregationChecker() {
        super(null);
    }
    
    
    public EnviroCarAggregationChecker(String apiTrackUrl, String aggregationTrackUrl, String email) {
        super(email);
        this.apiTrackUrl = apiTrackUrl;
        this.aggregationTrackUrl = aggregationTrackUrl;
    }
    
// Path: core/src/main/java/org/n52/supervisor/checks/AbstractServiceCheckRunner.java
// public abstract class AbstractServiceCheckRunner implements CheckRunner {
// 
//     protected static final DateFormat ISO8601LocalFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:SS.SSS");
// 
//     private static Logger log = LoggerFactory.getLogger(AbstractServiceCheckRunner.class);
// 
//     protected Client client = new Client();
// 
//     private final List<CheckResult> results = new ArrayList<CheckResult>();
// 
//     protected ServiceCheck check;
// 
//     private ResultDatabase rd;
// 
//     public AbstractServiceCheckRunner(final ServiceCheck check) {
//         this.check = check;
//     }
// 
//     @Override
//     public synchronized void addResult(final CheckResult result) {
//         results.add(result);
//         log.debug("Result added: " + result);
//     }
// 
//     public synchronized void clearResults() {
//     	log.debug("Clearing {} results",results.size());
//         results.clear();
//     }
// 
//     protected ServiceCheckResult createNegativeResult(final String text) {
//     	ResultType type = CheckResult.ResultType.NEGATIVE;
//     	final ServiceCheckResult result = createResult(text, type);
//         return result;
//     }
// 
//     
//     protected ServiceCheckResult createPositiveResult(final String text) {
//     	ResultType type = CheckResult.ResultType.POSITIVE;
//     	final ServiceCheckResult result = createResult(text, type);
//         return result;
//     }
//     
//     protected ServiceCheckResult createResult(final String text, ResultType type) {
// 		final ServiceCheckResult result = new ServiceCheckResult(
//     			ID_GENERATOR.generate(),
//     			check.getIdentifier(),
//     			text,
//     			new Date(),
//     			type,
//     			check.getServiceIdentifier());
// 		return result;
// 	}
// 
//     @Override
//     public Check getCheck() {
//         return check;
//     }
// 
//     @Override
//     public synchronized Collection<CheckResult> getResults() {
//         return results;
//     }
//     
//     @Override
//     public synchronized Collection<CheckResult> getAndClearResults() {
//     	List<CheckResult> copy = new ArrayList<CheckResult>(this.results);
//     	results.clear();
//     	return copy;
//     }
// 
//     @Override
//     public void notifyFailure() {
//         log.info("Check FAILED: {}", this);
// 
//         if (check.getNotificationEmail() == null) {
//             log.error("Can not notify via email, is null!");
//         } else {
//             final Collection<CheckResult> failures = new ArrayList<CheckResult>();
//             
//             synchronized (this) {
//             	for (final CheckResult r : results) {
//                     if (r.getType().equals(CheckResult.ResultType.NEGATIVE)) {
//     					failures.add(r);
//     				}
//                 }	
// 			}
// 
//             final Notification n = new EmailNotification(check, failures);
//             submitNotification(n);
//         }
//     }
// 
//     @Override
//     public void notifySuccess() {
//         log.info("Check SUCCESSFUL: {}", this);
//     }
// 
//     protected boolean saveAndReturnNegativeResult(final String text) {
//         final ServiceCheckResult r = createNegativeResult(text);
//         addResult(r);
//         return false;
//     }
// 
//     @Override
//     public void setCheck(final Check c) throws UnsupportedCheckException {
//         if (c instanceof ServiceCheck) {
//             final ServiceCheck sc = (ServiceCheck) c;
//             check = sc;
//         } else {
// 			throw new UnsupportedCheckException();
// 		}
//     }
// 
//     @Override
//     public void setResultDatabase(final ResultDatabase rd) {
//         this.rd = rd;
//     }
// 
// 	public void submitNotification(Notification n) {
// 		SendEmailTask set = new SendEmailTask(
//         		SupervisorProperties.instance().getAdminEmail(), rd);
//         set.addNotification(n);
//         set.execute();
// 	}
// 
// 	public List<CheckResult> getLatestDatabaseResults() {
// 		return rd.getLatestResults();
// 	}
// 
// }


// Path: json/src/main/java/org/n52/supervisor/checks/json/EnviroCarAggregationChecker.java
import org.n52.supervisor.checks.AbstractServiceCheckRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * ﻿Copyright (C) 2013 - 2014 52°North Initiative for Geospatial Open Source Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.n52.supervisor.checks.json;




@XmlRootElement
public class EnviroCarAggregationChecker extends BaseEnviroCarChecker {
    
    private static final Logger logger = LoggerFactory.getLogger(EnviroCarAggregationChecker.class);
    
    private String apiTrackUrl;
    private String aggregationTrackUrl;
    
	public static void main(String[] args) {
		String u1 = "https://envirocar.org/api/stable/tracks?limit=250&page=0";
		String u2 = "http://ags.dev.52north.org:8080/point-aggregation/aggregatedTracks";

		EnviroCarAggregationChecker checker = new EnviroCarAggregationChecker(u1, u2, null);
		boolean result = checker.new Runner().check();
	}
    
    public EnviroCarAggregationChecker() {
        super(null);
    }
    
    
    public EnviroCarAggregationChecker(String apiTrackUrl, String aggregationTrackUrl, String email) {
        super(email);
        this.apiTrackUrl = apiTrackUrl;
        this.aggregationTrackUrl = aggregationTrackUrl;
    }
    
    public class Runner extends AbstractServiceCheckRunner {