Skip to content

Commit 4c4f867

Browse files
CecileBONINSilverYoCha
authored andcommitted
fixing bug #4393 Administration : Manque d'informations sur la création d'un domaine SQL avec espaces et/ou accents
1 parent 72280a4 commit 4c4f867

File tree

11 files changed

+84
-160
lines changed

11 files changed

+84
-160
lines changed

config-core/src/main/config/silvertrace/messages/adminMessages_en.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ admin.EX_ERR_WACOMPONENT = Error in the builder
186186
admin.EX_ERR_MOVE_COMPONENT = Error during the move of a component
187187

188188
admin.MSG_ERR_ADD_DOMAIN = Error while adding a domain
189+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST = The domain's name already exists (in database or in the properties files)
190+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DATABASE = The domain's name already exists in database
191+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DOMAIN_PROPERTIES = The domain's name already exists in the domain's properties file
192+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_AUTHENTICATION_PROPERTIES = The domain's name already exists in the authentication properties file
189193
admin.MSG_ERR_ADD_COMPONENT = Error while adding a componant
190194
admin.MSG_ERR_ADD_PROFILE = Error while adding a role
191195
admin.MSG_ERR_ADD_SPACE = Error while adding a space

config-core/src/main/config/silvertrace/messages/adminMessages_fr.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ admin.EX_ERR_WACOMPONENT = Erreur dans le constructeur
186186
admin.EX_ERR_MOVE_COMPONENT = Erreur lors du déplacement de l'application
187187

188188
admin.MSG_ERR_ADD_DOMAIN = Erreur dans l'ajout du domaine
189+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST = Le nom de domaine existe déjà (en base ou dans les fichiers properties)
190+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DATABASE = Le nom de domaine existe déjà en base
191+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DOMAIN_PROPERTIES = Le nom de domaine existe déjà dans le fichier de properties de domaine
192+
admin.MSG_ERR_DOMAIN_ALREADY_EXIST_AUTHENTICATION_PROPERTIES = Le nom de domaine existe déjà dans le fichier de properties d'authentication
189193
admin.MSG_ERR_ADD_COMPONENT = Erreur dans l'ajout de l'application
190194
admin.MSG_ERR_ADD_PROFILE = Erreur dans l'ajout du rôle
191195
admin.MSG_ERR_ADD_SPACE = Erreur dans l'ajout de l'espace

lib-core/src/main/java/org/silverpeas/admin/domain/AbstractDomainService.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424

2525
package org.silverpeas.admin.domain;
2626

27-
import org.apache.commons.lang.StringUtils;
2827
import org.silverpeas.admin.domain.exception.DomainConflictException;
2928
import org.silverpeas.admin.domain.exception.DomainCreationException;
3029
import org.silverpeas.admin.domain.exception.DomainDeletionException;
3130
import org.silverpeas.admin.domain.exception.NameAlreadyExistsInDatabaseException;
32-
import org.silverpeas.admin.domain.exception.NonAlphaNumericDetectedException;
33-
import org.silverpeas.admin.domain.exception.WhiteSpacesDetectedException;
3431

3532
import com.stratelia.silverpeas.silvertrace.SilverTrace;
3633
import com.stratelia.webactiv.beans.admin.Admin;
@@ -48,19 +45,9 @@ public abstract class AbstractDomainService implements DomainService {
4845
* @throws AdminException if a technical problem occurs during checks
4946
*/
5047
protected void checkDomainName(String domainName)
51-
throws DomainConflictException, AdminException {
48+
throws AdminException, NameAlreadyExistsInDatabaseException {
5249

53-
// Check 1 - Detects white spaces in domain name
54-
if (StringUtils.contains(domainName, ' ')) {
55-
throw new WhiteSpacesDetectedException(domainName);
56-
}
57-
58-
// Check 2 - Detects non-alphanumerics characters
59-
if (!StringUtils.isAlphanumeric(domainName)) {
60-
throw new NonAlphaNumericDetectedException(domainName);
61-
}
62-
63-
// Check 3 - Check domain name availability in database
50+
// Check domain name availability in database
6451
Admin adminService = AdminReference.getAdminService();
6552
Domain[] tabDomain = adminService.getAllDomains();
6653
for (Domain domain : tabDomain) {
@@ -113,5 +100,4 @@ protected String unRegisterDomain(Domain domainToRemove) throws DomainDeletionEx
113100
throw new DomainDeletionException("AbstractDomainService.unRegisterDomain()", e);
114101
}
115102
}
116-
117103
}

lib-core/src/main/java/org/silverpeas/admin/domain/SQLDomainService.java

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.stratelia.webactiv.beans.admin.AdminException;
4848
import com.stratelia.webactiv.beans.admin.Domain;
4949
import com.stratelia.webactiv.util.FileRepositoryManager;
50+
import com.stratelia.webactiv.util.FileServerUtils;
5051
import com.stratelia.webactiv.util.ResourceLocator;
5152

5253
@Named("sqlDomainService")
@@ -64,41 +65,62 @@ void init() {
6465
new ResourceLocator("org.silverpeas.domains.templateDomainSQL", "");
6566
adminSettings = new ResourceLocator("org.silverpeas.beans.admin.admin", "");
6667
}
67-
68-
@Override
69-
protected void checkDomainName(String domainName) throws DomainConflictException, AdminException {
70-
71-
// Commons checks
72-
super.checkDomainName(domainName);
73-
74-
// Check properties files availability
75-
// org.silverpeas.domains.domain<domainName>.properties
76-
// org.silverpeas.authentication.autDomain<domainName>.properties
77-
String authenticationPropertiesPath =
78-
FileRepositoryManager.getDomainAuthenticationPropertiesPath(domainName);
79-
String domainPropertiesPath = FileRepositoryManager.getDomainPropertiesPath(domainName);
80-
81-
if (new File(authenticationPropertiesPath).exists()) {
82-
throw new DomainAuthenticationPropertiesAlreadyExistsException(domainName);
83-
}
84-
85-
if (new File(domainPropertiesPath).exists()) {
86-
throw new DomainPropertiesAlreadyExistsException(domainName);
87-
}
88-
}
68+
69+
private void checkFileName(String fileDomainName) throws DomainAuthenticationPropertiesAlreadyExistsException, DomainPropertiesAlreadyExistsException {
70+
// Check properties files availability
71+
// org.silverpeas.domains.domain<domainName>.properties
72+
// org.silverpeas.authentication.autDomain<domainName>.properties
73+
String authenticationPropertiesPath =
74+
FileRepositoryManager.getDomainAuthenticationPropertiesPath(fileDomainName);
75+
String domainPropertiesPath = FileRepositoryManager.getDomainPropertiesPath(fileDomainName);
76+
77+
if (new File(authenticationPropertiesPath).exists()) {
78+
throw new DomainAuthenticationPropertiesAlreadyExistsException(fileDomainName);
79+
}
80+
81+
if (new File(domainPropertiesPath).exists()) {
82+
throw new DomainPropertiesAlreadyExistsException(fileDomainName);
83+
}
84+
}
85+
86+
//transformation du nom du domaine, nécessaire pour pouvoir créer les fichiers sur le fileSystem
87+
//et créer les tables dans la BD
88+
private String getCorrectDomainFileName(String domainName) {
89+
//remplace les caractères accentués non compatibles avec les fichiers fileSystem et les noms de tables BD par les caractères non accentués correspondants
90+
String fileDomainName = FileServerUtils.replaceAccentChars(domainName);
91+
92+
//remplace les caractères spéciaux et les espaces non compatibles avec les fichiers fileSystem et les noms de tables BD par caractère '_'
93+
fileDomainName = fileDomainName.replaceAll("[^A-Za-z0-9]", "_");
94+
95+
//tronque le nom à 42 caractères pour être compatible avec les noms de tables BD
96+
if (fileDomainName.length()>42) {
97+
fileDomainName = fileDomainName.substring(0, 42);
98+
}
99+
100+
return fileDomainName;
101+
}
89102

90103
@Override
91104
public String createDomain(Domain domainToCreate) throws DomainConflictException,
92105
DomainCreationException {
93106

94107
// Check domain name
95-
String domainName = domainToCreate.getName();
108+
String initialDomainName = domainToCreate.getName();
96109
try {
97-
checkDomainName(domainName);
110+
checkDomainName(initialDomainName);
98111
} catch (AdminException e) {
99112
throw new DomainCreationException("SQLDomainService.createDomain", domainToCreate.toString(),
100113
e);
101114
}
115+
116+
//file domain name
117+
String fileDomainName = getCorrectDomainFileName(initialDomainName);
118+
119+
//check fileSystem
120+
checkFileName(fileDomainName);
121+
122+
//set nouveau nom pour le fileSystem et la BD
123+
domainToCreate.setName(fileDomainName);
102124

103125
// Generates domain properties file
104126
generateDomainPropertiesFile(domainToCreate);
@@ -110,7 +132,7 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
110132
try {
111133
dao.createDomainStorage(domainToCreate);
112134
} catch (Exception e) {
113-
removePropertiesFiles(domainName);
135+
removePropertiesFiles(fileDomainName);
114136
throw new DomainCreationException("SQLDomainService.createDomain", domainToCreate.toString(),
115137
e);
116138
}
@@ -120,17 +142,24 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
120142
if (!StringUtil.isDefined(domainToCreate.getDriverClassName())) {
121143
domainToCreate.setDriverClassName("com.stratelia.silverpeas.domains.sqldriver.SQLDriver");
122144
}
123-
domainToCreate.setPropFileName("org.silverpeas.domains.domain" + domainName);
124-
domainToCreate.setAuthenticationServer("autDomain" + domainName);
145+
domainToCreate.setPropFileName("org.silverpeas.domains.domain" + fileDomainName);
146+
domainToCreate.setAuthenticationServer("autDomain" + fileDomainName);
125147
domainToCreate.setTheTimeStamp("0");
148+
149+
// Enregistre le nom initial dans la table st_domain
150+
domainToCreate.setName(initialDomainName);
126151
String domainId = registerDomain(domainToCreate);
152+
153+
//set nouveau nom pour le fileSystem et la BD
154+
domainToCreate.setName(fileDomainName);
155+
127156
if (!StringUtil.isDefined(domainId)) {
128157
try {
129158
dao.deleteDomainStorage(domainToCreate);
130159
} catch (Exception e) {
131-
removePropertiesFiles(domainName);
160+
removePropertiesFiles(fileDomainName);
132161
}
133-
removePropertiesFiles(domainName);
162+
removePropertiesFiles(fileDomainName);
134163
}
135164

136165
return domainId;
@@ -139,12 +168,17 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
139168
@Override
140169
public String deleteDomain(Domain domainToRemove) throws DomainDeletionException {
141170

142-
// unregister new Domain
171+
//set nouveau nom pour le fileSystem et la BD
172+
String domainPropertiesPath = domainToRemove.getPropFileName();
173+
String fileDomainName = domainPropertiesPath.substring(29); //supprime org.silverpeas.domains.domain
174+
domainToRemove.setName(fileDomainName);
175+
176+
// unregister new Domain dans st_domain
143177
String domainId = unRegisterDomain(domainToRemove);
144178
if (!StringUtil.isDefined(domainId)) {
145179
throw new DomainDeletionException("SQLDomainService.deleteDomain");
146180
}
147-
181+
148182
// Remove storage
149183
try {
150184
dao.deleteDomainStorage(domainToRemove);
@@ -183,6 +217,7 @@ private void generateDomainPropertiesFile(Domain domainToCreate) throws DomainCr
183217
"root.MSG_GEN_ENTER_METHOD");
184218

185219
String domainName = domainToCreate.getName();
220+
186221
String domainPropertiesPath = FileRepositoryManager.getDomainPropertiesPath(domainName);
187222

188223
SilverpeasTemplate template = getNewTemplate();

lib-core/src/main/java/org/silverpeas/admin/domain/exception/DomainAuthenticationPropertiesAlreadyExistsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class DomainAuthenticationPropertiesAlreadyExistsException extends Domain
3333
private static final long serialVersionUID = -1196587632333002256L;
3434

3535
public DomainAuthenticationPropertiesAlreadyExistsException(String domainName) {
36-
super("AbstractDomainService", "admin.DOMAIN_AUTHENTICATION_PROPERTIES_ALREADY_EXISTS",
36+
super("AbstractDomainService", "admin.MSG_ERR_DOMAIN_ALREADY_EXIST_AUTHENTICATION_PROPERTIES",
3737
domainName);
3838
}
3939
}

lib-core/src/main/java/org/silverpeas/admin/domain/exception/DomainPropertiesAlreadyExistsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class DomainPropertiesAlreadyExistsException extends DomainConflictExcept
3333
private static final long serialVersionUID = -1196587632333002256L;
3434

3535
public DomainPropertiesAlreadyExistsException(String domainName) {
36-
super("AbstractDomainService", "admin.DOMAIN_PROPERTIES_ALREADY_EXISTS", domainName);
36+
super("AbstractDomainService", "admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DOMAIN_PROPERTIES", domainName);
3737
}
3838
}

lib-core/src/main/java/org/silverpeas/admin/domain/exception/NameAlreadyExistsInDatabaseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class NameAlreadyExistsInDatabaseException extends DomainConflictExceptio
3333
private static final long serialVersionUID = -1196587632333002256L;
3434

3535
public NameAlreadyExistsInDatabaseException(String domainName) {
36-
super("AbstractDomainService", "admin.DOMAIN_NAME_ALREADY_EXISTS_IN_DATABASE", domainName);
36+
super("AbstractDomainService", "admin.MSG_ERR_DOMAIN_ALREADY_EXIST_DATABASE", domainName);
3737
}
3838
}

lib-core/src/main/java/org/silverpeas/admin/domain/exception/NonAlphaNumericDetectedException.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib-core/src/main/java/org/silverpeas/admin/domain/exception/WhiteSpacesDetectedException.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

lib-core/src/test/java/org/silverpeas/admin/domain/SQLDomainServiceTest.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
import org.silverpeas.admin.domain.exception.DomainAuthenticationPropertiesAlreadyExistsException;
5454
import org.silverpeas.admin.domain.exception.DomainPropertiesAlreadyExistsException;
5555
import org.silverpeas.admin.domain.exception.NameAlreadyExistsInDatabaseException;
56-
import org.silverpeas.admin.domain.exception.NonAlphaNumericDetectedException;
57-
import org.silverpeas.admin.domain.exception.WhiteSpacesDetectedException;
5856
import org.springframework.context.ApplicationContext;
5957
import org.springframework.context.support.ClassPathXmlApplicationContext;
6058
import org.springframework.test.context.transaction.TransactionConfiguration;
@@ -222,39 +220,13 @@ public void testCreateDomain() throws Exception {
222220
testTablesExistence(true);
223221
}
224222

225-
@Test
226-
@Transactional
227-
public void testCreateDomainWithWhiteSpaces() throws Exception {
228-
Domain domain = new Domain();
229-
domain.setName("Test Creation");
230-
try {
231-
String domainId = service.createDomain(domain);
232-
fail("Exception must have been thrown");
233-
} catch (Exception e) {
234-
assertThat(e instanceof WhiteSpacesDetectedException, is(true));
235-
}
236-
}
237-
238-
@Test
239-
@Transactional
240-
public void testCreateDomainWithNonAlphaChars() throws Exception {
241-
Domain domain = new Domain();
242-
domain.setName("Test+Creation");
243-
try {
244-
String domainId = service.createDomain(domain);
245-
fail("Exception must have been thrown");
246-
} catch (Exception e) {
247-
assertThat(e instanceof NonAlphaNumericDetectedException, is(true));
248-
}
249-
}
250-
251223
@Test
252224
@Transactional
253225
public void testCreateDomainAlreadyInDB() throws Exception {
254226
Domain domain = new Domain();
255227
domain.setName("Customers");
256228
try {
257-
String domainId = service.createDomain(domain);
229+
service.createDomain(domain);
258230
fail("Exception must have been thrown");
259231
} catch (Exception e) {
260232
assertThat(e instanceof NameAlreadyExistsInDatabaseException, is(true));
@@ -271,7 +243,7 @@ public void testCreateDomainWithPropertiesNameConflicts() throws Exception {
271243
FileUtils.touch(conflictousPropertiesFile);
272244
conflictousPropertiesFile.deleteOnExit();
273245
try {
274-
String domainId = service.createDomain(domain);
246+
service.createDomain(domain);
275247
fail("Exception must have been thrown");
276248
} catch (Exception e) {
277249
assertThat(e instanceof DomainPropertiesAlreadyExistsException, is(true));
@@ -282,7 +254,7 @@ public void testCreateDomainWithPropertiesNameConflicts() throws Exception {
282254
FileUtils.touch(conflictousPropertiesFile);
283255
// create domain
284256
try {
285-
String domainId = service.createDomain(domain);
257+
service.createDomain(domain);
286258
fail("Exception must have been thrown");
287259
} catch (Exception e) {
288260
assertThat(e instanceof DomainAuthenticationPropertiesAlreadyExistsException, is(true));

0 commit comments

Comments
 (0)