Commit 963058fb authored by Matija Obreza's avatar Matija Obreza

Mock EasySMTA connector

parent 4f1c2f19
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.service;
public interface EasySMTA {
EasySMTAUserData getUserData(String emailAddress);
/**
* Data returned by Easy-SMTA
*
* @author matijaobreza
*/
public static class EasySMTAUserData {
private String pid;
private String firstName;
private String lastName;
private String email;
private String organization;
private String countryIsoCode3;
private String address;
private String shipAddress;
private String shipCountry;
public EasySMTAUserData() {
}
public EasySMTAUserData(String pid, String firstName, String lastName, String email, String organization, String countryIsoCode3, String address,
String shipAddress, String shipCountry) {
this.pid = pid;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.organization = organization;
this.countryIsoCode3 = countryIsoCode3;
this.address = address;
this.shipAddress = shipAddress;
this.shipCountry = shipCountry;
}
@Override
public String toString() {
return "ITPGRFA.PID email=" + email + " first=" + firstName + " last=" + lastName + ", org=" + organization + ", country=" + countryIsoCode3;
}
public String getPid() {
return pid;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public String getOrganization() {
return organization;
}
public String getCountryIsoCode3() {
return countryIsoCode3;
}
public String getAddress() {
return address;
}
public String getShipAddress() {
return shipAddress;
}
public String getShipCountry() {
return shipCountry;
}
}
}
......@@ -34,14 +34,17 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.genesys2.server.service.EasySMTA;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@Profile("aws")
@Component
public class EasySMTAConnector {
public class EasySMTAConnector implements EasySMTA {
private static final Log LOG = LogFactory.getLog(EasySMTAConnector.class);
@Value("${itpgrfa.easysmta.url}")
......@@ -53,7 +56,8 @@ public class EasySMTAConnector {
@Value("${itpgrfa.easysmta.password}")
private String serverPassword;
public EasySMTAUserData getUserData(String emailAddress) {
@Override
public EasySMTA.EasySMTAUserData getUserData(String emailAddress) {
final HttpClient httpclient = new DefaultHttpClient();
LOG.info("Checking EasySMTA at " + serverUrl + " for email: " + emailAddress);
......@@ -97,7 +101,7 @@ public class EasySMTAConnector {
} else {
return new EasySMTAUserData(tree.get("pid").asText(), tree.get("name").asText(), tree.get("surname").asText(), tree.get("email").asText(),
return new EasySMTA.EasySMTAUserData(tree.get("pid").asText(), tree.get("name").asText(), tree.get("surname").asText(), tree.get("email").asText(),
tree.get("orgName").asText(), tree.get("country").asText(), tree.get("address").asText(), tree.get("shipAddress").asText(), tree
.get("shipCountry").asText());
}
......@@ -115,75 +119,4 @@ public class EasySMTAConnector {
return null;
}
/**
* Data returned by Easy-SMTA
*
* @author matijaobreza
*/
public static class EasySMTAUserData {
private String pid;
private String firstName;
private String lastName;
private String email;
private String organization;
private String countryIsoCode3;
private String address;
private String shipAddress;
private String shipCountry;
public EasySMTAUserData(String pid, String firstName, String lastName, String email, String organization, String countryIsoCode3, String address,
String shipAddress, String shipCountry) {
this.pid = pid;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.organization = organization;
this.countryIsoCode3 = countryIsoCode3;
this.address = address;
this.shipAddress = shipAddress;
this.shipCountry = shipCountry;
}
@Override
public String toString() {
return "ITPGRFA.PID email=" + email + " first=" + firstName + " last=" + lastName + ", org=" + organization + ", country=" + countryIsoCode3;
}
public String getPid() {
return pid;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public String getOrganization() {
return organization;
}
public String getCountryIsoCode3() {
return countryIsoCode3;
}
public String getAddress() {
return address;
}
public String getShipAddress() {
return shipAddress;
}
public String getShipCountry() {
return shipCountry;
}
}
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.service.impl;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.service.EasySMTA;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@Profile({ "dev", "cacher" })
@Component
public class EasySMTAMockConnector implements EasySMTA {
private static final Log LOG = LogFactory.getLog(EasySMTAMockConnector.class);
@Override
public EasySMTA.EasySMTAUserData getUserData(String emailAddress) {
LOG.info("Mock EasySMTA connector for email: " + emailAddress);
if (RandomUtils.nextBoolean()) {
LOG.info("Valid mock EasySMTA check");
return new EasySMTA.EasySMTAUserData(RandomStringUtils.randomAlphanumeric(6), "Name", "Surname", emailAddress, "Organization", "DEU", "Address 1",
"Address 2", "DEU");
} else {
LOG.info("Invalid mock EasySMTA check");
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment