Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2012-04-16 22:31:29 +0000
committerRoberto E. Escobar2012-04-16 22:31:29 +0000
commit847a5f98d0a3d92092e08b2963c6464e765f7fd5 (patch)
tree91530fd2f08942a795599b67f55c30757429feae /plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org
parentbfb28b4528c2e3be64849f219c4a18a4679cf444 (diff)
downloadorg.eclipse.osee-847a5f98d0a3d92092e08b2963c6464e765f7fd5.tar.gz
org.eclipse.osee-847a5f98d0a3d92092e08b2963c6464e765f7fd5.tar.xz
org.eclipse.osee-847a5f98d0a3d92092e08b2963c6464e765f7fd5.zip
feature[ats_VDYBJ]: Add OseeDslRoleContextProvider
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org')
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java63
-rw-r--r--plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeDslRoleContextProvider.java139
2 files changed, 202 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java
new file mode 100644
index 00000000000..45dc5b04521
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/AbstractOseeDslProvider.java
@@ -0,0 +1,63 @@
+package org.eclipse.osee.framework.core.dsl.ui.integration.operations;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.eclipse.osee.framework.core.dsl.integration.OseeDslProvider;
+import org.eclipse.osee.framework.core.dsl.integration.util.ModelUtil;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.operation.IOperation;
+import org.eclipse.osee.framework.core.operation.Operations;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class AbstractOseeDslProvider implements OseeDslProvider {
+
+ private OseeDsl oseeDsl;
+ private final String locationUri;
+
+ protected AbstractOseeDslProvider(String locationUri) {
+ this.locationUri = locationUri;
+ }
+
+ protected abstract String getModelFromStorage() throws OseeCoreException;
+
+ protected abstract void saveModelToStorage(String model) throws OseeCoreException;
+
+ @Override
+ public void loadDsl() throws OseeCoreException {
+ String accessModel = getModelFromStorage();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ IOperation operation = new OseeTypesExportOperation(outputStream);
+ Operations.executeWorkAndCheckStatus(operation);
+ try {
+ outputStream.write(accessModel.getBytes("utf-8"));
+ oseeDsl = ModelUtil.loadModel(locationUri, outputStream.toString("utf-8"));
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+
+ @Override
+ public OseeDsl getDsl() throws OseeCoreException {
+ if (oseeDsl == null) {
+ loadDsl();
+ }
+ return oseeDsl;
+ }
+
+ @Override
+ public void storeDsl(OseeDsl dsl) throws OseeCoreException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ ModelUtil.saveModel(dsl, locationUri, outputStream, false);
+ saveModelToStorage(outputStream.toString("UTF-8"));
+ loadDsl();
+ } catch (IOException ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeDslRoleContextProvider.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeDslRoleContextProvider.java
new file mode 100644
index 00000000000..032d77ea9e6
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeDslRoleContextProvider.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.framework.core.dsl.ui.integration.operations;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.osee.framework.core.data.IAccessContextId;
+import org.eclipse.osee.framework.core.data.TokenFactory;
+import org.eclipse.osee.framework.core.dsl.integration.OseeDslProvider;
+import org.eclipse.osee.framework.core.dsl.integration.RoleContextProvider;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessContext;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.ReferencedContext;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.Role;
+import org.eclipse.osee.framework.core.dsl.oseeDsl.UsersAndGroups;
+import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.IBasicArtifact;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+
+/**
+ * @author John Misinco
+ */
+public class OseeDslRoleContextProvider implements RoleContextProvider {
+
+ private final OseeDslProvider dslProvider;
+
+ public OseeDslRoleContextProvider(OseeDslProvider dslProvider) {
+ this.dslProvider = dslProvider;
+ }
+
+ @Override
+ public Collection<? extends IAccessContextId> getContextId(IBasicArtifact<?> user) {
+ OseeDsl dsl = null;
+ try {
+ dsl = dslProvider.getDsl();
+ } catch (OseeCoreException ex) {
+ OseeLog.log(OseeDslRoleContextProvider.class, Level.WARNING, Lib.exceptionToString(ex));
+ return Collections.emptyList();
+ }
+
+ Collection<IAccessContextId> toReturn = Collections.emptyList();
+ EList<Role> roleDeclarations = dsl.getRoleDeclarations();
+
+ if (!roleDeclarations.isEmpty()) {
+
+ //find which roles have the relevant guids
+ List<String> applicableGuids;
+ try {
+ applicableGuids = getApplicableGuids((Artifact) user.getFullArtifact());
+ } catch (OseeCoreException ex) {
+ OseeLog.log(OseeDslRoleContextProvider.class, Level.SEVERE, Lib.exceptionToString(ex));
+ return Collections.emptyList();
+ }
+
+ //now go through roles and roll up the inherited roles
+ Set<Role> applicableRoles = getApplicableRoles(dsl.getRoleDeclarations(), applicableGuids);
+
+ if (!applicableRoles.isEmpty()) {
+ Map<String, String> accessContextMap = new HashMap<String, String>();
+ for (AccessContext ac : dsl.getAccessDeclarations()) {
+ accessContextMap.put(ac.getName(), ac.getGuid());
+ }
+
+ //now get the context id's
+ toReturn = new HashSet<IAccessContextId>();
+ for (Role role : applicableRoles) {
+ for (ReferencedContext ref : role.getReferencedContexts()) {
+ String contextName = ref.getAccessContextRef();
+ toReturn.add(TokenFactory.createAccessContextId(accessContextMap.get(contextName), contextName));
+ }
+ }
+ }
+ }
+ return toReturn;
+ }
+
+ private Set<Role> getApplicableRoles(List<Role> roles, List<String> applicableGuids) {
+ Queue<Role> applicableRoles = new LinkedList<Role>();
+ for (Role role : roles) {
+ for (UsersAndGroups uag : role.getUsersAndGroups()) {
+ if (applicableGuids.contains(uag.getUserOrGroupGuid()) && !applicableRoles.contains(role)) {
+ applicableRoles.add(role);
+ break;
+ }
+ }
+ }
+
+ Set<Role> includesInherited = new HashSet<Role>();
+ getSuperRoles(includesInherited, applicableRoles);
+ return includesInherited;
+ }
+
+ private List<String> getApplicableGuids(Artifact user) {
+ List<String> applicableGuids = new LinkedList<String>();
+ List<Artifact> groups = Collections.emptyList();
+
+ try {
+ groups = user.getRelatedArtifacts(CoreRelationTypes.Users_Artifact);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(OseeDslRoleContextProvider.class, Level.SEVERE, Lib.exceptionToString(ex));
+ }
+
+ String userGuid = user.getGuid();
+ applicableGuids.add(userGuid);
+ for (Artifact group : groups) {
+ applicableGuids.add(group.getGuid());
+ }
+ return applicableGuids;
+ }
+
+ private void getSuperRoles(Set<Role> visited, Queue<Role> toVisit) {
+ if (!toVisit.isEmpty()) {
+ Role role = toVisit.remove();
+ visited.add(role);
+ toVisit.addAll(role.getSuperRoles());
+ getSuperRoles(visited, toVisit);
+ }
+ }
+}

Back to the top