You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2022/06/14 20:00:49 UTC
[incubator-streampipes] branch dev updated: [STREAMPIPES-545] Add initial model to represent industrial assets
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new a9fc6def9 [STREAMPIPES-545] Add initial model to represent industrial assets
a9fc6def9 is described below
commit a9fc6def928fc4d47a9f2395459947a129a6307e
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Tue Jun 14 22:00:39 2022 +0200
[STREAMPIPES-545] Add initial model to represent industrial assets
---
.../backend/StreamPipesBackendApplication.java | 2 +
.../backend/StreamPipesResourceConfig.java | 1 +
.../rest/impl/admin/AssetManagementResource.java | 117 +++++++++++++++++++++
.../streampipes/storage/api/IGenericStorage.java | 36 +++++++
.../streampipes/storage/api/INoSqlStorage.java | 2 +
.../storage/couchdb/CouchDbStorageManager.java | 5 +
.../couchdb/constants/GenericCouchDbConstants.java | 27 +++++
.../storage/couchdb/impl/GenericStorageImpl.java | 96 +++++++++++++++++
.../couchdb/utils/CouchDbViewGenerator.java | 76 +++++++++++++
.../streampipes/storage/couchdb/utils/Utils.java | 51 ++++++++-
.../src/lib/apis/asset-management.service.ts | 57 ++++++++++
.../src/lib/model/assets/asset.model.ts | 45 ++++++++
.../platform-services/src/public-api.ts | 3 +
13 files changed, 514 insertions(+), 4 deletions(-)
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
index 6b0fe4f45..fb60350c7 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
@@ -27,6 +27,7 @@ import org.apache.streampipes.rest.security.SpPermissionEvaluator;
import org.apache.streampipes.service.base.BaseNetworkingConfig;
import org.apache.streampipes.service.base.StreamPipesServiceBase;
import org.apache.streampipes.storage.api.IPipelineStorage;
+import org.apache.streampipes.storage.couchdb.utils.CouchDbViewGenerator;
import org.apache.streampipes.storage.management.StorageDispatcher;
import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceGroups;
import org.apache.streampipes.svcdiscovery.api.model.DefaultSpServiceTags;
@@ -101,6 +102,7 @@ public class StreamPipesBackendApplication extends StreamPipesServiceBase {
}
new StreamPipesEnvChecker().updateEnvironmentVariables();
+ new CouchDbViewGenerator().createGenericDatabaseIfNotExists();
executorService.schedule(this::startAllPreviouslyStoppedPipelines, 5, TimeUnit.SECONDS);
LOG.info("Pipeline health check will run every {} seconds", HEALTH_CHECK_INTERVAL);
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
index 80dd28bd5..0499843fd 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
@@ -55,6 +55,7 @@ public class StreamPipesResourceConfig extends ResourceConfig {
register(AccountActivationResource.class);
register(Authentication.class);
register(AssetDashboardResource.class);
+ register(AssetManagementResource.class);
register(AutoComplete.class);
register(CategoryResource.class);
register(ConsulConfig.class);
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/AssetManagementResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/AssetManagementResource.java
new file mode 100644
index 000000000..d0317aec5
--- /dev/null
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/AssetManagementResource.java
@@ -0,0 +1,117 @@
+/*
+ * 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.rest.impl.admin;
+
+import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
+import org.apache.streampipes.rest.security.AuthConstants;
+import org.apache.streampipes.storage.api.IGenericStorage;
+import org.apache.streampipes.storage.management.StorageDispatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+
+@Path("/v2/assets")
+@Component
+@PreAuthorize(AuthConstants.IS_ADMIN_ROLE)
+public class AssetManagementResource extends AbstractAuthGuardedRestResource {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AssetManagementResource.class);
+
+ private static final String APP_DOC_TYPE = "asset-management";
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAll() {
+ try {
+ List<Map<String, Object>> assets = getGenericStorage().findAll(APP_DOC_TYPE);
+ return ok(assets);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response create(String asset) {
+ try {
+ Map<String, Object> obj = getGenericStorage().create(asset);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @GET
+ @Path("/{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCategory(@PathParam("id") String assetId) {
+ try {
+ Map<String, Object> obj = getGenericStorage().findOne(assetId);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @PUT
+ @Path("/{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response update(@PathParam("id") String assetId, String asset) {
+ try {
+ Map<String, Object> obj = getGenericStorage().update(assetId, asset);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @DELETE
+ @Path("/{id}/{rev}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response delete(@PathParam("id") String assetId, @PathParam("rev") String rev) {
+ try {
+ getGenericStorage().delete(assetId, rev);
+ return ok();
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ private IGenericStorage getGenericStorage() {
+ return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage();
+ }
+
+
+}
diff --git a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IGenericStorage.java b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IGenericStorage.java
new file mode 100644
index 000000000..7855a3791
--- /dev/null
+++ b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/IGenericStorage.java
@@ -0,0 +1,36 @@
+/*
+ * 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.storage.api;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+public interface IGenericStorage {
+
+ List<Map<String, Object>> findAll(String type) throws IOException;
+
+ Map<String, Object> findOne(String id) throws IOException;
+
+ Map<String, Object> create(String payload) throws IOException;
+
+ Map<String, Object> update(String id, String payload) throws IOException;
+
+ void delete(String id, String rev) throws IOException;
+}
diff --git a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INoSqlStorage.java b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INoSqlStorage.java
index 5c52dbcb5..6b4af153a 100644
--- a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INoSqlStorage.java
+++ b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INoSqlStorage.java
@@ -19,6 +19,8 @@ package org.apache.streampipes.storage.api;
public interface INoSqlStorage {
+ IGenericStorage getGenericStorage();
+
IAdapterStorage getAdapterInstanceStorage();
IAdapterStorage getAdapterDescriptionStorage();
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/CouchDbStorageManager.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/CouchDbStorageManager.java
index 4a8b83587..581ff2211 100644
--- a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/CouchDbStorageManager.java
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/CouchDbStorageManager.java
@@ -29,6 +29,11 @@ public enum CouchDbStorageManager implements INoSqlStorage {
return new AdapterDescriptionStorageImpl();
}
+ @Override
+ public IGenericStorage getGenericStorage() {
+ return new GenericStorageImpl();
+ }
+
@Override
public IAdapterStorage getAdapterInstanceStorage() {
return new AdapterInstanceStorageImpl();
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/constants/GenericCouchDbConstants.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/constants/GenericCouchDbConstants.java
new file mode 100644
index 000000000..97a597e5d
--- /dev/null
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/constants/GenericCouchDbConstants.java
@@ -0,0 +1,27 @@
+/*
+ * 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.storage.couchdb.constants;
+
+public class GenericCouchDbConstants {
+
+ public static final String DESIGN_DOC_NAME = "appDocType";
+ public static final String VIEW_NAME = "appDocType";
+ public static final String DB_NAME = "genericstorage";
+
+}
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/GenericStorageImpl.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/GenericStorageImpl.java
new file mode 100644
index 000000000..4465695ca
--- /dev/null
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/GenericStorageImpl.java
@@ -0,0 +1,96 @@
+package org.apache.streampipes.storage.couchdb.impl;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.net.UrlEscapers;
+import org.apache.http.client.fluent.Content;
+import org.apache.http.client.fluent.Request;
+import org.apache.streampipes.storage.api.IGenericStorage;
+import org.apache.streampipes.storage.couchdb.constants.GenericCouchDbConstants;
+import org.apache.streampipes.storage.couchdb.utils.Utils;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class GenericStorageImpl implements IGenericStorage {
+
+ private static final String ID = "id";
+ private static final String SLASH = "/";
+
+ private final TypeReference<Map<String,Object>> typeRef = new TypeReference<>() {};
+ private final ObjectMapper mapper;
+
+ public GenericStorageImpl() {
+ this.mapper = new ObjectMapper();
+ }
+
+ @Override
+ public List<Map<String, Object>> findAll(String type) throws IOException {
+ String query = getDatabaseRoute() + "/_design/appDocType/_view/appDocType?" + UrlEscapers.urlPathSegmentEscaper().escape("startkey=[\"" + type + "\"]&endkey=[\"" + type + "\",{}]&include_docs=true");
+ Map<String, Object> queryResult = this.queryDocuments(query);
+
+ List<Map<String, Object>> rows = (List<Map<String, Object>>) queryResult.get("rows");
+ List<Map<String, Object>> result = new ArrayList<>();
+
+ for (Map<String, Object> row : rows) {
+ if (!((String) row.get(ID)).startsWith("_design")) {
+ result.add((Map<String, Object>) row.get("doc"));
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public Map<String, Object> findOne(String id) throws IOException {
+ return this.queryDocuments(getDatabaseRoute() + SLASH + id);
+ }
+
+ @Override
+ public Map<String, Object> create(String payload) throws IOException {
+ Request req = Utils.postRequest(getDatabaseRoute(), payload);
+ Content content = executeAndReturnContent(req);
+
+ Map<String, Object> requestResult = deserialize(content.asString());
+ return this.findOne((String) requestResult.get(ID));
+ }
+
+ @Override
+ public Map<String, Object> update(String id, String payload) throws IOException {
+ Request req = Utils.putRequest(getDatabaseRoute() + SLASH + id, payload);
+ Content content = executeAndReturnContent(req);
+
+ Map<String, Object> requestResult = deserialize(content.asString());
+ return this.findOne((String) requestResult.get(ID));
+ }
+
+ @Override
+ public void delete(String id, String rev) throws IOException {
+ Request req = Utils.deleteRequest(getDatabaseRoute() + SLASH + id + "?rev=" + rev);
+ Content content = executeAndReturnContent(req);
+ }
+
+ private Map<String, Object> queryDocuments(String route) throws IOException {
+ Request req = Utils.getRequest(route);
+ Content content = executeAndReturnContent(req);
+
+ return deserialize(content.asString(StandardCharsets.UTF_8));
+ }
+
+ private Map<String, Object> deserialize(String payload) throws JsonProcessingException {
+
+ return mapper.readValue(payload, typeRef);
+ }
+
+ private Content executeAndReturnContent(Request req) throws IOException {
+ return req.execute().returnContent();
+ }
+
+ private String getDatabaseRoute() {
+ return Utils.getDatabaseRoute(GenericCouchDbConstants.DB_NAME);
+ }
+}
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/CouchDbViewGenerator.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/CouchDbViewGenerator.java
new file mode 100644
index 000000000..b9c440962
--- /dev/null
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/CouchDbViewGenerator.java
@@ -0,0 +1,76 @@
+/*
+ * 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.storage.couchdb.utils;
+
+import org.apache.http.client.fluent.Request;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import static org.apache.streampipes.storage.couchdb.constants.GenericCouchDbConstants.*;
+
+public class CouchDbViewGenerator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CouchDbViewGenerator.class);
+
+ public void createGenericDatabaseIfNotExists() {
+ LOG.info("Checking if generic database {} exists...", DB_NAME);
+
+ try {
+ int status = Request.Put(Utils.getDatabaseRoute(DB_NAME)).execute().returnResponse().getStatusLine().getStatusCode();
+
+ if (status == 201) {
+ LOG.info("Database {} successfully created", DB_NAME);
+ createViews();
+ } else if (status == 412) {
+ LOG.info("Database {} already present", DB_NAME);
+ } else {
+ LOG.warn("Status code {} from CouchDB - something went wrong during install!", status);
+ }
+ } catch (IOException e) {
+ LOG.error("Could not connect to CouchDB storage", e);
+ }
+ }
+
+ private void createViews() throws IOException {
+ LOG.info("Initializing database views...");
+
+ String viewContent = "{\n" +
+ "\"views\": {\n" +
+ "\"appDocType\": {\n" +
+ "\"map\": \"function (doc) {\\nif (doc._id) {\\nemit([doc.appDocType, doc._id], 1)\\n}\\n}\"\n" +
+ "}\n" +
+ "},\n" +
+ "\"language\": \"javascript\"\n" +
+ "}";
+
+ int status = Utils.putRequest(Utils.getDatabaseRoute(DB_NAME) + "/_design/" + DESIGN_DOC_NAME, viewContent)
+ .execute()
+ .returnResponse()
+ .getStatusLine()
+ .getStatusCode();
+
+ if (status == 201) {
+ LOG.info("View {} successfully created", VIEW_NAME);
+ } else {
+ LOG.warn("Status code {} from CouchDB - something went wrong during view generation!", status);
+ }
+ }
+}
diff --git a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/Utils.java b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/Utils.java
index 34a989ac6..d12e6e48c 100644
--- a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/Utils.java
+++ b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/utils/Utils.java
@@ -18,6 +18,8 @@
package org.apache.streampipes.storage.couchdb.utils;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.entity.ContentType;
import org.apache.streampipes.storage.couchdb.serializer.GsonSerializer;
import org.lightcouch.CouchDbClient;
import org.lightcouch.CouchDbProperties;
@@ -180,12 +182,53 @@ public class Utils {
return new CouchDbClient(props(dbname));
}
- public static CouchDbClient getCoucbDbClient(String table) {
- return new CouchDbClient(props(table));
+ public static CouchDbClient getCouchDbClient(String database) {
+ return new CouchDbClient(props(database));
}
private static CouchDbProperties props(String dbname) {
- return new CouchDbProperties(dbname, true, CouchDbConfig.INSTANCE.getProtocol(),
- CouchDbConfig.INSTANCE.getHost(), CouchDbConfig.INSTANCE.getPort(), null, null);
+ return new CouchDbProperties(
+ dbname,
+ true,
+ CouchDbConfig.INSTANCE.getProtocol(),
+ CouchDbConfig.INSTANCE.getHost(),
+ CouchDbConfig.INSTANCE.getPort(),
+ null,
+ null);
+ }
+
+ public static String getDatabaseRoute(String databaseName) {
+ return toUrl() + "/" + databaseName;
+ }
+
+ private static String toUrl() {
+ return CouchDbConfig.INSTANCE.getProtocol()
+ + "://" + CouchDbConfig.INSTANCE.getHost()
+ + ":" + CouchDbConfig.INSTANCE.getPort();
+ }
+
+ public static Request getRequest(String route) {
+ return append(Request.Get(route));
+ }
+
+ public static Request postRequest(String route,
+ String payload) {
+ return append(Request.Post(route).bodyString(payload, ContentType.APPLICATION_JSON));
+ }
+
+ public static Request deleteRequest(String route) {
+ return append(Request.Delete(route));
+ }
+
+ public static Request putRequest(String route,
+ String payload) {
+ return append(Request.Put(route).bodyString(payload, ContentType.APPLICATION_JSON));
+ }
+
+ private static Request append(Request req) {
+ req.connectTimeout(1000)
+ .socketTimeout(100000);
+
+ return req;
}
}
diff --git a/ui/projects/streampipes/platform-services/src/lib/apis/asset-management.service.ts b/ui/projects/streampipes/platform-services/src/lib/apis/asset-management.service.ts
new file mode 100644
index 000000000..5cf4ce2a2
--- /dev/null
+++ b/ui/projects/streampipes/platform-services/src/lib/apis/asset-management.service.ts
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ *
+ */
+
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { PlatformServicesCommons } from './commons.service';
+import { Observable } from 'rxjs';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AssetManagementService {
+
+ constructor(private http: HttpClient,
+ private platformServicesCommons: PlatformServicesCommons) {
+ }
+
+ createAsset(asset: any): Observable<any> {
+ return this.http.post(this.assetBasePath, asset);
+ }
+
+ getAllAssets(): Observable<any> {
+ return this.http.get(this.assetBasePath);
+ }
+
+ getAsset(assetId: string): Observable<any> {
+ return this.http.get(`${this.assetBasePath}/${assetId}`);
+ }
+
+ updateAsset(asset: any): Observable<any> {
+ return this.http.put(`${this.assetBasePath}/${asset._id}`, asset);
+ }
+
+ deleteAsset(assetId: string, rev: string): Observable<any> {
+ return this.http.delete(`${this.assetBasePath}/${assetId}/${rev}`);
+ }
+
+ private get assetBasePath() {
+ return this.platformServicesCommons.apiBasePath + '/assets';
+ }
+
+}
diff --git a/ui/projects/streampipes/platform-services/src/lib/model/assets/asset.model.ts b/ui/projects/streampipes/platform-services/src/lib/model/assets/asset.model.ts
new file mode 100644
index 000000000..3f006a246
--- /dev/null
+++ b/ui/projects/streampipes/platform-services/src/lib/model/assets/asset.model.ts
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ *
+ */
+
+export interface StorageItem {
+ _id: string;
+ _rev: string;
+}
+
+export interface AssetLink {
+ linkId: string;
+ linkPaths: string[];
+ linkType: string;
+ linkLabel: string;
+}
+
+export interface AssetType {
+ assetIcon: string;
+ assetIconColor: string;
+ assetTypeCategory: string;
+ assetTypeLabel: string;
+}
+
+export interface SimpleAsset extends StorageItem {
+ assetId: string;
+ assetType: AssetType;
+ assetName: string;
+ assetDescription: string;
+ links: AssetLink[];
+ assets: SimpleAsset[];
+}
diff --git a/ui/projects/streampipes/platform-services/src/public-api.ts b/ui/projects/streampipes/platform-services/src/public-api.ts
index bfa046db6..6a459cf49 100644
--- a/ui/projects/streampipes/platform-services/src/public-api.ts
+++ b/ui/projects/streampipes/platform-services/src/public-api.ts
@@ -24,6 +24,7 @@
export * from './lib/platform-services.module';
export * from './lib/apis/commons.service';
+export * from './lib/apis/asset-management.service';
export * from './lib/apis/data-view-data-explorer.service';
export * from './lib/apis/datalake-rest.service';
export * from './lib/apis/dashboard.service';
@@ -57,3 +58,5 @@ export * from './lib/model/datalake/data-lake-query-config.model';
export * from './lib/query/DatalakeQueryParameterBuilder';
export * from './lib/query/data-view-query-generator.service';
export * from './lib/model/user/user.model';
+
+export * from './lib/model/assets/asset.model';