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

Commit

Permalink
feat(messages): add the message feature
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud authored and brasseld committed Sep 6, 2018
1 parent f296b96 commit 057aae6
Show file tree
Hide file tree
Showing 28 changed files with 932 additions and 11 deletions.
@@ -0,0 +1,24 @@
/**
* 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;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public enum MessageChannel {
MAIL, PORTAL
}
@@ -0,0 +1,61 @@
/**
* 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;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class MessageEntity {

MessageRecipientEntity recipient;

MessageChannel channel;
String title;
String text;

public MessageRecipientEntity getRecipient() {
return recipient;
}

public void setRecipient(MessageRecipientEntity recipient) {
this.recipient = recipient;
}

public MessageChannel getChannel() {
return channel;
}

public void setChannel(MessageChannel channel) {
this.channel = channel;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}
@@ -0,0 +1,49 @@
/**
* 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;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class MessageRecipientEntity {

@JsonProperty("role_scope")
String roleScope;

@JsonProperty("role_value")
List<String> roleValues;

public String getRoleScope() {
return roleScope;
}

public void setRoleScope(String roleScope) {
this.roleScope = roleScope;
}

public List<String> getRoleValues() {
return roleValues;
}

public void setRoleValues(List<String> roleValues) {
this.roleValues = roleValues;
}
}
Expand Up @@ -36,7 +36,8 @@ public enum ApiPermission implements Permission {
RATING_ANSWER( "RATING_ANSWER", 2200),
AUDIT( "AUDIT", 2300),
DISCOVERY( "DISCOVERY", 2400),
NOTIFICATION( "NOTIFICATION", 2500);
NOTIFICATION( "NOTIFICATION", 2500),
MESSAGE( "MESSAGE", 2600);

String name;
int mask;
Expand Down
Expand Up @@ -30,7 +30,8 @@ public enum ManagementPermission implements Permission {
PLATFORM( "PLATFORM", 1800),
AUDIT( "AUDIT", 1900),
NOTIFICATION("NOTIFICATION", 2000),
USER ("USER", 2100);
USER ("USER", 2100),
MESSAGE ("MESSAGE", 2200);

String name;
int mask;
Expand Down
Expand Up @@ -31,6 +31,7 @@ public enum RolePermission {
MANAGEMENT_AUDIT (RoleScope.MANAGEMENT, ManagementPermission.AUDIT),
MANAGEMENT_NOTIFICATION (RoleScope.MANAGEMENT, ManagementPermission.NOTIFICATION),
MANAGEMENT_USERS (RoleScope.MANAGEMENT, ManagementPermission.USER),
MANAGEMENT_MESSAGE (RoleScope.MANAGEMENT, ManagementPermission.MESSAGE),

PORTAL_METADATA (RoleScope.PORTAL, PortalPermission.METADATA),
PORTAL_DOCUMENTATION (RoleScope.PORTAL, PortalPermission.DOCUMENTATION),
Expand All @@ -54,6 +55,7 @@ public enum RolePermission {
API_RATING (RoleScope.API, ApiPermission.RATING),
API_RATING_ANSWER (RoleScope.API, ApiPermission.RATING_ANSWER),
API_NOTIFICATION (RoleScope.API, ApiPermission.NOTIFICATION),
API_MESSAGE (RoleScope.API, ApiPermission.MESSAGE),

APPLICATION_DEFINITION (RoleScope.APPLICATION, ApplicationPermission.DEFINITION),
APPLICATION_MEMBER (RoleScope.APPLICATION, ApplicationPermission.MEMBER),
Expand Down
Expand Up @@ -26,6 +26,7 @@
import io.gravitee.management.rest.resource.param.LifecycleActionParam.LifecycleAction;
import io.gravitee.management.rest.security.Permission;
import io.gravitee.management.rest.security.Permissions;
import io.gravitee.management.service.MessageService;
import io.gravitee.management.service.NotifierService;
import io.gravitee.management.service.QualityMetricsService;
import io.gravitee.management.service.exceptions.ApiNotFoundException;
Expand Down Expand Up @@ -72,6 +73,9 @@ public class ApiResource extends AbstractResource {
@Autowired
private QualityMetricsService qualityMetricsService;

@Autowired
private MessageService messageService;

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get the API definition",
Expand Down Expand Up @@ -444,6 +448,17 @@ public ApiQualityMetricsEntity getQualityMetrics(@PathParam("api") String api) {
}


@POST
@Path("/messages")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({
@Permission(value = RolePermission.API_MESSAGE, acls = RolePermissionAction.CREATE)
})
public Response create(@PathParam("api") String api, final MessageEntity message) {
return Response.ok(messageService.create(api, message)).build();
}

@Path("keys")
public ApiKeysResource getApiKeyResource() {
return resourceContext.getResource(ApiKeysResource.class);
Expand Down
Expand Up @@ -223,7 +223,7 @@ public Response verify(@Valid VerifyApiParam verifyApiParam) {
@ApiOperation("Get the list of available hooks")
@Produces(MediaType.APPLICATION_JSON)
public Hook[] getHooks() {
return ApiHook.values();
return Arrays.stream(ApiHook.values()).filter(h -> !h.isHidden()).toArray(Hook[]::new);
}

@Path("{api}")
Expand Down
Expand Up @@ -35,6 +35,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.container.ResourceContext;
import javax.ws.rs.core.Context;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -57,7 +58,7 @@ public class ConfigurationResource {
@ApiOperation("Get the list of available hooks")
@Produces(MediaType.APPLICATION_JSON)
public Hook[] getHooks() {
return PortalHook.values();
return Arrays.stream(PortalHook.values()).filter(h -> !h.isHidden()).toArray(Hook[]::new);
}

@GET
Expand Down
Expand Up @@ -73,6 +73,7 @@ public GraviteeApplication(AuthenticationProviderManager authenticationProviderM
register(PortalResource.class);
register(AuditResource.class);
register(SearchResource.class);
register(MessagesResource.class);

// Dynamically register authentication endpoints
register(new AuthenticationBinder(authenticationProviderManager));
Expand Down
@@ -0,0 +1,54 @@
/**
* 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.rest.resource;

import io.gravitee.common.http.MediaType;
import io.gravitee.management.model.MessageEntity;
import io.gravitee.management.model.permissions.RolePermission;
import io.gravitee.management.model.permissions.RolePermissionAction;
import io.gravitee.management.rest.security.Permission;
import io.gravitee.management.rest.security.Permissions;
import io.gravitee.management.service.MessageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
@Path("/messages")
@Api(tags = {"Messages"})
public class MessagesResource extends AbstractResource {

@Autowired
private MessageService messageService;

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({
@Permission(value = RolePermission.MANAGEMENT_MESSAGE, acls = RolePermissionAction.CREATE)
})
public Response create(final MessageEntity message) {
return Response.ok(messageService.create(message)).build();
}
}
Expand Up @@ -108,6 +108,9 @@ public AbstractResourceTest(AuthenticationProviderManager authenticationProvider
@Autowired
protected QualityMetricsService qualityMetricsService;

@Autowired
protected MessageService messageService;

@Configuration
@PropertySource("classpath:/io/gravitee/management/rest/resource/jwt.properties")
static class ContextConfiguration {
Expand Down Expand Up @@ -200,6 +203,11 @@ public TaskService taskService() {
@Bean
public QualityMetricsService qualityMetricsService() {
return mock(QualityMetricsService.class);
}
}

@Bean
public MessageService messageService() {
return mock(MessageService.class);
}
}
}
Expand Up @@ -29,6 +29,7 @@ public class EmailNotification {
private String from;
private String fromName;
private String[] to;
private String[] bcc;
private String subject;
private String template;
private Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -90,6 +91,14 @@ public void setCopyToSender(boolean copyToSender) {
this.copyToSender = copyToSender;
}

public String[] getBcc() {
return bcc;
}

public void setBcc(String[] bcc) {
this.bcc = bcc;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -101,12 +110,13 @@ public boolean equals(Object o) {
Objects.equals(subject, that.subject) &&
Objects.equals(template, that.template) &&
Objects.equals(params, that.params) &&
Objects.equals(bcc, that.bcc) &&
Objects.equals(copyToSender, that.copyToSender);
}

@Override
public int hashCode() {
return Objects.hash(from, fromName, to, subject, template, params, copyToSender);
return Objects.hash(from, fromName, to, subject, template, params, copyToSender, bcc);
}

@Override
Expand All @@ -119,6 +129,7 @@ public String toString() {
", template='" + template + '\'' +
", params=" + params +
", copyToSender=" + copyToSender +
", bcc=" + Arrays.toString(bcc) +
'}';
}
}

0 comments on commit 057aae6

Please sign in to comment.