Skip to content

Commit

Permalink
feat(apache#3032): Harmonize data explorer and live dashboard (apache…
Browse files Browse the repository at this point in the history
…#3058)

* feat(apache#3033): Support modification of data views (apache#3034)

* feat(apache#3033): Support modification of data views

* Fix checkstyle

* Fix cypress

* Remove cypress selector

* feat(apache#3043): Add data view selection to data explorer dashboard (apache#3044)

* feat(apache#3043): Add data view selection to data explorer dashboard

* Add routing service

* Fix cypress tests and modify routing

* feat(3059): Extend capabilities of time selection bar (apache#3066)

* feat(apache#3059): Replace time selection bar with menu

* Fix tests

* Support global and widget time

* Fix time update

* feat(apache#3068): Add refresh interval to data explorer dashboard (apache#3069)

* feat(apache#3068): Add refresh interval to data explorer dashboard

* Remove empty stylesheet

* feat(apache#3079): Add permission management to data views (apache#3082)

* feat(apache#3079): Add migration for existing data views

* Fix checkstyle

* Add permissions to rest interface

* feat(apache#3091): Add option to configure time ordering (apache#3092)

* feat(apache#3091): Add option to configure time ordering

* Remove deprecated model

* Fix checkstyle

* test: Add time order test + minor changes (apache#3113)

* added time order test + minor changes

* minor changes for e2e test

---------

Co-authored-by: Marcelfrueh <[email protected]>

* feat(apache#3090): Add gauge chart to data explorer (apache#3127)

* feat(apache#3090): Add gauge chart to data explorer

* Cleanup

* Fix tests

* Add dialog window for deleting data views/dashboards and test functionality with new E2E-test (apache#3137)

* Add dialog window for deletion of data view and dashboards + add tests for this feature

* Enhance test with cancellation of deletion

* bug fixes and minor changes in data explorer

* new functions for data lake utils + fixes for delete-widget-test

* Update ts model

---------

Co-authored-by: Marcelfrueh <[email protected]>
  • Loading branch information
dominikriemer and Marcelfrueh authored Aug 19, 2024
1 parent a5c6e2d commit 6cce352
Show file tree
Hide file tree
Showing 132 changed files with 4,411 additions and 1,735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class PermissionBuilder {

private Permission permission;
private final Permission permission;

private PermissionBuilder(String objectInstanceId,
Class<?> objectInstanceClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public class DashboardModel implements Storable {

private Map<String, Object> dashboardTimeSettings;
private Map<String, Object> dashboardGeneralSettings;
private Map<String, Object> dashboardLiveSettings;

private List<DashboardItem> widgets;

public DashboardModel() {
this.dashboardTimeSettings = new HashMap<>();
this.dashboardGeneralSettings = new HashMap<>();
this.dashboardLiveSettings = new HashMap<>();
}

public String getId() {
Expand Down Expand Up @@ -133,4 +135,12 @@ public void setElementId(String elementId) {
public String getCouchDbId() {
return this.elementId;
}

public Map<String, Object> getDashboardLiveSettings() {
return dashboardLiveSettings;
}

public void setDashboardLiveSettings(Map<String, Object> dashboardLiveSettings) {
this.dashboardLiveSettings = dashboardLiveSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class DataExplorerWidgetModel extends DashboardEntity {
@JsonSerialize(using = CustomMapSerializer.class, as = Map.class)
private Map<String, Object> dataConfig;

@JsonSerialize(using = CustomMapSerializer.class, as = Map.class)
private Map<String, Object> timeSettings;

private String pipelineId;
private String measureName;

Expand All @@ -49,6 +52,7 @@ public DataExplorerWidgetModel() {
this.baseAppearanceConfig = new HashMap<>();
this.visualizationConfig = new HashMap<>();
this.dataConfig = new HashMap<>();
this.timeSettings = new HashMap<>();
}

public String getWidgetId() {
Expand Down Expand Up @@ -107,4 +111,12 @@ public void setMeasureName(String measureName) {
this.measureName = measureName;
}

public Map<String, Object> getTimeSettings() {
return this.timeSettings;
}

public void setTimeSettings(Map<String, Object> timeSettings) {
this.timeSettings = timeSettings;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,54 @@
package org.apache.streampipes.resource.management;

import org.apache.streampipes.model.client.user.Permission;
import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.model.shared.api.Storable;
import org.apache.streampipes.model.util.ElementIdGenerator;
import org.apache.streampipes.storage.api.CRUDStorage;

import java.util.List;

public abstract class AbstractDashboardResourceManager
extends AbstractResourceManager<CRUDStorage<DashboardModel>> {
public abstract class AbstractCRUDResourceManager<T extends Storable>
extends AbstractResourceManager<CRUDStorage<T>> {

public AbstractDashboardResourceManager(CRUDStorage<DashboardModel> db) {
private final Class<T> elementClass;

public AbstractCRUDResourceManager(CRUDStorage<T> db,
Class<T> elementClass) {
super(db);
this.elementClass = elementClass;
}

public List<DashboardModel> findAll() {
public List<T> findAll() {
return db.findAll();
}

public DashboardModel find(String dashboardId) {
return db.getElementById(dashboardId);
public T find(String elementId) {
return db.getElementById(elementId);
}

public void delete(String dashboardId) {
db.deleteElementById(dashboardId);
deletePermissions(dashboardId);
public void delete(String elementId) {
db.deleteElementById(elementId);
deletePermissions(elementId);
}

public void create(DashboardModel dashboardModel, String principalSid) {
if (dashboardModel.getElementId() == null) {
dashboardModel.setElementId(ElementIdGenerator.makeElementId(DashboardModel.class));
public T create(T element,
String principalSid) {
if (element.getElementId() == null) {
element.setElementId(ElementIdGenerator.makeElementId(elementClass));
}
db.persist(dashboardModel);
new PermissionResourceManager().createDefault(dashboardModel.getElementId(), DashboardModel.class, principalSid,
db.persist(element);
new PermissionResourceManager().createDefault(element.getElementId(), elementClass, principalSid,
false);
return find(element.getElementId());
}

public void update(DashboardModel dashboardModel) {
db.updateElement(dashboardModel);
public void update(T element) {
db.updateElement(element);
}

private void deletePermissions(String dashboardId) {
private void deletePermissions(String elementId) {
PermissionResourceManager manager = new PermissionResourceManager();
List<Permission> permissions = manager.findForObjectId(dashboardId);
List<Permission> permissions = manager.findForObjectId(elementId);
permissions.forEach(manager::delete);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package org.apache.streampipes.resource.management;

import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.storage.management.StorageDispatcher;

public class DashboardResourceManager extends AbstractDashboardResourceManager {
public class DashboardResourceManager extends AbstractCRUDResourceManager<DashboardModel> {

public DashboardResourceManager() {
super(StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardStorage());
super(StorageDispatcher.INSTANCE.getNoSqlStore().getDashboardStorage(), DashboardModel.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package org.apache.streampipes.resource.management;

import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.storage.management.StorageDispatcher;

public class DataExplorerResourceManager extends AbstractDashboardResourceManager {
public class DataExplorerResourceManager extends AbstractCRUDResourceManager<DashboardModel> {

public DataExplorerResourceManager() {
super(StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerDashboardStorage());
super(StorageDispatcher.INSTANCE.getNoSqlStore().getDataExplorerDashboardStorage(), DashboardModel.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.streampipes.resource.management;

import org.apache.streampipes.model.datalake.DataExplorerWidgetModel;
import org.apache.streampipes.storage.api.CRUDStorage;

public class DataExplorerWidgetResourceManager extends AbstractCRUDResourceManager<DataExplorerWidgetModel> {

public DataExplorerWidgetResourceManager(CRUDStorage<DataExplorerWidgetModel> db) {
super(db, DataExplorerWidgetModel.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public List<Permission> findAll() {
return db.findAll();
}

public Permission find(String elementId) {
return db.getElementById(elementId);
}

public List<Permission> findForObjectId(String objectInstanceId) {
return db.getUserPermissionsForObject(objectInstanceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package org.apache.streampipes.resource.management;

import org.apache.streampipes.model.datalake.DataExplorerWidgetModel;
import org.apache.streampipes.storage.api.CRUDStorage;

public class SpResourceManager {

public AdapterResourceManager manageAdapters() {
Expand All @@ -35,6 +38,10 @@ public DataExplorerResourceManager manageDataExplorer() {
return new DataExplorerResourceManager();
}

public DataExplorerWidgetResourceManager manageDataExplorerWidget(CRUDStorage<DataExplorerWidgetModel> db) {
return new DataExplorerWidgetResourceManager(db);
}

public DataProcessorResourceManager manageDataProcessors() {
return new DataProcessorResourceManager();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.streampipes.rest.impl.dashboard;

import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.resource.management.AbstractDashboardResourceManager;
import org.apache.streampipes.resource.management.AbstractCRUDResourceManager;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;

import org.springframework.http.MediaType;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<Void> createDashboard(@RequestBody DashboardModel dashboar
return ok();
}

protected abstract AbstractDashboardResourceManager getResourceManager();
protected abstract AbstractCRUDResourceManager<DashboardModel> getResourceManager();

/**
* Do not delete these abstract methods below - required by Spring SPEL (see above)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
package org.apache.streampipes.rest.impl.dashboard;

import org.apache.streampipes.model.client.user.Privilege;
import org.apache.streampipes.resource.management.AbstractDashboardResourceManager;
import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.resource.management.AbstractCRUDResourceManager;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -29,7 +30,7 @@
public class Dashboard extends AbstractDashboardResource {

@Override
protected AbstractDashboardResourceManager getResourceManager() {
protected AbstractCRUDResourceManager<DashboardModel> getResourceManager() {
return getSpResourceManager().manageDashboards();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


import org.apache.streampipes.model.client.user.Privilege;
import org.apache.streampipes.resource.management.AbstractDashboardResourceManager;
import org.apache.streampipes.model.dashboard.DashboardModel;
import org.apache.streampipes.resource.management.AbstractCRUDResourceManager;
import org.apache.streampipes.rest.impl.dashboard.AbstractDashboardResource;

import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -31,7 +32,7 @@
public class DataLakeDashboardResource extends AbstractDashboardResource {

@Override
protected AbstractDashboardResourceManager getResourceManager() {
protected AbstractCRUDResourceManager<DashboardModel> getResourceManager() {
return getSpResourceManager().manageDataExplorer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

package org.apache.streampipes.rest.impl.datalake;

import org.apache.streampipes.model.dashboard.DashboardWidgetModel;
import org.apache.streampipes.model.client.user.Privilege;
import org.apache.streampipes.model.datalake.DataExplorerWidgetModel;
import org.apache.streampipes.model.util.ElementIdGenerator;
import org.apache.streampipes.rest.core.base.impl.AbstractRestResource;
import org.apache.streampipes.storage.api.CRUDStorage;
import org.apache.streampipes.resource.management.DataExplorerWidgetResourceManager;
import org.apache.streampipes.resource.management.SpResourceManager;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -39,48 +42,69 @@

@RestController
@RequestMapping("/api/v3/datalake/dashboard/widgets")
public class DataLakeWidgetResource extends AbstractRestResource {
public class DataLakeWidgetResource extends AbstractAuthGuardedRestResource {

private final DataExplorerWidgetResourceManager resourceManager;

public DataLakeWidgetResource() {
this.resourceManager = new SpResourceManager().manageDataExplorerWidget(
getNoSqlStorage().getDataExplorerWidgetStorage()
);
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<DataExplorerWidgetModel>> getAllDataExplorerWidgets() {
return ok(getDataExplorerWidgetStorage().findAll());
@PreAuthorize(AuthConstants.HAS_READ_DATA_EXPLORER_PRIVILEGE)
@PostFilter("hasPermission(filterObject.elementId, 'READ')")
public List<DataExplorerWidgetModel> getAllDataExplorerWidgets() {
return resourceManager.findAll();
}

@GetMapping(path = "/{widgetId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DataExplorerWidgetModel> getDataExplorerWidget(@PathVariable("widgetId") String widgetId) {
return ok(getDataExplorerWidgetStorage().getElementById(widgetId));
@PreAuthorize("this.hasReadAuthority() and hasPermission(#elementId, 'READ')")
public ResponseEntity<DataExplorerWidgetModel> getDataExplorerWidget(@PathVariable("widgetId") String elementId) {
return ok(resourceManager.find(elementId));
}

@PutMapping(
path = "/{widgetId}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("this.hasWriteAuthority() and hasPermission(#dataExplorerWidgetModel.elementId, 'WRITE')")
public ResponseEntity<DataExplorerWidgetModel> modifyDataExplorerWidget(
@RequestBody DataExplorerWidgetModel dataExplorerWidgetModel) {
getDataExplorerWidgetStorage().updateElement(dataExplorerWidgetModel);
return ok(getDataExplorerWidgetStorage().getElementById(dataExplorerWidgetModel.getElementId()));
resourceManager.update(dataExplorerWidgetModel);
return ok(resourceManager.find(dataExplorerWidgetModel.getElementId()));
}

@DeleteMapping(path = "/{widgetId}")
public ResponseEntity<Void> deleteDataExplorerWidget(@PathVariable("widgetId") String widgetId) {
getDataExplorerWidgetStorage().deleteElementById(widgetId);
@PreAuthorize("this.hasWriteAuthority() and hasPermission(#elementId, 'WRITE')")
public ResponseEntity<Void> deleteDataExplorerWidget(@PathVariable("widgetId") String elementId) {
resourceManager.delete(elementId);
return ok();
}

@PostMapping(
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
@PreAuthorize("this.hasWriteAuthority() and hasPermission(#dataExplorerWidgetModel.elementId, 'WRITE')")
public ResponseEntity<DataExplorerWidgetModel> createDataExplorerWidget(
@RequestBody DataExplorerWidgetModel dataExplorerWidgetModel) {
String elementId = ElementIdGenerator.makeElementId(DashboardWidgetModel.class);
dataExplorerWidgetModel.setElementId(elementId);
getDataExplorerWidgetStorage().persist(dataExplorerWidgetModel);
return ok(getDataExplorerWidgetStorage().getElementById(elementId));
return ok(resourceManager.create(dataExplorerWidgetModel, getAuthenticatedUserSid()));
}

/**
* required by Spring expression
*/
public boolean hasReadAuthority() {
return isAdminOrHasAnyAuthority(Privilege.Constants.PRIVILEGE_READ_DATA_EXPLORER_VIEW_VALUE);
}

private CRUDStorage<DataExplorerWidgetModel> getDataExplorerWidgetStorage() {
return getNoSqlStorage().getDataExplorerWidgetStorage();
/**
* required by Spring expression
*/
public boolean hasWriteAuthority() {
return isAdminOrHasAnyAuthority(Privilege.Constants.PRIVILEGE_WRITE_DATA_EXPLORER_VIEW_VALUE);
}

}
Loading

0 comments on commit 6cce352

Please sign in to comment.