diff --git a/CHANGELOG.md b/CHANGELOG.md index a2d79a036c6b62ee21fdec238e579864fbb185cb..9b8cb6d6bd5197ae76d87fa8badca1594c132666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/nl/tudelft/tam/model/JobHolder.java b/src/main/java/nl/tudelft/tam/model/JobHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..30063763dbcdea30a6bed060484129171f1d78d2 --- /dev/null +++ b/src/main/java/nl/tudelft/tam/model/JobHolder.java @@ -0,0 +1,50 @@ +/* + * 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<>(); + } +} diff --git a/src/main/java/nl/tudelft/tam/model/JobOffer.java b/src/main/java/nl/tudelft/tam/model/JobOffer.java index 05b16a1d84087ae1efe4592167daf798018e3fce..ac4413970518bed08947d5b430385bf3f18e234f 100644 --- a/src/main/java/nl/tudelft/tam/model/JobOffer.java +++ b/src/main/java/nl/tudelft/tam/model/JobOffer.java @@ -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 diff --git a/src/main/java/nl/tudelft/tam/model/Project.java b/src/main/java/nl/tudelft/tam/model/Project.java new file mode 100644 index 0000000000000000000000000000000000000000..b45bc3fed3423613f00a84e9ede99d91c07e33f1 --- /dev/null +++ b/src/main/java/nl/tudelft/tam/model/Project.java @@ -0,0 +1,57 @@ +/* + * 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 + } + +} diff --git a/src/main/java/nl/tudelft/tam/model/ProjectId.java b/src/main/java/nl/tudelft/tam/model/ProjectId.java new file mode 100644 index 0000000000000000000000000000000000000000..a8c269fc3f07f5cc75e69c9ed414ae715c29ba37 --- /dev/null +++ b/src/main/java/nl/tudelft/tam/model/ProjectId.java @@ -0,0 +1,48 @@ +/* + * 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; + } + +} diff --git a/src/main/java/nl/tudelft/tam/model/TAMProgram.java b/src/main/java/nl/tudelft/tam/model/TAMProgram.java index 787607e584644159d8189d074b67a0eb0d39edc2..27bd39f590063072769682f4faf5b4c5421840f6 100644 --- a/src/main/java/nl/tudelft/tam/model/TAMProgram.java +++ b/src/main/java/nl/tudelft/tam/model/TAMProgram.java @@ -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<TAMProgram> 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 + } diff --git a/src/main/java/nl/tudelft/tam/repository/JobHolderRepository.java b/src/main/java/nl/tudelft/tam/repository/JobHolderRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..0f1734d8f4d2380796cdcb2400c8f5584430bf5c --- /dev/null +++ b/src/main/java/nl/tudelft/tam/repository/JobHolderRepository.java @@ -0,0 +1,25 @@ +/* + * 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> { +} diff --git a/src/main/java/nl/tudelft/tam/repository/ProjectIdRepository.java b/src/main/java/nl/tudelft/tam/repository/ProjectIdRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..40a92438fb5f0c967c11aed414321d2825b28c04 --- /dev/null +++ b/src/main/java/nl/tudelft/tam/repository/ProjectIdRepository.java @@ -0,0 +1,25 @@ +/* + * 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> { +} diff --git a/src/main/java/nl/tudelft/tam/repository/ProjectRepository.java b/src/main/java/nl/tudelft/tam/repository/ProjectRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..49c5698eb74d6f115353dda122935a3258e07c52 --- /dev/null +++ b/src/main/java/nl/tudelft/tam/repository/ProjectRepository.java @@ -0,0 +1,25 @@ +/* + * 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> { +} diff --git a/src/main/resources/migrations.yaml b/src/main/resources/migrations.yaml index 13512a3b1c57c95e73e67a4d1a880c4ff8bf22d3..da5b90901d0e6f04011b23031ccf804113faa13b 100644 --- a/src/main/resources/migrations.yaml +++ b/src/main/resources/migrations.yaml @@ -938,6 +938,8 @@ databaseChangeLog: oldColumnName: hidden columnDataType: bit tableName: job_offer + + - changeSet: id: 1740585090326-1 author: dsav (generated) @@ -950,4 +952,8 @@ databaseChangeLog: name: offer_type type: ENUM('HEAD_TA', 'TA', 'TA_OR_HEAD_TA') defaultValue: 'TA_OR_HEAD_TA' - tableName: job_offer \ No newline at end of file + tableName: job_offer + +## TAM Improvement + + diff --git a/src/test/java/nl/tudelft/tam/model/EditionRepository.java b/src/test/java/nl/tudelft/tam/model/EditionRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..69d4f0ce95ef0caefb343e3317e514a06faf4829 --- /dev/null +++ b/src/test/java/nl/tudelft/tam/model/EditionRepository.java @@ -0,0 +1,24 @@ +/* + * 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> { +} diff --git a/src/test/java/nl/tudelft/tam/model/JobHolderTest.java b/src/test/java/nl/tudelft/tam/model/JobHolderTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f8647f287f6c6070b4a3c4c3c536846d4f75d613 --- /dev/null +++ b/src/test/java/nl/tudelft/tam/model/JobHolderTest.java @@ -0,0 +1,81 @@ +/* + * 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); + } + } + +} diff --git a/src/test/resources/application-h2.properties b/src/test/resources/application-h2.properties index 5cd799fc3818e217349e3cdebabbcd1bd5b87259..a8cf9bff196b301cb8dcd58c93d75ae9d399e4de 100644 --- a/src/test/resources/application-h2.properties +++ b/src/test/resources/application-h2.properties @@ -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 diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index aa6590a487b3ec26012f308303c1314640632c28..77cd4fe27869e2e355f93f37692c346bc6884f90 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -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