use of org.killbill.billing.util.api.TagApiException in project killbill by killbill.
the class AccountResource method deleteTags.
@TimedResource
@DELETE
@Path("/{accountId:" + UUID_PATTERN + "}/" + TAGS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Remove tags from account")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied or account does not have a default payment method (AUTO_PAY_OFF tag only)") })
public Response deleteTags(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_TAGS) final String tagList, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException, AccountApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
// Look if there is an AUTO_PAY_OFF for that account and check if the account has a default paymentMethod
// If not we can't remove the AUTO_PAY_OFF tag
final Collection<UUID> tagDefinitionUUIDs = getTagDefinitionUUIDs(tagList);
boolean isTagAutoPayOff = false;
for (final UUID cur : tagDefinitionUUIDs) {
if (cur.equals(ControlTagType.AUTO_PAY_OFF.getId())) {
isTagAutoPayOff = true;
break;
}
}
final UUID accountId = UUID.fromString(id);
if (isTagAutoPayOff) {
final Account account = accountUserApi.getAccountById(accountId, callContext);
if (account.getPaymentMethodId() == null) {
throw new TagApiException(ErrorCode.TAG_CANNOT_BE_REMOVED, ControlTagType.AUTO_PAY_OFF, " the account does not have a default payment method");
}
}
return super.deleteTags(UUID.fromString(id), tagList, callContext);
}
use of org.killbill.billing.util.api.TagApiException in project killbill by killbill.
the class AccountResource method deleteAccountTags.
@TimedResource
@DELETE
@Path("/{accountId:" + UUID_PATTERN + "}/" + TAGS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Remove tags from account")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Successful operation"), @ApiResponse(code = 400, message = "Invalid account id supplied or account does not have a default payment method (AUTO_PAY_OFF tag only)") })
public Response deleteAccountTags(@PathParam(ID_PARAM_NAME) final UUID accountId, @QueryParam(QUERY_TAG) final List<UUID> tagList, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException, AccountApiException {
final CallContext callContext = context.createCallContextWithAccountId(accountId, createdBy, reason, comment, request);
// Look if there is an AUTO_PAY_OFF for that account and check if the account has a default paymentMethod
// If not we can't remove the AUTO_PAY_OFF tag
boolean isTagAutoPayOff = false;
for (final UUID cur : tagList) {
if (cur.equals(ControlTagType.AUTO_PAY_OFF.getId())) {
isTagAutoPayOff = true;
break;
}
}
if (isTagAutoPayOff) {
final Account account = accountUserApi.getAccountById(accountId, callContext);
if (account.getPaymentMethodId() == null) {
throw new TagApiException(ErrorCode.TAG_CANNOT_BE_REMOVED, ControlTagType.AUTO_PAY_OFF, " the account does not have a default payment method");
}
}
return super.deleteTags(accountId, tagList, callContext);
}
use of org.killbill.billing.util.api.TagApiException in project killbill by killbill.
the class DefaultTagUserApi method addTag.
@Override
public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final CallContext context) throws TagApiException {
if (SystemTags.isSystemTag(tagDefinitionId)) {
// TODO Create a proper ErrorCode instaed
throw new IllegalStateException(String.format("Failed to add tag for tagDefinitionId='%s': System tags are reserved for the system.", tagDefinitionId));
}
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(objectId, objectType, context);
final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType);
try {
tagDao.create(tag, internalContext);
} catch (TagApiException e) {
// Be lenient here and make the addTag method idempotent
if (ErrorCode.TAG_ALREADY_EXISTS.getCode() != e.getCode()) {
throw e;
}
}
}
Aggregations