diff --git a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementEditType.java b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementEditType.java index 18fa9c197550c3f91f55749feeb575961451cb1c..3199cf8921fda50f94f685a325ab5cc004832931 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementEditType.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementEditType.java @@ -47,4 +47,9 @@ public enum ConfigurationElementEditType { * Password value. */ PASSWORD, + + /** + * True/false value. + */ + BOOLEAN, } diff --git a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java index 5c8ca43e5c4be95202256a08f9a9d522c37ee606..fb5b54b6e514e95c796a157df5b2a37fa6f44bde 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java @@ -150,8 +150,17 @@ public enum ConfigurationElementType { * Default content of the email when requesting for an account in the system. */ REQUEST_ACCOUNT_DEFAULT_CONTENT("Email content used for requesting an account", - "Dear Disease map team,\nI would like to request an account in the system.\nKind regards", ConfigurationElementEditType.TEXT, - false), + "Dear Disease map team,\nI would like to request an account in the system.\nKind regards", + ConfigurationElementEditType.TEXT, false), + + DEFAULT_VIEW_PROJECT("Default user privilege for: " + PrivilegeType.VIEW_PROJECT.getCommonName(), "true", + ConfigurationElementEditType.BOOLEAN, false), + + DEFAULT_EDIT_COMMENTS_PROJECT("Default user privilege for: " + PrivilegeType.EDIT_COMMENTS_PROJECT.getCommonName(), + "false", ConfigurationElementEditType.BOOLEAN, false), + + DEFAULT_LAYOUT_MANAGEMENT("Default user privilege for: " + PrivilegeType.LAYOUT_MANAGEMENT.getCommonName(), "false", + ConfigurationElementEditType.BOOLEAN, false), ; diff --git a/model/src/main/java/lcsb/mapviewer/model/user/PrivilegeType.java b/model/src/main/java/lcsb/mapviewer/model/user/PrivilegeType.java index 2ae29adda5813df28b312c1290c906098976040a..be5c1fe1220fc167f988761be1372ee0f4a965f9 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/PrivilegeType.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/PrivilegeType.java @@ -11,140 +11,141 @@ import lcsb.mapviewer.model.map.layout.Layout; */ public enum PrivilegeType { - /** - * User can browse project. - */ - VIEW_PROJECT(ObjectPrivilege.class, Project.class, "View project"), - - /** - * User can add project. - */ - ADD_MAP(BasicPrivilege.class, null, "Add project"), - - /** - * User can edit comments in the project. - */ - EDIT_COMMENTS_PROJECT(ObjectPrivilege.class, Project.class, "Manage comments"), - - /** - * User can manage projects. - */ - PROJECT_MANAGEMENT(BasicPrivilege.class, null, "Map management"), - - /** - * User can manage users. - */ - USER_MANAGEMENT(BasicPrivilege.class, null, "User management"), - - /** - * User can have custom layouts (access level defines how many). - */ - CUSTOM_LAYOUTS(BasicPrivilege.class, null, "Custom layouts", true), - - /** - * User can view non-public layout. - */ - LAYOUT_VIEW(ObjectPrivilege.class, Layout.class, "View layout"), - - /** - * User can manage configuration. - */ - CONFIGURATION_MANAGE(BasicPrivilege.class, null, "Manage configuration"), - - /** - * User can manage layouts of all users in the project. - */ - LAYOUT_MANAGEMENT(ObjectPrivilege.class, Project.class, "Manage layouts"), // - - /** - * User can manage reference genomes. - */ - MANAGE_GENOMES(BasicPrivilege.class, null, "Manage genomes"); - - /** - * Type of privilege (basic or privilege to the object). - */ - private Class<? extends BasicPrivilege> privilegeClassType; - - /** - * Type of the object to which privilege refers. - */ - private Class<?> privilegeObjectType; - - /** - * Name of the privilege. - */ - private String commonName; - - /** - * Is the privilege numeric. - */ - private boolean numeric = false; - - /** - * Constructor that initialize enum with data. - * - * @param privilegeClazz - * {@link #privilegeClassType} - * @param objectClazz - * {@link #privilegeObjectType} - * @param commonName - * {@link #commonName} - */ - PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName) { - this.privilegeClassType = privilegeClazz; - this.privilegeObjectType = objectClazz; - this.commonName = commonName; - } - - /** - * Constructor that initialize enum with data. - * - * @param privilegeClazz - * {@link #privilegeClassType} - * @param objectClazz - * {@link #privilegeObjectType} - * @param commonName - * {@link #commonName} - * @param numeric - * {@link #numeric} - */ - PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName, boolean numeric) { - this.privilegeClassType = privilegeClazz; - this.privilegeObjectType = objectClazz; - this.commonName = commonName; - this.numeric = true; - } - - /** - * - * @return {@link #privilegeClassType} - */ - public Class<? extends BasicPrivilege> getPrivilegeClassType() { - return privilegeClassType; - } - - /** - * - * @return {@link #privilegeObjectType} - */ - public Class<?> getPrivilegeObjectType() { - return privilegeObjectType; - } - - /** - * - * @return {@link #commonName} - */ - public String getCommonName() { - return commonName; - } - - /** - * - * @return {@link #numeric} - */ - public boolean isNumeric() { - return numeric; - } + /** + * User can browse project. + */ + VIEW_PROJECT(ObjectPrivilege.class, Project.class, "View project"), + + /** + * User can add project. + */ + ADD_MAP(BasicPrivilege.class, null, "Add project"), + + /** + * User can edit comments in the project. + */ + EDIT_COMMENTS_PROJECT(ObjectPrivilege.class, Project.class, "Manage comments"), + + /** + * User can manage projects. + */ + PROJECT_MANAGEMENT(BasicPrivilege.class, null, "Map management"), + + /** + * User can manage users. + */ + USER_MANAGEMENT(BasicPrivilege.class, null, "User management"), + + /** + * User can have custom layouts (access level defines how many). + */ + CUSTOM_LAYOUTS(BasicPrivilege.class, null, "Custom layouts", true), + + /** + * User can view non-public layout. + */ + LAYOUT_VIEW(ObjectPrivilege.class, Layout.class, "View layout"), + + /** + * User can manage configuration. + */ + CONFIGURATION_MANAGE(BasicPrivilege.class, null, "Manage configuration"), + + /** + * User can manage layouts of all users in the project. + */ + LAYOUT_MANAGEMENT(ObjectPrivilege.class, Project.class, "Manage layouts"), // + + /** + * User can manage reference genomes. + */ + MANAGE_GENOMES(BasicPrivilege.class, null, "Manage genomes"); + + /** + * Type of privilege (basic or privilege to the object). + */ + private Class<? extends BasicPrivilege> privilegeClassType; + + /** + * Type of the object to which privilege refers. + */ + private Class<?> privilegeObjectType; + + /** + * Name of the privilege. + */ + private String commonName; + + /** + * Is the privilege numeric. + */ + private boolean numeric = false; + + /** + * Constructor that initialize enum with data. + * + * @param privilegeClazz + * {@link #privilegeClassType} + * @param objectClazz + * {@link #privilegeObjectType} + * @param commonName + * {@link #commonName} + */ + PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName) { + this.privilegeClassType = privilegeClazz; + this.privilegeObjectType = objectClazz; + this.commonName = commonName; + } + + /** + * Constructor that initialize enum with data. + * + * @param privilegeClazz + * {@link #privilegeClassType} + * @param objectClazz + * {@link #privilegeObjectType} + * @param commonName + * {@link #commonName} + * @param numeric + * {@link #numeric} + */ + PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName, + boolean numeric) { + this.privilegeClassType = privilegeClazz; + this.privilegeObjectType = objectClazz; + this.commonName = commonName; + this.numeric = true; + } + + /** + * + * @return {@link #privilegeClassType} + */ + public Class<? extends BasicPrivilege> getPrivilegeClassType() { + return privilegeClassType; + } + + /** + * + * @return {@link #privilegeObjectType} + */ + public Class<?> getPrivilegeObjectType() { + return privilegeObjectType; + } + + /** + * + * @return {@link #commonName} + */ + public String getCommonName() { + return commonName; + } + + /** + * + * @return {@link #numeric} + */ + public boolean isNumeric() { + return numeric; + } } diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java index cb87e19a7aa17896ae79e52d9ed9b5a013e1a052..c1d9d5f42618b159012d3890cb90647abfd114fa 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java @@ -3,6 +3,7 @@ package lcsb.mapviewer.services.impl; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.EnumUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; import lcsb.mapviewer.common.FrameworkVersion; import lcsb.mapviewer.model.user.Configuration; import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.model.user.PrivilegeType; import lcsb.mapviewer.persist.dao.ConfigurationDao; import lcsb.mapviewer.services.interfaces.IConfigurationService; import lcsb.mapviewer.services.view.ConfigurationView; @@ -158,4 +160,14 @@ public class ConfigurationService implements IConfigurationService { return runtime.maxMemory() / MEGABYTE_SIZE; } + @Override + public ConfigurationView getValue(PrivilegeType type) { + String name = "DEFAULT_" + type.name(); + if (EnumUtils.isValidEnum(ConfigurationElementType.class, name)) { + return getValue(ConfigurationElementType.valueOf(name)); + } else { + return null; + } + } + } diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java index bed88037e360c18bcfd4dfeed9ab9496da99ee78..2b7b894cbaf8c8906ec7a266d529950f14ef0a0f 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java @@ -4,6 +4,7 @@ import java.util.List; import lcsb.mapviewer.common.FrameworkVersion; import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.model.user.PrivilegeType; import lcsb.mapviewer.services.view.ConfigurationView; /** @@ -111,5 +112,7 @@ public interface IConfigurationService { */ String getSystemGitVersion(String baseDir); - ConfigurationView getValue(ConfigurationElementType type); + ConfigurationView getValue(ConfigurationElementType type); + + ConfigurationView getValue(PrivilegeType type); } diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java index ff1a5e29d35ab08dbf99a4ca3e48de0e5ba7a706..85492908da3a30bae460b1855a9a5ea71b0505e8 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java @@ -2,6 +2,7 @@ package lcsb.mapviewer.services.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.util.List; @@ -13,93 +14,114 @@ import org.springframework.test.annotation.Rollback; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.FrameworkVersion; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.model.user.PrivilegeType; import lcsb.mapviewer.services.ServiceTestFunctions; import lcsb.mapviewer.services.view.ConfigurationView; @Rollback(true) public class ConfigurationServiceTest extends ServiceTestFunctions { - Logger logger = Logger.getLogger(ConfigurationServiceTest.class); - - @Before - public void setUp() throws Exception { - // clear information about git version - Configuration.getSystemBuildVersion(null, true); - } - - @After - public void tearDown() throws Exception { - // clear information about git version - Configuration.getSystemBuildVersion(null, true); - } - - @Test - public void testGetUpdate() throws Exception { - try { - String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress); - configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world"); - newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - assertEquals("hello@world", newAddress); - - configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testList() throws Exception { - try { - List<ConfigurationView> list = configurationService.getAllValues(); - assertEquals(ConfigurationElementType.values().length, list.size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion() throws Exception { - try { - FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/"); - assertNotNull(view); - assertEquals("100", view.getGitVersion()); - assertEquals("202", view.getVersion()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion2() throws Exception { - try { - FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/"); - assertNotNull(view); - assertEquals("100:105", view.getGitVersion()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion3() throws Exception { - try { - FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/"); - assertNotNull(view); - assertEquals("117", view.getGitVersion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Logger logger = Logger.getLogger(ConfigurationServiceTest.class); + + @Before + public void setUp() throws Exception { + // clear information about git version + Configuration.getSystemBuildVersion(null, true); + } + + @After + public void tearDown() throws Exception { + // clear information about git version + Configuration.getSystemBuildVersion(null, true); + } + + @Test + public void testGetUpdate() throws Exception { + try { + String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress); + configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world"); + newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + assertEquals("hello@world", newAddress); + + configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testList() throws Exception { + try { + List<ConfigurationView> list = configurationService.getAllValues(); + assertEquals(ConfigurationElementType.values().length, list.size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/"); + assertNotNull(view); + assertEquals("100", view.getGitVersion()); + assertEquals("202", view.getVersion()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion2() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/"); + assertNotNull(view); + assertEquals("100:105", view.getGitVersion()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion3() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/"); + assertNotNull(view); + assertEquals("117", view.getGitVersion()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetConfiguratioElemntForPrivilege() throws Exception { + try { + for (PrivilegeType type : PrivilegeType.values()) { + ConfigurationView value = configurationService.getValue(type); + if (Project.class.equals(type.getPrivilegeObjectType())) { + assertNotNull("No default value for privilege " + type.getCommonName(), value); + assertNotNull(value.getValue()); + assertNotNull(value.getValueType()); + } else { + assertNull(value); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } }