Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

February Developer Challenge - CAP Plugins: Week 1

thomas_jung
Developer Advocate
Developer Advocate

Week 2 is now live: February Developer Challenge - CAP Plugins: Week 2 - SAP Community

Now that the challenge is complete: here is my sample solution: jung-thomas/dev-challenge-feb-2024: Developer Challenge February 2024 (github.com)

Welcome back to our monthly Developer Challenge series. These are fun puzzles that also challenge you to learn something new.  For February 2024 the challenge will focus on SAP Cloud Application Programming Model and its concept of plugins. To participate in the challenge you just have to post a screenshot of your solution as a reply here in this discussion.

SAP Cloud Application Programming Model (CAP) plugins are extensions to the CAP framework that enable developers to enhance the capabilities of their CAP-based applications. These plugins can be used to add custom features, integrate with external services, or modify the default behavior of the CAP framework. In the February 2024 Developer Challenge, you are going to learn just how easy and powerful these extensions are. We will build a simple, sample CAP application and then each week your challenge will be to integrate a different plugin into this application.

Key aspects of CAP plugins include

  1. Customization and Extension: Plugins allow developers to extend the core functionality of CAP by adding custom logic, services, or features that are not part of the standard CAP framework.

  2. Integration: They can be used to integrate CAP applications with other SAP solutions, third-party services, or APIs. This helps in building more comprehensive and connected systems.

  3. Reusability: Plugins can be developed in a way that they are reusable across different CAP projects. This promotes code reuse and consistency across applications.

  4. Community Contributions: Apart from official SAP-provided plugins, the community of developers can create and share their own plugins, fostering an ecosystem of tools and extensions.

  5. Simplified Development: By encapsulating complex or repetitive tasks into plugins, developers can simplify the application development process, focusing more on business logic rather than boilerplate code.

  6. Configuration and Customization: Plugins often come with configurable options allowing developers to tailor them according to specific project requirements.

Overall, CAP plugins are a powerful way to extend the capabilities of the SAP Cloud Application Programming Model, enabling developers to build more feature-rich, integrated, and efficient applications.

https://cap.cloud.sap/docs/plugins/

Types of Plugins for Node.js

  1. GraphQL Adapter: This plugin automatically generates a GraphQL schema for application models and allows querying services using GraphQL. It's activated by adding a @graphql annotation to service definitions.

  2. OData v2 Proxy: This protocol adapter exposes services as OData v2 services, converting OData V2 requests to CDS OData V4 calls and responses.

  3. UI5 Dev Server: Integrates UI5 tooling-based projects into the CDS server, serving dynamic UI5 resources and transpiling TypeScript implementations for UI5 controls.

  4. Change Tracking: Automatically captures, stores, and views changes in modeled entities. Entities and elements for change tracking are specified using @changelog annotations.

  5. Audit Logging: Logs personal data-related operations with the SAP Audit Log Service, using annotations to mark entities and fields related to personal data.

  6. Notifications: Integrates with the SAP Alert Notifications service to send notifications via various channels (email, Slack, Microsoft Teams, SAP Fiori). It provides a simple programmatic API for sending notifications.

Key Features

  1. Simplicity and Ease of Use: Many plugins have a minimalistic setup and offer a plug-and-play experience.
  2. Annotation-Based Configuration: Plugins like Audit Logging and Change Tracking use annotations for configuration, making them easy to implement.
  3. Integration with SAP Services: Plugins offer seamless integration with various SAP services for enhanced functionality.
  4. Support for Multiple Formats: The OData v2 Proxy and GraphQL Adapter allow services to be exposed in different data formats.
  5. Development and Production Logging: Plugins support logging in both development and production environments, with features like transactional outbox for scalability and resilience.

Week 1 Challenge

Week 1 of the challenge will be the most time consuming of all the weeks, simply because we need to get an initial sample application running. After we have our baseline project, this week and all subsequent weeks will just focus on adding one or more CAP plugins to that project.

Initial Project Creation

We will walk you through the initial project creation step-by-step. But later in the challenge once you are adding the plugins you will be expected to figure out that part on your own. That's the "challenge" after all.

  1. You can create your CAP project anywhere that CAP development has tooling. That could mean the SAP Business Application Studio, Microsoft Visual Studio Code, or really most any IDE, text editor, or command line. The screenshots and steps we are going to describe do use wizards and other tooling that's primarily available in both the SAP Business Application Studio or Microsoft Visual Studio Code with the SAP Cloud Application Studio extension.
  2. Start the IDE's Project Wizard. From SAP Business Application Studio, the wizards can be triggered from the Get Started page. From VSCode, you can begin by choosing Open Template Wizard from the Command Pallet.
  3. Choose the CAP Project as your Generator (IE wizard) type.
    wizard_type.png
  4. In the project details, name your project. I used dev-challenge-feb-2024 as my name, but you can choose what you want.
    template_wizard1.png 
    1. Select Node.js as your runtime.
    2. Choose Cloud Foundry: MTA Deployment as the way to deploy your project
    3. Check the Extended Sample with UI option for adding sample content to your project. This is the most important item as this will give us a starter project ready to use so that we can focus on CAP plugins.
    4. Double check your entires and press Finish

    Note: You can also create your project using the cds command line with the command: cds init --add nodejs,mta,sample

  5. After a moment or two, your project should be generated and visible in your Project Explorer view. You will find UI parts in the /app folder, database object definition in the /db folder, and service defintion and implementation in the /srv folder. Also make note of the package.json file in the root of the project. This is where most of the important configuration for CAP and especially plugins will be performed.
    generated_project.png 
     
  6. The project is really quite complete and nearly ready to test. The only thing you need to do first is to run the command npm install from the terminal. This will ensure that all external dependencies (including CAP itself) get installed into your project. 

    npm_install.png

     
  7. After the npm install completes, you are ready to test your project. You can do this by issuing the command from the terminal: npm start. This will trigger the cds-serve of your project. 

    npm_start1.png

     
  8. This command starts a CAP server in your development environment. This allows us to test locally on our development machine or in the cloud with a virtual machine/dev space if using the SAP Business Application Studio. This gives us quick testing and debugging capabilities without having to fully deploy the application to SAP BTP. You will see the start deploying of test data from CSV files, the authentication strategy and which services are running from which endpoints. Finally there is the URL which we can open in a web browser to test our application. 

    npm_start2.png

     
  9. As long as you choose the extended sample in the project wizard, you should see a Fiori UI that allows you test the sample application. 

    test1.png

     
  10. This is a nice UI but we also want to use the built-in CAP testing page. It's currently overridden by the index.html in the /app folder that is the Fiori LaunchPad. Let's just rename that index.html file to indexFLP.html. 

    rename_index.png

     
  11. Rerun the application and now you should see the CAP test page by default. You wiĺl have direct links to test individual entities from the OData Services, view the metadata documents but you can also still find a link to the Fiori application under Web Applications 
     

    test2.png

     

Adding the OData V2 plugin

We have our running CAP application and it exposes OData V4 services and has a nice annotation based Fiori UI. You are ready for the real challenge to begin.

OData V4 support is excellent, but what if you also need OData V2 for backwards compatibility? This is the first of the CAP Plugins we will use. Your challenge, should you choose to accept it, is to use what you have learned about CAP plugins here and use the @cap-js-community/odata-v2-adapter plugin. You should be able to complete this challenge with a single command!

  1. After adding support for OData V2, run your application again. You should see log entries during startup that indicate the OData V2 proxy was created. 

    test3.png

     
  2. You will also see that your test page automatically adapted and now has links to test the OData V2 endpoints as well as view the V2 metadata documents. 

    test4.png

     
  3. To complete the challenge, post a screenshot of your test page with the V2 endpoints as a response here in this thread.

Bonus 1: Use the test tool to compare the format and structural differences between OData V2 and OData V4 both on the service endpoints and the metadata documents.

Bonus 2: using only configuration in the package.json, change the default path from /odata/v2 to /devchallenge/v2 for only the OData V2 service endpoint.
bonus2_1.png

67 REPLIES 67

ajmaradiaga
Developer Advocate
Developer Advocate

Screenshot of test page with v2 endpoints...

ajmaradiaga_0-1707311986987.png

My OData v2 path is devchallenge-ajmc.

ajmaradiaga_1-1707312060769.png

ajmaradiaga_2-1707312344253.png

 

Alpesa1990
Participant

V4 Endpoints

Alpesa1990_0-1707340018317.png

Alpesa1990_1-1707340028935.png

 

V2 Endpoint (called devchallenge-ALPESA)

Alpesa1990_2-1707340104851.png

Alpesa1990_3-1707340114913.png

Alpesa1990_4-1707340176444.pngAlpesa1990_5-1707340210548.png

 

Alvaro Peñil

 

 

NicholasB
Product and Topic Expert
Product and Topic Expert

Endpoints v2:

NicholasB_0-1707346877931.png

Switched default path of plugin:

NicholasB_1-1707346893683.png

 

Raghu_150
Explorer

Hi @thomas_jung , feb week 1 challenge.

Raghu_150_0-1707380793379.png 

Raghu_150_1-1707380843456.png

 

Raghu_150_2-1707380900640.png

I'm super excited for the upcoming 2nd week.

 

I am curious, what is the difference between these 2 plugins

1) @cap-js-community/odata-v2-adapter

2) @Sap/cds-odata-v2-adapter-proxy

They both seem to be for the same purpose. 

Regards

Sandip

 @Sap/cds-odata-v2-adapter-proxy is the older version and now deprecated.  See @sap/cds-odata-v2-adapter-proxy - npm (npmjs.com) -

gphadnis2000
Participant

Hi,

My screenshot of week 1 challenge.

gphadnis2000_1-1707389412582.png

 

 

Thanks and Regards,

Gaurav Phadnis

MeriemSouissi
Participant

patricebender
Product and Topic Expert
Product and Topic Expert

Hi Thomas!

Love to see this challenge. I want to point out that we also have developed the new database services with the plugin technique. Including support for postgres

Cheers

Patrice

Very true.  In this challenge I am focused on the non-DB service plugins. But that's an idea for a future challenge - exploring the various DB services and how they plugin as well. It's very elegant architecture.  I actually did a video on hybrid testing with cds bind combined with the multi-DB service plugins - including Postgres

SandipAgarwalla
Active Contributor

Test Page with V2 end points

SandipAgarwalla_0-1707402625546.png

Custom Path for v2 end points

 

SandipAgarwalla_2-1707403244049.png

 

satya-dev
Participant

1. ODataV2 default

satyadev_0-1707405771776.png

2. test page Odatav2

satyadev_1-1707405859789.png

3). changed the default path 

satyadev_2-1707406054036.png

 

 

Cmdd
Participant

SMaaLL
Participant

test page

SMaaLL_0-1707487599800.png

My OData v2 path is ab_devchallenge

SMaaLL_2-1707487746287.png

egenoves
Participant

The screenshots of the challenge:

CDS localhost pageCDS localhost page

metadatametadatadevchg3.jpg

virengupta
Discoverer

Hi @thomas_jung , 
while generating the project via generator, i do not see the option "Extended sample with UI". any suggestions?

Screenshot 2024-02-10 at 07.18.56.png

Also, tried using: cds init -> cds add mta -> cds add samples but that does not adds the sample UI artefacts too!

Thanks.

0 Kudos

Looks to me like you have an older version of CAP most likely.  You want to be on version 7.x at least. I tested the challenge using 7.6.x. You can do a cds version to find out what you are running.  Here's my cds version:

thomas_jung_0-1707572023921.png

 

virengupta
Discoverer

The screenshot of the challenge (used the another existing project, instead of creating the new one):

virengupta_0-1707547485213.png

virengupta_1-1707547511301.png

 

0 Kudos

That's fine if you want to use an existing project but you might find it more difficult in later weeks in the challenge.  We will ask you to use the plugins in specific ways - like adding logic to an exit handler that already exists as part of the sample application.  

YoshiakiToma
Explorer

Screenshots about  V2 endpoints.

YoshiakiToma_3-1707661126615.png

 

And response below:

YoshiakiToma_2-1707657170840.png

 

 

JSkoczylas
Discoverer

Anand-Shankar
Newcomer

Application

AnandShankar_1-1707802746599.png

 

Diff. between V2 and V4

 

Action tag

AnandShankar_3-1707802746617.png

Service path change for v2

bonus2_1.png

brunonalon
Explorer

Nice challenge. 

V2 Endpoints 

brunonalon_0-1707825372226.png

Bonus 1

brunonalon_1-1707825506837.png

brunonalon_2-1707825534851.png

Bonus 2 

brunonalon_3-1707825974184.png