Skip to content
Snippets Groups Projects
Commit f73a9634 authored by buczekp's avatar buczekp
Browse files

[LMS-1676] use parent chooser to fill parents area (quick & dirty solution)

SVN: 17379
parent b169b7c1
No related branches found
No related tags found
No related merge requests found
Showing with 72 additions and 112 deletions
......@@ -50,17 +50,30 @@ abstract public class CodesArea<T extends ICodeHolder> extends MultilineVarcharF
setOriginalValue(textValue);
}
public final void appendCode(String code)
{
StringBuilder sb = new StringBuilder();
sb.append(getValue() == null ? "" : getValue());
appendCode(sb, code);
setValue(sb.toString());
}
private static String createTextValue(List<String> codes)
{
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (String code : codes)
{
if (sb.length() > 0)
{
sb.append(", ");
}
sb.append(code);
appendCode(sb, code);
}
return sb.toString();
}
private static final void appendCode(StringBuilder sb, String code)
{
if (sb.length() > 0)
{
sb.append(", ");
}
sb.append(code);
}
}
......@@ -39,6 +39,8 @@ public class SampleChooserField extends ChosenEntitySetter<Sample>
{
Field<?> getField();
SampleChooserField getChooserField();
/** @return the sample identifier (as a string) which is set as a field value */
String getValue();
......@@ -97,6 +99,11 @@ public class SampleChooserField extends ChosenEntitySetter<Sample>
return chooserField;
}
public SampleChooserField getChooserField()
{
return chooserField;
}
public String getValue()
{
return chooserField.getValue();
......
......@@ -138,20 +138,7 @@ abstract class AbstractSampleBusinessObject extends AbstractSampleIdentifierBusi
} else if (newSample.getParents() != null)
{
final String[] parents = newSample.getParents();
final List<SampleIdentifier> parentIdentifiers =
IdentifierHelper.extractSampleIdentifiers(parents);
if (sampleIdentifier.isSpaceLevel())
{
final String spaceCode = sampleIdentifier.getSpaceLevel().getSpaceCode();
final List<SamplePE> parentPEs = new ArrayList<SamplePE>();
for (SampleIdentifier si : parentIdentifiers)
{
IdentifierHelper.fillGroupIfNotSpecified(si, spaceCode);
SamplePE parent = getSampleByIdentifier(si);
parentPEs.add(parent);
}
addParents(samplePE, parentPEs);
}
setParents(samplePE, parents);
}
String containerIdentifier = newSample.getContainerIdentifier();
setContainer(sampleIdentifier, samplePE, containerIdentifier);
......@@ -224,13 +211,35 @@ abstract class AbstractSampleBusinessObject extends AbstractSampleIdentifierBusi
}
}
protected void setParents(SamplePE child, List<SamplePE> parents)
protected void setParents(final SamplePE childPE, final String[] parents)
{
removeParents(child);
final List<SampleIdentifier> parentIdentifiers =
IdentifierHelper.extractSampleIdentifiers(parents);
final SampleIdentifier childIdentifier = childPE.getSampleIdentifier();
if (childIdentifier.isSpaceLevel())
{
final String spaceCode = childIdentifier.getSpaceLevel().getSpaceCode();
for (SampleIdentifier si : parentIdentifiers)
{
IdentifierHelper.fillGroupIfNotSpecified(si, spaceCode);
}
}
final List<SamplePE> parentPEs = new ArrayList<SamplePE>();
for (SampleIdentifier si : parentIdentifiers)
{
SamplePE parent = getSampleByIdentifier(si);
parentPEs.add(parent);
}
setParents(childPE, parentPEs);
}
private void setParents(SamplePE childPE, List<SamplePE> parentPEs)
{
removeParents(childPE);
RelationshipTypePE relationshipType = tryFindParentChildRelationshipType();
for (SamplePE parent : parents)
for (SamplePE parentPE : parentPEs)
{
addParentRelationship(child, parent, relationshipType);
addParentRelationship(childPE, parentPE, relationshipType);
}
}
......@@ -251,22 +260,6 @@ abstract class AbstractSampleBusinessObject extends AbstractSampleIdentifierBusi
}
}
// ineffective for adding a collection of parents
protected void addParent(SamplePE child, SamplePE parent)
{
RelationshipTypePE relationshipType = tryFindParentChildRelationshipType();
addParentRelationship(child, parent, relationshipType);
}
protected void addParents(SamplePE child, List<SamplePE> parents)
{
RelationshipTypePE relationshipType = tryFindParentChildRelationshipType();
for (SamplePE parent : parents)
{
addParentRelationship(child, parent, relationshipType);
}
}
private void addParentRelationship(SamplePE child, SamplePE parent,
RelationshipTypePE relationshipType)
{
......
......@@ -17,20 +17,16 @@
package ch.systemsx.cisd.openbis.generic.server.business.bo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import ch.systemsx.cisd.common.collections.CollectionUtils;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.server.business.bo.util.SampleUtils;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IAttachmentDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
......@@ -38,7 +34,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE;
......@@ -275,42 +270,7 @@ public final class SampleBO extends AbstractSampleBusinessObject implements ISam
// attaches specified existing samples to the sample as parents
private void attachParents(String[] parentCodes)
{
List<SamplePE> parents =
findSamplesByCodes(getSampleDAO(), asSet(parentCodes), sample.getGroup());
setParents(sample, parents);
}
// Finds samples in the specified group. Throws exception if some samples do not exist.
private static List<SamplePE> findSamplesByCodes(ISampleDAO sampleDAO, Set<String> sampleCodes,
GroupPE group)
{
List<SamplePE> samples = new ArrayList<SamplePE>();
List<String> missingSamples = new ArrayList<String>();
for (String code : sampleCodes)
{
SamplePE sample = sampleDAO.tryFindByCodeAndGroup(code, group);
if (sample == null)
{
missingSamples.add(code);
} else
{
samples.add(sample);
}
}
if (missingSamples.size() > 0)
{
throw UserFailureException.fromTemplate(
"Samples with following codes do not exist in the space '%s': '%s'.", group
.getCode(), CollectionUtils.abbreviate(missingSamples, 10));
} else
{
return samples;
}
}
private static Set<String> asSet(String[] objects)
{
return new HashSet<String>(Arrays.asList(objects));
setParents(sample, parentCodes);
}
public void setGeneratedCode()
......
......@@ -35,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.
import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.SampleTypeDisplayID;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.GroupSelectionWidget;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.IChosenEntityListener;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.ExperimentChooserField.ExperimentChooserFieldAdaptor;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.SampleChooserField.SampleChooserFieldAdaptor;
......@@ -43,6 +44,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdAndCodeHolder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleTypePropertyType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space;
......@@ -215,6 +217,18 @@ abstract public class AbstractGenericSampleRegisterEditForm extends
SampleTypeDisplayID.SAMPLE_REGISTRATION_PARENT_CHOOSER
.withSuffix(getSampleTypeCode()));
parentsArea = new ParentSamplesArea(viewContext, simpleId);
SampleChooserField parentChooserField = parent.getChooserField();
parentChooserField.addChosenEntityListener(new IChosenEntityListener<Sample>()
{
public void entityChosen(Sample entity)
{
if (entity != null)
{
String sampleIdentifier = entity.getIdentifier();
parentsArea.appendCode(sampleIdentifier);
}
}
});
container =
SampleChooserField.create(viewContext.getMessage(Dict.PART_OF_SAMPLE), false, null,
true, false, false, viewContext.getCommonViewContext(), getId()
......
......@@ -68,12 +68,11 @@ public final class GenericSampleEditForm extends AbstractGenericSampleRegisterEd
final ExperimentIdentifier experimentIdent =
experimentField != null ? experimentField.tryToGetValue() : null;
final String containerOrNull = StringUtils.trimToNull(container.getValue());
final String parentOrNull = StringUtils.trimToNull(parent.getValue());
final String[] parents = getParents();
viewContext.getService().updateSample(
new SampleUpdates(attachmentsSessionKey, techIdOrNull, properties, attachments,
experimentIdent, originalSample.getModificationDate(),
createSampleIdentifier(), containerOrNull, parentOrNull, parents),
createSampleIdentifier(), containerOrNull, null, parents),
new UpdateSampleCallback(viewContext));
}
......@@ -107,7 +106,6 @@ public final class GenericSampleEditForm extends AbstractGenericSampleRegisterEd
experimentField.updateOriginalValue();
updateFieldOriginalValue(groupSelectionWidget);
container.updateOriginalValue();
parent.updateOriginalValue();
parentsArea.setSampleCodes(parents);
}
......@@ -129,7 +127,6 @@ public final class GenericSampleEditForm extends AbstractGenericSampleRegisterEd
experimentField.updateValue(originalExperiment);
initializeGroup();
initializeContainedInParent();
initializeGeneratedFromParent();
initializeParents();
}
......@@ -155,19 +152,6 @@ public final class GenericSampleEditForm extends AbstractGenericSampleRegisterEd
}
}
private void initializeGeneratedFromParent()
{
Set<Sample> parents = originalSample.getParents();
if (parents.size() == 1)
{
Sample parentSample = originalSample.getGeneratedFrom();
if (parentSample != null)
{
parent.updateValue(parentSample.getIdentifier());
}
}
}
private void initializeParents()
{
// TODO 2010-08-06, Piotr Buczek: load in background? like in experiment
......
......@@ -99,20 +99,9 @@ public final class GenericSampleRegistrationForm extends AbstractGenericSampleRe
: null;
final String containerOrNull = StringUtils.trimToNull(container.getValue());
final String parentOrNull = StringUtils.trimToNull(parent.getValue());
final NewSample newSample;
if (parentOrNull == null)
{
final String[] parents = getParents();
newSample =
NewSample.createWithParents(createSampleIdentifier(), sampleType,
containerOrNull, parents);
} else
{
newSample =
NewSample.createWithParent(createSampleIdentifier(), sampleType,
containerOrNull, parentOrNull);
}
final NewSample newSample =
NewSample.createWithParents(createSampleIdentifier(), sampleType, containerOrNull,
getParents());
final List<IEntityProperty> properties = extractProperties();
newSample.setProperties(properties.toArray(IEntityProperty.EMPTY_ARRAY));
newSample.setAttachments(attachmentsManager.extractAttachments());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment