
I need answer in JAVA: I have this written in Typescript but I need to write it in Java as part of java practice but I need help interpreting it into Java. //How to create RolePermission through endpoints static async addPermissions(roleId: number, permissionIds: number[]){ return permissionIds.map(async (permissionId) => { return await RolePermission.findOrCreate({where: {roleId: roleId, permissionId: permissionId}}); }); }

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

So RolePermission does not allow Static methods so I cannot create a findOrCreate() method in this class. And the addPermissions in RolePermissionServiceImpl requires a static method and not non-static. I am really confused here.
And can you help with the body for findOrCreate method. May be that will help understand a little more:
public static findOrCreate(Long roleId, Long permissionId){
}
I am getting an error: findOrCreate()
Cannot resolve method findOrCreate in RolePermission.
Also, when I try Option 3: The method cannot be reference if it is non-static. I'm not too familiar with it so do you suggest I make it static?
Below is my RolePermission Model:
@Entity
@Getter
@Setter
public class RolePermission {
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "Id")
// @Column(name = "id", nullable = false)
private Long id;
//
@ManyToOne(fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
// @ManyToOne
@JoinColumn(name = "roleId")
@JsonIgnore
Role role;
@ManyToOne(fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
// @ManyToOne
@JoinColumn(name = "permissionId")
// @JoinColumn(name = "permissionId", referencedColumnName = "permission",
// insertable = false,updatable = false)
@LazyToOne(LazyToOneOption.NO_PROXY)
@JsonIgnore
Permission permission;
@CreatedDate
@CreationTimestamp
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime createdAt;
@LastModifiedDate
@UpdateTimestamp
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime updatedAt;
}
So RolePermission does not allow Static methods so I cannot create a findOrCreate() method in this class. And the addPermissions in RolePermissionServiceImpl requires a static method and not non-static. I am really confused here.
And can you help with the body for findOrCreate method. May be that will help understand a little more:
public static findOrCreate(Long roleId, Long permissionId){
}
I am getting an error: findOrCreate()
Cannot resolve method findOrCreate in RolePermission.
Also, when I try Option 3: The method cannot be reference if it is non-static. I'm not too familiar with it so do you suggest I make it static?
Below is my RolePermission Model:
@Entity
@Getter
@Setter
public class RolePermission {
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "Id")
// @Column(name = "id", nullable = false)
private Long id;
//
@ManyToOne(fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
// @ManyToOne
@JoinColumn(name = "roleId")
@JsonIgnore
Role role;
@ManyToOne(fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
// @ManyToOne
@JoinColumn(name = "permissionId")
// @JoinColumn(name = "permissionId", referencedColumnName = "permission",
// insertable = false,updatable = false)
@LazyToOne(LazyToOneOption.NO_PROXY)
@JsonIgnore
Permission permission;
@CreatedDate
@CreationTimestamp
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime createdAt;
@LastModifiedDate
@UpdateTimestamp
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
LocalDateTime updatedAt;
}
- I need help explaining each and every line of the code functionality ========================================================== import React, { useState, useRef } from "react"; import Modal from "react-modal"; import { Cropper } from "react-advanced-cropper"; import "react-advanced-cropper/dist/style.css"; import { resizeImage } from "../util/Helper"; const ImageCropper = ({ modalIsOpen, closeModal, uploadImageData, setImageSrc, }) => { //customstyles constant is an object that defines the custom styles for the modal const customStyles = { content: { top: "50%", left: "50%", right: "auto", bottom: "auto", marginRight: "-50%", transform: "translate(-50%, -50%)", border: "none", backgroundColor: "transparent", }, }; const cropperRef = useRef(); const [image] = useState(uploadImageData); // gets the canvas and resize the image // sets the…arrow_forwardVariableReferenceNode.java, OperationNode.java, ConstantNode.java, and PatternNode.java must have their own java classes with the correct methods implemented: OperationNode: Has enum, left and Optional right members, good constructors and ToString is good VariableReferenceNode: Has name and Optional index, good constructors and ToString is good Constant & Node Pattern: Have name, good constructor and ToString is good Make sure to include the screenshot of the output of Parser.java as well.arrow_forwardWe have a parking office class for a parking management system. It has dependencies and relations with customer, car, parking lot and parking charge classes. Explain the code by stating implementation decisions, reasons behind those implementation decisions, what you assume was hard or easy to implement, and what helped. public class ParkingOffice {String name;String address;String phone;List<Customer> customers;List<Car> cars;List<ParkingLot> lots;List<ParkingCharge> charges; public ParkingOffice(){customers = new ArrayList<>();cars = new ArrayList<>();lots = new ArrayList<>();charges = new ArrayList<>();}public Customer register() {Customer cust = new Customer(name,address,phone);customers.add(cust);return cust;}public Car register(Customer c,String licence, CarType t) {Car car = new Car(c,licence,t);cars.add(car);return car;}public Customer getCustomer(String name) {for(Customer cust :…arrow_forward
- Assume class LinkedQueue has been deńned using the implementation in your textbook that myQueue has been initialized so it is empty. Type the EXACT output of the following code segment. You may assume that the code compiles and executes without errors. LinkedQueue myQueue; int i - 1; int j = 2; int k = 3; int n = 4; myQueue.enqueue (n); myQueue.enqueue (); i = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (k); n = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (); myQueue.enqueue (n); while (ImyQueue.isEmpty ()) { i = myQueue.peekFront (); myQueue.dequeue (); cout << i<< " ": cout << endl;arrow_forwardWhy is it necessary to implement all of the methods defined by an interface?arrow_forwardYou have to use comment function to describe what each line does import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class PreferenceData { private final List<Student> students; private final List<Project> projects; private int[][] preferences; private static enum ReadState { STUDENT_MODE, PROJECT_MODE, PREFERENCE_MODE, UNKNOWN; }; public PreferenceData() { super(); this.students = new ArrayList<Student>(); this.projects = new ArrayList<Project>(); } public void addStudent(Student s) { this.students.add(s); } public void addStudent(String s) { this.addStudent(Student.createStudent(s)); } public void addProject(Project p) { this.projects.add(p); } public void addProject(String p) { this.addProject(Project.createProject(p)); } public void createPreferenceMatrix() { this.preferences = new…arrow_forward
- What is the difference between the iterable interface and the iterator interface? Group of answer choices 1. If you implement the iterable interface you have an internal iterator and if you implement the iterator interface you will have an external interface. 2. If you implement the iterator interface you have an internal iterator and if you implement the iterable interface you will have an external interface. 3. An class that implements iterable has a method that returns an iterator, which will allow you to iterate through the data structure. 4. You can implement either interface to make it so you can iterate through a data structure, but you will have different named methods to do the iteration.arrow_forwardPlease write the code in Java usign this UML diagram. Add Comments.arrow_forwardEdit question USING C++ *Please explain in comments in the code of what you are doing and why Implement the GradedActivity class below. class GradedActivity { private: double score; public: GradedActivity() { score = 0.0; } GradedActivity(double s) { score = s; } void setScore(double s) { score = s; } double getScore() { return score; } char getLetterGrade() const; }; Create a new class Assignment which is derived from GradedActivity. It should have three private member ints for 3 different parts of an assignment score: functionality (max 50 points), efficiency (max 25 points), and style (max 25 points). Create member function set() in Assignment which takes three parameter ints and sets the member variables. It should also set its score member, which is inherited from GradedActivity, using the setScore() function, to functionality + efficiency + style. Signature: void Assignment::set(int, int, int) Create a main program which instantiates an Assignment, asks the user for its…arrow_forward
- In C++ Create a new project named lab9_1 . You will need to implement a Course class. Here is its UML diagram: Course - department : string- course_num : string- section : int- num_students : int- is_full : bool + Course()+ Course(string, string, int, int)+ setDepartment(string) : void+ setNumber(string) : void+ setSection(int) : void+ setStudents(int) : void+ getDepartment() const : string+ getNumber() const : string+ getSection() const : int+ getStudents() const : int+ print() const : void Create a sample file to read from: CSS 2A 1111 35 Additional information: The Course class has two constructors. Make sure you have default values for your default constructor. Each course maxes out at 40 students. Therefore, you need to make sure that there aren’t more than 40 students in a Course. You can choose how you handle situations where more than 40 students are added. Additionally, you should automatically set is_full to false or true, based on the number of…arrow_forwardIn C++ Create a new project named lab8_1. You will be implementing two classes: A Book class, and a Bookshelf class. The Bookshelf has a Book object (actually 3 of them). You will be able to choose what Book to place in each Bookshelf. Here are their UML diagrams Book class UML Book - author : string- title : string- id : int- count : static int + Book()+ Book(string, string)+ setAuthor(string) : void+ setTitle(string) : void+ print() : void+ setID() : void And the Bookshelf class UML Bookshelf - book1 : Book- book2 : Book- book3 : Book + Bookshelf()+ Bookshelf(Book, Book, Book)+ setBook1(Book) : void+ setBook2(Book) : void+ setBook3(Book) : void+ print() : void Some additional information: The Book class also has two constructors, which again offer the option of declaring a Book object with an author and title, or using the default constructor to set the author and title later, via the setters . The Book class will have a static member variable…arrow_forwardCode with java please. Critique the following code which is intended to print out whether or not a key value k1 is used in a map named relationships: if (relationships.get(k1) != null) System.out.println("yes it does"); else System.out.println("no it does not"); Now rewrite the code so that it works correctly.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





