Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
bugzilla:996425 Error message when another form with the same name ex…
Browse files Browse the repository at this point in the history
…ists.
  • Loading branch information
nmirasch committed Aug 27, 2013
1 parent 9e6890a commit 2f31945
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
Expand Up @@ -16,6 +16,8 @@
package org.jbpm.formModeler.panels.modeler.backend;

import org.apache.commons.lang.StringUtils;
import org.guvnor.common.services.backend.exceptions.ExceptionUtilities;
import org.jboss.errai.bus.client.api.base.MessageDeliveryFailure;
import org.jboss.errai.bus.server.annotations.Service;
import org.jbpm.formModeler.api.model.Field;
import org.jbpm.formModeler.core.config.FormManager;
Expand All @@ -29,10 +31,12 @@
import org.jbpm.formModeler.core.processing.FormProcessor;
import org.jbpm.formModeler.editor.service.FormModelerService;
import org.kie.commons.io.IOService;
import org.kie.commons.java.nio.file.FileAlreadyExistsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.workbench.events.NotificationEvent;
import org.uberfire.workbench.events.ResourceAddedEvent;
import org.uberfire.workbench.events.ResourceUpdatedEvent;

Expand Down Expand Up @@ -63,6 +67,8 @@ public class FormModelerServiceImpl implements FormModelerService, FormEditorCon
@Inject
private Event<ResourceUpdatedEvent> resourceUpdatedEvent;

@Inject
private Event<NotificationEvent> notification;

@Inject
private FormManager formManager;
Expand Down Expand Up @@ -90,7 +96,7 @@ public void removeEditingForm(String ctxUID) {
@Override
public FormEditorContextTO loadForm(Path context) {
try {
org.kie.commons.java.nio.file.Path kiePath = paths.convert( context );
org.kie.commons.java.nio.file.Path kiePath = paths.convert(context);

String xml = ioService.readAllString(kiePath).trim();
Form form = formSerializationManager.loadFormFromXML(xml, kiePath.toUri().toString());
Expand All @@ -105,7 +111,7 @@ public FormEditorContextTO loadForm(Path context) {
@Override
public FormEditorContext newContext(Form form, Object path) {
FormRenderContext ctx = formRenderContextManager.newContext(form, new HashMap<String, Object>());
org.kie.commons.java.nio.file.Path kpath = paths.convert((Path)path);
org.kie.commons.java.nio.file.Path kpath = paths.convert((Path) path);

FormEditorContext formEditorContext = new FormEditorContext(ctx, kpath.toUri().toString());
formEditorContextMap.put(ctx.getUID(), formEditorContext);
Expand Down Expand Up @@ -147,21 +153,23 @@ public void saveContext(String ctxUID) throws Exception {

@Override
public Path createForm(Path context, String formName) {
org.kie.commons.java.nio.file.Path kiePath = paths.convert(context ).resolve(formName);

if (ioService.exists(kiePath)) {
return context;
}
org.kie.commons.java.nio.file.Path kiePath = paths.convert(context).resolve(formName);
try {
ioService.createFile(kiePath);

ioService.createFile(kiePath);
Form form = formManager.createForm(formName);

Form form = formManager.createForm(formName);
ioService.write(kiePath, formSerializationManager.generateFormXML(form));

ioService.write(kiePath, formSerializationManager.generateFormXML(form));
final Path path = paths.convert(kiePath, false);
resourceAddedEvent.fire(new ResourceAddedEvent(path));

final Path path = paths.convert(kiePath, false);
resourceAddedEvent.fire(new ResourceAddedEvent(path));
return path;
} catch (FileAlreadyExistsException e) {
throw new IllegalArgumentException( kiePath.toString());
} catch (Exception e) {
throw new IllegalArgumentException(kiePath.toString());
}

return path;
}
}
Expand Up @@ -18,18 +18,27 @@

import com.google.gwt.user.client.ui.IsWidget;
import org.jboss.errai.bus.client.api.RemoteCallback;
import org.jboss.errai.bus.client.api.base.MessageDeliveryFailure;
import org.jboss.errai.ioc.client.api.Caller;
import org.jbpm.formModeler.editor.client.type.FormDefinitionResourceType;
import org.jbpm.formModeler.editor.service.FormModelerService;
import org.kie.workbench.common.widgets.client.callbacks.DefaultErrorCallback;
import org.kie.workbench.common.widgets.client.handlers.DefaultNewResourceHandler;
import org.kie.workbench.common.widgets.client.handlers.NewResourcePresenter;
import org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants;
import org.uberfire.backend.vfs.Path;
import org.uberfire.client.common.BusyPopup;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.mvp.PlaceRequest;
import org.uberfire.mvp.impl.PathPlaceRequest;
import org.uberfire.workbench.events.NotificationEvent;
import org.jboss.errai.bus.client.api.ErrorCallback;
import org.jboss.errai.bus.client.api.Message;
import org.kie.workbench.common.widgets.client.popups.errors.ErrorPopup;
import org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;

@ApplicationScoped
Expand All @@ -45,6 +54,9 @@ public class NewFormDefinitionlHandler extends DefaultNewResourceHandler {
@Inject
private FormDefinitionResourceType resourceType;

@Inject
private Event<NotificationEvent> notificationEvent;

@Override
public String getDescription() {
return "New Form";
Expand All @@ -59,15 +71,27 @@ public IsWidget getIcon() {
public void create(org.guvnor.common.services.project.model.Package pkg, String baseFileName, final NewResourcePresenter presenter) {
BusyPopup.showMessage("Creating New Form");

modelerService.call( new RemoteCallback<Path>() {
@Override
public void callback( final Path path ) {
BusyPopup.close();
presenter.complete();
notifySuccess();
PlaceRequest place = new PathPlaceRequest(path, "FormModelerEditor");
placeManager.goTo(place);
}
} ).createForm(pkg.getPackageMainResourcesPath(), buildFileName(resourceType, baseFileName));
modelerService.call(new RemoteCallback<Path>() {
@Override
public void callback(final Path path) {
BusyPopup.close();
presenter.complete();
notifySuccess();
PlaceRequest place = new PathPlaceRequest(path, "FormModelerEditor");
placeManager.goTo(place);

}
}, new ErrorCallback() {
@Override
public boolean error(Message message,
Throwable throwable) {
BusyPopup.close();
ErrorPopup.showMessage(CommonConstants.INSTANCE.ExceptionFileAlreadyExists0(throwable.getMessage()));
return true;
}
}
).createForm(pkg.getPackageMainResourcesPath(), buildFileName(resourceType, baseFileName));
}


}

0 comments on commit 2f31945

Please sign in to comment.