Skip to content

Commit

Permalink
AUS-4035 Added ROI to DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
jia020 committed Apr 30, 2024
1 parent 61f09d8 commit 1528b9b
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/db/mysql/auscope-schema-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DROP TABLE IF EXISTS `job_purchases`;
DROP TABLE IF EXISTS `job_annotations`;
DROP TABLE IF EXISTS `jobs`;
DROP TABLE IF EXISTS `series`;
DROP TABLE IF EXISTS `hashmap_params`;
DROP TABLE IF EXISTS `bookmark_download_options`;
DROP TABLE IF EXISTS `bookmarks`;
DROP TABLE IF EXISTS `data_purchases`;
Expand Down Expand Up @@ -163,6 +164,11 @@ CREATE TABLE `states` (
REFERENCES users(`id`)
ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE `hashmap_params` (
`key` varchar(128) NOT NULL,
`value` varchar(1000000) NOT NULL,
PRIMARY KEY (`key`)
);

CREATE TABLE `bookmarks` (
`fileIdentifier` varchar(128) NOT NULL,
Expand Down
7 changes: 7 additions & 0 deletions src/main/db/postgres/auscope-schema-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DROP TABLE IF EXISTS job_purchases;
DROP TABLE IF EXISTS job_annotations;
DROP TABLE IF EXISTS jobs;
DROP TABLE IF EXISTS series;
DROP TABLE IF EXISTS hashmap_params;
DROP TABLE IF EXISTS bookmark_download_options;
DROP TABLE IF EXISTS bookmarks;
DROP TABLE IF EXISTS data_purchases;
Expand Down Expand Up @@ -176,6 +177,12 @@ CREATE TABLE states (
ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE TABLE hashmap_params (
"key" varchar(128) NOT NULL,
"value" text NOT NULL,
PRIMARY KEY ("key")
);

CREATE SEQUENCE bookmarks_seq;

CREATE TABLE bookmarks (
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/org/auscope/portal/server/params/HashmapParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.auscope.portal.server.params;

import java.io.Serializable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;


/**
* Simple class that stores hashmap(key, value) etc. ROI
* @author jia020
*
*/
@Entity
@Table(name = "hashmap_params")
public class HashmapParams implements Serializable {

private static final long serialVersionUID = 8620093753366974709L;
/** The primary key for this Params*/
@Id
@Column(nullable=false)
private String key;
/** service id of the dataset */
@Column(length = 1000000,nullable=false)
private String value;

public HashmapParams() {
super();
}

public HashmapParams(String key, String value) {
super();
this.setKey(key);
this.setValue(value);
}
/**
* get key
* @return
*/
public String getKey( ) {
return this.key;
}

/**
* set key
* @param id
*/
public void setKey(String key) {
this.key = key;
}

/**
* Get value
* @return
*/
public String getValue() {
return value;
}
/**
* Set value
* @return
*/
public void setValue(String value) {
this.value = value;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.auscope.portal.server.web.controllers;
import org.auscope.portal.core.server.controllers.BasePortalController;
import org.auscope.portal.core.services.PortalServiceException;
import org.auscope.portal.server.params.HashmapParams;
import org.auscope.portal.server.web.security.PortalUser;
import org.auscope.portal.server.web.service.PortalParamsService;
import org.auscope.portal.server.web.service.PortalUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
* Controller class for accessing/modifying a user's Params
*/
@Controller
public class PortalParamsController extends BasePortalController {

@Autowired
PortalParamsService paramsService;

@Autowired
PortalUserService userService;

/**
* Retrieve the params for the current user
* @param key
*
* @return a list of Params objects, provided the user has any
*/
@RequestMapping("/secure/getUserParams.do")
public ModelAndView getUserParams(
@RequestParam(value="key") String key) throws PortalServiceException {

PortalUser user = userService.getLoggedInUser();
if (user == null) {
return generateJSONResponseMAV(false);
}
HashmapParams params = paramsService.getParamsByKey(key);
return generateJSONResponseMAV(true, params, "");
}

/**
* Add a new params for an authenticated user
*
* @param key
* @param value
* @throws PortalServiceException
*/
@RequestMapping("/secure/saveUserParams.do")
public ModelAndView addParamsForAuthenticatedUser(
@RequestParam(value="key") String key,
@RequestParam(value="value") String value) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
if (user == null) {
return generateJSONResponseMAV(false);
}
HashmapParams params = new HashmapParams();
params.setKey(key);
params.setValue(value);
String newKey = paramsService.saveParams(params);
return generateJSONResponseMAV(true, newKey, "");
}

/**
* Update an existing params
*
* @param key
* @param value
* @return json with key
* @throws PortalServiceException
*/
@RequestMapping("/secure/updateUserParams.do")
public ModelAndView updateUserParams(
@RequestParam(value="key") String key,
@RequestParam(value="value") String value) throws PortalServiceException {
// Get existing params and make sure current user is owner
PortalUser user = userService.getLoggedInUser();
HashmapParams params = paramsService.getParamsByKey(key);

if (params == null || user == null ) {
return generateJSONResponseMAV(false);
}
// Update params
params.setKey(key);
params.setValue(value);
String newKey = paramsService.saveParams(params);
return generateJSONResponseMAV(true, newKey, "");
}

/**
* Delete a params from the DB
*
* @param key
* @return a true response if successful, a PortalServiceException will be thrown if not
* @throws PortalServiceException
*/
@RequestMapping("/secure/deleteUserParams.do")
public ModelAndView deleteUserParams(
@RequestParam(value="key") String key) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
if (user == null) {
return generateJSONResponseMAV(false);
}
HashmapParams params = new HashmapParams();
params.setKey(key);
paramsService.deleteParams(params);
return generateJSONResponseMAV(true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.auscope.portal.server.web.repositories;

import org.auscope.portal.server.params.HashmapParams;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PortalParamsRepository extends JpaRepository<HashmapParams, Integer> {
HashmapParams findByKey(String key);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.auscope.portal.server.web.service;
import org.auscope.portal.server.params.HashmapParams;
import org.auscope.portal.server.web.repositories.PortalParamsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PortalParamsService {

@Autowired
private PortalParamsRepository paramsRepository;

public HashmapParams getParamsByKey(String key) {
return paramsRepository.findByKey(key);
}

public String saveParams(HashmapParams params) {
HashmapParams s = paramsRepository.saveAndFlush(params);
return s.getKey();
}

public void deleteParams(HashmapParams params) {
paramsRepository.delete(params);
}
}

0 comments on commit 1528b9b

Please sign in to comment.