Compare commits
52 Commits
11
.classpath
11
.classpath
|
@ -20,16 +20,15 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/OpenJDK-11">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="module" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId"/>
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
|
<wb-module deploy-name="social-networking-library-ws-3.0.0-SNAPSHOT">
|
||||||
|
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||||
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
|
<property name="context-root" value="social-networking-library-ws"/>
|
||||||
|
<property name="java-output-path" value="/social-networking-library-ws/target/classes"/>
|
||||||
|
</wb-module>
|
||||||
|
</project-modules>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<faceted-project>
|
<faceted-project>
|
||||||
<fixed facet="wst.jsdt.web"/>
|
<fixed facet="wst.jsdt.web"/>
|
||||||
<installed facet="jst.web" version="3.0"/>
|
|
||||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
|
||||||
<installed facet="jst.jaxrs" version="1.1"/>
|
|
||||||
<installed facet="java" version="1.8"/>
|
<installed facet="java" version="1.8"/>
|
||||||
|
<installed facet="jst.web" version="3.0"/>
|
||||||
|
<installed facet="jst.jaxrs" version="2.1"/>
|
||||||
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
</faceted-project>
|
</faceted-project>
|
||||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,5 +1,21 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [v3.0.1] - 2023-04-22
|
||||||
|
|
||||||
|
- Feature 27286: removed noisy logs
|
||||||
|
- Bug 27218: advance social networking library version
|
||||||
|
|
||||||
|
## [v3.0.0-SNAPSHOT] - 2023-12-06
|
||||||
|
|
||||||
|
- Feature #26193, new impl for get users by role in a VRE
|
||||||
|
- Replace Astyanx Java client for Cassandra 2 with Datastax client for Cassandra 4
|
||||||
|
- Add REST resources for all the functions in social networking library
|
||||||
|
|
||||||
|
## [v2.9.1] - 2023-09-28
|
||||||
|
|
||||||
|
- Fix for Bug #25760 not closing connection to distributed cached
|
||||||
|
- Removed memcached dep
|
||||||
|
|
||||||
## [v2.9.0] - 2023-02-13
|
## [v2.9.0] - 2023-02-13
|
||||||
|
|
||||||
- Feature #24456 social-networking rest api endpoints (comments, Likes, GetPost)
|
- Feature #24456 social-networking rest api endpoints (comments, Likes, GetPost)
|
||||||
|
|
|
@ -22,10 +22,12 @@ See [Releases](https://code-repo.d4science.org/gCubeSystem/social-networking-lib
|
||||||
|
|
||||||
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
|
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
|
||||||
* **Costantino Perciante**
|
* **Costantino Perciante**
|
||||||
|
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
|
||||||
|
|
||||||
## Maintainers
|
## Maintainers
|
||||||
|
|
||||||
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
|
* **Massimiliano Assante** ([ORCID](https://orcid.org/0000-0002-3761-1492)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/People/M.Assante)
|
||||||
|
* **Ahmed Ibrahim** ([ORCID](https://orcid.org/0009-0001-3009-5755)) - [ISTI-CNR Infrascience Group](https://www.isti.cnr.it/en/about/people-detail/976/Ahmed_Salah_Tawfik_Ibrahim)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -38,4 +40,4 @@ open-source software toolkit used for building and operating Hybrid Data
|
||||||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||||
by favouring the realisation of reuse oriented policies.
|
by favouring the realisation of reuse oriented policies.
|
||||||
|
|
||||||
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
|
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
|
||||||
|
|
216
pom.xml
216
pom.xml
|
@ -6,28 +6,31 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>social-networking-library-ws</artifactId>
|
<artifactId>social-networking-library-ws</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>2.9.0</version>
|
<version>3.0.1</version>
|
||||||
<name>social-networking-library-ws</name>
|
<name>social-networking-library-ws</name>
|
||||||
<description>Rest interface for the social networking library.</description>
|
<description>Rest interface for the social networking library.</description>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<enunciate.version>2.14.0</enunciate.version>
|
<enunciate.version>2.14.0</enunciate.version>
|
||||||
<jackson.version>2.8.11</jackson.version>
|
<cassandra.driver.oss.version>4.13.0</cassandra.driver.oss.version>
|
||||||
|
<jackson.version>2.12.6</jackson.version>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
<connection>
|
||||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||||
|
<developerConnection>
|
||||||
|
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
@ -79,11 +82,6 @@
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
<version>2.10.0</version>
|
<version>2.10.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.spy</groupId>
|
|
||||||
<artifactId>spymemcached</artifactId>
|
|
||||||
<version>2.12.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-control-library</artifactId>
|
<artifactId>authorization-control-library</artifactId>
|
||||||
|
@ -98,7 +96,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>storagehub-client-library</artifactId>
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
<!-- <version>2.0.0-SNAPSHOT</version> -->
|
<!-- <version>2.0.0-SNAPSHOT</version> -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>com.sun.mail</groupId>
|
||||||
|
@ -129,58 +127,6 @@
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.netflix.astyanax</groupId>
|
|
||||||
<artifactId>astyanax</artifactId>
|
|
||||||
<version>2.0.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>jersey-client</artifactId>
|
|
||||||
<groupId>com.sun.jersey</groupId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>jersey-bundle</artifactId>
|
|
||||||
<groupId>com.sun.jersey</groupId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>jersey-apache-client4</artifactId>
|
|
||||||
<groupId>com.sun.jersey.contribs</groupId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.ws.rs</groupId>
|
|
||||||
<artifactId>jsr311-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.mortbay.jetty</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.netflix.astyanax</groupId>
|
|
||||||
<artifactId>astyanax-thrift</artifactId>
|
|
||||||
<version>2.0.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.netflix.astyanax</groupId>
|
|
||||||
<artifactId>astyanax-cassandra</artifactId>
|
|
||||||
<version>2.0.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.netflix.astyanax</groupId>
|
|
||||||
<artifactId>astyanax-core</artifactId>
|
|
||||||
<version>2.0.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.socialnetworking</groupId>
|
<groupId>org.gcube.socialnetworking</groupId>
|
||||||
<artifactId>social-util-library</artifactId>
|
<artifactId>social-util-library</artifactId>
|
||||||
|
@ -190,7 +136,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.portal</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>social-networking-library</artifactId>
|
<artifactId>social-networking-library</artifactId>
|
||||||
<version>[1.18.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[2.0.0, 3.0.0)</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -232,26 +178,78 @@
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-admin-client</artifactId>
|
||||||
|
<version>21.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-annotations</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
|
||||||
<version>2.8.6</version>
|
<version>2.8.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
<artifactId>jackson-dataformat-smile</artifactId>
|
<artifactId>jackson-dataformat-smile</artifactId>
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
|
||||||
<version>2.8.6</version>
|
<version>2.8.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<artifactId>jackson-dataformat-cbor</artifactId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.8.6</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Please note that the elasticsearch client needs a compress-lzf version
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-cbor</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- needed by the search-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
<version>1.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-core-asl</artifactId>
|
||||||
|
<version>1.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.datastax.oss</groupId>
|
||||||
|
<artifactId>java-driver-query-builder</artifactId>
|
||||||
|
<version>${cassandra.driver.oss.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.datastax.oss</groupId>
|
||||||
|
<artifactId>java-driver-mapper-runtime</artifactId>
|
||||||
|
<version>${cassandra.driver.oss.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google</groupId>
|
||||||
|
<artifactId>gwt-jsonmaker</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Please note that the elasticsearch client needs a compress-lzf
|
||||||
|
version
|
||||||
>= 1.0.2 -->
|
>= 1.0.2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ning</groupId>
|
<groupId>com.ning</groupId>
|
||||||
|
@ -261,7 +259,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
|
<!-- if your container implements Servlet API older than 3.0, use
|
||||||
|
"jersey-container-servlet-core" -->
|
||||||
<artifactId>jersey-container-servlet-core</artifactId>
|
<artifactId>jersey-container-servlet-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -314,47 +313,30 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>4.3</version>
|
<version>4.5.3</version>
|
||||||
<scope>compile</scope>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mortbay.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>6.1.22</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>aspectj-maven-plugin</artifactId>
|
|
||||||
<version>1.14.0</version>
|
|
||||||
<configuration>
|
|
||||||
<complianceLevel>1.8</complianceLevel>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<aspectLibraries>
|
|
||||||
<aspectLibrary>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>authorization-control-library</artifactId>
|
|
||||||
</aspectLibrary>
|
|
||||||
</aspectLibraries>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>compile</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</pluginManagement>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>kr.motd.maven</groupId>
|
<groupId>kr.motd.maven</groupId>
|
||||||
<artifactId>sphinx-maven-plugin</artifactId>
|
<artifactId>sphinx-maven-plugin</artifactId>
|
||||||
<version>2.10.0</version>
|
<version>2.10.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
|
<outputDirectory>
|
||||||
|
${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
|
||||||
<builder>html</builder>
|
<builder>html</builder>
|
||||||
<configDirectory>${basedir}/docs</configDirectory>
|
<configDirectory>${basedir}/docs</configDirectory>
|
||||||
<sourceDirectory>${basedir}/docs</sourceDirectory>
|
<sourceDirectory>${basedir}/docs</sourceDirectory>
|
||||||
|
@ -376,7 +358,8 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<sourcepath-includes>
|
<sourcepath-includes>
|
||||||
<sourcepath-include>
|
<sourcepath-include>
|
||||||
<!-- Include the "com.external:external" artifact on the sourcepath. -->
|
<!-- Include the "com.external:external" artifact on
|
||||||
|
the sourcepath. -->
|
||||||
<groupId>org.gcube.social-networking</groupId>
|
<groupId>org.gcube.social-networking</groupId>
|
||||||
<artifactId>social-service-model</artifactId>
|
<artifactId>social-service-model</artifactId>
|
||||||
</sourcepath-include>
|
</sourcepath-include>
|
||||||
|
@ -399,7 +382,8 @@
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>aspectj-maven-plugin</artifactId>
|
<artifactId>aspectj-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Copy Enunciate Documentation from your-application/docs to your-application.war -->
|
<!-- Copy Enunciate Documentation from your-application/docs to
|
||||||
|
your-application.war -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
@ -415,8 +399,10 @@
|
||||||
<outputDirectory>target</outputDirectory>
|
<outputDirectory>target</outputDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<targetPath>${project.build.directory}/${project.artifactId}-${project.version}/api-docs</targetPath>
|
<targetPath>
|
||||||
<directory>${project.build.directory}/api-docs</directory>
|
${project.build.directory}/${project.artifactId}-${project.version}/api-docs</targetPath>
|
||||||
|
<directory>
|
||||||
|
${project.build.directory}/api-docs</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -424,24 +410,6 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<additionalparam>-Xdoclint:none</additionalparam>
|
|
||||||
<additionalJOption>-Xdoclint:none</additionalJOption>
|
|
||||||
</configuration>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>generate-doc</id>
|
|
||||||
<phase>install</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -16,7 +16,7 @@ public class GroupsCache {
|
||||||
*/
|
*/
|
||||||
private GroupsCache(){
|
private GroupsCache(){
|
||||||
|
|
||||||
logger.info("Building cache");
|
logger.debug("Building cache");
|
||||||
CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class GroupsCache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an entry
|
* Retrieve an entry
|
||||||
* @param id
|
* @param groupId
|
||||||
* @return user associated to the user
|
* @return user associated to the user
|
||||||
*/
|
*/
|
||||||
public GCubeGroup getGroup(long groupId){
|
public GCubeGroup getGroup(long groupId){
|
||||||
|
@ -44,7 +44,7 @@ public class GroupsCache {
|
||||||
/**
|
/**
|
||||||
* Save an entry into the cache
|
* Save an entry into the cache
|
||||||
* @param id
|
* @param id
|
||||||
* @param user
|
* @param group
|
||||||
*/
|
*/
|
||||||
public void pushEntry(long id, GCubeGroup group){
|
public void pushEntry(long id, GCubeGroup group){
|
||||||
Ehcache groupsCache = CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
Ehcache groupsCache = CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class SocialNetworkingSiteFinder {
|
||||||
|
|
||||||
// read fallback properties
|
// read fallback properties
|
||||||
try{
|
try{
|
||||||
logger.info("Trying to read config.properties");
|
logger.debug("Trying to read config.properties");
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
InputStream input = classLoader.getResourceAsStream("config.properties");
|
InputStream input = classLoader.getResourceAsStream("config.properties");
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
@ -90,11 +90,11 @@ public class SocialNetworkingSiteFinder {
|
||||||
if(scope == null || scope.isEmpty())
|
if(scope == null || scope.isEmpty())
|
||||||
throw new IllegalArgumentException("Scope cannot be null/empty");
|
throw new IllegalArgumentException("Scope cannot be null/empty");
|
||||||
|
|
||||||
if(socialSitesCache.get(scope) != null)
|
if(socialSitesCache != null && socialSitesCache.get(scope) != null)
|
||||||
return (SocialNetworkingSite) socialSitesCache.get(scope).getObjectValue();
|
return (SocialNetworkingSite) socialSitesCache.get(scope).getObjectValue();
|
||||||
else{
|
else{
|
||||||
SocialNetworkingSite site = discoverSite(scope);
|
SocialNetworkingSite site = discoverSite(scope);
|
||||||
if(site != null)
|
if(socialSitesCache != null && site != null)
|
||||||
socialSitesCache.put(new Element(scope, site));
|
socialSitesCache.put(new Element(scope, site));
|
||||||
return site;
|
return site;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class SocialNetworkingSiteFinder {
|
||||||
if(gatewayVirtualGroups != null && !gatewayVirtualGroups.isEmpty()){
|
if(gatewayVirtualGroups != null && !gatewayVirtualGroups.isEmpty()){
|
||||||
for (VirtualGroup gatewayVirtualGroup : gatewayVirtualGroups) {
|
for (VirtualGroup gatewayVirtualGroup : gatewayVirtualGroups) {
|
||||||
if(virtualGroupsOfGroup.contains(gatewayVirtualGroup)){
|
if(virtualGroupsOfGroup.contains(gatewayVirtualGroup)){
|
||||||
logger.info("Matching gateway for scope " + scope + " is " + gateway);
|
logger.debug("Matching gateway for scope " + scope + " is " + gateway);
|
||||||
matchingGateway = gateway;
|
matchingGateway = gateway;
|
||||||
break ext_loop;
|
break ext_loop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class UsersCache{
|
||||||
new Thread(){
|
new Thread(){
|
||||||
public void run() {
|
public void run() {
|
||||||
try{
|
try{
|
||||||
logger.info("Fetching users and putting them into cache");
|
logger.debug("Fetching users and putting them into cache");
|
||||||
Ehcache usersCache = CachesManager.getCache(CachesManager.USERS_CACHE);
|
Ehcache usersCache = CachesManager.getCache(CachesManager.USERS_CACHE);
|
||||||
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
@ -59,7 +59,7 @@ public class UsersCache{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an entry
|
* Retrieve an entry
|
||||||
* @param id
|
* @param userId
|
||||||
* @return user associated to the user
|
* @return user associated to the user
|
||||||
*/
|
*/
|
||||||
public GCubeUser getUser(long userId){
|
public GCubeUser getUser(long userId){
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class GroupManagerWSBuilder {
|
||||||
|
|
||||||
private GroupManagerWSBuilder(){
|
private GroupManagerWSBuilder(){
|
||||||
|
|
||||||
logger.info("Building GroupManager please wait");
|
logger.debug("Building GroupManager please wait");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
groupManagerWs = new LiferayWSGroupManager(
|
groupManagerWs = new LiferayWSGroupManager(
|
||||||
|
@ -31,7 +31,7 @@ public class GroupManagerWSBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("GroupManager instance built");
|
logger.debug("GroupManager instance built");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
package org.gcube.portal.social.networking.liferay.ws;
|
||||||
|
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class KeycloakAPICredentials {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(KeycloakAPICredentials.class);
|
||||||
|
|
||||||
|
// the singleton obj
|
||||||
|
private static KeycloakAPICredentials singleton = new KeycloakAPICredentials();
|
||||||
|
|
||||||
|
// properties that it contains
|
||||||
|
private String keycloakURL;
|
||||||
|
private String realm;
|
||||||
|
private String clientid;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
// Service endpoint properties
|
||||||
|
private final static String RUNTIME_RESOURCE_NAME = "IAM";
|
||||||
|
private final static String CATEGORY = "Service";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor
|
||||||
|
*/
|
||||||
|
private KeycloakAPICredentials() {
|
||||||
|
logger.debug("Building KeycloakAPICredentials object");
|
||||||
|
|
||||||
|
lookupPropertiesFromIs();
|
||||||
|
logger.debug("KeycloakAPICredentials object built");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the properties from the infrastructure
|
||||||
|
*/
|
||||||
|
private void lookupPropertiesFromIs() {
|
||||||
|
|
||||||
|
logger.debug("Starting creating KeycloakAPICredentials");
|
||||||
|
|
||||||
|
String oldContext = ScopeProvider.instance.get();
|
||||||
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
ScopeProvider.instance.set("/"+ctx.container().configuration().infrastructure());
|
||||||
|
logger.debug("Discovering liferay user's credentials in context " + ctx.container().configuration().infrastructure());
|
||||||
|
|
||||||
|
try{
|
||||||
|
List<ServiceEndpoint> resources = getConfigurationFromIS();
|
||||||
|
if (resources.size() == 0){
|
||||||
|
logger.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope.");
|
||||||
|
throw new Exception("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (ServiceEndpoint res : resources) {
|
||||||
|
Iterator<AccessPoint> accessPointIterator = res.profile().accessPoints().iterator();
|
||||||
|
while (accessPointIterator.hasNext()) {
|
||||||
|
ServiceEndpoint.AccessPoint accessPoint = (ServiceEndpoint.AccessPoint) accessPointIterator
|
||||||
|
.next();
|
||||||
|
|
||||||
|
if(accessPoint.name().equals("d4science")){
|
||||||
|
keycloakURL = accessPoint.address();
|
||||||
|
realm = accessPoint.name();
|
||||||
|
clientid = accessPoint.username();
|
||||||
|
password = StringEncrypter.getEncrypter().decrypt(accessPoint.password());
|
||||||
|
logger.info("Found accesspoint URL = " + keycloakURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such service endpoint information!", e);
|
||||||
|
return;
|
||||||
|
}finally{
|
||||||
|
if(oldContext != null)
|
||||||
|
ScopeProvider.instance.set(oldContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Bean built " + toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve endpoints information from IS for DB
|
||||||
|
* @return list of endpoints for ckan database
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private List<ServiceEndpoint> getConfigurationFromIS() throws Exception{
|
||||||
|
|
||||||
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
|
||||||
|
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
|
||||||
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
|
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
|
return toReturn;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static KeycloakAPICredentials getSingleton() {
|
||||||
|
if (singleton == null)
|
||||||
|
singleton = new KeycloakAPICredentials();
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerURL() {
|
||||||
|
return keycloakURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientid() {
|
||||||
|
return clientid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRealm() {
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "KeycloakAPICredentials [keycloakURL=" + keycloakURL + ", realm=" + realm + ", clientid=" + clientid
|
||||||
|
+ ", password=**************]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
|
@ -52,10 +52,10 @@ public class LiferayJSONWsCredentials {
|
||||||
* Private constructor
|
* Private constructor
|
||||||
*/
|
*/
|
||||||
private LiferayJSONWsCredentials() {
|
private LiferayJSONWsCredentials() {
|
||||||
logger.info("Building LiferayJSONWsCredentials object");
|
logger.debug("Building LiferayJSONWsCredentials object");
|
||||||
loadNotifierToken();
|
loadNotifierToken();
|
||||||
lookupPropertiesFromIs();
|
lookupPropertiesFromIs();
|
||||||
logger.info("LiferayJSONWsCredentials object built");
|
logger.debug("LiferayJSONWsCredentials object built");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ public class LiferayJSONWsCredentials {
|
||||||
*/
|
*/
|
||||||
private void lookupPropertiesFromIs() {
|
private void lookupPropertiesFromIs() {
|
||||||
|
|
||||||
logger.info("Starting creating LiferayJSONWsCredentials");
|
logger.debug("Starting creating LiferayJSONWsCredentials");
|
||||||
|
|
||||||
String oldContext = ScopeProvider.instance.get();
|
String oldContext = ScopeProvider.instance.get();
|
||||||
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
@ -118,7 +118,7 @@ public class LiferayJSONWsCredentials {
|
||||||
ScopeProvider.instance.set(oldContext);
|
ScopeProvider.instance.set(oldContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Bean built " + toString());
|
logger.debug("Bean built " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class RoleManagerWSBuilder {
|
||||||
|
|
||||||
private RoleManagerWSBuilder(){
|
private RoleManagerWSBuilder(){
|
||||||
|
|
||||||
logger.info("Building UserManager please wait");
|
logger.debug("Building UserManager please wait");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
roleManagerWs = new LiferayWSRoleManager(
|
roleManagerWs = new LiferayWSRoleManager(
|
||||||
|
@ -31,7 +31,7 @@ public class RoleManagerWSBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("UserManager instance built");
|
logger.debug("UserManager instance built");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class UserManagerWSBuilder {
|
||||||
|
|
||||||
private UserManagerWSBuilder(){
|
private UserManagerWSBuilder(){
|
||||||
|
|
||||||
logger.info("Building UserManager please wait");
|
logger.debug("Building UserManager please wait");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
userManagerWs = new LiferayWSUserManager(
|
userManagerWs = new LiferayWSUserManager(
|
||||||
|
@ -31,7 +31,7 @@ public class UserManagerWSBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("UserManager instance built");
|
logger.debug("UserManager instance built");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when @Valid fail
|
* Exception gets thrown when @Valid fail
|
||||||
*/
|
*/
|
||||||
@Provider
|
@Provider
|
||||||
public class ApplicationException implements ExceptionMapper<Exception> {
|
public class ApplicationException implements ExceptionMapper<Exception> {
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class CommentInputBean implements Serializable{
|
||||||
/**
|
/**
|
||||||
* @param text
|
* @param text
|
||||||
* @param postid
|
* @param postid
|
||||||
* @param params
|
*/
|
||||||
*/
|
|
||||||
public CommentInputBean(String text, String postid) {
|
public CommentInputBean(String text, String postid) {
|
||||||
super();
|
super();
|
||||||
this.text = text;
|
this.text = text;
|
||||||
|
|
|
@ -46,11 +46,12 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST interface for the social networking library (comments).
|
* REST interface for the social networking library (comments).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Path("2/comments")
|
@Path("2/comments")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Comments {
|
public class Comments {
|
||||||
|
|
||||||
|
@ -59,20 +60,20 @@ public class Comments {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the list of comments belonging to the post id (key) of the token in the related context
|
* Retrieve the list of comments belonging to the post id (key) of the token in the related context
|
||||||
* @param key the key as in the POST JSON representation
|
* @param key the key as in the POST JSON representation
|
||||||
* @pathExample /get-comments-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
* @pathExample /get-comments-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
||||||
* @return the list of comments belonging to the post identified by the key in the context identified by the token
|
* @return the list of comments belonging to the post identified by the key in the context identified by the token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-by-post-id")
|
@Path("get-comments-by-post-id")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllCommentsByPostId(
|
public Response getAllCommentsByPostId(
|
||||||
@NotNull
|
@NotNull
|
||||||
@QueryParam("key")
|
@QueryParam("key")
|
||||||
String key) {
|
String key) {
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
@ -83,7 +84,7 @@ public class Comments {
|
||||||
List<Comment> comments = null;
|
List<Comment> comments = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving comments for user id " + username);
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
comments = CassandraConnection.getInstance().getDatabookStore().getAllCommentByPost(key);
|
comments = CassandraConnection.getInstance().getDatabookStore().getAllCommentByPost(key);
|
||||||
Filters.filterCommentsPerContext(comments, context);
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
responseBean.setResult(comments);
|
responseBean.setResult(comments);
|
||||||
|
@ -105,8 +106,8 @@ public class Comments {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-user")
|
@Path("get-comments-user")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getCommentsUser() {
|
public Response getCommentsUser() {
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ public class Comments {
|
||||||
List<Comment> comments = null;
|
List<Comment> comments = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving comments for user id " + username);
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, 0);
|
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, 0);
|
||||||
Filters.filterCommentsPerContext(comments, context);
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
responseBean.setResult(comments);
|
responseBean.setResult(comments);
|
||||||
|
@ -140,10 +141,10 @@ public class Comments {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-comments-user-by-time")
|
@Path("get-comments-user-by-time")
|
||||||
public Response getCommentsUserByTime(
|
public Response getCommentsUserByTime(
|
||||||
@QueryParam("time")
|
@QueryParam("time")
|
||||||
@Min(value = 0, message="time cannot be negative")
|
@Min(value = 0, message="time cannot be negative")
|
||||||
long timeInMillis
|
long timeInMillis
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -153,7 +154,7 @@ public class Comments {
|
||||||
List<Comment> comments = null;
|
List<Comment> comments = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving comments for user id " + username);
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, timeInMillis);
|
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, timeInMillis);
|
||||||
Filters.filterCommentsPerContext(comments, context);
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
responseBean.setResult(comments);
|
responseBean.setResult(comments);
|
||||||
|
@ -179,12 +180,12 @@ public class Comments {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successfull created, the new comment is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successfull created, the new comment is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writeComment(
|
public Response writeComment(
|
||||||
@NotNull(message="Comment to write is missing")
|
@NotNull(message="Comment to write is missing")
|
||||||
@Valid
|
@Valid
|
||||||
CommentInputBean comment) throws ValidationException {
|
CommentInputBean comment) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -202,7 +203,7 @@ public class Comments {
|
||||||
String postOwnerId = CassandraConnection.getInstance().getDatabookStore().readPost(postId).getEntityId();
|
String postOwnerId = CassandraConnection.getInstance().getDatabookStore().readPost(postId).getEntityId();
|
||||||
Comment theComment = SocialUtils.commentPost(userid, time, postId, commentText, postOwnerId, context);
|
Comment theComment = SocialUtils.commentPost(userid, time, postId, commentText, postOwnerId, context);
|
||||||
if (theComment != null)
|
if (theComment != null)
|
||||||
logger.info("Added comment " + theComment.toString());
|
logger.debug("Added comment " + theComment.toString());
|
||||||
else {
|
else {
|
||||||
logger.error("Unable to write comment");
|
logger.error("Unable to write comment");
|
||||||
responseBean.setMessage("Unable to write comment, something went wrong please see server log");
|
responseBean.setMessage("Unable to write comment, something went wrong please see server log");
|
||||||
|
@ -220,7 +221,7 @@ public class Comments {
|
||||||
responseBean.setSuccess(false);
|
responseBean.setSuccess(false);
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
logger.error("Unable to write comment", e);
|
logger.error("Unable to write comment", e);
|
||||||
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||||
|
@ -229,6 +230,4 @@ public class Comments {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.validation.Valid;
|
||||||
import javax.ws.rs.Path;
|
import javax.validation.ValidationException;
|
||||||
import javax.ws.rs.Produces;
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
@ -13,6 +16,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portal.databook.server.DatabookStore;
|
import org.gcube.portal.databook.server.DatabookStore;
|
||||||
|
import org.gcube.portal.databook.shared.Post;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||||
|
@ -26,12 +30,13 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST interface for the social networking library (hash tags).
|
* REST interface for the social networking library (hash tags).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Path("2/hashtags")
|
@Path("2/hashtags")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class HashTags {
|
public class HashTags {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
|
@ -41,8 +46,8 @@ public class HashTags {
|
||||||
@Path("get-hashtags-and-occurrences/")
|
@Path("get-hashtags-and-occurrences/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Hashtags and occurrences retrieved, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Hashtags and occurrences retrieved, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
* @return hashtags in the context bound to the auth token
|
* @return hashtags in the context bound to the auth token
|
||||||
|
@ -55,7 +60,7 @@ public class HashTags {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
|
||||||
logger.info("User " + username + " has requested hashtags of context " + context);
|
logger.debug("User " + username + " has requested hashtags of context " + context);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
@ -76,5 +81,4 @@ public class HashTags {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,11 +35,12 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST interface for the social networking library (likes).
|
* REST interface for the social networking library (likes).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Path("2/likes")
|
@Path("2/likes")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Likes {
|
public class Likes {
|
||||||
|
|
||||||
|
@ -48,20 +49,20 @@ public class Likes {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve the list of likes belonging to the post id (key) of the token in the related context
|
* Retrieve the list of likes belonging to the post id (key) of the token in the related context
|
||||||
* @param key the key as in the POST JSON representation
|
* @param key the key as in the POST JSON representation
|
||||||
* @pathExample /get-likes-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
* @pathExample /get-likes-by-post-id?key=9ea137e9-6606-45ff-a1a2-94d4e8760583
|
||||||
* @return the list of likes belonging to the post identified by the key in the context identified by the token
|
* @return the list of likes belonging to the post identified by the key in the context identified by the token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("get-likes-by-post-id")
|
@Path("get-likes-by-post-id")
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "The list of likes is put into the 'result' field"),
|
@ResponseCode ( code = 200, condition = "The list of likes is put into the 'result' field"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikesByPostId(
|
public Response getAllLikesByPostId(
|
||||||
@NotNull
|
@NotNull
|
||||||
@QueryParam("key")
|
@QueryParam("key")
|
||||||
String key) {
|
String key) {
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
@ -72,7 +73,7 @@ public class Likes {
|
||||||
List<Like> likes = null;
|
List<Like> likes = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving likes for user id " + username);
|
logger.debug("Retrieving likes for user id " + username);
|
||||||
likes = CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(key);
|
likes = CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(key);
|
||||||
responseBean.setResult(likes);
|
responseBean.setResult(likes);
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
|
@ -89,7 +90,7 @@ public class Likes {
|
||||||
/**
|
/**
|
||||||
* Create a new like to a post in the context of the token
|
* Create a new like to a post in the context of the token
|
||||||
* @param postid The post id to be liked
|
* @param postid The post id to be liked
|
||||||
* @return true if everything is OK
|
* @return true if everything is OK
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
|
@ -97,12 +98,12 @@ public class Likes {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successful created, the like operation result is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successful created, the like operation result is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response like(
|
public Response like(
|
||||||
@NotNull(message="Post to like is missing")
|
@NotNull(message="Post to like is missing")
|
||||||
@Valid
|
@Valid
|
||||||
PostId post) throws ValidationException {
|
PostId post) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -112,7 +113,7 @@ public class Likes {
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
boolean likeResultOperation = SocialUtils.like(username, post.getPostId(), context);
|
boolean likeResultOperation = SocialUtils.like(username, post.getPostId(), context);
|
||||||
if (likeResultOperation)
|
if (likeResultOperation)
|
||||||
logger.info("Added like OK to postId " + post.getPostId());
|
logger.debug("Added like OK to postId " + post.getPostId());
|
||||||
else {
|
else {
|
||||||
logger.error("Unable to like this post"+ post.getPostId());
|
logger.error("Unable to like this post"+ post.getPostId());
|
||||||
responseBean.setMessage("Unable to like, something went wrong please see server log");
|
responseBean.setMessage("Unable to like, something went wrong please see server log");
|
||||||
|
@ -125,7 +126,7 @@ public class Likes {
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike to a post in the context of the token
|
* Unlike to a post in the context of the token
|
||||||
* @param postid The post id to be liked
|
* @param postid The post id to be liked
|
||||||
|
@ -137,12 +138,12 @@ public class Likes {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "The unlike operation result is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "The unlike operation result is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response unlike(
|
public Response unlike(
|
||||||
@NotNull(message="Post to unlike is missing")
|
@NotNull(message="Post to unlike is missing")
|
||||||
@Valid
|
@Valid
|
||||||
LikeInputBean likeInputBean) throws ValidationException {
|
LikeInputBean likeInputBean) throws ValidationException {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -151,7 +152,7 @@ public class Likes {
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
boolean likeResultOperation = SocialUtils.unlike(username, likeInputBean.getLikeid(), likeInputBean.getPostid());
|
boolean likeResultOperation = SocialUtils.unlike(username, likeInputBean.getLikeid(), likeInputBean.getPostid());
|
||||||
if (likeResultOperation)
|
if (likeResultOperation)
|
||||||
logger.info("Unlike OK to postId " + likeInputBean.getPostid());
|
logger.debug("Unlike OK to postId " + likeInputBean.getPostid());
|
||||||
else {
|
else {
|
||||||
logger.error("Unable to unlike this post"+ likeInputBean.getPostid());
|
logger.error("Unable to unlike this post"+ likeInputBean.getPostid());
|
||||||
responseBean.setMessage("Unable to unlike, something went wrong please see server log");
|
responseBean.setMessage("Unable to unlike, something went wrong please see server log");
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class Messages {
|
||||||
String body = input.getBody();
|
String body = input.getBody();
|
||||||
String subject = input.getSubject();
|
String subject = input.getSubject();
|
||||||
List<Recipient> recipientsIds = input.getRecipients(); // "recipients":[{"recipient":"id recipient"}, ......]
|
List<Recipient> recipientsIds = input.getRecipients(); // "recipients":[{"recipient":"id recipient"}, ......]
|
||||||
logger.info("Sender is going to be [" + fullName + "]");
|
logger.debug("Sender is going to be [" + fullName + "]");
|
||||||
|
|
||||||
// get the recipients ids (simple check, trim)
|
// get the recipients ids (simple check, trim)
|
||||||
List<String> recipientsListFiltered = new ArrayList<String>();
|
List<String> recipientsListFiltered = new ArrayList<String>();
|
||||||
|
@ -195,7 +195,7 @@ public class Messages {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
|
||||||
logger.info("Request for retrieving sent messages by " + username);
|
logger.debug("Request for retrieving sent messages by " + username);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
@ -231,7 +231,7 @@ public class Messages {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
|
||||||
logger.info("Request for retrieving received messages by " + username);
|
logger.debug("Request for retrieving received messages by " + username);
|
||||||
try{
|
try{
|
||||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
List<Message> getMessages =client.getReceivedMessages();
|
List<Message> getMessages =client.getReceivedMessages();
|
||||||
|
@ -277,7 +277,7 @@ public class Messages {
|
||||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
client.setRead(messageId, read);
|
client.setRead(messageId, read);
|
||||||
String toReturn = "set Message id:" + messageId + (read ? " read" : " unread");
|
String toReturn = "set Message id:" + messageId + (read ? " read" : " unread");
|
||||||
logger.info("set Message id:" + messageId + " read?" + read + " for " + opExecutor);
|
logger.debug("set Message id:" + messageId + " read?" + read + " for " + opExecutor);
|
||||||
|
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
responseBean.setResult(toReturn);
|
responseBean.setResult(toReturn);
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package org.gcube.portal.social.networking.ws.methods.v2;
|
package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.ValidationException;
|
import javax.validation.ValidationException;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -28,7 +23,6 @@ import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
import org.gcube.applicationsupportlayer.social.ScopeBeanExt;
|
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||||
|
@ -38,6 +32,7 @@ import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.portal.databook.shared.Notification;
|
import org.gcube.portal.databook.shared.Notification;
|
||||||
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
||||||
import org.gcube.portal.databook.shared.NotificationType;
|
import org.gcube.portal.databook.shared.NotificationType;
|
||||||
import org.gcube.portal.databook.shared.RunningJob;
|
import org.gcube.portal.databook.shared.RunningJob;
|
||||||
import org.gcube.portal.notifications.bean.GenericItemBean;
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
|
@ -48,20 +43,15 @@ import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials;
|
import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.ws.ex.AuthException;
|
import org.gcube.portal.social.networking.ws.ex.AuthException;
|
||||||
import org.gcube.portal.social.networking.ws.inputs.UserSetNotificationBean;
|
|
||||||
import org.gcube.portal.social.networking.ws.mappers.CatalogueEventTypeMapper;
|
import org.gcube.portal.social.networking.ws.mappers.CatalogueEventTypeMapper;
|
||||||
import org.gcube.portal.social.networking.ws.mappers.JobMapper;
|
import org.gcube.portal.social.networking.ws.mappers.JobMapper;
|
||||||
import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper;
|
import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper;
|
||||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||||
import org.gcube.portal.social.networking.ws.utils.DistributedCacheClient;
|
|
||||||
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
||||||
import org.gcube.portal.social.networking.ws.utils.SocialUtils;
|
|
||||||
import org.gcube.portal.social.networking.ws.utils.TokensUtils;
|
import org.gcube.portal.social.networking.ws.utils.TokensUtils;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
|
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
|
||||||
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.AddedItemEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.AddedItemEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.DeletedItemEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.DeletedItemEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderAddedUserEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderAddedUserEvent;
|
||||||
|
@ -72,31 +62,28 @@ import org.gcube.social_networking.socialnetworking.model.beans.workspace.Rename
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.SharedFolderEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.SharedFolderEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.UnsharedFolderEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.UnsharedFolderEvent;
|
||||||
import org.gcube.social_networking.socialnetworking.model.beans.workspace.UpdatedItemEvent;
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.UpdatedItemEvent;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.mortbay.log.Log;
|
import org.mortbay.log.Log;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
import net.spy.memcached.MemcachedClient;
|
|
||||||
import net.spy.memcached.internal.OperationFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST interface for the social networking library (notifications).
|
* REST interface for the social networking library (notifications).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Path("2/notifications")
|
@Path("2/notifications")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Notifications {
|
public class Notifications {
|
||||||
|
|
||||||
|
@ -115,15 +102,15 @@ public class Notifications {
|
||||||
@Path("get-range-notifications/")
|
@Path("get-range-notifications/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notifications retrieved and reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Notifications retrieved and reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRangeNotifications(
|
public Response getRangeNotifications(
|
||||||
@DefaultValue("1") @QueryParam("from") @Min(value=1, message="from must be greater or equal to 1")
|
@DefaultValue("1") @QueryParam("from") @Min(value=1, message="from must be greater or equal to 1")
|
||||||
int from,
|
int from,
|
||||||
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity must be greater or equal to 0")
|
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity must be greater or equal to 0")
|
||||||
int quantity
|
int quantity
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String username = caller.getClient().getId();
|
String username = caller.getClient().getId();
|
||||||
|
@ -156,19 +143,19 @@ public class Notifications {
|
||||||
* @responseExample application/json { "success": true, "message": null "result": true }
|
* @responseExample application/json { "success": true, "message": null "result": true }
|
||||||
* @param username the username you want to check
|
* @param username the username you want to check
|
||||||
* @return true if the notification for the user are disabled (Catalogue and Workspace ones)
|
* @return true if the notification for the user are disabled (Catalogue and Workspace ones)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("is-user-disabled/")
|
@Path("is-user-disabled/")
|
||||||
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "true if the notification for the username given as query param are disabled (Catalogue and Workspace ones), false otherwise"),
|
@ResponseCode ( code = 200, condition = "true if the notification for the username given as query param are disabled (Catalogue and Workspace ones), false otherwise"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
public Response isUserDisabled(
|
public Response isUserDisabled(
|
||||||
@QueryParam("username") @NotNull(message="username cannot be null")
|
@QueryParam("username") @NotNull(message="username cannot be null")
|
||||||
String username) throws ValidationException{
|
String username) throws ValidationException{
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -187,91 +174,98 @@ public class Notifications {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Set user notification enabled or disabled
|
// * Set user notification enabled or disabled
|
||||||
* @param disable true if you want to disable the notifications for this user, false if you want to enable them
|
// * @param disable true if you want to disable the notifications for this user, false if you want to enable them
|
||||||
* @return the result of the operation
|
// * @return the result of the operation
|
||||||
* @throws ValidationException
|
// * @throws ValidationException
|
||||||
*/
|
// */
|
||||||
@POST
|
// @POST
|
||||||
@Path("set-user-notifications/")
|
// @Path("set-user-notifications/")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
// @Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
// @StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notification set Off or On correctly executed"),
|
// @ResponseCode ( code = 200, condition = "Notification set Off or On correctly executed"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
// @ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
// })
|
||||||
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
// @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
public Response setUserNotifications(
|
// public Response setUserNotifications(
|
||||||
@NotNull(message="input is missing")
|
// @NotNull(message="input is missing")
|
||||||
@Valid
|
// @Valid
|
||||||
UserSetNotificationBean setting) throws ValidationException{
|
// UserSetNotificationBean setting) throws ValidationException{
|
||||||
|
//
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
// Caller caller = AuthorizationProvider.instance.get();
|
||||||
String context = ScopeProvider.instance.get();
|
// String context = ScopeProvider.instance.get();
|
||||||
ResponseBean responseBean = new ResponseBean();
|
// ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
// Status status = Status.OK;
|
||||||
|
//
|
||||||
|
//
|
||||||
try{
|
// try{
|
||||||
String opExecutor = caller.getClient().getId();
|
// String opExecutor = caller.getClient().getId();
|
||||||
Boolean result = setUserNotificationsOnOff(setting.getUsername(), setting.isDisableNotification(), opExecutor);
|
// Boolean result = setUserNotificationsOnOff(setting.getUsername(), setting.isDisableNotification(), opExecutor);
|
||||||
String toReturn = "Could not set notifications";
|
// String toReturn = "Could not set notifications";
|
||||||
if (result) {
|
// if (result) {
|
||||||
toReturn = "Notifications have been set";
|
// toReturn = "Notifications have been set";
|
||||||
toReturn += setting.isDisableNotification() ? " OFF (for 29 days unless re-enabled manually) ": " ON ";
|
// toReturn += setting.isDisableNotification() ? " OFF (for 29 days unless re-enabled manually) ": " ON ";
|
||||||
toReturn += "for username=" + setting.getUsername();
|
// toReturn += "for username=" + setting.getUsername();
|
||||||
}
|
// }
|
||||||
responseBean.setSuccess(true);
|
// responseBean.setSuccess(true);
|
||||||
responseBean.setResult(toReturn);
|
// responseBean.setResult(toReturn);
|
||||||
|
//
|
||||||
} catch(Exception e){
|
// } catch(Exception e){
|
||||||
logger.error("Unable to set user notification", e);
|
// logger.error("Unable to set user notification", e);
|
||||||
responseBean.setSuccess(false);
|
// responseBean.setSuccess(false);
|
||||||
responseBean.setMessage(e.getMessage());
|
// responseBean.setMessage(e.getMessage());
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
return Response.status(status).entity(responseBean).build();
|
// return Response.status(status).entity(responseBean).build();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @deprecated
|
||||||
* @param usernameToCheck
|
* @param usernameToCheck
|
||||||
* @return true if notification are enabled for this user
|
* @return true if notification are enabled for this user
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private boolean isNotificationEnabled(String usernameToCheck) {
|
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
||||||
MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+usernameToCheck;
|
// String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+usernameToCheck;
|
||||||
Boolean userEnabled = false;
|
// Boolean userEnabled = false;
|
||||||
if(entries.get(key) == null)
|
// if(entries.get(key) == null)
|
||||||
userEnabled = true;
|
// userEnabled = true;
|
||||||
return userEnabled;
|
// entries.getConnection().shutdown();
|
||||||
}
|
// return userEnabled;
|
||||||
/**
|
return true;
|
||||||
*
|
|
||||||
* @param username the user you want to disable or enable notifications (max 29 days)
|
|
||||||
* @param callerId the username or clientid of the operation executor
|
|
||||||
* @param disable true if you want to disable the notifications for this user
|
|
||||||
* @return true if the operation was performed
|
|
||||||
*/
|
|
||||||
private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) {
|
|
||||||
MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
|
||||||
String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+username;
|
|
||||||
OperationFuture<Boolean> result = null;
|
|
||||||
if (disable) {
|
|
||||||
result = entries.set(key, SocialUtils.CACHING_TIME_TO_EXPIRATION, "op.ex:" + callerId); //operator executor is who silenced the user
|
|
||||||
} else {
|
|
||||||
result = entries.delete(key);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return result.getStatus().isSuccess();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
// /**
|
||||||
|
// *
|
||||||
|
// * @param username the user you want to disable or enable notifications (max 29 days)
|
||||||
|
// * @param callerId the username or clientid of the operation executor
|
||||||
|
// * @param disable true if you want to disable the notifications for this user
|
||||||
|
// * @return true if the operation was performed
|
||||||
|
// * @throws IOException
|
||||||
|
// */
|
||||||
|
// private Boolean setUserNotificationsOnOff(String username, boolean disable, String callerId) throws IOException {
|
||||||
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
|
// String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+username;
|
||||||
|
// OperationFuture<Boolean> result = null;
|
||||||
|
// if (disable) {
|
||||||
|
// result = entries.set(key, SocialUtils.CACHING_TIME_TO_EXPIRATION, "op.ex:" + callerId); //operator executor is who silenced the user
|
||||||
|
// } else {
|
||||||
|
// result = entries.delete(key);
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// boolean res = result.getStatus().isSuccess();
|
||||||
|
// entries.getConnection().shutdown();
|
||||||
|
// return res;
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// entries.getConnection().shutdown();
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a JOB notification to a given recipient
|
* Send a JOB notification to a given recipient
|
||||||
|
@ -284,12 +278,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response notifyJobStatus(
|
public Response notifyJobStatus(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
JobNotificationBean job) throws ValidationException{
|
JobNotificationBean job) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -298,7 +292,7 @@ public class Notifications {
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
|
||||||
String appQualifier = caller.getClient().getId();
|
String appQualifier = caller.getClient().getId();
|
||||||
logger.info("Received request from app " + appQualifier + " to notify job status described by bean " + job);
|
logger.debug("Received request from app " + appQualifier + " to notify job status described by bean " + job);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
@ -340,12 +334,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Catalogue Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Catalogue Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response catalogue(
|
public Response catalogue(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
CatalogueEvent event) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
CatalogueEvent event) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -361,14 +355,14 @@ public class Notifications {
|
||||||
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
username = jarvis.getUsername();
|
username = jarvis.getUsername();
|
||||||
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
}else{
|
}else{
|
||||||
username = caller.getClient().getId();
|
username = caller.getClient().getId();
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
|
||||||
logger.debug("catalogue notifications from user = " + username);
|
logger.debug("catalogue notifications from user = " + username);
|
||||||
|
@ -376,11 +370,13 @@ public class Notifications {
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
boolean deliveryResult = false;
|
boolean deliveryResult = false;
|
||||||
try {
|
try {
|
||||||
logger.debug("catalogue notifications type is " + event.getType());
|
//logger.debug("catalogue notifications type is " + event.getType());
|
||||||
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
//logger.debug("social networking site is " + site.getName());
|
||||||
|
//logger.debug("context is " + context);
|
||||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
//logger.debug("user is " + user.getUsername());
|
||||||
|
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
String[] idsToNotify = event.getIdsToNotify();
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
if (! event.idsAsGroup()) {
|
if (! event.idsAsGroup()) {
|
||||||
|
@ -389,7 +385,7 @@ public class Notifications {
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
String username2Notify = null;
|
String username2Notify = null;
|
||||||
try {
|
try {
|
||||||
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
|
@ -398,15 +394,20 @@ public class Notifications {
|
||||||
responseBean.setMessage("Username not found, got: " + userIdToNotify);
|
responseBean.setMessage("Username not found, got: " + userIdToNotify);
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
//logger.debug("username2notify " + username2Notify);
|
||||||
deliveryResult =
|
//logger.debug("type is " + CatalogueEventTypeMapper.getType(event.getType()));
|
||||||
|
//logger.debug("item id is " + event.getItemId());
|
||||||
|
//logger.debug("item text is " + event.getNotifyText());
|
||||||
|
//logger.debug("item url is " + event.getItemURL());
|
||||||
|
|
||||||
|
deliveryResult =
|
||||||
nm.notifyCatalogueEvent(
|
nm.notifyCatalogueEvent(
|
||||||
CatalogueEventTypeMapper.getType(event.getType()),
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
username2Notify,
|
username2Notify,
|
||||||
event.getItemId(),
|
event.getItemId(),
|
||||||
event.getNotifyText(),
|
event.getNotifyText(),
|
||||||
event.getItemURL());
|
event.getItemURL());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
|
@ -427,20 +428,20 @@ public class Notifications {
|
||||||
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
for (int j = 0; j < userIdsToNotify.length; j++) {
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
String userIdToNotify = userIdsToNotify[j];
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
deliveryResult =
|
deliveryResult =
|
||||||
nm.notifyCatalogueEvent(
|
nm.notifyCatalogueEvent(
|
||||||
CatalogueEventTypeMapper.getType(event.getType()),
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
userIdToNotify,
|
userIdToNotify,
|
||||||
event.getItemId(),
|
event.getItemId(),
|
||||||
event.getNotifyText(),
|
event.getNotifyText(),
|
||||||
event.getItemURL());
|
event.getItemURL());
|
||||||
} else {
|
} else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IllegalArgumentException e) {
|
catch(IllegalArgumentException e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
logger.error("Context not valid", e);
|
logger.error("Context not valid", e);
|
||||||
|
@ -480,12 +481,12 @@ public class Notifications {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response workspace(
|
public Response workspace(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
WorkspaceEvent event) throws ValidationException{
|
WorkspaceEvent event) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -509,23 +510,23 @@ public class Notifications {
|
||||||
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
username = jarvis.getUsername();
|
username = jarvis.getUsername();
|
||||||
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
}else{
|
}else{
|
||||||
username = caller.getClient().getId();
|
username = caller.getClient().getId();
|
||||||
senderUser = um.getUserByUsername(username);
|
senderUser = um.getUserByUsername(username);
|
||||||
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
}
|
}
|
||||||
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
String[] idsToNotify = event.getIdsToNotify();
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
if (! event.idsAsGroup()) {
|
if (! event.idsAsGroup()) {
|
||||||
for (int i = 0; i < idsToNotify.length; i++) {
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
String userIdToNotify = idsToNotify[i];
|
String userIdToNotify = idsToNotify[i];
|
||||||
if (isNotificationEnabled(userIdToNotify)) {
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
String username2Notify = "";
|
String username2Notify = "";
|
||||||
try {
|
try {
|
||||||
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
status = Status.NOT_ACCEPTABLE;
|
status = Status.NOT_ACCEPTABLE;
|
||||||
|
@ -555,14 +556,14 @@ public class Notifications {
|
||||||
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
for (int j = 0; j < userIdsToNotify.length; j++) {
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
String userIdToNotify = userIdsToNotify[j];
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
if (isNotificationEnabled(userIdToNotify))
|
if (isNotificationEnabled(userIdToNotify))
|
||||||
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
||||||
else {
|
else {
|
||||||
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IllegalArgumentException e) {
|
catch(IllegalArgumentException e) {
|
||||||
status = Status.BAD_REQUEST;
|
status = Status.BAD_REQUEST;
|
||||||
logger.error("Context not valid", e);
|
logger.error("Context not valid", e);
|
||||||
|
@ -591,7 +592,7 @@ public class Notifications {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* @param nm
|
* @param nm
|
||||||
* @param idToNotify
|
* @param idToNotify
|
||||||
|
@ -600,49 +601,49 @@ public class Notifications {
|
||||||
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
||||||
try {
|
try {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
case ITEM_NEW: {
|
case ITEM_NEW: {
|
||||||
AddedItemEvent itemBean = (AddedItemEvent) event;
|
AddedItemEvent itemBean = (AddedItemEvent) event;
|
||||||
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
}
|
}
|
||||||
case ITEM_UPDATE: {
|
case ITEM_UPDATE: {
|
||||||
UpdatedItemEvent itemBean = (UpdatedItemEvent) event;
|
UpdatedItemEvent itemBean = (UpdatedItemEvent) event;
|
||||||
return nm.notifyUpdatedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
return nm.notifyUpdatedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
}
|
}
|
||||||
case ITEM_DELETE: {
|
case ITEM_DELETE: {
|
||||||
DeletedItemEvent itemBean = (DeletedItemEvent) event;
|
DeletedItemEvent itemBean = (DeletedItemEvent) event;
|
||||||
return nm.notifyRemovedItem(idToNotify, itemBean.getItemName(), WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyRemovedItem(idToNotify, itemBean.getItemName(), WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_SHARE: {
|
case FOLDER_SHARE: {
|
||||||
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
||||||
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_UNSHARE: {
|
case FOLDER_UNSHARE: {
|
||||||
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
||||||
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
||||||
}
|
}
|
||||||
case FOLDER_RENAME: {
|
case FOLDER_RENAME: {
|
||||||
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
||||||
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
||||||
}
|
}
|
||||||
case FOLDER_ADMIN_UPGRADE: {
|
case FOLDER_ADMIN_UPGRADE: {
|
||||||
FolderAdminUpgradeEvent itemBean = (FolderAdminUpgradeEvent) event;
|
FolderAdminUpgradeEvent itemBean = (FolderAdminUpgradeEvent) event;
|
||||||
return nm.notifyAdministratorUpgrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyAdministratorUpgrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_ADMIN_DOWNGRADE: {
|
case FOLDER_ADMIN_DOWNGRADE: {
|
||||||
FolderAdminDowngradeEvent itemBean = (FolderAdminDowngradeEvent) event;
|
FolderAdminDowngradeEvent itemBean = (FolderAdminDowngradeEvent) event;
|
||||||
return nm.notifyAdministratorDowngrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyAdministratorDowngrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
case FOLDER_ADDEDUSER: {
|
case FOLDER_ADDEDUSER: {
|
||||||
FolderAddedUserEvent itemBean = (FolderAddedUserEvent) event;
|
FolderAddedUserEvent itemBean = (FolderAddedUserEvent) event;
|
||||||
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
return nm.notifyFolderAddedUsers(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()), itemBean.getNewAddedUserIds(), userManager);
|
return nm.notifyFolderAddedUsers(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()), itemBean.getNewAddedUserIds(), userManager);
|
||||||
}
|
}
|
||||||
case FOLDER_REMOVEDUSER: {
|
case FOLDER_REMOVEDUSER: {
|
||||||
FolderRemovedUserEvent itemBean = (FolderRemovedUserEvent) event;
|
FolderRemovedUserEvent itemBean = (FolderRemovedUserEvent) event;
|
||||||
return nm.notifyFolderRemovedUser(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
return nm.notifyFolderRemovedUser(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
logger.error("Unable to send job notification", e);
|
logger.error("Unable to send job notification", e);
|
||||||
|
@ -651,7 +652,7 @@ public class Notifications {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -680,5 +681,4 @@ public class Notifications {
|
||||||
}
|
}
|
||||||
return usernames;
|
return usernames;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portal.social.networking.ws.methods.v2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.ValidationException;
|
import javax.validation.ValidationException;
|
||||||
|
@ -18,15 +19,13 @@ import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
import org.gcube.portal.databook.shared.PostWithAttachment;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portal.databook.server.DatabookStore;
|
import org.gcube.portal.databook.server.DatabookStore;
|
||||||
import org.gcube.portal.databook.shared.ApplicationProfile;
|
import org.gcube.portal.databook.shared.*;
|
||||||
import org.gcube.portal.databook.shared.Feed;
|
|
||||||
import org.gcube.portal.databook.shared.Post;
|
|
||||||
import org.gcube.portal.databook.shared.RangePosts;
|
|
||||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||||
|
@ -46,17 +45,18 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST interface for the social networking library (posts).
|
* REST interface for the social networking library (posts).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Path("2/posts")
|
@Path("2/posts")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Posts {
|
public class Posts {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Posts.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Posts.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve posts of the auth token's owner, and allow to filter them by time"
|
* Retrieve posts of the auth token's owner, and allow to filter them by time"
|
||||||
* @param timeInMillis The reference time since when retrieving posts
|
* @param timeInMillis The reference time since when retrieving posts
|
||||||
|
@ -67,13 +67,13 @@ public class Posts {
|
||||||
@Path("get-posts-user-since/")
|
@Path("get-posts-user-since/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRecentPostsByUserAndDate(
|
public Response getRecentPostsByUserAndDate(
|
||||||
@QueryParam("time") @Min(value = 0, message="time cannot be negative")
|
@QueryParam("time") @Min(value = 0, message="time cannot be negative")
|
||||||
long timeInMillis
|
long timeInMillis
|
||||||
) throws ValidationException{
|
) throws ValidationException{
|
||||||
|
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
|
@ -83,7 +83,7 @@ public class Posts {
|
||||||
List<Post> posts = null;
|
List<Post> posts = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Retrieving post for user id " + username + " and reference time " + timeInMillis);
|
logger.debug("Retrieving post for user id " + username + " and reference time " + timeInMillis);
|
||||||
posts = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(username, timeInMillis);
|
posts = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(username, timeInMillis);
|
||||||
Filters.filterPostsPerContext(posts, context);
|
Filters.filterPostsPerContext(posts, context);
|
||||||
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
Filters.hideSensitiveInformation(posts, caller.getClient().getId());
|
||||||
|
@ -100,8 +100,8 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all user's posts
|
* Retrieve all user's posts
|
||||||
* @return all posts of the auth token's owner in the context identified by the token
|
* @return all posts of the auth token's owner in the context identified by the token
|
||||||
|
@ -110,8 +110,8 @@ public class Posts {
|
||||||
@Path("get-posts-user/")
|
@Path("get-posts-user/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByUser() {
|
public Response getAllPostsByUser() {
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a post by id
|
* Retrieve a post by id
|
||||||
* @return the post if the post id belongs to a post in the context identified by the token
|
* @return the post if the post id belongs to a post in the context identified by the token
|
||||||
|
@ -147,18 +147,18 @@ public class Posts {
|
||||||
@Path("get-post/")
|
@Path("get-post/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getPost(@QueryParam("id") String id) {
|
public Response getPost(@QueryParam("id") String id) {
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
List<Post> posts = new ArrayList<>();
|
List<Post> posts = new ArrayList<>();
|
||||||
try{
|
try{
|
||||||
logger.debug("Retrieving post with id " + id);
|
logger.debug("Retrieving post with id " + id);
|
||||||
try {
|
try {
|
||||||
posts.add(CassandraConnection.getInstance().getDatabookStore().readPost(id));
|
posts.add(CassandraConnection.getInstance().getDatabookStore().readPost(id));
|
||||||
} catch(FeedIDNotFoundException e){
|
} catch(FeedIDNotFoundException e){
|
||||||
responseBean.setMessage("The post with id " + id + " does not exist in context " + context);
|
responseBean.setMessage("The post with id " + id + " does not exist in context " + context);
|
||||||
|
@ -185,7 +185,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given quantity of latest user's posts
|
* Retrieve a given quantity of latest user's posts
|
||||||
* @param quantity the number of latest post to get
|
* @param quantity the number of latest post to get
|
||||||
|
@ -197,13 +197,13 @@ public class Posts {
|
||||||
@Path("get-posts-user-quantity/")
|
@Path("get-posts-user-quantity/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts, reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getQuantityPostsByUser(
|
public Response getQuantityPostsByUser(
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("quantity")
|
@QueryParam("quantity")
|
||||||
@Min(value=0, message="quantity cannot be negative")
|
@Min(value=0, message="quantity cannot be negative")
|
||||||
int quantity) throws ValidationException{
|
int quantity) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -239,7 +239,7 @@ public class Posts {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user post having as owner the auth token's owner
|
* Create a new user post having as owner the auth token's owner
|
||||||
* @param post The post to be written
|
* @param post The post to be written
|
||||||
|
@ -251,12 +251,12 @@ public class Posts {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writePostUser(
|
public Response writePostUser(
|
||||||
@NotNull(message="Post to write is missing")
|
@NotNull(message="Post to write is missing")
|
||||||
@Valid
|
@Valid
|
||||||
PostInputBean post) throws ValidationException{
|
PostInputBean post) throws ValidationException{
|
||||||
|
|
||||||
logger.debug("Request of writing a feed coming from user " + post);
|
logger.debug("Request of writing a feed coming from user " + post);
|
||||||
|
@ -277,24 +277,24 @@ public class Posts {
|
||||||
|
|
||||||
// convert enablenotification parameter
|
// convert enablenotification parameter
|
||||||
if(enableNotification)
|
if(enableNotification)
|
||||||
logger.info("Enable notification for this user post.");
|
logger.debug("Enable notification for this user post.");
|
||||||
else
|
else
|
||||||
logger.info("Disable notification for this user post.");
|
logger.debug("Disable notification for this user post.");
|
||||||
|
|
||||||
|
|
||||||
// try to share
|
// try to share
|
||||||
logger.debug("Trying to share user post...");
|
logger.debug("Trying to share user post...");
|
||||||
Post res = SocialUtils.shareUserUpdate(
|
Post res = SocialUtils.shareUserUpdate(
|
||||||
username,
|
username,
|
||||||
postText,
|
postText,
|
||||||
context,
|
context,
|
||||||
previewTitle,
|
previewTitle,
|
||||||
previewDescription,
|
previewDescription,
|
||||||
previewHost,
|
previewHost,
|
||||||
previewUrl,
|
previewUrl,
|
||||||
httpImageUrl,
|
httpImageUrl,
|
||||||
enableNotification
|
enableNotification
|
||||||
);
|
);
|
||||||
|
|
||||||
if(res != null){
|
if(res != null){
|
||||||
logger.debug("Post correctly written by user " + username);
|
logger.debug("Post correctly written by user " + username);
|
||||||
|
@ -311,7 +311,7 @@ public class Posts {
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the application's posts
|
* Retrieve the application's posts
|
||||||
* @return the application (IAM Client) posts belonging to the token's owner (i.e., an application)"
|
* @return the application (IAM Client) posts belonging to the token's owner (i.e., an application)"
|
||||||
|
@ -320,9 +320,9 @@ public class Posts {
|
||||||
@Path("get-posts-app/")
|
@Path("get-posts-app/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByApp() {
|
public Response getAllPostsByApp() {
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new application post having as owner-application the token's owner (the IAM Client), note that the application must be registered on the Information System
|
* Create a new application post having as owner-application the token's owner (the IAM Client), note that the application must be registered on the Information System
|
||||||
* @param post The post to be written
|
* @param post The post to be written
|
||||||
|
@ -373,13 +373,13 @@ public class Posts {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull created, the new post is reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
@ResponseCode ( code = 403, condition = "\"There is no application profile with such token"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response writePostApp(
|
public Response writePostApp(
|
||||||
@NotNull(message="Post to write is null")
|
@NotNull(message="Post to write is null")
|
||||||
@Valid
|
@Valid
|
||||||
PostInputBean post){
|
PostInputBean post){
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -417,15 +417,15 @@ public class Posts {
|
||||||
|
|
||||||
// write post + notification if it is the case
|
// write post + notification if it is the case
|
||||||
Post written = SocialUtils.shareApplicationUpdate(
|
Post written = SocialUtils.shareApplicationUpdate(
|
||||||
postText,
|
postText,
|
||||||
params,
|
params,
|
||||||
previewTitle,
|
previewTitle,
|
||||||
previewDescription,
|
previewDescription,
|
||||||
httpImageUrl,
|
httpImageUrl,
|
||||||
appProfile,
|
appProfile,
|
||||||
caller,
|
caller,
|
||||||
enableNotification
|
enableNotification
|
||||||
);
|
);
|
||||||
|
|
||||||
if(written != null){
|
if(written != null){
|
||||||
responseBean.setResult(written);
|
responseBean.setResult(written);
|
||||||
|
@ -441,15 +441,15 @@ public class Posts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return all the posts in the context bound to the auth token
|
* @return all the posts in the context bound to the auth token
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("get-posts-vre/")
|
@Path("get-posts-vre/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllPostsByVRE() {
|
public Response getAllPostsByVRE() {
|
||||||
|
|
||||||
|
@ -476,28 +476,28 @@ public class Posts {
|
||||||
/**
|
/**
|
||||||
* return the most recent posts for this vre up to quantity param and the last index of the posts in the timeline
|
* return the most recent posts for this vre up to quantity param and the last index of the posts in the timeline
|
||||||
* lastReturnedPostTimelineIndex is useful to know from where to start the range the next time you ask, because there are deletions
|
* lastReturnedPostTimelineIndex is useful to know from where to start the range the next time you ask, because there are deletions
|
||||||
*
|
*
|
||||||
* @param from the range start (most recent feeds for this vre) has to be greater than 0
|
* @param from the range start (most recent feeds for this vre) has to be greater than 0
|
||||||
* @param quantity the number of most recent feeds for this vre starting from "from" param
|
* @param quantity the number of most recent feeds for this vre starting from "from" param
|
||||||
* @pathExample /get-recent-posts-vre-by-range?from=1&quantity=10
|
* @pathExample /get-recent-posts-vre-by-range?from=1&quantity=10
|
||||||
* @return a <class>RangePosts</class> containing of most recent feeds for this vre
|
* @return a <class>RangePosts</class> containing of most recent feeds for this vre
|
||||||
* @throws FeedTypeNotFoundException
|
* @throws FeedTypeNotFoundException
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("get-recent-posts-vre-by-range/")
|
@Path("get-recent-posts-vre-by-range/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getRecentPostsByVREAndRange(
|
public Response getRecentPostsByVREAndRange(
|
||||||
@QueryParam("from")
|
@QueryParam("from")
|
||||||
@Min(value=1, message="from cannot be negative")
|
@Min(value=1, message="from cannot be negative")
|
||||||
int from,
|
int from,
|
||||||
@QueryParam("quantity")
|
@QueryParam("quantity")
|
||||||
@Min(value=1, message="quantity cannot be negative")
|
@Min(value=1, message="quantity cannot be negative")
|
||||||
int quantity) throws ValidationException {
|
int quantity) throws ValidationException {
|
||||||
|
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
@ -531,12 +531,12 @@ public class Posts {
|
||||||
@Path("get-posts-by-hashtag/")
|
@Path("get-posts-by-hashtag/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getPostsByHashTags(
|
public Response getPostsByHashTags(
|
||||||
@QueryParam("hashtag")
|
@QueryParam("hashtag")
|
||||||
@NotNull(message="hashtag cannot be missing")
|
@NotNull(message="hashtag cannot be missing")
|
||||||
String hashtag) throws ValidationException {
|
String hashtag) throws ValidationException {
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -544,7 +544,7 @@ public class Posts {
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
logger.info("User " + username + " has requested posts containing hashtag " + hashtag + " in context " + context);
|
logger.debug("User " + username + " has requested posts containing hashtag " + hashtag + " in context " + context);
|
||||||
try{
|
try{
|
||||||
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
DatabookStore datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
List<Post> posts = datastore.getVREPostsByHashtag(context, hashtag);
|
List<Post> posts = datastore.getVREPostsByHashtag(context, hashtag);
|
||||||
|
@ -558,7 +558,7 @@ public class Posts {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve ids (UUID) of the liked posts by the user
|
* Retrieve ids (UUID) of the liked posts by the user
|
||||||
* @return ids (UUID) of the liked posts by the user in the context bound to the auth token
|
* @return ids (UUID) of the liked posts by the user in the context bound to the auth token
|
||||||
|
@ -567,8 +567,8 @@ public class Posts {
|
||||||
@Path("get-id-liked-posts/")
|
@Path("get-id-liked-posts/")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 201, condition = "Sccessfull retrieved ids, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 201, condition = "Sccessfull retrieved ids, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikedPostIdsByUser() {
|
public Response getAllLikedPostIdsByUser() {
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ public class Posts {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve posts liked by the user
|
* Retrieve posts liked by the user
|
||||||
* @param limit The maximum number of posts to be retrieved
|
* @param limit The maximum number of posts to be retrieved
|
||||||
|
@ -608,13 +608,13 @@ public class Posts {
|
||||||
@Path("get-liked-posts/")
|
@Path("get-liked-posts/")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Successfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
@ResponseCode ( code = 200, condition = "Successfull retrieved posts, they are reported in the 'result' field of the returned object"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response getAllLikedPostsByUser(
|
public Response getAllLikedPostsByUser(
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
@Min(message="limit cannot be negative", value = 0)
|
@Min(message="limit cannot be negative", value = 0)
|
||||||
int limit) throws ValidationException{
|
int limit) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
@ -640,4 +640,63 @@ public class Posts {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//libapi
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("save-user-post-attachments-lib")
|
||||||
|
public Response saveUserPostLib(
|
||||||
|
@NotNull(message="post to add is missing")
|
||||||
|
@Valid
|
||||||
|
PostWithAttachment postWithAttachment
|
||||||
|
) throws ValidationException{
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
Post post = postWithAttachment.getPost();
|
||||||
|
logger.debug("Post is " + post);
|
||||||
|
List<Attachment> attachments = postWithAttachment.getAttachments();
|
||||||
|
logger.debug("Attachments are " + attachments);
|
||||||
|
boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(post,attachments);
|
||||||
|
responseBean.setResult(result);
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(result);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to write comment.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("save-app-post-attachments-lib")
|
||||||
|
public Response saveAppPostLib(
|
||||||
|
@NotNull(message="post to add is missing")
|
||||||
|
@Valid
|
||||||
|
PostWithAttachment postWithAttachment
|
||||||
|
) throws ValidationException{
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
Post post = postWithAttachment.getPost();
|
||||||
|
List<Attachment> attachments = postWithAttachment.getAttachments();
|
||||||
|
boolean result = CassandraConnection.getInstance().getDatabookStore().saveAppPost(post,attachments);
|
||||||
|
responseBean.setResult(result);
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(result);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to write comment.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class Tokens {
|
||||||
status = Status.FORBIDDEN;
|
status = Status.FORBIDDEN;
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
logger.info("Generating token for the application with id " + appId);
|
logger.debug("Generating token for the application with id " + appId);
|
||||||
// each token is related to an identifier and the context
|
// each token is related to an identifier and the context
|
||||||
String appToken = authorizationService().generateExternalServiceToken(appId);
|
String appToken = authorizationService().generateExternalServiceToken(appId);
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||||
import org.gcube.portal.social.networking.caches.UsersCache;
|
import org.gcube.portal.social.networking.caches.UsersCache;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.portal.social.networking.liferay.ws.KeycloakAPICredentials;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.RoleManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.RoleManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
||||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||||
|
@ -35,6 +36,11 @@ import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.keycloak.OAuth2Constants;
|
||||||
|
import org.keycloak.admin.client.Keycloak;
|
||||||
|
import org.keycloak.admin.client.KeycloakBuilder;
|
||||||
|
import org.keycloak.representations.idm.ClientRepresentation;
|
||||||
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
@ -47,9 +53,9 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/users")
|
@Path("2/users")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Users {
|
public class Users {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
|
@ -135,7 +141,7 @@ public class Users {
|
||||||
|
|
||||||
GCubeUser user = userManager.getUserByUsername(username);
|
GCubeUser user = userManager.getUserByUsername(username);
|
||||||
fullName = user.getFullname();
|
fullName = user.getFullname();
|
||||||
logger.info("Found fullname " + fullName + " for user " + username);
|
logger.debug("Found fullname " + fullName + " for user " + username);
|
||||||
responseBean.setResult(fullName);
|
responseBean.setResult(fullName);
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
|
|
||||||
|
@ -176,7 +182,7 @@ public class Users {
|
||||||
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
GCubeUser user = userManager.getUserByUsername(username);
|
GCubeUser user = userManager.getUserByUsername(username);
|
||||||
email = user.getEmail();
|
email = user.getEmail();
|
||||||
logger.info("Found email " + email + " for user " + username);
|
logger.debug("Found email " + email + " for user " + username);
|
||||||
responseBean.setResult(email);
|
responseBean.setResult(email);
|
||||||
responseBean.setSuccess(true);
|
responseBean.setSuccess(true);
|
||||||
|
|
||||||
|
@ -228,7 +234,7 @@ public class Users {
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Function<GCubeUser, UserProfileExtendedWithVerifiedEmail> GCUBE_TO_EXTENDED_PROFILE_MAP_WITH_VERIFIED_EMAIL
|
private static final Function<GCubeUser, UserProfileExtendedWithVerifiedEmail> GCUBE_TO_EXTENDED_PROFILE_MAP_WITH_VERIFIED_EMAIL
|
||||||
= new Function<GCubeUser, UserProfileExtendedWithVerifiedEmail>() {
|
= new Function<GCubeUser, UserProfileExtendedWithVerifiedEmail>() {
|
||||||
|
|
||||||
|
@ -250,7 +256,7 @@ public class Users {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @responseExample application/json {
|
* @responseExample application/json {
|
||||||
"id": "john.smith",
|
"id": "john.smith",
|
||||||
|
@ -367,7 +373,7 @@ public class Users {
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the map of couples username/fullname of the users belonging to a given context
|
* Get the map of couples username/fullname of the users belonging to a given context
|
||||||
* @return the map of couples username/fullname of the users belonging to the context linked to the provided token.
|
* @return the map of couples username/fullname of the users belonging to the context linked to the provided token.
|
||||||
|
@ -493,51 +499,61 @@ public class Users {
|
||||||
ResponseBean responseBean = new ResponseBean();
|
ResponseBean responseBean = new ResponseBean();
|
||||||
Status status = Status.OK;
|
Status status = Status.OK;
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
|
||||||
|
KeycloakAPICredentials apiService = KeycloakAPICredentials.getSingleton();
|
||||||
|
|
||||||
|
Keycloak keycloak;
|
||||||
|
|
||||||
|
|
||||||
|
keycloak = KeycloakBuilder.builder()
|
||||||
|
.serverUrl(apiService.getServerURL())
|
||||||
|
.realm(apiService.getRealm())
|
||||||
|
.grantType(OAuth2Constants.CLIENT_CREDENTIALS)
|
||||||
|
.clientId(apiService.getClientid()) //
|
||||||
|
.clientSecret(apiService.getPassword()).build();
|
||||||
|
|
||||||
|
|
||||||
List<String> usernames = new ArrayList<String>();
|
List<String> usernames = new ArrayList<String>();
|
||||||
try{
|
try {
|
||||||
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
List<UserRepresentation> users = searchByRole(keycloak, apiService.getRealm(), context, roleName);
|
||||||
RoleManager roleManager = RoleManagerWSBuilder.getInstance().getRoleManager();
|
if(users != null){
|
||||||
long roleId = roleManager.getRoleIdByName(roleName);
|
for (UserRepresentation user : users) {
|
||||||
if(roleId > 0){
|
usernames.add(user.getUsername());
|
||||||
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
|
||||||
List<GCubeUser> users = null;
|
|
||||||
long groupId = groupManager.getGroupIdFromInfrastructureScope(context);
|
|
||||||
// first check if for any reason this is a global role, then (if result is null or exception arises) check for site role
|
|
||||||
// Global role's users are retrieved much faster
|
|
||||||
try{
|
|
||||||
if(GLOBAL_ROLES_ALLOWED_BY_LOCAL_CALL_METHOD.contains(roleName)){
|
|
||||||
// TODO inconsistent value can be returned
|
|
||||||
users = userManager.listUsersByGlobalRole(roleId);
|
|
||||||
}
|
|
||||||
}catch(Exception globalExp){
|
|
||||||
logger.warn("Failed while checking for global role... trying with local one", globalExp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(users == null || users.isEmpty()){
|
|
||||||
logger.debug("User list is still null/empty, checking for local information");
|
|
||||||
users = userManager.listUsersByGroupAndRole(groupId, roleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(users != null){
|
|
||||||
for (GCubeUser gCubeUser : users) {
|
|
||||||
usernames.add(gCubeUser.getUsername());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
responseBean.setResult(usernames);
|
|
||||||
responseBean.setSuccess(true);
|
|
||||||
}else{
|
|
||||||
responseBean.setMessage("No role exists whit such a name");
|
|
||||||
status = Status.BAD_REQUEST;
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
responseBean.setResult(usernames);
|
||||||
logger.error("Unable to retrieve user's usernames", e);
|
responseBean.setSuccess(true);
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve user with the requested role", e);
|
||||||
responseBean.setMessage(e.getMessage());
|
responseBean.setMessage(e.getMessage());
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.status(status).entity(responseBean).build();
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<UserRepresentation> searchByRole(Keycloak keycloak, String realmName, String context, String roleName) {
|
||||||
|
logger.debug("Searching by role: {}", roleName);
|
||||||
|
|
||||||
|
String clientIdContext = context.replace("/", "%2F") ;
|
||||||
|
|
||||||
|
List<ClientRepresentation> clients = keycloak.realm(realmName)
|
||||||
|
.clients().findByClientId(clientIdContext);
|
||||||
|
|
||||||
|
String id = "";
|
||||||
|
for (ClientRepresentation client : clients) {
|
||||||
|
logger.debug("found client ="+client.getClientId());
|
||||||
|
logger.debug("found client id="+client.getId());
|
||||||
|
id =client.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserRepresentation> users = keycloak.realm(realmName)
|
||||||
|
.clients()
|
||||||
|
.get(id).roles().get(roleName)
|
||||||
|
.getUserMembers(0, 100000);
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("user-exists")
|
@Path("user-exists")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
|
|
@ -31,8 +31,7 @@ public class ResponseBean implements Serializable {
|
||||||
* @param success
|
* @param success
|
||||||
* @param message
|
* @param message
|
||||||
* @param result
|
* @param result
|
||||||
* @param help
|
*/
|
||||||
*/
|
|
||||||
public ResponseBean(boolean success, String message, Object result) {
|
public ResponseBean(boolean success, String message, Object result) {
|
||||||
super();
|
super();
|
||||||
this.success = success;
|
this.success = success;
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class CassandraConnection {
|
||||||
|
|
||||||
private CassandraConnection(){
|
private CassandraConnection(){
|
||||||
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
logger.info("Getting connection to cassandra");
|
logger.debug("Getting connection to cassandra");
|
||||||
store = new DBCassandraAstyanaxImpl(ctx.container().configuration().infrastructure());
|
store = new DBCassandraAstyanaxImpl(ctx.container().configuration().infrastructure());
|
||||||
logger.info("Connection to cassandra created");
|
logger.debug("Connection to cassandra created");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
package org.gcube.portal.social.networking.ws.utils;
|
|
||||||
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
||||||
import org.gcube.smartgears.ContextProvider;
|
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import net.spy.memcached.KetamaConnectionFactory;
|
|
||||||
import net.spy.memcached.MemcachedClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Massimiliano Assante at ISTI-CNR
|
|
||||||
*/
|
|
||||||
public class DistributedCacheClient {
|
|
||||||
|
|
||||||
// Logger
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DistributedCacheClient.class);
|
|
||||||
|
|
||||||
private static final String MEMCACHED_RESOURCE_NAME = "Memcached";
|
|
||||||
private static final String CATEGORY = "Database";
|
|
||||||
|
|
||||||
private MemcachedClient mClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the singleton instance
|
|
||||||
*/
|
|
||||||
public DistributedCacheClient(){
|
|
||||||
List<InetSocketAddress> addrs = discoverHostOfServiceEndpoint();
|
|
||||||
try {
|
|
||||||
mClient = new MemcachedClient(new KetamaConnectionFactory(), addrs);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemcachedClient getMemcachedClient() {
|
|
||||||
return mClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve endpoint resoruce from IS
|
|
||||||
* @return List of InetSocketAddresses
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static List<InetSocketAddress> discoverHostOfServiceEndpoint(){
|
|
||||||
|
|
||||||
String currentScope = ScopeProvider.instance.get();
|
|
||||||
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
|
||||||
String infrastructure = "/"+ctx.container().configuration().infrastructure();
|
|
||||||
ScopeProvider.instance.set(infrastructure);
|
|
||||||
List<InetSocketAddress> toReturn = new ArrayList<InetSocketAddress>();
|
|
||||||
try{
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '"+ MEMCACHED_RESOURCE_NAME +"'");
|
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
|
||||||
List<ServiceEndpoint> ses = client.submit(query);
|
|
||||||
if (ses.isEmpty()) {
|
|
||||||
logger.error("There is no Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context in this infrastructure: ");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (ServiceEndpoint se : ses) {
|
|
||||||
Group<AccessPoint> aps = se.profile().accessPoints();
|
|
||||||
for (AccessPoint ap : aps.asCollection()) {
|
|
||||||
String address = ap.address(); //e.g. socialnetworking-d-d4s.d4science.org:11211
|
|
||||||
String[] splits = address.split(":");
|
|
||||||
String hostname = splits[0];
|
|
||||||
int port = Integer.parseInt(splits[1]);
|
|
||||||
toReturn.add(new InetSocketAddress(hostname, port));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch(Exception e){
|
|
||||||
logger.error("Error while retrieving hosts for the Memcached cluster having name: " + MEMCACHED_RESOURCE_NAME + " and Category " + CATEGORY + " on root context");
|
|
||||||
}finally{
|
|
||||||
ScopeProvider.instance.set(currentScope);
|
|
||||||
}
|
|
||||||
ScopeProvider.instance.set(currentScope);
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -24,9 +24,9 @@ public class ElasticSearchConnection {
|
||||||
private ElasticSearchConnection(){
|
private ElasticSearchConnection(){
|
||||||
try {
|
try {
|
||||||
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
logger.info("Creating connection to Elasticsearch");
|
logger.debug("Creating connection to Elasticsearch");
|
||||||
es = new ElasticSearchClientImpl(ctx.container().configuration().infrastructure());
|
es = new ElasticSearchClientImpl(ctx.container().configuration().infrastructure());
|
||||||
logger.info("Elasticsearch connection created");
|
logger.debug("Elasticsearch connection created");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to connect to elasticsearch", e);
|
logger.error("Failed to connect to elasticsearch", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class Filters {
|
||||||
* If the initial context is the root: all feeds are returned;
|
* If the initial context is the root: all feeds are returned;
|
||||||
* If the initial context is a VO: feeds for vres within the vo are returned;
|
* If the initial context is a VO: feeds for vres within the vo are returned;
|
||||||
* If the initial context is a vre: feeds of the vre are returned;
|
* If the initial context is a vre: feeds of the vre are returned;
|
||||||
* @param retrievedLikedFeeds
|
* @param feeds
|
||||||
* @param context
|
* @param context
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@ -160,7 +160,7 @@ public class Filters {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Depending on the type of object provided (e.g. Feed, Comment etc), some information are removed
|
* Depending on the type of object provided (e.g. Feed, Comment etc), some information are removed
|
||||||
* @param comments
|
* @param toClear
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static <T> void hideSensitiveInformation(List<T> toClear, String usernameCaller){
|
public static <T> void hideSensitiveInformation(List<T> toClear, String usernameCaller){
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class SocialUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used when an application needs to publish something.
|
* Method used when an application needs to publish something.
|
||||||
* @param feedText
|
* @param postText
|
||||||
* @param uriParams
|
* @param uriParams
|
||||||
* @param previewTitle
|
* @param previewTitle
|
||||||
* @param previewDescription
|
* @param previewDescription
|
||||||
|
@ -135,7 +135,7 @@ public class SocialUtils {
|
||||||
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(ScopeProvider.instance.get());
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(ScopeProvider.instance.get());
|
||||||
|
|
||||||
escapedPostText = Utils.convertMentionUsernamesAnchorHTML(escapedPostText, mentionedUsersToConvertInHTML, site.getSiteURL(), site.getSiteLandingPagePath());
|
escapedPostText = Utils.convertMentionUsernamesAnchorHTML(escapedPostText, mentionedUsersToConvertInHTML, site.getSiteURL(), site.getSiteLandingPagePath());
|
||||||
logger.info("*** Escaped post text is " + escapedPostText);
|
logger.debug("*** Escaped post text is " + escapedPostText);
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
String appId = caller.getClient().getId();
|
String appId = caller.getClient().getId();
|
||||||
|
@ -154,7 +154,7 @@ public class SocialUtils {
|
||||||
boolean res = CassandraConnection.getInstance().getDatabookStore().saveAppPost(toWrite);
|
boolean res = CassandraConnection.getInstance().getDatabookStore().saveAppPost(toWrite);
|
||||||
|
|
||||||
if(res){
|
if(res){
|
||||||
logger.info("Feed correctly written by application " + appId);
|
logger.debug("Feed correctly written by application " + appId);
|
||||||
|
|
||||||
// wait a bit before saving hashtags
|
// wait a bit before saving hashtags
|
||||||
if(hashtags != null && !hashtags.isEmpty())
|
if(hashtags != null && !hashtags.isEmpty())
|
||||||
|
@ -439,7 +439,7 @@ public class SocialUtils {
|
||||||
Post toShare = new Post(UUID.randomUUID().toString(), PostType.PUBLISH, userId, new Date(),
|
Post toShare = new Post(UUID.randomUUID().toString(), PostType.PUBLISH, userId, new Date(),
|
||||||
vreId, url, urlThumbnail, textToPost, PrivacyLevel.SINGLE_VRE, fullName, email, thumbnailURL, linkTitle, linkDesc, host);
|
vreId, url, urlThumbnail, textToPost, PrivacyLevel.SINGLE_VRE, fullName, email, thumbnailURL, linkTitle, linkDesc, host);
|
||||||
|
|
||||||
logger.info("Attempting to save Post with text: " + textToPost + " Level = " + PrivacyLevel.SINGLE_VRE + " Timeline = " + vreId);
|
logger.debug("Attempting to save Post with text: " + textToPost + " Level = " + PrivacyLevel.SINGLE_VRE + " Timeline = " + vreId);
|
||||||
|
|
||||||
boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(toShare);
|
boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(toShare);
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ public class SocialUtils {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.info("Sleeping waiting for cassandra's update");
|
logger.debug("Sleeping waiting for cassandra's update");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -547,10 +547,10 @@ public class SocialUtils {
|
||||||
String thumbnailURL = user.getUserAvatarURL();
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
|
||||||
Comment theComment = new Comment(commentKey, userid, time, postId, escapedCommentText, fullName, thumbnailURL);
|
Comment theComment = new Comment(commentKey, userid, time, postId, escapedCommentText, fullName, thumbnailURL);
|
||||||
logger.info("Attempting to save Comment with text: " + commentText + " postid="+postId);
|
logger.debug("Attempting to save Comment with text: " + commentText + " postid="+postId);
|
||||||
|
|
||||||
boolean result = CassandraConnection.getInstance().getDatabookStore().addComment(theComment);
|
boolean result = CassandraConnection.getInstance().getDatabookStore().addComment(theComment);
|
||||||
logger.info("Added comment? " + theComment.toString() + " Result is " +result);
|
logger.debug("Added comment? " + theComment.toString() + " Result is " +result);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
return null;
|
return null;
|
||||||
|
@ -561,10 +561,10 @@ public class SocialUtils {
|
||||||
NotificationsManager nm = new ApplicationNotificationsManager(uManager, site, context, socialUser, NEWS_FEED_PORTLET_CLASSNAME);
|
NotificationsManager nm = new ApplicationNotificationsManager(uManager, site, context, socialUser, NEWS_FEED_PORTLET_CLASSNAME);
|
||||||
|
|
||||||
//if the user who commented this post is not the user who posted it notify the poster user (Post owner)
|
//if the user who commented this post is not the user who posted it notify the poster user (Post owner)
|
||||||
logger.info("The post creator is " + postOwnerId);
|
logger.debug("The post creator is " + postOwnerId);
|
||||||
if (! user.getUsername().equals(postOwnerId)) {
|
if (! user.getUsername().equals(postOwnerId)) {
|
||||||
boolean resultNotifyOwnComment = nm.notifyOwnCommentReply(postOwnerId, postId, escapedCommentText, theComment.getKey());
|
boolean resultNotifyOwnComment = nm.notifyOwnCommentReply(postOwnerId, postId, escapedCommentText, theComment.getKey());
|
||||||
logger.info("Comment Notification to post creator added? " + resultNotifyOwnComment);
|
logger.debug("Comment Notification to post creator added? " + resultNotifyOwnComment);
|
||||||
}
|
}
|
||||||
//if there are users who liked this post they get notified, asynchronously with this thread
|
//if there are users who liked this post they get notified, asynchronously with this thread
|
||||||
ArrayList<Like> likes = getAllLikesByPost(postId);
|
ArrayList<Like> likes = getAllLikesByPost(postId);
|
||||||
|
@ -669,7 +669,7 @@ public class SocialUtils {
|
||||||
new Date(), postid, user.getFullname(), user.getUserAvatarURL());
|
new Date(), postid, user.getFullname(), user.getUserAvatarURL());
|
||||||
Post thePost = null;
|
Post thePost = null;
|
||||||
try {
|
try {
|
||||||
logger.info("Attempting to read post with id: " +postid);
|
logger.debug("Attempting to read post with id: " +postid);
|
||||||
thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid);
|
thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid);
|
||||||
likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike);
|
likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -689,10 +689,10 @@ public class SocialUtils {
|
||||||
String escapedPostText = messageParser.getParsedMessage();
|
String escapedPostText = messageParser.getParsedMessage();
|
||||||
|
|
||||||
//if the user who liked this post is not the user who posted it notify the poster user (Post owner)
|
//if the user who liked this post is not the user who posted it notify the poster user (Post owner)
|
||||||
logger.info("The post creator is " + postOwnerId);
|
logger.debug("The post creator is " + postOwnerId);
|
||||||
if (! user.getUsername().equals(postOwnerId)) {
|
if (! user.getUsername().equals(postOwnerId)) {
|
||||||
resultNotifyLike = nm.notifyLikedPost(postOwnerId, postid, escapedPostText);
|
resultNotifyLike = nm.notifyLikedPost(postOwnerId, postid, escapedPostText);
|
||||||
logger.info("Like Notification to post creator added? " + resultNotifyLike);
|
logger.debug("Like Notification to post creator added? " + resultNotifyLike);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return likeCommitResult && resultNotifyLike;
|
return likeCommitResult && resultNotifyLike;
|
||||||
|
|
Loading…
Reference in New Issue