fixed percentage during creation of Gis Layer

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@142713 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-17 15:57:00 +00:00
parent c70c4ac44a
commit e6b15618ff
5 changed files with 102 additions and 55 deletions

View File

@ -57,7 +57,7 @@ public class GisLayerJobUtil {
String jobId = taxonomyService.generateGisLayerFromOccurrenceKeys(occurrenceKeys,layerTitle,layerDescr,author,credits); String jobId = taxonomyService.generateGisLayerFromOccurrenceKeys(occurrenceKeys,layerTitle,layerDescr,author,credits);
logger.info("generated gis layer jobID: "+jobId); logger.info("generated gis layer jobID: "+jobId);
Date submitTime = DateUtil.getDateFormat(Calendar.getInstance()); 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); gisLayerJob.insert(gisLJ);
JobGisLayerModel jobModel = new JobGisLayerModel(jobId, layerTitle, DownloadState.PENDING,null, submitTime, null, null, layerDescr, 0, totalPoints, null, null); JobGisLayerModel jobModel = new JobGisLayerModel(jobId, layerTitle, DownloadState.PENDING,null, submitTime, null, null, layerDescr, 0, totalPoints, null, null);
logger.info("Returning job: "+jobModel); logger.info("Returning job: "+jobModel);
@ -111,14 +111,19 @@ public class GisLayerJobUtil {
} }
//TODO //TODO
int completedEntry = 0; int completedEntries = 0;
if(statusResponse.getCompletedEntries()>0) boolean completedEntriesChanged = false;
completedEntry = statusResponse.getCompletedEntries(); 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.setSubmitTime(submit);
jobGisModel.setLayerUUID(job.getLayerUUID()); jobGisModel.setLayerUUID(job.getLayerUUID());
jobGisModel.setGisViewerAppLink(job.getGisViewerAppLink()); jobGisModel.setGisViewerAppLink(job.getGisViewerAppLink());
jobGisModel.setCompletedPoints(completedEntries);
try{ try{
boolean changeEndTime = false; boolean changeEndTime = false;
@ -156,7 +161,7 @@ public class GisLayerJobUtil {
} }
//UPDATE DAO //UPDATE DAO
if(changeStatus || changeEndTime || changeStartTime || filledAppLink){ if(completedEntriesChanged || changeStatus || changeEndTime || changeStartTime || filledAppLink){
job.setState(downloadState.toString()); job.setState(downloadState.toString());
gisLayerJobP.update(job); gisLayerJobP.update(job);
} }

View File

@ -433,7 +433,10 @@ public class SpeciesService {
try { try {
logger.trace("Calling occurrencesCall passing keys: "+keys); 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<OccurrencePoint> stream = occurrencesCall.getByKeys(keys); Stream<OccurrencePoint> stream = occurrencesCall.getByKeys(keys);
return new StreamIterator<OccurrencePoint>(stream); return new StreamIterator<OccurrencePoint>(stream);
} }

View File

@ -25,18 +25,21 @@ public class GisLayerJob extends DefaultJob{
private long totalPoints; private long totalPoints;
private String layerUUID; private String layerUUID;
private String gisViewerAppLink; private String gisViewerAppLink;
private long completedEntries;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
protected int internalId; protected int internalId;
/** /**
* Instantiates a new gis layer job. * Instantiates a new gis layer job.
*/ */
public GisLayerJob() { public GisLayerJob() {
} }
/** /**
* Instantiates a new gis layer job. * Instantiates a new gis layer job.
* *
@ -45,16 +48,45 @@ public class GisLayerJob extends DefaultJob{
* @param startTime the start time * @param startTime the start time
* @param submitTime the submit time * @param submitTime the submit time
* @param endTime the end time * @param endTime the end time
* @param elapsedTime the elapsed time
* @param description the description * @param description the description
* @param state the state * @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); super(id, name, startTime, submitTime, endTime, description, state, elapsedTime);
this.totalPoints = totalPoints; this.totalPoints = totalPoints;
this.gisViewerAppLink = gisViewerAppLink; 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 * @return the totalPoints
*/ */
public long getTotalPoints() { public long getTotalPoints() {
@ -63,6 +95,8 @@ public class GisLayerJob extends DefaultJob{
} }
/** /**
* Gets the layer uuid.
*
* @return the layerUUID * @return the layerUUID
*/ */
public String getLayerUUID() { public String getLayerUUID() {
@ -72,6 +106,8 @@ public class GisLayerJob extends DefaultJob{
/** /**
* Sets the layer uuid.
*
* @param layerUUID the layerUUID to set * @param layerUUID the layerUUID to set
*/ */
public void setLayerUUID(String layerUUID) { public void setLayerUUID(String layerUUID) {
@ -80,6 +116,8 @@ public class GisLayerJob extends DefaultJob{
} }
/** /**
* Sets the total points.
*
* @param totalPoints the totalPoints to set * @param totalPoints the totalPoints to set
*/ */
public void setTotalPoints(long totalPoints) { public void setTotalPoints(long totalPoints) {
@ -88,6 +126,8 @@ public class GisLayerJob extends DefaultJob{
} }
/** /**
* Gets the gis viewer app link.
*
* @return the gisViewerAppLink * @return the gisViewerAppLink
*/ */
public String getGisViewerAppLink() { public String getGisViewerAppLink() {
@ -97,6 +137,8 @@ public class GisLayerJob extends DefaultJob{
/** /**
* Sets the gis viewer app link.
*
* @param gisViewerAppLink the gisViewerAppLink to set * @param gisViewerAppLink the gisViewerAppLink to set
*/ */
public void setGisViewerAppLink(String gisViewerAppLink) { public void setGisViewerAppLink(String gisViewerAppLink) {
@ -105,6 +147,8 @@ public class GisLayerJob extends DefaultJob{
} }
/** /**
* Gets the internal id.
*
* @return the internalId * @return the internalId
*/ */
public int getInternalId() { public int getInternalId() {
@ -125,6 +169,8 @@ public class GisLayerJob extends DefaultJob{
builder.append(layerUUID); builder.append(layerUUID);
builder.append(", gisViewerAppLink="); builder.append(", gisViewerAppLink=");
builder.append(gisViewerAppLink); builder.append(gisViewerAppLink);
builder.append(", completedEntries=");
builder.append(completedEntries);
builder.append(", internalId="); builder.append(", internalId=");
builder.append(internalId); builder.append(internalId);
builder.append(", id="); builder.append(", id=");
@ -146,5 +192,4 @@ public class GisLayerJob extends DefaultJob{
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -113,10 +113,16 @@ public class JobGisLayerModel implements Serializable, IsSerializable{
this.completedPoints = completedPoints; this.completedPoints = completedPoints;
this.gisViewerAppLink = gisViewerAppLink; this.gisViewerAppLink = gisViewerAppLink;
this.layerUUID = layerUUID; 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. * 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. * Sets the total points.
* *
@ -402,6 +395,7 @@ public class JobGisLayerModel implements Serializable, IsSerializable{
public void setCompletedPoints(long completedPoints) { public void setCompletedPoints(long completedPoints) {
this.completedPoints = completedPoints; this.completedPoints = completedPoints;
updatePercentage();
} }

View File

@ -13,10 +13,10 @@ public class JobOccurrencesModel implements Serializable{
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String JOBINDENTIFIER = "jobIdentifier"; public static final String JOBINDENTIFIER = "jobIdentifier";
public static final String JOBNAME = "Name"; public static final String JOBNAME = "Name";
public static final String STARTTIME = "Start Time"; 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 BYDATASOURCE = "byDataSource";
public static final String COMPLETEDENTRY = "Completed Entry"; public static final String COMPLETEDENTRY = "Completed Entry";
public static final String ITEMSNUMBER = "Number of items"; public static final String ITEMSNUMBER = "Number of items";
private String scientificName; private String scientificName;
private String jobIdentifier; private String jobIdentifier;
private String jobName; private String jobName;
@ -47,19 +47,19 @@ public class JobOccurrencesModel implements Serializable{
private String description; private String description;
private float percentage; private float percentage;
private int nodeCompleted; private int nodeCompleted;
private int totalOccurrences; private int totalOccurrences;
private SaveFileFormat fileFormat; private SaveFileFormat fileFormat;
private OccurrencesSaveEnum csvType; private OccurrencesSaveEnum csvType;
private boolean byDataSource; private boolean byDataSource;
public JobOccurrencesModel(){ public JobOccurrencesModel(){
} }
/** /**
* *
* @param jobIdentifier * @param jobIdentifier
* @param currentJobName * @param currentJobName
*/ */
@ -71,7 +71,7 @@ public class JobOccurrencesModel implements Serializable{
public void setJobName(String jobName) { public void setJobName(String jobName) {
this.jobName = jobName; this.jobName = jobName;
} }
@ -98,10 +98,10 @@ public class JobOccurrencesModel implements Serializable{
setDescription(description); setDescription(description);
setNodeCompleted(nodeCompleted); setNodeCompleted(nodeCompleted);
setTotalOccurrences(totalOccurrence); setTotalOccurrences(totalOccurrence);
setPercentage(nodeCompleted*100/totalOccurrence); setPercentage(nodeCompleted*100/totalOccurrence);
} }
/** /**
* USED FROM CREATE JOB ON CLIENT * USED FROM CREATE JOB ON CLIENT
* @param jobIdentifier * @param jobIdentifier
@ -121,7 +121,7 @@ public class JobOccurrencesModel implements Serializable{
setByDataSource(byDataSource); setByDataSource(byDataSource);
setTotalOccurrences(totalOccurrence); setTotalOccurrences(totalOccurrence);
} }
//By datasource //By datasource
public JobOccurrencesModel(String jobIdentifier, String jobName2, public JobOccurrencesModel(String jobIdentifier, String jobName2,
String scientificName2, List<DataSource> dataSourceList, String scientificName2, List<DataSource> dataSourceList,
@ -137,7 +137,7 @@ public class JobOccurrencesModel implements Serializable{
public void setScientificName(String scientificName) { public void setScientificName(String scientificName) {
this.scientificName = scientificName; this.scientificName = scientificName;
} }
public void setId(String jobId){ public void setId(String jobId){
@ -147,7 +147,7 @@ public class JobOccurrencesModel implements Serializable{
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
@ -155,54 +155,54 @@ public class JobOccurrencesModel implements Serializable{
public String getJobIdentifier(){ public String getJobIdentifier(){
return jobIdentifier; return jobIdentifier;
} }
public String getJobName(){ public String getJobName(){
return jobName; return jobName;
} }
public String getScientificName(){ public String getScientificName(){
return scientificName; return scientificName;
} }
public void setDataSources(List<DataSource> dataSources){ public void setDataSources(List<DataSource> dataSources){
this.dataSources = dataSources; this.dataSources = dataSources;
} }
public List<DataSource> getDataSources(){ public List<DataSource> getDataSources(){
return this.dataSources; return this.dataSources;
} }
public Date getSubmitTime(){ public Date getSubmitTime(){
return submitTime; return submitTime;
} }
public void setSubmitTime(Date startTime){ public void setSubmitTime(Date startTime){
this.submitTime = startTime; this.submitTime = startTime;
} }
public void setEndTime(Date endTime){ public void setEndTime(Date endTime){
this.endTime = endTime; this.endTime = endTime;
} }
public Date getEndTime(){ public Date getEndTime(){
return endTime; return endTime;
} }
public void setPercentage(float percentage){ public void setPercentage(float percentage){
this.percentage = percentage; this.percentage = percentage;
} }
public float getPercentage(){ public float getPercentage(){
return percentage; return percentage;
} }
public void setState(DownloadState state){ public void setState(DownloadState state){
this.downloadState = state; this.downloadState = state;
} }
public DownloadState getDownloadState(){ public DownloadState getDownloadState(){
return downloadState; return downloadState;
} }
public String getElapsedTime() { public String getElapsedTime() {
return elapsedTime; return elapsedTime;
} }
@ -210,7 +210,7 @@ public class JobOccurrencesModel implements Serializable{
public void setElapsedTime(String elapsedTime) { public void setElapsedTime(String elapsedTime) {
this.elapsedTime = elapsedTime; this.elapsedTime = elapsedTime;
} }
public SaveFileFormat getFileFormat() { public SaveFileFormat getFileFormat() {
return fileFormat; return fileFormat;
} }
@ -234,7 +234,7 @@ public class JobOccurrencesModel implements Serializable{
public void setByDataSource(boolean byDataSource) { public void setByDataSource(boolean byDataSource) {
this.byDataSource = byDataSource; this.byDataSource = byDataSource;
} }
public int getNodeCompleted() { public int getNodeCompleted() {
return nodeCompleted; return nodeCompleted;
} }
@ -242,15 +242,15 @@ public class JobOccurrencesModel implements Serializable{
public void setNodeCompleted(int nodeCompleted) { public void setNodeCompleted(int nodeCompleted) {
this.nodeCompleted = nodeCompleted; this.nodeCompleted = nodeCompleted;
} }
public List<String> getDataSourcesNameAsString(){ public List<String> getDataSourcesNameAsString(){
List<String> listDataSourceName = new ArrayList<String>(); List<String> listDataSourceName = new ArrayList<String>();
if(dataSources!=null){ if(dataSources!=null){
for (DataSource dataSource : dataSources) for (DataSource dataSource : dataSources)
listDataSourceName.add(dataSource.getName()); listDataSourceName.add(dataSource.getName());
} }
return listDataSourceName; return listDataSourceName;
} }
@ -309,5 +309,5 @@ public class JobOccurrencesModel implements Serializable{
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }