[jboss-svn-commits] JBL Code SVN: r9456 - labs/jbosslabs/trunk/portal-extensions/forge-portlets/src/java/org/jboss/forge/projects/info.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 12 15:24:10 EST 2007
Author: wrzep
Date: 2007-02-12 15:24:10 -0500 (Mon, 12 Feb 2007)
New Revision: 9456
Modified:
labs/jbosslabs/trunk/portal-extensions/forge-portlets/src/java/org/jboss/forge/projects/info/ProjectInfoEditBean.java
Log:
JBLAB-780
Rewriting edit to 1) improve usability, 2) make it less dependent on Project class as it is not thread-safe.
Pawel
Modified: labs/jbosslabs/trunk/portal-extensions/forge-portlets/src/java/org/jboss/forge/projects/info/ProjectInfoEditBean.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-portlets/src/java/org/jboss/forge/projects/info/ProjectInfoEditBean.java 2007-02-12 20:22:18 UTC (rev 9455)
+++ labs/jbosslabs/trunk/portal-extensions/forge-portlets/src/java/org/jboss/forge/projects/info/ProjectInfoEditBean.java 2007-02-12 20:24:10 UTC (rev 9456)
@@ -22,6 +22,7 @@
package org.jboss.forge.projects.info;
import java.util.ArrayList;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -52,295 +53,252 @@
private Project project;
private ProjectsService projectsService;
- private String newRepoURL;
- private RepoType newRepoType = ProjectInfoConstants.DEFAULT_REPO_TYPE;
+ private String issueTrackerURL;
+ private IssueTrackerType issueTrackerType =
+ ProjectInfoConstants.DEFAULT_ISSUE_TRACKER_TYPE;
- private String newRepoMonitorURL;
- private MonitorType newRepoMonitorType =
+ private RepoType repoType;
+ private String commiterRepoURL;
+ private String anonRepoURL;
+
+ private String repoMonitorURL;
+ private MonitorType repoMonitorType =
ProjectInfoConstants.DEFAULT_REPO_MONITOR_TYPE;
- private String newIssueTrackerURL;
- private IssueTrackerType newIssueTrackerType =
- ProjectInfoConstants.DEFAULT_ISSUE_TRACKER_TYPE;
+ private String trainingURL;
+ private String supportURL;
+ private String devForumURL;
+ private String userForumURL;
+
+ private List<Documentation> documentation;
+
+ /************/
+
private String newBuildResultsURL;
private BuildType newBuildResultsType =
ProjectInfoConstants.DEFAULT_BUILD_TYPE;
- private String newSupportServiceURL;
- private SupportType newSupportServiceType =
- ProjectInfoConstants.DEFAULT_SUPPORT_TYPE;
-
- private String newForumURL;
- private ForumType newForumType = ProjectInfoConstants.DEFAULT_FORUM_TYPE;
-
- private String newDocumentationURL;
- private DocumentationType newDocumentationType =
- ProjectInfoConstants.DEFAULT_DOCUMENTATION_TYPE;
-
public ProjectInfoEditBean() {
projectsService = ProjectsHelper.getProjectsService();
project = projectsService.getProjectByName(FacesTools.getSelectedProjectId());
- }
-
- /* Business methods */
-
- public String applyChanges() {
- projectsService.persistProject(project);
+ IssueTracker it = (IssueTracker) getFirst(project.getIssueTrackers());
+ if (it != null) {
+ issueTrackerURL = it.getValue();
+ issueTrackerType = it.getType();
+ }
- FacesTools.addMessage("Your changes have been saved");
+ RepoMonitor rm = (RepoMonitor) getFirst(project.getRepoMonitors());
+ if (rm != null) {
+ repoMonitorURL = rm.getValue();
+ repoMonitorType = rm.getType();
+ }
- return ProjectInfoConstants.APPLY_ACTION;
- }
-
- public String addRepo() {
-
- if ((newRepoURL == null) || (newRepoURL == "")) {
- FacesTools.addMessage("Please provide repository URL.");
- return ProjectInfoConstants.ERR_ACTION;
+ Map<RepoType,String> repoMap = getRepoMap(project);
+ if ((repoMap.containsKey(RepoType.CVS)) || (repoMap.containsKey(RepoType.ANONCVS))) {
+ repoType = RepoType.CVS;
+ commiterRepoURL = repoMap.get(RepoType.CVS);
+ anonRepoURL = repoMap.get(RepoType.ANONCVS);
+ } else {
+ repoType = RepoType.SVN;
+ commiterRepoURL = repoMap.get(RepoType.SVN);
+ anonRepoURL = repoMap.get(RepoType.ANONSVN);
}
- List<Repository> repoList = project.getRepositories();
+ Map<SupportType,String> supportMap = getSupportMap(project);
+ supportURL = supportMap.get(SupportType.SUPPORT);
+ trainingURL = supportMap.get(SupportType.TRAINING);
- Repository repo = new Repository();
- repo.setType(newRepoType);
- repo.setValue(newRepoURL);
+ Map<ForumType,String> forumsMap = getForumsMap(project);
+ devForumURL = forumsMap.get(ForumType.DEV);
+ userForumURL = forumsMap.get(ForumType.USER);
- repoList.add(repo);
- newRepoURL = "";
- newRepoType = ProjectInfoConstants.DEFAULT_REPO_TYPE;
-
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
- }
+ documentation = getDocumentation(project);
+ }
- public String delRepo() {
+ /* Business methods */
+
+ private List<Documentation> getDocumentation(Project prj) {
- String delRepoId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_REPO_PARAM);
+ Map<DocumentationType,Documentation> docMap = getDocumentationMap(prj);
+ List<Documentation> ret = new ArrayList<Documentation>();
- List<Repository> repositories = project.getRepositories();
- for (Repository repo : repositories) {
+ for (DocumentationType dt : DocumentationType.values()) {
+ System.out.println("ADD " + dt);
- if (delRepoId.equals(repo.getValue())) {
- repositories.remove(repo);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ Documentation d = docMap.get(dt);
+ if (d != null) {
+ ret.add(d);
+ } else {
+ d = new Documentation();
+ d.setType(dt);
+ ret.add(d);
}
+
}
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
+ return ret;
}
-
- public String addRepoMonitor() {
+
+ private Map<DocumentationType, Documentation> getDocumentationMap(Project prj) {
+
+ Map<DocumentationType, Documentation> map =
+ new EnumMap<DocumentationType, Documentation>(DocumentationType.class);
- if ((newRepoMonitorURL == null) || (newRepoMonitorURL == "")) {
- FacesTools.addMessage("Please provide repository monitor URL.");
- return ProjectInfoConstants.ERR_ACTION;
+ List<Documentation> docList = project.getDocumentation();
+ for (Documentation d : docList) {
+ map.put(d.getType(), d);
}
- RepoMonitor rm = new RepoMonitor();
- rm.setType(newRepoMonitorType);
- rm.setValue(newRepoMonitorURL);
-
- project.getRepoMonitors().add(rm);
- newRepoMonitorURL = "";
- newRepoMonitorType = ProjectInfoConstants.DEFAULT_REPO_MONITOR_TYPE;
-
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ return map;
}
-
- public String delRepoMonitor() {
+
+ private static Map<RepoType, String> getRepoMap(Project project) {
- String delRepoMonitorId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_REPO_MONITOR_PARAM);
+ Map<RepoType, String> map = new EnumMap<RepoType,String>(RepoType.class);
- List<RepoMonitor> repoMonitors = project.getRepoMonitors();
- for (RepoMonitor rm : repoMonitors) {
-
- if (delRepoMonitorId.equals(rm.getValue())) {
- repoMonitors.remove(rm);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
- }
+ List<Repository> repoList = project.getRepositories();
+ for (Repository repository : repoList) {
+ map.put(repository.getType(), repository.getValue());
}
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
+ return map;
}
-
- public String addIssueTracker() {
+
+ private Map<SupportType, String> getSupportMap(Project project2) {
+
+ Map<SupportType, String> map = new EnumMap<SupportType,String>(SupportType.class);
- if ((newIssueTrackerURL == null) || (newIssueTrackerURL == "")) {
- FacesTools.addMessage("Please provide issue tracker URL.");
- return ProjectInfoConstants.ERR_ACTION;
+ List<SupportService> supportList = project.getSupportServices();
+ for (SupportService s : supportList) {
+ map.put(s.getType(), s.getValue());
}
- IssueTracker rm = new IssueTracker();
- rm.setType(newIssueTrackerType);
- rm.setValue(newIssueTrackerURL);
-
- project.getIssueTrackers().add(rm);
- newIssueTrackerURL = "";
- newIssueTrackerType = ProjectInfoConstants.DEFAULT_ISSUE_TRACKER_TYPE;
-
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ return map;
}
- public String delIssueTracker() {
+ private Map<ForumType, String> getForumsMap(Project project2) {
+
+ Map<ForumType, String> map = new EnumMap<ForumType,String>(ForumType.class);
- String delIssueTrackerId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_ISSUE_TRACKER_PARAM);
-
- List<IssueTracker> repoMonitors = project.getIssueTrackers();
- for (IssueTracker rm : repoMonitors) {
-
- if (delIssueTrackerId.equals(rm.getValue())) {
- repoMonitors.remove(rm);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
- }
+ List<Forum> supportList = project.getForums();
+ for (Forum f : supportList) {
+ map.put(f.getType(), f.getValue());
}
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
+ return map;
}
- public String addBuildResults() {
+ public String applyChanges() {
- if ((newBuildResultsURL == null) || (newBuildResultsURL == "")) {
- FacesTools.addMessage("Please provide Continuous Integration Tool URL.");
- return ProjectInfoConstants.ERR_ACTION;
- }
+ setIssueTracker();
+ setRepoMonitor();
+ setRepositories();
+ setSupport();
+ setForums();
+ //setDocumentation();
- BuildResult rm = new BuildResult();
- rm.setType(newBuildResultsType);
- rm.setValue(newBuildResultsURL);
+ projectsService.persistProject(project);
- project.getBuildResults().add(rm);
- newBuildResultsURL = "";
- newBuildResultsType = ProjectInfoConstants.DEFAULT_BUILD_TYPE;
+ FacesTools.addMessage("Your changes have been saved");
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ return ProjectInfoConstants.APPLY_ACTION;
}
-
- public String delBuildResults() {
+
+ // TODO methods below will change
+ // after Rysiek finishes threadsafe project.xml impl
+ private void setIssueTracker() {
- String delBuildResultId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_BUILD_RESULTS_PARAM);
+ List<IssueTracker> list = project.getIssueTrackers();
- List<BuildResult> buildResults = project.getBuildResults();
- for (BuildResult br : buildResults) {
+ if ((issueTrackerURL != null) && (issueTrackerURL.length() > 0)) {
- if (delBuildResultId.equals(br.getValue())) {
- buildResults.remove(br);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ IssueTracker it = new IssueTracker();
+ it.setValue(issueTrackerURL);
+ it.setType(issueTrackerType);
+
+ if (list.size() > 0) {
+ list.set(0, it);
+ } else {
+ list.add(it);
}
+ } else {
+ list = new ArrayList<IssueTracker>();
}
-
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
}
- public String addSupportService() {
+ private void setRepoMonitor() {
- if ((newSupportServiceURL == null) || (newSupportServiceURL == "")) {
- FacesTools.addMessage("Please provide issue tracker URL.");
- return ProjectInfoConstants.ERR_ACTION;
- }
+ List<RepoMonitor> list = project.getRepoMonitors();
- SupportService support = new SupportService();
- support.setType(newSupportServiceType);
- support.setValue(newSupportServiceURL);
-
- project.getSupportServices().add(support);
- newSupportServiceURL = "";
- newSupportServiceType = ProjectInfoConstants.DEFAULT_SUPPORT_TYPE;
-
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
- }
-
- public String delSupportService() {
-
- String delSupportServiceId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_ISSUE_TRACKER_PARAM);
-
- List<SupportService> repoMonitors = project.getSupportServices();
- for (SupportService rm : repoMonitors) {
+ if ((repoMonitorURL != null) && (repoMonitorURL.length() > 0)) {
- if (delSupportServiceId.equals(rm.getValue())) {
- repoMonitors.remove(rm);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ RepoMonitor rm = new RepoMonitor();
+ rm.setValue(repoMonitorURL);
+ rm.setType(repoMonitorType);
+
+ if (list.size() > 0) {
+ list.set(0, rm);
+ } else {
+ list.add(rm);
}
+ } else {
+ list = new ArrayList<RepoMonitor>();
}
-
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
}
- public String addForum() {
+ private void setRepositories() {
- if ((newForumURL == null) || (newForumURL == "")) {
- FacesTools.addMessage("Please provide forum URL.");
- return ProjectInfoConstants.ERR_ACTION;
- }
-
- Forum forum = new Forum();
- forum.setType(newForumType);
- forum.setValue(newForumURL);
-
- project.getForums().add(forum);
- newForumURL = "";
- newForumType = ProjectInfoConstants.DEFAULT_FORUM_TYPE;
-
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
+ Map<RepoType,String> repoMap = getRepoMap(project);
+ repoMap.put(repoType, commiterRepoURL); // put even if null (= delete)
+
+ RepoType key = (repoType == RepoType.SVN) ? RepoType.ANONSVN : RepoType.ANONCVS;
+ repoMap.put(key, anonRepoURL);
}
- public String delForum() {
+ private void setSupport() {
- String delForumId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_FORUM_PARAM);
-
- List<Forum> repoMonitors = project.getForums();
- for (Forum rm : repoMonitors) {
-
- if (delForumId.equals(rm.getValue())) {
- repoMonitors.remove(rm);
- return ProjectInfoConstants.ADD_REMOVE_ACTION;
- }
- }
-
- FacesTools.addMessage("Unknown error");
- return ProjectInfoConstants.ERR_ACTION;
+ Map<SupportType,String> supportMap = getSupportMap(project);
+ supportMap.put(SupportType.SUPPORT, supportURL);
+ supportMap.put(SupportType.TRAINING, trainingURL);
}
- public String addDocumentation() {
+ private void setForums() {
+ Map<ForumType,String> forumsMap = getForumsMap(project);
+ forumsMap.put(ForumType.DEV, devForumURL);
+ forumsMap.put(ForumType.USER, userForumURL);
+ }
+
+ public String addBuildResults() {
- if ((newDocumentationURL == null) || (newDocumentationURL == "")) {
- FacesTools.addMessage("Please provide documentation URL.");
+ if ((newBuildResultsURL == null) || (newBuildResultsURL == "")) {
+ FacesTools.addMessage("Please provide Continuous Integration Tool URL.");
return ProjectInfoConstants.ERR_ACTION;
}
- Documentation doc = new Documentation();
- doc.setType(newDocumentationType);
- doc.setValue(newDocumentationURL);
+ BuildResult rm = new BuildResult();
+ rm.setType(newBuildResultsType);
+ rm.setValue(newBuildResultsURL);
- project.getDocumentation().add(doc);
- newDocumentationURL = "";
- newDocumentationType = ProjectInfoConstants.DEFAULT_DOCUMENTATION_TYPE;
+ project.getBuildResults().add(rm);
+ newBuildResultsURL = "";
+ newBuildResultsType = ProjectInfoConstants.DEFAULT_BUILD_TYPE;
return ProjectInfoConstants.ADD_REMOVE_ACTION;
}
- public String delDocumentation() {
+ public String delBuildResults() {
- String delDocumentationId = FacesTools.getRequestParameter(
- ProjectInfoConstants.DEL_DOC_PARAM);
+ String delBuildResultId = FacesTools.getRequestParameter(
+ ProjectInfoConstants.DEL_BUILD_RESULTS_PARAM);
- List<Documentation> docList = project.getDocumentation();
- for (Documentation d : docList) {
+ List<BuildResult> buildResults = project.getBuildResults();
+ for (BuildResult br : buildResults) {
- if (delDocumentationId.equals(d.getValue())) {
- docList.remove(d);
+ if (delBuildResultId.equals(br.getValue())) {
+ buildResults.remove(br);
return ProjectInfoConstants.ADD_REMOVE_ACTION;
}
}
@@ -348,6 +306,7 @@
FacesTools.addMessage("Unknown error");
return ProjectInfoConstants.ERR_ACTION;
}
+
/* Getters and setters */
@@ -359,117 +318,117 @@
this.project = project;
}
- public RepoType getNewRepoType() {
- return newRepoType;
+ public IssueTrackerType getIssueTrackerType() {
+ return issueTrackerType;
}
- public void setNewRepoType(RepoType newRepoType) {
- this.newRepoType = newRepoType;
+ public void setIssueTrackerType(IssueTrackerType issueTrackerType) {
+ this.issueTrackerType = issueTrackerType;
}
- public String getNewRepoURL() {
- return newRepoURL;
+ public String getIssueTrackerURL() {
+ return issueTrackerURL;
}
- public MonitorType getNewRepoMonitorType() {
- return newRepoMonitorType;
+ public void setIssueTrackerURL(String issueTrackerURL) {
+ this.issueTrackerURL = issueTrackerURL;
}
+
+ public RepoType getRepoType() {
+ return repoType;
+ }
- public void setNewRepoMonitorType(MonitorType newRepoMonitorType) {
- this.newRepoMonitorType = newRepoMonitorType;
+ public void setRepoType(RepoType repoType) {
+ this.repoType = repoType;
}
+
+ public String getAnonRepoURL() {
+ return anonRepoURL;
+ }
- public String getNewRepoMonitorURL() {
- return newRepoMonitorURL;
+ public void setAnonRepoURL(String anonRepoURL) {
+ this.anonRepoURL = anonRepoURL;
}
- public void setNewRepoMonitorURL(String newRepoMonitorURL) {
- this.newRepoMonitorURL = newRepoMonitorURL;
+ public String getCommiterRepoURL() {
+ return commiterRepoURL;
}
- public void setNewRepoURL(String newRepoURL) {
- this.newRepoURL = newRepoURL;
+ public void setCommiterRepoURL(String commiterRepoURL) {
+ this.commiterRepoURL = commiterRepoURL;
}
- public String getNewIssueTrackerURL() {
- return newIssueTrackerURL;
+ public MonitorType getRepoMonitorType() {
+ return repoMonitorType;
}
- public void setNewIssueTrackerURL(String newIssueTrackerURL) {
- this.newIssueTrackerURL = newIssueTrackerURL;
+ public void setRepoMonitorType(MonitorType repoMonitorType) {
+ this.repoMonitorType = repoMonitorType;
}
- public IssueTrackerType getNewIssueTrackerType() {
- return newIssueTrackerType;
+ public String getRepoMonitorURL() {
+ return repoMonitorURL;
}
- public void setNewIssueTrackerType(IssueTrackerType newIssueTrakcerType) {
- this.newIssueTrackerType = newIssueTrakcerType;
+ public void setRepoMonitorURL(String repoMonitorURL) {
+ this.repoMonitorURL = repoMonitorURL;
}
+
+ public String getSupportURL() {
+ return supportURL;
+ }
- public String getNewBuildResultsURL() {
- return newBuildResultsURL;
+ public void setSupportURL(String supportURL) {
+ this.supportURL = supportURL;
}
- public void setNewBuildResultsURL(String newBuildResultsURL) {
- this.newBuildResultsURL = newBuildResultsURL;
+ public String getTrainingURL() {
+ return trainingURL;
}
- public BuildType getNewBuildResultsType() {
- return newBuildResultsType;
+ public void setTrainingURL(String trainingURL) {
+ this.trainingURL = trainingURL;
}
- public void setNewBuildResultsType(BuildType newBuildType) {
- this.newBuildResultsType = newBuildType;
+ public String getDevForumURL() {
+ return devForumURL;
}
- public SupportType getNewSupportServiceType() {
- return newSupportServiceType;
+ public void setDevForumURL(String devForumURL) {
+ this.devForumURL = devForumURL;
}
- public void setNewSupportServiceType(SupportType newSupportServiceType) {
- this.newSupportServiceType = newSupportServiceType;
+ public String getUserForumURL() {
+ return userForumURL;
}
-
- public String getNewSupportServiceURL() {
- return newSupportServiceURL;
+
+ public void setUserForumURL(String userForumURL) {
+ this.userForumURL = userForumURL;
}
-
- public void setNewSupportServiceURL(String newSupportServiceURL) {
- this.newSupportServiceURL = newSupportServiceURL;
- }
- public ForumType getNewForumType() {
- return newForumType;
+ public List<Documentation> getDocumentation() {
+ return documentation;
}
- public void setNewForumType(ForumType newForumType) {
- this.newForumType = newForumType;
+ public void setDocumentation(List<Documentation> documentation) {
+ this.documentation = documentation;
}
- public String getNewForumURL() {
- return newForumURL;
+ public String getNewBuildResultsURL() {
+ return newBuildResultsURL;
}
- public void setNewForumURL(String newForumURL) {
- this.newForumURL = newForumURL;
- }
-
- public DocumentationType getNewDocumentationType() {
- return newDocumentationType;
+ public void setNewBuildResultsURL(String newBuildResultsURL) {
+ this.newBuildResultsURL = newBuildResultsURL;
}
- public void setNewDocumentationType(DocumentationType newDocumentationType) {
- this.newDocumentationType = newDocumentationType;
+ public BuildType getNewBuildResultsType() {
+ return newBuildResultsType;
}
- public String getNewDocumentationURL() {
- return newDocumentationURL;
+ public void setNewBuildResultsType(BuildType newBuildType) {
+ this.newBuildResultsType = newBuildType;
}
-
- public void setNewDocumentationURL(String newDocumentationURL) {
- this.newDocumentationURL = newDocumentationURL;
- }
/* Helper methods */
@@ -490,6 +449,15 @@
}
return map;
}
+
+ public Map<String,RepoType> getGeneralRepoTypes() {
+
+ Map<String,RepoType> map = new HashMap<String,RepoType>();
+ map.put("svn", RepoType.SVN);
+ map.put("cvs", RepoType.CVS);
+
+ return map;
+ }
public Map<String,MonitorType> getRepoMonitorTypes() {
@@ -544,4 +512,12 @@
}
return typesMap;
}
+
+ private static Object getFirst(List list) {
+
+ if ((list == null) || (list.size() == 0)) {
+ return null;
+ }
+ return list.get(0);
+ }
}
More information about the jboss-svn-commits
mailing list