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

File RenameJob.java

 

Coverage histogram

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

Code metrics

8
15
5
1
95
56
10
0.67
3
5
2

Classes

Class Line # Actions
RenameJob 40 15 0% 10 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 java.util.Collection;
23   
24    import javax.inject.Named;
25   
26    import org.xwiki.component.annotation.Component;
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.RefactoringJobs;
31   
32    /**
33    * A job that can rename entities.
34    *
35    * @version $Id: 345050940b82e60966d446d36db74a56c4dd1f63 $
36    * @since 7.2M1
37    */
38    @Component
39    @Named(RefactoringJobs.RENAME)
 
40    public class RenameJob extends MoveJob
41    {
 
42  40 toggle @Override
43    public String getType()
44    {
45  40 return RefactoringJobs.RENAME;
46    }
47   
 
48  8 toggle @Override
49    protected void process(Collection<EntityReference> entityReferences)
50    {
51  8 if (entityReferences.size() == 1) {
52  7 process(entityReferences.iterator().next());
53    }
54    }
55   
 
56  7 toggle @Override
57    protected void process(EntityReference source)
58    {
59    // Perform generic checks that don't depend on the source/destination type.
60   
61  7 EntityReference destination = this.request.getDestination();
62  7 if (source.getType() != destination.getType()) {
63  1 this.logger.error("You cannot change the entity type (from [{}] to [{}]).", source.getType(),
64    destination.getType());
65  1 return;
66    }
67   
68  6 super.process(source);
69    }
70   
 
71  5 toggle @Override
72    protected void process(DocumentReference source, EntityReference destination)
73    {
74    // We know the destination is a document (see above).
75  5 DocumentReference destinationDocumentReference = new DocumentReference(destination);
76  5 if (this.request.isDeep() && isSpaceHomeReference(source)) {
77  3 if (isSpaceHomeReference(destinationDocumentReference)) {
78    // Rename an entire space.
79  2 process(source.getLastSpaceReference(), destinationDocumentReference.getLastSpaceReference());
80    } else {
81  1 this.logger.error("You cannot transform a non-terminal document [{}] into a terminal document [{}]"
82    + " and preserve its child documents at the same time.", source, destinationDocumentReference);
83    }
84    } else {
85  2 maybeMove(source, destinationDocumentReference);
86    }
87    }
88   
 
89  1 toggle @Override
90    protected void process(SpaceReference source, EntityReference destination)
91    {
92    // We know the destination is a space (see above).
93  1 process(source, new SpaceReference(destination));
94    }
95    }