Example #1
0
  @Override
  public void visit(MetadataElement element) {
    if (!checkContext(METADATA)) return;

    CommentSets comments = element.getComments();
    insertComments(this.context, comments.getElementCommentSet());
  }
Example #2
0
  @Override
  public void visit(ConditionElement element) {
    if (!checkContext(CONDITION)) return;

    CommentSets comments = element.getComments();
    insertComments(this.context, comments.getElementCommentSet());
  }
Example #3
0
  @Override
  public void visit(MaskElement element) {
    if (!checkContext(MASK)) return;

    CommentSets comments = element.getComments();
    insertComments(this.context, comments.getElementCommentSet());
  }
Example #4
0
  @Override
  public void visit(SourceElement element) {
    if (!checkContext(SOURCE)) return;

    if (!nameAttribute(element.getName())) return;

    CommentSets comments = element.getComments();
    insertComments(this.context, comments.getElementCommentSet());
  }
Example #5
0
  @Override
  public void visit(ImportVdbElement element) {
    if (!checkContext(IMPORT_VDB)) return;

    if (!nameAttribute(element.getName())) return;

    CommentSets comments = element.getComments();
    insertComments(this.context, comments.getElementCommentSet());
  }
Example #6
0
  @Override
  public void visit(VdbElement vdbElement) {
    if (!checkContext(VDB)) return;

    CommentSets commentSets = vdbElement.getComments();
    List<String> comments = commentSets.getElementCommentSet();
    insertComments(this.context, comments);

    Node vdbContext = this.context;
    this.context = vdbContext.getFirstChild();
    while (this.context != null) {
      if (checkContext(DESCRIPTION) || checkContext(CONNECTION_TYPE)) {
        comments = commentSets.getCommentSet(DESCRIPTION);
        insertComments(this.context, comments);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(PROPERTY)) {
        for (PropertyElement pe : vdbElement.getProperties()) pe.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(IMPORT_VDB)) {
        for (ImportVdbElement ive : vdbElement.getImportVdbEntries()) ive.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(MODEL)) {
        for (ModelElement me : vdbElement.getModels()) me.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(TRANSLATOR)) {
        for (TranslatorElement te : vdbElement.getTranslators()) te.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(DATA_ROLE)) {
        for (DataRoleElement dre : vdbElement.getDataPolicies()) dre.accept(this);
      }

      this.context = this.context.getNextSibling();
    }

    this.context = vdbContext;
  }
Example #7
0
  @Override
  public void visit(ModelElement modelElement) {
    if (!checkContext(MODEL)) return;

    if (!nameAttribute(modelElement.getName())) return;

    CommentSets commentSets = modelElement.getComments();
    List<String> comments = commentSets.getElementCommentSet();
    insertComments(this.context, comments);

    Node modelContext = this.context;
    this.context = modelContext.getFirstChild();
    while (this.context != null) {

      if (checkContext(DESCRIPTION)) {
        comments = commentSets.getCommentSet(DESCRIPTION);
        insertComments(this.context, comments);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(PROPERTY)) {
        for (PropertyElement pe : modelElement.getProperties()) pe.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(SOURCE)) {
        for (SourceElement se : modelElement.getSources()) se.accept(this);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(METADATA)) {
        for (MetadataElement me : modelElement.getMetadata()) me.accept(this);
      }

      this.context = this.context.getNextSibling();
    }

    this.context = modelContext;
  }
Example #8
0
  @Override
  public void visit(DataRoleElement drElement) {
    if (!checkContext(DATA_ROLE)) return;

    if (!nameAttribute(drElement.getName())) return;

    CommentSets commentSets = drElement.getComments();
    List<String> comments = commentSets.getElementCommentSet();
    insertComments(this.context, comments);

    Node drContext = this.context;
    this.context = drContext.getFirstChild();
    while (this.context != null) {

      if (checkContext(DESCRIPTION)) {
        comments = commentSets.getCommentSet(DESCRIPTION);
        insertComments(this.context, comments);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(MAPPED_ROLE_NAME)) {
        comments =
            commentSets.getCommentSet(MAPPED_ROLE_NAME + HYPHEN + this.context.getTextContent());
        insertComments(this.context, comments);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(PERMISSION)) {
        for (PermissionElement pe : drElement.getPermissions()) pe.accept(this);
      }

      this.context = this.context.getNextSibling();
    }

    this.context = drContext;
  }
Example #9
0
  @Override
  public void visit(TranslatorElement trElement) {
    if (!checkContext(TRANSLATOR)) return;

    if (!nameAttribute(trElement.getName())) return;

    CommentSets comments = trElement.getComments();
    insertComments(this.context, comments.getElementCommentSet());

    Node trContext = this.context;
    this.context = trContext.getFirstChild();
    while (this.context != null) {

      if (checkContext(PROPERTY)) {
        for (PropertyElement pe : trElement.getProperties()) pe.accept(this);
      }

      this.context = this.context.getNextSibling();
    }

    this.context = trContext;
  }
  @Test
  public void testCommentsInDynamicVdb() throws Exception {
    MockFileBuilder portfolioXmlFile = VdbTestUtils.mockPortfolioVdbXmlFile();
    DynamicVdb vdb = new DynamicVdb(portfolioXmlFile.getResourceFile());

    CommentSets vdbComments = vdb.getComments();
    assertNotNull(vdbComments);
    assertEquals(2, vdbComments.size());
    checkComment(Comments.VDB_TITLE, vdbComments, EMPTY_STRING, 0);
    checkComment(Comments.VDB_TITLE_2, vdbComments, EMPTY_STRING, 1);
    checkComment(Comments.VDB_DESCRIPTION, vdbComments, DESCRIPTION, 0);

    CommentSets propertyComments = vdb.getPropertyComments("UseConnectorMetadata");
    assertNotNull(propertyComments);

    checkComment(Comments.USE_CONNECTOR_PROPERTY, propertyComments, EMPTY_STRING, 0);

    DynamicModel model = findModel(vdb.getDynamicModels(), "MarketData");
    checkComment(Comments.MODEL_MARKETDATA, model.getComments(), EMPTY_STRING, 0);

    VdbSource source = model.getSources()[0];
    assertEquals("text-connector", source.getName());
    checkComment(Comments.MARKETDATA_TEXT_CONNECTOR, source.getComments(), EMPTY_STRING, 0);

    model = findModel(vdb.getDynamicModels(), "Accounts");
    propertyComments = model.getPropertyComments("importer.useFullSchemaName");
    assertNotNull(propertyComments);
    checkComment(Comments.ACCOUNTS_USEFULLSCHEMA_PROPERTY, propertyComments, EMPTY_STRING, 0);

    source = model.getSources()[0];
    assertEquals("h2-connector", source.getName());
    checkComment(Comments.ACCOUNT_H2_CONNECTOR, source.getComments(), EMPTY_STRING, 0);

    model = findModel(vdb.getDynamicModels(), "PersonalValuations");
    propertyComments = model.getPropertyComments("importer.headerRowNumber");
    assertNotNull(propertyComments);
    checkComment(Comments.IMPORTER_HEADER_ROW_NUMBER_PROPERTY, propertyComments, EMPTY_STRING, 0);

    propertyComments = model.getPropertyComments("importer.ExcelFileName");
    assertNotNull(propertyComments);
    checkComment(Comments.IMPORT_EXCEL_FILE_NAME_PROPERTY, propertyComments, EMPTY_STRING, 0);

    Metadata metadata = model.getMetadata();
    assertNotNull(metadata);
    checkComment(Comments.METADATA_ELEMENT, metadata.getComments(), EMPTY_STRING, 0);

    Iterator<DataRole> dataRoleIter = vdb.getDataRoles().iterator();
    DataRole dataRole = dataRoleIter.next();
    assertNotNull(dataRole);
    checkComment(Comments.DATA_ROLE, dataRole.getComments(), EMPTY_STRING, 0);
    checkComment(Comments.DATA_ROLE_DESCRIPTION, dataRole.getComments(), DESCRIPTION, 0);
    checkComment(
        Comments.SUPERVISOR_MAPPED_ROLE,
        dataRole.getComments(),
        MAPPED_ROLE_NAME + HYPHEN + "supervisor",
        0);
    checkComment(
        Comments.DEPT_SUPER_MAPPED_ROLE,
        dataRole.getComments(),
        MAPPED_ROLE_NAME + HYPHEN + "dept-supervisor",
        0);

    Collection<Permission> permissions = dataRole.getPermissions();
    assertNotNull(permissions);
    Iterator<Permission> permIter = permissions.iterator();
    assertTrue(permIter.hasNext());
    Permission permission = permIter.next();
    assertEquals("Accounts", permission.getName());
    checkComment(Comments.PERMISSION_ON_ACCOUNTS_TABLE, permission.getComments(), EMPTY_STRING, 0);
    checkComment(
        Comments.RESOURCE_NAME_REFERENCED_BY_PERMISSION,
        permission.getComments(),
        RESOURCE_NAME,
        0);
    checkComment(Comments.DENY_CREATE, permission.getComments(), ALLOW_CREATE, 0);
    checkComment(Comments.ALLOW_READ, permission.getComments(), ALLOW_READ, 0);
    checkComment(Comments.ALLOW_UPDATE, permission.getComments(), ALLOW_UPDATE, 0);

    permission = permIter.next();
    assertEquals("Accounts.Customer", permission.getName());

    CommentSets conditionComments = permission.getConditionComments();
    assertNotNull(conditionComments);
    checkComment(Comments.PERMISSION_USING_A_CONDITION, conditionComments, EMPTY_STRING, 0);

    permission = permIter.next();
    assertEquals("Accounts.Customer.SSN", permission.getName());
    CommentSets maskComments = permission.getMaskComments();
    assertNotNull(maskComments);
    checkComment(Comments.PERMISSION_MASK, maskComments, EMPTY_STRING, 0);
  }
  @Test
  public void testCommentReader() throws Exception {
    MockFileBuilder portfolioXmlFile = VdbTestUtils.mockPortfolioVdbXmlFile();
    File portfolioFile = portfolioXmlFile.getRealFile();
    InputStream fileStream = new FileInputStream(portfolioFile);

    JAXBContext jaxbContext = JAXBContext.newInstance(new Class<?>[] {VdbElement.class});
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    unmarshaller.setSchema(VdbUtil.getManifestSchema());
    VdbElement manifest = (VdbElement) unmarshaller.unmarshal(fileStream);

    fileStream.close();

    CommentReader reader = new CommentReader(manifest);
    reader.read(portfolioFile);

    CommentSets vdbComments = manifest.getComments();
    assertNotNull(vdbComments);
    assertEquals(2, vdbComments.size());
    checkComment(Comments.VDB_TITLE, vdbComments, EMPTY_STRING, 0);
    checkComment(Comments.VDB_TITLE_2, vdbComments, EMPTY_STRING, 1);
    checkComment(Comments.VDB_DESCRIPTION, vdbComments, DESCRIPTION, 0);

    assertEquals(1, manifest.getProperties().size());
    PropertyElement propertyElement = manifest.getProperties().get(0);
    checkComment(Comments.USE_CONNECTOR_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0);

    ModelElement modelElement = manifest.getModels().get(0);
    assertEquals("MarketData", modelElement.getName());
    checkComment(Comments.MODEL_MARKETDATA, modelElement.getComments(), EMPTY_STRING, 0);

    SourceElement sourceElement = modelElement.getSources().get(0);
    assertEquals("text-connector", sourceElement.getName());
    checkComment(Comments.MARKETDATA_TEXT_CONNECTOR, sourceElement.getComments(), EMPTY_STRING, 0);

    modelElement = manifest.getModels().get(1);
    assertEquals("Accounts", modelElement.getName());
    propertyElement = modelElement.getProperties().get(0);
    assertNotNull(propertyElement);
    checkComment(
        Comments.ACCOUNTS_USEFULLSCHEMA_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0);

    sourceElement = modelElement.getSources().get(0);
    assertEquals("h2-connector", sourceElement.getName());
    checkComment(Comments.ACCOUNT_H2_CONNECTOR, sourceElement.getComments(), EMPTY_STRING, 0);

    modelElement = manifest.getModels().get(2);
    assertEquals("PersonalValuations", modelElement.getName());
    propertyElement = modelElement.getProperties().get(0);
    assertNotNull(propertyElement);
    checkComment(
        Comments.IMPORTER_HEADER_ROW_NUMBER_PROPERTY,
        propertyElement.getComments(),
        EMPTY_STRING,
        0);

    propertyElement = modelElement.getProperties().get(1);
    assertNotNull(propertyElement);
    checkComment(
        Comments.IMPORT_EXCEL_FILE_NAME_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0);

    MetadataElement metadataElement = modelElement.getMetadata().get(0);
    assertNotNull(metadataElement);
    checkComment(Comments.METADATA_ELEMENT, metadataElement.getComments(), EMPTY_STRING, 0);

    DataRoleElement dataRoleElement = manifest.getDataPolicies().get(0);
    assertNotNull(dataRoleElement);
    checkComment(Comments.DATA_ROLE, dataRoleElement.getComments(), EMPTY_STRING, 0);
    checkComment(Comments.DATA_ROLE_DESCRIPTION, dataRoleElement.getComments(), DESCRIPTION, 0);
    checkComment(
        Comments.SUPERVISOR_MAPPED_ROLE,
        dataRoleElement.getComments(),
        MAPPED_ROLE_NAME + HYPHEN + "supervisor",
        0);
    checkComment(
        Comments.DEPT_SUPER_MAPPED_ROLE,
        dataRoleElement.getComments(),
        MAPPED_ROLE_NAME + HYPHEN + "dept-supervisor",
        0);

    List<PermissionElement> permissionElements = dataRoleElement.getPermissions();
    assertNotNull(permissionElements);
    assertTrue(!permissionElements.isEmpty());
    PermissionElement permissionElement = permissionElements.get(0);
    assertEquals("Accounts", permissionElement.getResourceName());
    checkComment(
        Comments.PERMISSION_ON_ACCOUNTS_TABLE, permissionElement.getComments(), EMPTY_STRING, 0);
    checkComment(
        Comments.RESOURCE_NAME_REFERENCED_BY_PERMISSION,
        permissionElement.getComments(),
        RESOURCE_NAME,
        0);
    checkComment(Comments.DENY_CREATE, permissionElement.getComments(), ALLOW_CREATE, 0);
    checkComment(Comments.ALLOW_READ, permissionElement.getComments(), ALLOW_READ, 0);
    checkComment(Comments.ALLOW_UPDATE, permissionElement.getComments(), ALLOW_UPDATE, 0);

    permissionElement = permissionElements.get(1);
    assertEquals("Accounts.Customer", permissionElement.getResourceName());
    ConditionElement conditionElement = permissionElement.getCondition();
    checkComment(
        Comments.PERMISSION_USING_A_CONDITION, conditionElement.getComments(), EMPTY_STRING, 0);

    permissionElement = permissionElements.get(2);
    assertEquals("Accounts.Customer.SSN", permissionElement.getResourceName());
    MaskElement maskElement = permissionElement.getMask();
    checkComment(Comments.PERMISSION_MASK, maskElement.getComments(), EMPTY_STRING, 0);
  }
 private void checkComment(Comments expected, CommentSets comments, String commentKey, int index) {
   List<String> commentsList = comments.getCommentSet(commentKey);
   assertTrue(commentsList.size() > 0);
   assertTrue(commentsList.size() > index);
   assertEquals(expected.toString(), commentsList.get(index));
 }
Example #13
0
  @Override
  public void visit(PermissionElement permElement) {
    if (!checkContext(PERMISSION)) return;

    //
    // Check we have the right permission by checking its
    // resource name sub-element
    //
    String resourceName = null;
    Node permContext = this.context;
    this.context = permContext.getFirstChild();
    while (this.context != null) {
      if (checkContext(RESOURCE_NAME)) {
        resourceName = this.context.getTextContent();
        break;
      }

      this.context = this.context.getNextSibling();
    }
    this.context = permContext;

    if (!permElement.getResourceName().equals(resourceName)) return;

    CommentSets commentSets = permElement.getComments();
    List<String> comments = commentSets.getElementCommentSet();
    insertComments(this.context, comments);

    this.context = permContext.getFirstChild();
    while (this.context != null) {

      if (checkContext(RESOURCE_NAME)) {
        comments = commentSets.getCommentSet(RESOURCE_NAME);
        insertComments(this.context, comments);

        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(MASK) && permElement.getMask() != null) {
        permElement.getMask().accept(this);
        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(CONDITION) && permElement.getCondition() != null) {
        permElement.getCondition().accept(this);
        this.context = this.context.getNextSibling();
        continue;
      }

      if (checkContext(ALLOW_CREATE)
          || checkContext(ALLOW_READ)
          || checkContext(ALLOW_UPDATE)
          || checkContext(ALLOW_DELETE)
          || checkContext(ALLOW_EXECUTE)
          || checkContext(ALLOW_ALTER)
          || checkContext(ALLOW_LANGUAGE)) {
        comments = commentSets.getCommentSet(this.context.getNodeName());
        insertComments(this.context, comments);
      }

      this.context = this.context.getNextSibling();
    }
    this.context = permContext;
  }