diff --git a/dmp-backend/src/main/java/helpers/SerializerProvider.java b/dmp-backend/src/main/java/helpers/SerializerProvider.java index f1bce00a5..22c25dc90 100644 --- a/dmp-backend/src/main/java/helpers/SerializerProvider.java +++ b/dmp-backend/src/main/java/helpers/SerializerProvider.java @@ -1,12 +1,17 @@ package helpers; +import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; +import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature; @@ -52,5 +57,17 @@ public class SerializerProvider { return "["+StringUtils.join(list.toArray(), ",")+"]"; } + public static T fromJson(String jsonObject, Class type) throws Exception { + return getJsonSerializer().readValue(jsonObject, type); + } + + public static T fromJson(String jsonObject, JavaType type) throws Exception { + return getJsonSerializer().readValue(jsonObject, type); + } + + public static T fromJson(String jsonObject, TypeReference type) throws Exception { + return getJsonSerializer().readValue(jsonObject, type); + } + } diff --git a/dmp-backend/src/main/webapp/WEB-INF/dmp.properties b/dmp-backend/src/main/webapp/WEB-INF/dmp.properties deleted file mode 100644 index 743c06c7a..000000000 --- a/dmp-backend/src/main/webapp/WEB-INF/dmp.properties +++ /dev/null @@ -1,48 +0,0 @@ -##########################Security########################################## -#security.portmapping.http = 7081 -#security.portmapping.https = 7444 -##########################/Security######################################## - -##########################Persistence########################################## -persistence.jdbc.driver = org.postgresql.Driver -persistence.jdbc.url = jdbc:postgresql://host:5432/dbname -persistence.dbusername = valid-user -persistence.dbpassword = valid-pass -##########################/Persistence########################################## - -###################Allowed Proxy Service Host ############################ -proxy.allowed.host = https://eestore.paas2.uninett.no -####################################################### - -########################Persistence/Hibernate Generic############################# -persistence.hibernate.show_sql = false -persistence.hibernate.hbm2dll = validate -persistence.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect -#persistence.hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect -########################Persistence/Hibernate Generic############################# - - -########################Persistence/Hibernate/Batch############################## -persistence.hibernate.jdbc.batch_size = 30 -persistence.hibernate.order_inserts = true -persistence.hibernate.order_updates = true -persistence.hibernate.batch_versioned_data = true -persistence.hibernate.jdbc.batch_versioned_data = DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION -########################Persistence/Hibernate/Batch############################## - - -########################Persistence/Hibernate/Connection pool#################### -persistence.hibernate.connectionpool.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider -persistence.hibernate.connectionpool.c3p0.min_size = 5 -persistence.hibernate.connectionpool.c3p0.max_size = 100 -persistence.hibernate.connectionpool.c3p0.timeout = 0 -persistence.hibernate.connectionpool.c3p0.max_statements = 50 -persistence.hibernate.connectionpool.c3p0.acquire_retry_attempts = 30 -persistence.hibernate.connectionpool.c3p0.acquire_retry_delay = 1000 -persistence.hibernate.connectionpool.c3p0.idle_test_period = 3000 -persistence.hibernate.connectionpool.c3p0.break_after_acquire_failure = false -persistence.hibernate.connectionpool.c3p0.idle_connection_test_period = 3600 -persistence.hibernate.connectionpool.c3p0.test_connection_on_checkin = true -persistence.hibernate.connectionpool.c3p0.test_connection_on_checkout = false -persistence.hibernate.connectionpool.c3p0.preferred_test_query = select 1 -########################Persistence/Hibernate/Connection pool#################### \ No newline at end of file diff --git a/dmp-backend/src/test/java/TestRest.java b/dmp-backend/src/test/java/TestRest.java index 823c3ca2d..6c158a42a 100644 --- a/dmp-backend/src/test/java/TestRest.java +++ b/dmp-backend/src/test/java/TestRest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.*; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.junit.Before; @@ -17,6 +18,8 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -36,6 +39,7 @@ import dao.entities.UserInfoDao; import entities.DatasetProfile; import entities.DatasetProfileRuleset; import entities.DatasetProfileViewstyle; +import entities.Project; import entities.Service; import helpers.SerializerProvider; import rest.entities.DMPs; @@ -156,29 +160,37 @@ public class TestRest { -// @Test - public void testProject() { + @Test + public void testUserProject() { // System.out.println(projectsService.listProjects().getBody()); -// System.out.println(dmpsService.listDMPs().getBody()); + +// System.out.println(projectsService.getProjectsOfUser().getBody()); + + CollectionType typeReference = TypeFactory.defaultInstance().constructCollectionType(List.class, Project.class); + List userProjects = null; + try { + userProjects = SerializerProvider.fromJson(projectsService.getProjectsOfUser().getBody().toString(), typeReference) ; + } catch (Exception e) { + fail("Should not have thrown any exception"); + } + + assertNotNull(userProjects); + System.out.println(userProjects.size()); + + System.out.println(SerializerProvider.toJson(userProjects)); + - System.out.println(projectsService.getProjectsOfUser().getBody()); assertEquals("aaa", "aaa"); } - @Test +// @Test public void testDmpUser() { System.out.println(dmpsService.getDmpsOfUser().getBody()); - -// System.out.println(projectsService.listProjects().getBody()); -// System.out.println(dmpsService.listDMPs().getBody()); - - - assertEquals("aaa", "aaa");