Skip to content

Commit

Permalink
Merge branch 'release/2022-11'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gomes committed Dec 16, 2022
2 parents 9ff90c1 + c205604 commit 4961e98
Show file tree
Hide file tree
Showing 202 changed files with 522,289 additions and 516,604 deletions.
3 changes: 3 additions & 0 deletions app/controllers/CommitController.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public Result getChangeByProjectCommitAndId(UUID projectId, UUID commitId, UUID
return Results.status(NOT_IMPLEMENTED);
}
Optional<DataVersion> change = commitService.getChangeByProjectIdCommitIdAndId(projectId, commitId, changeId);
if (change.isEmpty()) {
return Results.notFound();
}
JsonNode json = JacksonHelper.objectToTree(
change,
Json.mapper()
Expand Down
23 changes: 22 additions & 1 deletion app/controllers/ElementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
* Copyright (C) 2021 Twingineer LLC
* Copyright (C) 2021-2022 Twingineer LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -22,13 +22,18 @@

package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import config.MetamodelProvider;
import jackson.JacksonHelper;
import jackson.jsonld.DataJsonLdAdorner;
import jackson.jsonld.JsonLdAdorner;
import org.omg.sysml.data.ProjectUsage;
import org.omg.sysml.metamodel.Element;
import play.Environment;
import play.libs.Json;
import play.mvc.Http.Request;
import play.mvc.Result;
import play.mvc.Results;
import services.ElementService;

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

public Result getProjectUsageByProjectIdCommitIdElementId(UUID projectId, UUID commitId, UUID elementId, Request request) {
if (respondWithJsonLd(request)) {
// TODO implement
return Results.status(NOT_IMPLEMENTED);
}
Optional<ProjectUsage> projectUsage = elementService.getProjectUsageByProjectIdCommitIdElementId(projectId, commitId, elementId);
if (projectUsage.isEmpty()) {
return Results.notFound();
}
JsonNode json = JacksonHelper.objectToTree(
projectUsage,
Json.mapper()
);
return Results.ok(json);
}

public Result getRootsByProjectIdCommitId(UUID projectId, UUID commitId, Optional<Boolean> excludeUsed, Request request) {
PageRequest<UUID> pageRequest = uuidRequest(request);
List<Element> roots = elementService.getRootsByProjectIdCommitId(projectId, commitId, excludeUsed.orElse(false), pageRequest.getAfter(), pageRequest.getBefore(), pageRequest.getSize());
Expand Down
5 changes: 4 additions & 1 deletion app/dao/ElementDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
* Copyright (C) 2021 Twingineer LLC
* Copyright (C) 2021-2022 Twingineer LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -22,6 +22,7 @@

package dao;

import org.omg.sysml.data.ProjectUsage;
import org.omg.sysml.lifecycle.Commit;
import org.omg.sysml.metamodel.Element;

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

Optional<Element> findByCommitAndQualifiedName(Commit commit, String qualifiedName);

Optional<ProjectUsage> findProjectUsageByCommitAndId(Commit commit, UUID elementId);
}
2 changes: 1 addition & 1 deletion app/dao/impl/FlatSchemaDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public FlatSchemaDao(MetamodelProvider metamodelProvider) {
try (Stream<Class<?>> interfaces = metamodelProvider.getAllInterfaces().stream()) {
map = Streams.concat(
interfaces
.map(type -> FlatSchemaDao.class.getResourceAsStream(String.format("/json/schema/lang/%s.json",
.map(type -> FlatSchemaDao.class.getResourceAsStream(String.format("/json/schema/metamodel/%s.json",
type.getSimpleName())))
.filter(Objects::nonNull),
Stream.of(ExternalData.class, ExternalRelationship.class, ProjectUsage.class)
Expand Down
29 changes: 29 additions & 0 deletions app/dao/impl/jpa/JpaElementDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import config.MetamodelProvider;
import dao.ElementDao;
import jpa.manager.JPAManager;
import org.omg.sysml.data.ProjectUsage;
import org.omg.sysml.internal.CommitDataVersionIndex;
import org.omg.sysml.internal.CommitNamedElementIndex;
import org.omg.sysml.internal.WorkingDataVersion;
Expand Down Expand Up @@ -207,6 +208,34 @@ public Optional<Element> findByCommitAndQualifiedName(Commit commit, String qual
});
}

@Override
public Optional<ProjectUsage> findProjectUsageByCommitAndId(Commit commit, UUID elementId) {
return jpaManager.transact(em -> {
// 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.
Commit c = em.contains(commit) ? commit : em.find(CommitImpl.class, commit.getId());
CommitDataVersionIndex commitIndex = dataDao.getCommitIndex(c, em);

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<WorkingDataVersionImpl> query = builder.createQuery(WorkingDataVersionImpl.class);
Root<CommitDataVersionIndexImpl> commitIndexRoot = query.from(CommitDataVersionIndexImpl.class);
SetJoin<CommitDataVersionIndexImpl, WorkingDataVersionImpl> workingDataVersionJoin = commitIndexRoot.join(CommitDataVersionIndexImpl_.workingDataVersion);
Join<WorkingDataVersionImpl, DataVersionImpl> dataVersionJoin = workingDataVersionJoin.join(WorkingDataVersionImpl_.dataVersion);
Join<DataVersionImpl, DataIdentityImpl> dataIdentityJoin = dataVersionJoin.join(DataVersionImpl_.identity);
Expression<Boolean> where = builder.and(
builder.equal(commitIndexRoot.get(CommitDataVersionIndexImpl_.id), commitIndex.getId()),
builder.equal(dataIdentityJoin.get(DataIdentityImpl_.id), elementId)
);
query.select(workingDataVersionJoin).where(where);
try {
return Optional.of(em.createQuery(query).getSingleResult())
.map(WorkingDataVersion::getSource)
.map(projectUsage -> JpaDataDao.resolve(projectUsage, ProjectUsage.class));
} catch (NoResultException e) {
return Optional.empty();
}
});
}

protected CommitNamedElementIndex getCommitNamedElementIndex(Commit commit, EntityManager em) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<CommitNamedElementIndexImpl> query = builder.createQuery(CommitNamedElementIndexImpl.class);
Expand Down
4 changes: 3 additions & 1 deletion app/org/omg/sysml/data/ProjectUsage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2021 Twingineer LLC
* Copyright (C) 2021-2022 Twingineer LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -26,6 +26,8 @@

public interface ProjectUsage extends Data {

String NAME = "ProjectUsage";

Commit getUsedCommit();

Project getUsedProject();
Expand Down
13 changes: 8 additions & 5 deletions app/org/omg/sysml/data/impl/ProjectUsageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
* Copyright (C) 2021 Twingineer LLC
* Copyright (C) 2021-2022 Twingineer LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -22,10 +22,7 @@

package org.omg.sysml.data.impl;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import jackson.RecordSerialization;
Expand Down Expand Up @@ -89,4 +86,10 @@ public Project getUsedProject() {
}
return usedCommit.getOwningProject();
}

@Transient
@JsonProperty("@type")
public String getType() {
return ProjectUsage.NAME;
}
}
12 changes: 10 additions & 2 deletions app/services/ElementService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
* Copyright (C) 2022 Twingineer LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -24,6 +25,7 @@
import dao.CommitDao;
import dao.ElementDao;
import dao.ProjectDao;
import org.omg.sysml.data.ProjectUsage;
import org.omg.sysml.metamodel.Element;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -81,4 +83,10 @@ public Optional<Element> getElementByProjectIdCommitIdQualifiedName(UUID project
.flatMap(project -> commitDao.findByProjectAndId(project, commitId))
.flatMap(commit -> dao.findByCommitAndQualifiedName(commit, qualifiedName));
}

public Optional<ProjectUsage> getProjectUsageByProjectIdCommitIdElementId(UUID projectId, UUID commitId, UUID elementId) {
return projectDao.findById(projectId)
.flatMap(project -> commitDao.findByProjectAndId(project, commitId))
.flatMap(commit -> dao.findProjectUsageByCommitAndId(commit, elementId));
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := """SysML-v2-API-Services"""
organization := "org.omg"

version := "2022-11-rc2"
version := "2022-11"

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

Expand Down
2 changes: 1 addition & 1 deletion conf/json/schema/api/ExternalData.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://www.omg.org/spec/SysML/2.0/API/ExternalData",
"$id": "https://www.omg.org/spec/SystemsModelingAPI/20230201/ExternalData",
"type": "object",
"properties": {
"@id": {
Expand Down
12 changes: 6 additions & 6 deletions conf/json/schema/api/ExternalRelationship.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://www.omg.org/spec/SysML/2.0/API/ExternalRelationship",
"$id": "https://www.omg.org/spec/SystemsModelingAPI/20230201/ExternalRelationship",
"type": "object",
"properties": {
"@id": {
Expand All @@ -12,12 +12,12 @@
"const": "ExternalRelationship"
},
"elementEnd": {
"$ref": "http://www.omg.org/spec/SysML/2.0/Identified",
"$comment": "http://www.omg.org/spec/SysML/2.0/Element"
"$ref": "https://www.omg.org/spec/SysML/20230201/Identified",
"$comment": "https://www.omg.org/spec/SysML/20230201/Element"
},
"externalDataEnd": {
"$ref": "http://www.omg.org/spec/SysML/2.0/Identified",
"$comment": "http://www.omg.org/spec/SysML/2.0/API/ExternalData"
"$ref": "https://www.omg.org/spec/SysML/20230201/Identified",
"$comment": "https://www.omg.org/spec/SystemsModelingAPI/20230201/ExternalData"
},
"language": {
"oneOf": [
Expand Down Expand Up @@ -51,7 +51,7 @@
"additionalProperties": false,
"$defs": {
"Identified": {
"$id": "http://www.omg.org/spec/SysML/2.0/Identified",
"$id": "https://www.omg.org/spec/SysML/20230201/Identified",
"title": "Identified",
"type": "object",
"properties": {
Expand Down
12 changes: 6 additions & 6 deletions conf/json/schema/api/ProjectUsage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://www.omg.org/spec/SysML/2.0/API/ProjectUsage",
"$id": "https://www.omg.org/spec/SystemsModelingAPI/20230201/ProjectUsage",
"type": "object",
"properties": {
"@id": {
Expand All @@ -12,12 +12,12 @@
"const": "ProjectUsage"
},
"usedCommit": {
"$ref": "http://www.omg.org/spec/SysML/2.0/Identified",
"$comment": "http://www.omg.org/spec/SysML/2.0/API/Commit"
"$ref": "https://www.omg.org/spec/SysML/20230201/Identified",
"$comment": "https://www.omg.org/spec/SystemsModelingAPI/20230201/Commit"
},
"usedProject": {
"$ref": "http://www.omg.org/spec/SysML/2.0/Identified",
"$comment": "http://www.omg.org/spec/SysML/2.0/API/Project"
"$ref": "https://www.omg.org/spec/SysML/20230201/Identified",
"$comment": "https://www.omg.org/spec/SystemsModelingAPI/20230201/Project"
}
},
"required": [
Expand All @@ -29,7 +29,7 @@
"additionalProperties": false,
"$defs": {
"Identified": {
"$id": "http://www.omg.org/spec/SysML/2.0/Identified",
"$id": "https://www.omg.org/spec/SysML/20230201/Identified",
"title": "Identified",
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 4961e98

Please sign in to comment.