JasperReportsPdfView always empty, how to send parameters?

I am very new making reports on jasper, I basically want to create a very basic report also using spring boot.

So I did this:

created my jasper template like:

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
    "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports
                                  http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
              name="report1" pageWidth="595" pageHeight="842"
              columnWidth="555" leftMargin="20" rightMargin="20"
              topMargin="20" bottomMargin="20">

    <field name="description" class="java.lang.String"/>

    <detail>
        <band height="51" splitType="Stretch">
            <textField>
                <reportElement x="100" y="100" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String">
                    <![CDATA[$F{description}]]></textFieldExpression>
            </textField>

            <textField>
            <reportElement x="100" y="100" width="100" height="20"/>
            <textElement/>
            <textFieldExpression class="java.lang.String">
                <![CDATA[$P{description}]]></textFieldExpression>
        </textField>

        </band>
    </detail>

</jasperReport>

By now I am just trying to print description (not even with a loop).

public ModelAndView  getAllInfo() {
    JasperReportsPdfView view = new JasperReportsPdfView();
    ClassLoader classLoader = getClass().getClassLoader();
    view.setUrl("classpath:report.jrxml");
    view.setApplicationContext(appContext);
    Map<String, Object> params = new HashMap<>();
    params.put("datasource", providerService.findOne(1l)); //tried also sending a list
    params.put("description", "test 123");
    params.put("id", "1");
    return new ModelAndView(view, params);
}

But no luck… any idea what im missing?

I get error saying no parameter of name description was set

Caused by: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 
     1. Parameter not found : description

When I remove

<textFieldExpression class="java.lang.String">
                    <![CDATA[$P{description}]]></textFieldExpression>
            </textField>

I stop seeing that error but a white pdf appears, no info printed.

Ideas?

How to create role user login?

I want to create a role user to login. So I am still confused how to create user role and login with role user. I have made some source code as below :

User.java :

package com.practice.login.entity;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "user")
public class User {
    private Long id;
    private String username;
    private String password;
    private String passwordConfirm;
    private Set<Role> roles;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long idUser) {
        this.id = idUser;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Transient
    public String getPasswordConfirm() {
        return passwordConfirm;
    }

    public void setPasswordConfirm(String passwordConfirm) {
        this.passwordConfirm = passwordConfirm;
    }

    @ManyToMany
    @JoinTable(
            name = "user_role", 
            joinColumns = @JoinColumn(
                    name = "user_id"), 
            inverseJoinColumns = @JoinColumn(
                    name = "role_id"))
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }
}

Role.java

package com.practice.login.entity;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "role")
public class Role {
    private Long id;
    private String name;
    private Set<User> users;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(mappedBy = "roles")
    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }
}

UserService.java :

package com.practice.login.service;

import com.practice.login.entity.User;

public interface UserService {

    void save(User user);

    User findByUsername(String username);

}

UserServiceImpl.java

package com.practice.login.service;

import com.practice.login.entity.User;
import com.practice.login.repository.RoleRepository;
import com.practice.login.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.HashSet;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private RoleRepository roleRepository;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public void save(User user) {
        user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
        user.setRoles(new HashSet<>(roleRepository.findAll()));
        userRepository.save(user);
    }

    @Override
    public User findByUsername(String username) {
        return userRepository.findByUsername(username);
    }
}

UserDetailServiceImpl.java

package com.practice.login.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.practice.login.entity.Role;
import com.practice.login.entity.User;
import com.practice.login.repository.UserRepository;

import java.util.HashSet;
import java.util.Set;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserRepository userRepository;

    @Override
    @Transactional(readOnly = true)
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepository.findByUsername(username);
        Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
        for (Role role : user.getRoles()) {
            grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
        }

        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
                grantedAuthorities);
    }
}

UserRepository.java

package com.practice.login.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.practice.login.entity.User;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    User findByUsername(String username);
}

RoleRepository.java

package com.practice.login.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.practice.login.entity.Role;

@Repository
public interface RoleRepository extends JpaRepository<Role, Long> {
}

How to login with role privilages?

Get Auth Token to call keycloak admin

Hi I am trying to call keycloak with the getInstance method.
However I cannot see where to get the auth Token.

FYI. The user is already logged in and has a keycloaksecurity context and has the correct rights…

My code below

private Keycloak getKeyCloakInstance() {
        final Authentication keyCloakAuth = SecurityContextHolder.getContext().getAuthentication();
        final KeycloakPrincipal<?> principal = (KeycloakPrincipal<?>) ((KeycloakAuthenticationToken) keyCloakAuth)
                .getPrincipal();
        realm = principal.getKeycloakSecurityContext().getRealm();


        // THIS DOES NOT WORK !!!!!! WHERE CAN I GET THIS TOKEN?? 
        // Keycloak.getInstance(AUTH_URL,REALM,CLIENT_ID,token);

   // THIS WORKS with the user who is connected
    // Keycloak.getInstance(env.getProperty(AUTH_URL,REALM, USER, PASS,
            CLIENT_ID);
}

I have tried with the tokenId found in the securitycontext.. but can’t get it to work..

Print patient data on Claims HCFA 1500 form

I have a pre-printed HCFA Claim form and I want to print only patient data on that. I am trying to achieve this functionality using Jasper Report, but not able to find the proper dimension for all the elements.
I have gone through this link How can I move the whole layout to adapt to pre-printed form on different printers,
But I don’t know the full size of that form in the pixel.

Actually, I want proper sizing and dimensions of the HCFA form components. Can anyone please help me out with this problem.

So could anyone please help me out in this problem.

Thanks in advance.

Creating a method of geometricmean in main JAVA

Asked me to write a program which should calculate a geometricmean but all the numbers should come from the command line and I have that source of my program:

public class Srednia_geom {
public static double geometricMean(double[] data){
double sum = data[0];

for (int i = 1; i < data.length; i++) {
    sum *= data[i]; 
}
return Math.pow(sum, 1.0 / data.length); 
}


public static void main(String[] args){

}

}

but unfortunetely… I don’t have any idea how to write the main method which may look like this after compliling: java Średnia_geom 1 3 5 7 8 to n. where n – lit of arguments. Could you help me, please?

Get page title of a native app using appium

It doesn’t seem that appium now has a direct way to get and verify the page of a native app, similar to the way it works on a web using the driver.getTitle(); method. Is this correct?

An indirect way I am using is the driver.findElement(By.xpath("")).getText(); method on the header text and then assert that the text is correct. With this method, there is no proof that the text fetched is definitely the title of the page as the text could also be contained in any part of the page.

Has anyone got a more genuine way of getting and verifying the page title of an iOS native app?

Online produktconfigurator

i need to create an online productconfigurator, but i have no plan how to do it. I am making an internship, but the firm i work in do not help me so i need to do it alone. The company uses wordpress for their own page, but i never used this before. In know the basics of HTML, PHP, JavaScript, C# and Java.

I hope someone can help me with my problem.

Greetings B3rgi

Hallo,
ich soll für eine Firma einen Produktkonfigurator erstellen, doch leider habe ich keine Ahnung wie ich das anstellen soll. Dieser Konfigurator soll als Projektarbeit für meine Abschlussprüfung dienen. Leider bin ich damit überfordert und vom Unternehmen kommt keine große Hilfe. Die Firma hat ihre Seite mit WordPress aufgebaut, damit hab ich leider auch keine Erfahrungen.
Ich besitze Grundkenntnisse in HTML, PHP, JavaScript, C# und Java.

Ich hoffe irgendwer kann mir helfen.

Grüße B3rgi

Selenium not waiting for page to load

I’m doing some tests with Selenium, and the tests have to login to a system. This login takes 17 seconds to fully happen.
The system has to wait for it to finish, otherwise the whole test fails.

I’ve tried many ways to do that, but all of them fail.

First code I’ve tried was this:

driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

When I use that, even though I tell it to wait for 100 seconds (which is almost 2 full minutes!), I get a timeout 2 seconds later with this stacktrace.

org.openqa.selenium.WebDriverException: timeouts
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'CMTCLX62137', ip: '53.19.227.206', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:UsersALEXAppDataLocalTemprust_mozprofile.Z2KJE568nWB8, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, proxy=Proxy(manual, http=localhost), specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0, platformVersion=6.1, moz:processID=21116.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: b2dca4a5-623a-4311-ad07-6444785dbcaf
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:868)

Another code I’ve tried:

new WebDriverWait(driver, 100).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript(
        "return document.readyState").equals("complete"));

Using this, it just doesn’t wait and I get a

org.openqa.selenium.NoSuchElementException: Unable to locate element

The only way for my test to work is using a Thread.sleep(), but this is a really bad option, because sometimes it loads faster than expected and sometimes it still fails because it takes more than 17s.

Any other option to wait for the page to fully load?

How to merge two mp3 files in java?

i have tow audio files and
i want to join that two audio files using java codding or any java Audio-Sound API.

 String wavFile1 = "D://SampleAudio_0.4mb.mp3";
     String wavFile2 = "D://wSampleAudio_0.7mb.mp3";
     AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1));
     AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));

     AudioInputStream appendedFiles = 
                     new AudioInputStream(
                         new SequenceInputStream(clip1, clip2),     
                         clip1.getFormat(), 
                         clip1.getFrameLength() + clip2.getFrameLength());

     AudioSystem.write(appendedFiles, 
                     AudioFileFormat.Type.WAVE, 
                     new File("D://merge1.mp3"));