Skip to content

Commit 4574bec

Browse files
committed
versioning query storage for application query
1 parent 7cac070 commit 4574bec

File tree

15 files changed

+1673
-270
lines changed

15 files changed

+1673
-270
lines changed

legend-engine-application-query/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<groupId>org.finos.legend.engine</groupId>
5050
<artifactId>legend-engine-shared-vault-core</artifactId>
5151
</dependency>
52+
<dependency>
53+
<groupId>org.finos.legend.engine</groupId>
54+
<artifactId>legend-engine-shared-mongo</artifactId>
55+
</dependency>
5256
<!-- ENGINE -->
5357

5458
<!-- JACKSON -->
@@ -138,6 +142,11 @@
138142
</dependency>
139143
<!-- LOG -->
140144

145+
<dependency>
146+
<groupId>org.apache.commons</groupId>
147+
<artifactId>commons-lang3</artifactId>
148+
</dependency>
149+
141150
<!-- TEST -->
142151
<dependency>
143152
<groupId>junit</groupId>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2026 Goldman Sachs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package org.finos.legend.engine.application.query.api;
16+
17+
import com.mongodb.client.MongoClient;
18+
import org.finos.legend.engine.application.query.model.ApplicationStoredQuery;
19+
import org.finos.legend.engine.shared.mongo.api.BaseStoredVersionedAssetDao;
20+
21+
/**
22+
* DAO for ApplicationStoredQuery that handles persistence with embedded audit information.
23+
* Extends BaseStoredVersionedAssetDao to inherit common versioning and audit logic.
24+
*/
25+
public class ApplicationQueryDao extends BaseStoredVersionedAssetDao<ApplicationStoredQuery, String>
26+
{
27+
public ApplicationQueryDao(MongoClient client, String database, String collectionName)
28+
{
29+
super(client, database, collectionName, ApplicationStoredQuery.class);
30+
}
31+
}

legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/api/QueryStoreManager.java

Lines changed: 85 additions & 117 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2026 Goldman Sachs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package org.finos.legend.engine.application.query.model;
16+
17+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
18+
import org.apache.commons.lang3.builder.EqualsBuilder;
19+
import org.apache.commons.lang3.builder.HashCodeBuilder;
20+
import org.finos.legend.engine.protocol.pure.m3.extension.StereotypePtr;
21+
import org.finos.legend.engine.protocol.pure.m3.extension.TaggedValue;
22+
import org.finos.legend.engine.shared.mongo.model.StoredAuditInformation;
23+
import org.finos.legend.engine.shared.mongo.model.StoredVersionedAssetContent;
24+
25+
import java.util.List;
26+
import java.util.Map;
27+
28+
@JsonIgnoreProperties(ignoreUnknown = true)
29+
public class ApplicationStoredQuery implements StoredVersionedAssetContent<String>
30+
{
31+
public String id;
32+
public String name;
33+
public String description;
34+
public String groupId;
35+
public String artifactId;
36+
public String versionId;
37+
public String originalVersionId;
38+
public QueryExecutionContext executionContext;
39+
public String content;
40+
public List<TaggedValue> taggedValues;
41+
public List<StereotypePtr> stereotypes;
42+
public List<QueryParameterValue> defaultParameterValues;
43+
public Map<String, ?> gridConfig;
44+
public Long lastOpenAt;
45+
public StoredAuditInformation audit;
46+
47+
@Override
48+
public String getId()
49+
{
50+
return id;
51+
}
52+
53+
@Override
54+
public StoredAuditInformation getAudit()
55+
{
56+
return audit;
57+
}
58+
59+
@Override
60+
public void setAudit(StoredAuditInformation audit)
61+
{
62+
this.audit = audit;
63+
}
64+
65+
@Override
66+
public boolean equals(Object obj)
67+
{
68+
return EqualsBuilder.reflectionEquals(this, obj);
69+
}
70+
71+
@Override
72+
public int hashCode()
73+
{
74+
return HashCodeBuilder.reflectionHashCode(this);
75+
}
76+
}

legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/model/Query.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Query
3131
public String artifactId;
3232
public String versionId;
3333
public String originalVersionId;
34+
// keeping this only for backward compatibility - this will not be populated
3435
@Deprecated
3536
public String mapping;
3637
@Deprecated
@@ -40,6 +41,9 @@ public class Query
4041
public Long lastUpdatedAt;
4142
public Long createdAt;
4243
public Long lastOpenAt;
44+
public Long deletedAt;
45+
public Long validUntil;
46+
public Integer version;
4347

4448
public List<TaggedValue> taggedValues;
4549
public List<StereotypePtr> stereotypes;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2026 Goldman Sachs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package org.finos.legend.engine.application.query.model;
16+
17+
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import org.finos.legend.engine.application.query.api.ApplicationQueryException;
19+
import org.finos.legend.engine.shared.mongo.model.StoredAuditInformation;
20+
21+
import javax.ws.rs.core.Response;
22+
import java.time.Instant;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
25+
26+
/**
27+
* Utility class to convert between Query (API model) and ApplicationStoredQuery (storage model).
28+
*/
29+
public class QueryModelConverter
30+
{
31+
private QueryModelConverter()
32+
{
33+
}
34+
35+
/**
36+
* Convert from storage model to API model.
37+
*/
38+
public static Query toQuery(ApplicationStoredQuery stored)
39+
{
40+
if (stored == null)
41+
{
42+
return null;
43+
}
44+
45+
Query query;
46+
try
47+
{
48+
query = new ObjectMapper().convertValue(stored, Query.class);
49+
}
50+
catch (Exception e)
51+
{
52+
throw new ApplicationQueryException("Unable to deserialize stored asset to class '" + Query.class.getName() + "':" + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
53+
}
54+
55+
56+
// Copy audit information to flattened fields
57+
if (stored.getAudit() != null)
58+
{
59+
query.version = stored.getAudit().getVersion();
60+
query.createdAt = toEpochMilli(stored.getAudit().getCreatedAt());
61+
query.lastUpdatedAt = toEpochMilli(stored.getAudit().getUpdatedAt());
62+
query.owner = stored.getAudit().getCreatedBy();
63+
query.deletedAt = toEpochMilli(stored.getAudit().getDeletedAt());
64+
query.validUntil = toEpochMilli(stored.getAudit().getValidUntil());
65+
}
66+
67+
return query;
68+
}
69+
70+
/**
71+
* Convert from API model to storage model.
72+
*/
73+
public static ApplicationStoredQuery toStoredQuery(Query query)
74+
{
75+
if (query == null)
76+
{
77+
return null;
78+
}
79+
80+
ApplicationStoredQuery stored = new ApplicationStoredQuery();
81+
stored.id = query.id;
82+
stored.name = query.name;
83+
stored.description = query.description;
84+
stored.groupId = query.groupId;
85+
stored.artifactId = query.artifactId;
86+
stored.versionId = query.versionId;
87+
stored.originalVersionId = query.originalVersionId;
88+
stored.executionContext = query.executionContext;
89+
stored.content = query.content;
90+
stored.taggedValues = query.taggedValues;
91+
stored.stereotypes = query.stereotypes;
92+
stored.defaultParameterValues = query.defaultParameterValues;
93+
stored.gridConfig = query.gridConfig;
94+
stored.lastOpenAt = Instant.now().toEpochMilli();
95+
96+
// Initialize audit with info from query
97+
stored.audit = StoredAuditInformation.builder()
98+
.withVersion(query.version)
99+
.withCreatedAt(toLocalDateTime(query.createdAt != null ? query.createdAt : Instant.now().toEpochMilli()))
100+
.withCreatedBy(query.owner)
101+
.build();
102+
103+
return stored;
104+
}
105+
106+
private static Long toEpochMilli(LocalDateTime dateTime)
107+
{
108+
if (dateTime == null)
109+
{
110+
return null;
111+
}
112+
return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
113+
}
114+
115+
private static LocalDateTime toLocalDateTime(Long epochMilli)
116+
{
117+
return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneId.systemDefault());
118+
}
119+
}
120+

0 commit comments

Comments
 (0)