Revision f905a388
Added by Andreas Müller almost 2 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/mapping/out/CreatedAndNotesMapper.java | ||
---|---|---|
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;import org.apache.logging.log4j.Logger; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
18 |
import eu.etaxonomy.cdm.io.common.DbExportStateBase; |
|
19 |
import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase; |
|
20 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
|
21 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
22 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
|
23 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
24 |
|
|
25 |
/** |
|
26 |
* @author a.mueller |
|
27 |
* @since 12.05.2009 |
|
28 |
* @version 1.0 |
|
29 |
*/ |
|
30 |
public class CreatedAndNotesMapper extends MultipleAttributeMapperBase<DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{ |
|
31 |
@SuppressWarnings("unused") |
|
32 |
private static final Logger logger = LogManager.getLogger(CreatedAndNotesMapper.class); |
|
33 |
|
|
34 |
public static CreatedAndNotesMapper NewInstance(){ |
|
35 |
return new CreatedAndNotesMapper(true); |
|
36 |
} |
|
37 |
|
|
38 |
public static CreatedAndNotesMapper NewInstance(boolean withUpdate){ |
|
39 |
return new CreatedAndNotesMapper(withUpdate); |
|
40 |
} |
|
41 |
|
|
42 |
|
|
43 |
/** |
|
44 |
* @param dbAttributString |
|
45 |
* @param cdmAttributeString |
|
46 |
*/ |
|
47 |
private CreatedAndNotesMapper(boolean withUpdate) { |
|
48 |
singleMappers.add(DbUserMapper.NewInstance("createdBy", "Created_Who")); |
|
49 |
singleMappers.add(DbDateMapper.NewInstance("created", "Created_When")); |
|
50 |
singleMappers.add(MethodMapper.NewInstance("Notes", this.getClass(), "getNotes", AnnotatableEntity.class)); |
|
51 |
if (withUpdate){ |
|
52 |
singleMappers.add(DbUserMapper.NewInstance("updatedBy", "Updated_Who")); |
|
53 |
singleMappers.add(DbDateMapper.NewInstance("updated", "Updated_When")); |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
/* (non-Javadoc) |
|
59 |
* @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) |
|
60 |
*/ |
|
61 |
public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase<?, IExportTransformer> state, String tableName) { |
|
62 |
for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){ |
|
63 |
mapper.initialize(stmt, index, state, tableName); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
/* (non-Javadoc) |
|
69 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#invoke(eu.etaxonomy.cdm.model.common.CdmBase) |
|
70 |
*/ |
|
71 |
public boolean invoke(CdmBase cdmBase) throws SQLException { |
|
72 |
boolean result = true; |
|
73 |
for (DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> mapper : singleMappers){ |
|
74 |
result &= mapper.invoke(cdmBase); |
|
75 |
} |
|
76 |
return result; |
|
77 |
} |
|
78 |
|
|
79 |
//used by MethodMapper |
|
80 |
@SuppressWarnings("unused") |
|
81 |
private static String getNotes(AnnotatableEntity obj){ |
|
82 |
String result = ""; |
|
83 |
String separator = ";"; |
|
84 |
for (Annotation annotation :obj.getAnnotations()){ |
|
85 |
if (! AnnotationType.TECHNICAL().equals(annotation.getAnnotationType())){ |
|
86 |
if (! ( annotation.getText() != null && annotation.getText().startsWith("ORDER:"))){ //TODO casus Salvador, should be stored in Extension ones extensions are also for annotatable entities |
|
87 |
result = CdmUtils.concat(separator, result, annotation.getText()); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
return (result.trim().equals("")? null : result); |
|
92 |
} |
|
93 |
|
|
94 |
} |
|
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 |
} |
Also available in: Unified diff
cleanup