Skip to content

Commit

Permalink
Merge pull request #1022 from bounswe/backend/annotation-init
Browse files Browse the repository at this point in the history
initialization of annotation backend
  • Loading branch information
halisbal authored Dec 17, 2023
2 parents 9a73ae4 + 7edeb9a commit bae0ca4
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 0 deletions.
40 changes: 40 additions & 0 deletions app/annotation/annotation/.gitignore
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
3 changes: 3 additions & 0 deletions app/annotation/annotation/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/annotation/annotation/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions app/annotation/annotation/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/annotation/annotation/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions app/annotation/annotation/pom.xml
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>
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);
}
}
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;
}
}
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;
}

}
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);
}

}
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;
}
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;
}
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;
}
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;
}
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;
}
}
Loading

0 comments on commit bae0ca4

Please sign in to comment.