-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1022 from bounswe/backend/annotation-init
initialization of annotation backend
- Loading branch information
Showing
24 changed files
with
630 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
src/main/resources/.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.0.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.app.annotation</groupId> | ||
<artifactId>annotation</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.modelmapper</groupId> | ||
<artifactId>modelmapper</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>me.paulschwarz</groupId> | ||
<artifactId>spring-dotenv</artifactId> | ||
<version>4.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.validation</groupId> | ||
<artifactId>jakarta.validation-api</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
11 changes: 11 additions & 0 deletions
11
app/annotation/annotation/src/main/java/com/app/annotation/Main.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,11 @@ | ||
package com.app.annotation; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Main { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Main.class, args); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/annotation/annotation/src/main/java/com/app/annotation/config/CorsConfig.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,27 @@ | ||
package com.app.annotation.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.Arrays; | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
|
||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
final CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.setAllowedOrigins(Arrays.asList("http://localhost:5173", "http://ec2-51-20-78-40.eu-north-1.compute.amazonaws.com/")); | ||
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); | ||
configuration.setAllowCredentials(true); | ||
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "Set-Cookie", "credentials")); | ||
configuration.setExposedHeaders(Arrays.asList("Set-Cookie")); | ||
|
||
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
return source; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/annotation/annotation/src/main/java/com/app/annotation/config/MapperConfig.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,17 @@ | ||
package com.app.annotation.config; | ||
|
||
import org.modelmapper.ModelMapper; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class MapperConfig { | ||
|
||
@Bean | ||
public static ModelMapper modelMapper() { | ||
ModelMapper modelMapper = new ModelMapper(); | ||
modelMapper.getConfiguration().setFieldMatchingEnabled(true); | ||
return modelMapper; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...notation/annotation/src/main/java/com/app/annotation/controller/AnnotationController.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,29 @@ | ||
package com.app.annotation.controller; | ||
|
||
import com.app.annotation.service.AnnotationService; | ||
import com.app.annotation.dto.request.CreateAnnotationRequestDto; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/api/annotation") | ||
public class AnnotationController { | ||
|
||
private final AnnotationService annotationService; | ||
|
||
public AnnotationController(AnnotationService annotationService) { | ||
this.annotationService = annotationService; | ||
} | ||
|
||
@PostMapping("/create") | ||
public ResponseEntity<Map<String, Object>> createAnnotation(@RequestBody CreateAnnotationRequestDto dto) { | ||
Map<String, Object> annotation = annotationService.createAnnotation(dto); | ||
return ResponseEntity.ok(annotation); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/annotation/annotation/src/main/java/com/app/annotation/dto/request/BodyDto.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,27 @@ | ||
package com.app.annotation.dto.request; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class BodyDto { | ||
|
||
@Pattern(regexp = "TextualBody", message = "Currently only Embedded Textual Bodies are supported.") | ||
private String type; | ||
|
||
private String id; | ||
|
||
private String purpose; | ||
|
||
@NotEmpty(message = "body value can not be empty.") | ||
private String value; | ||
|
||
private String format; | ||
|
||
private String language; | ||
} |
33 changes: 33 additions & 0 deletions
33
...n/annotation/src/main/java/com/app/annotation/dto/request/CreateAnnotationRequestDto.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,33 @@ | ||
package com.app.annotation.dto.request; | ||
|
||
import com.app.annotation.model.Creator; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Date; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CreateAnnotationRequestDto { | ||
|
||
@NotEmpty(message = "annotation target can not be empty.") | ||
private TargetDto target; | ||
|
||
@NotEmpty(message = "annotation body can not be empty.") | ||
private BodyDto body; | ||
|
||
@NotEmpty(message = "annotation id can not be empty.") | ||
private String id; | ||
|
||
@NotEmpty(message = "annotation type can not be empty.") | ||
private String type; | ||
|
||
private String motivation; | ||
|
||
private Date created; | ||
|
||
private Creator creator; | ||
} |
30 changes: 30 additions & 0 deletions
30
app/annotation/annotation/src/main/java/com/app/annotation/dto/request/SelectorDto.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,30 @@ | ||
package com.app.annotation.dto.request; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Positive; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SelectorDto { | ||
|
||
@Pattern(regexp = "^(TextQuoteSelector|TextPositionSelector)$", | ||
message = "Currently only Text Quote Selector and Text Position Selector are supported.") | ||
private String type; | ||
|
||
private String exact; | ||
|
||
private String prefix; | ||
|
||
private String suffix; | ||
|
||
@PositiveOrZero | ||
private Integer start; | ||
|
||
@Positive | ||
private Integer end; | ||
} |
28 changes: 28 additions & 0 deletions
28
app/annotation/annotation/src/main/java/com/app/annotation/dto/request/TargetDto.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,28 @@ | ||
package com.app.annotation.dto.request; | ||
|
||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class TargetDto { | ||
|
||
private String id; | ||
|
||
private String type; | ||
|
||
private String format; | ||
|
||
private String textDirection; | ||
|
||
@NotEmpty(message = "target source can not be empty.") | ||
private String source; | ||
|
||
@NotEmpty(message = "target selector can not be empty.") | ||
private List<SelectorDto> selector; | ||
} |
48 changes: 48 additions & 0 deletions
48
app/annotation/annotation/src/main/java/com/app/annotation/model/Annotation.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,48 @@ | ||
package com.app.annotation.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Document(collection = "Annotation") | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Annotation { | ||
|
||
@Id | ||
private String id; | ||
|
||
private Target target; | ||
|
||
private Body body; | ||
|
||
private String type; | ||
|
||
private String motivation; | ||
|
||
private Date created; | ||
|
||
private Creator creator; | ||
|
||
public Map<String, Object> toJSON() { | ||
Map<String, Object> json = new HashMap<>(); | ||
json.put("@context", "http://www.w3.org/ns/anno.jsonld"); | ||
if (this.id != null) json.put("id", this.id); | ||
if (this.type != null) json.put("type", this.type); | ||
if (this.motivation != null) json.put("motivation", this.motivation); | ||
if (this.created != null) json.put("created", this.created); | ||
if (this.target != null) json.put("target", this.target.toJSON()); | ||
if (this.body != null) json.put("body", this.body.toJSON()); | ||
if (this.creator != null) json.put("creator", this.creator.toJSON()); | ||
return json; | ||
} | ||
} |
Oops, something went wrong.