Revision a735bbbf
Added by Andreas Kohlbecker about 7 years ago
- ID a735bbbfccc284e24f355551d2496cd15e790243
- Parent a1dac6b2
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/EditConceptRelationshipPresenter.java | ||
---|---|---|
14 | 14 |
import java.util.Set; |
15 | 15 |
import java.util.UUID; |
16 | 16 |
|
17 |
import org.springframework.beans.factory.annotation.Autowired; |
|
18 |
import org.springframework.context.annotation.Scope; |
|
17 | 19 |
import org.springframework.transaction.TransactionStatus; |
18 | 20 |
|
19 | 21 |
import com.vaadin.data.util.filter.Compare; |
22 |
import com.vaadin.spring.annotation.SpringComponent; |
|
20 | 23 |
|
21 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
22 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
23 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
24 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
24 | 25 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
25 | 26 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
26 | 27 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
27 | 28 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
28 | 29 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
29 | 30 |
import eu.etaxonomy.cdm.vaadin.container.IdUuidName; |
30 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
|
31 | 31 |
|
32 | 32 |
/** |
33 | 33 |
* @author cmathew |
34 | 34 |
* @date 13 Apr 2015 |
35 | 35 |
* |
36 | 36 |
*/ |
37 |
@SpringComponent |
|
38 |
@Scope("prototype") |
|
37 | 39 |
public class EditConceptRelationshipPresenter { |
38 | 40 |
|
41 |
@Autowired |
|
42 |
private CdmRepository cdmRepo = null; |
|
43 |
|
|
39 | 44 |
private CdmSQLContainer taxonRTypeContainer; |
40 | 45 |
private CdmSQLContainer taxonRContainer; |
41 | 46 |
|
42 |
private final ITaxonService taxonService; |
|
43 |
private final ITermService termService; |
|
44 |
private final ICdmApplicationConfiguration app; |
|
45 |
|
|
46 | 47 |
public final static String REL_TYPE_KEY = "relTypeIun"; |
47 | 48 |
public final static String TO_TAXON_KEY = "toTaxonIun"; |
48 | 49 |
|
49 | 50 |
public EditConceptRelationshipPresenter() { |
50 |
taxonService = CdmSpringContextHelper.getTaxonService(); |
|
51 |
termService = CdmSpringContextHelper.getTermService(); |
|
52 |
app = CdmSpringContextHelper.getApplicationConfiguration(); |
|
53 | 51 |
} |
54 | 52 |
|
55 | 53 |
public CdmSQLContainer loadTaxonRelationshipTypeContainer() throws SQLException { |
... | ... | |
73 | 71 |
return taxonRContainer; |
74 | 72 |
} |
75 | 73 |
|
74 |
//@Transactional // FIXME use this annotation instead of the explicit start commit below |
|
76 | 75 |
public IdUuidName createRelationship(UUID fromTaxonUuid, UUID relTypeUuid, UUID toTaxonUuid) { |
77 |
TransactionStatus tx = app.startTransaction();
|
|
78 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
|
|
79 |
Taxon toTaxon = CdmBase.deproxy(taxonService.load(toTaxonUuid), Taxon.class);
|
|
80 |
TaxonRelationshipType relType = CdmBase.deproxy(termService.load(relTypeUuid), TaxonRelationshipType.class);
|
|
76 |
TransactionStatus tx = cdmRepo.startTransaction();
|
|
77 |
Taxon fromTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(fromTaxonUuid), Taxon.class);
|
|
78 |
Taxon toTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(toTaxonUuid), Taxon.class);
|
|
79 |
TaxonRelationshipType relType = CdmBase.deproxy(cdmRepo.getTermService().load(relTypeUuid), TaxonRelationshipType.class);
|
|
81 | 80 |
TaxonRelationship tr = fromTaxon.addTaxonRelation(toTaxon, relType, null, null); |
82 |
app.commitTransaction(tx);
|
|
81 |
cdmRepo.commitTransaction(tx);
|
|
83 | 82 |
return new IdUuidName(tr.getId(), tr.getUuid(), tr.getType().getTitleCache()); |
84 | 83 |
} |
85 | 84 |
|
86 |
|
|
85 |
//@Transactional // FIXME use this annotation instead of the explicit start commit below |
|
87 | 86 |
public void updateRelationship(UUID fromTaxonUuid, UUID taxonRelUuid, UUID newRelTypeUuid , UUID newToTaxonUuid) { |
88 |
TransactionStatus tx = app.startTransaction();
|
|
89 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
|
|
87 |
TransactionStatus tx = cdmRepo.startTransaction();
|
|
88 |
Taxon fromTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(fromTaxonUuid), Taxon.class);
|
|
90 | 89 |
for(TaxonRelationship tr : fromTaxon.getRelationsFromThisTaxon()) { |
91 | 90 |
if(tr.getUuid().equals(taxonRelUuid)) { |
92 | 91 |
if(newRelTypeUuid != null) { |
93 |
TaxonRelationshipType relType = CdmBase.deproxy(termService.load(newRelTypeUuid), TaxonRelationshipType.class);
|
|
92 |
TaxonRelationshipType relType = CdmBase.deproxy(cdmRepo.getTermService().load(newRelTypeUuid), TaxonRelationshipType.class);
|
|
94 | 93 |
tr.setType(relType); |
95 | 94 |
} |
96 | 95 |
if(newToTaxonUuid != null) { |
97 |
Taxon toTaxon = CdmBase.deproxy(taxonService.load(newToTaxonUuid), Taxon.class);
|
|
96 |
Taxon toTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(newToTaxonUuid), Taxon.class);
|
|
98 | 97 |
tr.setToTaxon(toTaxon); |
99 | 98 |
} |
100 | 99 |
} |
101 | 100 |
} |
102 |
app.commitTransaction(tx);
|
|
101 |
cdmRepo.commitTransaction(tx);
|
|
103 | 102 |
} |
104 | 103 |
|
105 |
|
|
104 |
//@Transactional // FIXME use this annotation instead of the explicit start commit below |
|
106 | 105 |
public void deleteRelationship(UUID fromTaxonUuid, UUID taxonRelUuid) { |
107 |
TransactionStatus tx = app.startTransaction();
|
|
108 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
|
|
106 |
TransactionStatus tx = cdmRepo.startTransaction();
|
|
107 |
Taxon fromTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(fromTaxonUuid), Taxon.class);
|
|
109 | 108 |
TaxonRelationship trToDelete = null; |
110 | 109 |
Set<TaxonRelationship> trList = fromTaxon.getRelationsFromThisTaxon(); |
111 | 110 |
for(TaxonRelationship tr : trList) { |
... | ... | |
116 | 115 |
if(trToDelete != null) { |
117 | 116 |
trList.remove(trToDelete); |
118 | 117 |
} |
119 |
app.commitTransaction(tx);
|
|
118 |
cdmRepo.commitTransaction(tx);
|
|
120 | 119 |
} |
121 | 120 |
|
122 | 121 |
|
123 |
|
|
122 |
//@Transactional // FIXME use this annotation instead of the explicit start commit below |
|
124 | 123 |
public Map<String, IdUuidName> getRelTypeToTaxonIunMap(UUID fromTaxonUuid, UUID taxonRelUuid) { |
125 | 124 |
Map<String, IdUuidName> relTypeToTaxonIunMap = new HashMap<String, IdUuidName>(); |
126 |
TransactionStatus tx = app.startTransaction();
|
|
127 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
|
|
125 |
TransactionStatus tx = cdmRepo.startTransaction();
|
|
126 |
Taxon fromTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(fromTaxonUuid), Taxon.class);
|
|
128 | 127 |
for(TaxonRelationship tr : fromTaxon.getRelationsFromThisTaxon()) { |
129 | 128 |
if(tr.getUuid().equals(taxonRelUuid)) { |
130 | 129 |
relTypeToTaxonIunMap.put(REL_TYPE_KEY, |
... | ... | |
133 | 132 |
new IdUuidName(tr.getToTaxon().getId(), tr.getToTaxon().getUuid(), tr.getToTaxon().getName().getTitleCache())); |
134 | 133 |
} |
135 | 134 |
} |
136 |
app.commitTransaction(tx);
|
|
135 |
cdmRepo.commitTransaction(tx);
|
|
137 | 136 |
return relTypeToTaxonIunMap; |
138 | 137 |
} |
139 | 138 |
|
140 | 139 |
public boolean canCreateRelationship(UUID fromTaxonUuid) { |
141 |
TransactionStatus tx = app.startTransaction();
|
|
142 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
|
|
140 |
TransactionStatus tx = cdmRepo.startTransaction();
|
|
141 |
Taxon fromTaxon = CdmBase.deproxy(cdmRepo.getTaxonService().load(fromTaxonUuid), Taxon.class);
|
|
143 | 142 |
boolean canCreateRelationship = true; |
144 | 143 |
Set<TaxonRelationship> trList = fromTaxon.getRelationsFromThisTaxon(); |
145 | 144 |
for(TaxonRelationship tr : trList) { |
... | ... | |
148 | 147 |
break; |
149 | 148 |
} |
150 | 149 |
} |
151 |
app.commitTransaction(tx);
|
|
150 |
cdmRepo.commitTransaction(tx);
|
|
152 | 151 |
return canCreateRelationship; |
153 | 152 |
} |
154 | 153 |
|
Also available in: Unified diff
ref #5285 attempt to avoid using the CdmSpringContextHelper
using DI to get rid of CdmSpringContextHelper, but got stuck due to the complexity and variety of the 'design patterns' that have been used.