import org.hibernate.LazyInitializationException;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.DefinedTerm;
import eu.etaxonomy.cdm.model.common.Identifier;
conversation.bind();
final String emptyString = "";
- final String separator = ", ";
+ final String separator = " ";
String label = emptyString;
FieldUnit fieldUnit = (FieldUnit)derivate;
if(fieldUnit.getGatheringEvent()!=null){
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
- if(CdmStore.getService(IOccurrenceService.class).exists(fieldUnit.getUuid()) && !conversation.getSession().contains(gatheringEvent)){
- fieldUnit = (FieldUnit) CdmStore.getService(IOccurrenceService.class).load(fieldUnit.getUuid());
- gatheringEvent = fieldUnit.getGatheringEvent();
- }
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
}
label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString;
+ label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString;
}
//TissueSample + DnaSample
else if(derivate instanceof DnaSample){
}
}
else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){
- label += dnaSample.getKindOfUnit()+separator;
+ if(dnaSample.getKindOfUnit()!=null){
+ label += dnaSample.getKindOfUnit()+separator;
+ }
Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
label += currentSampleDesignation.getIdentifier()+separator;
else if(derivate instanceof DerivedUnit){
DerivedUnit derivedUnit = (DerivedUnit)derivate;
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
- java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
- if(fieldUnits!=null && !fieldUnits.isEmpty()){
- FieldUnit fieldUnit = fieldUnits.iterator().next();
- GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
-// gatheringEvent = HibernateProxyHelper.deproxy(gatheringEvent, GatheringEvent.class);
- if(gatheringEvent!=null){
- label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
+ //TODO : This is not generic anymore for performance reasons
+ Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
+ if(originals!=null && originals.size() ==1) {
+ SpecimenOrObservationBase specimen = originals.iterator().next();
+ if(specimen instanceof FieldUnit) {
+ FieldUnit fieldUnit = (FieldUnit)specimen;
+ GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+ if(gatheringEvent!=null){
+ label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ }
+ label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
}
- label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
}
+
eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
if(collection!=null){
- label += collection.getName()!=null?collection.getName()+" ":emptyString;
- label += collection.getCode()!=null?"("+collection.getCode()+"), ":emptyString;
+ label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
}
- label += derivedUnit.getAccessionNumber()!=null?derivedUnit.getAccessionNumber()+separator:emptyString;
- label += derivedUnit.getBarcode()!=null?derivedUnit.getBarcode():emptyString;
+ String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
+ label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
}
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
//TissueSample should only be created by using it's own class
label += NO_SAMPLE_DESIGNATION+separator;
}
label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString;
- if(sequence!=null){
- label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString;
+ if(sequence!=null && sequence.getDnaMarker()!=null){
+ label += sequence.getDnaMarker()+separator;
+ }
+ if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){
+ label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator;
}
}
}
if(element instanceof TreeNode){
element = ((TreeNode) element).getValue();
}
- if(element instanceof FieldUnit){
- return ImageResources.getImage(ImageResources.FIELD_UNIT);
- }
- else if(element instanceof DerivedUnit){
- DerivedUnit derivedUnit = (DerivedUnit)element;
- if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
- return ImageResources.getImage(ImageResources.FIELD_UNIT);
- }
- else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
- return ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
- }
- else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
- return ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
+ if(element instanceof CdmBase){
+ CdmBase cdmBase = (CdmBase)element;
+ boolean hasCharacterData = false;
+ if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
+ SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
+ if(specimen.hasCharacterData()){
+ hasCharacterData = true;
+ }
}
- else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
- return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
+ if(cdmBase.isInstanceOf(FieldUnit.class)){
+ return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
}
- else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.Media){
- if(derivedUnit.getKindOfUnit()!=null){
- if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
- return ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
- }
- else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
- return ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
- }
- else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
- return ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
- }
- else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
- return ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
+ else if(cdmBase.isInstanceOf(DerivedUnit.class)){
+ DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
+ if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
+ return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
+ return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
+ return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+ return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.Media){
+ if(derivedUnit.getKindOfUnit()!=null){
+ if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
+ }
}
}
}
- }
- else if(element instanceof Sequence){
- return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
- }
-
- else if(element instanceof SingleRead){
- if(multiLinkSingleReads.contains(element)){
- return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
+ else if(cdmBase.isInstanceOf(Sequence.class)){
+ return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
}
- else{
- return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
+
+ else if(cdmBase.isInstanceOf(SingleRead.class)){
+ if(multiLinkSingleReads.contains(element)){
+ return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
+ }
+ else{
+ return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
+ }
}
}
return super.getImage(element);
}
public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) {
- if(entity instanceof DnaSample){
- DnaSample dnaSample = (DnaSample)entity;
+ if(entity.isInstanceOf(DnaSample.class)){
+ DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class);
for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) {
if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
//first sample designation is the current
}
}
}
- else if(entity instanceof Sequence){
- Sequence sequence = (Sequence)entity;
+ else if(entity.isInstanceOf(Sequence.class)){
+ Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class);
if(sequence.getDnaSample()!=null){
return getCurrentSampleDesignation(sequence.getDnaSample());
}