Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gomes committed Apr 3, 2020
2 parents 2e2381a + de8b91e commit 6461883
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/CommitController.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public Result byProjectAndId(UUID projectId, UUID commitId) {

public Result headByProject(UUID projectId) {
Optional<Commit> commit = commitService.getHeadByProjectId(projectId);
return commit.map(e -> ok(Json.toJson(e))).orElseGet(Results::notFound);
return commit.map(e -> ok(JacksonHelper.valueToTree(commit, writer -> writer.withView(CommitImpl.Views.Compact.class)))).orElseGet(Results::notFound);
}
}
10 changes: 5 additions & 5 deletions app/dao/impl/jpa/JpaCommitDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected JPAManager getJpaManager() {

@Override
public Optional<Commit> persist(Commit commit) {
// If previousCommit is not specified, default to head commit.
if (commit.getPreviousCommit() == null && commit.getContainingProject() != null) {
findHeadByProject(commit.getContainingProject()).ifPresent(commit::setPreviousCommit);
}

MofObject tombstone = new MofObjectImpl() {
UUID id = UUID.randomUUID();

Expand Down Expand Up @@ -143,11 +148,6 @@ public UUID getId() {
}
});*/

// If previousCommit is not specified, default to head commit.
if (commit.getPreviousCommit() == null && commit.getContainingProject() != null) {
findHeadByProject(commit.getContainingProject()).ifPresent(commit::setPreviousCommit);
}

return jpa.transact(em -> {
commit.getChanges().stream().map(ElementVersion::getData).filter(mof -> mof instanceof MofObjectImpl).map(mof -> (MofObjectImpl) mof).map(mof -> {
try {
Expand Down
8 changes: 8 additions & 0 deletions app/jackson/JacksonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public static JsonNode collectionValueToTree(@SuppressWarnings("rawtypes") Class
throw new RuntimeException(e);
}
}

public static JsonNode valueToTree(Object value, Function<ObjectWriter, ObjectWriter> objectWriterFunction) {
try {
return Json.mapper().readTree(objectWriterFunction.apply(Json.mapper().writer()).writeValueAsBytes(value));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
12 changes: 7 additions & 5 deletions app/jackson/MofObjectDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import javassist.util.proxy.ProxyFactory;
import org.omg.sysml.metamodel.impl.MofObjectImpl;

import javax.persistence.EntityManager;
Expand All @@ -22,7 +23,7 @@ public class MofObjectDeserializer extends StdDeserializer<MofObjectImpl> implem
private EntityManager entityManager;
private JavaType type;

//private static Map<Class<?>, Class<?>> PROXY_MAP = new HashMap<>();
private static Map<Class<?>, Class<?>> PROXY_MAP = new HashMap<>();

public MofObjectDeserializer(EntityManager entityManager) {
this(entityManager, null);
Expand All @@ -45,14 +46,15 @@ public MofObjectImpl deserialize(JsonParser p, DeserializationContext ctxt) thro
}

MofObjectImpl mof;
/* Class<?> proxyClass = PROXY_MAP.computeIfAbsent(type.getRawClass(), clazz -> {
// Proxy class to handle abstract classes
Class<?> proxyClass = PROXY_MAP.computeIfAbsent(type.getRawClass(), clazz -> {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(clazz);
return factory.createClass();
});*/
});
try {
//mof = (MofObjectImpl) proxyClass.getConstructor().newInstance();
mof = (MofObjectImpl) type.getRawClass().getConstructor().newInstance();
mof = (MofObjectImpl) proxyClass.getConstructor().newInstance();
//mof = (MofObjectImpl) type.getRawClass().getConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw new IOException(e);
}
Expand Down
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 := "2020-03-rc2"
version := "2020-03-rc3"

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

Expand Down
1 change: 1 addition & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ play.modules.enabled += "play.modules.swagger.SwaggerModule"
play.filters.headers.contentSecurityPolicy = null
play.filters.disabled+=play.filters.csrf.CSRFFilter
play.http.errorHandler = play.api.http.HtmlOrJsonHttpErrorHandler
play.http.parser.maxMemoryBuffer=1G

# https://www.playframework.com/documentation/2.7.x/JavaJPA
db.default.jndiName=DefaultDS
Expand Down

0 comments on commit 6461883

Please sign in to comment.