/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.k_int.webedit;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlTransient;

import com.k_int.webedit.layout.ContainerDTO;
import com.k_int.webedit.layout.PanelDTO;
import com.k_int.webedit.layout.TabPanelDTO;

import java.util.logging.Logger;


/**
 * REST Web Service
 *
 * The Data service retrieves data about a given URI, for example, given isbn:xxxxxx return the properties of that object.
 *
 * @author ibbo
 * @ImplicitProduces("text/html;qs=5")
 */

@XmlRootElement(name="tuple")
@XmlAccessorType(XmlAccessType.FIELD)
@Path("/Editor/Data/")
public class Data {
   
  // Been testing with curl  -H "Accept: application/json" "http://localhost:8080/WebEdit/Editor/Data/fgred?Accept=application/json"
  // @Context SecurtyContext sc;
  private static final Logger logger = Logger.getLogger( Editor.class.getName() );

  @XmlTransient
  @Context
  private UriInfo context;

  public TupleDTO tuple = null;
  public ContainerDTO layout = null;

  /** Creates a new instance of Made4UWorkOrderResource */
  public Data() {
    logger.info("New Data Instance");
  }

  /**
   * Retrieves representation of an instance of info.made4u.made4uws.workorder.Made4UWorkOrderResource
   * @param id resource URI parameter
   * @return an instance of java.lang.String
   */
  // @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
  @GET
  @Path("{uri}")
  @Produces({MediaType.APPLICATION_JSON})
  public Data getXml(@PathParam("uri") String uri) {
    logger.info("GetXML uri="+uri);
    tuple = new TupleDTO(uri);
    tuple.add("DC:Title","The value of some title");
    tuple.add("DC:Author","The value of some author");

    TabPanelDTO tab_panel = new TabPanelDTO();
    tab_panel.add(new PanelDTO("MimsyItem"));
    tab_panel.add(new PanelDTO("Other Tab 1"));
    tab_panel.add(new PanelDTO("Other Tab 2"));
    layout = tab_panel;

    return this;
  }

  /**
   * PUT method for updating or creating an instance of Made4UWorkOrderResource
   * @param id resource URI parameter
   * @param content representation for the resource
   * @return an HTTP response with content of the updated or created resource.
  @PUT
  @Consumes("application/xml")
  public void putXml(@PathParam("id")
  String id, String content) {
    System.out.println(content+","+id);
  }
   */
}
