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