From 632b6e2d2c2951ccb20b187a5100a8f5b258669a Mon Sep 17 00:00:00 2001 From: ZhangZihao Date: Thu, 11 Jul 2019 15:18:33 +0800 Subject: design modify 1 Change-Id: I32ef0ff484b786b9c5b73df8fd1b8cc97c5dc227 Issue-ID: DCAEGEN2-1658 Signed-off-by: ZhangZihao --- .../feeder/controller/DesignController.java | 179 +++++++++++++++++++ .../feeder/controller/PortalDesignController.java | 179 ------------------- .../org/onap/datalake/feeder/domain/Design.java | 92 ++++++++++ .../onap/datalake/feeder/domain/DesignType.java | 8 +- .../onap/datalake/feeder/domain/PortalDesign.java | 93 ---------- .../org/onap/datalake/feeder/domain/TopicName.java | 2 +- .../org/onap/datalake/feeder/dto/DesignConfig.java | 44 +++++ .../onap/datalake/feeder/dto/DesignTypeConfig.java | 5 +- .../datalake/feeder/dto/PortalDesignConfig.java | 52 ------ .../feeder/repository/DesignRepository.java | 36 ++++ .../feeder/repository/PortalDesignRepository.java | 39 ---- .../datalake/feeder/service/DesignService.java | 182 +++++++++++++++++++ .../feeder/service/PortalDesignService.java | 198 --------------------- 13 files changed, 541 insertions(+), 568 deletions(-) create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java create mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java delete mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java create mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java delete mode 100644 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java create mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java delete mode 100755 components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java (limited to 'components/datalake-handler/feeder/src/main/java/org') diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java new file mode 100644 index 00000000..0cac567c --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java @@ -0,0 +1,179 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.controller; + +import org.onap.datalake.feeder.controller.domain.PostReturnBody; +import org.onap.datalake.feeder.domain.Design; +import org.onap.datalake.feeder.dto.DesignConfig; +import org.onap.datalake.feeder.repository.DesignRepository; +import org.onap.datalake.feeder.service.DesignService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import io.swagger.annotations.ApiOperation; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + + +/** + * This controller manages design settings + * + * @author guochunmeng + */ +@RestController +@RequestMapping(value = "/designs", produces = MediaType.APPLICATION_JSON_VALUE) +public class DesignController { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private DesignRepository designRepository; + + @Autowired + private DesignService designService; + + @PostMapping("") + @ResponseBody + @ApiOperation(value="Create a design.") + public PostReturnBody createDesign(@RequestBody DesignConfig designConfig, BindingResult result, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DesignConfig: "+result.toString()); + return null; + } + + Design design = null; + try { + design = designService.fillDesignConfiguration(designConfig); + } catch (Exception e) { + log.debug("FillDesignConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage()); + return null; + } + designRepository.save(design); + log.info("Design save successed"); + return mkPostReturnBody(200, design); + } + + + @PutMapping("{id}") + @ResponseBody + @ApiOperation(value="Update a design.") + public PostReturnBody updateDesign(@RequestBody DesignConfig designConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DesignConfig: "+result.toString()); + return null; + } + + Design design = designService.getDesign(id); + if (design != null) { + try { + designService.fillDesignConfiguration(designConfig, design); + } catch (Exception e) { + log.debug("FillDesignConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage()); + return null; + } + designRepository.save(design); + log.info("Design update successed"); + return mkPostReturnBody(200, design); + } else { + sendError(response, 400, "Design not found: "+id); + return null; + } + + } + + + @DeleteMapping("/{id}") + @ResponseBody + @ApiOperation(value="delete a design.") + public void deleteDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{ + + Design oldDesign = designService.getDesign(id); + if (oldDesign == null) { + sendError(response, 400, "design not found "+id); + } else { + designRepository.delete(oldDesign); + response.setStatus(204); + } + } + + + @GetMapping("") + @ResponseBody + @ApiOperation(value="List all Designs") + public List queryAllDesign(){ + return designService.queryAllDesign(); + } + + + @PostMapping("/deploy/{id}") + @ResponseBody + @ApiOperation(value="Design deploy") + public void deployDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException { + + Design design = null; + try { + design = designRepository.findById(id).get(); + boolean flag; + try { + flag = designService.deploy(design); + if (flag) { + design.setSubmitted(true); + designRepository.save(design); + response.setStatus(204); + } else { + sendError(response, 400, "DeployDesign failed, id: "+id); + } + } catch (Exception e) { + log.debug("The request failed", e.getMessage()); + sendError(response, 400, "The request failed : "+e.getMessage()); + } + } catch (Exception e) { + log.debug("Design is null", e.getMessage()); + sendError(response, 400, "Design not found, id: "+id); + } + + } + + + private PostReturnBody mkPostReturnBody(int statusCode, Design design) { + PostReturnBody retBody = new PostReturnBody<>(); + retBody.setStatusCode(statusCode); + retBody.setReturnBody(design.getDesignConfig()); + return retBody; + } + + private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { + log.info(msg); + response.sendError(sc, msg); + } + +} \ No newline at end of file diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java deleted file mode 100644 index fa35b3ba..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.controller; - -import org.onap.datalake.feeder.controller.domain.PostReturnBody; -import org.onap.datalake.feeder.domain.PortalDesign; -import org.onap.datalake.feeder.dto.PortalDesignConfig; -import org.onap.datalake.feeder.repository.PortalDesignRepository; -import org.onap.datalake.feeder.service.PortalDesignService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import io.swagger.annotations.ApiOperation; - -import java.io.IOException; -import java.util.List; - -import javax.servlet.http.HttpServletResponse; - - -/** - * This controller manages portalDesign settings - * - * @author guochunmeng - */ -@RestController -@RequestMapping(value = "/portalDesigns", produces = MediaType.APPLICATION_JSON_VALUE) -public class PortalDesignController { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private PortalDesignRepository portalDesignRepository; - - @Autowired - private PortalDesignService portalDesignService; - - @PostMapping("") - @ResponseBody - @ApiOperation(value="Create a portalDesign.") - public PostReturnBody createPortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString()); - return null; - } - - PortalDesign portalDesign = null; - try { - portalDesign = portalDesignService.fillPortalDesignConfiguration(portalDesignConfig); - } catch (Exception e) { - log.debug("FillPortalDesignConfiguration failed", e.getMessage()); - sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage()); - return null; - } - portalDesignRepository.save(portalDesign); - log.info("PortalDesign save successed"); - return mkPostReturnBody(200, portalDesign); - } - - - @PutMapping("{id}") - @ResponseBody - @ApiOperation(value="Update a portalDesign.") - public PostReturnBody updatePortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString()); - return null; - } - - PortalDesign portalDesign = portalDesignService.getPortalDesign(id); - if (portalDesign != null) { - try { - portalDesignService.fillPortalDesignConfiguration(portalDesignConfig, portalDesign); - } catch (Exception e) { - log.debug("FillPortalDesignConfiguration failed", e.getMessage()); - sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage()); - return null; - } - portalDesignRepository.save(portalDesign); - log.info("PortalDesign update successed"); - return mkPostReturnBody(200, portalDesign); - } else { - sendError(response, 400, "PortalDesign not found: "+id); - return null; - } - - } - - - @DeleteMapping("/{id}") - @ResponseBody - @ApiOperation(value="delete a portalDesign.") - public void deletePortalDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{ - - PortalDesign oldPortalDesign= portalDesignService.getPortalDesign(id); - if (oldPortalDesign == null) { - sendError(response, 400, "portalDesign not found "+id); - } else { - portalDesignRepository.delete(oldPortalDesign); - response.setStatus(204); - } - } - - - @GetMapping("") - @ResponseBody - @ApiOperation(value="List all PortalDesigns") - public List queryAllPortalDesign(){ - return portalDesignService.queryAllPortalDesign(); - } - - - @PostMapping("/deploy/{id}") - @ResponseBody - @ApiOperation(value="PortalDesign deploy") - public void deployPortalDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException { - - PortalDesign portalDesign = null; - try { - portalDesign = portalDesignRepository.findById(id).get(); - boolean flag; - try { - flag = portalDesignService.deploy(portalDesign); - if (flag) { - portalDesign.setSubmitted(true); - portalDesignRepository.save(portalDesign); - response.setStatus(204); - } else { - sendError(response, 400, "DeployPortalDesign failed, id: "+id); - } - } catch (Exception e) { - log.debug("The request failed", e.getMessage()); - sendError(response, 400, "The request failed : "+e.getMessage()); - } - } catch (Exception e) { - log.debug("PortalDesign is null", e.getMessage()); - sendError(response, 400, "PortalDesign not found, id: "+id); - } - - } - - - private PostReturnBody mkPostReturnBody(int statusCode, PortalDesign portalDesign) { - PostReturnBody retBody = new PostReturnBody<>(); - retBody.setStatusCode(statusCode); - retBody.setReturnBody(portalDesign.getPortalDesignConfig()); - return retBody; - } - - private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { - log.info(msg); - response.sendError(sc, msg); - } - -} \ No newline at end of file diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java new file mode 100644 index 00000000..dde17b33 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java @@ -0,0 +1,92 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; + +import java.util.Set; + +import javax.persistence.*; + +import org.onap.datalake.feeder.dto.DesignConfig; + +/** + * Domain class representing design + * + * @author guochunmeng + */ + +@Getter +@Setter +@Entity +@Table(name = "design") +public class Design { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + private Integer id; + + @Column(name = "`name`") + private String name; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "topic_name_id", nullable = false) + private TopicName topicName;//topic name + + @Column(name = "`submitted`") + private Boolean submitted; + + @Column(name = "`body`") + private String body; + + @Column(name = "`note`") + private String note; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "design_type_id", nullable = false) + @JsonBackReference + private DesignType designType; + + //@ManyToMany(mappedBy = "topics", cascade=CascadeType.ALL) + @JsonBackReference + //@JsonManagedReference + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") }) + protected Set dbs; + + public DesignConfig getDesignConfig() { + + DesignConfig designConfig = new DesignConfig(); + + designConfig.setId(getId()); + designConfig.setBody(getBody()); + designConfig.setName(getName()); + designConfig.setNote(getNote()); + designConfig.setSubmitted(getSubmitted()); + designConfig.setTopicName(getTopicName().getId()); + designConfig.setDesignType(getDesignType().getId()); + + return designConfig; + } +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java index 83e1666a..dd327ea0 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java @@ -61,7 +61,7 @@ public class DesignType { private DbType dbType; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "designType") - protected Set designs = new HashSet<>(); + protected Set designs = new HashSet<>(); @Column(name = "`note`") private String note; @@ -69,8 +69,10 @@ public class DesignType { public DesignTypeConfig getDesignTypeConfig() { DesignTypeConfig designTypeConfig = new DesignTypeConfig(); - designTypeConfig.setDesignType(getName()); - //designTypeConfig.setDisplay(getDisplay()); + + designTypeConfig.setId(getId()); + designTypeConfig.setName(getName()); + return designTypeConfig; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java deleted file mode 100644 index 1cbf4e59..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.domain; - -import com.fasterxml.jackson.annotation.JsonBackReference; -import lombok.Getter; -import lombok.Setter; - -import java.util.Set; - -import javax.persistence.*; - -import org.onap.datalake.feeder.dto.PortalDesignConfig; - -/** - * Domain class representing design - * - * @author guochunmeng - */ - -@Getter -@Setter -@Entity -@Table(name = "design") -public class PortalDesign { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "`id`") - private Integer id; - - @Column(name = "`name`") - private String name; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "topic_name_id", nullable = false) - private TopicName topicName;//topic name - - @Column(name = "`submitted`") - private Boolean submitted; - - @Column(name = "`body`") - private String body; - - @Column(name = "`note`") - private String note; - - @ManyToOne(fetch=FetchType.EAGER) - @JoinColumn(name = "design_type_id", nullable = false) - @JsonBackReference - private DesignType designType; - - //@ManyToMany(mappedBy = "topics", cascade=CascadeType.ALL) - @JsonBackReference - //@JsonManagedReference - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") }) - protected Set dbs; - - public PortalDesignConfig getPortalDesignConfig() { - - PortalDesignConfig portalDesignConfig = new PortalDesignConfig(); - - portalDesignConfig.setId(getId()); - portalDesignConfig.setBody(getBody()); - portalDesignConfig.setName(getName()); - portalDesignConfig.setNote(getNote()); - portalDesignConfig.setSubmitted(getSubmitted()); - portalDesignConfig.setTopic(getTopicName().getId()); - portalDesignConfig.setDesignType(getDesignType().getId()); - portalDesignConfig.setDisplay(getDesignType().getName()); - - return portalDesignConfig; - } -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java index 35e6ea54..83227ada 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java @@ -49,7 +49,7 @@ public class TopicName { @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName") - protected Set designs; + protected Set designs; @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName") diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java new file mode 100755 index 00000000..d115529d --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.dto; + +import lombok.Getter; +import lombok.Setter; + +/** + * JSON request body for portalDesign Config. + * + * @author guochunmeng + */ + +@Getter +@Setter +public class DesignConfig { + + private Integer id; + private String name; + private Boolean submitted; + private String body; + private String note; + private String topicName; + private String designType; + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java index a4ed6d33..ddedf38b 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java @@ -33,8 +33,7 @@ import lombok.Setter; @Getter public class DesignTypeConfig { - private String designType; - - private String display; + private String id; + private String name; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java deleted file mode 100755 index 49e1cde5..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.dto; - -import lombok.Getter; -import lombok.Setter; - -/** - * JSON request body for portalDesign Config. - * - * @author guochunmeng - */ - -@Getter -@Setter -public class PortalDesignConfig { - - private Integer id; - - private String name; - - private Boolean submitted; - - private String body; - - private String note; - - private String topic; - - private String designType; - - private String display; - -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java new file mode 100644 index 00000000..f144e905 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.repository; + +import org.onap.datalake.feeder.domain.Design; +import org.springframework.data.repository.CrudRepository; + +/** + * Design Repository + * + * @author guochunmeng + */ + +public interface DesignRepository extends CrudRepository { + + Design findByName(String name); + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java deleted file mode 100644 index 181bc115..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.repository; - -import org.onap.datalake.feeder.domain.PortalDesign; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; - -import java.util.List; - -/** - * PortalDesign Repository - * - * @author guochunmeng - */ - -public interface PortalDesignRepository extends CrudRepository { - - PortalDesign findByName(String name); - -} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java new file mode 100755 index 00000000..61411a4d --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java @@ -0,0 +1,182 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.onap.datalake.feeder.config.ApplicationConfiguration; +import org.onap.datalake.feeder.domain.*; +import org.onap.datalake.feeder.domain.Design; +import org.onap.datalake.feeder.dto.DesignConfig; +import org.onap.datalake.feeder.enumeration.DesignTypeEnum; +import org.onap.datalake.feeder.repository.DesignTypeRepository; +import org.onap.datalake.feeder.repository.DesignRepository; +import org.onap.datalake.feeder.repository.TopicNameRepository; +import org.onap.datalake.feeder.util.HttpClientUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Service for portalDesigns + * + * @author guochunmeng + */ + +@Service +public class DesignService { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + static String POST_FLAG; + + @Autowired + private DesignRepository designRepository; + + @Autowired + private TopicNameRepository topicNameRepository; + + @Autowired + private DesignTypeRepository designTypeRepository; + + @Autowired + private ApplicationConfiguration applicationConfiguration; + + public Design fillDesignConfiguration(DesignConfig designConfig) { + Design design = new Design(); + fillDesign(designConfig, design); + return design; + } + + public void fillDesignConfiguration(DesignConfig designConfig, Design design) { + fillDesign(designConfig, design); + } + + private void fillDesign(DesignConfig designConfig, Design design) throws IllegalArgumentException { + + design.setId(designConfig.getId()); + design.setBody(designConfig.getBody()); + design.setName(designConfig.getName()); + design.setNote(designConfig.getNote()); + design.setSubmitted(designConfig.getSubmitted()); + + if (designConfig.getTopicName() == null) + throw new IllegalArgumentException("Can not find topicName in tpoic_name, topic name: " + designConfig.getTopicName()); + Optional topicName = topicNameRepository.findById(designConfig.getTopicName()); + if (!topicName.isPresent()) + throw new IllegalArgumentException("topicName is null " + designConfig.getTopicName()); + design.setTopicName(topicName.get()); + + + if (designConfig.getDesignType() == null) + throw new IllegalArgumentException("Can not find designType in design_type, designType id " + designConfig.getDesignType()); + Optional designType = designTypeRepository.findById(designConfig.getDesignType()); + if (!designType.isPresent()) + throw new IllegalArgumentException("designType is null"); + design.setDesignType(designType.get()); + + } + + public Design getDesign(Integer id) { + + Optional ret = designRepository.findById(id); + return ret.isPresent() ? ret.get() : null; + } + + public List queryAllDesign() { + + List designList = null; + List designConfigList = new ArrayList<>(); + designList = (List) designRepository.findAll(); + if (designList != null && designList.size() > 0) { + log.info("PortalDesignList is not null"); + for (Design design : designList) { + designConfigList.add(design.getDesignConfig()); + } + } + return designConfigList; + } + + public boolean deploy(Design design) { + DesignType designType = design.getDesignType(); + DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId()); + + switch (designTypeEnum) { + case KIBANA_DB: + return deployKibanaImport(design); + case ES_MAPPING: + return postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase()); + default: + log.error("Not implemented {}", designTypeEnum); + return false; + } + } + + private boolean deployKibanaImport(Design design) throws RuntimeException { + POST_FLAG = "KibanaDashboardImport"; + String requestBody = design.getBody(); + Portal portal = design.getDesignType().getPortal(); + String portalHost = portal.getHost(); + Integer portalPort = portal.getPort(); + String url = ""; + + if (portalHost == null || portalPort == null) { + String dbHost = portal.getDb().getHost(); + Integer dbPort = portal.getDb().getPort(); + url = kibanaImportUrl(dbHost, dbPort); + } else { + url = kibanaImportUrl(portalHost, portalPort); + } + return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG); + + } + + private String kibanaImportUrl(String host, Integer port) { + if (port == null) { + port = applicationConfiguration.getKibanaPort(); + } + return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi(); + } + + /** + * successed resp: { "acknowledged": true } + * + * @param design + * @param templateName + * @return flag + */ + public boolean postEsMappingTemplate(Design design, String templateName) throws RuntimeException { + POST_FLAG = "ElasticsearchMappingTemplate"; + String requestBody = design.getBody(); + + //FIXME + Set dbs = design.getDbs(); + //submit to each ES in dbs + + //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG); + return false; + } + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java deleted file mode 100755 index 408e4971..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import org.onap.datalake.feeder.config.ApplicationConfiguration; -import org.onap.datalake.feeder.domain.Db; -import org.onap.datalake.feeder.domain.DbType; -import org.onap.datalake.feeder.domain.DesignType; -import org.onap.datalake.feeder.domain.Portal; -import org.onap.datalake.feeder.domain.PortalDesign; -import org.onap.datalake.feeder.domain.Topic; -import org.onap.datalake.feeder.domain.TopicName; -import org.onap.datalake.feeder.dto.PortalDesignConfig; -import org.onap.datalake.feeder.enumeration.DbTypeEnum; -import org.onap.datalake.feeder.enumeration.DesignTypeEnum; -import org.onap.datalake.feeder.repository.DesignTypeRepository; -import org.onap.datalake.feeder.repository.PortalDesignRepository; -import org.onap.datalake.feeder.repository.TopicNameRepository; -import org.onap.datalake.feeder.service.db.CouchbaseService; -import org.onap.datalake.feeder.service.db.DbStoreService; -import org.onap.datalake.feeder.service.db.ElasticsearchService; -import org.onap.datalake.feeder.service.db.HdfsService; -import org.onap.datalake.feeder.service.db.MongodbService; -import org.onap.datalake.feeder.util.HttpClientUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * Service for portalDesigns - * - * @author guochunmeng - */ - -@Service -public class PortalDesignService { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - static String POST_FLAG; - - @Autowired - private PortalDesignRepository portalDesignRepository; - - @Autowired - private TopicNameRepository topicNameRepository; - - @Autowired - private DesignTypeRepository designTypeRepository; - - @Autowired - private ApplicationConfiguration applicationConfiguration; - - public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception { - PortalDesign portalDesign = new PortalDesign(); - fillPortalDesign(portalDesignConfig, portalDesign); - return portalDesign; - } - - public void fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws Exception { - fillPortalDesign(portalDesignConfig, portalDesign); - } - - private void fillPortalDesign(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws IllegalArgumentException { - - portalDesign.setId(portalDesignConfig.getId()); - portalDesign.setBody(portalDesignConfig.getBody()); - portalDesign.setName(portalDesignConfig.getName()); - portalDesign.setNote(portalDesignConfig.getNote()); - portalDesign.setSubmitted(portalDesignConfig.getSubmitted()); - - if (portalDesignConfig.getTopic() != null) { - Optional topicName = topicNameRepository.findById(portalDesignConfig.getTopic()); - if (topicName.isPresent()) { - portalDesign.setTopicName(topicName.get()); - } else { - throw new IllegalArgumentException("topic is null " + portalDesignConfig.getTopic()); - } - } else { - throw new IllegalArgumentException("Can not find topic in DB, topic name: " + portalDesignConfig.getTopic()); - } - - if (portalDesignConfig.getDesignType() != null) { - DesignType designType = designTypeRepository.findById(portalDesignConfig.getDesignType()).get(); - if (designType == null) - throw new IllegalArgumentException("designType is null"); - portalDesign.setDesignType(designType); - } else { - throw new IllegalArgumentException("Can not find designType in Design_type, designType name " + portalDesignConfig.getDesignType()); - } - - } - - public PortalDesign getPortalDesign(Integer id) { - - Optional ret = portalDesignRepository.findById(id); - return ret.isPresent() ? ret.get() : null; - } - - public List queryAllPortalDesign() { - - List portalDesignList = null; - List portalDesignConfigList = new ArrayList<>(); - portalDesignList = (List) portalDesignRepository.findAll(); - if (portalDesignList != null && portalDesignList.size() > 0) { - log.info("PortalDesignList is not null"); - for (PortalDesign portalDesign : portalDesignList) { - portalDesignConfigList.add(portalDesign.getPortalDesignConfig()); - } - } - return portalDesignConfigList; - } - - public boolean deploy(PortalDesign portalDesign) { - DesignType designType = portalDesign.getDesignType(); - DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId()); - - switch (designTypeEnum) { - case KIBANA_DB: - return deployKibanaImport(portalDesign); - case ES_MAPPING: - return postEsMappingTemplate(portalDesign, portalDesign.getTopicName().getId().toLowerCase()); - default: - log.error("Not implemented {}", designTypeEnum); - return false; - } - } - - private boolean deployKibanaImport(PortalDesign portalDesign) throws RuntimeException { - POST_FLAG = "KibanaDashboardImport"; - String requestBody = portalDesign.getBody(); - Portal portal = portalDesign.getDesignType().getPortal(); - String portalHost = portal.getHost(); - Integer portalPort = portal.getPort(); - String url = ""; - - if (portalHost == null || portalPort == null) { - String dbHost = portal.getDb().getHost(); - Integer dbPort = portal.getDb().getPort(); - url = kibanaImportUrl(dbHost, dbPort); - } else { - url = kibanaImportUrl(portalHost, portalPort); - } - return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG); - - } - - private String kibanaImportUrl(String host, Integer port) { - if (port == null) { - port = applicationConfiguration.getKibanaPort(); - } - return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi(); - } - - /** - * successed resp: { "acknowledged": true } - * - * @param portalDesign - * @param templateName - * @return flag - */ - public boolean postEsMappingTemplate(PortalDesign portalDesign, String templateName) throws RuntimeException { - POST_FLAG = "ElasticsearchMappingTemplate"; - String requestBody = portalDesign.getBody(); - - //FIXME - Set dbs = portalDesign.getDbs(); - //submit to each ES in dbs - - //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG); - return false; - } - -} -- cgit 1.2.3-korg