@Test
  public void testProcessDataRelationTypeMatchSideANoMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);
    restriction.setRestrictedToSide(XRelationSideEnum.SIDE_A);

    RelationType testRelationType =
        getTestRelationType(
            relationType, CoreArtifactTypes.Artifact, CoreArtifactTypes.SoftwareRequirement);

    IArtifactType artTypeToken1 = CoreArtifactTypes.SoftwareRequirement;
    ArtifactType artArtType =
        new ArtifactType(artTypeToken1.getGuid(), artTypeToken1.getName(), false);

    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, null, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_A);
    Scope expectedScope = new Scope();
    DslAsserts.assertAccessDetail(
        getRestrictionHandler(),
        restriction,
        artData,
        expectedObject,
        PermissionEnum.WRITE,
        expectedScope);
  }
示例#2
0
  @Test
  public void testCopyArtifact() throws OseeCoreException {
    String guid = GUID.create();

    ArtifactData data = Mockito.mock(ArtifactData.class);
    VersionData version = Mockito.mock(VersionData.class);
    when(data.getVersion()).thenReturn(version);
    when(version.getBranchId()).thenReturn(111L);

    Artifact sourceArtifact = Mockito.spy(new ArtifactImpl(null, data, null, provider));

    when(data.getGuid()).thenReturn(guid);

    List<? extends IAttributeType> copyTypes =
        Arrays.asList(CoreAttributeTypes.Active, CoreAttributeTypes.Name);
    when(sourceArtifact.getExistingAttributeTypes()).thenAnswer(answerValue(copyTypes));

    when(artifact2.getOrcsData()).thenReturn(data);
    when(data.isUseBackingData()).thenReturn(false);

    when(txData.isCommitInProgress()).thenReturn(false);
    when(txData.getTxState()).thenReturn(TxState.NEW_TX);
    when(txData.getWriteable(sourceArtifact)).thenReturn(null);
    when(artifactFactory.copyArtifact(session, sourceArtifact, copyTypes, branch))
        .thenReturn(artifact2);
    when(proxyManager.asExternalArtifact(session, artifact2)).thenReturn(readable2);

    ArtifactReadable actual = txDataManager.copyArtifact(txData, branch, sourceArtifact);

    verify(txData).getWriteable(sourceArtifact);
    verify(artifactFactory).copyArtifact(session, sourceArtifact, copyTypes, branch);

    assertEquals(readable2, actual);
  }
  private void testProcessRelationWithArtifactHelper(
      String artifactName, String matcherArtifactName, Scope expectedScope)
      throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);
    restriction.setRestrictedToSide(XRelationSideEnum.SIDE_B);

    XArtifactMatcher matcher =
        MockModel.createMatcher(
            "artifactMatcher \"Test\" where artifactName EQ \"" + matcherArtifactName + "\";");

    RelationTypeArtifactPredicate predicate =
        OseeDslFactory.eINSTANCE.createRelationTypeArtifactPredicate();
    predicate.setArtifactMatcherRef(matcher);
    restriction.setPredicate(predicate);

    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.Artifact.getGuid(), CoreArtifactTypes.Artifact.getName(), false));
    artArtType.setSuperTypes(superTypes);

    IBasicArtifact<Object> dummy = new DefaultBasicArtifact(43, GUID.create(), artifactName);
    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, dummy, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject = new RelationTypeSide(testRelationType, RelationSide.SIDE_B);
    DslAsserts.assertAccessDetail(
        getRestrictionHandler(),
        restriction,
        artData,
        expectedObject,
        PermissionEnum.WRITE,
        expectedScope);
  }
示例#4
0
  @Override
  protected void restoreWidgetValues() {
    super.restoreWidgetValues();
    IDialogSettings settings = getDialogSettings();
    if (settings != null) {
      if (getDefaultSourceFile() == null) {
        directoryFileSelector.setDirectorySelected(settings.getBoolean("isDirectory"));
        String file = settings.get("source.file");
        if (Strings.isValid(file)) {
          directoryFileSelector.setText(file);
        }
      }

      String parser = settings.get("selected.parser");
      if (Strings.isValid(parser)) {
        for (IArtifactExtractor item : importContributionManager.getExtractors()) {
          if (parser.equals(item.getClass().getSimpleName())) {
            parserSelectPanel.setArtifactExtractor(item);
          }
        }
      }
      if (getDefaultDestinationArtifact() == null) {
        String guid = settings.get("destination.artifact.guid");
        String branchUuidStr = settings.get("destination.branch.uuid");

        if (GUID.isValid(guid) && Strings.isNumeric(branchUuidStr)) {
          try {
            Long bramchUuid = Long.valueOf(branchUuidStr);
            Artifact artifact =
                ArtifactQuery.getArtifactFromId(guid, BranchManager.getBranchByUuid(bramchUuid));
            artifactSelectPanel.setDefaultItem(artifact);
          } catch (OseeCoreException ex) {
            OseeLog.logf(
                Activator.class,
                Level.SEVERE,
                "Unable to restore destination artifact- guid:[%s] branch uuid:[%d]",
                guid,
                branchUuidStr);
          }
        }
      }

      boolean toUpdate = settings.getBoolean("is.update.existing.selected");
      updateExistingArtifacts.setSelection(toUpdate);
      deleteUnmatchedArtifacts.setEnabled(toUpdate);
      if (toUpdate) {
        try {
          ArtifactType artType = ArtifactTypeManager.getType(getArtifactType());
          attributeTypeSelectPanel.setAllowedAttributeTypes(
              artType.getAttributeTypes(getDestinationArtifact().getFullBranch()));
        } catch (OseeCoreException ex) {
          OseeLog.log(Activator.class, Level.SEVERE, ex);
        }
      } else {
        attributeTypeSelectPanel.setAllowedAttributeTypes(new ArrayList<IAttributeType>());
      }
    }
  }
  @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);
  }
示例#6
0
  @Before
  public void init() throws OseeCoreException {
    MockitoAnnotations.initMocks(this);
    txDataManager = new TxDataManager(proxyManager, artifactFactory, relationManager, loader);

    guid = GUID.create();

    when(artifact1.getExistingAttributeTypes()).thenAnswer(answerValue(types));

    when(proxyManager.asInternalArtifact(readable1)).thenReturn(artifact1);
    when(proxyManager.asExternalArtifact(session, artifact1)).thenReturn(readable1);

    when(branch.getUuid()).thenReturn(111L);
    when(provider.getBranch(111L)).thenReturn(branch);

    when(txData.getSession()).thenReturn(session);
    when(txData.getBranch()).thenReturn(branch);
    when(txData.getGraph()).thenReturn(graph);

    r1Guid = GUID.create();
    r2Guid = GUID.create();
    r3Guid = GUID.create();

    when(artifactId1.getGuid()).thenReturn(r1Guid);
    when(artifactId2.getGuid()).thenReturn(r2Guid);
    when(artifactId3.getGuid()).thenReturn(r3Guid);

    when(readable1.getGuid()).thenReturn(r1Guid);
    when(readable2.getGuid()).thenReturn(r2Guid);
    when(readable3.getGuid()).thenReturn(r3Guid);

    when(readable1.getBranch()).thenReturn(branch);
    when(readable2.getBranch()).thenReturn(branch);
    when(readable3.getBranch()).thenReturn(branch);

    when(artifact1.getGuid()).thenReturn(r1Guid);
    when(artifact2.getGuid()).thenReturn(r2Guid);
    when(artifact3.getGuid()).thenReturn(r3Guid);

    when(artifact1.getBranch()).thenReturn(branch);
    when(artifact2.getBranch()).thenReturn(branch);
    when(artifact3.getBranch()).thenReturn(branch);
  }
  @Test(expected = OseeArgumentException.class)
  public void testHandleNonId() throws OseeCoreException {
    IdsPredicateHandler handler = new IdsPredicateHandler();
    // no type params, op, or flags for ids - any passed are ignored

    // all digits get treated as artId
    String id1 = GUID.create();
    List<String> values = Collections.singletonList(id1);
    Predicate testPredicate = new Predicate(SearchMethod.IDS, null, null, null, null, values);
    handler.handle(builder, testPredicate);
  }
  @Test
  public void testProcessDataRelationTypeMatchBothMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);
    restriction.setRestrictedToSide(XRelationSideEnum.BOTH);

    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.Artifact.getGuid(), CoreArtifactTypes.Artifact.getName(), false));
    artArtType.setSuperTypes(superTypes);

    MockArtifactProxy artData =
        new MockArtifactProxy(
            GUID.create(), artArtType, null, null, Collections.singleton(testRelationType));
    RelationTypeSide expectedObject1 = new RelationTypeSide(testRelationType, RelationSide.SIDE_A);
    RelationTypeSide expectedObject2 = new RelationTypeSide(testRelationType, RelationSide.SIDE_B);

    final List<AccessDetail<?>> actualAccesses = new ArrayList<>();
    AccessDetailCollector collector =
        new AccessDetailCollector() {

          @Override
          public void collect(AccessDetail<?> accessDetail) {
            Assert.assertNotNull(accessDetail);
            actualAccesses.add(accessDetail);
          }
        };

    Scope expectedScope = new Scope();
    getRestrictionHandler().process(restriction, artData, collector, expectedScope);

    AccessDetail<?> actualAccess = actualAccesses.get(0);
    Assert.assertEquals(actualAccess.getPermission(), PermissionEnum.WRITE);
    Assert.assertEquals(expectedObject1, actualAccess.getAccessObject());

    actualAccess = actualAccesses.get(1);
    Assert.assertEquals(actualAccess.getPermission(), PermissionEnum.WRITE);
    Assert.assertEquals(expectedObject2, actualAccess.getAccessObject());
  }
  @Test
  public void testProcessDataRelationTypeNoMatch() throws OseeCoreException {
    IRelationType relationType = CoreRelationTypes.Default_Hierarchical__Child;
    XRelationType relationTypeRef =
        MockModel.createXRelationType(relationType.getGuid(), relationType.getName());

    RelationTypeRestriction restriction = MockModel.createRelationTypeRestriction();
    restriction.setPermission(AccessPermissionEnum.ALLOW);
    restriction.setRelationTypeRef(relationTypeRef);

    // Artifact Data has no relation types therefore relation type will not match
    MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), null);
    Scope expectedScope = new Scope().add("fail");
    DslAsserts.assertNullAccessDetail(getRestrictionHandler(), restriction, artData, expectedScope);
  }
示例#10
0
  @Before
  public void setup() {
    branchToCheck1 = CoreBranches.SYSTEM_ROOT;
    branchToCheck2 = CoreBranches.COMMON;

    artifactType = CoreArtifactTypes.AbstractSoftwareRequirement;
    attributeType = CoreAttributeTypes.ParagraphNumber;
    wordAttributeType = CoreAttributeTypes.WordTemplateContent;

    RelationType relType = MockDataFactory.createRelationType(2, null, null);
    relTypeSide1 = new RelationTypeSide(relType, RelationSide.SIDE_A);
    relTypeSide2 = new RelationTypeSide(relType, RelationSide.SIDE_B);

    artifactToCheck = new DefaultBasicArtifact(12, GUID.create(), "Hello");
  }
示例#11
0
  @Override
  public ArtifactData create(IOseeBranch branch, IArtifactType token, String guid, long uuid)
      throws OseeCoreException {
    Conditions.checkNotNull(branch, "branch");

    Conditions.checkExpressionFailOnTrue(
        artifactCache.isAbstract(token), "Cannot create an instance of abstract type [%s]", token);

    String guidToSet = idFactory.getUniqueGuid(guid);

    Conditions.checkExpressionFailOnTrue(
        !GUID.isValid(guidToSet),
        "Invalid guid [%s] during artifact creation [type: %s]",
        guidToSet,
        token);

    VersionData version = objectFactory.createDefaultVersionData();
    version.setBranchId(branch.getUuid());

    ModificationType modType = RelationalConstants.DEFAULT_MODIFICATION_TYPE;
    ArtifactData artifactData =
        objectFactory.createArtifactData(version, (int) uuid, token, modType, guidToSet);
    return artifactData;
  }