| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Alfresco
Revision: 2854
Author: jsant
Date: 02 Sep 2008 14:55:42
Changes:refactored some of the admin-tool's jsps.
Scriplet code moved to AdminUtils.java so that it can later be unit-tested.
Also moved all param name strings and values into Constants.java so that small typos don't throw off the app.
| ... | ...@@ -0,0 +1,39 @@ | |
| 1 | package org.alfresco.extranet; | |
| 2 | ||
| 3 | /** | |
| 4 | * Constants used throughout the app | |
| 5 | * | |
| 6 | * @author jsant | |
| 7 | */ | |
| 8 | public class Constants { | |
| 9 | public static final String ADMIN_TOOLS_COMMAND = "command"; | |
| 10 | public static final String ADMIN_TOOLS_DISPATCH_TO = "dispatchTo"; | |
| 11 | public static final String ADMIN_TOOLS_P = "p"; | |
| 12 | ||
| 13 | ||
| 14 | // parameter values that are used with the "dispatchTo" parameter name | |
| 15 | public static final String ADMIN_TOOLS = "admin-tools"; | |
| 16 | public static final String ADMIN_TOOLS_DISPATCH_TO_ENTITY_ADD = "admin-entities-add"; | |
| 17 | public static final String ADMIN_TOOLS_DISPATCH_TO_ENTITY_EDIT = "admin-entities-edit"; | |
| 18 | public static final String ADMIN_TOOLS_DISPATCH_TO_INVITE_USER = "admin-invite-user"; | |
| 19 | ||
| 20 | // parameter values that are used with the "comand" parameter name | |
| 21 | public static final String ADMIN_TOOLS_COMMAND_INVITE_USER = "inviteUser"; | |
| 22 | public static final String ADMIN_TOOLS_COMMAND_SAVE = "save"; | |
| 23 | ||
| 24 | // parameter names used in the inviteUser action | |
| 25 | public static final String ADMIN_TOOLS_USER_ID = "userId"; | |
| 26 | public static final String ADMIN_TOOLS_FIRST_NAME = "firstName"; | |
| 27 | public static final String ADMIN_TOOLS_LAST_NAME = "lastName"; | |
| 28 | public static final String ADMIN_TOOLS_EMAIL = "email"; | |
| 29 | public static final String ADMIN_TOOLS_WHD_USER_ID = "whdUserId"; | |
| 30 | public static final String ADMIN_TOOLS_ALFRESCO_USER_ID = "alfrescoUserId"; | |
| 31 | public static final String ADMIN_TOOLS_SUBSCRIPTION_START = "subscriptionStart"; | |
| 32 | public static final String ADMIN_TOOLS_SUBSCRIPTION_END = "subscriptionEnd"; | |
| 33 | public static final String ADMIN_TOOLS_INVITATION_TYPE ="invitationType"; | |
| 34 | public static final String ADMIN_TOOLS_INVITATION_ENTERPRISE = "enterprise"; | |
| 35 | public static final String ADMIN_TOOLS_INVITATION_EMPLOYEE = "employee"; | |
| 36 | public static final String ADMIN_TOOLS_ENTITY_TYPE = "entity_type"; | |
| 37 | ||
| 38 | public static final String ADMIN_TOOLS_SELECTED_ID = "selectedId"; | |
| 39 | } |
| ... | ...@@ -11,64 +11,42 @@ | |
| 11 | 11 | <%@ taglib uri="/WEB-INF/tlds/alf.tld" prefix="alf" %> |
| 12 | 12 | <% |
| 13 | 13 | // safety check |
| 14 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 15 | if(user == null || !user.isAdmin()) | |
| 14 | AdminUtil admin = new AdminUtil(request); | |
| 15 | if( !admin.isAuthorizedAdmin()) | |
| 16 | 16 | { |
| 17 | //TODO: replace with redirect and error message | |
| 17 | 18 | out.println("Access denied"); |
| 18 | 19 | return; |
| 19 | 20 | } |
| 20 | %> | |
| 21 | <% | |
| 22 | // select the entity type | |
| 23 | String entityType = request.getParameter("entity_type"); | |
| 24 | ||
| 25 | // get the appropriate entity service | |
| 26 | EntityService entityService = ExtranetHelper.getEntityService(request, entityType); | |
| 27 | ||
| 28 | // properties | |
| 29 | String entityTitle = entityType; | |
| 30 | String[] propertyNames = ExtranetHelper.getEntityPropertyNames(entityType); | |
| 31 | String entityClassName = ExtranetHelper.getEntityClassName(entityType); | |
| 32 | ||
| 33 | // command processing | |
| 34 | String command = request.getParameter("command"); | |
| 35 | if("save".equals(command)) | |
| 36 | { | |
| 37 | String userId = request.getParameter("userId"); | |
| 38 | ||
| 39 | // new entity | |
| 40 | Entity entity = ExtranetHelper.newEntity(entityType, userId); | |
| 41 | ||
| 42 | // set properties | |
| 43 | for(int i = 0; i < propertyNames.length; i++) | |
| 44 | { | |
| 45 | String value = request.getParameter(propertyNames[i]); | |
| 46 | entity.setProperty(propertyNames[i], value); | |
| 47 | } | |
| 48 | ||
| 49 | // add | |
| 50 | entityService.insert(entity); | |
| 51 | ||
| 52 | out.println(entityTitle + " added!"); | |
| 53 | out.println("<br/>"); | |
| 54 | out.println("<a href='?p=admin-tools&dispatchTo=admin-entities'>Entities</a>"); | |
| 55 | ||
| 56 | return; | |
| 57 | } | |
| 21 | ||
| 22 | // select the entity type | |
| 23 | String entityType = request.getParameter(Constants.ADMIN_TOOLS_ENTITY_TYPE); | |
| 24 | ||
| 25 | ||
| 26 | // properties | |
| 27 | String entityTitle = entityType; | |
| 28 | String[] propertyNames = ExtranetHelper.getEntityPropertyNames(entityType); | |
| 29 | ||
| 30 | String result = admin.addEntity(entityType, entityTitle, propertyNames); | |
| 31 | if( result != null ) | |
| 32 | { | |
| 33 | out.println( result); | |
| 34 | return; | |
| 35 | } | |
| 58 | 36 | %> |
| 59 | 37 | <html> |
| 60 | 38 | <head><title>Add <%=entityTitle%></title></head> |
| 61 | 39 | <body> |
| 62 | 40 | <form method="POST" action="/extranet/"> |
| 63 | <input type="hidden" name="p" value="admin-tools"/> | |
| 64 | <input type="hidden" name="dispatchTo" value="admin-entities-add"/> | |
| 65 | <input type="hidden" name="entity_type" value="<%=entityType%>"/> | |
| 41 | <input type="hidden" name="p" value="<%=Constants.ADMIN_TOOLS%>"/> | |
| 42 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_DISPATCH_TO%>" value="<%=Constants.ADMIN_TOOLS_DISPATCH_TO_ENTITY_ADD%>"/> | |
| 43 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_ENTITY_TYPE%>" value="<%=entityType%>"/> | |
| 66 | 44 | |
| 67 | 45 | <table> |
| 68 | 46 | <% |
| 69 | 47 | for(int i = 0; i < propertyNames.length; i++) |
| 70 | 48 | { |
| 71 | %> | |
| 49 | %> | |
| 72 | 50 | <tr> |
| 73 | 51 | <td><%=propertyNames[i]%></td> |
| 74 | 52 | <td> |
| ... | ...@@ -79,10 +57,10 @@ | |
| 79 | 57 | } |
| 80 | 58 | %> |
| 81 | 59 | </table> |
| 82 | ||
| 83 | <input type="submit" value="save" name="command" /> | |
| 60 | ||
| 61 | <input type="submit" value="save" name="<%=Constants.ADMIN_TOOLS_COMMAND%>" /> | |
| 84 | 62 | <input type="button" value="cancel" onclick="window.location.href='?p=admin-tools&dispatchTo=admin-entities';" /> |
| 85 | 63 | </form> |
| 86 | ||
| 64 | ||
| 87 | 65 | </body> |
| 88 | 66 | </html> |
| ... | ...@@ -12,79 +12,25 @@ | |
| 12 | 12 | <%@ taglib uri="/WEB-INF/tlds/alf.tld" prefix="alf" %> |
| 13 | 13 | <% |
| 14 | 14 | // safety check |
| 15 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 16 | if(user == null || !user.isAdmin()) | |
| 15 | AdminUtil admin = new AdminUtil(request); | |
| 16 | if( !admin.isAuthorizedAdmin()) | |
| 17 | 17 | { |
| 18 | //TODO: replace with redirect and error message | |
| 18 | 19 | out.println("Access denied"); |
| 19 | 20 | return; |
| 20 | 21 | } |
| 21 | %> | |
| 22 | <%! | |
| 23 | public String nullAssert(String value) | |
| 24 | { | |
| 25 | if(value != null && value.length() == 0) | |
| 26 | { | |
| 27 | value = null; | |
| 28 | } | |
| 29 | ||
| 30 | return value; | |
| 31 | } | |
| 32 | %> | |
| 33 | <% | |
| 34 | // get services | |
| 35 | InvitationService invitationService = ExtranetHelper.getInvitationService(request); | |
| 36 | ||
| 37 | // command processor | |
| 38 | String command = request.getParameter("command"); | |
| 39 | if("inviteUser".equals(command)) | |
| 40 | { | |
| 41 | String userId = request.getParameter("userId"); | |
| 42 | String firstName = nullAssert(request.getParameter("firstName")); | |
| 43 | String lastName = nullAssert(request.getParameter("lastName")); | |
| 44 | String email = nullAssert(request.getParameter("email")); | |
| 45 | String whdUserId = nullAssert(request.getParameter("whdUserId")); | |
| 46 | String alfrescoUserId = nullAssert(request.getParameter("alfrescoUserId")); | |
| 47 | ||
| 48 | String subscriptionStart = nullAssert(request.getParameter("subscriptionStart")); | |
| 49 | String subscriptionEnd = nullAssert(request.getParameter("subscriptionEnd")); | |
| 50 | ||
| 51 | // we only handle enterprise invitation types for the moment | |
| 52 | String invitationType = nullAssert(request.getParameter("invitationType")); | |
| 53 | if("enterprise".equals(invitationType) || "employee".equals(invitationType)) | |
| 54 | { | |
| 55 | // build date objects | |
| 56 | Date subscriptionStartDate = null; | |
| 57 | if(subscriptionStart != null) | |
| 58 | { | |
| 59 | subscriptionStartDate = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse(subscriptionStart); | |
| 60 | System.out.println("Original Start Date: " + subscriptionStart); | |
| 61 | System.out.println("New Start Date: " + subscriptionStartDate); | |
| 62 | } | |
| 63 | Date subscriptionEndDate = null; | |
| 64 | if(subscriptionEnd != null) | |
| 65 | { | |
| 66 | subscriptionEndDate = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse(subscriptionEnd); | |
| 67 | System.out.println("Original End Date: " + subscriptionEnd); | |
| 68 | System.out.println("New End Date: " + subscriptionEndDate); | |
| 69 | } | |
| 70 | ||
| 71 | // invite the user | |
| 72 | DatabaseInvitedUser invitedUser = invitationService.inviteUser(userId, firstName, lastName, email, whdUserId, alfrescoUserId, "enterprise", subscriptionStartDate, subscriptionEndDate); | |
| 73 | if(invitedUser != null) | |
| 74 | { | |
| 75 | out.println("Invitation was created!"); | |
| 76 | return; | |
| 77 | } | |
| 78 | } | |
| 79 | } | |
| 22 | ||
| 23 | ||
| 24 | String invitationResult = admin.inviteUser(); | |
| 25 | out.println( invitationResult ); | |
| 80 | 26 | %> |
| 81 | 27 | <html> |
| 82 | 28 | <head> |
| 83 | 29 | <title>Invite a User</title> |
| 84 | 30 | </head> |
| 85 | 31 | <body> |
| 86 | ||
| 87 | ||
| 32 | ||
| 33 | ||
| 88 | 34 | <SCRIPT LANGUAGE="javascript"> |
| 89 | 35 | { |
| 90 | 36 | self.name="BODY" |
| ... | ...@@ -95,54 +41,55 @@ | |
| 95 | 41 | </SCRIPT> |
| 96 | 42 | <script language='javascript' src='/extranet/components/extranet/datepicker/popcalendar.js'></script> |
| 97 | 43 | |
| 98 | ||
| 44 | ||
| 99 | 45 | <form method="POST" action="/extranet/"> |
| 100 | <input type="hidden" name="p" value="admin-tools"/> | |
| 101 | <input type="hidden" name="dispatchTo" value="admin-invite-user"/> | |
| 46 | <input type="hidden" name="p" value="<%=Constants.ADMIN_TOOLS%>"/> | |
| 47 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_DISPATCH_TO%>" | |
| 48 | value="<%=Constants.ADMIN_TOOLS_DISPATCH_TO_INVITE_USER%>"/> | |
| 102 | 49 | |
| 103 | 50 | <table> |
| 104 | 51 | <tr> |
| 105 | 52 | <td>User ID</td> |
| 106 | 53 | <td> |
| 107 | <input name="userId" type="text"/> | |
| 54 | <input name="<%=Constants.ADMIN_TOOLS_USER_ID%>" type="text"/> | |
| 108 | 55 | </td> |
| 109 | 56 | </tr> |
| 110 | 57 | <tr> |
| 111 | 58 | <td>First Name</td> |
| 112 | 59 | <td> |
| 113 | <input name="firstName" type="text"/> | |
| 60 | <input name="<%=Constants.ADMIN_TOOLS_FIRST_NAME%>" type="text"/> | |
| 114 | 61 | </td> |
| 115 | 62 | </tr> |
| 116 | 63 | <tr> |
| 117 | 64 | <td>Last Name</td> |
| 118 | 65 | <td> |
| 119 | <input name="lastName" type="text"/> | |
| 66 | <input name="<%=Constants.ADMIN_TOOLS_LAST_NAME%>" type="text"/> | |
| 120 | 67 | </td> |
| 121 | 68 | </tr> |
| 122 | 69 | <tr> |
| 123 | 70 | <td>Email</td> |
| 124 | 71 | <td> |
| 125 | <input name="email" type="text"/> | |
| 72 | <input name="<%=Constants.ADMIN_TOOLS_EMAIL%>" type="text"/> | |
| 126 | 73 | </td> |
| 127 | 74 | </tr> |
| 128 | 75 | <tr> |
| 129 | 76 | <td>Web Helpdesk User ID</td> |
| 130 | 77 | <td> |
| 131 | <input name="whdUserId" type="text"/> | |
| 78 | <input name="<%=Constants.ADMIN_TOOLS_WHD_USER_ID%>" type="text"/> | |
| 132 | 79 | </td> |
| 133 | 80 | </tr> |
| 134 | 81 | <tr> |
| 135 | 82 | <td>Alfresco User ID</td> |
| 136 | 83 | <td> |
| 137 | <input name="alfrescoUserId" type="text"/> | |
| 84 | <input name="<%=Constants.ADMIN_TOOLS_ALFRESCO_USER_ID%>" type="text"/> | |
| 138 | 85 | </td> |
| 139 | 86 | </tr> |
| 140 | 87 | <tr> |
| 141 | 88 | <td>Invitation Type</td> |
| 142 | 89 | <td> |
| 143 | <select name="invitationType"> | |
| 144 | <option value="enterprise">Supported Enterprise Customer</option> | |
| 145 | <option value="employee">Alfresco Employee</option> | |
| 90 | <select name="<%=Constants.ADMIN_TOOLS_INVITATION_TYPE%>"> | |
| 91 | <option value="<%=Constants.ADMIN_TOOLS_INVITATION_ENTERPRISE%>">Supported Enterprise Customer</option> | |
| 92 | <option value="<%=Constants.ADMIN_TOOLS_INVITATION_EMPLOYEE%>">Alfresco Employee</option> | |
| 146 | 93 | <!-- |
| 147 | 94 | <option value="enterprise_trial">Enterprise Trial</option> |
| 148 | 95 | <option value="community">Community</option> |
| ... | ...@@ -153,25 +100,25 @@ | |
| 153 | 100 | <tr> |
| 154 | 101 | <td>Subscription Start</td> |
| 155 | 102 | <td> |
| 156 | <input type="text" name="subscriptionStart" id="subscriptionStart" value=""/> | |
| 157 | <img src="/extranet/components/extranet/datepicker/calendaricon.gif" height="17" width="17" border="0" onClick="popUpCalendar(this, document.getElementById('subscriptionStart'), 'm/dd/yyyy', 0, 0)"/> | |
| 103 | <input type="text" name="<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_START%>" id="<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_START%>" value=""/> | |
| 104 | <img src="/extranet/components/extranet/datepicker/calendaricon.gif" height="17" width="17" border="0" onClick="popUpCalendar(this, document.getElementById('<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_START%>'), 'm/dd/yyyy', 0, 0)"/> | |
| 158 | 105 | (m/dd/yyyy) |
| 159 | 106 | </td> |
| 160 | 107 | </tr> |
| 161 | 108 | <tr> |
| 162 | 109 | <td>Subscription End</td> |
| 163 | 110 | <td> |
| 164 | <input type="text" name="subscriptionEnd" id="subscriptionEnd" value=""/> | |
| 165 | <img src="/extranet/components/extranet/datepicker/calendaricon.gif" height="17" width="17" border="0" onClick="popUpCalendar(this, document.getElementById('subscriptionEnd'), 'm/dd/yyyy', 0, 0)"/> | |
| 111 | <input type="text" name="<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_END%>" id="<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_END%>" value=""/> | |
| 112 | <img src="/extranet/components/extranet/datepicker/calendaricon.gif" height="17" width="17" border="0" onClick="popUpCalendar(this, document.getElementById('<%=Constants.ADMIN_TOOLS_SUBSCRIPTION_END%>'), 'm/dd/yyyy', 0, 0)"/> | |
| 166 | 113 | (m/dd/yyyy) |
| 167 | 114 | </td> |
| 168 | 115 | </tr> |
| 169 | 116 | </table> |
| 170 | ||
| 171 | <input type="hidden" name="command" value="inviteUser"/> | |
| 117 | ||
| 118 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_COMMAND%>" value="<%=Constants.ADMIN_TOOLS_COMMAND_INVITE_USER%>"/> | |
| 172 | 119 | <br/> |
| 173 | 120 | <input type="submit" value="Invite"/> |
| 174 | 121 | </form> |
| 175 | ||
| 122 | ||
| 176 | 123 | </body> |
| 177 | 124 | </html> |
| ... | ...@@ -11,10 +11,11 @@ | |
| 11 | 11 | <%@ page isELIgnored="false" %> |
| 12 | 12 | <%@ taglib uri="/WEB-INF/tlds/alf.tld" prefix="alf" %> |
| 13 | 13 | <% |
| 14 | // safety check | |
| 15 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 16 | if(user == null || !user.isAdmin()) | |
| 14 | // safety check | |
| 15 | AdminUtil admin = new AdminUtil(request); | |
| 16 | if( !admin.isAuthorizedAdmin()) | |
| 17 | 17 | { |
| 18 | //TODO: replace with redirect and error message | |
| 18 | 19 | out.println("Access denied"); |
| 19 | 20 | return; |
| 20 | 21 | } |
| ... | ...@@ -24,7 +25,7 @@ | |
| 24 | 25 | <title>Show Pending Invited Users</title> |
| 25 | 26 | </head> |
| 26 | 27 | <body> |
| 27 | ||
| 28 | ||
| 28 | 29 | <table> |
| 29 | 30 | <tr> |
| 30 | 31 | <td>User ID</td> |
| ... | ...@@ -37,14 +38,14 @@ | |
| 37 | 38 | <% |
| 38 | 39 | // get services |
| 39 | 40 | InvitationService invitationService = ExtranetHelper.getInvitationService(request); |
| 40 | ||
| 41 | ||
| 41 | 42 | List invitedUsers = invitationService.list(); |
| 42 | 43 | for(int i = 0; i < invitedUsers.size(); i++) |
| 43 | 44 | { |
| 44 | 45 | DatabaseInvitedUser dbUser = (DatabaseInvitedUser) invitedUsers.get(i); |
| 45 | 46 | if(!dbUser.isCompleted()) |
| 46 | 47 | { |
| 47 | ||
| 48 | ||
| 48 | 49 | %> |
| 49 | 50 | <tr> |
| 50 | 51 | <td> |
| ... | ...@@ -73,6 +74,6 @@ | |
| 73 | 74 | %> |
| 74 | 75 | |
| 75 | 76 | </table> |
| 76 | ||
| 77 | ||
| 77 | 78 | </body> |
| 78 | 79 | </html> |
| ... | ...@@ -0,0 +1,166 @@ | |
| 1 | package org.alfresco.extranet; | |
| 2 | ||
| 3 | import org.alfresco.web.site.exception.RequestContextException; | |
| 4 | import org.alfresco.extranet.database.DatabaseInvitedUser; | |
| 5 | ||
| 6 | import javax.servlet.http.HttpServletRequest; | |
| 7 | import java.util.Locale; | |
| 8 | import java.util.Date; | |
| 9 | import java.text.SimpleDateFormat; | |
| 10 | import java.text.DateFormat; | |
| 11 | import java.text.ParseException; | |
| 12 | ||
| 13 | /** | |
| 14 | * Utility class for the admin-tools functionality. | |
| 15 | * This way we have something to unit test. | |
| 16 | * | |
| 17 | * @author jsant | |
| 18 | */ | |
| 19 | public class AdminUtil { | |
| 20 | HttpServletRequest request; | |
| 21 | ||
| 22 | public AdminUtil(HttpServletRequest request) { | |
| 23 | this.request = request; | |
| 24 | } | |
| 25 | ||
| 26 | /** | |
| 27 | * Check if this user is authorized to see the admin-tools section or not | |
| 28 | * @return true if authorized with admin status, false otherise | |
| 29 | * @throws RequestContextException | |
| 30 | */ | |
| 31 | public boolean isAuthorizedAdmin() throws RequestContextException | |
| 32 | { | |
| 33 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 34 | return user != null && user.isAdmin(); | |
| 35 | } | |
| 36 | ||
| 37 | ||
| 38 | /** | |
| 39 | * assign the value to null if it has no characters | |
| 40 | * @param value the value to check | |
| 41 | * @return the original no-zero-length value, or null | |
| 42 | */ | |
| 43 | public String nullAssert(String value) | |
| 44 | { | |
| 45 | if(value != null && value.length() == 0) | |
| 46 | { | |
| 47 | value = null; | |
| 48 | } | |
| 49 | ||
| 50 | return value; | |
| 51 | } | |
| 52 | ||
| 53 | ||
| 54 | /** | |
| 55 | * Generates a Network invitation based on the parameters found in the request | |
| 56 | * @return a String containing a reults message to be displyed in the browser | |
| 57 | * @throws ParseException | |
| 58 | */ | |
| 59 | public String inviteUser() throws ParseException | |
| 60 | { | |
| 61 | String result = ""; | |
| 62 | // get services | |
| 63 | InvitationService invitationService = ExtranetHelper.getInvitationService(request); | |
| 64 | ||
| 65 | // command processor | |
| 66 | String command = request.getParameter(Constants.ADMIN_TOOLS_COMMAND); | |
| 67 | if(Constants.ADMIN_TOOLS_COMMAND_INVITE_USER.equals(command)) | |
| 68 | { | |
| 69 | result = "A problem occured generating the invitation. See error log."; | |
| 70 | ||
| 71 | String userId = request.getParameter(Constants.ADMIN_TOOLS_USER_ID); | |
| 72 | String firstName = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_FIRST_NAME)); | |
| 73 | String lastName = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_LAST_NAME)); | |
| 74 | String email = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_EMAIL)); | |
| 75 | String whdUserId = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_WHD_USER_ID)); | |
| 76 | String alfrescoUserId = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_ALFRESCO_USER_ID)); | |
| 77 | ||
| 78 | String subscriptionStart = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_SUBSCRIPTION_START)); | |
| 79 | String subscriptionEnd = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_SUBSCRIPTION_END)); | |
| 80 | ||
| 81 | // we only handle enterprise and employee invitation types for the moment | |
| 82 | String invitationType = nullAssert(request.getParameter(Constants.ADMIN_TOOLS_INVITATION_TYPE)); | |
| 83 | if(Constants.ADMIN_TOOLS_INVITATION_ENTERPRISE.equals(invitationType) || Constants.ADMIN_TOOLS_INVITATION_EMPLOYEE.equals(invitationType)) | |
| 84 | { | |
| 85 | // build date objects | |
| 86 | Date subscriptionStartDate = null; | |
| 87 | if(subscriptionStart != null) | |
| 88 | { | |
| 89 | subscriptionStartDate = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse(subscriptionStart); | |
| 90 | System.out.println("Original Start Date: " + subscriptionStart); | |
| 91 | System.out.println("New Start Date: " + subscriptionStartDate); | |
| 92 | } | |
| 93 | else | |
| 94 | { | |
| 95 | result = Constants.ADMIN_TOOLS_SUBSCRIPTION_START + " was null"; | |
| 96 | } | |
| 97 | ||
| 98 | Date subscriptionEndDate = null; | |
| 99 | if(subscriptionEnd != null) | |
| 100 | { | |
| 101 | subscriptionEndDate = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse(subscriptionEnd); | |
| 102 | System.out.println("Original End Date: " + subscriptionEnd); | |
| 103 | System.out.println("New End Date: " + subscriptionEndDate); | |
| 104 | } | |
| 105 | else | |
| 106 | { | |
| 107 | result = Constants.ADMIN_TOOLS_SUBSCRIPTION_END + " was null"; | |
| 108 | } | |
| 109 | ||
| 110 | ||
| 111 | // invite the user | |
| 112 | DatabaseInvitedUser invitedUser = invitationService.inviteUser(userId, firstName, lastName, email, whdUserId, alfrescoUserId, Constants.ADMIN_TOOLS_INVITATION_ENTERPRISE, subscriptionStartDate, subscriptionEndDate); | |
| 113 | if(invitedUser != null) | |
| 114 | { | |
| 115 | result = "Invitation was created!"; | |
| 116 | } | |
| 117 | } | |
| 118 | } | |
| 119 | return result; | |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Adds the given entity to the database | |
| 124 | * | |
| 125 | * @param entityType the type of entity | |
| 126 | * @param entityTitle the title of this entity | |
| 127 | * @param propertyNames the property names of the entity | |
| 128 | * @return message to be displayed in the JSP | |
| 129 | */ | |
| 130 | public String addEntity(String entityType, String entityTitle, String[] propertyNames) | |
| 131 | { | |
| 132 | String result = ""; | |
| 133 | ||
| 134 | // get the appropriate entity service | |
| 135 | EntityService entityService = ExtranetHelper.getEntityService(request, entityType); | |
| 136 | String entityClassName = ExtranetHelper.getEntityClassName(entityType); | |
| 137 | ||
| 138 | // command processing | |
| 139 | String command = request.getParameter(Constants.ADMIN_TOOLS_COMMAND); | |
| 140 | if(Constants.ADMIN_TOOLS_COMMAND_SAVE.equals(command)) | |
| 141 | { | |
| 142 | String userId = request.getParameter(Constants.ADMIN_TOOLS_USER_ID); | |
| 143 | ||
| 144 | // new entity | |
| 145 | Entity entity = ExtranetHelper.newEntity(entityType, userId); | |
| 146 | ||
| 147 | // set properties | |
| 148 | for(int i = 0; i < propertyNames.length; i++) | |
| 149 | { | |
| 150 | String value = request.getParameter(propertyNames[i]); | |
| 151 | entity.setProperty(propertyNames[i], value); | |
| 152 | } | |
| 153 | ||
| 154 | // add | |
| 155 | entityService.insert(entity); | |
| 156 | ||
| 157 | StringBuilder resultStringBuilder = new StringBuilder(); | |
| 158 | resultStringBuilder.append(entityTitle).append( " added!").append("<br/>/n"); | |
| 159 | resultStringBuilder.append("<a href='?p=admin-tools&dispatchTo=admin-entities'>Entities</a>"); | |
| 160 | result = resultStringBuilder.toString(); | |
| 161 | ||
| 162 | } | |
| 163 | return result; | |
| 164 | } | |
| 165 | ||
| 166 | } |
| ... | ...@@ -10,10 +10,11 @@ | |
| 10 | 10 | <%@ page isELIgnored="false" %> |
| 11 | 11 | <%@ taglib uri="/WEB-INF/tlds/alf.tld" prefix="alf" %> |
| 12 | 12 | <% |
| 13 | // safety check | |
| 14 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 15 | if(user == null || !user.isAdmin()) | |
| 13 | AdminUtil admin = new AdminUtil(request); | |
| 14 | // safety check | |
| 15 | if( !admin.isAuthorizedAdmin()) | |
| 16 | 16 | { |
| 17 | //TODO: redirect to front page with error message | |
| 17 | 18 | out.println("Access denied"); |
| 18 | 19 | return; |
| 19 | 20 | } |
| ... | ...@@ -25,25 +26,25 @@ | |
| 25 | 26 | { |
| 26 | 27 | entityType = AbstractUser.ENTITY_TYPE; |
| 27 | 28 | } |
| 28 | ||
| 29 | ||
| 29 | 30 | // get the appropriate entity service |
| 30 | 31 | EntityService entityService = ExtranetHelper.getEntityService(request, entityType); |
| 31 | ||
| 32 | ||
| 32 | 33 | // properties |
| 33 | 34 | String[] propertyNames = ExtranetHelper.getEntityPropertyNames(entityType); |
| 34 | 35 | String entityTitle = entityType; |
| 35 | ||
| 36 | ||
| 36 | 37 | // get a list of entities |
| 37 | 38 | List entityList = entityService.list(); |
| 38 | 39 | %> |
| 39 | 40 | <html> |
| 40 | 41 | <head><title><%=entityTitle%>s</title></head> |
| 41 | 42 | <body> |
| 42 | ||
| 43 | ||
| 43 | 44 | <form method="POST" action="/extranet/"> |
| 44 | 45 | <input type="hidden" name="p" value="admin-tools"/> |
| 45 | 46 | <input type="hidden" id="dispatchTo" name="dispatchTo" value="admin-entities"/> |
| 46 | ||
| 47 | ||
| 47 | 48 | <select name="entity_type" onchange="document.forms[0].submit()"> |
| 48 | 49 | <option <%=(AbstractUser.ENTITY_TYPE.equals(entityType) ? " selected " : "")%> value="<%=AbstractUser.ENTITY_TYPE%>">User</option> |
| 49 | 50 | <option <%=(AbstractGroup.ENTITY_TYPE.equals(entityType) ? " selected " : "")%> value="<%=AbstractGroup.ENTITY_TYPE%>">Group</option> |
| ... | ...@@ -57,12 +58,12 @@ | |
| 57 | 58 | for(int i = 0; i < propertyNames.length; i++) |
| 58 | 59 | { |
| 59 | 60 | %> |
| 60 | <td><%=propertyNames[i]%></td> | |
| 61 | <th><%=propertyNames[i]%></th> | |
| 61 | 62 | <% |
| 62 | 63 | } |
| 63 | 64 | %> |
| 64 | 65 | </tr> |
| 65 | ||
| 66 | ||
| 66 | 67 | <% |
| 67 | 68 | for(int i = 0; i < entityList.size(); i++) |
| 68 | 69 | { |
| ... | ...@@ -81,13 +82,13 @@ | |
| 81 | 82 | </tr> |
| 82 | 83 | <% |
| 83 | 84 | } |
| 84 | %> | |
| 85 | %> | |
| 85 | 86 | </table> |
| 86 | ||
| 87 | ||
| 87 | 88 | <input type="button" value="add_entity" onclick="document.getElementById('dispatchTo').value='admin-entities-add'; document.forms[0].submit()" /> |
| 88 | 89 | <input type="button" value="edit_entity" onclick="document.getElementById('dispatchTo').value='admin-entities-edit'; document.forms[0].submit()" /> |
| 89 | 90 | <input type="button" value="remove_entity" onclick="document.getElementById('dispatchTo').value='admin-entities-remove'; document.forms[0].submit()" /> |
| 90 | 91 | </form> |
| 91 | ||
| 92 | ||
| 92 | 93 | </body> |
| 93 | 94 | </html> |
| ... | ...@@ -10,21 +10,22 @@ | |
| 10 | 10 | <%@ page isELIgnored="false" %> |
| 11 | 11 | <%@ taglib uri="/WEB-INF/tlds/alf.tld" prefix="alf" %> |
| 12 | 12 | <% |
| 13 | // safety check | |
| 14 | org.alfresco.connector.User user = org.alfresco.web.site.RequestUtil.getRequestContext(request).getUser(); | |
| 15 | if(user == null || !user.isAdmin()) | |
| 13 | // safety check | |
| 14 | AdminUtil admin = new AdminUtil(request); | |
| 15 | if( !admin.isAuthorizedAdmin()) | |
| 16 | 16 | { |
| 17 | //TODO: replace with redirect and error message | |
| 17 | 18 | out.println("Access denied"); |
| 18 | 19 | return; |
| 19 | 20 | } |
| 20 | 21 | %> |
| 21 | 22 | <% |
| 22 | 23 | // get the selected object |
| 23 | String entityId = request.getParameter("selectedId"); | |
| 24 | ||
| 24 | String entityId = request.getParameter(Constants.ADMIN_TOOLS_SELECTED_ID); | |
| 25 | ||
| 25 | 26 | // select the entity type |
| 26 | String entityType = request.getParameter("entity_type"); | |
| 27 | ||
| 27 | String entityType = request.getParameter(Constants.ADMIN_TOOLS_ENTITY_TYPE); | |
| 28 | ||
| 28 | 29 | // get the appropriate entity service |
| 29 | 30 | EntityService entityService = ExtranetHelper.getEntityService(request, entityType); |
| 30 | 31 | |
| ... | ...@@ -32,10 +33,10 @@ | |
| 32 | 33 | Entity entity = entityService.get(entityId); |
| 33 | 34 | String entityTitle = entityType; |
| 34 | 35 | String[] propertyNames = ExtranetHelper.getEntityPropertyNames(entityType); |
| 35 | ||
| 36 | ||
| 36 | 37 | // command processing |
| 37 | String command = request.getParameter("command"); | |
| 38 | if("save".equals(command)) | |
| 38 | String command = request.getParameter(Constants.ADMIN_TOOLS_COMMAND); | |
| 39 | if(Constants.ADMIN_TOOLS_COMMAND_SAVE.equals(command)) | |
| 39 | 40 | { |
| 40 | 41 | // store properties onto entity |
| 41 | 42 | for(int i = 0; i < propertyNames.length; i++) |
| ... | ...@@ -46,14 +47,14 @@ | |
| 46 | 47 | entity.setProperty(propertyNames[i], value); |
| 47 | 48 | } |
| 48 | 49 | } |
| 49 | ||
| 50 | ||
| 50 | 51 | // update |
| 51 | 52 | entityService.update(entity); |
| 52 | ||
| 53 | ||
| 53 | 54 | out.println(entityTitle + " updated!"); |
| 54 | 55 | out.println("<br/>"); |
| 55 | 56 | out.println("<a href='?p=admin-tools&dispatchTo=admin-entities'>Entities</a>"); |
| 56 | ||
| 57 | ||
| 57 | 58 | return; |
| 58 | 59 | } |
| 59 | 60 | %> |
| ... | ...@@ -61,16 +62,16 @@ | |
| 61 | 62 | <head><title>Add <%=entityTitle%></title></head> |
| 62 | 63 | <body> |
| 63 | 64 | <form method="POST" action="/extranet/"> |
| 64 | <input type="hidden" name="p" value="admin-tools"/> | |
| 65 | <input type="hidden" name="dispatchTo" value="admin-entities-edit"/> | |
| 66 | <input type="hidden" name="entity_type" value="<%=entityType%>"/> | |
| 67 | <input type="hidden" name="selectedId" value="<%=entityId%>"/> | |
| 65 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_P%>" value="<%=Constants.ADMIN_TOOLS%>"/> | |
| 66 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_DISPATCH_TO%>" value="<%=Constants.ADMIN_TOOLS_DISPATCH_TO_ENTITY_EDIT%>"/> | |
| 67 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_ENTITY_TYPE%>" value="<%=entityType%>"/> | |
| 68 | <input type="hidden" name="<%=Constants.ADMIN_TOOLS_SELECTED_ID%>" value="<%=entityId%>"/> | |
| 68 | 69 | |
| 69 | 70 | <table> |
| 70 | 71 | <% |
| 71 | 72 | for(int i = 0; i < propertyNames.length; i++) |
| 72 | 73 | { |
| 73 | %> | |
| 74 | %> | |
| 74 | 75 | <tr> |
| 75 | 76 | <td><%=propertyNames[i]%></td> |
| 76 | 77 | <td> |
| ... | ...@@ -81,10 +82,10 @@ | |
| 81 | 82 | } |
| 82 | 83 | %> |
| 83 | 84 | </table> |
| 84 | ||
| 85 | <input type="submit" value="save" name="command" /> | |
| 85 | ||
| 86 | <input type="submit" value="<%=Constants.ADMIN_TOOLS_COMMAND_SAVE%>" name="<%=Constants.ADMIN_TOOLS_COMMAND%>" /> | |
| 86 | 87 | <input type="button" value="cancel" onclick="window.location.href='?p=admin-tools&dispatchTo=admin-entities';" /> |
| 87 | 88 | </form> |
| 88 | ||
| 89 | ||
| 89 | 90 | </body> |
| 90 | 91 | </html> |