Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
feat(settings): move constants.json config to database
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud committed May 8, 2018
1 parent f1c28e4 commit fb9fb30
Show file tree
Hide file tree
Showing 23 changed files with 1,162 additions and 190 deletions.

Large diffs are not rendered by default.

Expand Up @@ -13,22 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.service.exceptions;
package io.gravitee.management.model.annotations;

import io.gravitee.management.model.parameters.Key;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class ParameterNotFoundException extends AbstractNotFoundException {

private final String parameterKey;

public ParameterNotFoundException(String parameterKey) {
this.parameterKey = parameterKey;
}

@Override
public String getMessage() {
return "Parameter [" + parameterKey + "] can not be found.";
}
}
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ParameterKey {
Key value();
}
@@ -0,0 +1,70 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.model.parameters;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public enum Key {
COMPANY_NAME("company.name"),

PORTAL_TITLE("portal.title"),
PORTAL_ENTRYPOINT("portal.entrypoint"),
PORTAL_APIKEY_HEADER("portal.apikey.header"),
PORTAL_SUPPORT_ENABLED("portal.support.enabled"),
PORTAL_RATING_ENABLED("portal.rating.enabled"),
PORTAL_DEVMODE_ENABLED("portal.devMode.enabled"),
PORTAL_USERCREATION_ENABLED("portal.userCreation.enabled"),
PORTAL_ANALYTICS_ENABLED("portal.analytics.enabled"),
PORTAL_ANALYTICS_TRACKINGID("portal.analytics.trackingId"),
PORTAL_APIS_TILESMODE_ENABLED("portal.apis.tilesMode.enabled"),
PORTAL_DASHBOARD_WIDGETS("portal.dashboard.widgets"),

MANAGEMENT_TITLE("management.title"),

THEME_NAME("theme.name"),
THEME_LOGO("theme.logo"),
THEME_LOADER("theme.loader"),
THEME_CSS("theme.css"),

AUTHENTICATION_FORCELOGIN_ENABLED("authentication.forceLogin.enabled"),
AUTHENTICATION_LOCALLOGIN_ENABLED("authentication.localLogin.enabled"),
AUTHENTICATION_GOOGLE_CLIENTID("authentication.google.clientId"),
AUTHENTICATION_GITHUB_CLIENTID("authentication.github.clientId"),
AUTHENTICATION_OAUTH2_CLIENTID("authentication.oauth2.clientId"),
AUTHENTICATION_OAUTH2_NAME("authentication.oauth2.name"),
AUTHENTICATION_OAUTH2_COLOR("authentication.oauth2.color"),
AUTHENTICATION_OAUTH2_AUTHORIZATION_ENDPOINT("authentication.oauth2.authorization.endpoint"),
AUTHENTICATION_OAUTH2_USER_LOGOUT_ENDPOINT("authentication.oauth2.user.logout.endpoint"),
AUTHENTICATION_OAUTH2_SCOPE("authentication.oauth2.scopes"),

SCHEDULER_TASKS("scheduler.tasks"),
SCHEDULER_NOTIFICATIONS("scheduler.notifications"),

DOCUMENTATION_URL("documentation.url")
;

String key;

Key(String key) {
this.key = key;
}

public String key() {
return key;
}
}
Expand Up @@ -24,7 +24,8 @@ public enum PortalPermission implements Permission {
DOCUMENTATION("DOCUMENTATION", 1100),
APPLICATION( "APPLICATION", 1200),
VIEW( "VIEW", 1300),
TOP_APIS( "TOP_APIS", 1400);
TOP_APIS( "TOP_APIS", 1400),
SETTINGS( "SETTINGS", 1500);

String name;
int mask;
Expand Down
Expand Up @@ -37,6 +37,7 @@ public enum RolePermission {
PORTAL_APPLICATION (RoleScope.PORTAL, PortalPermission.APPLICATION),
PORTAL_VIEW (RoleScope.PORTAL, PortalPermission.VIEW),
PORTAL_TOP_APIS (RoleScope.PORTAL, PortalPermission.TOP_APIS),
PORTAL_SETTINGS (RoleScope.PORTAL, PortalPermission.SETTINGS),

API_DEFINITION (RoleScope.API, ApiPermission.DEFINITION),
API_PLAN (RoleScope.API, ApiPermission.PLAN),
Expand Down
Expand Up @@ -20,6 +20,7 @@
import io.gravitee.repository.management.model.Parameter;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
Expand All @@ -34,6 +35,11 @@ public Optional<Parameter> findById(String s) throws TechnicalException {
return target.findById(s);
}

@Override
public List<Parameter> findAll(List<String> keys) throws TechnicalException {
return target.findAll(keys);
}

@Override
public Parameter create(Parameter item) throws TechnicalException {
return target.create(item);
Expand Down
Expand Up @@ -15,11 +15,24 @@
*/
package io.gravitee.management.rest.resource;

import io.gravitee.common.http.MediaType;
import io.gravitee.management.model.PortalConfigEntity;
import io.gravitee.management.model.permissions.RolePermission;
import io.gravitee.management.rest.security.Permission;
import io.gravitee.management.rest.security.Permissions;
import io.gravitee.management.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.ws.rs.Path;
import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import static io.gravitee.management.model.permissions.RolePermissionAction.*;

/**
* Defines the REST resources to manage Portal.
Expand All @@ -31,9 +44,35 @@
@Api(tags = {"Portal"})
public class PortalResource {

@Inject
ConfigService configService;

@Context
private ResourceContext resourceContext;


@GET
@Produces(MediaType.APPLICATION_JSON)
public PortalConfigEntity getConfig() {
return configService.getPortalConfig();
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save the portal configuration")
@Permissions({
@Permission(value = RolePermission.PORTAL_SETTINGS, acls = {CREATE, UPDATE, DELETE})
})
public Response savePortalConfig(
@ApiParam(name = "config", required = true) @NotNull PortalConfigEntity portalConfigEntity) {
configService.save(portalConfigEntity);
return Response
.ok()
.entity(portalConfigEntity)
.build();
}

@Path("pages")
public PortalPagesResource getPortalPagesResource() {
return resourceContext.getResource(PortalPagesResource.class);
Expand Down
Expand Up @@ -13,29 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.management.service.exceptions;
package io.gravitee.management.service;

import io.gravitee.common.http.HttpStatusCode;
import io.gravitee.management.model.PortalConfigEntity;

/**
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class ParameterAlreadyExistsException extends AbstractManagementException {

private final String parameterKey;

public ParameterAlreadyExistsException(String parameterKey) {
this.parameterKey = parameterKey;
}

@Override
public int getHttpStatusCode() {
return HttpStatusCode.BAD_REQUEST_400;
}

@Override
public String getMessage() {
return "A parameter [" + parameterKey + "] already exists.";
}
public interface ConfigService {
PortalConfigEntity getPortalConfig();
void save(PortalConfigEntity portalConfigEntity);
}
Expand Up @@ -18,26 +18,28 @@
import io.gravitee.repository.management.model.Parameter;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

/**
* @author Azize ELAMRANI (azize at graviteesource.com)
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public interface ParameterService {


boolean findAsBoolean(String key);
List<String> findAll(String key);
Map<String, List<String>> findAll(List<String> keys);

<T> List<T> findAll(String key, Function<String, T> mapper);
<T> Map<String, List<T>> findAll(List<String> keys, Function<String, T> mapper);

<T> List<T> findAll(String key, Function<String, T> mapper, Predicate<String> filter);
<T> Map<String, List<T>> findAll(List<String> keys, Function<String, T> mapper, Predicate<String> filter);

Parameter create(String key, String value);

void createMultipleValue(String key, String value);

Parameter update(String key, String value);

void updateMultipleValue(String key, List<String> values);
Parameter save(String key, String value);
Parameter save(String key, List<String> value);
}

0 comments on commit fb9fb30

Please sign in to comment.