Project

General

Profile

Download (2.64 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2017 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.app.common.tasks;
10

    
11
import org.apache.log4j.Logger;
12

    
13
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
14
import eu.etaxonomy.cdm.app.common.CdmDestinations;
15
import eu.etaxonomy.cdm.database.DbSchemaValidation;
16
import eu.etaxonomy.cdm.database.ICdmDataSource;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20

    
21
/**
22
 * Deduplicates certain classes.
23
 *
24
 * CAUTION: Deduplicating teams does not yet work correctly. Team members are often duplicated.
25
 *
26
 * @author a.mueller
27
 * @date 24.11.2017
28
 *
29
 */
30
public class Deduplicator {
31
    @SuppressWarnings("unused")
32
    private static final Logger logger = Logger.getLogger(Deduplicator.class);
33

    
34
    //database validation status (create, update, validate ...)
35
//  static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
36
//  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_cichorieae();
37
//  static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
38
    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_caryophyllales_spp();
39
//  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_caryo_spp();
40

    
41

    
42

    
43
   static boolean doPersons = false;
44
   static boolean doTeams = true;
45
   static boolean doReferences = false;
46

    
47

    
48
    private void doInvoke(ICdmDataSource destination){
49

    
50
        try {
51
            CdmApplicationController app = CdmApplicationController.NewInstance(destination, DbSchemaValidation.VALIDATE);
52

    
53
            if (doPersons){
54
                app.getAgentService().deduplicate(Person.class, null, null);
55
            }
56
            if (doTeams){
57
                app.getAgentService().deduplicate(Team.class, null, null);
58
            }
59
            if (doReferences){
60
                app.getReferenceService().deduplicate(Reference.class, null, null);
61
            }
62
        } catch (Exception e) {
63
            e.printStackTrace();
64
        }
65

    
66

    
67
    }
68

    
69
    /**
70
     * @param args
71
     */
72
    public static void main(String[] args) {
73
        ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
74

    
75
        System.out.println("Start updating caches for "+ destination.getDatabase() + "...");
76
        Deduplicator me = new Deduplicator();
77
        me.doInvoke(destination);
78
        System.exit(0);
79

    
80
    }
81
}
(2-2/2)