From 3b8c25af33cadb4115fdc5d73ac2cca73bd72f66 Mon Sep 17 00:00:00 2001 From: kraftek Date: Wed, 30 Oct 2019 15:36:14 +0200 Subject: [PATCH] Changes from Wed 10/30/2019 15:36:14.36 --- .../sen2agri/commons/DownloadProgress.java | 70 +++++++++++++++++++ .../sen2agri/services/DownloadService.java | 4 +- .../internal/DownloadServiceImpl.java | 22 +++--- .../esa/sen2agri/web/DownloadController.java | 10 +-- 4 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/commons/DownloadProgress.java diff --git a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/commons/DownloadProgress.java b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/commons/DownloadProgress.java new file mode 100644 index 00000000..7d8bc708 --- /dev/null +++ b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/commons/DownloadProgress.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2018 CS ROMANIA + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see http://www.gnu.org/licenses/ + */ +package org.esa.sen2agri.commons; + +import org.esa.sen2agri.entities.Site; +import org.esa.sen2agri.entities.enums.Satellite; +import ro.cs.tao.datasource.DataSourceTopic; +import ro.cs.tao.messaging.TaskProgress; + +import java.util.Objects; + +/** + * @author Cosmin Cara + */ +public class DownloadProgress extends TaskProgress { + private String siteName; + private int siteId; + private String satelliteName; + + public DownloadProgress(String name) { + super(name, DataSourceTopic.PRODUCT_PROGRESS.getTag()); + } + + public DownloadProgress(String name, Site site, Satellite satellite, double progress) { + this(name); + if (site != null) { + this.siteName = site.getName(); + this.siteId = site.getId(); + } + if (satellite != null) { + this.satelliteName = satellite.name(); + } + this.progress = progress; + } + + public String getSiteName() { return siteName; } + + public int getSiteId() { return siteId; } + + public String getSatelliteName() { return satelliteName; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + DownloadProgress that = (DownloadProgress) o; + return siteId == that.siteId && + siteName.equals(that.siteName) && + satelliteName.equals(that.satelliteName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), siteName, siteId, satelliteName); + } +} diff --git a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/DownloadService.java b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/DownloadService.java index ba792b4e..482d9c38 100644 --- a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/DownloadService.java +++ b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/DownloadService.java @@ -15,7 +15,7 @@ */ package org.esa.sen2agri.services; -import org.esa.sen2agri.commons.TaskProgress; +import org.esa.sen2agri.commons.DownloadProgress; import org.esa.sen2agri.entities.DataSourceConfiguration; import org.esa.sen2agri.web.beans.Query; import ro.cs.tao.datasource.ProductStatusListener; @@ -64,7 +64,7 @@ List download(short siteId, List products, Set til * If the siteId parameter value is 0, it returns information about all the downloads in progress. * @param siteId The site identifier */ - List getDownloadsInProgress(short siteId); + List getDownloadsInProgress(short siteId); /** * Stops the downloads and marks the downloader disabled for the specific site. * If the siteId parameter value is 0, it stops all the downloads and marks the downloader as diff --git a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/internal/DownloadServiceImpl.java b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/internal/DownloadServiceImpl.java index a2a792c4..6bde72c1 100644 --- a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/internal/DownloadServiceImpl.java +++ b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/services/internal/DownloadServiceImpl.java @@ -56,7 +56,7 @@ @Service("downloadService") public class DownloadServiceImpl extends Notifiable implements DownloadService { - private static final Map downloadsInProgress = Collections.synchronizedMap(new LinkedHashMap<>()); + private static final Map downloadsInProgress = Collections.synchronizedMap(new LinkedHashMap<>()); //private static final Map> infoCache = Collections.synchronizedMap(new HashMap<>()); private static final Map estimatedProductCount = Collections.synchronizedMap(new HashMap<>()); private final Map, List> querySiteDataSources; @@ -275,8 +275,8 @@ public List download(short siteId, List products, Set getDownloadsInProgress(short siteId) { - List tasks = new ArrayList<>(); + public List getDownloadsInProgress(short siteId) { + List tasks = new ArrayList<>(); if (siteId > 0) { dwnSiteDataSources.entrySet().stream() .filter(e -> siteId == e.getKey().getKeyOne()) @@ -485,7 +485,7 @@ protected void onMessageReceived(Message data) { satellite = productInfo.getKeyTwo(); } downloadsInProgress.put(taskName, - new TaskProgress(taskName, site, satellite, 0)); + new DownloadProgress(taskName, site, satellite, 0)); } else if (data instanceof ActivityEndMessage) { downloadsInProgress.remove(((ActivityEndMessage) data).getTaskName()); } else if (data instanceof SubActivityStartMessage) { @@ -497,19 +497,19 @@ protected void onMessageReceived(Message data) { satellite = productInfo.getKeyTwo(); } downloadsInProgress.put(taskName, - new TaskProgress(taskName, site, satellite, mainProgress)); + new DownloadProgress(taskName, site, satellite, mainProgress)); } } else if (data instanceof SubActivityEndMessage) { final String mainTask = ((SubActivityEndMessage) data).getTaskName(); - final TaskProgress taskProgress = downloadsInProgress.get(mainTask); - if (taskProgress != null) { - double mainProgress = taskProgress.getProgress(); + final DownloadProgress downloadProgress = downloadsInProgress.get(mainTask); + if (downloadProgress != null) { + double mainProgress = downloadProgress.getProgress(); if ((productInfo = getProductInfo(mainTask)) != null) { site = productInfo.getKeyOne(); satellite = productInfo.getKeyTwo(); } downloadsInProgress.put(mainTask, - new TaskProgress(mainTask, site, satellite, mainProgress)); + new DownloadProgress(mainTask, site, satellite, mainProgress)); } } else if (data instanceof SubActivityProgressMessage) { SubActivityProgressMessage casted = (SubActivityProgressMessage) data; @@ -518,7 +518,7 @@ protected void onMessageReceived(Message data) { site = productInfo.getKeyOne(); satellite = productInfo.getKeyTwo(); } - downloadsInProgress.put(mainTask, new TaskProgress(mainTask, site, satellite, casted.getTaskProgress())); + downloadsInProgress.put(mainTask, new DownloadProgress(mainTask, site, satellite, casted.getTaskProgress())); } else if (data instanceof ActivityProgressMessage) { ActivityProgressMessage casted = (ActivityProgressMessage) data; final String mainTask = casted.getTaskName(); @@ -526,7 +526,7 @@ protected void onMessageReceived(Message data) { site = productInfo.getKeyOne(); satellite = productInfo.getKeyTwo(); } - downloadsInProgress.put(mainTask, new TaskProgress(mainTask, site, satellite, casted.getProgress())); + downloadsInProgress.put(mainTask, new DownloadProgress(mainTask, site, satellite, casted.getProgress())); } } diff --git a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/web/DownloadController.java b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/web/DownloadController.java index 8eec21f0..bbec9b04 100644 --- a/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/web/DownloadController.java +++ b/sen2agri-services/sen2agri-services-core/src/main/java/org/esa/sen2agri/web/DownloadController.java @@ -15,7 +15,7 @@ */ package org.esa.sen2agri.web; -import org.esa.sen2agri.commons.TaskProgress; +import org.esa.sen2agri.commons.DownloadProgress; import org.esa.sen2agri.entities.enums.Satellite; import org.esa.sen2agri.services.DownloadService; import org.esa.sen2agri.services.ScheduleManager; @@ -52,8 +52,8 @@ public class DownloadController extends ControllerBase { * Returns information about all the downloads in progress. */ @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity> getInProgress() { - List tasks = downloadService.getDownloadsInProgress((short) 0); + public ResponseEntity> getInProgress() { + List tasks = downloadService.getDownloadsInProgress((short) 0); if (tasks == null || tasks.isEmpty()) { return new ResponseEntity<>(HttpStatus.OK); } @@ -65,8 +65,8 @@ public ResponseEntity> getInProgress() { * @param siteId The site identifier */ @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity> getInProgress(@PathVariable("id") short siteId) { - List tasks = downloadService.getDownloadsInProgress(siteId); + public ResponseEntity> getInProgress(@PathVariable("id") short siteId) { + List tasks = downloadService.getDownloadsInProgress(siteId); if (tasks == null || tasks.isEmpty()) { return new ResponseEntity<>(HttpStatus.OK); }