public void updateItems(Map<String, Map<String, Object>> map) {
/*
* ViewNavigator nav = view.createViewNav(); nav.skip(1000000);
*
* System.out.println("CacheSize: " + nav.getCacheSize());
*/
if (view != null) {
Document doc = null;
for (Entry<String, Map<String, Object>> flds : map.entrySet()) {
String key = flds.getKey();
doc = view.getFirstDocumentByKey(key, true);
if (doc != null)
//replace all values to new
if (!doc.entrySet().containsAll(flds.getValue().entrySet())) doc.putAll(flds.getValue());
else {
//create doc with values (from flds map), set permissions and form
doc = db.createDocument(flds.getValue());
doc.replaceItemValue("form", form);
access.setDefAccess(doc, ses.getEffectiveUserName());
}
if (doc.save()) {
list.add(key);
}
}
// view.setAutoUpdate(true);
}
}
public void updateItem(String key, Map<String, Object> value) {
if (view != null && key != null && !key.isEmpty()
&& !list.contains(key)) {
Document doc = null;
ViewEntry entry = view.getFirstEntryByKey(key, true);
// doc = view.getFirstDocumentByKey(key, true);
boolean bSave = false;
if (entry != null) {
bSave = !entry.getColumnValuesMap().entrySet().containsAll(
value.entrySet());
// doc = entry.getDocument();
// bSave = !doc.asDocMap().entrySet()
// .containsAll(value.entrySet());
if (bSave) {
doc = entry.getDocument();
logBody.appendText(entry.getColumnValuesMap().entrySet().toString());
// logBody.appendText(doc.asDocMap().entrySet().toString());
logBody.addNewLine();
if (isAppend) {
logBody.appendText("!append items");
logBody.addNewLine();
Map<String, Object> tmp = doc.asDocMap();
for (String k : value.keySet()) {
List<String> arr=new ArrayList<String>();
if (tmp.get(k) instanceof Collection<?>) {
arr.addAll((Collection<? extends String>) tmp.get(k));
}else if(tmp.get(k)!=null){
arr.add(tmp.get(k).toString());
}
if (value.get(k) instanceof Collection<?>) {
//for unique
List<String>lst=((List<String>) value.get(k));
arr.removeAll(lst);
arr.addAll(lst);
}else{
if(!arr.contains(value.get(k).toString()))arr.add(value.get(k).toString());
}
value.put(k,arr);
}
}
logBody.appendText("update doc with:");
doc.putAll(value);
}
} else {
bSave = true;
logBody.appendText("new doc with:");
doc = db.createDocument(value);
doc.replaceItemValue("form", form);
access.setDefAccess(doc, ses.getEffectiveUserName());
}
if (bSave && doc.save()) {
logBody.appendText(value.toString());
logBody.appendDocLink(doc);
logBody.addNewLine();
list.add(key);
}
}
}