Revision 2ba67e3f
Added by Cherian Mathew about 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/EditConceptRelationshipPresenter.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.vaadin.presenter; |
11 | 11 |
|
12 | 12 |
import java.sql.SQLException; |
13 |
import java.util.Set; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 |
import org.springframework.transaction.TransactionStatus; |
|
13 | 17 |
|
14 | 18 |
import com.vaadin.data.util.filter.Compare; |
15 | 19 |
|
20 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
21 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
22 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
23 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
26 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
16 | 27 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
28 |
import eu.etaxonomy.cdm.vaadin.container.IdUuidName; |
|
29 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
|
17 | 30 |
|
18 | 31 |
/** |
19 | 32 |
* @author cmathew |
... | ... | |
25 | 38 |
private CdmSQLContainer taxonRTypeContainer; |
26 | 39 |
private CdmSQLContainer taxonRContainer; |
27 | 40 |
|
41 |
private final ITaxonService taxonService; |
|
42 |
private final ITermService termService; |
|
43 |
private final ICdmApplicationConfiguration app; |
|
44 |
|
|
45 |
public EditConceptRelationshipPresenter() { |
|
46 |
taxonService = CdmSpringContextHelper.getTaxonService(); |
|
47 |
termService = CdmSpringContextHelper.getTermService(); |
|
48 |
app = CdmSpringContextHelper.getApplicationConfiguration(); |
|
49 |
} |
|
28 | 50 |
|
29 | 51 |
public CdmSQLContainer loadTaxonRelationshipTypeContainer() throws SQLException { |
30 | 52 |
taxonRTypeContainer = CdmSQLContainer.newInstance("DefinedTermBase"); |
31 | 53 |
taxonRTypeContainer.addContainerFilter(new Compare.Equal("DTYPE","TaxonRelationshipType")); |
54 |
taxonRTypeContainer.setPageLength(100); |
|
32 | 55 |
return taxonRTypeContainer; |
33 | 56 |
} |
34 | 57 |
|
... | ... | |
46 | 69 |
return taxonRContainer; |
47 | 70 |
} |
48 | 71 |
|
72 |
public IdUuidName createRelationship(UUID fromTaxonUuid, UUID relTypeUuid, UUID toTaxonUuid) { |
|
73 |
TransactionStatus tx = app.startTransaction(); |
|
74 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class); |
|
75 |
Taxon toTaxon = CdmBase.deproxy(taxonService.load(toTaxonUuid), Taxon.class); |
|
76 |
TaxonRelationshipType relType = CdmBase.deproxy(termService.load(relTypeUuid), TaxonRelationshipType.class); |
|
77 |
TaxonRelationship tr = fromTaxon.addTaxonRelation(toTaxon, relType, null, null); |
|
78 |
app.commitTransaction(tx); |
|
79 |
return new IdUuidName(tr.getId(), tr.getUuid(), tr.getType().getTitleCache()); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
public void updateRelationship(UUID fromTaxonUuid, UUID taxonRelUuid, UUID newRelTypeUuid , UUID newToTaxonUuid) { |
|
84 |
TransactionStatus tx = app.startTransaction(); |
|
85 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class); |
|
86 |
for(TaxonRelationship tr : fromTaxon.getRelationsFromThisTaxon()) { |
|
87 |
if(tr.getUuid().equals(taxonRelUuid)) { |
|
88 |
if(newRelTypeUuid != null) { |
|
89 |
TaxonRelationshipType relType = CdmBase.deproxy(termService.load(newRelTypeUuid), TaxonRelationshipType.class); |
|
90 |
tr.setType(relType); |
|
91 |
} |
|
92 |
if(newToTaxonUuid != null) { |
|
93 |
Taxon toTaxon = CdmBase.deproxy(taxonService.load(newToTaxonUuid), Taxon.class); |
|
94 |
tr.setToTaxon(toTaxon); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
app.commitTransaction(tx); |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
public void deleteRelationship(UUID fromTaxonUuid, UUID taxonRelUuid) { |
|
103 |
TransactionStatus tx = app.startTransaction(); |
|
104 |
Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class); |
|
105 |
TaxonRelationship trToDelete = null; |
|
106 |
Set<TaxonRelationship> trList = fromTaxon.getRelationsFromThisTaxon(); |
|
107 |
for(TaxonRelationship tr : trList) { |
|
108 |
if(tr.getUuid().equals(taxonRelUuid)) { |
|
109 |
trToDelete = tr; |
|
110 |
} |
|
111 |
} |
|
112 |
if(trToDelete != null) { |
|
113 |
trList.remove(trToDelete); |
|
114 |
} |
|
115 |
app.commitTransaction(tx); |
|
116 |
} |
|
117 |
|
|
49 | 118 |
} |
Also available in: Unified diff
EditConceptRelationshipComposite : updated ui, added save + cancel + drag&drop functionality
ConceptRelationshipComposite : using the EditConceptRelationshipComposite
StatusComposite : set drag&drop mode
ConceptRelationshipPresenter, EditConceptRelationshipPresenter : moved create, update, edit methods to EditConceptRelationshipPresenter
ConceptRelationshipPresenterTest, EditConceptRelationshipPresenterTest(xml) : moved tests to EditConceptRelationshipPresenterTest