Project

General

Profile

Download (2.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.io.cdm2cdm;
10

    
11
import java.util.HashMap;
12
import java.util.HashSet;
13
import java.util.Map;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmRepository;
18
import eu.etaxonomy.cdm.io.common.ImportStateBase;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20

    
21
/**
22
 * Import state base class for migrating data from one CDM instance to another.
23
 *
24
 * @author a.mueller
25
 * @since 17.08.2019
26
 */
27
public class Cdm2CdmImportState
28
        extends ImportStateBase<Cdm2CdmImportConfigurator,Cdm2CdmImportBase>{
29

    
30
    private ICdmRepository sourceRepository;
31

    
32
    private Map<UUID, CdmBase> permanentCache = new HashMap<>();
33

    
34
    private Map<UUID, CdmBase> sessionCache = new HashMap<>();
35
    private Map<Class,Set<UUID>> existingObjects = new HashMap<>();
36
    private Set<CdmBase> toSave = new HashSet<>();
37

    
38
//************************ CONSTRUCTOR **********************************/
39

    
40
    protected Cdm2CdmImportState(Cdm2CdmImportConfigurator config) {
41
        super(config);
42
    }
43

    
44
// ************************* GETTER / SETTER ****************************/
45

    
46
    public ICdmRepository getSourceRepository() {
47
        return sourceRepository;
48
    }
49
    public void setSourceRepository(ICdmRepository sourceRepository) {
50
        this.sourceRepository = sourceRepository;
51
    }
52

    
53
    public CdmBase getPermanent(UUID uuid) {
54
        return permanentCache.get(uuid);
55
    }
56
    public void putPermanent(UUID uuid, CdmBase cdmBase) {
57
        permanentCache.put(uuid, cdmBase);
58
    }
59

    
60
    //session cache
61
    public CdmBase getFromSessionCache(UUID uuid) {
62
        return sessionCache.get(uuid);
63
    }
64
    public void putToSessionCache(CdmBase cdmBase) {
65
        this.sessionCache.put(cdmBase.getUuid(), cdmBase);
66
    }
67
    public void clearSessionCache(){
68
        this.sessionCache.clear();
69
    }
70

    
71
    //existing objects
72
    public Set<UUID> getExistingObjects(Class clazz) {
73
        return existingObjects.get(clazz);
74
    }
75
    public void putExistingObjects(Class clazz, Set<UUID> uuids) {
76
        this.existingObjects.put(clazz, uuids);
77
    }
78

    
79
    //to save
80
    public Set<CdmBase> getToSave() {
81
        return toSave;
82
    }
83
    public void addToSave(CdmBase toSave) {
84
        this.toSave.add(toSave);
85
    }
86
    public void removeToSave(CdmBase toSave) {
87
        this.toSave.add(toSave);
88
    }
89
    public void clearToSave() {
90
        this.toSave.clear();
91
    }
92
}
(4-4/6)