Commit 89a494d5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

add plugin moved to service

parent b2b5f46a
...@@ -5,6 +5,7 @@ import java.util.HashMap; ...@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -59,7 +60,32 @@ public class PluginController extends BaseController { ...@@ -59,7 +60,32 @@ public class PluginController extends BaseController {
@RequestParam(value = "isPublic", defaultValue = "false") boolean isPublic, @RequestParam(value = "isPublic", defaultValue = "false") boolean isPublic,
@RequestParam(value = "isDefault", required = false) Boolean isDefault, @RequestParam(value = "isDefault", required = false) Boolean isDefault,
@RequestParam(value = "url", defaultValue = "") String url) throws QueryException { @RequestParam(value = "url", defaultValue = "") String url) throws QueryException {
return pluginRest.createPlugin(hash, name, version, url, isPublic, isDefault); if (!new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS).isValid(url)) {
throw new QueryException("Invalid url: " + url);
}
Plugin plugin = pluginService.getByHash(hash);
if (plugin != null) {
plugin.addUrl(url);
plugin.setPublic(plugin.isPublic() || isPublic);
if (isDefault != null) {
plugin.setDefault(isDefault);
}
pluginService.update(plugin);
} else {
plugin = new Plugin();
plugin.setHash(hash);
plugin.setName(name);
plugin.setVersion(version);
plugin.setPublic(isPublic);
if (isDefault != null) {
plugin.setDefault(isDefault);
}
if (!url.isEmpty()) {
plugin.addUrl(url);
}
pluginService.add(plugin);
}
return plugin;
} }
@PreAuthorize("hasAuthority('IS_ADMIN')") @PreAuthorize("hasAuthority('IS_ADMIN')")
......
...@@ -39,36 +39,6 @@ public class PluginRestImpl extends BaseRestImpl { ...@@ -39,36 +39,6 @@ public class PluginRestImpl extends BaseRestImpl {
this.pluginDataEntryDao = pluginDataEntryDao; this.pluginDataEntryDao = pluginDataEntryDao;
} }
public Plugin 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);
}
Plugin plugin = pluginDao.getByHash(hash);
if (plugin != null) {
plugin.addUrl(url);
plugin.setPublic(plugin.isPublic() || isPublic);
if (isDefault != null) {
plugin.setDefault(isDefault);
}
pluginDao.update(plugin);
} else {
plugin = new Plugin();
plugin.setHash(hash);
plugin.setName(name);
plugin.setVersion(version);
plugin.setPublic(isPublic);
if (isDefault != null) {
plugin.setDefault(isDefault);
}
if (!url.isEmpty()) {
plugin.addUrl(url);
}
pluginDao.add(plugin);
}
return plugin;
}
public PluginDataEntry createPluginDataEntry(String hash, User user, String key, String value) public PluginDataEntry createPluginDataEntry(String hash, User user, String key, String value)
throws QueryException { throws QueryException {
Plugin plugin = pluginDao.getByHash(hash); Plugin plugin = pluginDao.getByHash(hash);
......
...@@ -65,4 +65,14 @@ public class PluginService implements IPluginService { ...@@ -65,4 +65,14 @@ public class PluginService implements IPluginService {
public void delete(PluginDataEntry entry) { public void delete(PluginDataEntry entry) {
pluginDataEntryDao.delete(entry); pluginDataEntryDao.delete(entry);
} }
@Override
public void update(Plugin plugin) {
pluginDao.update(plugin);
}
@Override
public void add(Plugin plugin) {
pluginDao.add(plugin);
}
} }
...@@ -18,4 +18,8 @@ public interface IPluginService { ...@@ -18,4 +18,8 @@ public interface IPluginService {
void delete(PluginDataEntry entry); void delete(PluginDataEntry entry);
void update(Plugin plugin);
void add(Plugin plugin);
} }
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