| 1 |
|
package com.atlassian.mail.server.managers; |
| 2 |
|
|
| 3 |
|
import com.atlassian.core.util.ClassLoaderUtils; |
| 4 |
|
import com.atlassian.mail.MailException; |
| 5 |
|
import com.atlassian.mail.config.ConfigLoader; |
| 6 |
|
import com.atlassian.mail.server.MailServer; |
| 7 |
|
import com.atlassian.mail.server.PopMailServer; |
| 8 |
|
import com.atlassian.mail.server.SMTPMailServer; |
| 9 |
|
import com.atlassian.mail.server.impl.PopMailServerImpl; |
| 10 |
|
import com.atlassian.mail.server.impl.SMTPMailServerImpl; |
| 11 |
|
import org.apache.commons.digester.Digester; |
| 12 |
|
import org.apache.commons.digester.ExtendedBaseRules; |
| 13 |
|
import org.apache.log4j.Category; |
| 14 |
|
|
| 15 |
|
import java.io.InputStream; |
| 16 |
|
import java.util.*; |
| 17 |
|
|
|
|
|
| 73.9% |
Uncovered Elements: 30 (115) |
Complexity: 31 |
Complexity Density: 0.44 |
|
| 18 |
|
public class XMLMailServerManager extends AbstractMailServerManager |
| 19 |
|
{ |
| 20 |
|
private static final Category log = Category.getInstance(XMLMailServerManager.class); |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
Map serverIds; |
| 24 |
|
|
| 25 |
|
private static String DEFAULT_CONFIG_FILE = "mail-servers.xml"; |
| 26 |
|
|
| 27 |
|
String configFile; |
| 28 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 29 |
7
|
public void init(Map params)... |
| 30 |
|
{ |
| 31 |
7
|
configFile = DEFAULT_CONFIG_FILE; |
| 32 |
7
|
serverIds = new HashMap(); |
| 33 |
|
|
| 34 |
7
|
if (params.containsKey("config-file")) |
| 35 |
|
{ |
| 36 |
6
|
configFile = (String) params.get("config-file"); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
7
|
configure(); |
| 40 |
|
} |
| 41 |
|
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 2 |
Complexity Density: 0.12 |
|
| 42 |
7
|
private void configure()... |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
7
|
try |
| 46 |
|
{ |
| 47 |
7
|
Digester digester = new Digester(); |
| 48 |
7
|
digester.push(this); |
| 49 |
7
|
digester.setRules(new ExtendedBaseRules()); |
| 50 |
|
|
| 51 |
|
|
| 52 |
7
|
digester.addObjectCreate("mail-servers/pop-server", getPopMailServerClass()); |
| 53 |
7
|
digester.addSetProperties("mail-servers/pop-server"); |
| 54 |
7
|
digester.addBeanPropertySetter("mail-servers/pop-server/?"); |
| 55 |
7
|
digester.addSetRoot("mail-servers/pop-server", "create"); |
| 56 |
|
|
| 57 |
|
|
| 58 |
7
|
digester.addObjectCreate("mail-servers/smtp-server", getSMTPMailServerClass()); |
| 59 |
7
|
digester.addSetProperties("mail-servers/smtp-server"); |
| 60 |
7
|
digester.addBeanPropertySetter("mail-servers/smtp-server/?"); |
| 61 |
7
|
digester.addBeanPropertySetter("mail-servers/smtp-server/jndi-location", "jndiLocation"); |
| 62 |
7
|
digester.addSetRoot("mail-servers/smtp-server", "create"); |
| 63 |
|
|
| 64 |
7
|
InputStream is = getConfigurationInputStream(configFile); |
| 65 |
7
|
digester.parse(is); |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
} |
| 69 |
|
catch (Exception e) |
| 70 |
|
{ |
| 71 |
0
|
log.fatal(e, e); |
| 72 |
0
|
throw new RuntimeException("Error in mail config: " + e.getMessage(), e); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
7
|
protected InputStream getConfigurationInputStream(String resource)... |
| 77 |
|
{ |
| 78 |
7
|
return ClassLoaderUtils.getResourceAsStream(resource, ConfigLoader.class); |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
3
|
public String getConfigFile()... |
| 82 |
|
{ |
| 83 |
3
|
return configFile; |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
1
|
public MailServer getMailServer(Long id)... |
| 87 |
|
{ |
| 88 |
1
|
return (MailServer) serverIds.get(id); |
| 89 |
|
} |
| 90 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 91 |
0
|
public MailServer getMailServer(String name) throws MailException... |
| 92 |
|
{ |
| 93 |
0
|
if (name == null) |
| 94 |
0
|
throw new MailException("name is null"); |
| 95 |
|
|
| 96 |
0
|
for (Iterator iterator = serverIds.values().iterator(); iterator.hasNext();) |
| 97 |
|
{ |
| 98 |
0
|
MailServer server = (MailServer) iterator.next(); |
| 99 |
0
|
if (name.equals(server.getName())) |
| 100 |
0
|
return server; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0
|
return null; |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 106 |
15
|
public synchronized Long create(MailServer mailServer) throws MailException... |
| 107 |
|
{ |
| 108 |
15
|
Long id = new Long((serverIds.size() + 1)); |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
16
|
while (serverIds.containsKey(id)) |
| 113 |
1
|
id = new Long(id.longValue() + 1); |
| 114 |
|
|
| 115 |
15
|
mailServer.setId(id); |
| 116 |
15
|
serverIds.put(id, mailServer); |
| 117 |
15
|
return id; |
| 118 |
|
} |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
1
|
public void update(MailServer mailServer) throws MailException... |
| 121 |
|
{ |
| 122 |
1
|
serverIds.put(mailServer.getId(), mailServer); |
| 123 |
|
} |
| 124 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 125 |
3
|
public void delete(Long mailServerId) throws MailException... |
| 126 |
|
{ |
| 127 |
3
|
if (mailServerId == null) |
| 128 |
0
|
throw new MailException("mailServerId is null"); |
| 129 |
3
|
if (!serverIds.containsKey(mailServerId)) |
| 130 |
1
|
throw new MailException("A mail server with the specified mailServerId does not exist"); |
| 131 |
|
|
| 132 |
2
|
serverIds.remove(mailServerId); |
| 133 |
|
} |
| 134 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 135 |
0
|
public List getServerNames() throws MailException... |
| 136 |
|
{ |
| 137 |
0
|
List result = new ArrayList(); |
| 138 |
|
|
| 139 |
0
|
for (Iterator iterator = serverIds.values().iterator(); iterator.hasNext();) |
| 140 |
|
{ |
| 141 |
0
|
MailServer server = (MailServer) iterator.next(); |
| 142 |
0
|
result.add(server.getName()); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
0
|
return result; |
| 146 |
|
} |
| 147 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 148 |
7
|
public List getSmtpMailServers() throws MailException... |
| 149 |
|
{ |
| 150 |
7
|
List result = new ArrayList(); |
| 151 |
|
|
| 152 |
18
|
for (Iterator iterator = serverIds.values().iterator(); iterator.hasNext();) |
| 153 |
|
{ |
| 154 |
11
|
MailServer server = (MailServer) iterator.next(); |
| 155 |
11
|
if (server instanceof SMTPMailServer) |
| 156 |
6
|
result.add(server); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
7
|
return result; |
| 160 |
|
} |
| 161 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 162 |
3
|
public List getPopMailServers() throws MailException... |
| 163 |
|
{ |
| 164 |
3
|
List result = new ArrayList(); |
| 165 |
|
|
| 166 |
8
|
for (Iterator iterator = serverIds.values().iterator(); iterator.hasNext();) |
| 167 |
|
{ |
| 168 |
5
|
MailServer server = (MailServer) iterator.next(); |
| 169 |
5
|
if (server instanceof PopMailServer) |
| 170 |
2
|
result.add(server); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
3
|
return result; |
| 174 |
|
} |
| 175 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 176 |
2
|
public SMTPMailServer getDefaultSMTPMailServer() throws MailException... |
| 177 |
|
{ |
| 178 |
2
|
List smtpServers = getSmtpMailServers(); |
| 179 |
|
|
| 180 |
2
|
if (smtpServers.size() > 0) |
| 181 |
2
|
return (SMTPMailServer) smtpServers.get(0); |
| 182 |
|
|
| 183 |
0
|
return null; |
| 184 |
|
} |
| 185 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 186 |
1
|
public PopMailServer getDefaultPopMailServer() throws MailException... |
| 187 |
|
{ |
| 188 |
1
|
List popServers = getPopMailServers(); |
| 189 |
|
|
| 190 |
1
|
if (popServers.size() > 0) |
| 191 |
1
|
return (PopMailServer) popServers.get(0); |
| 192 |
|
|
| 193 |
0
|
return null; |
| 194 |
|
} |
| 195 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 196 |
7
|
protected Class getSMTPMailServerClass()... |
| 197 |
|
{ |
| 198 |
7
|
return SMTPMailServerImpl.class; |
| 199 |
|
} |
| 200 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 201 |
7
|
protected Class getPopMailServerClass()... |
| 202 |
|
{ |
| 203 |
7
|
return PopMailServerImpl.class; |
| 204 |
|
} |
| 205 |
|
} |