1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.refactoring.internal.job

File DeleteJob.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
24
7
1
116
77
15
0.62
3.43
7
2.14

Classes

Class Line # Actions
DeleteJob 46 24 0% 15 2
0.9487179594.9%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.refactoring.internal.job;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.SpaceReference;
31    import org.xwiki.refactoring.batch.BatchOperationExecutor;
32    import org.xwiki.refactoring.job.EntityJobStatus;
33    import org.xwiki.refactoring.job.EntityRequest;
34    import org.xwiki.refactoring.job.RefactoringJobs;
35    import org.xwiki.refactoring.job.question.EntitySelection;
36    import org.xwiki.security.authorization.Right;
37   
38    /**
39    * A job that can delete entities.
40    *
41    * @version $Id: 3dfa78048396682184b4821983aa33c269b0741b $
42    * @since 7.2M1
43    */
44    @Component
45    @Named(RefactoringJobs.DELETE)
 
46    public class DeleteJob extends AbstractEntityJobWithChecks<EntityRequest, EntityJobStatus<EntityRequest>>
47    {
48    @Inject
49    private BatchOperationExecutor batchOperationExecutor;
50   
 
51  516 toggle @Override
52    public String getType()
53    {
54  516 return RefactoringJobs.DELETE;
55    }
56   
 
57  86 toggle @Override
58    protected void process(Collection<EntityReference> entityReferences)
59    {
60    // Wrap the work as a batch operation.
61  86 batchOperationExecutor.execute(() -> super.process(entityReferences));
62    }
63   
 
64  86 toggle @Override
65    protected void process(EntityReference entityReference)
66    {
67    // Dispatch the delete operation based on the entity type.
68   
69  86 switch (entityReference.getType()) {
70  42 case DOCUMENT:
71  42 process(new DocumentReference(entityReference));
72  42 break;
73  43 case SPACE:
74  43 process(new SpaceReference(entityReference));
75  43 break;
76  1 default:
77  1 this.logger.error("Unsupported entity type [{}].", entityReference.getType());
78    }
79    }
80   
 
81  42 toggle private void process(DocumentReference documentReference)
82    {
83  42 if (this.request.isDeep() && isSpaceHomeReference(documentReference)) {
84  1 process(documentReference.getLastSpaceReference());
85    } else {
86  41 maybeDelete(documentReference);
87    }
88    }
89   
 
90  44 toggle private void process(SpaceReference spaceReference)
91    {
92  44 visitDocuments(spaceReference, new Visitor<DocumentReference>()
93    {
 
94  78 toggle @Override
95    public void visit(DocumentReference documentReference)
96    {
97  78 maybeDelete(documentReference);
98    }
99    });
100    }
101   
 
102  119 toggle private void maybeDelete(DocumentReference documentReference)
103    {
104  119 EntitySelection entitySelection = concernedEntities.get(documentReference);
105  119 if (entitySelection != null && !entitySelection.isSelected()) {
106    // TODO: handle entitySelection == null which means something is wrong
107  0 this.logger.info("Skipping [{}] because it has been unselected.", documentReference);
108  119 } else if (!this.modelBridge.exists(documentReference)) {
109  3 this.logger.warn("Skipping [{}] because it doesn't exist.", documentReference);
110  116 } else if (!hasAccess(Right.DELETE, documentReference)) {
111  2 this.logger.error("You are not allowed to delete [{}].", documentReference);
112    } else {
113  114 this.modelBridge.delete(documentReference);
114    }
115    }
116    }