Skip to content

Commit

Permalink
Merge pull request #154 from anotheria/ISSUE-151
Browse files Browse the repository at this point in the history
Issue #151
  • Loading branch information
dvayanu authored Nov 24, 2023
2 parents 0f37591 + 26f0c9f commit 2380f27
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,23 @@ public void removeChart(String name) {
charts = newCharts;
}

public void addView(ViewConfig newView){
//first we check if we have a view by this name, if positive - update, if negative - create.
int i = 0;
for (ViewConfig view : views){
if (view.getName().equals(newView.getName())){
views[i] = newView;
return;
}
i++;
}

ViewConfig[] newViews = Arrays.copyOf(views, views.length + 1);

newViews[newViews.length - 1] = newView;
views = newViews;
}

public void removeView(String name) {
boolean hasView = false;
for (ViewConfig view : views){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,7 @@ private void readConfig() {
views.put("ALL", defaultView);
}
for (ViewConfig vc : configuredViews) {
View v = new View(vc.getName());
v.setComponentCategoryFilter(vc.getComponentCategories());
v.setComponentFilter(vc.getComponents());
v.setComponentTagsFilter(vc.getComponentTags());
v.setChartFilter(vc.getCharts());
v.setChartTagsFilter(vc.getChartTags());
v.setWidgetsFilter(vc.getWidgets());
v.setWidgetTagsFilter(vc.getWidgetTags());
views.put(v.getName(), v);
addView(vc);
}

}
Expand Down Expand Up @@ -266,6 +258,18 @@ private boolean noCustomConfigurationProviders(){
return customConfigurationProviders==null || customConfigurationProviders.size()==0;
}

public void addView(ViewConfig vc) {
View v = new View(vc.getName());
v.setComponentCategoryFilter(vc.getComponentCategories());
v.setComponentFilter(vc.getComponents());
v.setComponentTagsFilter(vc.getComponentTags());
v.setChartFilter(vc.getCharts());
v.setChartTagsFilter(vc.getChartTags());
v.setWidgetsFilter(vc.getWidgets());
v.setWidgetTagsFilter(vc.getWidgetTags());
views.put(v.getName(), v);
}

public List<View> getViews() {
return new LinkedList<>(views.values());
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/moskito/control/core/View.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.moskito.control.core;

import org.moskito.control.common.HealthColor;
import org.moskito.control.config.ViewConfig;
import org.moskito.control.core.chart.Chart;
import org.moskito.control.core.history.StatusUpdateHistoryItem;
import org.moskito.control.core.history.StatusUpdateHistoryRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.moskito.control.ui.restapi.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.servers.Server;
import org.moskito.control.config.ChartConfig;
import org.moskito.control.config.ComponentConfig;
import org.moskito.control.config.MoskitoControlConfiguration;
import org.moskito.control.config.ViewConfig;
import org.moskito.control.core.Component;
import org.moskito.control.core.ComponentRepository;
import org.moskito.control.ui.restapi.ReplyObject;
import org.moskito.control.ui.restapi.config.bean.ViewPO;
import org.moskito.control.ui.restapi.config.bean.ComponentPO;

import javax.ws.rs.*;
Expand All @@ -22,7 +20,6 @@
@Path("configuration")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Server(url = "/rest")
@Server(url = "/api/v2")
public class ConfigResource {

Expand Down Expand Up @@ -77,6 +74,16 @@ public ReplyObject getViews(){
return ReplyObject.success("views", MoskitoControlConfiguration.getConfiguration().getViews());
}

@Path("views")
@POST
public ReplyObject addView(ViewPO viewPO){
ViewConfig toAdd = viewPO.toViewConfig();
MoskitoControlConfiguration.getConfiguration().addView(toAdd);
ComponentRepository.getInstance().addView(toAdd);

return ReplyObject.success();
}

@Path("views/{name}") @DELETE
public ReplyObject deleteView(
@Parameter(description = "Name of the view to remove from the config", required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.moskito.control.ui.restapi.config.bean;

import org.moskito.control.config.ViewConfig;

import java.util.Arrays;
import java.util.Objects;

public class ViewPO {

private String name;

private String[] componentCategories;

private String[] components;

private String[] charts;

private String[] chartTags;

private String[] componentTags;

private String[] widgets;

private String[] widgetTags;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String[] getComponentCategories() {
return componentCategories;
}

public void setComponentCategories(String[] componentCategories) {
this.componentCategories = componentCategories;
}

public String[] getComponents() {
return components;
}

public void setComponents(String[] components) {
this.components = components;
}

public String[] getCharts() {
return charts;
}

public void setCharts(String[] charts) {
this.charts = charts;
}

public String[] getChartTags() {
return chartTags;
}

public void setChartTags(String[] chartTags) {
this.chartTags = chartTags;
}

public String[] getComponentTags() {
return componentTags;
}

public void setComponentTags(String[] componentTags) {
this.componentTags = componentTags;
}

public String[] getWidgets() {
return widgets;
}

public void setWidgets(String[] widgets) {
this.widgets = widgets;
}

public String[] getWidgetTags() {
return widgetTags;
}

public void setWidgetTags(String[] widgetTags) {
this.widgetTags = widgetTags;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ViewPO viewPO = (ViewPO) o;
return Objects.equals(name, viewPO.name) && Arrays.equals(componentCategories, viewPO.componentCategories) && Arrays.equals(components, viewPO.components) && Arrays.equals(charts, viewPO.charts) && Arrays.equals(chartTags, viewPO.chartTags) && Arrays.equals(componentTags, viewPO.componentTags) && Arrays.equals(widgets, viewPO.widgets) && Arrays.equals(widgetTags, viewPO.widgetTags);
}

@Override
public int hashCode() {
int result = Objects.hash(name);
result = 31 * result + Arrays.hashCode(componentCategories);
result = 31 * result + Arrays.hashCode(components);
result = 31 * result + Arrays.hashCode(charts);
result = 31 * result + Arrays.hashCode(chartTags);
result = 31 * result + Arrays.hashCode(componentTags);
result = 31 * result + Arrays.hashCode(widgets);
result = 31 * result + Arrays.hashCode(widgetTags);
return result;
}

@Override
public String toString() {
return "ViewPO{" +
"name='" + name + '\'' +
", componentCategories=" + Arrays.toString(componentCategories) +
", components=" + Arrays.toString(components) +
", charts=" + Arrays.toString(charts) +
", chartTags=" + Arrays.toString(chartTags) +
", componentTags=" + Arrays.toString(componentTags) +
", widgets=" + Arrays.toString(widgets) +
", widgetTags=" + Arrays.toString(widgetTags) +
'}';
}

public ViewConfig toViewConfig(){
ViewConfig view = new ViewConfig();
view.setName(this.getName());
view.setComponentCategories(this.getComponentCategories());
view.setComponents(this.getComponents());
view.setCharts(this.getCharts());
view.setChartTags(this.getChartTags());
view.setComponentTags(this.getComponentTags());
view.setWidgets(this.getWidgets());
view.setWidgetTags(this.getWidgetTags());
return view;
}
}

0 comments on commit 2380f27

Please sign in to comment.