47
47
import com .stratelia .webactiv .beans .admin .AdminException ;
48
48
import com .stratelia .webactiv .beans .admin .Domain ;
49
49
import com .stratelia .webactiv .util .FileRepositoryManager ;
50
+ import com .stratelia .webactiv .util .FileServerUtils ;
50
51
import com .stratelia .webactiv .util .ResourceLocator ;
51
52
52
53
@ Named ("sqlDomainService" )
@@ -64,41 +65,62 @@ void init() {
64
65
new ResourceLocator ("org.silverpeas.domains.templateDomainSQL" , "" );
65
66
adminSettings = new ResourceLocator ("org.silverpeas.beans.admin.admin" , "" );
66
67
}
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
+ }
89
102
90
103
@ Override
91
104
public String createDomain (Domain domainToCreate ) throws DomainConflictException ,
92
105
DomainCreationException {
93
106
94
107
// Check domain name
95
- String domainName = domainToCreate .getName ();
108
+ String initialDomainName = domainToCreate .getName ();
96
109
try {
97
- checkDomainName (domainName );
110
+ checkDomainName (initialDomainName );
98
111
} catch (AdminException e ) {
99
112
throw new DomainCreationException ("SQLDomainService.createDomain" , domainToCreate .toString (),
100
113
e );
101
114
}
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 );
102
124
103
125
// Generates domain properties file
104
126
generateDomainPropertiesFile (domainToCreate );
@@ -110,7 +132,7 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
110
132
try {
111
133
dao .createDomainStorage (domainToCreate );
112
134
} catch (Exception e ) {
113
- removePropertiesFiles (domainName );
135
+ removePropertiesFiles (fileDomainName );
114
136
throw new DomainCreationException ("SQLDomainService.createDomain" , domainToCreate .toString (),
115
137
e );
116
138
}
@@ -120,17 +142,24 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
120
142
if (!StringUtil .isDefined (domainToCreate .getDriverClassName ())) {
121
143
domainToCreate .setDriverClassName ("com.stratelia.silverpeas.domains.sqldriver.SQLDriver" );
122
144
}
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 );
125
147
domainToCreate .setTheTimeStamp ("0" );
148
+
149
+ // Enregistre le nom initial dans la table st_domain
150
+ domainToCreate .setName (initialDomainName );
126
151
String domainId = registerDomain (domainToCreate );
152
+
153
+ //set nouveau nom pour le fileSystem et la BD
154
+ domainToCreate .setName (fileDomainName );
155
+
127
156
if (!StringUtil .isDefined (domainId )) {
128
157
try {
129
158
dao .deleteDomainStorage (domainToCreate );
130
159
} catch (Exception e ) {
131
- removePropertiesFiles (domainName );
160
+ removePropertiesFiles (fileDomainName );
132
161
}
133
- removePropertiesFiles (domainName );
162
+ removePropertiesFiles (fileDomainName );
134
163
}
135
164
136
165
return domainId ;
@@ -139,12 +168,17 @@ public String createDomain(Domain domainToCreate) throws DomainConflictException
139
168
@ Override
140
169
public String deleteDomain (Domain domainToRemove ) throws DomainDeletionException {
141
170
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
143
177
String domainId = unRegisterDomain (domainToRemove );
144
178
if (!StringUtil .isDefined (domainId )) {
145
179
throw new DomainDeletionException ("SQLDomainService.deleteDomain" );
146
180
}
147
-
181
+
148
182
// Remove storage
149
183
try {
150
184
dao .deleteDomainStorage (domainToRemove );
@@ -183,6 +217,7 @@ private void generateDomainPropertiesFile(Domain domainToCreate) throws DomainCr
183
217
"root.MSG_GEN_ENTER_METHOD" );
184
218
185
219
String domainName = domainToCreate .getName ();
220
+
186
221
String domainPropertiesPath = FileRepositoryManager .getDomainPropertiesPath (domainName );
187
222
188
223
SilverpeasTemplate template = getNewTemplate ();
0 commit comments