diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java index 955ddc2..19d50fd 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java @@ -1819,17 +1819,6 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T try { SpeciesService taxonomyService = getSpeciesService(); - -// String mimeType = null; -// switch (jobModel.getFileFormat()) { -// case CSV: { -// mimeType = "text/csv"; -// } break; -// case DARWIN_CORE:{ -// mimeType = "application/xhtml+xml"; -// } break; -// } - String mimeType = "text/plain"; InputStream inputStream = taxonomyService.getOccurrenceJobErrorFileById(jobModel.getJobIdentifier()); @@ -2136,8 +2125,24 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T logger.info("input stream is not null"); WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(destinationFolderId); fileName = WorkspaceUtil.getUniqueName(fileName, folder); + + if(jobGisLayer.getGisViewerAppLink()==null){ + SpeciesService speciesService = getSpeciesService(); + CompleteJobStatus statusResponse = speciesService.getGisLayerByJobId(jobGisLayer.getJobIdentifier()); + GisLayerJobPersistence gisLayerJobDao = DaoSession.getGisLayersJobDAO(getASLSession()); + + try{ + GisLayerJob gLJ = gisLayerJobDao.getItemByIdField(jobGisLayer.getJobIdentifier()); + if(gLJ!=null){ + jobGisLayer = GisLayerJobUtil.convertJob(gLJ, statusResponse, gisLayerJobDao, speciesService, getASLSession()); + } + }catch(Exception e){ + logger.error("Error on retrieving gis link from DB for job id: "+jobGisLayer.getJobIdentifier(), e); + throw new Exception(e.getMessage()); + } + } + workspace.createExternalUrl(fileName, jobGisLayer.getLayerDescription() + "- Layer UUID: "+jobGisLayer.getLayerUUID(), jobGisLayer.getGisViewerAppLink(), destinationFolderId); -// System.out.println("input stream is not null"); logger.info("Saving External link "+fileName +" completed"); return true; @@ -2155,10 +2160,9 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T GisLayerJobPersistence gisLayerDAO; try { + gisLayerDAO = DaoSession.getGisLayersJobDAO(getASLSession()); - int count = GisLayerJobUtil.changetStatusGisLayerJob(jobId, state, gisLayerDAO); - if(count==1) return true; 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 74f1f6e..d2a57a3 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 @@ -110,11 +110,11 @@ public class GisLayerJobUtil { } } + //TODO int completedEntry = 0; if(statusResponse.getCompletedEntries()>0) completedEntry = statusResponse.getCompletedEntries(); - //TODO jobGisModel = new JobGisLayerModel(job.getId(), job.getName(), downloadState, completedEntry, job.getTotalPoints()); jobGisModel.setSubmitTime(submit); jobGisModel.setLayerUUID(job.getLayerUUID()); @@ -122,24 +122,27 @@ public class GisLayerJobUtil { try{ boolean changeEndTime = false; + boolean filledAppLink = false; //UPDATE END TIME if(downloadState.equals(DownloadState.FAILED) || downloadState.equals(DownloadState.COMPLETED)){ + String layerUUID = taxonomyService.getGisLayerResultLinkByJobId(job.getId()); if(statusResponse.getEndDate()!=null && job.getEndTime()==0){ //UPDATE end time first time only logger.trace("UPDATE end time first time only - " + downloadState); endTime = statusResponse.getEndDate().getTimeInMillis(); - String layerUUID = taxonomyService.getGisLayerResultLinkByJobId(job.getId()); job.setLayerUUID(layerUUID); jobGisModel.setLayerUUID(layerUUID); job.setEndTime(endTime); changeEndTime = true; - if(downloadState.equals(DownloadState.COMPLETED)){ - logger.debug("UUID is "+layerUUID); - String gisLink=GisInfoServiceImpl.getPublicLinkByUUID(layerUUID); - logger.debug("public link is "+gisLink); - job.setGisViewerAppLink(gisLink); - jobGisModel.setGisViewerAppLink(gisLink); - } + } + + if(downloadState.equals(DownloadState.COMPLETED) && jobGisModel.getGisViewerAppLink()==null){ + logger.debug("UUID is "+layerUUID); + String gisLink=GisInfoServiceImpl.getPublicLinkByUUID(layerUUID); + logger.debug("public link is "+gisLink); + job.setGisViewerAppLink(gisLink); + jobGisModel.setGisViewerAppLink(gisLink); + filledAppLink = true; } } @@ -153,7 +156,7 @@ public class GisLayerJobUtil { } //UPDATE DAO - if(changeStatus || changeEndTime || changeStartTime){ + if(changeStatus || changeEndTime || changeStartTime || filledAppLink){ job.setState(downloadState.toString()); gisLayerJobP.update(job); } diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/dao/GisLayerJobPersistence.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/dao/GisLayerJobPersistence.java index 98df64f..f3e87bb 100644 --- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/dao/GisLayerJobPersistence.java +++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/dao/GisLayerJobPersistence.java @@ -254,4 +254,34 @@ public class GisLayerJobPersistence extends AbstractPersistence{ } + /** + * Gets the item by id field. + * + * @param idField the id field + * @return the item by id field + * @throws DatabaseServiceException the database service exception + */ + public GisLayerJob getItemByIdField(String idField) throws DatabaseServiceException{ + EntityManager em = super.createNewManager(); + try { + Query query = em.createQuery("Select t FROM "+GisLayerJob.class.getSimpleName()+" t WHERE t."+GisLayerJob.ID_FIELD+"='"+idField+"'"); + List listOJ = query.getResultList(); + + if(listOJ!=null && listOJ.get(0)!=null) + return listOJ.get(0); + + return null; + + } catch (Exception e) { + logger.error("Error in OccurrencesJob deleteItemByIdField: " + e.getMessage(), e); + throw new DatabaseServiceException(); + + } finally { + if(em!=null) + em.close(); + } + + } + + } \ No newline at end of file