<commit_before>package io.lumify.core.model.workspace;

import io.lumify.core.exception.LumifyAccessDeniedException;
import io.lumify.core.model.workspace.diff.DiffItem;
import io.lumify.core.security.LumifyVisibility;
import io.lumify.core.user.User;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.securegraph.util.ConvertingIterable;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

public abstract class WorkspaceRepository {
    public static String VISIBILITY_STRING = "workspace";
    public static LumifyVisibility VISIBILITY = new LumifyVisibility(VISIBILITY_STRING);
    public static String WORKSPACE_CONCEPT_NAME = "http://lumify.io/workspace";
    public static String WORKSPACE_TO_ENTITY_RELATIONSHIP_NAME = "http://lumify.io/workspace/toEntity";
    public static String WORKSPACE_TO_USER_RELATIONSHIP_NAME = "http://lumify.io/workspace/toUser";
    public static String WORKSPACE_ID_PREFIX = "WORKSPACE_";

    // change Workspace to workspace id?
    public abstract void delete(Workspace workspace, User user);

    public abstract Workspace findById(String workspaceId, User user);

    public Iterable<Workspace> findByIds(final Iterable<String> workspaceIds, final User user) {
        return new ConvertingIterable<String, Workspace>(workspaceIds) {
            @Override
            protected Workspace convert(String workspaceId) {
                if (workspaceId == null) {
                    return null;
                }
                try {
                    return findById(workspaceId, user);
                } catch (LumifyAccessDeniedException ex) {
                    return null;
                }
            }
        };
    }

    public abstract Workspace add(String title, User user);

    public abstract Iterable<Workspace> findAll(User user);

    // TODO change Workspace to workspace id?
    public abstract void setTitle(Workspace workspace, String title, User user);

    public abstract List<WorkspaceUser> findUsersWithAccess(String workspaceId, User user);

    // TODO change Workspace to workspace id?
    public abstract List<WorkspaceEntity> findEntities(Workspace workspace, User user);

    // TODO change Workspace to workspace id?
    public Workspace copy(Workspace workspace, User user) {
        return copyTo(workspace, user, user);
    }

    // TODO change Workspace to workspace id?
    public Workspace copyTo(Workspace workspace, User destinationUser, User user) {
        Workspace newWorkspace = add("Copy of " + workspace.getDisplayTitle(), destinationUser);
        List<WorkspaceEntity> entities = findEntities(workspace, user);
        for (WorkspaceEntity entity : entities) {
            updateEntityOnWorkspace(newWorkspace, entity.getEntityVertexId(), entity.isVisible(), entity.getGraphPositionX(), entity.getGraphPositionY(), destinationUser);
        }
        return newWorkspace;
    }

    // TODO change Workspace to workspace id?
    public abstract void softDeleteEntityFromWorkspace(Workspace workspace, Object vertexId, User user);

    // TODO change Workspace to workspace id?
    public abstract void updateEntityOnWorkspace(Workspace workspace, Object vertexId, Boolean visible, Integer graphPositionX, Integer graphPositionY, User user);

    // TODO change Workspace to workspace id?
    public abstract void deleteUserFromWorkspace(Workspace workspace, String userId, User user);

    // TODO change Workspace to workspace id?
    public abstract void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user);

    // TODO change Workspace to workspace id?
    public abstract List<DiffItem> getDiff(Workspace workspace, User user);

    public String getCreatorUserId(Workspace workspace, User user) {
        for (WorkspaceUser workspaceUser : findUsersWithAccess(workspace.getId(), user)) {
            if (workspaceUser.isCreator()) {
                return workspaceUser.getUserId();
            }
        }
        return null;
    }

    public abstract boolean hasWritePermissions(String workspaceId, User user);

    public abstract boolean hasReadPermissions(String workspaceId, User user);

    public JSONArray toJson(Iterable<Workspace> workspaces, User user, boolean includeVertices) {
        JSONArray resultJson = new JSONArray();
        for (Workspace workspace : workspaces) {
            resultJson.put(toJson(workspace, user, includeVertices));
        }
        return resultJson;
    }

    public JSONObject toJson(Workspace workspace, User user, boolean includeVertices) {
        checkNotNull(workspace, "workspace cannot be null");
        checkNotNull(user, "user cannot be null");

        try {
            JSONObject workspaceJson = new JSONObject();
            workspaceJson.put("workspaceId", workspace.getId());<commit_msg>removed todos to change from passing in workspace id instead of workspace<commit_after>package io.lumify.core.model.workspace;

import io.lumify.core.exception.LumifyAccessDeniedException;
import io.lumify.core.model.workspace.diff.DiffItem;
import io.lumify.core.security.LumifyVisibility;
import io.lumify.core.user.User;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.securegraph.util.ConvertingIterable;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

public abstract class WorkspaceRepository {
    public static String VISIBILITY_STRING = "workspace";
    public static LumifyVisibility VISIBILITY = new LumifyVisibility(VISIBILITY_STRING);
    public static String WORKSPACE_CONCEPT_NAME = "http://lumify.io/workspace";
    public static String WORKSPACE_TO_ENTITY_RELATIONSHIP_NAME = "http://lumify.io/workspace/toEntity";
    public static String WORKSPACE_TO_USER_RELATIONSHIP_NAME = "http://lumify.io/workspace/toUser";
    public static String WORKSPACE_ID_PREFIX = "WORKSPACE_";

    public abstract void delete(Workspace workspace, User user);

    public abstract Workspace findById(String workspaceId, User user);

    public Iterable<Workspace> findByIds(final Iterable<String> workspaceIds, final User user) {
        return new ConvertingIterable<String, Workspace>(workspaceIds) {
            @Override
            protected Workspace convert(String workspaceId) {
                if (workspaceId == null) {
                    return null;
                }
                try {
                    return findById(workspaceId, user);
                } catch (LumifyAccessDeniedException ex) {
                    return null;
                }
            }
        };
    }

    public abstract Workspace add(String title, User user);

    public abstract Iterable<Workspace> findAll(User user);

    public abstract void setTitle(Workspace workspace, String title, User user);

    public abstract List<WorkspaceUser> findUsersWithAccess(String workspaceId, User user);

    public abstract List<WorkspaceEntity> findEntities(Workspace workspace, User user);

    public Workspace copy(Workspace workspace, User user) {
        return copyTo(workspace, user, user);
    }

    public Workspace copyTo(Workspace workspace, User destinationUser, User user) {
        Workspace newWorkspace = add("Copy of " + workspace.getDisplayTitle(), destinationUser);
        List<WorkspaceEntity> entities = findEntities(workspace, user);
        for (WorkspaceEntity entity : entities) {
            updateEntityOnWorkspace(newWorkspace, entity.getEntityVertexId(), entity.isVisible(), entity.getGraphPositionX(), entity.getGraphPositionY(), destinationUser);
        }
        return newWorkspace;
    }

    public abstract void softDeleteEntityFromWorkspace(Workspace workspace, Object vertexId, User user);

    public abstract void updateEntityOnWorkspace(Workspace workspace, Object vertexId, Boolean visible, Integer graphPositionX, Integer graphPositionY, User user);

    public abstract void deleteUserFromWorkspace(Workspace workspace, String userId, User user);

    public abstract void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user);

    public abstract List<DiffItem> getDiff(Workspace workspace, User user);

    public String getCreatorUserId(Workspace workspace, User user) {
        for (WorkspaceUser workspaceUser : findUsersWithAccess(workspace.getId(), user)) {
            if (workspaceUser.isCreator()) {
                return workspaceUser.getUserId();
            }
        }
        return null;
    }

    public abstract boolean hasWritePermissions(String workspaceId, User user);

    public abstract boolean hasReadPermissions(String workspaceId, User user);

    public JSONArray toJson(Iterable<Workspace> workspaces, User user, boolean includeVertices) {
        JSONArray resultJson = new JSONArray();
        for (Workspace workspace : workspaces) {
            resultJson.put(toJson(workspace, user, includeVertices));
        }
        return resultJson;
    }

    public JSONObject toJson(Workspace workspace, User user, boolean includeVertices) {
        checkNotNull(workspace, "workspace cannot be null");
        checkNotNull(user, "user cannot be null");

        try {
            JSONObject workspaceJson = new JSONObject();
            workspaceJson.put("workspaceId", workspace.getId());
{'fraction_non_alphanumeric': 0.07812666311868015, 'fraction_numerical': 0.0, 'mean_word_length': 3.5064748201438847, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7395186', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2387, 'n_words': 685}