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.app.greece;
|
11
|
|
12
|
import java.util.List;
|
13
|
import java.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.transaction.TransactionStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
20
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
21
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
22
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
23
|
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
|
24
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
25
|
import eu.etaxonomy.cdm.model.media.Media;
|
26
|
import eu.etaxonomy.cdm.model.media.Rights;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @since 05.2017
|
31
|
*/
|
32
|
public class GreeceImagesUpdaterTurlandActivator {
|
33
|
@SuppressWarnings("unused")
|
34
|
private static final Logger logger = Logger.getLogger(GreeceImagesUpdaterTurlandActivator.class);
|
35
|
|
36
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
37
|
//static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
38
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_greece_checklist();
|
39
|
|
40
|
static boolean testOnly = false;
|
41
|
|
42
|
private void updateRights(ICdmDataSource cdmDestination){
|
43
|
CdmApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, DbSchemaValidation.VALIDATE);
|
44
|
TransactionStatus tx = app.startTransaction();
|
45
|
|
46
|
UUID uuidLicence = UUID.fromString("b1d1b1d2-dc79-4e13-b304-0bce50a648cc");
|
47
|
List<Media> list = app.getMediaService().list(Media.class, null, null, null, null);
|
48
|
Rights licenceRight = app.getRightsService().find(uuidLicence);
|
49
|
AgentBase<?> turland = app.getAgentService().find(3972);
|
50
|
int i = 0;
|
51
|
for (Media media : list){
|
52
|
Set<Rights> rights = media.getRights();
|
53
|
if (rights.size() == 1){
|
54
|
Rights right = rights.iterator().next();
|
55
|
if (right.getAgent().equals(turland)){
|
56
|
rights.add(licenceRight);
|
57
|
i++;
|
58
|
}
|
59
|
}
|
60
|
}
|
61
|
|
62
|
if (testOnly){
|
63
|
tx.setRollbackOnly();
|
64
|
}
|
65
|
app.commitTransaction(tx);
|
66
|
System.out.println("Updated " + i + " licences");
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* @param args
|
72
|
*/
|
73
|
public static void main(String[] args) {
|
74
|
GreeceImagesUpdaterTurlandActivator me = new GreeceImagesUpdaterTurlandActivator();
|
75
|
me.updateRights(cdmDestination);
|
76
|
// me.test();
|
77
|
System.exit(0);
|
78
|
}
|
79
|
|
80
|
}
|