Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-06-07 04:17:58 +0000
committerRoberto E. Escobar2014-06-18 17:21:20 +0000
commit3f0b3f1feb61e00cf2100396b233f6b819d883ee (patch)
tree1aedc35698c792f77ac12d83cf22e281dedecaf2 /plugins/org.eclipse.osee.orcs.account.admin
parent72650555ae15a8b604d5f0e92019d4d4deadea76 (diff)
downloadorg.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.tar.gz
org.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.tar.xz
org.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.zip
feature[ats_ATS64153]: Create ORCS Account Subscriptions storage
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.account.admin')
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/OSGI-INF/orcs.subscription.ds.xml10
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountFactory.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSubscriptionGroupImpl.java46
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/OrcsSubscriptionStorage.java189
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtil.java116
5 files changed, 381 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/OSGI-INF/orcs.subscription.ds.xml b/plugins/org.eclipse.osee.orcs.account.admin/OSGI-INF/orcs.subscription.ds.xml
new file mode 100644
index 00000000000..2ccb565de59
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin/OSGI-INF/orcs.subscription.ds.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+ <implementation class="org.eclipse.osee.orcs.account.admin.internal.OrcsSubscriptionStorage"/>
+ <service>
+ <provide interface="org.eclipse.osee.account.admin.ds.SubscriptionStorage"/>
+ </service>
+ <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
+ <reference bind="setOrcsApi" cardinality="1..1" interface="org.eclipse.osee.orcs.OrcsApi" name="OrcsApi" policy="static"/>
+ <reference bind="setAccountFactory" cardinality="1..1" interface="org.eclipse.osee.orcs.account.admin.internal.AccountFactory" name="AccountFactory" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountFactory.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountFactory.java
index 68b35e9e8e7..32ef66ecbf8 100644
--- a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountFactory.java
+++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountFactory.java
@@ -14,6 +14,7 @@ import java.util.Date;
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.SubscriptionGroup;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.type.ResultSetTransform.Function;
import org.eclipse.osee.framework.jdk.core.type.ResultSets;
@@ -26,6 +27,8 @@ public class AccountFactory {
private final Function<String, ArtifactReadable, Account> function1 = new ArtifactToAccount();
private final Function<String, ArtifactReadable, AccountPreferences> function2 = new ArtifactToAccountPreferences();
+ private final Function<String, ArtifactReadable, SubscriptionGroup> function3 =
+ new ArtifactToAccountSubscriptionGroup();
public ResultSet<Account> newAccountResultSet(ResultSet<ArtifactReadable> results) {
return ResultSets.transform(results, function1);
@@ -76,4 +79,21 @@ public class AccountFactory {
session.setAccessedFrom(accessedFrom);
return session;
}
+
+ public SubscriptionGroup newAccountSubscriptionGroup(ArtifactReadable source) {
+ return new AccountSubscriptionGroupImpl(source.getGuid(), source);
+ }
+
+ public ResultSet<SubscriptionGroup> newAccountSubscriptionGroupResultSet(ResultSet<ArtifactReadable> results) {
+ return ResultSets.transform(results, function3);
+ }
+
+ private class ArtifactToAccountSubscriptionGroup implements Function<String, ArtifactReadable, SubscriptionGroup> {
+
+ @Override
+ public SubscriptionGroup apply(ArtifactReadable source) {
+ return newAccountSubscriptionGroup(source);
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSubscriptionGroupImpl.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSubscriptionGroupImpl.java
new file mode 100644
index 00000000000..4791ea44ed6
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSubscriptionGroupImpl.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.orcs.account.admin.internal;
+
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.jdk.core.type.BaseIdentity;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AccountSubscriptionGroupImpl extends BaseIdentity<String> implements SubscriptionGroup {
+
+ private static final String NOT_AVAILABLE = "N/A";
+ private final ArtifactReadable artifact;
+
+ public AccountSubscriptionGroupImpl(String uuid, ArtifactReadable artifact) {
+ super(artifact.getGuid());
+ this.artifact = artifact;
+ }
+
+ @Override
+ public long getId() {
+ return artifact.getLocalId();
+ }
+
+ @Override
+ public String getName() {
+ return artifact.getSoleAttributeValue(CoreAttributeTypes.Name, NOT_AVAILABLE);
+ }
+
+ @Override
+ public String toString() {
+ return "AccountSubscriptionGroupImpl [artifact=" + artifact + "]";
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/OrcsSubscriptionStorage.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/OrcsSubscriptionStorage.java
new file mode 100644
index 00000000000..0da96c2f02b
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/OrcsSubscriptionStorage.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * 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.orcs.account.admin.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.admin.ds.SubscriptionStorage;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.type.ResultSets;
+import org.eclipse.osee.orcs.account.admin.internal.SubscriptionUtil.ActiveDelegate;
+import org.eclipse.osee.orcs.data.ArtifactId;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.transaction.TransactionBuilder;
+import org.eclipse.osee.orcs.utility.OrcsUtil;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OrcsSubscriptionStorage extends AbstractOrcsStorage implements SubscriptionStorage {
+
+ @Override
+ public ResultSet<Subscription> getSubscriptionsByAccountLocalId(long accountId) {
+ int intAccountId = Long.valueOf(accountId).intValue();
+ ResultSet<ArtifactReadable> accountResults =
+ newQuery().andIsOfType(CoreArtifactTypes.User).andLocalId(intAccountId).getResults();
+ ArtifactReadable account = accountResults.getExactlyOne();
+
+ ResultSet<ArtifactReadable> allGroups = newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).getResults();
+ List<Subscription> subscriptions = new ArrayList<Subscription>();
+ for (ArtifactReadable group : allGroups) {
+ boolean related = account.areRelated(CoreRelationTypes.Users_Artifact, group);
+ subscriptions.add(SubscriptionUtil.fromArtifactData(account, group, related));
+ }
+ return ResultSets.newResultSet(subscriptions);
+ }
+
+ @Override
+ public void updateSubscription(long accountId, long groupId, boolean activate) {
+ int intAccountId = Long.valueOf(accountId).intValue();
+ int intGroupId = Long.valueOf(groupId).intValue();
+
+ ArtifactReadable account = newQuery().andLocalId(intAccountId).getResults().getExactlyOne();
+ ArtifactReadable group =
+ newQuery().andLocalId(intGroupId).andIsOfType(CoreArtifactTypes.SubscriptionGroup).getResults().getExactlyOne();
+
+ String txComment =
+ String.format("%s user [%s] to [%s].", activate ? "Subscribe" : "Unsubscribe", account.getName(),
+ group.getName());
+ TransactionBuilder tx = newTransaction(txComment);
+ // relate/unrelate (Side_A Art) <- Users -> (Side_B Art)
+ if (activate) {
+ tx.relate(group, CoreRelationTypes.Users_Artifact, account);
+ } else {
+ tx.unrelate(group, CoreRelationTypes.Users_Artifact, account);
+ }
+ tx.commit();
+ }
+
+ @Override
+ public Subscription getSubscription(String subscriptionUuid) {
+ return SubscriptionUtil.fromEncodedUuid(subscriptionUuid, new LazyActiveDelegate());
+ }
+
+ private class LazyActiveDelegate implements ActiveDelegate {
+
+ private final AtomicBoolean wasRun = new AtomicBoolean(false);
+ private volatile boolean isActive;
+
+ @Override
+ public boolean isActive(long accountId, long groupId) {
+ if (wasRun.compareAndSet(false, true)) {
+ int intAccountId = Long.valueOf(accountId).intValue();
+ int intGroupId = Long.valueOf(groupId).intValue();
+
+ ArtifactReadable account = newQuery().andLocalId(intAccountId).getResults().getExactlyOne();
+ ArtifactReadable group = newQuery().andLocalId(intGroupId).getResults().getExactlyOne();
+ isActive = account.areRelated(CoreRelationTypes.Users_Artifact, group);
+ }
+ return isActive;
+ }
+ }
+
+ @Override
+ public ResultSet<SubscriptionGroup> getSubscriptionGroups() {
+ ResultSet<ArtifactReadable> results = newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).getResults();
+ return getFactory().newAccountSubscriptionGroupResultSet(results);
+ }
+
+ @Override
+ public ResultSet<SubscriptionGroup> getSubscriptionGroupByLocalId(long groupId) {
+ int intGroupId = Long.valueOf(groupId).intValue();
+ ResultSet<ArtifactReadable> results =
+ newQuery().andLocalId(intGroupId).andIsOfType(CoreArtifactTypes.SubscriptionGroup).getResults();
+ return getFactory().newAccountSubscriptionGroupResultSet(results);
+ }
+
+ @Override
+ public ResultSet<SubscriptionGroup> getSubscriptionGroupByName(String name) {
+ ResultSet<ArtifactReadable> results =
+ newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).andNameEquals(name).getResults();
+ return getFactory().newAccountSubscriptionGroupResultSet(results);
+ }
+
+ @Override
+ public ResultSet<SubscriptionGroup> getSubscriptionGroupByUuid(String uuid) {
+ ResultSet<ArtifactReadable> results =
+ newQuery().andGuid(uuid).andIsOfType(CoreArtifactTypes.SubscriptionGroup).getResults();
+ return getFactory().newAccountSubscriptionGroupResultSet(results);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public SubscriptionGroup createSubscriptionGroup(String name) {
+ String comment = String.format("Create subscription group [%s]", name);
+
+ TransactionBuilder tx = newTransaction(comment);
+ ArtifactId artId = tx.createArtifact(CoreArtifactTypes.SubscriptionGroup, name);
+ tx.commit();
+
+ ArtifactReadable groupArt = newQuery().andIds(artId).getResults().getExactlyOne();
+ return getFactory().newAccountSubscriptionGroup(groupArt);
+ }
+
+ @Override
+ public void deleteSubscriptionGroup(SubscriptionGroup group) {
+ ArtifactId artId = OrcsUtil.newArtifactId(group.getGuid(), group.getName());
+
+ String comment = String.format("Delete subscription group [%s]", group.getName());
+ TransactionBuilder tx = newTransaction(comment);
+ tx.deleteArtifact(artId);
+ tx.commit();
+ }
+
+ @Override
+ public ResultSet<Account> getSubscriptionGroupMembersByLocalId(long groupId) {
+ int intGroupId = Long.valueOf(groupId).intValue();
+ ResultSet<ArtifactReadable> results =
+ newQuery().andIsOfType(CoreArtifactTypes.User).andRelatedToLocalIds(CoreRelationTypes.Users_Artifact,
+ intGroupId).getResults();
+ return getFactory().newAccountResultSet(results);
+ }
+
+ @Override
+ public ResultSet<Account> getSubscriptionGroupMembersByName(String name) {
+ ResultSet<ArtifactReadable> results =
+ newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).andNameEquals(name).getResults();
+ ArtifactReadable group = results.getOneOrNull();
+ return getMembers(group);
+ }
+
+ @Override
+ public ResultSet<Account> getSubscriptionGroupMembersByUuid(String uuid) {
+ ResultSet<ArtifactReadable> results =
+ newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).andGuid(uuid).getResults();
+ ArtifactReadable group = results.getOneOrNull();
+ return getMembers(group);
+ }
+
+ private ResultSet<Account> getMembers(ArtifactReadable group) {
+ ResultSet<Account> toReturn;
+ if (group != null) {
+ ResultSet<ArtifactReadable> related = group.getRelated(CoreRelationTypes.Users_User);
+ toReturn = getFactory().newAccountResultSet(related);
+ } else {
+ toReturn = ResultSets.emptyResultSet();
+ }
+ return toReturn;
+ }
+
+ @Override
+ public boolean subscriptionGroupNameExists(String groupName) {
+ int count = newQuery().andIsOfType(CoreArtifactTypes.SubscriptionGroup).andNameEquals(groupName).getCount();
+ return count > 0;
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtil.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtil.java
new file mode 100644
index 00000000000..e0df4c30bed
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtil.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.orcs.account.admin.internal;
+
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.framework.jdk.core.type.NamedIdentity;
+import org.eclipse.osee.framework.jdk.core.util.EncryptUtility;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SubscriptionUtil {
+
+ private static final String SUBSCRIPTION_SECRET = "lRL2uka3CwLL88Q1";
+
+ public static interface ActiveDelegate {
+
+ boolean isActive(long accountId, long groupId);
+ }
+
+ public static String toEncodedUuid(long accountId, String accountDisplayName, long groupId, String subscriptionName) {
+ String rawData = String.format("%s:%s:%s:%s", accountId, accountDisplayName, groupId, subscriptionName);
+ return EncryptUtility.encrypt(rawData, SUBSCRIPTION_SECRET);
+ }
+
+ public static Subscription fromEncodedUuid(String subscriptionUuid, ActiveDelegate delegate) {
+ String decrypted = EncryptUtility.decrypt(subscriptionUuid, SUBSCRIPTION_SECRET);
+ String[] data = decrypted.split(":");
+ int index = 0;
+ int accountId = Integer.parseInt(data[index++]);
+ String accountDisplayName = data[index++];
+ int groupId = Integer.parseInt(data[index++]);
+ String subscriptionName = data[index++];
+ return new DelegatingActiveSubscriptionImpl(subscriptionUuid, accountId, accountDisplayName, groupId,
+ subscriptionName, delegate);
+ }
+
+ public static Subscription fromData(long accountId, String accountDisplayName, long groupId, String subscriptionName, boolean isActive) {
+ String encodedUuid = toEncodedUuid(accountId, accountDisplayName, groupId, subscriptionName);
+ return new SubscriptionImpl(encodedUuid, accountId, accountDisplayName, groupId, subscriptionName, isActive);
+ }
+
+ public static Subscription fromArtifactData(ArtifactReadable account, ArtifactReadable subscription, boolean isActive) {
+ int accountId = account.getLocalId();
+ String accountName = account.getName();
+ int groupId = subscription.getLocalId();
+ String subscriptionName = subscription.getName();
+ return fromData(accountId, accountName, groupId, subscriptionName, isActive);
+ }
+
+ private static final class DelegatingActiveSubscriptionImpl extends SubscriptionImpl {
+
+ private final ActiveDelegate provider;
+
+ private DelegatingActiveSubscriptionImpl(String encodedUuid, long accountId, String accountDisplayName, long groupId, String subscriptionName, ActiveDelegate provider) {
+ super(encodedUuid, accountId, accountDisplayName, groupId, subscriptionName, false);
+ this.provider = provider;
+ }
+
+ @Override
+ public boolean isActive() {
+ return provider.isActive(getAccountId(), getGroupId());
+ }
+ }
+
+ private static class SubscriptionImpl extends NamedIdentity<String> implements Subscription {
+
+ private final long accountId;
+ private final String accountDisplayName;
+ private final long groupId;
+ private final boolean active;
+
+ private SubscriptionImpl(String encodedUuid, long accountId, String accountDisplayName, long groupId, String subscriptionName, boolean active) {
+ super(encodedUuid, subscriptionName);
+ this.accountId = accountId;
+ this.accountDisplayName = accountDisplayName;
+ this.groupId = groupId;
+ this.active = active;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public String getAccountName() {
+ return accountDisplayName;
+ }
+
+ @Override
+ public long getGroupId() {
+ return groupId;
+ }
+
+ @Override
+ public boolean isActive() {
+ return active;
+ }
+
+ @Override
+ public String toString() {
+ return "SubscriptionImpl [accountId=" + accountId + ", accountDisplayName=" + accountDisplayName + ", groupId=" + groupId + ", active=" + isActive() + "]";
+ }
+
+ }
+} \ No newline at end of file

Back to the top