Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

WIP: multiple widgets #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/properties-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dbpassword=${SPRING_DATA_MONGODB_PASSWORD:-dbpassword}
#This is ensure if you are keeping DB outside docker compose.
dbhostport=${SPRING_DATA_MONGODB_HOST}:${SPRING_DATA_MONGODB_PORT}

# api port
server.port=${API_PORT:-8081}

#API encryption key. Optional. See https://hygieia.github.io/Hygieia/setup.html#encryption-for-private-repos
key=${KEY:-}
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/capitalone/dashboard/model/ActiveWidget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.capitalone.dashboard.model;

import java.util.Objects;

/**
* Created by stevegal on 20/10/2018.
*/
public class ActiveWidget {

private String type;

private String title;

public ActiveWidget(Builder builder) {
this.type = builder.type;
this.title = builder.title;
}

public ActiveWidget() {

}

public static Builder newActiveWidget() {
return new Builder();
}

public String getTitle() {
return title;
}

public String getType() {
return type;
}

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

public void setType(String type) {
this.type = type;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ActiveWidget that = (ActiveWidget) o;
return Objects.equals(type, that.type) &&
Objects.equals(title, that.title);
}

@Override
public int hashCode() {
return Objects.hash(type, title);
}

public static final class Builder {
private String type;
private String title;

public Builder() {
}

public ActiveWidget build() {
return new ActiveWidget(this);
}

public Builder type(String type) {
this.type = type;
return this;
}

public Builder title(String title) {
this.title = title;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import org.bson.types.ObjectId;

import javax.validation.constraints.NotNull;
import java.util.List;

public class CodeQualityRequest {
@NotNull
private ObjectId componentId;
@NotNull
private List<ObjectId> collectorItemIds;
private Integer max;
private Integer numberOfDays;
private Long dateBegins;
Expand Down Expand Up @@ -65,4 +68,12 @@ public void setType(CodeQualityType type) {
public boolean validDateRange() {
return dateBegins != null || dateEnds != null;
}

public List<ObjectId> getCollectorItemIds() {
return collectorItemIds;
}

public void setCollectorItemIds(List<ObjectId> collectorItemIds) {
this.collectorItemIds = collectorItemIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class CommitRequest {
@NotNull
private ObjectId componentId;
private ObjectId collectorItemId;
private Integer numberOfDays;
private Long commitDateBegins;
private Long commitDateEnds;
Expand Down Expand Up @@ -97,4 +98,12 @@ public boolean validCommitDateRange() {
public boolean validChangesRange() {
return changesGreaterThan != null || changesLessThan != null;
}

public ObjectId getCollectorItemId() {
return collectorItemId;
}

public void setCollectorItemId(ObjectId collectorItemId) {
this.collectorItemId = collectorItemId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.validation.constraints.Size;

import com.capitalone.dashboard.auth.AuthenticationUtil;
import com.capitalone.dashboard.model.ActiveWidget;
import com.capitalone.dashboard.model.Application;
import com.capitalone.dashboard.model.Component;
import com.capitalone.dashboard.model.Dashboard;
Expand All @@ -15,6 +16,7 @@
import com.google.common.collect.Lists;

import java.util.List;
import java.util.stream.Collectors;

public class DashboardRequest {
@NotNull
Expand Down Expand Up @@ -44,7 +46,7 @@ public class DashboardRequest {
@Size(min=1, message="Please select a type")
private String type;

private List<String> activeWidgets;
private List<DashboardRequestWidget> activeWidgets;

public String getTemplate() {
return template;
Expand Down Expand Up @@ -104,11 +106,11 @@ public void setConfigurationItemBusAppName(String configurationItemBusAppName) {
this.configurationItemBusAppName = configurationItemBusAppName;
}

public List<String> getActiveWidgets() {
public List<DashboardRequestWidget> getActiveWidgets() {
return activeWidgets;
}

public void setActiveWidgets(List<String> activeWidgets) {
public void setActiveWidgets(List<DashboardRequestWidget> activeWidgets) {
this.activeWidgets = activeWidgets;
}

Expand Down Expand Up @@ -142,14 +144,23 @@ public Dashboard toDashboard() {
type ,
configurationItemBusServName,
configurationItemBusAppName,
activeWidgets,
convert(activeWidgets),
scoreEnabled,
ScoreDisplayType.fromString(scoreDisplay)
);


}

private List<ActiveWidget> convert(List<DashboardRequestWidget> widget) {
return null==widget?null:widget.stream().map(DashboardRequest::convert).collect(Collectors.toList());
}

private static ActiveWidget convert(DashboardRequestWidget request) {
return ActiveWidget.newActiveWidget().title(request.getTitle()).type(request.getType()).build();
}


public Dashboard copyTo(Dashboard dashboard) {
Dashboard updated = toDashboard();
updated.setId(dashboard.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.capitalone.dashboard.request;

/**
* Created by stevegal on 20/10/2018.
*/
public class DashboardRequestWidget {

private String title;

private String type;

public String getType() {
return type;
}

public String getTitle() {
return title;
}

public void setType(String type) {
this.type = type;
}

public void setTitle(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class GitRequestRequest {
@NotNull
private ObjectId componentId;
private ObjectId collectorItemId;
private Integer numberOfDays;

public ObjectId getComponentId() {
Expand All @@ -25,4 +26,12 @@ public void setNumberOfDays(Integer numberOfDays) {
this.numberOfDays = numberOfDays;
}

public ObjectId getCollectorItemId() {
return collectorItemId;
}

public void setCollectorItemId(ObjectId collectorItemId) {
this.collectorItemId = collectorItemId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.bson.types.ObjectId;

import javax.validation.constraints.NotNull;
import java.util.List;

public class LibraryPolicyRequest {
@NotNull
private ObjectId componentId;
private List<ObjectId> collectorItemIds;
private Integer max;
private Integer numberOfDays;
private Long dateBegins;
Expand Down Expand Up @@ -55,4 +57,12 @@ public void setDateEnds(Long dateEnds) {
public boolean validDateRange() {
return dateBegins != null || dateEnds != null;
}

public List<ObjectId> getCollectorItemIds() {
return collectorItemIds;
}

public void setCollectorItemIds(List<ObjectId> collectorItemIds) {
this.collectorItemIds = collectorItemIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class PerformanceSearchRequest {
@NotNull
private ObjectId componentId;
private ObjectId collectorItemId;
private Integer max;
private Integer numberOfDays;
private Long dateBegins;
Expand Down Expand Up @@ -65,4 +66,12 @@ public void setType(PerformanceType type) {
public boolean validDateRange() {
return dateBegins != null || dateEnds != null;
}

public ObjectId getCollectorItemId() {
return collectorItemId;
}

public void setCollectorItemId(ObjectId collectorItemId) {
this.collectorItemId = collectorItemId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
public class TestResultRequest {
@NotNull
private ObjectId componentId;
@NotNull
private List<ObjectId> collectorItemIds;
private Integer max;
private Long startDateBegins;
private Long startDateEnds;
Expand Down Expand Up @@ -113,4 +115,12 @@ public boolean validEndDateRange() {
public boolean validDurationRange() {
return durationGreaterThan != null || durationLessThan != null;
}

public List<ObjectId> getCollectorItemIds() {
return collectorItemIds;
}

public void setCollectorItemIds(List<ObjectId> collectorItemIds) {
this.collectorItemIds = collectorItemIds;
}
}
17 changes: 15 additions & 2 deletions src/main/java/com/capitalone/dashboard/request/WidgetRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class WidgetRequest {
private ObjectId componentId;
private List<ObjectId> collectorItemIds;
private Map<String, Object> options;
private String type;

public String getName() {
return name;
Expand Down Expand Up @@ -44,29 +45,41 @@ public void setOptions(Map<String, Object> options) {
this.options = options;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Widget widget() {
Widget widget = new Widget();
widget.setName(name);
widget.setType(type);
widget.setComponentId(componentId);
if ((options != null) && !options.isEmpty()) {
widget.getOptions().put("id",options.get("id"));
if("build".equalsIgnoreCase(name)){
if("build".equalsIgnoreCase(type)){
widget.getOptions().put("buildDurationThreshold",3);
widget.getOptions().put("consecutiveFailureThreshold",5);
} else if ("AgileTool".equalsIgnoreCase(name) || "feature".equalsIgnoreCase(name)) {
} else if ("AgileTool".equalsIgnoreCase(type) || "feature".equalsIgnoreCase(type)) {
widget.getOptions().putAll(options);
}
}
widget.setCollectorItemIds(this.collectorItemIds);
return widget;
}

public Widget updateWidget(Widget widget) {
widget.setComponentId(componentId);
widget.setName(name);
widget.setType(type);
widget.getOptions().clear();
if ((options != null) && !options.isEmpty()) {
widget.getOptions().putAll(options);
}
widget.setCollectorItemIds(this.collectorItemIds);
return widget;
}
}
Loading