generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify MappingModelCoverageAnalysis to return PMCD for the model cove…
…rage (#2152) * Modify MappingModelCoverageAnalysis to return PMCD for the model coverage * update MappedEntityInfo model * update pom.xml * Update Server.java
- Loading branch information
1 parent
0e51390
commit 826ab6c
Showing
59 changed files
with
3,435 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...lytics/legend-engine-xts-analytics-binding/legend-engine-xt-analytics-binding-api/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2023 Goldman Sachs | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xts-analytics-binding</artifactId> | ||
<version>4.30.3-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>legend-engine-xt-analytics-binding-api</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Legend Engine - XT - Analytics - Binding - API</name> | ||
|
||
<dependencies> | ||
<!-- ENGINE --> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-external-shared</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-language-pure-modelManager</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-protocol-pure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-language-pure-compiler</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-shared-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-code-compiled-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-analytics-binding-pure</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<!-- ENGINE --> | ||
|
||
<!-- ANNOTATIONS --> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.swagger</groupId> | ||
<artifactId>swagger-annotations</artifactId> | ||
</dependency> | ||
<!-- ANNOTATIONS --> | ||
|
||
<!-- AUTHENTICATION --> | ||
<dependency> | ||
<groupId>org.pac4j.jax-rs</groupId> | ||
<artifactId>core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.pac4j</groupId> | ||
<artifactId>pac4j-core</artifactId> | ||
</dependency> | ||
<!-- AUTHENTICATION --> | ||
|
||
<!-- JACKSON --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<!-- JACKSON --> | ||
|
||
<!-- ECLIPSE COLLECTIONS --> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
<!-- ECLIPSE COLLECTIONS --> | ||
|
||
<!-- OPEN TRACING --> | ||
<dependency> | ||
<groupId>io.opentracing</groupId> | ||
<artifactId>opentracing-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentracing</groupId> | ||
<artifactId>opentracing-util</artifactId> | ||
</dependency> | ||
<!-- OPEN TRACING --> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-shared-core</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-common</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-external-shared-format-model</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-json-model</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- TEST --> | ||
</dependencies> | ||
</project> |
101 changes: 101 additions & 0 deletions
101
...ics-binding-api/src/main/java/org.finos.legend.engine.api.analytics/BindingAnalytics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2023 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.engine.api.analytics; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.opentracing.Scope; | ||
import io.opentracing.util.GlobalTracer; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiParam; | ||
import org.eclipse.collections.api.RichIterable; | ||
import org.eclipse.collections.api.list.MutableList; | ||
import org.eclipse.collections.impl.factory.Lists; | ||
import org.finos.legend.engine.api.analytics.model.BindingModelCoverageAnalysisInput; | ||
import org.finos.legend.engine.external.shared.format.imports.PureModelContextDataGenerator; | ||
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; | ||
import org.finos.legend.engine.language.pure.modelManager.ModelManager; | ||
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; | ||
import org.finos.legend.engine.shared.core.ObjectMapperFactory; | ||
import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; | ||
import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; | ||
import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; | ||
import org.finos.legend.engine.shared.core.operational.http.InflateInterceptor; | ||
import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; | ||
import org.finos.legend.pure.generated.Root_meta_analytics_binding_modelCoverage_BindingModelCoverageAnalysisResult; | ||
import org.finos.legend.pure.generated.Root_meta_external_format_shared_binding_Binding; | ||
import org.finos.legend.pure.generated.core_analytics_binding_modelCoverage_analytics; | ||
import org.pac4j.core.profile.CommonProfile; | ||
import org.pac4j.core.profile.ProfileManager; | ||
import org.pac4j.jax.rs.annotations.Pac4JProfileManager; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.Objects; | ||
|
||
@Api(tags = "Analytics - Model") | ||
@Path("pure/v1/analytics/binding") | ||
public class BindingAnalytics | ||
{ | ||
private static final ObjectMapper objectMapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports(); | ||
|
||
private final ModelManager modelManager; | ||
|
||
public BindingAnalytics(ModelManager modelManager) | ||
{ | ||
this.modelManager = modelManager; | ||
} | ||
|
||
@POST | ||
@Path("modelCoverage") | ||
@ApiOperation(value = "Analyze the binding to identify models covered by the binding") | ||
@Consumes({MediaType.APPLICATION_JSON, InflateInterceptor.APPLICATION_ZLIB}) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response analyzeBindingModelCoverage(BindingModelCoverageAnalysisInput input, | ||
@QueryParam("includeBinding") @DefaultValue("true") boolean includeBinding, | ||
@ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm) | ||
{ | ||
MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm); | ||
PureModelContextData pureModelContextData = this.modelManager.loadData(input.model, input.clientVersion, profiles); | ||
PureModel pureModel = this.modelManager.loadModel(pureModelContextData, input.clientVersion, profiles, null); | ||
Root_meta_external_format_shared_binding_Binding binding = (Root_meta_external_format_shared_binding_Binding) pureModel.getPackageableElement(input.binding); | ||
RichIterable<? extends Root_meta_external_format_shared_binding_Binding> bindings = Lists.immutable.of(binding); | ||
|
||
try (Scope scope = GlobalTracer.get().buildSpan("Analytics: binding model coverage").startActive(true)) | ||
{ | ||
try | ||
{ | ||
Root_meta_analytics_binding_modelCoverage_BindingModelCoverageAnalysisResult result = core_analytics_binding_modelCoverage_analytics.Root_meta_analytics_binding_modelCoverage_getBindingModelCoverage_Binding_MANY__BindingModelCoverageAnalysisResult_1_(bindings, pureModel.getExecutionSupport()); | ||
PureModelContextData classes = PureModelContextDataGenerator.generatePureModelContextDataFromClasses(result._classes(), input.clientVersion, pureModel.getExecutionSupport()); | ||
PureModelContextData.Builder builder = PureModelContextData.newBuilder(); | ||
if (includeBinding) | ||
{ | ||
builder.addElement(Objects.requireNonNull(pureModelContextData.getElements().stream().filter(el -> input.binding.equals(el.getPath())).findFirst().get())); | ||
} | ||
return ManageConstantResult.manageResult(profiles, builder.build().combine(classes), objectMapper); | ||
} | ||
catch (Exception e) | ||
{ | ||
return ExceptionTool.exceptionManager(e, LoggingEventType.ANALYTICS_ERROR, Response.Status.BAD_REQUEST, profiles); | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...n/java/org.finos.legend.engine.api.analytics/model/BindingModelCoverageAnalysisInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.engine.api.analytics.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; | ||
|
||
public class BindingModelCoverageAnalysisInput | ||
{ | ||
public String clientVersion; | ||
|
||
@JsonProperty(required = true) | ||
public String binding; | ||
|
||
@JsonProperty(required = true) | ||
public PureModelContext model; | ||
|
||
@JsonCreator | ||
public BindingModelCoverageAnalysisInput( | ||
@JsonProperty("clientVersion") String clientVersion, | ||
@JsonProperty("binding") String binding, | ||
@JsonProperty("model") PureModelContext model) | ||
{ | ||
this.clientVersion = clientVersion; | ||
this.binding = binding; | ||
this.model = model; | ||
} | ||
} |
Oops, something went wrong.