Skip to content

Commit

Permalink
Renaming response classes, using types for requested configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Mar 27, 2015
1 parent 8c701e7 commit a696efe
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 124 deletions.
Expand Up @@ -19,8 +19,7 @@
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.rest.models.alarmcallbacks.AlarmCallbackSummary;
import org.graylog2.restclient.models.api.responses.alarmcallbacks.AlarmCallbackSummaryResponse;
import org.graylog2.restclient.models.api.responses.alarmcallbacks.GetSingleAvailableAlarmCallbackResponse;
import org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbackSummaryResponse;
import org.joda.time.DateTime;

import java.util.Map;
Expand All @@ -30,7 +29,6 @@
*/
public class AlarmCallback extends ConfigurableEntity {
public interface Factory {
AlarmCallback fromSummaryResponse(String streamId, AlarmCallbackSummaryResponse response);
AlarmCallback fromSummaryResponse(String streamId, AlarmCallbackSummary response);
}

Expand All @@ -43,20 +41,6 @@ public interface Factory {
private String creatorUserId;
private User creatorUser;

@AssistedInject
public AlarmCallback(UserService userService,
@Assisted String streamId,
@Assisted AlarmCallbackSummaryResponse response) {
this.userService = userService;
this.streamId = streamId;
this.id = response.id;
this.type = response.type;
this.configuration = response.configuration;
this.createdAt = DateTime.parse(response.createdAt);
this.creatorUserId = response.creatorUserId;
this.creatorUser = userService.load(creatorUserId);
}

@AssistedInject
public AlarmCallback(UserService userService,
@Assisted String streamId,
Expand Down Expand Up @@ -88,7 +72,7 @@ public Map<String, Object> getConfiguration() {
return configuration;
}

public Map<String, Object> getConfiguration(GetSingleAvailableAlarmCallbackResponse availableAlarmCallbackResponse) {
public Map<String, Object> getConfiguration(AvailableAlarmCallbackSummaryResponse availableAlarmCallbackResponse) {
return getConfiguration(availableAlarmCallbackResponse.getRequestedConfiguration());
}

Expand Down
Expand Up @@ -20,10 +20,11 @@
import org.graylog2.rest.models.alarmcallbacks.AlarmCallbackListSummary;
import org.graylog2.rest.models.alarmcallbacks.AlarmCallbackSummary;
import org.graylog2.rest.models.alarmcallbacks.responses.CreateAlarmCallbackResponse;
import org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbacksResponse;
import org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbackSummaryResponse;
import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.lib.ApiClient;
import org.graylog2.restclient.models.api.requests.alarmcallbacks.CreateAlarmCallbackRequest;
import org.graylog2.restclient.models.api.responses.alarmcallbacks.*;
import org.graylog2.restroutes.generated.AlarmCallbackResource;
import org.graylog2.restroutes.generated.routes;
import play.mvc.Http;
Expand Down Expand Up @@ -71,8 +72,8 @@ public CreateAlarmCallbackResponse create(String streamId, CreateAlarmCallbackRe
return apiClient.path(resource.create(streamId), CreateAlarmCallbackResponse.class).body(request).expect(Http.Status.CREATED).execute();
}

public Map<String, GetSingleAvailableAlarmCallbackResponse> available(String streamId) throws IOException, APIException {
GetAvailableAlarmCallbacksResponse response = apiClient.path(resource.available(streamId), GetAvailableAlarmCallbacksResponse.class)
public Map<String, AvailableAlarmCallbackSummaryResponse> available(String streamId) throws IOException, APIException {
final AvailableAlarmCallbacksResponse response = apiClient.path(resource.available(streamId), AvailableAlarmCallbacksResponse.class)
.expect(Http.Status.OK).execute();

return response.types;
Expand Down
Expand Up @@ -17,7 +17,7 @@
package org.graylog2.restclient.models;

import com.google.common.collect.Maps;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.List;
import java.util.Map;
Expand Down
Expand Up @@ -17,14 +17,13 @@
package org.graylog2.restclient.models;

import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.lib.ApiClient;
import org.graylog2.restclient.lib.metrics.Gauge;
import org.graylog2.restclient.lib.metrics.Metric;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.restclient.lib.timeranges.InvalidRangeParametersException;
import org.graylog2.restclient.lib.timeranges.RelativeRange;
import org.graylog2.restclient.models.api.requests.AddStaticFieldRequest;
Expand Down
Expand Up @@ -18,11 +18,11 @@

import com.google.common.collect.Lists;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.graylog2.restclient.lib.plugin.configuration.BooleanField;
import org.graylog2.restclient.lib.plugin.configuration.DropdownField;
import org.graylog2.restclient.lib.plugin.configuration.NumberField;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.restclient.lib.plugin.configuration.TextField;
import org.graylog2.rest.models.configuration.responses.BooleanField;
import org.graylog2.rest.models.configuration.responses.DropdownField;
import org.graylog2.rest.models.configuration.responses.NumberField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.TextField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -18,11 +18,11 @@

import com.google.common.collect.Lists;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.graylog2.restclient.lib.plugin.configuration.BooleanField;
import org.graylog2.restclient.lib.plugin.configuration.DropdownField;
import org.graylog2.restclient.lib.plugin.configuration.NumberField;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.restclient.lib.plugin.configuration.TextField;
import org.graylog2.rest.models.configuration.responses.BooleanField;
import org.graylog2.rest.models.configuration.responses.DropdownField;
import org.graylog2.rest.models.configuration.responses.NumberField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.TextField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Expand Up @@ -18,8 +18,8 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.restclient.lib.plugin.configuration.TextField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.TextField;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Expand Up @@ -14,22 +14,22 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.models.api.responses.alarmcallbacks;
package org.graylog2.rest.models.alarmcallbacks.responses;

import com.google.common.collect.Lists;
import org.graylog2.restclient.lib.plugin.configuration.BooleanField;
import org.graylog2.restclient.lib.plugin.configuration.DropdownField;
import org.graylog2.restclient.lib.plugin.configuration.NumberField;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.restclient.lib.plugin.configuration.TextField;
import org.graylog2.rest.models.configuration.responses.BooleanField;
import org.graylog2.rest.models.configuration.responses.DropdownField;
import org.graylog2.rest.models.configuration.responses.NumberField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.TextField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

public class GetSingleAvailableAlarmCallbackResponse {
private static final Logger LOG = LoggerFactory.getLogger(GetSingleAvailableAlarmCallbackResponse.class);
public class AvailableAlarmCallbackSummaryResponse {
private static final Logger LOG = LoggerFactory.getLogger(AvailableAlarmCallbackSummaryResponse.class);

public String name;
public Map<String, Map<String, Object>> requested_configuration;
Expand Down
Expand Up @@ -14,24 +14,24 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.models.api.responses.alarmcallbacks;
package org.graylog2.rest.models.alarmcallbacks.responses;

import com.google.common.collect.Maps;
import org.graylog2.restclient.lib.plugin.configuration.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.List;
import java.util.Map;

/**
* @author Dennis Oelkers <dennis@torch.sh>
*/
public class GetAvailableAlarmCallbacksResponse {
public Map<String, GetSingleAvailableAlarmCallbackResponse> types;
public class AvailableAlarmCallbacksResponse {
public Map<String, AvailableAlarmCallbackSummaryResponse> types;

public Map<String, List<RequestedConfigurationField>> getRequestedConfiguration() {
Map<String, List<RequestedConfigurationField>> result = Maps.newHashMap();

for (Map.Entry<String, GetSingleAvailableAlarmCallbackResponse> entry : types.entrySet()) {
for (Map.Entry<String, AvailableAlarmCallbackSummaryResponse> entry : types.entrySet()) {
result.put(entry.getKey(), entry.getValue().extractRequestedConfiguration(entry.getValue().requested_configuration));
}

Expand Down
Expand Up @@ -14,7 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.lib.plugin.configuration;
package org.graylog2.rest.models.configuration.responses;

import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.Map;

Expand Down
Expand Up @@ -14,7 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.lib.plugin.configuration;
package org.graylog2.rest.models.configuration.responses;

import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.Map;

Expand Down
Expand Up @@ -14,7 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.lib.plugin.configuration;
package org.graylog2.rest.models.configuration.responses;

import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.Map;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.lib.plugin.configuration;
package org.graylog2.rest.models.configuration.responses;

import java.util.List;
import java.util.Map;
Expand Down
Expand Up @@ -14,7 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package org.graylog2.restclient.lib.plugin.configuration;
package org.graylog2.rest.models.configuration.responses;

import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;

import java.util.Map;

Expand Down
Expand Up @@ -17,7 +17,6 @@
package org.graylog2.rest.resources.alarmcallbacks;

import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.wordnik.swagger.annotations.Api;
Expand All @@ -36,6 +35,8 @@
import org.graylog2.rest.models.alarmcallbacks.AlarmCallbackListSummary;
import org.graylog2.rest.models.alarmcallbacks.AlarmCallbackSummary;
import org.graylog2.rest.models.alarmcallbacks.responses.CreateAlarmCallbackResponse;
import org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbacksResponse;
import org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbackSummaryResponse;
import org.graylog2.shared.rest.resources.RestResource;
import org.graylog2.shared.security.RestPermissions;
import org.graylog2.streams.StreamService;
Expand Down Expand Up @@ -158,17 +159,20 @@ public Response create(@ApiParam(name = "streamid", value = "The stream id this
@Timed
@ApiOperation(value = "Get a list of all alarm callback types")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Map<String, Object>> available(@ApiParam(name = "streamid", value = "The id of the stream whose alarm callbacks we want.", required = true)
public AvailableAlarmCallbacksResponse available(@ApiParam(name = "streamid", value = "The id of the stream whose alarm callbacks we want.", required = true)
@PathParam("streamid") String streamid) {
final Map<String, Object> types = Maps.newHashMapWithExpectedSize(availableAlarmCallbacks.size());
final Map<String, AvailableAlarmCallbackSummaryResponse> types = Maps.newHashMapWithExpectedSize(availableAlarmCallbacks.size());
for (AlarmCallback availableAlarmCallback : availableAlarmCallbacks) {
Map<String, Object> type = Maps.newHashMap();
type.put("requested_configuration", availableAlarmCallback.getRequestedConfiguration().asList());
type.put("name", availableAlarmCallback.getName());
final AvailableAlarmCallbackSummaryResponse type = new AvailableAlarmCallbackSummaryResponse();
type.name = availableAlarmCallback.getName();
type.requested_configuration = availableAlarmCallback.getRequestedConfiguration().asList();
types.put(availableAlarmCallback.getClass().getCanonicalName(), type);
}

return ImmutableMap.of("types", types);
final AvailableAlarmCallbacksResponse response = new AvailableAlarmCallbacksResponse();
response.types = types;

return response;
}

@DELETE
Expand Down

0 comments on commit a696efe

Please sign in to comment.