Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
963058fb
Commit
963058fb
authored
Mar 27, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mock EasySMTA connector
parent
4f1c2f19
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
150 additions
and
74 deletions
+150
-74
src/main/java/org/genesys2/server/service/EasySMTA.java
src/main/java/org/genesys2/server/service/EasySMTA.java
+97
-0
src/main/java/org/genesys2/server/service/impl/EasySMTAConnector.java
...a/org/genesys2/server/service/impl/EasySMTAConnector.java
+7
-74
src/main/java/org/genesys2/server/service/impl/EasySMTAMockConnector.java
...g/genesys2/server/service/impl/EasySMTAMockConnector.java
+46
-0
No files found.
src/main/java/org/genesys2/server/service/EasySMTA.java
0 → 100644
View file @
963058fb
/**
* 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
;
}
}
}
src/main/java/org/genesys2/server/service/impl/EasySMTAConnector.java
View file @
963058fb
...
...
@@ -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
.
EasySMTA
UserData
(
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
;
}
}
}
src/main/java/org/genesys2/server/service/impl/EasySMTAMockConnector.java
0 → 100644
View file @
963058fb
/**
* 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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment