diff --git a/sysml/sysml.gradle b/cameo/cameo.gradle similarity index 100% rename from sysml/sysml.gradle rename to cameo/cameo.gradle diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoConstants.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoConstants.java similarity index 99% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/CameoConstants.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/CameoConstants.java index 29aaaf5d5..b8386d663 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoConstants.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoConstants.java @@ -1,4 +1,4 @@ -package org.openmbee.sdvc.sysml; +package org.openmbee.sdvc.cameo; import java.util.HashMap; import java.util.Map; diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoEdgeType.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoEdgeType.java similarity index 94% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/CameoEdgeType.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/CameoEdgeType.java index 220034498..d7db11bb2 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoEdgeType.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoEdgeType.java @@ -1,4 +1,4 @@ -package org.openmbee.sdvc.sysml; +package org.openmbee.sdvc.cameo; import java.util.HashMap; import java.util.Map; diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoNodeType.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoNodeType.java similarity index 96% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/CameoNodeType.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/CameoNodeType.java index e62ab0a97..b2118eace 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/CameoNodeType.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/CameoNodeType.java @@ -1,4 +1,4 @@ -package org.openmbee.sdvc.sysml; +package org.openmbee.sdvc.cameo; import java.util.HashMap; import java.util.Map; diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/DocumentsController.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/DocumentsController.java similarity index 87% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/DocumentsController.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/DocumentsController.java index 1f67bf06c..fe28d29c9 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/DocumentsController.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/DocumentsController.java @@ -1,6 +1,6 @@ -package org.openmbee.sdvc.sysml.controllers; +package org.openmbee.sdvc.cameo.controllers; -import org.openmbee.sdvc.sysml.services.CameoNodeService; +import org.openmbee.sdvc.cameo.services.CameoNodeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/GroupsController.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/GroupsController.java similarity index 88% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/GroupsController.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/GroupsController.java index 1b026b6b8..590092d38 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/controllers/GroupsController.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/controllers/GroupsController.java @@ -1,7 +1,7 @@ -package org.openmbee.sdvc.sysml.controllers; +package org.openmbee.sdvc.cameo.controllers; import org.openmbee.sdvc.crud.controllers.BaseController; -import org.openmbee.sdvc.sysml.services.CameoNodeService; +import org.openmbee.sdvc.cameo.services.CameoNodeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; diff --git a/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoHelper.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoHelper.java new file mode 100644 index 000000000..c54991713 --- /dev/null +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoHelper.java @@ -0,0 +1,14 @@ +package org.openmbee.sdvc.cameo.services; + +import org.openmbee.sdvc.json.ElementJson; +import org.openmbee.sdvc.cameo.CameoNodeType; +import org.springframework.stereotype.Component; + +@Component +public class CameoHelper { + + public static CameoNodeType getNodeType(ElementJson e) { + return CameoNodeType.PACKAGE; + } + +} diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoNodeService.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoNodeService.java similarity index 69% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoNodeService.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoNodeService.java index 9d5fb6f36..32567ee49 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoNodeService.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoNodeService.java @@ -1,4 +1,4 @@ -package org.openmbee.sdvc.sysml.services; +package org.openmbee.sdvc.cameo.services; import java.time.Instant; import java.util.ArrayList; @@ -7,14 +7,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.openmbee.sdvc.crud.controllers.commits.CommitJson; -import org.openmbee.sdvc.crud.controllers.elements.ElementJson; -import org.openmbee.sdvc.crud.controllers.elements.ElementsRequest; +import org.openmbee.sdvc.json.CommitJson; +import org.openmbee.sdvc.json.ElementJson; import org.openmbee.sdvc.crud.controllers.elements.ElementsResponse; -import org.openmbee.sdvc.crud.domains.EdgeType; import org.openmbee.sdvc.crud.domains.Node; import org.openmbee.sdvc.crud.services.DefaultNodeService; import org.openmbee.sdvc.crud.services.NodeService; +import org.openmbee.sdvc.cameo.CameoEdgeType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; @@ -42,19 +41,19 @@ public void extraProcessPostedElement(ElementJson element, Node node, Set oldElasticIds, CommitJson cmjs, Instant now, Map toSave, Map response) { - node.setNodeType(CameoHelper.getNodeType(element)); + node.setNodeType(CameoHelper.getNodeType(element).getValue()); } @Override - public Map>> getEdgeInfo(Collection elements) { - Map>> res = new HashMap<>(); + public Map>> getEdgeInfo(Collection elements) { + Map>> res = new HashMap<>(); for (ElementJson e: elements) { String owner = (String) e.get("ownerId"); if (owner != null && !owner.isEmpty()) { - if (!res.containsKey(EdgeType.CONTAINMENT)) { - res.put(EdgeType.CONTAINMENT, new ArrayList<>()); + if (!res.containsKey(CameoEdgeType.CONTAINMENT.getValue())) { + res.put(CameoEdgeType.CONTAINMENT.getValue(), new ArrayList<>()); } - res.get(EdgeType.CONTAINMENT).add(Pair.of(owner, e.getId())); + res.get(CameoEdgeType.CONTAINMENT.getValue()).add(Pair.of(owner, e.getId())); } } //TODO when to delete existing edges diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoProjectService.java b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoProjectService.java similarity index 69% rename from sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoProjectService.java rename to cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoProjectService.java index 26c8746de..bc5f8d076 100644 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoProjectService.java +++ b/cameo/src/main/java/org/openmbee/sdvc/cameo/services/CameoProjectService.java @@ -1,6 +1,6 @@ -package org.openmbee.sdvc.sysml.services; +package org.openmbee.sdvc.cameo.services; -import org.openmbee.sdvc.crud.controllers.projects.ProjectJson; +import org.openmbee.sdvc.json.ProjectJson; import org.openmbee.sdvc.crud.services.DefaultProjectService; import org.openmbee.sdvc.crud.services.ProjectService; import org.springframework.stereotype.Service; @@ -10,7 +10,7 @@ public class CameoProjectService extends DefaultProjectService implements ProjectService { public ProjectJson post(ProjectJson projectsPost) { - //TODO create elastic index with sysml specific mapping + //TODO create elastic index with cameo specific mapping return super.post(projectsPost); } } diff --git a/crud/crud.gradle b/crud/crud.gradle index c5159b08a..85bb37661 100644 --- a/crud/crud.gradle +++ b/crud/crud.gradle @@ -2,7 +2,7 @@ apply plugin: 'io.spring.convention.spring-module' dependencies { compile project(':core') - compile project(':uml') + compile project(':json') compile group: 'org.springframework', name: 'spring-jdbc', version: '5.0.8.RELEASE' compile 'org.elasticsearch:elasticsearch:6.5.1' compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.5.1' diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseController.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseController.java index f38d5cad2..81ba7841a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseController.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseController.java @@ -1,11 +1,9 @@ package org.openmbee.sdvc.crud.controllers; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public abstract class BaseController { protected final Logger logger = LogManager.getLogger(getClass()); - protected final ObjectMapper om = new ObjectMapper(); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseJson.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseJson.java deleted file mode 100644 index 2c47ab816..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/BaseJson.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.openmbee.sdvc.crud.controllers; - -import java.util.HashMap; - -public class BaseJson extends HashMap { - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String ELASTICID = "_elasticId"; - public static final String PROJECTID = "_projectId"; - public static final String REFID = "_refId"; - public static final String MODIFIER = "_modifier"; - public static final String MODIFIED = "_modified"; - public static final String CREATOR = "_creator"; - public static final String CREATED = "_created"; - public static final String COMMITID = "_commitId"; - - - public String getId() { - return (String) this.get(ID); - } - - public BaseJson setId(String id) { - this.put(ID, id); - return this; - } - - public String getName() { - return (String) this.get(NAME); - } - - public BaseJson setName(String name) { - this.put(NAME, name); - return this; - } - - public String getElasticId() { - return (String) this.get(ELASTICID); - } - - public BaseJson setElasticId(String elasticId) { - this.put(ELASTICID, elasticId); - return this; - } - - public String getProjectId() { - return (String) this.get(PROJECTID); - } - - public BaseJson setProjectId(String projectId) { - this.put(PROJECTID, projectId); - return this; - } - - public String getRefId() { - return (String) this.get(REFID); - } - - public BaseJson setRefId(String refId) { - this.put(REFID, refId); - return this; - } - - public String getModifier() { - return (String) this.get(MODIFIER); - } - - public BaseJson setModifier(String modifier) { - this.put(MODIFIER, modifier); - return this; - } - - public String getModified() { - return (String) this.get(MODIFIED); - } - - public BaseJson setModified(String modified) { - this.put(MODIFIED, modified); - return this; - } - - public String getCreator() { - return (String) this.get(CREATOR); - } - - public BaseJson setCreator(String creator) { - this.put(CREATOR, creator); - return this; - } - - public String getCreated() { - return (String) this.get(CREATED); - } - - public BaseJson setCreated(String created) { - this.put(CREATED, created); - return this; - } - - public String getCommitId() { - return(String) this.get(COMMITID); - } - - public BaseJson setCommitId(String commitId) { - this.put(COMMITID, commitId); - return this; - } -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesPost.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesPost.java index a417a95c6..963f5bd4d 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesPost.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesPost.java @@ -10,6 +10,7 @@ import org.openmbee.sdvc.crud.repositories.branch.BranchDAO; import org.openmbee.sdvc.crud.repositories.commit.CommitDAO; import org.openmbee.sdvc.crud.services.DatabaseDefinitionService; +import org.openmbee.sdvc.json.RefJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -50,7 +51,7 @@ public ResponseEntity handleRequest( Branch b = new Branch(); b.setBranchId(branch.getId()); b.setBranchName(branch.getName()); - b.setElasticId("blah"); + b.setDescription("blah"); b.setTimestamp(Instant.now()); logger.info("Saving branch: {}", branch.getId()); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesRequest.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesRequest.java index cd5501c43..84b090f3f 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesRequest.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesRequest.java @@ -2,6 +2,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseRequest; +import org.openmbee.sdvc.json.RefJson; public class BranchesRequest extends BaseRequest { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesResponse.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesResponse.java index b5a3e1322..0f252d333 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesResponse.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/BranchesResponse.java @@ -4,6 +4,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.Constants; +import org.openmbee.sdvc.json.RefJson; public class BranchesResponse extends BaseResponse { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsRequest.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsRequest.java index 273b35ef1..5e26a5fab 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsRequest.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsRequest.java @@ -2,6 +2,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseRequest; +import org.openmbee.sdvc.json.CommitJson; public class CommitsRequest extends BaseRequest { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsResponse.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsResponse.java index db09a575d..558b7981a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsResponse.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitsResponse.java @@ -4,6 +4,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.Constants; +import org.openmbee.sdvc.json.CommitJson; public class CommitsResponse extends BaseResponse { @@ -18,5 +19,4 @@ public List getCommits() { public void setCommits(List commits) { this.put(Constants.COMMIT_KEY, commits); } - } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsRequest.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsRequest.java index 2743ca559..aba7a942f 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsRequest.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsRequest.java @@ -2,6 +2,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseRequest; +import org.openmbee.sdvc.json.ElementJson; public class ElementsRequest extends BaseRequest { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsResponse.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsResponse.java index 5aa2a4e2c..1d7bc5374 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsResponse.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementsResponse.java @@ -4,6 +4,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.Constants; +import org.openmbee.sdvc.json.ElementJson; public class ElementsResponse extends BaseResponse { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgJson.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgJson.java deleted file mode 100644 index 611bced24..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgJson.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.controllers.orgs; - -import org.openmbee.sdvc.crud.controllers.BaseJson; - -public class OrgJson extends BaseJson { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsDelete.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsDelete.java deleted file mode 100644 index d3d67663f..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsDelete.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.controllers.orgs; - -import org.openmbee.sdvc.crud.controllers.BaseController; - -public class OrganizationsDelete extends BaseController { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsGet.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsGet.java deleted file mode 100644 index cadb5177c..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsGet.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.openmbee.sdvc.crud.controllers.orgs; - -import org.openmbee.sdvc.crud.controllers.BaseController; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/orgs") -public class OrganizationsGet extends BaseController { - - @GetMapping(value = {"", "/{orgId}"}) - public ResponseEntity handleRequest(@PathVariable(required = false) String orgId) { - if (orgId != null) { - logger.debug("OrgId given: ", orgId); - return ResponseEntity.ok(orgId); - } else { - logger.debug("No OrgId given"); - return ResponseEntity.ok("Requesting all orgs"); - } - } -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPut.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPut.java deleted file mode 100644 index 65e9f763f..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPut.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.controllers.orgs; - -import org.openmbee.sdvc.crud.controllers.BaseController; - -public class OrganizationsPut extends BaseController { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsRequest.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsRequest.java index 0dc324a31..4af3251a5 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsRequest.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsRequest.java @@ -2,6 +2,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseRequest; +import org.openmbee.sdvc.json.OrgJson; public class OrganizationsRequest extends BaseRequest { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsResponse.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsResponse.java index c9bec0918..f960c3448 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsResponse.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsResponse.java @@ -4,6 +4,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.Constants; +import org.openmbee.sdvc.json.OrgJson; public class OrganizationsResponse extends BaseResponse { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPost.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgsController.java similarity index 68% rename from crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPost.java rename to crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgsController.java index fb6de0816..498d73701 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrganizationsPost.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/orgs/OrgsController.java @@ -5,23 +5,40 @@ import org.openmbee.sdvc.crud.controllers.BaseController; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.ErrorResponse; +import org.openmbee.sdvc.json.OrgJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; +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.RestController; - @RestController @RequestMapping("/orgs") -public class OrganizationsPost extends BaseController { +public class OrgsController extends BaseController { - @Autowired OrganizationRepository organizationRepository; + @Autowired + public OrgsController(OrganizationRepository organizationRepository) { + this.organizationRepository = organizationRepository; + } + + @GetMapping(value = {"", "/{orgId}"}) + public ResponseEntity handleGet(@PathVariable(required = false) String orgId) { + if (orgId != null) { + logger.debug("OrgId given: ", orgId); + return ResponseEntity.ok(orgId); + } else { + logger.debug("No OrgId given"); + return ResponseEntity.ok("Requesting all orgs"); + } + } + @PostMapping - public ResponseEntity handleRequest( + public ResponseEntity handlePost( @RequestBody OrganizationsRequest orgPost) { if (!orgPost.getOrgs().isEmpty()) { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectJson.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectJson.java deleted file mode 100644 index aafa2fe91..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectJson.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.controllers.projects; - -import org.openmbee.sdvc.crud.controllers.BaseJson; - -public class ProjectJson extends BaseJson { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsController.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsController.java index 3302ee78c..c18c29be5 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsController.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsController.java @@ -5,6 +5,7 @@ import org.openmbee.sdvc.crud.controllers.ErrorResponse; import org.openmbee.sdvc.crud.services.ProjectService; import org.openmbee.sdvc.crud.services.ServiceFactory; +import org.openmbee.sdvc.json.ProjectJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsRequest.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsRequest.java index 7b6d709f2..82ffe9399 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsRequest.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsRequest.java @@ -2,6 +2,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseRequest; +import org.openmbee.sdvc.json.ProjectJson; public class ProjectsRequest extends BaseRequest { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsResponse.java b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsResponse.java index 0cdcce1c6..507e1529d 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsResponse.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/controllers/projects/ProjectsResponse.java @@ -4,6 +4,7 @@ import java.util.List; import org.openmbee.sdvc.crud.controllers.BaseResponse; import org.openmbee.sdvc.crud.controllers.Constants; +import org.openmbee.sdvc.json.ProjectJson; public class ProjectsResponse extends BaseResponse { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Branch.java b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Branch.java index 07cdbfaa2..f244b3b96 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Branch.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Branch.java @@ -17,7 +17,7 @@ public class Branch { @Column(name = "id", updatable = false, nullable = false) Long id; - private String elasticId; + private String description; private String branchId; private String branchName; @@ -33,9 +33,9 @@ public Branch() { } - public Branch(String elasticId, String branchId, String branchName, String parentRef, + public Branch(String description, String branchId, String branchName, String parentRef, Long parentCommit, Instant timestamp, boolean tag, boolean deleted) { - setElasticId(elasticId); + setDescription(description); setBranchId(branchId); setBranchName(branchName); setParentRefId(parentRef); @@ -53,12 +53,12 @@ public void setId(Long id) { this.id = id; } - public String getElasticId() { - return elasticId; + public String getDescription() { + return description; } - public void setElasticId(String elasticId) { - this.elasticId = elasticId; + public void setDescription(String description) { + this.description = description; } public String getBranchId() { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Commit.java b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Commit.java index 5657109a9..3e2f9509a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Commit.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Commit.java @@ -22,10 +22,12 @@ public class Commit implements Serializable { private Instant timestamp; - private String elasticId; + private String indexId; private String branchId; private String creator; + private String comment; + @Column(columnDefinition = "smallint") private CommitType commitType; @@ -45,12 +47,12 @@ public void setTimestamp(Instant timestamp) { this.timestamp = timestamp; } - public String getElasticId() { - return elasticId; + public String getIndexId() { + return indexId; } - public void setElasticId(String elasticId) { - this.elasticId = elasticId; + public void setIndexId(String indexId) { + this.indexId = indexId; } public String getBranchId() { @@ -77,4 +79,12 @@ public void setCommitType(CommitType commitType) { this.commitType = commitType; } + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Edge.java b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Edge.java index a0ef988eb..5ec7bc3d3 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Edge.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Edge.java @@ -28,7 +28,7 @@ public class Edge { private Node child; @Column(columnDefinition = "smallint") - private EdgeType edgeType; + private Integer edgeType; public Long getId() { return id; @@ -54,11 +54,11 @@ public void setChild(Node child) { this.child = child; } - public EdgeType getEdgeType() { + public Integer getEdgeType() { return edgeType; } - public void setEdgeType(EdgeType edgeType) { + public void setEdgeType(Integer edgeType) { this.edgeType = edgeType; } } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Node.java b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Node.java index 3e10d4da0..050354bf7 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/domains/Node.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/domains/Node.java @@ -2,8 +2,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -18,26 +16,27 @@ public class Node { @Column(name = "id", updatable = false, nullable = false) Long id; - private String sysmlId; - private String elasticId; + private String nodeId; + private String indexId; private String lastCommit; private String initialCommit; private boolean deleted; @Column(columnDefinition = "smallint") - private NodeType nodeType; + private Integer nodeType; public Node() { } - public Node(long id, String sysmlId, String elasticId, String lastCommit, String initialCommit, - boolean deleted) { + public Node(long id, String nodeId, String indexId, String lastCommit, String initialCommit, + boolean deleted, Integer nodeType) { setId(id); - setSysmlId(sysmlId); - setElasticId(elasticId); + setNodeId(nodeId); + setIndexId(indexId); setLastCommit(lastCommit); setInitialCommit(initialCommit); setDeleted(deleted); + setNodeType(nodeType); } @@ -49,20 +48,20 @@ public void setId(Long id) { this.id = id; } - public String getSysmlId() { - return sysmlId; + public String getNodeId() { + return nodeId; } - public void setSysmlId(String sysmlId) { - this.sysmlId = sysmlId; + public void setNodeId(String nodeId) { + this.nodeId = nodeId; } - public String getElasticId() { - return elasticId; + public String getIndexId() { + return indexId; } - public void setElasticId(String elasticId) { - this.elasticId = elasticId; + public void setIndexId(String indexId) { + this.indexId = indexId; } public String getLastCommit() { @@ -89,12 +88,11 @@ public void setDeleted(boolean deleted) { this.deleted = deleted; } - @Enumerated(EnumType.ORDINAL) - public NodeType getNodeType() { + public Integer getNodeType() { return nodeType; } - public void setNodeType(NodeType nodeType) { + public void setNodeType(Integer nodeType) { this.nodeType = nodeType; } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAOImpl.java index 3262f1d2c..031358cb4 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAOImpl.java @@ -6,24 +6,24 @@ import java.util.Map; import java.util.Set; import org.openmbee.sdvc.crud.config.DbContextHolder; -import org.openmbee.sdvc.crud.controllers.BaseJson; +import org.openmbee.sdvc.json.BaseJson; -public abstract class BaseElasticDAOImpl implements BaseElasticDAO { +public abstract class BaseElasticDAOImpl implements BaseIndexDAO { public String getIndex() { return DbContextHolder.getContext().getIndex(); } - public Map findByElasticId(String elasticId) { + public Map findByIndexId(String indexId) { return null; } - public List> findByElasticIds(Set elasticIds) { + public List> findByIndexIds(Set indexIds) { List> maps = new ArrayList<>(); int i = 97; - for (String eid : elasticIds) { + for (String eid : indexIds) { BaseJson json = new BaseJson(); - json.setElasticId(eid); + json.setIndexId(eid); json.setModified("2018-12-08T01:25:00.117-0700"); json.setId(Character.toString((char) i)); json.setName(json.getId()); @@ -34,7 +34,7 @@ public List> findByElasticIds(Set elasticIds) { BaseJson baseJson = new BaseJson(); baseJson.setId("testing"); baseJson.setName("element1"); - baseJson.setElasticId("8a1ee2ef-078f-4f3f-ae89-66fb5e9e7bba"); + baseJson.getIndexId("8a1ee2ef-078f-4f3f-ae89-66fb5e9e7bba"); baseJson.setModified("2015-07-04T12:08:56.235-0700"); List> maps = new ArrayList<>(); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseIndexDAO.java similarity index 52% rename from crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAO.java rename to crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseIndexDAO.java index 08cfcf642..614b55ec5 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseElasticDAO.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/BaseIndexDAO.java @@ -4,13 +4,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.openmbee.sdvc.crud.controllers.BaseJson; +import org.openmbee.sdvc.json.BaseJson; -public interface BaseElasticDAO { +public interface BaseIndexDAO { - Map findByElasticId(String elasticId); + Map findByIndexId(String indexId); - List> findByElasticIds(Set elasticIds); + List> findByIndexIds(Set indexIds); void indexAll(Collection jsons); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchDAOImpl.java index faff3a1b4..7d25a334a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchDAOImpl.java @@ -6,10 +6,7 @@ import java.sql.Timestamp; import java.util.List; import org.openmbee.sdvc.crud.domains.Branch; -import org.openmbee.sdvc.crud.domains.Commit; import org.openmbee.sdvc.crud.repositories.BaseDAOImpl; -import org.openmbee.sdvc.crud.repositories.commit.CommitDAO; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.PreparedStatementCreator; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; @@ -26,7 +23,7 @@ public void setCommitRepository(CommitDAO commitRepository) { } */ public Branch save(Branch branch) { - String sql = "INSERT INTO branches (elasticId, branchId, branchName, parentRefId, parentCommit, timestamp, tag, deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + String sql = "INSERT INTO branches (description, branchId, branchName, parentRefId, parentCommit, timestamp, tag, deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; /* if (branch.getParentRefId() != null && branch.getParentRef() == null) { Branch parentRef = findByBranchId(branch.getParentRefId()); @@ -50,7 +47,7 @@ public Branch save(Branch branch) { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql, new String[]{"id"}); - ps.setString(1, branch.getElasticId()); + ps.setString(1, branch.getDescription()); ps.setString(2, branch.getBranchId()); ps.setString(3, branch.getBranchName()); ps.setString(4, branch.getParentRefId()); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAO.java deleted file mode 100644 index a5ffbb1b3..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAO.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.repositories.branch; - -import org.openmbee.sdvc.crud.repositories.BaseElasticDAO; - -public interface BranchElasticDAO extends BaseElasticDAO { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAOImpl.java deleted file mode 100644 index ae7bf7cd7..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/branch/BranchElasticDAOImpl.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.openmbee.sdvc.crud.repositories.branch; - -import org.openmbee.sdvc.crud.repositories.BaseElasticDAOImpl; -import org.springframework.stereotype.Component; - -@Component -public class BranchElasticDAOImpl extends BaseElasticDAOImpl implements BranchElasticDAO { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitDAOImpl.java index bcc2e03f1..4c491ed54 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitDAOImpl.java @@ -28,7 +28,7 @@ public void setBranchRepository(BranchDAO branchRepository) { } public Commit save(Commit commit) { - String sql = "INSERT INTO commits (commitType, creator, elasticId, branchId, timestamp) VALUES (?, ?, ?, ?, ?)"; + String sql = "INSERT INTO commits (commitType, creator, indexId, branchId, timestamp, comment) VALUES (?, ?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); getConnection().update(new PreparedStatementCreator() { @@ -37,9 +37,10 @@ public PreparedStatement createPreparedStatement(Connection connection) PreparedStatement ps = connection.prepareStatement(sql, new String[]{"id"}); ps.setInt(1, commit.getCommitType().getId()); ps.setString(2, commit.getCreator()); - ps.setString(3, commit.getElasticId()); + ps.setString(3, commit.getIndexId()); ps.setString(4, commit.getBranchId()); ps.setTimestamp(5, Timestamp.from(commit.getTimestamp())); + ps.setString(6, commit.getComment()); return ps; } @@ -60,7 +61,7 @@ public Commit findById(long id) { } public Commit findByCommitId(String commitId) { - String sql = "SELECT * FROM commits WHERE elasticId = ?"; + String sql = "SELECT * FROM commits WHERE indexid = ?"; return (Commit) getConnection() .queryForObject(sql, new Object[]{commitId}, new CommitRowMapper()); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAO.java deleted file mode 100644 index c2512057f..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAO.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.repositories.commit; - -import org.openmbee.sdvc.crud.repositories.BaseElasticDAO; - -public interface CommitElasticDAO extends BaseElasticDAO { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAOImpl.java index 53538dfec..12629d91a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitElasticDAOImpl.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Component; @Component -public class CommitElasticDAOImpl extends BaseElasticDAOImpl implements CommitElasticDAO { +public class CommitElasticDAOImpl extends BaseElasticDAOImpl implements CommitIndexDAO { } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitIndexDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitIndexDAO.java new file mode 100644 index 000000000..cce9de44d --- /dev/null +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/commit/CommitIndexDAO.java @@ -0,0 +1,7 @@ +package org.openmbee.sdvc.crud.repositories.commit; + +import org.openmbee.sdvc.crud.repositories.BaseIndexDAO; + +public interface CommitIndexDAO extends BaseIndexDAO { + +} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAO.java index 74ffb9f5f..25bc5eb83 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAO.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAO.java @@ -6,17 +6,17 @@ public interface EdgeDAO { - public Edge save(Edge edge); + Edge save(Edge edge); - public List saveAll(List nodes); + List saveAll(List nodes); - public List insertAll(List nodes); + List insertAll(List nodes); - public List updateAll(List nodes); + List updateAll(List nodes); - public Edge findParents(String child, EdgeType et); + Edge findParents(String child, Integer et); - public Edge findChildren(String parent, EdgeType et); + Edge findChildren(String parent, Integer et); - public List findAll(); + List findAll(); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAOImpl.java index 5829f9dad..f800956e3 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeDAOImpl.java @@ -61,7 +61,7 @@ public List insertAll(List edges) { PreparedStatement ps = rawConn .prepareStatement(String.format(INSERT_SQL, getSuffix()), new String[]{"id"}); for (Edge e: edges) { - ps.setInt(1, e.getEdgeType().getId()); + ps.setInt(1, e.getEdgeType()); ps.setLong(2, e.getChild().getId()); ps.setLong(3, e.getParent().getId()); ps.addBatch(); @@ -85,7 +85,7 @@ public List updateAll(List edges) { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Edge e = edges.get(i); - ps.setInt(1, e.getEdgeType().getId()); + ps.setInt(1, e.getEdgeType()); ps.setLong(2, e.getChild().getId()); ps.setLong(3, e.getParent().getId()); ps.setLong(4, e.getId()); @@ -100,7 +100,7 @@ public int getBatchSize() { } @SuppressWarnings({"unchecked"}) - public Edge findParents(String sysmlId, EdgeType et) { + public Edge findParents(String sysmlId, Integer et) { String sql = String.format("SELECT * FROM nodes%s WHERE sysmlid = ?", getSuffix()); @@ -109,7 +109,7 @@ public Edge findParents(String sysmlId, EdgeType et) { } @SuppressWarnings({"unchecked"}) - public Edge findChildren(String sysmlId, EdgeType et) { + public Edge findChildren(String sysmlId, Integer et) { String sql = String.format("SELECT * FROM nodes%s WHERE sysmlid = ?", getSuffix()); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeRowMapper.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeRowMapper.java index 95217f8cd..e850a095a 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeRowMapper.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/edge/EdgeRowMapper.java @@ -14,7 +14,8 @@ public Node mapRow(ResultSet rs, int rowNum) throws SQLException { rs.getString("elasticid"), rs.getString("lastcommit"), rs.getString("initialcommit"), - rs.getBoolean("deleted") + rs.getBoolean("deleted"), + rs.getInt("nodetype") ); } } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAO.java index 5b0c94a95..0fe559db8 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAO.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAO.java @@ -16,9 +16,9 @@ public interface NodeDAO { public Node findById(long id); - public Node findBySysmlId(String sysmlid); + public Node findByNodeId(String sysmlid); - public List findAllBySysmlIds(Collection ids); + public List findAllByNodeIds(Collection ids); public List findAll(); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAOImpl.java index a60aee5b9..363d1f957 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeDAOImpl.java @@ -18,8 +18,8 @@ @Component public class NodeDAOImpl extends BaseDAOImpl implements NodeDAO { - private final String INSERT_SQL = "INSERT INTO nodes%s (sysmlid, elasticid, lastcommit, initialcommit, deleted, nodetype) VALUES (?, ?, ?, ?, ?, ?)"; - private final String UPDATE_SQL = "UPDATE nodes%s SET sysmlid = ?, elasticid = ?, lastcommit = ?, initialcommit = ?, deleted = ?, nodetype = ? WHERE id = ?"; + private final String INSERT_SQL = "INSERT INTO nodes%s (nodeid, indexid, lastcommit, initialcommit, deleted, nodetype) VALUES (?, ?, ?, ?, ?, ?)"; + private final String UPDATE_SQL = "UPDATE nodes%s SET nodeid = ?, indexid = ?, lastcommit = ?, initialcommit = ?, deleted = ?, nodetype = ? WHERE id = ?"; public Node save(Node node) { if (node.getId() == null) { @@ -31,12 +31,12 @@ public PreparedStatement createPreparedStatement(Connection connection) PreparedStatement ps = connection .prepareStatement(String.format(INSERT_SQL, getSuffix()), new String[]{"id"}); - ps.setString(1, node.getSysmlId()); - ps.setString(2, node.getElasticId()); + ps.setString(1, node.getNodeId()); + ps.setString(2, node.getIndexId()); ps.setString(3, node.getLastCommit()); ps.setString(4, node.getInitialCommit()); ps.setBoolean(5, node.isDeleted()); - ps.setInt(6, node.getNodeType().getId()); + ps.setInt(6, node.getNodeType()); return ps; } }, keyHolder); @@ -51,12 +51,12 @@ public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection .prepareStatement(String.format(UPDATE_SQL, getSuffix())); - ps.setString(1, node.getSysmlId()); - ps.setString(2, node.getElasticId()); + ps.setString(1, node.getNodeId()); + ps.setString(2, node.getIndexId()); ps.setString(3, node.getLastCommit()); ps.setString(4, node.getInitialCommit()); ps.setBoolean(5, node.isDeleted()); - ps.setInt(6, node.getNodeType().getId()); + ps.setInt(6, node.getNodeType()); ps.setLong(7, node.getId()); return ps; } @@ -95,12 +95,12 @@ public List insertAll(List nodes) { PreparedStatement ps = rawConn .prepareStatement(String.format(INSERT_SQL, getSuffix()), new String[]{"id"}); for (Node n : nodes) { - ps.setString(1, n.getSysmlId()); - ps.setString(2, n.getElasticId()); + ps.setString(1, n.getNodeId()); + ps.setString(2, n.getIndexId()); ps.setString(3, n.getLastCommit()); ps.setString(4, n.getInitialCommit()); ps.setBoolean(5, n.isDeleted()); - ps.setInt(6, n.getNodeType().getId()); + ps.setInt(6, n.getNodeType()); ps.addBatch(); } ps.executeBatch(); @@ -122,12 +122,12 @@ public List updateAll(List nodes) { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Node n = nodes.get(i); - ps.setString(1, n.getSysmlId()); - ps.setString(2, n.getElasticId()); + ps.setString(1, n.getNodeId()); + ps.setString(2, n.getIndexId()); ps.setString(3, n.getLastCommit()); ps.setString(4, n.getInitialCommit()); ps.setBoolean(5, n.isDeleted()); - ps.setInt(6, n.getNodeType().getId()); + ps.setInt(6, n.getNodeType()); ps.setLong(7, n.getId()); } @@ -149,19 +149,19 @@ public Node findById(long id) { } @SuppressWarnings({"unchecked"}) - public Node findBySysmlId(String sysmlId) { - String sql = String.format("SELECT * FROM nodes%s WHERE sysmlid = ?", + public Node findByNodeId(String nodeId) { + String sql = String.format("SELECT * FROM nodes%s WHERE nodeid = ?", getSuffix()); return (Node) getConnection() - .queryForObject(sql, new Object[]{sysmlId}, new NodeRowMapper()); + .queryForObject(sql, new Object[]{nodeId}, new NodeRowMapper()); } - public List findAllBySysmlIds(Collection ids) { + public List findAllByNodeIds(Collection ids) { if (ids == null || ids.isEmpty()) { return new ArrayList<>(); } - String sql = String.format("SELECT * FROM nodes%s WHERE sysmlid IN (%s)", + String sql = String.format("SELECT * FROM nodes%s WHERE nodeid IN (%s)", getSuffix(), "'" + String.join("','", ids) + "'"); return getConnection().query(sql, new NodeRowMapper()); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAO.java deleted file mode 100644 index 574c52ce5..000000000 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAO.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.openmbee.sdvc.crud.repositories.node; - -import org.openmbee.sdvc.crud.repositories.BaseElasticDAO; - -public interface NodeElasticDAO extends BaseElasticDAO { - -} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAOImpl.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAOImpl.java index 87dec65e3..d16502173 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAOImpl.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeElasticDAOImpl.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Component; @Component -public class NodeElasticDAOImpl extends BaseElasticDAOImpl implements NodeElasticDAO { +public class NodeElasticDAOImpl extends BaseElasticDAOImpl implements NodeIndexDAO { } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeIndexDAO.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeIndexDAO.java new file mode 100644 index 000000000..57ce95227 --- /dev/null +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeIndexDAO.java @@ -0,0 +1,7 @@ +package org.openmbee.sdvc.crud.repositories.node; + +import org.openmbee.sdvc.crud.repositories.BaseIndexDAO; + +public interface NodeIndexDAO extends BaseIndexDAO { + +} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeRowMapper.java b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeRowMapper.java index 7e7431b74..c3f980cf6 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeRowMapper.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/repositories/node/NodeRowMapper.java @@ -47,8 +47,6 @@ public Node mapRow(ResultSet rs, int rowNum) throws SQLException { if (column != null) { if (column instanceof Timestamp) { beanMap.put(field, ((Timestamp) column).toInstant()); - } else if (field.equalsIgnoreCase("nodetype")) { - beanMap.put(field, NodeType.getNodeType((int) column)); } else { beanMap.put(field, column); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/CommitService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/CommitService.java index ce64a58c2..d54fd7523 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/CommitService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/CommitService.java @@ -9,12 +9,12 @@ import java.util.Map; import java.util.Set; import org.openmbee.sdvc.crud.config.DbContextHolder; -import org.openmbee.sdvc.crud.controllers.commits.CommitJson; +import org.openmbee.sdvc.json.CommitJson; import org.openmbee.sdvc.crud.controllers.commits.CommitsRequest; import org.openmbee.sdvc.crud.controllers.commits.CommitsResponse; import org.openmbee.sdvc.crud.domains.Commit; import org.openmbee.sdvc.crud.repositories.commit.CommitDAO; -import org.openmbee.sdvc.crud.repositories.commit.CommitElasticDAO; +import org.openmbee.sdvc.crud.repositories.commit.CommitIndexDAO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -23,7 +23,7 @@ public class CommitService { public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); private CommitDAO commitRepository; - private CommitElasticDAO commitElasticRepository; + private CommitIndexDAO commitIndex; @Autowired public void setCommitDao(CommitDAO commitDao) { @@ -31,8 +31,8 @@ public void setCommitDao(CommitDAO commitDao) { } @Autowired - public void setCommitElasticDao(CommitElasticDAO commitElasticRepository) { - this.commitElasticRepository = commitElasticRepository; + public void setCommitElasticDao(CommitIndexDAO commitElasticRepository) { + this.commitIndex = commitElasticRepository; } public CommitsResponse getRefCommits(String projectId, String refId, @@ -58,7 +58,8 @@ public CommitsResponse getRefCommits(String projectId, String refId, CommitJson json = new CommitJson(); json.setCreated(c.getTimestamp().toString()); json.setCreator(c.getCreator()); - json.setId(c.getElasticId()); + json.setId(c.getIndexId()); + json.setComment(c.getComment()); resJson.add(json); } res.setCommits(resJson); @@ -67,7 +68,7 @@ public CommitsResponse getRefCommits(String projectId, String refId, public CommitsResponse getCommit(String projectId, String commitId) { DbContextHolder.setContext(projectId); - Map commit = commitElasticRepository.findByElasticId(commitId); + Map commit = commitIndex.findByIndexId(commitId); List resJson = new ArrayList<>(); CommitJson c = new CommitJson(); c.putAll(commit); @@ -92,7 +93,7 @@ public CommitsResponse getCommits(String projectId, CommitsRequest req) { for (CommitJson j : req.getCommits()) { ids.add(j.getId()); } - List> jsons = commitElasticRepository.findByElasticIds(ids); + List> jsons = commitIndex.findByIndexIds(ids); //TODO CommitsResponse res = new CommitsResponse(); return res; diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/DatabaseDefinitionService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/DatabaseDefinitionService.java index 213f081cd..995c27697 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/DatabaseDefinitionService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/DatabaseDefinitionService.java @@ -106,12 +106,12 @@ public class DatabaseDefinitionService { + "$$ LANGUAGE plpgsql;"; private static final String GET_IMMEDIATE_PARENTS = "CREATE OR REPLACE FUNCTION get_immediate_parents(integer, integer, text)\n" - + " RETURNS TABLE(sysmlid text, elasticid text)\n" + + " RETURNS TABLE(nodeid text, indexid text)\n" + "AS $$\n" + " begin\n" + " return query\n" + " execute '\n" - + " select sysmlid, elasticid from nodes' || $3 || ' where id in\n" + + " select nodeid, indexid from nodes' || $3 || ' where id in\n" + " (select id from get_parents(' || $1 || ',' || $2 || ',''' || format('%s',$3) ||\n" + " ''') where height = 1);';\n" + " end;\n" diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultNodeService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultNodeService.java index 738a9adf3..493a0e97f 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultNodeService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultNodeService.java @@ -11,20 +11,19 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.openmbee.sdvc.crud.config.DbContextHolder; -import org.openmbee.sdvc.crud.controllers.commits.CommitJson; -import org.openmbee.sdvc.crud.controllers.elements.ElementJson; +import org.openmbee.sdvc.json.CommitJson; +import org.openmbee.sdvc.json.ElementJson; import org.openmbee.sdvc.crud.controllers.elements.ElementsRequest; import org.openmbee.sdvc.crud.controllers.elements.ElementsResponse; import org.openmbee.sdvc.crud.domains.Commit; import org.openmbee.sdvc.crud.domains.CommitType; import org.openmbee.sdvc.crud.domains.Edge; -import org.openmbee.sdvc.crud.domains.EdgeType; import org.openmbee.sdvc.crud.domains.Node; import org.openmbee.sdvc.crud.repositories.commit.CommitDAO; -import org.openmbee.sdvc.crud.repositories.commit.CommitElasticDAO; +import org.openmbee.sdvc.crud.repositories.commit.CommitIndexDAO; import org.openmbee.sdvc.crud.repositories.edge.EdgeDAO; import org.openmbee.sdvc.crud.repositories.node.NodeDAO; -import org.openmbee.sdvc.crud.repositories.node.NodeElasticDAO; +import org.openmbee.sdvc.crud.repositories.node.NodeIndexDAO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; @@ -36,9 +35,9 @@ public class DefaultNodeService implements NodeService { protected NodeDAO nodeRepository; protected CommitDAO commitRepository; - protected NodeElasticDAO nodeElasticRepository; + protected NodeIndexDAO nodeIndex; //to save to this use base json classes - protected CommitElasticDAO commitElasticRepository; + protected CommitIndexDAO commitIndex; protected EdgeDAO edgeRepository; protected NodePostHelper nodePostHelper; @@ -53,13 +52,13 @@ public void setCommitRepository(CommitDAO commitRepository) { } @Autowired - public void setNodeElasticRepository(NodeElasticDAO nodeElasticRepository) { - this.nodeElasticRepository = nodeElasticRepository; + public void setNodeIndex(NodeIndexDAO nodeIndex) { + this.nodeIndex = nodeIndex; } @Autowired - public void setCommitElasticRepository(CommitElasticDAO commitElasticRepository) { - this.commitElasticRepository = commitElasticRepository; + public void setCommitIndex(CommitIndexDAO commitIndex) { + this.commitIndex = commitIndex; } @Autowired @@ -80,9 +79,9 @@ public ElementsResponse get(String projectId, String refId, String id, logger.info("params: " + params); if (id != null) { logger.debug("ElementId given: ", id); - Node node = nodeRepository.findBySysmlId(id); + Node node = nodeRepository.findByNodeId(id); ElementJson e = new ElementJson(); - e.setId(node.getSysmlId()); + e.setId(node.getNodeId()); //set other stuff ElementsResponse res = new ElementsResponse(); List list = new ArrayList<>(); @@ -131,9 +130,9 @@ public ElementsResponse post(String projectId, String refId, ElementsRequest req } protected void commitChanges(Map nodes, Map json, - CommitJson cmjs, Instant now, Set oldElasticIds) { + CommitJson cmjs, Instant now, Set oldIndexIds) { if (!nodes.isEmpty()) { - this.nodeElasticRepository.indexAll(json.values()); + this.nodeIndex.indexAll(json.values()); this.nodeRepository.saveAll(new ArrayList<>(nodes.values())); List edges = nodePostHelper.getEdgesToSave(nodes, json, this); @@ -145,10 +144,11 @@ protected void commitChanges(Map nodes, Map j commit.setBranchId(cmjs.getRefId()); commit.setCommitType(CommitType.COMMIT); commit.setCreator(cmjs.getCreator()); - commit.setElasticId(cmjs.getId()); + commit.setIndexId(cmjs.getId()); commit.setTimestamp(now); + commit.setComment(cmjs.getComment()); - this.commitElasticRepository.index(cmjs); + this.commitIndex.index(cmjs); this.commitRepository.save(commit); } } @@ -160,7 +160,7 @@ public void extraProcessPostedElement(ElementJson element, Node node, } @Override - public Map>> getEdgeInfo(Collection elements) { + public Map>> getEdgeInfo(Collection elements) { return new HashMap<>(); } } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultProjectService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultProjectService.java index 3c2b5a480..9f45fd1a5 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultProjectService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/DefaultProjectService.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger; import org.openmbee.sdvc.core.domains.Project; import org.openmbee.sdvc.core.repositories.ProjectRepository; -import org.openmbee.sdvc.crud.controllers.projects.ProjectJson; +import org.openmbee.sdvc.json.ProjectJson; import org.openmbee.sdvc.crud.controllers.projects.ProjectsResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/Helper.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/Helper.java index e906a8893..396dd4fa4 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/Helper.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/Helper.java @@ -3,7 +3,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.openmbee.sdvc.crud.controllers.BaseJson; +import org.openmbee.sdvc.json.BaseJson; import org.openmbee.sdvc.crud.domains.Node; public class Helper { @@ -28,8 +28,8 @@ public static Map convertNodesToMap(List nodes) { if (node == null) { continue; } - if (node.getSysmlId() != null && !node.getSysmlId().equals("")) { - result.put(node.getSysmlId(), node); + if (node.getNodeId() != null && !node.getNodeId().equals("")) { + result.put(node.getNodeId(), node); } } return result; @@ -48,68 +48,4 @@ public static Map convertToMap(List> element } return result; } - - public static boolean isEquivalent(Map map1, Map map2) { - if (map1 == map2) { - return true; - } - if (map1 == null || map2 == null) { - return false; - } - for (Map.Entry entry : map1.entrySet()) { - if (!map2.containsKey(entry.getKey())) { - return false; - } - Object value1 = entry.getValue(); - Object value2 = map2.get(entry.getKey()); - if (value1 == null && value2 != null) { - return false; - } - if (value1 == value2) { - continue; - } - if (value1 instanceof Map) { - if (!(value2 instanceof Map)) { - return false; - } else { - if (!isEquivalent((Map) value1, (Map) value2)) { - return false; - } - } - } else if (value1 instanceof List) { - if (!(value2 instanceof List)) { - return false; - } else { - if (!isEquivalent((List) value1, (List) value2)) { - return false; - } - } - } else if (!value1.equals(value2)) { - return false; - } - } - return true; - } - - public static boolean isEquivalent(List list1, List list2) { - if (list1 == list2) { - return true; - } - if (list1 == null || list2 == null || list1.size() != list2.size()) { - return false; - } - - for (int i = 0; i < list1.size(); i++) { - Map toTestMap = new HashMap<>(); - Map testAgainstMap = new HashMap<>(); - - toTestMap.put("fromList", list1.get(i)); - testAgainstMap.put("fromList", list2.get(i)); - - if (!isEquivalent(toTestMap, testAgainstMap)) { - return false; - } - } - return true; - } } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/NodePostHelper.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/NodePostHelper.java index 6831361d8..24cc7667e 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/NodePostHelper.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/NodePostHelper.java @@ -13,16 +13,13 @@ import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.openmbee.sdvc.crud.config.DbContextHolder; -import org.openmbee.sdvc.crud.controllers.BaseJson; -import org.openmbee.sdvc.crud.controllers.commits.CommitJson; -import org.openmbee.sdvc.crud.controllers.elements.ElementJson; +import org.openmbee.sdvc.json.BaseJson; +import org.openmbee.sdvc.json.CommitJson; +import org.openmbee.sdvc.json.ElementJson; import org.openmbee.sdvc.crud.domains.Edge; -import org.openmbee.sdvc.crud.domains.EdgeType; import org.openmbee.sdvc.crud.domains.Node; -import org.openmbee.sdvc.crud.domains.NodeType; import org.openmbee.sdvc.crud.repositories.node.NodeDAO; -import org.openmbee.sdvc.crud.repositories.node.NodeElasticDAO; +import org.openmbee.sdvc.crud.repositories.node.NodeIndexDAO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.util.Pair; import org.springframework.stereotype.Component; @@ -33,7 +30,7 @@ public class NodePostHelper { protected static final Logger logger = LogManager.getLogger(NodePostHelper.class); public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); protected NodeDAO nodeRepository; - protected NodeElasticDAO nodeElasticRepository; + protected NodeIndexDAO nodeIndex; public static void processElementAdded(ElementJson e, Node n, CommitJson cmjs) { processElementAddedOrUpdated(e, n, cmjs); @@ -43,15 +40,15 @@ public static void processElementAdded(ElementJson e, Node n, CommitJson cmjs) { Map newObj = new HashMap<>(); newObj.put(CommitJson.TYPE, "Element"); - newObj.put(BaseJson.ELASTICID, e.getElasticId()); + newObj.put(BaseJson.INDEXID, e.getIndexId()); newObj.put(BaseJson.ID, e.getId()); cmjs.getAdded().add(newObj); - n.setSysmlId(e.getId()); - n.setElasticId(e.getElasticId()); + n.setNodeId(e.getId()); + n.setIndexId(e.getIndexId()); n.setLastCommit(cmjs.getId()); - n.setInitialCommit(e.getElasticId()); - n.setNodeType(NodeType.ELEMENT); + n.setInitialCommit(e.getIndexId()); + n.setNodeType(0); n.setDeleted(false); } @@ -59,21 +56,21 @@ public static void processElementUpdated(ElementJson e, Node n, CommitJson cmjs) processElementAddedOrUpdated(e, n, cmjs); Map newObj = new HashMap<>(); - newObj.put(CommitJson.PREVIOUS, n.getElasticId()); + newObj.put(CommitJson.PREVIOUS, n.getIndexId()); newObj.put(CommitJson.TYPE, "Element"); - newObj.put(BaseJson.ELASTICID, e.getElasticId()); + newObj.put(BaseJson.INDEXID, e.getIndexId()); newObj.put(BaseJson.ID, e.getId()); cmjs.getUpdated().add(newObj); - n.setElasticId(e.getElasticId()); + n.setIndexId(e.getIndexId()); n.setLastCommit(cmjs.getId()); - n.setNodeType(NodeType.ELEMENT); + n.setNodeType(0); n.setDeleted(false); } public static void processElementDeleted(ElementJson e, Node n, CommitJson cmjs) { Map newObj = new HashMap<>(); - newObj.put(CommitJson.PREVIOUS, n.getElasticId()); + newObj.put(CommitJson.PREVIOUS, n.getIndexId()); newObj.put(CommitJson.TYPE, "Element"); newObj.put(BaseJson.ID, e.getId()); cmjs.getDeleted().add(newObj); @@ -88,7 +85,7 @@ public static void processElementAddedOrUpdated(ElementJson e, Node n, CommitJso inRefIds.add(cmjs.getRefId()); e.setInRefIds(inRefIds); String elasticId = UUID.randomUUID().toString(); - e.setElasticId(elasticId); + e.setIndexId(elasticId); e.setCommitId(cmjs.getId()); e.setModified(cmjs.getCreated()); e.setModifier(cmjs.getCreator()); @@ -97,7 +94,7 @@ public static void processElementAddedOrUpdated(ElementJson e, Node n, CommitJso public static boolean isUpdated(BaseJson element, Map existing, Map rejection) { - boolean equiv = Helper.isEquivalent(element, existing); + boolean equiv = element.isPartialOf(existing); if (equiv) { rejection.put("message", "Is Equivalent"); rejection.put("code", 304); @@ -125,53 +122,43 @@ public static boolean diffUpdateJson(BaseJson element, Map exist logger.info("date parse exception:" + jsonModified + " " + existingModified); } } - mergeJson(element, existing); + element.merge(existing); return true; } - private static void mergeJson(BaseJson partial, Map original) { - for (Map.Entry entry : original.entrySet()) { - String attr = entry.getKey(); - if (!partial.containsKey(attr)) { - partial.put(attr, original.get(attr)); - } - } - } - @Autowired public void setNodeRepository(NodeDAO nodeRepository) { this.nodeRepository = nodeRepository; } @Autowired - public void setNodeElasticRepository(NodeElasticDAO nodeElasticRepository) { - this.nodeElasticRepository = nodeElasticRepository; + public void setNodeIndex(NodeIndexDAO nodeIndex) { + this.nodeIndex = nodeIndex; } // create new elastic id for all element json, update modified time, modifier (use dummy for now), set _projectId, _refId, _inRefIds public Map processPostJson(List elements, boolean overwriteJson, Instant now, CommitJson cmjs, Map response, List rejectedList, - NodeService service, Set oldElasticIds) { + NodeService service, Set oldIndexIds) { Set elasticIds = new HashSet<>(); Map reqElementMap = (Map) Helper .convertJsonToMap(elements); - List existingNodes = nodeRepository.findAllBySysmlIds(reqElementMap.keySet()); + List existingNodes = nodeRepository.findAllByNodeIds(reqElementMap.keySet()); Map existingNodeMap = new HashMap<>(); for (Node node : existingNodes) { logger.info("Got element with id: {}", node.getId()); - elasticIds.add(node.getElasticId()); - existingNodeMap.put(node.getSysmlId(), node); + elasticIds.add(node.getIndexId()); + existingNodeMap.put(node.getNodeId(), node); } // bulk get existing elements in elastic - List> existingElasticNodes = nodeElasticRepository - .findByElasticIds(elasticIds); + List> existingElasticNodes = nodeIndex.findByIndexIds(elasticIds); Map elasticNodeMap = Helper .convertToMap(existingElasticNodes, ElementJson.ID); Map toSave = new HashMap<>(); cmjs.setId(UUID.randomUUID().toString()); - cmjs.setElasticId(cmjs.getId()); + cmjs.setIndexId(cmjs.getId()); cmjs.setCreated(now.toString()); cmjs.setAdded(new ArrayList<>()); cmjs.setDeleted(new ArrayList<>()); @@ -214,17 +201,17 @@ public Map processPostJson(List elements, boolean ove if (added) { Node node = new Node(); processElementAdded(element, node, cmjs); - toSave.put(node.getSysmlId(), node); + toSave.put(node.getNodeId(), node); response.put(element.getId(), element); - service.extraProcessPostedElement(element, node, oldElasticIds, cmjs, now, toSave, + service.extraProcessPostedElement(element, node, oldIndexIds, cmjs, now, toSave, response); } else if (updated) { Node node = existingNodeMap.get(element.getId()); - oldElasticIds.add(node.getElasticId()); + oldIndexIds.add(node.getIndexId()); processElementUpdated(element, node, cmjs); - toSave.put(node.getSysmlId(), node); + toSave.put(node.getNodeId(), node); response.put(element.getId(), element); - service.extraProcessPostedElement(element, node, oldElasticIds, cmjs, now, toSave, + service.extraProcessPostedElement(element, node, oldIndexIds, cmjs, now, toSave, response); } else { rejectedList.add(rejected); @@ -238,11 +225,11 @@ public List getEdgesToSave(Map nodes, Map toFind = new HashSet<>(); List res = new ArrayList<>(); - Map>> edges = service.getEdgeInfo(json.values()); + Map>> edges = service.getEdgeInfo(json.values()); if (edges.isEmpty()) { return res; } - for (Map.Entry>> entry : edges.entrySet()) { + for (Map.Entry>> entry : edges.entrySet()) { for (Pair pair : entry.getValue()) { toFind.add(pair.getFirst()); toFind.add(pair.getSecond()); @@ -250,10 +237,10 @@ public List getEdgesToSave(Map nodes, Map edgeNodes = Helper - .convertNodesToMap(this.nodeRepository.findAllBySysmlIds(toFind)); + .convertNodesToMap(nodeRepository.findAllByNodeIds(toFind)); edgeNodes.putAll(nodes); - for (Map.Entry>> entry : edges.entrySet()) { + for (Map.Entry>> entry : edges.entrySet()) { for (Pair pair : entry.getValue()) { Node parent = edgeNodes.get(pair.getFirst()); Node child = edgeNodes.get(pair.getSecond()); diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/NodeService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/NodeService.java index 85640286b..ba775e4e4 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/NodeService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/NodeService.java @@ -5,11 +5,10 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.openmbee.sdvc.crud.controllers.commits.CommitJson; -import org.openmbee.sdvc.crud.controllers.elements.ElementJson; +import org.openmbee.sdvc.json.CommitJson; +import org.openmbee.sdvc.json.ElementJson; import org.openmbee.sdvc.crud.controllers.elements.ElementsRequest; import org.openmbee.sdvc.crud.controllers.elements.ElementsResponse; -import org.openmbee.sdvc.crud.domains.EdgeType; import org.openmbee.sdvc.crud.domains.Node; import org.springframework.data.util.Pair; @@ -24,5 +23,5 @@ void extraProcessPostedElement(ElementJson element, Node node, Set oldElasticIds, CommitJson cmjs, Instant now, Map toSave, Map response); - Map>> getEdgeInfo(Collection elements); + Map>> getEdgeInfo(Collection elements); } diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/services/ProjectService.java b/crud/src/main/java/org/openmbee/sdvc/crud/services/ProjectService.java index c8125c3ba..34ba10739 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/services/ProjectService.java +++ b/crud/src/main/java/org/openmbee/sdvc/crud/services/ProjectService.java @@ -1,7 +1,6 @@ package org.openmbee.sdvc.crud.services; -import org.openmbee.sdvc.crud.controllers.projects.ProjectJson; -import org.openmbee.sdvc.crud.controllers.projects.ProjectsRequest; +import org.openmbee.sdvc.json.ProjectJson; import org.openmbee.sdvc.crud.controllers.projects.ProjectsResponse; public interface ProjectService { diff --git a/crud/src/main/resources/project-data.sql b/crud/src/main/resources/project-data.sql index 04de9b944..6133d90d4 100644 --- a/crud/src/main/resources/project-data.sql +++ b/crud/src/main/resources/project-data.sql @@ -1,4 +1,4 @@ -INSERT INTO nodes (id, elasticid, initialcommit, lastcommit, nodetype, sysmlid, deleted) +INSERT INTO nodes (id, indexid, initialcommit, lastcommit, nodetype, nodeid, deleted) VALUES (0, 'test', 'test', 'test', 1, '${projectId}', false); INSERT INTO branches (id, branchid, branchname, tag, deleted, timestamp) diff --git a/example/example.gradle b/example/example.gradle index fb1e29090..cd0f8fa05 100644 --- a/example/example.gradle +++ b/example/example.gradle @@ -18,7 +18,7 @@ repositories { dependencies { compile( project(':ldap'), - project(':sysml'), + project(':cameo'), 'org.springframework.boot:spring-boot-starter-web', 'org.postgresql:postgresql:42.2.5', 'io.springfox:springfox-swagger2:2.7.0', diff --git a/jcr/src/main/java/org/openmbee/sdvc/jcr/config/JcrConfig.java b/jcr/src/main/java/org/openmbee/sdvc/jcr/config/JcrConfig.java index 24a8ea30f..0c9407348 100644 --- a/jcr/src/main/java/org/openmbee/sdvc/jcr/config/JcrConfig.java +++ b/jcr/src/main/java/org/openmbee/sdvc/jcr/config/JcrConfig.java @@ -8,7 +8,7 @@ @Configuration @PropertySource("classpath:application.properties") public abstract class JcrConfig { - String uri = "mongodb://" + host + ":" + port; - Node ns = new DocumentMK.Builder().setMongoDB(uri, "oak_demo", 16).getNodeStore(); - Repository repo = new Jcr(new Oak(ns)).createRepository(); + //String uri = "mongodb://" + host + ":" + port; + //Node ns = new DocumentMK.Builder().setMongoDB(uri, "oak_demo", 16).getNodeStore(); + //Repository repo = new Jcr(new Oak(ns)).createRepository(); } diff --git a/json/json.gradle b/json/json.gradle new file mode 100644 index 000000000..6d237a5c4 --- /dev/null +++ b/json/json.gradle @@ -0,0 +1,5 @@ +apply plugin: 'io.spring.convention.spring-module' + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/json/src/main/java/org/openmbee/sdvc/json/BaseJson.java b/json/src/main/java/org/openmbee/sdvc/json/BaseJson.java new file mode 100644 index 000000000..977d91b53 --- /dev/null +++ b/json/src/main/java/org/openmbee/sdvc/json/BaseJson.java @@ -0,0 +1,186 @@ +package org.openmbee.sdvc.json; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BaseJson extends HashMap { + + public static final String ID = "id"; + public static final String NAME = "name"; + public static final String INDEXID = "_indexId"; + public static final String PROJECTID = "_projectId"; + public static final String REFID = "_refId"; + public static final String MODIFIER = "_modifier"; + public static final String MODIFIED = "_modified"; + public static final String CREATOR = "_creator"; + public static final String CREATED = "_created"; + public static final String COMMITID = "_commitId"; + + public String getId() { + return (String) this.get(ID); + } + + public BaseJson setId(String id) { + this.put(ID, id); + return this; + } + + public String getName() { + return (String) this.get(NAME); + } + + public BaseJson setName(String name) { + this.put(NAME, name); + return this; + } + + public String getIndexId() { + return (String) this.get(INDEXID); + } + + public BaseJson setIndexId(String indexId) { + this.put(INDEXID, indexId); + return this; + } + + public String getProjectId() { + return (String) this.get(PROJECTID); + } + + public BaseJson setProjectId(String projectId) { + this.put(PROJECTID, projectId); + return this; + } + + public String getRefId() { + return (String) this.get(REFID); + } + + public BaseJson setRefId(String refId) { + this.put(REFID, refId); + return this; + } + + public String getModifier() { + return (String) this.get(MODIFIER); + } + + public BaseJson setModifier(String modifier) { + this.put(MODIFIER, modifier); + return this; + } + + public String getModified() { + return (String) this.get(MODIFIED); + } + + public BaseJson setModified(String modified) { + this.put(MODIFIED, modified); + return this; + } + + public String getCreator() { + return (String) this.get(CREATOR); + } + + public BaseJson setCreator(String creator) { + this.put(CREATOR, creator); + return this; + } + + public String getCreated() { + return (String) this.get(CREATED); + } + + public BaseJson setCreated(String created) { + this.put(CREATED, created); + return this; + } + + public String getCommitId() { + return(String) this.get(COMMITID); + } + + public BaseJson setCommitId(String commitId) { + this.put(COMMITID, commitId); + return this; + } + + public boolean isPartialOf(Map o) { + return isPartial(this, o); + } + + public void merge(Map o) { + for (Map.Entry entry : o.entrySet()) { + String attr = entry.getKey(); + if (!this.containsKey(attr)) { + this.put(attr, o.get(attr)); + } + } + } + + private static boolean isPartial(Map map1, Map map2) { + if (map1 == map2) { + return true; + } + if (map1 == null || map2 == null) { + return false; + } + for (Map.Entry entry : map1.entrySet()) { + if (!map2.containsKey(entry.getKey())) { + return false; + } + Object value1 = entry.getValue(); + Object value2 = map2.get(entry.getKey()); + if (value1 == null && value2 != null) { + return false; + } + if (value1 == value2) { + continue; + } + if (value1 instanceof Map) { + if (!(value2 instanceof Map)) { + return false; + } else { + if (!isPartial((Map) value1, (Map) value2)) { + return false; + } + } + } else if (value1 instanceof List) { + if (!(value2 instanceof List)) { + return false; + } else { + if (!isPartial((List) value1, (List) value2)) { + return false; + } + } + } else if (!value1.equals(value2)) { + return false; + } + } + return true; + } + + private static boolean isPartial(List list1, List list2) { + if (list1 == list2) { + return true; + } + if (list1 == null || list2 == null || list1.size() != list2.size()) { + return false; + } + + for (int i = 0; i < list1.size(); i++) { + Map toTestMap = new HashMap<>(); + Map testAgainstMap = new HashMap<>(); + + toTestMap.put("fromList", list1.get(i)); + testAgainstMap.put("fromList", list2.get(i)); + + if (!isPartial(toTestMap, testAgainstMap)) { + return false; + } + } + return true; + } +} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitJson.java b/json/src/main/java/org/openmbee/sdvc/json/CommitJson.java similarity index 93% rename from crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitJson.java rename to json/src/main/java/org/openmbee/sdvc/json/CommitJson.java index e95ad7d5b..8050968bd 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/commits/CommitJson.java +++ b/json/src/main/java/org/openmbee/sdvc/json/CommitJson.java @@ -1,8 +1,7 @@ -package org.openmbee.sdvc.crud.controllers.commits; +package org.openmbee.sdvc.json; import java.util.List; import java.util.Map; -import org.openmbee.sdvc.crud.controllers.BaseJson; public class CommitJson extends BaseJson { diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementJson.java b/json/src/main/java/org/openmbee/sdvc/json/ElementJson.java similarity index 76% rename from crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementJson.java rename to json/src/main/java/org/openmbee/sdvc/json/ElementJson.java index 223ebb2e1..f0e58a6cf 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/elements/ElementJson.java +++ b/json/src/main/java/org/openmbee/sdvc/json/ElementJson.java @@ -1,7 +1,6 @@ -package org.openmbee.sdvc.crud.controllers.elements; +package org.openmbee.sdvc.json; import java.util.List; -import org.openmbee.sdvc.crud.controllers.BaseJson; public class ElementJson extends BaseJson { diff --git a/json/src/main/java/org/openmbee/sdvc/json/OrgJson.java b/json/src/main/java/org/openmbee/sdvc/json/OrgJson.java new file mode 100644 index 000000000..44b4a3f00 --- /dev/null +++ b/json/src/main/java/org/openmbee/sdvc/json/OrgJson.java @@ -0,0 +1,5 @@ +package org.openmbee.sdvc.json; + +public class OrgJson extends BaseJson { + +} diff --git a/json/src/main/java/org/openmbee/sdvc/json/ProjectJson.java b/json/src/main/java/org/openmbee/sdvc/json/ProjectJson.java new file mode 100644 index 000000000..81630b062 --- /dev/null +++ b/json/src/main/java/org/openmbee/sdvc/json/ProjectJson.java @@ -0,0 +1,5 @@ +package org.openmbee.sdvc.json; + +public class ProjectJson extends BaseJson { + +} diff --git a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/RefJson.java b/json/src/main/java/org/openmbee/sdvc/json/RefJson.java similarity index 91% rename from crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/RefJson.java rename to json/src/main/java/org/openmbee/sdvc/json/RefJson.java index bab9d7252..59e71f9b9 100644 --- a/crud/src/main/java/org/openmbee/sdvc/crud/controllers/branches/RefJson.java +++ b/json/src/main/java/org/openmbee/sdvc/json/RefJson.java @@ -1,6 +1,4 @@ -package org.openmbee.sdvc.crud.controllers.branches; - -import org.openmbee.sdvc.crud.controllers.BaseJson; +package org.openmbee.sdvc.json; public class RefJson extends BaseJson { diff --git a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoHelper.java b/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoHelper.java deleted file mode 100644 index 51db47acd..000000000 --- a/sysml/src/main/java/org/openmbee/sdvc/sysml/services/CameoHelper.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.openmbee.sdvc.sysml.services; - -import org.openmbee.sdvc.crud.controllers.elements.ElementJson; -import org.openmbee.sdvc.crud.domains.NodeType; -import org.springframework.stereotype.Component; - -@Component -public class CameoHelper { - - public static NodeType getNodeType(ElementJson e) { - return NodeType.PACKAGE; - } - -}