Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping-step-defs + Fix-warnings #5

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2ae5330
setup readme open issues
ZcR-01 Feb 28, 2024
cbc0e55
setup readme open issues
ZcR-01 Feb 28, 2024
e2496e2
feat: create Mapping entity
ZcR-01 Mar 4, 2024
66d1eed
feat: create Mapping and CustomMapping entity
ZcR-01 Mar 11, 2024
24f8f9e
feat: create Provider entity
ZcR-01 Mar 11, 2024
069e094
feat: change table name
ZcR-01 Mar 11, 2024
e20992d
feat: change class name
ZcR-01 Mar 11, 2024
fb839e1
feat: create mapping controller and repository
ZcR-01 Mar 11, 2024
1cf4e03
feat: create some controller exception
ZcR-01 Mar 11, 2024
16983c7
feat: fix user get id error
ZcR-01 Mar 13, 2024
25c9a80
feat: add provider repository
ZcR-01 Mar 13, 2024
d324fdf
feat: configure web security config for providers and mappings
ZcR-01 Mar 13, 2024
3a0d72b
refactor: rename supplier class
ZcR-01 Mar 13, 2024
758d71d
feat: register supplier test steps defs
ZcR-01 Mar 13, 2024
31cbf2f
feat: test register supplier cases
ZcR-01 Mar 13, 2024
405cb28
feat: test register supplier complete cases
ZcR-01 Mar 13, 2024
7924de7
feat: firsts test for create mapping
ZcR-01 Mar 14, 2024
33d32f6
feat: link Custom Mapping to Mapping repository
ZcR-01 Mar 14, 2024
1c45a16
feat: Mapping Controller for POST method
ZcR-01 Mar 14, 2024
b8b3dce
feat: add authentication config for user repository
ZcR-01 Mar 14, 2024
2b8534d
feat: first mapping step defs test
ZcR-01 Mar 15, 2024
8dbd746
feat: next mapping steps def && try catch mapping title empty error
ZcR-01 Mar 15, 2024
361d045
feat: add User id not blank
ZcR-01 Mar 15, 2024
95d5a44
feat: add mapping title empty error message
ZcR-01 Mar 15, 2024
4798189
feat: finish create mapping step defs
ZcR-01 Mar 15, 2024
4980232
feat: authentication config fix supplier username
ZcR-01 Mar 15, 2024
2c5375e
feat: add forbidden exception
ZcR-01 Mar 15, 2024
46be389
feat: mapping event handler for MethodArgumentNotValidException
ZcR-01 Mar 15, 2024
a9a313a
feat: firsts test for retrieve mapping && rename demo supplier
ZcR-01 Mar 18, 2024
67c06cd
feat: finish retrieve mapping test && stepdefs
ZcR-01 Mar 18, 2024
b918773
feat: add csv example for testing
ZcR-01 Mar 18, 2024
96c5c94
feat: upload mapping feature && step defs
ZcR-01 Mar 18, 2024
27db8e9
refactor: move supplier && mapping feature to folder
ZcR-01 Mar 18, 2024
810771d
refactor: import jakarta persistence column
ZcR-01 Mar 18, 2024
730f58c
feat: column entity && repository && custom column interface
ZcR-01 Mar 18, 2024
2de98d8
feat: create column feature && step defs
ZcR-01 Mar 18, 2024
dfb85fd
feat: create supplier event handler
ZcR-01 Mar 19, 2024
f257f96
refactor: delete mapping event handler
ZcR-01 Mar 19, 2024
0d3e19c
feat: add jackson library dependency to pom
ZcR-01 Mar 20, 2024
b13e81c
feat: YamlMapping to map yaml rule file
ZcR-01 Mar 20, 2024
323a909
feat: yaml generator first feature + step defs
ZcR-01 Mar 20, 2024
921bbb7
feat: yarrrml parser executor
ZcR-01 Mar 20, 2024
b619453
feat: execute yarrrml parser first feature + step defs
ZcR-01 Mar 20, 2024
4142910
feat: upload files resource for test yarrrml parser
ZcR-01 Mar 20, 2024
496afdb
feat: new attributes for Column entity
ZcR-01 Mar 22, 2024
408ad2a
feat: new attributes for Mapping entity
ZcR-01 Mar 22, 2024
d106536
feat: new methods for Column Repository
ZcR-01 Mar 22, 2024
3c4d836
feat: implements getters && delete extends of Mapping
ZcR-01 Mar 22, 2024
c1f1f27
feat: cucumber features + step defs for write yaml file
ZcR-01 Mar 22, 2024
46f139b
feat: move write yaml code to YamlGenerator class
ZcR-01 Apr 2, 2024
a63fd4f
feat: use a docker container to execute yarrrml mapping command
ZcR-01 Apr 2, 2024
c8e1e81
feat: finish docker command executor
ZcR-01 Apr 3, 2024
5621ad8
feat: define write yaml && execute parser feature and step defs
ZcR-01 Apr 3, 2024
5fdbfb2
refactor: delete comment lines
ZcR-01 Apr 3, 2024
b61deb0
feat: delete mapping feature + step defs
ZcR-01 Apr 3, 2024
4c9cb1b
feat: delete supplier feature + step defs
ZcR-01 Apr 3, 2024
6b248b4
feat: mapping controller for delete operation
ZcR-01 Apr 3, 2024
c838ac7
refactor: delete redundant comment
ZcR-01 Apr 3, 2024
cebf051
feat: retrieve supplier feature + step defs
ZcR-01 Apr 3, 2024
3fde804
feat: update column feature + step defs
ZcR-01 Apr 3, 2024
55effa2
feat: update supplier feature + step defs
ZcR-01 Apr 3, 2024
f67a88c
feat: delete column feature + step defs + controller
ZcR-01 Apr 4, 2024
d052f0d
feat: retrieve column feature + step defs
ZcR-01 Apr 4, 2024
c1e6d7c
fix: warning APPLICATION_JSON_UTF8 is deprecated
ZcR-01 Apr 4, 2024
361b553
fix: unnecessary modifier, redundant public for interface members
ZcR-01 Apr 4, 2024
6cd9f0b
fix: unnecessary semicolon
ZcR-01 Apr 4, 2024
d8e39fa
fix: never thrown exceptions
ZcR-01 Apr 4, 2024
7268925
fix: delete unused finds
ZcR-01 Apr 4, 2024
f351fc0
fix: delete repository's imports
ZcR-01 Apr 4, 2024
f12e32d
fix: delete repository's imports
ZcR-01 Apr 4, 2024
8edb077
refactor: delete unused imports
ZcR-01 Apr 4, 2024
9c88123
refactor: delete unused imports
ZcR-01 Apr 4, 2024
6e46669
refactor: delete unused find
ZcR-01 Apr 4, 2024
9af6e37
fix: check if variable is non-null
ZcR-01 Apr 4, 2024
6531647
refactor: add getter && setter lombok && rename User table
ZcR-01 Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Template for a Spring Boot project including Spring REST, HATEOAS, JPA, etc. Additional details: [HELP.md](HELP.md)

[![Open Issues](https://img.shields.io/github/issues-raw/UdL-EPS-SoftArch/spring-template?logo=github)](https://github.com/orgs/UdL-EPS-SoftArch/projects/12)
[![Open Issues](https://img.shields.io/github/issues-raw/Tab2KGWiz/tab2kgwiz-client?logo=github)](https://github.com/orgs/Tab2KGWiz/projects/2)
[![CI/CD](https://github.com/UdL-EPS-SoftArch/spring-template/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/UdL-EPS-SoftArch/spring-template/actions)
[![CucumberReports: UdL-EPS-SoftArch](https://messages.cucumber.io/api/report-collections/faed8ca5-e474-4a1a-a72a-b8e2a2cd69f0/badge)](https://reports.cucumber.io/report-collections/faed8ca5-e474-4a1a-a72a-b8e2a2cd69f0)
[![Deployment status](https://img.shields.io/uptimerobot/status/m792691238-18db2a43adf8d8ded474f885)](https://spring-template.fly.dev/users)
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cat.udl.eps.softarch.demo.config;

import cat.udl.eps.softarch.demo.domain.User;
import cat.udl.eps.softarch.demo.repository.SupplierRepository;
import cat.udl.eps.softarch.demo.domain.Supplier;
import cat.udl.eps.softarch.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,15 +18,39 @@ public class AuthenticationConfig extends GlobalAuthenticationConfigurerAdapter
final BasicUserDetailsService basicUserDetailsService;
final UserRepository userRepository;

public AuthenticationConfig(BasicUserDetailsService basicUserDetailsService, UserRepository userRepository) {
final SupplierRepository supplierRepository;

public AuthenticationConfig(BasicUserDetailsService basicUserDetailsService, UserRepository userRepository,
SupplierRepository supplierRepository) {
this.basicUserDetailsService = basicUserDetailsService;
this.userRepository = userRepository;
this.supplierRepository = supplierRepository;
}

@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(basicUserDetailsService)
.passwordEncoder(User.passwordEncoder);


//Sample User
if (!userRepository.existsById("demo")) {
User user = new User();
user.setEmail("[email protected]");
user.setUsername("demo");
user.setPassword(defaultPassword);
user.encodePassword();
userRepository.save(user);
}

if (!supplierRepository.existsById("demoSupplier")) {
Supplier supplier = new Supplier();
supplier.setUsername("demoSupplier");
supplier.setEmail("[email protected]");
supplier.setPassword(defaultPassword);
supplier.encodePassword();
supplierRepository.save(supplier);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cat.udl.eps.softarch.demo.config;

import cat.udl.eps.softarch.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void initializeDatabase() {
if (!userRepository.existsById("demo")) {
User user = new User();
user.setEmail("[email protected]");
user.setId("demo");
user.setUsername("demo");
user.setPassword(defaultPassword);
user.encodePassword();
userRepository.save(user);
Expand All @@ -34,7 +34,7 @@ public void initializeDatabase() {
if (!userRepository.existsById("test")) {
User user = new User();
user.setEmail("[email protected]");
user.setId("test");
user.setUsername("test");
user.setPassword(defaultPassword);
user.encodePassword();
userRepository.save(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exce
.requestMatchers(HttpMethod.GET, "/identity").authenticated()
.requestMatchers(HttpMethod.POST, "/users").anonymous()
.requestMatchers(HttpMethod.POST, "/users/*").denyAll()
.requestMatchers(HttpMethod.DELETE, "/suppliers/*").hasRole("SUPPLIER")
.requestMatchers(HttpMethod.PATCH, "/suppliers/*").hasRole("SUPPLIER")
.requestMatchers(HttpMethod.POST, "/suppliers").anonymous()
.requestMatchers(HttpMethod.POST, "/mappings").hasRole("SUPPLIER")
.requestMatchers(HttpMethod.DELETE, "/mappings/*").hasRole("SUPPLIER")
.requestMatchers(HttpMethod.PATCH, "/mappings/*").hasRole("SUPPLIER")
.requestMatchers(HttpMethod.POST, "/**/*").authenticated()
.requestMatchers(HttpMethod.PUT, "/**/*").authenticated()
.requestMatchers(HttpMethod.PATCH, "/**/*").authenticated()
Expand All @@ -38,7 +44,7 @@ protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exce
.csrf((csrf) -> csrf.disable())
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.cors((cors) -> cors.configurationSource(corsConfigurationSource()))
.httpBasic((httpBasic) -> httpBasic.realmName("demo"));
.httpBasic((httpBasic) -> httpBasic.realmName("tab2kgwiz"));
return http.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cat.udl.eps.softarch.demo.controller;

import cat.udl.eps.softarch.demo.domain.Column;
import cat.udl.eps.softarch.demo.domain.Mapping;
import cat.udl.eps.softarch.demo.domain.Supplier;
import cat.udl.eps.softarch.demo.domain.User;
import cat.udl.eps.softarch.demo.exception.NotAuthorizedException;
import cat.udl.eps.softarch.demo.exception.NotFoundException;
import cat.udl.eps.softarch.demo.repository.ColumnRepository;
import cat.udl.eps.softarch.demo.repository.MappingRepository;
import cat.udl.eps.softarch.demo.repository.SupplierRepository;
import org.springframework.data.rest.webmvc.PersistentEntityResource;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;
import java.util.Optional;

@RepositoryRestController
public class ColumnController {
private final ColumnRepository columnRepository;
private final MappingRepository mappingRepository;
private final SupplierRepository supplierRepository;

public ColumnController(ColumnRepository columnRepository, MappingRepository mappingRepository, SupplierRepository supplierRepository) {
this.columnRepository = columnRepository;
this.mappingRepository = mappingRepository;
this.supplierRepository = supplierRepository;
}

@RequestMapping(value = "/columns/{id}", method = RequestMethod.GET)
public @ResponseBody PersistentEntityResource getColumn(PersistentEntityResourceAssembler resourceAssembler,
@PathVariable Long id) {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof AnonymousAuthenticationToken) {
throw new NotAuthorizedException();
}

User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Optional<Column> column = columnRepository.findById(id);

if (column.isEmpty()) {
throw new NotFoundException();
}

Column col = column.get();
assert col.getColumnBelongsTo().getId() != null;
Optional<Mapping> mappingBelongs = mappingRepository.findById(col.getColumnBelongsTo().getId());

if (mappingBelongs.isPresent() && Objects.equals(mappingBelongs.get().getProvidedBy().getId(), user.getId())) {
return resourceAssembler.toFullResource(col);
} else {
throw new NotAuthorizedException();
}
}

@RequestMapping(value = "/columns/{id}", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteColumns(@PathVariable Long id) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentSupplierUsername = authentication.getName();
Supplier currentSupplier = supplierRepository.findByUsernameContaining(currentSupplierUsername).get(0);

Optional<Column> column = columnRepository.findById(id);

if (column.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Column not found.");
}

Column col = column.get();
assert col.getColumnBelongsTo().getId() != null;
Optional<Mapping> mappingBelongs = mappingRepository.findById(col.getColumnBelongsTo().getId());

if (mappingBelongs.isPresent() && Objects.equals(mappingBelongs.get().getProvidedBy().getId(), currentSupplier.getId())) {
columnRepository.delete(col);
return ResponseEntity.ok("Column deleted successfully.");
} else {
throw new NotAuthorizedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package cat.udl.eps.softarch.demo.controller;
import cat.udl.eps.softarch.demo.domain.Mapping;
import cat.udl.eps.softarch.demo.domain.Supplier;
import cat.udl.eps.softarch.demo.domain.User;
import cat.udl.eps.softarch.demo.exception.NotAuthorizedException;
import cat.udl.eps.softarch.demo.exception.NotFoundException;
import cat.udl.eps.softarch.demo.repository.MappingRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.data.rest.webmvc.PersistentEntityResource;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RepositoryRestController
public class MappingController {
private final MappingRepository mappingRepository;

public MappingController(MappingRepository mappingRepository) {
this.mappingRepository = mappingRepository;
}

@RequestMapping(value = "/mappings/{id}", method = RequestMethod.GET)
public @ResponseBody PersistentEntityResource getMapping(PersistentEntityResourceAssembler resourceAssembler,
@PathVariable Long id) {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof AnonymousAuthenticationToken) {
throw new NotAuthorizedException();
}

User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Optional<Mapping> mapping = mappingRepository.findById(id);

if (mapping.isEmpty()) {
throw new NotFoundException();
}

Mapping m = mapping.get();

if(m.getProvidedBy().getId() == null) {
throw new NotFoundException();
}

if (m.getProvidedBy().getId().equals(user.getId())) {
return resourceAssembler.toFullResource(m);
} else {
throw new NotAuthorizedException();
}
}

@RequestMapping(value = "/mappings", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public @ResponseBody PersistentEntityResource createMapping(PersistentEntityResourceAssembler resourceAssembler,
@RequestBody Mapping mapping) throws MethodArgumentNotValidException {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication instanceof AnonymousAuthenticationToken) {
throw new NotAuthorizedException();
}

Supplier supplier = (Supplier) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

mapping.setProvidedBy(supplier);

try {
mapping = mappingRepository.save(mapping);
} catch (Exception e) {
throw new MethodArgumentNotValidException(null, new BeanPropertyBindingResult(mapping, "mapping"));
}

return resourceAssembler.toFullResource(mapping);
}

@RequestMapping(value = "/mappings/{id}", method = RequestMethod.DELETE)
public ResponseEntity<String> deleteMapping(@PathVariable Long id) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentSupplierUsername = authentication.getName();

Optional<Mapping> mapping = mappingRepository.findById(id);

if (mapping.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Mapping not found.");
}

if (!mapping.get().getProvidedBy().getUsername().equals(currentSupplierUsername)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("You are not allowed to delete this mapping.");
}

mappingRepository.delete(mapping.get());
return ResponseEntity.ok("Mapping deleted successfully.");
}
}
41 changes: 41 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cat.udl.eps.softarch.demo.domain;

import com.fasterxml.jackson.annotation.JsonIdentityReference;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
public class Column extends UriEntity<Long> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotBlank(message = "Title is mandatory")
@Length(min = 1, max = 80)
private String title;

@NotBlank
private String dataType;

private String ontologyURI;

private String ontologyType;


@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
private Mapping columnBelongsTo;

// private String measurement;

@Override
public Long getId() {
return id;
}

}
16 changes: 16 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/CustomColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cat.udl.eps.softarch.demo.domain;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.rest.core.config.Projection;

@Projection(
name = "customColumn",
types = { Column.class }
)

public interface CustomColumn {
Long getId();
String getTitle();
@Value("#{target.columnBelongsTo.title}")
String getProvideBy();
}
16 changes: 16 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/CustomMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cat.udl.eps.softarch.demo.domain;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.rest.core.config.Projection;

@Projection(
name = "customMapping",
types = { Mapping.class }
)

public interface CustomMapping {
Long getId();
String getTitle();
@Value("#{target.providedBy.username}")
String getProvideBy();
}
Loading
Loading