Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionData.java97
-rw-r--r--plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionGroupData.java88
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountDataUtilTest.java119
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java5
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java28
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java25
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java1
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/SubscriptionsResourceTest.java242
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/UnsubscribeResourceTest.java115
-rw-r--r--plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml1
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java14
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountDataUtil.java108
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java73
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java22
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/PageWriter.java71
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/SubscriptionsResource.java204
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/UnsubscribeResource.java148
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe.html30
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_no_subscription.html21
-rw-r--r--plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_success.html22
22 files changed, 1342 insertions, 98 deletions
diff --git a/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionData.java b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionData.java
new file mode 100644
index 0000000000..ed9e27ab2b
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionData.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 javax.xml.bind.annotation.XmlRootElement;
+import org.eclipse.osee.framework.jdk.core.type.Identifiable;
+import org.eclipse.osee.framework.jdk.core.type.Identity;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@XmlRootElement
+public class SubscriptionData implements Identifiable<String> {
+
+ private String uuid;
+ private String name;
+ private boolean isActive;
+ private String accountName;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getGuid() {
+ return uuid;
+ }
+
+ public void setGuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public boolean isActive() {
+ return isActive;
+ }
+
+ public void setActive(boolean isActive) {
+ this.isActive = isActive;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ @Override
+ public int hashCode() {
+ return getGuid().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean equal = false;
+ if (obj instanceof Identity) {
+ @SuppressWarnings("unchecked")
+ Identity<String> identity = (Identity<String>) obj;
+ if (getGuid() == identity.getGuid()) {
+ equal = true;
+ } else if (getGuid() != null) {
+ equal = getGuid().equals(identity.getGuid());
+ }
+ }
+ return equal;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(getGuid());
+ }
+
+ @Override
+ public boolean matches(Identity<?>... identities) {
+ for (Identity<?> identity : identities) {
+ if (equals(identity)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionGroupData.java b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionGroupData.java
new file mode 100644
index 0000000000..d1e160b3ea
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.model/src/org/eclipse/osee/account/rest/model/SubscriptionGroupData.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 javax.xml.bind.annotation.XmlRootElement;
+import org.eclipse.osee.framework.jdk.core.type.Identifiable;
+import org.eclipse.osee.framework.jdk.core.type.Identity;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@XmlRootElement
+public class SubscriptionGroupData implements Identifiable<String> {
+
+ private String uuid;
+ private String name;
+ private long id;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getGuid() {
+ return uuid;
+ }
+
+ public void setGuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Override
+ public int hashCode() {
+ return getGuid().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean equal = false;
+ if (obj instanceof Identity) {
+ @SuppressWarnings("unchecked")
+ Identity<String> identity = (Identity<String>) obj;
+ if (getGuid() == identity.getGuid()) {
+ equal = true;
+ } else if (getGuid() != null) {
+ equal = getGuid().equals(identity.getGuid());
+ }
+ }
+ return equal;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(getGuid());
+ }
+
+ @Override
+ public boolean matches(Identity<?>... identities) {
+ for (Identity<?> identity : identities) {
+ if (equals(identity)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF
index ac9e913b1c..721eb4055b 100644
--- a/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF
@@ -7,6 +7,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: Eclipse Open System Engineering Environment
Fragment-Host: org.eclipse.osee.account.rest;bundle-version="0.17.0"
Import-Package: com.sun.ws.rs.ext,
+ org.apache.commons.codec.binary,
org.apache.commons.lang.math,
org.hamcrest.core,
org.junit,
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountDataUtilTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountDataUtilTest.java
new file mode 100644
index 0000000000..de3c5c3350
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountDataUtilTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.Date;
+import org.apache.commons.lang.math.RandomUtils;
+import org.eclipse.osee.account.admin.AccountSession;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
+import org.eclipse.osee.account.rest.model.SubscriptionData;
+import org.eclipse.osee.account.rest.model.SubscriptionGroupData;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test Case for {@link AccountDataUtil}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountDataUtilTest {
+
+ @Test
+ public void testAsAccountAccessData() {
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+
+ AccountSession access = mockAccess(789L, "t3", d1, d2, "f3", "d3");
+
+ AccountSessionDetailsData actual = AccountDataUtil.asAccountAccessData(access);
+
+ assertAccess(actual, 789L, d1, d2, "f3", "d3");
+ }
+
+ @Test
+ public void testAsSessionData() {
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+ AccountSession access = mockAccess(123L, "t1", d1, d2, "f1", "d1");
+
+ AccountSessionData actual = AccountDataUtil.asSessionData(access);
+
+ assertEquals(123L, actual.getAccountId());
+ assertEquals("t1", actual.getToken());
+ }
+
+ @Test
+ public void testAsSubscriptionData() {
+ Subscription subscription = Mockito.mock(Subscription.class);
+ when(subscription.getGuid()).thenReturn("ABCDE");
+ when(subscription.getName()).thenReturn("group-1");
+ when(subscription.getGroupId()).thenReturn(98765L);
+ when(subscription.getAccountId()).thenReturn(123145L);
+ when(subscription.getAccountName()).thenReturn("account-1");
+ when(subscription.isActive()).thenReturn(true);
+
+ SubscriptionData actual = AccountDataUtil.asAccountSubscriptionData(subscription);
+
+ assertEquals("ABCDE", actual.getGuid());
+ assertEquals("group-1", actual.getName());
+ assertEquals("account-1", actual.getAccountName());
+ assertEquals(true, actual.isActive());
+
+ assertEquals(true, actual.matches(subscription));
+ assertEquals(true, actual.equals(subscription));
+ }
+
+ @Test
+ public void testAsSubscriptionGroupData() {
+ SubscriptionGroup group = Mockito.mock(SubscriptionGroup.class);
+ when(group.getGuid()).thenReturn("ABCDE");
+ when(group.getName()).thenReturn("group-1");
+ when(group.getId()).thenReturn(98765L);
+
+ SubscriptionGroupData actual = AccountDataUtil.asSubscriptionGroupData(group);
+
+ assertEquals("ABCDE", actual.getGuid());
+ assertEquals("group-1", actual.getName());
+ assertEquals(98765L, actual.getId());
+
+ assertEquals(true, actual.matches(group));
+ assertEquals(true, actual.equals(group));
+ }
+
+ private static Date newRandomDate() {
+ return new Date(Math.abs(System.currentTimeMillis() - RandomUtils.nextLong()));
+ }
+
+ private static AccountSession mockAccess(long id, String token, Date created, Date accessed, String accessFrom, String accessDetails) {
+ AccountSession access = Mockito.mock(AccountSession.class);
+ when(access.getAccountId()).thenReturn(id);
+ when(access.getSessionToken()).thenReturn(token);
+ when(access.getCreatedOn()).thenReturn(created);
+ when(access.getLastAccessedOn()).thenReturn(accessed);
+ when(access.getAccessedFrom()).thenReturn(accessFrom);
+ when(access.getAccessDetails()).thenReturn(accessDetails);
+ return access;
+ }
+
+ private static void assertAccess(AccountSessionDetailsData actual, long id, Date created, Date accessed, String accessFrom, String accessDetails) {
+ assertEquals(accessDetails, actual.getAccessDetails());
+ assertEquals(accessFrom, actual.getAccessedFrom());
+ assertEquals(id, actual.getAccountId());
+ assertEquals(created, actual.getCreatedOn());
+ assertEquals(accessed, actual.getLastAccessedOn());
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java
index 1a9dd21f22..64dfd5ea40 100644
--- a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java
@@ -19,13 +19,16 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AccountActiveResourceTest.class,
+ AccountDataUtilTest.class,
AccountLoginResourceTest.class,
AccountLogoutResourceTest.class,
AccountOpsTest.class,
AccountPreferencesResourceTest.class,
AccountResourceTest.class,
AccountSessionsResourceTest.class,
- AccountsResourceTest.class})
+ AccountsResourceTest.class,
+ SubscriptionsResourceTest.class,
+ UnsubscribeResourceTest.class})
public class AccountInternalTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java
index 7899de35c4..149ae9299b 100644
--- a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java
@@ -26,12 +26,11 @@ import javax.ws.rs.core.HttpHeaders;
import org.apache.commons.lang.math.RandomUtils;
import org.eclipse.osee.account.admin.AccessDetails;
import org.eclipse.osee.account.admin.Account;
-import org.eclipse.osee.account.admin.AccountSession;
import org.eclipse.osee.account.admin.AccountAdmin;
import org.eclipse.osee.account.admin.AccountLoginRequest;
import org.eclipse.osee.account.admin.AccountPreferences;
+import org.eclipse.osee.account.admin.AccountSession;
import org.eclipse.osee.account.admin.CreateAccountRequest;
-import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.account.rest.model.AccountActiveData;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
@@ -40,6 +39,7 @@ import org.eclipse.osee.account.rest.model.AccountLoginData;
import org.eclipse.osee.account.rest.model.AccountPreferencesData;
import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.framework.jdk.core.type.Identifiable;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.type.ResultSets;
@@ -199,30 +199,6 @@ public class AccountOpsTest {
}
@Test
- public void testAsAccountAccessData() {
- Date d1 = newRandomDate();
- Date d2 = newRandomDate();
-
- AccountSession access = mockAccess(789L, "t3", d1, d2, "f3", "d3");
-
- AccountSessionDetailsData actual = ops.asAccountAccessData(access);
-
- assertAccess(actual, 789L, d1, d2, "f3", "d3");
- }
-
- @Test
- public void testAsSessionData() {
- Date d1 = newRandomDate();
- Date d2 = newRandomDate();
- AccountSession access = mockAccess(123L, "t1", d1, d2, "f1", "d1");
-
- AccountSessionData actual = ops.asSessionData(access);
-
- assertEquals(123L, actual.getAccountId());
- assertEquals("t1", actual.getToken());
- }
-
- @Test
public void testGetAccountAccessById() {
Date d1 = newRandomDate();
Date d2 = newRandomDate();
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java
index c9683edb9a..e1dcaea7de 100644
--- a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java
@@ -15,8 +15,12 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import java.net.URI;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
import org.eclipse.osee.account.rest.model.AccountInput;
@@ -35,10 +39,11 @@ public class AccountResourceTest {
//@formatter:off
@Mock private AccountOps accountOps;
-
@Mock private AccountInput accountInput;
@Mock private AccountInfoData accountInfoData;
@Mock private AccountDetailsData details;
+
+ @Mock private UriInfo uriInfo;
//@formatter:on
private AccountResource resource;
@@ -120,4 +125,22 @@ public class AccountResourceTest {
verify(accountOps).getAccountSessionById(ACCOUNT_ID);
}
+ @Test
+ public void testGetSubscriptions() {
+ URI uri =
+ UriBuilder.fromPath("http://localhost:8089/oseex/accounts/{account-id}/subscriptions").build(ACCOUNT_ID);
+ when(uriInfo.getRequestUri()).thenReturn(uri);
+
+ Response response = resource.getSubscriptions(uriInfo);
+
+ int status = response.getStatus();
+ assertEquals(Status.SEE_OTHER.getStatusCode(), status);
+
+ URI location = (URI) response.getMetadata().getFirst(HttpHeaders.LOCATION);
+ URI expectedLocation =
+ UriBuilder.fromUri(uri).path("..").path("..").path("subscriptions").path("for-account").path("{account-id}").build(
+ ACCOUNT_ID);
+ assertEquals(expectedLocation, location);
+ }
+
}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java
index f3ba09b165..928b80d17d 100644
--- a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java
@@ -34,7 +34,6 @@ public class AccountsResourceTest {
//@formatter:off
@Mock private AccountOps accountOps;
-
@Mock private AccountInfoData account;
@Mock private AccountInput input;
//@formatter:on
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/SubscriptionsResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/SubscriptionsResourceTest.java
new file mode 100644
index 0000000000..bc48349337
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/SubscriptionsResourceTest.java
@@ -0,0 +1,242 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionAdmin;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.SubscriptionData;
+import org.eclipse.osee.account.rest.model.SubscriptionGroupData;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.type.ResultSets;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link SubscriptionsResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SubscriptionsResourceTest {
+
+ private static final String SUBSCRIPTION_UUID = "D_UhOLi6D7q_MbOiUYny75bUWxYdlHI9yCLyosilpDMYxRhasnqYvwCOlNEPgvrk";
+ private static final boolean SUBSCRIPTION_IS_ACTIVE = true;
+
+ private static final String ACCOUNT_UUID = "asdksa";
+ private static final String ACCOUNT_NAME = "account-1";
+ private static final long ACCOUNT_ID = 3129303L;
+ private static final String ACCOUNT_USERNAME = "sadfaa";
+ private static final String ACCOUNT_EMAIL = "hello@hello.com";
+ private static final boolean ACCOUNT_IS_ACTIVE = true;
+
+ private static final String GROUP_UUID = "sadjha322";
+ private static final String GROUP_NAME = "group-1";
+ private static final long GROUP_ID = 37219891L;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ //@formatter:off
+ @Mock private SubscriptionAdmin manager;
+
+ @Mock private Subscription subscription;
+ @Mock private SubscriptionGroup group;
+ @Mock private Account account;
+ //@formatter:on
+
+ private SubscriptionsResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new SubscriptionsResource(manager);
+
+ when(subscription.getGuid()).thenReturn(GROUP_UUID);
+ when(subscription.getName()).thenReturn(GROUP_NAME);
+ when(subscription.getAccountName()).thenReturn(ACCOUNT_NAME);
+ when(subscription.isActive()).thenReturn(SUBSCRIPTION_IS_ACTIVE);
+
+ when(group.getGuid()).thenReturn(GROUP_UUID);
+ when(group.getName()).thenReturn(GROUP_NAME);
+ when(group.getId()).thenReturn(GROUP_ID);
+
+ when(account.getGuid()).thenReturn(ACCOUNT_UUID);
+ when(account.getName()).thenReturn(ACCOUNT_NAME);
+ when(account.getId()).thenReturn(ACCOUNT_ID);
+ when(account.getUserName()).thenReturn(ACCOUNT_USERNAME);
+ when(account.getEmail()).thenReturn(ACCOUNT_EMAIL);
+ when(account.isActive()).thenReturn(ACCOUNT_IS_ACTIVE);
+ }
+
+ @Test
+ public void testGetSubscriptions() {
+ ResultSet<Subscription> results = ResultSets.singleton(subscription);
+ when(manager.getSubscriptionsByAccountUniqueField(ACCOUNT_UUID)).thenReturn(results);
+
+ SubscriptionData[] actual = resource.getSubscriptions(ACCOUNT_UUID);
+
+ assertEquals(1, actual.length);
+ SubscriptionData data = actual[0];
+ checkSubscription(data, GROUP_UUID, GROUP_NAME, ACCOUNT_NAME, SUBSCRIPTION_IS_ACTIVE);
+ verify(manager).getSubscriptionsByAccountUniqueField(ACCOUNT_UUID);
+ }
+
+ @Test
+ public void testGetSubscription() {
+ when(manager.getSubscription(SUBSCRIPTION_UUID)).thenReturn(subscription);
+
+ SubscriptionData actual = resource.getSubscription(SUBSCRIPTION_UUID);
+
+ checkSubscription(actual, GROUP_UUID, GROUP_NAME, ACCOUNT_NAME, SUBSCRIPTION_IS_ACTIVE);
+ verify(manager).getSubscription(SUBSCRIPTION_UUID);
+ }
+
+ @Test
+ public void testSetSubscriptionActiveOk() {
+ when(manager.setSubscriptionActive(SUBSCRIPTION_UUID, true)).thenReturn(true);
+
+ Response response = resource.setSubscriptionActive(SUBSCRIPTION_UUID);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ verify(manager).setSubscriptionActive(SUBSCRIPTION_UUID, true);
+ }
+
+ @Test
+ public void testSetSubscriptionActiveNotModified() {
+ when(manager.setSubscriptionActive(SUBSCRIPTION_UUID, true)).thenReturn(false);
+
+ Response response = resource.setSubscriptionActive(SUBSCRIPTION_UUID);
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
+
+ verify(manager).setSubscriptionActive(SUBSCRIPTION_UUID, true);
+ }
+
+ @Test
+ public void testSetSubscriptionInactiveOk() {
+ when(manager.setSubscriptionActive(SUBSCRIPTION_UUID, false)).thenReturn(true);
+
+ Response response = resource.setSubscriptionInactive(SUBSCRIPTION_UUID);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ verify(manager).setSubscriptionActive(SUBSCRIPTION_UUID, false);
+ }
+
+ @Test
+ public void testSetSubscriptionInactiveMotModified() {
+ when(manager.setSubscriptionActive(SUBSCRIPTION_UUID, false)).thenReturn(false);
+
+ Response response = resource.setSubscriptionInactive(SUBSCRIPTION_UUID);
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
+
+ verify(manager).setSubscriptionActive(SUBSCRIPTION_UUID, false);
+ }
+
+ @Test
+ public void testGetSubscriptionGroups() {
+ ResultSet<SubscriptionGroup> results = ResultSets.singleton(group);
+ when(manager.getSubscriptionGroups()).thenReturn(results);
+
+ SubscriptionGroupData[] actual = resource.getSubscriptionGroups();
+
+ assertEquals(1, actual.length);
+ SubscriptionGroupData data = actual[0];
+ checkSubscriptionGroup(data, GROUP_UUID, GROUP_NAME, GROUP_ID);
+ verify(manager).getSubscriptionGroups();
+ }
+
+ @Test
+ public void testGetSubscriptionGroup() {
+ ResultSet<SubscriptionGroup> results = ResultSets.singleton(group);
+ when(manager.getSubscriptionGroupByUniqueField(GROUP_UUID)).thenReturn(results);
+
+ SubscriptionGroupData actual = resource.getSubscriptionGroup(GROUP_UUID);
+
+ checkSubscriptionGroup(actual, GROUP_UUID, GROUP_NAME, GROUP_ID);
+ verify(manager).getSubscriptionGroupByUniqueField(GROUP_UUID);
+ }
+
+ @Test
+ public void testCreateSubscriptionGroup() {
+ when(manager.createSubscriptionGroup(GROUP_NAME)).thenReturn(group);
+
+ SubscriptionGroupData actual = resource.createSubscriptionGroup(GROUP_NAME);
+
+ checkSubscriptionGroup(actual, GROUP_UUID, GROUP_NAME, GROUP_ID);
+ verify(manager).createSubscriptionGroup(GROUP_NAME);
+ }
+
+ @Test
+ public void testDeleteSubscriptionGroup() {
+ when(manager.deleteSubscriptionGroupByUniqueField(GROUP_UUID)).thenReturn(true);
+
+ Response actual = resource.deleteSubscriptionGroup(GROUP_UUID);
+ assertEquals(Status.OK.getStatusCode(), actual.getStatus());
+
+ verify(manager).deleteSubscriptionGroupByUniqueField(GROUP_UUID);
+ }
+
+ @Test
+ public void testDeleteSubscriptionGroupNotModified() {
+ when(manager.deleteSubscriptionGroupByUniqueField(GROUP_UUID)).thenReturn(false);
+
+ Response actual = resource.deleteSubscriptionGroup(GROUP_UUID);
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
+
+ verify(manager).deleteSubscriptionGroupByUniqueField(GROUP_UUID);
+ }
+
+ @Test
+ public void testGetSubscriptionGroupMembers() {
+ ResultSet<Account> results = ResultSets.singleton(account);
+ when(manager.getSubscriptionGroupMembersByUniqueField(GROUP_UUID)).thenReturn(results);
+
+ AccountInfoData[] actual = resource.getSubscriptionGroupMembers(GROUP_UUID);
+
+ assertEquals(1, actual.length);
+ AccountInfoData data = actual[0];
+ checkAccount(data, ACCOUNT_UUID, ACCOUNT_NAME, ACCOUNT_ID, ACCOUNT_USERNAME, ACCOUNT_EMAIL, ACCOUNT_IS_ACTIVE);
+ verify(manager).getSubscriptionGroupMembersByUniqueField(GROUP_UUID);
+ }
+
+ private static void checkSubscription(SubscriptionData actual, String guid, String name, String accountName, boolean active) {
+ assertEquals(guid, actual.getGuid());
+ assertEquals(name, actual.getName());
+ assertEquals(accountName, actual.getAccountName());
+ assertEquals(active, actual.isActive());
+ }
+
+ private static void checkSubscriptionGroup(SubscriptionGroupData actual, String guid, String name, long groupId) {
+ assertEquals(guid, actual.getGuid());
+ assertEquals(name, actual.getName());
+ assertEquals(groupId, actual.getId());
+ }
+
+ private static void checkAccount(AccountInfoData actual, String guid, String name, long accountId, String username, String email, boolean active) {
+ assertEquals(guid, actual.getGuid());
+ assertEquals(name, actual.getName());
+ assertEquals(accountId, actual.getAccountId());
+ assertEquals(username, actual.getUserName());
+ assertEquals(email, actual.getEmail());
+ assertEquals(active, actual.isActive());
+ }
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/UnsubscribeResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/UnsubscribeResourceTest.java
new file mode 100644
index 0000000000..1f6f931e02
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/UnsubscribeResourceTest.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.net.URI;
+import javax.ws.rs.core.UriBuilder;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionAdmin;
+import org.eclipse.osee.account.rest.internal.UnsubscribeResource.UnsubscribePageWriter;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link UnsubscribeResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class UnsubscribeResourceTest {
+
+ private static final String SUBSCRIPTION_UUID = "D_UhOLi6D7q_MbOiUYny75bUWxYdlHI9yCLyosilpDMYxRhasnqYvwCOlNEPgvrk";
+
+ private static final String GROUP_UUID = "sadjha322";
+ private static final long GROUP_ID = 37219891L;
+ private static final String GROUP_NAME = "group-1";
+ private static final long ACCOUNT_ID = 3129303L;
+ private static final String ACCOUNT_NAME = "account-1";
+
+ //@formatter:off
+ @Mock private SubscriptionAdmin manager;
+ @Mock private Subscription subscription;
+ @Mock private UnsubscribePageWriter writer;
+ //@formatter:on
+
+ private UnsubscribeResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new UnsubscribeResource(manager, writer);
+
+ when(subscription.getGuid()).thenReturn(GROUP_UUID);
+ when(subscription.getGroupId()).thenReturn(GROUP_ID);
+ when(subscription.getName()).thenReturn(GROUP_NAME);
+ when(subscription.getAccountId()).thenReturn(ACCOUNT_ID);
+ when(subscription.getAccountName()).thenReturn(ACCOUNT_NAME);
+ }
+
+ @Test
+ public void testGetUnsubscribePageActiveSubscription() {
+ when(manager.getSubscription(SUBSCRIPTION_UUID)).thenReturn(subscription);
+ when(subscription.isActive()).thenReturn(true);
+ when(subscription.getGuid()).thenReturn(SUBSCRIPTION_UUID);
+
+ URI expected = UriBuilder.fromPath(SUBSCRIPTION_UUID).path("confirm").build();
+
+ resource.getUnsubscribePage(SUBSCRIPTION_UUID);
+
+ verify(manager).getSubscription(SUBSCRIPTION_UUID);
+ verify(subscription).isActive();
+ verify(subscription).getGuid();
+ verify(writer).newUnsubscribePage(expected, GROUP_NAME, ACCOUNT_NAME);
+ }
+
+ @Test
+ public void testGetUnsubscribePageInActiveSubscription() {
+ when(manager.getSubscription(SUBSCRIPTION_UUID)).thenReturn(subscription);
+ when(subscription.isActive()).thenReturn(false);
+
+ resource.getUnsubscribePage(SUBSCRIPTION_UUID);
+
+ verify(manager).getSubscription(SUBSCRIPTION_UUID);
+ verify(subscription).isActive();
+ verify(subscription, times(0)).getGuid();
+ verify(writer).newUnsubscribeNoSubscriptionFoundPage(GROUP_NAME, ACCOUNT_NAME);
+ }
+
+ @Test
+ public void testProcessUnsubscribePageSubscriptionRemoved() {
+ when(manager.getSubscription(SUBSCRIPTION_UUID)).thenReturn(subscription);
+ when(manager.setSubscriptionActive(subscription, false)).thenReturn(true);
+
+ resource.processUnsubscribePage(SUBSCRIPTION_UUID);
+
+ verify(manager).getSubscription(SUBSCRIPTION_UUID);
+ verify(manager).setSubscriptionActive(subscription, false);
+ verify(writer).newUnsubscribeSuccessPage(GROUP_NAME, ACCOUNT_NAME);
+ }
+
+ @Test
+ public void testProcessUnsubscribePageSubscriptionNoChange() {
+ when(manager.getSubscription(SUBSCRIPTION_UUID)).thenReturn(subscription);
+ when(manager.setSubscriptionActive(subscription, false)).thenReturn(false);
+
+ resource.processUnsubscribePage(SUBSCRIPTION_UUID);
+
+ verify(manager).getSubscription(SUBSCRIPTION_UUID);
+ verify(manager).setSubscriptionActive(subscription, false);
+ verify(writer).newUnsubscribeNoSubscriptionFoundPage(GROUP_NAME, ACCOUNT_NAME);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF
index 55880e547a..bcccbbe7dc 100644
--- a/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.account.rest/META-INF/MANIFEST.MF
@@ -11,9 +11,10 @@ Import-Package: javax.annotation.security,
javax.servlet.http,
javax.ws.rs,
javax.ws.rs.core,
- javax.ws.rs.ext,
+ org.apache.commons.codec.binary,
org.eclipse.osee.account.admin,
org.eclipse.osee.account.rest.model,
org.eclipse.osee.framework.jdk.core.type,
- org.eclipse.osee.framework.jdk.core.util
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.template.engine
Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml b/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml
index 1ce0ba56b7..0c1957492a 100644
--- a/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml
+++ b/plugins/org.eclipse.osee.account.rest/OSGI-INF/account.rest.application.xml
@@ -5,4 +5,5 @@
<provide interface="javax.ws.rs.core.Application"/>
</service>
<reference bind="setAccountAdmin" cardinality="1..1" interface="org.eclipse.osee.account.admin.AccountAdmin" name="AccountAdmin" policy="static"/>
+ <reference bind="setSubscriptionAdmin" cardinality="1..1" interface="org.eclipse.osee.account.admin.SubscriptionAdmin" name="SubscriptionAdmin" policy="static"/>
</scr:component>
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java
index ad792432d7..a901b450da 100644
--- a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountApplication.java
@@ -15,23 +15,33 @@ import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.eclipse.osee.account.admin.AccountAdmin;
+import org.eclipse.osee.account.admin.SubscriptionAdmin;
/**
* @author Roberto E. Escobar
*/
@ApplicationPath("oseex/accounts")
public class AccountApplication extends Application {
-
private final Set<Object> singletons = new HashSet<Object>();
+
private AccountAdmin accountAdmin;
+ private SubscriptionAdmin subscriptionAdmin;
public void setAccountAdmin(AccountAdmin accountAdmin) {
this.accountAdmin = accountAdmin;
}
+ public void setSubscriptionAdmin(SubscriptionAdmin subscriptionAdmin) {
+ this.subscriptionAdmin = subscriptionAdmin;
+ }
+
public void start() {
+ PageWriter writer = new PageWriter();
AccountOps ops = new AccountOps(accountAdmin);
+
singletons.add(new AccountsResource(ops));
+ singletons.add(new SubscriptionsResource(subscriptionAdmin));
+ singletons.add(new UnsubscribeResource(subscriptionAdmin, writer));
}
public void stop() {
@@ -43,4 +53,4 @@ public class AccountApplication extends Application {
return singletons;
}
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountDataUtil.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountDataUtil.java
new file mode 100644
index 0000000000..cbf3031418
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountDataUtil.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.AccountPreferences;
+import org.eclipse.osee.account.admin.AccountSession;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.rest.model.AccountActiveData;
+import org.eclipse.osee.account.rest.model.AccountDetailsData;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesData;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
+import org.eclipse.osee.account.rest.model.SubscriptionData;
+import org.eclipse.osee.account.rest.model.SubscriptionGroupData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class AccountDataUtil {
+
+ private AccountDataUtil() {
+ // Utility class
+ }
+
+ public static AccountSessionDetailsData asAccountAccessData(AccountSession session) {
+ AccountSessionDetailsData data = new AccountSessionDetailsData();
+ data.setAccountId(session.getAccountId());
+ data.setAccessDetails(session.getAccessDetails());
+ data.setAccessedFrom(session.getAccessedFrom());
+ data.setCreatedOn(session.getCreatedOn());
+ data.setLastAccessedOn(session.getLastAccessedOn());
+ return data;
+ }
+
+ public static AccountSessionData asSessionData(AccountSession session) {
+ AccountSessionData data = new AccountSessionData();
+ data.setAccountId(session.getAccountId());
+ data.setToken(session.getSessionToken());
+ return data;
+ }
+
+ public static AccountDetailsData asAccountDetailsData(Account account) {
+ AccountDetailsData data = new AccountDetailsData();
+ fillData(account, data);
+ AccountPreferencesData preferences = asAccountPreferencesData(account.getPreferences());
+ data.setPreferences(preferences);
+ return data;
+ }
+
+ public static AccountInfoData asAccountData(Account account) {
+ AccountInfoData data = new AccountInfoData();
+ fillData(account, data);
+ return data;
+ }
+
+ private static void fillData(Account account, AccountInfoData data) {
+ data.setAccountId(account.getId());
+ data.setGuid(account.getGuid());
+ data.setName(account.getName());
+ data.setEmail(account.getEmail());
+ data.setUserName(account.getUserName());
+ data.setActive(account.isActive());
+ }
+
+ public static AccountPreferencesData asAccountPreferencesData(AccountPreferences preferences) {
+ AccountPreferencesData data = new AccountPreferencesData();
+ data.setId(preferences.getId());
+ data.setMap(preferences.asMap());
+ return data;
+ }
+
+ public static AccountActiveData asAccountActiveData(Account account) {
+ AccountActiveData data = new AccountActiveData();
+ data.setAccountId(account.getId());
+ data.setGuid(account.getGuid());
+ data.setActive(account.isActive());
+ return data;
+ }
+
+ public static SubscriptionData asAccountSubscriptionData(Subscription subscription) {
+ SubscriptionData data = new SubscriptionData();
+ data.setGuid(subscription.getGuid());
+ data.setName(subscription.getName());
+ data.setActive(subscription.isActive());
+ data.setAccountName(subscription.getAccountName());
+ return data;
+ }
+
+ public static SubscriptionGroupData asSubscriptionGroupData(SubscriptionGroup src) {
+ SubscriptionGroupData data = new SubscriptionGroupData();
+ data.setGuid(src.getGuid());
+ data.setName(src.getName());
+ data.setId(src.getId());
+ return data;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java
index 0ed1649b0c..83dfe785f7 100644
--- a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountOps.java
@@ -21,7 +21,6 @@ import org.eclipse.osee.account.admin.AccountPreferences;
import org.eclipse.osee.account.admin.AccountSession;
import org.eclipse.osee.account.admin.CreateAccountRequest;
import org.eclipse.osee.account.admin.CreateAccountRequestBuilder;
-import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.account.rest.model.AccountActiveData;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
@@ -30,6 +29,7 @@ import org.eclipse.osee.account.rest.model.AccountLoginData;
import org.eclipse.osee.account.rest.model.AccountPreferencesData;
import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.account.rest.model.AccountSessionDetailsData;
import org.eclipse.osee.framework.jdk.core.type.Identifiable;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
@@ -67,21 +67,11 @@ public class AccountOps {
ResultSet<AccountSession> result = accountAdmin.getAccountSessionByUniqueField(accountId);
List<AccountSessionDetailsData> toReturn = new ArrayList<AccountSessionDetailsData>();
for (AccountSession session : result) {
- toReturn.add(asAccountAccessData(session));
+ toReturn.add(AccountDataUtil.asAccountAccessData(session));
}
return toReturn;
}
- public AccountSessionDetailsData asAccountAccessData(AccountSession session) {
- AccountSessionDetailsData data = new AccountSessionDetailsData();
- data.setAccountId(session.getAccountId());
- data.setAccessDetails(session.getAccessDetails());
- data.setAccessedFrom(session.getAccessedFrom());
- data.setCreatedOn(session.getCreatedOn());
- data.setLastAccessedOn(session.getLastAccessedOn());
- return data;
- }
-
public AccountSessionData doLogin(RequestInfo info, AccountLoginData input) {
AccountLoginRequestBuilder builder = AccountLoginRequestBuilder.newBuilder();
AccountLoginRequest request = builder//
@@ -92,20 +82,13 @@ public class AccountOps {
.remoteAddress(info.getRemoteIpAddress()) //
.build();
AccountSession session = accountAdmin.login(request);
- return asSessionData(session);
+ return AccountDataUtil.asSessionData(session);
}
public boolean doLogout(String token) {
return accountAdmin.logout(token);
}
- public AccountSessionData asSessionData(AccountSession session) {
- AccountSessionData data = new AccountSessionData();
- data.setAccountId(session.getAccountId());
- data.setToken(session.getSessionToken());
- return data;
- }
-
public AccountInfoData createAccount(String username, AccountInput input) {
CreateAccountRequestBuilder builder = CreateAccountRequestBuilder.newBuilder();
CreateAccountRequest request = builder//
@@ -119,7 +102,7 @@ public class AccountOps {
Identifiable<String> id = accountAdmin.createAccount(request);
ResultSet<Account> result = accountAdmin.getAccountByUuid(id.getGuid());
Account account = result.getExactlyOne();
- return asAccountData(account);
+ return AccountDataUtil.asAccountData(account);
}
public boolean deleteAccount(String accountId) {
@@ -133,14 +116,14 @@ public class AccountOps {
public AccountActiveData isActive(String accountId) {
ResultSet<Account> result = accountAdmin.getAccountByUniqueField(accountId);
Account account = result.getExactlyOne();
- return asAccountActiveData(account);
+ return AccountDataUtil.asAccountActiveData(account);
}
public List<AccountInfoData> getAllAccounts() {
List<AccountInfoData> toReturn = new ArrayList<AccountInfoData>();
ResultSet<Account> result = accountAdmin.getAllAccounts();
for (Account account : result) {
- toReturn.add(asAccountData(account));
+ toReturn.add(AccountDataUtil.asAccountData(account));
}
return toReturn;
}
@@ -148,58 +131,20 @@ public class AccountOps {
public AccountDetailsData getAccountDetailsData(String accountId) {
ResultSet<Account> result = accountAdmin.getAccountByUniqueField(accountId);
Account account = result.getExactlyOne();
- return asAccountDetailsData(account);
+ return AccountDataUtil.asAccountDetailsData(account);
}
public AccountInfoData getAccountData(String value) {
ResultSet<Account> result = accountAdmin.getAccountByUniqueField(value);
Account account = result.getExactlyOne();
- return asAccountData(account);
+ return AccountDataUtil.asAccountData(account);
}
public AccountPreferencesData getAccountPreferencesData(String value) {
ResultSet<Account> result = accountAdmin.getAccountByUniqueField(value);
Account account = result.getExactlyOne();
AccountPreferences preferences = account.getPreferences();
- return asAccountPreferencesData(preferences);
- }
-
- private AccountDetailsData asAccountDetailsData(Account account) {
- AccountDetailsData data = new AccountDetailsData();
- fillData(account, data);
- AccountPreferencesData preferences = asAccountPreferencesData(account.getPreferences());
- data.setPreferences(preferences);
- return data;
- }
-
- private AccountInfoData asAccountData(Account account) {
- AccountInfoData data = new AccountInfoData();
- fillData(account, data);
- return data;
- }
-
- private void fillData(Account account, AccountInfoData data) {
- data.setAccountId(account.getId());
- data.setGuid(account.getGuid());
- data.setName(account.getName());
- data.setEmail(account.getEmail());
- data.setUserName(account.getUserName());
- data.setActive(account.isActive());
- }
-
- private AccountPreferencesData asAccountPreferencesData(AccountPreferences preferences) {
- AccountPreferencesData data = new AccountPreferencesData();
- data.setId(preferences.getId());
- data.setMap(preferences.asMap());
- return data;
- }
-
- private AccountActiveData asAccountActiveData(Account account) {
- AccountActiveData data = new AccountActiveData();
- data.setAccountId(account.getId());
- data.setGuid(account.getGuid());
- data.setActive(account.isActive());
- return data;
+ return AccountDataUtil.asAccountPreferencesData(preferences);
}
public boolean setAccountPreferences(String accountId, AccountPreferencesInput input) {
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java
index d919ee5101..9a03144794 100644
--- a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/AccountResource.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.account.rest.internal;
+import java.net.URI;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
@@ -18,9 +19,12 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import org.eclipse.osee.account.admin.SystemRoles;
import org.eclipse.osee.account.rest.model.AccountContexts;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
@@ -86,6 +90,22 @@ public class AccountResource {
return accountOps.getAccountDetailsData(accountId);
}
+ /**
+ * Get All account subscriptions
+ *
+ * @return accountSubscriptions
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("subscriptions")
+ @GET
+ public Response getSubscriptions(@Context UriInfo uriInfo) {
+ URI requestUri = uriInfo.getRequestUri();
+ URI uri =
+ UriBuilder.fromUri(requestUri).path("..").path("..").path("subscriptions").path("for-account").path(
+ "{account-id}").build(accountId);
+ return Response.seeOther(uri).build();
+ }
+
@Path(AccountContexts.ACCOUNT_PREFERENCES)
public AccountPreferencesResource getAccountSettingsData() {
return new AccountPreferencesResource(accountOps, accountId);
@@ -101,4 +121,4 @@ public class AccountResource {
return new AccountSessionsResource(accountOps, accountId);
}
-}
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/PageWriter.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/PageWriter.java
new file mode 100644
index 0000000000..38c808d6e4
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/PageWriter.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import java.net.URI;
+import org.eclipse.osee.account.rest.internal.UnsubscribeResource.UnsubscribePageWriter;
+import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken;
+import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry;
+import org.eclipse.osee.framework.jdk.core.type.ResourceRegistry;
+import org.eclipse.osee.framework.jdk.core.type.ResourceToken;
+import org.eclipse.osee.template.engine.PageFactory;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class PageWriter implements UnsubscribePageWriter {
+ private static final ResourceToken UNSUBSCRIBE_TEMPLATE = createToken("unsubscribe.html");
+ private static final ResourceToken UNSUBSCRIBE_SUCCESS_TEMPLATE = createToken("unsubscribe_success.html");
+ private static final ResourceToken UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE =
+ createToken("unsubscribe_no_subscription.html");
+
+ private static final String ACCOUNT_DISPLAY_NAME_TAG = "accountDisplayName";
+ private static final String SUBSCRIPTION_NAME_TAG = "subscriptionName";
+ private static final String UNSUBSCRIBE_URL = "unsubscribeUrl";
+
+ private IResourceRegistry registry;
+
+ private IResourceRegistry getRegistry() {
+ if (registry == null) {
+ registry = new ResourceRegistry();
+ registry.registerResource(-1L, UNSUBSCRIBE_TEMPLATE);
+ registry.registerResource(-2L, UNSUBSCRIBE_SUCCESS_TEMPLATE);
+ registry.registerResource(-3L, UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE);
+ }
+ return registry;
+ }
+
+ @Override
+ public String newUnsubscribePage(URI unsubscribeUri, String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_TEMPLATE, //
+ UNSUBSCRIBE_URL, unsubscribeUri.toASCIIString(), //
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ @Override
+ public String newUnsubscribeNoSubscriptionFoundPage(String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE, //
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ @Override
+ public String newUnsubscribeSuccessPage(String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_SUCCESS_TEMPLATE,//
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ private static ResourceToken createToken(String fileName) {
+ return new ClassBasedResourceToken(fileName, UnsubscribeResource.class);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/SubscriptionsResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/SubscriptionsResource.java
new file mode 100644
index 0000000000..f0217cb7b8
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/SubscriptionsResource.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionAdmin;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.admin.SystemRoles;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.SubscriptionData;
+import org.eclipse.osee.account.rest.model.SubscriptionGroupData;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Path("/subscriptions")
+public class SubscriptionsResource {
+
+ private final SubscriptionAdmin manager;
+
+ public SubscriptionsResource(SubscriptionAdmin manager) {
+ super();
+ this.manager = manager;
+ }
+
+ /**
+ * Get All account subscriptions
+ *
+ * @return accountSubscriptions
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/for-account/{account-id}")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public SubscriptionData[] getSubscriptions(@PathParam("account-id") String accountId) {
+ ResultSet<Subscription> subscriptions = manager.getSubscriptionsByAccountUniqueField(accountId);
+ SubscriptionData[] toReturn = new SubscriptionData[subscriptions.size()];
+ int index = 0;
+ for (Subscription subscription : subscriptions) {
+ toReturn[index++] = AccountDataUtil.asAccountSubscriptionData(subscription);
+ }
+ return toReturn;
+ }
+
+ /**
+ * Get account subscription info
+ *
+ * @return accountSubscription
+ */
+ @Path("/{subscription-uuid}")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public SubscriptionData getSubscription(@PathParam("subscription-uuid") String subscriptionUuid) {
+ Subscription accountSubscription = manager.getSubscription(subscriptionUuid);
+ return AccountDataUtil.asAccountSubscriptionData(accountSubscription);
+ }
+
+ /**
+ * Set subscription status to active
+ *
+ * @return response
+ * @response.representation.200.doc subscription status set to active
+ * @response.representation.304.doc subscription active status not modified
+ */
+ @Path("/{subscription-uuid}/active")
+ @PUT
+ public Response setSubscriptionActive(@PathParam("subscription-uuid") String subscriptionUuid) {
+ ResponseBuilder builder;
+ boolean modified = manager.setSubscriptionActive(subscriptionUuid, true);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+ /**
+ * Set subscription status to inactive
+ *
+ * @return response
+ * @response.representation.200.doc subscription status set to inactive
+ * @response.representation.304.doc subscription status not modified
+ */
+ @Path("/{subscription-uuid}/active")
+ @DELETE
+ public Response setSubscriptionInactive(@PathParam("subscription-uuid") String subscriptionUuid) {
+ ResponseBuilder builder;
+ boolean modified = manager.setSubscriptionActive(subscriptionUuid, false);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+ /**
+ * Get all subscription groups
+ *
+ * @return subscription groups
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/groups")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public SubscriptionGroupData[] getSubscriptionGroups() {
+ ResultSet<SubscriptionGroup> groups = manager.getSubscriptionGroups();
+ SubscriptionGroupData[] toReturn = new SubscriptionGroupData[groups.size()];
+ int index = 0;
+ for (SubscriptionGroup group : groups) {
+ toReturn[index++] = AccountDataUtil.asSubscriptionGroupData(group);
+ }
+ return toReturn;
+ }
+
+ /**
+ * Get subscription group
+ *
+ * @return subscription group
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/groups/{group-id}")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public SubscriptionGroupData getSubscriptionGroup(@PathParam("group-id") String groupId) {
+ SubscriptionGroup group = manager.getSubscriptionGroupByUniqueField(groupId).getExactlyOne();
+ return AccountDataUtil.asSubscriptionGroupData(group);
+ }
+
+ /**
+ * Get subscription group
+ *
+ * @return subscription group
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/groups/{group-id}/members")
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public AccountInfoData[] getSubscriptionGroupMembers(@PathParam("group-id") String groupId) {
+ ResultSet<Account> accounts = manager.getSubscriptionGroupMembersByUniqueField(groupId);
+ AccountInfoData[] toReturn = new AccountInfoData[accounts.size()];
+ int index = 0;
+ for (Account group : accounts) {
+ toReturn[index++] = AccountDataUtil.asAccountData(group);
+ }
+ return toReturn;
+ }
+
+ /**
+ * Create a subscription group
+ *
+ * @return subscription group
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/groups/{group-name}")
+ @POST
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public SubscriptionGroupData createSubscriptionGroup(@PathParam("group-name") String groupName) {
+ SubscriptionGroup group = manager.createSubscriptionGroup(groupName);
+ return AccountDataUtil.asSubscriptionGroupData(group);
+ }
+
+ /**
+ * Delete subscription group
+ *
+ * @return subscription group
+ */
+ @RolesAllowed(SystemRoles.ROLES_AUTHENTICATED)
+ @Path("/groups/{group-id}")
+ @DELETE
+ public Response deleteSubscriptionGroup(@PathParam("group-id") String groupId) {
+ ResponseBuilder builder;
+ boolean modified = manager.deleteSubscriptionGroupByUniqueField(groupId);
+ if (modified) {
+ builder = Response.ok();
+ } else {
+ builder = Response.notModified();
+ }
+ return builder.build();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/UnsubscribeResource.java b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/UnsubscribeResource.java
new file mode 100644
index 0000000000..50846d2380
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/UnsubscribeResource.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.internal;
+
+import java.net.URI;
+import javax.annotation.security.PermitAll;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriBuilder;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionAdmin;
+import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken;
+import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry;
+import org.eclipse.osee.framework.jdk.core.type.ResourceRegistry;
+import org.eclipse.osee.framework.jdk.core.type.ResourceToken;
+import org.eclipse.osee.template.engine.PageFactory;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@PermitAll
+@Path("/unsubscribe")
+public class UnsubscribeResource {
+
+ public static interface UnsubscribePageWriter {
+
+ String newUnsubscribePage(URI unsubscribeUri, String subscriptionName, String accountName);
+
+ String newUnsubscribeNoSubscriptionFoundPage(String subscriptionName, String accountName);
+
+ String newUnsubscribeSuccessPage(String subscriptionName, String accountName);
+
+ }
+
+ private final SubscriptionAdmin manager;
+ private final UnsubscribePageWriter writer;
+
+ public UnsubscribeResource(SubscriptionAdmin manager, UnsubscribePageWriter writer) {
+ this.manager = manager;
+ this.writer = writer;
+ }
+
+ /**
+ * Gets an Unsubscribe page to allow the user to select to unsubscribe
+ *
+ * @param subscriptionUuid
+ */
+ @Path("/ui/{subscription-uuid}")
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public String getUnsubscribePage(@PathParam("subscription-uuid") String subscriptionUuid) {
+ Subscription subscription = manager.getSubscription(subscriptionUuid);
+ String page;
+ if (subscription.isActive()) {
+ String uuid = subscription.getGuid();
+ URI unsubscribeUri = UriBuilder.fromPath("{subscription-uuid}").path("confirm").build(uuid);
+ page = writer.newUnsubscribePage(unsubscribeUri, subscription.getName(), subscription.getAccountName());
+ } else {
+ page = writer.newUnsubscribeNoSubscriptionFoundPage(subscription.getName(), subscription.getAccountName());
+ }
+ return page;
+ }
+
+ /**
+ * Gets an Unsubscribe page to allow the user to select to unsubscribe
+ *
+ * @param subscriptionUuid
+ */
+ @Path("/ui/{subscription-uuid}/confirm")
+ @POST
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ @Produces(MediaType.TEXT_HTML)
+ public String processUnsubscribePage(@Encoded @PathParam("subscription-uuid") String subscriptionUuid) {
+ Subscription subscription = manager.getSubscription(subscriptionUuid);
+ boolean modified = manager.setSubscriptionActive(subscription, false);
+ String page;
+ if (modified) {
+ page = writer.newUnsubscribeSuccessPage(subscription.getName(), subscription.getAccountName());
+ } else {
+ page = writer.newUnsubscribeNoSubscriptionFoundPage(subscription.getName(), subscription.getAccountName());
+ }
+ return page;
+ }
+
+ public static class UnsubscribePageWriterImpl implements UnsubscribePageWriter {
+ private static final ResourceToken UNSUBSCRIBE_TEMPLATE = createToken("unsubscribe.html");
+ private static final ResourceToken UNSUBSCRIBE_SUCCESS_TEMPLATE = createToken("unsubscribe_success.html");
+ private static final ResourceToken UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE =
+ createToken("unsubscribe_no_subscription.html");
+
+ private static final String ACCOUNT_DISPLAY_NAME_TAG = "accountDisplayName";
+ private static final String SUBSCRIPTION_NAME_TAG = "subscriptionName";
+ private static final String UNSUBSCRIBE_URL = "unsubscribeUrl";
+
+ private IResourceRegistry registry;
+
+ private IResourceRegistry getRegistry() {
+ if (registry == null) {
+ registry = new ResourceRegistry();
+ registry.registerResource(-1L, UNSUBSCRIBE_TEMPLATE);
+ registry.registerResource(-2L, UNSUBSCRIBE_SUCCESS_TEMPLATE);
+ registry.registerResource(-3L, UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE);
+ }
+ return registry;
+ }
+
+ @Override
+ public String newUnsubscribePage(URI unsubscribeUri, String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_TEMPLATE, //
+ UNSUBSCRIBE_URL, unsubscribeUri.toASCIIString(), //
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ @Override
+ public String newUnsubscribeNoSubscriptionFoundPage(String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_NO_SUBSCRIPTION_TEMPLATE, //
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ @Override
+ public String newUnsubscribeSuccessPage(String subscriptionName, String accountName) {
+ return PageFactory.realizePage(getRegistry(), UNSUBSCRIBE_SUCCESS_TEMPLATE,//
+ ACCOUNT_DISPLAY_NAME_TAG, accountName, //
+ SUBSCRIPTION_NAME_TAG, subscriptionName);
+ }
+
+ private static ResourceToken createToken(String fileName) {
+ return new ClassBasedResourceToken(fileName, UnsubscribeResource.class);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe.html b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe.html
new file mode 100644
index 0000000000..7fa0648322
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <link rel="stylesheet" type="text/css" href="/lib/css/bootstrap.min.css"></link>
+ <meta name="viewport" content="width=device-width, initial-scale=1"></meta>
+ <meta charset="UTF-8">
+ <title>OSEE Unsubscribe</title>
+</head>
+<body>
+<div class="container">
+ <div>
+ <h1>OSEE - Opt Out </h1>
+ <p>Unsubscribe from this mailing list...</p>
+ <div>
+ <br/>
+
+ <form role="form" method="POST" action="<?unsubscribeUrl?>">
+ <input class="form-control" type="hidden" name="accountDisplayName" value="<?accountDisplayName?>">
+ <input class="form-control" type="hidden" name="subscriptionName" value="<?subscriptionName?>">
+ <div class="form-group">
+ <div class="container">
+ Are you sure you want to remove <b><?accountDisplayName?></b> from future <b><?subscriptionName?></b> announcements?
+ </div>
+ <br/>
+ <button type="submit" class="btn btn-default">Confirm</button>
+ </div>
+ </form>
+</div>
+</body>
+</html>
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_no_subscription.html b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_no_subscription.html
new file mode 100644
index 0000000000..7bc6dae633
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_no_subscription.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <link rel="stylesheet" type="text/css" href="/lib/css/bootstrap.min.css"></link>
+ <meta name="viewport" content="width=device-width, initial-scale=1"></meta>
+ <meta charset="UTF-8">
+ <title>OSEE Unsubscribe</title>
+</head>
+<body>
+<div class="container">
+ <div>
+ <h1>OSEE - Opt Out </h1>
+ <p>Unsubscribe from this mailing list...</p>
+ <div>
+ <br/>
+ <div class="container">
+ <b>No Change</b> - <b><?accountDisplayName?></b> has already been removed from future <b><?subscriptionName?></b> announcements.
+ </div>
+</div>
+</body>
+</html>
diff --git a/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_success.html b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_success.html
new file mode 100644
index 0000000000..309700dcfb
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest/src/org/eclipse/osee/account/rest/internal/html/unsubscribe_success.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <link rel="stylesheet" type="text/css" href="/lib/css/bootstrap.min.css"></link>
+ <meta name="viewport" content="width=device-width, initial-scale=1"></meta>
+ <meta charset="UTF-8">
+ <title>OSEE Unsubscribe</title>
+</head>
+<body>
+<div class="container">
+ <div>
+ <h1>OSEE - Opt Out </h1>
+ <p>Unsubscribe from this mailing list...</p>
+ <div>
+ <br/>
+
+ <div class="container">
+ <b>Success</b> - <b><?accountDisplayName?></b> has been removed from future <b><?subscriptionName?></b> announcements.
+ </div>
+</div>
+</body>
+</html>

Back to the top