Skip to content

Commit

Permalink
Merge branch 'release/2020-09'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gomes committed Oct 9, 2020
2 parents 6555752 + 2c76d97 commit 3febd23
Show file tree
Hide file tree
Showing 361 changed files with 9,836 additions and 437 deletions.
32 changes: 24 additions & 8 deletions app/Module.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

import com.google.inject.AbstractModule;
import config.MetamodelProvider;
import config.impl.JPAMetamodelProvider;
import dao.CommitDao;
import dao.ElementDao;
import dao.ProjectDao;
import dao.RelationshipDao;
import dao.impl.jpa.JpaCommitDao;
import dao.impl.jpa.JpaElementDao;
import dao.impl.jpa.JpaProjectDao;
import dao.impl.jpa.JpaRelationshipDao;
import dao.*;
import dao.impl.jpa.*;
import jackson.databind.ObjectMapperFactory;
import jackson.databind.impl.HibernateObjectMapperFactory;
import jpa.manager.JPAManager;
Expand All @@ -25,5 +40,6 @@ protected void configure() {
bind(ProjectDao.class).to(JpaProjectDao.class);
bind(RelationshipDao.class).to(JpaRelationshipDao.class);
bind(CommitDao.class).to(JpaCommitDao.class);
bind(QueryDao.class).to(JpaQueryDao.class);
}
}
21 changes: 21 additions & 0 deletions app/config/MetamodelProvider.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

package config;

import java.util.Set;
Expand Down
50 changes: 40 additions & 10 deletions app/config/impl/JPAMetamodelProvider.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

package config.impl;

import config.MetamodelProvider;
import org.omg.sysml.metamodel.MofObject;
import org.omg.sysml.metamodel.impl.MofObjectImpl;
import org.omg.sysml.query.Constraint;
import org.omg.sysml.record.Record;
import org.reflections.Reflections;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class JPAMetamodelProvider implements MetamodelProvider {
private static Set<Class<?>> INTERFACES = new HashSet<>(), IMPLEMENTATION_CLASSES = new HashSet<>();
private static final Set<Class<?>> INTERFACES = new HashSet<>();
private static final Set<Class<?>> IMPLEMENTATION_CLASSES = new HashSet<>();

static {
INTERFACES.add(MofObject.class);
for (String pakkage : new String[]{"org.omg.sysml.metamodel", "org.omg.sysml.extension", "org.omg.sysml.versioning"}) {
INTERFACES.addAll(new Reflections(pakkage).getSubTypesOf(MofObject.class));
}
IMPLEMENTATION_CLASSES.add(MofObjectImpl.class);
for (String pakkage : new String[]{"org.omg.sysml.metamodel.impl", "org.omg.sysml.extension.impl", "org.omg.sysml.versioning.impl"}) {
IMPLEMENTATION_CLASSES.addAll(new Reflections(pakkage).getSubTypesOf(MofObjectImpl.class));
}
List<Class<?>> roots = Arrays.asList(
MofObject.class,
Record.class,
Constraint.class
);
String packageScope = "org.omg.sysml";

INTERFACES.addAll(roots);
Reflections reflections = new Reflections(packageScope);
roots.stream()
.map(reflections::getSubTypesOf)
.flatMap(Set::stream)
.forEach(c -> (c.isInterface() ? INTERFACES : IMPLEMENTATION_CLASSES).add(c));
}

@Override
Expand Down
42 changes: 34 additions & 8 deletions app/controllers/CommitController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import config.MetamodelProvider;
import jackson.JacksonHelper;
import org.omg.sysml.lifecycle.Commit;
Expand All @@ -19,11 +41,15 @@
import java.util.UUID;

public class CommitController extends Controller {
@Inject
private MetamodelProvider metamodelProvider;

private final MetamodelProvider metamodelProvider;
private final CommitService commitService;

@Inject
private CommitService commitService;
public CommitController(CommitService commitService, MetamodelProvider metamodelProvider) {
this.commitService = commitService;
this.metamodelProvider = metamodelProvider;
}

public Result byId(String id) {
UUID uuid = UUID.fromString(id);
Expand All @@ -33,7 +59,7 @@ public Result byId(String id) {

public Result all() {
List<Commit> commits = commitService.getAll();
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Commit.class), commits));
return ok(JacksonHelper.collectionToTree(commits, List.class, metamodelProvider.getImplementationClass(Commit.class)));
}

public Result create(Http.Request request) {
Expand All @@ -54,13 +80,13 @@ public Result createWithProjectId(UUID projectId, Http.Request request) {
return Results.badRequest();
}
requestedObject.setTimestamp(ZonedDateTime.now());
Optional<Commit> responseCommit = commitService.create(projectId, requestedObject);
return responseCommit.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
Optional<Commit> response = commitService.create(projectId, requestedObject);
return response.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
}

public Result byProject(UUID projectId) {
List<Commit> commits = commitService.getByProjectId(projectId);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Commit.class), commits, writer -> writer.withView(CommitImpl.Views.Compact.class)));
return ok(JacksonHelper.collectionToTree(commits, List.class, metamodelProvider.getImplementationClass(Commit.class), Json::mapper, writer -> writer.withView(CommitImpl.Views.Compact.class)));
}

public Result byProjectAndId(UUID projectId, UUID commitId) {
Expand All @@ -70,6 +96,6 @@ public Result byProjectAndId(UUID projectId, UUID commitId) {

public Result headByProject(UUID projectId) {
Optional<Commit> commit = commitService.getHeadByProjectId(projectId);
return commit.map(e -> ok(JacksonHelper.valueToTree(commit, writer -> writer.withView(CommitImpl.Views.Compact.class)))).orElseGet(Results::notFound);
return commit.map(e -> ok(JacksonHelper.objectToTree(commit, Json::mapper, mapper -> mapper.writer().withView(CommitImpl.Views.Compact.class), ObjectMapper::reader))).orElseGet(Results::notFound);
}
}
52 changes: 35 additions & 17 deletions app/controllers/ElementController.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

package controllers;

import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -23,20 +44,18 @@

import static jackson.JsonLdMofObjectAdornment.JSONLD_MIME_TYPE;

/**
* @author Manas Bajaj
* <p>
* Controller for handling all API requests related to SysML v2 elements
*/
public class ElementController extends Controller {
@Inject
private MetamodelProvider metamodelProvider;

@Inject
private ElementService elementService;
private final ElementService elementService;
private final MetamodelProvider metamodelProvider;
private final Environment environment;

@Inject
private Environment environment;
public ElementController(ElementService elementService, MetamodelProvider metamodelProvider, Environment environment) {
this.elementService = elementService;
this.metamodelProvider = metamodelProvider;
this.environment = environment;
}

private static final boolean INLINE_JSON_LD_CONTEXT_DEFAULT = true;
private static final boolean INLINE_JSON_LD_CONTEXT = Optional.ofNullable(System.getenv("INLINE_JSON_LD_CONTEXT"))
Expand All @@ -50,7 +69,7 @@ public Result byId(String id) {

public Result all() {
List<Element> elements = elementService.getAll();
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Element.class), elements));
return ok(JacksonHelper.collectionToTree(elements, List.class, metamodelProvider.getImplementationClass(Element.class)));
}

public Result create(Http.Request request) {
Expand All @@ -74,9 +93,9 @@ public Result getElementsByProjectIdCommitId(UUID projectId, UUID commitId, Http
)
.collect(Collectors.toSet())
)
.map(set -> JacksonHelper.collectionValueToTree(Set.class, respondWithJsonLd ?
.map(set -> JacksonHelper.collectionToTree(set, Set.class, respondWithJsonLd ?
JsonLdMofObjectAdornment.class :
metamodelProvider.getImplementationClass(Element.class), set)
metamodelProvider.getImplementationClass(Element.class))
)
.map(Results::ok)
.map(result -> respondWithJsonLd ? result.as(JSONLD_MIME_TYPE) : result)
Expand Down Expand Up @@ -106,11 +125,10 @@ static JsonLdMofObjectAdornment adornMofObject(MofObject mof, Http.Request reque
public Result getRootsByProjectIdCommitId(UUID projectId, UUID commitId, Http.Request request) {
Set<Element> roots = elementService.getRootsByProjectIdCommitId(projectId, commitId);
boolean respondWithJsonLd = respondWithJsonLd(request);
return ok(JacksonHelper.collectionValueToTree(Set.class,
respondWithJsonLd ? JsonLdMofObjectAdornment.class : metamodelProvider.getImplementationClass(Element.class),
roots.stream()
return ok(JacksonHelper.collectionToTree(roots.stream()
.map(e -> respondWithJsonLd ? adornMofObject(e, request, metamodelProvider, environment, projectId, commitId) : e)
.collect(Collectors.toSet())
.collect(Collectors.toSet()), Set.class,
respondWithJsonLd ? JsonLdMofObjectAdornment.class : metamodelProvider.getImplementationClass(Element.class)
));
}

Expand Down
21 changes: 21 additions & 0 deletions app/controllers/HomeController.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* SysML v2 REST/HTTP Pilot Implementation
* Copyright (C) 2020 InterCAX LLC
* Copyright (C) 2020 California Institute of Technology ("Caltech")
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*/

package controllers;

import play.mvc.*;
Expand Down
Loading

0 comments on commit 3febd23

Please sign in to comment.