Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Avila2015-09-23 18:58:38 -0400
committerAngel Avila2015-10-09 19:34:53 -0400
commit563e417f65cccbb9f3aa5bacf333437ee3fa5aad (patch)
tree7154135c3f62fb2df84e1994d0d2b9c4e5155a50 /plugins/org.eclipse.osee.account.rest.model
parent00878178c763d9dae76166f92462eff6672c5e30 (diff)
downloadorg.eclipse.osee-563e417f65cccbb9f3aa5bacf333437ee3fa5aad.tar.gz
org.eclipse.osee-563e417f65cccbb9f3aa5bacf333437ee3fa5aad.tar.xz
org.eclipse.osee-563e417f65cccbb9f3aa5bacf333437ee3fa5aad.zip
feature[ats_ATS209686]: Add OAuth protected resource at server root
Diffstat (limited to 'plugins/org.eclipse.osee.account.rest.model')
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountUtil.java60
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountWebPreferences.java79
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/Link.java57
4 files changed, 199 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.account.rest.model/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest.model/META-INF/MANIFEST.MF
index fdbf4977b9..6742bcfc9a 100644
--- a/plugins/org.eclipse.osee.account.rest.model/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.account.rest.model/META-INF/MANIFEST.MF
@@ -6,4 +6,6 @@ Bundle-Version: 0.23.0.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.osee.account.rest.model
-Import-Package: org.eclipse.osee.framework.jdk.core.type
+Import-Package: org.eclipse.osee.framework.jdk.core.type,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.json
diff --git a/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountUtil.java b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountUtil.java
new file mode 100644
index 0000000000..1520f4a40e
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountUtil.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.model;
+
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * @author Angel Avila
+ */
+public class AccountUtil {
+
+ public static String updateSinglePreference(AccountWebPreferences allPreferences, String key, String id, String newValue) {
+ try {
+ JSONObject preferencesJObject = new JSONObject(allPreferences);
+ JSONObject singlePreferenceObject = preferencesJObject.getJSONObject(key);
+
+ JSONObject newValueAsObject;
+ if (!Strings.isValid(id)) {
+ newValueAsObject = createNewPreference(newValue);
+ singlePreferenceObject.put(newValueAsObject.getString("id"), newValueAsObject);
+ } else {
+ newValueAsObject = new JSONObject(newValue);
+ if (newValueAsObject.toString().equals("{}")) {
+ singlePreferenceObject.remove(id);
+ } else {
+ singlePreferenceObject.put(id, newValueAsObject);
+ }
+ }
+
+ preferencesJObject.put(key, singlePreferenceObject);
+
+ return preferencesJObject.toString();
+ } catch (JSONException ex) {
+ throw new OseeCoreException(ex);
+ }
+ }
+
+ private static JSONObject createNewPreference(String newValue) {
+ String newId = GUID.create();
+ try {
+ JSONObject newObject = new JSONObject(newValue);
+ newObject.put("id", newId);
+ return newObject;
+ } catch (JSONException ex) {
+ throw new OseeCoreException(ex);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountWebPreferences.java b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountWebPreferences.java
new file mode 100644
index 0000000000..b09094e7be
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/AccountWebPreferences.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.model;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * @author Angel Avila
+ */
+public class AccountWebPreferences {
+
+ Map<String, Link> linksMap;
+
+ public AccountWebPreferences() {
+
+ }
+
+ public AccountWebPreferences(Map<String, String> teamToPreferences) {
+ for (String team : teamToPreferences.keySet()) {
+ initPreferences(teamToPreferences.get(team), team);
+ }
+
+ }
+
+ private void initPreferences(String string, String team) {
+ try {
+ JSONObject jObject = new JSONObject(string);
+
+ if (linksMap == null) {
+ linksMap = new HashMap<String, Link>();
+ }
+ JSONObject linkJsonObject = jObject.getJSONObject("links");
+ @SuppressWarnings("unchecked")
+ Iterator<String> keys = linkJsonObject.keys();
+ while (keys.hasNext()) {
+ String next = keys.next();
+ JSONObject linkJObject = linkJsonObject.getJSONObject(next);
+ Link link = new Link();
+ if (linkJObject.has("name")) {
+ link.setName(linkJObject.getString("name"));
+ }
+ if (linkJObject.has("url")) {
+ link.setUrl(linkJObject.getString("url"));
+ }
+ link.setTeam(team);
+ link.setId(linkJObject.getString("id"));
+ linksMap.put(next, link);
+ }
+
+ } catch (JSONException ex) {
+ //
+ }
+ }
+
+ public AccountWebPreferences(String jsonString, String team) {
+ initPreferences(jsonString, team);
+ }
+
+ public Map<String, Link> getLinks() {
+ return linksMap;
+ }
+
+ public void setLinks(Map<String, Link> links) {
+ this.linksMap = links;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/Link.java b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/Link.java
new file mode 100644
index 0000000000..7f500b6cd2
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/Link.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.account.rest.model;
+
+/**
+ * @author Angel Avila
+ */
+public class Link {
+ String name;
+ String url;
+ String id;
+ String team;
+
+ public Link() {
+
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public void setTeam(String team) {
+ this.team = team;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public String getTeam() {
+ return team;
+ }
+}

Back to the top