Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aus 4069 #175

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/org/auscope/portal/server/PortalApplication.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package org.auscope.portal.server;

import java.util.Map;

import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;


@SpringBootApplication
@ComponentScan(
Expand Down Expand Up @@ -35,5 +45,13 @@ public void initProperties() {
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}

@Bean
public OpenAPI customOpenAPI(@Value("${springdoc.version}") String appVersion) {
return new OpenAPI().components(new Components()).info(new Info().title("AuScope API").version(appVersion)
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
.schema("ParameterMap", new Schema<Map<String, String>>().addProperty("sourceAccountId",
new StringSchema().example("1")).addProperty("targetAccountId", new StringSchema().example("2")));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.auscope.portal.server.web.controllers;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.auscope.portal.core.server.controllers.BasePortalController;
import org.auscope.portal.core.services.PortalServiceException;
Expand All @@ -10,18 +12,49 @@
import org.auscope.portal.server.web.service.PortalUserService;
import org.auscope.portal.server.web.service.BookMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
//import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.Explode;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.enums.ParameterStyle;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.*;
import io.swagger.v3.oas.annotations.tags.Tag;
//import io.swagger.v3.oas.models.media.Schema;
import org.springframework.http.MediaType;


/**
* A controller class for accessing/modifying bookmark information for a user
* @author san239
*/
//@Tag(name = "bookmarks", description="Manage Bookmarks and the download options")
@RestController
@SecurityRequirement(name = "public")
@Tag(
name= "bookmarks",
description = "Alows the user to manage bookmarks for layers"
)
//@RequestMapping(consumes = "application/json", produces = "application/json")
@Controller
public class BookMarksController extends BasePortalController {

Expand All @@ -35,125 +68,178 @@ public class BookMarksController extends BasePortalController {
public @ResponseBody String handleException(IllegalArgumentException ex) {
return ex.getMessage();
}

/**
* Adds a dataset as a book mark. Uses fileIdentifier and service id from CSW record.
* @param fileIdentifier
* @param serviceId
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/addBookMark.do")
public ModelAndView addBookMark(@RequestParam(value="fileIdentifier") String fileIdentifier,
@RequestParam(value="serviceId") String serviceId) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
BookMark bookMark = new BookMark();
bookMark.setParent(userService.getLoggedInUser());
bookMark.setFileIdentifier(fileIdentifier);
bookMark.setServiceId(serviceId);
bookMark.setParent(user);
Integer id = bookmarkService.saveBookmark(bookMark);
@Operation(summary = "Adds a dataset as a bookmark.",
description = "Uses fileIdentifier and service id from CSW record.")
@PostMapping("/bookmarks")
public ModelAndView postBookMark(@RequestBody Map<String, Object> bm) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
BookMark bookMark = new BookMark();
bookMark.setParent(userService.getLoggedInUser());
bookMark.setFileIdentifier(bm.get("fileIdentifier").toString());
bookMark.setServiceId(bm.get("serviceId").toString());
bookMark.setParent(user);
Integer id = bookmarkService.saveBookmark(bookMark);
return generateJSONResponseMAV(true, id, "");
}

/**
* Retrieves book information for a user.
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/getBookMarks.do")
public ModelAndView getbookMarks() throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
List<BookMark> bookMarks = bookmarkService.getBookmarkByUser(user);
return generateJSONResponseMAV(true, bookMarks, "");
}

/**
* Removes a book mark.
* @param id
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/deleteBookMark.do")
public ModelAndView deleteBookMark(@RequestParam(value="id") Integer id) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
BookMark bookMark = new BookMark();
bookMark.setId(id);
bookMark.setParent(user);
bookmarkService.deleteBookmark(bookMark);
return generateJSONResponseMAV(true);
}
static class bookmark {
public int id;
public String fileIdentifier;
public int serviceId;
}

/**
* Retrieves bookmark information for a user.
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Retrieves bookmark information for a user.")
@GetMapping("/bookmarks")
@ApiResponse(
content = @Content(
schema = @Schema(
implementation = bookmark.class
),
mediaType = "application/json",
examples = {
@ExampleObject(
name = "list of bookmarks for the current user",
summary = "bookmarks example",
value = "{\"data\": [{"
+ "\"id\": 59,"
+ "\"fileIdentifier\": \"remanent-anomalies\","
+ "\"serviceId\": \"\","
+ "\"bookMarkDownloads\": [ ]},"
+ "{\"id\": 72,"
+ "\"fileIdentifier\": \"regolith-depth-layer\","
+ "\"serviceId\": \"\","
+ "\"bookMarkDownloads\": [ ]}],"
+ "\"msg\": \"\","
+ "\"success\": true}"
)
}))
public ModelAndView getbookMarks() throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
List<BookMark> bookMarks = bookmarkService.getBookmarkByUser(user);
return generateJSONResponseMAV(true, bookMarks, "");
}

/**
* Retrieves download options stored for a book mark
* @param bookmarkId
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/getDownloadOptions.do")
public ModelAndView getDownloadOptions(@RequestParam(value="bookmarkId") Integer bookmarkId) throws PortalServiceException {
BookMark bookmark = new BookMark();
bookmark.setId(bookmarkId);
List<BookMarkDownload> bookMarkDownloads = bookmarkService.getBookmarkDownloadsByBookMark(bookmark);
return generateJSONResponseMAV(true, bookMarkDownloads, "");
/**
* Retrieves download options stored for a book mark
* @param bookmarkId
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Retrieves a bookmark.")
@GetMapping("/bookmarks/{id}")
@Id
public ModelAndView getbookMarks(@PathVariable(value="id") Integer id) throws PortalServiceException {
Optional<BookMark> bookmark = bookmarkService.getBookmarkById(id);

return generateJSONResponseMAV(true, bookmark, "");
}

/**
* Removes a book mark.
* @param id
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Removes a bookmark.")
@DeleteMapping("/bookmarks/{id}")
public ModelAndView deleteBookMark(@PathVariable(value="id") Integer id) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
BookMark bookMark = new BookMark();
bookMark.setId(id);
bookMark.setParent(user);
bookmarkService.deleteBookmark(bookMark);
return generateJSONResponseMAV(true);
}

/**
* Retrieves download options stored for a book mark
* @param bookmarkId
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Retrieves download options stored for a bookmark.")
@GetMapping("/bookmarks/{id}/downloadOptions")
public ModelAndView getDownloadOptions(@PathVariable(value="id") Integer bookmarkId) throws PortalServiceException {
BookMark bookmark = new BookMark();
bookmark.setId(bookmarkId);
List<BookMarkDownload> bookMarkDownloads = bookmarkService.getBookmarkDownloadsByBookMark(bookmark);
return generateJSONResponseMAV(true, bookMarkDownloads, "");
}

/**
* Adds the download options for a book mark
* @param bookmarkId
* @param bookmarkOptionName
* @param url
* @param localPath
* @param name
* @param description
* @param northBoundLatitude
* @param eastBoundLongitude
* @param southBoundLatitude
* @param westBoundLongitude
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/saveDownloadOptions.do")
public ModelAndView saveDownloadOptions(@RequestParam(value="bookmarkId") Integer bookmarkId,
@RequestParam(value="bookmarkOptionName") String bookmarkOptionName,
@RequestParam(value="url") final String url,
@RequestParam(value="localPath") final String localPath,
@RequestParam(value="name") final String name,
@RequestParam(value="description") final String description,
@RequestParam(value="northBoundLatitude", required=false) final Double northBoundLatitude,
@RequestParam(value="eastBoundLongitude", required=false) final Double eastBoundLongitude,
@RequestParam(value="southBoundLatitude", required=false) final Double southBoundLatitude,
@RequestParam(value="westBoundLongitude", required=false) final Double westBoundLongitude) throws PortalServiceException {
PortalUser user = userService.getLoggedInUser();
BookMarkDownload bookMarkDownload = new BookMarkDownload();
BookMark bookmark = new BookMark();
bookmark.setId(bookmarkId);
bookmark.setParent(user);
bookMarkDownload.setParent(bookmark);
bookMarkDownload.setBookmarkOptionName(bookmarkOptionName);
bookMarkDownload.setUrl(url);
bookMarkDownload.setLocalPath(localPath);
bookMarkDownload.setName(name);
bookMarkDownload.setDescription(description);
bookMarkDownload.setEastBoundLongitude(eastBoundLongitude);
bookMarkDownload.setNorthBoundLatitude(northBoundLatitude);
bookMarkDownload.setWestBoundLongitude(westBoundLongitude);
bookMarkDownload.setSouthBoundLatitude(southBoundLatitude);
Integer id = bookmarkService.saveBookmarkDownload(bookMarkDownload);
/**
* Adds the download options for a book mark
* @param bookmarkId
* @param bookmarkOptionName
* @param url
* @param localPath
* @param name
* @param description
* @param northBoundLatitude
* @param eastBoundLongitude
* @param southBoundLatitude
* @param westBoundLongitude
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Adds the download options for a bookmark.")
@PostMapping("/booksmarks/{id}/downloadOptions")
@Parameter(name = "params",
in = ParameterIn.QUERY,
required = true,
schema = @Schema(type = "object", additionalProperties = Schema.AdditionalPropertiesValue.TRUE,
ref = "#/components/schemas/ParameterMap"),
style = ParameterStyle.FORM,
explode = Explode.TRUE)
public ModelAndView saveDownloadOptions(@PathVariable(value="id") Integer bookmarkId, @RequestBody Map<String, Object> bm) throws PortalServiceException {
if (!bm.containsKey("bookmarkId")) {
bm.put("bookmarkId", bookmarkId);
}
PortalUser user = userService.getLoggedInUser();
BookMarkDownload bookMarkDownload = new BookMarkDownload();
BookMark bookmark = new BookMark();
bookmark.setId((Integer) bm.get("bookmarkId"));
bookmark.setParent(user);
bookMarkDownload.setParent(bookmark);
bookMarkDownload.setBookmarkOptionName(bm.get("bookmarkOptionName").toString());
bookMarkDownload.setUrl(bm.get("url").toString());
bookMarkDownload.setLocalPath(bm.get("localPath").toString());
bookMarkDownload.setName(bm.get("name").toString());
bookMarkDownload.setDescription(bm.get("description").toString());
bookMarkDownload.setEastBoundLongitude((Double) bm.get("eastBoundLongitude"));
bookMarkDownload.setNorthBoundLatitude((Double) bm.get("northBoundLatitude"));
bookMarkDownload.setWestBoundLongitude((Double) bm.get("westBoundLongitude"));
bookMarkDownload.setSouthBoundLatitude((Double) bm.get("southBoundLatitude"));
Integer id = bookmarkService.saveBookmarkDownload(bookMarkDownload);
return generateJSONResponseMAV(true, id, "");
}

/**
* Removes a download option stored as a book mark for the user.
* @param id
* @return
* @throws PortalServiceException
*/
@RequestMapping("/secure/deleteDownloadOptions.do")
public ModelAndView deleteDownloadOptions(@RequestParam(value="id") Integer id) throws PortalServiceException {
BookMarkDownload bookMarkDownload = new BookMarkDownload();
bookMarkDownload.setId(id);
bookmarkService.deleteBookmarkDownload(bookMarkDownload);
return generateJSONResponseMAV(true);
}
/**
* Removes a download option stored as a book mark for the user.
* @param id
* @return
* @throws PortalServiceException
*/
@Operation(summary = "Removes a download option stored as a bookmark for the user.")
@DeleteMapping("/bookmarks/{id}/downloadOptions")
public ModelAndView deleteDownloadOptions(@RequestParam(value="id") Integer id) throws PortalServiceException {
BookMarkDownload bookMarkDownload = new BookMarkDownload();
bookMarkDownload.setId(id);
bookmarkService.deleteBookmarkDownload(bookMarkDownload);
return generateJSONResponseMAV(true);
}

}
Loading
Loading