1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.refactoring.internal.job

File DeleteJob.java

 

Coverage histogram

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

Code metrics

6
21
7
1
103
68
13
0.62
3
7
1.86

Classes

Class Line # Actions
DeleteJob 41 21 0% 13 0
1.0100%
 

Contributing tests

This file is covered by 6 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 javax.inject.Named;
23   
24    import org.xwiki.component.annotation.Component;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.model.reference.EntityReference;
27    import org.xwiki.model.reference.SpaceReference;
28    import org.xwiki.refactoring.job.EntityJobStatus;
29    import org.xwiki.refactoring.job.EntityRequest;
30    import org.xwiki.refactoring.job.RefactoringJobs;
31    import org.xwiki.security.authorization.Right;
32   
33    /**
34    * A job that can delete entities.
35    *
36    * @version $Id: a81ec771016f7148a7f1d2e5d5f88f826a9769d6 $
37    * @since 7.2M1
38    */
39    @Component
40    @Named(RefactoringJobs.DELETE)
 
41    public class DeleteJob extends AbstractEntityJob<EntityRequest, EntityJobStatus<EntityRequest>>
42    {
 
43  130 toggle @Override
44    public String getType()
45    {
46  130 return RefactoringJobs.DELETE;
47    }
48   
 
49  26 toggle @Override
50    protected EntityJobStatus<EntityRequest> createNewStatus(EntityRequest request)
51    {
52  26 return new EntityJobStatus<EntityRequest>(request, this.observationManager, this.loggerManager, null);
53    }
54   
 
55  26 toggle @Override
56    protected void process(EntityReference entityReference)
57    {
58    // Dispatch the delete operation based on the entity type.
59   
60  26 switch (entityReference.getType()) {
61  16 case DOCUMENT:
62  16 process(new DocumentReference(entityReference));
63  15 break;
64  9 case SPACE:
65  9 process(new SpaceReference(entityReference));
66  4 break;
67  1 default:
68  1 this.logger.error("Unsupported entity type [{}].", entityReference.getType());
69    }
70    }
71   
 
72  16 toggle private void process(DocumentReference documentReference)
73    {
74  16 if (this.request.isDeep() && isSpaceHomeReference(documentReference)) {
75  1 process(documentReference.getLastSpaceReference());
76    } else {
77  15 maybeDelete(documentReference);
78    }
79    }
80   
 
81  10 toggle private void process(SpaceReference spaceReference)
82    {
83  10 visitDocuments(spaceReference, new Visitor<DocumentReference>()
84    {
 
85  12 toggle @Override
86    public void visit(DocumentReference documentReference)
87    {
88  12 maybeDelete(documentReference);
89    }
90    });
91    }
92   
 
93  27 toggle private void maybeDelete(DocumentReference documentReference)
94    {
95  27 if (!this.modelBridge.exists(documentReference)) {
96  3 this.logger.warn("Skipping [{}] because it doesn't exist.", documentReference);
97  24 } else if (!hasAccess(Right.DELETE, documentReference)) {
98  1 this.logger.error("You are not allowed to delete [{}].", documentReference);
99    } else {
100  23 this.modelBridge.delete(documentReference);
101    }
102    }
103    }