From 8caed4ce1db2386cec23e5377c490738a14f1564 Mon Sep 17 00:00:00 2001 From: gakin <gakin> Date: Tue, 19 May 2015 17:08:03 +0000 Subject: [PATCH] SSDM-1825 CORE: Warning on deleting samples with SVN: 34002 --- .../ui/sample/SampleBrowserGrid.java | 51 ++-------- .../util/EntityDeletionConfirmationUtils.java | 99 +++++++++++++++++++ .../sample/GenericSampleViewer.java | 36 +------ 3 files changed, 111 insertions(+), 75 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/EntityDeletionConfirmationUtils.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java index 706d13168e4..2395462e0ba 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java @@ -56,6 +56,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IC import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabHelper; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.IDataRefreshCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.EntityDeletionConfirmationUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedActionWithResult; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDirectlyConnectedController; @@ -598,50 +599,16 @@ public class SampleBrowserGrid extends AbstractEntityGrid<Sample> new AbstractAsyncCallback<List<SampleChildrenInfo>>(viewContext) { @Override - protected void process(List<SampleChildrenInfo> sampleChildrenInfo) + protected void process(List<SampleChildrenInfo> sampleChildrenInfoList) { - int samplesWithChildren = 0; - int samplesWithDataSets = 0; - final int MAX_DISPLAY_SIZE = 10; - - Set<String> samplesWithChildrenToDisplay = new HashSet<String>(); - Set<String> samplesWithDataSetsToDisplay = new HashSet<String>(); - - for(SampleChildrenInfo info: sampleChildrenInfo) { - if(info.getChildCount() > 0) { - samplesWithChildren++; - if(samplesWithChildren <= MAX_DISPLAY_SIZE) { - samplesWithChildrenToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); - } - } - if(info.getDataSetCount() > 0) { - samplesWithDataSets++; - if(samplesWithDataSets <= MAX_DISPLAY_SIZE) { - samplesWithDataSetsToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); - } - } + String additionalMessage = null; + if(sampleChildrenInfoList.size() == 1) + { + additionalMessage = EntityDeletionConfirmationUtils.getMessageForSingleSample(sampleChildrenInfoList.get(0)); } - String additionalMessage=""; - if(samplesWithChildren > 0) { - additionalMessage += "<br>There are " + samplesWithChildren + " sample(s) with children samples, these relationships will be broken but the children will remain:<br>"; - for(String sample : samplesWithChildrenToDisplay) { - additionalMessage += "<br>" + sample; - } - if(samplesWithChildren > MAX_DISPLAY_SIZE) { - additionalMessage += "<br>and " + (samplesWithChildren-MAX_DISPLAY_SIZE) + " more"; - } - additionalMessage += "<br>"; - } - if(samplesWithDataSets > 0) { - additionalMessage += "<br>There are " + samplesWithDataSets + " sample(s) with data sets, these will be deleted with the sample:<br>"; - for(String sample : samplesWithDataSetsToDisplay) { - additionalMessage += "<br>" + sample; - } - if(samplesWithDataSets > MAX_DISPLAY_SIZE) { - additionalMessage += "<br>and " + (samplesWithDataSets-MAX_DISPLAY_SIZE) + " more"; - } - additionalMessage += "<br>"; - } + else { + additionalMessage = EntityDeletionConfirmationUtils.getMessageForMultipleSamples(sampleChildrenInfoList, techIdsToSampleIds); + } new SampleListDeletionConfirmationDialog<TableModelRowWithObject<Sample>>(viewContext.getCommonViewContext(), samples, callback, s, additionalMessage).show();; } }; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/EntityDeletionConfirmationUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/EntityDeletionConfirmationUtils.java new file mode 100644 index 00000000000..462c388c455 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/EntityDeletionConfirmationUtils.java @@ -0,0 +1,99 @@ +package ch.systemsx.cisd.openbis.generic.client.web.client.application.util; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleChildrenInfo; + +public class EntityDeletionConfirmationUtils +{ + + //return information about selected samples child samples and data sets + public static String getMessageForSingleSample(SampleChildrenInfo sampleChildrenInfo) { + final int MAX_DISPLAY_SIZE = 10; + + StringBuffer additionalMessage = new StringBuffer(); + StringBuffer sampleSb = new StringBuffer(); + StringBuffer dataSetSb = new StringBuffer(); + + for (String child : sampleChildrenInfo.getDerivedSamples()) + { + sampleSb.append("<br>" + child); + } + for (String ds : sampleChildrenInfo.getDataSets()) + { + dataSetSb.append("<br>" + ds); + } + + if(sampleSb.length() > 0) { + additionalMessage.append("<br>The sample has " + sampleChildrenInfo.getChildCount() + " children samples, these relationships will be broken but the children will remain:"); + additionalMessage.append("<br>"); + additionalMessage.append(sampleSb); + if(sampleChildrenInfo.getChildCount() > MAX_DISPLAY_SIZE ) { + additionalMessage.append("<br> and " + (sampleChildrenInfo.getChildCount()-MAX_DISPLAY_SIZE) + " more"); + } + additionalMessage.append("<br>"); + } + if(dataSetSb.length() > 0) { + additionalMessage.append("<br>The sample has " + sampleChildrenInfo.getDataSetCount() + " datasets, these will be deleted with the sample:"); + additionalMessage.append("<br>"); + additionalMessage.append(dataSetSb); + if(sampleChildrenInfo.getDataSetCount() > MAX_DISPLAY_SIZE) { + additionalMessage.append("<br>and " + (sampleChildrenInfo.getDataSetCount()-MAX_DISPLAY_SIZE) + " more"); + } + additionalMessage.append("<br>"); + } + return additionalMessage.toString(); + } + + //return information about the number of samples with child samples and data sets + //and a summary of those + public static String getMessageForMultipleSamples(List<SampleChildrenInfo> sampleChildrenInfo, Map<String, String> techIdsToSampleIds) { + StringBuffer additionalMessage = new StringBuffer(); + int samplesWithChildren = 0; + int samplesWithDataSets = 0; + final int MAX_DISPLAY_SIZE = 10; + + Set<String> samplesWithChildrenToDisplay = new HashSet<String>(); + Set<String> samplesWithDataSetsToDisplay = new HashSet<String>(); + + for(SampleChildrenInfo info: sampleChildrenInfo) { + if(info.getChildCount() > 0) { + samplesWithChildren++; + if(samplesWithChildren <= MAX_DISPLAY_SIZE) { + samplesWithChildrenToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); + } + } + if(info.getDataSetCount() > 0) { + samplesWithDataSets++; + if(samplesWithDataSets <= MAX_DISPLAY_SIZE) { + samplesWithDataSetsToDisplay.add(techIdsToSampleIds.get(info.getSampleIdentifier())); + } + } + } + if(samplesWithChildren > 0) { + additionalMessage.append("<br>There are " + samplesWithChildren + " sample(s) with children samples, these relationships will be broken but the children will remain:<br>"); + for(String sample : samplesWithChildrenToDisplay) { + additionalMessage.append("<br>" + sample); + } + if(samplesWithChildren > MAX_DISPLAY_SIZE) { + additionalMessage.append("<br>and " + (samplesWithChildren-MAX_DISPLAY_SIZE) + " more"); + } + additionalMessage.append("<br>"); + } + if(samplesWithDataSets > 0) { + additionalMessage.append("<br>There are " + samplesWithDataSets + " sample(s) with data sets, these will be deleted with the sample:<br>"); + for(String sample : samplesWithDataSetsToDisplay) { + additionalMessage.append("<br>" + sample); + } + if(samplesWithDataSets > MAX_DISPLAY_SIZE) { + additionalMessage.append("<br>and " + (samplesWithDataSets-MAX_DISPLAY_SIZE) + " more"); + } + additionalMessage.append("<br>"); + } + return additionalMessage.toString(); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java index ad2a629f4e9..05bb52d6a8e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java @@ -53,6 +53,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.propert import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleListDeletionConfirmationDialog; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.ExternalHyperlink; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.SectionsPanel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.EntityDeletionConfirmationUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GridRowModels; @@ -182,47 +183,16 @@ abstract public class GenericSampleViewer extends AbstractViewerWithVerticalSpli //we need info for just 1 sample/ List<TechId> sampleIds = new ArrayList<TechId>(Arrays.asList(TechId.create(getOriginalData()))); - // new ArrayList<TechId>(); - // sampleIds.add(TechId.create(getOriginalData())); - viewContext.getCommonService().getSampleChildrenInfo(sampleIds, true, new AbstractAsyncCallback<List<SampleChildrenInfo>>(viewContext) { @Override protected void process(List<SampleChildrenInfo> info) { - final int MAX_INFO_SIZE = 10; SampleChildrenInfo sampleInfo = info.get(0); + + additionalMessage.append(EntityDeletionConfirmationUtils.getMessageForSingleSample(sampleInfo)); - StringBuffer sampleSb = new StringBuffer(); - StringBuffer dataSetSb = new StringBuffer(); - for (String child : sampleInfo.getDerivedSamples()) - { - sampleSb.append("<br>" + child); - } - for (String ds : sampleInfo.getDataSets()) - { - dataSetSb.append("<br>" + ds); - } - - if(sampleSb.length() > 0) { - additionalMessage.append("<br>The sample has " + sampleInfo.getChildCount() + " children samples, these relationships will be broken but the children will remain:"); - additionalMessage.append("<br>"); - additionalMessage.append(sampleSb); - if(sampleInfo.getChildCount() > MAX_INFO_SIZE ) { - additionalMessage.append("<br> and " + (sampleInfo.getChildCount()-MAX_INFO_SIZE) + " more"); - } - additionalMessage.append("<br>"); - } - if(dataSetSb.length() > 0) { - additionalMessage.append("<br>The sample has " + sampleInfo.getDataSetCount() + " datasets, these will be deleted with the sample:"); - additionalMessage.append("<br>"); - additionalMessage.append(dataSetSb); - if(sampleInfo.getDataSetCount() > MAX_INFO_SIZE) { - additionalMessage.append("<br>and " + (sampleInfo.getDataSetCount()-MAX_INFO_SIZE) + " more"); - } - additionalMessage.append("<br>"); - } new SampleListDeletionConfirmationDialog(getViewContext() .getCommonViewContext(), getOriginalDataAsSingleton(), callback, getOriginalData(), additionalMessage.toString()).show(); -- GitLab