// Path: server/war/src/main/java/eu/stratuslab/marketplace/server/MarketplaceException.java
// @SuppressWarnings("serial")
// public class MarketplaceException extends RuntimeException {
// 
//     public MarketplaceException() {
//     }
// 
//     public MarketplaceException(String message) {
//         super(message);
//     }
//     
//     public MarketplaceException(String message, Throwable cause){
//     	super(message, cause);
//     }
// 
// }
// 
// Path: server/war/src/main/java/eu/stratuslab/marketplace/server/utils/MarketplaceUtils.java
// public final class MarketplaceUtils {
// 		
// 	private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
// 	
// 	private MarketplaceUtils(){}
// 	
// 	public static String getCurrentDate() {
// 		return getFormattedDate(new Date());
// 	}
// 
// 	public static Date getFormattedDate(String timestamp) throws ParseException{
// 		return getDateFormat().parse(timestamp);
// 	}
// 	
// 	public static String getFormattedDate(Date date){
// 		return getDateFormat().format(date);
// 	}
// 	
// 	private static DateFormat getDateFormat() {
// 		SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
// 		format.setLenient(false);
// 		format.setTimeZone(TimeZone.getTimeZone("UTC"));
// 
// 		return format;
// 	}
// 
// }


import eu.stratuslab.marketplace.server.MarketplaceException;
import eu.stratuslab.marketplace.server.utils.MarketplaceUtils;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
        StringRepresentation representation = new StringRepresentation(results,
                MediaType.APPLICATION_XML);

        // Returns the XML representation of this document.
        return representation;
    }
    
    private String getRangeFromRequest(){
		Form form = getRequest().getResourceRef().getQueryAsForm();
		String range = form.getFirstValue("range", "30");

		return range;
	}
    
    private String getHistoryRange(String range){
		Date today = new Date();
		Calendar cal = Calendar.getInstance();  
		cal.setTime(today);    
		
		int r = DEFAULT_RANGE;
		
		try {
			r = Integer.parseInt(range);
		} catch(NumberFormatException n){
			LOGGER.warning("incorrect range value entered: " + range);
		}
		
		cal.add(Calendar.DATE, -r);
		Date expiration = cal.getTime();
				
// Path: server/war/src/main/java/eu/stratuslab/marketplace/server/MarketplaceException.java
// @SuppressWarnings("serial")
// public class MarketplaceException extends RuntimeException {
// 
//     public MarketplaceException() {
//     }
// 
//     public MarketplaceException(String message) {
//         super(message);
//     }
//     
//     public MarketplaceException(String message, Throwable cause){
//     	super(message, cause);
//     }
// 
// }
// 
// Path: server/war/src/main/java/eu/stratuslab/marketplace/server/utils/MarketplaceUtils.java
// public final class MarketplaceUtils {
// 		
// 	private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
// 	
// 	private MarketplaceUtils(){}
// 	
// 	public static String getCurrentDate() {
// 		return getFormattedDate(new Date());
// 	}
// 
// 	public static Date getFormattedDate(String timestamp) throws ParseException{
// 		return getDateFormat().parse(timestamp);
// 	}
// 	
// 	public static String getFormattedDate(Date date){
// 		return getDateFormat().format(date);
// 	}
// 	
// 	private static DateFormat getDateFormat() {
// 		SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
// 		format.setLenient(false);
// 		format.setTimeZone(TimeZone.getTimeZone("UTC"));
// 
// 		return format;
// 	}
// 
// }


// Path: server/war/src/main/java/eu/stratuslab/marketplace/server/resources/EndorserResource.java
import eu.stratuslab.marketplace.server.MarketplaceException;
import eu.stratuslab.marketplace.server.utils.MarketplaceUtils;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;

        StringRepresentation representation = new StringRepresentation(results,
                MediaType.APPLICATION_XML);

        // Returns the XML representation of this document.
        return representation;
    }
    
    private String getRangeFromRequest(){
		Form form = getRequest().getResourceRef().getQueryAsForm();
		String range = form.getFirstValue("range", "30");

		return range;
	}
    
    private String getHistoryRange(String range){
		Date today = new Date();
		Calendar cal = Calendar.getInstance();  
		cal.setTime(today);    
		
		int r = DEFAULT_RANGE;
		
		try {
			r = Integer.parseInt(range);
		} catch(NumberFormatException n){
			LOGGER.warning("incorrect range value entered: " + range);
		}
		
		cal.add(Calendar.DATE, -r);
		Date expiration = cal.getTime();
				
		return MarketplaceUtils.getFormattedDate(expiration);