-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
305 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/nl/dtls/adminpanel/api/controller/exception/ExceptionControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package nl.dtls.adminpanel.api.controller.exception; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import nl.dtls.adminpanel.api.dto.error.ErrorDTO; | ||
import nl.dtls.adminpanel.entity.exception.ResourceNotFoundException; | ||
import nl.dtls.adminpanel.entity.exception.ValidationException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.authentication.BadCredentialsException; | ||
import org.springframework.security.authentication.CredentialsExpiredException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ControllerAdvice | ||
public class ExceptionControllerAdvice { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(ExceptionControllerAdvice.class); | ||
|
||
@ExceptionHandler({ValidationException.class}) | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ResponseBody | ||
public ErrorDTO handleBadRequest(Exception e, HttpServletResponse response) { | ||
LOGGER.error(e.getMessage()); | ||
return new ErrorDTO(HttpStatus.BAD_REQUEST, e.getMessage()); | ||
} | ||
|
||
@ExceptionHandler({BadCredentialsException.class, CredentialsExpiredException.class}) | ||
@ResponseStatus(HttpStatus.UNAUTHORIZED) | ||
@ResponseBody | ||
public ErrorDTO handleUnauthorized(Exception e, HttpServletResponse response) { | ||
LOGGER.error(e.getMessage()); | ||
return new ErrorDTO(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(ResourceNotFoundException.class) | ||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
@ResponseBody | ||
public ErrorDTO handleResourceNotFound(ResourceNotFoundException e, | ||
HttpServletResponse response) { | ||
LOGGER.error(e.getMessage()); | ||
return new ErrorDTO(HttpStatus.NOT_FOUND, e.getMessage()); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/nl/dtls/adminpanel/api/dto/error/ErrorDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package nl.dtls.adminpanel.api.dto.error; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class ErrorDTO { | ||
|
||
@JsonProperty | ||
private long timestamp; | ||
|
||
@JsonProperty | ||
private int status; | ||
|
||
@JsonProperty | ||
private String error; | ||
|
||
@JsonProperty() | ||
@JsonInclude(value = JsonInclude.Include.NON_NULL) | ||
private Map<String, ?> errors; | ||
|
||
@JsonProperty | ||
private String message; | ||
|
||
@JsonProperty | ||
private String path; | ||
|
||
public ErrorDTO(HttpStatus status, String message, Map<String, ?> errors) { | ||
this.timestamp = new Date().getTime(); | ||
this.status = status.value(); | ||
this.error = status.getReasonPhrase(); | ||
this.message = message; | ||
this.errors = errors; | ||
} | ||
|
||
public ErrorDTO(HttpStatus status, String message) { | ||
this(status, message, null); | ||
} | ||
|
||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/nl/dtls/adminpanel/database/fixtures/DummyDataLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package nl.dtls.adminpanel.database.fixtures; | ||
|
||
import nl.dtls.adminpanel.database.fixtures.data.ApplicationFixtures; | ||
import nl.dtls.adminpanel.database.fixtures.data.InstanceFixtures; | ||
import nl.dtls.adminpanel.database.fixtures.data.ServerFixtures; | ||
import nl.dtls.adminpanel.database.fixtures.data.UserFixtures; | ||
import nl.dtls.adminpanel.database.repository.ApplicationRepository; | ||
import nl.dtls.adminpanel.database.repository.InstanceRepository; | ||
import nl.dtls.adminpanel.database.repository.ServerRepository; | ||
import nl.dtls.adminpanel.database.repository.UserRepository; | ||
import nl.dtls.adminpanel.entity.Application; | ||
import nl.dtls.adminpanel.entity.Server; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class DummyDataLoader { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private UserFixtures userFixtures; | ||
|
||
@Autowired | ||
private ServerRepository serverRepository; | ||
|
||
@Autowired | ||
private ServerFixtures serverFixtures; | ||
|
||
@Autowired | ||
private InstanceRepository instanceRepository; | ||
|
||
@Autowired | ||
private InstanceFixtures instanceFixtures; | ||
|
||
@Autowired | ||
private ApplicationRepository applicationRepository; | ||
|
||
@Autowired | ||
private ApplicationFixtures applicationFixtures; | ||
|
||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
public void load() { | ||
userRepository.deleteAll(); | ||
userRepository.save(userFixtures.albert()); | ||
userRepository.save(userFixtures.nikola()); | ||
|
||
applicationRepository.deleteAll(); | ||
Application fdpApplication = applicationFixtures.fdpApplication(); | ||
applicationRepository.save(fdpApplication); | ||
|
||
serverRepository.deleteAll(); | ||
Server fdpServer = serverFixtures.fdpServer(); | ||
serverRepository.save(fdpServer); | ||
|
||
instanceRepository.deleteAll(); | ||
instanceRepository.save(instanceFixtures.stagingFdpInstance(fdpApplication, fdpServer)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,12 @@ | ||
package nl.dtls.adminpanel.database; | ||
package nl.dtls.adminpanel.database.fixtures.data; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import nl.dtls.adminpanel.database.repository.ApplicationRepository; | ||
import nl.dtls.adminpanel.database.repository.InstanceRepository; | ||
import nl.dtls.adminpanel.database.repository.ServerRepository; | ||
import nl.dtls.adminpanel.database.repository.UserRepository; | ||
import nl.dtls.adminpanel.entity.Application; | ||
import nl.dtls.adminpanel.entity.Instance; | ||
import nl.dtls.adminpanel.entity.Server; | ||
import nl.dtls.adminpanel.entity.Template; | ||
import nl.dtls.adminpanel.entity.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class DevelopmentDummyDataLoader { | ||
|
||
@Value("${dummy.server.username:}") | ||
private String serverUsername; | ||
|
||
@Value("${dummy.server.hostname:}") | ||
private String serverHostname; | ||
|
||
@Value("${dummy.server.privateKey:}") | ||
private String serverPrivateKey; | ||
|
||
@Value("${dummy.server.publicKey:}") | ||
private String serverPublicKey; | ||
|
||
@Value("${dummy.instance.url:}") | ||
private String instanceUrl; | ||
|
||
@Value("${dummy.instance.jwtSecret:}") | ||
private String instanceJwtSecret; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private ServerRepository serverRepository; | ||
|
||
@Autowired | ||
private InstanceRepository instanceRepository; | ||
|
||
@Autowired | ||
private ApplicationRepository applicationRepository; | ||
|
||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
public void load() { | ||
userRepository.deleteAll(); | ||
userRepository.save(admin()); | ||
|
||
applicationRepository.deleteAll(); | ||
Application fdpApplication = fdpApplication(); | ||
applicationRepository.save(fdpApplication); | ||
|
||
serverRepository.deleteAll(); | ||
Server fdpServer = fdpServer(); | ||
serverRepository.save(fdpServer); | ||
|
||
instanceRepository.deleteAll(); | ||
instanceRepository.save(stagingFdpInstance(fdpApplication, fdpServer)); | ||
} | ||
|
||
public User admin() { | ||
return new User( | ||
"7e64818d-6276-46fb-8bb1-732e6e09f7e9", | ||
"Admin", | ||
"[email protected]", | ||
passwordEncoder.encode("password") | ||
); | ||
} | ||
public class ApplicationFixtures { | ||
|
||
public Application fdpApplication() { | ||
return new Application( | ||
|
@@ -183,60 +114,4 @@ public Application fdpApplication() { | |
}}); | ||
} | ||
|
||
public Server fdpServer() { | ||
return new Server( | ||
"166c48ba-64d9-473a-8b59-7c1fdbb901f0", | ||
"FDP Server", | ||
serverUsername, | ||
serverHostname, | ||
serverPrivateKey, | ||
serverPublicKey); | ||
} | ||
|
||
public Instance stagingFdpInstance(Application fdpApplication, | ||
Server fdpServer) { | ||
return new Instance( | ||
"6f29daa8-1c43-49c3-9d1b-dc422e333d1e", | ||
"FDP Staging Instance", | ||
instanceUrl, | ||
"/tmp/fdp-test", | ||
new HashMap<>() {{ | ||
put("server_image", "fairdata/fairdatapoint:develop"); | ||
put("server_port", "81"); | ||
put("jwt_secret", instanceJwtSecret); | ||
put("repository_type", 1); | ||
put("repository_agraph_url", "http://localhost:10035/repositories/fdp"); | ||
put("repository_agraph_username", "user"); | ||
put("repository_agraph_password", "password"); | ||
put("repository_graphDb_url", "http://localhost:7200"); | ||
put("repository_graphDb_repository", "test"); | ||
put("repository_blazegraph_url", "http://localhost:8079/blazegraph"); | ||
put("repository_blazegraph_repository", "fdp"); | ||
put("repository_native_dir", "/tmp/fdp-store/"); | ||
put("metadata_rootSpecs", | ||
"https://www.purl.org/fairtools/fdp/schema/0.1/fdpMetadata"); | ||
put("metadata_catalogSpecs", | ||
"https://www.purl.org/fairtools/fdp/schema/0.1/catalogMetadata"); | ||
put("metadata_datasetSpecs", | ||
"https://www.purl.org/fairtools/fdp/schema/0.1/datasetMetadata"); | ||
put("metadata_distributionSpecs", | ||
"https://www.purl.org/fairtools/fdp/schema/0.1/distributionMetadata"); | ||
put("metadata_publisherURI", "http://localhost"); | ||
put("metadata_publisherName", "localhost"); | ||
put("metadata_language", "http://id.loc.gov/vocabulary/iso639-1/en"); | ||
put("metadata_license", "http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0"); | ||
put("metadata_accessRightsDescription", "This resource has no access restriction"); | ||
put("fairSearch_fdpSubmitUrl", "http://localhost:8080/fse/submitFdp"); | ||
put("pidSystem_type", 1); | ||
put("pidSystem_purl_baseUrl", "http://purl.org/YOUR-PURL-DOMAIN/fdp"); | ||
put("scss_customizations", "$color-primary: red"); | ||
put("scss_extra", "body { background: pink; }"); | ||
}}, | ||
new HashMap<>() {{ | ||
// put("logo.png", new ObjectId("5d9dcdea7c889a377583cfef")); | ||
}}, | ||
fdpApplication, | ||
fdpServer); | ||
} | ||
|
||
} |
Oops, something went wrong.