All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.confluence.actions.server.RegistrationAction Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.confluence.actions.server;

import static com.greenpepper.confluence.utils.HtmlUtils.stringSetToTextArea;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringEscapeUtils;

import com.atlassian.user.User;
import com.greenpepper.confluence.velocity.ConfluenceGreenPepper;
import com.greenpepper.server.GreenPepperServerException;
import com.greenpepper.server.domain.ClasspathSet;
import com.greenpepper.server.domain.Project;
import com.greenpepper.server.domain.Repository;
import com.greenpepper.server.domain.RepositoryType;
import com.greenpepper.server.domain.Runner;
import com.greenpepper.server.domain.SystemUnderTest;
import com.greenpepper.server.domain.component.ContentType;
import com.greenpepper.util.StringUtil;

/**
 * Action for the GreenPepper Server Properties.
 * 

* Copyright (c) 2006 Pyxis technologies inc. All Rights Reserved. * * @author oaouattara * @version $Id: $Id */ @SuppressWarnings("serial") public class RegistrationAction extends GreenPepperServerAction { private Boolean readonly = Boolean.FALSE; private List runners; private LinkedList projects; private List systemUnderTests; private SystemUnderTest selectedSut; private String selectedSutName; private String repositoryName; private String newProjectName; private String username; private String pwd; private String baseUrl; private String newSutName = ""; private String newFixtureFactory; private String newFixtureFactoryArgs; private String newRunnerName = ""; private Boolean selected = Boolean.FALSE; private String newProjectDependencyDescriptor; private String sutClasspath; private String fixtureClasspath; private boolean addMode; private boolean editMode; private boolean editPropertiesMode; private boolean editClasspathsMode; private boolean editFixturesMode; /** *

doGetRegistration.

* * @return a {@link java.lang.String} object. */ public String doGetRegistration() { if (!isServerReady()) { addActionError(ConfluenceGreenPepper.SERVER_NOCONFIGURATION); readonly = true; editMode = false; addMode = false; return SUCCESS; } try { final User activeUser = getRemoteUser(); if (activeUser == null) { addActionError(ConfluenceGreenPepper.ANONYMOUS_ACCESS_DENIED); readonly = true; editMode = false; addMode = false; return SUCCESS; } if (!gpUtil.getGreenPepperUserGroup().hasMembership(activeUser)) { addActionError(ConfluenceGreenPepper.USER_NOTMEMBEROF_GREENPEPPERUSERS_GROUP); readonly = true; editMode = false; addMode = false; return SUCCESS; } if(StringUtil.isEmpty(projectName)) projectName = getRegisteredRepository().getProject().getName(); if(StringUtil.isEmpty(repositoryName)) repositoryName = getRegisteredRepository().getName(); if(StringUtil.isEmpty(username)) username = getRegisteredRepository().getUsername(); if(StringUtil.isEmpty(pwd)) pwd = getRegisteredRepository().getPassword(); checkRepositoryBaseUrl(); return doGetSystemUnderTests(); } catch(GreenPepperServerException e) { if(editMode && StringUtil.isEmpty(projectName) && !isWithNewProject()) projectName = getProjects().iterator().next().getName(); readonly = true; } return editMode ? doGetSystemUnderTests(): SUCCESS; } /** *

doRegister.

* * @return a {@link java.lang.String} object. */ public String doRegister() { try { if (getUsername() != null) { gpUtil.verifyCredentials(getUsername(), getPwd()); } String uid = gpUtil.getSettingsManager().getGlobalSettings().getSiteTitle() + "-" + getSpaceKey(); registeredRepository = Repository.newInstance(uid); registeredRepository.setProject(getProjectForRegistration()); registeredRepository.setType(RepositoryType.newInstance("CONFLUENCE")); registeredRepository.setName(repositoryName); registeredRepository.setContentType(ContentType.TEST); registeredRepository.setBaseUrl(getBaseUrl()); registeredRepository.setBaseRepositoryUrl(repositoryBaseUrl()); registeredRepository.setBaseTestUrl(newTestUrl()); registeredRepository.setUsername(getUsername()); registeredRepository.setPassword(getPwd()); registeredRepository.setMaxUsers(gpUtil.getNumberOfUserForGreenPepperUserGroup()); getService().registerRepository(registeredRepository); projectName = isWithNewProject() ? newProjectName : projectName; } catch (GreenPepperServerException e) { addActionError(e.getId()); editMode = true; readonly = true; } return doGetRegistration(); } /** *

doUpdateRegistration.

* * @return a {@link java.lang.String} object. */ public String doUpdateRegistration() { try { if (getUsername() != null) { gpUtil.verifyCredentials(getUsername(), getPwd()); } String uid = gpUtil.getSettingsManager().getGlobalSettings().getSiteTitle() + "-" + getSpaceKey(); Repository newRepository = Repository.newInstance(uid); newRepository.setProject(getProjectForRegistration()); newRepository.setType(RepositoryType.newInstance("CONFLUENCE")); newRepository.setName(repositoryName); newRepository.setContentType(ContentType.TEST); newRepository.setBaseUrl(getBaseUrl()); newRepository.setBaseRepositoryUrl(repositoryBaseUrl()); newRepository.setBaseTestUrl(newTestUrl()); newRepository.setUsername(getUsername()); newRepository.setPassword(getPwd()); newRepository.setMaxUsers(gpUtil.getNumberOfUserForGreenPepperUserGroup()); getService().updateRepositoryRegistration(newRepository); projectName = isWithNewProject() ? newProjectName : projectName; } catch (GreenPepperServerException e) { addActionError(e.getId()); editMode = true; readonly = true; } return doGetRegistration(); } /** *

doGetSystemUnderTests.

* * @return a {@link java.lang.String} object. */ public String doGetSystemUnderTests() { try { runners = getService().getAllRunners(); if(runners.isEmpty()) throw new GreenPepperServerException("greenpepper.suts.norunners", "No runners."); systemUnderTests = getService().getSystemUnderTestsOfProject(projectName); if(selectedSut == null) { for(SystemUnderTest sut : systemUnderTests) { if(sut.getName().equals(selectedSutName)) { selectedSut = sut; return SUCCESS; } if(sut.isDefault()) { selectedSut = sut; } } if(selectedSut != null) selectedSutName = selectedSut.getName(); } } catch (GreenPepperServerException e) { addActionError(e.getId()); addMode = false; } return SUCCESS; } /** *

doAddSystemUnderTest.

* * @return a {@link java.lang.String} object. */ public String doAddSystemUnderTest() { try { selectedSut = SystemUnderTest.newInstance(newSutName); selectedSut.setProject(Project.newInstance(projectName)); selectedSut.setFixtureFactory(newFixtureFactory); selectedSut.setFixtureFactoryArgs(newFixtureFactoryArgs); selectedSut.setIsDefault(selected); selectedSut.setRunner(Runner.newInstance(newRunnerName)); selectedSut.setProjectDependencyDescriptor(newProjectDependencyDescriptor); getService().createSystemUnderTest(selectedSut, getHomeRepository()); successfullAction(); } catch (GreenPepperServerException e) { addActionError(e.getId()); } return doGetSystemUnderTests(); } /** *

doUpdateSystemUnderTest.

* * @return a {@link java.lang.String} object. */ public String doUpdateSystemUnderTest() { try { SystemUnderTest newSut = SystemUnderTest.newInstance(selectedSutName); newSut.setProject(Project.newInstance(projectName)); newSut = getService().getSystemUnderTest(newSut, getHomeRepository()); newSut.setName(newSutName); newSut.setFixtureFactory(newFixtureFactory); newSut.setFixtureFactoryArgs(newFixtureFactoryArgs); newSut.setRunner(Runner.newInstance(newRunnerName)); newSut.setProjectDependencyDescriptor(newProjectDependencyDescriptor); getService().updateSystemUnderTest(selectedSutName, newSut, getHomeRepository()); successfullAction(); return doGetSystemUnderTests(); } catch (GreenPepperServerException e) { try { runners = getService().getAllRunners(); if(runners.isEmpty()) throw new GreenPepperServerException("greenpepper.suts.norunners", "No runners."); systemUnderTests = getService().getSystemUnderTestsOfProject(projectName); selectedSut = SystemUnderTest.newInstance(selectedSutName); selectedSut.setProject(Project.newInstance(projectName)); selectedSut.setFixtureFactory(newFixtureFactory); selectedSut.setFixtureFactoryArgs(newFixtureFactoryArgs); selectedSut.setRunner(Runner.newInstance(newRunnerName)); selectedSut.setProjectDependencyDescriptor(newProjectDependencyDescriptor); } catch (GreenPepperServerException e1) { addActionError(e.getId()); } addActionError(e.getId()); } return SUCCESS; } /** *

doRemoveSystemUnderTest.

* * @return a {@link java.lang.String} object. */ public String doRemoveSystemUnderTest() { try { selectedSut = SystemUnderTest.newInstance(selectedSutName); selectedSut.setProject(Project.newInstance(projectName)); getService().removeSystemUnderTest(selectedSut, getHomeRepository()); selectedSutName = null; } catch (GreenPepperServerException e) { addActionError(e.getId()); } selectedSut = null; return doGetSystemUnderTests(); } /** *

doEditClasspath.

* * @return a {@link java.lang.String} object. */ public String doEditClasspath() { try { SystemUnderTest selectedSut = SystemUnderTest.newInstance(selectedSutName); selectedSut.setProject(Project.newInstance(projectName)); selectedSut = getService().getSystemUnderTest(selectedSut, getHomeRepository()); selectedSut.setSutClasspaths(ClasspathSet.parse(sutClasspath)); getService().updateSystemUnderTest(selectedSutName, selectedSut, getHomeRepository()); } catch (GreenPepperServerException e) { addActionError(e.getId()); } return doGetSystemUnderTests(); } /** *

getClasspaths.

* * @return a {@link java.util.Set} object. */ public Set getClasspaths() { return selectedSut.getSutClasspaths(); } /** *

getClasspathsAsTextAreaContent.

* * @return a {@link java.lang.String} object. */ public String getClasspathsAsTextAreaContent() { return stringSetToTextArea(getClasspaths()); } /** *

getClasspathTitle.

* * @return a {@link java.lang.String} object. */ public String getClasspathTitle() { return getText("greenpepper.suts.classpath"); } /** *

getFixtureClasspathTitle.

* * @return a {@link java.lang.String} object. */ public String getFixtureClasspathTitle() { return getText("greenpepper.suts.fixture"); } /** *

getFixtureClasspaths.

* * @return a {@link java.util.Set} object. */ public Set getFixtureClasspaths() { return selectedSut.getFixtureClasspaths(); } /** *

getFixtureClasspathsAsTextAreaContent.

* * @return a {@link java.lang.String} object. */ public String getFixtureClasspathsAsTextAreaContent() { return stringSetToTextArea(getFixtureClasspaths()); } /** *

doEditFixture.

* * @return a {@link java.lang.String} object. */ public String doEditFixture() { try { SystemUnderTest selectedSut = SystemUnderTest.newInstance(selectedSutName); selectedSut.setProject(Project.newInstance(projectName)); selectedSut = getService().getSystemUnderTest(selectedSut, getHomeRepository()); selectedSut.setFixtureClasspaths(ClasspathSet.parse(fixtureClasspath)); getService().updateSystemUnderTest(selectedSutName, selectedSut, getHomeRepository()); } catch (GreenPepperServerException e) { addActionError(e.getId()); } return doGetSystemUnderTests(); } /** *

doSetAsDefault.

* * @return a {@link java.lang.String} object. */ public String doSetAsDefault() { try { SystemUnderTest sut = SystemUnderTest.newInstance(selectedSutName); sut.setProject(Project.newInstance(projectName)); getService().setSystemUnderTestAsDefault(sut, getHomeRepository()); } catch (GreenPepperServerException e) { addActionError(e.getId()); } return doGetSystemUnderTests(); } /** {@inheritDoc} */ @Override public LinkedList getProjects() { if(projects != null) return projects; try { projects = new LinkedList(getService().getAllProjects()); projects.addLast(Project.newInstance(projectCreateOption())); projectName = projectName == null ? projects.iterator().next().getName() : projectName; return projects; } catch (GreenPepperServerException e) { addActionError(e.getId()); } return projects; } /** *

Getter for the field selectedSut.

* * @return a {@link com.greenpepper.server.domain.SystemUnderTest} object. */ public SystemUnderTest getSelectedSut() { return selectedSut; } /** *

Getter for the field repositoryName.

* * @return a {@link java.lang.String} object. */ public String getRepositoryName() { return repositoryName; } /** *

Setter for the field repositoryName.

* * @param repositoryName a {@link java.lang.String} object. */ public void setRepositoryName(String repositoryName) { this.repositoryName = repositoryName.trim(); } /** *

getProjectName.

* * @return a {@link java.lang.String} object. */ public String getProjectName() { return projectName; } /** {@inheritDoc} */ public void setProjectName(String projectName) { this.projectName = projectName; } /** *

Getter for the field pwd.

* * @return a {@link java.lang.String} object. */ public String getPwd() { return pwd; } /** *

Setter for the field pwd.

* * @param pwd a {@link java.lang.String} object. */ public void setPwd(String pwd) { this.pwd = StringUtil.toNullIfEmpty(pwd.trim()); } /** *

getEscapedPassword.

* * @return a {@link java.lang.String} object. */ public String getEscapedPassword() { return StringEscapeUtils.escapeHtml(getPwd()); } /** *

Getter for the field username.

* * @return a {@link java.lang.String} object. */ public String getUsername() { return username; } /** *

Setter for the field username.

* * @param username a {@link java.lang.String} object. */ public void setUsername(String username) { this.username = StringUtil.toNullIfEmpty(username.trim()); } /** *

Getter for the field newProjectName.

* * @return a {@link java.lang.String} object. */ public String getNewProjectName() { return newProjectName; } /** *

Setter for the field newProjectName.

* * @param newProjectName a {@link java.lang.String} object. */ public void setNewProjectName(String newProjectName) { this.newProjectName = newProjectName.trim(); } /** *

Getter for the field newSutName.

* * @return a {@link java.lang.String} object. */ public String getNewSutName() { return newSutName; } /** *

Setter for the field newSutName.

* * @param newSutName a {@link java.lang.String} object. */ public void setNewSutName(String newSutName) { this.newSutName = newSutName.trim(); } /** *

Getter for the field newFixtureFactory.

* * @return a {@link java.lang.String} object. */ public String getNewFixtureFactory() { return newFixtureFactory; } /** *

Setter for the field newFixtureFactory.

* * @param fixtureFactory a {@link java.lang.String} object. */ public void setNewFixtureFactory(String fixtureFactory) { this.newFixtureFactory = StringUtil.toNullIfEmpty(fixtureFactory.trim()); } /** *

Getter for the field newFixtureFactoryArgs.

* * @return a {@link java.lang.String} object. */ public String getNewFixtureFactoryArgs() { return newFixtureFactoryArgs; } /** *

Setter for the field newFixtureFactoryArgs.

* * @param fixtureFactoryArgs a {@link java.lang.String} object. */ public void setNewFixtureFactoryArgs(String fixtureFactoryArgs) { this.newFixtureFactoryArgs = StringUtil.toNullIfEmpty(fixtureFactoryArgs.trim()); } /** *

Getter for the field newRunnerName.

* * @return a {@link java.lang.String} object. */ public String getNewRunnerName() { return newRunnerName; } /** *

Setter for the field newRunnerName.

* * @param runnerName a {@link java.lang.String} object. */ public void setNewRunnerName(String runnerName) { this.newRunnerName = runnerName.trim(); } /** *

Getter for the field sutClasspath.

* * @return a {@link java.lang.String} object. */ public String getSutClasspath() { return sutClasspath; } /** *

Setter for the field sutClasspath.

* * @param sutClasspath a {@link java.lang.String} object. */ public void setSutClasspath(String sutClasspath) { this.sutClasspath = sutClasspath.trim(); } /** *

Getter for the field fixtureClasspath.

* * @return a {@link java.lang.String} object. */ public String getFixtureClasspath() { return fixtureClasspath; } /** *

Setter for the field fixtureClasspath.

* * @param fixtureClasspath a {@link java.lang.String} object. */ public void setFixtureClasspath(String fixtureClasspath) { this.fixtureClasspath = fixtureClasspath.trim(); } /** *

Getter for the field newProjectDependencyDescriptor.

* * @return a {@link java.lang.String} object. */ public String getNewProjectDependencyDescriptor() { return newProjectDependencyDescriptor; } /** *

Setter for the field newProjectDependencyDescriptor.

* * @param newProjectDependencyDescriptor a {@link java.lang.String} object. */ public void setNewProjectDependencyDescriptor(String newProjectDependencyDescriptor) { this.newProjectDependencyDescriptor = StringUtil.toNullIfEmpty(newProjectDependencyDescriptor.trim()); } /** *

getDefault.

* * @return a {@link java.lang.Boolean} object. */ public Boolean getDefault() { return selected; } /** *

setDefault.

* * @param selected a {@link java.lang.Boolean} object. */ public void setDefault(Boolean selected) { this.selected = selected; } /** *

Getter for the field runners.

* * @return a {@link java.util.List} object. */ public List getRunners() { return runners; } /** *

Getter for the field selectedSutName.

* * @return a {@link java.lang.String} object. */ public String getSelectedSutName() { return selectedSutName; } /** *

Setter for the field selectedSutName.

* * @param selectedSutName a {@link java.lang.String} object. */ public void setSelectedSutName(String selectedSutName) { this.selectedSutName = selectedSutName; } /** *

Getter for the field readonly.

* * @return a boolean. */ public boolean getReadonly() { return readonly; } /** *

Setter for the field readonly.

* * @param readonly a boolean. */ public void setReadonly(boolean readonly) { this.readonly = readonly; } /** *

isEditMode.

* * @return a boolean. */ public boolean isEditMode() { return editMode; } /** *

Setter for the field editMode.

* * @param editMode a boolean. */ public void setEditMode(boolean editMode) { this.editMode = editMode; } /** *

isAddMode.

* * @return a boolean. */ public boolean isAddMode() { return addMode; } /** *

Setter for the field addMode.

* * @param addMode a boolean. */ public void setAddMode(boolean addMode) { this.addMode = addMode; } /** *

isEditClasspathsMode.

* * @return a boolean. */ public boolean isEditClasspathsMode() { return editClasspathsMode; } /** *

Setter for the field editClasspathsMode.

* * @param editClasspathsMode a boolean. */ public void setEditClasspathsMode(boolean editClasspathsMode) { this.editClasspathsMode = editClasspathsMode; } /** *

isEditFixturesMode.

* * @return a boolean. */ public boolean isEditFixturesMode() { return editFixturesMode; } /** *

Setter for the field editFixturesMode.

* * @param editFixturesMode a boolean. */ public void setEditFixturesMode(boolean editFixturesMode) { this.editFixturesMode = editFixturesMode; } /** *

isEditPropertiesMode.

* * @return a boolean. */ public boolean isEditPropertiesMode() { return editPropertiesMode; } /** *

Setter for the field editPropertiesMode.

* * @param editPropertiesMode a boolean. */ public void setEditPropertiesMode(boolean editPropertiesMode) { this.editPropertiesMode = editPropertiesMode; } /** *

Getter for the field systemUnderTests.

* * @return a {@link java.util.List} object. */ public List getSystemUnderTests() { return systemUnderTests; } private Project getProjectForRegistration() throws GreenPepperServerException { if(isWithNewProject()) { validateProjectName(); return Project.newInstance(newProjectName); } return Project.newInstance(projectName); } private void validateProjectName() throws GreenPepperServerException { if(StringUtil.isBlank(newProjectName) || newProjectName.equals(getText("greenpepper.project.newname"))) { throw new GreenPepperServerException("greenpepper.registration.invalidprojectname", "invalid name"); } } private void successfullAction() { addMode = false; editPropertiesMode = false; editClasspathsMode = false; editFixturesMode = false; selectedSutName = newSutName; newSutName = ""; newRunnerName = ""; newFixtureFactory = null; newFixtureFactoryArgs = null; newProjectDependencyDescriptor = null; } private String getBaseUrl() { if(baseUrl != null) return baseUrl; baseUrl = gpUtil.getBaseUrl(); return baseUrl; } private String repositoryBaseUrl() { StringBuilder sb = new StringBuilder(); sb.append(getBaseUrl()).append("/display/").append(getSpaceKey()); return sb.toString(); } private String newTestUrl() { StringBuilder sb = new StringBuilder(); sb.append(getBaseUrl()).append("/rpc/xmlrpc"); sb.append("?handler=").append(getHandler()); sb.append("#").append(getSpaceKey()); return sb.toString(); } private void checkRepositoryBaseUrl() throws GreenPepperServerException { if (!editMode && !addMode && !getRegisteredRepository().getBaseUrl().equals(getBaseUrl())) { addActionError(getText(ConfluenceGreenPepper.REPOSITORY_BASEURL_OUTOFSYNC, new String[]{getRegisteredRepository().getBaseUrl(), getBaseUrl()})); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy