#Builder.Default usage - default

I was wondering what is the difference if I'm using #Builder.Default or not for having a default value for a variable, for example in variable range.
#Builder
#Data
#Valid
#RequiredArgsConstructor
#AllArgsConstructor
#NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
public class BookRequest {
#Min(0)
#Max(9999)
#NotNull
private final Integer id;
#Min(1)
private final int genre;
#Nullable
#Builder.Default private Range range = Range.POPULAR;
#Nullable
private Range range = Range.POPULAR;
}

Related

React.js - get enum values from class in Spring Boot

I have a class:
#Data
#Entity
public class NewOrder {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "Id")
private int Id;
private Date createdAt = new Date();
private Type types;
public enum Type {
ONDELIVERY, INADVANCE
}
#ManyToMany
private List<Product> products = new ArrayList<>();
public void addProduct(Product product) {
this.products.add(product);
}
}
I want to show available enum values of Type in React form. How could I get them? Is it possible without creating a new class with its own controller?

How can I model a drone medication delivery system in a database structure?

I have thought extensively about it and came up with these 2 classes:
public class Drone {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#NotEmpty(message = "Serial Number is required")
#Size(max = 100)
private String serial_number;
private ModelType model;
#Max(500)
private int weight_limit;
#NotEmpty(message = "Battery capacity is required")
private BigDecimal battery_capacity;
private StateType state;
}
and
public class Medication {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#Pattern(regexp = "^[a-zA-Z0-9_-]*$")
private String name;
private float weight;
#Pattern(regexp = "^[a-zA-Z0-9_]*$")
private String code;
#Column(nullable = true, length = 64)
private String image;
}
But I just can't figure out how to link them since each drone will be carrying medications. I still think I'm missing something. Any ideas?

Cannot Convert String to Timespamp inside REST

Hello:) i really hope i can find help here!
the Problem: Im using Spring JPA, have created a basic REST Service, i added my Database, and i can find data in the databaste via entitymanager.createQuery()
BUT when i try to search for a timestamp or a datetime, it gives me this error:
15:12 SELECT b FROM StationsMessung b WHERE b.AVNR=:AVNR AND
b.TXNR=:TXNR AND b.DBTM=:DATUM
java.lang.ClassCastException: java.lang.String cannot
be cast to java.util.Date
at org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor.unwrap(JdbcTimestampTypeDescriptor.java:24)
at org.hibernate.type.descriptor.sql.TimestampTypeDescriptor$1.doBind(TimestampTypeDescriptor.java:48)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:628)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2001)
at
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1915)
at org.hibernate.... (show balloon)
i know it says it cannot convert String to java.util.Date, but i dont know how to solve it.thanks for every helper!
/////////////////////////////////////////////////////////ENTITY CLASS
#Entity
#IdClass(StationsMessung.class)
#Table(name = "****", schema = "***")
public class StationsMessung implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "AVNR")
private int AVNR; ////
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "TXNR")
private int TXNR;
#GeneratedValue(strategy = GenerationType.AUTO)
#Temporal(TemporalType.TIMESTAMP)
#Type(type = "date")
#Column(name = "DBTM")
private Timestamp DBTM;
public StationsMessung(int AVNR, int TXNR, Timestamp DBTM) {
this.AVNR = AVNR;
this.TXNR = TXNR;
this.DBTM = DBTM;
}
public StationsMessung() {
}
public int getAvnr() {
return AVNR;
}
public void setAvnr(int AVNR) {
this.AVNR = AVNR;
}
public int getTxnr() {
return TXNR;
}
public void setTxnr(int TXNR) {
this.TXNR = TXNR;
}
public Timestamp getDBTM() {
return DBTM;
}
public void setDBTM(Timestamp DBTM) {
this.DBTM = DBTM;
}
///////////////////////////////////////////////////////////SERVICE CLASS
#Service
public class StationService {
#PersistenceContext
EntityManager entityManager;
public List<Station> getAllStationMessungen(int AVNR, int TXNR, Timestamp DATUM) {
return entityManager.createQuery("SELECT b FROM StationsMessung b WHERE b.AVNR=:AVNR AND b.TXNR=:TXNR AND b.DBTM=:DATUM")
.setParameter("TXNR",TXNR )
.setParameter("AVNR",AVNR )
.setParameter("DATUM", DATUM)
.getResultList();
}
////////////////////////////////////////////////////////////CONTROLER CLASS
#RestController
#RequestMapping("/station")
public class StationController {
#Autowired //This annotation allows Spring to resolve and inject
collaborating beans into your bean
StationService stationService; //service
#RequestMapping(value = "/allmessungen/{AVNR}/{TXNR}/{DATUM}", method =
RequestMethod.GET)
public List<Station> getAllStationMessungen(#PathVariable int AVNR, int
TXNR, Timestamp DATUM) {
return stationService.getAllStationMessungen( AVNR, TXNR, DATUM);
}
now when i search for data without the timestamp,it shows me data,it works.
when i use a timestamp or date it shows me the error above.
THE INPUT OF ME IS:
PARAM.1 AVNR: 716
PARAM.2 TXNR: 1339
PARAM.3 DBTM: 2014-01-04 05:30:00
(its this format yyyy-mm-dd-hh24:mi:ss)
thanks for every help:)

Room database with one-to-much relation

I have 2 Entities: Employee and Specialty.
Every Employee can have some Specialties.
POJOs are generated.
#Entity(indices = {#Index(value = {"f_name", "l_name", "birthday",
"avatarLink"}, unique = false)}, inheritSuperIndices = true)
public class Employee implements Serializable {
#PrimaryKey(autoGenerate = true)
private int employeeId;
private String f_name;
private String l_name;
private String birthday;
#Ignore
private int age;
private String avatarLink;
#Embedded
private List<Specialty> specialty;
private final static long serialVersionUID = -8824149947485321362L;
#Ignore
public Employee() {
}
public Employee(int employeeId, String f_name, String l_name, String
birthday, String avatarLink, List<Specialty> specialty) {
this.employeeId = employeeId;
this.f_name = f_name;
this.l_name = l_name;
this.birthday = birthday;
this.avatarLink = avatarLink;
this.specialty = specialty;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
And some more setters\getters...
And Specialty
#Entity
public class Specialty implements Serializable {
#PrimaryKey
private int specId;
private String specName;
private final static long serialVersionUID = 4288061416169200241L;
public Specialty(int specId, String specName) {
this.specId = specId;
this.specName = specName;
}
#Ignore
public Specialty() {
}
public int getSpecId() {
return specId;
}
And some more setters\getters...
I have this error:
error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
I check so many questions and read docs, but it not helps me. Thank you
you should add #Ignore to serialVersionUID fields.
In view of Room, it's just another column.
#Ignore
private final static long serialVersionUID = 4288061416169200241L;

EJB Find element's parameter ManyToOne

I have two classes related by ManyToOne, I have the id of "Chantier" and I'd like to find all the Lots which have this chantier's id.
public class Chantier implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String titre_aff;
private String num_aff;
private String ville;
public class Lots implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
List<String> numero_lot;
List<String> designation;
#ManyToOne
private Chantier chantier;
I tried with this in my LotsREST but it is looking for Lots with this id and not chantier :
#GET
#Path("{id}")
#Produces(MediaType.APPLICATION_JSON)
public Lots getLotByChantier(#PathParam("id") String id) {
return faL.find(Long.parseLong(id));
}
I just created this function to return what i wanted
#GET
#Path("{id}")
#Produces(MediaType.APPLICATION_JSON)
public List<Lots> getLotByChantier(#PathParam("id") String id) {
List<Lots> listLots = faL.findAll();
for (Lots lot : listLots) {
if (!lot.getChantier().getId().equals(Long.parseLong(id))) {
listLots.remove(lot);
}
}
return listLots;
}

Resources