Skip to content

Commit

Permalink
Merge pull request #191 from couchbaselabs/1.0.9_bug_fixes
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
deniswsrosa authored Apr 15, 2024
2 parents 5d386f8 + c0c46e5 commit 87860ce
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 28 deletions.
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.couchbase"
version = "1.0.9"
version = "1.0.10"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand All @@ -24,7 +24,7 @@ dependencies {
implementation(files("lib/couchbase-lite-java-ee-3.1.3-7-release.jar"))
annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("org.projectlombok:lombok:1.18.30")
implementation("com.couchbase.client:java-client:3.4.11")
implementation("com.couchbase.client:java-client:3.6.1")
implementation("org.slf4j:slf4j-simple:2.0.7")
implementation("org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r")
implementation("com.google.code.gson:gson:2.10.1")
Expand Down Expand Up @@ -56,6 +56,10 @@ dependencies {
implementation("com.vladsch.flexmark:flexmark:0.64.8")
implementation("com.vladsch.flexmark:flexmark-ext-tables:0.64.8")
implementation("com.vladsch.flexmark:flexmark-html2md-converter:0.64.8")

testImplementation("org.testcontainers:couchbase:1.19.7")
testImplementation("org.testcontainers:junit-jupiter:1.19.7")

}

// Configure Gradle IntelliJ Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ public void updateSchema() {
Log.debug("updated cluster schema");
}

@VisibleForTesting
public void setCluster(Cluster cluster) {
this.cluster = cluster;
}

@Override
public SavedCluster getSavedCluster() {
return savedCluster;
Expand Down
43 changes: 42 additions & 1 deletion src/main/java/com/couchbase/intellij/database/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,14 @@ public static void listDocuments(DefaultMutableTreeNode parentNode, Tree tree, i
parentNode.remove(parentNode.getChildCount() - 1);
}


//selects the attribute that needs to be used according to the index
String idxField = getIndexedField(colNode);
if (idxField == null) {
throw new IndexFailureException(null);
}
String filter = colNode.getQueryFilter();
String query = "Select meta(couchbaseAlias).id as cbFileNameId, meta(couchbaseAlias).type as cbMetaType from `" + colNode.getText() + "` as couchbaseAlias WHERE meta(couchbaseAlias).id IS NOT MISSING " + ((filter == null || filter.isEmpty()) ? "" : (" and " + filter)) + (SQLPPQueryUtils.hasOrderBy(filter) ? "" : " order by meta(couchbaseAlias).id ") + (newOffset == 0 ? "" : " OFFSET " + newOffset) + " limit 10";
String query = "Select meta(couchbaseAlias).id as cbFileNameId, meta(couchbaseAlias).type as cbMetaType from `" + colNode.getText() + "` as couchbaseAlias WHERE " + idxField + " IS NOT MISSING " + ((filter == null || filter.isEmpty()) ? "" : (" and " + filter)) + (SQLPPQueryUtils.hasOrderBy(filter) ? "" : " order by meta(couchbaseAlias).id ") + (newOffset == 0 ? "" : " OFFSET " + newOffset) + " limit 10";

final List<JsonObject> results = ActiveCluster.getInstance().get().bucket(colNode.getBucket()).scope(colNode.getScope()).query(query).rowsAsObject();
InferHelper.invalidateInferCacheIfOlder(colNode.getBucket(), colNode.getScope(), colNode.getText(), TimeUnit.MINUTES.toMillis(5));
Expand Down Expand Up @@ -277,6 +283,41 @@ public static void listDocuments(DefaultMutableTreeNode parentNode, Tree tree, i
}
}

public static String getIndexedField(CollectionNodeDescriptor colNode) {
List<QueryIndex> idxs = ActiveCluster.getInstance().get().bucket(colNode.getBucket()).scope(colNode.getScope()).collection(colNode.getText()).queryIndexes().getAllIndexes();
String filter = null;
for (QueryIndex idx : idxs) {
if (idx.primary()) {
return "meta(couchbaseAlias).id";
} else {
AbstractMap.SimpleEntry<String, Boolean> result = getValidIndexKey(idx.indexKey());
if (result != null) {
if (!idx.condition().isPresent() && result.getValue()) {
return result.getKey();
} else {
filter = result.getKey();
}
}
}
}
return filter;
}

private static AbstractMap.SimpleEntry<String, Boolean> getValidIndexKey(JsonArray array) {
for (int i = 0; i < array.size(); i++) {
String key = array.getString(i);
if (!key.contains("(")) {
if (key.endsWith(" DESC") || key.endsWith(" ASC")) {
key = key.replace(" ASC", "").replace(" DESC", "").trim();
}
key = key.replaceAll("`", "");

return new AbstractMap.SimpleEntry<>(key, i == 0);
}
}
return null;
}

private static void loadKVDocuments(DefaultMutableTreeNode parentNode, Tree tree, int newOffset, CollectionNodeDescriptor colNode) throws Exception {
List<String> docIds = CouchbaseRestAPI.listKVDocuments(colNode.getBucket(), colNode.getScope(), colNode.getText(), newOffset, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,38 @@ public Map<String, ToolSpec> getDownloadList(String os) {

if (MACOS_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-apple-darwin.zip", TOOL_SHELL, MACOS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-macos_x86_64.zip", TOOL_IMPORT_EXPORT, MACOS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-macos_x86_64.zip", TOOL_IMPORT_EXPORT, MACOS_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-macos_64.zip", ALL_TOOLS, MACOS_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_darwin_amd64.zip", CB_MIGRATE, MACOS_64));

} else if (MACOS_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-aarch64-apple-darwin.zip", TOOL_SHELL, MACOS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-macos_arm64.zip", TOOL_IMPORT_EXPORT, MACOS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-macos_arm64.zip", TOOL_IMPORT_EXPORT, MACOS_ARM));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-macos_arm.zip", ALL_TOOLS, MACOS_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_darwin_arm64.zip", CB_MIGRATE, MACOS_ARM));


} else if (WINDOWS_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-windows_64.zip", ALL_TOOLS, WINDOWS_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_windows_amd64.zip", CB_MIGRATE, WINDOWS_64));

} else if (WINDOWS_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_ARM));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-windows_64.zip", ALL_TOOLS, WINDOWS_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_windows_amd64.zip", CB_MIGRATE, WINDOWS_ARM));

} else if (LINUX_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-linux_x86_64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-linux_x86_64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-linux_64.zip", ALL_TOOLS, LINUX_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_linux_amd64.zip", CB_MIGRATE, LINUX_64));

} else if (LINUX_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-aarch64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-linux_aarch64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-linux_aarch64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.0.1-beta_linux_arm64.zip", CB_MIGRATE, LINUX_ARM));

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class DependenciesUtil {

public static final String TOOLS_VERSION = "7.2";

public static final String CBMIGRATE_VERSION = "3";
public static final String CBMIGRATE_VERSION = "4";
public static final String SHELL_VERSION = "1";
public static final String CBIMPORT_EXPORT_VERSION = "7.2";
public static final String CBIMPORT_EXPORT_VERSION = "7.6";
public static final String EXPLAIN_VERSION = "1";

public static final String JS_DEPENDENCIES_KEY = "js_dependencies";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private JPanel createTargetPanel() {
JPanel targetPanel = new JPanel(new GridBagLayout());

JLabel infoLabel = new JLabel();
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", DocumentFilterDialog.class));
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", MigrationDialog.class));
infoLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.couchbase.intellij.tools.CBImportCommandBuilder;
import com.couchbase.intellij.tree.NewEntityCreationDialog;
import com.couchbase.intellij.tree.NewEntityCreationDialog.EntityType;
import com.couchbase.intellij.tree.docfilter.DocumentFilterDialog;
import com.couchbase.intellij.workbench.Log;
import com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -226,7 +225,7 @@ protected JPanel createDatasetPanel() {
JLabel infoLabel = new JLabel();

String fontKeywordColor = ColorHelper.getKeywordColor();
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", DocumentFilterDialog.class));
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", ImportDialog.class));
infoLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,20 @@ public void actionPerformed(@NotNull AnActionEvent e) {
AnAction menuItem = new AnAction(filter) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
DocumentFilterDialog dialog = new DocumentFilterDialog(tree, clickedNode, col.getBucket(), col.getScope(), col.getText());
dialog.show();

CollectionNodeDescriptor desc = new CollectionNodeDescriptor(
col.getText(), null, col.getBucket(), col.getScope(), null);
String field = DataLoader.getIndexedField(desc);

if (field != null) {
DocumentFilterDialog dialog = new DocumentFilterDialog(tree, clickedNode, col.getBucket(), col.getScope(), col.getText());
dialog.show();
} else {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(
"Filters can only be applied to collections that have at least one index.",
"Document Filters"
));
}
}
};
actionGroup.add(menuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.couchbase.client.java.json.JsonArray;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.intellij.tree.cblite.ActiveCBLDatabase;
import com.couchbase.intellij.tree.docfilter.DocumentFilterDialog;
import com.couchbase.intellij.workbench.Log;
import com.couchbase.lite.Collection;
import com.couchbase.lite.*;
Expand Down Expand Up @@ -98,7 +97,7 @@ protected JPanel createSourceTargetPanel() {

String fontKeywordColor = ColorHelper.getKeywordColor();
JLabel infoLabel = new JLabel();
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", DocumentFilterDialog.class));
infoLabel.setIcon(IconLoader.getIcon("/assets/icons/information_big.svg", CBLImportDialog.class));
infoLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import com.couchbase.intellij.VirtualFileKeys;
import com.couchbase.intellij.database.ActiveCluster;
import com.couchbase.intellij.persistence.storage.QueryHistoryStorage;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
Expand All @@ -26,7 +25,6 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
Expand Down Expand Up @@ -166,13 +164,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {
topPanel.add(leftPanel, BorderLayout.WEST);
topPanel.add(rightPanel, BorderLayout.EAST);

if (ActiveCluster.getInstance().getColor() != null) {
Border line = BorderFactory.createMatteBorder(0, 0, 1, 0, ActiveCluster.getInstance().getColor());
Border margin = BorderFactory.createEmptyBorder(0, 0, 1, 0);
Border compound = BorderFactory.createCompoundBorder(margin, line);
topPanel.setBorder(compound);
}

panel.add(topPanel, BorderLayout.NORTH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static Boolean executeQuery(BlockingQueue<Boolean> queue, QueryType type,
if (!SQLPPAnalyzer.isLimited(project, query)) {
Integer queryLimit = ActiveCluster.getInstance().getQueryLimit();
if (queryLimit != null) {
query = String.format("SELECT * FROM (%s) as d LIMIT %d", query, queryLimit);
query = String.format("SELECT d.* FROM (%s) as d LIMIT %d", query, queryLimit);
autoLimited = true;
}
}
Expand Down
Loading

0 comments on commit 87860ce

Please sign in to comment.