mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 07:07:57 +01:00
#179: default language (api)
This commit is contained in:
parent
66cd4abd8b
commit
9a9e86829e
@ -20,6 +20,11 @@ public enum ConfigType {
|
|||||||
*/
|
*/
|
||||||
GUEST_LOGIN,
|
GUEST_LOGIN,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default language.
|
||||||
|
*/
|
||||||
|
DEFAULT_LANGUAGE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP server configuration.
|
* SMTP server configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -1 +1 @@
|
|||||||
db.version=15
|
db.version=16
|
@ -0,0 +1,2 @@
|
|||||||
|
insert into T_CONFIG(CFG_ID_C, CFG_VALUE_C) values('DEFAULT_LANGUAGE', 'eng');
|
||||||
|
update T_CONFIG set CFG_VALUE_C = '16' where CFG_ID_C = 'DB_VERSION';
|
@ -1,3 +1,3 @@
|
|||||||
api.current_version=${project.version}
|
api.current_version=${project.version}
|
||||||
api.min_version=1.0
|
api.min_version=1.0
|
||||||
db.version=15
|
db.version=16
|
@ -16,6 +16,7 @@ import com.sismics.docs.core.util.DirectoryUtil;
|
|||||||
import com.sismics.docs.core.util.jpa.PaginatedList;
|
import com.sismics.docs.core.util.jpa.PaginatedList;
|
||||||
import com.sismics.docs.core.util.jpa.PaginatedLists;
|
import com.sismics.docs.core.util.jpa.PaginatedLists;
|
||||||
import com.sismics.docs.rest.constant.BaseFunction;
|
import com.sismics.docs.rest.constant.BaseFunction;
|
||||||
|
import com.sismics.rest.exception.ClientException;
|
||||||
import com.sismics.rest.exception.ForbiddenClientException;
|
import com.sismics.rest.exception.ForbiddenClientException;
|
||||||
import com.sismics.rest.exception.ServerException;
|
import com.sismics.rest.exception.ServerException;
|
||||||
import com.sismics.rest.util.ValidationUtil;
|
import com.sismics.rest.util.ValidationUtil;
|
||||||
@ -39,6 +40,7 @@ import javax.ws.rs.core.Response;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,6 +81,7 @@ public class AppResource extends BaseResource {
|
|||||||
String currentVersion = configBundle.getString("api.current_version");
|
String currentVersion = configBundle.getString("api.current_version");
|
||||||
String minVersion = configBundle.getString("api.min_version");
|
String minVersion = configBundle.getString("api.min_version");
|
||||||
Boolean guestLogin = ConfigUtil.getConfigBooleanValue(ConfigType.GUEST_LOGIN);
|
Boolean guestLogin = ConfigUtil.getConfigBooleanValue(ConfigType.GUEST_LOGIN);
|
||||||
|
String defaultLanguage = ConfigUtil.getConfigStringValue(ConfigType.DEFAULT_LANGUAGE);
|
||||||
UserDao userDao = new UserDao();
|
UserDao userDao = new UserDao();
|
||||||
DocumentDao documentDao = new DocumentDao();
|
DocumentDao documentDao = new DocumentDao();
|
||||||
String globalQuotaStr = System.getenv(Constants.GLOBAL_QUOTA_ENV);
|
String globalQuotaStr = System.getenv(Constants.GLOBAL_QUOTA_ENV);
|
||||||
@ -91,6 +94,7 @@ public class AppResource extends BaseResource {
|
|||||||
.add("current_version", currentVersion.replace("-SNAPSHOT", ""))
|
.add("current_version", currentVersion.replace("-SNAPSHOT", ""))
|
||||||
.add("min_version", minVersion)
|
.add("min_version", minVersion)
|
||||||
.add("guest_login", guestLogin)
|
.add("guest_login", guestLogin)
|
||||||
|
.add("default_language", defaultLanguage)
|
||||||
.add("total_memory", Runtime.getRuntime().totalMemory())
|
.add("total_memory", Runtime.getRuntime().totalMemory())
|
||||||
.add("free_memory", Runtime.getRuntime().freeMemory())
|
.add("free_memory", Runtime.getRuntime().freeMemory())
|
||||||
.add("document_count", documentDao.getDocumentCount())
|
.add("document_count", documentDao.getDocumentCount())
|
||||||
@ -131,6 +135,38 @@ public class AppResource extends BaseResource {
|
|||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General application configuration.
|
||||||
|
*
|
||||||
|
* @api {post} /app/config General application configuration
|
||||||
|
* @apiName PostAppConfig
|
||||||
|
* @apiGroup App
|
||||||
|
* @apiParam {String} default_language Default language
|
||||||
|
* @apiError (client) ForbiddenError Access denied
|
||||||
|
* @apiPermission admin
|
||||||
|
* @apiVersion 1.5.0
|
||||||
|
*
|
||||||
|
* @param defaultLanguage Default language
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("config")
|
||||||
|
public Response config(@FormParam("default_language") String defaultLanguage) {
|
||||||
|
if (!authenticate()) {
|
||||||
|
throw new ForbiddenClientException();
|
||||||
|
}
|
||||||
|
checkBaseFunction(BaseFunction.ADMIN);
|
||||||
|
ValidationUtil.validateRequired(defaultLanguage, "default_language");
|
||||||
|
if (!Constants.SUPPORTED_LANGUAGES.contains(defaultLanguage)) {
|
||||||
|
throw new ClientException("ValidationError", MessageFormat.format("{0} is not a supported language", defaultLanguage));
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigDao configDao = new ConfigDao();
|
||||||
|
configDao.update(ConfigType.DEFAULT_LANGUAGE, defaultLanguage);
|
||||||
|
|
||||||
|
return Response.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the SMTP server configuration.
|
* Get the SMTP server configuration.
|
||||||
*
|
*
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
api.current_version=${project.version}
|
api.current_version=${project.version}
|
||||||
api.min_version=1.0
|
api.min_version=1.0
|
||||||
db.version=15
|
db.version=16
|
@ -1,3 +1,3 @@
|
|||||||
api.current_version=${project.version}
|
api.current_version=${project.version}
|
||||||
api.min_version=1.0
|
api.min_version=1.0
|
||||||
db.version=15
|
db.version=16
|
@ -36,6 +36,7 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
Long totalMemory = json.getJsonNumber("total_memory").longValue();
|
Long totalMemory = json.getJsonNumber("total_memory").longValue();
|
||||||
Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory);
|
Assert.assertTrue(totalMemory > 0 && totalMemory > freeMemory);
|
||||||
Assert.assertFalse(json.getBoolean("guest_login"));
|
Assert.assertFalse(json.getBoolean("guest_login"));
|
||||||
|
Assert.assertEquals("eng", json.getString("default_language"));
|
||||||
Assert.assertTrue(json.containsKey("global_storage_current"));
|
Assert.assertTrue(json.containsKey("global_storage_current"));
|
||||||
Assert.assertTrue(json.getJsonNumber("active_user_count").longValue() > 0);
|
Assert.assertTrue(json.getJsonNumber("active_user_count").longValue() > 0);
|
||||||
|
|
||||||
@ -56,6 +57,28 @@ public class TestAppResource extends BaseJerseyTest {
|
|||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
.post(Entity.form(new Form()));
|
.post(Entity.form(new Form()));
|
||||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
|
||||||
|
// Change the default language
|
||||||
|
response = target().path("/app/config").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.post(Entity.form(new Form().param("default_language", "fra")));
|
||||||
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
|
||||||
|
// Check the application info
|
||||||
|
json = target().path("/app").request()
|
||||||
|
.get(JsonObject.class);
|
||||||
|
Assert.assertEquals("fra", json.getString("default_language"));
|
||||||
|
|
||||||
|
// Change the default language
|
||||||
|
response = target().path("/app/config").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.post(Entity.form(new Form().param("default_language", "eng")));
|
||||||
|
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||||
|
|
||||||
|
// Check the application info
|
||||||
|
json = target().path("/app").request()
|
||||||
|
.get(JsonObject.class);
|
||||||
|
Assert.assertEquals("eng", json.getString("default_language"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user