Package org.sonar.core.resource

Examples of org.sonar.core.resource.ResourceDto


  @CheckForNull
  public List<String> getSourceAsHtml(String componentKey, @Nullable Integer from, @Nullable Integer to) {
    DbSession session = mybatis.openSession(false);
    try {
      ResourceDto component = resourceDao.getResource(ResourceQuery.create().setKey(componentKey), session);
      if (component == null) {
        throw new NotFoundException("The component '" + componentKey + "' does not exists.");
      }
      String source = snapshotSourceDao.selectSnapshotSourceByComponentKey(componentKey, session);
      if (source != null) {
        return splitSourceByLine(source, component.getLanguage(), from, to);
      } else {
        return null;
      }
    } finally {
      MyBatis.closeQuietly(session);
View Full Code Here


      }
      checkKeyFormat(qualifier, kee);

      String uuid = UUID.randomUUID().toString();
      resourceDao.insertOrUpdate(
        new ResourceDto()
          .setUuid(uuid)
          .setProjectUuid(uuid)
          .setKey(kee)
          .setDeprecatedKey(kee)
          .setName(name)
View Full Code Here

    }
    return null;
  }

  public void updateComponent(Long id, String key, String name) {
    ResourceDto resource = resourceDao.getResource(id);
    if (resource == null) {
      throw new NotFoundException();
    }
    checkKeyFormat(resource.getQualifier(), key);

    resourceDao.insertOrUpdate(resource.setKey(key).setName(name));
  }
View Full Code Here

  private void checkProject(String projectParam, Result<ActionPlan> result) {
    if (Strings.isNullOrEmpty(projectParam)) {
      result.addError(Result.Message.ofL10n(Validation.CANT_BE_EMPTY_MESSAGE, PROJECT_PARAM));
    } else {
      ResourceDto project = resourceDao.getResource(ResourceQuery.create().setKey(projectParam));
      if (project == null) {
        result.addError(Result.Message.ofL10n("action_plans.errors.project_does_not_exist", projectParam));
      }
    }
  }
View Full Code Here

   * Does the user have the given project permission for a component ?
   */
  public boolean hasComponentPermission(String permission, String componentKey) {
    String projectKey = projectKeyByComponentKey.get(componentKey);
    if (projectKey == null) {
      ResourceDto project = resourceDao().getRootProjectByComponentKey(componentKey);
      if (project == null) {
        return false;
      }
      projectKey = project.getKey();
    }
    boolean hasComponentPermission = hasProjectPermission(permission, projectKey);
    if (hasComponentPermission) {
      projectKeyByComponentKey.put(componentKey, projectKey);
      return true;
View Full Code Here

    service.createComponent(componentKey, componentName, qualifier);

    ArgumentCaptor<ResourceDto> resourceCaptor = ArgumentCaptor.forClass(ResourceDto.class);
    verify(resourceDao).insertOrUpdate(resourceCaptor.capture());
    ResourceDto created = resourceCaptor.getValue();
    assertThat(created.getUuid()).isNotNull();
    assertThat(created.getProjectUuid()).isEqualTo(created.getUuid());
    assertThat(created.getKey()).isEqualTo(componentKey);
    assertThat(created.getName()).isEqualTo(componentName);
    assertThat(created.getLongName()).isEqualTo(componentName);
    assertThat(created.getScope()).isEqualTo(Scopes.PROJECT);
    assertThat(created.getQualifier()).isEqualTo(qualifier);
    verify(resourceDao, times(2)).findByKey(componentKey);
    verify(resourceIndexerDao).indexResource(componentId);
  }
View Full Code Here

  @Test
  public void should_update_component() {
    final long componentId = 1234l;
    final String newKey = "newKey";
    final String newName = "newName";
    ResourceDto resource = mock(ResourceDto.class);
    when(resourceDao.getResource(componentId)).thenReturn(resource);
    when(resource.setKey(newKey)).thenReturn(resource);
    when(resource.setName(newName)).thenReturn(resource);
    service.updateComponent(componentId, newKey, newName);
    verify(resource).setKey(newKey);
    verify(resource).setName(newName);
    verify(resourceDao).insertOrUpdate(resource);
  }
View Full Code Here

  @Test(expected=BadRequestException.class)
  public void should_throw_if_malformed_key_in_update() {
    final long componentId = 1234l;
    final String newKey = "new/key";
    final String newName = "newName";
    ResourceDto resource = mock(ResourceDto.class);
    when(resourceDao.getResource(componentId)).thenReturn(resource);
    service.updateComponent(componentId, newKey, newName);
  }
View Full Code Here

  PermissionFinder finder;

  @Before
  public void setUp() throws Exception {
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(100L).setName("org.sample.Sample"));
    finder = new PermissionFinder(permissionDao, resourceDao, permissionTemplateDao);
  }
View Full Code Here

  InternalRubyIssueService service;

  @Before
  public void setUp() {
    ResourceDto project = new ResourceDto().setKey("org.sonar.Sample");
    when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(project);
    service = new InternalRubyIssueService(issueService, issueQueryService, commentService, changelogService, actionPlanService, resourceDao, actionService,
      issueFilterService, issueBulkChangeService);
  }
View Full Code Here

TOP

Related Classes of org.sonar.core.resource.ResourceDto

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.