Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
4 myconfig-service-api/src/main/java/net/myconfig/service/api/MyConfigService.java
@@ -38,4 +38,8 @@
KeyVersionConfiguration keyVersionConfiguration(int id);
+ Ack addKeyVersion(int application, String version, String key);
+
+ Ack removeKeyVersion(int application, String version, String key);
+
}
View
10 ...nfig-service-api/src/main/java/net/myconfig/service/exception/KeyNotDefinedException.java
@@ -0,0 +1,10 @@
+package net.myconfig.service.exception;
+
+
+public class KeyNotDefinedException extends CoreException {
+
+ public KeyNotDefinedException(int application, String name) {
+ super (application, name);
+ }
+
+}
View
10 ...-service-api/src/main/java/net/myconfig/service/exception/VersionNotDefinedException.java
@@ -0,0 +1,10 @@
+package net.myconfig.service.exception;
+
+
+public class VersionNotDefinedException extends CoreException {
+
+ public VersionNotDefinedException(int application, String name) {
+ super (application, name);
+ }
+
+}
View
4 myconfig-service-api/src/main/java/net/myconfig/service/model/Ack.java
@@ -9,6 +9,10 @@ public static Ack validate(boolean test) {
return test ? OK : NOK;
}
+ public static Ack one(int count) {
+ return validate (count == 1);
+ }
+
private final boolean success;
private Ack(boolean success) {
View
51 myconfig-service-api/src/main/java/net/myconfig/service/model/VersionConfiguration.java
@@ -1,25 +1,26 @@
-package net.myconfig.service.model;
-
-import java.util.Set;
-
-import com.google.common.collect.ImmutableSet;
-
-public class VersionConfiguration {
-
- private final String name;
- private final Set<String> keys;
-
- public VersionConfiguration(String name, Set<String> keys) {
- this.name = name;
- this.keys = ImmutableSet.copyOf(keys);
- }
-
- public String getName() {
- return name;
- }
-
- public Set<String> getKeys() {
- return keys;
- }
-
-}
+package net.myconfig.service.model;
+
+import java.util.Collection;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+
+public class VersionConfiguration {
+
+ private final String name;
+ private final Set<String> keys;
+
+ public VersionConfiguration(String name, Collection<String> keys) {
+ this.name = name;
+ this.keys = ImmutableSet.copyOf(keys);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Set<String> getKeys() {
+ return keys;
+ }
+
+}
View
2 myconfig-service-api/src/main/resources/META-INF/resources/exceptions.properties
@@ -6,3 +6,5 @@ net.myconfig.service.exception.VersionNotFoundException = [S-005] Cannot find ve
net.myconfig.service.exception.EnvironmentNotFoundException = [S-006] Cannot find environment {1} for application {0}
net.myconfig.service.exception.EnvironmentAlreadyDefinedException = [S-007] The environment \"{0}\" is already defined.
net.myconfig.service.exception.KeyAlreadyDefinedException = [S-008] The key \"{0}\" is already defined.
+net.myconfig.service.exception.VersionNotDefinedException = [S-009] Version \"{1}\" is not defined.
+net.myconfig.service.exception.KeyNotDefinedException = [S-010] Key \"{1}\" is not defined.
View
99 myconfig-service-impl/src/main/java/net/myconfig/service/impl/MyConfigServiceImpl.java
@@ -12,11 +12,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
import javax.sql.DataSource;
@@ -27,8 +24,10 @@
import net.myconfig.service.exception.EnvironmentAlreadyDefinedException;
import net.myconfig.service.exception.EnvironmentNotFoundException;
import net.myconfig.service.exception.KeyAlreadyDefinedException;
+import net.myconfig.service.exception.KeyNotDefinedException;
import net.myconfig.service.exception.KeyNotFoundException;
import net.myconfig.service.exception.VersionAlreadyDefinedException;
+import net.myconfig.service.exception.VersionNotDefinedException;
import net.myconfig.service.exception.VersionNotFoundException;
import net.myconfig.service.model.Ack;
import net.myconfig.service.model.ApplicationConfiguration;
@@ -39,14 +38,14 @@
import net.myconfig.service.model.Key;
import net.myconfig.service.model.KeySummary;
import net.myconfig.service.model.KeyVersionConfiguration;
+import net.myconfig.service.model.Version;
import net.myconfig.service.model.VersionConfiguration;
import net.myconfig.service.model.VersionSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -149,7 +148,7 @@ public ApplicationSummary createApplication(String name) {
@Transactional
public Ack deleteApplication(int id) {
int count = getNamedParameterJdbcTemplate().update(SQL.APPLICATION_DELETE, new MapSqlParameterSource (ID, id));
- return Ack.validate (count == 1);
+ return Ack.one (count);
}
@Override
@@ -159,7 +158,7 @@ public Ack createVersion(int id, String name) {
try {
int count = getNamedParameterJdbcTemplate().update(SQL.VERSION_CREATE,
idNameSource(id, name));
- return Ack.validate (count == 1);
+ return Ack.one (count);
} catch (DuplicateKeyException ex) {
throw new VersionAlreadyDefinedException (id, name);
}
@@ -176,7 +175,7 @@ protected MapSqlParameterSource idNameSource(int id, String name) {
public Ack deleteVersion(int id, String name) {
checkApplication(id);
int count = getNamedParameterJdbcTemplate().update(SQL.VERSION_DELETE, idNameSource(id, name));
- return Ack.validate (count == 1);
+ return Ack.one (count);
}
@Override
@@ -186,7 +185,7 @@ public Ack createEnvironment(int id, String name) {
try {
int count = getNamedParameterJdbcTemplate().update(SQL.ENVIRONMENT_CREATE,
idNameSource(id, name));
- return Ack.validate (count == 1);
+ return Ack.one (count);
} catch (DuplicateKeyException ex) {
throw new EnvironmentAlreadyDefinedException(id, name);
}
@@ -197,7 +196,7 @@ public Ack createEnvironment(int id, String name) {
public Ack deleteEnvironment(int id, String name) {
checkApplication(id);
int count = getNamedParameterJdbcTemplate().update(SQL.ENVIRONMENT_DELETE, idNameSource(id, name));
- return Ack.validate (count == 1);
+ return Ack.one (count);
}
@Override
@@ -207,7 +206,7 @@ public Ack createKey(int id, String name, String description) {
try {
int count = getNamedParameterJdbcTemplate().update(SQL.KEY_CREATE,
idNameSource(id, name).addValue(DESCRIPTION, description));
- return Ack.validate (count == 1);
+ return Ack.one (count);
} catch (DuplicateKeyException ex) {
throw new KeyAlreadyDefinedException (id, name);
}
@@ -218,7 +217,7 @@ public Ack createKey(int id, String name, String description) {
public Ack deleteKey(int id, String name) {
checkApplication(id);
int count = getNamedParameterJdbcTemplate().update(SQL.KEY_DELETE, idNameSource(id, name));
- return Ack.validate (count == 1);
+ return Ack.one (count);
}
@Override
@@ -235,31 +234,61 @@ public Key mapRow(ResultSet rs, int i) throws SQLException {
return new Key(rs.getString(NAME), rs.getString(DESCRIPTION));
}
});
- // Key x version
- final Map<String, Set<String>> matrix = new TreeMap<String, Set<String>>();
- getNamedParameterJdbcTemplate().query(SQL.VERSION_CONFIGURATIONS, idCriteria, new RowCallbackHandler() {
-
+ // List of versions
+ List<Version> versionList = getNamedParameterJdbcTemplate().query(SQL.VERSIONS, idCriteria, new RowMapper<Version>() {
@Override
- public void processRow(ResultSet rs) throws SQLException {
- String version = rs.getString(VERSION);
- String key = rs.getString(KEY);
- Set<String> keysForVersions = matrix.get(version);
- if (keysForVersions == null) {
- keysForVersions = new HashSet<String>();
- matrix.put (version, keysForVersions);
- }
- keysForVersions.add(key);
+ public Version mapRow(ResultSet rs, int i) throws SQLException {
+ return new Version(rs.getString(NAME));
}
});
+ // Configuration list for versions
List<VersionConfiguration> versionConfigurationList = new ArrayList<VersionConfiguration>();
- for (Map.Entry<String, Set<String>> entry: matrix.entrySet()) {
- String version = entry.getKey();
- Set<String> keys = entry.getValue();
- versionConfigurationList.add(new VersionConfiguration(version, keys));
+ for (Version version : versionList) {
+ // Gets the list of keys for this version
+ List<String> keys = getNamedParameterJdbcTemplate().queryForList(
+ SQL.VERSION_KEYS,
+ idCriteria.addValue(VERSION, version.getName()),
+ String.class);
+ // Version configuration
+ VersionConfiguration versionConfiguration = new VersionConfiguration(version.getName(), keys);
+ // Adds to the list
+ versionConfigurationList.add(versionConfiguration);
}
// OK
return new KeyVersionConfiguration(id, name, versionConfigurationList, keyList);
}
+
+ @Override
+ @Transactional
+ public Ack addKeyVersion(int application, String version, String key) {
+ checkApplication(application);
+ checkVersion(application, version);
+ checkKey(application, key);
+ int count = getNamedParameterJdbcTemplate().update(
+ SQL.VERSION_KEY_ADD,
+ new MapSqlParameterSource()
+ .addValue(APPLICATION, application)
+ .addValue(VERSION, version)
+ .addValue(KEY, key)
+ );
+ return Ack.one(count);
+ }
+
+ @Override
+ @Transactional
+ public Ack removeKeyVersion(int application, String version, String key) {
+ checkApplication(application);
+ checkVersion(application, version);
+ checkKey(application, key);
+ int count = getNamedParameterJdbcTemplate().update(
+ SQL.VERSION_KEY_REMOVE,
+ new MapSqlParameterSource()
+ .addValue(APPLICATION, application)
+ .addValue(VERSION, version)
+ .addValue(KEY, key)
+ );
+ return Ack.one(count);
+ }
@Override
@Transactional(readOnly = true)
@@ -331,6 +360,20 @@ protected void checkVersion(String application, String version) {
new VersionNotFoundException(application, version));
}
+ protected void checkVersion(int application, String version) {
+ check (
+ SQL.VERSION_EXISTS_BY_ID,
+ new MapSqlParameterSource(NAME, version).addValue(APPLICATION, application),
+ new VersionNotDefinedException(application, version));
+ }
+
+ protected void checkKey(int application, String key) {
+ check (
+ SQL.KEY_EXISTS_BY_ID,
+ new MapSqlParameterSource(NAME, key).addValue(APPLICATION, application),
+ new KeyNotDefinedException(application, key));
+ }
+
protected void checkEnvironment(String application, String environment) {
check (
SQL.ENVIRONMENT_EXISTS,
View
23 myconfig-service-impl/src/main/java/net/myconfig/service/impl/SQL.java
@@ -20,6 +20,8 @@
String APPLICATION_NAME = "select name from application where id = :id";
+ String VERSIONS = "select * from version where application = :application order by name";
+
String VERSION_SUMMARIES = "select v.name, count (vk.key) as keyNumber " +
"from version v " +
"left join version_key vk " +
@@ -57,19 +59,36 @@
String KEY_DELETE = "delete from key where application = :id and name = :name";
- String VERSION_CONFIGURATIONS = "select * " +
+ String VERSION_KEYS = "select key " +
"from version_key " +
"where application = :application " +
- "order by version, key";
+ "and version = :version " +
+ "order by key";
+
+ String VERSION_KEY_ADD = "insert into version_key (application, version, key) " +
+ "values (:application, :version, :key)";
+
+ String VERSION_KEY_REMOVE = "delete from version_key " +
+ "where application = :application and version = :version and key = :key";
String APPLICATION_EXISTS = "select id from application where name = :name";
+ String VERSION_EXISTS_BY_ID = "select v.name " +
+ "from version v " +
+ "where v.name = :name " +
+ "and v.application = :application";
+
String VERSION_EXISTS = "select v.name " +
"from version v, application a " +
"where v.name = :name " +
"and v.application = a.id " +
"and a.name = :application";
+ String KEY_EXISTS_BY_ID = "select name " +
+ "from key " +
+ "where name = :name " +
+ "and application = :application";
+
String ENVIRONMENT_EXISTS = "select e.name " +
"from environment e, application a " +
"where e.name = :name " +
View
24 myconfig-web/src/main/java/net/myconfig/web/rest/UIController.java
@@ -53,37 +53,37 @@ public ApplicationConfiguration applicationConfiguration(int id) {
@Override
@RequestMapping(value = "/version/{id}/{name}", method = RequestMethod.PUT)
- public Ack versionCreate(@PathVariable int id, @PathVariable String name) {
+ public @ResponseBody Ack versionCreate(@PathVariable int id, @PathVariable String name) {
return getMyConfigService().createVersion (id, name);
}
@Override
@RequestMapping(value = "/version/{id}/{name}", method = RequestMethod.DELETE)
- public Ack versionDelete(@PathVariable int id, @PathVariable String name) {
+ public @ResponseBody Ack versionDelete(@PathVariable int id, @PathVariable String name) {
return getMyConfigService().deleteVersion (id, name);
}
@Override
@RequestMapping(value = "/environment/{id}/{name}", method = RequestMethod.PUT)
- public Ack environmentCreate(@PathVariable int id, @PathVariable String name) {
+ public @ResponseBody Ack environmentCreate(@PathVariable int id, @PathVariable String name) {
return getMyConfigService().createEnvironment (id, name);
}
@Override
@RequestMapping(value = "/environment/{id}/{name}", method = RequestMethod.DELETE)
- public Ack environmentDelete(@PathVariable int id, @PathVariable String name) {
+ public @ResponseBody Ack environmentDelete(@PathVariable int id, @PathVariable String name) {
return getMyConfigService().deleteEnvironment (id, name);
}
@Override
@RequestMapping(value = "/key/{id}/{name}", method = RequestMethod.PUT)
- public Ack keyCreate(@PathVariable int id, @PathVariable String name, @RequestParam String description) {
+ public @ResponseBody Ack keyCreate(@PathVariable int id, @PathVariable String name, @RequestParam String description) {
return getMyConfigService().createKey (id, name, description);
}
@Override
@RequestMapping(value = "/key/{id}/{name}", method = RequestMethod.DELETE)
- public Ack keyDelete(@PathVariable int id, @PathVariable String name) {
+ public @ResponseBody Ack keyDelete(@PathVariable int id, @PathVariable String name) {
return getMyConfigService().deleteKey (id, name);
}
@@ -93,4 +93,16 @@ public KeyVersionConfiguration keyVersionConfiguration(int id) {
return getMyConfigService().keyVersionConfiguration(id);
}
+ @Override
+ @RequestMapping(value = "/version/{application}/{version}/add/{key:.*}", method = RequestMethod.POST)
+ public @ResponseBody Ack keyVersionAdd (@PathVariable int application, @PathVariable String version, @PathVariable String key) {
+ return getMyConfigService().addKeyVersion (application, version, key);
+ }
+
+ @Override
+ @RequestMapping(value = "/version/{application}/{version}/remove/{key:.*}", method = RequestMethod.POST)
+ public @ResponseBody Ack keyVersionRemove (@PathVariable int application, @PathVariable String version, @PathVariable String key) {
+ return getMyConfigService().removeKeyVersion (application, version, key);
+ }
+
}
View
4 myconfig-web/src/main/java/net/myconfig/web/rest/UIInterface.java
@@ -31,4 +31,8 @@
KeyVersionConfiguration keyVersionConfiguration(int id);
+ Ack keyVersionAdd(int application, String version, String key);
+
+ Ack keyVersionRemove(int application, String version, String key);
+
}
View
3 myconfig-web/src/main/resources/META-INF/resources/web-labels.properties
@@ -41,6 +41,9 @@ configuration.key.new = Create a key
versionConfiguration = Keys x Versions
versionConfiguration.title = @[versionConfiguration] for {0}
+versionConfiguration.key = Key
+versionConfiguration.key.yes = Key is used by this version
+versionConfiguration.key.no = Key is not used by this version
rest.AbstractRESTController.version = Gets the version of the API
View
47 myconfig-web/src/main/webapp/WEB-INF/freemarker/versionConfiguration.html
@@ -1,5 +1,50 @@
<#include "/lib/layout.html">
-<@layout_std pageId="versionConfiguration" style=false modules=[] title=loc("versionConfiguration.title", configuration.name)>
+<@layout_std pageId="versionConfiguration" style=true modules=[] title=loc("versionConfiguration.title", configuration.name)>
+ <article class="versionConfiguration">
+ <table border="1">
+ <thead>
+ <tr>
+ <th>
+ <@lh key="versionConfiguration.key" />
+ </th>
+ <#list configuration.versionConfigurationList as versionConfiguration>
+ <th>
+ ${versionConfiguration.name?html}
+ </th>
+ </#list>
+ </tr>
+ </thead>
+ <tbody>
+ <#list configuration.keyList as key>
+ <tr>
+ <td class="key">
+ <div class="key-name">${key.name?html}</div>
+ <div class="key-description">${key.description?html}</div>
+ </td>
+ <#list configuration.versionConfigurationList as versionConfiguration>
+ <td class="key-flag">
+ <#if versionConfiguration.keys?seq_contains(key.name)>
+ <#assign setValue = "yes" />
+ <#else>
+ <#assign setValue = "no" />
+ </#if>
+ <#assign flag = versionConfiguration.keys?seq_contains(key.name) />
+ <div
+ id="versionConfiguration_${versionConfiguration.name?html}_${key.name?html}"
+ application="${configuration.id?html}"
+ version="${versionConfiguration.name?html}"
+ key="${key.name?html}"
+ set="${setValue}"
+ class="versionConfiguration"
+ title="<@lh key='versionConfiguration.key.${setValue}'/>"
+ onclick="myconfig.keyVersion(this);" />
+ </td>
+ </#list>
+ </tr>
+ </#list>
+ </tbody>
+ </table>
+ </article>
<@layout_std_nav href="gui/" key="applications" />
<@layout_std_nav href="gui/application/configure?id=${configuration.id}" key="configuration" />
</@layout_std>
View
BIN myconfig-web/src/main/webapp/images/version_key_no.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN myconfig-web/src/main/webapp/images/version_key_yes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 myconfig-web/src/main/webapp/less/versionConfiguration.less
@@ -0,0 +1,12 @@
+div.versionConfiguration {
+ width: 16px;
+ height: 16px;
+ cursor: pointer;
+ background-repeat: no-repeat;
+ &[set=yes] {
+ background-image: url('../images/version_key_yes.png');
+ }
+ &[set=no] {
+ background-image: url('../images/version_key_no.png');
+ }
+}
View
41 myconfig-web/src/main/webapp/scripts/myconfig.js
@@ -1,5 +1,27 @@
+String.prototype.format = function() {
+ var args = arguments;
+ return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function(m, n) {
+ if (m == "{{") {
+ return "{";
+ }
+ if (m == "}}") {
+ return "}";
+ }
+ return args[n];
+ });
+};
+
var myconfig = function () {
+ function displayError (text) {
+ alert(text);
+ }
+
+ function displayAjaxError (message, jqXHR, textStatus, errorThrown) {
+ var text = '{0}\n[{1}] {2}'.format(message, jqXHR.status, jqXHR.statusText);
+ displayError(text);
+ }
+
return {
changeLanguage: function (lang) {
if (location.search.indexOf("language") > -1) {
@@ -9,6 +31,25 @@ var myconfig = function () {
} else {
location.href += "&language=" + lang;
}
+ },
+ keyVersion: function (img) {
+ var application = img.getAttribute('application');
+ var version = img.getAttribute('version');
+ var key = img.getAttribute('key');
+ var oldSet = img.getAttribute('set');
+ var set = oldSet == 'yes' ? 'no' : 'yes';
+ var mode = set == 'yes' ? 'add' : 'remove';
+ var url = 'ui/version/' + application + '/' + version + '/' + mode + '/' + key;
+ $.post (url, function (data) {
+ if (data.success) {
+ img.setAttribute('set', set);
+ } else {
+ displayError ('TODO Could not update the key x version');
+ }
+ })
+ .error(function (jqXHR, textStatus, errorThrown) {
+ displayAjaxError ('TODO Error', jqXHR, textStatus, errorThrown);
+ });
}
};

No commit comments for this range

Something went wrong with that request. Please try again.