From 1654097c69cfc6b3dbeda09265b96fb7fed81353 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Sun, 17 Mar 2013 09:38:58 +0100 Subject: [PATCH] #591 --- .../webgui/persistence/IProjectDAO.java | 2 +- .../persistence/impl/FSProjectDAOImpl.java | 62 ++++++++----------- .../application/GlobalPropertiesBean.java | 5 ++ .../web/beans/application/ProjectsBean.java | 22 ++++++- .../main/resources/lang/Common_de.properties | 3 +- .../main/resources/lang/Common_en.properties | 3 +- .../dialogs/ProjectOverviewPageDialogs.xhtml | 2 +- .../webapp/pages/AnalysisEditorPage.xhtml | 4 +- .../webapp/pages/ProjectOverviewPage.xhtml | 2 +- 9 files changed, 59 insertions(+), 46 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java index 9d80b506..6c6adc29 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java @@ -56,7 +56,7 @@ public interface IProjectDAO { public abstract void addProject(String projectName, final String username) throws ProjectAlreadyExistingException, IOException; @PreAuthorize("hasAnyRole('User', 'Administrator')") - public abstract void delProject(String projectName); + public abstract void delProject(String projectName) throws IOException; /** * This method imports an existing kax-file into the application. If the given project name does already exist, the application will not try to upload it in the diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java index 182249a5..e83909cb 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java @@ -785,17 +785,18 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { @Override @PreAuthorize("hasAnyRole('User', 'Administrator')") - public void delProject(final String projectName) { + public void delProject(final String projectName) throws IOException { if (!this.projectExists(projectName)) { throw new ProjectNotExistingException("A project with the name '" + projectName + "' does not exist."); } - // Assemble all paths - FSProjectDAOImpl.assembleProjectDir(projectName); - FSProjectDAOImpl.assembleKaxFile(projectName); - FSProjectDAOImpl.assembleMetaFile(projectName); - this.assembleLibDir(projectName); + // Try to remove the whole project + final File projectDir = FSProjectDAOImpl.assembleProjectDir(projectName); + final boolean result = FileSystemUtils.deleteRecursively(projectDir); + if (!result) { + throw new IOException("Could not remove the project directory."); + } } /* @@ -886,42 +887,29 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { @PreAuthorize("hasAnyRole('User', 'Administrator')") public void copyProject(final String originalProjectName, final String newProjectName) throws ProjectNotExistingException, ProjectAlreadyExistingException, IOException { - // Get the necessary paths final File dstProjDir = FSProjectDAOImpl.assembleProjectDir(newProjectName); - final File srcLibDir = this.assembleLibDir(originalProjectName); - final File dstLibDir = this.assembleLibDir(newProjectName); + try { + // Check whether the project exists already! + if (this.projectExists(newProjectName)) { + throw new ProjectAlreadyExistingException("A project with the name '" + newProjectName + "' exists already."); + } + if (!this.projectExists(originalProjectName)) { + throw new ProjectNotExistingException("A project with the name '" + originalProjectName + "' does not exist."); + } - // Check whether the project exists already! - if (this.projectExists(newProjectName)) { - throw new ProjectAlreadyExistingException("A project with the name '" + newProjectName + "' exists already."); - } + final File srcProjDir = FSProjectDAOImpl.assembleProjectDir(originalProjectName); - final File srcKaxFile = FSProjectDAOImpl.assembleKaxFile(originalProjectName); - final File dstKaxFile = FSProjectDAOImpl.assembleKaxFile(newProjectName); + // Copy all files and rename the kax file + FileSystemUtils.copyRecursively(srcProjDir, dstProjDir); - try { - if (dstProjDir.mkdir() && dstLibDir.mkdir()) { - // Copy the kax file - FileCopyUtils.copy(srcKaxFile, dstKaxFile); - - // Copy the libs - for (final File lib : srcLibDir.listFiles()) { - final File dstLibFile = new File(dstLibDir, lib.getName()); - FileCopyUtils.copy(lib, dstLibFile); - } - } else { - throw new IOException("Could not create directories."); - } - } catch (final IOException ex) { - // Something went wrong. Remove the directories and files! - final boolean libDirDeleted = dstLibDir.delete(); - // Keep in mind that the potential remains of the file have to be deleted before the directory. - final boolean projectFileDeleted = dstKaxFile.delete(); - final boolean projectDeleted = dstProjDir.delete(); + final File dstKaxFile = new File(FSProjectDAOImpl.ROOT_DIRECTORY + File.separator + newProjectName + File.separator + originalProjectName + "." + + FSProjectDAOImpl.KAX_EXTENSION); + final File realDstKaxFile = FSProjectDAOImpl.assembleKaxFile(newProjectName); - // The following part is only necessary to calm FindBugs... - @SuppressWarnings("unused") - final boolean deleteResults = libDirDeleted && projectFileDeleted && projectDeleted; + dstKaxFile.renameTo(realDstKaxFile); + } catch (final IOException ex) { + // Something went wrong. Remove everything + FileSystemUtils.deleteRecursively(dstProjDir); // Rethrow the exception in order to inform the caller of this method throw new IOException("An IO Exception occured while copying the project.", ex); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/GlobalPropertiesBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/GlobalPropertiesBean.java index d7f6227f..b15d3f6b 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/GlobalPropertiesBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/GlobalPropertiesBean.java @@ -58,6 +58,7 @@ public final class GlobalPropertiesBean implements Serializable { private static final String PROPERTY_MSG_REPOSITORY_CREATION_EXCEPTION = "msgRepositoryCreationException"; private static final String PROPERTY_MSG_LIBRARY_UPLOADED = "msgLibraryUploaded"; private static final String PROPERTY_MSG_PROJECT_CREATED = "msgProjectCreated"; + private static final String PROPERTY_MSG_PROJECT_DELETED = "msgProjectDeleted"; private static final String PROPERTY_MSG_PROJECT_SAVING_EXCEPTION = "msgProjectSavingException"; private static final String PROPERTY_MSG_PROJECT_NOT_EXISTING_EXCEPTION = "msgProjectNotExistingException"; private static final String PROPERTY_MSG_PROJECT_MODIFIED = "msgProjectModified"; @@ -188,6 +189,10 @@ public final class GlobalPropertiesBean implements Serializable { return GlobalPropertiesBean.getLocalizedString(GlobalPropertiesBean.PROPERTY_MSG_LIBRARY_UPLOADING_EXCEPTION); } + public String getMsgProjectDeleted() { + return GlobalPropertiesBean.getLocalizedString(GlobalPropertiesBean.PROPERTY_MSG_PROJECT_DELETED); + } + private static String getLocalizedString(final String key) { // Get the correct resource bundle for the current language (taken from the current context) and search it for the given key final Locale currLocale = FacesContext.getCurrentInstance().getELContext().getLocale(); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java index f41f692a..f4287206 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java @@ -55,7 +55,6 @@ import org.primefaces.model.UploadedFile; @Component @Lazy @Scope("singleton") -// TODO Remove this bean if possible. It seems to be unnecessary. public final class ProjectsBean { private static final Log LOG = LogFactory.getLog(ProjectsBean.class); @@ -101,7 +100,7 @@ public final class ProjectsBean { */ public void addProject(final String project, final CurrentProjectOverviewBean currentProjectOverviewBean, final UserBean userBean) { try { - // Try and use the FS-Manager to create the project atomically. + // Try and use the project service to create the project atomically. this.projectService.addProject(project, userBean.getUsername()); // If there were no exception, everything went well. We can add the project to our list. this.projects.add(project); @@ -118,6 +117,25 @@ public final class ProjectsBean { } } + public void delProject(final String project, final CurrentProjectOverviewBean currentProjectOverviewBean) { + try { + // Try and use the project service to delete the project atomically. + this.projectService.delProject(project); + // If there were no exception, everything went well. We can remove the project from our list. + this.projects.remove(project); + // Inform the user + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectDeleted()); + // Update the list of the "calling" bean + currentProjectOverviewBean.updateLists(); + } catch (final IOException ex) { + ProjectsBean.LOG.error("An error occured while removing the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while removing the project."); + } catch (final ProjectAlreadyExistingException ex) { + ProjectsBean.LOG.info("A project with the same name exists already.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, "A project with the same name exists already."); + } + } + /** * This method tries to copy the project with the given name and saves it under the given new name. In either case (this means if the project has been created, * if the project could not be created for any reason) the user will be informed via the growl component. In other words: A message will be delivered within the diff --git a/Kieker.WebGUI/src/main/resources/lang/Common_de.properties b/Kieker.WebGUI/src/main/resources/lang/Common_de.properties index 70b373b8..10dd44a2 100644 --- a/Kieker.WebGUI/src/main/resources/lang/Common_de.properties +++ b/Kieker.WebGUI/src/main/resources/lang/Common_de.properties @@ -72,4 +72,5 @@ msgProjectSavingException = Beim Speichern des Projekts ist ein Fehler aufgetre msgProjectNotExistingException = Das aktuelle Projekt existiert nicht. msgProjectModified = Das Projekt wurde in der Zwischenzeit au\u00dferhalb dieses Editors modifiziert. msgLibraryExistingException = Eine Bibliothek mit dem gleichen Namen existiert bereits. -msgLibraryUploadingException = Beim Hochladen der Bibliothek ist ein Fehler aufgetreten. Bitte �berpr�fen Sie den Log f�r weitere Details. \ No newline at end of file +msgLibraryUploadingException = Beim Hochladen der Bibliothek ist ein Fehler aufgetreten. Bitte �berpr�fen Sie den Log f�r weitere Details. +msgProjectDeleted = Das Projekt wurde erfolgreich gel�scht. \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/resources/lang/Common_en.properties b/Kieker.WebGUI/src/main/resources/lang/Common_en.properties index dddf48c9..d827892e 100644 --- a/Kieker.WebGUI/src/main/resources/lang/Common_en.properties +++ b/Kieker.WebGUI/src/main/resources/lang/Common_en.properties @@ -72,4 +72,5 @@ msgProjectSavingException = An error occured while saving the project. msgProjectNotExistingException = The project does not exist. msgProjectModified = The project has been modified externally in the meanwhile. msgLibraryExistingException = A library with the same name exists already. -msgLibraryUploadingException = An error occured while uploading the library. \ No newline at end of file +msgLibraryUploadingException = An error occured while uploading the library. +msgProjectDeleted = The project has been deleted successfully. \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/webapp/dialogs/ProjectOverviewPageDialogs.xhtml b/Kieker.WebGUI/src/main/webapp/dialogs/ProjectOverviewPageDialogs.xhtml index 81a75b76..99ea950a 100644 --- a/Kieker.WebGUI/src/main/webapp/dialogs/ProjectOverviewPageDialogs.xhtml +++ b/Kieker.WebGUI/src/main/webapp/dialogs/ProjectOverviewPageDialogs.xhtml @@ -50,7 +50,7 @@ <hr/> <div style="text-align: right"> - <p:commandButton value="#{localizedMessages.ok}" action="#{projectsBean.deleteProject(currentProjectOverviewBean.projectName)}" update=":projectsListForm :messages" oncomplete="deleteProjectDialog.hide()" /> + <p:commandButton value="#{localizedMessages.ok}" action="#{projectsBean.delProject(currentProjectOverviewBean.projectName, currentProjectOverviewBean)}" update=":projectsListForm :messages" oncomplete="deleteProjectDialog.hide()" /> </div> </h:form> </p:dialog> diff --git a/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml b/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml index 0d67ef9e..3b034dfd 100644 --- a/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml +++ b/Kieker.WebGUI/src/main/webapp/pages/AnalysisEditorPage.xhtml @@ -69,7 +69,7 @@ // "Overwrite" the function in the template function bodyLoaded() { - // postInit(); + postInit(); } </script> </ui:define> @@ -77,7 +77,7 @@ <ui:define name="furtherForms"> <h:form id="hidden" style="display:none"> <p:remoteCommand autoRun="true" name="init" action="#{currentAnalysisEditorBean.initializeGraph()}" /> - <p:remoteCommand name="postInit" action="#{currentAnalysisEditorGraphBean.startAutoLayout()}" /> + <p:remoteCommand name="postInit" action="#{currentAnalysisEditorGraphBean.scaleToFit()}" /> </h:form> <h:form id="hiddenNodeProperties" style="display:none"> <p:remoteCommand name="nodeClickCommand" action="#{currentAnalysisEditorGraphBean.nodeClicked()}" update=":propertiesForm"/> diff --git a/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml b/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml index 598930a3..2715d9dc 100644 --- a/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml +++ b/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml @@ -70,7 +70,7 @@ <p:separator/> <p:menuitem id="copyButton" icon="ui-icon-copy" styleClass="element-with-whitespace" value=" #{localizedProjectOverviewMessages.copyProject}" action="#{currentProjectOverviewBean.setProjectName(project)}" onclick="copyProjectDialog.show()" update=":messages"/> <p:menuitem id="renameButton" icon="ui-icon-edit" styleClass="element-with-whitespace" value=" #{localizedProjectOverviewMessages.renameProject}" action="#{currentProjectOverviewBean.setProjectName(project)}" onclick="renameProjectDialog.show()" disabled="true" update=":messages"/> - <p:menuitem id="deleteButton" icon="ui-icon-delete" styleClass="element-with-whitespace" value=" #{localizedProjectOverviewMessages.deleteProject}" action="#{currentProjectOverviewBean.setProjectName(project)}" onclick="deleteProjectDialog.show()" disabled="true" update=":messages"/> + <p:menuitem id="deleteButton" icon="ui-icon-delete" styleClass="element-with-whitespace" value=" #{localizedProjectOverviewMessages.deleteProject}" action="#{currentProjectOverviewBean.setProjectName(project)}" onclick="deleteProjectDialog.show()" update=":messages"/> </c:if> </p:menu> </p:column> -- GitLab