Skip to content

Commit 05be79b

Browse files
Merge pull request #6864 from microsoft/bugfixes-combobox
fix miscellaneous bugs found in feature test about cosmos db.
2 parents 1b8e623 + 7f2ddd1 commit 05be79b

File tree

13 files changed

+98
-45
lines changed

13 files changed

+98
-45
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/FunctionRunLineMarkerProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
public class FunctionRunLineMarkerProvider extends RunLineMarkerContributor {
2424
@Nullable
2525
@Override
26-
@ExceptionNotification
2726
public Info getInfo(@NotNull PsiElement e) {
2827
if (isIdentifier(e)) {
2928
final PsiElement parentElement = e.getParent();

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/resources/META-INF/azure-intellij-plugin-cosmos-dbtools.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<extensionFallback dbms="AZ_COSMOS_CASSANDRA" fallbackDbms="CASSANDRA"/>
1010
<driversConfig config="databaseDrivers/azure-cosmos-mongo-drivers.xml"/>
1111
<driversConfig config="databaseDrivers/azure-cosmos-cassandra-drivers.xml"/>
12+
<artifactsConfig config="databaseDrivers/azure-cosmos-cassandra-drivers-extension.xml"/>
1213
<urlParamEditorProvider implementation="com.microsoft.azure.toolkit.intellij.cosmos.dbtools.MongoCosmosDbAccountTypeFactory" order="first"/>
1314
<urlParamEditorProvider implementation="com.microsoft.azure.toolkit.intellij.cosmos.dbtools.CassandraCosmosDbAccountTypeFactory" order="first"/>
1415
</extensions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<artifacts>
3+
<artifact name="Azure Cosmos Extensions for Apache Cassandra">
4+
<version version="1.1.2">
5+
<item type="maven" url="com.azure:azure-cosmos-cassandra-driver-4-extensions:1.1.2"/>
6+
</version>
7+
<version version="1.1.1">
8+
<item type="maven" url="com.azure:azure-cosmos-cassandra-driver-4-extensions:1.1.1"/>
9+
</version>
10+
<version version="1.1.0">
11+
<item type="maven" url="com.azure:azure-cosmos-cassandra-driver-4-extensions:1.1.0"/>
12+
</version>
13+
<version version="1.0.1">
14+
<item type="maven" url="com.azure:azure-cosmos-cassandra-driver-4-extensions:1.0.1"/>
15+
</version>
16+
<version version="1.0.0">
17+
<item type="maven" url="com.azure:azure-cosmos-cassandra-driver-4-extensions:1.0.0"/>
18+
</version>
19+
</artifact>
20+
</artifacts>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/resources/databaseDrivers/azure-cosmos-cassandra-drivers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
dialect="CassandraQL" driver-class="com.dbschema.CassandraJdbcDriver">
77
<url-template name="default" template="jdbc:cassandra://&lt;\,,{host::localhost}?[:{port::10350}]&gt;[/{database:::keyspace}?[/{account:cosmos_account_cassandra}?][\?&lt;&amp;,user={user},password={password},{:identifier}={:identifier}&gt;]]"/>
88
<artifact name="Cassandra" use="true" rolling="true"/>
9+
<artifact name="Azure Cosmos Extensions for Apache Cassandra" use="true" rolling="true"/>
910
<option name="auto-sync" value="true"/>
1011
<property name="appName" value="DataGrip"/>
1112
</driver>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/resources/databaseDrivers/azure-cosmos-mongo-drivers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!--driver will use same icon as that of DBMS if not configured according to com/intellij/database/dataSource/DatabaseDriverImpl.class:644-->
44
<driver id="az_cosmos_mongo" name="Azure Cosmos DB (MongoDB)"
55
dbms="AZ_COSMOS_MONGO" forced-dbms="AZ_COSMOS_MONGO"
6-
dialect="MongoJS" driver-class="com.dbschema.MongoJdbcDriver">
6+
dialect="MongoDB" driver-class="com.dbschema.MongoJdbcDriver">
77
<url-template name="default" template="[jdbc:]mongodb[+srv]://[{user:identifier}[:{password:param}]@]&lt;\,,{host::localhost}?[:{port::27017}]&gt;[/{database}?[/{account:cosmos_account_mongo}?][\?&lt;&amp;,{:identifier}={:param}&gt;]]"/>
88
<artifact name="MongoDB" use="true" rolling="true"/>
99
<option name="auto-sync" value="true"/>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureComboBox.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,11 @@ private void refreshValue() {
171171
final List<T> items = this.getItems();
172172
if (this.value instanceof AzureComboBox.ItemReference) {
173173
items.stream().filter(i -> ((ItemReference<?>) this.value).is(i)).findFirst().ifPresent(this::setValue);
174+
} else if (items.contains(this.value)) {
175+
super.setSelectedItem(this.value);
174176
} else if (this.value instanceof AbstractAzResource && ((AbstractAzResource<?, ?, ?>) this.value).isDraftForCreating()) {
175-
// todo: unify model for custom created resource
176177
super.addItem((T) this.value);
177178
super.setSelectedItem(this.value);
178-
} else if (items.contains(this.value)) {
179-
super.setSelectedItem(this.value);
180179
} else {
181180
super.setSelectedItem(null);
182181
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureFormInputComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ default JComponent getInputComponent() {
3232
@Override
3333
default boolean needValidation() {
3434
final JComponent comp = this.getInputComponent();
35-
return AzureFormInput.super.needValidation() && comp.isEnabled() && comp.isVisible();
35+
return AzureFormInput.super.needValidation() && comp.isVisible();
3636
}
3737

3838
@Override

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/intellij/ui/ServicePrincipalLoginDialog.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ServicePrincipalLoginDialog(@Nonnull Project project) {
9393
initJsonData();
9494

9595
// initialize cert file select
96-
FileChooserDescriptor pem = FileChooserDescriptorFactory.createSingleFileDescriptor("pem");
96+
final FileChooserDescriptor pem = FileChooserDescriptorFactory.createSingleFileDescriptor("pem");
9797
pem.withFileFilter(file -> StringUtils.equalsIgnoreCase(file.getExtension(), "pem"));
9898
certFileTextField.addActionListener(new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select Certificate File", null, certFileTextField, null,
9999
pem, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
@@ -131,20 +131,20 @@ public void documentChanged(@NotNull DocumentEvent event) {
131131

132132
@Override
133133
protected @NotNull List<ValidationInfo> doValidateAll() {
134-
List<ValidationInfo> res = new ArrayList<>();
135-
AuthConfiguration data = getValue();
134+
final List<ValidationInfo> res = new ArrayList<>();
135+
final AuthConfiguration data = getValue();
136136
if (StringUtils.isBlank(data.getTenant())) {
137-
res.add(new ValidationInfo("tenant is required.", tenantIdTextField));
137+
res.add(new ValidationInfo("Tenant is required.", tenantIdTextField));
138138
}
139-
if (!isGuid(data.getTenant())) {
140-
res.add(new ValidationInfo("tenant should be a valid guid.", tenantIdTextField));
139+
if (notGuid(data.getTenant())) {
140+
res.add(new ValidationInfo("Tenant should be a valid guid.", tenantIdTextField));
141141
}
142142

143143
if (StringUtils.isBlank(data.getClient())) {
144-
res.add(new ValidationInfo("clientId(appId) is required.", clientIdTextField));
144+
res.add(new ValidationInfo("ClientId(appId) is required.", clientIdTextField));
145145
}
146-
if (!isGuid(data.getClient())) {
147-
res.add(new ValidationInfo("clientId(appId) should be a valid guid.", clientIdTextField));
146+
if (notGuid(data.getClient())) {
147+
res.add(new ValidationInfo("ClientId(appId) should be a valid guid.", clientIdTextField));
148148
}
149149

150150
if (this.passwordRadioButton.isSelected()) {
@@ -182,17 +182,17 @@ private void createUIComponents() {
182182
}
183183

184184
private EditorTextField buildCodeViewer() {
185-
EditorTextFieldProvider service = ApplicationManager.getApplication().getService(EditorTextFieldProvider.class);
186-
Set<EditorCustomization> editorFeatures = new HashSet<>();
185+
final EditorTextFieldProvider service = ApplicationManager.getApplication().getService(EditorTextFieldProvider.class);
186+
final Set<EditorCustomization> editorFeatures = new HashSet<>();
187187
editorFeatures.add(SoftWrapsEditorCustomization.ENABLED);
188188
editorFeatures.add(SpellCheckingEditorCustomization.getInstance(false));
189-
EditorTextField editorTextField = service.getEditorField(Objects.requireNonNull(Language.findLanguageByID("JSON")), project, editorFeatures);
189+
final EditorTextField editorTextField = service.getEditorField(Objects.requireNonNull(Language.findLanguageByID("JSON")), project, editorFeatures);
190190
editorTextField.setMinimumSize(new Dimension(200, 100));
191191
return editorTextField;
192192
}
193193

194194
public AuthConfiguration getValue() {
195-
AuthConfiguration data = new AuthConfiguration(AuthType.SERVICE_PRINCIPAL);
195+
final AuthConfiguration data = new AuthConfiguration(AuthType.SERVICE_PRINCIPAL);
196196

197197
data.setClient(clientIdTextField.getText());
198198
data.setTenant(tenantIdTextField.getText());
@@ -220,7 +220,7 @@ public List<AzureValidationInfo> validateData() {
220220
}
221221

222222
private void initJsonData() {
223-
String textFromClip = findTextInClipboard(str ->
223+
final String textFromClip = findTextInClipboard(str ->
224224
StringUtils.contains(str, "appId") && StringUtils.contains(str, "tenant") &&
225225
(StringUtils.contains(str, "password") || StringUtils.contains(str, "fileWithCertAndPrivateKey"))
226226
);
@@ -235,14 +235,14 @@ public static String findTextInClipboard(Predicate<String> func) {
235235
if (func == null) {
236236
return null;
237237
}
238-
for (Transferable currentItem : CopyPasteManager.getInstance().getAllContents()) {
238+
for (final Transferable currentItem : CopyPasteManager.getInstance().getAllContents()) {
239239
if (currentItem.isDataFlavorSupported(DataFlavor.stringFlavor)) {
240240
try {
241-
String itemStr = currentItem.getTransferData(DataFlavor.stringFlavor).toString();
241+
final String itemStr = currentItem.getTransferData(DataFlavor.stringFlavor).toString();
242242
if (func.test(itemStr)) {
243243
return itemStr;
244244
}
245-
} catch (Exception e) {
245+
} catch (final Exception e) {
246246
e.printStackTrace();
247247
}
248248
}
@@ -258,18 +258,18 @@ private void uiTextComponents2Json() {
258258
return;
259259
}
260260
try {
261-
Map<String, String> map = new LinkedHashMap<>();
262-
AuthConfiguration data = getValue();
261+
final Map<String, String> map = new LinkedHashMap<>();
262+
final AuthConfiguration data = getValue();
263263

264264
if (this.certificateRadioButton.isSelected()) {
265265
map.put("fileWithCertAndPrivateKey", data.getCertificate());
266266
} else {
267-
String password = StringUtils.isNotBlank(data.getKey()) ? "<hidden>" : "<empty>";
267+
final String password = StringUtils.isNotBlank(data.getKey()) ? "<hidden>" : "<empty>";
268268
map.put("password", password);
269269
}
270270
map.put("appId", data.getClient());
271271
map.put("tenant", data.getTenant());
272-
String text = JsonUtils.toJson(map);
272+
final String text = JsonUtils.toJson(map);
273273
if (!StringUtils.equals(jsonDataEditor.getText(), text)) {
274274
this.jsonDataEditor.setText(text);
275275
this.jsonDataEditor.setCaretPosition(0);
@@ -314,7 +314,7 @@ private void json2UIComponents(String json) {
314314
});
315315
}
316316

317-
} catch (JsonSyntaxException ex) {
317+
} catch (final JsonSyntaxException ex) {
318318
// ignore all json errors
319319
}
320320
}
@@ -323,11 +323,11 @@ private static boolean isPlaceHolder(String password) {
323323
return Arrays.asList("<hidden>", "<empty>").contains(password);
324324
}
325325

326-
private static boolean isGuid(String str) {
326+
private static boolean notGuid(String str) {
327327
if (StringUtils.isBlank(str)) {
328-
return false;
328+
return true;
329329
}
330-
return GUID_PATTERN.matcher(str).matches();
330+
return !GUID_PATTERN.matcher(str).matches();
331331
}
332332

333333
// CHECKSTYLE IGNORE check FOR NEXT 1 LINES

Utils/azure-toolkit-ide-libs/azure-toolkit-ide-appservice-lib/src/main/java/com/microsoft/azure/toolkit/ide/appservice/model/AppServiceConfig.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.microsoft.azure.toolkit.ide.appservice.model;
77

88
import com.azure.core.management.AzureEnvironment;
9+
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
910
import com.microsoft.azure.toolkit.lib.Azure;
1011
import com.microsoft.azure.toolkit.lib.appservice.config.AppServicePlanConfig;
1112
import com.microsoft.azure.toolkit.lib.appservice.model.PricingTier;
@@ -16,12 +17,13 @@
1617
import com.microsoft.azure.toolkit.lib.resource.ResourceGroupConfig;
1718
import lombok.AllArgsConstructor;
1819
import lombok.Builder;
19-
import lombok.EqualsAndHashCode;
2020
import lombok.Getter;
2121
import lombok.NoArgsConstructor;
2222
import lombok.Setter;
2323
import lombok.experimental.SuperBuilder;
2424
import org.apache.commons.lang3.StringUtils;
25+
import org.apache.commons.lang3.builder.EqualsBuilder;
26+
import org.apache.commons.lang3.builder.HashCodeBuilder;
2527

2628
import java.nio.file.Path;
2729
import java.text.SimpleDateFormat;
@@ -34,7 +36,6 @@
3436
@Setter
3537
@NoArgsConstructor
3638
@AllArgsConstructor
37-
@EqualsAndHashCode
3839
@SuperBuilder(toBuilder = true)
3940
public abstract class AppServiceConfig {
4041
protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyMMddHHmmss");
@@ -91,8 +92,36 @@ public static boolean isSameApp(AppServiceConfig first, AppServiceConfig second)
9192
return first == second;
9293
}
9394
return StringUtils.equalsIgnoreCase(first.resourceId, second.resourceId) ||
94-
(StringUtils.equalsIgnoreCase(first.name, second.name) &&
95-
StringUtils.equalsIgnoreCase(first.getResourceGroupName(), second.getResourceGroupName()) &&
96-
StringUtils.equalsIgnoreCase(first.getSubscriptionId(), second.getSubscriptionId()));
95+
(StringUtils.equalsIgnoreCase(first.name, second.name) &&
96+
StringUtils.equalsIgnoreCase(first.getResourceGroupName(), second.getResourceGroupName()) &&
97+
StringUtils.equalsIgnoreCase(first.getSubscriptionId(), second.getSubscriptionId()));
98+
}
99+
100+
@Override
101+
public boolean equals(Object o) {
102+
if (this == o) return true;
103+
if (o == null || getClass() != o.getClass()) return false;
104+
final AppServiceConfig that = (AppServiceConfig) o;
105+
106+
final ResourceId thisId = Optional.ofNullable(this.resourceId).map(ResourceId::fromString).orElse(null);
107+
final String thisName = Optional.ofNullable(thisId).map(ResourceId::name).orElse(this.getName());
108+
final String thisRg = Optional.ofNullable(thisId).map(ResourceId::resourceGroupName).orElse(this.getResourceGroupName());
109+
final String thisSub = Optional.ofNullable(thisId).map(ResourceId::subscriptionId).orElse(this.getSubscriptionId());
110+
111+
final ResourceId thatId = Optional.ofNullable(that.resourceId).map(ResourceId::fromString).orElse(null);
112+
final String thatName = Optional.ofNullable(thatId).map(ResourceId::name).orElse(that.getName());
113+
final String thatRg = Optional.ofNullable(thatId).map(ResourceId::resourceGroupName).orElse(that.getResourceGroupName());
114+
final String thatSub = Optional.ofNullable(thatId).map(ResourceId::subscriptionId).orElse(that.getSubscriptionId());
115+
116+
return new EqualsBuilder().append(thisSub, thatSub).append(thisName, thatName).append(thisRg, thatRg).isEquals();
117+
}
118+
119+
@Override
120+
public int hashCode() {
121+
final ResourceId thisId = Optional.ofNullable(this.resourceId).map(ResourceId::fromString).orElse(null);
122+
final String thisName = Optional.ofNullable(thisId).map(ResourceId::name).orElse(this.getName());
123+
final String thisRg = Optional.ofNullable(thisId).map(ResourceId::resourceGroupName).orElse(this.getResourceGroupName());
124+
final String thisSub = Optional.ofNullable(thisId).map(ResourceId::subscriptionId).orElse(this.getSubscriptionId());
125+
return new HashCodeBuilder(17, 37).append(thisSub).append(thisRg).append(thisName).toHashCode();
97126
}
98127
}

Utils/azure-toolkit-ide-libs/azure-toolkit-ide-appservice-lib/src/main/java/com/microsoft/azure/toolkit/ide/appservice/webapp/model/WebAppConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
@Setter
3232
@NoArgsConstructor
3333
@AllArgsConstructor
34-
@EqualsAndHashCode(callSuper = true)
3534
@SuperBuilder(toBuilder = true)
3635
public class WebAppConfig extends AppServiceConfig {
3736
public static final Runtime DEFAULT_RUNTIME = Runtime.LINUX_JAVA8_TOMCAT9;

0 commit comments

Comments
 (0)