Commit c1f100f6 authored by tbilos's avatar tbilos
Browse files

Merge main int fix/report

parents b165b4f7 fdd60658
Pipeline #123045 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());
}
}
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.sql.Date;
import java.util.HashSet;
import java.util.Set;
/**
* @author Tomáš Biloš
*
* Entity representing assignment of an agent in a mission. Contains report by agent participating in the mission and
* evaluation of his performance from his superiors.
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public class AgentAssignment {
@Id
@Column(name = "id", nullable = false)
@Getter
@Setter
private Long id;
@Getter
@Setter
private Date start;
@Getter
@Setter
private int durationInDays;
@OneToOne
@JoinColumn(name = "report_id")
@Getter
@Setter
private Report report;
@ManyToOne
@JoinColumn(name = "mission_id", referencedColumnName = "id")
@Getter
@Setter
private Mission mission;
@ManyToOne
@Getter
@Setter
private Agent agent;
public AgentAssignment() {}
@OneToMany
@Setter(AccessLevel.NONE)
private Set<PerformanceEvaluation> performanceEvaluations = new HashSet<>();
public void addPerformanceEvaluation(PerformanceEvaluation performanceEvaluation) {
performanceEvaluations.add(performanceEvaluation);
}
public void removePerformanceEvaluation(PerformanceEvaluation performanceEvaluation) {
performanceEvaluations.remove(performanceEvaluation);
}
// TODO equal & hashcode
}
......@@ -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
package cz.fi.muni.pa165.seminar4.group7.secretservice.entity;
import com.sun.istack.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import javax.persistence.*;
import java.util.List;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* @author Milan Mozolak
*/
@Entity
@Getter
@Setter
@Accessors(chain = true)
public class Country {
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String code;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String name;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String demographics;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String geography;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String communications;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String government;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String economy;
@NotNull
@Column(nullable = false)
@Getter
@Setter
private String military;
@Getter
@Setter
@Setter(AccessLevel.NONE)
@OneToMany(mappedBy = "country")
private List<Mission> missions;
private Set<Mission> missions = new HashSet<>();
public void addMission(Mission mission) {
missions.add(mission);
mission.setCountry(this);
}
public void removeMission(Mission mission) {
missions.remove(mission);
mission.setCountry(null);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Country country = (Country) o;
return id.equals(country.id) && code.equals(country.code);
return code.equals(country.code);
}
@Override
public int hashCode() {
return Objects.hash(id, code);
return Objects.hash(code);
}
}
......@@ -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) {
......
......@@ -8,6 +8,8 @@ import javax.persistence.*;
/**
* @author Jan Smejkal
*
* Entity to represent a performance of an agent in a mission. Contains text evaluation as well as rating.
*/
@Entity
@Getter
......@@ -19,9 +21,6 @@ public class PerformanceEvaluation {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private Report report;
private String evaluation;
private int rating;
......@@ -33,4 +32,5 @@ public class PerformanceEvaluation {
this.evaluation = evaluation;
}
// TODO equals & hashcode
}
\ No newline at end of file
......@@ -8,6 +8,8 @@ import javax.persistence.*;
/**
* @author Jan Smejkal
*
* Entity representing text report submited by an agent to his assignment.
*/
@Entity
@Getter
......@@ -21,9 +23,6 @@ public class Report {
private String report;
@OneToOne
private PerformanceEvaluation performanceEvaluation;
@OneToOne(mappedBy = "report")
private AgentAssignment agentAssignment;
......@@ -33,28 +32,5 @@ public class Report {
this.report = report;
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((report == null) ? 0 : report.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Report))
return false;
Report other = (Report) obj;
if (id == null) {
if (other.getReport() != null)
return false;
} else if (!report.equals(other.getReport()))
return false;
return true;
}
// TODO equals & hashcode
}
\ No newline at end of file
......@@ -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