

package oracle.fusion.pts.restService;



import java.io.InputStream;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
import oracle.demo.pts.fusionservices.FusionUserDetailsService;
import oracle.fusion.pts.restService.exceptions.FusionGenericException;

import oracle.fusion.pts.restService.utils.RESTfulFusionService;
import com.oracle.xmlns.apps.hcm.people.roles.userdetailsservicev2.UserDetails;

import javax.ws.rs.core.Context;

import oracle.fusion.pts.restService.types.RESTUserDetailsResult;

@Path("/userdetails")

public class RESTfulUserDetailsService  extends RESTfulFusionService {
    
    FusionUserDetailsService objectService = new FusionUserDetailsService();
    String fusionEndpointName="fusionHCMUserDetailsService";

    /**
     * @param pHttpHeaders
     * @param pInputStream
     * @return
     * @throws JAXBException
     */
    @GET
    @Path("/self")
    @Produces({"application/xml", "application/json"})
    public RESTUserDetailsResult find(@Context HttpHeaders pHttpHeaders, String pAttributes,
                       String pQuery, String pConjunction,
                       InputStream pInputStream)
    {
        String xmlQuery=convertStreamToString(pInputStream);                                                     
        // Initialise the connections
        processRESTServiceHeaders(pHttpHeaders);
        objectService.initialiseConnection(this.getFusionJWTToken(), this.getFusionUsername(), this.getFusionPassword(), 
                                                  this.getFusionHCMEndpointURL(fusionEndpointName),this.getFetchSize(),this.getFetchStart());
        
        List<UserDetails> result = null;
        try {
            
            result=objectService.find(xmlQuery,"","","AND").getValue();
        } 
        catch (com.sun.xml.ws.client.ClientTransportAccessException ctae) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
        catch (Exception e) {
            logMessage("exception @ findPerson");
            e.printStackTrace();
            throw new FusionGenericException(e.getLocalizedMessage());    
        }

        RESTUserDetailsResult ro2=new RESTUserDetailsResult();
        ro2.setUserDetailsResult(result);
        return ro2;

    }

    public Object findXMLQuery(HttpHeaders pHttpHeaders,
                               InputStream pInputStream) {
        return null;
    }
}

