mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-1353 Refactor MailReader to use namespaces and conventional, finely-grained actions with no aliases. (Refactoring for wildcards is next.)
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@428196 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -37,6 +37,7 @@ public class AppData {
|
||||
|
||||
/**
|
||||
* <p>Adapt internal Integer value to external boolean value. </p>
|
||||
*
|
||||
* @return False if host_auto==0, True otherwise
|
||||
*/
|
||||
public boolean isHost_auto_checkbox() {
|
||||
@@ -57,6 +58,7 @@ public class AppData {
|
||||
/**
|
||||
* <p>Return true if a logic or state test passed,
|
||||
* such as whether a record already exists.</p>
|
||||
*
|
||||
* @return True if a business logic test passed.
|
||||
*/
|
||||
public boolean isNominal() {
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.io.*;
|
||||
|
||||
/**
|
||||
* <p><code>ServletContextListener</code> that initializes and finalizes the
|
||||
* persistent storage of User and Subscription information for the Struts
|
||||
* persistent storage of User and Support information for the Struts
|
||||
* Demonstration Application, using an in-memory database backed by an XML
|
||||
* file.</p>
|
||||
* <p/>
|
||||
@@ -50,7 +50,7 @@ import java.io.*;
|
||||
* <li>Class to store protocol list (an array here). </li>
|
||||
* <p/>
|
||||
* </ul>
|
||||
* <p>
|
||||
* <p/>
|
||||
* DEVELOPMENT NOTE - Another approach would be to instantiate the database via Spring.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package mailreader2;
|
||||
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import java.util.Map;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
|
||||
public class AuthenticationInterceptor implements Interceptor {
|
||||
import java.util.Map;
|
||||
|
||||
public void destroy () {}
|
||||
public class AuthenticationInterceptor implements Interceptor {
|
||||
|
||||
public void init() {}
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public String intercept(ActionInvocation actionInvocation) throws Exception {
|
||||
|
||||
@@ -18,12 +21,11 @@ public class AuthenticationInterceptor implements Interceptor {
|
||||
|
||||
User user = (User) session.get(Constants.USER_KEY);
|
||||
|
||||
boolean isAuthenticated = (null!=user) && (null!=user.getDatabase());
|
||||
boolean isAuthenticated = (null != user) && (null != user.getDatabase());
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return Action.LOGIN;
|
||||
}
|
||||
else {
|
||||
return Action.LOGIN;
|
||||
} else {
|
||||
return actionInvocation.invoke();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public final class Constants {
|
||||
public static final String PACKAGE = "org.apache.struts.apps.mailreader";
|
||||
|
||||
/**
|
||||
* <p> The session scope attribute under which the Subscription object
|
||||
* <p> The session scope attribute under which the Support object
|
||||
* currently selected by our logged-in User is stored. </p>
|
||||
*/
|
||||
public static final String SUBSCRIPTION_KEY = "subscription";
|
||||
@@ -91,11 +91,10 @@ public final class Constants {
|
||||
*/
|
||||
public static final String HOST = "host";
|
||||
|
||||
|
||||
// ---- Error Messages ----
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <p/>
|
||||
* A static message in case message resource is not loaded.
|
||||
* </p>
|
||||
*/
|
||||
@@ -103,31 +102,31 @@ public final class Constants {
|
||||
"ERROR: Message resources not loaded -- check servlet container logs for error messages.";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <p/>
|
||||
* A static message in case database resource is not loaded.
|
||||
* <p>
|
||||
* <p/>
|
||||
*/
|
||||
public static final String ERROR_DATABASE_NOT_LOADED =
|
||||
"ERROR: User database not loaded -- check servlet container logs for error messages.";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <p/>
|
||||
* A standard key from the message resources file, to test if it is available.
|
||||
* <p>
|
||||
* <p/>
|
||||
*/
|
||||
public static final String ERROR_DATABASE_MISSING = "error.database.missing";
|
||||
|
||||
/**
|
||||
* <P>
|
||||
* <p/>
|
||||
* A "magic" username to trigger an ExpiredPasswordException for testing.
|
||||
*</p>
|
||||
* </p>
|
||||
*/
|
||||
public static final String EXPIRED_PASSWORD_EXCEPTION = "ExpiredPasswordException";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <p/>
|
||||
* Name of field to associate with authentification errors.
|
||||
* <p>
|
||||
* <p/>
|
||||
*/
|
||||
public static final String PASSWORD_MISMATCH_FIELD = "password";
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ package mailreader2;
|
||||
public class Logoff extends MailreaderSupport {
|
||||
|
||||
public String execute() {
|
||||
|
||||
setUser(null);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package mailreader2;
|
||||
|
||||
import com.opensymphony.util.BeanUtils;
|
||||
import org.apache.struts2.interceptor.ApplicationAware;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -30,6 +28,8 @@ import org.apache.struts.apps.mailreader.dao.User;
|
||||
import org.apache.struts.apps.mailreader.dao.UserDatabase;
|
||||
import org.apache.struts.apps.mailreader.dao.impl.memory.MemorySubscription;
|
||||
import org.apache.struts.apps.mailreader.dao.impl.memory.MemoryUser;
|
||||
import org.apache.struts2.interceptor.ApplicationAware;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -54,13 +54,13 @@ public class MailreaderSupport extends ActionSupport
|
||||
|
||||
/**
|
||||
* Return CANCEL so apropriate result can be selected.
|
||||
*
|
||||
* @return "cancel" so apropriate result can be selected.
|
||||
*/
|
||||
public String cancel() {
|
||||
return Constants.CANCEL;
|
||||
}
|
||||
|
||||
|
||||
// ---- ApplicationAware ----
|
||||
|
||||
/**
|
||||
@@ -140,7 +140,7 @@ public class MailreaderSupport extends ActionSupport
|
||||
* @param value The task to set.
|
||||
*/
|
||||
public void setTask(String value) {
|
||||
task = value;
|
||||
task = value;
|
||||
}
|
||||
|
||||
// ---- Token property (utilized by UI) ----
|
||||
@@ -166,18 +166,17 @@ public class MailreaderSupport extends ActionSupport
|
||||
* @param value The token to set.
|
||||
*/
|
||||
public void setToken(String value) {
|
||||
token = value;
|
||||
token = value;
|
||||
}
|
||||
|
||||
|
||||
// ---- Host property ----
|
||||
|
||||
/**
|
||||
* <p>Field to store Subscription host.</p>
|
||||
* <p>Field to store Support host.</p>
|
||||
* <p/>
|
||||
* <p> The host is an immutable property of the Subscrtion DAP object, so
|
||||
* we need to store it locally until we are ready to create the
|
||||
* Subscription. </p>
|
||||
* Support. </p>
|
||||
*/
|
||||
private String host;
|
||||
|
||||
@@ -191,7 +190,7 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Store new Subscription host.</p>
|
||||
* <p>Store new Support host.</p>
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
@@ -401,7 +400,7 @@ public class MailreaderSupport extends ActionSupport
|
||||
|
||||
try {
|
||||
user = database.findUser(username);
|
||||
}
|
||||
}
|
||||
|
||||
catch (ExpiredPasswordException e) {
|
||||
user = getUser(); // Just so that it is not null
|
||||
@@ -437,19 +436,19 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Subscription property ----
|
||||
// ---- Support property ----
|
||||
|
||||
/**
|
||||
* <p>Obtain the cached Subscription object, if any. </p>
|
||||
* <p>Obtain the cached Support object, if any. </p>
|
||||
*
|
||||
* @return Cached Subscription object or null
|
||||
* @return Cached Support object or null
|
||||
*/
|
||||
public Subscription getSubscription() {
|
||||
return (Subscription) getSession().get(Constants.SUBSCRIPTION_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Store new User Subscription.</p>
|
||||
* <p>Store new User Support.</p>
|
||||
*
|
||||
* @param subscription
|
||||
*/
|
||||
@@ -458,13 +457,13 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Obtain User Subscription object for the given host, or return null
|
||||
* <p> Obtain User Support object for the given host, or return null
|
||||
* if not found. </p>
|
||||
*
|
||||
* <p/>
|
||||
* <p>It would be possible for this code to throw a NullPointerException,
|
||||
* but the ExceptionHandler in the xwork.xml will catch that for us.</p>
|
||||
*
|
||||
* @return The matching Subscription or null
|
||||
* @return The matching Support or null
|
||||
*/
|
||||
public Subscription findSubscription(String host) {
|
||||
Subscription subscription;
|
||||
@@ -473,19 +472,19 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Obtain uSER Subscription for the local Host property.</p>
|
||||
* <p>Obtain uSER Support for the local Host property.</p>
|
||||
* <p/>
|
||||
* <p>Usually, the host property will be set from the client request,
|
||||
* because it was embedded in a link to the Subcription action.
|
||||
*
|
||||
* @return Subscription or null if not found
|
||||
* @return Support or null if not found
|
||||
*/
|
||||
public Subscription findSubscription() {
|
||||
return findSubscription(getHost());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Provide a "temporary" User Subscription object that can be used to
|
||||
* <p>Provide a "temporary" User Support object that can be used to
|
||||
* capture input values.</p>
|
||||
*/
|
||||
public void createInputSubscription() {
|
||||
@@ -495,11 +494,11 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Provide new User Subscription object for the given host, or null if
|
||||
* <p>Provide new User Support object for the given host, or null if
|
||||
* the host is not unique.</p>
|
||||
*
|
||||
* @param host
|
||||
* @return New User Subscription object or null
|
||||
* @return New User Support object or null
|
||||
*/
|
||||
public Subscription createSubscription(String host) {
|
||||
|
||||
@@ -509,7 +508,7 @@ public class MailreaderSupport extends ActionSupport
|
||||
|
||||
if (null != sub) {
|
||||
// FIXME - localization - "error.host.unique")
|
||||
addFieldError(Constants.HOST,"That hostname is already defined");
|
||||
addFieldError(Constants.HOST, "That hostname is already defined");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -517,10 +516,10 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Create a new Subscription from the current Subscription object,
|
||||
* making the new Subscription the current Subscription. </p>
|
||||
* <p>Create a new Support from the current Support object,
|
||||
* making the new Support the current Support. </p>
|
||||
* <p/>
|
||||
* <p>Usually, the "current" Subscription is a temporary object being used
|
||||
* <p>Usually, the "current" Support is a temporary object being used
|
||||
* to capture input values.</p>
|
||||
*
|
||||
* @param host
|
||||
@@ -536,17 +535,17 @@ public class MailreaderSupport extends ActionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Delete the current Subscription object from the database.</p>
|
||||
* <p>Delete the current Support object from the database.</p>
|
||||
*/
|
||||
public void removeSubscription() {
|
||||
public void removeSubscription() {
|
||||
getUser().removeSubscription(getSubscription());
|
||||
getSession().remove(Constants.SUBSCRIPTION_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Provide MailServer Host for current User Subscription.</p>
|
||||
* <p>Provide MailServer Host for current User Support.</p>
|
||||
*
|
||||
* @return MailServer Host for current User Subscription
|
||||
* @return MailServer Host for current User Support
|
||||
*/
|
||||
public String getSubscriptionHost() {
|
||||
Subscription sub = getSubscription();
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package mailreader2;
|
||||
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Insert or update a User object to the persistent store. </p>
|
||||
*/
|
||||
public class Registration extends MailreaderSupport {
|
||||
|
||||
/**
|
||||
* <p>Double check that there is not a valid User logon. </p>
|
||||
*
|
||||
* @return True if there is not a valid User logon
|
||||
*/
|
||||
private boolean isCreating() {
|
||||
User user = getUser();
|
||||
return (null == user) || (null == user.getDatabase());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Retrieve User object to edit or null if User does not exist. </p>
|
||||
*
|
||||
* @return The "Success" result for this mapping
|
||||
* @throws Exception on any error
|
||||
*/
|
||||
public String input() throws Exception {
|
||||
|
||||
if (isCreating()) {
|
||||
createInputUser();
|
||||
setTask(Constants.CREATE);
|
||||
} else {
|
||||
setTask(Constants.EDIT);
|
||||
setUsername(getUser().getUsername());
|
||||
setPassword(getUser().getPassword());
|
||||
setPassword2(getUser().getPassword());
|
||||
}
|
||||
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Insert or update a User object to the persistent store. </p>
|
||||
* <p/>
|
||||
* <p> If a User is not logged in, then a new User is created and
|
||||
* automatically logged in. Otherwise, the existing User is updated. </p>
|
||||
*
|
||||
* @return The "Success" result for this mapping
|
||||
* @throws Exception on any error
|
||||
*/
|
||||
public String execute()
|
||||
throws Exception {
|
||||
|
||||
boolean creating = Constants.CREATE.equals(getTask());
|
||||
creating = creating && isCreating(); // trust but verify
|
||||
|
||||
if (creating) {
|
||||
|
||||
User user = findUser(getUsername(), getPassword());
|
||||
boolean haveUser = (user != null);
|
||||
|
||||
if (haveUser) {
|
||||
addActionError(getText("error.username.unique"));
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
copyUser(getUsername(), getPassword());
|
||||
|
||||
} else {
|
||||
|
||||
// FIXME: Any way to call the RegisrationSave validators from here?
|
||||
String newPassword = getPassword();
|
||||
if (newPassword != null) {
|
||||
String confirmPassword = getPassword2();
|
||||
boolean matches = ((null != confirmPassword)
|
||||
&& (confirmPassword.equals(newPassword)));
|
||||
if (matches) {
|
||||
getUser().setPassword(newPassword);
|
||||
} else {
|
||||
addActionError(getText("error.password.match"));
|
||||
return INPUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveUser();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package mailreader2;
|
||||
|
||||
/**
|
||||
* <p>Stub class to allow extra validation on initial Save.</p>
|
||||
*/
|
||||
public final class RegistrationSave extends Registration {
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package mailreader2;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p> Provide an Edit method for retrieving an existing subscription, and a
|
||||
* Save method for updating or inserting a subscription. </p>
|
||||
*/
|
||||
public class Subscription extends MailreaderSupport
|
||||
implements Preparable {
|
||||
|
||||
/**
|
||||
* <p>Field to store list of MailServer types</p>
|
||||
*/
|
||||
private Map types = null;
|
||||
|
||||
/**
|
||||
* <p>Provide the list of MailServer types.</p>
|
||||
*
|
||||
* @return List of MailServer types
|
||||
*/
|
||||
public Map getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setup the MailerServer types and set the local Host property from
|
||||
* the User Subscription (if any). </p>
|
||||
*/
|
||||
public void prepare() {
|
||||
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("imap", "IMAP Protocol");
|
||||
m.put("pop3", "POP3 Protocol");
|
||||
types = m;
|
||||
|
||||
setHost(getSubscriptionHost());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setup a temporary User Subscription object to capture input
|
||||
* values.</p>
|
||||
*
|
||||
* @return INPUT
|
||||
*/
|
||||
public String input() {
|
||||
createInputSubscription();
|
||||
setTask(Constants.CREATE);
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Load User Subscription for the local Host property.</p>
|
||||
* <p/>
|
||||
* <p>Usually, the Host is being set from the request by a link to an Edit
|
||||
* or Delete task.</p>
|
||||
*
|
||||
* @return INPUT or Error, if Subscription is not found
|
||||
*/
|
||||
public String find() {
|
||||
|
||||
org.apache.struts.apps.mailreader.dao.Subscription
|
||||
sub = findSubscription();
|
||||
|
||||
if (sub == null) {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
setSubscription(sub);
|
||||
|
||||
return INPUT;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare to present a confirmation page before removing
|
||||
* Subscription.</p>
|
||||
*
|
||||
* @return INPUT or Error, if Subscription is not found
|
||||
*/
|
||||
public String delete() {
|
||||
|
||||
setTask(Constants.DELETE);
|
||||
return find();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Prepare to edit User Subscription.</p>
|
||||
*
|
||||
* @return INPUT or Error, if Subscription is not found
|
||||
*/
|
||||
public String edit() {
|
||||
|
||||
setTask(Constants.EDIT);
|
||||
return find();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Examine the Task property and DELETE, CREATE, or save the User
|
||||
* Subscription, as appropriate. </p>
|
||||
*
|
||||
* @return SUCCESS
|
||||
* @throws Exception on a database error
|
||||
*/
|
||||
public String save() throws Exception {
|
||||
|
||||
if (Constants.DELETE.equals(getTask())) {
|
||||
removeSubscription();
|
||||
}
|
||||
|
||||
if (Constants.CREATE.equals(getTask())) {
|
||||
copySubscription(getHost());
|
||||
}
|
||||
|
||||
if (hasErrors()) return INPUT;
|
||||
|
||||
saveUser();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package mailreader2;
|
||||
|
||||
/**
|
||||
* <p> Workaround class. Submitting to an alias doesn't seem to work. </p>
|
||||
*/
|
||||
public final class SubscriptionSave extends Subscription {
|
||||
|
||||
public void prepare() {
|
||||
super.prepare();
|
||||
// checkbox workaround
|
||||
getSubscription().setAutoConnect(false);
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
|
||||
"http://struts.apache.org/dtds/struts-2.0.dtd">
|
||||
|
||||
<struts>
|
||||
<package name="Welcome" namespace="/" extends="MailreaderSupport">
|
||||
|
||||
<action name="Welcome" class="mailreader2.Welcome">
|
||||
<result>/pages/Welcome.jsp</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
</struts>
|
||||
@@ -14,14 +14,13 @@ public class Welcome extends MailreaderSupport {
|
||||
}
|
||||
|
||||
// Confirm database loaded
|
||||
if (null==getDatabase()) {
|
||||
addActionError(Constants.ERROR_DATABASE_NOT_LOADED);
|
||||
if (null == getDatabase()) {
|
||||
addActionError(Constants.ERROR_DATABASE_NOT_LOADED);
|
||||
}
|
||||
|
||||
if (hasErrors()) {
|
||||
return ERROR;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+28
-28
@@ -1,28 +1,28 @@
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="password">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password.required"/>
|
||||
</field-validator>
|
||||
<field-validator type="stringlength">
|
||||
<param name="trim">true</param>
|
||||
<param name="minLength">4</param>
|
||||
<param name="maxLength">10</param>
|
||||
<message key="errors.range"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="password2">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password2.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<validator type="expression">
|
||||
<param name="expression">password eq password2</param>
|
||||
<message key="error.password.match"/>
|
||||
</validator>
|
||||
|
||||
</validators>
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="password">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password.required"/>
|
||||
</field-validator>
|
||||
<field-validator type="stringlength">
|
||||
<param name="trim">true</param>
|
||||
<param name="minLength">4</param>
|
||||
<param name="maxLength">10</param>
|
||||
<message key="errors.range"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="password2">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password2.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<validator type="expression">
|
||||
<param name="expression">password eq password2</param>
|
||||
<message key="error.password.match"/>
|
||||
</validator>
|
||||
|
||||
</validators>
|
||||
@@ -0,0 +1,33 @@
|
||||
package mailreader2.registration;
|
||||
|
||||
import mailreader2.Constants;
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
|
||||
/**
|
||||
* <p>Insert new user, providing extra validation.</p>
|
||||
* <p/>
|
||||
* <p>(On an update, the password change is optional.)</p>
|
||||
*/
|
||||
public final class Create extends Update {
|
||||
|
||||
public String execute()
|
||||
throws Exception {
|
||||
|
||||
// trust but verify
|
||||
boolean creating = Constants.CREATE.equals(getTask());
|
||||
creating = creating && isCreating();
|
||||
if (!creating) return ERROR;
|
||||
|
||||
User user = findUser(getUsername(), getPassword());
|
||||
boolean haveUser = (user != null);
|
||||
|
||||
if (haveUser) {
|
||||
addActionError(getText("error.username.unique"));
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
copyUser(getUsername(), getPassword());
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package mailreader2.registration;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p> Retrieve User object to edit or null if User does not exist. </p>
|
||||
*/
|
||||
public class Input extends Support {
|
||||
|
||||
/**
|
||||
* <p> Retrieve User object to edit or null if User does not exist. </p>
|
||||
*
|
||||
* @return The "Success" result for this mapping
|
||||
* @throws Exception on any error
|
||||
*/
|
||||
public String execute() throws Exception {
|
||||
|
||||
if (isCreating()) {
|
||||
createInputUser();
|
||||
setTask(Constants.CREATE);
|
||||
} else {
|
||||
setTask(Constants.EDIT);
|
||||
setUsername(getUser().getUsername());
|
||||
setPassword(getUser().getPassword());
|
||||
setPassword2(getUser().getPassword());
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
+46
-45
@@ -1,45 +1,46 @@
|
||||
/*
|
||||
* $Id: LogonAction.java 360442 2005-12-31 20:10:04Z husted $
|
||||
*
|
||||
* Copyright 2000-2004 Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package mailreader2;
|
||||
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
import org.apache.struts.apps.mailreader.dao.ExpiredPasswordException;
|
||||
|
||||
/**
|
||||
* <p> Validate a user logon. </p>
|
||||
*/
|
||||
public final class Logon extends MailreaderSupport {
|
||||
|
||||
public String execute() throws ExpiredPasswordException {
|
||||
|
||||
User user = findUser(getUsername(), getPassword());
|
||||
|
||||
if (user != null) {
|
||||
setUser(user);
|
||||
}
|
||||
|
||||
if (hasErrors()) {
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* $Id: LogonAction.java 360442 2005-12-31 20:10:04Z husted $
|
||||
*
|
||||
* Copyright 2000-2004 Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package mailreader2.registration;
|
||||
|
||||
import mailreader2.MailreaderSupport;
|
||||
import org.apache.struts.apps.mailreader.dao.ExpiredPasswordException;
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
|
||||
/**
|
||||
* <p> Validate a user logon. </p>
|
||||
*/
|
||||
public final class Retrieve extends MailreaderSupport {
|
||||
|
||||
public String execute() throws ExpiredPasswordException {
|
||||
|
||||
User user = findUser(getUsername(), getPassword());
|
||||
|
||||
if (user != null) {
|
||||
setUser(user);
|
||||
}
|
||||
|
||||
if (hasErrors()) {
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package mailreader2.registration;
|
||||
|
||||
import mailreader2.MailreaderSupport;
|
||||
import org.apache.struts.apps.mailreader.dao.User;
|
||||
|
||||
/**
|
||||
* <p>Base class to store shared methods.</p>
|
||||
*/
|
||||
public class Support extends MailreaderSupport {
|
||||
|
||||
/**
|
||||
* <p>Double check that there is not a valid User logon. </p>
|
||||
*
|
||||
* @return True if there is not a valid User logon
|
||||
*/
|
||||
protected boolean isCreating() {
|
||||
User user = getUser();
|
||||
return (null == user) || (null == user.getDatabase());
|
||||
}
|
||||
}
|
||||
+32
-32
@@ -1,32 +1,32 @@
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="username">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.username.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.fullName">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.fullName.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.fromAddress">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.fromAddress.required"/>
|
||||
</field-validator>
|
||||
<field-validator type="email">
|
||||
<message key="errors.email"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.replyToAddress">
|
||||
<field-validator type="email">
|
||||
<message key="errors.email"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="username">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.username.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.fullName">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.fullName.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.fromAddress">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.fromAddress.required"/>
|
||||
</field-validator>
|
||||
<field-validator type="email">
|
||||
<message key="errors.email"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="user.replyToAddress">
|
||||
<field-validator type="email">
|
||||
<message key="errors.email"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
@@ -0,0 +1,41 @@
|
||||
package mailreader2.registration;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p> Update a User object to the persistent store. </p>
|
||||
*/
|
||||
public class Update extends Support {
|
||||
|
||||
private String fixNull(String value) {
|
||||
if (value == null) return null;
|
||||
String buffer = value.trim();
|
||||
if (buffer.length() == 0) return null;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public String execute()
|
||||
throws Exception {
|
||||
|
||||
boolean creating = Constants.CREATE.equals(getTask());
|
||||
creating = creating && isCreating(); // trust but verify
|
||||
if (creating) return ERROR;
|
||||
// FIXME: Any way to call the RegisrationSave validators from here?
|
||||
String newPassword = fixNull(getPassword());
|
||||
String confirmPassword = fixNull(getPassword2());
|
||||
if (newPassword != null) {
|
||||
boolean matches = ((confirmPassword != null)
|
||||
&& (confirmPassword.equals(newPassword)));
|
||||
if (matches) {
|
||||
getUser().setPassword(newPassword);
|
||||
} else {
|
||||
addActionError(getText("error.password.match"));
|
||||
return INPUT;
|
||||
}
|
||||
}
|
||||
|
||||
saveUser();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package mailreader2.subscription;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p>Prepare to present a confirmation page before removing
|
||||
* subscription.</p>
|
||||
*/
|
||||
public class Delete extends Edit {
|
||||
|
||||
public String execute() throws Exception {
|
||||
setTask(Constants.DELETE);
|
||||
return find();
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="host">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.host.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="host">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.host.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
@@ -0,0 +1,16 @@
|
||||
package mailreader2.subscription;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p>Prepare to edit User Support.</p>
|
||||
*/
|
||||
public class Edit extends Support {
|
||||
|
||||
public String execute() throws Exception {
|
||||
setTask(Constants.EDIT);
|
||||
return find();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package mailreader2.subscription;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p>Setup a temporary User Support object to capture input
|
||||
* values.</p>
|
||||
*/
|
||||
public class Input extends Support {
|
||||
|
||||
public String execute() {
|
||||
createInputSubscription();
|
||||
setTask(Constants.CREATE);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
+23
-23
@@ -1,23 +1,23 @@
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="subscription.username">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.username.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="subscription.password">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="subscription.type">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.type.invalid"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
|
||||
|
||||
<validators>
|
||||
|
||||
<field name="subscription.username">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.username.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="subscription.password">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.password.required"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
<field name="subscription.type">
|
||||
<field-validator type="requiredstring">
|
||||
<message key="error.type.invalid"/>
|
||||
</field-validator>
|
||||
</field>
|
||||
|
||||
</validators>
|
||||
@@ -0,0 +1,38 @@
|
||||
package mailreader2.subscription;
|
||||
|
||||
import mailreader2.Constants;
|
||||
|
||||
/**
|
||||
* <p> Workaround class. Submitting to an alias doesn't seem to work. </p>
|
||||
*/
|
||||
public final class Save extends Edit {
|
||||
|
||||
public void prepare() {
|
||||
super.prepare();
|
||||
// checkbox workaround
|
||||
getSubscription().setAutoConnect(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Examine the Task property and DELETE, CREATE, or save the User
|
||||
* Support, as appropriate. </p>
|
||||
*
|
||||
* @return SUCCESS
|
||||
* @throws Exception on a database error
|
||||
*/
|
||||
public String execute() throws Exception {
|
||||
|
||||
if (Constants.DELETE.equals(getTask())) {
|
||||
removeSubscription();
|
||||
}
|
||||
|
||||
if (Constants.CREATE.equals(getTask())) {
|
||||
copySubscription(getHost());
|
||||
}
|
||||
|
||||
if (hasErrors()) return INPUT;
|
||||
|
||||
saveUser();
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package mailreader2.subscription;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import mailreader2.MailreaderSupport;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p> Provide an Edit method for retrieving an existing subscription, and a
|
||||
* Save method for updating or inserting a subscription. </p>
|
||||
*/
|
||||
public class Support extends MailreaderSupport
|
||||
implements Preparable {
|
||||
|
||||
/**
|
||||
* <p>Field to store list of MailServer types</p>
|
||||
*/
|
||||
private Map types = null;
|
||||
|
||||
/**
|
||||
* <p>Provide the list of MailServer types.</p>
|
||||
*
|
||||
* @return List of MailServer types
|
||||
*/
|
||||
public Map getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setup the MailerServer types and set the local Host property from
|
||||
* the User Support (if any). </p>
|
||||
*/
|
||||
public void prepare() {
|
||||
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("imap", "IMAP Protocol");
|
||||
m.put("pop3", "POP3 Protocol");
|
||||
types = m;
|
||||
|
||||
setHost(getSubscriptionHost());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Load User Support for the local Host property.</p>
|
||||
* <p/>
|
||||
* <p>Usually, the Host is being set from the request by a link to an Edit
|
||||
* or Delete task.</p>
|
||||
*
|
||||
* @return INPUT or Error, if Support is not found
|
||||
*/
|
||||
public String find() {
|
||||
|
||||
org.apache.struts.apps.mailreader.dao.Subscription
|
||||
sub = findSubscription();
|
||||
|
||||
if (sub == null) {
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
setSubscription(sub);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
<!DOCTYPE sqlMapConfig PUBLIC
|
||||
"-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
"-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
|
||||
|
||||
<sqlMapConfig>
|
||||
|
||||
<properties resource="sql/sql-map-config-hsql.properties"/>
|
||||
<properties resource="sql/sql-map-config-hsql.properties"/>
|
||||
|
||||
<settings cacheModelsEnabled="true" enhancementEnabled="false"
|
||||
maxSessions="64" maxTransactions="8" maxRequests="128"/>
|
||||
<settings cacheModelsEnabled="true" enhancementEnabled="false"
|
||||
maxSessions="64" maxTransactions="8" maxRequests="128"/>
|
||||
|
||||
<transactionManager type="JDBC">
|
||||
<dataSource type="SIMPLE">
|
||||
<property value="${driver}" name="JDBC.Driver"/>
|
||||
<property value="${url}" name="JDBC.ConnectionURL"/>
|
||||
<property value="${username}" name="JDBC.Username"/>
|
||||
<property value="${password}" name="JDBC.Password"/>
|
||||
<property value="15" name="Pool.MaximumActiveConnections"/>
|
||||
<property value="15" name="Pool.MaximumIdleConnections"/>
|
||||
<property value="1000" name="Pool.MaximumWait"/>
|
||||
</dataSource>
|
||||
</transactionManager>
|
||||
<transactionManager type="JDBC">
|
||||
<dataSource type="SIMPLE">
|
||||
<property value="${driver}" name="JDBC.Driver"/>
|
||||
<property value="${url}" name="JDBC.ConnectionURL"/>
|
||||
<property value="${username}" name="JDBC.Username"/>
|
||||
<property value="${password}" name="JDBC.Password"/>
|
||||
<property value="15" name="Pool.MaximumActiveConnections"/>
|
||||
<property value="15" name="Pool.MaximumIdleConnections"/>
|
||||
<property value="1000" name="Pool.MaximumWait"/>
|
||||
</dataSource>
|
||||
</transactionManager>
|
||||
|
||||
<sqlMap resource="sql/sql-map.xml"/>
|
||||
<sqlMap resource="sql/sql-map.xml"/>
|
||||
</sqlMapConfig>
|
||||
@@ -1,10 +1,10 @@
|
||||
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
|
||||
|
||||
<sqlMap namespace="mailreader">
|
||||
|
||||
<typeAlias alias="data"
|
||||
type="mailreader2.AppData"/>
|
||||
type="mailreader2.AppData"/>
|
||||
|
||||
<select id="LOCALE_LIST" resultClass="data">
|
||||
SELECT pk_locale AS locale_key, locale_code
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<insert id="REGISTRATION_INSERT" parameterClass="data">
|
||||
INSERT INTO registration
|
||||
(pk_registration, fk_locale, username, password, fullname, email_from, email_replyto)
|
||||
(pk_registration, fk_locale, username, password, fullname, email_from, email_replyto)
|
||||
VALUES (#registration_key#, #locale_key#, #username#, #password#, #fullname#, #email_from#, #email_replyto#);
|
||||
</insert>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<select id="REGISTRATION_EDIT" parameterClass="data" resultClass="data">
|
||||
SELECT pk_registration AS registration_key, fk_locale AS locale_key,
|
||||
username, password, fullname, email_from, email_replyto
|
||||
username, password, fullname, email_from, email_replyto
|
||||
FROM registration
|
||||
WHERE pk_registration=#registration_key#;
|
||||
</select>
|
||||
@@ -45,7 +45,7 @@
|
||||
<update id="REGISTRATION_UPDATE" parameterClass="data">
|
||||
UPDATE registration
|
||||
SET fk_locale=#locale_key#, username=#username#, password=#password#, fullname=#fullname#,
|
||||
email_from=#email_from#, email_replyto=#email_replyto#
|
||||
email_from=#email_from#, email_replyto=#email_replyto#
|
||||
WHERE pk_registration=#registration_key#;
|
||||
</update>
|
||||
|
||||
@@ -53,36 +53,36 @@
|
||||
SELECT COUNT(*)
|
||||
FROM subscription
|
||||
WHERE fk_registration=#registration_key#
|
||||
AND subscription_host=#subscription_host#;
|
||||
AND subscription_host=#subscription_host#;
|
||||
</select>
|
||||
|
||||
<insert id="SUBSCRIPTION_INSERT" parameterClass="data">
|
||||
INSERT INTO subscription
|
||||
(pk_subscription, fk_registration, fk_protocol, subscription_host, host_user, host_pass, host_auto)
|
||||
(pk_subscription, fk_registration, fk_protocol, subscription_host, host_user, host_pass, host_auto)
|
||||
VALUES (#subscription_key#, #registration_key#, #protocol_key#, #subscription_host#,
|
||||
#host_user#, #host_pass#, #host_auto#);
|
||||
#host_user#, #host_pass#, #host_auto#);
|
||||
</insert>
|
||||
|
||||
<select id="SUBSCRIPTION_LIST" parameterClass="data" resultClass="data">
|
||||
SELECT pk_subscription AS subscription_key,
|
||||
subscription_host, host_user, host_pass, host_auto, protocol_name
|
||||
subscription_host, host_user, host_pass, host_auto, protocol_name
|
||||
FROM subscription
|
||||
JOIN protocol ON pk_protocol=fk_protocol
|
||||
JOIN protocol ON pk_protocol=fk_protocol
|
||||
WHERE fk_registration=#registration_key#;
|
||||
</select>
|
||||
|
||||
<select id="SUBSCRIPTION_EDIT" parameterClass="data" resultClass="data">
|
||||
SELECT pk_subscription AS subscription_key, fk_protocol AS protocol_key,
|
||||
subscription_host, host_user, host_pass, host_auto, protocol_name
|
||||
subscription_host, host_user, host_pass, host_auto, protocol_name
|
||||
FROM subscription
|
||||
JOIN protocol ON pk_protocol=fk_protocol
|
||||
JOIN protocol ON pk_protocol=fk_protocol
|
||||
WHERE pk_subscription=#subscription_key#;
|
||||
</select>
|
||||
|
||||
<update id="SUBSCRIPTION_UPDATE" parameterClass="data">
|
||||
UPDATE subscription
|
||||
SET fk_registration=#registration_key#, fk_protocol=#protocol_key#,
|
||||
subscription_host=#subscription_host#, host_user=#host_user#, host_pass=#host_pass#, host_auto=#host_auto#
|
||||
subscription_host=#subscription_host#, host_user=#host_user#, host_pass=#host_pass#, host_auto=#host_auto#
|
||||
WHERE pk_subscription=#subscription_key#;
|
||||
</update>
|
||||
|
||||
|
||||
@@ -1,112 +1,169 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
|
||||
"http://struts.apache.org/dtds/struts-2.0.dtd">
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
|
||||
"http://struts.apache.org/dtds/struts-2.0.dtd">
|
||||
|
||||
<struts>
|
||||
<include file="struts-default.xml"/>
|
||||
|
||||
<package name="default" namespace="/" extends="struts-default">
|
||||
<package name="default" namespace="" extends="struts-default">
|
||||
|
||||
<interceptors>
|
||||
|
||||
<interceptor name="authentication"
|
||||
class="mailreader2.AuthenticationInterceptor"/>
|
||||
|
||||
<interceptor-stack name="user" >
|
||||
<interceptor-ref name="authentication" />
|
||||
<interceptor-stack name="user">
|
||||
<interceptor-ref name="authentication"/>
|
||||
<interceptor-ref name="defaultStack"/>
|
||||
</interceptor-stack>
|
||||
|
||||
<interceptor-stack name="user-submit" >
|
||||
<interceptor-ref name="token-session" />
|
||||
<interceptor-stack name="user-submit">
|
||||
<interceptor-ref name="token-session"/>
|
||||
<interceptor-ref name="user"/>
|
||||
</interceptor-stack>
|
||||
|
||||
<interceptor-stack name="guest" >
|
||||
<interceptor-stack name="guest">
|
||||
<interceptor-ref name="defaultStack"/>
|
||||
</interceptor-stack>
|
||||
|
||||
<interceptor-stack name="guest-submit" >
|
||||
<interceptor-ref name="token-session" />
|
||||
<interceptor-stack name="guest-submit">
|
||||
<interceptor-ref name="token-session"/>
|
||||
<interceptor-ref name="guest"/>
|
||||
</interceptor-stack>
|
||||
|
||||
</interceptors>
|
||||
|
||||
<default-interceptor-ref name="user"/>
|
||||
|
||||
<default-action-ref name="Welcome"/>
|
||||
|
||||
<!-- default-action-ref name="Welcome"/ -->
|
||||
|
||||
<global-results>
|
||||
<result name="error">/pages/Error.jsp</result>
|
||||
<result name="invalid.token">/pages/Error.jsp</result>
|
||||
<result name="login" type="redirect-action">Logon!input</result>
|
||||
<result name="login" type="redirect-action">Logon</result>
|
||||
<result name="cancel" type="redirect-action">Welcome</result>
|
||||
<result name="success" type="redirect-action">MainMenu</result>
|
||||
<result name="expired" type="chain">ChangePassword</result>
|
||||
</global-results>
|
||||
|
||||
<global-exception-mappings>
|
||||
<exception-mapping
|
||||
result="error"
|
||||
exception="java.lang.Throwable"/>
|
||||
</global-exception-mappings>
|
||||
|
||||
<action name="Welcome" class="mailreader2.Welcome">
|
||||
<result>/pages/Welcome.jsp</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
<action name="Logon!*" class="mailreader2.Logon" method="{1}">
|
||||
<result name="input">/pages/Logon.jsp</result>
|
||||
<result name="cancel" type="redirect-action">Welcome</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<result name="expired" type="chain">ChangePassword</result>
|
||||
<exception-mapping
|
||||
exception="org.apache.struts.apps.mailreader.dao.ExpiredPasswordException"
|
||||
result="expired"/>
|
||||
<interceptor-ref name="guest"/>
|
||||
</global-exception-mappings>
|
||||
|
||||
<!--
|
||||
<action name="*" class="mailreader2.{1}">
|
||||
<result name="input">/pages/{1}.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="*/*" class="mailreader2.{1}.{2}">
|
||||
<result name="input">/pages/{1}.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
</action>
|
||||
|
||||
<action name="*/Create" class="mailreader2.{1}.Create">
|
||||
<result name="input">/pages/{1}.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="user-submit" />
|
||||
</action>
|
||||
|
||||
<action name="*/Update" class="mailreader2.{1}.Update">
|
||||
<result name="input">/pages/{1}.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="user-submit" />
|
||||
</action>
|
||||
|
||||
<action name="*/Save" class="mailreader2.{1}.Save">
|
||||
<result name="input">/pages/{1}.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="user-submit" />
|
||||
</action>
|
||||
|
||||
-->
|
||||
|
||||
<action name="ChangePassword">
|
||||
<result>/pages/ChangePassword.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="MainMenu" class="mailreader2.MailreaderSupport">
|
||||
<result>/pages/MainMenu.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Registration!*" class="mailreader2.Registration" method="{1}">
|
||||
<result name="input">/pages/Registration.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
<!-- last match wins -->
|
||||
<action name="Registration_save" class="mailreader2.RegistrationSave">
|
||||
<result name="input">/pages/Registration.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="guest-submit" />
|
||||
</action>
|
||||
|
||||
<action name="Subscription!*" class="mailreader2.Subscription" method="{1}">
|
||||
<result name="input">/pages/Subscription.jsp</result>
|
||||
<result type="redirect-action">Registration!input</result>
|
||||
</action>
|
||||
|
||||
<!-- last match wins -->
|
||||
<action name="Subscription_save" class="mailreader2.SubscriptionSave">
|
||||
<result name="input">/pages/Subscription.jsp</result>
|
||||
<result type="redirect-action">Registration!input</result>
|
||||
<interceptor-ref name="user-submit" />
|
||||
<result name="input">/pages/ChangePassword.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Logoff" class="mailreader2.Logoff">
|
||||
<result type="redirect-action">Welcome</result>
|
||||
</action>
|
||||
|
||||
<action name="Logon">
|
||||
<result>/pages/Logon.jsp</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
<action name="MainMenu" class="mailreader2.MailreaderSupport">
|
||||
<result>/pages/MainMenu.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Tour">
|
||||
<result>/pages/tour.html</result>
|
||||
<result>/pages/Tour.html</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
<action name="Welcome" class="mailreader2.Welcome">
|
||||
<result>/pages/Welcome.jsp</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
|
||||
<package name="registration" namespace="/registration" extends="default">
|
||||
|
||||
<action name="Update" class="mailreader2.registration.Update">
|
||||
<result name="input">/pages/registration.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
</action>
|
||||
|
||||
<action name="Create" class="mailreader2.registration.Create">
|
||||
<result name="input">/pages/registration.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="guest-submit"/>
|
||||
</action>
|
||||
|
||||
<action name="Input" class="mailreader2.registration.Input">
|
||||
<result>/pages/registration.jsp</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
<action name="Retrieve" class="mailreader2.registration.Retrieve">
|
||||
<result name="input">/pages/Logon.jsp</result>
|
||||
<result type="redirect-action">MainMenu</result>
|
||||
<interceptor-ref name="guest"/>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
|
||||
<package name="subscription" namespace="/subscription" extends="default">
|
||||
|
||||
<action name="Delete" class="mailreader2.subscription.Delete">
|
||||
<result>/pages/subscription.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Edit" class="mailreader2.subscription.Edit">
|
||||
<result>/pages/subscription.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Input" class="mailreader2.subscription.Input">
|
||||
<result>/pages/subscription.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Save" class="mailreader2.subscription.Save">
|
||||
<result name="input">/pages/subscription.jsp</result>
|
||||
<result type="redirect-action">
|
||||
<param name="actionName">Input</param>
|
||||
<param name="namespace">/registration</param>
|
||||
</result>
|
||||
<interceptor-ref name="user-submit"/>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
|
||||
</struts>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
mailreader2.ApplicationListener
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="<s:url action="Logon!input"/>">
|
||||
<a href="<s:url action="Logon"/>">
|
||||
<s:text name="change.try"/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<h3>Error Message</h3>
|
||||
|
||||
<s:actionerror />
|
||||
<s:actionerror/>
|
||||
|
||||
<p>
|
||||
<s:property value="%{exception.message}"/>
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
type="text/css"/>
|
||||
</head>
|
||||
|
||||
<body onLoad="self.focus();document.Logon.username.focus()">
|
||||
<body onLoad="self.focus();document.Retrieve.username.focus()">
|
||||
|
||||
<s:actionerror />
|
||||
<s:form action="Logon!execute" validate="true">
|
||||
<s:actionerror/>
|
||||
<s:form action="Retrieve" namespace="/registration" validate="true">
|
||||
<s:textfield label="%{getText('username')}" name="username"/>
|
||||
|
||||
<s:password label="%{getText('password')}" name="password" showPassword="true"/>
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
<s:reset value="%{getText('button.reset')}"/>
|
||||
|
||||
<s:submit action="Logon!cancel" value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
<s:submit action="Welcome" value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
</s:form>
|
||||
|
||||
<jsp:include page="Footer.jsp"/>
|
||||
|
||||
@@ -13,13 +13,21 @@
|
||||
<h3><s:text name="mainMenu.heading"/> <s:property
|
||||
value="user.fullName"/></h3>
|
||||
<ul>
|
||||
<li><a href="<s:url action="Registration!input" />">
|
||||
<s:text name="mainMenu.registration"/>
|
||||
</a>
|
||||
<li>
|
||||
<s:url id="Input" action="Input" namespace="/registration"/>
|
||||
<s:a href="%{Input}">
|
||||
<s:text name="mainMenu.registration"/>
|
||||
</s:a>
|
||||
</li>
|
||||
<li>
|
||||
<s:url id="Logoff" action="Logoff"/>
|
||||
<s:a href="%{Logoff}">
|
||||
<s:text name="mainMenu.logoff"/>
|
||||
</s:a>
|
||||
</li>
|
||||
<li><a href="<s:url action="Logoff"/>">
|
||||
<s:text name="mainMenu.logoff"/>
|
||||
</a>
|
||||
</ul>
|
||||
|
||||
<jsp:include page="Footer.jsp"/>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
type="text/css"/>
|
||||
</head>
|
||||
|
||||
<body onLoad="self.focus();document.Registration.username.focus()">
|
||||
<body onLoad="self.focus();document.Update.username.focus()">
|
||||
|
||||
<s:actionerror/>
|
||||
<s:form action="Registration" validate="true">
|
||||
<s:form action="Update" validate="true">
|
||||
<s:token/>
|
||||
<s:hidden name="task"/>
|
||||
<s:if test="task == 'Create'">
|
||||
@@ -33,29 +33,29 @@
|
||||
<s:password label="%{getText('password2')}" name="password2"/>
|
||||
|
||||
<s:textfield label="%{getText('fullName')}"
|
||||
name="user.fullName"/>
|
||||
name="user.fullName"/>
|
||||
|
||||
<s:textfield label="%{getText('fromAddress')}"
|
||||
name="user.fromAddress"/>
|
||||
name="user.fromAddress"/>
|
||||
|
||||
<s:textfield label="%{getText('replyToAddress')}"
|
||||
name="user.replyToAddress"/>
|
||||
name="user.replyToAddress"/>
|
||||
|
||||
<s:if test="task == 'Create'">
|
||||
<s:submit value="%{getText('button.save')}" action="Registration_save"/>
|
||||
<s:submit value="%{getText('button.save')}" action="Create"/>
|
||||
|
||||
<s:reset value="%{getText('button.reset')}"/>
|
||||
|
||||
<s:submit action="Welcome" value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
onclick="form.onsubmit=null"/>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<s:submit value="%{getText('button.save')}"/>
|
||||
|
||||
<s:reset value="%{getText('button.reset')}"/>
|
||||
|
||||
<s:submit action="MainMenu" value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
<s:submit value="%{getText('button.cancel')}"
|
||||
action="MainMenu" onclick="form.onsubmit=null"/>
|
||||
</s:else>
|
||||
|
||||
</s:form>
|
||||
@@ -100,23 +100,27 @@
|
||||
<s:property value="autoConnect"/>
|
||||
</td>
|
||||
<td align="center">
|
||||
|
||||
<a href="<s:url action="Subscription!delete"><s:param name="host" value="host"/></s:url>">
|
||||
<s:url id="Delete" action="Delete" namespace="/subscription">
|
||||
<s:param name="host" value="host"/>
|
||||
</s:url>
|
||||
<s:a href="%{Delete}">
|
||||
<s:text name="registration.deleteSubscription"/>
|
||||
</a>
|
||||
</s:a>
|
||||
|
||||
<a href="<s:url action="Subscription!edit"><s:param name="host" value="host"/></s:url>">
|
||||
<s:url id="Edit" action="Edit" namespace="/subscription">
|
||||
<s:param name="host" value="host"/>
|
||||
</s:url>
|
||||
<s:a href="%{Edit}">
|
||||
<s:text name="registration.editSubscription"/>
|
||||
</a>
|
||||
|
||||
</s:a>
|
||||
</td>
|
||||
</tr>
|
||||
</s:iterator>
|
||||
|
||||
</table>
|
||||
|
||||
<a href="<s:url action="Subscription!input"/>"><s:text
|
||||
name="registration.addSubscription"/></a>
|
||||
<s:url id="Input" action="Input" namespace="/subscription"/>
|
||||
<s:a href="%{Input}"><s:text name="registration.addSubscription"/></s:a>
|
||||
|
||||
</s:if>
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
type="text/css"/>
|
||||
</head>
|
||||
|
||||
<body onLoad="self.focus();document.Subscription_save.username.focus()">
|
||||
<body onLoad="self.focus();document.Save.username.focus()">
|
||||
|
||||
<s:actionerror/>
|
||||
<s:form action="Subscription_save" validate="true">
|
||||
<s:form action="Save" validate="true">
|
||||
<s:token/>
|
||||
<s:hidden name="task"/>
|
||||
<s:label label="%{getText('username')}" name="user.username"/>
|
||||
@@ -35,31 +35,31 @@
|
||||
|
||||
<s:if test="task == 'Delete'">
|
||||
<s:label label="%{getText('mailUsername')}"
|
||||
name="subscription.username"/>
|
||||
name="subscription.username"/>
|
||||
<s:label label="%{getText('mailPassword')}"
|
||||
name="subscription.password"/>
|
||||
name="subscription.password"/>
|
||||
<s:label label="%{getText('mailServerType')}"
|
||||
name="subscription.type"/>
|
||||
name="subscription.type"/>
|
||||
<s:label label="%{getText('autoConnect')}"
|
||||
name="subscription.autoConnect"/>
|
||||
name="subscription.autoConnect"/>
|
||||
<s:submit value="%{getText('button.confirm')}"/>
|
||||
</s:if>
|
||||
<s:else>
|
||||
<s:textfield label="%{getText('mailUsername')}"
|
||||
name="subscription.username"/>
|
||||
name="subscription.username"/>
|
||||
<s:textfield label="%{getText('mailPassword')}"
|
||||
name="subscription.password"/>
|
||||
name="subscription.password"/>
|
||||
<s:select label="%{getText('mailServerType')}"
|
||||
name="subscription.type" list="types"/>
|
||||
name="subscription.type" list="types"/>
|
||||
<s:checkbox label="%{getText('autoConnect')}"
|
||||
name="subscription.autoConnect"/>
|
||||
name="subscription.autoConnect"/>
|
||||
<s:submit value="%{getText('button.save')}"/>
|
||||
<s:reset value="%{getText('button.reset')}"/>
|
||||
</s:else>
|
||||
|
||||
<s:submit action="Registration!input"
|
||||
value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
<s:submit action="MainMenu"
|
||||
value="%{getText('button.cancel')}"
|
||||
onclick="form.onsubmit=null"/>
|
||||
</s:form>
|
||||
|
||||
<jsp:include page="Footer.jsp"/>
|
||||
|
||||
@@ -14,10 +14,14 @@
|
||||
<h3><s:text name="index.heading"/></h3>
|
||||
|
||||
<ul>
|
||||
<li><a href="<s:url action="Registration!input"/>"><s:text
|
||||
name="index.registration"/></a></li>
|
||||
<li><a href="<s:url action="Logon!input"/>"><s:text
|
||||
name="index.logon"/></a></li>
|
||||
<li>
|
||||
<s:url id="Input" action="Input" namespace="/registration"/>
|
||||
<s:a href="%{Input}"><s:text name="index.registration"/></s:a>
|
||||
</li>
|
||||
<li>
|
||||
<s:url id="Logon" action="Logon"/>
|
||||
<s:a href="%{Logon}"><s:text name="index.logon"/></s:a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Language Options</h3>
|
||||
@@ -29,25 +33,31 @@
|
||||
<s:a href="%{en}">English</s:a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<s:url action="Welcome">
|
||||
<s:url id="ja" action="Welcome">
|
||||
<s:param name="request_locale">ja</s:param>
|
||||
</s:url>">Japanese</a>
|
||||
</li>
|
||||
</s:url>
|
||||
<s:a href="%{ja}">Japanese</s:a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<s:url value="Welcome.do">
|
||||
<s:param name="request_locale" value="'ru'" />
|
||||
</s:url>">Russian</a>
|
||||
<s:url id="ru" action="Welcome">
|
||||
<s:param name="request_locale">ru</s:param>
|
||||
</s:url>
|
||||
<s:a href="%{ru}">Russian</s:a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr/>
|
||||
|
||||
<p><s:i18n name="alternate">
|
||||
<img src="<s:text name="struts.logo.path"/>"
|
||||
alt="<s:text name="struts.logo.alt"/>"/>
|
||||
</s:i18n></p>
|
||||
<p>
|
||||
<s:i18n name="alternate">
|
||||
<img src="<s:text name="struts.logo.path"/>"
|
||||
alt="<s:text name="struts.logo.alt"/>"/>
|
||||
</s:i18n>
|
||||
</p>
|
||||
|
||||
<p><a href="<s:url action="Tour" />"><s:text name="index.tour"/></a></p>
|
||||
<p>
|
||||
<s:url id="Tour" action="Tour"/><s:a href="%{Tour}"><s:text name="index.tour"/></s:a>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@ public class BaseSqlMapTest extends TestCase {
|
||||
|
||||
protected SqlMapClient sqlMap;
|
||||
|
||||
protected void initSqlMap(String configFile, Properties props) throws Exception {
|
||||
protected void initSqlMap(String configFile, Properties props) throws Exception {
|
||||
Reader reader = Resources.getResourceAsReader(configFile);
|
||||
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
|
||||
reader.close();
|
||||
|
||||
@@ -48,47 +48,47 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
input = new AppData();
|
||||
input = new AppData();
|
||||
}
|
||||
|
||||
public void testLOCALE_LIST() throws Exception {
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.LOCALE_LIST,null);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.LOCALE_LIST, null);
|
||||
assertNotNull(output);
|
||||
}
|
||||
|
||||
public void testREGISTRATION_INSERT_ASSERT_fail() throws Exception {
|
||||
input.setUsername(username);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected user to already exist",count.intValue()>0);
|
||||
assertTrue("Expected user to already exist", count.intValue() > 0);
|
||||
}
|
||||
|
||||
public void testREGISTRATION_INSERT_ASSERT() throws Exception {
|
||||
input.setUsername(username2);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.REGISTRATION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Did not expected user to exist",count.intValue()==0);
|
||||
assertTrue("Did not expected user to exist", count.intValue() == 0);
|
||||
}
|
||||
|
||||
public void testREGISTRATION_INSERT() throws Exception {
|
||||
input.setRegistration_key(registration_key2);
|
||||
input.setLocale_key(locale_key);
|
||||
input.setUsername(username2);
|
||||
input.setPassword(password2 );
|
||||
input.setPassword(password2);
|
||||
input.setFullname(fullname2);
|
||||
input.setEmail_from(email_from2);
|
||||
input.setEmail_replyto(email_replyto2);
|
||||
sqlMap.insert(Constants.REGISTRATION_INSERT,input);
|
||||
sqlMap.insert(Constants.REGISTRATION_INSERT, input);
|
||||
// Trust but verify
|
||||
input.setPassword(null);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD,input);
|
||||
assertEquals(password2,output.getPassword());
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD, input);
|
||||
assertEquals(password2, output.getPassword());
|
||||
}
|
||||
|
||||
public void testREGISTRATION_PASSWORD() throws Exception {
|
||||
public void testREGISTRATION_PASSWORD() throws Exception {
|
||||
input.setUsername(username);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD,input);
|
||||
assertEquals(password,output.getPassword());
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD, input);
|
||||
assertEquals(password, output.getPassword());
|
||||
}
|
||||
|
||||
public void testREGISTRATION_FULLNAME() throws Exception {
|
||||
@@ -96,13 +96,13 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_FULLNAME, input);
|
||||
assertEquals(fullname, output.getFullname());
|
||||
assertNull("Expected other fields to be null", output.getPassword());
|
||||
assertNull("Expected other fields to be null",output.getEmail_from());
|
||||
assertNull("Expected other fields to be null", output.getEmail_from());
|
||||
}
|
||||
|
||||
public void testREGISTRATION_EDIT() throws Exception {
|
||||
input.setRegistration_key(registration_key);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_EDIT, input);
|
||||
assertNotNull("Registration not found!",output);
|
||||
assertNotNull("Support not found!", output);
|
||||
assertEquals(fullname, output.getFullname());
|
||||
assertEquals(email_from, output.getEmail_from());
|
||||
assertEquals(email_replyto, output.getEmail_replyto());
|
||||
@@ -111,36 +111,36 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
public void testREGISTRATION_UPDATE() throws Exception {
|
||||
input.setRegistration_key(registration_key);
|
||||
input.setUsername(username2);
|
||||
input.setPassword(password2 );
|
||||
input.setPassword(password2);
|
||||
input.setFullname(fullname2);
|
||||
input.setEmail_from(email_from2);
|
||||
input.setEmail_replyto(email_replyto2);
|
||||
sqlMap.update(Constants.REGISTRATION_UPDATE,input);
|
||||
sqlMap.update(Constants.REGISTRATION_UPDATE, input);
|
||||
// Trust but verify
|
||||
input.setPassword(null);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD,input);
|
||||
assertEquals(password2,output.getPassword());
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.REGISTRATION_PASSWORD, input);
|
||||
assertEquals(password2, output.getPassword());
|
||||
}
|
||||
|
||||
public void testREGISTRATION_UPDATE_fails() throws Exception {
|
||||
input.setRegistration_key(null);
|
||||
sqlMap.update(Constants.REGISTRATION_UPDATE,input);
|
||||
sqlMap.update(Constants.REGISTRATION_UPDATE, input);
|
||||
}
|
||||
|
||||
public void testSUBSCRIPTION_INSERT_ASSERT_fail() throws Exception {
|
||||
input.setRegistration_key(registration_key);
|
||||
input.setSubscription_host(subscription_host);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected subscription to already exist",count.intValue()>0);
|
||||
assertTrue("Expected subscription to already exist", count.intValue() > 0);
|
||||
}
|
||||
|
||||
public void SUBSCRIPTION_INSERT_ASSERT() throws Exception {
|
||||
input.setSubscription_key(subscription_key2);
|
||||
input.setSubscription_host(subscription_host2);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Did not expect subscription to exist",count.intValue()==0);
|
||||
assertTrue("Did not expect subscription to exist", count.intValue() == 0);
|
||||
}
|
||||
|
||||
public void testSUBSCRIPTION_INSERT() throws Exception {
|
||||
@@ -151,27 +151,27 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
input.setHost_user(host_user2);
|
||||
input.setHost_pass(host_pass2);
|
||||
input.setHost_auto(host_auto2);
|
||||
sqlMap.insert(Constants.SUBSCRIPTION_INSERT,input);
|
||||
sqlMap.insert(Constants.SUBSCRIPTION_INSERT, input);
|
||||
// Trust but verify
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected subscription to NOW exist",count.intValue()>0);
|
||||
assertTrue("Expected subscription to NOW exist", count.intValue() > 0);
|
||||
}
|
||||
|
||||
private void assertSubscription(AppData output) throws Exception {
|
||||
assertEquals(host_user, output.getHost_user());
|
||||
assertEquals(host_pass, output.getHost_pass());
|
||||
assertEquals(protocol_name, output.getProtocol_name());
|
||||
assertEquals(host_auto,output.getHost_auto());
|
||||
assertFalse(output.isHost_auto_checkbox());
|
||||
}
|
||||
private void assertSubscription(AppData output) throws Exception {
|
||||
assertEquals(host_user, output.getHost_user());
|
||||
assertEquals(host_pass, output.getHost_pass());
|
||||
assertEquals(protocol_name, output.getProtocol_name());
|
||||
assertEquals(host_auto, output.getHost_auto());
|
||||
assertFalse(output.isHost_auto_checkbox());
|
||||
}
|
||||
|
||||
public void testSUBSCRIPTION_LIST() throws Exception {
|
||||
input.setRegistration_key(registration_key);
|
||||
Object output = sqlMap.queryForList(Constants.SUBSCRIPTION_LIST,input);
|
||||
assertNotNull("Query failed!",output);
|
||||
Object output = sqlMap.queryForList(Constants.SUBSCRIPTION_LIST, input);
|
||||
assertNotNull("Query failed!", output);
|
||||
List list = (List) output;
|
||||
assertEquals(SAMPLE_SIZE,list.size());
|
||||
assertEquals(SAMPLE_SIZE, list.size());
|
||||
AppData row1 = (AppData) list.get(0);
|
||||
assertSubscription(row1);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
public void testSUBSCRIPTION_EDIT() throws Exception {
|
||||
input.setSubscription_key(subscription_key);
|
||||
AppData output = (AppData) sqlMap.queryForObject(Constants.SUBSCRIPTION_EDIT, input);
|
||||
assertNotNull("Subscription not found!",output);
|
||||
assertNotNull("Support not found!", output);
|
||||
assertSubscription(output);
|
||||
}
|
||||
|
||||
@@ -191,11 +191,11 @@ public class SqlMapTest extends BaseSqlMapTest {
|
||||
input.setHost_user(host_user2);
|
||||
input.setHost_pass(host_pass2);
|
||||
input.setHost_auto(host_auto2);
|
||||
sqlMap.update(Constants.SUBSCRIPTION_UPDATE,input);
|
||||
sqlMap.update(Constants.SUBSCRIPTION_UPDATE, input);
|
||||
// Trust but verify
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT,input);
|
||||
Object output = sqlMap.queryForObject(Constants.SUBSCRIPTION_INSERT_ASSERT, input);
|
||||
Long count = (Long) output;
|
||||
assertTrue("Expected subscription to exist",count.intValue()>0);
|
||||
assertTrue("Expected subscription to exist", count.intValue() > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user