Project

General

Profile

« Previous | Next » 

Revision 2eaad1b1

Added by Andreas Müller over 4 years ago

ref #1444, ref #8509 LastAction(Date) handling for ERMS

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsImportBase.java
364 364
		return markerType;
365 365
	}
366 366

  
367
    protected AnnotationType getAnnotationType(UUID uuid, String label, String text, String labelAbbrev){
368
        AnnotationType annotationType = (AnnotationType)getTermService().find(uuid);
369
        if (annotationType == null){
370
            annotationType = AnnotationType.NewInstance(label, text, labelAbbrev);
371
            annotationType.setUuid(uuid);
372
            getTermService().save(annotationType);
373
        }
374
        return annotationType;
375
    }
367 376

  
368 377
	/**
369 378
	 * Reads a foreign key field from the result set and adds its value to the idSet.
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsTaxonImport.java
23 23

  
24 24
import eu.etaxonomy.cdm.io.common.IOValidator;
25 25
import eu.etaxonomy.cdm.io.common.mapping.DbIgnoreMapper;
26
import eu.etaxonomy.cdm.io.common.mapping.DbImportAnnotationMapper;
26 27
import eu.etaxonomy.cdm.io.common.mapping.DbImportExtensionMapper;
27 28
import eu.etaxonomy.cdm.io.common.mapping.DbImportLsidMapper;
28 29
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping;
......
31 32
import eu.etaxonomy.cdm.io.common.mapping.DbImportStringMapper;
32 33
import eu.etaxonomy.cdm.io.common.mapping.DbNotYetImplementedMapper;
33 34
import eu.etaxonomy.cdm.io.common.mapping.IMappingImport;
35
import eu.etaxonomy.cdm.io.common.mapping.out.DbLastActionMapper;
34 36
import eu.etaxonomy.cdm.io.pesi.erms.validation.ErmsTaxonImportValidator;
35 37
import eu.etaxonomy.cdm.io.pesi.out.PesiTaxonExport;
38
import eu.etaxonomy.cdm.model.common.AnnotationType;
36 39
import eu.etaxonomy.cdm.model.common.CdmBase;
37 40
import eu.etaxonomy.cdm.model.common.ExtensionType;
41
import eu.etaxonomy.cdm.model.common.MarkerType;
38 42
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
39 43
import eu.etaxonomy.cdm.model.name.Rank;
40 44
import eu.etaxonomy.cdm.model.name.TaxonName;
......
95 99

  
96 100
			ExtensionType fossilStatusExtType = getExtensionType(ErmsTransformer.uuidExtFossilStatus, "fossil status", "fossil status", "fos. stat.");
97 101
			mapping.addMapper(DbImportExtensionMapper.NewInstance("fossil_name", fossilStatusExtType));
98
//			mapping.addMapper(DbImportExtensionTypeCreationMapper.NewInstance("fossil_name", EXTENSION_TYPE_NAMESPACE, "fossil_name", "fossil_name", "fossil_name"));
99 102

  
100 103
			ExtensionType unacceptExtType = getExtensionType(ErmsTransformer.uuidExtUnacceptReason, "unaccept reason", "unaccept reason", "reason");
101 104
			mapping.addMapper(DbImportExtensionMapper.NewInstance("tu_unacceptreason", unacceptExtType));
......
107 110
			mapping.addMapper(DbImportMarkerMapper.NewInstance("tu_brackish", ErmsTransformer.uuidMarkerBrackish, "brackish", "brackish", "brackish", null));
108 111
			mapping.addMapper(DbImportMarkerMapper.NewInstance("tu_fresh", ErmsTransformer.uuidMarkerFreshwater, "freshwater", "fresh", "fresh", null));
109 112
			mapping.addMapper(DbImportMarkerMapper.NewInstance("tu_terrestrial", ErmsTransformer.uuidMarkerTerrestrial, "terrestrial", "terrestrial", "terrestrial", null));
113
			AnnotationType lastActionDateType = getAnnotationType(DbLastActionMapper.uuidAnnotationTypeLastActionDate, "Last action date", "Last action date", null);
114
			mapping.addMapper(DbImportAnnotationMapper.NewInstance("lastActionDate", lastActionDateType));
115
            AnnotationType lastActionType = getAnnotationType(DbLastActionMapper.uuidAnnotationTypeLastAction, "Last action", "Last action", null);
116
            MarkerType hasNoLastActionMarkerType = getMarkerType(DbLastActionMapper.uuidMarkerTypeHasNoLastAction, "has no last action", "No last action information available", "no last action");
117
            mapping.addMapper(DbImportAnnotationMapper.NewInstance("lastAction", lastActionType, hasNoLastActionMarkerType));
110 118

  
111 119
//			UUID hiddenUuid = ErmsTransformer.uuidHidden;
112 120
//			mapping.addMapper(DbImportMarkerCreationMapper.Mapper.NewInstance("qualitystatus_name", qualityUuid, "quality status", "quality status", "quality status")); //checked by Tax Editor ERMS1.1, Added by db management team (2x), checked by Tax Editor
......
126 134
	protected String getRecordQuery(ErmsImportConfigurator config) {
127 135
		String strSelect = " SELECT tu.*, parent1.tu_name AS parent1name, parent2.tu_name AS parent2name, parent3.tu_name AS parent3name, "
128 136
			+ " parent1.tu_rank AS parent1rank, parent2.tu_rank AS parent2rank, parent3.tu_rank AS parent3rank, " +
129
			" status.status_id as status_id, status.status_name, fossil.fossil_name, qualitystatus.qualitystatus_name";
137
			" status.status_id as status_id, status.status_name, fossil.fossil_name, qualitystatus.qualitystatus_name,"
138
			+ " gr.date lastActionDate, a.action_name lastAction";
130 139
		String strFrom = " FROM tu  LEFT OUTER JOIN  tu AS parent1 ON parent1.id = tu.tu_parent " +
131 140
				" LEFT OUTER JOIN   tu AS parent2  ON parent2.id = parent1.tu_parent " +
132 141
				" LEFT OUTER JOIN tu AS parent3 ON parent2.tu_parent = parent3.id " +
133 142
				" LEFT OUTER JOIN status ON tu.tu_status = status.status_id " +
134 143
				" LEFT OUTER JOIN fossil ON tu.tu_fossil = fossil.fossil_id " +
135
				" LEFT OUTER JOIN qualitystatus ON tu.tu_qualitystatus = qualitystatus.id ";
144
				" LEFT OUTER JOIN qualitystatus ON tu.tu_qualitystatus = qualitystatus.id " +
145
				" LEFT JOIN ( SELECT maxDate.tu_id, maxDate.date, max(action_id) action_id " +
146
				   " FROM (SELECT tu_id, max(s.sessiondate) date FROM  tu_sessions MN INNER JOIN sessions s ON s.id = MN.session_id GROUP BY tu_id) maxDate " +
147
				   " INNER JOIN (SELECT MN2.tu_id, MN2.action_id, s2.sessiondate FROM tu_sessions MN2  INNER JOIN sessions s2 ON s2.id = MN2.session_id) as a ON a.tu_id = maxDate.tu_id AND a.sessiondate = maxDate.date " +
148
				   " GROUP BY maxDate.tu_id,  maxDate.date) as gr ON tu.id = gr.tu_id " +
149
				" LEFT JOIN actions a ON a.id = gr.action_id ";
136 150
		String strWhere = " WHERE ( tu.id IN (" + ID_LIST_TOKEN + ") )";
137 151
		String strRecordQuery = strSelect + strFrom + strWhere;
138 152
		return strRecordQuery;

Also available in: Unified diff