private void doHandle(BulkApplyTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
      PermissionTemplateDto template =
          wsSupport.findTemplate(
              dbSession,
              newTemplateRef(
                  request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
      ComponentQuery componentQuery =
          ComponentQuery.builder()
              .setNameOrKeyQuery(request.getQuery())
              .setQualifiers(qualifiers(request.getQualifier()))
              .build();
      List<ComponentDto> projects =
          dbClient.componentDao().selectByQuery(dbSession, componentQuery, 0, Integer.MAX_VALUE);

      for (ComponentDto project : projects) {
        ProjectId projectId = new ProjectId(project);
        checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.of(projectId));
      }
      permissionTemplateService.apply(dbSession, template, projects);
    }
  }
Example #2
0
  @CheckForNull
  private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
    String componentUuid = request.getComponentId();
    String componentQuery = request.getQuery();

    if (componentUuid != null) {
      return singletonList(componentUuid);
    }
    if (componentQuery != null) {
      ComponentQuery componentDtoQuery =
          ComponentQuery.builder()
              .setNameOrKeyQuery(componentQuery)
              .setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0]))
              .build();
      List<ComponentDto> componentDtos =
          dbClient
              .componentDao()
              .selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
      return Lists.transform(componentDtos, ComponentDtoFunctions.toUuid());
    }

    return null;
  }