Commit 6ce44a43 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

allow to remove plugin data entry

parent d8accf2a
Pipeline #28880 failed with stage
in 11 minutes and 24 seconds
......@@ -12,6 +12,7 @@ minerva (15.1.0) unstable; urgency=medium
species name those two values are assigned to name and full name (#1275)
* Small improvement: process rectangle can be specified in SBML with reaction
bounding box (#1292)
* Small improvement: API allows to remove plugin data entry (#1298)
* Bug fix: export to image from selected polygon contained all elements
inside rectangle bounded by the polygon coordinates (#1096)
* Bug fix: continuous refreshing list of project when uploading/removing
......
package lcsb.mapviewer.api.plugins;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -83,6 +82,18 @@ public class PluginController extends BaseController {
return pluginRest.createPluginDataEntry(hash, user, key, value);
}
@DeleteMapping(value = "/{hash}/data/users/{key}")
public Map<String, Object> deletePluginDataEntry(
Authentication authentication,
@PathVariable(value = "hash") String hash,
@PathVariable(value = "key") String key) throws QueryException {
User user = userService.getUserByLogin(authentication.getName());
pluginRest.deletePluginDataEntry(hash, user, key);
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
return result;
}
@PostMapping(value = "/{hash}/data/global/{key}")
public Map<String, Object> createPluginDataEntry(
@PathVariable(value = "hash") String hash,
......@@ -91,6 +102,16 @@ public class PluginController extends BaseController {
return pluginRest.createPluginDataEntry(hash, null, key, value);
}
@DeleteMapping(value = "/{hash}/data/global/{key}")
public Map<String, Object> deletePluginDataEntry(
@PathVariable(value = "hash") String hash,
@PathVariable(value = "key") String key) throws QueryException {
pluginRest.deletePluginDataEntry(hash, null, key);
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
return result;
}
@GetMapping(value = "/{hash}/data/users/{key}")
public Map<String, Object> getPluginDataEntry(
Authentication authentication,
......
......@@ -33,7 +33,8 @@ public class PluginRestImpl extends BaseRestImpl {
this.pluginDataEntryDao = pluginDataEntryDao;
}
public Map<String, Object> createPlugin(String hash, String name, String version, String url, boolean isPublic, Boolean isDefault) throws QueryException {
public Map<String, Object> createPlugin(String hash, String name, String version, String url, boolean isPublic,
Boolean isDefault) throws QueryException {
if (!new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS).isValid(url)) {
throw new QueryException("Invalid url: " + url);
}
......@@ -115,6 +116,20 @@ public class PluginRestImpl extends BaseRestImpl {
return pluginEntryToMap(entry);
}
public void deletePluginDataEntry(String hash, User user, String key) throws QueryException {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin == null) {
throw new ObjectNotFoundException("Plugin doesn't exist");
}
PluginDataEntry entry = pluginDataEntryDao.getByKey(plugin, key, user);
if (entry == null) {
throw new ObjectNotFoundException("Data entry not found");
} else {
pluginDataEntryDao.delete(entry);
}
}
private Map<String, Object> pluginEntryToMap(PluginDataEntry entry) {
Map<String, Object> result = new TreeMap<>();
result.put("key", entry.getKey());
......
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -28,9 +29,11 @@ import com.google.gson.Gson;
import com.google.gson.JsonParser;
import lcsb.mapviewer.model.plugin.Plugin;
import lcsb.mapviewer.model.plugin.PluginDataEntry;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.plugin.PluginDao;
import lcsb.mapviewer.persist.dao.plugin.PluginDataEntryDao;
import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -43,6 +46,8 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
Logger logger = LogManager.getLogger();
@Autowired
private PluginDao pluginDao;
@Autowired
private PluginDataEntryDao pluginDataEntryDao;
@Autowired
private IUserService userService;
......@@ -188,6 +193,25 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
assertEquals("xxx", result);
}
@Test
public void removeGlobalPluginData() throws Exception {
Plugin plugin = createPlugin();
PluginDataEntry entry = new PluginDataEntry();
entry.setKey("key");
entry.setValue("val");
entry.setPlugin(plugin);
pluginDataEntryDao.add(entry);
RequestBuilder request = delete("/plugins/" + plugin.getHash() + "/data/global/" + entry.getKey() + "/");
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertNull(pluginDataEntryDao.getByKey(plugin, entry.getKey(), null));
}
@Test
public void testSetInvalidGlobalPluginDataKey() throws Exception {
StringBuilder body = new StringBuilder("value=xxx");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment