-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
229 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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/org/auscope/portal/server/params/HashmapParams.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,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; | ||
} | ||
} | ||
|
||
|
112 changes: 112 additions & 0 deletions
112
src/main/java/org/auscope/portal/server/web/controllers/PortalParamsController.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,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); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/auscope/portal/server/web/repositories/PortalParamsRepository.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,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); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/auscope/portal/server/web/service/PortalParamsService.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,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); | ||
} | ||
} |