Project

General

Profile

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

    
11
package eu.etaxonomy.cdm.io.common;
12

    
13
import java.util.HashMap;
14
import java.util.Map;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.api.service.IReferenceService;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.common.User;
21
import eu.etaxonomy.cdm.model.reference.Reference;
22

    
23
/**
24
 * @author a.mueller
25
 * @created 11.05.2009
26
 */
27
public abstract class DbImportStateBase<CONFIG extends DbImportConfiguratorBase, STATE extends DbImportStateBase> extends ImportStateBase<CONFIG, CdmImportBase> implements IPartitionedState {
28
	@SuppressWarnings("unused")
29
	private static final Logger logger = Logger.getLogger(DbImportStateBase.class);
30

    
31
	public static final String CURRENT_OBJECT_NAMESPACE = "CurrentObjectNamespace";
32
	public static final String CURRENT_OBJECT_ID = "CurrentObjectId";
33

    
34
	private final Map<String, User> usernameMap = new HashMap<String, User>();
35

    
36

    
37
	private Reference partitionSourceReference;
38

    
39
	private final RelatedObjectsHelper relatedObjectsHelper = new RelatedObjectsHelper();
40
	//holds the classifications needed for this partition, the key is a value that differentiate classifications
41
	//like the taxons reference (secundum)
42

    
43

    
44
	/**
45
	 * @param config
46
	 */
47
	protected DbImportStateBase(CONFIG config) {
48
		super(config);
49
	}
50

    
51
	@Override
52
	public void addRelatedObject(Object namespace, String id, CdmBase relatedObject) {
53
		this.relatedObjectsHelper.addRelatedObjet(namespace, id, relatedObject);
54
	}
55

    
56
	@Override
57
	public CdmBase getRelatedObject(Object namespace, String id) {
58
		return relatedObjectsHelper.getRelatedObject(namespace, id);
59
	}
60

    
61
	public<T extends CdmBase> T getRelatedObject(Object namespace, String id, Class<T> clazz) {
62
		CdmBase cdmBase = relatedObjectsHelper.getRelatedObject(namespace, id);
63
		T result = CdmBase.deproxy(cdmBase, clazz);
64
		return result;
65
	}
66

    
67
	@Override
68
    public void setRelatedObjects(Map<Object, Map<String, ? extends CdmBase>> relatedObjects) {
69
		relatedObjectsHelper.setRelatedObjects(relatedObjects);
70
	}
71

    
72

    
73
	/**
74
	 * Stores the source reference for the time of a transaction. Needs to be
75
	 * deleted manually after transaction finishes to avoid memory leaks.
76
	 * @return
77
	 */
78
	@Override
79
    public Reference getTransactionalSourceReference() {
80
		return partitionSourceReference;
81
	}
82

    
83

    
84
	@Override
85
    public void resetTransactionalSourceReference(){
86
		this.partitionSourceReference = null;
87
	}
88

    
89
	@Override
90
    public void makeTransactionalSourceReference(IReferenceService service){
91
		//TODO handle undefined sourceRefUuid
92
		this.partitionSourceReference = service.find(this.getConfig().getSourceRefUuid());
93
		if (this.partitionSourceReference == null){
94
			this.partitionSourceReference = this.getConfig().getSourceReference();
95
			service.saveOrUpdate(this.partitionSourceReference);
96
		}
97
	}
98

    
99
	public User getUser(String username){
100
		return usernameMap.get(username);
101
	}
102

    
103
	public void putUser(String username, User user){
104
		usernameMap.put(username, user);
105
	}
106

    
107

    
108
}
(17-17/59)