Skip to content

Commit

Permalink
Merge branch 'release/2020-03-rc1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gomes committed Mar 11, 2020
2 parents 6fd7f62 + 5c35907 commit 7529ba2
Show file tree
Hide file tree
Showing 56 changed files with 1,411 additions and 596 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
logs
target
/.bloop
/.idea
/.idea_modules
/.classpath
Expand Down
3 changes: 3 additions & 0 deletions app/Module.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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;
Expand All @@ -22,5 +24,6 @@ protected void configure() {
bind(ElementDao.class).to(JpaElementDao.class);
bind(ProjectDao.class).to(JpaProjectDao.class);
bind(RelationshipDao.class).to(JpaRelationshipDao.class);
bind(CommitDao.class).to(JpaCommitDao.class);
}
}
4 changes: 2 additions & 2 deletions app/config/impl/JPAMetamodelProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class JPAMetamodelProvider implements MetamodelProvider {

static {
INTERFACES.add(MofObject.class);
for (String pakkage : new String[]{"org.omg.sysml.metamodel", "org.omg.sysml.extension"}) {
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"}) {
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));
}
}
Expand Down
75 changes: 75 additions & 0 deletions app/controllers/CommitController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import config.MetamodelProvider;
import jackson.JacksonHelper;
import org.omg.sysml.lifecycle.Commit;
import org.omg.sysml.lifecycle.impl.CommitImpl;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import play.mvc.Results;
import services.CommitService;

import javax.inject.Inject;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

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

@Inject
private CommitService commitService;

public Result byId(String id) {
UUID uuid = UUID.fromString(id);
Optional<Commit> commit = commitService.getById(uuid);
return commit.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
}

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

public Result create(Http.Request request) {
JsonNode requestBodyJson = request.body().asJson();
Commit requestedObject = Json.fromJson(requestBodyJson, metamodelProvider.getImplementationClass(Commit.class));
if (requestedObject.getId() != null || requestedObject.getTimestamp() != null) {
return Results.badRequest();
}
requestedObject.setTimestamp(ZonedDateTime.now());
Optional<Commit> responseCommit = commitService.create(requestedObject);
return responseCommit.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
}

public Result createWithProjectId(UUID projectId, Http.Request request) {
JsonNode requestBodyJson = request.body().asJson();
Commit requestedObject = Json.fromJson(requestBodyJson, metamodelProvider.getImplementationClass(Commit.class));
if (requestedObject.getId() != null || requestedObject.getTimestamp() != null) {
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);
}

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)));
}

public Result byProjectAndId(UUID projectId, UUID commitId) {
Optional<Commit> commit = commitService.getByProjectIdAndId(projectId, commitId);
return commit.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
}

public Result headByProject(UUID projectId) {
Optional<Commit> commit = commitService.getHeadByProjectId(projectId);
return commit.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
}
}
27 changes: 19 additions & 8 deletions app/controllers/ElementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.inject.Inject;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

/**
Expand Down Expand Up @@ -47,19 +48,29 @@ public Result create(Http.Request request) {
return Results.badRequest();
}
Optional<Element> responseElement = elementService.create(((Element) requestedObject));
return responseElement.map(e -> created(Json.toJson(e))).orElseGet(Results::badRequest);
return responseElement.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
}

public Result byProject(String projectId) {
UUID projectUuid = UUID.fromString(projectId);
List<Element> elements = elementService.getByProjectId(projectUuid);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Element.class), elements));
public Result byCommit(String commitId) {
UUID commitUuid = UUID.fromString(commitId);
Set<Element> elements = elementService.getByCommitId(commitUuid);
return ok(JacksonHelper.collectionValueToTree(Set.class, metamodelProvider.getImplementationClass(Element.class), elements));
}

public Result byProjectAndId(String elementId, String projectId) {
public Result byCommitAndId(String commitId, String elementId) {
UUID commitUuid = UUID.fromString(commitId);
UUID elementUuid = UUID.fromString(elementId);
UUID projectUuid = UUID.fromString(projectId);
Optional<Element> element = elementService.getByProjectIdAndId(projectUuid, elementUuid);
Optional<Element> element = elementService.getByCommitIdAndId(commitUuid, elementUuid);
return element.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
}

public Result getElementsByProjectIdCommitId(UUID projectId, UUID commitId) {
Set<Element> elements = elementService.getElementsByProjectIdCommitId(projectId, commitId);
return ok(JacksonHelper.collectionValueToTree(Set.class, metamodelProvider.getImplementationClass(Element.class), elements));
}

public Result getElementByProjectIdCommitIdElementId(UUID projectId, UUID commitId, UUID elementId) {
Optional<Element> element = elementService.getElementsByProjectIdCommitIdElementId(projectId, commitId, elementId);
return element.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
}
}
9 changes: 4 additions & 5 deletions app/controllers/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import config.MetamodelProvider;
import jackson.JacksonHelper;
import org.omg.sysml.extension.Project;
import org.omg.sysml.lifecycle.Project;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Http;
Expand All @@ -28,9 +28,8 @@ public class ProjectController extends Controller {
@Inject
private ProjectService projectService;

public Result byId(String id) {
UUID uuid = UUID.fromString(id);
Optional<Project> project = projectService.getById(uuid);
public Result byId(UUID id) {
Optional<Project> project = projectService.getById(id);
return project.map(m -> ok(Json.toJson(m))).orElseGet(Results::notFound);
}

Expand All @@ -43,6 +42,6 @@ public Result create(Http.Request request) {
JsonNode requestBodyJson = request.body().asJson();
Project requestProject = Json.fromJson(requestBodyJson, metamodelProvider.getImplementationClass(Project.class));
Optional<Project> responseProject = projectService.create(requestProject);
return responseProject.map(e -> created(Json.toJson(e))).orElseGet(Results::badRequest);
return responseProject.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
}
}
29 changes: 6 additions & 23 deletions app/controllers/RelationshipController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.inject.Inject;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

/**
Expand Down Expand Up @@ -47,30 +48,12 @@ public Result create(Http.Request request) {
return Results.badRequest();
}
Optional<Relationship> responseRelationship = relationshipService.create((Relationship) requestedObject);
return responseRelationship.map(e -> created(Json.toJson(e))).orElseGet(Results::badRequest);
return responseRelationship.map(e -> created(Json.toJson(e))).orElseGet(Results::internalServerError);
}

public Result byRelatedElementId(String id) {
UUID elementUuid = UUID.fromString(id);
List<Relationship> relationships = relationshipService.getByRelatedElementId(elementUuid);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Relationship.class), relationships));
}

public Result bySourceElementId(String id) {
UUID elementUuid = UUID.fromString(id);
List<Relationship> relationships = relationshipService.getBySourceElementId(elementUuid);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Relationship.class), relationships));
}

public Result byTargetElementId(String id) {
UUID elementUuid = UUID.fromString(id);
List<Relationship> relationships = relationshipService.getByTargetElementId(elementUuid);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Relationship.class), relationships));
}

public Result byProject(String projectId) {
UUID projectUuid = UUID.fromString(projectId);
List<Relationship> relationships = relationshipService.getByProjectId(projectUuid);
return ok(JacksonHelper.collectionValueToTree(List.class, metamodelProvider.getImplementationClass(Relationship.class), relationships));
public Result getRelationshipsByProjectIdCommitIdRelatedElementId(UUID projectId, UUID commitId, UUID elementId) {
System.out.println(projectId + " : " + commitId + " : " + elementId);
Set<Relationship> relationships = relationshipService.getRelationshipsByProjectCommitRelatedElement(projectId, commitId, elementId);
return ok(JacksonHelper.collectionValueToTree(Set.class, metamodelProvider.getImplementationClass(Relationship.class), relationships));
}
}
28 changes: 28 additions & 0 deletions app/dao/CommitDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dao;

import org.omg.sysml.lifecycle.Project;
import org.omg.sysml.lifecycle.Commit;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface CommitDao extends Dao<Commit> {
Optional<Commit> persist(Commit commit);

Optional<Commit> update(Commit commit);

Optional<Commit> findById(UUID id);

List<Commit> findAll();

void delete(Commit commit);

void deleteAll();

List<Commit> findAllByProject(Project project);

Optional<Commit> findByProjectAndId(Project project, UUID id);

Optional<Commit> findHeadByProject(Project project);
}
13 changes: 7 additions & 6 deletions app/dao/ElementDao.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package dao;

import org.omg.sysml.extension.Project;
import org.omg.sysml.lifecycle.Commit;
import org.omg.sysml.metamodel.Element;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

public interface ElementDao extends Dao<Element> {
Optional<Element> persist(Element Element);
Optional<Element> persist(Element element);

Optional<Element> update(Element entity);
Optional<Element> update(Element element);

Optional<Element> findById(UUID id);

List<Element> findAll();

void delete(Element Element);
void delete(Element element);

void deleteAll();

List<Element> findAllByProject(Project project);
Set<Element> findAllByCommit(Commit commit);

Optional<Element> findByProjectAndId(Project project, UUID id);
Optional<Element> findByCommitAndId(Commit commit, UUID id);
}
8 changes: 4 additions & 4 deletions app/dao/ProjectDao.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package dao;

import org.omg.sysml.extension.Project;
import org.omg.sysml.lifecycle.Project;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface ProjectDao extends Dao<Project> {
Optional<Project> persist(Project Project);
Optional<Project> persist(Project project);

Optional<Project> update(Project entity);
Optional<Project> update(Project project);

Optional<Project> findById(UUID id);

List<Project> findAll();

void delete(Project Project);
void delete(Project project);

void deleteAll();
}
18 changes: 7 additions & 11 deletions app/dao/RelationshipDao.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package dao;

import org.omg.sysml.lifecycle.Commit;
import org.omg.sysml.lifecycle.Project;
import org.omg.sysml.metamodel.Element;
import org.omg.sysml.extension.Project;
import org.omg.sysml.metamodel.Relationship;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

public interface RelationshipDao extends Dao<Relationship> {
Optional<Relationship> persist(Relationship Relationship);
Optional<Relationship> persist(Relationship relationship);

Optional<Relationship> update(Relationship entity);
Optional<Relationship> update(Relationship relationship);

Optional<Relationship> findById(UUID id);

List<Relationship> findAll();

void delete(Relationship Relationship);
void delete(Relationship relationship);

void deleteAll();

List<Relationship> findAllByRelatedElement(Element element);

List<Relationship> findAllBySourceElement(Element element);

List<Relationship> findAllByTargetElement(Element element);

List<Relationship> findAllByProject(Project project);
Set<Relationship> findAllByCommitRelatedElement(Commit commit, Element relatedElement);
}
Loading

0 comments on commit 7529ba2

Please sign in to comment.