@Test public void check_component_keys() { db.prepareDbUnit(getClass(), "shared.xml"); Map<String, Boolean> result = underTest.checkComponentKeys(dbSession, newArrayList("foo:struts", "foo:struts-core", "foo:struts-ui")); assertThat(result) .hasSize(3) .containsOnly(entry("foo:struts", false), entry("foo:struts-core", true), entry("foo:struts-ui", false)); }
private BulkUpdateKeyWsResponse doHandle(BulkUpdateKeyRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto projectOrModule = componentFinder.getByUuidOrKey(dbSession, request.getId(), request.getKey(), ParamNames.ID_AND_KEY); checkIsProjectOrModule(projectOrModule); userSession.checkComponentPermission(UserRole.ADMIN, projectOrModule); Map<String, String> newKeysByOldKeys = componentKeyUpdater.simulateBulkUpdateKey(dbSession, projectOrModule.uuid(), request.getFrom(), request.getTo()); Map<String, Boolean> newKeysWithDuplicateMap = componentKeyUpdater.checkComponentKeys(dbSession, ImmutableList.copyOf(newKeysByOldKeys.values())); if (!request.isDryRun()) { checkNoDuplicate(newKeysWithDuplicateMap); bulkUpdateKey(dbSession, request, projectOrModule); } return buildResponse(newKeysByOldKeys, newKeysWithDuplicateMap); } }
@Test public void check_component_keys_checks_inactive_components() { OrganizationDto organizationDto = db.organizations().insert(); db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("my-project")); db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("your-project").setEnabled(false)); Map<String, Boolean> result = underTest.checkComponentKeys(dbSession, newArrayList("my-project", "your-project", "new-project")); assertThat(result) .hasSize(3) .containsOnly(entry("my-project", true), entry("your-project", true), entry("new-project", false)); }
private BulkUpdateKeyWsResponse doHandle(BulkUpdateKeyRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto projectOrModule = componentFinder.getByUuidOrKey(dbSession, request.getId(), request.getKey(), ParamNames.ID_AND_KEY); checkIsProjectOrModule(projectOrModule); userSession.checkComponentPermission(UserRole.ADMIN, projectOrModule); Map<String, String> newKeysByOldKeys = componentKeyUpdater.simulateBulkUpdateKey(dbSession, projectOrModule.uuid(), request.getFrom(), request.getTo()); Map<String, Boolean> newKeysWithDuplicateMap = componentKeyUpdater.checkComponentKeys(dbSession, ImmutableList.copyOf(newKeysByOldKeys.values())); if (!request.isDryRun()) { checkNoDuplicate(newKeysWithDuplicateMap); bulkUpdateKey(dbSession, request, projectOrModule); } return buildResponse(newKeysByOldKeys, newKeysWithDuplicateMap); } }