diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/PerformFishAnalytics.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/PerformFishAnalytics.java index 6883abe..dc888c9 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/PerformFishAnalytics.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/PerformFishAnalytics.java @@ -1,9 +1,22 @@ package org.gcube.portlets.user.performfishanalytics.client; +import java.util.HashMap; +import java.util.Map; + +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.POPULATION_LEVEL; +import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsController; import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadPopulationTypeEvent; +import org.gcube.portlets.user.performfishanalytics.client.view.util.DecodeParameterUtil; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter; import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; /** * Entry point classes define onModuleLoad(). @@ -15,6 +28,102 @@ public class PerformFishAnalytics implements EntryPoint { */ public void onModuleLoad() { - new PerformFishAnalyticsController(); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + + Map initParams = new HashMap(); + for (String key : Window.Location.getParameterMap().keySet()) { + try { + String dKeY = DecodeParameterUtil.base64Decode(key); + String eValue = Window.Location.getParameter(key); + String dParam = DecodeParameterUtil.base64Decode(eValue); + initParams.put(dKeY, dParam); + } catch (Exception e) { + GWT.log("Error: "+e.getMessage()); + } + } + + GWT.log("Decoded parameters: "+initParams); + + + final String farmidParam = initParams.get(PerformFishAnalyticsConstant.QUERY_STRING_FARMID_PARAM); + + if(farmidParam==null || farmidParam.isEmpty()){ + Window.alert("Error: no '"+PerformFishAnalyticsConstant.QUERY_STRING_FARMID_PARAM+"' param detected"); + return; + } + + final String annual = initParams.get(PerformFishAnalyticsConstant.QUERY_STRING_ANNUAL_PARAMETER); + + boolean isAnnualCall = false; + + try { + isAnnualCall = Boolean.parseBoolean(annual); + GWT.log("Read decoded isAnnual at: "+isAnnualCall); + }catch (Exception e) { + GWT.log("Forcing isAnnual at TRUE"); + isAnnualCall = false; + } + + String batchtypeParam = initParams.get(PerformFishAnalyticsConstant.QUERY_STRING_BATCHTYPE_PARAM); + + //IS ANNUAL CALL + if(isAnnualCall) { + + //CALLING THE PORTLET WITH ANNUAL CONFIGURATION + batchtypeParam = PerformFishAnalyticsConstant.BATCH_LEVEL.GROW_OUT_AGGREGATED_CLOSED_BATCHES.name(); + GWT.log("Hard cabling batchtypeParam as: "+batchtypeParam); + + PerformFishInitParameter performFishInitParams = new PerformFishInitParameter(); + performFishInitParams.addParameter(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM, batchtypeParam); + performFishInitParams.addParameter(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM, farmidParam); + + PerformFishAnalyticsServiceAsync.Util.getInstance().validParameters(performFishInitParams, new AsyncCallback() { + + @Override + public void onSuccess(PerformFishInitParameter result) { + PerformFishAnnualAnalyticsController controller = new PerformFishAnnualAnalyticsController(); + controller.setInitParmaters(result); + PerformFishAnnualAnalyticsController.eventBus.fireEvent(new LoadPopulationTypeEvent(POPULATION_LEVEL.FARM.name(), null)); + } + + @Override + public void onFailure(Throwable caught) { + + Window.alert(caught.getMessage()); + } + }); + + }else { + + //CALLING THE PORTLET WITHOUT ANNUAL CONFIGURATION + if(batchtypeParam==null || batchtypeParam.isEmpty()){ + Window.alert("Error: no '"+PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM+"' param detected"); + return; + } + + PerformFishInitParameter performFishInitParams = new PerformFishInitParameter(); + performFishInitParams.addParameter(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM, batchtypeParam); + performFishInitParams.addParameter(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM, farmidParam); + + PerformFishAnalyticsServiceAsync.Util.getInstance().validParameters(performFishInitParams, new AsyncCallback() { + + @Override + public void onSuccess(PerformFishInitParameter result) { + PerformFishAnalyticsController controller = new PerformFishAnalyticsController(); + controller.setInitParmaters(result); + PerformFishAnalyticsController.eventBus.fireEvent(new LoadPopulationTypeEvent(POPULATION_LEVEL.BATCH.name(), null)); + } + + @Override + public void onFailure(Throwable caught) { + + Window.alert(caught.getMessage()); + } + }); + } + } + }); } } diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java new file mode 100644 index 0000000..d367694 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java @@ -0,0 +1,679 @@ +/** + * + */ +package org.gcube.portlets.user.performfishanalytics.client.annualcontrollers; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.POPULATION_LEVEL; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync; +import org.gcube.portlets.user.performfishanalytics.client.event.AddedBatchIdEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.AddedBatchIdEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.CallAlgorithmEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.CallAlgorithmEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadBatchesEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadBatchesEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadPopulationTypeEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadPopulationTypeEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.PerformFishFieldFormChangedEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.PerformFishFieldFormChangedEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.SelectedKPIEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.SelectedKPIEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulationTypeEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulationTypeEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler; +import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel; +import org.gcube.portlets.user.performfishanalytics.shared.KPI; +import org.gcube.portlets.user.performfishanalytics.shared.OutputFile; +import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile; +import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.Tab; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.ComplexPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Panel; +import com.google.gwt.user.client.ui.VerticalPanel; + + +// TODO: Auto-generated Javadoc +/** + * The Class PerformFishAnalyticsController. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 16, 2019 + */ +public class PerformFishAnnualAnalyticsController { + + /** The Constant eventBus. */ + + public final static HandlerManager eventBus = new HandlerManager(null); + + /** The view controller. */ + private PerformFishAnnualAnalyticsViewController viewAnnualController; + + /** The decrypt parameters. */ + private PerformFishInitParameter decryptParameters; + + + /** + * Instantiates a new perform fish analytics controller. + */ + public PerformFishAnnualAnalyticsController() { + + registerHandlers(); + } + + /** + * Sets the inits the parmaters. + * + * @param result the new inits the parmaters + */ + public void setInitParmaters(PerformFishInitParameter result) { + this.decryptParameters = result; + viewAnnualController = new PerformFishAnnualAnalyticsViewController(); + } + + + /** + * Register handlers. + */ + private void registerHandlers() { + + eventBus.addHandler(LoadPopulationTypeEvent.TYPE, new LoadPopulationTypeEventHandler() { + + @Override + public void onLoadPopulationType( + LoadPopulationTypeEvent loadPopulationEvent) { + + viewAnnualController.loadPopulationTypeForLevelAndBatchType(loadPopulationEvent.getPopulationName(), decryptParameters); + + } + }); + + eventBus.addHandler(CallAlgorithmEvent.TYPE, new CallAlgorithmEventHandler() { + + @Override + public void onCall(CallAlgorithmEvent callAlgorithmEvent) { + + callAlgorithm(callAlgorithmEvent.getAlgorithm(), callAlgorithmEvent.getFocusID(), callAlgorithmEvent.getInputKPI(), callAlgorithmEvent.getOutputKPI()); + } + }); + + eventBus.addHandler(SelectedPopulationTypeEvent.TYPE, new SelectedPopulationTypeEventHandler() { + + @Override + public void onSelectedPopulationType( + SelectedPopulationTypeEvent selectedPopulationTypeEvent) { + + viewAnnualController.setRootPopulationTypeForKPIs(selectedPopulationTypeEvent.getSelectedPopulationType()); + } + }); + + eventBus.addHandler(SelectedKPIEvent.TYPE, new SelectedKPIEventHandler() { + + @Override + public void onSelectedKPI(SelectedKPIEvent selectedKPI) { + GWT.log("Selected KPI: "+selectedKPI); + viewAnnualController.manageKPI(selectedKPI.getKpi(), selectedKPI.isChecked(), selectedKPI.getSelectedPopulationType()); + eventBus.fireEvent(new PerformFishFieldFormChangedEvent(null)); + + //viewController.manageAlgorithmsSubmit(selectedKPIsSize); +// List batchIds = viewController.getSelectedBatchID(); +// if(batchIds==null || batchIds.size()==0) { +// viewController.enableAllAlgorithmsForSubmit(false); +// }else + + //viewController.manageAlgorithmsSubmit(selectedKPIsSize); + } + }); + + eventBus.addHandler(LoadBatchesEvent.TYPE, new LoadBatchesEventHandler() { + + @Override + public void onLoadBatches(LoadBatchesEvent loadBatchesEvent) { + + viewAnnualController.hideErrors(); + + final Map> mapParameters = new HashMap>(); + String farmId = decryptParameters.getParameters().get(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM); + String batchType = viewAnnualController.getForm().getBatchType(); + + List listYear = viewAnnualController.getForm().getYear(); + + mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM, Arrays.asList(farmId)); + mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM, Arrays.asList(batchType)); + + if(!listYear.isEmpty()){ + mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_QUARTER_PARAM, listYear); + } + + final Modal modal = new Modal(true); + modal.setCloseVisible(false); + modal.hide(false); + final VerticalPanel vp = new VerticalPanel(); + LoaderIcon loader = new LoaderIcon("Loading batch(es) from PerformFish service, please wait..."); + vp.add(loader); + loader.show(true); + modal.add(vp); + PerformFishAnalyticsServiceAsync.Util.getInstance().submitRequestToPerformFishService(mapParameters, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + modal.hide(); + Window.alert(caught.getMessage()); + } + + @Override + public void onSuccess(PerformFishResponse performFishResponse) { + modal.hide(); + viewAnnualController.managePerformFishServiceResponse(performFishResponse, mapParameters, POPULATION_LEVEL.BATCH); + } + }); + modal.show(); + + } + }); + + + eventBus.addHandler(PerformFishFieldFormChangedEvent.TYPE, new PerformFishFieldFormChangedEventHandler() { + + @Override + public void onFieldFormChanged( + PerformFishFieldFormChangedEvent performFishFieldFormChangedEvent) { + + viewAnnualController.setReloadPerformFishServiceData(true); + boolean isValidForm = viewAnnualController.validatePerformFishInputFields(); + + //viewController.resetBatchIdStatus(); + + if(isValidForm) { + //boolean isKPIsSelected = viewAnnualController.validateKPIFields(); + int selectedKPIsSize = viewAnnualController.getSelectedKPIs().size(); + if(selectedKPIsSize>0) { + viewAnnualController.enableAllAlgorithmsForSubmit(true); + }else + viewAnnualController.enableAllAlgorithmsForSubmit(false); + + }else { + //viewController.enableLoadBatches(false); + viewAnnualController.enableAllAlgorithmsForSubmit(false); + } + } + }); + + eventBus.addHandler(AddedBatchIdEvent.TYPE, new AddedBatchIdEventHandler() { + + @Override + public void onAddedBatchId(AddedBatchIdEvent checkValidBatchIdEvent) { + + boolean isBatchIdValid = viewAnnualController.validateBatchIdSelection(); + if(isBatchIdValid) + viewAnnualController.enableAllAlgorithmsForSubmit(true); + else + viewAnnualController.enableAllAlgorithmsForSubmit(false); + + //viewController.resyncSelectedKPIs(); + } + }); + + + eventBus.addHandler(SubmitRequestEvent.TYPE, new SubmitRequestEventHandler() { + + @Override + public void onSubmitRequest(SubmitRequestEvent submitRequestEvent) { + + boolean isValidBatchId = viewAnnualController.validateBatchIdSelection(); + + boolean isValidKPI = viewAnnualController.validateKPIFields(); + + List selectedKPI = viewAnnualController.getSelectedKPIs(); + viewAnnualController.manageAlgorithmsSubmit(selectedKPI.size()); + + if(isValidBatchId && isValidKPI){ + + switch (submitRequestEvent.getChartType()) { + + case BOXPLOT: + //UNARY + //callAlgorithm(submitRequestEvent.getChartType(), viewController.getSelectedBatchID().get(0), selectedKPI, null); + break; + + case SCATTER: +// if(selectedKPI.size()==2) +// callAlgorithm(submitRequestEvent.getChartType(), viewController.getSelectedBatchID().get(0), selectedKPI, null); +// else +// Window.alert("Something seems wrong... You must select exactly two KPIs to execute the "+submitRequestEvent.getChartType()); + break; + + case CORRELATION: + //callDataMinerServiceForChartTypeCorrelation(viewController.getPerformFishResponse(), viewController.getRequestMapParameters()); + break; + + case SPEEDOMETER: + //UNARY + //callAlgorithm(submitRequestEvent.getChartType(), viewController.getSelectedBatchID().get(0), selectedKPI, selectedKPI); + break; + + default: + break; + } + + } + + return; + } + }); + + } + + /** + * Call data miner service for chart type correlation. + * + * @param performFishResponse the perform fish response + * @param performFishRequestParameters the perform fish request parameters + */ + private void callDataMinerServiceForChartTypeCorrelation(final PerformFishResponse performFishResponse, final Map> performFishRequestParameters) { + + GWT.log("Read perform fish response: "+performFishResponse); + + String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE); + + if(batchTableURL==null || batchTableURL.isEmpty()) + Window.alert("Something seems wrong. No batches tables matching with parameter "+PerformFishAnalyticsConstant.BATCHES_TABLE+" returned from service"); + + final Map> mapParameters = new HashMap>(); + + StringBuilder dataInputsFormatter = new StringBuilder(); + + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM+"=BATCH;"); + String theBatchType = viewAnnualController.getForm().getBatchType(); + theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); //REMOVING SUFFIX _CLOSED_BATCHES FOR DATAMINER CALL + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM+"="+theBatchType+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM+"="+ DataMinerAlgorithms.CORRELATION+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM+"="+batchTableURL+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;"); + + String kpiCodes = ""; + for (KPI kpi : viewAnnualController.getSelectedKPIs()) { + kpiCodes+=kpi.getCode()+"|"; + } + //remove last | + kpiCodes = kpiCodes.substring(0, kpiCodes.length()-1); + dataInputsFormatter.append("inputKPI="+kpiCodes+";"); + //dataInputsFormatter.append("outputKPI=;"); + + String dataInParameters = dataInputsFormatter.toString(); + GWT.log("Calling DM service with client input parameters: "+dataInParameters); + + mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters)); + + final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1); + submitRequestPanel.showLoader(true, "Submitting "+DataMinerAlgorithms.CORRELATION.getName()+" request to DM Service..."); + String tabTitle = DataMinerAlgorithms.CORRELATION.getName().substring(0,1).toUpperCase()+DataMinerAlgorithms.CORRELATION.getName().toLowerCase().substring(1, DataMinerAlgorithms.CORRELATION.getName().length()); //CAMEL CASE + final Tab tab = viewAnnualController.createTab(submitRequestPanel, tabTitle+" #"+(viewAnnualController.currentNumberOfTab()+1)); + + PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishCorrelationAnalysis(performFishResponse, mapParameters, new AsyncCallback() { + + @Override + public void onSuccess(DataMinerResponse dmResponse) { + submitRequestPanel.showLoader(false, null); + checkTabSpinner(submitRequestPanel, tab); + AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult(); + analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM)); + analyticsPanelResult.addSelectedKPIs(viewAnnualController.getSelectedKPIs()); + + + + //TODO COMMENTED NOW + //analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); + + + + analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewAnnualController.getForm().getBatchType()); + analyticsPanelResult.addResults(dmResponse); + submitRequestPanel.addWidget(analyticsPanelResult); + //viewController.geTabPanelView().addResult(resultPanel, "Analysis #"+(viewController.geTabPanelView().countTab()+1)); + //modal.hide(); + } + + @Override + public void onFailure(Throwable caught) { + GWT.log(caught.toString()); + submitRequestPanel.showLoader(false, null); + checkTabSpinner(submitRequestPanel, tab); + try { + AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult(); + analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM)); + analyticsPanelResult.addSelectedKPIs(viewAnnualController.getSelectedKPIs()); + + //TODO COMMENTED NOW + //analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); + + + analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewAnnualController.getForm().getBatchType()); + submitRequestPanel.addWidget(analyticsPanelResult); + }catch (Exception e) { + // TODO: handle exception + } + + Alert error = new Alert(caught.getMessage()); + error.setClose(false); + error.setType(AlertType.ERROR); + submitRequestPanel.addWidget(error); + } + }); + } + + + /** + * Creating new TAB and calling DM algorithm. + * + * @param algorithm the algorithm + * @param focusID the focus id + * @param inputKPI the input kpi + * @param outputKPI the output kpi + */ + private void callAlgorithm(DataMinerAlgorithms algorithm, String focusID, List inputKPI, final List outputKPI){ + +// List listBatchID = viewController.getSelectedBatchID(); +// +// if(listBatchID==null || listBatchID.size()==0) +// Window.alert("Something seems wrong, no selected BatchID, try again"); + + SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1); + //submitRequestPanel.getElement().addClassName("ext-horizontal-panel"); + String tabTitle = algorithm.getName().substring(0,1).toUpperCase()+algorithm.getName().toLowerCase().substring(1, algorithm.getName().length()); //CAMEL CASE + Tab tab = viewAnnualController.createTab(submitRequestPanel, tabTitle+" #"+(viewAnnualController.currentNumberOfTab()+1)); + + switch (algorithm) { + case BOXPLOT: + case SPEEDOMETER: + + submitRequestPanel.setTotalRequests(inputKPI.size()); + for (KPI kpi : inputKPI) { + String title = "KPI: "+kpi.getName(); + HTML toBigTitle = new HTML(title); + toBigTitle.getElement().addClassName("to-big-title"); + submitRequestPanel.addWidget(toBigTitle); + HorizontalPanel hp = new HorizontalPanel(); + hp.getElement().addClassName("ext-horizontal-panel"); + callDataMinerServiceForChart(viewAnnualController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, Arrays.asList(kpi), Arrays.asList(kpi), algorithm, focusID, submitRequestPanel, hp, tab); + //resultPanel.add(hp); + submitRequestPanel.addWidget(hp); + } + break; + case SCATTER: + + if(inputKPI.get(0)==null || inputKPI.get(1)==null){ + submitRequestPanel.setTheTitle("Sorry, something seems wrong, the selected KPIs are not valid. Please try again"); + checkTabSpinner(submitRequestPanel, tab); + return; +// Window.alert("Something seems wrong, no selected BatchID, try again"); + } + + String titleScatter = "KPI: "+inputKPI.get(0).getName() +" vs "+inputKPI.get(1).getName(); + submitRequestPanel.setTheTitle(titleScatter); + + default: + callDataMinerServiceForChart(viewAnnualController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, inputKPI, outputKPI, algorithm, focusID, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab); + } + } + + + /** + * Call data miner service for chart. + * + * @param performFishResponse the perform fish response + * @param scalePValue the scale p value + * @param inputKPI the input kpi + * @param outputKPI the output kpi + * @param chartType the chart type + * @param focusID the focus id + * @param requestPanel the request panel + * @param panelContainer the panel + * @param tab the tab + */ + private void callDataMinerServiceForChart(PerformFishResponse performFishResponse, POPULATION_LEVEL scalePValue, final List inputKPI, final List outputKPI, final DataMinerAlgorithms chartType, final String focusID, final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab) { + + GWT.log("Read perform fish response: "+performFishResponse); + + String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE); + + if(batchTableURL==null || batchTableURL.isEmpty()) + Window.alert("Something seems wrong. No batches tables matching with parameter "+PerformFishAnalyticsConstant.BATCHES_TABLE+" returned from service"); + + + StringBuilder dataInputsFormatter = new StringBuilder(); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM+"="+scalePValue.name()+";"); + String theBatchType = viewAnnualController.getForm().getBatchType(); + theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); //REMOVING SUFFIX _CLOSED_BATCHES FOR DATAMINER CALL + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM+"="+theBatchType+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM+"="+ chartType +";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM+"="+batchTableURL+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"="+focusID+";"); + //dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;"); + + if(inputKPI!=null && inputKPI.size()>0){ + String kpiCodes = ""; + for (KPI kpi : inputKPI) { + kpiCodes+=kpi.getCode()+"|"; + } + //remove last | + kpiCodes = kpiCodes.substring(0, kpiCodes.length()-1); + + GWT.log("Input KPICodes: "+kpiCodes); + //ADDING KPIs code + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM+"="+kpiCodes+";"); + + } + + if(outputKPI!=null && outputKPI.size()>0){ + String kpiCodes = ""; + for (KPI kpi : outputKPI) { + kpiCodes+=kpi.getCode()+"|"; + } + //remove last | + kpiCodes = kpiCodes.substring(0, kpiCodes.length()-1); + + GWT.log("Output KPICodes: "+kpiCodes); + //ADDING KPIs code + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM+"="+kpiCodes+";"); + + } + + String dataInParameters = dataInputsFormatter.toString(); + GWT.log("Calling DM service with client input parameters: "+dataInParameters); + + Map> mapParameters = new HashMap>(); + mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters)); + + final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to "+chartType+" Analysis..."); + loaderIcon.setVisible(true); + panelContainer.setVisible(true); + panelContainer.add(loaderIcon); + Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { + @Override + public void execute() { + loaderIcon.setFocus(true); + }}); + + PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnalysis(mapParameters, new AsyncCallback() { + + @Override + public void onSuccess(DataMinerResponse dmResponse) { + loaderIcon.setVisible(false); + checkTabSpinner(requestPanel, tab); + //field_unary_algorithm.setVisible(true); + GWT.log("I'm displaying: "+dmResponse); + displayOutputFilesAsStaticEntities(dmResponse, chartType, inputKPI, outputKPI, focusID, panelContainer, false); + } + + @Override + public void onFailure(Throwable caught) { + loaderIcon.setVisible(false); + checkTabSpinner(requestPanel, tab); + displayOutputFilesAsStaticEntities(null, chartType, inputKPI, outputKPI, focusID, panelContainer, true); + + } + }); + } + + /** + * Remove the spinner if all DM responses are returned. + * + * @param requestPanel the request panel + * @param tab the tab + */ + private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab){ + requestPanel.incrementCompletedRequests(); + int completed = requestPanel.getCompletedRequests(); + int total = requestPanel.getTotalRequests(); + + if(completed>=total) { + viewAnnualController.noSpinner(tab); + } + } + + /** + * Display output files as static entities. + * + * @param dmResponse the dm response + * @param chartType the chart type + * @param inputKPIs the input kp is + * @param outputKPIs the output kp is + * @param focusID the focus id + * @param container the container + * @param displayError the display error + */ + private void displayOutputFilesAsStaticEntities(DataMinerResponse dmResponse, final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID, final Panel container, boolean displayError){ + + String title = displayError?"No results ":""; + + if(displayError){ + Alert alert = new Alert(title); + alert.setType(AlertType.ERROR); + alert.setClose(false); + alert.getElement().getStyle().setMargin(10, Unit.PX); + container.add(alert); + return; + } + + final String toTitle = title; + + for (final OutputFile outputFile : dmResponse.getListOutput()) { + + switch (outputFile.getDataType()) { + case IMAGE: + PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + //showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + Window.alert(caught.getMessage()); + + } + + @Override + public void onSuccess(String base64Content) { + + String title = toTitle; + switch (chartType) { + case BOXPLOT: + title = chartType.getName()+" - on all batches
"; + title += "Blue dots indicate the selected batch(es): "+focusID; + break; + case CORRELATION: + break; + case DEA_ANALYSIS: + break; + case SCATTER: + break; + case SPEEDOMETER: + title = "Speedometer
"; + title+= "Selected BATCH ID: "+focusID+"
"; + title+= "Normalized with respect to all batches in the VRE"; + break; + case DEA_CHART: + break; + } + + ShowResult showResult = new ShowResult(title); + showResult.showImage(base64Content); + container.add(showResult); + + } + }); + break; + case CSV: + PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + //showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + Window.alert(caught.getMessage()); + } + + @Override + public void onSuccess(CSVFile result) { + GWT.log("Displaying: "+result); + + String title = toTitle; + switch (chartType) { + case BOXPLOT: + if(result.getFileName().contains("_user")){ + title = "My Batch(es)"; + }else{ + title = "All batches in the VRE (including mine)"; + } + break; + case CORRELATION: + break; + case DEA_ANALYSIS: + break; + case SCATTER: + break; + case SPEEDOMETER: + break; + case DEA_CHART: + break; + } + + ShowResult showResult = new ShowResult(title); + showResult.showCSVFile(result); + container.add(showResult); + } + }); + break; + + default: + break; + } + + } + + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsViewController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsViewController.java new file mode 100644 index 0000000..8fa0bfe --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsViewController.java @@ -0,0 +1,482 @@ +/** + * + */ +package org.gcube.portlets.user.performfishanalytics.client.annualcontrollers; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.POPULATION_LEVEL; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync; +import org.gcube.portlets.user.performfishanalytics.client.view.BaseDockLayoutPanel; +import org.gcube.portlets.user.performfishanalytics.client.view.BodyPanel; +import org.gcube.portlets.user.performfishanalytics.client.view.CustomTreeModel; +import org.gcube.portlets.user.performfishanalytics.client.view.HeaderPanel; +import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnnualListKPIView; +import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.PerformFishAnnualAnalitycsFormView; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.PortletTitle; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.RecapSubmitPage; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.TabPanelView; +import org.gcube.portlets.user.performfishanalytics.shared.KPI; +import org.gcube.portlets.user.performfishanalytics.shared.Population; +import org.gcube.portlets.user.performfishanalytics.shared.PopulationType; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishInitParameter; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; + +import com.github.gwtbootstrap.client.ui.Tab; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.cellview.client.CellTree; +import com.google.gwt.user.cellview.client.TreeNode; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +/** + * The Class PerformFishAnnualAnalyticsViewController. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * May 7, 2019 + */ +public class PerformFishAnnualAnalyticsViewController { + + /** The Constant PERFORM_FISH_ANALYTICS_DIV. */ + public static final String PERFORM_FISH_ANALYTICS_DIV = "perform-fish-analytics"; + + /** The base dock layout panel. */ + private BaseDockLayoutPanel baseDockLayoutPanel; + + /** The header page. */ + private HeaderPanel headerPage; + + /** The body page. */ + private BodyPanel bodyPage; + + /** The batch ID and list KPI. */ + private AnnualListKPIView annualListKPIView; + + /** The form. */ + private PerformFishAnnualAnalitycsFormView form; + + /** The selected population. */ + private Population selectedPopulation; + + /** The custom tree model. */ + private CustomTreeModel customTreeModel; + + /** The tree. */ + private CellTree tree; + + /** The west panel. */ + private VerticalPanel westPanel; + + /** The est panel. */ + private VerticalPanel estPanel; + + /** The recap page. */ + private RecapSubmitPage recapPage; + + /** The tab panel. */ + private TabPanelView tabPanel; + + /** The root panel. */ + private VerticalPanel rootPanel; + + /** The reload perform fish service data. */ + private boolean reloadPerformFishServiceData = true; + + /** + * Instantiates a new perform fish analytics view controller. + */ + public PerformFishAnnualAnalyticsViewController() { + initLayout(); + form = new PerformFishAnnualAnalitycsFormView(); + //customTreeModel = new CustomTreeModel(); + customTreeModel = new CustomTreeModel(PerformFishAnnualAnalyticsController.eventBus); + annualListKPIView = new AnnualListKPIView(); + tree = new CellTree(customTreeModel, null); + //tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); + westPanel.add(form); + //estPanel.add(recapPage); + //bodyPage.add(form); + //tree.setWidth("600px"); + //tree.setSize("600px", "800px"); + annualListKPIView.add(tree); + bodyPage.addWidget(annualListKPIView); + bodyPage.addWidget(recapPage); + } + + /** + * Inits the layout. + */ + private void initLayout(){ + rootPanel = new VerticalPanel(); + headerPage = new HeaderPanel(); + bodyPage = new BodyPanel(); + + baseDockLayoutPanel = new BaseDockLayoutPanel(Unit.PX); + headerPage.showLoading(true, "Loading Data...."); + westPanel = new VerticalPanel(); + estPanel = new VerticalPanel(); + recapPage = new RecapSubmitPage(); + tabPanel = new TabPanelView(); + + headerPage.add(new PortletTitle("PerformFISH Statistical Analysis")); + + //baseDockLayoutPanel.addNorth(headerPage, 60); + baseDockLayoutPanel.addWest(westPanel, 500); + //baseDockLayoutPanel.addEast(estPanel, 250); + baseDockLayoutPanel.add(bodyPage); + + tabPanel.getTabCreateRequestPanel().add(baseDockLayoutPanel); + + rootPanel.add(headerPage); + rootPanel.add(tabPanel); + RootPanel.get(PERFORM_FISH_ANALYTICS_DIV).add(rootPanel); + } + + + /** + * Creates the tab. + * + * @param w the w + * @param tabTitle the tab title + * @return the tab + */ + public Tab createTab(Widget w, String tabTitle){ + return tabPanel.addAsTab(w, tabTitle, true); + } + + + /** + * No spinner. + * + * @param tab the tab + */ + public void noSpinner(Tab tab){ + tabPanel.setNoSpinner(tab); + } + + + /** + * Current number of tab. + * + * @return the int + */ + public int currentNumberOfTab(){ + + return tabPanel.countTab(); + } + + + /** + * Gets the base panel. + * + * @return the basePanel + */ + public BaseDockLayoutPanel getBasePanel() { + + return baseDockLayoutPanel; + } + + + /** + * Load population type for level and batch type. + * + * @param populationName the population name + * @param decodedParameters the decoded parameters + */ + public void loadPopulationTypeForLevelAndBatchType(final String populationName, final PerformFishInitParameter decodedParameters){ + + PerformFishAnalyticsServiceAsync.Util.getInstance().getListPopulationType(populationName, new AsyncCallback>() { + + @Override + public void onSuccess(List result) { + + GWT.log("Loaded list of "+PopulationType.class.getSimpleName()+ ": "+result); + headerPage.showLoading(false); + + if(result.size()>0){ + String passedBatchType = decodedParameters.getParameters().get(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM); + for (PopulationType populationType : result) { + + if(populationType.getName().compareToIgnoreCase(passedBatchType)==0){ + GWT.log("Found the passed batch type: "+populationType); + selectedPopulation = result.get(0).getPopulation(); + form.addPopulationTypes(populationName, Arrays.asList(populationType), selectedPopulation); + } + } + }else{ + Window.alert("No batch type found for level: "+populationName); + } + } + + @Override + public void onFailure(Throwable caught) { + headerPage.showLoading(false); + String error = "Error on getting Population Type for population: "+populationName; + GWT.log(caught.getLocalizedMessage()); + Window.alert(error); + } + }); + + } + + + /** + * Sets the root population type for kp is. + * + * @param rootPopulationType the new root population type for kp is + */ + public void setRootPopulationTypeForKPIs(final PopulationType rootPopulationType) { + GWT.log("Set root: "+rootPopulationType); + //customTreeModel.addChildrenListKPI(rootPopulationType.getListKPI()); + + PerformFishAnalyticsServiceAsync.Util.getInstance().getPopulationTypeWithListKPI(rootPopulationType.getId(), new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + + Window.alert("Error on loading KPIs for population type: "+rootPopulationType.getName()); + + } + + @Override + public void onSuccess(PopulationType result) { + + TreeNode rootNode = tree.getRootTreeNode(); + customTreeModel.setNewBatchType(result); + // Open the first playlist by default. + + //firstPlaylist.setChildOpen(0, true); + + expandAllTreeNode(rootNode); + + //IT SHOULD BE AN EVENT + recapPage.removeAllSelected(); + + } + }); + + } + + /** + * Expand all tree node. + * + * @param rootNode the root node + */ + private void expandAllTreeNode(TreeNode rootNode) { + + if(rootNode==null || rootNode.getChildCount()==0) + return; + + for (int i=0; i0){ + if(selectedKPIsSize==1){ + recapPage.activeBoxPlot(true); + recapPage.activeSpeedometer(true); + }else if(selectedKPIsSize==2){ + recapPage.activeAllAlgorithms(true); + }else{ + //IS GREATER THAN 2 + recapPage.activeAllAlgorithms(true); + recapPage.activeScatterPlot(false); + } + + } + } + + + /** + * Enable all algorithms for submit. + * + * @param bool the bool + */ + public void enableAllAlgorithmsForSubmit(boolean bool){ + recapPage.activeAllAlgorithms(bool); + } + + + /** + * Manage perform fish service response. + * + * @param performFishResponse the perform fish response + * @param mapParameters the map parameters + * @param populationLevel the population level + */ + public void managePerformFishServiceResponse( + PerformFishResponse performFishResponse, + Map> mapParameters, POPULATION_LEVEL populationLevel) { + + annualListKPIView.managePerformFishServiceResponse(performFishResponse, mapParameters, populationLevel); + + } + + + /** + * Gets the perform fish response. + * + * @return the perform fish response + */ + public PerformFishResponse getPerformFishResponse() { + + return annualListKPIView.getPerformFishResponse(); + } + + + /** + * Gets the map parameters. + * + * @return the map parameters + */ + public Map> getRequestMapParameters() { + + return annualListKPIView.getMapParameters(); + } + + + /** + * Validate kpi fields. + * + * @return true, if successful + */ + public boolean validateKPIFields() { + + bodyPage.hideError(); + List selectedKPIs = recapPage.getSelectedKPIs(); + if(selectedKPIs.size()<1){ + //bodyPage.showAlert("Please select at least 1 KPI.", AlertType.ERROR); + bodyPage.showAlert("Please select at least 1 KPI. Expand the KPI's levels and than select at least 1 KPI by checkbox", AlertType.ERROR); + //recapPage.setError("You must select a KPI"); + return false; + } + + if(selectedKPIs.size()>10){ + bodyPage.showAlert("Please select 10 KPI at most", AlertType.ERROR); + //recapPage.setError("You must select a KPI"); + return false; + } + + return true; + + } + + /** + * Validate batch id selection. + * + * @return true, if successful + */ + public boolean validateBatchIdSelection() { + + //batchIDAndListKPI.showSelectionOK("Batch ID selection is valid", closable); + return true; + } + + + /** + * Validate perform fish input fields. + * + * @return true, if successful + */ + public boolean validatePerformFishInputFields() { + return form.validateForm(); + + } + + + /** + * Resync selected kp is. + */ + public void resyncSelectedKPIs() { + + //customTreeModel.resync(getSelectedKPIs()); + + } + + /** + * Gets the form. + * + * @return the form + */ + public PerformFishAnnualAnalitycsFormView getForm() { + + return form; + } + + /** + * Hide errors. + */ + public void hideErrors(){ + bodyPage.hideError(); + form.hideError(null, true); + } + + + /** + * Gets the selected kp is. + * + * @return the selected kp is + */ + public List getSelectedKPIs(){ + + return recapPage.getSelectedKPIs(); + } + + + /** + * Checks if is reload perform fish service data. + * + * @return true, if is reload perform fish service data + */ + public boolean isReloadPerformFishServiceData() { + + return reloadPerformFishServiceData; + } + + + /** + * Sets the reload perform fish service data. + * + * @param reloadPerformFishServiceData the new reload perform fish service data + */ + public void setReloadPerformFishServiceData(boolean reloadPerformFishServiceData) { + + this.reloadPerformFishServiceData = reloadPerformFishServiceData; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java index 2647f2c..3d84693 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java @@ -29,7 +29,6 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulat import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent; import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler; import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon; -import org.gcube.portlets.user.performfishanalytics.client.view.util.DecodeParameterUtil; import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult; import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult; import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel; @@ -46,7 +45,6 @@ import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.HandlerManager; @@ -78,6 +76,7 @@ public class PerformFishAnalyticsController { /** The decrypt parameters. */ private PerformFishInitParameter decryptParameters; + /** * Instantiates a new perform fish analytics controller. */ @@ -85,6 +84,8 @@ public class PerformFishAnalyticsController { registerHandlers(); viewController = new PerformFishAnalyticsViewController(); + + /*viewAnnualController = new PerformFishAnnualAnalyticsViewController(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override @@ -180,8 +181,18 @@ public class PerformFishAnalyticsController { }); } } - }); + });*/ } + + /** + * Sets the inits the parmaters. + * + * @param result the new inits the parmaters + */ + public void setInitParmaters(PerformFishInitParameter result) { + this.decryptParameters = result; + } + /** * Register handlers. @@ -193,7 +204,14 @@ public class PerformFishAnalyticsController { @Override public void onLoadPopulationType( LoadPopulationTypeEvent loadPopulationEvent) { - viewController.loadPopulationTypeForLevelAndBatchType(loadPopulationEvent.getPopulationName(), decryptParameters); + + viewController.loadPopulationTypeForLevelAndBatchType(loadPopulationEvent.getPopulationName(), decryptParameters); + +// if(loadPopulationEvent.getPopulationName().equals(POPULATION_LEVEL.BATCH.name())) { +// +// }else { +// viewAnnualController.loadPopulationTypeForLevelAndBatchType(loadPopulationEvent.getPopulationName(), decryptParameters); +// } } }); @@ -621,7 +639,7 @@ public class PerformFishAnalyticsController { } /** - * Remove the spinner if all DM responses are returned + * Remove the spinner if all DM responses are returned. * * @param requestPanel the request panel * @param tab the tab @@ -756,4 +774,5 @@ public class PerformFishAnalyticsController { } + } diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsViewController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsViewController.java index 309ebcb..226ecda 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsViewController.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsViewController.java @@ -102,7 +102,7 @@ public class PerformFishAnalyticsViewController { initLayout(); form = new PerformFishAnalitycsFormView(); //customTreeModel = new CustomTreeModel(); - customTreeModel = new CustomTreeModel(); + customTreeModel = new CustomTreeModel(PerformFishAnalyticsController.eventBus); batchIDAndListKPI = new BatchIDAndListKPIView(); tree = new CellTree(customTreeModel, null); //tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/view/CustomTreeModel.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/view/CustomTreeModel.java index 5eb0af0..22305c2 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/view/CustomTreeModel.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/view/CustomTreeModel.java @@ -7,7 +7,6 @@ package org.gcube.portlets.user.performfishanalytics.client.view; import java.util.ArrayList; import java.util.List; -import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController; import org.gcube.portlets.user.performfishanalytics.client.event.SelectedKPIEvent; import org.gcube.portlets.user.performfishanalytics.shared.KPI; import org.gcube.portlets.user.performfishanalytics.shared.PopulationType; @@ -20,6 +19,7 @@ import com.google.gwt.cell.client.FieldUpdater; import com.google.gwt.cell.client.HasCell; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Element; +import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.view.client.ListDataProvider; import com.google.gwt.view.client.SelectionChangeEvent; @@ -42,9 +42,11 @@ public class CustomTreeModel implements TreeViewModel { private final SingleSelectionModel multiSelectionModel = new SingleSelectionModel(); private ListDataProvider populationTypeProvider = new ListDataProvider(); private Cell kpiCell; + private HandlerManager eventBus; // private ListDataProvider dataProvider = new ListDataProvider(); - public CustomTreeModel() { + public CustomTreeModel(HandlerManager eventBus) { + this.eventBus = eventBus; init(); multiSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @@ -76,7 +78,7 @@ public class CustomTreeModel implements TreeViewModel { public void update(int index, KPI object, Boolean value) { // TODO Auto-generated method stub GWT.log("Checked: "+object.getName() + " value: "+value); - PerformFishAnalyticsController.eventBus.fireEvent(new SelectedKPIEvent(null, object, value)); + eventBus.fireEvent(new SelectedKPIEvent(null, object, value)); // cell.set(value); // dataGrid.redraw(); } diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.java new file mode 100644 index 0000000..fd8b2c3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.java @@ -0,0 +1,233 @@ +/** + * + */ +package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder; + +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.POPULATION_LEVEL; +import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync; +import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController; +import org.gcube.portlets.user.performfishanalytics.client.event.AddedBatchIdEvent; +import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon; +import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile; +import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow; +import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.ComplexPanel; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +// TODO: Auto-generated Javadoc +/** + * The Class BatchIDAndListKPIView. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Feb 28, 2019 + */ +public class AnnualListKPIView extends Composite { + + /** The ui binder. */ + private static BatchIDAndListKPIViewUiBinder uiBinder = + GWT.create(BatchIDAndListKPIViewUiBinder.class); + + + /** + * The Interface BatchIDAndListKPIViewUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Feb 28, 2019 + */ + interface BatchIDAndListKPIViewUiBinder + extends UiBinder { + } + + /** The the panel container. */ + @UiField + VerticalPanel the_panel_container; + + + /** The the panel error. */ + @UiField + HorizontalPanel the_panel_error; + + + /** The perform fish response. */ + private PerformFishResponse performFishResponse; + + /** The map parameters. */ + private Map> mapParameters; + + + + /** + * Instantiates a new batch id and list kpi view. + */ + public AnnualListKPIView() { + + initWidget(uiBinder.createAndBindUi(this)); + } + + + /** + * Adds the. + * + * @param w the w + */ + public void add(Widget w){ + the_panel_container.add(w); + + } + + /** + * Manage perform fish service response. + * + * @param performFishResponse the perform fish response + * @param mapParameters the map parameters + * @param level the level + */ + public void managePerformFishServiceResponse( + PerformFishResponse performFishResponse, + Map> mapParameters, final POPULATION_LEVEL level) { + this.performFishResponse = performFishResponse; + this.mapParameters = mapParameters; + + GWT.log("PerformFish Response: "+performFishResponse); + + String fileURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL); + + GWT.log("BatchesTable_internal is: "+fileURL); + + //Managing the Perform Fish Service Response + if(fileURL==null){ + showAlert("No select found for "+PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL, AlertType.ERROR, false, the_panel_error); + }else{ + + final LoaderIcon loader = new LoaderIcon("Loading Values..."); + the_panel_container.insert(loader, 1); + + PerformFishAnalyticsServiceAsync.Util.getInstance().readCSVFile(fileURL, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + loader.setVisible(false); + the_panel_container.remove(loader); + Window.alert(caught.getMessage()); + + } + + @Override + public void onSuccess(CSVFile result) { + loader.setVisible(false); + the_panel_container.remove(loader); + + if(result==null){ + showAlert("No value found for "+PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL, AlertType.ERROR, false, the_panel_error); + return; + } + + + //IT CAN BE "BATCH", "FARM", etc. + String theScalePParamValue = level.name(); + int indexOfTheScaleValue = result.getHeaderRow().getListValues().indexOf(theScalePParamValue); + + if(indexOfTheScaleValue>-1){ + List rows = result.getValueRows(); + + if(rows==null || rows.isEmpty()){ + PerformFishAnalyticsController.eventBus.fireEvent(new AddedBatchIdEvent()); + return; + } + + for (CSVRow row : rows) { + String valuePerScaleP = row.getListValues().get(indexOfTheScaleValue); + //field_list_focus_id_dea.addItem(valuePerScaleP, valuePerScaleP); +// uib_list_batch_id.addItem(valuePerScaleP, valuePerScaleP); +// listBatchesID.add(valuePerScaleP); + } + +// uib_list_batch_id.addItem(PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE, PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE); +// listBatchesID.add(PerformFishAnalyticsConstant.DM_FOCUS_ID_ALL_VALUE); + + PerformFishAnalyticsController.eventBus.fireEvent(new AddedBatchIdEvent()); + } + } + }); + } + } + + /** + * Show alert. + * + * @param error the error + * @param type the type + * @param closable the closable + * @param panel the panel + */ + private void showAlert(String error, AlertType type, boolean closable, ComplexPanel panel){ + panel.clear(); + Alert alert = new Alert(error); + alert.setType(type); + alert.setClose(closable); + alert.getElement().getStyle().setMargin(10, Unit.PX); + panel.add(alert); + } + + + /** + * Show alert. + * + * @param error the error + * @param type the type + * @param closable the closable + */ + public void showAlert(String error, AlertType type, boolean closable){ + showAlert(error, type, closable, the_panel_error); + } + + + /** + * Show selection ok. + * + * @param msg the msg + * @param closable the closable + */ + public void showSelectionOK(String msg, boolean closable){ + showAlert(msg, AlertType.INFO, closable, the_panel_error); + } + + /** + * Gets the perform fish response. + * + * @return the performFishResponse + */ + public PerformFishResponse getPerformFishResponse() { + + return performFishResponse; + } + + + /** + * Gets the map parameters. + * + * @return the mapParameters + */ + public Map> getMapParameters() { + + return mapParameters; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.ui.xml b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.ui.xml new file mode 100644 index 0000000..16fd526 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnnualListKPIView.ui.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/PerformFishAnnualAnalitycsFormView.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/PerformFishAnnualAnalitycsFormView.java new file mode 100644 index 0000000..c543178 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/PerformFishAnnualAnalitycsFormView.java @@ -0,0 +1,339 @@ + +package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsController; +import org.gcube.portlets.user.performfishanalytics.client.event.LoadPopulationTypeEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.PerformFishFieldFormChangedEvent; +import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulationTypeEvent; +import org.gcube.portlets.user.performfishanalytics.shared.Population; +import org.gcube.portlets.user.performfishanalytics.shared.PopulationType; +import org.gcube.portlets.user.performfishanalytics.shared.Year; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.DomEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +/** + * The Class PerformFishAnalitycsFormView. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 22, 2019 + */ +public class PerformFishAnnualAnalitycsFormView extends Composite { + + /** The ui binder. */ + private static PerformFishAnalitycsFormViewUiBinder uiBinder = + GWT.create(PerformFishAnalitycsFormViewUiBinder.class); + + /** + * The Interface CreateFolderConfigurationToThreddsSyncUiBinder. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, + * 2018 + */ + interface PerformFishAnalitycsFormViewUiBinder + extends UiBinder { + } + /** The pager. */ + // @UiField + // Pager pager; + @UiField + public ListBox field_select_population; + @UiField + protected ListBox field_select_population_type; + @UiField + ListBox field_select_year; + @UiField + ControlGroup cg_select_population; + @UiField + ControlGroup cg_select_population_type; + @UiField + ControlGroup cg_select_year; + @UiField + VerticalPanel errorPanel; + @UiField + CheckBox uib_check_all_year; + + // @UiField + // Fieldset fieldset_add_catalogue_bean; + /** The folder id. */ + private String folderId; + private Map> mapPopulation = + new HashMap>(); + private Map mapPopulationType = + new HashMap(); + + + /** + * Instantiates a new perform fish analitycs form view. + */ + public PerformFishAnnualAnalitycsFormView() { + + initWidget(uiBinder.createAndBindUi(this)); + + field_select_population.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + // String scope = field_select_scope.getSelectedItemText(); + String value = field_select_population.getSelectedValue(); + GWT.log("Selected POPULATION: " + value); + PerformFishAnnualAnalyticsController.eventBus.fireEvent(new LoadPopulationTypeEvent(value, null)); + //PerformFishAnalyticsController.eventBus.fireEvent(new PerformFishFieldFormChangedEvent(field_select_population)); + } + }); + + field_select_population_type.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + String populatioTypeSelected = field_select_population_type.getSelectedValue(); + GWT.log("Selected population type: " + populatioTypeSelected); + PopulationType opt = mapPopulationType.get(populatioTypeSelected); + PerformFishAnnualAnalyticsController.eventBus.fireEvent(new SelectedPopulationTypeEvent(opt)); + fillYear(opt.getListYears()); + PerformFishAnnualAnalyticsController.eventBus.fireEvent(new PerformFishFieldFormChangedEvent(field_select_population_type)); + } + }); + + field_select_year.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + hideError(cg_select_year, false); + PerformFishAnnualAnalyticsController.eventBus.fireEvent(new PerformFishFieldFormChangedEvent(field_select_year)); + } + }); + + + uib_check_all_year.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + boolean isChecked = uib_check_all_year.getValue(); + selectAllFields(field_select_year, isChecked); + } + }); + } + + /** + * Select all fields. + * + * @param listBox the list box + * @param selected the selected + */ + private void selectAllFields(ListBox listBox, boolean selected){ + + for (int i=0; i result, + Population population) { + + mapPopulation.put(populationName, result); + fillPopulationType(populationName, result, population); + } + + /** + * Fill year. + * + * @param listQuarter the list quarter + */ + private void fillYear(List listQuarter) { + + field_select_year.clear(); + if (listQuarter != null && listQuarter.size() > 0) { + field_select_year.setEnabled(true); + for (Year year : listQuarter) { + field_select_year.addItem(year.getName(), year.getId()); + } + } + else { + field_select_year.setEnabled(false); + uib_check_all_year.setEnabled(false); + } + } + + /** + * Fill population type. + * + * @param populationName + * the population name + * @param result + * the result + * @param population + * the population + */ + private void fillPopulationType( + String populationName, List result, + Population population) { + + field_select_population_type.clear(); + if (result != null && result.size() > 0) { + field_select_population_type.setEnabled(true); + mapPopulationType.clear(); + for (PopulationType popType : result) { + field_select_population_type.addItem( + popType.getName(), popType.getId()); + mapPopulationType.put(popType.getId(), popType); + // if(thCatalogueBean.isDefault()){ + // field_select_catalogue_name.setSelectedValue(thCatalogueBean.getName()); + // } + } + // field_select_population_type.setSelectedValue(thCatalogueBean.getName()); + field_select_population_type.setSelectedValue(result.get(0).getName()); + DomEvent.fireNativeEvent( + Document.get().createChangeEvent(), + field_select_population_type); + field_select_population.addItem( + population.getName(), population.getId()); + } + } + + + /** + * Validate form. + * + * @return true, if successful + */ + public boolean validateForm() { + + cg_select_year.setType(ControlGroupType.NONE); + errorPanel.setVisible(false); + // cg_remote_path.setType(ControlGroupType.NONE); + if (field_select_year.getItemCount()>0 && field_select_year.getSelectedIndex() == -1) { + cg_select_year.setType(ControlGroupType.INFO); + showAlert("Please select a Year", AlertType.INFO); + return false; + } + return true; + } + + + /** + * Show alert. + * + * @param txt the txt + * @param type the type + */ + public void showAlert(String txt, AlertType type) { + errorPanel.clear(); + errorPanel.setVisible(true); + Alert msg = new Alert(txt); + msg.setAnimation(true); + msg.setClose(false); + msg.setType(type); + errorPanel.add(msg); + + } + + /** + * Hide error. + * + * @param cgroup the cgroup + * @param forceHide the force hide + */ + public void hideError(ControlGroup cgroup, boolean forceHide){ + + if(forceHide){ + cg_select_year.setType(ControlGroupType.NONE); + errorPanel.setVisible(false); + } + + if(cgroup!=null){ + cgroup.setType(ControlGroupType.NONE); + } + + errorPanel.setVisible(false); + } + + + /** + * Gets the batch type. + * + * @return the batch type + */ + public String getBatchType(){ + + return field_select_population_type.getSelectedItemText(); + + } + + /** + * Gets the sel level. + * + * @return the sel level + */ + public String getLevel(){ + return field_select_population.getSelectedItemText(); + } + + + /** + * Gets the year. + * + * @return the year + */ + public List getYear(){ + return getSelected(field_select_year); + } + + /** + * Gets the selected. + * + * @param listBox the list box + * @return the selected + */ + private List getSelected(ListBox listBox){ + List selected = new ArrayList(); + for (int i=0; i + + + .noBorder { + border: 0px; + } + + .marginToError { + margin-left: 180px; + } + + + + + + + + + + Batch Type + + + + + + + + Level + + + + + + + + Year + + + + + + + + + + + + + + + + + \ No newline at end of file