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;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.model.common.User;
|
20
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @since 11.05.2009
|
25
|
*/
|
26
|
public abstract class DbImportStateBase<CONFIG extends DbImportConfiguratorBase, STATE extends DbImportStateBase> extends ImportStateBase<CONFIG, CdmImportBase> implements IPartitionedState {
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(DbImportStateBase.class);
|
29
|
|
30
|
public static final String CURRENT_OBJECT_NAMESPACE = "CurrentObjectNamespace";
|
31
|
public static final String CURRENT_OBJECT_ID = "CurrentObjectId";
|
32
|
|
33
|
private final Map<String, User> usernameMap = new HashMap<String, User>();
|
34
|
|
35
|
|
36
|
private Reference partitionSourceReference;
|
37
|
|
38
|
private final RelatedObjectsHelper relatedObjectsHelper = new RelatedObjectsHelper();
|
39
|
//holds the classifications needed for this partition, the key is a value that differentiate classifications
|
40
|
//like the taxons reference (secundum)
|
41
|
|
42
|
|
43
|
/**
|
44
|
* @param config
|
45
|
*/
|
46
|
protected DbImportStateBase(CONFIG config) {
|
47
|
super(config);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void addRelatedObject(Object namespace, String id, CdmBase relatedObject) {
|
52
|
this.relatedObjectsHelper.addRelatedObjet(namespace, id, relatedObject);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public CdmBase getRelatedObject(Object namespace, String id) {
|
57
|
return relatedObjectsHelper.getRelatedObject(namespace, id);
|
58
|
}
|
59
|
|
60
|
public<T extends CdmBase> T getRelatedObject(Object namespace, String id, Class<T> clazz) {
|
61
|
CdmBase cdmBase = relatedObjectsHelper.getRelatedObject(namespace, id);
|
62
|
T result = CdmBase.deproxy(cdmBase, clazz);
|
63
|
return result;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public void setRelatedObjects(Map<Object, Map<String, ? extends CdmBase>> relatedObjects) {
|
68
|
relatedObjectsHelper.setRelatedObjects(relatedObjects);
|
69
|
}
|
70
|
|
71
|
|
72
|
/**
|
73
|
* Stores the source reference for the time of a transaction. Needs to be
|
74
|
* deleted manually after transaction finishes to avoid memory leaks.
|
75
|
* @return
|
76
|
*/
|
77
|
@Override
|
78
|
public Reference getTransactionalSourceReference() {
|
79
|
return partitionSourceReference;
|
80
|
}
|
81
|
|
82
|
|
83
|
@Override
|
84
|
public void resetTransactionalSourceReference(){
|
85
|
this.partitionSourceReference = null;
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public void makeTransactionalSourceReference(IReferenceService service){
|
90
|
//TODO handle undefined sourceRefUuid
|
91
|
this.partitionSourceReference = service.find(this.getConfig().getSourceRefUuid());
|
92
|
if (this.partitionSourceReference == null){
|
93
|
this.partitionSourceReference = this.getConfig().getSourceReference();
|
94
|
service.saveOrUpdate(this.partitionSourceReference);
|
95
|
}
|
96
|
}
|
97
|
|
98
|
public User getUser(String username){
|
99
|
return usernameMap.get(username);
|
100
|
}
|
101
|
|
102
|
public void putUser(String username, User user){
|
103
|
usernameMap.put(username, user);
|
104
|
}
|
105
|
|
106
|
|
107
|
}
|