From 334c8f4595658c738f1b422a002d9b74bab5ef4a Mon Sep 17 00:00:00 2001
From: Christoph Thelen <christoph.thelen@mni.thm.de>
Date: Mon, 16 Mar 2015 10:50:38 +0100
Subject: [PATCH] Remove obsolete View extensions

With the migration to our CouchDB4J fork, we can
remove all extensions that are no longer needed.
---
 .../java/de/thm/arsnova/dao/NovaView.java     | 162 +-----------------
 .../java/de/thm/arsnova/dao/NovaViewTest.java |   2 +-
 2 files changed, 5 insertions(+), 159 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/dao/NovaView.java b/src/main/java/de/thm/arsnova/dao/NovaView.java
index 1248b1719..8f320a0fc 100644
--- a/src/main/java/de/thm/arsnova/dao/NovaView.java
+++ b/src/main/java/de/thm/arsnova/dao/NovaView.java
@@ -17,168 +17,14 @@
  */
 package de.thm.arsnova.dao;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-
 import com.fourspaces.couchdb.View;
 
+/**
+ * Stub class that needs to be removed once migration to our CouchDB4J fork is complete
+ */
 public class NovaView extends View {
 
-	public enum StaleMode {
-		NONE, OK, UPDATE_AFTER
-	}
-
-	protected String keys;
-
-	protected StaleMode stale = StaleMode.NONE;
-
-	protected boolean includeDocs = false;
-
-	public boolean isIncludeDocs() {
-		return includeDocs;
-	}
-
-	public void setIncludeDocs(boolean includeDocs) {
-		this.includeDocs = includeDocs;
-	}
-
-	public NovaView(final String fullname) {
+	public NovaView(String fullname) {
 		super(fullname);
 	}
-
-	@Override
-	public void setStartKey(final String key) {
-		startKey = quote(key);
-	}
-
-	public void setStartKeyArray(final String key) {
-		if (isNumber(key)) {
-			startKey = encode("[" + key + "]");
-		} else {
-			startKey = encode("[\"" + key + "\"]");
-		}
-	}
-
-	public void setStartKeyArray(final String... keys) {
-		this.setStartKey(keys);
-	}
-
-	@Override
-	public void setEndKey(final String key) {
-		endKey = quote(key);
-	}
-
-	public void setEndKeyArray(final String key) {
-		if (isNumber(key)) {
-			endKey = encode("[" + key + "]");
-		} else {
-			endKey = encode("[\"" + key + "\"]");
-		}
-	}
-
-	public void setEndKeyArray(final String... keys) {
-		this.setEndKey(keys);
-	}
-
-	public void setStartKey(final String... keys) {
-		startKey = toJsonArray(keys);
-	}
-
-	public void setEndKey(final String... keys) {
-		endKey = toJsonArray(keys);
-	}
-
-	@Override
-	public void setKey(final String key) {
-		this.key = quote(key);
-	}
-
-	public void setKey(final String... keys) {
-		key = toJsonArray(keys);
-	}
-
-	public void setKeys(List<String> keys) {
-		this.keys = toJsonArray(keys.toArray(new String[keys.size()]));
-	}
-
-	public void setStale(StaleMode stale) {
-		this.stale = stale;
-	}
-
-	@Override
-	public String getQueryString() {
-		final String tempQuery = super.getQueryString();
-		final StringBuilder query = new StringBuilder();
-		if (tempQuery != null) {
-			query.append(tempQuery);
-		}
-		if (keys != null) {
-			if (query.length() > 0) {
-				query.append("&");
-			}
-			query.append("keys=" + keys);
-		}
-		if (stale != null && stale != StaleMode.NONE) {
-			if (query.length() > 0) {
-				query.append("&");
-			}
-			if (stale == StaleMode.OK) {
-				query.append("stale=ok");
-			} else if (stale == StaleMode.UPDATE_AFTER) {
-				query.append("stale=update_after");
-			}
-		}
-		if (includeDocs != false) {
-			if (query.length() > 0) {
-				query.append("&");
-			}
-			query.append("include_docs=true");
-		}
-
-		if (query.length() == 0) {
-			return null;
-		}
-		return query.toString();
-	}
-
-	private String toJsonArray(final String[] strs) {
-		final List<String> strings = new ArrayList<String>();
-		for (final String string : strs) {
-			if (isNumber(string) || isPlaceholder(string) || isArray(string)) {
-				strings.add(string);
-			} else {
-				strings.add("\"" + string + "\"");
-			}
-		}
-		return encode("[" + StringUtils.join(strings, ",") + "]");
-	}
-
-	private String quote(final String string) {
-		return encode("\"" + string + "\"");
-	}
-
-	private boolean isNumber(final String string) {
-		return string.matches("^[0-9]+$");
-	}
-
-	private boolean isPlaceholder(final String string) {
-		return string.equals("{}");
-	}
-
-	private boolean isArray(final String string) {
-		return string.startsWith("[") && string.endsWith("]");
-	}
-
-	private String encode(final String string) {
-		try {
-			return URLEncoder.encode(string, "UTF-8");
-		} catch (final UnsupportedEncodingException e) {
-			// Since we're using 'UTF-8', this should Exception should never occur.
-			return "";
-		}
-	}
 }
diff --git a/src/test/java/de/thm/arsnova/dao/NovaViewTest.java b/src/test/java/de/thm/arsnova/dao/NovaViewTest.java
index 2459d502d..2e6551468 100644
--- a/src/test/java/de/thm/arsnova/dao/NovaViewTest.java
+++ b/src/test/java/de/thm/arsnova/dao/NovaViewTest.java
@@ -26,7 +26,7 @@ import java.util.Arrays;
 
 import org.junit.Test;
 
-import de.thm.arsnova.dao.NovaView.StaleMode;
+import com.fourspaces.couchdb.View.StaleMode;
 
 public class NovaViewTest {
 
-- 
GitLab