Starting work on Task #7001

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@142442 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-09 17:23:28 +00:00
parent 09838ce10f
commit e055612cd2
19 changed files with 1325 additions and 330 deletions

View File

@ -2,6 +2,7 @@
<Changeset component="org.gcube.portlets-user.species-discovery.3-9-0"
date="11-01-2016">
<Change>[Feature #6313] SPD portlet upgrade: porting to spd-client-library 4.0.0 </Change>
<Change>[Task #7001] Create Gis Layer via job</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.species-discovery.3-8-1"
date="15-09-2016">

View File

@ -22,6 +22,8 @@ import org.gcube.portlets.user.speciesdiscovery.client.event.ChangeFilterClassif
import org.gcube.portlets.user.speciesdiscovery.client.event.ChangeFilterClassificationOnResultEventHandler;
import org.gcube.portlets.user.speciesdiscovery.client.event.CompletedLoadDataSourceEvent;
import org.gcube.portlets.user.speciesdiscovery.client.event.CompletedLoadDataSourceEventHandler;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateGisLayerJobEvent;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateGisLayerJobEventHandler;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateOccurrenceJobEvent;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateOccurrenceJobEventHandler;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateTaxonomyJobEvent;
@ -77,6 +79,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.CommonName;
import org.gcube.portlets.user.speciesdiscovery.shared.Coordinate;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSourceModel;
import org.gcube.portlets.user.speciesdiscovery.shared.DownloadState;
import org.gcube.portlets.user.speciesdiscovery.shared.JobGisLayerModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobOccurrencesModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobTaxonomyModel;
import org.gcube.portlets.user.speciesdiscovery.shared.LightTaxonomyRow;
@ -101,7 +104,6 @@ import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@ -267,6 +269,62 @@ public class SearchController {
}
});
eventBus.addHandler(CreateGisLayerJobEvent.TYPE, new CreateGisLayerJobEventHandler() {
@Override
public void onCreateGisLayerJob(CreateGisLayerJobEvent createGisLayerJobEvent) {
// TODO Auto-generated method stub
SpeciesDiscovery.taxonomySearchService.createGisLayerJobFromSelectedOccurrenceKeys(createGisLayerJobEvent.getJobName(), createGisLayerJobEvent.getJobDescription(), new AsyncCallback<JobGisLayerModel>() {
@Override
public void onFailure(Throwable caught) {
Info.display("Error generating the map", "An error occurred generating the map, retry");
Log.error("Error on loading", "An error occurred on edit listner, retry." +caught.getMessage());
}
@Override
public void onSuccess(JobGisLayerModel jobId) {
//Info.display("Gis Layer Occurrence Job", result.size() + " occurrence job "+msg+" submitted");
// progress.close();
// showMap(layerName);
}
});
// SpeciesDiscovery.taxonomySearchService.createOccurrencesJob(listJobOccurrenceModel, createOccurrenceJobEvent.getFileFormat(), createOccurrenceJobEvent.getSaveEnum(), createOccurrenceJobEvent.isByDataSource(), createOccurrenceJobEvent.getExpectedOccurrences(), new AsyncCallback<List<JobOccurrencesModel>>() {
//
// @Override
// public void onFailure(Throwable caught) {
// Info.display("Error", "Sorry, An error occurred on create job. Please try again later");
// Log.error("Error on loading", "An error occurred on create job, retry." +caught.getMessage());
//
// }
//
// @Override
// public void onSuccess(List<JobOccurrencesModel> result) {
//
// if(result!=null){
// int jobs = result.size();
// if(jobs>0){
// String msg = jobs==1? "was":"were";
// Info.display("Species Occurrence Job", result.size() + " occurrence job "+msg+" submitted");
// excecuteGetJobs(SearchResultType.OCCURRENCE_POINT, false);
// searchBorderLayoutPanel.getSpeciesSouthPanel().setIconOccurrenceByCounter(result.size());
// }
// else{
// Info.display("Species Occurrence Job","An error occurred on submit job, retry");
// }
//
// }
// }
// });
}
});
eventBus.addHandler(SearchEvent.TYPE, new SearchEventHandler() {
@ -306,19 +364,8 @@ public class SearchController {
}
if(!createOccurrenceJobEvent.isByDataSource()){ //ONE JOB FOR ALL DATASOURCE
/*
String jobName = createOccurrenceJobEvent.getSearchTerm() + " occurrences from";
List<org.gcube.portlets.user.speciesdiscovery.shared.DataSource> dataSourceList = new ArrayList<org.gcube.portlets.user.speciesdiscovery.shared.DataSource>();
for (String dataSource : createOccurrenceJobEvent.getListDataSourceFound()) {
dataSourceList.add(new org.gcube.portlets.user.speciesdiscovery.shared.DataSource(dataSource,dataSource));
jobName+=" "+dataSource;
}
*/
String jobName = createOccurrenceJobEvent.getSearchTerm() + " occurrences";
List<org.gcube.portlets.user.speciesdiscovery.shared.DataSource> dataSourceList = new ArrayList<org.gcube.portlets.user.speciesdiscovery.shared.DataSource>();
for (String dataSource : createOccurrenceJobEvent.getListDataSourceFound()) {
@ -330,17 +377,11 @@ public class SearchController {
}else{ //IS BY DATASOURCE - ONE JOB FOR EACH DATASOURCE
for (String dataSource : createOccurrenceJobEvent.getListDataSourceFound()) {
// System.out.println("########DATASOURCE FOUND: "+dataSource);
// String jobName = createOccurrenceJobEvent.getSearchTerm() + " occurrences from " +dataSource;
String jobName = createOccurrenceJobEvent.getSearchTerm() + " occurrences";
List<org.gcube.portlets.user.speciesdiscovery.shared.DataSource> dataSourceList = new ArrayList<org.gcube.portlets.user.speciesdiscovery.shared.DataSource>();
dataSourceList.add(new org.gcube.portlets.user.speciesdiscovery.shared.DataSource(dataSource,dataSource));
listJobOccurrenceModel.add(new JobOccurrencesModel("", jobName,createOccurrenceJobEvent.getSearchTerm(), dataSourceList, createOccurrenceJobEvent.getFileFormat(), createOccurrenceJobEvent.getSaveEnum(), createOccurrenceJobEvent.isByDataSource()));
}
}
@ -576,14 +617,9 @@ public class SearchController {
@Override
public void onSuccess(OccurrencesStatus result) {
MessageDialog dialog;
if(event.getExpectedPoints()>result.getSize()){
dialog = new MessageDialog("Info", "Loading in progress", "On server are available only "+result.getSize()+" of "+event.getExpectedPoints()+" occurrence points. Do you want continue?");
dialog.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
@ -618,8 +654,9 @@ public class SearchController {
@Override
public void onShowOccurrencesMap(final ShowOccurrencesMapEvent event) {
SpeciesDiscovery.taxonomySearchService.getCountOfOccurrencesBatch(new AsyncCallback<OccurrencesStatus>() {
/*
* Moved INTO GisLayerJob
* SpeciesDiscovery.taxonomySearchService.getCountOfOccurrencesBatch(new AsyncCallback<OccurrencesStatus>() {
@Override
public void onFailure(Throwable caught) {
@ -629,13 +666,10 @@ public class SearchController {
@Override
public void onSuccess(OccurrencesStatus result) {
MessageDialog dialog;
if(event.getExpectedPoints()>result.getSize()){
dialog = new MessageDialog("Info", "Loading in progress", "On server are available only "+result.getSize()+" of "+event.getExpectedPoints()+" occurrences points. Do you want continue?");
dialog.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
@ -652,6 +686,7 @@ public class SearchController {
}
});
*/
}
});
@ -1346,30 +1381,30 @@ public class SearchController {
navigator.show();
}
public void showOccurrencesMap()
{
final MessageBox progress = MessageBox.wait("Generating map", "Calculating occurrence points", "generating...");
//MOVED
// public void showOccurrencesMap()
// {
// final MessageBox progress = MessageBox.wait("Generating map", "Calculating occurrence points", "generating...");
//
// SpeciesDiscovery.taxonomySearchService.generateMapFromSelectedOccurrencePoints(new AsyncCallback<String>() {
//
// @Override
// public void onFailure(Throwable caught) {
// progress.close();
// Info.display("Error generating the map", "An error occurred generating the map, retry");
// Log.error("Error on loading", "An error occurred on edit listner, retry." +caught.getMessage());
//
// }
//
// @Override
// public void onSuccess(String layerName) {
// progress.close();
// showMap(layerName);
// }
// });
// }
SpeciesDiscovery.taxonomySearchService.generateMapFromSelectedOccurrencePoints(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
progress.close();
Info.display("Error generating the map", "An error occurred generating the map, retry");
Log.error("Error on loading", "An error occurred on edit listner, retry." +caught.getMessage());
}
@Override
public void onSuccess(String layerName) {
progress.close();
showMap(layerName);
}
});
}
public void showMap(final String layerName)
{
public void showMap(final String layerName){
Log.trace("Obtaining public link for layer : "+layerName);
Info.display("Just moment...", "Generating link to layer");
@ -1654,7 +1689,6 @@ public class SearchController {
public static void excecuteGetJobs(SearchResultType type, final boolean resetStructures){
System.out.println("New rpc get list SpeciesJobs......." + type);
if(type.equals(SearchResultType.TAXONOMY_ITEM)){

View File

@ -0,0 +1,64 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.client.event;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class CreateGisLayerJobEvent.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class CreateGisLayerJobEvent extends GwtEvent<CreateGisLayerJobEventHandler> {
public static final GwtEvent.Type<CreateGisLayerJobEventHandler> TYPE = new Type<CreateGisLayerJobEventHandler>();
private String jobName;
/**
* @return the jobName
*/
public String getJobName() {
return jobName;
}
/**
* @return the jobDescription
*/
public String getJobDescription() {
return jobDescription;
}
private String jobDescription;
/**
* @param jobName
* @param string
*/
public CreateGisLayerJobEvent(String jobName, String descr) {
this.jobName = jobName;
this.jobDescription = descr;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
public Type<CreateGisLayerJobEventHandler> getAssociatedType() {
return TYPE;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
*/
@Override
protected void dispatch(CreateGisLayerJobEventHandler handler) {
handler.onCreateGisLayerJob(this);
}
}

View File

@ -0,0 +1,25 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface CreateGisLayerJobEventHandler.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public interface CreateGisLayerJobEventHandler extends EventHandler {
/**
* On create gis layer job.
*
* @param createGisLayerJobEvent the create gis layer job event
*/
public void onCreateGisLayerJob(
CreateGisLayerJobEvent createGisLayerJobEvent);
}

View File

@ -0,0 +1,82 @@
package org.gcube.portlets.user.speciesdiscovery.client.gridview;
import org.gcube.portlets.user.speciesdiscovery.client.SpeciesDiscovery;
import org.gcube.portlets.user.speciesdiscovery.client.event.CreateGisLayerJobEvent;
import org.gcube.portlets.user.speciesdiscovery.client.window.MessageDialog;
import org.gcube.portlets.user.speciesdiscovery.shared.OccurrencesStatus;
import org.gcube.portlets.user.speciesdiscovery.shared.util.NormalizeString;
import com.allen_sauer.gwt.log.client.Log;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class GisLayerJobGridManager {
private String searchTerm;
private EventBus eventBus;
private long expectedOccurrences;
private boolean isSearchByCommonName;
private static final String SCIENTIFIC_NAME = "(scientific name)";
private static final String COMMON_NAME = "(common name)";
public GisLayerJobGridManager(EventBus eventBus, String searchTerm, boolean isSearchByCommonName, long expectedOccurrences) {
this.eventBus = eventBus;
this.expectedOccurrences = expectedOccurrences;
this.searchTerm = searchTerm;
this.isSearchByCommonName = isSearchByCommonName;
}
public void saveOccurrence(){
SpeciesDiscovery.taxonomySearchService.getCountOfOccurrencesBatch(new AsyncCallback<OccurrencesStatus>() {
@Override
public void onFailure(Throwable caught) {
Log.error("Error on loading", "An error occurred on count of occurrence point, retry." +caught.getMessage());
}
@Override
public void onSuccess(OccurrencesStatus result) {
MessageDialog dialog;
if(expectedOccurrences>result.getSize()){
dialog = new MessageDialog("Info", "Loading in progress", "On server are available only "+result.getSize()+" of "+expectedOccurrences+" occurrences points. Do you want continue?");
dialog.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES))
createGisLayerJobEventCallback();
}
});
}
else
createGisLayerJobEventCallback();
}
});
}
private void createGisLayerJobEventCallback() {
String jobName = getSearchTermBySearchType(isSearchByCommonName, searchTerm);
eventBus.fireEvent(new CreateGisLayerJobEvent(jobName, "Gis Layer generated from SPD Portlet by gCube Framework"));
}
public static String getSearchTermBySearchType(boolean isSearchByCommonName, String searchTerm){
if(isSearchByCommonName)
return NormalizeString.lowerCaseUpFirstChar(searchTerm) + " " + COMMON_NAME;
else
return NormalizeString.lowerCaseUpFirstChar(searchTerm) + " " + SCIENTIFIC_NAME;
}
}

View File

@ -53,21 +53,21 @@ public class ResultRowResultsPanel extends ContentPanel {
protected final static String TOGGLE_GROUP = "SPECIES_VIEW";
private static ResultRowResultsPanel instance;
protected SpeciesGrid classicGridView;
protected DescriptiveSpeciesGrid descriptiveGridView;
public final static AbstractImagePrototype deleteFilterImage = AbstractImagePrototype.create(Resources.INSTANCE.getDelete());
public final static AbstractImagePrototype imgCheckBoxFull = AbstractImagePrototype.create(Resources.INSTANCE.getCheckBoxFull());
public final static AbstractImagePrototype imgCheckBoxEmpty = AbstractImagePrototype.create(Resources.INSTANCE.getCheckBoxEmpty());
public final static AbstractImagePrototype imgCheckSelected = AbstractImagePrototype.create(Resources.INSTANCE.getCheckSelected());
public final static AbstractImagePrototype imgDetailsWindow = AbstractImagePrototype.create(Resources.INSTANCE.getDetailsWindow());
protected ContentPanel currentView;
protected ToggleButton classicGridViewButton;
@ -75,9 +75,9 @@ public class ResultRowResultsPanel extends ContentPanel {
protected ToggleButton descriptiveGridViewButton;
protected Button actionButton;
protected Button btnSelectAllRow;
// protected Button btnDeselectAllRow;
protected EventBus eventBus;
@ -89,11 +89,11 @@ public class ResultRowResultsPanel extends ContentPanel {
private LabelToolItem labelFilterValue;
private Button btnViewDetails;
private Button btnRemoveFilter;
private ToolBar viewsToolBar = new ToolBar();
private ToolBar viewsToolBar = new ToolBar();
private final ToggleButton btnShowOnlySelectedButton;
private ListStore<ModelData> store;
@ -101,7 +101,7 @@ public class ResultRowResultsPanel extends ContentPanel {
private Button btnDeSelectAllRow;
private SearchController searchController;
private Button btnShowInGisViewer;
private Button btnOccurrencesMenu;
@ -109,7 +109,7 @@ public class ResultRowResultsPanel extends ContentPanel {
return instance;
}
public ResultRowResultsPanel(final EventBus eventBus, StreamPagingLoader loader, SearchController searchController) {
instance=this;
@ -120,21 +120,21 @@ public class ResultRowResultsPanel extends ContentPanel {
bind(eventBus, loader);
setFrame(false);
setFrame(false);
setCollapsible(false);
setAnimCollapse(false);
setAnimCollapse(false);
setHeaderVisible(false);
setLayout(new AnchorLayout());
setScrollMode(Scroll.AUTOX);
setScrollMode(Scroll.AUTOX);
classicGridView = new SpeciesGrid(loader.getStore(), eventBus);
classicGridView = new SpeciesGrid(loader.getStore(), eventBus);
// classicGridView.setBodyBorder(false);
descriptiveGridView = new DescriptiveSpeciesGrid(loader.getStore());
// descriptiveGridView.setBodyBorder(false);
viewsToolBar = new ToolBar();
viewsToolBar = new ToolBar();
classicGridViewButton = new ToggleButton("", AbstractImagePrototype.create(Resources.INSTANCE.getGridSpeciesIcon()));
@ -159,27 +159,27 @@ public class ResultRowResultsPanel extends ContentPanel {
toggleView(descriptiveGridView);
}
});
descriptiveGridViewButton.setAllowDepress(false);
descriptiveGridViewButton.setToolTip(new ToolTipConfig("Expandable List view", "Shows species as a grid letting users to expand interested rows."));
viewsToolBar.add(descriptiveGridViewButton);
LabelToolItem labelView = new LabelToolItem("Switch view");
viewsToolBar.add(labelView);
actionButton = new Button("Actions");
viewsToolBar.add(new SeparatorToolItem());
btnShowOnlySelectedButton = new ToggleButton(ONLY_SELECTED);
btnShowOnlySelectedButton = new ToggleButton(ONLY_SELECTED);
btnShowOnlySelectedButton.setIcon(imgCheckSelected);
btnShowOnlySelectedButton.setScale(ButtonScale.MEDIUM);
btnShowOnlySelectedButton.addSelectionListener(btnOnlySelectedListner);
btnShowOnlySelectedButton.setToolTip(new ToolTipConfig(SHOW_ONLY_SELECTED, SHOWS_ONLY_THE_SELECTED_RESULTS));
viewsToolBar.add(btnShowOnlySelectedButton);
btnViewDetails = new Button(ConstantsSpeciesDiscovery.VIEWDETAILS);
btnViewDetails.setScale(ButtonScale.MEDIUM);
btnViewDetails.setIcon(imgDetailsWindow);
@ -188,14 +188,14 @@ public class ResultRowResultsPanel extends ContentPanel {
@Override
public void componentSelected(ButtonEvent ce) {
eventBus.fireEvent(new ViewDetailsOfSelectedEvent());
}
});
viewsToolBar.add(new SeparatorToolItem());
viewsToolBar.add(btnViewDetails);
btnSelectAllRow = new Button(ConstantsSpeciesDiscovery.SELECTALL);
btnSelectAllRow.setIcon(imgCheckBoxFull);
btnSelectAllRow.setScale(ButtonScale.MEDIUM);
@ -203,7 +203,7 @@ public class ResultRowResultsPanel extends ContentPanel {
@Override
public void componentSelected(ButtonEvent ce) {
// if(btnToggleSelectAllRow.isPressed()){
// btnToggleSelectAllRow.setText(ConstantsSpeciesDiscovery.DESELECTALL);
// btnToggleSelectAllRow.setIcon(imgCheckBoxEmpty);
@ -213,16 +213,16 @@ public class ResultRowResultsPanel extends ContentPanel {
// btnToggleSelectAllRow.setIcon(imgCheckBoxFull);
// eventBus.fireEvent(new UpdateAllRowSelectionEvent(false, SearchResultType.SPECIES_PRODUCT));
// }
eventBus.fireEvent(new UpdateAllRowSelectionEvent(true, SearchResultType.SPECIES_PRODUCT));
}
});
viewsToolBar.add(new SeparatorToolItem());
viewsToolBar.add(btnSelectAllRow);
btnDeSelectAllRow = new Button(ConstantsSpeciesDiscovery.DESELECTALL);
btnDeSelectAllRow.setIcon(imgCheckBoxEmpty);
btnDeSelectAllRow.setScale(ButtonScale.MEDIUM);
@ -232,20 +232,20 @@ public class ResultRowResultsPanel extends ContentPanel {
public void componentSelected(ButtonEvent ce) {
eventBus.fireEvent(new UpdateAllRowSelectionEvent(false, SearchResultType.SPECIES_PRODUCT));
}
});
viewsToolBar.add(new SeparatorToolItem());
viewsToolBar.add(btnDeSelectAllRow);
viewsToolBar.add(new SeparatorToolItem());
addButtonsOccurrencesJob();
viewsToolBar.add(new FillToolItem());
labelFilter = new LabelToolItem(ConstantsSpeciesDiscovery.FILTER);
viewsToolBar.add(labelFilter);
labelFilterValue = new LabelToolItem(ConstantsSpeciesDiscovery.NONE);
viewsToolBar.add(labelFilterValue);
@ -253,19 +253,19 @@ public class ResultRowResultsPanel extends ContentPanel {
btnRemoveFilter.setIcon(deleteFilterImage);
btnRemoveFilter.getElement().getStyle().setLeft(5, Unit.PX);
btnRemoveFilter.setVisible(false);
btnRemoveFilter.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
eventBus.fireEvent(new DisableFilterEvent());
}
});
btnRemoveFilter.setToolTip(ConstantsSpeciesDiscovery.REMOVEFILTERTOOLTIP);
viewsToolBar.add(btnRemoveFilter);
setTopComponent(viewsToolBar);
@ -275,20 +275,20 @@ public class ResultRowResultsPanel extends ContentPanel {
pageToolBar.bind(loader);
setBottomComponent(pageToolBar);
add(classicGridView, new AnchorData("100% 100%"));
add(descriptiveGridView, new AnchorData("100% 100%"));
activeToolBarButtons(false); //DEFAULT DISABLE BUTTONS
btnSelectAllRow.setEnabled(false);
btnDeSelectAllRow.setEnabled(false);
toggleView(classicGridView);
toggleView(classicGridView);
}
public void activeToolBarButtons(boolean bool){
btnShowOnlySelectedButton.setEnabled(bool);
btnViewDetails.setEnabled(bool);
@ -296,25 +296,25 @@ public class ResultRowResultsPanel extends ContentPanel {
btnOccurrencesMenu.setEnabled(bool);
}
public void resetFilter (){
labelFilter.setLabel(ConstantsSpeciesDiscovery.FILTER);
labelFilterValue.setLabel(ConstantsSpeciesDiscovery.NONE);
btnRemoveFilter.setVisible(false);
classicGridView.setBodyStyleAsFiltered(false);
pageToolBar.reset(); //ADDED 03/08/2012
}
public void setFilterActive(boolean isActive, String label){
if(isActive){
labelFilterValue.setLabel(label);
btnRemoveFilter.setVisible(true);
classicGridView.setBodyStyleAsFiltered(true);
}
else
resetFilter();
resetFilter();
}
protected void bind(EventBus eventBus, StreamPagingLoader loader)
@ -339,16 +339,16 @@ public class ResultRowResultsPanel extends ContentPanel {
if (view.equals(descriptiveGridView)) {
descriptiveGridViewButton.toggle(true);
descriptiveGridView.show();
descriptiveGridView.show();
actionButton.setEnabled(true);
} else {
descriptiveGridViewButton.toggle(false);
descriptiveGridViewButton.toggle(false);
descriptiveGridView.hide();
}
currentView = view;
instance.unmask();
instance.unmask();
}
@ -361,19 +361,19 @@ public class ResultRowResultsPanel extends ContentPanel {
}
public void reload() {
// if (currentView!=null)
// if (currentView!=null)
// this.gridViewManager.reload();
}
public void activeBtnShowOnlySelected(boolean bool) {
this.btnShowOnlySelectedButton.removeSelectionListener(btnOnlySelectedListner);
this.btnShowOnlySelectedButton.toggle(bool);
this.btnShowOnlySelectedButton.addSelectionListener(btnOnlySelectedListner);
}
private SelectionListener< ButtonEvent> btnOnlySelectedListner = new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
@ -396,7 +396,7 @@ public class ResultRowResultsPanel extends ContentPanel {
classicGridView.selectAll();
else
classicGridView.deselectAll();
}
public void activeCheckAllRows(boolean active) {
@ -406,45 +406,11 @@ public class ResultRowResultsPanel extends ContentPanel {
public void addButtonsOccurrencesJob(){
// btnShowInGisViewer = new Button(ConstantsSpeciesDiscovery.SHOW_IN_GIS_VIEWER);
// btnShowInGisViewer.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.getGisProducts()));
// btnShowInGisViewer.setToolTip(new ToolTipConfig(ConstantsSpeciesDiscovery.SHOW_IN_GIS_VIEWER, "Show occurences points from selected results in a Gis Viewer Map."));
// btnShowInGisViewer.setScale(ButtonScale.SMALL);
//// btnShowInGisViewer.setIconAlign(IconAlign.TOP);
// btnShowInGisViewer.setArrowAlign(ButtonArrowAlign.BOTTOM);
// btnShowInGisViewer.addSelectionListener(new SelectionListener<ButtonEvent>() {
//
// @Override
// public void componentSelected(ButtonEvent ce) {
//
// SpeciesDiscovery.taxonomySearchService.retrieveOccurencesFromSelection(new AsyncCallback<Integer>() {
//
// @Override
// public void onSuccess(Integer points) {
// Log.trace("Expected points: "+points);
//
// int expectedPoints = points.intValue();
//
// if(expectedPoints>0)
// eventBus.fireEvent(new ShowOccurrencesMapEvent(expectedPoints));
// }
//
// @Override
// public void onFailure(Throwable caught) {
// Info.display("Error getting occurrences", "Error getting occurrences, retry");
// Log.trace("Error getting occurrences", caught);
// }
// });
//
//
// }
// });
btnOccurrencesMenu = new Button(ConstantsSpeciesDiscovery.SAVE_OCCURRENCES);
btnOccurrencesMenu = new Button(ConstantsSpeciesDiscovery.SAVE_OCCURRENCES);
Menu formatSubMenu = new Menu();
btnOccurrencesMenu.setMenu(formatSubMenu);
btnOccurrencesMenu.setScale(ButtonScale.MEDIUM);
// btnOccurrencesMenu.setIconAlign(IconAlign.TOP);
btnOccurrencesMenu.setMenu(formatSubMenu);
btnOccurrencesMenu.setScale(ButtonScale.MEDIUM);
// btnOccurrencesMenu.setIconAlign(IconAlign.TOP);
btnOccurrencesMenu.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.getSaveProducts24()));
btnOccurrencesMenu.setToolTip(new ToolTipConfig(ConstantsSpeciesDiscovery.SAVE_OCCURRENCES, ConstantsSpeciesDiscovery.SAVE_OCCURENCES_POINTS_FROM_SELECTED_RESULTS));
@ -456,88 +422,69 @@ public class ResultRowResultsPanel extends ContentPanel {
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.CSV, OccurrencesSaveEnum.STANDARD,searchController.getLastSearchEvent().getSearchTerm(), false, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
}
});
formatSubMenu.add(csvFormatItem);
Menu csvTypeMenu = new Menu();
Menu csvTypeMenu = new Menu();
MenuItem csvStandard = new MenuItem(ConstantsSpeciesDiscovery.PLAIN_CSV);
csvStandard.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.CSV, OccurrencesSaveEnum.STANDARD,searchController.getLastSearchEvent().getSearchTerm(), false, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
occurrenceJobMng.saveOccurrence();
}
});
MenuItem csvStandardByDataSource = new MenuItem(ConstantsSpeciesDiscovery.PLAIN_CSV_BY_DATA_SOURCE);
csvStandardByDataSource.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.CSV, OccurrencesSaveEnum.STANDARD,searchController.getLastSearchEvent().getSearchTerm(), true, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
}
});
MenuItem csvOpenModeller = new MenuItem(ConstantsSpeciesDiscovery.OPEN_MODELLER);
csvOpenModeller.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.CSV, OccurrencesSaveEnum.OPENMODELLER,searchController.getLastSearchEvent().getSearchTerm(), false, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
}
});
MenuItem csvOpenModellerByDataSource = new MenuItem(ConstantsSpeciesDiscovery.OPEN_MODELLER_BY_DATA_SOURCE);
csvOpenModellerByDataSource.addSelectionListener(new SelectionListener<MenuEvent>() {
@Override
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.CSV, OccurrencesSaveEnum.OPENMODELLER,searchController.getLastSearchEvent().getSearchTerm(), true, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
occurrenceJobMng.saveOccurrence();
}
});
csvTypeMenu.add(csvStandard);
csvTypeMenu.add(csvStandard);
csvTypeMenu.add(csvStandardByDataSource);
csvTypeMenu.add(csvOpenModeller);
csvTypeMenu.add(csvOpenModeller);
csvTypeMenu.add(csvOpenModellerByDataSource);
csvFormatItem.setSubMenu(csvTypeMenu);
csvFormatItem.setSubMenu(csvTypeMenu);
MenuItem darwinCoreFormatItem = new MenuItem(ConstantsSpeciesDiscovery.DARWIN_CORE);
darwinCoreFormatItem.setToolTip(new ToolTipConfig(ConstantsSpeciesDiscovery.SAVES_IN_DARWIN_CORE_FILE_FORMAT));
darwinCoreFormatItem.addSelectionListener(new SelectionListener<MenuEvent>() {
@ -546,24 +493,21 @@ public class ResultRowResultsPanel extends ContentPanel {
public void componentSelected(MenuEvent ce) {
OccurrenceJobGridManager occurrenceJobMng = new OccurrenceJobGridManager(eventBus,SaveFileFormat.DARWIN_CORE, null,searchController.getLastSearchEvent().getSearchTerm(), false, isSearchByCommonName());
occurrenceJobMng.saveOccurrence();
}
});
formatSubMenu.add(darwinCoreFormatItem);
viewsToolBar.add(btnOccurrencesMenu);
// viewsToolBar.add(new SeparatorToolItem());
// viewsToolBar.add(btnShowInGisViewer);
}
protected boolean isSearchByCommonName() {
if(searchController.getLastSearchEvent().getType().equals(SearchType.BY_COMMON_NAME))
return true;
return false;
}
}

View File

@ -10,6 +10,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.CommonName;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSource;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSourceModel;
import org.gcube.portlets.user.speciesdiscovery.shared.DownloadState;
import org.gcube.portlets.user.speciesdiscovery.shared.JobGisLayerModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobOccurrencesModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobTaxonomyModel;
import org.gcube.portlets.user.speciesdiscovery.shared.LightTaxonomyRow;
@ -65,8 +66,8 @@ public interface TaxonomySearchService extends RemoteService {
public void stopRetrievingOccurrences() throws SearchServiceException;
public String generateMapFromSelectedOccurrencePoints()
throws SearchServiceException;
JobGisLayerModel createGisLayerJobFromSelectedOccurrenceKeys(
String layerTitle, String layerDescr) throws Exception;
// Added by Francesco M.
public void saveSelectedOccurrencePoints(String destinationFolderId,
@ -138,23 +139,23 @@ public interface TaxonomySearchService extends RemoteService {
public JobTaxonomyModel resubmitTaxonomyJob(String jobIdentifier)
throws Exception;
public ClusterStructuresForResultRow loadStructuresForResultRowClustering() throws Exception;
public ClusterStructuresForTaxonomyRow loadStructuresForTaxonomyClustering()
throws Exception;
public boolean changeStatusOccurrenceJob(String jobIdentifier, DownloadState state) throws Exception;
public boolean changeStatusTaxonomyJob(String jobIdentifier, DownloadState state) throws Exception;
public List<DataSource> loadDataSourceForResultRow(boolean selected, boolean distinct) throws Exception;
public JobTaxonomyModel createTaxonomyJobByIds(String search,
List<DataSourceModel> dataSources) throws Exception;
public JobTaxonomyModel createTaxonomyJobByChildren(String taxonomyServiceId,
String taxonomyName, String taxonomyRank, String dataSourceName)
throws Exception;
@ -173,7 +174,7 @@ public interface TaxonomySearchService extends RemoteService {
String dataSourceName) throws Exception;
boolean isAvailableTaxonomyJobReportError(String jobIdentifier) throws Exception;
/**
* @param jobModel
* @param destinationFolderId
@ -204,5 +205,5 @@ public interface TaxonomySearchService extends RemoteService {
ClusterCommonNameDataSourceForTaxonomyRow loadClusterCommonNameForTaxonomyRowByScientificName(
String scientificName);
}

View File

@ -10,6 +10,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.CommonName;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSource;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSourceModel;
import org.gcube.portlets.user.speciesdiscovery.shared.DownloadState;
import org.gcube.portlets.user.speciesdiscovery.shared.JobGisLayerModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobOccurrencesModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobTaxonomyModel;
import org.gcube.portlets.user.speciesdiscovery.shared.LightTaxonomyRow;
@ -38,37 +39,37 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
public interface TaxonomySearchServiceAsync {
public void searchByScientificName(String searchTerm, SearchFilters searchFilters, AsyncCallback<Void> callback);
public void searchByCommonName(String searchTerm, SearchFilters searchFilters, AsyncCallback<Void> callback);
void getSearchStatus(boolean onlySelected, boolean isActiveFilterOnResult,
AsyncCallback<SearchStatus> callback);
// void getSearchStatus(boolean onlySelected, AsyncCallback<SearchStatus> callback);
public void stopSearch(AsyncCallback<Void> callback);
public void updateRowSelection(int rowId, boolean selection, AsyncCallback<Void> callback);
public void retrieveOccurencesFromSelection(AsyncCallback<Integer> callback);
void getOccurrencesBatch(int start, int count, AsyncCallback<OccurrenceBatch> callback);
public void stopRetrievingOccurrences(AsyncCallback<Void> callback);
public void generateMapFromSelectedOccurrencePoints(AsyncCallback<String> callback);
void createGisLayerJobFromSelectedOccurrenceKeys(
String layerTitle, String layerDescr,
AsyncCallback<JobGisLayerModel> callback);
//Added by Francesco M.
void saveSelectedOccurrencePoints(String destinationFolderId, String fileName, SaveFileFormat fileFormat, OccurrencesSaveEnum typeCSV, AsyncCallback<Void> callback);
void updateRowSelections(boolean selection,
ResultFilter activeFiltersObject, AsyncCallback<Integer> callback);
void loadDataSourceList(AsyncCallback<List<DataSourceModel>> callback);
void getFilterCounterById(GridField field, AsyncCallback<HashMap<String, Integer>> callback);
void getParentsList(Taxon taxon, AsyncCallback<List<Taxon>> callback);
void getFilterCounterForClassification(String rank, AsyncCallback<HashMap<String, ClassificationModel>> callback);
@ -163,9 +164,9 @@ public interface TaxonomySearchServiceAsync {
void loadClusterCommonNameForResultRowByScientificName(
String scientificName,
AsyncCallback<ClusterCommonNameDataSourceForResultRow> callback);
void loadClusterCommonNameForTaxonomyRowByScientificName(
String scientificName,
AsyncCallback<ClusterCommonNameDataSourceForTaxonomyRow> callback);
}

View File

@ -37,10 +37,12 @@ import org.gcube.portlets.user.speciesdiscovery.client.model.ClassificationModel
import org.gcube.portlets.user.speciesdiscovery.client.rpc.TaxonomySearchService;
import org.gcube.portlets.user.speciesdiscovery.client.util.GridField;
import org.gcube.portlets.user.speciesdiscovery.server.asl.SessionUtil;
import org.gcube.portlets.user.speciesdiscovery.server.job.GisLinkJobUtil;
import org.gcube.portlets.user.speciesdiscovery.server.job.OccurrenceJobUtil;
import org.gcube.portlets.user.speciesdiscovery.server.job.OccurrenceKeys;
import org.gcube.portlets.user.speciesdiscovery.server.job.TaxonomyJobUtil;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.DaoSession;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.GisLayerJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceRowPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.ResultRowPersistence;
@ -56,7 +58,6 @@ import org.gcube.portlets.user.speciesdiscovery.server.session.FilterableFetchin
import org.gcube.portlets.user.speciesdiscovery.server.session.SelectableFetchingBuffer;
import org.gcube.portlets.user.speciesdiscovery.server.stream.CSVGenerator;
import org.gcube.portlets.user.speciesdiscovery.server.stream.CloseableIterator;
import org.gcube.portlets.user.speciesdiscovery.server.stream.IteratorPointInfo;
import org.gcube.portlets.user.speciesdiscovery.server.stream.OccurenceCSVConverter;
import org.gcube.portlets.user.speciesdiscovery.server.stream.OccurenceCSVConverterOpenModeller;
import org.gcube.portlets.user.speciesdiscovery.server.stream.aggregation.FieldAggregator;
@ -71,6 +72,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.DatabaseServiceException;
import org.gcube.portlets.user.speciesdiscovery.shared.DownloadState;
import org.gcube.portlets.user.speciesdiscovery.shared.FetchingElement;
import org.gcube.portlets.user.speciesdiscovery.shared.ItemParameter;
import org.gcube.portlets.user.speciesdiscovery.shared.JobGisLayerModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobOccurrencesModel;
import org.gcube.portlets.user.speciesdiscovery.shared.JobTaxonomyModel;
import org.gcube.portlets.user.speciesdiscovery.shared.LightTaxonomyRow;
@ -847,11 +849,26 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T
* {@inheritDoc}
*/
@Override
public String generateMapFromSelectedOccurrencePoints() throws SearchServiceException {
public JobGisLayerModel createGisLayerJobFromSelectedOccurrenceKeys(String layerTitle, String layerDescr) throws Exception {
try {
logger.info("generate Map From Occurrence Points");
List<String> occurrenceKeys = getSelectedOccurrenceKeys();
SpeciesService taxonomyService = getSpeciesService();
String author = getASLSession().getUsername();
String credits = "";
GisLayerJobPersistence gisLayerJob = DaoSession.getGisLayersJobDAO(getASLSession());
GisLinkJobUtil.createGisLayerJobByOccurrenceKeys(occurrenceKeys, taxonomyService, layerTitle, layerDescr, author, credits, gisLayerJob);
logger.trace("Generating Map form Occurrence Keys selected: "+occurrenceKeys.size());
String jobId = taxonomyService.generateMapFromOccurrenceKeys(occurrenceKeys,layerTitle,layerDescr,author,credits);
logger.info("generated gis layer jobID: "+jobId);
return new JobGisLayerModel(jobId, layerTitle, 0, Calendar.getInstance().getTimeInMillis(), 0, layerDescr, DownloadState.PENDING.toString());
} catch (Exception e) {
logger.error("An error occurred creating the map", e);
throw new Exception(e.getMessage());
}
Iterator<Occurrence> iteratorOccurrences = getIteratorSelectedOccurrenceIds();
/*Iterator<Occurrence> iteratorOccurrences = getIteratorSelectedOccurrenceIds();
IteratorPointInfo streamKey = new IteratorPointInfo(iteratorOccurrences);
try {
@ -862,7 +879,7 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T
} catch (Exception e) {
logger.error("An error occurred creating the map", e);
throw new SearchServiceException(e.getMessage());
}
}*/
}
//USED FOR DEBUG
@ -1670,7 +1687,7 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T
}
else{
logger.info("statusResponse of occurrence job is null..." + job.getId());
logger.info("delete job ..." + job.getId());
logger.info("deleting job ..." + job.getId());
OccurrenceJobUtil.deleteOccurrenceJobById(job.getId(),occurrencesJobDao);
}

View File

@ -12,6 +12,7 @@ import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.GisLayerJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceRowPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.ResultRowPersistence;
@ -45,6 +46,7 @@ public class SessionUtil {
public static final String EJB_TAXONOMY = "EJB_TAXONOMY";
public static final String EJB_OCCURRENCES_JOB = "EJB_OCCURRENCES_JOB";
public static final String EJB_TAXONOMY_JOB = "EJB_TAXONOMY_JOB";
public static final String EJB_GIS_LAYER_JOB = "EJB_GIS_LAYER_JOB";
public static final String CURRENT_SPD_QUERY = "CURRENT_SPD_QUERY";
private static final String CLUSTER_COMMONNAME_FOR_RESULTROW = "CLUSTER_COMMONNAME_FOR_RESULTROW";
private static final String CLUSTER_COMMONNAME_FOR_TAXONOMYROW = "CLUSTER_COMMONNAME_FOR_TAXONOMYROW";
@ -171,6 +173,22 @@ public class SessionUtil {
session.setAttribute(EJB_TAXONOMY_JOB, taxonomyJobPeristence);
}
/**
* @param session
* @param gisLayerJobDao
*/
public static void setCurrentEJBGisLayerJob(ASLSession session, GisLayerJobPersistence gisLayerJobDao) {
session.setAttribute(EJB_GIS_LAYER_JOB, gisLayerJobDao);
}
/**
* @param session
* @return
*/
public static GisLayerJobPersistence getCurrentGisLayersJob( ASLSession session) {
return (GisLayerJobPersistence) session.getAttribute(EJB_GIS_LAYER_JOB);
}
/**
* @param aslSession
* @param lastQuery
@ -279,4 +297,8 @@ public class SessionUtil {
session.setAttribute(CACHE_HASH_MAP_TAXONOMYID_TAXONOMY, list);
}
}

View File

@ -0,0 +1,57 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.server.job;
import java.util.Calendar;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.GisLayerJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.service.SpeciesService;
import org.gcube.portlets.user.speciesdiscovery.shared.DownloadState;
import org.gcube.portlets.user.speciesdiscovery.shared.GisLayerJob;
import org.gcube.portlets.user.speciesdiscovery.shared.JobGisLayerModel;
/**
* The Class GisLinkJobUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class GisLinkJobUtil {
protected static Logger logger = Logger.getLogger(GisLinkJobUtil.class);
/**
* Creates the gis layer job by occurrence keys.
*
* @param occurrenceKeys the occurrence keys
* @param taxonomyService the taxonomy service
* @param layerTitle the layer title
* @param layerDescr the layer descr
* @param author the author
* @param credits the credits
* @param gisLayerJob the gis layer job
* @return the job gis layer model
* @throws Exception the exception
*/
public static JobGisLayerModel createGisLayerJobByOccurrenceKeys(List<String> occurrenceKeys, SpeciesService taxonomyService, String layerTitle, String layerDescr, String author, String credits, GisLayerJobPersistence gisLayerJob) throws Exception {
try {
logger.trace("Generating Map form Occurrence Keys selected: "+occurrenceKeys.size());
String jobId = taxonomyService.generateMapFromOccurrenceKeys(occurrenceKeys,layerTitle,layerDescr,author,credits);
logger.info("generated gis layer jobID: "+jobId);
GisLayerJob gisLJ = new GisLayerJob(jobId, layerTitle, 0, Calendar.getInstance().getTimeInMillis(), 0, layerDescr, DownloadState.PENDING.toString());
gisLayerJob.insert(gisLJ);
return new JobGisLayerModel(jobId, layerTitle, 0, Calendar.getInstance().getTimeInMillis(), 0, layerDescr, DownloadState.PENDING.toString());
} catch (Exception e) {
logger.error("An error occurred creating the map", e);
throw new Exception(e.getMessage());
}
}
}

View File

@ -128,7 +128,6 @@ public class OccurrenceJobUtil {
}
}
boolean changeStartTime = false;
//SET START TIME
@ -140,7 +139,6 @@ public class OccurrenceJobUtil {
changeStartTime = true;
}
//UPDATE DAO
if(changeStatus || changeEndTime || changeStartTime){
job.setState(downloadState.toString());
@ -168,7 +166,6 @@ public class OccurrenceJobUtil {
//SET ELAPSED TIME
jobOccurrenceModel.setElapsedTime(DateUtil.getDifference(submitTime, elapsedTime));
//OTHERS SET
jobOccurrenceModel.setFileFormat(converFileFormat(job.getFileFormat()));
jobOccurrenceModel.setCsvType(convertCsvType(job.getCsvType()));
@ -277,9 +274,7 @@ public class OccurrenceJobUtil {
public static int changeStatusOccurrenceJobById(String jobIdentifier, DownloadState state, OccurrenceJobPersistence occurrencesJobDao){
logger.trace("Change status occurrence job id: " + jobIdentifier);
// System.out.println("Delete job id: " + jobIdentifier);
int result = 0;
try{
CriteriaBuilder queryBuilder = occurrencesJobDao.getCriteriaBuilder();
@ -288,16 +283,13 @@ public class OccurrenceJobUtil {
cq.where(pr1);
Iterator<OccurrencesJob> iterator = occurrencesJobDao.executeCriteriaQuery(cq).iterator();
OccurrencesJob job;
if(iterator.hasNext())
job = iterator.next();
else
return 0;
job.setState(state.toString());
occurrencesJobDao.update(job);
}catch (Exception e) {
@ -319,11 +311,8 @@ public class OccurrenceJobUtil {
Collection<ResultRow> selectedRows = ((SelectableFetchingBuffer<ResultRow>) searchSession.getBuffer()).getSelected();
logger.trace("found "+selectedRows.size()+" selected rows");
int count = 0;
List<String> keys = new ArrayList<String>(selectedRows.size());
for (ResultRow row:selectedRows) {
//ADD KEY ONLY IF IS NOT EQUAL NULL AND SIZE IS > 0
if(row.getOccurencesKey()!=null && row.getOccurencesKey().length()>0){
@ -333,7 +322,6 @@ public class OccurrenceJobUtil {
}
logger.trace("found "+count+" occurrence points");
return keys;
}
@ -350,41 +338,25 @@ public class OccurrenceJobUtil {
logger.trace("getListOfSelectedKeyByDataSource...");
OccurrenceKeys occurrenceKeys = new OccurrenceKeys();
List<String> keys = new ArrayList<String>();
Iterator<ResultRow> resulRowIt = null;
int count = 0;
try{
// System.out.println("dasource name: "+dataSource);
logger.trace("datasource name: "+dataSource);
ResultRowPersistence resultRowDao = DaoSession.getResultRowDAO(session);
/*CriteriaBuilder cb = resultRowDao.getCriteriaBuilder();
CriteriaQuery<Object> cq = cb.createQuery();
Predicate pr1 = cb.equal(resultRowDao.rootFrom(cq).get(ResultRow.DATASOURCE_NAME), dataSource);
Predicate pr2 = cb.equal(resultRowDao.rootFrom(cq).get(ResultRow.SELECTED), true);
cq.where(cb.and(pr1,pr2));
Iterator<ResultRow> resulRowIt = resultRowDao.executeCriteriaQuery(cq).iterator();
*/
EntityManager em = resultRowDao.createNewManager();
try {
Query query = em.createQuery("select t from ResultRow t where t."+ResultRow.DATASOURCE_NAME +" = '"+dataSource+ "' AND t."+ResultRow.SELECTED+" = true");
resulRowIt = query.getResultList().iterator();
} catch (Exception e) {
logger.error("Error in update: "+e.getMessage(), e);
return null;
@ -394,14 +366,11 @@ public class OccurrenceJobUtil {
}
while(resulRowIt.hasNext()){
ResultRow row = resulRowIt.next();
if(row.getOccurencesKey()!=null && row.getOccurencesKey().length()>0){
keys.add(row.getOccurencesKey());
count += row.getOccurencesCount();
}
}
occurrenceKeys.setListKey(keys);
@ -411,8 +380,7 @@ public class OccurrenceJobUtil {
logger.error("error in getListOfSelectedKeyByDataSource "+ e);
}
logger.trace("found "+count+" occurrence points");
logger.debug("found "+count+" occurrence points");
return occurrenceKeys;
}
@ -432,10 +400,9 @@ public class OccurrenceJobUtil {
* @return the job occurrences model
*/
public static JobOccurrencesModel createOccurrenceJobOnServiceByKeys(JobOccurrencesModel jobModel,SpeciesService taxonomyService, OccurrenceJobPersistence occurrencesJobDao, List<String> keys, List<DataSource> dataSources, SaveFileFormat saveFileFormat, OccurrencesSaveEnum csvType, int expectedOccurrence) {
String serviceJobId = null;
StreamExtend<String> streamKeys = new StreamExtend<String>(keys.iterator()); //convert
String csvTypeString = null;
try {
@ -457,9 +424,7 @@ public class OccurrenceJobUtil {
case DARWIN_CORE:
serviceJobId = taxonomyService.createOccurrenceDARWINCOREJob(streamKeys);
csvTypeString = "";
break;
default:
@ -471,22 +436,17 @@ public class OccurrenceJobUtil {
return null;
}
long submitTimeInMillis = Calendar.getInstance().getTimeInMillis();
try {
//STORE INTO DAO
OccurrencesJob occurrenceJob = new OccurrencesJob(serviceJobId, jobModel.getJobName(), jobModel.getDescription(), jobModel.getScientificName(), dataSources, DownloadState.PENDING.toString(), "", submitTimeInMillis, 0, 0, jobModel.getFileFormat().toString(),csvTypeString, jobModel.isByDataSource(), convertListKeyIntoStoreXMLString(keys), expectedOccurrence);
//for debug
// System.out.println("INTO createOccurrenceJobOnServiceByKeys " + occurrenceJob);
occurrencesJobDao.insert(occurrenceJob);
Date start = DateUtil.millisecondsToDate(submitTimeInMillis);
jobModel.setSubmitTime(start);
//FILL MODEL WITH OTHER DATA
jobModel.setId(serviceJobId);
jobModel.setState(DownloadState.PENDING);
@ -511,7 +471,6 @@ public class OccurrenceJobUtil {
String storeKeys = "";
KeyStringList keyStringList = new KeyStringList();
XStreamUtil<KeyStringList> xstreamUtil = new XStreamUtil<KeyStringList>(ALIASKEY,KeyStringList.class);
for (String key : keys) {
@ -521,10 +480,6 @@ public class OccurrenceJobUtil {
}
storeKeys = xstreamUtil.toXML(keyStringList);
//FOR DEBUG
// System.out.println("stored keys: "+storeKeys);
return storeKeys;
}
@ -537,17 +492,11 @@ public class OccurrenceJobUtil {
public static List<String> revertListKeyFromStoredXMLString(String storedKeysAsXml){
List<String> listKey = new ArrayList<String>();
XStreamUtil<KeyStringList> xstreamUtil = new XStreamUtil<KeyStringList>(ALIASKEY,KeyStringList.class);
KeyStringList keyStringList = (KeyStringList) xstreamUtil.fromXML(storedKeysAsXml);
for (String key : keyStringList.getListKeys()) {
// for debug
// System.out.println("key :"+ key);
listKey.add(key);
}
return listKey;
}

View File

@ -10,6 +10,7 @@ import javax.persistence.Persistence;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.user.speciesdiscovery.server.asl.SessionUtil;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.GisLayerJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceRowPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.ResultRowPersistence;
@ -18,9 +19,12 @@ import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyJ
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyRowPersistence;
import org.gcube.portlets.user.speciesdiscovery.shared.DatabaseServiceException;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* The Class DaoSession.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class DaoSession {
@ -31,6 +35,13 @@ public class DaoSession {
private static final String JDBCDRIVER = "jdbc:h2:";
/**
* Gets the username scope value.
*
* @param username the username
* @param scope the scope
* @return the username scope value
*/
public static String getUsernameScopeValue(String username, String scope){
scope = scope.replaceAll("/","");
@ -43,10 +54,10 @@ public class DaoSession {
/**
*
* @return $CATALINA_HOME
* @throws Exception
*/
* Gets the tomcat folder.
*
* @return $CATALINA_HOME
*/
public static String getTomcatFolder(){
String catalinaHome = System.getenv(CATALINA_HOME) != null ? System.getenv(CATALINA_HOME) : System.getProperty(PROPERTY_CATALINA_HOME);
@ -59,6 +70,12 @@ public class DaoSession {
}
/**
* Gets the connection url.
*
* @param session the session
* @return the connection url
*/
public static String getConnectionUrl(ASLSession session){
String username = session.getUsername();
@ -67,6 +84,12 @@ public class DaoSession {
}
/**
* Inits the session dao objects.
*
* @param session the session
* @throws DatabaseServiceException the database service exception
*/
public static void initSessionDaoObjects(ASLSession session) throws DatabaseServiceException{
try{
@ -75,6 +98,7 @@ public class DaoSession {
getTaxonomyDAO(session);
getOccurrencesJobDAO(session);
getTaxonomyJobDAO(session);
getGisLayersJobDAO(session);
}catch (Exception e) {
logger.error("An error occurred on init DB: ", e);
e.printStackTrace();
@ -83,15 +107,23 @@ public class DaoSession {
}
//MODIFIED**************************************************************************************+
/**
* New entity manager.
*
* @param session the session
* @return the entity manager
*/
public static EntityManager newEntityManager(ASLSession session){
return getEntityManagerFactory(session).createEntityManager();
}
/**
* Gets the entity manager factory.
*
* @param session the session
* @return the entity manager factory
*/
public static EntityManagerFactory getEntityManagerFactory(ASLSession session){
@ -105,6 +137,13 @@ public class DaoSession {
return factory;
}
/**
* Gets the occurrences job dao.
*
* @param session the session
* @return the occurrences job dao
* @throws Exception the exception
*/
public static OccurrenceJobPersistence getOccurrencesJobDAO(ASLSession session) throws Exception
{
@ -120,6 +159,45 @@ public class DaoSession {
/**
* Gets the gis layers job dao.
*
* @param session the session
* @return the gis layers job dao
* @throws Exception the exception
*/
public static GisLayerJobPersistence getGisLayersJobDAO(ASLSession session) throws Exception {
GisLayerJobPersistence gisLayerJobDao = SessionUtil.getCurrentGisLayersJob(session);
if(gisLayerJobDao==null){
gisLayerJobDao = initGisLayerJobsDao(session);
SessionUtil.setCurrentEJBGisLayerJob(session, gisLayerJobDao);
}
return gisLayerJobDao;
}
/**
* Inits the gis layer jobs dao.
*
* @param session the session
* @return the gis layer job persistence
*/
private static GisLayerJobPersistence initGisLayerJobsDao(ASLSession session) {
GisLayerJobPersistence gisLayerJobP = new GisLayerJobPersistence(getEntityManagerFactory(session));
SessionUtil.setCurrentEJBGisLayerJob(session, gisLayerJobP);
return gisLayerJobP;
}
/**
* Gets the taxonomy job dao.
*
* @param session the session
* @return the taxonomy job dao
* @throws Exception the exception
*/
public static TaxonomyJobPersistence getTaxonomyJobDAO(ASLSession session) throws Exception
{
@ -133,6 +211,12 @@ public class DaoSession {
return taxonomyJobPeristence;
}
/**
* Creates the entity manager factory.
*
* @param session the session
* @return the entity manager factory
*/
public static EntityManagerFactory createEntityManagerFactory(ASLSession session){
Map<String,String> properties = new HashMap<String, String>();
@ -152,6 +236,13 @@ public class DaoSession {
}
/**
* Inits the occurrences jobs dao.
*
* @param session the session
* @return the occurrence job persistence
* @throws Exception the exception
*/
public static OccurrenceJobPersistence initOccurrencesJobsDao(ASLSession session) throws Exception
{
@ -162,6 +253,13 @@ public class DaoSession {
}
/**
* Inits the taxonomy jobs dao.
*
* @param session the session
* @return the taxonomy job persistence
* @throws Exception the exception
*/
public static TaxonomyJobPersistence initTaxonomyJobsDao(ASLSession session) throws Exception{
TaxonomyJobPersistence occurrenceJobPersistence = new TaxonomyJobPersistence(getEntityManagerFactory(session));
SessionUtil.setCurrentDAOTaxonomyJob(session, occurrenceJobPersistence);
@ -169,6 +267,15 @@ public class DaoSession {
}
/**
* Creates the occurrences job dao.
*
* @param username the username
* @param scope the scope
* @param session the session
* @return the occurrence job persistence
* @throws Exception the exception
*/
public static OccurrenceJobPersistence createOccurrencesJobDao(String username, String scope, ASLSession session) throws Exception{
OccurrenceJobPersistence occurrenceJobPersistence = new OccurrenceJobPersistence(getEntityManagerFactory(session));
@ -179,6 +286,13 @@ public class DaoSession {
return occurrenceJobPersistence;
}
/**
* Inits the result row dao.
*
* @param session the session
* @return the result row persistence
* @throws Exception the exception
*/
public static ResultRowPersistence initResultRowDao(ASLSession session) throws Exception
{
@ -191,6 +305,13 @@ public class DaoSession {
}
/**
* Gets the occurrence dao.
*
* @param session the session
* @return the occurrence dao
* @throws Exception the exception
*/
public static OccurrenceRowPersistence getOccurrenceDAO(ASLSession session) throws Exception
{
@ -204,6 +325,13 @@ public class DaoSession {
return occurrenceEJB;
}
/**
* Inits the taxon dao.
*
* @param session the session
* @return the taxon row persistence
* @throws Exception the exception
*/
public static TaxonRowPersistence initTaxonDao(ASLSession session) throws Exception
{
@ -216,6 +344,13 @@ public class DaoSession {
}
/**
* Inits the occurrence dao.
*
* @param session the session
* @return the occurrence row persistence
* @throws Exception the exception
*/
private static OccurrenceRowPersistence initOccurrenceDao(ASLSession session) throws Exception {
OccurrenceRowPersistence occurrenceRowPersistence = new OccurrenceRowPersistence(getEntityManagerFactory(session));
@ -227,6 +362,13 @@ public class DaoSession {
}
/**
* Gets the taxon dao.
*
* @param session the session
* @return the taxon dao
* @throws Exception the exception
*/
public static TaxonRowPersistence getTaxonDAO(ASLSession session) throws Exception
{
@ -243,6 +385,13 @@ public class DaoSession {
return taxonDao;
}
/**
* Gets the taxonomy dao.
*
* @param session the session
* @return the taxonomy dao
* @throws Exception the exception
*/
public static TaxonomyRowPersistence getTaxonomyDAO(ASLSession session) throws Exception
{
logger.trace("In getTaxonomyDAO...");
@ -260,6 +409,14 @@ public class DaoSession {
return taxonItemDAO;
}
/**
* Inits the taxonomy item dao.
*
* @param session the session
* @param tableName the table name
* @return the taxonomy row persistence
* @throws Exception the exception
*/
private static TaxonomyRowPersistence initTaxonomyItemDao(ASLSession session, String tableName) throws Exception{
TaxonomyRowPersistence taxonomyRP = new TaxonomyRowPersistence(getEntityManagerFactory(session));
@ -268,6 +425,13 @@ public class DaoSession {
return taxonomyRP;
}
/**
* Gets the result row dao.
*
* @param session the session
* @return the result row dao
* @throws Exception the exception
*/
public static ResultRowPersistence getResultRowDAO(ASLSession session) throws Exception
{

View File

@ -0,0 +1,257 @@
package org.gcube.portlets.user.speciesdiscovery.server.persistence.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.gcube.portlets.user.speciesdiscovery.shared.DatabaseServiceException;
import org.gcube.portlets.user.speciesdiscovery.shared.GisLayerJob;
/**
* The Class GisLayerJobPersistence.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class GisLayerJobPersistence extends AbstractPersistence<GisLayerJob>{
/**
* Instantiates a new gis layer job persistence.
*
* @param factory the factory
*/
public GisLayerJobPersistence(EntityManagerFactory factory) {
super(factory);
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#removeAll()
*/
@Override
public int removeAll() throws DatabaseServiceException {
EntityManager em = super.createNewManager();
int removed = 0;
try {
em.getTransaction().begin();
removed = em.createQuery("DELETE FROM "+GisLayerJob.class.getSimpleName()).executeUpdate();
em.getTransaction().commit();
logger.trace("DELETED FROM "+GisLayerJob.class.getSimpleName()+" " + removed +" items");
} catch (Exception e) {
logger.error("Error in removeAll: " + e.getMessage(), e);
} finally {
em.close();
}
return removed;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#getList()
*/
@Override
public List<GisLayerJob> getList() throws DatabaseServiceException {
EntityManager em = super.createNewManager();
List<GisLayerJob> listGisLayerJob = new ArrayList<GisLayerJob>();
try {
Query query = em.createQuery("select t from "+GisLayerJob.class.getSimpleName()+ " t");
listGisLayerJob = query.getResultList();
} catch (Exception e) {
logger.error("Error in "+GisLayerJob.class.getSimpleName()+" - getList: " + e.getMessage(), e);
} finally {
em.close();
}
return listGisLayerJob;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#countItems()
*/
@Override
public int countItems() throws DatabaseServiceException {
return getList().size();
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#getItemByKey(java.lang.Integer)
*/
@Override
public GisLayerJob getItemByKey(Integer id) throws DatabaseServiceException {
logger.trace("getItemByKey id: "+id);
EntityManager em = super.createNewManager();
GisLayerJob gisLayerJob = null;
try {
gisLayerJob = em.getReference(GisLayerJob.class, id);
} finally {
em.close();
}
if(gisLayerJob!=null)
logger.trace("getItemByKey return row: "+gisLayerJob.getId());
else
logger.trace("getItemByKey return null");
//FOR DEBUG
// System.out.println("getItemByKey return: "+row );
return gisLayerJob;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#executeCriteriaQuery(javax.persistence.criteria.CriteriaQuery)
*/
@Override
public List<GisLayerJob> executeCriteriaQuery(CriteriaQuery<Object> criteriaQuery) throws DatabaseServiceException {
EntityManager em = super.createNewManager();
List<GisLayerJob> listOJ = new ArrayList<GisLayerJob>();
try {
Query query = em.createQuery(criteriaQuery);
listOJ = query.getResultList();
} finally {
em.close();
}
return listOJ;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#getCriteriaBuilder()
*/
@Override
public CriteriaBuilder getCriteriaBuilder() throws DatabaseServiceException {
return createNewManager().getCriteriaBuilder();
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#rootFrom(javax.persistence.criteria.CriteriaQuery)
*/
@Override
public Root<GisLayerJob> rootFrom(CriteriaQuery<Object> cq) {
return cq.from(GisLayerJob.class);
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#getList(int, int)
*/
@Override
public List<GisLayerJob> getList(int startIndex, int offset) throws DatabaseServiceException {
EntityManager em = super.createNewManager();
List<GisLayerJob> listOJ = new ArrayList<GisLayerJob>();
try {
Query query = em.createQuery("select t from "+GisLayerJob.class.getSimpleName()+" t");
query.setFirstResult(startIndex);
query.setMaxResults(offset);
listOJ = query.getResultList();
} finally {
em.close();
}
return listOJ;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#getList(java.util.Map, int, int)
*/
@Override
public List<GisLayerJob> getList(Map<String, String> filterMap, int startIndex, int offset) throws DatabaseServiceException{
EntityManager em = super.createNewManager();
List<GisLayerJob> listOJ = new ArrayList<GisLayerJob>();
try {
String queryString = "select t from "+GisLayerJob.class.getSimpleName()+" t";
if(filterMap!=null && filterMap.size()>0){
queryString+=" where ";
for (String param : filterMap.keySet()) {
String value = filterMap.get(param);
queryString+=" t."+param+"="+value;
queryString+=AND;
}
queryString = queryString.substring(0, queryString.lastIndexOf(AND));
}
Query query = em.createQuery(queryString);
if(startIndex>-1)
query.setFirstResult(startIndex);
if(offset>-1)
query.setMaxResults(offset);
listOJ = query.getResultList();
} finally {
em.close();
}
return listOJ;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#executeTypedQuery(javax.persistence.criteria.CriteriaQuery, int, int)
*/
@Override
public List<GisLayerJob> executeTypedQuery(CriteriaQuery<Object> cq, int startIndex, int offset) throws DatabaseServiceException {
EntityManager em = super.createNewManager();
List<GisLayerJob> listOJ = new ArrayList<GisLayerJob>();
try {
TypedQuery typedQuery = em.createQuery(cq);
if(startIndex>-1)
typedQuery.setFirstResult(startIndex);
if(offset>-1)
typedQuery.setMaxResults(offset);
listOJ = typedQuery.getResultList();
} finally {
em.close();
}
return listOJ;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.AbstractPersistence#deleteItemByIdField(java.lang.String)
*/
@Override
public int deleteItemByIdField(String idField) throws DatabaseServiceException{
EntityManager em = super.createNewManager();
int removed = 0;
try {
em.getTransaction().begin();
removed = em.createQuery("DELETE FROM "+GisLayerJob.class.getSimpleName()+" t WHERE t."+GisLayerJob.ID_FIELD+"='"+idField+"'").executeUpdate();
em.getTransaction().commit();
logger.trace("Item "+ idField + " was deleted from "+GisLayerJob.class.getSimpleName());
} catch (Exception e) {
logger.error("Error in "+GisLayerJob.class.getSimpleName()+" deleteItemByIdField: " + e.getMessage(), e);
e.printStackTrace();
} finally {
em.close();
}
return removed;
}
}

View File

@ -18,6 +18,7 @@ import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.gcube.data.spd.client.plugins.AbstractPlugin;
import org.gcube.data.spd.client.proxies.ClassificationClient;
import org.gcube.data.spd.client.proxies.ExecutorClient;
import org.gcube.data.spd.client.proxies.ManagerClient;
@ -32,10 +33,11 @@ import org.gcube.data.spd.model.products.TaxonomyItem;
import org.gcube.data.spd.model.service.exceptions.InvalidIdentifierException;
import org.gcube.data.spd.model.service.exceptions.UnsupportedPluginException;
import org.gcube.data.spd.model.service.types.CompleteJobStatus;
import org.gcube.data.spd.model.service.types.MetadataDetails;
import org.gcube.data.spd.model.util.Capabilities;
import org.gcube.data.streams.Stream;
import org.gcube.data.streams.dsl.Streams;
import org.gcube.portlets.user.speciesdiscovery.server.stream.CloseableIterator;
import org.gcube.portlets.user.speciesdiscovery.server.stream.IteratorPointInfo;
import org.gcube.portlets.user.speciesdiscovery.server.util.StorageUtil;
import org.gcube.portlets.user.speciesdiscovery.shared.Coordinate;
import org.gcube.portlets.user.speciesdiscovery.shared.DataSourceCapability;
@ -466,21 +468,26 @@ public class SpeciesService {
}
}
/**
* Generate map from occurrence points.
* Generate map from occurrence keys.
*
* @param streamKey
* the stream key
* @param occurrenceKeys the occurrence keys
* @param layerTitle the layer title
* @param layerDescr the layer descr
* @param author the author
* @param credits the credits
* @return the string
* @throws SearchServiceException
* the search service exception
* @throws SearchServiceException the search service exception
*/
public String generateMapFromOccurrencePoints(IteratorPointInfo streamKey)
throws SearchServiceException {
public String generateMapFromOccurrenceKeys(List<String> occurrenceKeys, String layerTitle, String layerDescr, String author, String credits) throws SearchServiceException {
try {
// Stream<String> keysStream = convert(keys);
return occurrencesCall.createLayer(streamKey);
ExecutorClient creator = AbstractPlugin.executor().build();
Stream<String> keyStream = Streams.convert(occurrenceKeys);
MetadataDetails details= new MetadataDetails(layerTitle, layerDescr, layerTitle, author, credits);
return creator.createLayer(keyStream, details);
}
catch (Exception e) {
logger.error(

View File

@ -12,17 +12,30 @@ import org.gcube.data.streams.Stream;
import org.gcube.portlets.user.speciesdiscovery.shared.Occurrence;
import org.gcube.portlets.user.speciesdiscovery.shared.util.NormalizeString;
/**
* The Class IteratorPointInfo.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class IteratorPointInfo implements Stream<PointInfo> {
protected Logger logger = Logger.getLogger(IteratorPointInfo.class);
private Iterator<Occurrence> iterator;
// protected Logger logger = Logger.getLogger(IteratorCoordinate.class);
/**
* Instantiates a new iterator point info.
*
* @param iterator the iterator
*/
public IteratorPointInfo(Iterator<Occurrence> iterator) {
this.iterator = iterator;
}
/* (non-Javadoc)
* @see org.gcube.data.streams.Stream#hasNext()
*/
@Override
public boolean hasNext() {
if (iterator.hasNext())
@ -30,104 +43,117 @@ public class IteratorPointInfo implements Stream<PointInfo> {
return false;
}
/* (non-Javadoc)
* @see org.gcube.data.streams.Stream#next()
*/
@Override
public PointInfo next() {
Occurrence occrs = iterator.next();
// Coordinate coordinate = null;
// Coordinate coordinate = null;
PointInfo pointInfo = null;
if (occrs != null){
logger.trace("get occurences id "+occrs.getServiceId());
Double decimalLatitude = null;
Double decimalLongitude = null;
try{
decimalLatitude = Double.valueOf(occrs.getDecimalLatitude());
decimalLongitude = Double.valueOf(occrs.getDecimalLongitude());
}
catch (Exception e) {
logger.error("error in get coordinate return null");
return null;
}
// coordinate = new Coordinate(decimalLatitude,decimalLongitude);
pointInfo = new PointInfo(decimalLongitude, decimalLatitude);
// LinkedHashMap<String, String> listMetaData = new LinkedHashMap<String, String>();
List<KeyValue> listMetaData = new ArrayList<KeyValue>();
listMetaData.add(new KeyValue(Occurrence.BASIS_OF_RECORD, NormalizeString.validateUndefined(occrs.getBasisOfRecord())));
listMetaData.add(new KeyValue(Occurrence.CATALOGUE_NUMBER, NormalizeString.validateUndefined(occrs.getCatalogueNumber())));
listMetaData.add(new KeyValue(Occurrence.CITATION, NormalizeString.validateUndefined(occrs.getCitation())));
listMetaData.add(new KeyValue(Occurrence.COLLECTION_CODE, NormalizeString.validateUndefined(occrs.getCollectionCode())));
listMetaData.add(new KeyValue(Occurrence.COORDINATE_INMETERS, NormalizeString.validateUndefined(occrs.getCoordinateUncertaintyInMeters())));
listMetaData.add(new KeyValue(Occurrence.COUNTRY, NormalizeString.validateUndefined(occrs.getCountry())));
listMetaData.add(new KeyValue(Occurrence.DATAPROVIDER, NormalizeString.validateUndefined(occrs.getDataProvider())));
listMetaData.add(new KeyValue(Occurrence.DATASET, NormalizeString.validateUndefined(occrs.getDataSet())));
listMetaData.add(new KeyValue(Occurrence.SCIENTIFICNAMEAUTHORSHIP, NormalizeString.validateUndefined(occrs.getScientificNameAuthorship())));
listMetaData.add(new KeyValue(Occurrence.LSID, NormalizeString.validateUndefined(occrs.getLsid())));
listMetaData.add(new KeyValue(Occurrence.CREDITS, NormalizeString.validateUndefined(occrs.getCredits())));
listMetaData.add(new KeyValue(Occurrence.DATASOURCE, NormalizeString.validateUndefined(occrs.getDataSource())));
listMetaData.add(new KeyValue(Occurrence.EVENT_DATE, NormalizeString.validateUndefined(occrs.getEventDate())));
listMetaData.add(new KeyValue(Occurrence.FAMILY, NormalizeString.validateUndefined(occrs.getFamily())));
listMetaData.add(new KeyValue(Occurrence.ID_FIELD, NormalizeString.validateUndefined(""+occrs.getId())));
listMetaData.add(new KeyValue(Occurrence.INSTITUTE_CODE, NormalizeString.validateUndefined(occrs.getInstitutionCode())));
listMetaData.add(new KeyValue(Occurrence.LOCALITY, NormalizeString.validateUndefined(occrs.getLocality())));
listMetaData.add(new KeyValue(Occurrence.MAX_DEPTH, NormalizeString.validateUndefined(occrs.getMaxDepth())));
listMetaData.add(new KeyValue(Occurrence.MIN_DEPTH, NormalizeString.validateUndefined(occrs.getMinDepth())));
listMetaData.add(new KeyValue(Occurrence.MODIFIED, NormalizeString.validateUndefined(occrs.getModified())));
listMetaData.add(new KeyValue(Occurrence.RECORD_BY, NormalizeString.validateUndefined(occrs.getRecordedBy())));
listMetaData.add(new KeyValue(Occurrence.SCIENTIFICNAME, NormalizeString.validateUndefined(occrs.getScientificName())));
listMetaData.add(new KeyValue(Occurrence.DECIMAL_LATITUDE, decimalLatitude+""));
listMetaData.add(new KeyValue(Occurrence.DECIMAL_LONGITUDE, decimalLongitude+""));
// pointInfo.setPropertiesMap(listMetaData);
pointInfo.setPropertiesList(listMetaData);
logger.trace("create new object point info lat: "+decimalLatitude +" long: "+decimalLongitude);
return pointInfo;
}
logger.trace("get occurences null - return null");
return null;
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
iterator.remove();
// throw new UnsupportedOperationException();
}
/**
* Iterator.
*
* @return the iterator
*/
public Iterator<PointInfo> iterator() {
return this;
}
/* (non-Javadoc)
* @see org.gcube.data.streams.Stream#close()
*/
@Override
public void close() {
}
/* (non-Javadoc)
* @see org.gcube.data.streams.Stream#locator()
*/
@Override
public URI locator() throws IllegalStateException {
return null;
}
/* (non-Javadoc)
* @see org.gcube.data.streams.Stream#isClosed()
*/
@Override
public boolean isClosed() {
return false;
}
}

View File

@ -0,0 +1,223 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.shared;
import java.io.Serializable;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class DefaultJob implements Serializable{
/**
*
*/
private static final long serialVersionUID = -4448201743475516557L;
public final static String ID_FIELD = "id";
public final static String NAME = "name";
public final static String DESCRIPTION = "description";
public final static String STARTTIME = "startTime";
public final static String SUBMITTIME = "submitTime";
public final static String ENDTIME = "endTime";
public static final String STATE = "state";
protected String id;
protected String name;
protected long startTime;
protected long submitTime;
protected long endTime;
protected String description;
protected String state;
/**
*
*/
public DefaultJob() {
}
/**
* Instantiates a new default job.
*
* @param id the id
* @param name the name
* @param startTime the start time
* @param submitTime the submit time
* @param endTime the end time
* @param description the description
* @param state the state
*/
public DefaultJob(
String id, String name, long startTime, long submitTime, long endTime,
String description, String state) {
this.id = id;
this.name = name;
this.startTime = startTime;
this.submitTime = submitTime;
this.endTime = endTime;
this.description = description;
this.state = state;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the startTime
*/
public long getStartTime() {
return startTime;
}
/**
* @return the submitTime
*/
public long getSubmitTime() {
return submitTime;
}
/**
* @return the endTime
*/
public long getEndTime() {
return endTime;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param startTime the startTime to set
*/
public void setStartTime(long startTime) {
this.startTime = startTime;
}
/**
* @param submitTime the submitTime to set
*/
public void setSubmitTime(long submitTime) {
this.submitTime = submitTime;
}
/**
* @param endTime the endTime to set
*/
public void setEndTime(long endTime) {
this.endTime = endTime;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DefaultJob [id=");
builder.append(id);
builder.append(", name=");
builder.append(name);
builder.append(", startTime=");
builder.append(startTime);
builder.append(", submitTime=");
builder.append(submitTime);
builder.append(", endTime=");
builder.append(endTime);
builder.append(", description=");
builder.append(description);
builder.append(", state=");
builder.append(state);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.shared;
import javax.persistence.Entity;
/**
* The Class GisLayerJob.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
@Entity
public class GisLayerJob extends DefaultJob{
/**
*
*/
private static final long serialVersionUID = 2604265579184366453L;
/**
* Instantiates a new gis layer job.
*/
public GisLayerJob() {
}
/**
* Instantiates a new gis layer job.
*
* @param id the id
* @param name the name
* @param startTime the start time
* @param submitTime the submit time
* @param endTime the end time
* @param description the description
* @param state the state
*/
public GisLayerJob(
String id, String name, long startTime, long submitTime, long endTime,
String description, String state) {
super(id, name, startTime, submitTime, endTime, description, state);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return super.toString();
}
}

View File

@ -0,0 +1,61 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.shared;
/**
* The Class JobGisLayerModel.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 9, 2017
*/
public class JobGisLayerModel extends DefaultJob{
/**
*
*/
private static final long serialVersionUID = 8754068044391917378L;
/**
* Instantiates a new gis layer job.
*/
public JobGisLayerModel() {
}
/**
* Instantiates a new gis layer job.
*
* @param id the id
* @param name the name
* @param startTime the start time
* @param submitTime the submit time
* @param endTime the end time
* @param description the description
* @param state the state
*/
public JobGisLayerModel(
String id, String name, long startTime, long submitTime, long endTime,
String description, String state) {
super(id, name, startTime, submitTime, endTime, description, state);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return super.toString();
}
}