| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import java.util.Collection; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Map; |
| 26 |
|
|
| 27 |
|
import com.xpn.xwiki.XWiki; |
| 28 |
|
import com.xpn.xwiki.XWikiContext; |
| 29 |
|
import com.xpn.xwiki.XWikiException; |
| 30 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 31 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 32 |
|
import com.xpn.xwiki.objects.classes.PropertyClass; |
| 33 |
|
import com.xpn.xwiki.util.Util; |
| 34 |
|
|
| |
|
| 61.5% |
Uncovered Elements: 25 (65) |
Complexity: 11 |
Complexity Density: 0.23 |
|
| 35 |
|
public class PropUpdateAction extends XWikiAction |
| 36 |
|
{ |
| |
|
| 63.8% |
Uncovered Elements: 17 (47) |
Complexity: 6 |
Complexity Density: 0.16 |
|
| 37 |
2 |
public boolean propUpdate(XWikiContext context) throws XWikiException... |
| 38 |
|
{ |
| 39 |
2 |
XWiki xwiki = context.getWiki(); |
| 40 |
2 |
XWikiDocument doc = context.getDoc(); |
| 41 |
2 |
XWikiForm form = context.getForm(); |
| 42 |
|
|
| 43 |
|
|
| 44 |
2 |
BaseClass bclass = doc.getXClass(); |
| 45 |
2 |
BaseClass bclass2 = bclass.clone(); |
| 46 |
2 |
bclass2.setFields(new HashMap()); |
| 47 |
|
|
| 48 |
|
|
| 49 |
2 |
Map<String, String> fieldsToRename = new HashMap<String, String>(); |
| 50 |
|
|
| 51 |
2 |
for (PropertyClass originalProperty : (Collection<PropertyClass>) bclass.getFieldList()) { |
| 52 |
3 |
PropertyClass newProperty = originalProperty.clone(); |
| 53 |
3 |
String name = newProperty.getName(); |
| 54 |
3 |
Map<String, ?> map = ((EditForm) form).getObject(name); |
| 55 |
3 |
newProperty.getXClass(context).fromMap(map, newProperty); |
| 56 |
3 |
String newName = newProperty.getName(); |
| 57 |
|
|
| 58 |
3 |
if (!Util.isValidXMLElementName(newName)) { |
| 59 |
0 |
context.put("message", "propertynamenotcorrect"); |
| 60 |
0 |
return true; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
3 |
if (newName.indexOf(" ") != -1) { |
| 64 |
0 |
newName = newName.replaceAll(" ", ""); |
| 65 |
0 |
newProperty.setName(newName); |
| 66 |
|
} |
| 67 |
3 |
bclass2.addField(newName, newProperty); |
| 68 |
3 |
if (!newName.equals(name)) { |
| 69 |
0 |
fieldsToRename.put(name, newName); |
| 70 |
0 |
bclass2.addPropertyForRemoval(originalProperty); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
2 |
doc.setXClass(bclass2); |
| 75 |
2 |
doc.renameProperties(bclass.getName(), fieldsToRename); |
| 76 |
2 |
doc.setMetaDataDirty(true); |
| 77 |
2 |
if (doc.isNew()) { |
| 78 |
0 |
doc.setCreator(context.getUser()); |
| 79 |
|
} |
| 80 |
2 |
doc.setAuthor(context.getUser()); |
| 81 |
2 |
xwiki.saveDocument(doc, localizePlainOrKey("core.comment.updateClassProperty"), true, |
| 82 |
|
context); |
| 83 |
|
|
| 84 |
|
|
| 85 |
2 |
if (fieldsToRename.size() > 0) { |
| 86 |
0 |
List<String> list = |
| 87 |
|
xwiki.getStore().searchDocumentsNames( |
| 88 |
|
", BaseObject as obj where obj.name=doc.fullName and obj.className='" |
| 89 |
|
+ Utils.SQLFilter(bclass.getName()) + "' and doc.fullName <> '" |
| 90 |
|
+ Utils.SQLFilter(bclass.getName()) + "'", context); |
| 91 |
0 |
for (String docName : list) { |
| 92 |
0 |
XWikiDocument doc2 = xwiki.getDocument(docName, context); |
| 93 |
0 |
doc2.renameProperties(bclass.getName(), fieldsToRename); |
| 94 |
0 |
xwiki.saveDocument(doc2, localizePlainOrKey("core.comment.updateClassPropertyName"), true, context); |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
|
| 98 |
2 |
return false; |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 57.1% |
Uncovered Elements: 6 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 101 |
2 |
@Override... |
| 102 |
|
public boolean action(XWikiContext context) throws XWikiException |
| 103 |
|
{ |
| 104 |
|
|
| 105 |
2 |
if (!csrfTokenCheck(context)) { |
| 106 |
0 |
return false; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
2 |
try { |
| 110 |
2 |
if (propUpdate(context)) { |
| 111 |
0 |
return true; |
| 112 |
|
} |
| 113 |
|
} catch (XWikiException ex) { |
| 114 |
0 |
context.put("exception", ex); |
| 115 |
0 |
return true; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
2 |
String redirect = Utils.getRedirect("view", context); |
| 119 |
2 |
sendRedirect(context.getResponse(), redirect); |
| 120 |
2 |
return false; |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
0 |
@Override... |
| 124 |
|
public String render(XWikiContext context) throws XWikiException |
| 125 |
|
{ |
| 126 |
0 |
return "exception"; |
| 127 |
|
} |
| 128 |
|
} |