SAP Commerce OCC Controller Generator

GETgetLoyaltyPoints
Live preview — getLoyaltyPoints
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Paste inside LoyaltyController — field loyaltyFacade and dataMapper come from the full class.

/**
 * Get loyalty points
 * Returns the current loyalty point balance for the customer.
 * @param baseSiteId Base site identifier
 * @param userId User identifier, or "current"
 * @param fields Response field set: BASIC, DEFAULT, or FULL
 * @param code Loyalty program code
 */
@Operation(operationId = "getLoyaltyPoints", summary = "Get loyalty points", description = "Returns the current loyalty point balance for the customer.")
@ApiResponses({
    @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "Loyalty points returned successfully"),
    @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "Loyalty account not found")
})
@Secured("ROLE_CUSTOMERGROUP")
@GetMapping(value = "/{code}", produces = { "application/json" })
@ResponseBody
public LoyaltyPointsWsDTO getLoyaltyPoints(
        @PathVariable("baseSiteId") @Parameter(description = "Base site identifier", required = true) String baseSiteId,
        @PathVariable("userId") @Parameter(description = "User identifier, or \"current\"", required = true) String userId,
        @RequestParam(value = "fields", required = false, defaultValue = "DEFAULT") @Parameter(description = "Response field set: BASIC, DEFAULT, or FULL", required = false) String fields,
        @PathVariable("code") @Parameter(description = "Loyalty program code", required = true) String code)
 {
    final LoyaltyPointsData data = loyaltyFacade.getLoyaltyPoints(baseSiteId, userId, fields, code);
    if (data == null) {
        throw new UnknownIdentifierException("Not found");
    }
    return dataMapper.map(data, LoyaltyPointsWsDTO.class, fields);
}

What is the SAP Commerce OCC Controller Generator?

OCC (OmniCommerce Connect) is SAP Commerce's REST API layer. Every custom endpoint needs a controller method with the right Spring annotations, parameter bindings, security roles, Swagger documentation, and often a custom WsDTO to shape the response — boilerplate that's easy to get slightly wrong and tedious to write from scratch every time.

This generator builds that controller method (plus optional facade, validator, and WsDTO classes) from a form, and lets you test the generated endpoint logic against a mock server or a real one before it's wired into a project.

How to use it

  1. Pick a method preset to start from, or build one from scratch.
  2. Configure the controller, HTTP method, parameters, security role, and response type in the Builder tab.
  3. Switch to "Generated Code" to see the controller method, and any facade/validator/WsDTO classes it depends on.
  4. Switch to "Test" to run the generated logic against a mock response or a real server and inspect the result.
  5. Copy the code into your project, or use "Export" to save it.

How it works

The form builds a structured model of the controller method — its path, HTTP method, parameters (query/path), security annotation, and return type. Code generation templates read that model and emit idiomatic Spring/OCC Java: @GetMapping or @PostMapping, @RequestParam/@PathVariable bindings, @Secured roles, and @ApiResponses documentation blocks matching what a real OCC controller needs.

The Test tab runs the same configured request shape against either a built-in mock responder (useful with no backend running) or a real OCC server URL you provide, so you can sanity-check the contract before writing any Java.

Example

A GET method configured for loyalty points generates:

@GetMapping(value = "/{code}")
@Secured("ROLE_CUSTOMERGROUP")
public LoyaltyPointsWsDTO getLoyaltyPoints(
@PathVariable("baseSiteId") String baseSiteId,
@PathVariable("code") String code) { ... }

Frequently asked questions

What is an OCC controller?

A Spring MVC controller in SAP Commerce's OmniCommerce Connect (OCC) module that exposes a REST endpoint — the same pattern used by SAP Commerce's own out-of-the-box storefront APIs.

Does it generate the WsDTO class too, not just the controller?

Yes — when you define custom response fields, the generator produces the matching WsDTO class alongside the controller method.

Can I test the generated endpoint without deploying it?

Yes — the Test tab can run against a built-in mock response matching your configured return type, so you can verify the shape of the response before any Java is deployed.

Does it support securing endpoints with customer group roles?

Yes — the Security section lets you configure @Secured roles like ROLE_CUSTOMERGROUP, matching standard OCC authorization patterns.

Can I import an existing controller instead of starting from scratch?

Yes — "Import Java" parses an existing controller class and loads its configuration into the builder.

🗳️ Vote for the next SAP Commerce guide

  • FlexibleSearch joins explained with real examples42 votes
  • ImpEx: insert, update, remove with macros and translators0 votes
  • Creating a custom OCC endpoint step by step0 votes
Vote or suggest a topic
What should we write next? Vote