Skip to content

Commit

Permalink
Added: Create query and draft project (Lens)
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 26, 2023
1 parent 590a00c commit e90670d
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Exporter Service implementation
- Bridgehead configuration with explorer and exporter mapping
- Bridgehead Operation
- Create query and draft project (Lens)
2 changes: 1 addition & 1 deletion src/main/java/de/samply/aop/NotEmptyAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Object validateParameterNotEmpty(ProceedingJoinPoint joinPoint) throws Th
AtomicReference<String> emptyParameter = new AtomicReference<>("");
IntStream.range(0, args.length)
.filter(i -> hasNotEmptyAnnotation(parameterAnnotations[i]))
.filter(i -> args[i] == null || StringUtils.isEmpty(args[i].toString().trim()))
.filter(i -> args[i] == null || !StringUtils.hasText(args[i].toString().trim()))
.findFirst()
.ifPresent(i -> emptyParameter.set(signature.getParameterNames()[i]));
return (!emptyParameter.get().isEmpty()) ?
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ public class ProjectManagerConst {
public final static String APP_NAME = "Project Manager";

// Sites
public final static String PROJECT_DASHBOARD_SITE = "Project Dashboard";
public final static String PROJECT_VIEW_SITE = "Project View";
public final static String PROJECT_FORM_SITE = "Project Form";
public final static String PROJECT_PUBLICATIONS_SITE = "Project Publications";
public final static String PROJECT_DASHBOARD_SITE = "project-dashboard";
public final static String PROJECT_VIEW_SITE = "project-view";

//Modules
public final static String USER_MODULE = "User Module";
Expand Down Expand Up @@ -36,13 +34,15 @@ public class ProjectManagerConst {
public final static String SAVE_QUERY_IN_BRIDGEHEAD_ACTION = "Save query in bridgehead";
public final static String SAVE_AND_EXECUTE_QUERY_IN_BRIDGEHEAD_ACTION = "Save and execute query in bridgehead";
public final static String FETCH_AUTHENTICATION_SCRIPT_ACTION = "Fetch authentication script";
public final static String CREATE_QUERY_AND_DESIGN_PROJECT_ACTION = "Create Query and Design Project";

// REST Services
public final static String INFO = "/info";
public final static String ACTIONS = "/actions";
public final static String SET_DEVELOPER_USER = "/set-developer-user";
public final static String SET_PILOT_USER = "/set-pilot-user";
public final static String SET_FINAL_USER = "/set-final-user";
public final static String CREATE_QUERY_AND_DESIGN_PROJECT = "/create-query-and-design-project";
public final static String DESIGN_PROJECT = "/design-project";
public final static String CREATE_PROJECT = "/create-project";
public final static String ACCEPT_PROJECT = "/accept-project";
Expand All @@ -53,7 +53,6 @@ public class ProjectManagerConst {
public final static String START_FINAL_STAGE = "/start-final-project";
public final static String FINISH_PROJECT = "/finish-project";
public final static String CREATE_QUERY = "/create-query";
public final static String CREATE_CQL_DATA_QUERY = "/create-cql-data-query";
public final static String UPLOAD_PROJECT_DOCUMENT = "/upload-project-document";
public final static String ADD_PROJECT_DOCUMENT_URL = "/add-project-document-url";
public final static String DOWNLOAD_PROJECT_DOCUMENT = "/download-project-document";
Expand All @@ -78,6 +77,8 @@ public class ProjectManagerConst {
public final static String DESCRIPTION = "description";
public final static String OUTPUT_FORMAT = "output-format";
public final static String TEMPLATE_ID = "template-id";
public final static String HUMAN_READABLE = "human-readable";
public final static String EXPLORER_URL = "explorer-url";


// Application Properties
Expand Down Expand Up @@ -115,6 +116,7 @@ public class ProjectManagerConst {
public final static String BK_ADMIN_GROUP_PREFIX = "BK_ADMIN_GROUP_PREFIX";
public final static String BK_ADMIN_GROUP_SUFFIX = "BK_ADMIN_GROUP_SUFFIX";
public final static String REGISTERED_BRIDGEHEADS = "bridgeheads";
public final static String FRONTEND_CONFIG = "frontend";
public final static String PROJECT_DOCUMENTS_DIRECTORY = "PROJECT_DOCUMENTS_DIRECTORY";
public final static String PROJECT_DOCUMENTS_DIRECTORY_TIMESTAMP_FORMAT = "PROJECT_DOCUMENTS_DIRECTORY_TIMESTAMP";
public final static String WEBCLIENT_BUFFER_SIZE_IN_BYTES = "WEBCLIENT_BUFFER_SIZE_IN_BYTES";
Expand Down
73 changes: 45 additions & 28 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.samply.exporter.ExporterService;
import de.samply.frontend.FrontendService;
import de.samply.project.ProjectType;
import de.samply.project.event.ProjectEventActionsException;
import de.samply.project.event.ProjectEventService;
import de.samply.project.state.ProjectState;
import de.samply.query.OutputFormat;
Expand Down Expand Up @@ -42,6 +43,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;

@Controller
Expand Down Expand Up @@ -133,6 +135,47 @@ public ResponseEntity<String> setUserAsFinal(
this.userService.setProjectBridgheadUserWithRole(email, projectCode, bridgehead, ProjectRole.FINAL));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER})
@PostMapping(value = ProjectManagerConst.CREATE_QUERY)
public ResponseEntity<String> createProjectQuery(
@NotEmpty @RequestBody() String query,
@NotEmpty @RequestParam(name = ProjectManagerConst.QUERY_FORMAT) QueryFormat queryFormat,
@RequestParam(name = ProjectManagerConst.LABEL, required = false) String label,
@RequestParam(name = ProjectManagerConst.DESCRIPTION, required = false) String description,
@RequestParam(name = ProjectManagerConst.OUTPUT_FORMAT, required = false) OutputFormat outputFormat,
@RequestParam(name = ProjectManagerConst.TEMPLATE_ID, required = false) String templateId,
@RequestParam(name = ProjectManagerConst.HUMAN_READABLE, required = false) String humanReadable,
@RequestParam(name = ProjectManagerConst.EXPLORER_URL, required = false) String explorerUrl
) {
return convertToResponseEntity(() ->
this.queryService.createQuery(query, queryFormat, label, description, outputFormat, templateId, humanReadable, explorerUrl));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.CREATE_QUERY_AND_DESIGN_PROJECT_ACTION)
@PostMapping(value = ProjectManagerConst.CREATE_QUERY_AND_DESIGN_PROJECT)
public ResponseEntity<String> createQueryAndDesignProject(
@NotEmpty @RequestBody() String query,
@NotEmpty @RequestParam(name = ProjectManagerConst.QUERY_FORMAT) QueryFormat queryFormat,
@NotEmpty @RequestParam(name = ProjectManagerConst.BRIDGEHEADS) String[] bridgeheads,
@RequestParam(name = ProjectManagerConst.LABEL, required = false) String label,
@RequestParam(name = ProjectManagerConst.DESCRIPTION, required = false) String description,
@RequestParam(name = ProjectManagerConst.OUTPUT_FORMAT, required = false) OutputFormat outputFormat,
@RequestParam(name = ProjectManagerConst.TEMPLATE_ID, required = false) String templateId,
@RequestParam(name = ProjectManagerConst.HUMAN_READABLE, required = false) String humanReadable,
@RequestParam(name = ProjectManagerConst.EXPLORER_URL, required = false) String explorerUrl,
@RequestParam(name = ProjectManagerConst.PROJECT_TYPE, required = false) ProjectType projectType
) throws ProjectEventActionsException {
String queryCode = this.queryService.createQuery(
query, queryFormat, label, description, outputFormat, templateId, humanReadable, explorerUrl);
String projectCode = this.projectEventService.draft(bridgeheads, queryCode, projectType);
return convertToResponseEntity(() -> this.frontendService.fetchUrl(
ProjectManagerConst.PROJECT_VIEW_SITE,
Map.of(ProjectManagerConst.QUERY_CODE, projectCode)
));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_STATE_MODULE)
@FrontendAction(action = ProjectManagerConst.DESIGN_PROJECT_ACTION)
Expand Down Expand Up @@ -231,32 +274,6 @@ public ResponseEntity<String> finishProject(
return convertToResponseEntity(() -> projectEventService.finish(projectCode));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER})
@PostMapping(value = ProjectManagerConst.CREATE_QUERY)
public ResponseEntity<String> createProjectQuery(
@NotEmpty @RequestBody() String query,
@NotEmpty @RequestParam(name = ProjectManagerConst.QUERY_FORMAT) QueryFormat queryFormat,
@NotEmpty @RequestParam(name = ProjectManagerConst.LABEL) String label,
@NotEmpty @RequestParam(name = ProjectManagerConst.DESCRIPTION) String description,
@NotEmpty @RequestParam(name = ProjectManagerConst.OUTPUT_FORMAT) OutputFormat outputFormat,
@NotEmpty @RequestParam(name = ProjectManagerConst.TEMPLATE_ID) String templateId
) {
return convertToResponseEntity(() -> this.queryService.createQuery(query, queryFormat, label, description, outputFormat, templateId));
}

@RoleConstraints(organisationRoles = {OrganisationRole.RESEARCHER})
@PostMapping(value = ProjectManagerConst.CREATE_CQL_DATA_QUERY)
public ResponseEntity<String> createProjectCqlDataQuery(
@NotEmpty @RequestBody() String query,
@NotEmpty @RequestParam(name = ProjectManagerConst.LABEL) String label,
@NotEmpty @RequestParam(name = ProjectManagerConst.DESCRIPTION) String description,
@NotEmpty @RequestParam(name = ProjectManagerConst.OUTPUT_FORMAT) OutputFormat outputFormat,
@NotEmpty @RequestParam(name = ProjectManagerConst.TEMPLATE_ID) String templateId

) {
return convertToResponseEntity(() -> this.queryService.createQuery(query, QueryFormat.CQL_DATA, label, description, outputFormat, templateId));
}

@RoleConstraints(projectRoles = {ProjectRole.CREATOR, ProjectRole.DEVELOPER, ProjectRole.BRIDGEHEAD_ADMIN, ProjectRole.PROJECT_MANAGER_ADMIN})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.PROJECT_DOCUMENTS_MODULE)
@FrontendAction(action = ProjectManagerConst.UPLOAD_PROJECT_DOCUMENT_ACTION)
Expand Down Expand Up @@ -334,8 +351,8 @@ private ByteArrayResource fetchResource(Path filePath) throws DocumentServiceExc
@FrontendAction(action = ProjectManagerConst.SAVE_QUERY_IN_BRIDGEHEAD_ACTION)
@PostMapping(value = ProjectManagerConst.SAVE_QUERY_IN_BRIDGEHEAD)
public ResponseEntity<String> saveQueryInBridgehead(
@ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode,
@Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead
@NotEmpty @ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode,
@NotEmpty @Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead
) {
return convertToResponseEntity(() -> this.exporterService.sendQueryToBridgehead(projectCode, bridgehead));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/samply/db/model/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Project {
@JoinColumn(name = "query_id")
private Query query;

@Column(name = "type", nullable = false)
@Column(name = "type")
@Enumerated(EnumType.STRING)
private ProjectType type;

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/samply/db/model/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class Query {
@Column(name = "query", nullable = false)
private String query;

@Column(name = "human_readable")
private String humanReadable;

@Column(name = "query_format", nullable = false)
@Enumerated(EnumType.STRING)
private QueryFormat queryFormat;
Expand All @@ -47,4 +50,7 @@ public class Query {
@Column(name = "description")
private String description;

@Column(name = "explorer_url")
private String explorerUrl;

}
24 changes: 24 additions & 0 deletions src/main/java/de/samply/frontend/FrontendConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.samply.frontend;

import de.samply.app.ProjectManagerConst;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Configuration
@ConfigurationProperties(prefix = ProjectManagerConst.FRONTEND_CONFIG)
@Data
public class FrontendConfiguration {

private String baseUrl;
private Map<String, String> sites = new HashMap<>();

public Optional<String> getSitePath(String site) {
return Optional.ofNullable(sites.get(site));
}

}
22 changes: 21 additions & 1 deletion src/main/java/de/samply/frontend/FrontendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
import de.samply.user.roles.RolesExtractor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.*;

@Service
public class FrontendService {

private final ConstraintsService constraintsService;
private final FrontendConfiguration frontendConfiguration;

public FrontendService(ConstraintsService constraintsService) {
public FrontendService(
ConstraintsService constraintsService,
FrontendConfiguration frontendConfiguration) {
this.constraintsService = constraintsService;
this.frontendConfiguration = frontendConfiguration;
}

public Collection<ModuleActionsPackage> fetchModuleActionPackage(String site, Optional<String> projectCode, Optional<String> bridgehead) {
Expand Down Expand Up @@ -50,4 +55,19 @@ public Collection<ModuleActionsPackage> fetchModuleActionPackage(String site, Op
return moduleModuleActionsPackageMap.values();
}

public String fetchUrl(String site, Map<String, String> parameters) {
UriComponentsBuilder result = UriComponentsBuilder.fromHttpUrl(frontendConfiguration.getBaseUrl());
if (site != null) {
Optional<String> sitePath = frontendConfiguration.getSitePath(site);
if (sitePath.isPresent()) {
result.path(sitePath.get());
}
}
if (parameters != null && !parameters.isEmpty()) {
parameters.keySet().forEach(parameter ->
result.queryParamIfPresent(parameter, Optional.ofNullable(parameters.get(parameter))));
}
return result.toUriString();
}

}
6 changes: 5 additions & 1 deletion src/main/java/de/samply/query/QueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public QueryService(QueryRepository queryRepository) {
this.queryRepository = queryRepository;
}

public String createQuery(String query, QueryFormat queryFormat, String label, String description, OutputFormat outputFormat, String templateId) {
public String createQuery(
String query, QueryFormat queryFormat, String label, String description,
OutputFormat outputFormat, String templateId, String humanReadable, String explorerUrl) {
Query tempQuery = new Query();
tempQuery.setCode(generateQueryCode());
tempQuery.setQuery(query);
Expand All @@ -27,6 +29,8 @@ public String createQuery(String query, QueryFormat queryFormat, String label, S
tempQuery.setDescription(description);
tempQuery.setOutputFormat(outputFormat);
tempQuery.setTemplateId(templateId);
tempQuery.setHumanReadable(humanReadable);
tempQuery.setExplorerUrl(explorerUrl);
tempQuery = this.queryRepository.save(tempQuery);
return tempQuery.getCode();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ jwt.groups.claim: ${OIDC_CLAIM_GROUPS}
# explorer-code: berlin456
# exporter-url: http://berlin-bridgehead.com/ccp-exporter
# exporter-api-key: erewrtwwenbmtvwnbvetnbvter

#frontend:
# base-url: "http://localhost:8099"
# sites:
# project-dashboard: "/project-dashboard"
# project: "/project"
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ search_path TO samply;

CREATE TABLE samply.query
(
id SERIAL PRIMARY KEY,
code TEXT NOT NULL,
query TEXT NOT NULL,
query_format TEXT NOT NULL,
created_at TIMESTAMP NOT NULL,
output_format TEXT,
template_id TEXT,
label TEXT,
description TEXT
id SERIAL PRIMARY KEY,
code TEXT NOT NULL,
query TEXT NOT NULL,
query_format TEXT NOT NULL,
created_at TIMESTAMP NOT NULL,
human_readable TEXT,
explorer_url TEXT,
output_format TEXT,
template_id TEXT,
label TEXT,
description TEXT
);

CREATE TABLE samply.project
Expand Down

0 comments on commit e90670d

Please sign in to comment.