-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14d5cbc
commit 653fddf
Showing
9 changed files
with
493 additions
and
10 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/CreateContainerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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.actions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import org.netbeans.api.project.Project; | ||
import org.netbeans.api.project.ProjectInformation; | ||
import org.netbeans.api.project.ProjectUtils; | ||
import org.netbeans.modules.cloud.oracle.assets.OpenProjectsFinder; | ||
import org.netbeans.modules.cloud.oracle.assets.Steps; | ||
import org.netbeans.modules.cloud.oracle.compartment.CompartmentItem; | ||
import org.netbeans.modules.cloud.oracle.items.OCIItem; | ||
import org.netbeans.modules.cloud.oracle.requests.ContainerRepositoryRequest; | ||
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails; | ||
import org.netbeans.modules.cloud.oracle.steps.CompartmentStep; | ||
import org.openide.DialogDisplayer; | ||
import org.openide.NotifyDescriptor; | ||
import org.openide.util.NbBundle; | ||
|
||
/** | ||
* | ||
* @author Dusan Petrovic | ||
*/ | ||
|
||
@NbBundle.Messages({ | ||
"CreateContainerRepository=Create new container repository", | ||
"EnterName=Enter OCI resource name" | ||
}) | ||
public class CreateContainerRepository implements OCIItemCreator { | ||
|
||
private static final String REPOSITORY_NAME_FIELD = "name"; | ||
|
||
@Override | ||
public CompletableFuture<? extends OCIItem> create(Steps.Values values, Map<String, Object> params) { | ||
String compartmentId = ((CompartmentItem)values.getValueForStep(CompartmentStep.class)).getKey().getValue(); | ||
String displayName = (String) params.get(REPOSITORY_NAME_FIELD); | ||
OCIItemCreationDetails creationDetails = new ContainerRepositoryRequest(compartmentId, displayName); | ||
return new org.netbeans.modules.cloud.oracle.actions.CreateContainerRepositoryCommand().create(creationDetails); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Map<String, Object>> steps() { | ||
Map<String, Object> result = new HashMap<>(); | ||
CompletableFuture future = new CompletableFuture(); | ||
|
||
String suggestedName = getSuggestedName(future); | ||
NotifyDescriptor.InputLine ci = new NotifyDescriptor.InputLine(Bundle.EnterName(), Bundle.EnterName()); | ||
|
||
if (suggestedName != null) { | ||
ci.setInputText(suggestedName); | ||
} | ||
|
||
DialogDisplayer.getDefault().notifyFuture(ci).handle((r, exception) -> { | ||
result.put(REPOSITORY_NAME_FIELD, r.getInputText()); | ||
|
||
if (exception != null) { | ||
future.completeExceptionally(exception); | ||
} else { | ||
future.complete(result); | ||
} | ||
return null; | ||
}); | ||
return future; | ||
} | ||
|
||
private String getSuggestedName(CompletableFuture future) { | ||
CompletableFuture<Project[]> projects = OpenProjectsFinder.getDefault().findTopLevelProjects(); | ||
ProjectInformation pi = null; | ||
try { | ||
Project[] p = projects.get(); | ||
if (p != null && p.length > 0) { | ||
pi = ProjectUtils.getInformation(p[0]); | ||
} | ||
} catch (InterruptedException | ExecutionException ex) { | ||
future.completeExceptionally(ex); | ||
} | ||
return pi == null ? null : pi.getDisplayName(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...racle/src/org/netbeans/modules/cloud/oracle/actions/CreateContainerRepositoryCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.actions; | ||
|
||
import com.oracle.bmc.artifacts.ArtifactsClient; | ||
import com.oracle.bmc.artifacts.model.ContainerRepository; | ||
import com.oracle.bmc.artifacts.requests.CreateContainerRepositoryRequest; | ||
import com.oracle.bmc.artifacts.responses.CreateContainerRepositoryResponse; | ||
import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem; | ||
import org.netbeans.modules.cloud.oracle.items.OCID; | ||
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails; | ||
|
||
/** | ||
* | ||
* @author Dusan Petrovic | ||
*/ | ||
public class CreateContainerRepositoryCommand extends CreateResourceCommand<ContainerRepositoryItem> { | ||
|
||
@Override | ||
ContainerRepositoryItem callCreate(OCIItemCreationDetails itemCreator) { | ||
ArtifactsClient client = this.getProfile().newClient(ArtifactsClient.class); | ||
|
||
CreateContainerRepositoryRequest request = (CreateContainerRepositoryRequest) itemCreator.getRequest(); | ||
CreateContainerRepositoryResponse response = client.createContainerRepository(request); | ||
ContainerRepository res = response.getContainerRepository(); | ||
|
||
return new ContainerRepositoryItem( | ||
OCID.of(res.getId(), "ContainerRepository"), //NOI18N | ||
res.getCompartmentId(), | ||
res.getDisplayName(), | ||
this.getProfile().getRegion().getRegionCode(), | ||
res.getNamespace(), | ||
res.getIsPublic(), | ||
res.getImageCount() | ||
); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...ise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/CreateResourceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.actions; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import org.netbeans.modules.cloud.oracle.OCIManager; | ||
import org.netbeans.modules.cloud.oracle.OCISessionInitiator; | ||
import org.netbeans.modules.cloud.oracle.items.OCIItem; | ||
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails; | ||
|
||
/** | ||
* | ||
* @author Dusan Petrovic | ||
*/ | ||
public abstract class CreateResourceCommand<T extends OCIItem> { | ||
|
||
private final OCISessionInitiator profile; | ||
|
||
public CreateResourceCommand() { | ||
this.profile = OCIManager.getDefault().getActiveProfile(); | ||
} | ||
|
||
public OCISessionInitiator getProfile() { | ||
return profile; | ||
} | ||
|
||
abstract T callCreate(OCIItemCreationDetails itemCreator); | ||
|
||
public CompletableFuture<T> create(OCIItemCreationDetails creationDetails) { | ||
CompletableFuture future = new CompletableFuture(); | ||
|
||
try { | ||
T item = callCreate(creationDetails); | ||
future.complete(item); | ||
} catch (Exception ex) { | ||
future.completeExceptionally(ex); | ||
} | ||
return future; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/OCIItemCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.actions; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.netbeans.modules.cloud.oracle.assets.Steps; | ||
import org.netbeans.modules.cloud.oracle.items.OCIItem; | ||
|
||
/** | ||
* | ||
* @author Dusan Petrovic | ||
*/ | ||
public interface OCIItemCreator { | ||
|
||
CompletableFuture<Map<String, Object>> steps(); | ||
|
||
CompletableFuture<? extends OCIItem> create(Steps.Values values, Map<String, Object> params); | ||
|
||
public static OCIItemCreator getCreator(String itemType) { | ||
switch (itemType) { | ||
case "ContainerRepository": | ||
return new CreateContainerRepository(); | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.