Project

General

Profile

Download (3.5 KB) Statistics
| Branch: | Tag: | 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.common.mapping.out;
11

    
12
import java.sql.PreparedStatement;
13
import java.sql.SQLException;
14

    
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.common.CdmUtils;
19
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
20
import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
21
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
22
import eu.etaxonomy.cdm.model.common.Annotation;
23
import eu.etaxonomy.cdm.model.common.AnnotationType;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25

    
26
/**
27
 * @author a.mueller
28
 * @since 12.05.2009
29
 */
30
public class CreatedAndNotesMapper extends MultipleAttributeMapperBase<DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
31

    
32
    @SuppressWarnings("unused")
33
	private static final Logger logger = LogManager.getLogger();
34

    
35
	public static CreatedAndNotesMapper NewInstance(){
36
		return new CreatedAndNotesMapper(true);
37
	}
38

    
39
	public static CreatedAndNotesMapper NewInstance(boolean withUpdate){
40
		return new CreatedAndNotesMapper(withUpdate);
41
	}
42

    
43

    
44
	/**
45
	 * @param dbAttributString
46
	 * @param cdmAttributeString
47
	 */
48
	private CreatedAndNotesMapper(boolean withUpdate) {
49
		singleMappers.add(DbUserMapper.NewInstance("createdBy", "Created_Who"));
50
		singleMappers.add(DbDateMapper.NewInstance("created", "Created_When"));
51
		singleMappers.add(MethodMapper.NewInstance("Notes", this.getClass(), "getNotes", AnnotatableEntity.class));
52
		if (withUpdate){
53
			singleMappers.add(DbUserMapper.NewInstance("updatedBy", "Updated_Who"));
54
			singleMappers.add(DbDateMapper.NewInstance("updated", "Updated_When"));
55
		}
56
	}
57

    
58

    
59
	/* (non-Javadoc)
60
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#initialize(java.sql.PreparedStatement, eu.etaxonomy.cdm.io.berlinModel.out.mapper.IndexCounter, eu.etaxonomy.cdm.io.berlinModel.out.DbExportState)
61
	 */
62
	@Override
63
    public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase<?, IExportTransformer> state, String tableName) {
64
		for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){
65
			mapper.initialize(stmt, index, state, tableName);
66
		}
67
	}
68

    
69

    
70
	/* (non-Javadoc)
71
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#invoke(eu.etaxonomy.cdm.model.common.CdmBase)
72
	 */
73
	@Override
74
    public boolean invoke(CdmBase cdmBase) throws SQLException {
75
		boolean result = true;
76
		for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){
77
			result &= mapper.invoke(cdmBase);
78
		}
79
		return result;
80
	}
81

    
82
	//used by MethodMapper
83
	@SuppressWarnings("unused")
84
	private static String getNotes(AnnotatableEntity obj){
85
		String result = "";
86
		String separator = ";";
87
		for (Annotation annotation :obj.getAnnotations()){
88
			if (! AnnotationType.TECHNICAL().equals(annotation.getAnnotationType())){
89
				if (! ( annotation.getText() != null && annotation.getText().startsWith("ORDER:"))){  //TODO casus Salvador, should be stored in Extension ones extensions are also for annotatable entities
90
					result = CdmUtils.concat(separator, result, annotation.getText());
91
				}
92
			}
93
		}
94
		return (result.trim().equals("")? null : result);
95
	}
96

    
97
}
(3-3/44)