TAVERNA-988: Removed user registration mechanism This should not be needed for ASF distributed software
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/commit/08af5c4f Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/tree/08af5c4f Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/diff/08af5c4f Branch: refs/heads/master Commit: 08af5c4f70f3c83f4322770c13438ad97313f600 Parents: 7e375f8 Author: Stian Soiland-Reyes <[email protected]> Authored: Thu Jul 14 15:08:26 2016 +0100 Committer: Stian Soiland-Reyes <[email protected]> Committed: Thu Jul 14 15:10:55 2016 +0100 ---------------------------------------------------------------------- .../workbench/ui/impl/UserRegistrationData.java | 104 -- .../workbench/ui/impl/UserRegistrationForm.java | 994 ------------------- .../workbench/ui/impl/UserRegistrationHook.java | 162 --- .../org.apache.taverna.workbench.StartupSPI | 1 - .../spring/workbench-impl-context-osgi.xml | 3 +- .../META-INF/spring/workbench-impl-context.xml | 3 - .../resources/example-registration-form.xml | 30 - .../src/main/resources/registration-form.xsd | 27 - .../src/main/resources/registration.php | 137 --- .../workbench/ui/impl/UserRegistrationTest.java | 189 ---- 10 files changed, 1 insertion(+), 1649 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationData.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationData.java b/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationData.java deleted file mode 100644 index 97b7630..0000000 --- a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationData.java +++ /dev/null @@ -1,104 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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 org.apache.taverna.workbench.ui.impl; - -public class UserRegistrationData { - private String tavernaVersion = ""; - private String firstName = ""; - private String lastName = ""; - private String emailAddress = ""; - private String institutionOrCompanyName = ""; - private String industry = ""; - private String field = ""; - private String purposeOfUsingTaverna = ""; - private boolean keepMeInformed = false; - - public void setTavernaVersion(String tavernaVersion) { - this.tavernaVersion = tavernaVersion; - } - - public String getTavernaVersion() { - return tavernaVersion; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getFirstName() { - return firstName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getLastName() { - return lastName; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setInstitutionOrCompanyName(String institutionOrCompanyName) { - this.institutionOrCompanyName = institutionOrCompanyName; - } - - public String getInstitutionOrCompanyName() { - return institutionOrCompanyName; - } - - public void setIndustry(String industry) { - this.industry = industry; - } - - public String getIndustry() { - return industry; - } - - public void setField(String field) { - this.field = field; - } - - public String getField() { - return field; - } - - public void setPurposeOfUsingTaverna(String purposeOfUsingTaverna) { - this.purposeOfUsingTaverna = purposeOfUsingTaverna; - } - - public String getPurposeOfUsingTaverna() { - return purposeOfUsingTaverna; - } - - public void setKeepMeInformed(boolean keepMeInformed) { - this.keepMeInformed = keepMeInformed; - } - - public boolean getKeepMeInformed() { - return keepMeInformed; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationForm.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationForm.java b/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationForm.java deleted file mode 100644 index 3753ba1..0000000 --- a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationForm.java +++ /dev/null @@ -1,994 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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 org.apache.taverna.workbench.ui.impl; - -import static java.awt.BorderLayout.CENTER; -import static java.awt.BorderLayout.NORTH; -import static java.awt.Color.LIGHT_GRAY; -import static java.awt.Color.WHITE; -import static java.awt.FlowLayout.LEFT; -import static java.awt.Font.BOLD; -import static java.awt.GridBagConstraints.FIRST_LINE_START; -import static java.awt.GridBagConstraints.HORIZONTAL; -import static java.awt.GridBagConstraints.LINE_START; -import static java.awt.GridBagConstraints.NONE; -import static java.awt.GridBagConstraints.WEST; -import static java.awt.event.KeyEvent.VK_ENTER; -import static java.awt.event.KeyEvent.VK_TAB; -import static javax.swing.JOptionPane.ERROR_MESSAGE; -import static javax.swing.JOptionPane.showMessageDialog; -import static javax.swing.SwingConstants.BOTTOM; -import static javax.swing.SwingConstants.TOP; -import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED; -import static org.apache.taverna.workbench.icons.WorkbenchIcons.tavernaCogs32x32Icon; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Desktop; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.ConnectException; -import java.net.MalformedURLException; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.Properties; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JEditorPane; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.border.Border; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; -import javax.swing.text.Document; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.StyleSheet; - -import org.apache.taverna.lang.ui.DialogTextArea; -import org.apache.taverna.workbench.helper.HelpEnabledDialog; - -import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; -/** - * User registration form. - * - * @author Alex Nenadic - */ -@SuppressWarnings("serial") -public class UserRegistrationForm extends HelpEnabledDialog { - private static final String FAILED = "User registration failed: "; - - private static final String REGISTRATION_FAILED_MSG = "User registration failed. Please try again later."; - - private static final String REGISTRATION_URL = "http://www.mygrid.org.uk/taverna/registration/"; - - public static final String TAVERNA_VERSION_PROPERTY_NAME = "Taverna version"; - public static final String FIRST_NAME_PROPERTY_NAME = "First name"; - public static final String LAST_NAME_PROPERTY_NAME = "Last name"; - public static final String EMAIL_ADDRESS_PROPERTY_NAME = "Email address"; - public static final String INSTITUTION_OR_COMPANY_PROPERTY_NAME = "Institution or company name"; - public static final String INDUSTRY_PROPERTY_NAME = "Industry"; - public static final String FIELD_PROPERTY_NAME = "Field of investigation"; - public static final String PURPOSE_PROPERTY_NAME = "Purpose of using Taverna"; - public static final String KEEP_ME_INFORMED_PROPERTY_NAME = "Keep me informed by email"; - - public static final String TAVERNA_REGISTRATION_POST_PARAMETER_NAME = "taverna_registration"; - public static final String TAVERNA_VERSION_POST_PARAMETER_NAME = "taverna_version"; - public static final String FIRST_NAME_POST_PARAMETER_NAME = "first_name"; - public static final String LAST_NAME_POST_PARAMETER_NAME = "last_name"; - public static final String EMAIL_ADDRESS_POST_PARAMETER_NAME = "email"; - public static final String INSTITUTION_OR_COMPANY_POST_PARAMETER_NAME = "institution_or_company"; - public static final String INDUSTRY_TYPE_POST_PARAMETER_NAME = "industry_type"; - public static final String FIELD_POST_PARAMETER_NAME = "field"; - public static final String PURPOSE_POST_PARAMETER_NAME = "purpose"; - public static final String KEEP_ME_INFORMED_POST_PARAMETER_PROPERTY_NAME = "keep_me_informed"; - - private static String TRUE = Boolean.TRUE.toString(); - private static String FALSE = Boolean.FALSE.toString(); - - private static final String WELCOME = "Welcome to the Taverna User Registration Form"; - private static final String PLEASE_FILL_IN_THIS_REGISTRATION_FORM = "Please fill in this registration form to let us know that you are using Taverna"; - - private static final String WE_DO = "Note that by registering:\n" - + " \u25CF We do not have access to your data\n" - + " \u25CF We do not have access to your service usage\n" - + " \u25CF You will not be monitored\n" - + " \u25CF We do record the information you provide\n" - + " at registration time"; - - private static final String WHY_REGISTER = "By registering you will:\n" - + " \u25CF Allow us to support you better; future plans will be\n" - + " directed towards solutions Taverna users require\n" - + " \u25CF Help sustain Taverna development; our continued\n" - + " funding relies on us showing usage\n" - + " \u25CF (Optionally) Hear about news and product updates"; - - private static final String FIRST_NAME = "*First name:"; - private static final String LAST_NAME = "*Last name:"; - private static final String EMAIL_ADDRESS = "*Email address:"; - private static final String KEEP_ME_INFORMED = "Keep me informed of news and product updates via email"; - private static final String INSTITUTION_COMPANY_NAME = "*Institution/Company name:"; - private static final String FIELD_OF_INVESTIGATION = " Field of investigation:\n" - + " (e.g. bioinformatics)"; - private static final String WHY_YOU_INTEND_TO_USE_TAVERNA = " A brief description of how you intend\n" - + " to use Taverna: (e.g. genome analysis\n" - + " for bacterial strain identification)"; - - private static String[] industryTypes = { "", "Academia - Life Sciences", - "Academia - Social Sciences", "Academia - Physical Sciences", - "Academia - Environmental Sciences", "Academia - Other", - "Industry - Biotechnology", "Industry - Pharmaceutical", - "Industry - Engineering", "Industry - Other", - "Healthcare Services", "Goverment and Public Sector", "Other" }; - - private static final String I_AGREE_TO_THE_TERMS_AND_CONDITIONS = "I agree to the terms and conditions of registration at"; - private static final String TERMS_AND_CONDITIONS_URL = "http://www.taverna.org.uk/legal/terms"; - - private Logger logger = Logger.getLogger(UserRegistrationForm.class); - private UserRegistrationData previousRegistrationData; - private JTextField firstNameTextField; - private JTextField lastNameTextField; - private JTextField emailTextField; - private JCheckBox keepMeInformedCheckBox; - private JTextField institutionOrCompanyTextField; - private JComboBox<String> industryTypeTextField; - private JTextField fieldTextField; - private JTextArea purposeTextArea; - private JCheckBox termsAndConditionsCheckBox; - - private final File registrationDataFile; - private final File remindMeLaterFile; - private final File doNotRegisterMeFile; - private final String appName; - - public UserRegistrationForm(String appName, File registrationDataFile, - File doNotRegisterMeFile, File remindMeLaterFile) { - super((Frame) null, "Taverna User Registration", true); - this.appName = appName; - this.registrationDataFile = registrationDataFile; - this.doNotRegisterMeFile = doNotRegisterMeFile; - this.remindMeLaterFile = remindMeLaterFile; - initComponents(); - } - - public UserRegistrationForm(String appName, - File previousRegistrationDataFile, File registrationDataFile, - File doNotRegisterMeFile, File remindMeLaterFile) { - super((Frame) null, "Taverna User Registration", true); - this.appName = appName; - this.registrationDataFile = registrationDataFile; - this.doNotRegisterMeFile = doNotRegisterMeFile; - this.remindMeLaterFile = remindMeLaterFile; - previousRegistrationData = loadUserRegistrationData(previousRegistrationDataFile); - initComponents(); - } - - // For testing only - // public static void main(String[] args) throws ClassNotFoundException, - // InstantiationException, IllegalAccessException, - // UnsupportedLookAndFeelException{ - // WorkbenchImpl.setLookAndFeel(); - // UserRegistrationForm form = new UserRegistrationForm(); - // form.setVisible(true); - // } - - private void initComponents() { - JPanel mainPanel = new JPanel(new GridBagLayout()); - - // Base font for all components on the form - Font baseFont = new JLabel("base font").getFont().deriveFont(11f); - - // Title panel - JPanel titlePanel = new JPanel(new FlowLayout(LEFT)); - titlePanel.setBackground(WHITE); - // titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10)); - JLabel titleLabel = new JLabel(WELCOME); - titleLabel.setFont(baseFont.deriveFont(BOLD, 13.5f)); - // titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10)); - JLabel titleIcon = new JLabel(tavernaCogs32x32Icon); - // titleIcon.setBorder(new EmptyBorder(10, 10, 10, 10)); - DialogTextArea titleMessage = new DialogTextArea( - PLEASE_FILL_IN_THIS_REGISTRATION_FORM); - titleMessage.setMargin(new Insets(0, 20, 0, 10)); - titleMessage.setFont(baseFont); - titleMessage.setEditable(false); - titleMessage.setFocusable(false); - // titlePanel.setBorder( new EmptyBorder(10, 10, 0, 10)); - JPanel messagePanel = new JPanel(new BorderLayout()); - messagePanel.add(titleLabel, NORTH); - messagePanel.add(titleMessage, CENTER); - messagePanel.setBackground(WHITE); - titlePanel.add(titleIcon); - titlePanel.add(messagePanel); - addDivider(titlePanel, BOTTOM, true); - - GridBagConstraints gbc = new GridBagConstraints(); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 0; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 2; - // gbc.insets = new Insets(5, 10, 0, 0); - mainPanel.add(titlePanel, gbc); - - // Registration messages - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 1; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 2; - // gbc.insets = new Insets(5, 0, 0, 10); - DialogTextArea registrationMessage1 = new DialogTextArea(WHY_REGISTER); - registrationMessage1.setMargin(new Insets(0, 10, 0, 0)); - registrationMessage1.setFont(baseFont); - registrationMessage1.setEditable(false); - registrationMessage1.setFocusable(false); - registrationMessage1.setBackground(getBackground()); - - DialogTextArea registrationMessage2 = new DialogTextArea(WE_DO); - registrationMessage2.setMargin(new Insets(0, 10, 0, 10)); - registrationMessage2.setFont(baseFont); - registrationMessage2.setEditable(false); - registrationMessage2.setFocusable(false); - registrationMessage2.setBackground(getBackground()); - JPanel registrationMessagePanel = new JPanel(new FlowLayout( - FlowLayout.CENTER)); - registrationMessagePanel.add(registrationMessage1); - registrationMessagePanel.add(registrationMessage2); - addDivider(registrationMessagePanel, BOTTOM, true); - mainPanel.add(registrationMessagePanel, gbc); - - // Mandatory label - // JLabel mandatoryLabel = new JLabel("* Mandatory fields"); - // mandatoryLabel.setFont(baseFont); - // gbc.weightx = 0.0; - // gbc.weighty = 0.0; - // gbc.gridx = 0; - // gbc.gridy = 3; - // gbc.fill = NONE; - // gbc.anchor = GridBagConstraints.EAST; - // gbc.gridwidth = 2; - // gbc.insets = new Insets(0, 10, 0, 20); - // mainPanel.add(mandatoryLabel, gbc); - - // First name - JLabel firstNameLabel = new JLabel(FIRST_NAME); - firstNameLabel.setFont(baseFont); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 4; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(0, 10, 0, 10); - mainPanel.add(firstNameLabel, gbc); - - firstNameTextField = new JTextField(); - firstNameTextField.setFont(baseFont); - if (previousRegistrationData != null) - firstNameTextField.setText(previousRegistrationData.getFirstName()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 4; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(firstNameTextField, gbc); - - // Last name - JLabel lastNameLabel = new JLabel(LAST_NAME); - lastNameLabel.setFont(baseFont); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 5; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(0, 10, 0, 10); - mainPanel.add(lastNameLabel, gbc); - - lastNameTextField = new JTextField(); - lastNameTextField.setFont(baseFont); - if (previousRegistrationData != null) - lastNameTextField.setText(previousRegistrationData.getLastName()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 5; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(lastNameTextField, gbc); - - // Email address - JLabel emailLabel = new JLabel(EMAIL_ADDRESS); - emailLabel.setFont(baseFont); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 6; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(emailLabel, gbc); - - emailTextField = new JTextField(); - emailTextField.setFont(baseFont); - if (previousRegistrationData != null) - emailTextField.setText(previousRegistrationData.getEmailAddress()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 6; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(emailTextField, gbc); - - // Keep me informed - keepMeInformedCheckBox = new JCheckBox(KEEP_ME_INFORMED); - keepMeInformedCheckBox.setFont(baseFont); - if (previousRegistrationData != null) - keepMeInformedCheckBox.setSelected(previousRegistrationData - .getKeepMeInformed()); - keepMeInformedCheckBox.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_ENTER) { - evt.consume(); - keepMeInformedCheckBox.setSelected(!keepMeInformedCheckBox - .isSelected()); - } - } - }); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 7; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 2; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(keepMeInformedCheckBox, gbc); - - // Institution name - JLabel institutionLabel = new JLabel(INSTITUTION_COMPANY_NAME); - institutionLabel.setFont(baseFont); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 8; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(institutionLabel, gbc); - - institutionOrCompanyTextField = new JTextField(); - institutionOrCompanyTextField.setFont(baseFont); - if (previousRegistrationData != null) - institutionOrCompanyTextField.setText(previousRegistrationData - .getInstitutionOrCompanyName()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 8; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(institutionOrCompanyTextField, gbc); - - // Industry type - JLabel industryLabel = new JLabel(" Industry type:"); - industryLabel.setFont(baseFont); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 9; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(industryLabel, gbc); - - industryTypeTextField = new JComboBox<>(industryTypes); - industryTypeTextField.setFont(baseFont); - if (previousRegistrationData != null) - industryTypeTextField.setSelectedItem(previousRegistrationData - .getIndustry()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 9; - gbc.fill = HORIZONTAL; - gbc.anchor = WEST; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(industryTypeTextField, gbc); - - // Field of investigation - JTextArea fieldLabel = new JTextArea(FIELD_OF_INVESTIGATION); - fieldLabel.setFont(baseFont); - fieldLabel.setEditable(false); - fieldLabel.setFocusable(false); - fieldLabel.setBackground(getBackground()); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 10; - gbc.fill = NONE; - gbc.anchor = LINE_START; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(fieldLabel, gbc); - - fieldTextField = new JTextField(); - fieldTextField.setFont(baseFont); - if (previousRegistrationData != null) - fieldTextField.setText(previousRegistrationData.getField()); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 10; - gbc.fill = HORIZONTAL; - gbc.anchor = FIRST_LINE_START; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(fieldTextField, gbc); - - // Purpose of using Taverna - JTextArea purposeLabel = new JTextArea(WHY_YOU_INTEND_TO_USE_TAVERNA); - purposeLabel.setFont(baseFont); - purposeLabel.setEditable(false); - purposeLabel.setFocusable(false); - purposeLabel.setBackground(getBackground()); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 11; - gbc.fill = NONE; - gbc.anchor = LINE_START; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(purposeLabel, gbc); - - purposeTextArea = new JTextArea(4, 30); - purposeTextArea.setFont(baseFont); - purposeTextArea.setLineWrap(true); - purposeTextArea.setAutoscrolls(true); - if (previousRegistrationData != null) - purposeTextArea.setText(previousRegistrationData - .getPurposeOfUsingTaverna()); - purposeTextArea.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_TAB) { - if (evt.getModifiers() > 0) - purposeTextArea.transferFocusBackward(); - else - purposeTextArea.transferFocus(); - evt.consume(); - } - } - }); - JScrollPane purposeScrollPane = new JScrollPane(purposeTextArea); - gbc.weightx = 1.0; - gbc.weighty = 0.0; - gbc.gridx = 1; - gbc.gridy = 11; - gbc.fill = HORIZONTAL; - gbc.anchor = FIRST_LINE_START; - gbc.gridwidth = 1; - gbc.insets = new Insets(5, 10, 0, 10); - mainPanel.add(purposeScrollPane, gbc); - - // Terms and conditions - termsAndConditionsCheckBox = new JCheckBox( - I_AGREE_TO_THE_TERMS_AND_CONDITIONS); - termsAndConditionsCheckBox.setFont(baseFont); - termsAndConditionsCheckBox.setBorder(null); - termsAndConditionsCheckBox.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_ENTER) { - evt.consume(); - termsAndConditionsCheckBox - .setSelected(!termsAndConditionsCheckBox - .isSelected()); - } - } - }); - // gbc.weightx = 0.0; - // gbc.weighty = 0.0; - // gbc.gridx = 0; - // gbc.gridy = 12; - // gbc.fill = NONE; - // gbc.anchor = WEST; - // gbc.gridwidth = 2; - // gbc.insets = new Insets(10, 10, 0, 0); - // mainPanel.add(termsAndConditionsCheckBox, gbc); - - // Terms and conditions link - JEditorPane termsAndConditionsURL = new JEditorPane(); - termsAndConditionsURL.setEditable(false); - termsAndConditionsURL.setBackground(getBackground()); - termsAndConditionsURL.setFocusable(false); - HTMLEditorKit kit = new HTMLEditorKit(); - termsAndConditionsURL.setEditorKit(kit); - StyleSheet styleSheet = kit.getStyleSheet(); - // styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); - // // base font looks bigger when rendered as HTML - styleSheet.addRule("body {font-family:" + baseFont.getFamily() - + "; font-size:9px;}"); - Document doc = kit.createDefaultDocument(); - termsAndConditionsURL.setDocument(doc); - termsAndConditionsURL.setText("<html><body><a href=\"" - + TERMS_AND_CONDITIONS_URL + "\">" + TERMS_AND_CONDITIONS_URL - + "</a></body></html>"); - termsAndConditionsURL.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent he) { - if (he.getEventType() == ACTIVATED) - followHyperlinkToTandCs(); - } - }); - gbc.weightx = 0.0; - gbc.weighty = 0.0; - gbc.gridx = 0; - gbc.gridy = 13; - gbc.fill = NONE; - gbc.anchor = WEST; - gbc.gridwidth = 2; - gbc.insets = new Insets(5, 10, 0, 10); - JPanel termsAndConditionsPanel = new JPanel(new FlowLayout(LEFT)); - termsAndConditionsPanel.add(termsAndConditionsCheckBox); - termsAndConditionsPanel.add(termsAndConditionsURL); - mainPanel.add(termsAndConditionsPanel, gbc); - - // Button panel - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - JButton registerButton = new JButton("Register"); - registerButton.setFont(baseFont); - registerButton.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_ENTER) { - evt.consume(); - register(); - } - } - }); - registerButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - register(); - } - }); - JButton doNotRegisterButton = new JButton("Do not ask me again"); - doNotRegisterButton.setFont(baseFont); - doNotRegisterButton.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_ENTER) { - evt.consume(); - doNotRegister(); - } - } - }); - doNotRegisterButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - doNotRegister(); - } - }); - JButton remindMeLaterButton = new JButton("Remind me later"); // in 2 weeks - remindMeLaterButton.setFont(baseFont); - remindMeLaterButton.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == VK_ENTER) { - evt.consume(); - remindMeLater(); - } - } - }); - remindMeLaterButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - remindMeLater(); - } - }); - buttonPanel.add(registerButton); - buttonPanel.add(remindMeLaterButton); - buttonPanel.add(doNotRegisterButton); - addDivider(buttonPanel, TOP, true); - gbc.gridx = 0; - gbc.gridy = 14; - gbc.fill = HORIZONTAL; - gbc.anchor = GridBagConstraints.CENTER; - gbc.insets = new Insets(5, 10, 0, 10); - gbc.gridwidth = 2; - mainPanel.add(buttonPanel, gbc); - - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(mainPanel, CENTER); - - pack(); - setResizable(false); - // Center the dialog on the screen (we do not have the parent) - Dimension dimension = getToolkit().getScreenSize(); - Rectangle abounds = getBounds(); - setLocation((dimension.width - abounds.width) / 2, - (dimension.height - abounds.height) / 2); - setSize(getPreferredSize()); - } - - protected void remindMeLater() { - try { - FileUtils.touch(remindMeLaterFile); - } catch (IOException ioex) { - logger.error( - "Failed to touch the 'Remind me later' file at user registration.", - ioex); - } - closeDialog(); - } - - protected void doNotRegister() { - try { - FileUtils.touch(doNotRegisterMeFile); - if (remindMeLaterFile.exists()) - remindMeLaterFile.delete(); - } catch (IOException ioex) { - logger.error( - "Failed to touch the 'Do not register me' file at user registration.", - ioex); - } - closeDialog(); - } - - private void register() { - if (!validateForm()) - return; - UserRegistrationData regData = new UserRegistrationData(); - regData.setTavernaVersion(appName); - regData.setFirstName(firstNameTextField.getText()); - regData.setLastName(lastNameTextField.getText()); - regData.setEmailAddress(emailTextField.getText()); - regData.setKeepMeInformed(keepMeInformedCheckBox.isSelected()); - regData.setInstitutionOrCompanyName(institutionOrCompanyTextField - .getText()); - regData.setIndustry(industryTypeTextField.getSelectedItem().toString()); - regData.setField(fieldTextField.getText()); - regData.setPurposeOfUsingTaverna(purposeTextArea.getText()); - - if (postUserRegistrationDataToServer(regData)) { - saveUserRegistrationData(regData, registrationDataFile); - if (remindMeLaterFile.exists()) - remindMeLaterFile.delete(); - closeDialog(); - } - } - - private boolean validateForm() { - String errorMessage = ""; - if (firstNameTextField.getText().isEmpty()) - errorMessage += "Please provide your first name.<br>"; - if (lastNameTextField.getText().isEmpty()) - errorMessage += "Please provide your last name.<br>"; - if (emailTextField.getText().isEmpty()) - errorMessage += "Please provide your email address.<br>"; - if (institutionOrCompanyTextField.getText().isEmpty()) - errorMessage += "Please provide your institution or company name."; - if (!errorMessage.isEmpty()) { - showMessageDialog(this, new JLabel("<html><body>" - + errorMessage + "</body></html>"), "Error in form", - ERROR_MESSAGE); - return false; - } - if (!termsAndConditionsCheckBox.isSelected()) { - showMessageDialog(this, new JLabel( - "You must agree to the terms and conditions."), - "Error in form", ERROR_MESSAGE); - return false; - } - return true; - } - - public UserRegistrationData loadUserRegistrationData(File propertiesFile) { - UserRegistrationData regData = new UserRegistrationData(); - Properties props = new Properties(); - - // Try to retrieve data from file - try { - props.load(new FileInputStream(propertiesFile)); - } catch (IOException e) { - logger.error("Failed to load old user registration data from " - + propertiesFile.getAbsolutePath(), e); - return null; - } - regData.setTavernaVersion(props - .getProperty(TAVERNA_VERSION_PROPERTY_NAME)); - regData.setFirstName(props.getProperty(FIRST_NAME_PROPERTY_NAME)); - regData.setLastName(props.getProperty(LAST_NAME_PROPERTY_NAME)); - regData.setEmailAddress(props.getProperty(EMAIL_ADDRESS_PROPERTY_NAME)); - regData.setKeepMeInformed(props.getProperty( - KEEP_ME_INFORMED_PROPERTY_NAME).equals(TRUE)); - regData.setInstitutionOrCompanyName(props - .getProperty(INSTITUTION_OR_COMPANY_PROPERTY_NAME)); - regData.setIndustry(props.getProperty(INDUSTRY_PROPERTY_NAME)); - regData.setField(props.getProperty(FIELD_PROPERTY_NAME)); - regData.setPurposeOfUsingTaverna(props - .getProperty(PURPOSE_PROPERTY_NAME)); - return regData; - } - - private void enc(StringBuilder buffer, String name, Object value) - throws UnsupportedEncodingException { - if (buffer.length() != 0) - buffer.append('&'); - buffer.append(URLEncoder.encode(name, "UTF-8")); - buffer.append('='); - buffer.append(URLEncoder.encode(value.toString(), "UTF-8")); - } - - /** - * Post registration data to our server. - */ - private boolean postUserRegistrationDataToServer( - UserRegistrationData regData) { - StringBuilder parameters = new StringBuilder(); - - /* - * The 'submit' parameter - to let the server-side script know we are - * submitting the user's registration form - all other requests will be - * silently ignored - */ - try { - // value does not matter - enc(parameters, TAVERNA_REGISTRATION_POST_PARAMETER_NAME, "submit"); - - enc(parameters, TAVERNA_VERSION_POST_PARAMETER_NAME, - regData.getTavernaVersion()); - enc(parameters, FIRST_NAME_POST_PARAMETER_NAME, - regData.getFirstName()); - enc(parameters, LAST_NAME_POST_PARAMETER_NAME, - regData.getLastName()); - enc(parameters, EMAIL_ADDRESS_POST_PARAMETER_NAME, - regData.getEmailAddress()); - enc(parameters, KEEP_ME_INFORMED_POST_PARAMETER_PROPERTY_NAME, - regData.getKeepMeInformed()); - enc(parameters, INSTITUTION_OR_COMPANY_POST_PARAMETER_NAME, - regData.getInstitutionOrCompanyName()); - enc(parameters, INDUSTRY_TYPE_POST_PARAMETER_NAME, - regData.getIndustry()); - enc(parameters, FIELD_POST_PARAMETER_NAME, regData.getField()); - enc(parameters, PURPOSE_POST_PARAMETER_NAME, - regData.getPurposeOfUsingTaverna()); - } catch (UnsupportedEncodingException ueex) { - logger.error(FAILED + "Could not url encode post parameters", ueex); - showMessageDialog(null, REGISTRATION_FAILED_MSG, - "Error encoding registration data", ERROR_MESSAGE); - return false; - } - String server = REGISTRATION_URL; - logger.info("Posting user registartion to " + server - + " with parameters: " + parameters); - String response = ""; - String failure; - try { - URL url = new URL(server); - URLConnection conn = url.openConnection(); - /* - * Set timeout to e.g. 7 seconds, otherwise we might hang too long - * if server is not responding and it will block Taverna - */ - conn.setConnectTimeout(7000); - // Set connection parameters - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - // Make server believe we are HTML form data... - conn.setRequestProperty("Content-Type", - "application/x-www-form-urlencoded"); - // Write out the bytes of the content string to the stream. - try (DataOutputStream out = new DataOutputStream( - conn.getOutputStream())) { - out.writeBytes(parameters.toString()); - out.flush(); - } - // Read response from the input stream. - try (BufferedReader in = new BufferedReader(new InputStreamReader( - conn.getInputStream()))) { - String temp; - while ((temp = in.readLine()) != null) - response += temp + "\n"; - // Remove the last \n character - if (!response.isEmpty()) - response = response.substring(0, response.length() - 1); - } - if (response.equals("Registration successful!")) - return true; - logger.error(FAILED + "Response form server was: " + response); - failure = "Error saving registration data on the server"; - } catch (ConnectException ceex) { - /* - * the connection was refused remotely (e.g. no process is listening - * on the remote address/port). - */ - logger.error( - FAILED - + "Registration server is not listening of the specified url.", - ceex); - failure = "Registration server is not listening at the specified url"; - } catch (SocketTimeoutException stex) { - // timeout has occurred on a socket read or accept. - logger.error(FAILED + "Socket timeout occurred.", stex); - failure = "Registration server timeout"; - } catch (MalformedURLException muex) { - logger.error(FAILED + "Registartion server's url is malformed.", - muex); - failure = "Error with registration server's url"; - } catch (IOException ioex) { - logger.error( - FAILED - + "Failed to open url connection to registration server or writing/reading to/from it.", - ioex); - failure = "Error opening connection to the registration server"; - } - showMessageDialog(null, REGISTRATION_FAILED_MSG, failure, ERROR_MESSAGE); - return false; - } - - private void saveUserRegistrationData(UserRegistrationData regData, - File propertiesFile) { - Properties props = new Properties(); - props.setProperty(TAVERNA_VERSION_PROPERTY_NAME, - regData.getTavernaVersion()); - props.setProperty(FIRST_NAME_PROPERTY_NAME, regData.getFirstName()); - props.setProperty(LAST_NAME_PROPERTY_NAME, regData.getLastName()); - props.setProperty(EMAIL_ADDRESS_PROPERTY_NAME, - regData.getEmailAddress()); - props.setProperty(KEEP_ME_INFORMED_PROPERTY_NAME, - regData.getKeepMeInformed() ? TRUE : FALSE); - props.setProperty(INSTITUTION_OR_COMPANY_PROPERTY_NAME, - regData.getInstitutionOrCompanyName()); - props.setProperty(INDUSTRY_PROPERTY_NAME, regData.getIndustry()); - props.setProperty(FIELD_PROPERTY_NAME, - regData.getPurposeOfUsingTaverna()); - props.setProperty(PURPOSE_PROPERTY_NAME, - regData.getPurposeOfUsingTaverna()); - - // Write the properties file. - try { - props.store(new FileOutputStream(propertiesFile), null); - } catch (Exception e) { - logger.error("Failed to save user registration data locally on disk."); - } - } - - private void closeDialog() { - setVisible(false); - dispose(); - } - - /** - * Adds a light gray or etched border to the top or bottom of a JComponent. - * - * @author David Withers - * @param component - */ - protected void addDivider(JComponent component, final int position, - final boolean etched) { - component.setBorder(new Border() { - private final Color borderColor = new Color(.6f, .6f, .6f); - - @Override - public Insets getBorderInsets(Component c) { - if (position == TOP) - return new Insets(5, 0, 0, 0); - else - return new Insets(0, 0, 5, 0); - } - - @Override - public boolean isBorderOpaque() { - return false; - } - - @Override - public void paintBorder(Component c, Graphics g, int x, int y, - int width, int height) { - if (position == TOP) { - if (etched) { - g.setColor(borderColor); - g.drawLine(x, y, x + width, y); - g.setColor(WHITE); - g.drawLine(x, y + 1, x + width, y + 1); - } else { - g.setColor(LIGHT_GRAY); - g.drawLine(x, y, x + width, y); - } - } else { - if (etched) { - g.setColor(borderColor); - g.drawLine(x, y + height - 2, x + width, y + height - 2); - g.setColor(WHITE); - g.drawLine(x, y + height - 1, x + width, y + height - 1); - } else { - g.setColor(LIGHT_GRAY); - g.drawLine(x, y + height - 1, x + width, y + height - 1); - } - } - } - }); - } - - private void followHyperlinkToTandCs() { - // Open a Web browser - try { - Desktop.getDesktop().browse(new URI(TERMS_AND_CONDITIONS_URL)); - } catch (Exception ex) { - logger.error("User registration: Failed to launch browser to show terms and conditions at " - + TERMS_AND_CONDITIONS_URL); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationHook.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationHook.java b/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationHook.java deleted file mode 100644 index e5cdfcc..0000000 --- a/taverna-workbench-impl/src/main/java/org/apache/taverna/workbench/ui/impl/UserRegistrationHook.java +++ /dev/null @@ -1,162 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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 org.apache.taverna.workbench.ui.impl; - -import static java.awt.GraphicsEnvironment.isHeadless; - -import java.io.File; -import java.io.FileFilter; -import java.util.Date; -import org.apache.taverna.configuration.app.ApplicationConfiguration; - -import org.apache.taverna.workbench.StartupSPI; - -public class UserRegistrationHook implements StartupSPI { - /** Delay between when we ask the user about registration, in milliseconds */ - private static final int TWO_WEEKS = 14 * 24 * 3600 * 1000; - public static final String REGISTRATION_DIRECTORY_NAME = "registration"; - public static final String REGISTRATION_DATA_FILE_NAME = "registration_data.properties"; - public static final String REMIND_ME_LATER_FILE_NAME = "remind_me_later"; - public static final String DO_NOT_REGISTER_ME_FILE_NAME = "do_not_register_me"; - - private ApplicationConfiguration applicationConfiguration; - - @Override - public int positionHint() { - return 50; - } - - @Override - public boolean startup() { - File registrationDirectory = getRegistrationDirectory(); - File registrationDataFile = new File(registrationDirectory, - REGISTRATION_DATA_FILE_NAME); - File doNotRegisterMeFile = new File(registrationDirectory, - DO_NOT_REGISTER_ME_FILE_NAME); - File remindMeLaterFile = new File(registrationDirectory, - REMIND_ME_LATER_FILE_NAME); - - // if we are running headlessly just return - if (isHeadless()) - return true; - // For Taverna snapshots - do not ask user to register - if (applicationConfiguration.getName().toLowerCase().contains("snapshot")) - return true; - - // If there is already user's registration data present - exit. - if (registrationDataFile.exists()) - return true; - - // If user did not want to register - exit. - if (doNotRegisterMeFile.exists()) - return true; - - /* - * If user said to remind them - check if more than 2 weeks passed since - * we asked previously. - */ - if (remindMeLaterFile.exists()) { - long lastModified = remindMeLaterFile.lastModified(); - long now = new Date().getTime(); - if (now - lastModified < TWO_WEEKS) - // 2 weeks have not passed since we last asked - return true; - - // Ask user again if they want to register - UserRegistrationForm form = new UserRegistrationForm( - applicationConfiguration.getName(), registrationDataFile, - doNotRegisterMeFile, remindMeLaterFile); - form.setVisible(true); - return true; - } - - /* - * Check if there are previous Taverna versions installed and find the - * latest one that contains user registration data, if any. Ask user if - * they want to upload that previous data. - */ - final File appHomeDirectory = applicationConfiguration.getApplicationHomeDir(); - File parentDirectory = appHomeDirectory.getParentFile(); - FileFilter fileFilter = new FileFilter() { - @Override - public boolean accept(File file) { - return !(file.getName().equals(appHomeDirectory.getName()) - // Exclude Taverna home directory for this app - && file.isDirectory() - && file.getName().toLowerCase().startsWith("taverna-") - // exclude snapshots - && !file.getName().toLowerCase().contains("snapshot") - // exclude command line tool - && !file.getName().toLowerCase().contains("cmd") - // exclude dataviewer - && !file.getName().toLowerCase().contains("dataviewer")); - } - }; - File[] tavernaDirectories = parentDirectory.listFiles(fileFilter); - // Find the latest previous registration data file, if any - File previousRegistrationDataFile = null; - for (File tavernaDirectory : tavernaDirectories) { - File regFile = new File(tavernaDirectory, REGISTRATION_DIRECTORY_NAME - + System.getProperty("file.separator") + REGISTRATION_DATA_FILE_NAME); - if (!regFile.exists()) - continue; - if (previousRegistrationDataFile == null) - previousRegistrationDataFile = regFile; - else if (previousRegistrationDataFile.lastModified() < regFile - .lastModified()) - previousRegistrationDataFile = regFile; - } - - UserRegistrationForm form; - if (previousRegistrationDataFile == null) - // No previous registration file - ask user to register - form = new UserRegistrationForm(applicationConfiguration.getName(), - registrationDataFile, doNotRegisterMeFile, - remindMeLaterFile); - else - /* - * Fill in user's old registration data in the form and ask them to - * register - */ - form = new UserRegistrationForm(applicationConfiguration.getName(), - previousRegistrationDataFile, registrationDataFile, - doNotRegisterMeFile, remindMeLaterFile); - form.setVisible(true); - return true; - } - - /** - * Gets the registration directory where info about registration will be - * saved to. - */ - public File getRegistrationDirectory() { - File home = applicationConfiguration.getApplicationHomeDir(); - - File registrationDirectory = new File(home, REGISTRATION_DIRECTORY_NAME); - if (!registrationDirectory.exists()) - registrationDirectory.mkdir(); - return registrationDirectory; - } - - public void setApplicationConfiguration( - ApplicationConfiguration applicationConfiguration) { - this.applicationConfiguration = applicationConfiguration; - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/META-INF/services/org.apache.taverna.workbench.StartupSPI ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/META-INF/services/org.apache.taverna.workbench.StartupSPI b/taverna-workbench-impl/src/main/resources/META-INF/services/org.apache.taverna.workbench.StartupSPI index 7499a70..2000beb 100644 --- a/taverna-workbench-impl/src/main/resources/META-INF/services/org.apache.taverna.workbench.StartupSPI +++ b/taverna-workbench-impl/src/main/resources/META-INF/services/org.apache.taverna.workbench.StartupSPI @@ -1,2 +1 @@ -org.apache.taverna.workbench.ui.impl.UserRegistrationHook org.apache.taverna.workbench.ui.impl.SetConsoleLoggerStartup http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context-osgi.xml ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context-osgi.xml b/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context-osgi.xml index cac8080..2344aba 100644 --- a/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context-osgi.xml +++ b/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context-osgi.xml @@ -24,8 +24,7 @@ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"> - <service ref="UserRegistrationHook" interface="org.apache.taverna.workbench.StartupSPI" /> - <!-- <service ref="SetConsoleLoggerStartup" interface="org.apache.taverna.workbench.StartupSPI" /> --> + <!-- <service ref="SetConsoleLoggerStartup" interface="org.apache.taverna.workbench.StartupSPI" /> --> <service ref="StoreWindowStateOnShutdown" interface="org.apache.taverna.workbench.ShutdownSPI" /> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context.xml ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context.xml b/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context.xml index 0c4e368..c24a1c6 100644 --- a/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context.xml +++ b/taverna-workbench-impl/src/main/resources/META-INF/spring/workbench-impl-context.xml @@ -21,9 +21,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - <bean id="UserRegistrationHook" class="org.apache.taverna.workbench.ui.impl.UserRegistrationHook"> - <property name="applicationConfiguration" ref="applicationConfiguration"/> - </bean> <bean id="SetConsoleLoggerStartup" class="org.apache.taverna.workbench.ui.impl.SetConsoleLoggerStartup"> <constructor-arg ref="workbenchConfiguration" /> </bean> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/example-registration-form.xml ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/example-registration-form.xml b/taverna-workbench-impl/src/main/resources/example-registration-form.xml deleted file mode 100644 index 6941375..0000000 --- a/taverna-workbench-impl/src/main/resources/example-registration-form.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<registration_data> - <taverna_version>taverna-2.2.0</taverna_version> - <first_name>John</first_name> - <last_name>Doe</last_name> - <email_address>[email protected]</email_address> - <keep_me_informed>false</keep_me_informed> - <institution_or_company_name>JD Consulting</institution_or_company_name> - <industry_type>Industry - Pharmaceutical</industry_type> - <field_of_interest>bioinformatics</field_of_interest> - <purpose_of_using_taverna>pharmacogenomics</purpose_of_using_taverna> -</registration_data> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/registration-form.xsd ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/registration-form.xsd b/taverna-workbench-impl/src/main/resources/registration-form.xsd deleted file mode 100644 index 776f8e5..0000000 --- a/taverna-workbench-impl/src/main/resources/registration-form.xsd +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> - <xs:element name="registration_data"> - <xs:complexType> - <xs:sequence> - <xs:element ref="taverna_version"/> - <xs:element ref="first_name"/> - <xs:element ref="last_name"/> - <xs:element ref="email_address"/> - <xs:element ref="keep_me_informed"/> - <xs:element ref="institution_or_company_name"/> - <xs:element ref="industry_type"/> - <xs:element ref="field_of_interest"/> - <xs:element ref="purpose_of_using_taverna"/> - </xs:sequence> - </xs:complexType> - </xs:element> - <xs:element name="taverna_version" type="xs:string"/> - <xs:element name="first_name" type="xs:string"/> - <xs:element name="last_name" type="xs:string"/> - <xs:element name="email_address" type="xs:string"/> - <xs:element name="keep_me_informed" type="xs:boolean"/> - <xs:element name="institution_or_company_name" type="xs:string"/> - <xs:element name="industry_type" type="xs:string"/> - <xs:element name="field_of_interest" type="xs:string"/> - <xs:element name="purpose_of_using_taverna" type="xs:string"/> -</xs:schema> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/main/resources/registration.php ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/main/resources/registration.php b/taverna-workbench-impl/src/main/resources/registration.php deleted file mode 100644 index 902200b..0000000 --- a/taverna-workbench-impl/src/main/resources/registration.php +++ /dev/null @@ -1,137 +0,0 @@ -<?php - -/** - * A folder where to write the registrations - */ - -$registrations_folder = "/var/taverna-registration"; - - - -function xmlescape($string){ - $res = str_replace("&", "&",$string); - $res = str_replace("<", "<",$res); - $res = str_replace(">", ">",$res); - return $res; -} - - - -/* From http://php.net/manual/en/function.uiqid.php - * Requires yum install uuid-php - and in .htaccess / php.ini: - php_value allow_call_time_pass_reference true - */ - -class uuid { - /** - * This class enables you to get real uuids using the OSSP library. - * Note you need php-uuid installed. - * On my system 1000 UUIDs are created in 0.0064 seconds. - * - * @author Marius Karthaus - * - */ - - protected $uuidobject; - - /** - * On long running deamons i've seen a lost resource. This checks the resource and creates it if needed. - * - */ - protected function create() { - if (! is_resource ( $this->uuidobject )) { - uuid_create ( &$this->uuidobject ); - } - } - - /** - * Return a type 1 (MAC address and time based) uuid - * - * @return String - */ - public function v1() { - $this->create (); - uuid_make ( $this->uuidobject, UUID_MAKE_V1 ); - uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring ); - return trim ( $uuidstring ); - } - - /** - * Return a type 4 (random) uuid - * - * @return String - */ - public function v4() { - $this->create (); - uuid_make ( $this->uuidobject, UUID_MAKE_V4 ); - uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring ); - return trim ( $uuidstring ); - } - - /** - * Return a type 5 (SHA-1 hash) uuid - * - * @return String - */ - public function v5() { - $this->create (); - uuid_make ( $this->uuidobject, UUID_MAKE_V5 ); - uuid_export ( $this->uuidobject, UUID_FMT_STR, $uuidstring ); - return trim ( $uuidstring ); - } -} - - if(isset($_POST['taverna_registration'])){ - - $taverna_version = $_POST['taverna_version']; - $first_name = $_POST['first_name']; - $last_name = $_POST['last_name']; - $email = $_POST['email']; - $keep_me_informed = $_POST['keep_me_informed']; - $institution_or_company = $_POST['institution_or_company']; - $industry = $_POST['industry_type']; - $field = $_POST['field']; - $purpose = $_POST['purpose']; - - $uuid=new uuid(); - - - // Generate user registration data file name with a random identifier - $random_id = $uuid->v4(); - $user_registration_file_name = $registrations_folder . "/user_registration_" . $random_id . ".xml"; - $user_registration_file = fopen($user_registration_file_name,'w') or die ("Could not open file ". $user_registration_file_name . " for writing." ); - - // Save this to a file - /* - $registration_data = ""; - $registration_data .= "Taverna version=" . $taverna_version . "\n"; - $registration_data .= "First name=" . $first_name . "\n"; - $registration_data .= "Last name=" . $last_name . "\n"; - $registration_data .= "Email address=" . $email . "\n"; - $registration_data .= "Keep me informed by email=" . $keep_me_informed . "\n"; - $registration_data .= "Institution or company=" . $institution_or_company . "\n"; - $registration_data .= "Industry=" . $industry_type . "\n"; - $registration_data .= "Field of interest=" . $field . "\n"; - $registration_data .= "Purpose of using Taverna=" . $purpose; - */ - - $registration_data = ""; - $registration_data .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - $registration_data .= "<registration_data>\n"; - $registration_data .= "\t<taverna_version>".xmlescape($taverna_version)."</taverna_version>\n"; - $registration_data .= "\t<first_name>".xmlescape($first_name)."</first_name>\n"; - $registration_data .= "\t<last_name>".xmlescape($last_name)."</last_name>\n"; - $registration_data .= "\t<email_address>".xmlescape($email)."</email_address>\n"; - $registration_data .= "\t<keep_me_informed>".xmlescape($keep_me_informed)."</keep_me_informed>\n"; - $registration_data .= "\t<institution_or_company_name>".xmlescape($institution_or_company)."</institution_or_company_name>\n"; - $registration_data .= "\t<industry_type>".xmlescape($industry)."</industry_type>\n"; - $registration_data .= "\t<field_of_interest>".xmlescape($field)."</field_of_interest>\n"; - $registration_data .= "\t<purpose_of_using_taverna>".xmlescape($purpose)."</purpose_of_using_taverna>\n"; - $registration_data .= "</registration_data>\n"; - - fwrite($user_registration_file, $registration_data) or die ("Could not write to file ". $user_registration_file_name ); - fclose($user_registration_file); - echo "Registration successful!"; - } -?> http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/08af5c4f/taverna-workbench-impl/src/test/java/org/apache/taverna/workbench/ui/impl/UserRegistrationTest.java ---------------------------------------------------------------------- diff --git a/taverna-workbench-impl/src/test/java/org/apache/taverna/workbench/ui/impl/UserRegistrationTest.java b/taverna-workbench-impl/src/test/java/org/apache/taverna/workbench/ui/impl/UserRegistrationTest.java deleted file mode 100644 index 8833770..0000000 --- a/taverna-workbench-impl/src/test/java/org/apache/taverna/workbench/ui/impl/UserRegistrationTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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 org.apache.taverna.workbench.ui.impl; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.ConnectException; -import java.net.MalformedURLException; -import java.net.SocketTimeoutException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; - -import static org.junit.Assert.*; - -import org.apache.taverna.workbench.ui.impl.UserRegistrationForm; - -import org.junit.Ignore; -import org.junit.Test; - -public class UserRegistrationTest { - - @Ignore - @Test - public void postUserRegistrationDataToServer() { - - String parameters = ""; - - // The 'submit' parameter - to let the server-side script know we are - // submitting - // the user's registration form - all other requests will be silently - // ignored - try { - parameters = URLEncoder - .encode( - UserRegistrationForm.TAVERNA_REGISTRATION_POST_PARAMETER_NAME, - "UTF-8") - + "=" + URLEncoder.encode("submit", "UTF-8"); // value does - // not - // matter - - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.TAVERNA_VERSION_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("snapshot", "UTF-8"); - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.FIRST_NAME_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("Alex", "UTF-8"); - parameters += "&" - + URLEncoder.encode( - UserRegistrationForm.LAST_NAME_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("Nenadic", "UTF-8"); - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.EMAIL_ADDRESS_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("[email protected]", "UTF-8"); - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.KEEP_ME_INFORMED_POST_PARAMETER_PROPERTY_NAME, - "UTF-8") + "=" - + URLEncoder.encode("true", "UTF-8"); - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.INSTITUTION_OR_COMPANY_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("Uni of Manchester", "UTF-8"); - parameters += "&" - + URLEncoder - .encode( - UserRegistrationForm.INDUSTRY_TYPE_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("Academia", "UTF-8"); - parameters += "&" - + URLEncoder.encode( - UserRegistrationForm.FIELD_POST_PARAMETER_NAME, - "UTF-8") + "=" - + URLEncoder.encode("Research", "UTF-8"); - parameters += "&" - + URLEncoder.encode( - UserRegistrationForm.PURPOSE_POST_PARAMETER_NAME, - "UTF-8") + "=" + URLEncoder.encode("None", "UTF-8"); - } catch (UnsupportedEncodingException ueex) { - System.out - .println("Failed to url encode post parameters when sending user registration data."); - } - String server = "http://cactus.cs.man.ac.uk/~alex/taverna_registration/registration.php"; - server = "http://localhost/~alex/taverna_registration/registration.php"; - // server = "https://somehost.co.uk"; - - System.out.println("Posting user registartion to " + server - + " with parameters: " + parameters); - String response = ""; - try { - URL url = new URL(server); - URLConnection conn = url.openConnection(); - System.out.println("Opened a connection"); - // Set timeout for connection, otherwise we might hang too long - // if server is not responding and it will block Taverna - conn.setConnectTimeout(7000); - // Set connection parameters - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - // Make server believe we are HTML form data... - conn.setRequestProperty("Content-Type", - "application/x-www-form-urlencoded"); - System.out - .println("Trying to get an output stream from the connection"); - DataOutputStream out = new DataOutputStream(conn.getOutputStream()); - // Write out the bytes of the content string to the stream. - out.writeBytes(parameters); - out.flush(); - out.close(); - // Read response from the input stream. - BufferedReader in = new BufferedReader(new InputStreamReader(conn - .getInputStream())); - String temp; - while ((temp = in.readLine()) != null) { - response += temp + "\n"; - } - // Remove the last \n character - if (!response.equals("")) { - response = response.substring(0, response.length() - 1); - } - in.close(); - System.out.println(response); - if (!response.equals("Registration successful!")) { - System.out - .println("Registration failed. Response form server was: " - + response); - } - assertTrue(response.equals("Registration successful!")); - } - // Catch some runtime exceptions - catch (ConnectException ceex) { // the connection was refused remotely - // (e.g. no process is listening on the - // remote address/port). - System.out - .println("User registration failed: Registration server is not listening of the specified url."); - ceex.printStackTrace(); - } - // Catch some runtime exceptions - catch (SocketTimeoutException stex) { // timeout has occurred on a - // socket read or accept. - System.out - .println("User registration failed: Socket timeout occurred."); - stex.printStackTrace(); - } catch (MalformedURLException muex) { - System.out - .println("User registration failed: Registartion server's url is malformed."); - muex.printStackTrace(); - } catch (IOException ioex) { - System.out - .println("User registration failed: Failed to open url connection to registration server or writing to it or reading from it."); - ioex.printStackTrace(); - } - } - -}
