Package org.sonar.core.component

Examples of org.sonar.core.component.ComponentDto


  }

  private void writeComponents(JsonWriter json, Collection<ComponentDto> components, Map<String, ComponentDto> projectsByComponentUuid) {
    json.name("components").beginArray();
    for (ComponentDto component : components) {
      ComponentDto project = projectsByComponentUuid.get(component.uuid());
      json.beginObject()
        .prop("uuid", component.uuid())
        .prop("key", component.key())
        .prop("id", component.getId())
        .prop("enabled", component.isEnabled())
        .prop("qualifier", component.qualifier())
        .prop("name", component.name())
        .prop("longName", component.longName())
        .prop("path", component.path())
        // On a root project, subProjectId is null but projectId is equal to itself, which make no sense.
        .prop("projectId", (component.projectUuid() != null && component.subProjectId() != null) ? project.getId() : null)
        .prop("subProjectId", component.subProjectId())
        .endObject();
    }
    json.endArray();
  }
View Full Code Here


    @Nullable Double effortToFix) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
      ComponentDto project = dbClient.componentDao().getRootProjectByKey(componentKey, session);

      UserSession.get().checkProjectPermission(UserRole.USER, project.getKey());
      if (!ruleKey.isManual()) {
        throw new IllegalArgumentException("Issues can be created only on rules marked as 'manual': " + ruleKey);
      }
      Rule rule = getNullableRuleByKey(ruleKey);
      if (rule == null) {
        throw new IllegalArgumentException("Unknown rule: " + ruleKey);
      }

      DefaultIssue issue = new DefaultIssueBuilder()
        .componentKey(component.getKey())
        .projectKey(project.getKey())
        .line(line)
        .message(!Strings.isNullOrEmpty(message) ? message : rule.getName())
        .severity(Objects.firstNonNull(severity, Severity.MAJOR))
        .effortToFix(effortToFix)
        .ruleKey(ruleKey)
View Full Code Here

      String projectOrModuleKey = request.mandatoryParam(PARAM_KEY);
      String profileName = request.param(PARAM_PROFILE);

      String projectKey = null;
      ComponentDto module = dbClient.componentDao().getNullableByKey(session, projectOrModuleKey);
      // Current project can be null when analysing a new project
      if (module != null) {
        ComponentDto project = dbClient.componentDao().getNullableRootProjectByKey(projectOrModuleKey, session);
        // Can be null if the given project is a provisioned one
        if (project != null) {
          if (!project.key().equals(module.key())) {
            addSettings(ref, module.getKey(), getSettingsFromParents(module.key(), hasScanPerm, session));
          }
          projectKey = project.key();
          addSettingsToChildrenModules(ref, projectOrModuleKey, Maps.<String, String>newHashMap(), hasScanPerm, session);
        } else {
          // Add settings of the provisioned project
          addSettings(ref, projectOrModuleKey, getPropertiesMap(propertiesDao.selectProjectProperties(projectOrModuleKey, session), hasScanPerm));
          projectKey = projectOrModuleKey;
View Full Code Here

    this.dbClient = dbClient;
  }

  @Override
  protected void doInsert(DbSession session, Date now, DefaultIssue issue) {
    ComponentDto component = component(session, issue);
    ComponentDto project = project(session, issue);
    int ruleId = ruleId(issue);
    IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleId, now);

    dbClient.issueDao().insert(session, dto);
  }
View Full Code Here

    }
    return parentProperties;
  }

  private void aggregateParentModules(String component, List<ComponentDto> parents, DbSession session){
    ComponentDto parent = dbClient.componentDao().getParentModuleByKey(component, session);
    if (parent != null) {
      parents.add(parent);
      aggregateParentModules(parent.key(), parents, session);
    }
  }
View Full Code Here

  }

  public void delete(String projectKey) {
    DbSession dbSession = dbClient.openSession(false);
    try {
      ComponentDto project = dbClient.componentDao().getByKey(dbSession, projectKey);
      if (!Scopes.PROJECT.equals(project.scope())) {
        throw new IllegalArgumentException("Only project can be deleted");
      }
      purgeDao.deleteResourceTree(project.getId());
      deletePermissionIndexes(dbSession, project.uuid());
      dbSession.commit();

      deleteIssuesFromIndex(project.uuid());
    } finally {
      MyBatis.closeQuietly(dbSession);
    }
  }
View Full Code Here

    long start = System.currentTimeMillis();
    Result<Issue> result = issueIndex.search(IssueQuery.builder().build(), new QueryContext());
    LOGGER.info("Search for all issues : returned {} issues in {} ms", result.getTotal(), System.currentTimeMillis() - start);

    start = System.currentTimeMillis();
    ComponentDto project = componentsByProject.keySet().iterator().next();
    result = issueIndex.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new QueryContext());
    LOGGER.info("Search for issues from one project : returned {} issues in {} ms", result.getTotal(), System.currentTimeMillis() - start);

    start = System.currentTimeMillis();
    ComponentDto file = componentsByProject.get(project).get(0);
    result = issueIndex.search(IssueQuery.builder().componentUuids(newArrayList(file.uuid())).build(), new QueryContext());
    LOGGER.info("Search for issues from one file : returned {} issues in {} ms", result.getTotal(), System.currentTimeMillis() - start);
  }
View Full Code Here

      rules.next().setId((int) ids++);
    }

    long start = System.currentTimeMillis();
    for (long projectIndex = 0; projectIndex < PROJECTS_NUMBER; projectIndex++) {
      ComponentDto project = ComponentTesting.newProjectDto()
        .setId(ids++)
        .setKey("project-" + projectIndex)
        .setName("Project " + projectIndex)
        .setLongName("Project " + projectIndex);
      projects.add(project);

      // All project are visible by anyone
      // TODO set different groups/users to test search issues queries with more realistic data
      batchSession.enqueue(new InsertDto<IssueAuthorizationDto>(IndexDefinition.ISSUES_AUTHORIZATION.getIndexType(),
        new IssueAuthorizationDto().setProjectUuid(project.uuid()).setGroups(newArrayList(DefaultGroups.ANYONE)), false));

      for (int fileIndex = 0; fileIndex < NUMBER_FILES_PER_PROJECT; fileIndex++) {
        String index = projectIndex * PROJECTS_NUMBER + fileIndex + "";
        ComponentDto file = ComponentTesting.newFileDto(project)
          .setId(ids++)
          .setKey("file-" + index)
          .setName("File " + index)
          .setLongName("File " + index);
        componentsByProject.put(project, file);
View Full Code Here

  @CheckForNull
  public Long createComponent(String kee, String name, String qualifier) {
    // Sub view should not be created with provisioning. Will be fixed by http://jira.sonarsource.com/browse/VIEWS-296
    if (!Qualifiers.SUBVIEW.equals(qualifier)) {
      ComponentDto component = (ComponentDto) resourceDao.findByKey(kee);
      if (component != null) {
        throw new BadRequestException(formatMessage("Could not create %s, key already exists: %s", qualifier, kee));
      }
      checkKeyFormat(qualifier, kee);

      String uuid = UUID.randomUUID().toString();
      resourceDao.insertOrUpdate(
        new ResourceDto()
          .setUuid(uuid)
          .setProjectUuid(uuid)
          .setKey(kee)
          .setDeprecatedKey(kee)
          .setName(name)
          .setLongName(name)
          .setScope(Scopes.PROJECT)
          .setQualifier(qualifier)
          .setCreatedAt(new Date()));
      component = (ComponentDto) resourceDao.findByKey(kee);
      if (component == null) {
        throw new BadRequestException(String.format("Component not created: %s", kee));
      }
      resourceIndexerDao.indexResource(component.getId());
      return component.getId();
    }
    return null;
  }
View Full Code Here

      ruleDao.insert(session, rules.next());
    }
    session.commit();

    for (long projectIndex = 0; projectIndex < PROJECTS_NUMBER; projectIndex++) {
      ComponentDto project = ComponentTesting.newProjectDto()
        .setKey("project-" + projectIndex)
        .setName("Project " + projectIndex)
        .setLongName("Project " + projectIndex);
      componentDao.insert(session, project);

      for (int fileIndex = 0; fileIndex < NUMBER_FILES_PER_PROJECT; fileIndex++) {
        String index = projectIndex * PROJECTS_NUMBER + fileIndex + "";
        ComponentDto file = ComponentTesting.newFileDto(project)
          .setKey("file-" + index)
          .setName("File " + index)
          .setLongName("File " + index);
        componentDao.insert(session, file);

View Full Code Here

TOP

Related Classes of org.sonar.core.component.ComponentDto

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.