Shruti
Shruti
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
i added this @Override
public String toString() {
return "Product{id=" + id + ", name='" + name + "', brand='" + brand + "', price=" + price + ", category='" + category + "', quantity=" + quantity + "}";
} and got results
public String toString() {
return "Product{id=" + id + ", name='" + name + "', brand='" + brand + "', price=" + price + ", category='" + category + "', quantity=" + quantity + "}";
} and got results
82 replies
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
controller package com.example.EcomTutDemo11.controller; import com.example.EcomTutDemo11.model.Product; import com.example.EcomTutDemo11.service.ProdcutService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/api")
public class Prodcontroller {

@Autowired
private ProdcutService service;
@GetMapping("/")
public String g()
{
return "hi";
}

@GetMapping("/products")
public List<Product> getAllProducts()
{
List<Product> products = service.getAllProducts();
System.out.println(" API /products was called!");
System.out.println("Fetched Products: " + products);
return products;
}
public class Prodcontroller {

@Autowired
private ProdcutService service;
@GetMapping("/")
public String g()
{
return "hi";
}

@GetMapping("/products")
public List<Product> getAllProducts()
{
List<Product> products = service.getAllProducts();
System.out.println(" API /products was called!");
System.out.println("Fetched Products: " + products);
return products;
}
82 replies
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
model package com.example.EcomTutDemo11.model; import jakarta.persistence.Entity; import jakarta.persistence.Id; import lombok.*; import java.math.BigDecimal; import java.util.Date; @Data @AllArgsConstructor @NoArgsConstructor @Getter @Setter @Entity
public class Product {
@Id
private int id;
private String name;
private String description;
private String brand;
private BigDecimal price;
private String category;
private Date releaseDate;
private boolean available;
private int quantity;


}
public class Product {
@Id
private int id;
private String name;
private String description;
private String brand;
private BigDecimal price;
private String category;
private Date releaseDate;
private boolean available;
private int quantity;


}
82 replies
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
service package com.example.EcomTutDemo11.service; import com.example.EcomTutDemo11.model.Product; import com.example.EcomTutDemo11.repo.ProductRepo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service
public class ProdcutService {
@Autowired
private ProductRepo repo;

public List<Product> getAllProducts(){

return repo.findAll();
}

}
public class ProdcutService {
@Autowired
private ProductRepo repo;

public List<Product> getAllProducts(){

return repo.findAll();
}

}
82 replies
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
package com.example.EcomTutDemo11.repo; import com.example.EcomTutDemo11.model.Product; import jakarta.persistence.criteria.CriteriaBuilder; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository
public interface ProductRepo extends JpaRepository<Product, Integer> {

}
public interface ProductRepo extends JpaRepository<Product, Integer> {

}
82 replies
JCHJava Community | Help. Code. Learn.
Created by Shruti on 4/1/2025 in #java-help
Issue: API Returning Empty JSON Objects {}
package com.example.EcomTutDemo11.service; import com.example.EcomTutDemo11.model.Product; import com.example.EcomTutDemo11.repo.ProductRepo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service
public class ProdcutService {
@Autowired
private ProductRepo repo;

public List<Product> getAllProducts(){

return repo.findAll();
}

}
public class ProdcutService {
@Autowired
private ProductRepo repo;

public List<Product> getAllProducts(){

return repo.findAll();
}

}
82 replies
JCHJava Community | Help. Code. Learn.
Created by Kale Vivi on 3/29/2025 in #java-help
Hexagonal architecture question
ok so let's assume both products have the exact same things you want to expose. Then you might have a new requirement in the future for one product but not the other. What are you doing now?
186 replies
JCHJava Community | Help. Code. Learn.
Created by Hype_the_Time (PING ON REPLY) on 3/27/2025 in #java-help
can not launch external service.
public static Intent launchGameBaseIntent(Context context, String profileId, String userDetail) {
Intent launchIntent = new Intent("net.kdt.pojavlaunch.action.START_PROFILE");
// launchIntent.putExtra("profile_id", profileId);
// launchIntent.putExtra("launch_user", userDetail);
// Specify the package name of the target application.
launchIntent.setComponent(new ComponentName("net.kdt.pojavlaunch.debug", "net.kdt.pojavlaunch.api.StartMinecraftService"));
context.startService(launchIntent);
return launchIntent;
}
public static Intent launchGameBaseIntent(Context context, String profileId, String userDetail) {
Intent launchIntent = new Intent("net.kdt.pojavlaunch.action.START_PROFILE");
// launchIntent.putExtra("profile_id", profileId);
// launchIntent.putExtra("launch_user", userDetail);
// Specify the package name of the target application.
launchIntent.setComponent(new ComponentName("net.kdt.pojavlaunch.debug", "net.kdt.pojavlaunch.api.StartMinecraftService"));
context.startService(launchIntent);
return launchIntent;
}
118 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Shift.class)
.filter(shift -> shift.getEmployee() != null) // Ensure shift has an employee
.groupBy(shift -> shift.getEmployee(), // Group shifts by employee
ConstraintCollectors.sumLong(shift -> Duration.between(shift.getStart(), shift.getEnd()).toMinutes())) // Sum total assigned minutes
.filter((employee, totalShiftMinutes) -> {
long fullTimeMinutes = 160 * 60; // 9600 minutes per month (assuming full-time is 160 hours)
long employeeAvailableMinutes = (employee.getWorkPercentage() * fullTimeMinutes) / 100;
return totalShiftMinutes > employeeAvailableMinutes; // Penalize if assigned shifts exceed allowed minutes
})
.penalize(HardSoftBigDecimalScore.ONE_HARD)
.asConstraint("Employee work percentage exceeded");
}
Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Shift.class)
.filter(shift -> shift.getEmployee() != null) // Ensure shift has an employee
.groupBy(shift -> shift.getEmployee(), // Group shifts by employee
ConstraintCollectors.sumLong(shift -> Duration.between(shift.getStart(), shift.getEnd()).toMinutes())) // Sum total assigned minutes
.filter((employee, totalShiftMinutes) -> {
long fullTimeMinutes = 160 * 60; // 9600 minutes per month (assuming full-time is 160 hours)
long employeeAvailableMinutes = (employee.getWorkPercentage() * fullTimeMinutes) / 100;
return totalShiftMinutes > employeeAvailableMinutes; // Penalize if assigned shifts exceed allowed minutes
})
.penalize(HardSoftBigDecimalScore.ONE_HARD)
.asConstraint("Employee work percentage exceeded");
}
Finally its working :3 thank you for your help
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Employee.class)
.join(Shift.class, equal(Employee::getName, Shift::getEmployee)) // Join Employee and Shift on Employee
.filter((employee, shift) -> {
long fullTimeMinutes = 160 * 60; // 40 hours/week * 60 minutes/hour (2400 minutes)
// Get the employee's total work time in minutes based on their work percentage
long employeeWorkMinutes = (employee.getWorkPercentage() * fullTimeMinutes) / 100;

// Get the shift duration in minutes
long shiftMinutes = Duration.between(shift.getStart(), shift.getEnd()).toMinutes();

// Calculate the new available work time in minutes after the shift is assigned
long newEmployeeWorkMinutes = employeeWorkMinutes - shiftMinutes; // Subtract shift duration

// Ensure that the employee's total work minutes doesn't go below 0
return newEmployeeWorkMinutes >= 0;
})
.penalize(HardSoftBigDecimalScore.ONE_HARD)
.asConstraint("Employee work percentage exceeded");
}
Constraint workPercentage(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Employee.class)
.join(Shift.class, equal(Employee::getName, Shift::getEmployee)) // Join Employee and Shift on Employee
.filter((employee, shift) -> {
long fullTimeMinutes = 160 * 60; // 40 hours/week * 60 minutes/hour (2400 minutes)
// Get the employee's total work time in minutes based on their work percentage
long employeeWorkMinutes = (employee.getWorkPercentage() * fullTimeMinutes) / 100;

// Get the shift duration in minutes
long shiftMinutes = Duration.between(shift.getStart(), shift.getEnd()).toMinutes();

// Calculate the new available work time in minutes after the shift is assigned
long newEmployeeWorkMinutes = employeeWorkMinutes - shiftMinutes; // Subtract shift duration

// Ensure that the employee's total work minutes doesn't go below 0
return newEmployeeWorkMinutes >= 0;
})
.penalize(HardSoftBigDecimalScore.ONE_HARD)
.asConstraint("Employee work percentage exceeded");
}
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
{
"employees": [
{
"name": "Alice",
"skills": ["Nursing", "CPR"],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": ["MORNING","NIGHT"],
"workPercentage": 0
},
{
"name": "Bob",
"skills": ["Medical Assistance", "Nursing"],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": ["NIGHT","MORNING"],
"workPercentage": 100
}
],
"shifts": [
{
"id": "2027-02-03-night1",
"start": "2025-02-03T07:00",
"end": "2025-02-03T10:00",
"location": "Hospital",
"requiredSkill": "Nursing"
},
{
"id": "2027-02-01-night2",
"start": "2025-02-01T22:00",
"end": "2025-02-01T23:59",
"location": "Hospital",
"requiredSkill": "Nursing"
}
]
}
{
"employees": [
{
"name": "Alice",
"skills": ["Nursing", "CPR"],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": ["MORNING","NIGHT"],
"workPercentage": 0
},
{
"name": "Bob",
"skills": ["Medical Assistance", "Nursing"],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": ["NIGHT","MORNING"],
"workPercentage": 100
}
],
"shifts": [
{
"id": "2027-02-03-night1",
"start": "2025-02-03T07:00",
"end": "2025-02-03T10:00",
"location": "Hospital",
"requiredSkill": "Nursing"
},
{
"id": "2027-02-01-night2",
"start": "2025-02-01T22:00",
"end": "2025-02-01T23:59",
"location": "Hospital",
"requiredSkill": "Nursing"
}
]
}
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
"shifts": [
{
"id": "2027-02-01-night1",
"start": "2025-02-01T07:00:00",
"end": "2025-02-01T10:00:00",
"location": "Hospital",
"requiredSkill": "Nursing",
"shiftType": "MORNING",
"employee": {
"name": "Alice",
"skills": [
"Nursing",
"CPR"
],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": [
"NIGHT",
"MORNING"
],
"workPercentage": 0
}
},
{
"id": "2027-02-01-night1",
"start": "2025-02-01T07:00:00",
"end": "2025-02-01T10:00:00",
"location": "Hospital",
"requiredSkill": "Nursing",
"shiftType": "MORNING",
"employee": {
"name": "Alice",
"skills": [
"Nursing",
"CPR"
],
"unavailableDates": [],
"undesiredDates": [],
"desiredDates": [],
"shiftPreferences": [
"NIGHT",
"MORNING"
],
"workPercentage": 0
}
},
154 replies
JCHJava Community | Help. Code. Learn.
Created by dghf on 3/19/2025 in #java-help
Issues with Contract Work Percentage Constraint in Employee Scheduling
154 replies
JCHJava Community | Help. Code. Learn.
Created by Suika on 2/18/2025 in #java-help
Spring Boot, JavaScript fetching Endpoint
and send it: const csrfToken = getCsrfToken();
const response = await fetch('/api/get-seconds', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'X-CRSF': csrfToken
},
body: JSON.stringify({ fachId}) // Send fachId in a JSON object
});
const response = await fetch('/api/get-seconds', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'X-CRSF': csrfToken
},
body: JSON.stringify({ fachId}) // Send fachId in a JSON object
});
222 replies
JCHJava Community | Help. Code. Learn.
Created by userexit on 2/16/2025 in #java-help
Help designin products model spring boot
@startuml
map Product {
1 => id
2 => name
3 => description
}
map ProductVariant {
1 => id
2 => product_id
3 => design_id
4 => price
5 => stock
6 => color
7 => size_id
}
map Design {
1 => id
2 => name
3 => license_fee
}
map Size {
1 => id
2 => size_name (xxl, xl, l, s etc.)
}
map Character {
1 => id
2 => character_name
}

map Design2Character {
1 => design_id
2 => character_id
}
map Product {
1 => id
2 => name
3 => description
}
map ProductVariant {
1 => id
2 => product_id
3 => design_id
4 => price
5 => stock
6 => color
7 => size_id
}
map Design {
1 => id
2 => name
3 => license_fee
}
map Size {
1 => id
2 => size_name (xxl, xl, l, s etc.)
}
map Character {
1 => id
2 => character_name
}

map Design2Character {
1 => design_id
2 => character_id
}
ProductVariant::product_id --> Product::id ProductVariant::design_id --> Design::id ProductVariant::size_id --> Size::id Design2Character::design_id --> Design::id Design2Character::character_id --> Character::id @enduml
74 replies
JCHJava Community | Help. Code. Learn.
Created by userexit on 2/16/2025 in #java-help
Help designin products model spring boot
public class ProductFormat {
public Product product;
public Format format;
}
public class ProductFormat {
public Product product;
public Format format;
}
74 replies
JCHJava Community | Help. Code. Learn.
Created by fhaedl on 2/13/2025 in #java-help
SPRING SECURITY
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").authenticated()
.anyRequest().permitAll()
)
.httpBasic(Customizer.withDefaults()) // Enable Basic Authentication
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(Customizer.withDefaults()) // Enable OAuth2 Resource Server
);
return http.build();
}
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").authenticated()
.anyRequest().permitAll()
)
.httpBasic(Customizer.withDefaults()) // Enable Basic Authentication
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(Customizer.withDefaults()) // Enable OAuth2 Resource Server
);
return http.build();
}
6 replies
JCHJava Community | Help. Code. Learn.
Created by ysemoo_ on 2/9/2025 in #java-help
I keep getting this error when i try run JDK installer
6 replies
JCHJava Community | Help. Code. Learn.
Created by red on 2/8/2025 in #java-help
@MapsId not works
The User abstract entity: @Getter @Setter @Entity @NoArgsConstructor @Inheritance(strategy = InheritanceType.JOINED)
public abstract class User {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Getter
private Long id;
@Column(unique = true)
private String email;
private String password;

public List<Role> roles;
public User(LoginAndRegisterDto dto) {
this.email=dto.email();
this.password=dto.password();
}
public boolean isAdmin(){
return this.roles.contains(Role.ADMIN);
}

}
public abstract class User {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Getter
private Long id;
@Column(unique = true)
private String email;
private String password;

public List<Role> roles;
public User(LoginAndRegisterDto dto) {
this.email=dto.email();
this.password=dto.password();
}
public boolean isAdmin(){
return this.roles.contains(Role.ADMIN);
}

}
37 replies
JCHJava Community | Help. Code. Learn.
Created by MeetnotFound | 12400f - 3070 on 2/6/2025 in #java-help
Javafx Not importing
module com.example {
requires javafx.controls;
requires javafx.fxml;

opens com.example to javafx.fxml;
exports com.example;
}
module com.example {
requires javafx.controls;
requires javafx.fxml;

opens com.example to javafx.fxml;
exports com.example;
}
585 replies