Project

General

Profile

Revision 2b161626

ID2b16162667d1001b587ec7ba2f5ac6b9df8370ba
Parent fa2b2dbb
Child ffb73a43

Added by Katja Luther over 1 year ago

add check for dna data

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
458 458
                    if (handleAssociatedUnits) {
459 459
                        importAssociatedUnits(state, item, derivedUnitFacade);
460 460
                    }
461
                    if (state.getConfig().getDnaSoure() != null){
462
                        importAssociatedDna(state, item, derivedUnitFacade);
463
                    }
461 464

  
462 465
                    state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, config),
463 466
                            derivedUnit);
......
925 928
                                            .getOccurrenceService().findFieldUnits(associatedUnit.getUuid(), null);
926 929
                                    // ignore field unit if associated unit has
927 930
                                    // more than one
928
                                    if (associatedFieldUnits.size() > 1) {
931
                                    if (associatedFieldUnit == null){
932
                                        state.getReport().addInfoMessage(
933
                                                String.format("%s has no field unit.", associatedUnit));
934
                                    }else if(associatedFieldUnits.size() > 1) {
929 935
                                        state.getReport().addInfoMessage(
930 936
                                                String.format("%s has more than one field unit.", associatedUnit));
931 937
                                    } else if (associatedFieldUnits.size() == 1) {
......
1050 1056
        state.setPrefix(currentPrefix);
1051 1057
    }
1052 1058

  
1059
    private void importAssociatedDna(Abcd206ImportState state, Object itemObject,
1060
            DerivedUnitFacade derivedUnitFacade){
1061
        URI dnaSource = state.getConfig().getDnaSoure();
1062
        String unitId = derivedUnitFacade.getCatalogNumber();
1063
        if (unitId == null) {
1064
            unitId = derivedUnitFacade.getAccessionNumber();
1065
        }
1066

  
1067
        UnitAssociationParser unitParser = new UnitAssociationParser(state.getPrefix(), state.getReport(),
1068
                state.getCdmRepository());
1069
        UnitAssociationWrapper unitAssociationWrapper = null;
1070

  
1071
        unitAssociationWrapper = unitParser.parseSiblings(unitId, dnaSource);
1072

  
1073

  
1074
        DerivedUnit currentUnit = state.getDerivedUnitBase();
1075
        // DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
1076
        FieldUnit currentFieldUnit = derivedUnitFacade.getFieldUnit(false);
1077
        if (unitAssociationWrapper != null) {
1078
            NodeList associatedUnits = unitAssociationWrapper.getAssociatedUnits();
1079
            if (associatedUnits != null) {
1080
                for (int m = 0; m < associatedUnits.getLength(); m++) {
1081
                    if (associatedUnits.item(m) instanceof Element) {
1082
                        state.reset();
1083
                        String associationType = AbcdParseUtility
1084
                                .parseFirstTextContent(((Element) associatedUnits.item(m))
1085
                                        .getElementsByTagName(state.getPrefix() + "AssociationType"));
1086

  
1087
                        Abcd206ImportParser.setUnitPropertiesXML((Element) associatedUnits.item(m),
1088
                                new Abcd206XMLFieldGetter(state.getDataHolder(), unitAssociationWrapper.getPrefix()),
1089
                                state);
1090
                        // logger.debug("derived unit: " +
1091
                        // state.getDerivedUnitBase().toString() + " associated
1092
                        // unit: " +state.getDataHolder().getKindOfUnit() + ", "
1093
                        // + state.getDataHolder().accessionNumber + ", " +
1094
                        // state.getDataHolder().getRecordBasis() + ", " +
1095
                        // state.getDataHolder().getUnitID());
1096

  
1097
                        handleSingleUnit(state, associatedUnits.item(m), false);
1098

  
1099
                        DerivedUnit associatedUnit = state.getDerivedUnitBase();
1100
                        FieldUnit associatedFieldUnit = null;
1101
                        java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository()
1102
                                .getOccurrenceService().findFieldUnits(associatedUnit.getUuid(), null);
1103
                        // ignore field unit if associated unit has more than
1104
                        // one
1105
                        if (associatedFieldUnits.size() > 1) {
1106
                            state.getReport()
1107
                                    .addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
1108
                        } else if (associatedFieldUnits.size() == 1) {
1109
                            associatedFieldUnit = associatedFieldUnits.iterator().next();
1110
                        }
1111
                        // parent-child relation:
1112
                        if (associationType.contains("individual") || associationType.contains("culture")
1113
                                || associationType.contains("sample") ||  associationType.contains("isolated")) {
1114
                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(currentUnit,
1115
                                    associatedUnit, DerivationEventType.ACCESSIONING());
1116

  
1117
                            updatedDerivationEvent.setDescription(associationType);
1118
                            if (associatedFieldUnit != null && associatedFieldUnit != currentFieldUnit) {
1119
                                associatedFieldUnit.removeDerivationEvent(updatedDerivationEvent);
1120
                                state.getCdmRepository().getOccurrenceService().delete(associatedFieldUnit);
1121
                            }
1122
                            state.getReport().addDerivate(associatedUnit, currentUnit, state.getConfig());
1123
                        }
1124
                        save(associatedUnit, state);
1125

  
1126
                    }
1127
                }
1128
            }
1129
        }
1130
        state.reset();
1131
        state.setDerivedUnitBase(currentUnit);
1132

  
1133

  
1134

  
1135
    }
1136

  
1137

  
1138

  
1053 1139
    /**
1054 1140
     * @param derivedUnitFacade
1055 1141
     * @param sour
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportConfigurator.java
43 43

  
44 44
    private boolean getSiblings = false;
45 45

  
46

  
46
    private URI dnaSoure = URI.create("https://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=DNA_Bank");
47 47

  
48 48
    @Override
49 49
    @SuppressWarnings("unchecked")
......
138 138

  
139 139

  
140 140

  
141
    public URI getDnaSoure() {
142
        return dnaSoure;
143
    }
144

  
145
    public void setDnaSoure(URI dnaSoure) {
146
        this.dnaSoure = dnaSoure;
147
    }
148

  
141 149
    @Override
142 150
    public Reference getSourceReference() {
143 151
        //TODO

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)