Skip to content
Snippets Groups Projects
Commit 1654097c authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

#591

parent 6033c559
No related branches found
No related tags found
No related merge requests found
Showing with 59 additions and 46 deletions
...@@ -56,7 +56,7 @@ public interface IProjectDAO { ...@@ -56,7 +56,7 @@ public interface IProjectDAO {
public abstract void addProject(String projectName, final String username) throws ProjectAlreadyExistingException, IOException; public abstract void addProject(String projectName, final String username) throws ProjectAlreadyExistingException, IOException;
@PreAuthorize("hasAnyRole('User', 'Administrator')") @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 * 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
......
...@@ -785,17 +785,18 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { ...@@ -785,17 +785,18 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
@Override @Override
@PreAuthorize("hasAnyRole('User', 'Administrator')") @PreAuthorize("hasAnyRole('User', 'Administrator')")
public void delProject(final String projectName) { public void delProject(final String projectName) throws IOException {
if (!this.projectExists(projectName)) { if (!this.projectExists(projectName)) {
throw new ProjectNotExistingException("A project with the name '" + projectName + "' does not exist."); throw new ProjectNotExistingException("A project with the name '" + projectName + "' does not exist.");
} }
// Assemble all paths // Try to remove the whole project
FSProjectDAOImpl.assembleProjectDir(projectName); final File projectDir = FSProjectDAOImpl.assembleProjectDir(projectName);
FSProjectDAOImpl.assembleKaxFile(projectName); final boolean result = FileSystemUtils.deleteRecursively(projectDir);
FSProjectDAOImpl.assembleMetaFile(projectName);
this.assembleLibDir(projectName);
if (!result) {
throw new IOException("Could not remove the project directory.");
}
} }
/* /*
...@@ -886,42 +887,29 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { ...@@ -886,42 +887,29 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener {
@PreAuthorize("hasAnyRole('User', 'Administrator')") @PreAuthorize("hasAnyRole('User', 'Administrator')")
public void copyProject(final String originalProjectName, final String newProjectName) throws ProjectNotExistingException, ProjectAlreadyExistingException, public void copyProject(final String originalProjectName, final String newProjectName) throws ProjectNotExistingException, ProjectAlreadyExistingException,
IOException { IOException {
// Get the necessary paths
final File dstProjDir = FSProjectDAOImpl.assembleProjectDir(newProjectName); final File dstProjDir = FSProjectDAOImpl.assembleProjectDir(newProjectName);
final File srcLibDir = this.assembleLibDir(originalProjectName); try {
final File dstLibDir = this.assembleLibDir(newProjectName); // 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! final File srcProjDir = FSProjectDAOImpl.assembleProjectDir(originalProjectName);
if (this.projectExists(newProjectName)) {
throw new ProjectAlreadyExistingException("A project with the name '" + newProjectName + "' exists already.");
}
final File srcKaxFile = FSProjectDAOImpl.assembleKaxFile(originalProjectName); // Copy all files and rename the kax file
final File dstKaxFile = FSProjectDAOImpl.assembleKaxFile(newProjectName); FileSystemUtils.copyRecursively(srcProjDir, dstProjDir);
try { final File dstKaxFile = new File(FSProjectDAOImpl.ROOT_DIRECTORY + File.separator + newProjectName + File.separator + originalProjectName + "."
if (dstProjDir.mkdir() && dstLibDir.mkdir()) { + FSProjectDAOImpl.KAX_EXTENSION);
// Copy the kax file final File realDstKaxFile = FSProjectDAOImpl.assembleKaxFile(newProjectName);
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();
// The following part is only necessary to calm FindBugs... dstKaxFile.renameTo(realDstKaxFile);
@SuppressWarnings("unused") } catch (final IOException ex) {
final boolean deleteResults = libDirDeleted && projectFileDeleted && projectDeleted; // Something went wrong. Remove everything
FileSystemUtils.deleteRecursively(dstProjDir);
// Rethrow the exception in order to inform the caller of this method // Rethrow the exception in order to inform the caller of this method
throw new IOException("An IO Exception occured while copying the project.", ex); throw new IOException("An IO Exception occured while copying the project.", ex);
......
...@@ -58,6 +58,7 @@ public final class GlobalPropertiesBean implements Serializable { ...@@ -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_REPOSITORY_CREATION_EXCEPTION = "msgRepositoryCreationException";
private static final String PROPERTY_MSG_LIBRARY_UPLOADED = "msgLibraryUploaded"; 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_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_SAVING_EXCEPTION = "msgProjectSavingException";
private static final String PROPERTY_MSG_PROJECT_NOT_EXISTING_EXCEPTION = "msgProjectNotExistingException"; private static final String PROPERTY_MSG_PROJECT_NOT_EXISTING_EXCEPTION = "msgProjectNotExistingException";
private static final String PROPERTY_MSG_PROJECT_MODIFIED = "msgProjectModified"; private static final String PROPERTY_MSG_PROJECT_MODIFIED = "msgProjectModified";
...@@ -188,6 +189,10 @@ public final class GlobalPropertiesBean implements Serializable { ...@@ -188,6 +189,10 @@ public final class GlobalPropertiesBean implements Serializable {
return GlobalPropertiesBean.getLocalizedString(GlobalPropertiesBean.PROPERTY_MSG_LIBRARY_UPLOADING_EXCEPTION); 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) { 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 // 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(); final Locale currLocale = FacesContext.getCurrentInstance().getELContext().getLocale();
......
...@@ -55,7 +55,6 @@ import org.primefaces.model.UploadedFile; ...@@ -55,7 +55,6 @@ import org.primefaces.model.UploadedFile;
@Component @Component
@Lazy @Lazy
@Scope("singleton") @Scope("singleton")
// TODO Remove this bean if possible. It seems to be unnecessary.
public final class ProjectsBean { public final class ProjectsBean {
private static final Log LOG = LogFactory.getLog(ProjectsBean.class); private static final Log LOG = LogFactory.getLog(ProjectsBean.class);
...@@ -101,7 +100,7 @@ public final class ProjectsBean { ...@@ -101,7 +100,7 @@ public final class ProjectsBean {
*/ */
public void addProject(final String project, final CurrentProjectOverviewBean currentProjectOverviewBean, final UserBean userBean) { public void addProject(final String project, final CurrentProjectOverviewBean currentProjectOverviewBean, final UserBean userBean) {
try { 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()); this.projectService.addProject(project, userBean.getUsername());
// If there were no exception, everything went well. We can add the project to our list. // If there were no exception, everything went well. We can add the project to our list.
this.projects.add(project); this.projects.add(project);
...@@ -118,6 +117,25 @@ public final class ProjectsBean { ...@@ -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, * 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 * 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
......
...@@ -72,4 +72,5 @@ msgProjectSavingException = Beim Speichern des Projekts ist ein Fehler aufgetre ...@@ -72,4 +72,5 @@ msgProjectSavingException = Beim Speichern des Projekts ist ein Fehler aufgetre
msgProjectNotExistingException = Das aktuelle Projekt existiert nicht. msgProjectNotExistingException = Das aktuelle Projekt existiert nicht.
msgProjectModified = Das Projekt wurde in der Zwischenzeit au\u00dferhalb dieses Editors modifiziert. msgProjectModified = Das Projekt wurde in der Zwischenzeit au\u00dferhalb dieses Editors modifiziert.
msgLibraryExistingException = Eine Bibliothek mit dem gleichen Namen existiert bereits. msgLibraryExistingException = Eine Bibliothek mit dem gleichen Namen existiert bereits.
msgLibraryUploadingException = Beim Hochladen der Bibliothek ist ein Fehler aufgetreten. Bitte berprfen Sie den Log fr weitere Details. msgLibraryUploadingException = Beim Hochladen der Bibliothek ist ein Fehler aufgetreten. Bitte berprfen Sie den Log fr weitere Details.
\ No newline at end of file msgProjectDeleted = Das Projekt wurde erfolgreich gelscht.
\ No newline at end of file
...@@ -72,4 +72,5 @@ msgProjectSavingException = An error occured while saving the project. ...@@ -72,4 +72,5 @@ msgProjectSavingException = An error occured while saving the project.
msgProjectNotExistingException = The project does not exist. msgProjectNotExistingException = The project does not exist.
msgProjectModified = The project has been modified externally in the meanwhile. msgProjectModified = The project has been modified externally in the meanwhile.
msgLibraryExistingException = A library with the same name exists already. msgLibraryExistingException = A library with the same name exists already.
msgLibraryUploadingException = An error occured while uploading the library. msgLibraryUploadingException = An error occured while uploading the library.
\ No newline at end of file msgProjectDeleted = The project has been deleted successfully.
\ No newline at end of file
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<hr/> <hr/>
<div style="text-align: right"> <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> </div>
</h:form> </h:form>
</p:dialog> </p:dialog>
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
// "Overwrite" the function in the template // "Overwrite" the function in the template
function bodyLoaded() { function bodyLoaded() {
// postInit(); postInit();
} }
</script> </script>
</ui:define> </ui:define>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
<ui:define name="furtherForms"> <ui:define name="furtherForms">
<h:form id="hidden" style="display:none"> <h:form id="hidden" style="display:none">
<p:remoteCommand autoRun="true" name="init" action="#{currentAnalysisEditorBean.initializeGraph()}" /> <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>
<h:form id="hiddenNodeProperties" style="display:none"> <h:form id="hiddenNodeProperties" style="display:none">
<p:remoteCommand name="nodeClickCommand" action="#{currentAnalysisEditorGraphBean.nodeClicked()}" update=":propertiesForm"/> <p:remoteCommand name="nodeClickCommand" action="#{currentAnalysisEditorGraphBean.nodeClicked()}" update=":propertiesForm"/>
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<p:separator/> <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="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="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> </c:if>
</p:menu> </p:menu>
</p:column> </p:column>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment