Record square video

I use CameraView library. It’s cool library. It has height and width customizations.

I tried to change them. But unfortunately these settings are only for CameraView View, not for video. that is, when recording CameraView is square, and in preview video back to rectangular.

I tried to set the parameter in activity_main.xml app:cameraPictureSizeAspectRatio="1:1", but the result is the same

Question: Tell me how I can solve this problem, how to record video square as in instagram?

I’m having trouble turning this program from an if-else-if statement into a switch statement. Any help would be appreciated

I’m having trouble turning this program from an if-else-if statement into a switch statement. Any help would be appreciated.

public void tick() {
    if (s.word == 0)
        return;

    short t = this.sc.word;
    short d = this.get_opcode();
    short i = this.get_indirect_bit();

    if (t == 0 || t == 1)
        this.instruction_fetch(t);

    if (t == 2)
        this.instruction_decode();

    if (t == 3 && d != 7)
        this.operand_fetch(i);

    if (t > 3 && d != 7)
        this.execute_mri(d, t);

    if (t == 3 && d == 7) {
        this.execute_rri((short) (this.ir.word & 0xFFF));
    }
}

Invalid content was found starting with element ‘dependency’

I am new for that concept, I did’t understand what the error is, so somebody help me to correct this error.
I use the same version in my xml as in my pom file.
I want to set mybatis with spring (intellij)
I tried searching, so if you add tag to pom.xml, I can download the library automatically and know the setting is possible.
I already have added [mybatis-3.4.5.jar] to lib.

This is pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>GRU</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>


        <!-- MyBatis -->
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.2.8</version>

        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.2.2</version>

        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework-version}</version>

        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

</project>

and, this is error message

invalid content was found starting with element ‘dependency’. One of "http://mavenapache.org/POM/4.0.0"parent,
http://maven.apache.org/POM/4.0.0":name, "http:/mavenapache.org/POM/400":description, "http://mavenapache.org/POM/4.0.0":url,
"http://mavenapache.org/POM/4.0.0":prerequisites, "http://mavenapache.org/POM/4.0.0":issueManagement,
"http://mavenapache.org/POM/4.0.0":ciManagment, "http://mavenapache.org/POM/4.0.0":inceptionYear,
"http://mavenapache.org/POM/4.0.0":mailingLists, "http://mavenapache.org/POM/4.0.0":developers,
“http://mavenapache.org/POM/4.0.0":contributors, "http://mavenapacheorg/POM/4.0.0":licenses, "http://mavenapache.org/POM/400":scm ,
“http://mavenapache.org/POM/4.0.0":organization, "http://maven.apache.org/POM/4.0.0":build, "http://mavenapache.org/POM/400":profiles, “http://mavenapache.org/POM/4.0.0":modules, http://mavenapache.org/POM/4.0.0":repositories, “http://mavenapache.org/POM/4.0.0":plugin Repositories,"http://mavenapache.org/POM/400":dependencies, “http://mavenapache.org/POM/4.0.0":reports, http://mavenapache.org/POM/4.0.0":reporting, “http://mavenapache.org/POM/4.0.0":dependencyManagement, "http://maven.apache.org/POM/4.0.0":distributionManagement
http://mavenapache.org/POM/40.0.":properties)’ is expected.

java hibernate fetchtype eager works well, while fetchtype lazy ends up with an exception

Today I did some further experiments with hibernate.
There are books, users and rental in my database.
Each book knows about the matching rentals, each ren
tal knows about the matching book and the matching user and finally each user knows about the matching rentals.

Before giving a book to a user I want to check, if it was given back before.
Therefore I want to walk through the list of rents which are connected to the book and if there is one without a return date, I know that something is wrong.

Everything works fine, as long as I use fetchtype.EAGER in my book class.
Of course I would prefer LAZY because I have some other operations on books where no knowledge about the connected rents is needed.
But if I change to lazy I get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at org.hibernate.collection.internal.AbstractPersistentCollection.openTemporarySessionForLoading(AbstractPersistentCollection.java:275)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:198)
    at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:561)
    at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
    at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:277)
    at code.worker.Verleihworker.verleihen(Verleihworker.java:153)
    at code.worker.Verleihworker.access$5(Verleihworker.java:145)
    at code.worker.Verleihworker$3.actionPerformed(Verleihworker.java:135)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

I don’t really understand why that happens. I thought that lazy means, that the rents are loaded, as soon, as I need them.

package code.logik;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.ManyToAny;

@Entity
@Table(name="buch")
public class Buch {

    @Column(nullable=false)
    private String titel;
    private String autor;

    @ManyToOne
    private WlBuchart wlBuchart;

    @OneToMany(cascade=CascadeType.ALL, mappedBy="buch", fetch=FetchType.LAZY)
    private List<Leihstellung>leihstellungs;

    public WlBuchart getWlBuchart() {
        return wlBuchart;
    }

    public void setWlBuchart(WlBuchart wlBuchart) {
        this.wlBuchart = wlBuchart;
    }

    @Id
    private int nummer;



    public Buch(String titel, String autor,int nummer) {
        this.titel=titel; 
        this.autor=autor; 
        this.nummer=nummer;
        leihstellungs = new ArrayList<>();
    }

    public Buch() {
        // TODO Auto-generated constructor stub
    }


    public String getTitel() {
        return titel;
    }

    public String getAutor() {
        return autor;
    }



    public int getNummer() {
        return nummer;
    }

    public List<Leihstellung> getLeihstellungs() {
        return leihstellungs;
    }

    public void addLeihstellung(Leihstellung leihstellung)
    {
        leihstellungs.add(leihstellung);
    }

    public void removeLeihstellung(Leihstellung leihstellung)
    {
        leihstellungs.remove(leihstellung);
    }

    public void setTitel(String titel) {
        this.titel = titel;
    }

    public void setAutor(String autor) {
        this.autor = autor;
    }


}


package code.logik;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.Session;

@Entity
@Table(name="benutzer")
public class Benutzer {

    @Column(nullable=false)
    private String vorname, nachname, gruppe; 
    @Id
    private String kennung;
    private boolean admin;
    @Column(nullable=true)
    private String kennwort;

    @OneToMany(cascade=CascadeType.ALL, orphanRemoval =true, mappedBy="benutzer", fetch=FetchType.EAGER)
    private List<Leihstellung>leihstellungs;


    public String getKennwort() {
        return kennwort;
    }

    public void setKennwort(String kennwort) {
        this.kennwort = kennwort;
    }

    public Benutzer(String vorname, String nachname, String gruppe, String kennung) {
        this.vorname=vorname; 
        this.nachname=nachname; 
        this.gruppe=gruppe; 
        this.kennung=kennung;
        this.leihstellungs= new ArrayList<>();

    }

    public Benutzer() {
        // TODO Auto-generated constructor stub
    }

    public String getVorname() {
        return vorname;
    }

    public String getNachname() {
        return nachname;
    }

    public String getGruppe() {
        return gruppe;
    }

    public String getKennung() {
        return kennung;
    }

    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    public List<Leihstellung> getLeihstellungs() {
        return leihstellungs;
    }

    public void addLeihstellung(Leihstellung leihstellung)
    {
        leihstellungs.add(leihstellung);
    }



    public int compare(Benutzer other)
    {
        if (this.getNachname().compareTo(other.getNachname())!=0)
        {
            return this.getNachname().compareTo(other.getNachname());
        }
        return this.getVorname().compareTo(other.getVorname());
    }

    public void removeLeihstellungen(Session session)
    {
        for (Leihstellung current : leihstellungs)
        {
            current.removeFromBuch(session);
        }
        leihstellungs = null;
        session.update(this);
    }


}

package code.logik;

import java.time.LocalDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.Session;

@Entity
@Table(name="leihstellung")
public class Leihstellung {

    @ManyToOne
    private Benutzer benutzer; 

    @Id @GeneratedValue
    private int id;

    @Column(nullable=false)
    private LocalDate von;

    private LocalDate bis;

    @ManyToOne
    private Buch buch;

    public Leihstellung(Benutzer benutzer, Buch buch) {
        this.benutzer=benutzer; 
        this.buch=buch; 
        this.von = LocalDate.now();
    }

    public Leihstellung() {
        // TODO Auto-generated constructor stub
    }

    public void setAbgegeben()
    {
        bis = LocalDate.now();
    }

    public Benutzer getBenutzer() {
        return benutzer;
    }

    public int getId() {
        return id;
    }

    public LocalDate getVon() {
        return von;
    }

    public LocalDate getBis() {
        return bis;
    }

    public Buch getBuch() {
        return buch;
    }

    public void updateBenutzer()
    {
        benutzer = null;
    }

    public void removeFromBuch(Session session)
    {
        buch.removeLeihstellung(this);
        session.update(buch);
    }


}


package code.worker;

import java.awt.Desktop.Action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import org.hibernate.Session;

import Tools.Sessiongetter;
import code.logik.Benutzer;
import code.logik.Buch;
import code.logik.Leihstellung;
import code.logik.Worker;
import gui.Ausleihe;
import gui.RentError;

public class Verleihworker {

    private Ausleihe ausleihe; 
    private Buch buch;
    private Benutzer benutzer;
    private Worker worker;

    public Verleihworker(Ausleihe ausleihe, Worker worker) {
        this.ausleihe=ausleihe;
        this.worker=worker;
    }

    public void work()
    {
        MouseListener buchlistener = new MouseListener() {

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                Buchgetter buchgetter = new Buchgetter(); 
                Buch temp = null;
                try
                {
                    temp = buchgetter.getBuch(Integer.parseInt(ausleihe.getBuchText()));
                }
                catch (Exception ex)
                {

                }
                if (temp !=null)
                {
                    buch = temp;
                    ausleihe.setBuchText(buch.getTitel());
                }


            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        };

        MouseListener benutzerlistener = new MouseListener() {

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                Benutzergetter benutzergetter = new Benutzergetter(); 
                Benutzer temp = null;
                try
                {
                     temp = benutzer = benutzergetter.getBenutzer(ausleihe.getBenutzerText());
                }
                catch (Exception ex)
                {

                }
                if (temp!=null)
                {
                    benutzer=temp;
                    ausleihe.setBenutzerText(benutzer.getVorname()+" "+benutzer.getNachname());
                }


            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        };
        ActionListener al = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (buch!=null && benutzer !=null)
                {
                    verleihen();
                }

            }
        };
        ausleihe.addSchuelerListener(benutzerlistener);
        ausleihe.addBuchListener(buchlistener);
        ausleihe.addButtonListener(al);
    }

    private void verleihen()
    {
        Sessiongetter sg = new Sessiongetter(); 
        Session session = sg.getSesseion();
        session.beginTransaction();

        List<Leihstellung>buchLeihstellungen = buch.getLeihstellungs();
        boolean problem = false;
        for (Leihstellung aktuell : buchLeihstellungen)
        {
            if (aktuell.getBis()==null)
            {
                Benutzer hatNoch = aktuell.getBenutzer();
                problem=true;
                System.out.println("Das Buch mit dem Titel "+buch.getTitel()+" ist noch an "+hatNoch.getVorname()+" "+hatNoch.getNachname()+" verliehen");
                RentError rentError = new RentError(); 
                rentError.setText(" Das Bucht "+buch.getTitel()+" ist laut Datenbank noch an "+hatNoch.getVorname()+" "+hatNoch.getNachname()+" verliehen. Bitte verbuchen Sie erst die Rückgabe");
                worker.addView(rentError, "renterror");
                worker.showPanel("renterror");

                ActionListener al = new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        worker.showPanel("mm");
                        worker.removeCard("renterror");
                    }
                };
                rentError.addActionListener(al);
            }
        }
        if (!problem)
        {
            Leihstellung leihstellung = new Leihstellung(benutzer, buch);
            buch.addLeihstellung(leihstellung);
            benutzer.addLeihstellung(leihstellung);
            session.save(leihstellung);
            session.update(benutzer);
            session.update(buch);
            session.getTransaction().commit();
            session.close();
            sg.closeSessionFactory();

        }


    }



}

package Tools;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Sessiongetter {

    private SessionFactory sf; 

    private void init()
    {
        if (sf==null)
        {
            Configuration configuration = new Configuration().configure();
            sf = configuration.buildSessionFactory();
        }
    }

    public Session getSesseion()
    {
        init();
        return sf.openSession();
    }

    public void closeSessionFactory()
    {
        sf.close();
    }

}

<?xml version='1.0' encoding='utf-8'?>

<!--
  ~ Hibernate, Relational Persistence for Idiomatic Java
  ~
  ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  -->
<!DOCTYPE hibernate-configuration SYSTEM
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration
>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://192.168.2.252:5432/schulbib</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">postgres</property>

        <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
        <property name="hibernate.enable_lazy_load_no_trans">true</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->

        <mapping class="code.logik.Buch"/>
        <mapping class="code.logik.WlBuchart"/>
        <mapping class="code.logik.Benutzer"/>
        <mapping class="code.logik.Leihstellung"/>
    </session-factory>
</hibernate-configuration>

How can I convert my web app to Angular 4 without Node.js/NPM

I currently am using java/html/css/js for my web app. I want to add Angular 4 into my webapp without using Node.js or NPM. Instead I would like to use Java.

Does anyone have any recommendations, examples, or ways I could go about doing this?

I imported the angular.min.js file into my project directory and added in some demo Angular code but it’s not working. After running ng-build, I receive an error saying: “node_modules appears empty, you may need to run npm install

java HttpURLConnection convert to Spring RestTemplate

I have java code with HttpURLConnection and i want to convert this to Spring RestTemplate.

Method:

private static void post(String request, String urlStr) throws Exception {
    HttpURLConnection conn = null;
    try {
        URL url = new URL(urlStr);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);

        Map<String, String> params = new HashMap<>();
        params.put("OrderText", "Text");
        params.put("Order", request);
        try (OutputStream os = conn.getOutputStream()) {
            String postDataString = getPostDataString(params);
            os.write(postDataString.getBytes());
            os.flush();
        }
        try (BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())))) {
            String output;
            StringBuilder sb = new StringBuilder();
            while ((output = br.readLine()) != null) {
                sb.append(output);
            }
            System.out.println("result=" + sb.toString());
        }
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
}

private static String getPostDataString(Map<String, String> params) throws UnsupportedEncodingException {
    StringBuilder result = new StringBuilder();
    boolean first = true;
    for (Map.Entry<String, String> entry : params.entrySet()) {
        if (first) {
            first = false;
        } else {
            result.append("&");
        }
        result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        result.append("=");
        result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
    }
    return result.toString();
}

I’m just sending post request to some url, but I have 2 params and Order param it’s xml, so i’m using getPostDataString method to transform my params, and it’s works fine(i’m getting response spring and code 200).

And example on Spring RestTemplate:

 Map<String, String> params = new HashMap<>();
    params.put("OrderText", "Text");
    params.put("Order", request);
    String body = getPostDataString(params);
    String result = new RestTemplate().postForObject(url, body.getBytes(), String.class);
    System.out.println(result);

also tried

String result = new RestTemplate().postForObject(url, body, String.class);

and

String result = new RestTemplate().postForObject(url, new HttpEntity(body), String.class);

I’m always getting 500 from server. Unfortunately i don’t have access to server, so i can’t ask someone what’s wrong