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 0325a9a9c79654ae68571863d18b0e673cf51c4f..66c6f16b812b50d8e3bb4a7e2b82d5043d0e228f 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java @@ -136,7 +136,10 @@ public interface IProjectDAO { * @param timeStamp * The time stamp which has to be compared with the "real" time stamp of the project. * @param overwriteNewerProject - * Determines whether a newer project file will be overwritten without further warning or not- + * Determines whether a newer project file will be overwritten without further warning or not. + * @param username + * The name of the user who saves the project. + * * @throws ProjectNotExistingException * If a project with the given name does not exist. * @throws IOException @@ -145,7 +148,7 @@ public interface IProjectDAO { * If the project on the file system is newer and the overwriteNewerProject-flag has not been set. */ @PreAuthorize("hasAnyRole('User', 'Administrator')") - public abstract void saveProject(String projectName, MIProject project, long timeStamp, boolean overwriteNewerProject) throws + public abstract void saveProject(String projectName, MIProject project, long timeStamp, boolean overwriteNewerProject, String username) throws ProjectNotExistingException, IOException, NewerProjectException; /** @@ -246,13 +249,24 @@ public interface IProjectDAO { public abstract ComponentListContainer getAvailableComponents(final String project); /** - * Delivers the owner of the given project or a substituion if the meta data are corrupt or missing. + * Delivers the owner of the given project or a substitution if the meta data is corrupt or missing. * * @param projectName * The name of the project whose owner should be delivered. + * * @return The owner (creator) of the project. */ @PreAuthorize("isAuthenticated()") public abstract String getOwner(final String projectName); + /** + * Delivers the last user of the given project or a substitution if the meta data is corrupt or missing. + * + * @param projectName + * The name of the project whose last user should be delivered. + * + * @return The last user of the project. + */ + @PreAuthorize("isAuthenticated()") + public abstract String getLastUser(final String projectName); } 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 f851fa5353cc539359cc93e18531d42da0087f85..641ecf5abf0ddfbeda1c7f8a1fccd346abfd0dea 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 @@ -23,7 +23,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.lang.annotation.Annotation; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; @@ -104,6 +103,8 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { private static final String LIB_EXTENSION = "jar"; private static final String LIB_DIRECTORY = "lib"; private static final String ROOT_DIRECTORY = "data"; + private static final String PROPERTY_KEY_LAST_USER = "last user"; + private static final String PROPERTY_KEY_OWNER = "owner"; @Autowired private PluginFinder pluginFinder; @@ -811,17 +812,9 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { // Store the initial meta data final Properties properties = new Properties(); - properties.put("owner", username); - - FileOutputStream out = null; - try { - out = new FileOutputStream(metaFile); - properties.store(out, ""); - } finally { - if (out != null) { - out.close(); - } - } + properties.put(FSProjectDAOImpl.PROPERTY_KEY_OWNER, username); + properties.put(FSProjectDAOImpl.PROPERTY_KEY_LAST_USER, username); + FSProjectDAOImpl.savePropertiesFile(properties, projectName); } else { // The directories could not be created throw new IOException("Project-Directories could not be created."); @@ -864,7 +857,7 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { // Now load the kax file and use the resulting MIProject to overwrite the existing (newly created) kax file final MIProject project = AnalysisController.loadFromFile(tempFile); - this.saveProject(projectName, project, 0, true); + this.saveProject(projectName, project, 0, true, username); } /* @@ -964,12 +957,12 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { /* * (non-Javadoc) * - * @see kieker.webgui.persistence.IProjectDAO#saveProject(java.lang.String, kieker.analysis.model.analysisMetaModel.MIProject, long, boolean) + * @see kieker.webgui.persistence.IProjectDAO#saveProject(java.lang.String, kieker.analysis.model.analysisMetaModel.MIProject, long, boolean, String) */ @Override @PreAuthorize("hasAnyRole('User', 'Administrator')") - public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject) throws - ProjectNotExistingException, IOException, NewerProjectException { + public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject, + final String username) throws ProjectNotExistingException, IOException, NewerProjectException { // Check whether the project exists if (!this.projectExists(projectName)) { throw new ProjectNotExistingException("A project with the name '" + projectName + "' does not exist."); @@ -983,6 +976,41 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { // Try to save it. AnalysisController.saveToFile(FSProjectDAOImpl.assembleKaxFile(projectName), project); + + // Store the new meta data + final Properties properties = FSProjectDAOImpl.loadPropertiesFile(projectName); + properties.put(FSProjectDAOImpl.PROPERTY_KEY_LAST_USER, username); + FSProjectDAOImpl.savePropertiesFile(properties, projectName); + } + + private static final Properties loadPropertiesFile(final String projectName) throws IOException { + final File metaFile = FSProjectDAOImpl.assembleMetaFile(projectName); + final Properties properties = new Properties(); + + FileInputStream in = null; + try { + in = new FileInputStream(metaFile); + properties.load(in); + } finally { + if (in != null) { + in.close(); + } + } + + return properties; + } + + private static final void savePropertiesFile(final Properties properties, final String projectName) throws IOException { + final File metaFile = FSProjectDAOImpl.assembleMetaFile(projectName); + FileOutputStream out = null; + try { + out = new FileOutputStream(metaFile); + properties.store(out, ""); + } finally { + if (out != null) { + out.close(); + } + } } /* @@ -1312,23 +1340,28 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { */ @Override public String getOwner(final String projectName) { - final File metaFile = FSProjectDAOImpl.assembleMetaFile(projectName); - final Properties properties = new Properties(); - InputStream inputStream = null; try { - inputStream = new FileInputStream(metaFile); - properties.load(inputStream); - return properties.getProperty("owner"); + final Properties properties = FSProjectDAOImpl.loadPropertiesFile(projectName); + return properties.getProperty(FSProjectDAOImpl.PROPERTY_KEY_OWNER); + } catch (final IOException ex) { + FSProjectDAOImpl.LOG.warn("Could not open meta file.", ex); + } + + return "N/A"; + } + + /* + * (non-Javadoc) + * + * @see kieker.webgui.persistence.IProjectDAO#getLastUser(java.lang.String) + */ + @Override + public String getLastUser(final String projectName) { + try { + final Properties properties = FSProjectDAOImpl.loadPropertiesFile(projectName); + return properties.getProperty(FSProjectDAOImpl.PROPERTY_KEY_LAST_USER); } catch (final IOException ex) { FSProjectDAOImpl.LOG.warn("Could not open meta file.", ex); - } finally { - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (final IOException ex) { - FSProjectDAOImpl.LOG.warn("Could not open meta file.", ex); - } } return "N/A"; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java index 217e22bcb64376bc4952386f4b8f629c2bccd4e4..0a42a4b6e693272d74a2e5408465c88a84f6fa1f 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java @@ -141,7 +141,10 @@ public interface IProjectService { * @param timeStamp * The time stamp which has to be compared with the "real" time stamp of the project. * @param overwriteNewerProject - * Determines whether a newer project file will be overwritten without further warning or not- + * Determines whether a newer project file will be overwritten without further warning or not. + * @param username + * The name of the user who saves the project. + * * @throws ProjectNotExistingException * If a project with the given name does not exist. * @throws IOException @@ -150,8 +153,8 @@ public interface IProjectService { * If the project on the file system is newer and the overwriteNewerProject-flag has not been set. */ @PreAuthorize("hasAnyRole('User', 'Administrator')") - public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject) throws - ProjectNotExistingException, IOException, NewerProjectException; + public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject, + final String username) throws ProjectNotExistingException, IOException, NewerProjectException; /** * Delivers the current time stamp of the given project. @@ -166,7 +169,7 @@ public interface IProjectService { public long getCurrTimeStamp(final String projectName) throws ProjectNotExistingException; /** - * Delivers the owner of the given project or a substituion if the meta data are corrupt or missing. + * Delivers the owner of the given project or a substituion if the meta data is corrupt or missing. * * @param projectName * The name of the project whose owner should be delivered. @@ -177,6 +180,20 @@ public interface IProjectService { @PreAuthorize("isAuthenticated()") public String getOwner(final String projectName) throws ProjectNotExistingException; + /** + * Delivers the last user of the given project or a substituion if the meta data is corrupt or missing. + * + * @param projectName + * The name of the project whose last user should be delivered. + * + * @return The last user of the project. + * + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + */ + @PreAuthorize("isAuthenticated()") + public String getLastUser(final String projectName) throws ProjectNotExistingException; + /** * This method tries to upload a dependency to the given project. An existing version of the library will be overwritten. * diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java index 883644aee5dea81c397461fede761d9ed8785c21..2d44ff711a4841261c160b94e317543ac60ba04c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java @@ -139,15 +139,15 @@ public final class ProjectServiceImpl implements IProjectService { /* * (non-Javadoc) * - * @see kieker.webgui.service.IProjectService#saveProject(java.lang.String, kieker.analysis.model.analysisMetaModel.MIProject, long, boolean) + * @see kieker.webgui.service.IProjectService#saveProject(java.lang.String, kieker.analysis.model.analysisMetaModel.MIProject, long, boolean, String) */ @Override - public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject) throws - ProjectNotExistingException, IOException, NewerProjectException { + public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject, + final String username) throws ProjectNotExistingException, IOException, NewerProjectException { final Object projectLock = this.getLock(projectName, this.fileSystemLocks); synchronized (projectLock) { - this.projectDAO.saveProject(projectName, project, timeStamp, overwriteNewerProject); + this.projectDAO.saveProject(projectName, project, timeStamp, overwriteNewerProject, username); } } @@ -388,6 +388,20 @@ public final class ProjectServiceImpl implements IProjectService { } } + /* + * (non-Javadoc) + * + * @see kieker.webgui.service.IProjectService#getLastUser(java.lang.String) + */ + @Override + public String getLastUser(final String projectName) throws ProjectNotExistingException { + final Object projectLock = this.getLock(projectName, this.fileSystemLocks); + + synchronized (projectLock) { + return this.projectDAO.getLastUser(projectName); + } + } + @Override public void importProject(final String projectName, final String username, final UploadedFile file) throws ProjectAlreadyExistingException, IOException { final Object projectLock = this.getLock(projectName, this.fileSystemLocks); 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 ebeda1bd736f757e76ac115fd04f1958b88b3f4a..ea26d976be07d815c110732b4dedb8994924c940 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 @@ -226,10 +226,11 @@ public final class ProjectsBean { } /** - * Delivers the owner of the given project or a substituion if the meta data are corrupt or missing. + * Delivers the owner of the given project or a substitution if the meta data is corrupt or missing. * * @param project * The name of the project whose owner should be delivered. + * * @return The owner (creator) of the project. */ public String getOwner(final String project) { @@ -242,6 +243,25 @@ public final class ProjectsBean { } } + /** + * Delivers the last user of the given project or a substitution if the meta data is corrupt or missing. More precisely: It will be the user who saves the + * project the last time. + * + * @param project + * The name of the project whose last user should be delivered. + * + * @return The last user of the project. + */ + public String getLastUser(final String project) { + try { + return this.projectService.getLastUser(project); + } catch (final ProjectNotExistingException ex) { + ProjectsBean.LOG.info("A project with the given name does not exist.", ex); + // We can assume that something went wrong + return "N/A"; + } + } + /** * This method delivers all available projects as a list of string. The list itself is just a copy and can be modified as will. Keep in mind that this means also * that every call to this method will create a new copy. diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java index 2030acbf47aa60f8b14b7fd560abf967ab03767c..9e1becf2e39cef97a8fd8ddf9e364a21d2b1778c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java @@ -313,7 +313,7 @@ public final class CurrentAnalysisEditorBean { */ public synchronized void saveProject(final boolean overwriteNewerProject) { try { - this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); + this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject, this.userBean.getUsername()); GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); // Update the time stamp! this.resetTimeStamp(); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java index 019217a3946bea34009d9d312f9e1bea269a9e6d..5e63f81b5c82cc49737d55348d3f6af6497bad82 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java @@ -50,6 +50,7 @@ import kieker.webgui.domain.RepositoryContainer; import kieker.webgui.service.IProjectService; import kieker.webgui.web.beans.application.GlobalPropertiesBean; import kieker.webgui.web.beans.application.ProjectsBean; +import kieker.webgui.web.beans.session.UserBean; import org.primefaces.component.dashboard.Dashboard; import org.primefaces.component.panel.Panel; @@ -90,6 +91,8 @@ public final class CurrentCockpitEditorBean { private ProjectsBean projectsBean; @Autowired private GlobalPropertiesBean globalPropertiesBean; + @Autowired + private UserBean userBean; private final Registry<MIDisplayConnector> connectors = new Registry<MIDisplayConnector>(); private MIDisplayConnector selectedNode = null; @@ -284,7 +287,7 @@ public final class CurrentCockpitEditorBean { */ public synchronized void saveProject(final boolean overwriteNewerProject) { try { - this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); + this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject, this.userBean.getUsername()); GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); // Update the time stamp! this.resetTimeStamp(); diff --git a/Kieker.WebGUI/src/main/resources/kieker-1.7-SNAPSHOT_emf.jar b/Kieker.WebGUI/src/main/resources/kieker-1.7-SNAPSHOT_emf.jar index 3a451b894e1b5e2dd4ec3423a638bea57a009503..bc66beb54f9812369b8fd5a9f79184ad6e687efe 100644 Binary files a/Kieker.WebGUI/src/main/resources/kieker-1.7-SNAPSHOT_emf.jar and b/Kieker.WebGUI/src/main/resources/kieker-1.7-SNAPSHOT_emf.jar differ diff --git a/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml b/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml index cf321bc2e0a872d26532560e2e7980ef07f6862b..97d97a2aaad7fca64a3cbe636027bd7c0543a0ee 100644 --- a/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml +++ b/Kieker.WebGUI/src/main/webapp/pages/ProjectOverviewPage.xhtml @@ -87,7 +87,7 @@ </p:column> <p:column headerText="#{localizedProjectOverviewMessages.lastEditor}" style="text-align: center"> - <h:outputText value="N/A" /> + <h:outputText value="#{projectsBean.getLastUser(project)}" /> </p:column> </p:dataTable>