package qa.qcri.mm.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import qa.qcri.mm.api.entity.ClientApp;
import qa.qcri.mm.api.service.ClientAppService;
import qa.qcri.mm.api.store.CodeLookUp;
import qa.qcri.mm.api.store.StatusCodeType;
import qa.qcri.mm.api.template.ClientAppModel;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jlucas
 * Date: 2/21/14
 * Time: 1:44 AM
 * To change this template use File | Settings | File Templates.
 */
@Path("/clientapp")
@Component
public class ClientAppController {
    @Autowired
    private ClientAppService clientAppService;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/delete/{crisiscode}/{attributecode}")
    public Response getCrisisByID(@PathParam("crisiscode") String crisiscode,
                                @PathParam("attributecode") String attributecode){

        String shortName = crisiscode+"_"+ attributecode;
        clientAppService.updateClientAppByShortName(shortName, StatusCodeType.CLIENT_APP_INACTIVE);

        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();

    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/delete/crisis/{crisisID}")
    public Response disableClientApps(@PathParam("crisisID") Long crisisID){

        try{
            clientAppService.deactivateClientAppByCrisis(crisisID);
        }
        catch(Exception e){
            System.out.println("disableClientApps : " + e);
        }


        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/delete/attribute/{crisisID}/{attributeID}")
    public Response disableClientApp(@PathParam("crisisID") Long crisisID, @PathParam("attributeID") Long attributeID){

        try{
            clientAppService.deactivateClientAppByAttribute(crisisID, attributeID);
        }
        catch(Exception e){
            System.out.println("disableClientApps : " + e);
        }


        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/allactive")
    public List<ClientAppModel> getAllActive(){
        return clientAppService.getAllActiveClientApps();
    }


    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/get/crisis/{crisisID}")
    public List<ClientApp> getClientAppsByCrisisID(@PathParam("crisisID") Long crisisID){
        return clientAppService.getAllClientAppByCrisisID(crisisID);
    }


    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/activate/mobile/crisis/{crisisID}")
    public Response enableMobileClientAppByCrisisID(@PathParam("crisisID") Long crisisID){
        Integer status = StatusCodeType.AIDR_MICROMAPPER_BOTH;
        String returnValue = clientAppService.enableForClientAppStatusByCrisisID(crisisID, status);
        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(returnValue).build();
    }




}

@@ -849,2468 +849,187 @@
 e;%0A%0A
-    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/delete/%7Bcrisiscode%7D/%7Battributecode%7D%22)%0A    public Response getCrisisByID(@PathParam(%22crisiscode%22) String crisiscode,%0A                                @PathParam(%22attributecode%22) String attributecode)%7B%0A%0A        String shortName = crisiscode+%22_%22+ attributecode;%0A        clientAppService.updateClientAppByShortName(shortName, StatusCodeType.CLIENT_APP_INACTIVE);%0A%0A        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();%0A%0A    %7D%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/delete/crisis/%7BcrisisID%7D%22)%0A    public Response disableClientApps(@PathParam(%22crisisID%22) Long crisisID)%7B%0A%0A        try%7B%0A            clientAppService.deactivateClientAppByCrisis(crisisID);%0A        %7D%0A        catch(Exception e)%7B%0A            System.out.println(%22disableClientApps : %22 + e);%0A        %7D%0A%0A%0A        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();%0A    %7D%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/delete/attribute/%7BcrisisID%7D/%7BattributeID%7D%22)%0A    public Response disableClientApp(@PathParam(%22crisisID%22) Long crisisID, @PathParam(%22attributeID%22) Long attributeID)%7B%0A%0A        try%7B%0A            clientAppService.deactivateClientAppByAttribute(crisisID, attributeID);%0A        %7D%0A        catch(Exception e)%7B%0A            System.out.println(%22disableClientApps : %22 + e);%0A        %7D%0A%0A%0A        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(StatusCodeType.POST_COMPLETED).build();%0A    %7D%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/allactive%22)%0A    public List%3CClientAppModel%3E getAllActive()%7B%0A        return clientAppService.getAllActiveClientApps();%0A    %7D%0A%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/get/crisis/%7BcrisisID%7D%22)%0A    public List%3CClientApp%3E getClientAppsByCrisisID(@PathParam(%22crisisID%22) Long crisisID)%7B%0A        return clientAppService.getAllClientAppByCrisisID(crisisID);%0A    %7D%0A%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/activate/mobile/crisis/%7BcrisisID%7D%22)%0A    public Response enableMobileClientAppByCrisisID(@PathParam(%22crisisID%22) Long crisisID)%7B%0A        Integer status = StatusCodeType.AIDR_MICROMAPPER_BOTH;%0A        String returnValue = clientAppService.enableForClientAppStatusByCrisisID(crisisID, status);%0A        return Response.status(CodeLookUp.APP_SERVICE_COMPLETED).entity(returnValue).build
+%0A%0A    @GET%0A    @Produces(MediaType.APPLICATION_JSON)%0A    @Path(%22/allactive%22)%0A    public List%3CClientAppModel%3E getAllActive()%7B%0A        return clientAppService.getAllActiveClientApps
 ();%0A

clean clientAPP api