tenthe commented on code in PR #3770:
URL: https://github.com/apache/streampipes/pull/3770#discussion_r2335741267


##########
streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java:
##########
@@ -139,6 +139,9 @@ public enum Envs {
   SP_PLC4X_CONN_MAX_WAIT_TIME_MS("SP_PLC4X_CONN_MAX_WAIT_TIME_MS", "20000"),
   SP_PLC4X_CONN_MAX_LEASE_TIME_MS("SP_PLC4X_CONN_MAX_LEASE_TIME_MS", "4000"),
 
+  // Retention Local File 
+  SP_RETENTION_LOCAL_DIR("SP_RETENTION_LOCAL_DIR", "./output"),

Review Comment:
   Maybe we can choose a more expressive name for the output directory, e.g. 
ArchivedData, ArchivedMeasurements, ...
   What do you think?



##########
streampipes-data-explorer-export/src/main/java/org/apache/streampipes/dataexplorer/export/ObjectStorge/ExportProviderFactory.java:
##########
@@ -0,0 +1,44 @@
+/**
+ * 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.dataexplorer.export.ObjectStorge;
+
+import org.apache.streampipes.model.datalake.ExportProviderSettings;
+
+import 
org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
+
+public class ExportProviderFactory {
+    public static IObjectStorage createExportProvider(String providerType, 
String measurementName, StreamingResponseBody streamingOutput, 
ExportProviderSettings settings, String format) throws Exception {
+        switch (providerType) {
+            case "local":
+                return new LocalFolder(streamingOutput, measurementName, 
format);
+
+            //case "s3":

Review Comment:
   For now, only make a comment that further providers can be added here



##########
ui/src/app/configuration/dialog/data-retention-dialog/components/select-retention/select-data.component.ts:
##########
@@ -18,7 +18,8 @@
 
 import { Component, Input } from '@angular/core';
 
-import { DataRetentionConfig } from '../../model/data-retention-config.model';
+//import { DataRetentionConfig } from 
'../../model/data-retention-config.model';

Review Comment:
   ```suggestion
   
   ```



##########
ui/projects/streampipes/platform-services/src/lib/apis/datalake-rest.service.ts:
##########
@@ -155,21 +156,18 @@ export class DatalakeRestService {
     }
 
     cleanup(index: string, config: any) {
-        console.log('cleanup');
-        console.log(config);
-
         const url = `${this.dataLakeUrl}/${index}/cleanup`;
 
         const request = new HttpRequest('POST', url, config, {
             headers: new HttpHeaders({ 'Content-Type': 'application/json' }), 
// optional if already handled globally
         });
 
-        console.log(request);
-
         return this.http.request(request);
     }
 
     buildDownloadRequest(index: string, queryParams: any) {
+        console.log('Query Params');

Review Comment:
   ```suggestion
   
   ```



##########
streampipes-service-core/src/main/java/org/apache/streampipes/service/core/scheduler/DataLakeScheduler.java:
##########
@@ -45,31 +54,81 @@ public class DataLakeScheduler {
             .getDataExplorerManager()
             .getQueryManagement(this.dataExplorerSchemaManagement);
 
-    public void exportMeasurements() {
+    public void exportMeasurements(DataLakeMeasure m, Instant now, long 
endDate) {
         // Method body is empty; add functionality as needed
+        //Prepare Data for export 
+
+        if (System.getenv("SP_RETENTION_LOCAL_DIR") == null || 
System.getenv("SP_RETENTION_LOCAL_DIR").isEmpty()) {
+        LOG.error("For Local Retention Storage, please configure the 
environment variable SP_RETENTION_LOCAL_DIR");
     }
 
-    public void deleteMeasurements(DataLakeMeasure m) {
-        Instant now = Instant.now();
-        Instant daysAgo = 
now.minus(m.getRetentionTime().dataRetentionConfig().olderThanDays(), 
ChronoUnit.DAYS);
+        var outputFormat = 
OutputFormat.fromString(m.getRetentionTime().exportConfig().exportConfig().format());
+        Map<String, String> params = new HashMap<>();
+        
+        params.put("delimiter", 
m.getRetentionTime().exportConfig().exportConfig().csvDelimiter());
+        params.put("format", 
m.getRetentionTime().exportConfig().exportConfig().format());
+        params.put("headerColumnName", 
m.getRetentionTime().exportConfig().exportConfig().headerColumnName());
+        params.put("missingValueBehaviour", 
m.getRetentionTime().exportConfig().exportConfig().missingValueBehaviour());
+        params.put("endDate",  Long.toString(endDate));
+
+        ProvidedRestQueryParams sanitizedParams = new 
ProvidedRestQueryParams(m.getMeasureName(), 
params);//populate(m.getMeasureName(), params);
+        
+        StreamingResponseBody streamingOutput = output -> 
dataExplorerQueryManagement.getDataAsStream(
+                sanitizedParams,
+                outputFormat,
+                
"ignore".equals(m.getRetentionTime().exportConfig().exportConfig().missingValueBehaviour()),
+                output
+         );
+         try {
+            ExportProviderSettings exportProviderSettings = 
m.getRetentionTime().exportConfig().exportProviderSettings();
+
+            String providerType =  exportProviderSettings.providerType();
 
-        long endDate = daysAgo.toEpochMilli();
+            LOG.info("Write to " + System.getenv("SP_RETENTION_LOCAL_DIR"));
+
+        
+            IObjectStorage exportProvider = 
ExportProviderFactory.createExportProvider(
+                providerType, m.getMeasureName(), streamingOutput, 
exportProviderSettings, 
m.getRetentionTime().exportConfig().exportConfig().format());
+            exportProvider.store();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void deleteMeasurements(DataLakeMeasure m, Instant now, long 
endDate) {
+       
+     
         LOG.info("Current time in millis: " + now.toEpochMilli());
         LOG.info("Current time in millis to delete: " + endDate);
 
         this.dataExplorerQueryManagement.deleteData(m.getMeasureName(), null, 
endDate);
     }
 
-    @Scheduled(cron = "0 1 0 * * 6") // CronJob Scheduled every Saturday (5) 
00:01
+    @Scheduled(cron = "0 1 0 * * 6")//@Scheduled(cron = "0 */2 * * * 
*")//@Scheduled(cron = "0 1 0 * * 6") // CronJob Scheduled every Saturday (5) 
00:01

Review Comment:
   ```suggestion
       @Scheduled(cron = "0 1 0 * * 6") // CronJob Scheduled every Saturday (5) 
00:01
   ```



##########
ui/projects/streampipes/platform-services/src/lib/apis/datalake-rest.service.ts:
##########
@@ -140,6 +140,7 @@ export class DatalakeRestService {
                       ...formatConfig,
                       missingValueBehaviour,
                   };
+        console.log(queryParams);

Review Comment:
   ```suggestion
      
   ```



##########
ui/projects/streampipes/platform-services/src/lib/apis/datalake-rest.service.ts:
##########
@@ -155,21 +156,18 @@ export class DatalakeRestService {
     }
 
     cleanup(index: string, config: any) {
-        console.log('cleanup');
-        console.log(config);
-
         const url = `${this.dataLakeUrl}/${index}/cleanup`;
 
         const request = new HttpRequest('POST', url, config, {
             headers: new HttpHeaders({ 'Content-Type': 'application/json' }), 
// optional if already handled globally
         });
 
-        console.log(request);
-
         return this.http.request(request);
     }
 
     buildDownloadRequest(index: string, queryParams: any) {
+        console.log('Query Params');
+        console.log(queryParams);

Review Comment:
   ```suggestion
   ```



##########
ui/projects/streampipes/shared-ui/src/lib/dialog/data-download-dialog/services/data-export.service.ts:
##########
@@ -79,6 +79,8 @@ export class DataExportService {
                 startTime,
                 endTime,
             );
+            console.log('Download Request');
+            console.log(downloadRequest);

Review Comment:
   ```suggestion
   ```



##########
output.csv:
##########


Review Comment:
   Is this a test file and can therefore be deleted?



##########
ui/src/app/configuration/dialog/data-retention-dialog/components/select-export/select-format.component.ts:
##########
@@ -16,41 +16,17 @@
  *
  */
 
-import { Component, inject, Input, OnInit } from '@angular/core';
-import { FormatExportConfig } from '../../model/format-export-config.model';
-import { FileMetadata, FilesService } from '@streampipes/platform-services';
-import { CurrentUserService } from '../../../../services/current-user.service';
+import { Component, Input, OnInit } from '@angular/core';
+import { DataExplorerDataConfig } from '@streampipes/platform-services';
+import { RetentionTimeConfig } from '@streampipes/platform-services';
 
 @Component({
-    selector: 'sp-select-format',
+    selector: 'sp-data-export',
     templateUrl: './select-format.component.html',
-    styleUrls: [
-        './select-format.component.scss',
-        '../../data-download-dialog.component.scss',
-    ],
+    styleUrls: ['./select-format.component.scss'],
     standalone: false,
 })
-export class SelectFormatComponent implements OnInit {
-    @Input() formatExportConfig: FormatExportConfig;
-
-    hasReadFilePrivilege = false;
-    excelTemplates: FileMetadata[] = [];
-
-    private fileService = inject(FilesService);
-    private currentUserService = inject(CurrentUserService);
-
-    constructor() {}
-
-    ngOnInit() {
-        this.hasReadFilePrivilege = this.currentUserService.hasRole(
-            'PRIVILEGE_READ_FILES',
-        );
-        if (this.hasReadFilePrivilege) {
-            this.fileService
-                .getFileMetadata(['xlsx'])
-                .subscribe(excelTemplates => {
-                    this.excelTemplates = excelTemplates;
-                });
-        }
-    }
+export class SelectDataExportComponent {
+    @Input() dataExplorerDataConfig: DataExplorerDataConfig;
+    @Input() dataRetentionConfig: RetentionTimeConfig;

Review Comment:
   ```suggestion
       @Input() 
       dataExplorerDataConfig: DataExplorerDataConfig;
       @Input() 
       dataRetentionConfig: RetentionTimeConfig;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to