Search in sources :

Example 91 with ApiResponses

use of io.swagger.annotations.ApiResponses in project killbill by killbill.

the class SubscriptionResource method changeEntitlementPlan.

@TimedResource
@PUT
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@ApiOperation(value = "Change entitlement plan")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found") })
public Response changeEntitlementPlan(final SubscriptionJson entitlement, @PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion, @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec, @QueryParam(QUERY_BILLING_POLICY) final String policyString, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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 EntitlementApiException, AccountApiException, SubscriptionApiException {
    verifyNonNullOrEmpty(entitlement, "SubscriptionJson body should be specified");
    if (entitlement.getPlanName() == null) {
        verifyNonNullOrEmpty(entitlement.getProductName(), "SubscriptionJson productName needs to be set", entitlement.getBillingPeriod(), "SubscriptionJson billingPeriod needs to be set", entitlement.getPriceList(), "SubscriptionJson priceList needs to be set");
    }
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final EntitlementCallCompletionCallback<Response> callback = new EntitlementCallCompletionCallback<Response>() {

        private boolean isImmediateOp = true;

        @Override
        public Response doOperation(final CallContext ctx) throws EntitlementApiException, InterruptedException, TimeoutException, AccountApiException {
            final UUID uuid = UUID.fromString(subscriptionId);
            final Entitlement current = entitlementApi.getEntitlementForId(uuid, callContext);
            final LocalDate inputLocalDate = toLocalDate(requestedDate);
            final Entitlement newEntitlement;
            final Account account = accountUserApi.getAccountById(current.getAccountId(), callContext);
            final PlanSpecifier planSpec = entitlement.getPlanName() != null ? new PlanSpecifier(entitlement.getPlanName()) : new PlanSpecifier(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList());
            final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(entitlement.getPriceOverrides(), planSpec, account.getCurrency());
            if (requestedDate == null && policyString == null) {
                newEntitlement = current.changePlan(planSpec, overrides, pluginProperties, ctx);
            } else if (policyString == null) {
                newEntitlement = current.changePlanWithDate(planSpec, overrides, inputLocalDate, pluginProperties, ctx);
            } else {
                final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase());
                newEntitlement = current.changePlanOverrideBillingPolicy(planSpec, overrides, inputLocalDate, policy, pluginProperties, ctx);
            }
            isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) && newEntitlement.getLastActivePlan().getRecurringBillingPeriod() == BillingPeriod.valueOf(entitlement.getBillingPeriod()) && newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList());
            return Response.status(Status.OK).build();
        }

        @Override
        public boolean isImmOperation() {
            return isImmediateOp;
        }

        @Override
        public Response doResponseOk(final Response operationResponse) throws SubscriptionApiException, AccountApiException, CatalogApiException {
            if (operationResponse.getStatus() != Status.OK.getStatusCode()) {
                return operationResponse;
            }
            return getEntitlement(subscriptionId, new AuditMode(AuditLevel.NONE.toString()), request);
        }
    };
    final EntitlementCallCompletion<Response> callCompletionCreation = new EntitlementCallCompletion<Response>();
    return callCompletionCreation.withSynchronization(callback, timeoutSec, callCompletion, callContext);
}
Also used : Account(org.killbill.billing.account.api.Account) BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 92 with ApiResponses

use of io.swagger.annotations.ApiResponses in project killbill by killbill.

the class SubscriptionResource method getEntitlement.

@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a subscription by id", response = SubscriptionJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Subscription not found") })
public Response getEntitlement(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException {
    final UUID uuid = UUID.fromString(subscriptionId);
    final TenantContext context = this.context.createContext(request);
    final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(uuid, context);
    final Account account = accountUserApi.getAccountById(subscription.getAccountId(), context);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(subscription.getAccountId(), auditMode.getLevel(), context);
    final SubscriptionJson json = new SubscriptionJson(subscription, account.getCurrency(), accountAuditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : Account(org.killbill.billing.account.api.Account) SubscriptionJson(org.killbill.billing.jaxrs.json.SubscriptionJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) UUID(java.util.UUID) Subscription(org.killbill.billing.entitlement.api.Subscription) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 93 with ApiResponses

use of io.swagger.annotations.ApiResponses in project killbill by killbill.

the class SubscriptionResource method uncancelEntitlementPlan.

@TimedResource
@PUT
@Path("/{subscriptionId:" + UUID_PATTERN + "}/uncancel")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Un-cancel an entitlement")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found") })
public Response uncancelEntitlementPlan(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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 EntitlementApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final UUID uuid = UUID.fromString(subscriptionId);
    final Entitlement current = entitlementApi.getEntitlementForId(uuid, context.createContext(createdBy, reason, comment, request));
    current.uncancelEntitlement(pluginProperties, context.createContext(createdBy, reason, comment, request));
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 94 with ApiResponses

use of io.swagger.annotations.ApiResponses in project killbill by killbill.

the class TagDefinitionResource method getTagDefinitions.

@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List tag definitions", response = TagDefinitionJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getTagDefinitions(@javax.ws.rs.core.Context final HttpServletRequest request, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode) {
    final TenantContext tenantContext = context.createContext(request);
    final List<TagDefinition> tagDefinitions = tagUserApi.getTagDefinitions(tenantContext);
    final Collection<TagDefinitionJson> result = new LinkedList<TagDefinitionJson>();
    for (final TagDefinition tagDefinition : tagDefinitions) {
        final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
        result.add(new TagDefinitionJson(tagDefinition, auditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TenantContext(org.killbill.billing.util.callcontext.TenantContext) TagDefinitionJson(org.killbill.billing.jaxrs.json.TagDefinitionJson) LinkedList(java.util.LinkedList) AuditLog(org.killbill.billing.util.audit.AuditLog) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 95 with ApiResponses

use of io.swagger.annotations.ApiResponses in project killbill by killbill.

the class TagDefinitionResource method getTagDefinition.

@TimedResource
@GET
@Path("/{tagDefinitionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a tag definition", response = TagDefinitionJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tagDefinitionId supplied") })
public Response getTagDefinition(@PathParam("tagDefinitionId") final String tagDefId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException {
    final TenantContext tenantContext = context.createContext(request);
    final TagDefinition tagDefinition = tagUserApi.getTagDefinition(UUID.fromString(tagDefId), tenantContext);
    final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
    final TagDefinitionJson json = new TagDefinitionJson(tagDefinition, auditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TenantContext(org.killbill.billing.util.callcontext.TenantContext) TagDefinitionJson(org.killbill.billing.jaxrs.json.TagDefinitionJson) AuditLog(org.killbill.billing.util.audit.AuditLog) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiResponses (io.swagger.annotations.ApiResponses)612 ApiOperation (io.swagger.annotations.ApiOperation)607 Path (javax.ws.rs.Path)319 Produces (javax.ws.rs.Produces)223 Counted (com.codahale.metrics.annotation.Counted)210 Timed (com.codahale.metrics.annotation.Timed)193 GET (javax.ws.rs.GET)169 POST (javax.ws.rs.POST)119 TimedResource (org.killbill.commons.metrics.TimedResource)111 Consumes (javax.ws.rs.Consumes)109 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)94 Authorisation (nikita.webapp.security.Authorisation)87 PUT (javax.ws.rs.PUT)66 UUID (java.util.UUID)62 DELETE (javax.ws.rs.DELETE)62 AuditEvent (org.graylog2.audit.jersey.AuditEvent)59 TenantContext (org.killbill.billing.util.callcontext.TenantContext)58 RestException (com.yahoo.pulsar.broker.web.RestException)54 ApiResponse (io.swagger.annotations.ApiResponse)53 CallContext (org.killbill.billing.util.callcontext.CallContext)51