package org.pentaho.platform.dataaccess.datasource.wizard.service.impl;

import org.pentaho.platform.engine.core.system.PentahoSessionHolder;
import org.pentaho.platform.web.http.api.resources.JaxbList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;

/**
 * @author Rowell Belen
 */
@Path("/data-access/api/permissions")
public class DataAccessPermissionResource
{
  private SimpleDataAccessPermissionHandler dataAccessPermHandler;
  private SimpleDataAccessViewPermissionHandler dataAccessViewPermHandler;

  public DataAccessPermissionResource(){
    dataAccessPermHandler = new SimpleDataAccessPermissionHandler();
    dataAccessViewPermHandler = new SimpleDataAccessViewPermissionHandler();
  }

  @GET
  @Path("/hasDataAccess")
  @Produces( { APPLICATION_XML, APPLICATION_JSON })
  public Boolean hasDataAccessPermission() {
    return dataAccessPermHandler != null
       && dataAccessPermHandler.hasDataAccessPermission(PentahoSessionHolder.getSession());
  }

  @GET
  @Path("/hasDataAccessView")
  @Produces( { APPLICATION_XML, APPLICATION_JSON })
  public Boolean hasDataAccessViewPermission() {
    return dataAccessViewPermHandler != null
       && dataAccessViewPermHandler.hasDataAccessViewPermission(PentahoSessionHolder.getSession());
  }

  @GET
  @Path("/permittedRoles")
  @Produces( { APPLICATION_XML, APPLICATION_JSON })
  public JaxbList<String> getPermittedRoleList() {
    if (dataAccessViewPermHandler == null) {
      return new JaxbList<String>();
    }
    return new JaxbList<String>(dataAccessViewPermHandler.getPermittedRoleList(PentahoSessionHolder.getSession()));
  }

  @GET
  @Path("/permittedUsers")
  @Produces( { APPLICATION_XML, APPLICATION_JSON })
  public JaxbList<String> getPermittedUserList() {
    if (dataAccessViewPermHandler == null) {
      return new JaxbList<String>();
    }
    return new JaxbList<String>(dataAccessViewPermHandler.getPermittedUserList(PentahoSessionHolder.getSession()));
  }
}

@@ -338,66 +338,8 @@
 SON;
-%0Aimport static javax.ws.rs.core.MediaType.APPLICATION_XML;
 %0A%0A/*
@@ -832,34 +832,16 @@
 duces( %7B
- APPLICATION_XML, 
 APPLICAT
@@ -1086,34 +1086,16 @@
 duces( %7B
- APPLICATION_XML, 
 APPLICAT
@@ -1353,34 +1353,16 @@
 duces( %7B
- APPLICATION_XML, 
 APPLICAT
@@ -1663,24 +1663,24 @@
 ttedUsers%22)%0A
+
   @Produces(
@@ -1685,26 +1685,8 @@
 s( %7B
- APPLICATION_XML, 
 APPL

Change default output type to JSON