Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[M] Improved error output surrounding owner creation and service levels #1965

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion server/src/main/java/org/candlepin/resource/OwnerResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@ public OwnerInfo getOwnerInfo(@PathParam("owner_key")
@ApiOperation(notes = "Creates an Owner", value = "Create Owner")
@ApiResponses({ @ApiResponse(code = 400, message = "Invalid owner specified in body") })
public OwnerDTO createOwner(@ApiParam(name = "owner", required = true) OwnerDTO dto) {
// Verify that we have an owner key (as required)
if (StringUtils.isBlank(dto.getKey())) {
throw new BadRequestException(i18n.tr("Owners must be created with a valid key"));
}

// Validate and set content access mode list & content access mode
if (StringUtils.isBlank(dto.getContentAccessModeList())) {
dto.setContentAccessModeList(ContentAccessCertServiceAdapter.DEFAULT_CONTENT_ACCESS_MODE);
Expand All @@ -897,10 +902,18 @@ public OwnerDTO createOwner(@ApiParam(name = "owner", required = true) OwnerDTO
dto.getContentAccessMode()));
}


// Check that the default service level is *not* set at this point
if (!StringUtils.isBlank(dto.getDefaultServiceLevel())) {
throw new BadRequestException(i18n.tr(
"The default service level cannot be specified during owner creation"));
}

// Translate the DTO to an entity Owner.
Owner owner = new Owner();
this.populateEntity(owner, dto);
owner.setKey(dto.getKey());

this.populateEntity(owner, dto);
owner.setContentAccessModeList(dto.getContentAccessModeList());
owner.setContentAccessMode(dto.getContentAccessMode());

Expand Down