Skip to content

Commit

Permalink
WIP: seed
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Apr 26, 2024
1 parent d994ba7 commit 76198ec
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ FROM eclipse-temurin:21-jdk-alpine

WORKDIR /fdp

ADD data /data
ADD target/fdp-spring-boot.jar /fdp/app.jar
ADD target/classes/application-production.yml /fdp/application.yml

Expand Down
10 changes: 10 additions & 0 deletions data/schemas/schema-resource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '1.0'
type: 'Schema'
entity:
uuid:
versionUuid:
version: ''
name: 'Resource'
description: ''
abstract: true
definition:
8 changes: 8 additions & 0 deletions data/users/user-albert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 1.0
type: User
entity:
uuid:
firstName: Albert
lastName: Einstein
email: [email protected]
password: password
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class InstanceProperties {
private String title = "FAIR Data Point";
private String subtitle = "Metadata for machines";

private String seedPath = "/data/**/*.yml";

public String getUrl() {
if (persistentUrl == null || persistentUrl.isBlank()) {
return clientUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nl.dtls.fairdatapoint.service.seeder;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import nl.dtls.fairdatapoint.config.properties.InstanceProperties;
import nl.dtls.fairdatapoint.service.seeder.entity.EntitiesContainer;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class EntitySeeder {
private static final String DSO_SCHEMA_VERSION = "1.0.0";

private final InstanceProperties instanceProperties;

public EntitiesContainer loadLocal() {
final EntitiesContainer container = new EntitiesContainer();

// TODO: list YAML/JSON files in directory
// TODO: load files one by one and add elements

return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nl.dtls.fairdatapoint.service.seeder.entity;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Data
public class EntitiesContainer {

private final SettingsDSO settings = null;

private final Map<UUID, UserDSO> users = new HashMap<>();

private final Map<UUID, MetadataSchemaDSO> schemas = new HashMap<>();

private final Map<UUID, ResourceDefinitionDSO> resourceDefinitions = new HashMap<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package nl.dtls.fairdatapoint.service.seeder.entity;

import lombok.Data;
import nl.dtls.fairdatapoint.entity.schema.MetadataSchemaState;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Data
public class MetadataSchemaDSO {

private UUID uuid = UUID.randomUUID();

private UUID versionUuid = UUID.randomUUID();

private String name;

private String version = "1.0.0";

private String description = "";

private Boolean abstractSchema = false;

private MetadataSchemaState state = MetadataSchemaState.LATEST;

private String definition;

private String suggestedResourceName = null;

private String suggestedUrlPrefix = null;

private List<UUID> extendSchemaUuids = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nl.dtls.fairdatapoint.service.seeder.entity;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import nl.dtls.fairdatapoint.api.dto.resource.ResourceDefinitionChildDTO;
import nl.dtls.fairdatapoint.api.dto.resource.ResourceDefinitionLinkDTO;

import java.util.List;
import java.util.UUID;

@Data
public class ResourceDefinitionDSO {

@NotBlank
private UUID uuid;

@NotBlank
private String name;

@NotNull
private String urlPrefix;

@NotNull
private List<UUID> metadataSchemaUuids;

@NotNull
private List<String> targetClassUris;

@NotNull
@Valid
private List<ResourceDefinitionChildDTO> children;

@NotNull
@Valid
private List<ResourceDefinitionLinkDTO> externalLinks;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package nl.dtls.fairdatapoint.service.seeder.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import nl.dtls.fairdatapoint.api.dto.settings.*;

import java.util.List;

@Data
public class SettingsDSO {

private String clientUrl;

private String persistentUrl;

@JsonInclude
private String appTitle;

@JsonInclude
private String appSubtitle;

private String appTitleFromConfig;

private String appSubtitleFromConfig;

private List<SettingsMetricDTO> metadataMetrics;

private SettingsPingDTO ping;

private SettingsRepositoryDTO mainRepository;

private SettingsRepositoryDTO draftsRepository;

private SettingsSearchDTO search;

private SettingsFormsDTO forms;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package nl.dtls.fairdatapoint.service.seeder.entity;

import lombok.Data;
import nl.dtls.fairdatapoint.entity.user.UserRole;

import java.util.UUID;

@Data
public class UserDSO {

private UUID uuid = UUID.randomUUID();

private String firstName;

private String lastName;

private String email;

private String password;

private UserRole role = UserRole.USER;
}

0 comments on commit 76198ec

Please sign in to comment.