Skip to content

Commit 4961e98

Browse files
committed
Merge branch 'release/2022-11'
2 parents 9ff90c1 + c205604 commit 4961e98

202 files changed

Lines changed: 522289 additions & 516604 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/controllers/CommitController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public Result getChangeByProjectCommitAndId(UUID projectId, UUID commitId, UUID
159159
return Results.status(NOT_IMPLEMENTED);
160160
}
161161
Optional<DataVersion> change = commitService.getChangeByProjectIdCommitIdAndId(projectId, commitId, changeId);
162+
if (change.isEmpty()) {
163+
return Results.notFound();
164+
}
162165
JsonNode json = JacksonHelper.objectToTree(
163166
change,
164167
Json.mapper()

app/controllers/ElementController.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SysML v2 REST/HTTP Pilot Implementation
33
* Copyright (C) 2020 InterCAX LLC
44
* Copyright (C) 2020 California Institute of Technology ("Caltech")
5-
* Copyright (C) 2021 Twingineer LLC
5+
* Copyright (C) 2021-2022 Twingineer LLC
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
@@ -22,13 +22,18 @@
2222

2323
package controllers;
2424

25+
import com.fasterxml.jackson.databind.JsonNode;
2526
import config.MetamodelProvider;
27+
import jackson.JacksonHelper;
2628
import jackson.jsonld.DataJsonLdAdorner;
2729
import jackson.jsonld.JsonLdAdorner;
30+
import org.omg.sysml.data.ProjectUsage;
2831
import org.omg.sysml.metamodel.Element;
2932
import play.Environment;
33+
import play.libs.Json;
3034
import play.mvc.Http.Request;
3135
import play.mvc.Result;
36+
import play.mvc.Results;
3237
import services.ElementService;
3338

3439
import javax.inject.Inject;
@@ -61,6 +66,22 @@ public Result getElementByProjectIdCommitIdElementId(UUID projectId, UUID commit
6166
return buildResult(element.orElse(null), request, new DataJsonLdAdorner.Parameters(projectId, commitId));
6267
}
6368

69+
public Result getProjectUsageByProjectIdCommitIdElementId(UUID projectId, UUID commitId, UUID elementId, Request request) {
70+
if (respondWithJsonLd(request)) {
71+
// TODO implement
72+
return Results.status(NOT_IMPLEMENTED);
73+
}
74+
Optional<ProjectUsage> projectUsage = elementService.getProjectUsageByProjectIdCommitIdElementId(projectId, commitId, elementId);
75+
if (projectUsage.isEmpty()) {
76+
return Results.notFound();
77+
}
78+
JsonNode json = JacksonHelper.objectToTree(
79+
projectUsage,
80+
Json.mapper()
81+
);
82+
return Results.ok(json);
83+
}
84+
6485
public Result getRootsByProjectIdCommitId(UUID projectId, UUID commitId, Optional<Boolean> excludeUsed, Request request) {
6586
PageRequest<UUID> pageRequest = uuidRequest(request);
6687
List<Element> roots = elementService.getRootsByProjectIdCommitId(projectId, commitId, excludeUsed.orElse(false), pageRequest.getAfter(), pageRequest.getBefore(), pageRequest.getSize());

app/dao/ElementDao.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SysML v2 REST/HTTP Pilot Implementation
33
* Copyright (C) 2020 InterCAX LLC
44
* Copyright (C) 2020 California Institute of Technology ("Caltech")
5-
* Copyright (C) 2021 Twingineer LLC
5+
* Copyright (C) 2021-2022 Twingineer LLC
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
@@ -22,6 +22,7 @@
2222

2323
package dao;
2424

25+
import org.omg.sysml.data.ProjectUsage;
2526
import org.omg.sysml.lifecycle.Commit;
2627
import org.omg.sysml.metamodel.Element;
2728

@@ -39,4 +40,6 @@ public interface ElementDao extends Dao<Element> {
3940
List<Element> findRootsByCommit(Commit commit, boolean excludeUsed, @Nullable UUID after, @Nullable UUID before, int maxResults);
4041

4142
Optional<Element> findByCommitAndQualifiedName(Commit commit, String qualifiedName);
43+
44+
Optional<ProjectUsage> findProjectUsageByCommitAndId(Commit commit, UUID elementId);
4245
}

app/dao/impl/FlatSchemaDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public FlatSchemaDao(MetamodelProvider metamodelProvider) {
4949
try (Stream<Class<?>> interfaces = metamodelProvider.getAllInterfaces().stream()) {
5050
map = Streams.concat(
5151
interfaces
52-
.map(type -> FlatSchemaDao.class.getResourceAsStream(String.format("/json/schema/lang/%s.json",
52+
.map(type -> FlatSchemaDao.class.getResourceAsStream(String.format("/json/schema/metamodel/%s.json",
5353
type.getSimpleName())))
5454
.filter(Objects::nonNull),
5555
Stream.of(ExternalData.class, ExternalRelationship.class, ProjectUsage.class)

app/dao/impl/jpa/JpaElementDao.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import config.MetamodelProvider;
2626
import dao.ElementDao;
2727
import jpa.manager.JPAManager;
28+
import org.omg.sysml.data.ProjectUsage;
2829
import org.omg.sysml.internal.CommitDataVersionIndex;
2930
import org.omg.sysml.internal.CommitNamedElementIndex;
3031
import org.omg.sysml.internal.WorkingDataVersion;
@@ -207,6 +208,34 @@ public Optional<Element> findByCommitAndQualifiedName(Commit commit, String qual
207208
});
208209
}
209210

211+
@Override
212+
public Optional<ProjectUsage> findProjectUsageByCommitAndId(Commit commit, UUID elementId) {
213+
return jpaManager.transact(em -> {
214+
// TODO Commit is detached at this point. This ternary mitigates by requerying for the Commit in this transaction. A better solution would be moving transaction handling up to service layer (supported by general wisdom) and optionally migrating to using Play's @Transactional/JPAApi. Pros would include removal of repetitive transaction handling at the DAO layer and ability to interface with multiple DAOs in the same transaction (consistent view). Cons include increased temptation to keep transaction open for longer than needed, e.g. during JSON serialization due to the convenience of @Transactional (deprecated in >= 2.8.x), and the service, a higher level of abstraction, becoming aware of transactions. An alternative would be DAO-to-DAO calls (generally discouraged) and delegating to non-transactional versions of methods.
215+
Commit c = em.contains(commit) ? commit : em.find(CommitImpl.class, commit.getId());
216+
CommitDataVersionIndex commitIndex = dataDao.getCommitIndex(c, em);
217+
218+
CriteriaBuilder builder = em.getCriteriaBuilder();
219+
CriteriaQuery<WorkingDataVersionImpl> query = builder.createQuery(WorkingDataVersionImpl.class);
220+
Root<CommitDataVersionIndexImpl> commitIndexRoot = query.from(CommitDataVersionIndexImpl.class);
221+
SetJoin<CommitDataVersionIndexImpl, WorkingDataVersionImpl> workingDataVersionJoin = commitIndexRoot.join(CommitDataVersionIndexImpl_.workingDataVersion);
222+
Join<WorkingDataVersionImpl, DataVersionImpl> dataVersionJoin = workingDataVersionJoin.join(WorkingDataVersionImpl_.dataVersion);
223+
Join<DataVersionImpl, DataIdentityImpl> dataIdentityJoin = dataVersionJoin.join(DataVersionImpl_.identity);
224+
Expression<Boolean> where = builder.and(
225+
builder.equal(commitIndexRoot.get(CommitDataVersionIndexImpl_.id), commitIndex.getId()),
226+
builder.equal(dataIdentityJoin.get(DataIdentityImpl_.id), elementId)
227+
);
228+
query.select(workingDataVersionJoin).where(where);
229+
try {
230+
return Optional.of(em.createQuery(query).getSingleResult())
231+
.map(WorkingDataVersion::getSource)
232+
.map(projectUsage -> JpaDataDao.resolve(projectUsage, ProjectUsage.class));
233+
} catch (NoResultException e) {
234+
return Optional.empty();
235+
}
236+
});
237+
}
238+
210239
protected CommitNamedElementIndex getCommitNamedElementIndex(Commit commit, EntityManager em) {
211240
CriteriaBuilder builder = em.getCriteriaBuilder();
212241
CriteriaQuery<CommitNamedElementIndexImpl> query = builder.createQuery(CommitNamedElementIndexImpl.class);

app/org/omg/sysml/data/ProjectUsage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* SysML v2 REST/HTTP Pilot Implementation
3-
* Copyright (C) 2021 Twingineer LLC
3+
* Copyright (C) 2021-2022 Twingineer LLC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -26,6 +26,8 @@
2626

2727
public interface ProjectUsage extends Data {
2828

29+
String NAME = "ProjectUsage";
30+
2931
Commit getUsedCommit();
3032

3133
Project getUsedProject();

app/org/omg/sysml/data/impl/ProjectUsageImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SysML v2 REST/HTTP Pilot Implementation
33
* Copyright (C) 2020 InterCAX LLC
44
* Copyright (C) 2020 California Institute of Technology ("Caltech")
5-
* Copyright (C) 2021 Twingineer LLC
5+
* Copyright (C) 2021-2022 Twingineer LLC
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
@@ -22,10 +22,7 @@
2222

2323
package org.omg.sysml.data.impl;
2424

25-
import com.fasterxml.jackson.annotation.JsonGetter;
26-
import com.fasterxml.jackson.annotation.JsonSetter;
27-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
28-
import com.fasterxml.jackson.annotation.JsonTypeName;
25+
import com.fasterxml.jackson.annotation.*;
2926
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
3027
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
3128
import jackson.RecordSerialization;
@@ -89,4 +86,10 @@ public Project getUsedProject() {
8986
}
9087
return usedCommit.getOwningProject();
9188
}
89+
90+
@Transient
91+
@JsonProperty("@type")
92+
public String getType() {
93+
return ProjectUsage.NAME;
94+
}
9295
}

app/services/ElementService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
* SysML v2 REST/HTTP Pilot Implementation
3-
* Copyright (C) 2020 InterCAX LLC
4-
* Copyright (C) 2020 California Institute of Technology ("Caltech")
3+
* Copyright (C) 2020 InterCAX LLC
4+
* Copyright (C) 2020 California Institute of Technology ("Caltech")
5+
* Copyright (C) 2022 Twingineer LLC
56
*
67
* This program is free software: you can redistribute it and/or modify
78
* it under the terms of the GNU Lesser General Public License as published by
@@ -24,6 +25,7 @@
2425
import dao.CommitDao;
2526
import dao.ElementDao;
2627
import dao.ProjectDao;
28+
import org.omg.sysml.data.ProjectUsage;
2729
import org.omg.sysml.metamodel.Element;
2830

2931
import javax.annotation.Nullable;
@@ -81,4 +83,10 @@ public Optional<Element> getElementByProjectIdCommitIdQualifiedName(UUID project
8183
.flatMap(project -> commitDao.findByProjectAndId(project, commitId))
8284
.flatMap(commit -> dao.findByCommitAndQualifiedName(commit, qualifiedName));
8385
}
86+
87+
public Optional<ProjectUsage> getProjectUsageByProjectIdCommitIdElementId(UUID projectId, UUID commitId, UUID elementId) {
88+
return projectDao.findById(projectId)
89+
.flatMap(project -> commitDao.findByProjectAndId(project, commitId))
90+
.flatMap(commit -> dao.findProjectUsageByCommitAndId(commit, elementId));
91+
}
8492
}

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name := """SysML-v2-API-Services"""
22
organization := "org.omg"
33

4-
version := "2022-11-rc2"
4+
version := "2022-11"
55

66
javacOptions ++= Seq("-source", "11", "-target", "11", "-Xlint")
77

conf/json/schema/api/ExternalData.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "http://www.omg.org/spec/SysML/2.0/API/ExternalData",
3+
"$id": "https://www.omg.org/spec/SystemsModelingAPI/20230201/ExternalData",
44
"type": "object",
55
"properties": {
66
"@id": {

0 commit comments

Comments
 (0)