// 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;
/**
 * Created as part of the StratusLab project (http://stratuslab.eu),
 * co-funded by the European Commission under the Grant Agreement
 * INSFO-RI-261552.
 *
 * Copyright (c) 2011
 *
 * 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 eu.stratuslab.marketplace.server.resources;




/**
 * This resource represents a single endorser
 */
public class EndorserResource extends BaseResource {

	private static final int DEFAULT_RANGE = 30;
	
    private String query = null;
    private String email = null;
            
    @Override
    protected void doInit() {
        email = (String) getRequest().getAttributes().get("email");
        
        String range = getRangeFromRequest();
        
        query = getQueryBuilder().buildEndorserQuery(email, getHistoryRange(range));
    }

    @Get("html")
    public Representation toHtml() {
        List<Map<String, String>> results = new ArrayList<Map<String, String>>();
        
        try {
        	results = query(query);
// 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;

/**
 * Created as part of the StratusLab project (http://stratuslab.eu),
 * co-funded by the European Commission under the Grant Agreement
 * INSFO-RI-261552.
 *
 * Copyright (c) 2011
 *
 * 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 eu.stratuslab.marketplace.server.resources;




/**
 * This resource represents a single endorser
 */
public class EndorserResource extends BaseResource {

	private static final int DEFAULT_RANGE = 30;
	
    private String query = null;
    private String email = null;
            
    @Override
    protected void doInit() {
        email = (String) getRequest().getAttributes().get("email");
        
        String range = getRangeFromRequest();
        
        query = getQueryBuilder().buildEndorserQuery(email, getHistoryRange(range));
    }

    @Get("html")
    public Representation toHtml() {
        List<Map<String, String>> results = new ArrayList<Map<String, String>>();
        
        try {
        	results = query(query);
        } catch(MarketplaceException e){