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

File AbstractEntityJobWithChecks.java

 

Coverage histogram

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

Code metrics

10
39
6
1
143
88
14
0.36
6.5
6
2.33

Classes

Class Line # Actions
AbstractEntityJobWithChecks 43 39 0% 14 3
0.9454545494.5%
 

Contributing tests

This file is covered by 34 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    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.xwiki.bridge.event.DocumentsDeletingEvent;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.model.reference.SpaceReference;
30    import org.xwiki.refactoring.job.EntityJobStatus;
31    import org.xwiki.refactoring.job.EntityRequest;
32    import org.xwiki.refactoring.job.question.EntitySelection;
33   
34    /**
35    * Abstract job that create the list of pages to delete in order to do some checks and ask a confirmation to the user.
36    *
37    * @param <R> the request type
38    * @param <S> the job status type
39    *
40    * @version $Id: e43a01c54d4ece662f33948b5771f2eaf20925c5 $
41    * @since 9.1RC1
42    */
 
43    public abstract class AbstractEntityJobWithChecks<R extends EntityRequest, S extends EntityJobStatus<? super R>>
44    extends AbstractEntityJob<R, S>
45    {
46    /**
47    * Map that will contain all entities that are concerned by the refactoring.
48    */
49    protected Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
50   
51    /**
52    * @return true means that this job will delete sources.
53    * @since 10.11RC1
54    */
 
55  86 toggle protected boolean isDeleteSources()
56    {
57  86 return true;
58    }
59   
 
60  146 toggle @Override
61    protected void runInternal() throws Exception
62    {
63  146 progressManager.pushLevelProgress(2, this);
64  146 try {
65  146 Collection<EntityReference> entityReferences = this.request.getEntityReferences();
66  146 if (entityReferences != null) {
67    // Get the list of concerned entities
68  146 progressManager.startStep(this);
69  146 getEntities(entityReferences);
70   
71  146 if (isDeleteSources()) {
72    // Send the event
73  118 DocumentsDeletingEvent event = new DocumentsDeletingEvent();
74  118 observationManager.notify(event, this, concernedEntities);
75   
76    // Stop the job if some listener has canceled the action
77  118 if (event.isCanceled()) {
78  1 getStatus().cancel();
79   
80  1 return;
81    }
82    }
83   
84    // Process
85  145 progressManager.startStep(this);
86  145 setContextUser();
87  145 process(entityReferences);
88    }
89    } finally {
90  146 progressManager.popLevelProgress(this);
91    }
92    }
93   
94   
 
95  146 toggle protected void getEntities(Collection<EntityReference> entityReferences)
96    {
97  146 this.progressManager.pushLevelProgress(entityReferences.size(), this);
98   
99  146 try {
100  146 for (EntityReference entityReference : entityReferences) {
101  147 if (this.status.isCanceled()) {
102  0 break;
103    } else {
104  147 this.progressManager.startStep(this);
105  147 getEntities(entityReference);
106  147 this.progressManager.endStep(this);
107    }
108    }
109    } finally {
110  146 this.progressManager.popLevelProgress(this);
111    }
112    }
113   
 
114  147 toggle protected void getEntities(EntityReference entityReference)
115    {
116    // Dispatch the check operation based on the entity type.
117  147 switch (entityReference.getType()) {
118  97 case DOCUMENT:
119  97 getEntities(new DocumentReference(entityReference));
120  97 break;
121  48 case SPACE:
122  48 getEntities(new SpaceReference(entityReference));
123  48 break;
124  2 default:
125  2 this.logger.error("Unsupported entity type [{}].", entityReference.getType());
126    }
127    }
128   
 
129  97 toggle private void getEntities(DocumentReference documentReference)
130    {
131  97 if (this.request.isDeep() && isSpaceHomeReference(documentReference)) {
132  5 getEntities(documentReference.getLastSpaceReference());
133    } else {
134  92 this.concernedEntities.put(documentReference, new EntitySelection(documentReference));
135    }
136    }
137   
 
138  53 toggle private void getEntities(SpaceReference spaceReference)
139    {
140  53 visitDocuments(spaceReference, documentReference ->
141    concernedEntities.put(documentReference, new EntitySelection(documentReference)));
142    }
143    }