@Test public void testProcessDataArtifactTypeMatch() throws OseeCoreException { IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child; IArtifactType artifactType = CoreArtifactTypes.AbstractSoftwareRequirement; XArtifactType artifactTypeRef = MockModel.createXArtifactType(artifactType.getGuid(), artifactType.getName()); RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction(); restriction.setPermission(AccessPermissionEnum.ALLOW); restriction.setRelationTypeMatch(true); RelationTypeArtifactTypePredicate predicate = OseeDslFactory.eINSTANCE.createRelationTypeArtifactTypePredicate(); predicate.setArtifactTypeRef(artifactTypeRef); restriction.setPredicate(predicate); restriction.setRestrictedToSide(XRelationSideEnum.SIDE_B); RelationType testRelationType = getTestRelationType( relationType, CoreArtifactTypes.SoftwareRequirement, CoreArtifactTypes.Artifact); IArtifactType artTypeToken1 = CoreArtifactTypes.SoftwareRequirement; ArtifactType artArtType = new ArtifactType(artTypeToken1.getGuid(), artTypeToken1.getName(), false); Set<ArtifactType> superTypes = new HashSet<>(); superTypes.add( new ArtifactType( CoreArtifactTypes.AbstractSoftwareRequirement.getGuid(), CoreArtifactTypes.AbstractSoftwareRequirement.getName(), false)); artArtType.setSuperTypes(superTypes); DefaultBasicArtifact expectedAccessObject = new DefaultBasicArtifact(1, GUID.create(), "Another Artifact"); MockArtifactProxy artData = new MockArtifactProxy( expectedAccessObject.getGuid(), artArtType, expectedAccessObject, null, Collections.singleton(testRelationType)); RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_B); Scope expectedScope = new Scope(); expectedScope.addSubPath(artData.getName()); DslAsserts.assertAccessDetail( getRestrictionHandler(), restriction, artData, expectedObject, PermissionEnum.WRITE, expectedScope); }
private void processContext( AccessDetailCollector collector, AccessContext context, ArtifactProxy artifactData, Scope scope) throws OseeCoreException { collectRestrictions(collector, artifactData, context.getAccessRules(), scope); Collection<HierarchyRestriction> restrictions = context.getHierarchyRestrictions(); Collection<ArtifactProxy> proxyHierarchy = artifactData.getHierarchy(); for (HierarchyRestriction hierarchy : restrictions) { XArtifactMatcher artifactRef = hierarchy.getArtifactMatcherRef(); if (matcher.matches(artifactRef, proxyHierarchy)) { String tag = String.format("childOf-%s", artifactRef.getName()); Scope child = scope.clone().addSubPath(tag); collectRestrictions(collector, artifactData, hierarchy.getAccessRules(), child); } } }
private void scopeHelper(Scope scope, AccessContext context) { for (AccessContext parent : context.getSuperAccessContexts()) { scopeHelper(scope, parent); } scope.add(context.getName()); }