Git Product home page Git Product logo

Comments (5)

frandevel avatar frandevel commented on May 29, 2024

It was due to trying to create a role that was already existing on the server. Weird.
Now it's solved
Thanks anyway!

from jrs-rest-java-client.

boryskolesnykov avatar boryskolesnykov commented on May 29, 2024

Hi frandevel,
Sorry for that long is not answered.
I tried to reproduce your error but have no succes. Could you tell me version of JasperReports server you are using?

from jrs-rest-java-client.

frandevel avatar frandevel commented on May 29, 2024

No worries at all! It was not a long wait anyway.
I'm using version 5.5 with Multi-tenancy license
ServerVersionInfo.getEditionName returns "Professional" ;O)

from jrs-rest-java-client.

boryskolesnykov avatar boryskolesnykov commented on May 29, 2024

Ok, I'm executing following sample code, where I'm firstly creating new user and new role, then I'm getting them from server, then granting user with TEST_ROLE and then update user. That's work for me.

Try to execute this code and if you will get an error please provide me with full stack trace.

        RestClientConfiguration configuration1 = new RestClientConfiguration("http://localhost:8081/jasperserver-pro");
        JasperserverRestClient client = new JasperserverRestClient(configuration1);

        Session session = client.authenticate("jasperadmin|organization_1", "jasperadmin");


        //role creation
        ClientRole role = new ClientRole();
        OperationResult<RolesListWrapper> result = session
                .rolesService()
                .organization("organization_1")
                .rolename("TEST_ROLE")
                .createOrUpdate(role);

        System.out.println("Create role: " + result.getEntity());

        //user creation
        ClientUser newUser = new ClientUser();
        newUser.setFullName("Test User");
        newUser.setPassword("password");

        OperationResult<ClientUser> result1 = session
                .usersService()
                .organization("organization_1")
                .username("testUser")
                .createOrUpdate(newUser);

        System.out.println("Create user: " + result1.getEntity());

        //getting created user
        OperationResult<ClientUser> result2 = session
                .usersService()
                .organization("organization_1")
                .username("testUser")
                .get();

        System.out.println("Get user: " + result2.getEntity());

        ClientUser user = result2.getEntity();

        //getting created role
        OperationResult<ClientRole> result3 = session
                .rolesService()
                .organization("organization_1")
                .rolename("TEST_ROLE")
                .get();

        System.out.println("Get role: " + result3.getEntity());

        //setting user's roles
        HashSet<ClientRole> roleSet = new HashSet<ClientRole>(user.getRoleSet());
        roleSet.add(result3.getEntity());
        user.setRoleSet(roleSet);


        //updating user
        OperationResult<ClientUser> result4 = session
                .usersService()
                .organization(user.getTenantId())
                .username(user.getUsername())
                .createOrUpdate(user);

        System.out.println("Update user with new role: " + result4.getEntity());

from jrs-rest-java-client.

frandevel avatar frandevel commented on May 29, 2024

Thanks Borys, it was now working. I guess I have to keep in mind that to modify entities it's probably better to create the entity, send it to the server to be persisted and updated with the correct field values (some of them set on the server on creation) and then update the entities after grabing latest changes from server and send them back again.

from jrs-rest-java-client.

Related Issues (20)

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.