diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/job/GisLayerJobUtil.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/job/GisLayerJobUtil.java index d2a57a3..ec41e6b 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/job/GisLayerJobUtil.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/job/GisLayerJobUtil.java @@ -57,7 +57,7 @@ public class GisLayerJobUtil { String jobId = taxonomyService.generateGisLayerFromOccurrenceKeys(occurrenceKeys,layerTitle,layerDescr,author,credits); logger.info("generated gis layer jobID: "+jobId); Date submitTime = DateUtil.getDateFormat(Calendar.getInstance()); - GisLayerJob gisLJ = new GisLayerJob(jobId, layerTitle, 0, submitTime.getTime(), 0, 0, layerDescr, DownloadState.PENDING.toString(), null, totalPoints); + GisLayerJob gisLJ = new GisLayerJob(jobId, layerTitle, 0, submitTime.getTime(), 0, 0, layerDescr, DownloadState.PENDING.toString(), null, totalPoints, 0); gisLayerJob.insert(gisLJ); JobGisLayerModel jobModel = new JobGisLayerModel(jobId, layerTitle, DownloadState.PENDING,null, submitTime, null, null, layerDescr, 0, totalPoints, null, null); logger.info("Returning job: "+jobModel); @@ -111,14 +111,19 @@ public class GisLayerJobUtil { } //TODO - int completedEntry = 0; - if(statusResponse.getCompletedEntries()>0) - completedEntry = statusResponse.getCompletedEntries(); + int completedEntries = 0; + boolean completedEntriesChanged = false; + if(statusResponse.getCompletedEntries()>0){ + completedEntries = statusResponse.getCompletedEntries(); + job.setCompletedEntries(completedEntries); + completedEntriesChanged = true; + } - jobGisModel = new JobGisLayerModel(job.getId(), job.getName(), downloadState, completedEntry, job.getTotalPoints()); + jobGisModel = new JobGisLayerModel(job.getId(), job.getName(), downloadState, completedEntries, job.getTotalPoints()); jobGisModel.setSubmitTime(submit); jobGisModel.setLayerUUID(job.getLayerUUID()); jobGisModel.setGisViewerAppLink(job.getGisViewerAppLink()); + jobGisModel.setCompletedPoints(completedEntries); try{ boolean changeEndTime = false; @@ -156,7 +161,7 @@ public class GisLayerJobUtil { } //UPDATE DAO - if(changeStatus || changeEndTime || changeStartTime || filledAppLink){ + if(completedEntriesChanged || changeStatus || changeEndTime || changeStartTime || filledAppLink){ job.setState(downloadState.toString()); gisLayerJobP.update(job); } diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/service/SpeciesService.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/service/SpeciesService.java index 33943e2..cf3f9b9 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/service/SpeciesService.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/service/SpeciesService.java @@ -433,7 +433,10 @@ public class SpeciesService { try { logger.trace("Calling occurrencesCall passing keys: "+keys); - logger.trace("occurrencesCall != null? "+(occurrencesCall==null)); + if(occurrencesCall==null){ + logger.warn("occurrencesCall is null, instancing again..."); + this.occurrencesCall = occurrences().withTimeout(3, TimeUnit.MINUTES).build(); + } Stream stream = occurrencesCall.getByKeys(keys); return new StreamIterator(stream); } diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/GisLayerJob.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/GisLayerJob.java index 238eef1..a3c5bac 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/GisLayerJob.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/GisLayerJob.java @@ -25,18 +25,21 @@ public class GisLayerJob extends DefaultJob{ private long totalPoints; private String layerUUID; private String gisViewerAppLink; + private long completedEntries; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected int internalId; + /** * Instantiates a new gis layer job. */ public GisLayerJob() { } + /** * Instantiates a new gis layer job. * @@ -45,16 +48,45 @@ public class GisLayerJob extends DefaultJob{ * @param startTime the start time * @param submitTime the submit time * @param endTime the end time + * @param elapsedTime the elapsed time * @param description the description * @param state the state + * @param gisViewerAppLink the gis viewer app link + * @param totalPoints the total points + * @param completedEntries the completed entries */ - public GisLayerJob(String id, String name, long startTime, long submitTime, long endTime,long elapsedTime, String description, String state, String gisViewerAppLink, long totalPoints) { + public GisLayerJob(String id, String name, long startTime, long submitTime, long endTime,long elapsedTime, String description, String state, String gisViewerAppLink, long totalPoints, long completedEntries) { super(id, name, startTime, submitTime, endTime, description, state, elapsedTime); this.totalPoints = totalPoints; this.gisViewerAppLink = gisViewerAppLink; + this.completedEntries = completedEntries; + } + + + /** + * Gets the completed entries. + * + * @return the completedEntries + */ + public long getCompletedEntries() { + + return completedEntries; + } + + + /** + * Sets the completed entries. + * + * @param completedEntries the completedEntries to set + */ + public void setCompletedEntries(long completedEntries) { + + this.completedEntries = completedEntries; } /** + * Gets the total points. + * * @return the totalPoints */ public long getTotalPoints() { @@ -63,6 +95,8 @@ public class GisLayerJob extends DefaultJob{ } /** + * Gets the layer uuid. + * * @return the layerUUID */ public String getLayerUUID() { @@ -72,6 +106,8 @@ public class GisLayerJob extends DefaultJob{ /** + * Sets the layer uuid. + * * @param layerUUID the layerUUID to set */ public void setLayerUUID(String layerUUID) { @@ -80,6 +116,8 @@ public class GisLayerJob extends DefaultJob{ } /** + * Sets the total points. + * * @param totalPoints the totalPoints to set */ public void setTotalPoints(long totalPoints) { @@ -88,6 +126,8 @@ public class GisLayerJob extends DefaultJob{ } /** + * Gets the gis viewer app link. + * * @return the gisViewerAppLink */ public String getGisViewerAppLink() { @@ -97,6 +137,8 @@ public class GisLayerJob extends DefaultJob{ /** + * Sets the gis viewer app link. + * * @param gisViewerAppLink the gisViewerAppLink to set */ public void setGisViewerAppLink(String gisViewerAppLink) { @@ -105,6 +147,8 @@ public class GisLayerJob extends DefaultJob{ } /** + * Gets the internal id. + * * @return the internalId */ public int getInternalId() { @@ -125,6 +169,8 @@ public class GisLayerJob extends DefaultJob{ builder.append(layerUUID); builder.append(", gisViewerAppLink="); builder.append(gisViewerAppLink); + builder.append(", completedEntries="); + builder.append(completedEntries); builder.append(", internalId="); builder.append(internalId); builder.append(", id="); @@ -146,5 +192,4 @@ public class GisLayerJob extends DefaultJob{ builder.append("]"); return builder.toString(); } - } diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobGisLayerModel.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobGisLayerModel.java index fa8b0ee..a4880d4 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobGisLayerModel.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobGisLayerModel.java @@ -113,10 +113,16 @@ public class JobGisLayerModel implements Serializable, IsSerializable{ this.completedPoints = completedPoints; this.gisViewerAppLink = gisViewerAppLink; this.layerUUID = layerUUID; - this.percentage = completedPoints!=0?completedPoints*100/totalPoints:0; + updatePercentage(); } + /** + * Update percentage. + */ + private void updatePercentage(){ + this.percentage = completedPoints!=0 && totalPoints!=0?completedPoints*100/totalPoints:0; + } /** * Gets the job identifier. @@ -369,19 +375,6 @@ public class JobGisLayerModel implements Serializable, IsSerializable{ } - - /** - * Sets the percentage. - * - * @param percentage the percentage to set - */ - public void setPercentage(float percentage) { - - this.percentage = percentage; - } - - - /** * Sets the total points. * @@ -402,6 +395,7 @@ public class JobGisLayerModel implements Serializable, IsSerializable{ public void setCompletedPoints(long completedPoints) { this.completedPoints = completedPoints; + updatePercentage(); } diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobOccurrencesModel.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobOccurrencesModel.java index 7c7ebdf..122e451 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobOccurrencesModel.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/JobOccurrencesModel.java @@ -13,10 +13,10 @@ public class JobOccurrencesModel implements Serializable{ /** - * + * */ private static final long serialVersionUID = 1L; - + public static final String JOBINDENTIFIER = "jobIdentifier"; public static final String JOBNAME = "Name"; public static final String STARTTIME = "Start Time"; @@ -34,7 +34,7 @@ public class JobOccurrencesModel implements Serializable{ public static final String BYDATASOURCE = "byDataSource"; public static final String COMPLETEDENTRY = "Completed Entry"; public static final String ITEMSNUMBER = "Number of items"; - + private String scientificName; private String jobIdentifier; private String jobName; @@ -47,19 +47,19 @@ public class JobOccurrencesModel implements Serializable{ private String description; private float percentage; private int nodeCompleted; - + private int totalOccurrences; - + private SaveFileFormat fileFormat; private OccurrencesSaveEnum csvType; - + private boolean byDataSource; public JobOccurrencesModel(){ } /** - * + * * @param jobIdentifier * @param currentJobName */ @@ -71,7 +71,7 @@ public class JobOccurrencesModel implements Serializable{ public void setJobName(String jobName) { this.jobName = jobName; - + } @@ -98,10 +98,10 @@ public class JobOccurrencesModel implements Serializable{ setDescription(description); setNodeCompleted(nodeCompleted); setTotalOccurrences(totalOccurrence); - + setPercentage(nodeCompleted*100/totalOccurrence); } - + /** * USED FROM CREATE JOB ON CLIENT * @param jobIdentifier @@ -121,7 +121,7 @@ public class JobOccurrencesModel implements Serializable{ setByDataSource(byDataSource); setTotalOccurrences(totalOccurrence); } - + //By datasource public JobOccurrencesModel(String jobIdentifier, String jobName2, String scientificName2, List dataSourceList, @@ -137,7 +137,7 @@ public class JobOccurrencesModel implements Serializable{ public void setScientificName(String scientificName) { this.scientificName = scientificName; - + } public void setId(String jobId){ @@ -147,7 +147,7 @@ public class JobOccurrencesModel implements Serializable{ public void setDescription(String description) { this.description = description; } - + public String getDescription() { return description; } @@ -155,54 +155,54 @@ public class JobOccurrencesModel implements Serializable{ public String getJobIdentifier(){ return jobIdentifier; } - + public String getJobName(){ return jobName; } - + public String getScientificName(){ return scientificName; } - + public void setDataSources(List dataSources){ this.dataSources = dataSources; } - + public List getDataSources(){ return this.dataSources; } - + public Date getSubmitTime(){ return submitTime; } - + public void setSubmitTime(Date startTime){ this.submitTime = startTime; } - + public void setEndTime(Date endTime){ this.endTime = endTime; } - + public Date getEndTime(){ return endTime; } - + public void setPercentage(float percentage){ this.percentage = percentage; } public float getPercentage(){ return percentage; } - + public void setState(DownloadState state){ this.downloadState = state; } - + public DownloadState getDownloadState(){ return downloadState; } - + public String getElapsedTime() { return elapsedTime; } @@ -210,7 +210,7 @@ public class JobOccurrencesModel implements Serializable{ public void setElapsedTime(String elapsedTime) { this.elapsedTime = elapsedTime; } - + public SaveFileFormat getFileFormat() { return fileFormat; } @@ -234,7 +234,7 @@ public class JobOccurrencesModel implements Serializable{ public void setByDataSource(boolean byDataSource) { this.byDataSource = byDataSource; } - + public int getNodeCompleted() { return nodeCompleted; } @@ -242,15 +242,15 @@ public class JobOccurrencesModel implements Serializable{ public void setNodeCompleted(int nodeCompleted) { this.nodeCompleted = nodeCompleted; } - + public List getDataSourcesNameAsString(){ List listDataSourceName = new ArrayList(); - + if(dataSources!=null){ - for (DataSource dataSource : dataSources) + for (DataSource dataSource : dataSources) listDataSourceName.add(dataSource.getName()); } - + return listDataSourceName; } @@ -309,5 +309,5 @@ public class JobOccurrencesModel implements Serializable{ builder.append("]"); return builder.toString(); } - + }