+ if(element instanceof TreeNode){
+ element = ((TreeNode) element).getValue();
+ }
+ String text = null;
+
+ //check if collection code does not exist -> use collection name then
+ FormatKey collectionKey = FormatKey.COLLECTION_CODE;
+ text = CdmFormatterFactory.format(element,new FormatKey[]{FormatKey.COLLECTION_CODE});
+ if(CdmUtils.isBlank(text)){
+ collectionKey = FormatKey.COLLECTION_NAME;
+ }
+
+ //Use titlecache for FieldUnits
+ if(element instanceof FieldUnit){
+ text = ((FieldUnit) element).getTitleCache();
+ }
+ else if(element instanceof MediaSpecimen){
+ text = CdmFormatterFactory.format(element,
+ new FormatKey[]{
+ FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE,
+ collectionKey, FormatKey.SPACE,
+ FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
+ FormatKey.MEDIA_TITLE, FormatKey.SPACE,
+ FormatKey.MEDIA_ARTIST, FormatKey.SPACE,
+ });
+ }
+ else if (element instanceof DnaSample) {
+ text = CdmFormatterFactory.format(element,
+ new FormatKey[] {
+ collectionKey, FormatKey.SPACE,
+ FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
+ FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE
+ });
+ }
+ else if (element instanceof DerivedUnit) {
+ text = CdmFormatterFactory.format(element,
+ new FormatKey[] {
+ collectionKey, FormatKey.SPACE,
+ FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE
+ });
+ }
+ else if (element instanceof Sequence) {
+ text = CdmFormatterFactory.format(element,
+ new FormatKey[] {
+ FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE
+ });
+ }
+ else if (element instanceof SingleRead) {
+ text = CdmFormatterFactory.format(element,
+ new FormatKey[] {
+ FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE,
+ FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
+ });
+ }
+ else if(element instanceof IdentifiableEntity){
+
+ IdentifiableEntity identifiableEntity = (IdentifiableEntity) element;
+ if(identifiableEntity.isProtectedTitleCache()){
+ text = identifiableEntity.getTitleCache();
+ }
+ }
+ if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){
+ if(element instanceof CdmBase){
+ text = ((CdmBase) element).getUuid().toString();
+ }
+ else{
+ text = element.toString();
+ }
+ }
+ //remove dot at the end
+ if(text.endsWith(".")){
+ text = text.substring(0, text.length()-1);
+ }
+ return text;