Skip to content

Resolve effective name from map key in all bulk set services#474

Draft
pathob wants to merge 1 commit into
mainfrom
fix/resolve-effective-name-from-map-key
Draft

Resolve effective name from map key in all bulk set services#474
pathob wants to merge 1 commit into
mainfrom
fix/resolve-effective-name-from-map-key

Conversation

@pathob
Copy link
Copy Markdown
Contributor

@pathob pathob commented May 12, 2026

When a model's name field is null in a map-based request, fall back to the map key as the effective name. Also validate null models and throw BadRequestException with a descriptive message. Applies to groups, directories, application links, and applications. Covered by new unit tests for both cases in each service.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates multiple “bulk set” services to treat the map key as the effective entity name when the model’s name field is null, and adds explicit validation for null models in map-based requests (with BadRequestException messages). It also updates and expands unit tests for these behaviors in most affected services.

Changes:

  • Add null-model validation in bulk set loops for applications, directories, and application links (throwing BadRequestException with an entity-specific message).
  • Populate missing model names from the map key in applications, directories, and application links; add similar “effective name” handling for group creation.
  • Add new unit tests for the new validations/fallbacks (directories, applications, application links) and adjust group tests for the new createGroup overload.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/GroupsServiceTest.java Updates mocking/verification to match the new createGroup(directoryId, groupName, model) overload.
crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/DirectoriesServiceTest.java Adds tests for null model rejection and map-key name fallback in directory bulk set.
crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/ApplicationsServiceTest.java Adds tests for null model rejection and map-key name fallback in application bulk set.
crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/GroupsServiceImpl.java Introduces an overload to resolve the “effective” group name using the map key during group creation.
crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/ApplicationsServiceImpl.java Validates null models and fills missing names from map keys during bulk set.
commons/src/test/java/com/deftdevs/bootstrapi/commons/service/DefaultApplicationLinkServiceTest.java Adds tests for null model rejection and map-key name fallback in application link bulk set.
commons/src/main/java/com/deftdevs/bootstrapi/commons/service/DefaultApplicationLinksServiceImpl.java Validates null models and fills missing names from map keys during bulk set.
commons/src/main/java/com/deftdevs/bootstrapi/commons/service/AbstractDirectoriesService.java Validates null models and fills missing names from map keys during bulk set; uses the key consistently for lookups/updates.
Comments suppressed due to low confidence (1)

crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/GroupsServiceImpl.java:133

  • This PR description says null models in map-based requests should be rejected with BadRequestException across groups/directories/app links/applications, but setGroup() still treats a null model as "not found" when the group doesn't exist (and as a no-op when it does exist). If the intent is to validate null entries like the other bulk-set services, setGroup() (or setGroups()) should throw BadRequestException when groupModel is null rather than returning/throwing NotFound.
        final Group group = findGroup(directoryId, groupName);

        if (group == null) {
            if (groupModel == null) {
                throw new GroupNotFoundException(groupName);
            }
            return createGroup(directoryId, groupName, groupModel);
        }

        if (groupModel == null) {
            return GroupModelUtil.toGroupModel(group);
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 48 to +53
public GroupModel createGroup(
final long directoryId,
final GroupModel groupModel) {

if (groupModel.getName() == null) {
return createGroup(directoryId, groupModel.getName(), groupModel);
}
verify(spy).createGroup(anyLong(), anyString(), any());
}

@Test
When a model's name field is null in a map-based request, fall back to the map
key as the effective name. Also validate null models and throw BadRequestException
with a descriptive message. Applies to groups, directories, application links,
and applications. Covered by new unit tests for both cases in each service.
@pathob pathob force-pushed the fix/resolve-effective-name-from-map-key branch from 5287b03 to 3264f4e Compare May 12, 2026 11:52
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment on lines +70 to +72
if (groupName != null && !effectiveGroupName.equals(groupName)) {
throw new BadRequestException("Cannot create group, two different group names provided");
}
Comment on lines +161 to +164
if (groupModel.getName() == null) {
groupModel.setName(groupName);
}

Comment on lines +75 to +77
if (applicationModel.getName() == null) {
applicationModel.setName(applicationName);
}
Comment on lines +114 to +116
if (applicationLinkModel.getName() == null) {
applicationLinkModel.setName(name);
}
Comment on lines +33 to +35
if (directoryModel.getName() == null) {
directoryModel.setName(directoryName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants