Skip to content

Commit

Permalink
Merge pull request apache#7678 from petrovic-d/refactor-create-oci-re…
Browse files Browse the repository at this point in the history
…souce

Suggest OCI resource creation when showing existing resources
  • Loading branch information
jhorvath authored Aug 19, 2024
2 parents 36171a7 + 15d4044 commit ce1faa0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.netbeans.modules.cloud.oracle.steps.ItemTypeStep;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.steps.DatabaseConnectionStep;
import org.netbeans.modules.cloud.oracle.steps.ItemCreationDecisionStep;
import org.netbeans.modules.cloud.oracle.steps.TenancyStep;
import org.netbeans.spi.lsp.CommandProvider;
import org.openide.util.lookup.Lookups;
Expand Down Expand Up @@ -78,14 +77,8 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
}
return new TenancyStep();
}).stepForClass(TenancyStep.class, (s) -> new CompartmentStep())
.stepForClass(CompartmentStep.class, (s) -> new ItemCreationDecisionStep())
.stepForClass(ItemCreationDecisionStep.class, (s) -> {
if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(s.getValue())) {
return null;
}
return new SuggestedStep(null);
})
.stepForClass(SuggestedStep.class, (s) -> new ProjectStep())
.stepForClass(CompartmentStep.class, (s) -> new SuggestedStep(null))
.stepForClass(SuggestedStep.class, (s) -> new ProjectStep())
.build();

Steps.getDefault()
Expand All @@ -101,15 +94,6 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
} else {
item = CompletableFuture.completedFuture(i);
}
} else if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(values.getValueForStep(ItemCreationDecisionStep.class))) { //NOI18N
OCIItemCreator creator = OCIItemCreator.getCreator(itemType);
if (creator != null) {
CompletableFuture<Map<String, Object>> vals = creator.steps();
item = vals.thenCompose(params -> {
return creator.create(values, params);
});
}

} else {
OCIItem i = values.getValueForStep(SuggestedStep.class);
if (i == null) {
Expand All @@ -120,6 +104,16 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
}
}

if (values.getValueForStep(SuggestedStep.class) instanceof CreateNewResourceItem) {
OCIItemCreator creator = OCIItemCreator.getCreator(itemType);
if (creator != null) {
CompletableFuture<Map<String, Object>> vals = creator.steps();
item = vals.thenCompose(params -> {
return creator.create(values, params);
});
}
}

item.thenAccept(i -> {
CloudAssets.getDefault().addItem(i);
String[] art = DEP_MAP.get(i.getKey().getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.netbeans.modules.cloud.oracle.steps.TenancyStep;
import org.netbeans.modules.cloud.oracle.database.DatabaseItem;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.steps.ItemCreationDecisionStep;
import org.openide.awt.ActionID;
import org.openide.awt.ActionRegistration;
import org.openide.util.Lookup;
Expand Down Expand Up @@ -85,18 +84,12 @@ public void actionPerformed(ActionEvent e) {
}
Steps.NextStepProvider nsProvider = Steps.NextStepProvider.builder()
.stepForClass(TenancyStep.class, (s) -> new CompartmentStep())
.stepForClass(CompartmentStep.class, (s) -> new ItemCreationDecisionStep(context.getPath()))
.stepForClass(ItemCreationDecisionStep.class, (s) -> {
if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(s.getValue())) {
return null;
}
return new SuggestedStep(context.getPath());
})
.stepForClass(CompartmentStep.class, (s) -> new SuggestedStep(context.getPath()))
.build();
Lookup lookup = Lookups.fixed(nsProvider);
Steps.getDefault().executeMultistep(new TenancyStep(), lookup)
.thenAccept(values -> {
if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(values.getValueForStep(ItemCreationDecisionStep.class))) { //NOI18N
if (values.getValueForStep(SuggestedStep.class) instanceof CreateNewResourceItem) {
OCIItemCreator creator = OCIItemCreator.getCreator(context.getPath());
if (creator != null) {
CompletableFuture<Map<String, Object>> vals = creator.steps();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.cloud.oracle.assets;

import org.netbeans.modules.cloud.oracle.items.OCIItem;

/**
*
* @author Dusan Petrovic
*/
public class CreateNewResourceItem extends OCIItem {

private static final String DISPLAY_NAME = "<Create new>";

public CreateNewResourceItem() {
super(null, null, DISPLAY_NAME);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.netbeans.modules.cloud.oracle.steps;

import com.oracle.bmc.model.BmcException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -28,6 +29,7 @@
import java.util.logging.Logger;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.modules.cloud.oracle.assets.AbstractStep;
import org.netbeans.modules.cloud.oracle.assets.CreateNewResourceItem;
import org.netbeans.modules.cloud.oracle.assets.Steps;
import org.netbeans.modules.cloud.oracle.assets.Steps.Values;
import org.netbeans.modules.cloud.oracle.bucket.BucketNode;
Expand Down Expand Up @@ -124,7 +126,7 @@ public boolean onlyOneChoice() {
* @return List of items found
*/
protected static List<? extends OCIItem> getItemsByPath(CompartmentItem parent, String path) {
Map<String, OCIItem> items = new HashMap<>();
List<OCIItem> items = new ArrayList<>();
try {
switch (path) {
case "Databases": //NOI18N
Expand All @@ -138,7 +140,9 @@ protected static List<? extends OCIItem> getItemsByPath(CompartmentItem parent,
case "ComputeInstance": //NOI18N
return ComputeInstanceNode.getComputeInstances().apply(parent);
case "ContainerRepository": //NOI18N
return ContainerRepositoryNode.getContainerRepositories().apply(parent);
items.add(new CreateNewResourceItem());
items.addAll(ContainerRepositoryNode.getContainerRepositories().apply(parent));
return items;
default:
return Collections.emptyList();
}
Expand Down
5 changes: 3 additions & 2 deletions java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@
},
{
"command": "nbls:Edit:org.openide.actions.DeleteAction",
"title": "Delete"
"title": "Delete",
"icon": "$(trash)"
},
{
"command": "nbls.project.run",
Expand Down Expand Up @@ -1128,7 +1129,7 @@
},
{
"command": "nbls:Edit:org.openide.actions.DeleteAction",
"when": "viewItem =~ /lifecycleState:ACTIVE*/ || (viewItem =~ /publicIp:.*/ && viewItem =~ /imageUrl:.*/)",
"when": "viewItem =~ /lifecycleState:ACTIVE*/ || viewItem =~ /ContainerTagItem/",
"group": "inline@10"
}
]
Expand Down

0 comments on commit ce1faa0

Please sign in to comment.