Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Basic add assignment workflow in place
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed May 18, 2015
1 parent 980a731 commit 2a19edb
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public void proceed() {

@Override
public void abort() {
new RuntimeException("").printStackTrace();
this.aborted = true;
this.pending = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1347,4 +1347,6 @@ public interface UIConstants extends Constants {
String bs_connect_interface_no_selection();

String subsys_iiop_openjdk_desc();

String wizard_back();
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=Erstellen der JDBC-Verbindung fehlgeschlagen.
verify_datasource_internal_error=Ein interner Fehler ist aufgetreten.
verify_datasource_no_running_servers=Es sind keine laufenden Server an diese Datenquelle gebunden.
verify_datasource_successful_header=Successfully created JDBC connection.
wizard_back=‹‹ Zur\u00FCck
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=Failed to create JDBC connection.
verify_datasource_internal_error=An internal error occured.
verify_datasource_no_running_servers=There are no running servers bound to this datasource.
verify_datasource_successful_header=Successfully created JDBC connection.
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=No se logr\u00F3 crear la conexi\u00F3n JDBC.
verify_datasource_internal_error=Ocurri\u00F3 un error interno.
verify_datasource_no_running_servers=No hay servidores en ejecuci\u00F3n enlazados a esta fuente de datos.
verify_datasource_successful_header=Se cre\u00F3 exitosamente la conexi\u00F3n JDBC.
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=N'a pas pu cr\u00E9er de connexion JDBC.
verify_datasource_internal_error=Erreur interne
verify_datasource_no_running_servers=Il n'y a pas de serveur en cours d'ex\u00E9cution li\u00E9 \u00E0 cette source de donn\u00E9es.
verify_datasource_successful_header=Connexion JDBC cr\u00E9\u00E9e avec succ\u00E8s.
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=JDBC \u63A5\u7D9A\u306E\u4F5C\u6210\u306B\u5931\
verify_datasource_internal_error=\u5185\u90E8\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002
verify_datasource_no_running_servers=\u3053\u306E\u30C7\u30FC\u30BF\u30BD\u30FC\u30B9\u306B\u30D0\u30A4\u30F3\u30C9\u3055\u308C\u305F\u7A3C\u50CD\u4E2D\u306E\u30B5\u30FC\u30D0\u30FC\u306F\u3042\u308A\u307E\u305B\u3093\u3002
verify_datasource_successful_header=JDBC \u63A5\u7D9A\u304C\u6B63\u5E38\u306B\u4F5C\u6210\u3055\u308C\u307E\u3057\u305F\u3002
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=Failed to create JDBC connection.
verify_datasource_internal_error=An internal error occured.
verify_datasource_no_running_servers=There are no running servers bound to this datasource.
verify_datasource_successful_header=Successfully created JDBC connection.
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=Falha ao criar a conex\u00E3o JDBC.
verify_datasource_internal_error=Ocorreu um erro interno.
verify_datasource_no_running_servers=N\u00E3o existe limite de servidores executados para esta fonte de dados.
verify_datasource_successful_header=Conex\u00E3o JDBC criada com \u00EAxito.
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,4 @@ verify_datasource_failed_header=\u521B\u5EFA JDBC \u8FDE\u63A5\u5931\u8D25\u3002
verify_datasource_internal_error=\u51FA\u73B0\u4E00\u4E2A\u5185\u90E8\u9519\u8BEF\u3002
verify_datasource_no_running_servers=\u6CA1\u6709\u8FD0\u884C\u7684\u670D\u52A1\u5668\u7ED1\u5B9A\u5230\u8FD9\u4E2A\u6570\u636E\u6E90\u3002
verify_datasource_successful_header=\u521B\u5EFA JDBC \u8FDE\u63A5\u6210\u529F\u3002
wizard_back=‹‹ Back
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean hasError() {

public String getErrorMessage() {
//noinspection ThrowableResultOfMethodCallIgnored
return hasError() ? null : getError().getMessage();
return hasError() ? getError().getMessage() : null;
}

public boolean isForbidden() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
*/
package org.jboss.as.console.client.v3.deployment;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FileUpload;
import org.jboss.as.console.client.core.BootstrapContext;
import org.jboss.as.console.client.shared.deployment.DeploymentReference;
import org.jboss.as.console.client.shared.flow.FunctionContext;
import org.jboss.as.console.client.v3.dmr.Operation;
Expand All @@ -37,9 +43,6 @@
import org.jboss.gwt.flow.client.Control;
import org.jboss.gwt.flow.client.Function;

import java.util.ArrayList;
import java.util.List;

import static org.jboss.dmr.client.ModelDescriptionConstants.ADD;
import static org.jboss.dmr.client.ModelDescriptionConstants.NAME;

Expand All @@ -54,7 +57,7 @@ private DeploymentFunctions() {
}

/**
* Expects an instance of {@link DeploymentReference} in the context.
* Expects a {@link DeploymentReference} instance in the context.
*/
public static class Upload implements Function<FunctionContext> {

Expand Down Expand Up @@ -89,52 +92,99 @@ public void execute(final Control<FunctionContext> control) {


/**
* Expects an instance of {@link DeploymentReference} in the context.
* Expects a {@link DeploymentReference} instance in the context.
*/
public static class AddContent implements Function<FunctionContext> {

private final DispatchAsync dispatcher;
static final String HEADER_CONTENT_TYPE = "Content-Type";
static final String APPLICATION_JSON = "application/json";

public AddContent(final DispatchAsync dispatcher) {this.dispatcher = dispatcher;}
private final BootstrapContext bootstrapContext;
private final boolean replace;

public AddContent(final BootstrapContext bootstrapContext, final boolean replace) {
this.bootstrapContext = bootstrapContext;
this.replace = replace;
}

@Override
public void execute(final Control<FunctionContext> control) {
DeploymentReference upload = control.getContext().pop();
List<ModelNode> contents = new ArrayList<>(1);
ModelNode hash = new ModelNode();
hash.get("hash").set(upload.getHash().getBytes());
contents.add(hash);

final Operation op = new Operation.Builder(ADD, ResourceAddress.ROOT)
.param(NAME, upload.getName())
.param("runtime-name", upload.getRuntimeName())
.param("enabled", upload.isEnableAfterDeployment())
.param("content", contents)
.build();

dispatcher.execute(new DMRAction(op), new AsyncCallback<DMRResponse>() {
@Override
public void onFailure(final Throwable caught) {
control.getContext()
.setError(new RuntimeException("Unable to add upload to the content repository."));
control.abort();
}
String requestJSO = replace ? makeReplaceJSO(upload) : makeAddJSO(upload);
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
bootstrapContext.getProperty(BootstrapContext.DOMAIN_API));
rb.setIncludeCredentials(true);
rb.setHeader(HEADER_CONTENT_TYPE, APPLICATION_JSON);

try {
rb.sendRequest(requestJSO, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
if (200 != statusCode) {
control.getContext()
.setError(new RuntimeException("Unable to add upload to the content repository."));
control.abort();
} else {
ModelNode node = new ModelNode();
node.get(NAME).set(upload.getName());
node.get("runtime-name").set(upload.getRuntimeName());
control.getContext().push(new Content(node));
control.proceed();
}
}

@Override
public void onError(Request request, Throwable exception) {
control.getContext().setError(
new RuntimeException("Unable to add upload to the content repository."));
control.abort();
}
});
} catch (RequestException e) {
control.getContext().setError(new RuntimeException("Unable to add upload to the content repository."));
control.abort();
}
}

@Override
public void onSuccess(final DMRResponse result) {
final ModelNode node = new ModelNode();
node.get(NAME).set(upload.getName());
node.get("runtime-name").set(upload.getRuntimeName());
control.getContext().push(new Content(node));
control.proceed();
}
});
private String makeAddJSO(DeploymentReference upload) {
//noinspection StringBufferReplaceableByString
StringBuilder builder = new StringBuilder();
builder.append("{");
builder.append("\"address\":[").append("{\"deployment\":\"").append(upload.getName()).append("\"}],");
builder.append("\"operation\":\"add\",");
builder.append("\"runtime-name\":\"").append(upload.getRuntimeName()).append("\",");
builder.append("\"content\":");
builder.append("[{\"hash\":{");
builder.append("\"BYTES_VALUE\":\"").append(upload.getHash()).append("\"");
builder.append("}}],");
builder.append("\"name\":\"").append(upload.getName()).append("\",");
builder.append("\"enabled\":\"").append(upload.isEnableAfterDeployment()).append("\"");
builder.append("}");
return builder.toString();
}

private String makeReplaceJSO(DeploymentReference upload) {
//noinspection StringBufferReplaceableByString
StringBuilder builder = new StringBuilder();
builder.append("{");
builder.append("\"operation\":\"full-replace-deployment\",");
builder.append("\"content\":");
builder.append("[{\"hash\":{");
builder.append("\"BYTES_VALUE\":\"").append(upload.getHash()).append("\"");
builder.append("}}],");
builder.append("\"name\":\"").append(upload.getName()).append("\",");
builder.append("\"runtime-name\":\"").append(upload.getRuntimeName()).append("\",");
builder.append("\"enabled\":\"").append(upload.isEnableAfterDeployment()).append("\"");
builder.append("}");
return builder.toString();
}
}


/**
* Expects an instance of {@link Content} in the context.
* Expects a {@link Content} instance in the context.
*/
public static class AddAssignment implements Function<FunctionContext> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ enum State {

static final UIMessages MESSAGES = Console.MESSAGES;

private final BootstrapContext bootstrapContext;
private final BeanFactory beanFactory;
private final DispatchAsync dispatcher;
private final DeploymentFinder deploymentFinder;

public AddDeploymentWizard(BootstrapContext bootstrapContext, BeanFactory beanFactory, DispatchAsync dispatcher,
DeploymentFinder deploymentFinder) {
super("add_deployment", new Context(bootstrapContext.isStandalone()), MESSAGES.createTitle("Deployment"));
this.bootstrapContext = bootstrapContext;
this.beanFactory = beanFactory;
this.dispatcher = dispatcher;
this.deploymentFinder = deploymentFinder;
Expand Down Expand Up @@ -216,7 +218,7 @@ public void onSuccess(final FunctionContext context) {

new Async<FunctionContext>(Footer.PROGRESS_ELEMENT).waterfall(functionContext, outcome,
new DeploymentFunctions.Upload(wizardContext.uploadForm, wizardContext.fileUpload),
new DeploymentFunctions.AddContent(dispatcher),
new DeploymentFunctions.AddContent(bootstrapContext, false),
new DeploymentFunctions.AddAssignment(dispatcher, wizardContext.serverGroup,
wizardContext.upload.isEnableAfterDeployment()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,55 @@
package org.jboss.as.console.client.v3.deployment.wizard;

import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SingleSelectionModel;
import org.jboss.as.console.client.domain.groups.deployment.CheckboxColumn;
import org.jboss.as.console.client.v3.deployment.Content;
import org.jboss.as.console.client.v3.widgets.wizard.WizardStep;
import org.jboss.ballroom.client.widgets.tables.DefaultCellTable;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;

import java.util.ArrayList;
import java.util.List;

/**
* @author Harald Pehl
*/
public class ContentRepositoryStep extends
WizardStep<AddDeploymentWizard.Context, AddDeploymentWizard.State> {

private DefaultCellTable<Content> table;
private ListDataProvider<Content> contentProvider;
private SingleSelectionModel<Content> selection;
private CheckBox enable;
static class SelectableContent implements CheckboxColumn.Selectable {

private final Content content;
private boolean selected;

SelectableContent(final Content content) {
this.content = content;
this.selected = false;
}

@Override
public boolean isSelected() {
return selected;
}

@Override
public void setSelected(final boolean selected) {
this.selected = selected;
}

public Content getContent() {
return content;
}
}


private DefaultCellTable<SelectableContent> table;
private ListDataProvider<SelectableContent> contentProvider;
private SingleSelectionModel<SelectableContent> selection;

public ContentRepositoryStep(final AddDeploymentWizard wizard) {super(wizard, "Uploaded Content");}

Expand All @@ -51,19 +79,20 @@ public class ContentRepositoryStep extends
public Widget asWidget() {
FlowPanel panel = new FlowPanel();

ProvidesKey<Content> keyProvider = Content::getName;
ProvidesKey<SelectableContent> keyProvider = item -> item.getContent().getName();

selection = new SingleSelectionModel<>(keyProvider);

table = new DefaultCellTable<>(5, keyProvider);
table.setSelectionModel(selection);
table.addColumn(new TextColumn<Content>() {
table.addColumn(new TextColumn<SelectableContent>() {
@Override
public String getValue(final Content content) {
return content.getName();
public String getValue(final SelectableContent item) {
return item.getContent().getName();
}
}, "Name");
panel.add(table);
table.addColumn(new CheckboxColumn<>(), "Enable");

contentProvider = new ListDataProvider<>(keyProvider);
contentProvider.addDataDisplay(table);
Expand All @@ -72,22 +101,23 @@ public String getValue(final Content content) {
pager.setDisplay(table);
panel.add(pager);

enable = new CheckBox("Enable");
panel.add(enable);

return panel;
}

@Override
protected void onShow(final AddDeploymentWizard.Context context) {
if (context.contentRepository.isEmpty()) {
wizard.showError("Please choose an entry!");
List<SelectableContent> data = new ArrayList<>();
for (Content content : context.contentRepository) {
data.add(new SelectableContent(content));
}

if (data.isEmpty()) {
wizard.showError("All uploaded content is already assigned to this server group!");
} else {
wizard.clearError();
}
contentProvider.setList(context.contentRepository);
contentProvider.setList(data);
table.selectDefaultEntity();
enable.setValue(context.enableExistingContent);
}

@Override
Expand All @@ -97,8 +127,8 @@ protected boolean onNext(final AddDeploymentWizard.Context context) {
return false;
}
wizard.clearError();
context.existingContent = selection.getSelectedObject();
context.enableExistingContent = enable.getValue();
context.existingContent = selection.getSelectedObject().getContent();
context.enableExistingContent = selection.getSelectedObject().isSelected();
return true; // actual upload is done in AddDeploymentWizard.finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public Widget asWidget() {

// create a panel to hold all of the form widgets.
VerticalPanel formPanel = new VerticalPanel();
// formPanel.getElement().setAttribute("style", "width:100%");
form.setWidget(formPanel);

// create a FileUpload widgets.
Expand All @@ -79,6 +78,7 @@ public Widget asWidget() {

@Override
protected void onShow(final AddDeploymentWizard.Context context) {
form.reset();
context.uploadForm = form;
context.fileUpload = fileUpload;
}
Expand Down
Loading

0 comments on commit 2a19edb

Please sign in to comment.