Commit 6b3ab8b9 authored by tbilos's avatar tbilos
Browse files

Merge branch 'main' into 16-change-relationship

parents 0a801139 4d03e523
Pipeline #123034 waiting for manual action with stage
package cz.fi.muni.pa165.seminar4.group7.secretservice.dao;
import cz.fi.muni.pa165.seminar4.group7.secretservice.entity.Agent;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* @author Juraj Fiala
*/
public interface AgentDao {
void create(Agent a);
List<Agent> findAll();
Agent findById(Long id);
void remove(Agent a);
public interface AgentDao extends CrudRepository<Agent, Long> {
}
package cz.fi.muni.pa165.seminar4.group7.secretservice.dao;
import cz.fi.muni.pa165.seminar4.group7.secretservice.entity.Agent;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
/**
* @author Juraj Fiala
*/
@Repository
public class AgentDaoImpl implements AgentDao {
@PersistenceContext
private EntityManager em;
public AgentDaoImpl(EntityManager em) {
this.em = em;
}
@Override
public void create(Agent a) {
em.persist(a);
}
@Override
public List<Agent> findAll() {
return em.createQuery("select a from Agent a", Agent.class).getResultList();
}
@Override
public Agent findById(Long id) {
return em.find(Agent.class, id);
}
@Override
public void remove(Agent a) {
em.remove(a);
}
}
\ No newline at end of file
package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author Juraj Fiala
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public class Agent {
@Id
@Getter
@Setter
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany
@Getter
@Setter(AccessLevel.NONE)
private List<Skill> skills = new ArrayList<>();
@Getter
@Setter
private String training;
private String training = "";
@OneToMany
@Getter
private List<CodeName> codeNames;
@Setter(AccessLevel.NONE)
private List<CodeName> codeNames = new ArrayList<>();
@OneToMany(mappedBy = "agent")
@Getter
......@@ -42,7 +44,28 @@ public class Agent {
codeNames.add(codeName);
}
public void removeCodeName(CodeName codeName) {
codeNames.remove(codeName);
}
public void addSkill(Skill skill) {
skills.add(skill);
}
public void removeSkill(Skill skill) {
skills.remove(skill);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Agent)) return false;
Agent agent = (Agent) o;
return Objects.equals(getSkills(), agent.getSkills()) && Objects.equals(getTraining(), agent.getTraining()) && Objects.equals(getCodeNames(), agent.getCodeNames());
}
@Override
public int hashCode() {
return Objects.hash(getSkills(), getTraining(), getCodeNames());
}
}
......@@ -4,31 +4,37 @@ import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.Objects;
/**
* @author Juraj Fiala
*/
@Entity
@Getter
@Setter
public class CodeName {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@Getter
@Setter
private String codeName = "";
@ManyToOne
@Getter
@Setter
private Agent agent;
public CodeName(Agent agent, String codeName) {
this.agent = agent;
public CodeName(String codeName) {
this.codeName = codeName;
}
public CodeName() { }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CodeName)) return false;
CodeName codeName1 = (CodeName) o;
return Objects.equals(getCodeName(), codeName1.getCodeName());
}
@Override
public int hashCode() {
return Objects.hash(getCodeName());
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import cz.fi.muni.pa165.seminar4.group7.secretservice.enums.LanguageCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import javax.persistence.Entity;
......@@ -10,10 +11,10 @@ import javax.persistence.Entity;
* @author Juraj Fiala
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public class LanguageSkill extends Skill {
@Getter
@Setter
private LanguageCode languageCode;
public LanguageSkill(int level, LanguageCode languageCode) {
......
......@@ -2,22 +2,23 @@ package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import javax.persistence.*;
import java.util.Objects;
/**
* @author Juraj Fiala
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public abstract class Skill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@Getter
@Setter
private int level;
public Skill(int level) {
......@@ -25,4 +26,17 @@ public abstract class Skill {
}
public Skill() { }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Skill)) return false;
Skill skill = (Skill) o;
return getLevel() == skill.getLevel();
}
@Override
public int hashCode() {
return Objects.hash(getLevel());
}
}
......@@ -3,6 +3,7 @@ package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import cz.fi.muni.pa165.seminar4.group7.secretservice.enums.WeaponCategory;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import javax.persistence.Entity;
......@@ -10,10 +11,10 @@ import javax.persistence.Entity;
* @author Juraj Fiala
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public class WeaponSkill extends Skill {
@Getter
@Setter
private WeaponCategory weaponCategory;
public WeaponSkill() { }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment