package io.lumify.web.routes.workspace;

import io.lumify.miniweb.HandlerChain;
import com.google.inject.Inject;
import io.lumify.core.config.Configuration;
import io.lumify.core.model.user.UserRepository;
import io.lumify.core.model.workspace.Workspace;
import io.lumify.core.model.workspace.WorkspaceRepository;
import io.lumify.core.user.User;
import io.lumify.core.util.LumifyLogger;
import io.lumify.core.util.LumifyLoggerFactory;
import io.lumify.web.BaseRequestHandler;
import org.json.JSONObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WorkspaceById extends BaseRequestHandler {
    private static final LumifyLogger LOGGER = LumifyLoggerFactory.getLogger(WorkspaceById.class);

    @Inject
    public WorkspaceById(
            final WorkspaceRepository workspaceRepo,
            final UserRepository userRepository,
            final WorkspaceRepository workspaceRepository,
            final Configuration configuration) {
        super(userRepository, workspaceRepository, configuration);
    }

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain) throws Exception {
        final String workspaceId = super.getAttributeString(request, "workspaceId");
        final User authUser = getUser(request);
        LOGGER.info("Attempting to retrieve workspace: %s", workspaceId);
        final Workspace workspace = getWorkspaceRepository().findById(workspaceId, authUser);
        if (workspace == null) {
            LOGGER.warn("Could not find workspace: %s", workspaceId);
            respondWithNotFound(response);
        } else {
            LOGGER.debug("Successfully found workspace");
            final JSONObject resultJSON = getWorkspaceRepository().toJson(workspace, authUser, true);
            respondWithJson(response, resultJSON);
        }

        chain.next(request, response);
    }
}

@@ -38,47 +38,8 @@
 e;%0A%0A
-import io.lumify.miniweb.HandlerChain;%0A
 impo
@@ -411,30 +411,28 @@
 ify.
+mini
 web.
-BaseRequest
 Handler
+Chain
 ;%0Aim
@@ -440,27 +440,40 @@
 ort 
-org.json.JSONObject
+io.lumify.web.BaseRequestHandler
 ;%0A%0Ai
@@ -1715,35 +1715,54 @@
     
-final JSONObject
+io.lumify.web.clientapi.model.Workspace
  result
-JSON
  = g
@@ -1787,20 +1787,25 @@
 ory().to
-Json
+ClientApi
 (workspa
@@ -1852,12 +1852,8 @@
 With
-Json
 (res
@@ -1869,12 +1869,8 @@
 sult
-JSON
 );%0A 

change WorkspaceById to jackson