Skip to content
Snippets Groups Projects
Commit acef5f8f authored by Danae Savvidi's avatar Danae Savvidi :laughing:
Browse files

Merge branch 'development' into 271-create-an-organisation-entity

parents d6cbe78c b4634560
Branches
No related tags found
1 merge request!419Resolve "Create an organisation entity"
Showing
with 365 additions and 7 deletions
......@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Button added to switch to dark theme. @rgiedryte
- Add HeadTA Job Offers @toberhuber @dsavvidi
- Added JobHolder and Project Entity @mmadara
### Changed
### Fixed
......
......
......@@ -70,7 +70,7 @@ public class ErrorController extends ResponseEntityExceptionHandler {
* @return The page to load
*/
@ResponseStatus(FORBIDDEN)
@ExceptionHandler({ AccessDeniedException.class, WebClientResponseException.Forbidden.class })
@ExceptionHandler({ AccessDeniedException.class })
public String forbidden() {
return "error/403";
}
......
......
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.model;
import java.util.HashSet;
import java.util.Set;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.experimental.SuperBuilder;
@Data
@Entity
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class JobHolder {
@Id
protected String id;
@NotNull
@Builder.Default
@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "holder")
private Set<JobOffer> jobOffers = new HashSet<>();
public JobHolder(String id) {
this.id = id;
this.jobOffers = new HashSet<>();
}
}
......@@ -44,7 +44,11 @@ public class JobOffer {
private Long id;
@NotNull
private Long editionId;
private Long editionId; //TODO: Remove this field
@Nullable
@ManyToOne
private JobHolder holder;
@NotBlank
@Builder.Default
......
......
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.model;
import javax.validation.constraints.NotNull;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/*
* TODO: once suborganisation is implemented, change JobHolder to SubOrganisation and add a one to one
* ProjectJobOffers entity
*/
@Data
@Entity
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Project extends JobHolder {
@NotNull
@OneToOne
private ProjectId projectId;
@NotNull
private String name;
@NotNull
@ManyToOne
private TAMProgram organisation; //TODO: once Organisation is implemented, change TAMProgram to Organisation
@PrePersist
private void prePersist() {
this.id = "project-" + projectId.getId(); // Avoid overlap with IDs of other JobHolders
}
}
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.model;
import javax.annotation.Nullable;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@Entity
public class ProjectId {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Nullable
@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToOne(mappedBy = "projectId")
private Project project;
public ProjectId() {
}
public ProjectId(Long id) {
this.id = id;
}
}
......@@ -23,6 +23,7 @@ import java.util.Set;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotNull;
import lombok.*;
......@@ -52,4 +53,11 @@ public class TAMProgram {
@ManyToMany(mappedBy = "advertisesTo")
private Set<Organisation> advertisedToBy = new HashSet<>();
@NotNull
@Builder.Default
@ToString.Exclude
@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "organisation")
private Set<Project> projects = new HashSet<>(); // TODO move this to organisations, and change the field type to Set<SubOrganisation> when possible
}
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import nl.tudelft.tam.model.JobHolder;
public interface JobHolderRepository extends JpaRepository<JobHolder, String> {
}
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import nl.tudelft.tam.model.ProjectId;
public interface ProjectIdRepository extends JpaRepository<ProjectId, Long> {
}
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import nl.tudelft.tam.model.Project;
public interface ProjectRepository extends JpaRepository<Project, String> {
}
......@@ -938,6 +938,8 @@ databaseChangeLog:
oldColumnName: hidden
columnDataType: bit
tableName: job_offer
- changeSet:
id: 1740585090326-1
author: dsav (generated)
......@@ -951,3 +953,7 @@ databaseChangeLog:
type: ENUM('HEAD_TA', 'TA', 'TA_OR_HEAD_TA')
defaultValue: 'TA_OR_HEAD_TA'
tableName: job_offer
## TAM Improvement
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.model;
import org.springframework.data.jpa.repository.JpaRepository;
// TODO change this for the real TAMEditionRepository when it exists
public interface EditionRepository extends JpaRepository<JobHolderTest.Edition, String> {
}
/*
* TAM
* Copyright (C) 2021 - Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package nl.tudelft.tam.model;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import application.test.TestTAMApplication;
import jakarta.persistence.Entity;
import nl.tudelft.tam.repository.JobHolderRepository;
import nl.tudelft.tam.repository.ProjectIdRepository;
import nl.tudelft.tam.repository.ProjectRepository;
import nl.tudelft.tam.repository.TAMProgramRepository;
@SpringBootTest(classes = { TestTAMApplication.class, JobHolderTest.class })
public class JobHolderTest {
private final ProjectRepository projectRepository;
private final TAMProgramRepository programRepository;
private final ProjectIdRepository projectIdRepository;
private final EditionRepository editionRepository;
private final JobHolderRepository jobHolderRepository;
@Autowired
public JobHolderTest(ProjectRepository projectRepository, TAMProgramRepository programRepository,
ProjectIdRepository projectIdRepository, EditionRepository editionRepository,
JobHolderRepository jobHolderRepository) {
this.projectRepository = projectRepository;
this.programRepository = programRepository;
this.projectIdRepository = projectIdRepository;
this.editionRepository = editionRepository;
this.jobHolderRepository = jobHolderRepository;
}
@Test
public void jobHolderIdsCanBeAutoGeneratedOrSetManually() {
TAMProgram program = programRepository.save(TAMProgram.builder().id(1L).build());
ProjectId projectId = projectIdRepository.save(new ProjectId());
Project project = new Project(projectId, "name", program);
project = projectRepository.save(project);
assertThat(project.getId()).isEqualTo("project-" + projectId.getId());
Edition edition = new Edition("edition-1");
edition = editionRepository.save(edition);
assertThat(edition.getId()).isEqualTo("edition-1");
assertThat(jobHolderRepository.existsById("project-" + projectId.getId())).isTrue();
assertThat(jobHolderRepository.existsById("edition-1")).isTrue();
}
// TODO remove in favour of TAMEdition when it exists
@Entity
public static class Edition extends JobHolder {
public Edition() {
}
public Edition(String id) {
super(id);
}
}
}
......@@ -21,9 +21,11 @@
spring.profiles.active=testing
spring.jpa.hibernate.ddl-auto=validate
# TODO change back to validate
spring.jpa.hibernate.ddl-auto=create
spring.liquibase.change-log=classpath:/changelog-master.yaml
spring.liquibase.enabled=true
# TODO change back to true
spring.liquibase.enabled=false
spring.datasource.url=jdbc:h2:mem:testdb
......@@ -18,8 +18,10 @@
spring.profiles.active=test
spring.jpa.hibernate.ddl-auto=validate
spring.liquibase.enabled=true
# TODO change back to validate
spring.jpa.hibernate.ddl-auto=create
# TODO change back to true
spring.liquibase.enabled=false
spring.datasource.url=jdbc:h2:mem:testdb
spring.liquibase.change-log=classpath:/changelog-master.yaml
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment