Package org.sonar.core.component

Examples of org.sonar.core.component.ComponentDto


    setupData("shared");

    List<ComponentDto> results = dao.getByKeys(session, "org.struts:struts-core:src/org/struts/RequestContext.java");
    assertThat(results).hasSize(1);

    ComponentDto result = results.get(0);
    assertThat(result).isNotNull();
    assertThat(result.key()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
    assertThat(result.path()).isEqualTo("src/org/struts/RequestContext.java");
    assertThat(result.name()).isEqualTo("RequestContext.java");
    assertThat(result.longName()).isEqualTo("org.struts.RequestContext");
    assertThat(result.qualifier()).isEqualTo("FIL");
    assertThat(result.scope()).isEqualTo("FIL");
    assertThat(result.language()).isEqualTo("java");
    assertThat(result.subProjectId()).isEqualTo(2);

    assertThat(dao.getByKeys(session, "unknown")).isEmpty();
  }
View Full Code Here


  public void applyDefaultPermissionTemplate(final String componentKey) {
    UserSession.get().checkLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
      ResourceDto provisioned = resourceDao.selectProvisionedProject(session, componentKey);
      if (provisioned == null) {
        checkProjectAdminPermission(componentKey);
      } else {
        UserSession.get().checkGlobalPermission(GlobalPermissions.PROVISIONING);
View Full Code Here

        checkProjectAdminPermission(null);
        UserSession.get().checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
      }

      for (String componentKey : query.getSelectedComponents()) {
        ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
        permissionFacade.applyPermissionTemplate(session, query.getTemplateKey(), component.getId());
        synchronizeProjectPermissions(session, component.uuid());
      }
      session.commit();
    } finally {
      session.close();
    }
View Full Code Here

  @Nullable
  private Long getComponentId(DbSession session, @Nullable String componentKey) {
    if (componentKey == null) {
      return null;
    } else {
      ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
      return component.getId();
    }
  }
View Full Code Here

    addUserWithLabel(issue.reporter(), "reporter", json);
    addCharacteristics(rule, json);
  }

  private void addComponents(DbSession session, Issue issue, JsonWriter json) {
    ComponentDto component = dbClient.componentDao().getByUuid(session, issue.componentUuid());
    Long subProjectId = component.subProjectId();
    ComponentDto subProject = subProjectId != null ? dbClient.componentDao().getNullableById(subProjectId, session) : null;
    ComponentDto project = dbClient.componentDao().getByUuid(session, component.projectUuid());

    String projectName = project.longName() != null ? project.longName() : project.name();
    // Do not display sub project long name if sub project and project are the same
    boolean displaySubProjectLongName = subProject != null && !subProject.getId().equals(project.getId());
    String subProjectName = displaySubProjectLongName ? subProject.longName() != null ? subProject.longName() : subProject.name() : null;

    json
      .prop("component", component.key())
      .prop("componentLongName", component.longName())
      .prop("componentQualifier", component.qualifier())
      .prop("componentEnabled", component.isEnabled())
      .prop("project", project.key())
      .prop("projectName", projectName)
      .prop("subProjectName", subProjectName);
  }
View Full Code Here

    }
    return blocks;
  }

  private Duplication createDuplication(Map<String, ComponentDto> componentsByKey, String from, String size, String componentKey, DbSession session) {
    ComponentDto component = componentsByKey.get(componentKey);
    if (component == null) {
      component = componentDao.getNullableByKey(session, componentKey);
      componentsByKey.put(componentKey, component);
    }
    return new Duplication(component, Integer.valueOf(from), Integer.valueOf(size));
View Full Code Here

    public int compare(@Nullable Duplication d1,
      @Nullable Duplication d2) {
      if (d1 == null || d2 == null) {
        return -1;
      }
      ComponentDto file1 = d1.file();
      ComponentDto file2 = d2.file();

      if (file1 == null || file2 == null) {
        return -1;
      }

      if (file1.equals(d2.file())) {
        // if duplication on same file => order by starting line
        return d1.from().compareTo(d2.from());
      } else if (file1.equals(component)) {
        // the current resource must be displayed first
        return -1;
      } else if (file2.equals(component)) {
        // the current resource must be displayed first
        return 1;
      } else if (StringUtils.equals(file1.projectUuid(), component.projectUuid()) && !StringUtils.equals(file2.projectUuid(), component.projectUuid())) {
        // if resource is in the same project, this it must be displayed first
        return -1;
      } else if (StringUtils.equals(file2.projectUuid(), component.projectUuid()) && !StringUtils.equals(file1.projectUuid(), component.projectUuid())) {
        // if resource is in the same project, this it must be displayed first
        return 1;
      } else {
        return d1.from().compareTo(d2.from());
      }
View Full Code Here

    String fileKey = request.mandatoryParam("key");
    UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey);

    DbSession session = dbClient.openSession(false);
    try {
      ComponentDto component = findComponent(fileKey, session);
      JsonWriter json = response.newJsonWriter().beginObject();
      String duplications = findDataFromComponent(fileKey, CoreMetrics.DUPLICATIONS_DATA_KEY, session);
      List<DuplicationsParser.Block> blocks = parser.parse(component, duplications, session);
      duplicationsJsonWriter.write(blocks, json, session);
      json.endObject().close();
View Full Code Here

    }
    return null;
  }

  private ComponentDto findComponent(String key, DbSession session) {
    ComponentDto componentDto = componentDao.getNullableByKey(session, key);
    if (componentDto == null) {
      throw new NotFoundException(String.format("Component with key '%s' not found", key));
    }
    return componentDto;
  }
View Full Code Here

  private void checkPermission(UserSession userSession) {
    userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
  }

  private void checkPermission(UserSession userSession, Long projectId, DbSession session) {
    ComponentDto project = componentDao.getById(projectId, session);
    if (!userSession.hasGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN) && !userSession.hasProjectPermission(UserRole.ADMIN, project.key())) {
      throw new ForbiddenException("Insufficient privileges");
    }
  }
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.