Project

General

Profile

Download (3.28 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.io.pesi.out;
11

    
12
import java.sql.PreparedStatement;
13
import java.sql.SQLException;
14
import java.util.Collection;
15
import java.util.HashSet;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.log4j.Logger;
20

    
21
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
22
import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
23
import eu.etaxonomy.cdm.io.common.mapping.out.DbAnnotationMapper;
24
import eu.etaxonomy.cdm.io.common.mapping.out.DbExportNotYetImplementedMapper;
25
import eu.etaxonomy.cdm.io.common.mapping.out.DbLastActionMapper;
26
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleAttributeExportMapperBase;
27
import eu.etaxonomy.cdm.io.common.mapping.out.IDbExportMapper;
28
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
29
import eu.etaxonomy.cdm.io.common.mapping.out.IndexCounter;
30
import eu.etaxonomy.cdm.io.pesi.erms.ErmsTransformer;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32

    
33
/**
34
 * @author a.mueller
35
 * @since 12.05.2009
36
 */
37
public class ExpertsAndLastActionMapper
38
        extends MultipleAttributeMapperBase<DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>>
39
        implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
40

    
41
    @SuppressWarnings("unused")
42
	private static final Logger logger = Logger.getLogger(ExpertsAndLastActionMapper.class);
43

    
44
	private static final boolean IS_ACTION_TYPE = true;
45

    
46
	public static ExpertsAndLastActionMapper NewInstance(){
47
		return new ExpertsAndLastActionMapper();
48
	}
49

    
50
	private ExpertsAndLastActionMapper() {
51
		singleMappers.add(DbLastActionMapper.NewInstance("LastActionDate", ! IS_ACTION_TYPE));
52
		singleMappers.add(DbLastActionMapper.NewInstance("LastAction", IS_ACTION_TYPE));
53
		singleMappers.add(DbAnnotationMapper.NewIncludedInstance(getSpeciesExpertNameType(), "SpeciesExpertName"));
54
		singleMappers.add(DbExportNotYetImplementedMapper.NewInstance("SpeciesExpertName", "Only implemented for ERMS until now. For other need to better understand what the species expert name is"));
55
		singleMappers.add(DbExportNotYetImplementedMapper.NewInstance("SpeciesExpertGUID", "SpeciesExpertGUID derives from an external mapeing list: name to GUID from expertsDB"));
56
	}
57

    
58
    private Collection<UUID> getSpeciesExpertNameType() {
59
        Set<UUID> result = new HashSet<>();
60
        result.add(ErmsTransformer.uuidAnnSpeciesExpertName);
61
        return result;
62
    }
63

    
64
    @Override
65
    public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase<?, IExportTransformer> state, String tableName) {
66
		for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){
67
			mapper.initialize(stmt, index, state, tableName);
68
		}
69
	}
70

    
71
	@Override
72
    public boolean invoke(CdmBase cdmBase) throws SQLException {
73
		boolean result = true;
74
		for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){
75
			result &= mapper.invoke(cdmBase);
76
		}
77
		return result;
78
	}
79
}
(1-1/14)