Project

General

Profile

« Previous | Next » 

Revision 5454a90f

Added by Andreas Kohlbecker over 8 years ago

#5479 preliminar solution for user defined presenceAbsence terms vocabularies

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceUtilities.java
38 38
import com.fasterxml.jackson.databind.type.TypeFactory;
39 39

  
40 40
import eu.etaxonomy.cdm.api.service.ITermService;
41
import eu.etaxonomy.cdm.api.service.IVocabularyService;
41 42
import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
42 43
import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
43 44
import eu.etaxonomy.cdm.common.CdmUtils;
45
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44 46
import eu.etaxonomy.cdm.model.common.Language;
45 47
import eu.etaxonomy.cdm.model.common.Representation;
48
import eu.etaxonomy.cdm.model.common.TermType;
46 49
import eu.etaxonomy.cdm.model.common.TermVocabulary;
47 50
import eu.etaxonomy.cdm.model.description.Distribution;
48 51
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
......
99 102

  
100 103
    private static HashMap<PresenceAbsenceTerm, Color> defaultPresenceAbsenceTermBaseColors = null;
101 104

  
105
    private static List<UUID>  presenceAbsenceTermVocabularyUuids = null;
106

  
102 107
    private static HashMap<PresenceAbsenceTerm, Color> getDefaultPresenceAbsenceTermBaseColors() {
103 108
        if(defaultPresenceAbsenceTermBaseColors == null){
104 109
            defaultPresenceAbsenceTermBaseColors = new HashMap<PresenceAbsenceTerm, Color>();
......
359 364
            if(status == null){
360 365
                status = defaultStatus;
361 366
            }
367
            status = HibernateProxyHelper.deproxy(status, PresenceAbsenceTerm.class);
362 368
            if (! statusList.contains(status)){
363 369
                statusList.add(status);
364 370
            }
......
682 688

  
683 689
    /**
684 690
     * @param statusColorJson for example: {@code {"n":"#ff0000","p":"#ffff00"}}
691
     * @param vocabularyService TODO
685 692
     * @return
686 693
     * @throws IOException
687 694
     * @throws JsonParseException
688 695
     * @throws JsonMappingException
689 696
     */
690
    public static Map<PresenceAbsenceTerm, Color> buildStatusColorMap(String statusColorJson, ITermService termService) throws IOException, JsonParseException,
697
    public static Map<PresenceAbsenceTerm, Color> buildStatusColorMap(String statusColorJson, ITermService termService, IVocabularyService vocabularyService) throws IOException, JsonParseException,
691 698
            JsonMappingException {
692 699

  
693 700
        Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;
......
700 707
            MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, String.class);
701 708

  
702 709
            Map<String,String> statusColorMap = mapper.readValue(statusColorJson, mapType);
703
            UUID presenceTermVocabUuid = PresenceAbsenceTerm.NATIVE().getVocabulary().getUuid();
704 710
            presenceAbsenceTermColors = new HashMap<PresenceAbsenceTerm, Color>();
705 711
            PresenceAbsenceTerm paTerm = null;
706 712
            for(String statusId : statusColorMap.keySet()){
707 713
                try {
708 714
                    Color color = Color.decode(statusColorMap.get(statusId));
709
                    paTerm = termService.findByIdInVocabulary(statusId, presenceTermVocabUuid, PresenceAbsenceTerm.class);
715
                    // the below loop is  a hack for #4522 (custom status colors not working in cyprus portal)
716
                    // remove it once the ticket is solved
717
                    for(UUID vocabUuid : presenceAbsenceTermVocabularyUuids(vocabularyService)) {
718
                        paTerm = termService.findByIdInVocabulary(statusId, vocabUuid, PresenceAbsenceTerm.class);
719
                        if(paTerm != null) {
720
                            break;
721
                        }
722
                    }
710 723
                    if(paTerm != null){
711 724
                        presenceAbsenceTermColors.put(paTerm, color);
712 725
                    }
......
718 731
        return presenceAbsenceTermColors;
719 732
    }
720 733

  
734
    /**
735
     * this is a hack for #4522 (custom status colors not working in cyprus portal)
736
     * remove this method once the ticket is solved
737
     *
738
     * @param vocabularyService
739
     * @return
740
     */
741
    private static List<UUID> presenceAbsenceTermVocabularyUuids(IVocabularyService vocabularyService) {
742

  
743
        if(EditGeoServiceUtilities.presenceAbsenceTermVocabularyUuids == null) {
744

  
745
            List<UUID> uuids = new ArrayList<UUID>();
746
            // the default as first entry
747
            UUID presenceTermVocabUuid = PresenceAbsenceTerm.NATIVE().getVocabulary().getUuid();
748
            uuids.add(presenceTermVocabUuid);
749

  
750

  
751
            for(TermVocabulary vocab : vocabularyService.findByTermType(TermType.PresenceAbsenceTerm)) {
752
                if(!uuids.contains(vocab.getUuid())) {
753
                    uuids.add(vocab.getUuid());
754
                }
755
            }
756

  
757
            EditGeoServiceUtilities.presenceAbsenceTermVocabularyUuids = uuids;
758
        }
759

  
760
        return EditGeoServiceUtilities.presenceAbsenceTermVocabularyUuids;
761
    }
762

  
721 763

  
722 764
    /**
723 765
     * @param filteredDistributions

Also available in: Unified diff