Coder Social home page Coder Social logo

jpawebapi's Introduction

JPA Web API

license Build Status Documentation

Overview

The universal JPA web API enables loading and saving any entities defined in the application data model by sending simple HTTP requests.

The add-on provides an easy way to integrate with a wide range of third-party applications โ€“ from the JavaScript code executed in the browser to arbitrary systems running on Java, .NET, PHP or any other platform.

Key API features:

  • Loading entity instances from the database by identifier or by JPQL query with parameters.
  • Saving new and modified instances, deleting instances.
  • Obtaining a description of the data model in HTML format.
  • Data representation in JSON and XML formats.
  • Middleware service calls.
  • User authentication.

Read add-on Wiki for additional information.

Installation

You can install the add-on by coordinates choosing the required version of the add-on from the table.

In case you want to install the add-on by manual editing or by building from sources see the complete add-ons installation guide in CUBA Platform documentation.

By Coordinates

  1. Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
  2. Go to CUBA -> Marketplace in the main menu.

marketplace

  1. Click the icon in the upper-right corner.

by-coordinates

  1. Paste the add-on coordinates in the corresponding field as follows:

com.haulmont.addon.jpawebapi:jpawebapi-global:<add-on version>

where <add-on version> is compatible with the used version of the CUBA platform.

Platform Version Add-on Version
7.2.X 1.1.0
7.1.X 1.0.0
  1. Click Install and apply the changes. The add-on will be installed to your project.

After that the JPA Web API functionality will be available at:

  • {host:port}/app/dispatch/api/* - for Web module
  • {host:port}/app-portal/api/* - for Portal module

Customization

JPA Web API URL can be customized via jpawebapi.mapping.url app property both for web and portal application modules.

Security

Since CUBA Platform 7.2 you should create a new role with included permission-config.jpawebapi.api.enabled permission and assign it to new users in order to grant them access to the add-on.

Demo

  1. Login as admin / admin with GET request:
http://localhost:8080/app/dispatch/api/login?u=admin&p=admin&l=ru
  1. Load Users list using auth token:
http://localhost:8080/app/dispatch/api/query.json?e=sec$Role&q=select+r+from+sec$Role+r&s=b376f1d2-15d7-ea33-4048-2199de9721e7

demo

jpawebapi's People

Contributors

dtsaryov avatar ilya-c avatar mikhailstrokov avatar nikitashchienko avatar

Watchers

 avatar  avatar  avatar

Forkers

ilya-c

jpawebapi's Issues

Add information about the need to creating custom role with allowed permission-config.jpawebapi.api.enabled

Environment

  • Platform version: 7.2.8
  • Addon version: 1.1.0

Description of the bug or enhancement

Add information about that permission-config.jpawebapi.api.enabled specific permission is enabled

  • Minimal reproducible example
  1. Create a new project on 6.10.18 Platform version

  2. Migrate the project to the 7.2.8 Platform version

  3. Add jpawebapi addon

  4. Run the project

  5. Create a new user

  6. Try to login as created user with GET request
    AR: Request return JSON with error HTTP Status 401 โ€“ Unauthorize

  7. Login in app and open Administration -> Roles -> Create a new Role -> Open the Specific tab

  8. Allow the permission-config.jpawebapi.api.enabled and save changes

  9. Assign the created role to created user
    10 Try to login as created user with GET request

AR: Login as created user was successeful and request return JSON with access token

Entity is updated which specified as new property value of commit instance

Environment

  • Platform version: 7.2-SNAPSHOT
  • Addon version: 1.1.0

Description of the bug or enhancement

  • Minimal reproducible example
    By use http://localhost:8080/app-portal/api/commit request
    try to update existing entity (without specified view !) with setting reference property to the new value.
    Bug is reproducing only if reference entity (specified as new property value) has @PostConstruct method in which some fields are initializing by not null values (or some entity fields are initializing in field declaration).

For example (request body):

{
  "commitInstances": [
    {
      "id": "df$DocKind-c40ea551-d399-4a11-b6be-347ca5f27837",
      "numerator": {
        "id": "df$Numerator-70dfe954-fe9d-11e2-96e0-1f9c56fc4e22"
      }
    }
  ]
}
  1. "df$DocKind-c40ea551-d399-4a11-b6be-347ca5f27837" - without view
  2. "df$Numerator-70dfe954-fe9d-11e2-96e0-1f9c56fc4e22" - new reference property value
  3. Entity 'df$Numerator' has @PostConstruct method:
    @PostConstruct
    protected void init() {
        setPeriodicity(PeriodicityType.YEAR);
        setScriptEnabled(false);
        setNumberInitialValue(1);
    }

These 3 fields of Numerator entity will be really updated after merge DocKind.

see:
com.haulmont.addon.jpawebapi.api.controller.DataServiceController#commit

// reference to an existing entity
                            Object refEntityId = refEntity.getId();
                            refEntity = metadata.create(refEntity.getMetaClass());

                            //noinspection unchecked
                            ((BaseGenericIdEntity) refEntity).setId(refEntityId);

com.haulmont.cuba.core.sys.EntityManagerImpl#merge(T)
com.haulmont.cuba.core.sys.EntityManagerImpl#deepCopyIgnoringNulls

  • Expected behavior
    Entity which specified as new property value is not updated.
    (DocKind is updated, Numerator is not, for example)
  • Actual behavior
    The commit instance and entity which specified as new property value are updated.

REST API doesn't allow returning collection of non-entity types for service invocation

For service methods that return collection of non-entity types REST API checks that case and throws an exception from JSONConverter.processServiceMethodResult().

if (!checkCollectionItemTypes((Collection) result, Entity.class))
                throw new IllegalArgumentException("Items that are not instances of Entity found in service method result");

Whereas returning non-entity types (not wrapped in a collection) is allowed.
Returning a collection of non-entity types should be allowed as well.


Original issue: https://youtrack.haulmont.com/issue/PL-8131

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.