migrating to cdmlib-plugin 2.0.0.20 including new term loading
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / datasource / CdmTransactionController.java
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.taxeditor.datasource;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16 import org.springframework.transaction.TransactionStatus;
17
18 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
19 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;
22 import eu.etaxonomy.taxeditor.model.CdmUtil;
23
24 /**
25 * @author p.ciardelli
26 * @created 16.12.2008
27 * @version 1.0
28 */
29 public class CdmTransactionController {
30 private static final Logger logger = Logger
31 .getLogger(CdmTransactionController.class);
32
33 private static CdmApplicationController applicationController;
34 private static TransactionStatus txStatus;
35 private CdmTransactionController controller;
36
37 public static void startTransaction() {
38
39 txStatus = getCdmAppController().startTransaction();
40
41 // Workaround - nom statii were causing a lazy loading error
42 List<NomenclaturalStatusType> list = new ArrayList<NomenclaturalStatusType>();
43 list.add(NomenclaturalStatusType.SUPERFLUOUS());
44 list.add(NomenclaturalStatusType.NUDUM());
45 list.add(NomenclaturalStatusType.ILLEGITIMATE());
46 list.add(NomenclaturalStatusType.INVALID());
47 list.add(NomenclaturalStatusType.CONSERVED());
48 list.add(NomenclaturalStatusType.ALTERNATIVE());
49 list.add(NomenclaturalStatusType.REJECTED());
50 list.add(NomenclaturalStatusType.REJECTED_PROP());
51 list.add(NomenclaturalStatusType.PROVISIONAL());
52 list.add(NomenclaturalStatusType.SUBNUDUM());
53 list.add(NomenclaturalStatusType.OPUS_UTIQUE_OPPR());
54 list.add(NomenclaturalStatusType.AMBIGUOUS());
55 list.add(NomenclaturalStatusType.DOUBTFUL());
56 list.add(NomenclaturalStatusType.CONFUSUM());
57 list.add(NomenclaturalStatusType.UTIQUE_REJECTED());
58 list.add(NomenclaturalStatusType.CONSERVED_PROP());
59 list.add(NomenclaturalStatusType.LEGITIMATE());
60 list.add(NomenclaturalStatusType.NOVUM());
61 list.add(NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED());
62 list.add(NomenclaturalStatusType.SANCTIONED());
63 list.add(NomenclaturalStatusType.COMBINATION_INVALID());
64 list.add(NomenclaturalStatusType.VALID());
65 for (NomenclaturalStatusType status : list){
66 //applicationController.getTermService().saveTerm(status);
67 }
68 }
69
70 public static void commitTransaction() {
71
72 // Make sure transaction exists
73 if (txStatus == null) {
74 throw new IllegalStateException("Transaction was NULL - be sure to call startTransaction first.");
75 }
76
77 getCdmAppController().commitTransaction(txStatus);
78 txStatus = null;
79 }
80
81 public static void setApplicationController(CdmApplicationController applicationController) {
82 CdmTransactionController.applicationController = applicationController;
83 }
84
85 private static CdmApplicationController getCdmAppController() {
86
87 // Make sure the app controller has been set
88 if (applicationController == null) {
89 throw new IllegalStateException("CdmApplicationController not yet set.");
90 }
91 return applicationController;
92 }
93
94 public static void addTaxonToTransaction(Taxon taxon) {
95 CdmUtil.getTaxonService().saveTaxon(taxon);
96 }
97
98 public static void addSessionTaxaToTransaction() {
99 CdmUtil.getTaxonService().saveTaxonAll(
100 CdmSessionDataRepository.getDefault().getAllTaxa());
101 }
102 }