Revision 086a1ba9
Added by Andreas Müller about 3 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/DeleteNonReferencedReferencesUpdater.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.io.operation; |
10 | 10 |
|
11 | 11 |
import java.util.List; |
12 |
import java.util.Set; |
|
13 | 12 |
|
14 | 13 |
import org.springframework.stereotype.Component; |
15 | 14 |
|
... | ... | |
18 | 17 |
import eu.etaxonomy.cdm.io.common.DefaultImportState; |
19 | 18 |
import eu.etaxonomy.cdm.io.operation.config.DeleteNonReferencedReferencesConfigurator; |
20 | 19 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
21 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
22 | 20 |
import eu.etaxonomy.cdm.model.reference.Reference; |
23 | 21 |
|
24 | 22 |
/** |
... | ... | |
31 | 29 |
private static final long serialVersionUID = -3514276133181062270L; |
32 | 30 |
|
33 | 31 |
@Override |
34 |
protected void doInvoke( |
|
35 |
DefaultImportState<DeleteNonReferencedReferencesConfigurator> state) { |
|
32 |
protected void doInvoke(DefaultImportState<DeleteNonReferencedReferencesConfigurator> state) { |
|
36 | 33 |
|
37 | 34 |
if (state.getConfig().isDoAuthors()){ |
38 | 35 |
List<TeamOrPersonBase> authors =getAgentService().list(TeamOrPersonBase.class, null, null, null, null); |
39 |
DeleteResult result; |
|
36 |
|
|
40 | 37 |
int deleted = 0; |
41 | 38 |
System.out.println("There are " + authors.size() + " authors"); |
42 | 39 |
for (TeamOrPersonBase<?> author: authors){ |
43 |
Set<CdmBase> refObjects = getCommonService().getReferencingObjects(author);
|
|
44 |
if (refObjects.isEmpty()) {
|
|
45 |
result = getAgentService().delete(author);
|
|
40 |
long refObjects = getCommonService().getReferencingObjectsCount(author);
|
|
41 |
if (refObjects == 0) {
|
|
42 |
DeleteResult result = getAgentService().delete(author);
|
|
46 | 43 |
deleted++; |
47 | 44 |
if (!result.isOk()){ |
48 | 45 |
System.out.println("Author " + author.getTitleCache() + " with id " + author.getId() + " could not be deleted."); |
... | ... | |
54 | 51 |
} |
55 | 52 |
if (state.getConfig().isDoReferences()){ |
56 | 53 |
List<Reference> references =getReferenceService().list(Reference.class, null, null, null, null); |
57 |
DeleteResult result; |
|
54 |
|
|
58 | 55 |
int deleted = 0; |
59 | 56 |
System.out.println("There are " + references.size() + " references"); |
60 | 57 |
for (Reference ref: references){ |
61 | 58 |
long refObjects = getCommonService().getReferencingObjectsCount(ref); |
62 |
if (refObjects > 0) {
|
|
63 |
result = getReferenceService().delete(ref);
|
|
59 |
if (refObjects == 0) {
|
|
60 |
DeleteResult result = getReferenceService().delete(ref);
|
|
64 | 61 |
deleted++; |
65 | 62 |
if (!result.isOk()){ |
66 | 63 |
System.out.println("Reference " + ref.getTitle() + " with id " + ref.getId() + " could not be deleted."); |
Also available in: Unified diff
DeleteNonReferencedReferencesUpdater uses ReferencingObjectsCount instead of ReferencingObjects