From 92b3efee0bce32f45d9c3346a1ad3c57a935dc7b Mon Sep 17 00:00:00 2001 From: srinathgit Date: Fri, 26 Feb 2021 11:30:35 -0800 Subject: [PATCH] DHFPROD-6693:Updates to step schema to support related entity mappings --- .../steps/MappingStepController.java | 10 +- .../schemas/MappingPropertiesSchema.java | 51 +++ .../central/schemas/MappingStepSchema.java | 143 +++++++++ .../central/schemas/RelatedEntityMapping.java | 300 ++++++++++++++++++ specs/models/MappingProperties.schema.json | 22 ++ specs/models/MappingStep.schema.json | 53 ++++ specs/models/Step.schema.json | 1 + 7 files changed, 575 insertions(+), 5 deletions(-) create mode 100644 marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingPropertiesSchema.java create mode 100644 marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingStepSchema.java create mode 100644 marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/RelatedEntityMapping.java create mode 100644 specs/models/MappingProperties.schema.json create mode 100644 specs/models/MappingStep.schema.json diff --git a/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/steps/MappingStepController.java b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/steps/MappingStepController.java index e7c2a9e3d3..6050283624 100644 --- a/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/steps/MappingStepController.java +++ b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/steps/MappingStepController.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.marklogic.hub.central.controllers.BaseController; -import com.marklogic.hub.central.schemas.StepSchema; +import com.marklogic.hub.central.schemas.MappingStepSchema; import com.marklogic.hub.dataservices.ArtifactService; import com.marklogic.hub.dataservices.MappingService; import com.marklogic.hub.dataservices.StepService; @@ -35,14 +35,14 @@ public ResponseEntity getSteps() { } @RequestMapping(value = "/{stepName}", method = RequestMethod.GET) - @ApiOperation(value = "Get a step", response = StepSchema.class) + @ApiOperation(value = "Get a step", response = MappingStepSchema.class) @Secured("ROLE_readMapping") public ResponseEntity getStep(@PathVariable String stepName) { return ResponseEntity.ok(newService().getStep(STEP_DEFINITION_TYPE, stepName)); } @RequestMapping(method = RequestMethod.POST) - @ApiImplicitParam(required = true, paramType = "body", dataType = "StepSchema") + @ApiImplicitParam(required = true, paramType = "body", dataType = "MappingStepSchema") @Secured("ROLE_writeMapping") public ResponseEntity createMappingStep(@RequestBody @ApiParam(hidden = true) ObjectNode propertiesToAssign) { String stepName = propertiesToAssign.get("name").asText(); @@ -52,7 +52,7 @@ public ResponseEntity createMappingStep(@RequestBody @ApiParam(hidden = tr } @RequestMapping(value = "/{stepName}", method = RequestMethod.PUT) - @ApiImplicitParam(required = true, paramType = "body", dataType = "StepSchema") + @ApiImplicitParam(required = true, paramType = "body", dataType = "MappingStepSchema") @Secured("ROLE_writeMapping") public ResponseEntity updateMappingStep(@RequestBody @ApiParam(hidden = true) ObjectNode propertiesToAssign, @PathVariable String stepName) { propertiesToAssign.put("name", stepName); @@ -102,7 +102,7 @@ private StepService newService() { return StepService.on(getHubClient().getStagingClient()); } - public static class MappingSteps extends ArrayList { + public static class MappingSteps extends ArrayList { } } diff --git a/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingPropertiesSchema.java b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingPropertiesSchema.java new file mode 100644 index 0000000000..1480ad6af8 --- /dev/null +++ b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingPropertiesSchema.java @@ -0,0 +1,51 @@ + +package com.marklogic.hub.central.schemas; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + +/** + * MappingProperties + *

+ * + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + +}) +public class MappingPropertiesSchema { + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(MappingPropertiesSchema.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + if (sb.charAt((sb.length()- 1)) == ',') { + sb.setCharAt((sb.length()- 1), ']'); + } else { + sb.append(']'); + } + return sb.toString(); + } + + @Override + public int hashCode() { + int result = 1; + return result; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof MappingPropertiesSchema) == false) { + return false; + } + MappingPropertiesSchema rhs = ((MappingPropertiesSchema) other); + return true; + } + +} diff --git a/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingStepSchema.java b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingStepSchema.java new file mode 100644 index 0000000000..f8ecbfde14 --- /dev/null +++ b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/MappingStepSchema.java @@ -0,0 +1,143 @@ + +package com.marklogic.hub.central.schemas; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + + +/** + * MappingStep + *

+ * + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "properties", + "relatedEntityMappings" +}) +public class MappingStepSchema { + + /** + * MappingProperties + *

+ * + * + */ + @JsonProperty("properties") + private MappingPropertiesSchema properties; + /** + * additional collections provided by the user that get applied to the step output + * + */ + @JsonProperty("relatedEntityMappings") + @JsonPropertyDescription("additional collections provided by the user that get applied to the step output") + private List relatedEntityMappings = new ArrayList(); + @JsonIgnore + private Map additionalProperties = new HashMap(); + + /** + * MappingProperties + *

+ * + * + */ + @JsonProperty("properties") + public MappingPropertiesSchema getProperties() { + return properties; + } + + /** + * MappingProperties + *

+ * + * + */ + @JsonProperty("properties") + public void setProperties(MappingPropertiesSchema properties) { + this.properties = properties; + } + + /** + * additional collections provided by the user that get applied to the step output + * + */ + @JsonProperty("relatedEntityMappings") + public List getRelatedEntityMappings() { + return relatedEntityMappings; + } + + /** + * additional collections provided by the user that get applied to the step output + * + */ + @JsonProperty("relatedEntityMappings") + public void setRelatedEntityMappings(List relatedEntityMappings) { + this.relatedEntityMappings = relatedEntityMappings; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(MappingStepSchema.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append("properties"); + sb.append('='); + sb.append(((this.properties == null)?"":this.properties)); + sb.append(','); + sb.append("relatedEntityMappings"); + sb.append('='); + sb.append(((this.relatedEntityMappings == null)?"":this.relatedEntityMappings)); + sb.append(','); + sb.append("additionalProperties"); + sb.append('='); + sb.append(((this.additionalProperties == null)?"":this.additionalProperties)); + sb.append(','); + if (sb.charAt((sb.length()- 1)) == ',') { + sb.setCharAt((sb.length()- 1), ']'); + } else { + sb.append(']'); + } + return sb.toString(); + } + + @Override + public int hashCode() { + int result = 1; + result = ((result* 31)+((this.relatedEntityMappings == null)? 0 :this.relatedEntityMappings.hashCode())); + result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); + result = ((result* 31)+((this.properties == null)? 0 :this.properties.hashCode())); + return result; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof MappingStepSchema) == false) { + return false; + } + MappingStepSchema rhs = ((MappingStepSchema) other); + return ((((this.relatedEntityMappings == rhs.relatedEntityMappings)||((this.relatedEntityMappings!= null)&&this.relatedEntityMappings.equals(rhs.relatedEntityMappings)))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.properties == rhs.properties)||((this.properties!= null)&&this.properties.equals(rhs.properties)))); + } + +} diff --git a/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/RelatedEntityMapping.java b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/RelatedEntityMapping.java new file mode 100644 index 0000000000..5ab0d67023 --- /dev/null +++ b/marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/schemas/RelatedEntityMapping.java @@ -0,0 +1,300 @@ + +package com.marklogic.hub.central.schemas; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "relatedEntityMappingId", + "expressionContext", + "uriExpression", + "properties", + "collections", + "permissions", + "targetEntityType" +}) +public class RelatedEntityMapping { + + /** + * Unique identifier of the related entity mapping + * (Required) + * + */ + @JsonProperty("relatedEntityMappingId") + @JsonPropertyDescription("Unique identifier of the related entity mapping") + private String relatedEntityMappingId; + /** + * An element in the source data from which to derive the values of this related entity's properties + * + */ + @JsonProperty("expressionContext") + @JsonPropertyDescription("An element in the source data from which to derive the values of this related entity's properties") + private String expressionContext; + /** + * XPath expression for generating the uri of this related entity instance document + * + */ + @JsonProperty("uriExpression") + @JsonPropertyDescription("XPath expression for generating the uri of this related entity instance document") + private String uriExpression; + /** + * MappingProperties + *

+ * + * (Required) + * + */ + @JsonProperty("properties") + private MappingPropertiesSchema properties; + /** + * additional collections provided by the user that get applied to this related entity instance document + * + */ + @JsonProperty("collections") + @JsonPropertyDescription("additional collections provided by the user that get applied to this related entity instance document") + private List collections = new ArrayList(); + /** + * Comma-delimited string of role,capability,role,capability,etc for the entity instance generated by this mapping + * + */ + @JsonProperty("permissions") + @JsonPropertyDescription("Comma-delimited string of role,capability,role,capability,etc for the entity instance generated by this mapping") + private String permissions; + /** + * The identifier of the related Entity Type. (IRI, with title as fallback) + * (Required) + * + */ + @JsonProperty("targetEntityType") + @JsonPropertyDescription("The identifier of the related Entity Type. (IRI, with title as fallback)") + private String targetEntityType; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + /** + * Unique identifier of the related entity mapping + * (Required) + * + */ + @JsonProperty("relatedEntityMappingId") + public String getRelatedEntityMappingId() { + return relatedEntityMappingId; + } + + /** + * Unique identifier of the related entity mapping + * (Required) + * + */ + @JsonProperty("relatedEntityMappingId") + public void setRelatedEntityMappingId(String relatedEntityMappingId) { + this.relatedEntityMappingId = relatedEntityMappingId; + } + + /** + * An element in the source data from which to derive the values of this related entity's properties + * + */ + @JsonProperty("expressionContext") + public String getExpressionContext() { + return expressionContext; + } + + /** + * An element in the source data from which to derive the values of this related entity's properties + * + */ + @JsonProperty("expressionContext") + public void setExpressionContext(String expressionContext) { + this.expressionContext = expressionContext; + } + + /** + * XPath expression for generating the uri of this related entity instance document + * + */ + @JsonProperty("uriExpression") + public String getUriExpression() { + return uriExpression; + } + + /** + * XPath expression for generating the uri of this related entity instance document + * + */ + @JsonProperty("uriExpression") + public void setUriExpression(String uriExpression) { + this.uriExpression = uriExpression; + } + + /** + * MappingProperties + *

+ * + * (Required) + * + */ + @JsonProperty("properties") + public MappingPropertiesSchema getProperties() { + return properties; + } + + /** + * MappingProperties + *

+ * + * (Required) + * + */ + @JsonProperty("properties") + public void setProperties(MappingPropertiesSchema properties) { + this.properties = properties; + } + + /** + * additional collections provided by the user that get applied to this related entity instance document + * + */ + @JsonProperty("collections") + public List getCollections() { + return collections; + } + + /** + * additional collections provided by the user that get applied to this related entity instance document + * + */ + @JsonProperty("collections") + public void setCollections(List collections) { + this.collections = collections; + } + + /** + * Comma-delimited string of role,capability,role,capability,etc for the entity instance generated by this mapping + * + */ + @JsonProperty("permissions") + public String getPermissions() { + return permissions; + } + + /** + * Comma-delimited string of role,capability,role,capability,etc for the entity instance generated by this mapping + * + */ + @JsonProperty("permissions") + public void setPermissions(String permissions) { + this.permissions = permissions; + } + + /** + * The identifier of the related Entity Type. (IRI, with title as fallback) + * (Required) + * + */ + @JsonProperty("targetEntityType") + public String getTargetEntityType() { + return targetEntityType; + } + + /** + * The identifier of the related Entity Type. (IRI, with title as fallback) + * (Required) + * + */ + @JsonProperty("targetEntityType") + public void setTargetEntityType(String targetEntityType) { + this.targetEntityType = targetEntityType; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(RelatedEntityMapping.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append("relatedEntityMappingId"); + sb.append('='); + sb.append(((this.relatedEntityMappingId == null)?"":this.relatedEntityMappingId)); + sb.append(','); + sb.append("expressionContext"); + sb.append('='); + sb.append(((this.expressionContext == null)?"":this.expressionContext)); + sb.append(','); + sb.append("uriExpression"); + sb.append('='); + sb.append(((this.uriExpression == null)?"":this.uriExpression)); + sb.append(','); + sb.append("properties"); + sb.append('='); + sb.append(((this.properties == null)?"":this.properties)); + sb.append(','); + sb.append("collections"); + sb.append('='); + sb.append(((this.collections == null)?"":this.collections)); + sb.append(','); + sb.append("permissions"); + sb.append('='); + sb.append(((this.permissions == null)?"":this.permissions)); + sb.append(','); + sb.append("targetEntityType"); + sb.append('='); + sb.append(((this.targetEntityType == null)?"":this.targetEntityType)); + sb.append(','); + sb.append("additionalProperties"); + sb.append('='); + sb.append(((this.additionalProperties == null)?"":this.additionalProperties)); + sb.append(','); + if (sb.charAt((sb.length()- 1)) == ',') { + sb.setCharAt((sb.length()- 1), ']'); + } else { + sb.append(']'); + } + return sb.toString(); + } + + @Override + public int hashCode() { + int result = 1; + result = ((result* 31)+((this.collections == null)? 0 :this.collections.hashCode())); + result = ((result* 31)+((this.targetEntityType == null)? 0 :this.targetEntityType.hashCode())); + result = ((result* 31)+((this.permissions == null)? 0 :this.permissions.hashCode())); + result = ((result* 31)+((this.relatedEntityMappingId == null)? 0 :this.relatedEntityMappingId.hashCode())); + result = ((result* 31)+((this.expressionContext == null)? 0 :this.expressionContext.hashCode())); + result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); + result = ((result* 31)+((this.uriExpression == null)? 0 :this.uriExpression.hashCode())); + result = ((result* 31)+((this.properties == null)? 0 :this.properties.hashCode())); + return result; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof RelatedEntityMapping) == false) { + return false; + } + RelatedEntityMapping rhs = ((RelatedEntityMapping) other); + return (((((((((this.collections == rhs.collections)||((this.collections!= null)&&this.collections.equals(rhs.collections)))&&((this.targetEntityType == rhs.targetEntityType)||((this.targetEntityType!= null)&&this.targetEntityType.equals(rhs.targetEntityType))))&&((this.permissions == rhs.permissions)||((this.permissions!= null)&&this.permissions.equals(rhs.permissions))))&&((this.relatedEntityMappingId == rhs.relatedEntityMappingId)||((this.relatedEntityMappingId!= null)&&this.relatedEntityMappingId.equals(rhs.relatedEntityMappingId))))&&((this.expressionContext == rhs.expressionContext)||((this.expressionContext!= null)&&this.expressionContext.equals(rhs.expressionContext))))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.uriExpression == rhs.uriExpression)||((this.uriExpression!= null)&&this.uriExpression.equals(rhs.uriExpression))))&&((this.properties == rhs.properties)||((this.properties!= null)&&this.properties.equals(rhs.properties)))); + } + +} diff --git a/specs/models/MappingProperties.schema.json b/specs/models/MappingProperties.schema.json new file mode 100644 index 0000000000..083bfff1ab --- /dev/null +++ b/specs/models/MappingProperties.schema.json @@ -0,0 +1,22 @@ +{ + "title": "MappingProperties", + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^[a-zA-Z0-9]+$": { + "type": "object", + "properties": { + "sourcedFrom": { + "type": "string" + }, + "targetEntityType": { + "type": "string" + }, + "properties": { + "$ref": "#" + } + }, + "required": ["sourcedFrom"] + } + } +} diff --git a/specs/models/MappingStep.schema.json b/specs/models/MappingStep.schema.json new file mode 100644 index 0000000000..99ded1a57e --- /dev/null +++ b/specs/models/MappingStep.schema.json @@ -0,0 +1,53 @@ +{ + "title": "MappingStep", + "id": "http://marklogic.com/data-hub/MappingStep.schema.json", + "allOf": [{ "$ref": "http://marklogic.com/data-hub/Step.schema.json" }], + "type": "object", + "properties": { + "properties": { + "type": "object", + "$ref": "./MappingProperties.schema.json" + }, + "relatedEntityMappings": { + "type": "array", + "description": "additional collections provided by the user that get applied to the step output", + "items": { + "type": "object", + "properties": { + "relatedEntityMappingId": { + "type": "string", + "description": "Unique identifier of the related entity mapping" + }, + "expressionContext": { + "type": "string", + "description": "An element in the source data from which to derive the values of this related entity's properties" + }, + "uriExpression": { + "type": "string", + "description": "XPath expression for generating the uri of this related entity instance document" + }, + "properties": { + "type": "object", + "$ref": "./MappingProperties.schema.json" + }, + "collections": { + "type": "array", + "items": { + "type": "string" + }, + "description": "additional collections provided by the user that get applied to this related entity instance document" + }, + "permissions": { + "type": "string", + "description": "Comma-delimited string of role,capability,role,capability,etc for the entity instance generated by this mapping" + }, + "targetEntityType": { + "type": "string", + "description": "The identifier of the related Entity Type. (IRI, with title as fallback)" + } + }, + "required": ["relatedEntityMappingId", "properties", "targetEntityType"] + } + } + } +} diff --git a/specs/models/Step.schema.json b/specs/models/Step.schema.json index 14dae91b8c..7dcb46989a 100644 --- a/specs/models/Step.schema.json +++ b/specs/models/Step.schema.json @@ -1,5 +1,6 @@ { "title": "Step", + "id": "http://marklogic.com/data-hub/Step.schema.json", "type": "object", "properties": { "interceptors": {