Commit 91a43bf5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

PluginService contains removePlugin method

parent 61cbb125
package lcsb.mapviewer.api.plugins;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -8,12 +10,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.api.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.model.plugin.Plugin;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IPluginService;
import lcsb.mapviewer.services.interfaces.IUserService;
@RestController
......@@ -27,11 +39,13 @@ public class PluginController extends BaseController {
private PluginRestImpl pluginRest;
private IUserService userService;
private IPluginService pluginService;
@Autowired
public PluginController(PluginRestImpl pluginRest, IUserService userService) {
public PluginController(PluginRestImpl pluginRest, IUserService userService, IPluginService pluginService) {
this.pluginRest = pluginRest;
this.userService = userService;
this.pluginService = pluginService;
}
@PreAuthorize("(not #isPublic and #isDefault!=true) or hasAuthority('IS_ADMIN')")
......@@ -67,11 +81,15 @@ public class PluginController extends BaseController {
return pluginRest.getPlugin(hash);
}
// FIXME: check if this takes priority over filter chain
@PreAuthorize("hasAuthority('IS_ADMIN')")
@DeleteMapping(value = "/{hash}")
public void removePlugin(@PathVariable(value = "hash") String hash) throws ObjectNotFoundException {
pluginRest.removePlugin(hash);
Plugin plugin = pluginService.getByHash(hash);
if (plugin != null) {
pluginService.delete(plugin);
} else {
throw new ObjectNotFoundException("Plugin doesn't exist");
}
}
@PostMapping(value = "/{hash}/data/users/{key}")
......
package lcsb.mapviewer.api.plugins;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.logging.log4j.LogManager;
......@@ -10,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.*;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.model.plugin.Plugin;
import lcsb.mapviewer.model.plugin.PluginDataEntry;
import lcsb.mapviewer.model.user.User;
......@@ -168,19 +172,6 @@ public class PluginRestImpl extends BaseRestImpl {
return result;
}
public void removePlugin(String hash) throws ObjectNotFoundException {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin != null) {
List<PluginDataEntry> entries = pluginDataEntryDao.getByPlugin(plugin);
for (PluginDataEntry pluginDataEntry : entries) {
pluginDataEntryDao.delete(pluginDataEntry);
}
pluginDao.delete(plugin);
} else {
throw new ObjectNotFoundException("Plugin doesn't exist");
}
}
public Map<String, Object> updatePlugin(String hash, Map<String, Object> data) throws QueryException {
Plugin plugin = pluginDao.getByHash(hash);
if (plugin == null) {
......
......@@ -4,14 +4,12 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.api.genomics.AllGenomicsTests;
import lcsb.mapviewer.api.mesh.AllMeshTests;
import lcsb.mapviewer.api.projects.AllProjectTests;
import lcsb.mapviewer.api.users.AllUserTests;
@RunWith(Suite.class)
@SuiteClasses({
AllGenomicsTests.class,
AllMeshTests.class,
AllProjectTests.class,
AllUserTests.class,
......
package lcsb.mapviewer.services.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.model.plugin.Plugin;
import lcsb.mapviewer.model.plugin.PluginDataEntry;
import lcsb.mapviewer.persist.dao.plugin.PluginDao;
import lcsb.mapviewer.persist.dao.plugin.PluginDataEntryDao;
import lcsb.mapviewer.services.interfaces.IPluginService;
@Transactional
@Service
public class PluginService implements IPluginService {
private PluginDao pluginDao;
private PluginDataEntryDao pluginDataEntryDao;
@Autowired
public PluginService(PluginDao pluginDao, PluginDataEntryDao pluginDataEntryDao) {
this.pluginDao = pluginDao;
this.pluginDataEntryDao = pluginDataEntryDao;
}
@Override
public Plugin getByHash(String hash) {
return pluginDao.getByHash(hash);
}
@Override
public void delete(Plugin plugin) {
List<PluginDataEntry> entries = pluginDataEntryDao.getByPlugin(plugin);
for (PluginDataEntry pluginDataEntry : entries) {
pluginDataEntryDao.delete(pluginDataEntry);
}
pluginDao.delete(plugin);
}
}
package lcsb.mapviewer.services.interfaces;
import lcsb.mapviewer.model.plugin.Plugin;
public interface IPluginService {
Plugin getByHash(String hash);
void delete(Plugin plugin);
}
......@@ -3,13 +3,20 @@ package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.http.client.entity.UrlEncodedFormEntity;
......@@ -17,7 +24,9 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
......@@ -35,6 +44,7 @@ import lcsb.mapviewer.model.plugin.PluginDataEntry;
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.IPluginService;
@RunWith(SpringJUnit4ClassRunner.class)
public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
......@@ -51,6 +61,9 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
@Autowired
private PluginDataEntryDao pluginDataEntryDao;
@Autowired
private IPluginService pluginService;
private User user;
@Before
......@@ -375,6 +388,8 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertNull(pluginService.getByHash(plugin.getHash()));
}
......
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