Compare commits
11 Commits
main
...
idm_integr
Author | SHA1 | Date |
---|---|---|
Ahmed Salah Tawfik Ibrahim | adfb010f61 | |
Ahmed Salah Tawfik Ibrahim | d560078141 | |
Alfredo Oliviero | 9c9ab7fdb4 | |
Alfredo Oliviero | fe44723739 | |
Alfredo Oliviero | 3e228a5df5 | |
Alfredo Oliviero | 1b4a284009 | |
Alfredo Oliviero | 24a65c548e | |
Alfredo Oliviero | b4a6cb5539 | |
Alfredo Oliviero | a2a1c03067 | |
Ahmed Salah Tawfik Ibrahim | c2dcfac36c | |
Alfredo Oliviero | 566364940c |
|
@ -1,5 +1,16 @@
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/macos,intellij,eclipse,visualstudiocode,linux
|
#
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,intellij,eclipse,visualstudiocode,linux
|
ignore_me
|
||||||
|
tomcat
|
||||||
|
|
||||||
|
target
|
||||||
|
.classpath
|
||||||
|
.visual
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
/**/.DS_Store
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/java,macos,linux,visualstudiocode,eclipse
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=java,macos,linux,visualstudiocode,eclipse
|
||||||
|
|
||||||
### Eclipse ###
|
### Eclipse ###
|
||||||
.metadata
|
.metadata
|
||||||
|
@ -67,118 +78,31 @@ local.properties
|
||||||
# Spring Boot Tooling
|
# Spring Boot Tooling
|
||||||
.sts4-cache/
|
.sts4-cache/
|
||||||
|
|
||||||
### Intellij ###
|
### Java ###
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
# Compiled class file
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
*.class
|
||||||
|
|
||||||
# User-specific stuff
|
# Log file
|
||||||
.idea/**/workspace.xml
|
*.log
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/**/usage.statistics.xml
|
|
||||||
.idea/**/dictionaries
|
|
||||||
.idea/**/shelf
|
|
||||||
|
|
||||||
# AWS User-specific
|
# BlueJ files
|
||||||
.idea/**/aws.xml
|
*.ctxt
|
||||||
|
|
||||||
# Generated files
|
# Mobile Tools for Java (J2ME)
|
||||||
.idea/**/contentModel.xml
|
.mtj.tmp/
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
# Package Files #
|
||||||
.idea/**/dataSources/
|
*.jar
|
||||||
.idea/**/dataSources.ids
|
*.war
|
||||||
.idea/**/dataSources.local.xml
|
*.nar
|
||||||
.idea/**/sqlDataSources.xml
|
*.ear
|
||||||
.idea/**/dynamic.xml
|
*.zip
|
||||||
.idea/**/uiDesigner.xml
|
*.tar.gz
|
||||||
.idea/**/dbnavigator.xml
|
*.rar
|
||||||
|
|
||||||
# Gradle
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
.idea/**/gradle.xml
|
hs_err_pid*
|
||||||
.idea/**/libraries
|
replay_pid*
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
cmake-build-*/
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
.idea/replstate.xml
|
|
||||||
|
|
||||||
# SonarLint plugin
|
|
||||||
.idea/sonarlint/
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
.idea/httpRequests
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
.idea/caches/build_file_checksums.ser
|
|
||||||
|
|
||||||
### Intellij Patch ###
|
|
||||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
|
||||||
|
|
||||||
# *.iml
|
|
||||||
# modules.xml
|
|
||||||
# .idea/misc.xml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# Sonarlint plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
|
||||||
.idea/**/sonarlint/
|
|
||||||
|
|
||||||
# SonarQube Plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
|
||||||
.idea/**/sonarIssues.xml
|
|
||||||
|
|
||||||
# Markdown Navigator plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
|
||||||
.idea/**/markdown-navigator.xml
|
|
||||||
.idea/**/markdown-navigator-enh.xml
|
|
||||||
.idea/**/markdown-navigator/
|
|
||||||
|
|
||||||
# Cache file creation bug
|
|
||||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
|
||||||
.idea/$CACHE_FILE$
|
|
||||||
|
|
||||||
# CodeStream plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
|
||||||
.idea/codestream.xml
|
|
||||||
|
|
||||||
# Azure Toolkit for IntelliJ plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
|
||||||
.idea/**/azureSettings.xml
|
|
||||||
|
|
||||||
### Linux ###
|
### Linux ###
|
||||||
*~
|
*~
|
||||||
|
@ -247,4 +171,4 @@ Temporary Items
|
||||||
.history
|
.history
|
||||||
.ionide
|
.ionide
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/macos,intellij,eclipse,visualstudiocode,linux
|
# End of https://www.toptal.com/developers/gitignore/api/java,macos,linux,visualstudiocode,eclipse
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
// Usare IntelliSense per informazioni sui possibili attributi.
|
||||||
|
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
|
||||||
|
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Debug Service (Attach)",
|
||||||
|
"projectName": "social-service",
|
||||||
|
"request": "attach",
|
||||||
|
"hostName": "localhost",
|
||||||
|
"port": 5005
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Current File",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "${file}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
|
"java.compile.nullAnalysis.mode": "automatic"
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
# Changelog for Hello World Service
|
# Changelog for Hello World Service
|
||||||
|
|
||||||
|
|
||||||
## [v1.0.0-SNAPSHOT]
|
## [v0.0.1-SNAPSHOT]
|
||||||
|
|
||||||
- First Version
|
- First Version
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
ARG JAVA_VERSION=11
|
||||||
|
ARG SMARTGEARS_VERSION=4.0.1-SNAPSHOT
|
||||||
|
|
||||||
|
#FROM d4science/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19
|
||||||
|
FROM hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19
|
||||||
|
#FROM smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19
|
||||||
|
ARG CONTAINER_INI="./docker/container.ini"
|
||||||
|
|
||||||
|
COPY ./docker/logback.xml /etc/
|
||||||
|
COPY ./docker/*.gcubekey /tomcat/lib
|
||||||
|
COPY ./target/social-service.war /tomcat/webapps/
|
||||||
|
COPY ${CONTAINER_INI} /etc/container.ini
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
|
@ -0,0 +1,179 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# set -x # uncomment to debug script
|
||||||
|
|
||||||
|
BUILD_VERSION=0.0.1-SNAPSHOT
|
||||||
|
SMARTGEARS_VERSION=4.0.1-SNAPSHOT
|
||||||
|
|
||||||
|
ACCEPTED_JAVA_VERSIONs=(11 17)
|
||||||
|
PORT=8080
|
||||||
|
DEBUG_PORT=5005
|
||||||
|
DEBUG=false
|
||||||
|
EXECUTE=false
|
||||||
|
TEST=false
|
||||||
|
COMPILE=true
|
||||||
|
|
||||||
|
JAVA_VERSION=11
|
||||||
|
NAME=social-service
|
||||||
|
CONTAINER_INI="./docker/container.ini"
|
||||||
|
IMAGE_VERSION=${BUILD_VERSION}-java${JAVA_VERSION}-smartgears${SMARTGEARS_VERSION}
|
||||||
|
|
||||||
|
PUSH_DOCKER=false
|
||||||
|
PUSH_HARBOR=false
|
||||||
|
LOGIN_HARBOR=false
|
||||||
|
|
||||||
|
BUILD_NAME=$NAME:$IMAGE_VERSION
|
||||||
|
|
||||||
|
SMARTGEAR_IMAGE=hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19
|
||||||
|
DOCKER_IMAGE_NAME=d4science/$BUILD_NAME
|
||||||
|
HARBOR_IMAGE_NAME=hub.dev.d4science.org/gcube/$BUILD_NAME
|
||||||
|
|
||||||
|
echo "BUILD_NAME=$BUILD_NAME"
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Help #
|
||||||
|
################################################################################
|
||||||
|
Help() {
|
||||||
|
# Display Help
|
||||||
|
echo "build, create and run in docker the identity manager service"
|
||||||
|
echo
|
||||||
|
echo "Syntax: buildDistribution [-n arg] [-p arg] [-j arg] [-d arg?] [-h]"
|
||||||
|
echo "options:"
|
||||||
|
echo "-s skip maven package"
|
||||||
|
echo "-t exec also maven tests"
|
||||||
|
echo "-n arg specifies the docker image name (default is identity-manager)."
|
||||||
|
echo "-p arg specifies the port to be exposed for the docker container to access the service (default $PORT)"
|
||||||
|
echo "-j arg specify java version (default is $JAVA_VERSION)"
|
||||||
|
echo " accepted version are: ${ACCEPTED_JAVA_VERSIONs[@]}"
|
||||||
|
echo "-e execute the image"
|
||||||
|
echo "-d arg? enable java debug mode for execution"
|
||||||
|
echo " arg is the debug port (default is $DEBUG_PORT)"
|
||||||
|
echo "-r push image to d4science harbo[r] (with login already done, or -l to login)"
|
||||||
|
echo "-l [l]ogin to d4science harbor"
|
||||||
|
echo "-u p[u]sh image to dockerhub (with docker login already done)"
|
||||||
|
echo "-c arg path of the file to deploy as container.ini (default ./docker/container.ini)"
|
||||||
|
echo "-h Print this Help."
|
||||||
|
echo
|
||||||
|
echo "to compile and push to harbor registry with a custom container.ini file: "
|
||||||
|
echo " ./buildImageAndStart.sh -r -m -l -c \"./docker/container-XXX.ini\" "
|
||||||
|
echo
|
||||||
|
echo "to debug locally: "
|
||||||
|
echo " ./buildImageAndStart.sh -d "
|
||||||
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
################################################################################
|
||||||
|
# Main program #
|
||||||
|
################################################################################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#OPTSTRING=":sn:p:d:j:?h"
|
||||||
|
OPTSTRING=":c:n:p:d:?jsmulrteh"
|
||||||
|
|
||||||
|
while getopts $OPTSTRING opt; do
|
||||||
|
# echo "Option -${opt} was triggered, Argument: ${OPTARG}"
|
||||||
|
case "${opt}" in
|
||||||
|
s) COMPILE=false && echo "compile $COMPILE" ;;
|
||||||
|
c)
|
||||||
|
CONTAINER_INI=${OPTARG}
|
||||||
|
echo "CONTAINER_INI: $CONTAINER_INI"
|
||||||
|
;;
|
||||||
|
m) MULTI_PLATFORM=true ;;
|
||||||
|
n) NAME=${OPTARG} ;;
|
||||||
|
p) PORT=${OPTARG} ;;
|
||||||
|
|
||||||
|
u) PUSH_DOCKER=true ;;
|
||||||
|
l) LOGIN_HARBOR=true ;;
|
||||||
|
r) PUSH_HARBOR=true ;;
|
||||||
|
|
||||||
|
t) TEST=true ;;
|
||||||
|
e) EXECUTE=true ;;
|
||||||
|
d)
|
||||||
|
DEBUG=true
|
||||||
|
DEBUG_PORT=${OPTARG}
|
||||||
|
EXECUTE=true ;
|
||||||
|
echo "debug enabled, port $DEBUG_PORT, execute $EXECUTE"
|
||||||
|
;;
|
||||||
|
j)
|
||||||
|
if [[ ${ACCEPTED_JAVA_VERSIONs[@]} =~ ${OPTARG} ]]; then
|
||||||
|
JAVA_VERSION=${OPTARG}
|
||||||
|
else
|
||||||
|
echo "Invalid java version" && echo "accepted version are: ${ACCEPTED_JAVA_VERSIONs[@]}" && exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
h) Help && exit 0 ;;
|
||||||
|
|
||||||
|
:)
|
||||||
|
# matched when an option that is expected to have an argument is passed without one
|
||||||
|
if [ ${OPTARG} = "d" ]; then
|
||||||
|
DEBUG=true
|
||||||
|
EXECUTE=true
|
||||||
|
echo "debug enabled, not default debug port $DEBUG_PORT, execute $EXECUTE"
|
||||||
|
else
|
||||||
|
# matched when an option that is expected to have an argument is passed without one
|
||||||
|
echo "Option -${OPTARG} requires an argument."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
?) # match any invalid option that is passed
|
||||||
|
echo "Invalid option: -${OPTARG}."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $COMPILE = true ]; then
|
||||||
|
if [ $TEST = false ]; then
|
||||||
|
mvn clean package -Dmaven.test.skip
|
||||||
|
else
|
||||||
|
mvn clean package
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "skipping mvn package"
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker pull $SMARTGEAR_IMAGE
|
||||||
|
|
||||||
|
if [ $MULTI_PLATFORM ]; then
|
||||||
|
|
||||||
|
echo "build multiplatform"
|
||||||
|
|
||||||
|
docker build -t $BUILD_NAME --build-arg="CONTAINER_INI=$CONTAINER_INI" --build-arg="JAVA_VERSION=${JAVA_VERSION}" --build-arg="SMARTGEARS_VERSION=${SMARTGEARS_VERSION}" --platform=linux/amd64,linux/arm64,linux/arm/v7 .
|
||||||
|
else
|
||||||
|
echo "build single platform"
|
||||||
|
docker build -t $BUILD_NAME --build-arg="CONTAINER_INI=$CONTAINER_INI" --build-arg="JAVA_VERSION=${JAVA_VERSION}" --build-arg="SMARTGEARS_VERSION=${SMARTGEARS_VERSION}" .
|
||||||
|
|
||||||
|
# docker manifest create hub.dev.d4science.org/gcube/$BUILD_NAME \
|
||||||
|
# hub.dev.d4science.org/gcube/$NAME-amd64-linux:$IMAGE_VERSION \
|
||||||
|
# hub.dev.d4science.org/gcube/$NAME-arm-linux:$IMAGE_VERSION \
|
||||||
|
# hub.dev.d4science.org/gcube/$NAME-arm-linux:$IMAGE_VERSION
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${PUSH_DOCKER} = true ]; then
|
||||||
|
docker tag $BUILD_NAME $DOCKER_IMAGE_NAME./
|
||||||
|
docker push $DOCKER_IMAGE_NAME
|
||||||
|
echo ">>> pushed on dockerhub the image $DOCKER_IMAGE_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${LOGIN_HARBOR} = true ]; then
|
||||||
|
./loginHarborHub.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $PUSH_HARBOR = true ]; then
|
||||||
|
echo ">>> PUSHING on hub.dev.d4science.org the image $HARBOR_IMAGE_NAME"
|
||||||
|
|
||||||
|
docker tag $BUILD_NAME $HARBOR_IMAGE_NAME
|
||||||
|
echo ">>> docker push $HARBOR_IMAGE_NAME"
|
||||||
|
docker push $HARBOR_IMAGE_NAME
|
||||||
|
echo ">>> pushed on hub.dev.d4science.org the image $HARBOR_IMAGE_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${EXECUTE} = true ]; then
|
||||||
|
if [ $DEBUG = true ]; then
|
||||||
|
docker run -p $PORT:8080 -p $DEBUG_PORT:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" $BUILD_NAME
|
||||||
|
else
|
||||||
|
docker run -p $PORT:8080 $BUILD_NAME
|
||||||
|
fi
|
||||||
|
fi
|
|
@ -0,0 +1 @@
|
||||||
|
mvn install:install-file -Dfile="social-service-model.jar" -DgroupId=org.gcube.social-networking -DartifactId=social-service-model -Dversion=2.0.0-SNAPSHOT -Dpackaging=jar
|
|
@ -0,0 +1,3 @@
|
||||||
|
container*.ini
|
||||||
|
!container.default.ini
|
||||||
|
*.gcubekey
|
|
@ -0,0 +1,25 @@
|
||||||
|
[node]
|
||||||
|
mode = offline
|
||||||
|
hostname = localhost
|
||||||
|
protocol= http
|
||||||
|
port = 8080
|
||||||
|
infrastructure = /gcube
|
||||||
|
authorizeChildrenContext = true
|
||||||
|
publicationFrequencyInSeconds = 60
|
||||||
|
|
||||||
|
[properties]
|
||||||
|
SmartGearsDistribution = 4.0.1-SNAPSHOT
|
||||||
|
SmartGearsDistributionBundle = UnBundled
|
||||||
|
|
||||||
|
[site]
|
||||||
|
country = it
|
||||||
|
location = pisa
|
||||||
|
|
||||||
|
[authorization]
|
||||||
|
factory = org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory
|
||||||
|
factory.endpoint = https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token
|
||||||
|
credentials.class = org.gcube.smartgears.security.SimpleCredentials
|
||||||
|
|
||||||
|
credentials.clientID =
|
||||||
|
credentials.secret =
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<configuration scan="true" debug="true">
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>Ï <pattern>%-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.gcube.service.idm" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.service.rest" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.smartgears" level="DEBUG" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<logger name="org.gcube" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.smartgears" level="TRACE" />
|
||||||
|
<logger name="org.gcube.smartgears.handlers" level="TRACE" />
|
||||||
|
<logger name="org.gcube.common.events" level="WARN" />
|
||||||
|
<logger name="org.gcube.data.publishing" level="ERROR" />
|
||||||
|
<logger name="org.gcube.documentstore" level="ERROR" />
|
||||||
|
<logger name="org.gcube.common.core.publisher.is.legacy" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG" />
|
||||||
|
-->
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<configuration scan="true" debug="true">
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>Ï <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.gcube.service.idm" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.service.rest" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.smartgears" level="DEBUG" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<logger name="org.gcube" level="DEBUG" />
|
||||||
|
<logger name="org.gcube.smartgears" level="TRACE" />
|
||||||
|
<logger name="org.gcube.smartgears.handlers" level="TRACE" />
|
||||||
|
<logger name="org.gcube.common.events" level="WARN" />
|
||||||
|
<logger name="org.gcube.data.publishing" level="ERROR" />
|
||||||
|
<logger name="org.gcube.documentstore" level="ERROR" />
|
||||||
|
<logger name="org.gcube.common.core.publisher.is.legacy" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG" />
|
||||||
|
-->
|
||||||
|
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<configuration scan="true" debug="true">
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>Ï
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.gcube" level="TRACE" />
|
||||||
|
<logger name="org.gcube.smartgears" level="TRACE" />
|
||||||
|
<logger name="org.gcube.smartgears.handlers" level="TRACE"/>
|
||||||
|
<logger name="org.gcube.common.events" level="WARN" />
|
||||||
|
<logger name="org.gcube.data.publishing" level="ERROR" />
|
||||||
|
<logger name="org.gcube.documentstore" level="ERROR" />
|
||||||
|
<logger name="org.gcube.common.core.publisher.is.legacy" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access" level="TRACE" />
|
||||||
|
<logger name="org.gcube.data.access.storagehub.handlers" level="ERROR"/>
|
||||||
|
|
||||||
|
<root level="ERROR">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
|
@ -0,0 +1,2 @@
|
||||||
|
${{adminId}}=social
|
||||||
|
${{adminPwd}}=social
|
|
@ -0,0 +1,5 @@
|
||||||
|
mvn clean package
|
||||||
|
docker build -t idm .
|
||||||
|
docker compose up -d --build --force-recreate
|
||||||
|
|
||||||
|
#docker run -it -d -p 9090:8080 --name idm idm
|
|
@ -2,22 +2,36 @@
|
||||||
<enunciate
|
<enunciate
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
|
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
|
||||||
<description package="org.gcube.acme.rest"/>
|
|
||||||
<api-classes>
|
<api-classes>
|
||||||
<include pattern="org.gcube.acme.rest.*" />
|
<include
|
||||||
<exclude pattern="org.gcube.acme.*" />
|
pattern="org.gcube.portal.social.networking.**"/>
|
||||||
|
<include
|
||||||
|
pattern="org.gcube.social_networking.socialnetworking.model.beans.**"/>
|
||||||
|
<exclude
|
||||||
|
pattern="org.gcube.portal.social.networking.ws.docs.DocsGenerator" />
|
||||||
</api-classes>
|
</api-classes>
|
||||||
<modules>
|
<modules>
|
||||||
|
<jackson1 disabled="true" />
|
||||||
<gwt-json-overlay disabled="true" />
|
<gwt-json-overlay disabled="true" />
|
||||||
<php-json-client disabled="true" />
|
<php-json-client disabled="true" />
|
||||||
<ruby-json-client disabled="true" />
|
<ruby-json-client disabled="true" />
|
||||||
<java-json-client disabled="true" />
|
<java-json-client disabled="true" />
|
||||||
|
<!-- <java-json-client jarName="social-service-client.jar" -->
|
||||||
|
<!-- bundleSourcesWithClasses="true" groupId="org.gcube.social-networking" -->
|
||||||
|
<!-- artifactId="auto-social-client" javac-source="1.8" javac-target="1.8"> -->
|
||||||
|
<!-- <package-conversions> -->
|
||||||
|
<!-- <convert -->
|
||||||
|
<!-- from="org.gcube.portal.social.networking.ws" -->
|
||||||
|
<!-- to="org.gcube.social.client" /> -->
|
||||||
|
<!-- </package-conversions> -->
|
||||||
|
<!-- </java-json-client> -->
|
||||||
<javascript-client disabled="true" />
|
<javascript-client disabled="true" />
|
||||||
<docs docsDir="${project.build.directory}" docsSubdir="api-docs" />
|
<docs docsDir="${project.build.directory}" docsSubdir="api-docs" />
|
||||||
<swagger basePath="/${project.artifactId}" />
|
<docs
|
||||||
<docs freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
|
freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
|
||||||
<additional-css
|
<additional-css
|
||||||
file="css/d4science_enunciate_custom.css" />
|
file="css/d4science_enunciate_custom.css" />
|
||||||
</docs>
|
</docs>
|
||||||
|
<swagger basePath="/rest" />
|
||||||
</modules>
|
</modules>
|
||||||
</enunciate>
|
</enunciate>
|
|
@ -0,0 +1,8 @@
|
||||||
|
name: ${artifactId}
|
||||||
|
group: ${groupId}
|
||||||
|
version: ${version}
|
||||||
|
description: ${description}
|
||||||
|
excludes:
|
||||||
|
- path: /docs.*
|
||||||
|
- path: /api-docs.*
|
||||||
|
- path: /guest
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE xml>
|
|
||||||
<application mode='online'>
|
|
||||||
<name>${project.artifactId}</name>
|
|
||||||
<group>${project.groupId}</group>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<description>${project.description}</description>
|
|
||||||
<exclude>/api-docs.*</exclude>
|
|
||||||
<exclude>/docs.*</exclude>
|
|
||||||
</application>
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||||
|
version="4.0">
|
||||||
|
<display-name>Social Service</display-name>
|
||||||
|
<description>
|
||||||
|
Gcube Social Service
|
||||||
|
</description>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>social-service</servlet-name>
|
||||||
|
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>jersey.config.server.provider.packages</param-name>
|
||||||
|
<param-value>org.gcube.social_networking.rest</param-value>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>jersey.config.server.provider.packages</param-name>
|
||||||
|
<param-value>
|
||||||
|
org.gcube.social_networking.mappers
|
||||||
|
</param-value>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>social-service</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
</web-app>
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
REGISTRY_URL="hub.dev.d4science.org"
|
||||||
|
#USERNAME="alfredo.oliviero"
|
||||||
|
echo "to obtain Harbor username and CLI secret:"
|
||||||
|
echo "https://hub.dev.d4science.org/ -> user profile -> CLI secret"
|
||||||
|
|
||||||
|
read -p "username:" USERNAME
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
read -s -p "CLI secret:" ACCESS_TOKEN
|
||||||
|
echo "$ACCESS_TOKEN" | docker login $REGISTRY_URL -u $USERNAME --password-stdin
|
||||||
|
unset ACCESS_TOKEN
|
278
pom.xml
278
pom.xml
|
@ -5,21 +5,33 @@
|
||||||
<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.social_networking</groupId>
|
<groupId>org.gcube.social_networking</groupId>
|
||||||
<artifactId>social-service</artifactId>
|
<artifactId>social-service</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>Social Service</name>
|
<name>Social Service</name>
|
||||||
<description>This is the social service</description>
|
<description>This is the social service</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- OPTIONAL. for authorization-control-library -->
|
||||||
|
<aspectj-plugin.version>1.14.0</aspectj-plugin.version>
|
||||||
|
|
||||||
<webappDirectory>
|
<webappDirectory>
|
||||||
${project.basedir}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF</webappDirectory>
|
${project.basedir}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF</webappDirectory>
|
||||||
<enunciate.version>2.14.0</enunciate.version>
|
<enunciate.version>2.14.0</enunciate.version>
|
||||||
<cassandra.driver.oss.version>4.13.0</cassandra.driver.oss.version>
|
<cassandra.driver.oss.version>4.13.0</cassandra.driver.oss.version>
|
||||||
|
|
||||||
|
<!-- only for serializers in example folder -->
|
||||||
|
<!-- <jackson.version>2.15.3</jackson.version> -->
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
|
@ -35,7 +47,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-smartgears-bom</artifactId>
|
<artifactId>gcube-smartgears-bom</artifactId>
|
||||||
<version>2.5.0</version>
|
<version>3.0.1-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -47,6 +59,7 @@
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -54,34 +67,44 @@
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>authorization-utils</artifactId>
|
|
||||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
|
||||||
<artifactId>jersey-media-multipart</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>jersey-container-servlet</artifactId>
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>jersey-container-servlet-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-smartgears-app</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common.portal</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>portal-manager</artifactId>
|
<artifactId>common-smartgears</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--must be provided -->
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-scope</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-scope-maps</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>authorization-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.social-networking</groupId>
|
<groupId>org.gcube.social-networking</groupId>
|
||||||
<artifactId>social-service-model</artifactId>
|
<artifactId>social-service-model</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.datastax.oss</groupId>
|
<groupId>com.datastax.oss</groupId>
|
||||||
<artifactId>java-driver-query-builder</artifactId>
|
<artifactId>java-driver-query-builder</artifactId>
|
||||||
|
@ -92,41 +115,28 @@
|
||||||
<artifactId>java-driver-mapper-runtime</artifactId>
|
<artifactId>java-driver-mapper-runtime</artifactId>
|
||||||
<version>${cassandra.driver.oss.version}</version>
|
<version>${cassandra.driver.oss.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.mail</groupId>
|
|
||||||
<artifactId>javax.mail</artifactId>
|
|
||||||
<version>1.5.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.core</groupId>
|
|
||||||
<artifactId>common-smartgears-app</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Added to support Java 11 JDK -->
|
<!-- <dependency>
|
||||||
<dependency>
|
<groupId>org.gcube.common</groupId>
|
||||||
<groupId>javax.xml.ws</groupId>
|
<artifactId>common-authorization</artifactId>
|
||||||
<artifactId>jaxws-api</artifactId>
|
</dependency> -->
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- END Added to support Java 11 JDK -->
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>common-smartgears</artifactId>
|
<artifactId>authorization-control-library</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common.portal</groupId>
|
||||||
|
<artifactId>portal-manager</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Required for Enunciate plugin -->
|
<!-- Required for Enunciate plugin -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.webcohesion.enunciate</groupId>
|
<groupId>com.webcohesion.enunciate</groupId>
|
||||||
|
@ -140,19 +150,23 @@
|
||||||
<version>${enunciate.version}</version>
|
<version>${enunciate.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<!-- only for serializers in example folder -->
|
||||||
<version>3.1.0</version>
|
<!-- <dependency>
|
||||||
<scope>provided</scope>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
</dependency>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency> -->
|
||||||
|
|
||||||
|
|
||||||
<!-- END Required for Enunciate plugin -->
|
<!-- END Required for Enunciate plugin -->
|
||||||
|
|
||||||
<!-- Test libraries -->
|
<!-- Test libraries -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -160,33 +174,118 @@
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/jakarta.mail/jakarta.mail-api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.mail</groupId>
|
||||||
|
<artifactId>jakarta.mail-api</artifactId>
|
||||||
|
<version>1.6.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.ehcache</groupId>
|
||||||
|
<artifactId>ehcache</artifactId>
|
||||||
|
<version>2.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.dvos</groupId>
|
||||||
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||||
|
<artifactId>aslsocial</artifactId>
|
||||||
|
<version>[1.8.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.servlet</groupId>
|
||||||
|
<artifactId>jakarta.servlet-api</artifactId>
|
||||||
|
<version>4.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.validation</groupId>
|
||||||
|
<artifactId>jakarta.validation-api</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>portal-service</artifactId>
|
||||||
|
<version>6.2.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.portal</groupId>
|
||||||
|
<artifactId>notifications-common-library</artifactId>
|
||||||
|
<version>[1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.socialnetworking</groupId>
|
||||||
|
<artifactId>social-data-search-client</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.socialnetworking</groupId>
|
||||||
|
<artifactId>social-util-library</artifactId>
|
||||||
|
<version>[1.0.1-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mortbay.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>6.1.22</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>storagehub-client-library</artifactId>
|
||||||
|
<!-- <version>2.0.0-SNAPSHOT</version> -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.idm</groupId>
|
||||||
|
<artifactId>idm-common-library</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.inject</groupId>
|
||||||
|
<artifactId>jersey-cdi2-se</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- idm client -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.idm</groupId>
|
||||||
|
<artifactId>idm-common-library</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.idm</groupId>
|
||||||
|
<artifactId>idm-client-library</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<!-- Sphinx plugin' -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>kr.motd.maven</groupId>
|
|
||||||
<artifactId>sphinx-maven-plugin</artifactId>
|
|
||||||
<version>2.10.0</version>
|
|
||||||
<configuration>
|
|
||||||
<outputDirectory>
|
|
||||||
${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
|
|
||||||
<builder>html</builder>
|
|
||||||
<configDirectory>${basedir}/docs</configDirectory>
|
|
||||||
<sourceDirectory>${basedir}/docs</sourceDirectory>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>process-resources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>generate</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- Enunciate Maven plugin -->
|
<plugins>
|
||||||
|
<!-- Enunciate Maven plugin
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.webcohesion.enunciate</groupId>
|
<groupId>com.webcohesion.enunciate</groupId>
|
||||||
<artifactId>enunciate-maven-plugin</artifactId>
|
<artifactId>enunciate-maven-plugin</artifactId>
|
||||||
|
@ -200,8 +299,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Copy Enunciate Documentation from your-application/api-docs
|
|
||||||
into your 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>
|
||||||
|
@ -227,7 +325,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
-->
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -237,6 +335,34 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- OPTIONAL. authorization-control-library: add this plugin if you
|
||||||
|
want to use gcube
|
||||||
|
authorization control funzionalities -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>aspectj-maven-plugin</artifactId>
|
||||||
|
<version>${aspectj-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<complianceLevel>${java.version}</complianceLevel>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
package org.gcube.social_networking;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
|
||||||
import org.gcube.smartgears.ApplicationManager;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*/
|
|
||||||
public class HelloWorldInitializator implements ApplicationManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger
|
|
||||||
*/
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(HelloWorldInitializator.class);
|
|
||||||
|
|
||||||
public static boolean initialised;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public synchronized void onInit() {
|
|
||||||
|
|
||||||
String context = SecretManagerProvider.instance.get().getContext();
|
|
||||||
|
|
||||||
logger.trace(
|
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Hello World Service is Starting on context {}\n"
|
|
||||||
+ "-------------------------------------------------------",
|
|
||||||
context);
|
|
||||||
|
|
||||||
// ApplicationContext applicationContext = ContextProvider.get();
|
|
||||||
// String helloWorldEServiceID = applicationContext.id();
|
|
||||||
|
|
||||||
logger.trace(
|
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Hello World Service Started Successfully on context {}\n"
|
|
||||||
+ "-------------------------------------------------------",
|
|
||||||
context);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public synchronized void onShutdown(){
|
|
||||||
|
|
||||||
String context = SecretManagerProvider.instance.get().getContext();
|
|
||||||
|
|
||||||
logger.trace(
|
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Hello World Service is Stopping on context {}\n"
|
|
||||||
+ "-------------------------------------------------------",
|
|
||||||
context);
|
|
||||||
|
|
||||||
|
|
||||||
logger.trace(
|
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Hello World Service Stopped Successfully on context {}\n"
|
|
||||||
+ "-------------------------------------------------------",
|
|
||||||
context);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.gcube.social_networking;
|
|
||||||
|
|
||||||
import javax.ws.rs.ApplicationPath;
|
|
||||||
|
|
||||||
import org.gcube.acme.rest.HelloWorld;
|
|
||||||
import org.gcube.smartgears.annotations.ManagedBy;
|
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*/
|
|
||||||
@ApplicationPath("/")
|
|
||||||
@ManagedBy(HelloWorldInitializator.class)
|
|
||||||
public class ResourceInitializer extends ResourceConfig {
|
|
||||||
|
|
||||||
public ResourceInitializer() {
|
|
||||||
packages(HelloWorld.class.getPackage().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package org.gcube.social_networking;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.idm.client.IdmClientFactory;
|
||||||
|
import org.gcube.idm.common.is.IsServerConfig;
|
||||||
|
import org.gcube.smartgears.ApplicationManager;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.configuration.Mode;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.utils.InfrastructureUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ahmed Ibrahim
|
||||||
|
*/
|
||||||
|
public class SocialServiceApplicationManager implements ApplicationManager {
|
||||||
|
Logger logger = LoggerFactory.getLogger(SocialServiceApplicationManager.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onInit() {
|
||||||
|
Secret isSecret = InfrastructureUtils.getSecretForInfrastructure();
|
||||||
|
IdmClientFactory factory = IdmClientFactory.getSingleton();
|
||||||
|
factory.setSecret(isSecret);
|
||||||
|
|
||||||
|
String baseurl = "http://146.48.85.179:9999/idm-service/";
|
||||||
|
IsServerConfig config = new IsServerConfig(baseurl);
|
||||||
|
factory.setConfig(config);
|
||||||
|
|
||||||
|
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
||||||
|
|
||||||
|
logger.debug("init called in offline mode");
|
||||||
|
} else {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
if (secret != null) {
|
||||||
|
logger.debug("init called in context {}", secret.getContext());
|
||||||
|
} else {
|
||||||
|
logger.debug("init called in null context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//setting cassandra connection
|
||||||
|
CassandraConnection conn = CassandraConnection.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onShutdown() {
|
||||||
|
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
||||||
|
logger.debug("shutDown called in offline mode");
|
||||||
|
} else {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
if (secret != null) {
|
||||||
|
logger.debug("shutDown called in context {}", secret.getContext());
|
||||||
|
} else {
|
||||||
|
logger.debug("shutDown called in null context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.gcube.social_networking.caches;
|
||||||
|
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Ehcache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle caches via Ehcache
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class CachesManager {
|
||||||
|
|
||||||
|
private static CacheManager cacheManager;
|
||||||
|
public static final CachesManager singleton = new CachesManager();
|
||||||
|
|
||||||
|
// the following caches are declared within the ehcache.xml (no default is available)
|
||||||
|
public static final String SOCIAL_NETWORKING_SITES_CACHE = "social_networking_site_cache";
|
||||||
|
public static final String USERS_CACHE = "users_cache";
|
||||||
|
public static final String GROUPS_CACHE = "groups_cache";
|
||||||
|
|
||||||
|
private CachesManager(){
|
||||||
|
cacheManager = CacheManager.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ehcache getCache(String name){
|
||||||
|
return cacheManager.getEhcache(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
super.finalize();
|
||||||
|
cacheManager.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.gcube.social_networking.caches;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.Element;
|
||||||
|
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class GroupsCache {
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GroupsCache.class);
|
||||||
|
private static GroupsCache singleton = new GroupsCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor: build the cache
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GroupsCache(){
|
||||||
|
|
||||||
|
logger.debug("Building cache");
|
||||||
|
CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the singleton object
|
||||||
|
*/
|
||||||
|
public static GroupsCache getSingleton() {
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an entry
|
||||||
|
* @param groupId
|
||||||
|
* @return user associated to the user
|
||||||
|
*/
|
||||||
|
public GCubeGroup getGroup(long groupId){
|
||||||
|
Ehcache groupsCache = CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
||||||
|
if(groupsCache.get(groupId) != null)
|
||||||
|
return (GCubeGroup) groupsCache.get(groupId).getObjectValue();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save an entry into the cache
|
||||||
|
* @param id
|
||||||
|
* @param group
|
||||||
|
*/
|
||||||
|
public void pushEntry(long id, GCubeGroup group){
|
||||||
|
Ehcache groupsCache = CachesManager.getCache(CachesManager.GROUPS_CACHE);
|
||||||
|
groupsCache.put(new Element(id, group));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,262 @@
|
||||||
|
package org.gcube.social_networking.caches;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
import org.gcube.common.portal.GCubePortalConstants;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.idm.common.is.InfrastrctureServiceClient;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.utils.InfrastructureUtils;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a notification needs to be sent, this class offers utility to discover (starting from the scope)
|
||||||
|
* the site information needed to build up the SocialNetworkingSite object (which, for instance, contains the
|
||||||
|
* portal email).
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class SocialNetworkingSiteFinder {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocialNetworkingSiteFinder.class);
|
||||||
|
|
||||||
|
private static final String EMAIL_SENDER_SITE_CUSTOM_FIELD = "Emailsender";
|
||||||
|
private static final String CATEGORY = "Portal";
|
||||||
|
|
||||||
|
// these properties could be overwritten by the ones read from config.properties
|
||||||
|
private static String PROD_FALLBACK_GATEWAY = "D4Science.org Gateway";
|
||||||
|
private static String DEV_FALLBACK_GATEWAY = "gCube Snapshot Gateway";
|
||||||
|
private static String PREPROD_FALLBACK_GATEWAY = "D4Science Preproduction Gateway";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton object
|
||||||
|
*/
|
||||||
|
private static SocialNetworkingSiteFinder singleton = new SocialNetworkingSiteFinder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the singleton instance
|
||||||
|
*/
|
||||||
|
private SocialNetworkingSiteFinder(){
|
||||||
|
|
||||||
|
// read fallback properties
|
||||||
|
try{
|
||||||
|
logger.debug("Trying to read config.properties");
|
||||||
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
InputStream input = classLoader.getResourceAsStream("config.properties");
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(input);
|
||||||
|
PROD_FALLBACK_GATEWAY = properties.getProperty("PROD_FALLBACK_GATEWAY");
|
||||||
|
DEV_FALLBACK_GATEWAY = properties.getProperty("DEV_FALLBACK_GATEWAY");
|
||||||
|
PREPROD_FALLBACK_GATEWAY = properties.getProperty("PREPROD_FALLBACK_GATEWAY");
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.warn("Failed to read config.properties...", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the singleton instance
|
||||||
|
*/
|
||||||
|
public static SocialNetworkingSiteFinder getInstance(){
|
||||||
|
|
||||||
|
return singleton;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the SocialNetworkingSite given the scope
|
||||||
|
* @param scope
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static SocialNetworkingSite getSocialNetworkingSiteFromScope(String scope){
|
||||||
|
|
||||||
|
Ehcache socialSitesCache = CachesManager.getCache(CachesManager.SOCIAL_NETWORKING_SITES_CACHE);
|
||||||
|
|
||||||
|
if(scope == null || scope.isEmpty())
|
||||||
|
throw new IllegalArgumentException("Scope cannot be null/empty");
|
||||||
|
|
||||||
|
if(socialSitesCache != null && socialSitesCache.get(scope) != null)
|
||||||
|
return (SocialNetworkingSite) socialSitesCache.get(scope).getObjectValue();
|
||||||
|
else{
|
||||||
|
SocialNetworkingSite site = discoverSite(scope);
|
||||||
|
if(socialSitesCache != null && site != null)
|
||||||
|
socialSitesCache.put(new Element(scope, site));
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discover the site for this scope
|
||||||
|
* @param scope
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static SocialNetworkingSite discoverSite(String scope) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
logger.info("Requested site for scope " + scope);
|
||||||
|
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
long groupId = groupManager.getGroupIdFromInfrastructureScope(scope);
|
||||||
|
|
||||||
|
GCubeGroup matchingGateway = null;
|
||||||
|
|
||||||
|
if(groupManager.isVRE(groupId)){
|
||||||
|
|
||||||
|
// get the Virtual groups for the groupid related to the scope
|
||||||
|
|
||||||
|
List<VirtualGroup> virtualGroupsOfGroup = groupManager.getVirtualGroups(groupId);
|
||||||
|
|
||||||
|
if(virtualGroupsOfGroup == null || virtualGroupsOfGroup.isEmpty())
|
||||||
|
throw new Exception("It seems that the VRE is not linked to any VirtualGroups");
|
||||||
|
|
||||||
|
// get the gateways
|
||||||
|
List<GCubeGroup> gateways = groupManager.getGateways();
|
||||||
|
|
||||||
|
if(gateways == null || gateways.isEmpty())
|
||||||
|
throw new Exception("It seems there is no gateway here!");
|
||||||
|
|
||||||
|
logger.info("Retrieved Gateways are " + gateways);
|
||||||
|
|
||||||
|
// now, retrieve the virtual groups for each gateway and stop when a VG matches with one of the group
|
||||||
|
// then, it is the gateway of interest
|
||||||
|
ext_loop: for (GCubeGroup gateway : gateways) {
|
||||||
|
List<VirtualGroup> gatewayVirtualGroups = groupManager.getVirtualGroups(gateway.getGroupId());
|
||||||
|
if(gatewayVirtualGroups != null && !gatewayVirtualGroups.isEmpty()){
|
||||||
|
for (VirtualGroup gatewayVirtualGroup : gatewayVirtualGroups) {
|
||||||
|
if(virtualGroupsOfGroup.contains(gatewayVirtualGroup)){
|
||||||
|
logger.debug("Matching gateway for scope " + scope + " is " + gateway);
|
||||||
|
matchingGateway = gateway;
|
||||||
|
break ext_loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
List<GCubeGroup> gateways = groupManager.getGateways();
|
||||||
|
|
||||||
|
// vo and root vo cases are treated separately: in production environment services.d4science.org is used, instead
|
||||||
|
// in dev next.d4science.org is used TODO better way...
|
||||||
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
String rootContext = "/"+ctx.container().configuration().infrastructure();
|
||||||
|
String matchingGatewayName = null;
|
||||||
|
if(isDevOrPreprod(rootContext)){
|
||||||
|
matchingGatewayName = DEV_FALLBACK_GATEWAY;
|
||||||
|
}else{
|
||||||
|
matchingGatewayName = PROD_FALLBACK_GATEWAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the matching one among the gateways
|
||||||
|
for (GCubeGroup gateway : gateways) {
|
||||||
|
if(gateway.getGroupName().equals(matchingGatewayName)){
|
||||||
|
matchingGateway = gateway;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matchingGateway == null && isDevOrPreprod(rootContext)){
|
||||||
|
|
||||||
|
logger.warn("Checking if it is the preprod environment");
|
||||||
|
matchingGatewayName = PREPROD_FALLBACK_GATEWAY;
|
||||||
|
// find the matching one among the gateways
|
||||||
|
for (GCubeGroup gateway : gateways) {
|
||||||
|
if(gateway.getGroupName().equals(matchingGatewayName)){
|
||||||
|
matchingGateway = gateway;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matchingGateway == null){
|
||||||
|
logger.warn("There is no gateway for such scope. Returning null");
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
String siteName = matchingGateway.getGroupName();
|
||||||
|
String emailSender = (String)groupManager.readCustomAttr(matchingGateway.getGroupId(), EMAIL_SENDER_SITE_CUSTOM_FIELD);
|
||||||
|
emailSender = emailSender.replace("\"", ""); //this is because otherwise it would contains double quotes and postfix would use it as first part before @ e.g. senderEmail="aginfra@d4science.org"@d4science.org
|
||||||
|
String siteLandingPagePath = GCubePortalConstants.PREFIX_GROUP_URL + matchingGateway.getFriendlyURL();
|
||||||
|
String siteUrl = discoverHostOfServiceEndpoint(siteName);
|
||||||
|
SocialNetworkingSite site = new SocialNetworkingSite(siteName, emailSender, siteUrl, siteLandingPagePath);
|
||||||
|
logger.info("Site is " + site);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to determine the SocialNetworkingSite for scope " + scope, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDevOrPreprod(String rootContext) {
|
||||||
|
return (rootContext.equals("/gcube") || rootContext.equals("/pred4s"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve endpoint host from IS for this gateway
|
||||||
|
* @return the host for the gateway
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static String discoverHostOfServiceEndpoint(String gatewayName){
|
||||||
|
|
||||||
|
// String RUNTIME_RESOURCE_NAME = "identity-manager";
|
||||||
|
// String CATEGORY = "org.gcube.auth";
|
||||||
|
// String END_POINT_NAME = "d4science";
|
||||||
|
// boolean IS_ROOT_SERVICE = true;
|
||||||
|
|
||||||
|
Secret secret = InfrastructureUtils.getSecretForInfrastructure();
|
||||||
|
List<ServiceEndpoint> resources = InfrastrctureServiceClient.getEndopintsFromIS(gatewayName, CATEGORY, true, secret);
|
||||||
|
ServiceEndpoint serviceEndpoint = resources.get(0);
|
||||||
|
String host = "https://" + serviceEndpoint.profile().runtime().hostedOn();
|
||||||
|
logger.info("Gateway host is " + host);
|
||||||
|
|
||||||
|
// IsServerConfig cfg = InfrastrctureServiceClient.serviceConfigFromIS(gatewayName, CATEGORY,
|
||||||
|
// END_POINT_NAME, IS_ROOT_SERVICE, current_secret);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// String currentScope = ScopeProvider.instance.get();
|
||||||
|
// ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
// ScopeProvider.instance.set("/"+ctx.container().configuration().infrastructure());
|
||||||
|
// String host = null;
|
||||||
|
// try{
|
||||||
|
|
||||||
|
// SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
// query.addCondition("$resource/Profile/Name/text() eq '"+ gatewayName +"'");
|
||||||
|
// query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
|
||||||
|
// DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
|
// List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
|
// for (ServiceEndpoint serviceEndpoint : toReturn) {
|
||||||
|
// host = "https://" + serviceEndpoint.profile().runtime().hostedOn();
|
||||||
|
// logger.info("Gateway host is " + host);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }catch(Exception e){
|
||||||
|
// logger.error("Error while retrieving host for the gateway " + gatewayName);
|
||||||
|
// }finally{
|
||||||
|
// ScopeProvider.instance.set(currentScope);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return host;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package org.gcube.social_networking.caches;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Ehcache;
|
||||||
|
import net.sf.ehcache.Element;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This cache will store GCubeUser of the users of the infrastructure as couples {user-id, user screename}
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class UsersCache{
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UsersCache.class);
|
||||||
|
private static UsersCache singleton = new UsersCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor: build the cache
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private UsersCache(){
|
||||||
|
|
||||||
|
// create a thread to build the cache
|
||||||
|
new Thread(){
|
||||||
|
public void run() {
|
||||||
|
try{
|
||||||
|
logger.debug("Fetching users and putting them into cache");
|
||||||
|
Ehcache usersCache = CachesManager.getCache(CachesManager.USERS_CACHE);
|
||||||
|
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
List<GCubeUser> users = userManager.listUsersByGroup(groupManager.getGroupIdFromInfrastructureScope("/"+ctx.container().configuration().infrastructure()));
|
||||||
|
for (GCubeUser gCubeUser : users) {
|
||||||
|
usersCache.put(new Element(gCubeUser.getUserId(), gCubeUser));
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve user's usernames. Other users will be discovered later on", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the singleton object
|
||||||
|
*/
|
||||||
|
public static UsersCache getSingleton() {
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an entry
|
||||||
|
* @param userId
|
||||||
|
* @return user associated to the user
|
||||||
|
*/
|
||||||
|
public GCubeUser getUser(long userId){
|
||||||
|
Ehcache usersCache = CachesManager.getCache(CachesManager.USERS_CACHE);
|
||||||
|
if(usersCache.get(userId) != null)
|
||||||
|
return (GCubeUser) usersCache.get(userId).getObjectValue();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save an entry into the cache
|
||||||
|
* @param id
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
public void pushEntry(long id, GCubeUser user){
|
||||||
|
Ehcache usersCache = CachesManager.getCache(CachesManager.USERS_CACHE);
|
||||||
|
usersCache.put(new Element(id, user));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.gcube.social_networking.liferay.ws;
|
||||||
|
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.ws.LiferayWSGroupManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that builds a (singleton) GroupManagerWS object.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class GroupManagerWSBuilder {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(GroupManagerWSBuilder.class);
|
||||||
|
private static GroupManagerWSBuilder singleton = new GroupManagerWSBuilder();
|
||||||
|
private static GroupManager groupManagerWs;
|
||||||
|
|
||||||
|
private GroupManagerWSBuilder(){
|
||||||
|
|
||||||
|
logger.debug("Building GroupManager please wait");
|
||||||
|
|
||||||
|
try{
|
||||||
|
groupManagerWs = new LiferayWSGroupManager(
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getUser(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPassword(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getHost(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getSchema(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPort());
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to build the GroupManager. ", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("GroupManager instance built");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user manager instance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public GroupManager getGroupManager(){
|
||||||
|
return groupManagerWs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupManagerWSBuilder getInstance(){
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,157 @@
|
||||||
|
package org.gcube.social_networking.liferay.ws;
|
||||||
|
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
import java.rmi.ServerException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.idm.common.is.InfrastrctureServiceClient;
|
||||||
|
import org.gcube.idm.common.is.IsServerConfig;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.social_networking.utils.InfrastructureUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.NotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a singleton bean instantiated at service start up. It contains
|
||||||
|
* the credentials of the user who is allowed to perform calls to Liferay.
|
||||||
|
* Its credentials are looked up from the infrastructure.
|
||||||
|
*
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class LiferayJSONWsCredentials {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(LiferayJSONWsCredentials.class);
|
||||||
|
|
||||||
|
// the singleton obj
|
||||||
|
private static LiferayJSONWsCredentials singleton = new LiferayJSONWsCredentials();
|
||||||
|
|
||||||
|
// properties that it contains
|
||||||
|
private String host;
|
||||||
|
private String schema;
|
||||||
|
private String user;
|
||||||
|
private String password;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
// The token of the user used to send notifications/messages when an application
|
||||||
|
// token is provided. (will be read from web.xml)
|
||||||
|
private String notifierUserToken;
|
||||||
|
|
||||||
|
// Service endpoint properties
|
||||||
|
|
||||||
|
private final static String RUNTIME_RESOURCE_NAME = "D4Science Infrastructure Gateway";
|
||||||
|
private final static String CATEGORY = "Portal";
|
||||||
|
private final static String END_POINT_NAME = "JSONWSUser";
|
||||||
|
private final static boolean IS_ROOT_SERVICE = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor
|
||||||
|
*/
|
||||||
|
private LiferayJSONWsCredentials() {
|
||||||
|
logger.debug("Building LiferayJSONWsCredentials object");
|
||||||
|
loadNotifierToken();
|
||||||
|
lookupPropertiesFromIs();
|
||||||
|
logger.debug("LiferayJSONWsCredentials object built");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the token of the notifier user
|
||||||
|
*/
|
||||||
|
private void loadNotifierToken() {
|
||||||
|
try {
|
||||||
|
notifierUserToken = ServletContextClass.getNotifierToken();
|
||||||
|
logger.debug("Token read " + notifierUserToken.substring(0, 5) + "*********************");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to read notifier user token!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the properties from the infrastructure
|
||||||
|
*/
|
||||||
|
private void lookupPropertiesFromIs() {
|
||||||
|
Secret secret = InfrastructureUtils.getSecretForInfrastructure();
|
||||||
|
|
||||||
|
IsServerConfig cfg;
|
||||||
|
try {
|
||||||
|
cfg = InfrastrctureServiceClient.serviceConfigFromIS(RUNTIME_RESOURCE_NAME, CATEGORY,
|
||||||
|
END_POINT_NAME, IS_ROOT_SERVICE, secret);
|
||||||
|
} catch (NotFoundException | ServerException e) {
|
||||||
|
logger.error("Unable to retrieve such service endpoint information!", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
host = cfg.getServerUrl();
|
||||||
|
schema = cfg.getProperty("schema");
|
||||||
|
user = cfg.getProperty("username");
|
||||||
|
|
||||||
|
password = cfg.getProperty("password");
|
||||||
|
|
||||||
|
// TODO: check if needs to be decrypted
|
||||||
|
// password = StringEncrypter.getEncrypter().decrypt(passsword);
|
||||||
|
|
||||||
|
port = Integer.valueOf(cfg.getProperty("port"));
|
||||||
|
|
||||||
|
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 LiferayJSONWsCredentials getSingleton() {
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotifierUserToken() {
|
||||||
|
return notifierUserToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "LiferayJSONWsCredentials [host=" + host + ", schema=" + schema
|
||||||
|
+ ", user=" + user + ", password=" + password + ", port="
|
||||||
|
+ port + ", notifierUserToken=" + notifierUserToken + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.gcube.social_networking.liferay.ws;
|
||||||
|
|
||||||
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.ws.LiferayWSRoleManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that builds a (singleton) UserManagerWS object.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class RoleManagerWSBuilder {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(UserManagerWSBuilder.class);
|
||||||
|
private static RoleManagerWSBuilder singleton = new RoleManagerWSBuilder();
|
||||||
|
private RoleManager roleManagerWs;
|
||||||
|
|
||||||
|
private RoleManagerWSBuilder(){
|
||||||
|
|
||||||
|
logger.debug("Building UserManager please wait");
|
||||||
|
|
||||||
|
try{
|
||||||
|
roleManagerWs = new LiferayWSRoleManager(
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getUser(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPassword(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getHost(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getSchema(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPort());
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to build the UserManager. ", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("UserManager instance built");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the role manager instance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public RoleManager getRoleManager(){
|
||||||
|
return roleManagerWs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RoleManagerWSBuilder getInstance(){
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.social_networking.liferay.ws;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loaded at start up. This class performs some init - to be done once - operations.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class ServletContextClass implements ServletContextListener
|
||||||
|
{
|
||||||
|
|
||||||
|
private static String notifierToken;
|
||||||
|
|
||||||
|
public void contextInitialized(ServletContextEvent arg0) {
|
||||||
|
|
||||||
|
// get the token and save it
|
||||||
|
notifierToken = arg0.getServletContext().getInitParameter("NOTIFIER_TOKEN");
|
||||||
|
|
||||||
|
// start the thread to retrieve infrastructure users (which is, build up the singleton)
|
||||||
|
//UsersCache.getSingleton();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent arg0){
|
||||||
|
// on shutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the token of the Liferay's User.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getNotifierToken() {
|
||||||
|
return notifierToken;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.gcube.social_networking.liferay.ws;
|
||||||
|
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.ws.LiferayWSUserManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that builds a (singleton) UserManagerWS object.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class UserManagerWSBuilder {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(UserManagerWSBuilder.class);
|
||||||
|
private static UserManagerWSBuilder singleton = new UserManagerWSBuilder();
|
||||||
|
private UserManager userManagerWs;
|
||||||
|
|
||||||
|
private UserManagerWSBuilder(){
|
||||||
|
|
||||||
|
logger.debug("Building UserManager please wait");
|
||||||
|
|
||||||
|
try{
|
||||||
|
userManagerWs = new LiferayWSUserManager(
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getUser(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPassword(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getHost(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getSchema(),
|
||||||
|
LiferayJSONWsCredentials.getSingleton().getPort());
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to build the UserManager. ", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("UserManager instance built");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user manager instance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UserManager getUserManager(){
|
||||||
|
return userManagerWs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserManagerWSBuilder getInstance(){
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package org.gcube.social_networking.mappers;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.utils.ResponseBean;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.ForbiddenException;
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import jakarta.ws.rs.core.Response.Status;
|
||||||
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alfredo Oliviero (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
public class ForbiddenExceptionMapper implements ExceptionMapper<ForbiddenException> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response toResponse(ForbiddenException exception) {
|
||||||
|
|
||||||
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
String exceptionMessage = exception.getMessage();
|
||||||
|
|
||||||
|
ResponseBean responseBean = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (exception.getCause() != null) {
|
||||||
|
exceptionMessage = exception.getCause().getMessage();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptionMessage = exception.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||||
|
|
||||||
|
if (WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
||||||
|
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
||||||
|
Object entity = gotResponse.getEntity();
|
||||||
|
if (entity != null && ResponseBean.class.isAssignableFrom(entity.getClass())) {
|
||||||
|
responseBean = (ResponseBean) entity;
|
||||||
|
}
|
||||||
|
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseBean == null) {
|
||||||
|
responseBean = new ResponseBean();
|
||||||
|
}
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(exceptionMessage);
|
||||||
|
// responseBean.set
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).type(mediaType).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.gcube.social_networking.mappers;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.utils.ResponseBean;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import jakarta.ws.rs.core.Response.Status;
|
||||||
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
public class IDMExceptionMapper implements ExceptionMapper<Exception> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response toResponse(Exception exception) {
|
||||||
|
|
||||||
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
String exceptionMessage = exception.getMessage();
|
||||||
|
|
||||||
|
ResponseBean responseBean = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (exception.getCause() != null) {
|
||||||
|
exceptionMessage = exception.getCause().getMessage();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptionMessage = exception.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||||
|
|
||||||
|
if (WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
||||||
|
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
||||||
|
Object entity = gotResponse.getEntity();
|
||||||
|
if (entity != null && ResponseBean.class.isAssignableFrom(entity.getClass())) {
|
||||||
|
responseBean = (ResponseBean) entity;
|
||||||
|
}
|
||||||
|
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseBean == null) {
|
||||||
|
responseBean = new ResponseBean();
|
||||||
|
}
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(exceptionMessage);
|
||||||
|
// responseBean.set
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).type(mediaType).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,26 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
@Path("attachments")
|
|
||||||
@ResourceGroup("Attachments APIs")
|
|
||||||
@ResourceLabel("Attachments APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Attachments {
|
|
||||||
@POST
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveAttachmentEntry(Attachment toSave) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Path("comments")
|
|
||||||
@ResourceGroup("Comments APIs")
|
|
||||||
@ResourceLabel("Comments APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Comments {
|
|
||||||
@POST
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void addComment(Comment comment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void readComment(@PathParam("id") String id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{id}")
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void editComment(@PathParam("id") String id, Comment comment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void deleteComment(@PathParam("id") String id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//the following two methods had vreid why?
|
|
||||||
@POST
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveHashTagsComment(@PathParam("id") String commentId, List<String> hashtags) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void deleteHashTagsComment(@PathParam("id") String commentId, List<String> hashtags) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,94 +1,26 @@
|
||||||
package org.gcube.social_networking.rest;
|
package org.gcube.social_networking.rest;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import org.gcube.smartgears.annotations.ManagedBy;
|
||||||
import javax.ws.rs.DELETE;
|
import org.gcube.social_networking.SocialServiceApplicationManager;
|
||||||
import javax.ws.rs.DefaultValue;
|
import org.slf4j.Logger;
|
||||||
import javax.ws.rs.GET;
|
import org.slf4j.LoggerFactory;
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
import jakarta.ws.rs.GET;
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
import jakarta.ws.rs.Path;
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
import jakarta.ws.rs.Produces;
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
|
||||||
import org.gcube.social_networking.server.CassandraConnection;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.CommentIDNotFoundException;
|
|
||||||
|
|
||||||
@Path("comments")
|
@Path("test")
|
||||||
@ResourceGroup("Comments APIs")
|
@ManagedBy(SocialServiceApplicationManager.class)
|
||||||
@ResourceLabel("Comments APIs")
|
|
||||||
@RequestHeaders ({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class HelloWorld {
|
public class HelloWorld {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(HelloWorld.class);
|
||||||
@POST
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void addComment(Comment comment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}")
|
@Path("/")
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public void readComment(@PathParam("id") String id) {
|
public String test(){
|
||||||
|
logger.info("/social-service/test/ here");
|
||||||
|
return "{\"result\":\"funziona!!!\"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{id}")
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void editComment(@PathParam("id") String id, Comment comment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void deleteComment(@PathParam("id") String id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Produces("application/json;charset=UTF-8")
|
|
||||||
@Consumes("application/json;charset=UTF-8")
|
|
||||||
public String create(String json) {
|
|
||||||
//Greeting g = new Greeting();
|
|
||||||
//return g.create(json);
|
|
||||||
return "{\"text\":\"hi\"}";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{greeting_name}")
|
|
||||||
@Consumes("application/json;charset=UTF-8")
|
|
||||||
@Produces("application/json;charset=UTF-8")
|
|
||||||
@StatusCodes ({
|
|
||||||
@ResponseCode ( code = 200, condition = "The greeting has been updated successfully.")
|
|
||||||
})
|
|
||||||
// @AuthorizationControl(allowedRoles={"boss"}, exception=NotAuthorizedException.class)
|
|
||||||
public String update(@PathParam("greeting_name") String name, String json) {
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{greeting_name}")
|
|
||||||
@StatusCodes ({
|
|
||||||
@ResponseCode ( code = 204, condition = "The item has been deleted successfully."),
|
|
||||||
@ResponseCode ( code = 404, condition = "The item was not found.")
|
|
||||||
})
|
|
||||||
public String delete(@PathParam("greeting_name") String name) {
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.gcube.social_networking.rest;
|
package org.gcube.social_networking.rest;
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import jakarta.ws.rs.core.Response.Status;
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
||||||
import javax.ws.rs.ext.Provider;
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
package org.gcube.social_networking.rest;
|
||||||
|
|
||||||
|
import java.rmi.ServerException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.idm.client.IdmClientFactory;
|
||||||
|
import org.gcube.idm.client.IdmMeClient;
|
||||||
|
import org.gcube.idm.client.IdmUsersClient;
|
||||||
|
import org.gcube.idm.client.SearchUsersParams;
|
||||||
|
import org.gcube.idm.client.model.UserInfo;
|
||||||
|
import org.gcube.idm.common.models.IdmFullUser;
|
||||||
|
import org.gcube.idm.common.models.IdmUser;
|
||||||
|
import org.gcube.social_networking.utils.InfrastructureUtils;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.DefaultValue;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.PathParam;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.QueryParam;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/idm")
|
||||||
|
@RequestHeaders({
|
||||||
|
@RequestHeader(name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
||||||
|
})
|
||||||
|
public class IdmRest {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/me")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response test() throws ServerException {
|
||||||
|
|
||||||
|
IdmClientFactory factory = IdmClientFactory.getSingleton();
|
||||||
|
|
||||||
|
String token = InfrastructureUtils.getAccessToken();
|
||||||
|
|
||||||
|
IdmMeClient client = factory.meClient(token);
|
||||||
|
|
||||||
|
UserInfo user = client.getMe();
|
||||||
|
|
||||||
|
HashMap<String, Object> resp = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
resp.put("result", user);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jsonData = new ObjectMapper().writeValueAsString(resp);
|
||||||
|
return Response.ok(jsonData).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{username}/")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response getUser(
|
||||||
|
@PathParam("username") String username) throws ServerException {
|
||||||
|
|
||||||
|
IdmClientFactory factory = IdmClientFactory.getSingleton();
|
||||||
|
|
||||||
|
String token = InfrastructureUtils.getAccessToken();
|
||||||
|
|
||||||
|
IdmUsersClient client = factory.userClient(token);
|
||||||
|
|
||||||
|
UserInfo user = client.getUser(username);
|
||||||
|
|
||||||
|
HashMap<String, Object> resp = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
resp.put("result", user);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jsonData = new ObjectMapper().writeValueAsString(resp);
|
||||||
|
return Response.ok(jsonData).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{search}/")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response searchUsers(
|
||||||
|
@QueryParam("format") @DefaultValue("username") IdmUser.USERS_REPR format,
|
||||||
|
@QueryParam("exact") @DefaultValue("true") Boolean exact,
|
||||||
|
@QueryParam("username") String username,
|
||||||
|
@QueryParam("firstName") String firstName,
|
||||||
|
@QueryParam("lastName") String lastName,
|
||||||
|
@QueryParam("email") String email,
|
||||||
|
@QueryParam("first") @DefaultValue("0") int firstResult,
|
||||||
|
@QueryParam("max") @DefaultValue("100") int maxResults,
|
||||||
|
@QueryParam("enabled") @DefaultValue("true") Boolean enabled
|
||||||
|
|
||||||
|
) throws ServerException {
|
||||||
|
|
||||||
|
IdmClientFactory factory = IdmClientFactory.getSingleton();
|
||||||
|
|
||||||
|
String token = InfrastructureUtils.getAccessToken();
|
||||||
|
|
||||||
|
IdmUsersClient client = factory.userClient(token);
|
||||||
|
|
||||||
|
SearchUsersParams params = new SearchUsersParams();
|
||||||
|
|
||||||
|
if (exact != null)
|
||||||
|
params.exact = exact;
|
||||||
|
|
||||||
|
if (username != null)
|
||||||
|
params.username = username;
|
||||||
|
|
||||||
|
if (firstName != null)
|
||||||
|
params.firstName = firstName;
|
||||||
|
|
||||||
|
if (lastName != null)
|
||||||
|
params.lastName = lastName;
|
||||||
|
|
||||||
|
if (email != null)
|
||||||
|
params.email = email;
|
||||||
|
|
||||||
|
if (enabled != null)
|
||||||
|
params.enabled = enabled;
|
||||||
|
|
||||||
|
Object resp = null;
|
||||||
|
|
||||||
|
if (format.equals(IdmUser.USERS_REPR.compact)) {
|
||||||
|
List<IdmUser> users = client.searchUsers(firstResult, maxResults, params);
|
||||||
|
resp = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format.equals(IdmUser.USERS_REPR.full)) {
|
||||||
|
List<IdmFullUser> users = client.searchFullUsers(firstResult, maxResults, params);
|
||||||
|
resp = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format.equals(IdmUser.USERS_REPR.username)) {
|
||||||
|
List<String> users = client.searchUsernames(firstResult, maxResults, params);
|
||||||
|
resp = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format.equals(IdmUser.USERS_REPR.email)) {
|
||||||
|
List<String> users = client.searchEmails(firstResult, maxResults, params);
|
||||||
|
resp = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
|
||||||
|
{
|
||||||
|
String jsonData = new ObjectMapper().writeValueAsString(resp);
|
||||||
|
return Response.ok(jsonData).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,35 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Invite;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Notification;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
@Path("invites")
|
|
||||||
@ResourceGroup("Invites APIs")
|
|
||||||
@ResourceLabel("Invites APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Invites {
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveInvite(Invite invite) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void readInvite(@PathParam("id") String inviteid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Notification;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
@Path("likes")
|
|
||||||
@ResourceGroup("Likes APIs")
|
|
||||||
@ResourceLabel("Likes APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Likes {
|
|
||||||
@POST
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void like(Like like) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//had other params why?
|
|
||||||
@DELETE
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void unlike(@PathParam("id") String likeid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Notification;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
@Path("notifications")
|
|
||||||
@ResourceGroup("Notifications APIs")
|
|
||||||
@ResourceLabel("Notifications APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Notifications {
|
|
||||||
@POST
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveNotification(Notification notification) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void setNotificationRead(@PathParam("id") String notid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void readNotification(@PathParam("id") String notid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Path("posts")
|
|
||||||
@ResourceGroup("Posts APIs")
|
|
||||||
@ResourceLabel("Posts APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Posts {
|
|
||||||
@POST
|
|
||||||
@Path("/postuser")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveUserPost(Post post) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/postuser")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveUserPost(Post post, List<Attachment> attachments){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void deletePost(@PathParam("id") String postid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/postapp")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveAppPost(Post post) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/postapp/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveAppPost(Post post, List<Attachment> attachments){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void readPost(@PathParam("id") String postid){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/portalprivacy")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllPortalPrivacyLevelPosts(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/comments")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllCommentByPost(@PathParam("id") String postid){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/likes")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllLikesByPost(@PathParam("id") String postid){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//the following two methods had vreid why?
|
|
||||||
@POST
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void saveHashTags(@PathParam("id") String postid, List<String> hashtags) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void deleteHashTagsComment(@PathParam("id") String postid, List<String> hashtags) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/attachments")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAttachmentsByPostId(@PathParam("id") String postid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.gcube.social_networking.rest;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/test")
|
||||||
|
@ResourceGroup("Comments APIs")
|
||||||
|
@ResourceLabel("Comments APIs")
|
||||||
|
@RequestHeaders({
|
||||||
|
@RequestHeader(name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
||||||
|
})
|
||||||
|
public class TestRest {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/test")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response test() {
|
||||||
|
|
||||||
|
HashMap<String, Object> resp = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
resp.put("result", "funziona");
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jsonData = new ObjectMapper().writeValueAsString(resp);
|
||||||
|
return Response.ok(jsonData).build();
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,149 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.InviteStatus;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.NotificationChannelType;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.NotificationType;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Path("entities")
|
|
||||||
@ResourceGroup("Users & Apps APIs")
|
|
||||||
@ResourceLabel("Users & Apps APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Users {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllPostsByUser(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("apps/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllPostsByApp(@PathParam("id") String appid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/posts/comments")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentCommentedPostsByUserAndDate(@PathParam("id") String userid, @QueryParam("time") long timeInMillis) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentPostsByUser(@PathParam("id") String userid, @QueryParam("limit") int limit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentPostsByUser(@PathParam("id") String userid, @QueryParam("time") long timeInMillis) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("users/{id}/notifications")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void setAllNotificationReadByUser(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notifications")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getUnreadNotificationsByUser(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notificationchannels")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getUserNotificationChannels(@PathParam("id") String userid, @QueryParam("type") NotificationType notificationType) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("users/{id}/notificationpreferences")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void setUserNotificationPreferences(@PathParam("id") String userid, Map<NotificationType, NotificationChannelType[]> enabledChannels) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notificationpreferences")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getUserNotificationPreferences(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/comments")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentCommentsByUserAndDate(@PathParam("id") String userid, @QueryParam("time") long timeInMillis) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/likes")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllLikedPostIdsByUser(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/likes")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllLikedPostsByUser(@PathParam("id") String userid, @QueryParam("limit") int limit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/posts/likes")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentLikedPostsByUserAndDate(@PathParam("id") String userid, @QueryParam("time") long timeInMillis) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notifications")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllNotificationByUser(@PathParam("id") String userid, @QueryParam("limit") int limit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notifications")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRangeNotificationsByUser(@PathParam("id") String userid, @QueryParam("limit") int limit, @QueryParam("from") int from) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notifications/unread")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void checkUnreadNotifications(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("users/{id}/notifications/unread/messages")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void checkUnreadMessagesNotifications(@PathParam("id") String userid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
package org.gcube.social_networking.rest;
|
|
||||||
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
|
||||||
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.InviteStatus;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
|
|
||||||
@Path("vres")
|
|
||||||
@ResourceGroup("VREs APIs")
|
|
||||||
@ResourceLabel("VREs APIs")
|
|
||||||
@RequestHeaders({
|
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see <a href=\"https://dev.d4science.org/how-to-access-resources\">https://dev.d4science.org/how-to-access-resources</a>")
|
|
||||||
})
|
|
||||||
public class Vres {
|
|
||||||
@POST
|
|
||||||
@Path("/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void savePostToVRETimeline(@PathParam("id") String vreid, Post post) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllPostsByVRE(@PathParam("id") String vreid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentPostsByVRE(@PathParam("id") String vreid, @QueryParam("limit") int limit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getRecentPostsByVREAndRange(@PathParam("id") String vreid, @QueryParam("limit") int limit, @QueryParam("from") int from) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getVREHashtagsWithOccurrence(@PathParam("id") String vreid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/hashtags")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getVREHashtagsWithOccurrenceFilteredByTime(@PathParam("id") String vreid, @QueryParam("time") long timestamp) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/hashtags/{hashtag}/posts")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getVREPostsByHashtag(@PathParam("id") String vreid, @PathParam("hashtag") String hashtag) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}/email/{email}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void isExistingInvite(@PathParam("id") String vreid, @PathParam("email") String email) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PUT
|
|
||||||
@Path("/{id}/email/{email}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void setInviteStatus(@PathParam("id") String vreid, @PathParam("email") String email, InviteStatus status) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{id}")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
@Consumes({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getInvitedEmailsByVRE(@PathParam("id") String vreid, InviteStatus... status) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/")
|
|
||||||
@Produces({"application/json;charset=UTF-8", "application/vnd.api+json"})
|
|
||||||
public void getAllVREIds() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.gcube.social_networking.rest.examples;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.smartgears.utils.InnerMethodName;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lucio Lelii (ISTI - CNR)
|
||||||
|
* @author Alfredo Oliviero (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("auth")
|
||||||
|
public class AuthenticatedService {
|
||||||
|
|
||||||
|
private static final String ALLOWED_ROLE = "myRole";
|
||||||
|
private static final String ALLOWED_ROLE_ORG = "OrganizationMember";
|
||||||
|
private static final String ALLOWED_ROLE_MEMBER = "Member";
|
||||||
|
|
||||||
|
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_ORG })
|
||||||
|
@GET
|
||||||
|
@Path("org_member")
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String authorizedOrg() {
|
||||||
|
InnerMethodName.set("auth");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String userId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
return String.format(
|
||||||
|
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||||
|
context, ALLOWED_ROLE_ORG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_MEMBER })
|
||||||
|
@GET
|
||||||
|
@Path("member")
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String authorizedMember() {
|
||||||
|
InnerMethodName.set("auth");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String userId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
return String.format(
|
||||||
|
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||||
|
context, ALLOWED_ROLE_MEMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE })
|
||||||
|
@GET
|
||||||
|
@Path("")
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String authorized() {
|
||||||
|
InnerMethodName.set("auth");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String userId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
return String.format(
|
||||||
|
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
|
||||||
|
context, ALLOWED_ROLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.gcube.social_networking.rest.examples;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@Path("guest")
|
||||||
|
public class ExcludeAuthorizationService {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method doesn't need authorization and the SecretManagerProvider is null
|
||||||
|
* see to implement this behavior add to excludes section in your
|
||||||
|
* application.yaml
|
||||||
|
*
|
||||||
|
* - path: /{path-to-your-method-path}
|
||||||
|
*
|
||||||
|
* example for this method
|
||||||
|
*
|
||||||
|
* - path: /excluded
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
public String exludedMethod() {
|
||||||
|
logger.info("executed whithout any authorization");
|
||||||
|
return "executed whithout any authorization";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package org.gcube.social_networking.rest.examples;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.common.security.Owner;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.utils.InnerMethodName;
|
||||||
|
import org.gcube.social_networking.rest.examples.serializers.IdmObjectSerializator;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Lucio Lelii (ISTI-CNR)
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("")
|
||||||
|
public class HelloService {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(HelloService.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("hello")
|
||||||
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
|
public String hello() {
|
||||||
|
InnerMethodName.set("hello");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String userId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
String infrastructureName = ContextProvider.get().container().configuration().infrastructure();
|
||||||
|
logger.info("caller id is {}", userId);
|
||||||
|
return String.format("Hello %s in context %s in infastructure %s -roles %s", userId, context,
|
||||||
|
infrastructureName, secret.getOwner().getRoles());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("details")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public Response details() {
|
||||||
|
InnerMethodName.set("details");
|
||||||
|
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
|
||||||
|
String context = secret.getContext();
|
||||||
|
data.put("context", context);
|
||||||
|
|
||||||
|
Owner owner = secret.getOwner();
|
||||||
|
|
||||||
|
data.put("owner", owner);
|
||||||
|
|
||||||
|
// ContainerContext container = ContextProvider.get().container();
|
||||||
|
// data.put("container", container);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = IdmObjectSerializator.getSerializer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jsonData = objectMapper.writeValueAsString(data);
|
||||||
|
return Response.ok(jsonData).build();
|
||||||
|
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Response.serverError().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson serializer for ContainerConfiguration
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> {
|
||||||
|
protected ContainerConfigurationSerializer(Class<ContainerConfiguration> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerConfigurationSerializer() {
|
||||||
|
super(ContainerConfiguration.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ContainerConfiguration configuration, JsonGenerator jgen, SerializerProvider provider)
|
||||||
|
throws IOException {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeObjectField("mode", configuration.mode());
|
||||||
|
jgen.writeObjectField("app", configuration.apps());
|
||||||
|
jgen.writeObjectField("site", configuration.site());
|
||||||
|
jgen.writeObjectField("infrastructure", configuration.infrastructure());
|
||||||
|
jgen.writeObjectField("hostname", configuration.hostname());
|
||||||
|
jgen.writeObjectField("port", configuration.port());
|
||||||
|
jgen.writeObjectField("protocol", configuration.protocol());
|
||||||
|
jgen.writeObjectField("authorizeChildrenContext", configuration.authorizeChildrenContext());
|
||||||
|
jgen.writeObjectField("proxy", configuration.proxy());
|
||||||
|
|
||||||
|
jgen.writeObjectField("desc", configuration.toString());
|
||||||
|
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson serializer for ContainerContext
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ContainerContextSerializer extends StdSerializer<ContainerContext> {
|
||||||
|
protected ContainerContextSerializer(Class<ContainerContext> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerContextSerializer() {
|
||||||
|
super(ContainerContext.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ContainerContext ccontext, JsonGenerator jgen, SerializerProvider provider)
|
||||||
|
throws IOException {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeStringField("id", ccontext.id());
|
||||||
|
// jgen.writeObjectField("configuration.site", ccontext.configuration().site());
|
||||||
|
// jgen.writeObjectField("configuration", ccontext.configuration());
|
||||||
|
jgen.writeObjectField("properties", ccontext.properties());
|
||||||
|
jgen.writeObjectField("authorizationProvider", ccontext.authorizationProvider());
|
||||||
|
|
||||||
|
jgen.writeObjectField("configuration", ccontext.configuration());
|
||||||
|
jgen.writeObjectField("desc", ccontext.toString());
|
||||||
|
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
import org.gcube.smartgears.security.SimpleCredentials;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson Serialization utils for Smartgear Context classes
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class IdmObjectSerializator {
|
||||||
|
private static ObjectMapper serializer = null;
|
||||||
|
|
||||||
|
protected static TypeReference<HashMap<String, Object>> typeRefHashmap = new TypeReference<HashMap<String, Object>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
public static String decodeBase64String(String encodedString) {
|
||||||
|
return new String(Base64.getUrlDecoder().decode(encodedString), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, Object> jsonStringToHasmap(String jsonString)
|
||||||
|
throws IOException {
|
||||||
|
return getSerializer().readValue(jsonString, typeRefHashmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ObjectMapper getSerializer() {
|
||||||
|
if (serializer == null) {
|
||||||
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
SimpleModule module = new SimpleModule();
|
||||||
|
// module.addSerializer(Owner.class, new OwnerSerializer());
|
||||||
|
|
||||||
|
module.addSerializer(ContainerConfiguration.class, new ContainerConfigurationSerializer());
|
||||||
|
module.addSerializer(ContainerContext.class, new ContainerContextSerializer());
|
||||||
|
module.addSerializer(SimpleCredentials.class, new SimpleCredentialsSerializer());
|
||||||
|
|
||||||
|
// DecodedJWT serialization
|
||||||
|
//om.registerModule(new JavaTimeModule());
|
||||||
|
serializer = om;
|
||||||
|
}
|
||||||
|
return serializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.common.security.Owner;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson serializer for Owner
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class OwnerSerializer extends StdSerializer<Owner> {
|
||||||
|
|
||||||
|
protected OwnerSerializer(Class<Owner> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OwnerSerializer() {
|
||||||
|
super(Owner.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeStringField("ownerId", owner.getId());
|
||||||
|
jgen.writeStringField("clientName", owner.getClientName());
|
||||||
|
jgen.writeArrayFieldStart("roles");
|
||||||
|
for (String role : owner.getRoles()) {
|
||||||
|
jgen.writeString(role);
|
||||||
|
}
|
||||||
|
jgen.writeEndArray();
|
||||||
|
jgen.writeStringField("email", owner.getEmail());
|
||||||
|
jgen.writeStringField("firstName", owner.getFirstName());
|
||||||
|
jgen.writeStringField("lastName", owner.getLastName());
|
||||||
|
jgen.writeBooleanField("externalClient", owner.isExternalClient());
|
||||||
|
jgen.writeStringField("contactPerson", owner.getClientName());
|
||||||
|
jgen.writeStringField("contactOrganisation", owner.getContactOrganisation());
|
||||||
|
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson serializer for ServiceEndpoint.AccessPoint
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ServiceEndpointAccessPointSerializer extends StdSerializer<ServiceEndpoint.AccessPoint> {
|
||||||
|
|
||||||
|
protected ServiceEndpointAccessPointSerializer(Class<ServiceEndpoint.AccessPoint> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceEndpointAccessPointSerializer() {
|
||||||
|
super(ServiceEndpoint.AccessPoint.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ServiceEndpoint.AccessPoint accessPoint, JsonGenerator jgen, SerializerProvider provider)
|
||||||
|
throws IOException {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
|
||||||
|
String error = null;
|
||||||
|
String clientSecret = null;
|
||||||
|
try {
|
||||||
|
clientSecret = StringEncrypter.getEncrypter().decrypt(accessPoint.password());
|
||||||
|
} catch (Exception e) {
|
||||||
|
error = e.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
jgen.writeStringField("address", accessPoint.address());
|
||||||
|
jgen.writeStringField("name", accessPoint.name());
|
||||||
|
jgen.writeStringField("description", accessPoint.description());
|
||||||
|
|
||||||
|
try {
|
||||||
|
jgen.writeStringField("username", accessPoint.username());
|
||||||
|
} catch (Exception e) {
|
||||||
|
jgen.writeStringField("username", null);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
jgen.writeStringField("tostring", accessPoint.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
jgen.writeStringField("tostring", null);
|
||||||
|
}
|
||||||
|
if (error != null) {
|
||||||
|
jgen.writeStringField("key_error", error);
|
||||||
|
jgen.writeBooleanField("key_decoded", false);
|
||||||
|
} else {
|
||||||
|
jgen.writeBooleanField("key_decoded", true);
|
||||||
|
}
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gcube.social_networking.rest.examples.serializers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.security.SimpleCredentials;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson serializer for SimpleCredentials
|
||||||
|
*
|
||||||
|
* @author Alfredo Oliviero (ISTI-CNR)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials> {
|
||||||
|
|
||||||
|
protected SimpleCredentialsSerializer(Class<SimpleCredentials> t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleCredentialsSerializer() {
|
||||||
|
super(SimpleCredentials.class, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(SimpleCredentials credentials, JsonGenerator jgen, SerializerProvider provider)
|
||||||
|
throws IOException {
|
||||||
|
jgen.writeStartObject();
|
||||||
|
jgen.writeStringField("clientId", credentials.getClientID());
|
||||||
|
jgen.writeStringField("secret", "[*****]");
|
||||||
|
jgen.writeEndObject();
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ import org.gcube.common.portal.GCubePortalConstants;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
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.scope.api.ScopeProvider;
|
//import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.TooManyRunningClustersException;
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.TooManyRunningClustersException;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
@ -122,15 +122,15 @@ class CassandraCluster implements Serializable {
|
||||||
scope += readInfrastructureName();
|
scope += readInfrastructureName();
|
||||||
_log.debug("infrastrucute name is null, setting root scope=" + scope);
|
_log.debug("infrastrucute name is null, setting root scope=" + scope);
|
||||||
}
|
}
|
||||||
String currScope = ScopeProvider.instance.get();
|
/*String currScope = ScopeProvider.instance.get();
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
|
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
|
||||||
query.addCondition("$resource/Profile/Platform/Name/text() eq '"+ PLATFORM_NAME +"'");
|
query.addCondition("$resource/Profile/Platform/Name/text() eq '"+ PLATFORM_NAME +"'");
|
||||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||||
ScopeProvider.instance.set(currScope);
|
ScopeProvider.instance.set(currScope);*/
|
||||||
return toReturn;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readInfrastructureName() {
|
private String readInfrastructureName() {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,34 +5,15 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
|
import org.gcube.social_networking.socialnetworking.model.shared.*;
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.*;
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Invite;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.InviteOperationResult;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.InviteStatus;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Notification;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.NotificationChannelType;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.NotificationType;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.RangePosts;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.ColumnNameNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.CommentIDNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostTypeNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.InviteIDNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.InviteStatusNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.LikeIDNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.NotificationChannelTypeNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.NotificationIDNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.NotificationTypeNotFoundException;
|
|
||||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PrivacyLevelTypeNotFoundException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Massimiliano Assante ISTI-CNR
|
* @author Massimiliano Assante ISTI-CNR
|
||||||
* @author Costantino Perciante ISTI-CNR
|
* @author Costantino Perciante ISTI-CNR
|
||||||
* <class>DatabookStore</class> is the high level interface for querying and adding data to DatabookStore
|
* <class>DatabookStore</class> is the high level interface for querying and adding data to DatabookStore
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface SocialDBDriver {
|
public interface SocialDBDriver {
|
||||||
/**
|
/**
|
||||||
* save a Post instance in the store
|
* save a Post instance in the store
|
||||||
|
@ -48,7 +29,7 @@ public interface SocialDBDriver {
|
||||||
*/
|
*/
|
||||||
boolean saveUserPost(Post post, List<Attachment> attachments);
|
boolean saveUserPost(Post post, List<Attachment> attachments);
|
||||||
/**
|
/**
|
||||||
* delete a post from the store
|
* delete a Post from the store
|
||||||
* @throws PostIDNotFoundException
|
* @throws PostIDNotFoundException
|
||||||
* @return true if everything went fine
|
* @return true if everything went fine
|
||||||
*/
|
*/
|
||||||
|
@ -95,8 +76,7 @@ public interface SocialDBDriver {
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
List<Post> getAllPostsByApp(String appid) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException;
|
List<Post> getAllPostsByApp(String appid) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException; /**
|
||||||
/**
|
|
||||||
* @param userid the user identifier like andrea.rossi
|
* @param userid the user identifier like andrea.rossi
|
||||||
* @param timeInMillis the initial time in millis to be considered
|
* @param timeInMillis the initial time in millis to be considered
|
||||||
* @return a list of posts commented by userid starting from timeInMillis
|
* @return a list of posts commented by userid starting from timeInMillis
|
||||||
|
@ -110,6 +90,7 @@ public interface SocialDBDriver {
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
*/
|
*/
|
||||||
List<Post> getAllPortalPrivacyLevelPosts() throws PostTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException;
|
List<Post> getAllPortalPrivacyLevelPosts() throws PostTypeNotFoundException, ColumnNameNotFoundException, PrivacyLevelTypeNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the most recent posts for this user up to quantity param
|
* return the most recent posts for this user up to quantity param
|
||||||
* @param userid user identifier
|
* @param userid user identifier
|
||||||
|
@ -128,6 +109,7 @@ public interface SocialDBDriver {
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
List<Post> getAllPostsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
List<Post> getAllPostsByVRE(String vreid) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the most recent posts for this vre up to quantity param
|
* return the most recent posts for this vre up to quantity param
|
||||||
* @param vreid VRES identifier
|
* @param vreid VRES identifier
|
||||||
|
@ -138,6 +120,7 @@ public interface SocialDBDriver {
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
List<Post> getRecentPostsByVRE(String vreid, int quantity) throws IllegalArgumentException, PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
List<Post> getRecentPostsByVRE(String vreid, int quantity) throws IllegalArgumentException, PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -151,6 +134,7 @@ public interface SocialDBDriver {
|
||||||
* @throws ColumnNameNotFoundException
|
* @throws ColumnNameNotFoundException
|
||||||
*/
|
*/
|
||||||
RangePosts getRecentPostsByVREAndRange(String vreid, int from, int quantity) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
RangePosts getRecentPostsByVREAndRange(String vreid, int from, int quantity) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, ColumnNameNotFoundException, PostIDNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param userid user identifier
|
* @param userid user identifier
|
||||||
* @param timeInMillis time in milliseconds from which you want to start retrieve the posts
|
* @param timeInMillis time in milliseconds from which you want to start retrieve the posts
|
||||||
|
@ -308,6 +292,7 @@ public interface SocialDBDriver {
|
||||||
* return all the postids a user has liked
|
* return all the postids a user has liked
|
||||||
*/
|
*/
|
||||||
List<String> getAllLikedPostIdsByUser(String userid);
|
List<String> getAllLikedPostIdsByUser(String userid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param userid user identifier
|
* @param userid user identifier
|
||||||
* @param limit set 0 to get everything, an int to get the most recent -limit- liked posts
|
* @param limit set 0 to get everything, an int to get the most recent -limit- liked posts
|
||||||
|
@ -315,15 +300,18 @@ public interface SocialDBDriver {
|
||||||
* @throws PostIDNotFoundException .
|
* @throws PostIDNotFoundException .
|
||||||
* @throws PostTypeNotFoundException .
|
* @throws PostTypeNotFoundException .
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
|
* @throws PostIDNotFoundException .
|
||||||
* return all the posts a user has liked
|
* return all the posts a user has liked
|
||||||
*/
|
*/
|
||||||
List<Post> getAllLikedPostsByUser(String userid, int limit) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException;
|
List<Post> getAllLikedPostsByUser(String userid, int limit) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param userid user identifier
|
* @param userid user identifier
|
||||||
* @param timeInMillis time in milliseconds from which you want to start retrieve the posts
|
* @param timeInMillis time in milliseconds from which you want to start retrieve the posts
|
||||||
* @return the likes made to posts in the range from: today to: timeInMillis
|
* @return the likes made to posts in the range from: today to: timeInMillis
|
||||||
*/
|
*/
|
||||||
List<Post> getRecentLikedPostsByUserAndDate(String userid, long timeInMillis) throws IllegalArgumentException;
|
List<Post> getRecentLikedPostsByUserAndDate(String userid, long timeInMillis) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param postid postid identifier
|
* @param postid postid identifier
|
||||||
* return all the likes belonging to the postid
|
* return all the likes belonging to the postid
|
||||||
|
@ -386,6 +374,7 @@ public interface SocialDBDriver {
|
||||||
* @throws PostIDNotFoundException .
|
* @throws PostIDNotFoundException .
|
||||||
* @throws PostTypeNotFoundException .
|
* @throws PostTypeNotFoundException .
|
||||||
* @throws PrivacyLevelTypeNotFoundException
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
|
* @throws PostIDNotFoundException .
|
||||||
* @return all the posts having the hashtag passed as parameter
|
* @return all the posts having the hashtag passed as parameter
|
||||||
*/
|
*/
|
||||||
List<Post> getVREPostsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException;
|
List<Post> getVREPostsByHashtag(String vreid, String hashtag) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException;
|
||||||
|
@ -426,7 +415,7 @@ public interface SocialDBDriver {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param postId
|
* @param postId
|
||||||
* @return the list of attachments of the post postId, starting from the second one (first attachment is included in post instance already)
|
* @return the list of attachments of the post postId, starting from the second one (first attachment is included in Post instance already)
|
||||||
*/
|
*/
|
||||||
List<Attachment> getAttachmentsByPostId(String postId) throws PostIDNotFoundException;
|
List<Attachment> getAttachmentsByPostId(String postId) throws PostIDNotFoundException;
|
||||||
|
|
||||||
|
@ -439,11 +428,12 @@ public interface SocialDBDriver {
|
||||||
* Retrieve all the ids of the vre
|
* Retrieve all the ids of the vre
|
||||||
* @return the set of ids of the vre available or empty list in case of errors.
|
* @return the set of ids of the vre available or empty list in case of errors.
|
||||||
*/
|
*/
|
||||||
public List<String> getAllVREIds();
|
List<String> getAllVREIds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* close the connection to the underlying database
|
* close the connection to the underlying database
|
||||||
*/
|
*/
|
||||||
void closeConnection();
|
void closeConnection();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gcube.social_networking.utils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.gcube.smartgears.context.container.ContainerContext;
|
||||||
|
|
||||||
|
public class InfrastructureUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the secret from smartgear configuration
|
||||||
|
*
|
||||||
|
* @return Secret
|
||||||
|
*/
|
||||||
|
public static Secret getSecretForInfrastructure() {
|
||||||
|
ApplicationContext ctx = ContextProvider.get();
|
||||||
|
ContainerContext container = ctx.container();
|
||||||
|
ContainerConfiguration configuration = container.configuration();
|
||||||
|
String infra_context = configuration.infrastructure();
|
||||||
|
Secret secret = ctx.container().authorizationProvider().getSecretForContext(infra_context);
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String getAccessToken() {
|
||||||
|
Map<String, String> authorizations = SecretManagerProvider.get().getHTTPAuthorizationHeaders();
|
||||||
|
String access_token = authorizations.get("Authorization").replace("Bearer", "").trim();
|
||||||
|
return access_token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package org.gcube.social_networking.utils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response bean
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResponseBean <T> implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2725238162673879658L;
|
||||||
|
/**
|
||||||
|
* The result of the request: true if it succeeded, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error message if something wrong happened, null/empty otherwise
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
/**
|
||||||
|
* The result object of the request
|
||||||
|
*/
|
||||||
|
private T result;
|
||||||
|
|
||||||
|
public ResponseBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param success
|
||||||
|
* @param message
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
public ResponseBean(boolean success, String message, T result) {
|
||||||
|
super();
|
||||||
|
this.success = success;
|
||||||
|
this.message = message;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setSuccess(boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public T getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setResult(T result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResponseBean [success=" + success
|
||||||
|
+ ", message=" + message + ", result=" + result + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.gcube.social_networking.ws;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/")
|
||||||
|
@Singleton
|
||||||
|
public class WelcomeService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.TEXT_HTML)
|
||||||
|
public Response sayHtmlHello() {
|
||||||
|
return Response.ok("<html><body><h2>The social networking web service is up and running!</h2></body></html>").build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.gcube.social_networking.ws.docs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@Path("api-docs")
|
||||||
|
public class DocsGenerator {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DocsGenerator.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{any: .*}")
|
||||||
|
public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
logger.info(DocsGenerator.class.getSimpleName() + " toDoc called");
|
||||||
|
|
||||||
|
String pathInfo = req.getPathInfo();
|
||||||
|
logger.debug("pathInfo {}", pathInfo);
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (pathInfo.endsWith("/api-docs")) {
|
||||||
|
pathInfo += "index.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pathInfo.endsWith("/api-docs/")) {
|
||||||
|
pathInfo += "index.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logger.info("going to {}", pathInfo);
|
||||||
|
|
||||||
|
String realPath = req.getServletContext().getRealPath(pathInfo);
|
||||||
|
return new FileInputStream(new File(realPath));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
//MANAGE THE EXCEPTION
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.gcube.social_networking.ws.ex;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception gets thrown when @Valid fail
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
public class ApplicationException implements ExceptionMapper<Exception> {
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ApplicationException.class);
|
||||||
|
|
||||||
|
public Response toResponse(Exception e) {
|
||||||
|
logger.warn("ApplicationException invoked for exception ", e);
|
||||||
|
return Response
|
||||||
|
.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
|
||||||
|
.type(MediaType.APPLICATION_JSON)
|
||||||
|
.entity(new ResponseBean(false, e.getMessage(), null))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.gcube.social_networking.ws.ex;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
public class AuthException extends WebApplicationException {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public AuthException(Throwable cause) {
|
||||||
|
super(cause, Status.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gcube.social_networking.ws.ex;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown on fail
|
||||||
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
public class ValidationException implements ExceptionMapper<javax.validation.ValidationException> {
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ValidationException.class);
|
||||||
|
@Override
|
||||||
|
public Response toResponse(javax.validation.ValidationException e) {
|
||||||
|
final StringBuilder strBuilder = new StringBuilder();
|
||||||
|
for (ConstraintViolation<?> cv : ((ConstraintViolationException) e).getConstraintViolations()) {
|
||||||
|
strBuilder.append(cv.getMessage());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.warn("ValidationException invoked, returning " + strBuilder.toString());
|
||||||
|
return Response
|
||||||
|
.status(Response.Status.BAD_REQUEST.getStatusCode())
|
||||||
|
.type(MediaType.APPLICATION_JSON)
|
||||||
|
.entity(new ResponseBean(false, strBuilder.toString(), null))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application id object
|
||||||
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
|
*/
|
||||||
|
//@ApiModel(description="An object containing the app_id field", value="Application")
|
||||||
|
public class ApplicationId {
|
||||||
|
|
||||||
|
@JsonProperty("app_id")
|
||||||
|
@NotNull(message="app_id cannot be null")
|
||||||
|
@Size(message="app_id cannot be empty", min=1)
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
public ApplicationId() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationId(String appId) {
|
||||||
|
super();
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ApplicationId [appId=" + appId + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.webcohesion.enunciate.metadata.DocumentationExample;
|
||||||
|
/**
|
||||||
|
* Generic input bean for methods that allow to comment posts
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||||
|
public class CommentInputBean implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5274608088828232980L;
|
||||||
|
|
||||||
|
@JsonProperty("text")
|
||||||
|
@NotNull(message="text cannot be null")
|
||||||
|
@Size(min=1, message="text cannot be empty")
|
||||||
|
@DocumentationExample("I would like to comment that ...")
|
||||||
|
/**
|
||||||
|
* text the text of the comment
|
||||||
|
*/
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
@NotNull(message="postid cannot be null")
|
||||||
|
@JsonProperty("postid")
|
||||||
|
/**
|
||||||
|
* postid the postid of the post where you attach the comment
|
||||||
|
*/
|
||||||
|
private String postid;
|
||||||
|
|
||||||
|
public CommentInputBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text
|
||||||
|
* @param postid
|
||||||
|
*/
|
||||||
|
public CommentInputBean(String text, String postid) {
|
||||||
|
super();
|
||||||
|
this.text = text;
|
||||||
|
this.postid = postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostid() {
|
||||||
|
return postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostid(String postid) {
|
||||||
|
this.postid = postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CommentInputBean [text=" + text + ", postid=" + postid + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like Bean object
|
||||||
|
*/
|
||||||
|
public class LikeInputBean {
|
||||||
|
|
||||||
|
@JsonProperty("likeid")
|
||||||
|
@NotNull(message="likeid cannot be null")
|
||||||
|
@Size(message="likeid cannot be empty", min=1)
|
||||||
|
private String likeid;
|
||||||
|
|
||||||
|
@JsonProperty("postid")
|
||||||
|
@NotNull(message="postid cannot be null")
|
||||||
|
@Size(message="postid cannot be empty", min=1)
|
||||||
|
private String postid;
|
||||||
|
|
||||||
|
public LikeInputBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param likeid
|
||||||
|
* @param postid
|
||||||
|
*/
|
||||||
|
public LikeInputBean(String likeid, String postid) {
|
||||||
|
super();
|
||||||
|
this.likeid = likeid;
|
||||||
|
this.postid = postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLikeid() {
|
||||||
|
return likeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLikeid(String likeid) {
|
||||||
|
this.likeid = likeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostid() {
|
||||||
|
return postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostid(String postid) {
|
||||||
|
this.postid = postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "LikeInputBean [likeid=" + likeid + ", postid=" + postid + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application id object
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class PostId {
|
||||||
|
|
||||||
|
@JsonProperty("postid")
|
||||||
|
@NotNull(message="postid cannot be null")
|
||||||
|
@Size(message="postid cannot be empty", min=1)
|
||||||
|
private String postId;
|
||||||
|
|
||||||
|
public PostId() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostId(String postId) {
|
||||||
|
super();
|
||||||
|
this.postId = postId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostId() {
|
||||||
|
return postId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostId(String postId) {
|
||||||
|
this.postId = postId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PostId [postid=" + postId + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.webcohesion.enunciate.metadata.DocumentationExample;
|
||||||
|
/**
|
||||||
|
* Generic input bean for methods that allow to write posts
|
||||||
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
|
||||||
|
public class PostInputBean implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5274608088828232980L;
|
||||||
|
|
||||||
|
@JsonProperty("text")
|
||||||
|
@NotNull(message="text cannot be null")
|
||||||
|
@Size(min=1, message="text cannot be empty")
|
||||||
|
@DocumentationExample("Dear vre members, ...")
|
||||||
|
/**
|
||||||
|
* text the text of the post
|
||||||
|
*/
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
private String previewtitle;
|
||||||
|
|
||||||
|
@JsonProperty("preview_description")
|
||||||
|
private String previewdescription;
|
||||||
|
|
||||||
|
@JsonProperty("preview_host")
|
||||||
|
private String previewhost;
|
||||||
|
|
||||||
|
@JsonProperty("preview_url")
|
||||||
|
private String previewurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* param httpimageurl An image url for the preview"
|
||||||
|
*/
|
||||||
|
@JsonProperty("image_url")
|
||||||
|
private String httpimageurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enablenotification If true send a notification to the other vre members about this post
|
||||||
|
*/
|
||||||
|
@JsonProperty("enable_notification")
|
||||||
|
private boolean enablenotification;
|
||||||
|
|
||||||
|
@JsonProperty("params")
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
public PostInputBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostInputBean(String text, String previewtitle,
|
||||||
|
String previewdescription, String previewhost, String previewurl,
|
||||||
|
String httpimageurl, boolean enablenotification, String params) {
|
||||||
|
super();
|
||||||
|
this.text = text;
|
||||||
|
this.previewtitle = previewtitle;
|
||||||
|
this.previewdescription = previewdescription;
|
||||||
|
this.previewhost = previewhost;
|
||||||
|
this.previewurl = previewurl;
|
||||||
|
this.httpimageurl = httpimageurl;
|
||||||
|
this.enablenotification = enablenotification;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviewtitle() {
|
||||||
|
return previewtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviewtitle(String previewtitle) {
|
||||||
|
this.previewtitle = previewtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviewdescription() {
|
||||||
|
return previewdescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviewdescription(String previewdescription) {
|
||||||
|
this.previewdescription = previewdescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviewhost() {
|
||||||
|
return previewhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviewhost(String previewhost) {
|
||||||
|
this.previewhost = previewhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviewurl() {
|
||||||
|
return previewurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviewurl(String previewurl) {
|
||||||
|
this.previewurl = previewurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHttpimageurl() {
|
||||||
|
return httpimageurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpimageurl(String httpimageurl) {
|
||||||
|
this.httpimageurl = httpimageurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnablenotification() {
|
||||||
|
return enablenotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnablenotification(boolean enablenotification) {
|
||||||
|
this.enablenotification = enablenotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(String params) {
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PostInputBean [text=" + text + ", previewtitle=" + previewtitle
|
||||||
|
+ ", previewdescription=" + previewdescription
|
||||||
|
+ ", previewhost=" + previewhost + ", previewurl=" + previewurl
|
||||||
|
+ ", httpimageurl=" + httpimageurl + ", enablenotification="
|
||||||
|
+ enablenotification + ", params=" + params + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.gcube.social_networking.ws.inputs;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class UserSetNotificationBean {
|
||||||
|
|
||||||
|
@JsonProperty("username")
|
||||||
|
@NotNull(message="username cannot be null")
|
||||||
|
@Size(message="username cannot be empty", min=1)
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@JsonProperty("disableNotification")
|
||||||
|
@NotNull(message="disableNotification cannot be null")
|
||||||
|
private Boolean disableNotification;
|
||||||
|
|
||||||
|
public UserSetNotificationBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param username
|
||||||
|
* @param disableNotification
|
||||||
|
*/
|
||||||
|
public UserSetNotificationBean(String username, boolean disableNotification) {
|
||||||
|
super();
|
||||||
|
this.username = username;
|
||||||
|
this.disableNotification = disableNotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisableNotification() {
|
||||||
|
return disableNotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisableNotification(boolean disableNotification) {
|
||||||
|
this.disableNotification = disableNotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UserSetNotificationBean [username=" + username + ", disableNotification=" + disableNotification + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.gcube.social_networking.ws.mappers;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.NotificationType;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.NotificationTypeNotFoundException;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
|
||||||
|
|
||||||
|
public class CatalogueEventTypeMapper {
|
||||||
|
|
||||||
|
public CatalogueEventTypeMapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NotificationType getType(CatalogueEventType type) throws NotificationTypeNotFoundException {
|
||||||
|
switch (type) {
|
||||||
|
case ITEM_PUBLISHED:
|
||||||
|
return NotificationType.CAT_ITEM_PUBLISHED;
|
||||||
|
case ITEM_REJECTED:
|
||||||
|
return NotificationType.CAT_ITEM_REJECTED;
|
||||||
|
case ITEM_REMOVED:
|
||||||
|
return NotificationType.CAT_ITEM_DELETE;
|
||||||
|
case ITEM_SUBMITTED:
|
||||||
|
return NotificationType.CAT_ITEM_SUBMITTED;
|
||||||
|
case ITEM_UPDATED:
|
||||||
|
return NotificationType.CAT_ITEM_UPDATED;
|
||||||
|
default:
|
||||||
|
throw new NotificationTypeNotFoundException("The Catalogue event could not be mapped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package org.gcube.social_networking.ws.mappers;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.JobStatusType;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.RunningJob;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.JobStatusModelType;
|
||||||
|
|
||||||
|
public class JobMapper {
|
||||||
|
|
||||||
|
public JobMapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RunningJob getJob(JobNotificationBean item) {
|
||||||
|
String jobId = null;
|
||||||
|
String jobName = null;
|
||||||
|
JobStatusType status = null;
|
||||||
|
String message = null;
|
||||||
|
String serviceName = null; // i.e., Dataminer, SmartExecutor..
|
||||||
|
|
||||||
|
try {
|
||||||
|
jobId = item.getJobId();
|
||||||
|
jobName = item.getJobName();
|
||||||
|
status = getType(item.getStatus());
|
||||||
|
message = item.getStatusMessage();
|
||||||
|
serviceName = item.getServiceName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new RunningJob(jobId, jobName, status, message, serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JobStatusType getType(JobStatusModelType type) {
|
||||||
|
JobStatusType toReturn = null;
|
||||||
|
switch (type) {
|
||||||
|
case CANCELLED:
|
||||||
|
return JobStatusType.CANCELLED;
|
||||||
|
case DELETED:
|
||||||
|
return JobStatusType.DELETED;
|
||||||
|
case FAILED:
|
||||||
|
return JobStatusType.FAILED;
|
||||||
|
case CANCELLING:
|
||||||
|
return JobStatusType.CANCELLING;
|
||||||
|
case DELETING:
|
||||||
|
return JobStatusType.DELETING;
|
||||||
|
case EXECUTING:
|
||||||
|
return JobStatusType.EXECUTING;
|
||||||
|
case NEW:
|
||||||
|
return JobStatusType.NEW;
|
||||||
|
case SUBMITTED:
|
||||||
|
return JobStatusType.SUBMITTED;
|
||||||
|
case SUCCEEDED:
|
||||||
|
return JobStatusType.SUCCEEDED;
|
||||||
|
case TIMED_OUT:
|
||||||
|
return JobStatusType.TIMED_OUT;
|
||||||
|
case WAITING:
|
||||||
|
return JobStatusType.WAITING;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.gcube.social_networking.ws.mappers;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FileItemBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderBean;
|
||||||
|
|
||||||
|
public class WorkspaceItemMapper {
|
||||||
|
|
||||||
|
public WorkspaceItemMapper() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SocialFileItem getFileItem(FileItemBean item) {
|
||||||
|
String id = null;
|
||||||
|
String name= null;
|
||||||
|
String title= null;
|
||||||
|
String path= null;
|
||||||
|
SocialSharedFolder parent = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
id = item.getId();
|
||||||
|
name = item.getName();
|
||||||
|
title = item.getTitle();
|
||||||
|
path = item.getPath();
|
||||||
|
parent = getSharedFolder(item.getParent());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SocialFileItem toReturn = new SocialFileItem(id, name, title, path, parent);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SocialSharedFolder getSharedFolder(FolderBean item) {
|
||||||
|
|
||||||
|
String id = null;
|
||||||
|
String name= null;
|
||||||
|
String title= null;
|
||||||
|
String displayName= null;
|
||||||
|
String path= null;
|
||||||
|
String parentId= null;
|
||||||
|
boolean vreFolder = false;
|
||||||
|
try {
|
||||||
|
id = item.getId();
|
||||||
|
name = item.getName();
|
||||||
|
title = item.getTitle();
|
||||||
|
displayName = item.getDisplayName();
|
||||||
|
path = item.getPath();
|
||||||
|
parentId = item.getParentId();
|
||||||
|
vreFolder = item.isVreFolder();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SocialSharedFolder toReturn = new SocialSharedFolder(id, name, title, displayName, path, parentId, vreFolder);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,232 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.smartgears.utils.InnerMethodName;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
||||||
|
import org.gcube.social_networking.ws.inputs.CommentInputBean;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.Filters;
|
||||||
|
import org.gcube.social_networking.ws.utils.SocialUtils;
|
||||||
|
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (comments).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Path("2/comments")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class Comments {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Comments.class);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("get-comments-by-post-id")
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response getAllCommentsByPostId(
|
||||||
|
@NotNull
|
||||||
|
@QueryParam("key")
|
||||||
|
String key) {
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
InnerMethodName.set("get-comments-by-post-id");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
List<Comment> comments = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
|
comments = CassandraConnection.getInstance().getDatabookStore().getAllCommentByPost(key);
|
||||||
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
|
responseBean.setResult(comments);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such comments.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Retrieve the list of comments belonging to the owner of the token in the related context
|
||||||
|
* @return the list of comments belonging to the owner of the token in the related context.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("get-comments-user")
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "The list of comments is put into the 'result' field"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response getCommentsUser() {
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
InnerMethodName.set("get-comments-user");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
List<Comment> comments = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
|
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, 0);
|
||||||
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
|
responseBean.setResult(comments);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such comments.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve comments of the token owner in the context bound to the token itself and filter them by date
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("get-comments-user-by-time")
|
||||||
|
public Response getCommentsUserByTime(
|
||||||
|
@QueryParam("time")
|
||||||
|
@Min(value = 0, message="time cannot be negative")
|
||||||
|
long timeInMillis
|
||||||
|
) throws ValidationException{
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
List<Comment> comments = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving comments for user id " + username);
|
||||||
|
comments = CassandraConnection.getInstance().getDatabookStore().getRecentCommentsByUserAndDate(username, timeInMillis);
|
||||||
|
Filters.filterCommentsPerContext(comments, context);
|
||||||
|
responseBean.setResult(comments);
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such comments.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Create a new comment to a post having as owner the auth token's owner
|
||||||
|
* @param comment The CommentInputBean object
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("comment-post")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response writeComment(
|
||||||
|
@NotNull(message="Comment to write is missing")
|
||||||
|
@Valid
|
||||||
|
CommentInputBean comment) throws ValidationException {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
logger.debug("Request of writing a comment coming from user " + username);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
try {
|
||||||
|
String postId = comment.getPostid();
|
||||||
|
String commentText = comment.getText();
|
||||||
|
String userid = username;
|
||||||
|
Date time = new Date();
|
||||||
|
|
||||||
|
String postOwnerId = CassandraConnection.getInstance().getDatabookStore().readPost(postId).getEntityId();
|
||||||
|
Comment theComment = SocialUtils.commentPost(userid, time, postId, commentText, postOwnerId, context, secret);
|
||||||
|
if (theComment != null)
|
||||||
|
logger.debug("Added comment " + theComment.toString());
|
||||||
|
else {
|
||||||
|
logger.error("Unable to write comment");
|
||||||
|
responseBean.setMessage("Unable to write comment, something went wrong please see server log");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBean.setResult(theComment);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
} catch(PostIDNotFoundException ex) {
|
||||||
|
logger.error("Unable to find a post comment", ex);
|
||||||
|
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
logger.error("Unable to write comment", e);
|
||||||
|
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,170 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.server.SocialDBDriver;
|
||||||
|
import org.gcube.social_networking.ws.utils.ElasticSearchConnection;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.Filters;
|
||||||
|
import org.gcube.social_networking.ws.utils.TokensUtils;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (post and its comments).
|
||||||
|
*/
|
||||||
|
@Path("2/full-text-search")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class FullTextSearch {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(FullTextSearch.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve posts/comments that match the given query
|
||||||
|
* @param httpServletRequest
|
||||||
|
* @param query A string to search for
|
||||||
|
* @param from the index of the base result to be returned, range[0, infinity], defaults from = 0
|
||||||
|
* @param quantity defines how many results are most are to be returned, range[1, infinity], defaults from = 0,
|
||||||
|
* @return The posts/comments returned belong to the context bound to the AUTH Token
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("search-by-query")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Successful retrieval of posts/comments that match the query, reported in the 'result' field of the returned object"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response searchByQuery(
|
||||||
|
@Context HttpServletRequest httpServletRequest,
|
||||||
|
@QueryParam("query") @NotNull(message="query cannot be null") @Size(min=1, message="query cannot be empty")
|
||||||
|
String query,
|
||||||
|
@DefaultValue("0") @QueryParam("from") @Min(value=0, message="from cannot be negative")
|
||||||
|
int from,
|
||||||
|
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity cannot be negative")
|
||||||
|
int quantity
|
||||||
|
) throws ValidationException{
|
||||||
|
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.BAD_REQUEST;
|
||||||
|
responseBean.setMessage("This method can be only invoked by using a user token.");
|
||||||
|
if(!TokensUtils.isUserToken(secret))
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
|
status = Status.OK;
|
||||||
|
responseBean.setMessage(null);
|
||||||
|
|
||||||
|
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
|
||||||
|
try{
|
||||||
|
// Retrieve user's vres in which we must search
|
||||||
|
Set<String> vres = new HashSet<String>();
|
||||||
|
|
||||||
|
// get the group id from the current context
|
||||||
|
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(context);
|
||||||
|
GCubeUser currUser = userManager.getUserByUsername(username);
|
||||||
|
List<GCubeGroup> userContexts = groupManager.listGroupsByUser(currUser.getUserId());
|
||||||
|
|
||||||
|
if (groupManager.isRootVO(currentGroupId)) {
|
||||||
|
for (GCubeGroup group : groupManager.listGroupsByUser(currUser.getUserId())) {
|
||||||
|
if (groupManager.isVRE(group.getGroupId()) && userContexts.contains(group)) {
|
||||||
|
vres.add(groupManager.getInfrastructureScope(group.getGroupId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(groupManager.isVO(currentGroupId)){
|
||||||
|
for (GCubeGroup group : groupManager.listGroupsByUser(currUser.getUserId())) {
|
||||||
|
if (groupManager.isVRE(group.getGroupId()) && group.getParentGroupId() == currentGroupId && userContexts.contains(group)) {
|
||||||
|
vres.add(groupManager.getInfrastructureScope(group.getGroupId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vres.add(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
// query elastic search
|
||||||
|
List<EnhancedPost> enhancedPosts = ElasticSearchConnection.getSingleton().getElasticSearchClient().search(query, vres, from, quantity);
|
||||||
|
Filters.hideSensitiveInformation(enhancedPosts, secret.getOwner().getId());
|
||||||
|
SocialDBDriver store = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
|
||||||
|
// retrieve the ids of liked Posts by the user
|
||||||
|
List<String> likedPosts = store.getAllLikedPostIdsByUser(username);
|
||||||
|
|
||||||
|
// update fields "liked" and "isuser"
|
||||||
|
for (EnhancedPost enhancedPost : enhancedPosts) {
|
||||||
|
if(isUsers(enhancedPost.getPost(), username))
|
||||||
|
enhancedPost.setUsers(true);
|
||||||
|
if(likedPosts.contains(enhancedPost.getPost().getKey()))
|
||||||
|
enhancedPost.setLiked(true);
|
||||||
|
}
|
||||||
|
responseBean.setResult((ArrayList<EnhancedPost>) enhancedPosts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Something went wrong while searching", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tell if a Post belongs to the current user or not
|
||||||
|
* @param tocheck
|
||||||
|
* @param username
|
||||||
|
* @return true if this Post is of the current user
|
||||||
|
*/
|
||||||
|
private static final boolean isUsers(Post tocheck, String username) {
|
||||||
|
return (tocheck.getEntityId().equals(username));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.server.SocialDBDriver;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (hash tags).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Path("2/hashtags")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class HashTags {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HashTags.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("get-hashtags-and-occurrences/")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* @return hashtags in the context bound to the auth token
|
||||||
|
*/
|
||||||
|
public Response getHashTagsAndOccurrences(){
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
logger.debug("User " + username + " has requested hashtags of context " + context);
|
||||||
|
|
||||||
|
try{
|
||||||
|
SocialDBDriver datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
// TODO handle the case of VO and ROOT
|
||||||
|
boolean isVRE = GroupManagerWSBuilder.getInstance().getGroupManager().isVRE(GroupManagerWSBuilder.getInstance().getGroupManager().getGroupIdFromInfrastructureScope(context));
|
||||||
|
if(isVRE){
|
||||||
|
Map<String, Integer> map = datastore.getVREHashtagsWithOccurrence(context);
|
||||||
|
responseBean.setResult(map);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}else{
|
||||||
|
responseBean.setMessage("Please provide a VRE token. VO and ROOT VO cases are not yet managed.");
|
||||||
|
responseBean.setResult(false);
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to retrieve hashtags", e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,166 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
||||||
|
import org.gcube.social_networking.ws.inputs.LikeInputBean;
|
||||||
|
import org.gcube.social_networking.ws.inputs.PostId;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.SocialUtils;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (likes).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Path("2/likes")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class Likes {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Likes.class);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("get-likes-by-post-id")
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "The list of likes is put into the 'result' field"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response getAllLikesByPostId(
|
||||||
|
@NotNull
|
||||||
|
@QueryParam("key")
|
||||||
|
String key) {
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
List<Like> likes = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving likes for user id " + username);
|
||||||
|
likes = CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(key);
|
||||||
|
responseBean.setResult(likes);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such likes.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new like to a post in the context of the token
|
||||||
|
* @param postid The post id to be liked
|
||||||
|
* @return true if everything is OK
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("like-post")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response like(
|
||||||
|
@NotNull(message="Post to like is missing")
|
||||||
|
@Valid
|
||||||
|
PostId post) throws ValidationException {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
logger.debug("Request of like coming from user " + username);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
boolean likeResultOperation = SocialUtils.like(username, post.getPostId(), context);
|
||||||
|
if (likeResultOperation)
|
||||||
|
logger.debug("Added like OK to postId " + post.getPostId());
|
||||||
|
else {
|
||||||
|
logger.error("Unable to like this post"+ post.getPostId());
|
||||||
|
responseBean.setMessage("Unable to like, something went wrong please see server log");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBean.setResult(true);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlike to a post in the context of the token
|
||||||
|
* @param postid The post id to be liked
|
||||||
|
* @return true if everything is OK
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("unlike-post")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response unlike(
|
||||||
|
@NotNull(message="Post to unlike is missing")
|
||||||
|
@Valid
|
||||||
|
LikeInputBean likeInputBean) throws ValidationException {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
logger.debug("Request of unlike coming from user " + username);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
boolean likeResultOperation = SocialUtils.unlike(username, likeInputBean.getLikeid(), likeInputBean.getPostid());
|
||||||
|
if (likeResultOperation)
|
||||||
|
logger.debug("Unlike OK to postId " + likeInputBean.getPostid());
|
||||||
|
else {
|
||||||
|
logger.error("Unable to unlike this post"+ likeInputBean.getPostid());
|
||||||
|
responseBean.setMessage("Unable to unlike, something went wrong please see server log");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBean.setResult(true);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,300 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
|
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||||
|
import org.gcube.common.storagehub.model.messages.Message;
|
||||||
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
|
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
||||||
|
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||||
|
import org.gcube.social_networking.caches.SocialNetworkingSiteFinder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.LiferayJSONWsCredentials;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.ws.ex.AuthException;
|
||||||
|
import org.gcube.social_networking.ws.inputs.UserSetNotificationBean;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.TokensUtils;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Messages services REST interface
|
||||||
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
|
* (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
@Path("2/messages")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class Messages {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Messages.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a message to another user. The sender is the token's owner by default
|
||||||
|
* @responseExample application/json {"success": true, "message": null, "result": "556142e3-d6f5-4550-b2fa-abe5626625d3"}
|
||||||
|
* @param input The message to write"
|
||||||
|
* @param httpServletRequest
|
||||||
|
* @return see response example
|
||||||
|
* @throws ValidationException
|
||||||
|
* @throws UserManagementSystemException
|
||||||
|
* @throws UserRetrievalFault
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("write-message/")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Successful write a message. Its id is reported in the 'result' field of the returned object"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response writeMessage(
|
||||||
|
@NotNull(message="Message to send is missing")
|
||||||
|
@Valid
|
||||||
|
MessageInputBean input,
|
||||||
|
@Context HttpServletRequest httpServletRequest) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
||||||
|
|
||||||
|
logger.debug("Incoming message bean is " + input);
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
|
||||||
|
UserManager um = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
GCubeUser senderUser = null;
|
||||||
|
SocialNetworkingUser user = null;
|
||||||
|
// check if the token belongs to an application token. In this case use J.A.R.V.I.S (the username used to communicate with Liferay)
|
||||||
|
String username = null;
|
||||||
|
String fullName = "";
|
||||||
|
|
||||||
|
logger.debug("Catalogue Notification called by " + secret.getOwner().getId() + " isUser?"+TokensUtils.isUserToken(caller));
|
||||||
|
if(!TokensUtils.isUserToken(caller)){
|
||||||
|
GCubeUser jarvis = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
|
username = jarvis.getUsername();
|
||||||
|
fullName = secret.getOwner().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
|
}else{
|
||||||
|
username = secret.getOwner().getId();
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
fullName = senderUser.getFullname();
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
|
}
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.CREATED;
|
||||||
|
String body = input.getBody();
|
||||||
|
String subject = input.getSubject();
|
||||||
|
List<Recipient> recipientsIds = input.getRecipients(); // "recipients":[{"recipient":"id recipient"}, ......]
|
||||||
|
logger.debug("Sender is going to be [" + fullName + "]");
|
||||||
|
|
||||||
|
// get the recipients ids (simple check, trim)
|
||||||
|
List<String> recipientsListFiltered = new ArrayList<String>();
|
||||||
|
List<GenericItemBean> recipientsBeans = new ArrayList<GenericItemBean>();
|
||||||
|
for (Recipient recipientId : recipientsIds) {
|
||||||
|
try{
|
||||||
|
String tempId = recipientId.getId().trim();
|
||||||
|
if(tempId.isEmpty())
|
||||||
|
continue;
|
||||||
|
GCubeUser userRecipient = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(tempId);
|
||||||
|
if(userRecipient == null)
|
||||||
|
userRecipient = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(tempId);
|
||||||
|
if(userRecipient != null){
|
||||||
|
GenericItemBean beanUser = new GenericItemBean(userRecipient.getUsername(), userRecipient.getUsername(), userRecipient.getFullname(), userRecipient.getUserAvatarURL());
|
||||||
|
recipientsBeans.add(beanUser);
|
||||||
|
recipientsListFiltered.add(userRecipient.getUsername());
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve recipient information for recipient with id " + recipientId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(recipientsListFiltered.isEmpty()){
|
||||||
|
logger.error("Missing/wrong request parameters");
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
responseBean.setMessage(ErrorMessages.MISSING_PARAMETERS);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
logger.debug("Trying to send message with body " + body + " subject " + subject + " to users " + recipientsIds + " from " + username);
|
||||||
|
|
||||||
|
// send message
|
||||||
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
logger.debug("Sending message to " + recipientsListFiltered);
|
||||||
|
String messageId = client.sendMessage(recipientsListFiltered, subject, body, input.getAttachmentIds());
|
||||||
|
|
||||||
|
// send notification
|
||||||
|
logger.debug("Message sent to " + recipientsIds + ". Sending message notification to: " + recipientsIds);
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, secret.getContext(), user);
|
||||||
|
new Thread(new MessageNotificationsThread(recipientsBeans, messageId, subject, body, nm)).start();
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(messageId);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to send message.", e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
responseBean.setMessage(e.toString());
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("get-sent-messages")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Successful read of the sent messages, reported in the 'result' field of the returned object"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the list of sent messages of the user (the token's owner)
|
||||||
|
*/
|
||||||
|
public Response getSentMessages(){
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
logger.debug("Request for retrieving sent messages by " + username);
|
||||||
|
|
||||||
|
try{
|
||||||
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
List<Message> sentMessages = client.getSentMessages();
|
||||||
|
Collections.reverse(sentMessages);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
logger.debug("Result is " + sentMessages);
|
||||||
|
responseBean.setResult(sentMessages);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve sent messages", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("get-received-messages")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Successful read of the received messages, reported in the 'result' field of the returned object"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the list of received messages of the user (the token's owner)
|
||||||
|
*/
|
||||||
|
public Response getReceivedMessages(){
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
logger.debug("Request for retrieving received messages by " + username);
|
||||||
|
try{
|
||||||
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
List<Message> getMessages =client.getReceivedMessages();
|
||||||
|
Collections.reverse(getMessages);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(getMessages);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve sent messages", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set message read or unread
|
||||||
|
* @param messageId the message identifier
|
||||||
|
* @param read true to set read, false to set unread
|
||||||
|
* @return the result of the operation
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("set-message-read/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Message set Read or Unread is correctly executed"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response setMessageRead(
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@FormParam("messageId") String messageId,
|
||||||
|
@FormParam("read") Boolean read) throws ValidationException{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
String opExecutor = "";
|
||||||
|
try{
|
||||||
|
opExecutor = secret.getOwner().getId();
|
||||||
|
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||||
|
client.setRead(messageId, read);
|
||||||
|
String toReturn = "set Message id:" + messageId + (read ? " read" : " unread");
|
||||||
|
logger.debug("set Message id:" + messageId + " read?" + read + " for " + opExecutor);
|
||||||
|
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(toReturn);
|
||||||
|
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to set message read / unread property for user " + opExecutor, e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,688 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
|
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||||
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Notification;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.NotificationChannelType;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.NotificationType;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.RunningJob;
|
||||||
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
|
import org.gcube.portal.notifications.thread.JobStatusNotificationThread;
|
||||||
|
import org.gcube.social_networking.caches.SocialNetworkingSiteFinder;
|
||||||
|
import org.gcube.social_networking.caches.UsersCache;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.LiferayJSONWsCredentials;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.ws.ex.AuthException;
|
||||||
|
import org.gcube.social_networking.ws.mappers.CatalogueEventTypeMapper;
|
||||||
|
import org.gcube.social_networking.ws.mappers.JobMapper;
|
||||||
|
import org.gcube.social_networking.ws.mappers.WorkspaceItemMapper;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.TokensUtils;
|
||||||
|
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.workspace.AddedItemEvent;
|
||||||
|
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.FolderAdminDowngradeEvent;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderAdminUpgradeEvent;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderRemovedUserEvent;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.RenamedFolderEvent;
|
||||||
|
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.UpdatedItemEvent;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.mortbay.log.Log;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (notifications).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Path("2/notifications")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class Notifications {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Notifications.class);
|
||||||
|
private static final String INFRASTRUCTURE_MANAGER_ROLE = "Infrastructure-Manager";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve notifications of the token's owner
|
||||||
|
* @param from must be greater or equal to 1, range[0, infinity]
|
||||||
|
* @param quantity quantity must be greater or equal to 0
|
||||||
|
* @return notifications up to quantity
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-range-notifications/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getRangeNotifications(
|
||||||
|
@DefaultValue("1") @QueryParam("from") @Min(value=1, message="from must be greater or equal to 1")
|
||||||
|
int from,
|
||||||
|
@DefaultValue("10") @QueryParam("quantity") @Min(value=0, message="quantity must be greater or equal to 0")
|
||||||
|
int quantity
|
||||||
|
) throws ValidationException{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
logger.debug("Retrieving " + quantity + " notifications of user = " + username + " from " + from);
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
List<Notification> notifications = null;
|
||||||
|
try{
|
||||||
|
notifications = CassandraConnection.getInstance().getDatabookStore().getRangeNotificationsByUser(username, from, quantity);
|
||||||
|
responseBean.setResult(notifications);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
logger.debug("List of notifications retrieved");
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such notifications.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the notifications for this user are enabled or not
|
||||||
|
* @pathExample /is-user-disabled?username=john.smith
|
||||||
|
* @responseExample application/json { "success": true, "message": null "result": true }
|
||||||
|
* @param username the username you want to check
|
||||||
|
* @return true if the notification for the user are disabled (Catalogue and Workspace ones)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("is-user-disabled/")
|
||||||
|
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@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 = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
@AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
|
public Response isUserDisabled(
|
||||||
|
@QueryParam("username") @NotNull(message="username cannot be null")
|
||||||
|
String username) throws ValidationException{
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
Boolean userDisabled= !isNotificationEnabled(username);
|
||||||
|
responseBean.setResult(userDisabled);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
logger.debug("are User " + username + " Notifications Disabled?"+userDisabled);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to read whether the notifications for this user are enabled or not.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 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
|
||||||
|
// * @return the result of the operation
|
||||||
|
// * @throws ValidationException
|
||||||
|
// */
|
||||||
|
// @POST
|
||||||
|
// @Path("set-user-notifications/")
|
||||||
|
// @Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
|
// @StatusCodes ({
|
||||||
|
// @ResponseCode ( code = 200, condition = "Notification set Off or On correctly executed"),
|
||||||
|
// @ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
// })
|
||||||
|
// @AuthorizationControl(allowedRoles={INFRASTRUCTURE_MANAGER_ROLE}, exception=AuthException.class)
|
||||||
|
// public Response setUserNotifications(
|
||||||
|
// @NotNull(message="input is missing")
|
||||||
|
// @Valid
|
||||||
|
// UserSetNotificationBean setting) throws ValidationException{
|
||||||
|
//
|
||||||
|
// Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
// String context = ScopeProvider.instance.get();
|
||||||
|
// ResponseBean responseBean = new ResponseBean();
|
||||||
|
// Status status = Status.OK;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// try{
|
||||||
|
// String opExecutor = caller.getClient().getId();
|
||||||
|
// Boolean result = setUserNotificationsOnOff(setting.getUsername(), setting.isDisableNotification(), opExecutor);
|
||||||
|
// String toReturn = "Could not set notifications";
|
||||||
|
// if (result) {
|
||||||
|
// toReturn = "Notifications have been set";
|
||||||
|
// toReturn += setting.isDisableNotification() ? " OFF (for 29 days unless re-enabled manually) ": " ON ";
|
||||||
|
// toReturn += "for username=" + setting.getUsername();
|
||||||
|
// }
|
||||||
|
// responseBean.setSuccess(true);
|
||||||
|
// responseBean.setResult(toReturn);
|
||||||
|
//
|
||||||
|
// } catch(Exception e){
|
||||||
|
// logger.error("Unable to set user notification", e);
|
||||||
|
// responseBean.setSuccess(false);
|
||||||
|
// responseBean.setMessage(e.getMessage());
|
||||||
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return Response.status(status).entity(responseBean).build();
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @param usernameToCheck
|
||||||
|
* @return true if notification are enabled for this user
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private boolean isNotificationEnabled(String usernameToCheck) throws IOException {
|
||||||
|
// MemcachedClient entries = new DistributedCacheClient().getMemcachedClient();
|
||||||
|
// String key = SocialUtils.DISABLED_USERS_NOTIFICATIONS_NAMESPACE+usernameToCheck;
|
||||||
|
// Boolean userEnabled = false;
|
||||||
|
// if(entries.get(key) == null)
|
||||||
|
// userEnabled = true;
|
||||||
|
// 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
|
||||||
|
// * @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
|
||||||
|
* @param job The job bean
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("notify-job-status/")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response notifyJobStatus(
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@Valid
|
||||||
|
JobNotificationBean job) throws ValidationException{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
String appQualifier = secret.getOwner().getId();
|
||||||
|
logger.debug("Received request from app " + appQualifier + " to notify job status described by bean " + job);
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
String recipient = job.getRecipient();
|
||||||
|
GCubeUser userRecipient = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(recipient);
|
||||||
|
GenericItemBean recipientBean = new GenericItemBean(userRecipient.getUsername(), userRecipient.getUsername(), userRecipient.getFullname(), userRecipient.getUserAvatarURL());
|
||||||
|
|
||||||
|
// notifications are sent by using the user allowed to use liferay's json apis
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
|
RunningJob theJob = JobMapper.getJob(job);
|
||||||
|
|
||||||
|
new Thread(new JobStatusNotificationThread(theJob, Arrays.asList(recipientBean), nm)).start();
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult("Notification thread started");
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Catalogue notification to a given user
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("catalogue/")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Catalogue Notification is sent correctly"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response catalogue(
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@Valid
|
||||||
|
CatalogueEvent event) throws ValidationException, UserManagementSystemException, UserRetrievalFault{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
|
||||||
|
UserManager um = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
GCubeUser senderUser = null;
|
||||||
|
SocialNetworkingUser user = null;
|
||||||
|
// check if the token belongs to an application token. In this case use J.A.R.V.I.S (the username used to communicate with Liferay)
|
||||||
|
String username = null;
|
||||||
|
String fullName = "";
|
||||||
|
logger.debug("Catalogue Notification called by " + secret.getOwner().getId() + " isUser?"+TokensUtils.isUserToken(caller));
|
||||||
|
if(!TokensUtils.isUserToken(caller)){
|
||||||
|
GCubeUser jarvis = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
|
username = jarvis.getUsername();
|
||||||
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
|
}else{
|
||||||
|
username = secret.getOwner().getId();
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
String context = secret.getContext();
|
||||||
|
|
||||||
|
logger.debug("catalogue notifications from user = " + username);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
boolean deliveryResult = false;
|
||||||
|
try {
|
||||||
|
//logger.debug("catalogue notifications type is " + event.getType());
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
//logger.debug("social networking site is " + site.getName());
|
||||||
|
//logger.debug("context is " + context);
|
||||||
|
//logger.debug("user is " + user.getUsername());
|
||||||
|
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
|
if (! event.idsAsGroup()) {
|
||||||
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
|
String userIdToNotify = idsToNotify[i];
|
||||||
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
|
String username2Notify = null;
|
||||||
|
try {
|
||||||
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
logger.error("Username not found", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Username not found, got: " + userIdToNotify);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
//logger.debug("username2notify " + username2Notify);
|
||||||
|
//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(
|
||||||
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
|
username2Notify,
|
||||||
|
event.getItemId(),
|
||||||
|
event.getNotifyText(),
|
||||||
|
event.getItemURL());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else { //the ids are contexts
|
||||||
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
|
String contextId = idsToNotify[i];
|
||||||
|
try {
|
||||||
|
ScopeBean scope = new ScopeBean(contextId);
|
||||||
|
if (scope.type() != ScopeBean.Type.VRE) {
|
||||||
|
logger.error("Context not a VRE");
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Not a VRE Context, only VREs are supported");
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
} else { // it is a context and it is a valid VRE
|
||||||
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
|
deliveryResult =
|
||||||
|
nm.notifyCatalogueEvent(
|
||||||
|
CatalogueEventTypeMapper.getType(event.getType()),
|
||||||
|
userIdToNotify,
|
||||||
|
event.getItemId(),
|
||||||
|
event.getNotifyText(),
|
||||||
|
event.getItemURL());
|
||||||
|
} else {
|
||||||
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException e) {
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
logger.error("Context not valid", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Context not valid, must start with / " + e.getMessage());
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
logger.debug("catalogue notifications should have been sent");
|
||||||
|
if (deliveryResult) {
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setMessage("catalogue notification delivered correctly");
|
||||||
|
responseBean.setResult(new Boolean(true));
|
||||||
|
} else {
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("An error occurred between this service and Cassandra DB, notification not delivered correctly");
|
||||||
|
responseBean.setResult(new Boolean(false));
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Workspace notification to a given user
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("workspace/")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response workspace(
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@Valid
|
||||||
|
WorkspaceEvent event) throws ValidationException{
|
||||||
|
|
||||||
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
String context = ScopeProvider.instance.get();
|
||||||
|
String username = caller.getClient().getId();
|
||||||
|
|
||||||
|
logger.debug("workspace notifications from = " + username);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
boolean deliveryResult = false;
|
||||||
|
try {
|
||||||
|
GCubeUser senderUser = null;
|
||||||
|
SocialNetworkingUser user = null;
|
||||||
|
String fullName = "";
|
||||||
|
logger.debug("workspace notifications type is " + event.getType());
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
UserManager um = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
logger.debug("Workspace Notification called by " + caller.getClient().getId() + " isUser?"+TokensUtils.isUserToken(caller));
|
||||||
|
if(!TokensUtils.isUserToken(caller)){
|
||||||
|
GCubeUser jarvis = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SecurityTokenProvider.instance.set(LiferayJSONWsCredentials.getSingleton().getNotifierUserToken());
|
||||||
|
username = jarvis.getUsername();
|
||||||
|
fullName = caller.getClient().getId().replace("service-account-", ""); // the actual name of the IAM Client
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), fullName, senderUser.getUserAvatarURL());
|
||||||
|
}else{
|
||||||
|
username = caller.getClient().getId();
|
||||||
|
senderUser = um.getUserByUsername(username);
|
||||||
|
user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
|
}
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
|
||||||
|
String[] idsToNotify = event.getIdsToNotify();
|
||||||
|
if (! event.idsAsGroup()) {
|
||||||
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
|
String userIdToNotify = idsToNotify[i];
|
||||||
|
if (isNotificationEnabled(userIdToNotify)) {
|
||||||
|
String username2Notify = "";
|
||||||
|
try {
|
||||||
|
username2Notify = um.getUserByUsername(userIdToNotify).getUsername();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
status = Status.NOT_ACCEPTABLE;
|
||||||
|
logger.error("Username not found", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Username not found, received: " + userIdToNotify);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
deliveryResult = notifyWorkspaceEvent(event, nm, username2Notify);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { //the ids are contexts
|
||||||
|
for (int i = 0; i < idsToNotify.length; i++) {
|
||||||
|
String contextId = idsToNotify[i];
|
||||||
|
try {
|
||||||
|
ScopeBean scope = new ScopeBean(contextId);
|
||||||
|
if (scope.type() != ScopeBean.Type.VRE) {
|
||||||
|
logger.error("Context not a VRE");
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Not a VRE Context, only VREs are supported");
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
} else { // it is a context and it is a valid VRE
|
||||||
|
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
|
||||||
|
for (int j = 0; j < userIdsToNotify.length; j++) {
|
||||||
|
String userIdToNotify = userIdsToNotify[j];
|
||||||
|
if (isNotificationEnabled(userIdToNotify))
|
||||||
|
deliveryResult = notifyWorkspaceEvent(event, nm, userIdToNotify);
|
||||||
|
else {
|
||||||
|
Log.info("Notification disabled (admin) for user "+userIdToNotify + " will not notify");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException e) {
|
||||||
|
status = Status.BAD_REQUEST;
|
||||||
|
logger.error("Context not valid", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("Context not valid, must start with / " + e.getMessage());
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
logger.debug("workspace notifications should have been sent");
|
||||||
|
if (deliveryResult) {
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setMessage("Workspace notification delivered correctly");
|
||||||
|
responseBean.setResult(new Boolean(true));
|
||||||
|
} else {
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage("An error occurred between this service and Cassandra DB, notification not delivered correctly");
|
||||||
|
responseBean.setResult(new Boolean(false));
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* @param nm
|
||||||
|
* @param idToNotify
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean notifyWorkspaceEvent(WorkspaceEvent event, NotificationsManager nm, String idToNotify) {
|
||||||
|
try {
|
||||||
|
switch (event.getType()) {
|
||||||
|
case ITEM_NEW: {
|
||||||
|
AddedItemEvent itemBean = (AddedItemEvent) event;
|
||||||
|
return nm.notifyAddedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
|
}
|
||||||
|
case ITEM_UPDATE: {
|
||||||
|
UpdatedItemEvent itemBean = (UpdatedItemEvent) event;
|
||||||
|
return nm.notifyUpdatedItem(idToNotify, WorkspaceItemMapper.getFileItem(itemBean.getItem()), WorkspaceItemMapper.getSharedFolder(itemBean.getItem().getParent()));
|
||||||
|
}
|
||||||
|
case ITEM_DELETE: {
|
||||||
|
DeletedItemEvent itemBean = (DeletedItemEvent) event;
|
||||||
|
return nm.notifyRemovedItem(idToNotify, itemBean.getItemName(), WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
|
}
|
||||||
|
case FOLDER_SHARE: {
|
||||||
|
SharedFolderEvent itemBean = (SharedFolderEvent) event;
|
||||||
|
return nm.notifyFolderSharing(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
|
}
|
||||||
|
case FOLDER_UNSHARE: {
|
||||||
|
UnsharedFolderEvent itemBean = (UnsharedFolderEvent) event;
|
||||||
|
return nm.notifyFolderUnsharing(idToNotify, itemBean.getUnsharedFolderId(), itemBean.getUnsharedFolderName());
|
||||||
|
}
|
||||||
|
case FOLDER_RENAME: {
|
||||||
|
RenamedFolderEvent itemBean = (RenamedFolderEvent) event;
|
||||||
|
return nm.notifyFolderRenaming(idToNotify, itemBean.getPreviousName(), itemBean.getNewName(), itemBean.getRenamedFolderId());
|
||||||
|
}
|
||||||
|
case FOLDER_ADMIN_UPGRADE: {
|
||||||
|
FolderAdminUpgradeEvent itemBean = (FolderAdminUpgradeEvent) event;
|
||||||
|
return nm.notifyAdministratorUpgrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
|
}
|
||||||
|
case FOLDER_ADMIN_DOWNGRADE: {
|
||||||
|
FolderAdminDowngradeEvent itemBean = (FolderAdminDowngradeEvent) event;
|
||||||
|
return nm.notifyAdministratorDowngrade(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
|
}
|
||||||
|
case FOLDER_ADDEDUSER: {
|
||||||
|
FolderAddedUserEvent itemBean = (FolderAddedUserEvent) event;
|
||||||
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
return nm.notifyFolderAddedUsers(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()), itemBean.getNewAddedUserIds(), userManager);
|
||||||
|
}
|
||||||
|
case FOLDER_REMOVEDUSER: {
|
||||||
|
FolderRemovedUserEvent itemBean = (FolderRemovedUserEvent) event;
|
||||||
|
return nm.notifyFolderRemovedUser(idToNotify, WorkspaceItemMapper.getSharedFolder(itemBean.getFolder()));
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private List<String> getUsernamesByContext(ScopeBean context) throws Exception {
|
||||||
|
List<String> usernames = new ArrayList<String>();
|
||||||
|
GroupManager groupManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
long groupId = groupManager.getGroupIdFromInfrastructureScope(context.toString());
|
||||||
|
|
||||||
|
// first retrieve ids
|
||||||
|
List<Long> userIds = userManager.getUserIdsByGroup(groupId);
|
||||||
|
|
||||||
|
// check info in cache when available
|
||||||
|
UsersCache cache = UsersCache.getSingleton();
|
||||||
|
|
||||||
|
for (Long userId : userIds) {
|
||||||
|
if(cache.getUser(userId) == null){
|
||||||
|
GCubeUser theUser = userManager.getUserById(userId);
|
||||||
|
if(theUser != null){
|
||||||
|
usernames.add(theUser.getUsername());
|
||||||
|
cache.pushEntry(userId, theUser);
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
usernames.add(cache.getUser(userId).getUsername());
|
||||||
|
}
|
||||||
|
return usernames;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,701 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.*;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.ColumnNameNotFoundException;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostTypeNotFoundException;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PrivacyLevelTypeNotFoundException;
|
||||||
|
import org.gcube.social_networking.ws.inputs.PostInputBean;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.social_networking.server.SocialDBDriver;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.Filters;
|
||||||
|
import org.gcube.social_networking.ws.utils.SocialUtils;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (posts).
|
||||||
|
* @author Ahmed Ibrahim ISTI-CNR
|
||||||
|
*/
|
||||||
|
@Path("2/posts")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class Posts {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
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"
|
||||||
|
* @param timeInMillis The reference time since when retrieving posts
|
||||||
|
* @return the posts
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-user-since/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getRecentPostsByUserAndDate(
|
||||||
|
@QueryParam("time") @Min(value = 0, message="time cannot be negative")
|
||||||
|
long timeInMillis
|
||||||
|
) throws ValidationException{
|
||||||
|
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
List<Post> posts = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving post for user id " + username + " and reference time " + timeInMillis);
|
||||||
|
posts = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByUserAndDate(username, timeInMillis);
|
||||||
|
Filters.filterPostsPerContext(posts, context);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all user's posts
|
||||||
|
* @return all posts of the auth token's owner in the context identified by the token
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-user/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getAllPostsByUser() {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
List<Post> posts = null;
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving posts for user with id " + username);
|
||||||
|
posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(username);
|
||||||
|
Filters.filterPostsPerContext(posts, context);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such Posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a post by id
|
||||||
|
* @return the post if the post id belongs to a post in the context identified by the token
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-post/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getPost(@QueryParam("id") String id) {
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
List<Post> posts = new ArrayList<>();
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving post with id " + id);
|
||||||
|
try {
|
||||||
|
posts.add(CassandraConnection.getInstance().getDatabookStore().readPost(id));
|
||||||
|
} catch(PostIDNotFoundException e){
|
||||||
|
responseBean.setMessage("The post with id " + id + " does not exist in context " + context);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
Filters.filterPostsPerContext(posts, context);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
if (posts.isEmpty()) {
|
||||||
|
responseBean.setMessage("The post with id " + id + " does not belong to this context " + context);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
responseBean.setResult(posts.get(0));
|
||||||
|
responseBean.setMessage("");
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such post.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a given quantity of latest user's posts
|
||||||
|
* @param quantity the number of latest post to get
|
||||||
|
* @pathExample /get-posts-user-quantity?quantity=10
|
||||||
|
* @return all posts of the auth token's owner in the context identified by the token, in reverse chronological order up to quantity (at most)
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-user-quantity/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getQuantityPostsByUser(
|
||||||
|
@DefaultValue("10")
|
||||||
|
@QueryParam("quantity")
|
||||||
|
@Min(value=0, message="quantity cannot be negative")
|
||||||
|
int quantity) throws ValidationException{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
List<Post> posts = new ArrayList<>();
|
||||||
|
|
||||||
|
// if quantity is zero, just return an empty list
|
||||||
|
if(quantity == 0){
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
logger.debug("getRecentPostsByUser first, posts made by user " + username);
|
||||||
|
posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByUser(username);
|
||||||
|
if (posts != null)
|
||||||
|
logger.debug("got " + posts.size() + " posts");
|
||||||
|
logger.debug("Retrieving last " + quantity + " posts made by user " + username + " in context = "+context);
|
||||||
|
Filters.filterPostsPerContext(posts, context);
|
||||||
|
quantity = (quantity > posts.size()) ? posts.size() : quantity;
|
||||||
|
posts = posts.subList(0, quantity);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve such posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user post having as owner the auth token's owner
|
||||||
|
* @param post The post to be written
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("write-post-user")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response writePostUser(
|
||||||
|
@NotNull(message="Post to write is missing")
|
||||||
|
@Valid
|
||||||
|
PostInputBean post) throws ValidationException{
|
||||||
|
|
||||||
|
logger.debug("Request of writing a Post coming from user " + post);
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.CREATED;
|
||||||
|
|
||||||
|
// parse
|
||||||
|
String postText = post.getText();
|
||||||
|
String previewTitle = post.getPreviewtitle();
|
||||||
|
String previewDescription = post.getPreviewdescription();
|
||||||
|
String previewHost = post.getPreviewhost();
|
||||||
|
String previewUrl = post.getPreviewurl();
|
||||||
|
String httpImageUrl = post.getHttpimageurl();
|
||||||
|
boolean enableNotification = post.isEnablenotification();
|
||||||
|
|
||||||
|
// convert enablenotification parameter
|
||||||
|
if(enableNotification)
|
||||||
|
logger.debug("Enable notification for this user post.");
|
||||||
|
else
|
||||||
|
logger.debug("Disable notification for this user post.");
|
||||||
|
|
||||||
|
|
||||||
|
// try to share
|
||||||
|
logger.debug("Trying to share user post...");
|
||||||
|
Post res = SocialUtils.shareUserUpdate(
|
||||||
|
username,
|
||||||
|
postText,
|
||||||
|
context,
|
||||||
|
previewTitle,
|
||||||
|
previewDescription,
|
||||||
|
previewHost,
|
||||||
|
previewUrl,
|
||||||
|
httpImageUrl,
|
||||||
|
enableNotification
|
||||||
|
);
|
||||||
|
|
||||||
|
if(res != null){
|
||||||
|
logger.debug("Post correctly written by user " + username);
|
||||||
|
responseBean.setResult(res);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Unable to write post.");
|
||||||
|
responseBean.setMessage("Unable to write post");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the application's posts
|
||||||
|
* @return the application (IAM Client) posts belonging to the token's owner (i.e., an application)"
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-app/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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 = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response getAllPostsByApp() {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String appId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
// check if the token actually matches an application
|
||||||
|
ApplicationProfile appProfile = SocialUtils.getProfileFromInfrastrucure(appId, context);
|
||||||
|
if(appProfile == null){
|
||||||
|
|
||||||
|
logger.error("The given token is not belonging to an application!!!");
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(ErrorMessages.NOT_APP_TOKEN);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
|
||||||
|
logger.debug("Retrieving posts for app with id " + appId);
|
||||||
|
List<Post> posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByApp(appId);
|
||||||
|
Filters.filterPostsPerContext(posts, context);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
|
||||||
|
logger.error("Unable to retrieve such Posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
* @param post The post to be written
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("write-post-app")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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 = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response writePostApp(
|
||||||
|
@NotNull(message="Post to write is null")
|
||||||
|
@Valid
|
||||||
|
PostInputBean post){
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String appId = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.CREATED;
|
||||||
|
|
||||||
|
logger.debug("Request of writing a Post coming from an application.");
|
||||||
|
|
||||||
|
// check if the token actually matches an application profile
|
||||||
|
ApplicationProfile appProfile = SocialUtils.getProfileFromInfrastrucure(appId, context);
|
||||||
|
|
||||||
|
if(appProfile == null){
|
||||||
|
logger.error("The given token doesn't belong to an application!!!");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(ErrorMessages.NOT_APP_TOKEN);
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse
|
||||||
|
String postText = post.getText();
|
||||||
|
String previewTitle = post.getPreviewtitle();
|
||||||
|
String previewDescription = post.getPreviewdescription();
|
||||||
|
String httpImageUrl = post.getHttpimageurl();
|
||||||
|
boolean enableNotification = post.isEnablenotification();
|
||||||
|
String params = post.getParams();
|
||||||
|
|
||||||
|
// convert enablenotification parameter
|
||||||
|
if(enableNotification)
|
||||||
|
logger.debug("Enable notification for this application post.");
|
||||||
|
else
|
||||||
|
logger.debug("Disable notification for this application post.");
|
||||||
|
|
||||||
|
// write post + notification if it is the case
|
||||||
|
Post written = SocialUtils.shareApplicationUpdate(
|
||||||
|
postText,
|
||||||
|
params,
|
||||||
|
previewTitle,
|
||||||
|
previewDescription,
|
||||||
|
httpImageUrl,
|
||||||
|
appProfile,
|
||||||
|
secret,
|
||||||
|
enableNotification
|
||||||
|
);
|
||||||
|
|
||||||
|
if(written != null){
|
||||||
|
responseBean.setResult(written);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Unable to write post.");
|
||||||
|
responseBean.setMessage("Unable to write post");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return all the posts in the context bound to the auth token
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-vre/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getAllPostsByVRE() {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
logger.debug("Retrieving all posts coming from vre = " + context);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
List<Post> posts = CassandraConnection.getInstance().getDatabookStore().getAllPostsByVRE(context);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve posts for vre = " + context, e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
responseBean.setMessage(e.toString());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @param from the range start (most recent Posts for this vre) has to be greater than 0
|
||||||
|
* @param quantity the number of most recent Posts for this vre starting from "from" param
|
||||||
|
* @pathExample /get-recent-posts-vre-by-range?from=1&quantity=10
|
||||||
|
* @return a <class>RangePosts</class> containing of most recent Posts for this vre
|
||||||
|
* @throws PostTypeNotFoundException
|
||||||
|
* @throws PrivacyLevelTypeNotFoundException
|
||||||
|
* @throws ColumnNameNotFoundException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-recent-posts-vre-by-range/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getRecentPostsByVREAndRange(
|
||||||
|
@QueryParam("from")
|
||||||
|
@Min(value=1, message="from cannot be negative")
|
||||||
|
int from,
|
||||||
|
@QueryParam("quantity")
|
||||||
|
@Min(value=1, message="quantity cannot be negative")
|
||||||
|
int quantity) throws ValidationException {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String context = secret.getContext();
|
||||||
|
logger.debug("Retrieving all posts coming from vre = " + context);
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
RangePosts rangePosts = CassandraConnection.getInstance().getDatabookStore().getRecentPostsByVREAndRange(context, from, quantity);
|
||||||
|
Filters.hideSensitiveInformation(rangePosts.getPosts(), secret.getOwner().getId());
|
||||||
|
responseBean.setResult(rangePosts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to retrieve posts for vre = " + context, e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
responseBean.setMessage(e.toString());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve posts containing the hashtag in the context bound to the auth token
|
||||||
|
* @param hashtag he hashtag to be contained within the posts
|
||||||
|
* @pathExample /get-posts-by-hashtag?hashtag=#thehashtag
|
||||||
|
* @return the posts in the context bound to the auth token matching the hashtag
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-posts-by-hashtag/")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getPostsByHashTags(
|
||||||
|
@QueryParam("hashtag")
|
||||||
|
@NotNull(message="hashtag cannot be missing")
|
||||||
|
String hashtag) throws ValidationException {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
logger.debug("User " + username + " has requested posts containing hashtag " + hashtag + " in context " + context);
|
||||||
|
try{
|
||||||
|
SocialDBDriver datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
List<Post> posts = datastore.getVREPostsByHashtag(context, hashtag);
|
||||||
|
Filters.hideSensitiveInformation(posts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(posts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to retrieve hashtags", e);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-id-liked-posts/")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getAllLikedPostIdsByUser() {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
logger.debug("Retrieving all liked posts for user with id " + username + " in context " + context);
|
||||||
|
|
||||||
|
List<String> retrievedLikedPostsIds = null;
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
try{
|
||||||
|
|
||||||
|
SocialDBDriver datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
retrievedLikedPostsIds = datastore.getAllLikedPostIdsByUser(username);
|
||||||
|
Filters.filterPostsPerContextById(retrievedLikedPostsIds, context);
|
||||||
|
responseBean.setResult(retrievedLikedPostsIds);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
logger.debug("Ids of liked posts by " + username + " retrieved");
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to read such ids of liked Posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve posts liked by the user
|
||||||
|
* @param limit The maximum number of posts to be retrieved
|
||||||
|
* @return posts liked by the user (up to a given quantity) in the context bound to the auth token
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("get-liked-posts/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@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)
|
||||||
|
})
|
||||||
|
public Response getAllLikedPostsByUser(
|
||||||
|
@DefaultValue("10")
|
||||||
|
@QueryParam("limit")
|
||||||
|
@Min(message="limit cannot be negative", value = 0)
|
||||||
|
int limit) throws ValidationException{
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
String context = secret.getContext();
|
||||||
|
List<Post> retrievedLikedPosts = null;
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Retrieving " + limit + " liked posts for user with id " + username + " in context " + context);
|
||||||
|
retrievedLikedPosts = CassandraConnection.getInstance().getDatabookStore().getAllLikedPostsByUser(username, limit);
|
||||||
|
Filters.filterPostsPerContext(retrievedLikedPosts, context);
|
||||||
|
Filters.hideSensitiveInformation(retrievedLikedPosts, secret.getOwner().getId());
|
||||||
|
responseBean.setResult(retrievedLikedPosts);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
logger.debug("Liked posts by " + username + " retrieved");
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to read such liked posts.", e);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.ApplicationProfile;
|
||||||
|
import org.gcube.social_networking.ws.inputs.ApplicationId;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.social_networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.ws.utils.SocialUtils;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (tokens).
|
||||||
|
*/
|
||||||
|
@Path("2/tokens")
|
||||||
|
@Deprecated
|
||||||
|
public class Tokens {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Tokens.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("generate-application-token/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 201, condition = "Successful creation of the token, reported in the 'result' field of the returned object"),
|
||||||
|
@ResponseCode ( code = 403, condition = "There is no application profile with such id"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* Generate a legacy application auth token for the application with id app_id
|
||||||
|
* @param input The bean containing the app_id field
|
||||||
|
* @return the legacy application token
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public Response generateApplicationToken(
|
||||||
|
@NotNull(message="Missing input parameter")
|
||||||
|
@Valid
|
||||||
|
ApplicationId input) throws ValidationException{
|
||||||
|
|
||||||
|
logger.debug("Incoming request for app token generation.");
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String context = secret.getContext();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.CREATED;
|
||||||
|
String appId = input.getAppId();
|
||||||
|
try {
|
||||||
|
// check if the token actually matches an application profile
|
||||||
|
ApplicationProfile appProfile = SocialUtils.getProfileFromInfrastrucure(appId, context);
|
||||||
|
if(appProfile == null){
|
||||||
|
logger.error("The given id doesn't belong to an application!!!");
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(ErrorMessages.NOT_APP_ID);
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
logger.debug("Generating token for the application with id " + appId);
|
||||||
|
// each token is related to an identifier and the context
|
||||||
|
String appToken = authorizationService().generateExternalServiceToken(appId);
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(appToken);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Unable to generate token for app " + appId + " and scope " + context);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(ErrorMessages.TOKEN_GENERATION_APP_FAILED);
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
package org.gcube.social_networking.ws.methods.v2;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.ValidationException;
|
||||||
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.policies.Users;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.RoleManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.ws.outputs.ResponseBean;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST interface for the social networking library (vres).
|
||||||
|
*/
|
||||||
|
@Path("2/vres")
|
||||||
|
@RequestHeaders ({
|
||||||
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
|
})
|
||||||
|
public class VREs {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Users.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @responseExample application/json {
|
||||||
|
"success" : true,
|
||||||
|
"message" : null,
|
||||||
|
"result" : [ {
|
||||||
|
"name" : "NextNext",
|
||||||
|
"context" : "/gcube/devNext/NextNext",
|
||||||
|
"description" : "NextNext description AAA"
|
||||||
|
}, {
|
||||||
|
"name" : "devVRE",
|
||||||
|
"context" : "/gcube/devsec/devVRE",
|
||||||
|
"description" : "devVRE description BBB"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
* @pathExample /get-my-vres?getManagers=false
|
||||||
|
* @param getManagers set true if you also want to know the VRE-Managers
|
||||||
|
* @return the list of vres along with some metadata
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@GET
|
||||||
|
@Path("get-my-vres/")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getMyVres(
|
||||||
|
@DefaultValue("false") @QueryParam("getManagers") boolean getManagers
|
||||||
|
) throws ValidationException {
|
||||||
|
|
||||||
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
String username = secret.getOwner().getId();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
|
||||||
|
if(!TokensUtils.isUserToken(caller)){
|
||||||
|
status = Status.FORBIDDEN;
|
||||||
|
responseBean.setMessage("This method can only be invoked with a user token!");
|
||||||
|
logger.warn("Trying to access get-my-vres method via a token different than USER is not allowed");
|
||||||
|
}else{
|
||||||
|
GroupManager gmManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
UserManager userManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
RoleManager roleManager = RoleManagerWSBuilder.getInstance().getRoleManager();
|
||||||
|
try{
|
||||||
|
|
||||||
|
GCubeUser user = userManager.getUserByUsername(username);
|
||||||
|
List<GCubeGroup> vres = gmManager.listVresByUser(user.getUserId());
|
||||||
|
JSONArray toReturn = new JSONArray();
|
||||||
|
|
||||||
|
for (GCubeGroup group : vres) {
|
||||||
|
|
||||||
|
// # ticket 9333
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
obj.put("name", group.getGroupName());
|
||||||
|
obj.put("context", gmManager.getInfrastructureScope(group.getGroupId()));
|
||||||
|
obj.put("description", group.getDescription());
|
||||||
|
//obj.put("thumbnail_url", ...); // TODO
|
||||||
|
JSONArray managers = new JSONArray();
|
||||||
|
|
||||||
|
if(getManagers){
|
||||||
|
List<GCubeUser> vreManagers = userManager.listUsersByGroupAndRole(group.getGroupId(),
|
||||||
|
roleManager.getRoleIdByName(GatewayRolesNames.VRE_MANAGER.getRoleName()));
|
||||||
|
|
||||||
|
for (GCubeUser vreManager : vreManagers) {
|
||||||
|
JSONObject manager = new JSONObject();
|
||||||
|
manager.put("username", vreManager.getUsername());
|
||||||
|
manager.put("fullname", vreManager.getFullname());
|
||||||
|
managers.add(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.put("managers", managers);
|
||||||
|
}
|
||||||
|
toReturn.add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBean.setSuccess(true);
|
||||||
|
responseBean.setResult(toReturn);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
|
||||||
|
logger.error("Unable to retrieve vres for user.", e);
|
||||||
|
responseBean.setMessage(e.toString());
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package org.gcube.social_networking.ws.outputs;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response bean
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResponseBean implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2725238162673879658L;
|
||||||
|
/**
|
||||||
|
* The result of the request: true if it succeeded, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error message if something wrong happened, null/empty otherwise
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
/**
|
||||||
|
* The result object of the request
|
||||||
|
*/
|
||||||
|
private Object result;
|
||||||
|
|
||||||
|
public ResponseBean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param success
|
||||||
|
* @param message
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
public ResponseBean(boolean success, String message, Object result) {
|
||||||
|
super();
|
||||||
|
this.success = success;
|
||||||
|
this.message = message;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setSuccess(boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Object getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setResult(Object result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResponseBean [success=" + success
|
||||||
|
+ ", message=" + message + ", result=" + result + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.social_networking.ws.providers;
|
||||||
|
|
||||||
|
import javax.ws.rs.ext.ContextResolver;
|
||||||
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
/**
|
||||||
|
* Custom mapper with property CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES to perform serialization/deserialization
|
||||||
|
* with snake case over camel case for json beans.
|
||||||
|
* TODO check https://github.com/FasterXML/jackson-docs/wiki/JacksonMixInAnnotations for applying such transformation
|
||||||
|
* only to some classes.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class CustomObjectMapper implements ContextResolver<ObjectMapper> {
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CustomObjectMapper.class);
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public CustomObjectMapper() {
|
||||||
|
logger.debug("new ObjectMapperResolver()");
|
||||||
|
mapper = new ObjectMapper();
|
||||||
|
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMapper getContext(Class<?> type) {
|
||||||
|
logger.debug("ObjectMapperResolver.getContext(...) invoked");
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.gcube.social_networking.ws.utils;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClient;
|
||||||
|
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class discovers and offer connections to the elastic search cluster.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class ElasticSearchConnection {
|
||||||
|
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ElasticSearchConnection.class);
|
||||||
|
|
||||||
|
// databook store (singleton)
|
||||||
|
private ElasticSearchClient es;
|
||||||
|
|
||||||
|
// singleton
|
||||||
|
private static ElasticSearchConnection singleton = new ElasticSearchConnection();
|
||||||
|
|
||||||
|
private ElasticSearchConnection(){
|
||||||
|
try {
|
||||||
|
ApplicationContext ctx = ContextProvider.get(); // get this info from SmartGears
|
||||||
|
logger.debug("Creating connection to Elasticsearch");
|
||||||
|
es = new ElasticSearchClientImpl(ctx.container().configuration().infrastructure());
|
||||||
|
logger.debug("Elasticsearch connection created");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to connect to elasticsearch", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ElasticSearchConnection getSingleton(){
|
||||||
|
|
||||||
|
return singleton;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the object to connect to cassandra cluster.
|
||||||
|
* @return connection pool to cassandra cluster
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public ElasticSearchClient getElasticSearchClient(){
|
||||||
|
|
||||||
|
return es;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.gcube.social_networking.ws.utils;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that contains error messages to be returned in the HTTP responses.
|
||||||
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
|
*/
|
||||||
|
public class ErrorMessages {
|
||||||
|
|
||||||
|
public static final String MISSING_TOKEN = "Missing token.";
|
||||||
|
public static final String MISSING_PARAMETERS = "Missing request parameters.";
|
||||||
|
public static final String INVALID_TOKEN = "Invalid token.";
|
||||||
|
public static final String TOKEN_GENERATION_APP_FAILED = "Token generation failed.";
|
||||||
|
public static final String NOT_APP_TOKEN = "Invalid token: not belonging to an application.";
|
||||||
|
public static final String NOT_APP_ID = "Invalid application id: it doesn't belong to an application.";
|
||||||
|
public static final String NO_APP_PROFILE_FOUND = "There is no application profile for this app id/scope.";
|
||||||
|
public static final String BAD_REQUEST = "Please check the parameter you passed, it seems a bad request";
|
||||||
|
public static final String ERROR_IN_API_RESULT = "The error is reported into the 'message' field of the returned object";
|
||||||
|
public static final String POST_OUTSIDE_VRE = "A post cannot be written into a context that is not a VRE";
|
||||||
|
public static final String DEPRECATED_METHOD = "This method is deprecated, must use version 2";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,172 @@
|
||||||
|
package org.gcube.social_networking.ws.utils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.server.SocialDBDriver;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters to apply to Posts/comments etc
|
||||||
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
*/
|
||||||
|
public class Filters {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Filters.class);
|
||||||
|
|
||||||
|
private static List<String> getContexts(String context) throws IllegalArgumentException, UserManagementSystemException, GroupRetrievalFault{
|
||||||
|
|
||||||
|
// retrieve group information
|
||||||
|
GroupManager gm = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
GCubeGroup group = gm.getGroup(gm.getGroupIdFromInfrastructureScope(context));
|
||||||
|
|
||||||
|
List<String> contexts = new ArrayList<String>();
|
||||||
|
|
||||||
|
if(gm.isRootVO(group.getGroupId())){
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(gm.isVO(group.getGroupId())){
|
||||||
|
|
||||||
|
List<GCubeGroup> vres = group.getChildren();
|
||||||
|
for (GCubeGroup gCubeGroup : vres) {
|
||||||
|
contexts.add(gm.getInfrastructureScope(gCubeGroup.getGroupId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
contexts.add(gm.getInfrastructureScope(group.getGroupId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return contexts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a list of not filtered Posts, the methods remove Posts unaccessible in this scope.
|
||||||
|
* If the initial context is the root: all Posts are returned;
|
||||||
|
* If the initial context is a VO: Posts for vres within the vo are returned;
|
||||||
|
* If the initial context is a vre: Posts of the vre are returned;
|
||||||
|
* @param postsIds
|
||||||
|
* @param context
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void filterPostsPerContextById(
|
||||||
|
List<String> postsIds, String context) throws Exception {
|
||||||
|
|
||||||
|
SocialDBDriver datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
List<Post> posts = new ArrayList<Post>();
|
||||||
|
|
||||||
|
for (String postId : postsIds) {
|
||||||
|
try{
|
||||||
|
posts.add(datastore.readPost(postId));
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to read post with id " + postId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter
|
||||||
|
filterPostsPerContext(posts, context);
|
||||||
|
|
||||||
|
// clear and convert
|
||||||
|
postsIds.clear();
|
||||||
|
for (Post post : posts) {
|
||||||
|
postsIds.add(post.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a list of not filtered posts, the methods remove posts unaccessible in this scope.
|
||||||
|
* If the initial context is the root: all posts are returned;
|
||||||
|
* If the initial context is a VO: posts for vres within the vo are returned;
|
||||||
|
* If the initial context is a vre: posts of the vre are returned;
|
||||||
|
* @param posts
|
||||||
|
* @param context
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void filterPostsPerContext(List<Post> posts, String context) throws Exception {
|
||||||
|
|
||||||
|
List<String> contexts = getContexts(context);
|
||||||
|
|
||||||
|
// filter
|
||||||
|
Iterator<Post> iterator = posts.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Post post = (Post) iterator.next();
|
||||||
|
if(!contexts.contains(post.getVreid()))
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter comments per context
|
||||||
|
* @param comments
|
||||||
|
* @param context
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void filterCommentsPerContext(List<Comment> comments, String context) throws Exception {
|
||||||
|
|
||||||
|
List<String> contexts = getContexts(context);
|
||||||
|
|
||||||
|
// get cassandra store
|
||||||
|
SocialDBDriver datastore = CassandraConnection.getInstance().getDatabookStore();
|
||||||
|
|
||||||
|
// filter
|
||||||
|
Iterator<Comment> iterator = comments.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
try{
|
||||||
|
Comment comment = (Comment) iterator.next();
|
||||||
|
Post parent = datastore.readPost(comment.getPostid());
|
||||||
|
if(!contexts.contains(parent.getVreid()))
|
||||||
|
iterator.remove();
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.warn("Failed to analyze this comment", e);
|
||||||
|
iterator.remove(); // remove it anyway
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Depending on the type of object provided (e.g. Post, Comment etc), some information are removed
|
||||||
|
* @param toClear
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> void hideSensitiveInformation(List<T> toClear, String usernameCaller){
|
||||||
|
|
||||||
|
if(toClear == null || toClear.isEmpty() || usernameCaller == null || usernameCaller.isEmpty())
|
||||||
|
return;
|
||||||
|
else{
|
||||||
|
|
||||||
|
// for posts
|
||||||
|
if(toClear.get(0).getClass().equals(Post.class)){
|
||||||
|
|
||||||
|
for (T post : toClear) {
|
||||||
|
Post posted = ((Post)post);
|
||||||
|
if(!usernameCaller.equals(posted.getEntityId()))
|
||||||
|
posted.setEmail(""); // remove the email field
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(toClear.get(0).getClass().equals(EnhancedPost.class)){
|
||||||
|
for (T enhancedPost : toClear) {
|
||||||
|
Post posted = ((EnhancedPost)enhancedPost).getPost();
|
||||||
|
if(!usernameCaller.equals(posted.getEntityId()))
|
||||||
|
posted.setEmail(""); // remove the email field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,622 @@
|
||||||
|
package org.gcube.social_networking.ws.utils;
|
||||||
|
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
|
import org.gcube.social_networking.server.CassandraConnection;
|
||||||
|
//import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.ApplicationProfile;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.PostType;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.PrivacyLevel;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
||||||
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
|
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
|
||||||
|
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
|
||||||
|
import org.gcube.portal.notifications.thread.MentionNotificationsThread;
|
||||||
|
import org.gcube.portal.notifications.thread.PostNotificationsThread;
|
||||||
|
import org.gcube.social_networking.caches.SocialNetworkingSiteFinder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.GroupManagerWSBuilder;
|
||||||
|
import org.gcube.social_networking.liferay.ws.UserManagerWSBuilder;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
|
import org.gcube.social_networking.socialutillibrary.Utils;
|
||||||
|
import org.gcube.socialnetworking.socialtoken.SocialMessageParser;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class SocialUtils {
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocialUtils.class);
|
||||||
|
|
||||||
|
public final static String NO_TEXT_FILE_SHARE = "_N0_73X7_SH4R3_";
|
||||||
|
public final static int CACHING_TIME_TO_EXPIRATION = 2506000;//29 days 6 minutes 40 seconds
|
||||||
|
public final static String DISABLED_USERS_NOTIFICATIONS_NAMESPACE = "dun:";
|
||||||
|
|
||||||
|
// name of the portlet for vre notification
|
||||||
|
public static final String NEWS_FEED_PORTLET_CLASSNAME = "org.gcube.portlets.user.newspost.server.NewsServiceImpl";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param mentions the set of string containing the usernames
|
||||||
|
* @return a list of existing usernames associated with their fullnames
|
||||||
|
*/
|
||||||
|
private static ArrayList<GenericItemBean> getUsersFromUsernames(Set<String> mentions) {
|
||||||
|
if (mentions.isEmpty())
|
||||||
|
return new ArrayList<>();
|
||||||
|
ArrayList<GenericItemBean> toReturn = new ArrayList<>();
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
for (String username : mentions) {
|
||||||
|
try{
|
||||||
|
GCubeUser user = uManager.getUserByUsername(username);
|
||||||
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
||||||
|
toReturn.add(new GenericItemBean(""+user.getUserId(), username, fullName, ""));
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations for username=" + username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility method
|
||||||
|
private static ArrayList<ItemBean> convertToItemBean(Collection<GenericItemBean> items) {
|
||||||
|
ArrayList<ItemBean> toReturn = new ArrayList<>(items.size());
|
||||||
|
for (GenericItemBean item : items) {
|
||||||
|
toReturn.add(new ItemBean(item.getId(), item.getName(), item.getAlternativeName(), item.getThumbnailURL()));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used when an application needs to publish something.
|
||||||
|
* @param postText
|
||||||
|
* @param uriParams
|
||||||
|
* @param previewTitle
|
||||||
|
* @param previewDescription
|
||||||
|
* @param httpImageUrl
|
||||||
|
* @return true upon success, false on failure
|
||||||
|
*/
|
||||||
|
public static Post shareApplicationUpdate(
|
||||||
|
String postText,
|
||||||
|
String uriParams,
|
||||||
|
String previewTitle,
|
||||||
|
String previewDescription,
|
||||||
|
String httpImageUrl,
|
||||||
|
ApplicationProfile applicationProfile,
|
||||||
|
Secret secret,
|
||||||
|
boolean notifyGroup
|
||||||
|
){
|
||||||
|
|
||||||
|
SocialMessageParser messageParser = new SocialMessageParser(postText);
|
||||||
|
String escapedPostText = messageParser.getParsedMessage();
|
||||||
|
List<String> hashtags = messageParser.getHashtags();
|
||||||
|
ArrayList<GenericItemBean> mentionedUsers = getUsersFromUsernames(Utils.getMentionedUsernames(postText));
|
||||||
|
ArrayList<ItemBean> mentionedUsersToConvertInHTML = convertToItemBean(mentionedUsers);
|
||||||
|
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(secret.getContext());
|
||||||
|
|
||||||
|
escapedPostText = Utils.convertMentionUsernamesAnchorHTML(escapedPostText, mentionedUsersToConvertInHTML, site.getSiteURL(), site.getSiteLandingPagePath());
|
||||||
|
logger.debug("*** Escaped post text is " + escapedPostText);
|
||||||
|
|
||||||
|
String scope = secret.getContext();
|
||||||
|
String appId = secret.getOwner().getId();
|
||||||
|
|
||||||
|
Post toWrite =
|
||||||
|
buildPost(
|
||||||
|
escapedPostText,
|
||||||
|
uriParams == null ? "" : uriParams,
|
||||||
|
previewTitle == null ? "" : previewTitle,
|
||||||
|
previewDescription == null ? "" : previewDescription,
|
||||||
|
httpImageUrl == null ? "" : httpImageUrl,
|
||||||
|
applicationProfile,
|
||||||
|
scope);
|
||||||
|
|
||||||
|
// try to save it
|
||||||
|
boolean res = CassandraConnection.getInstance().getDatabookStore().saveAppPost(toWrite);
|
||||||
|
|
||||||
|
if(res){
|
||||||
|
logger.debug("Post correctly written by application " + appId);
|
||||||
|
|
||||||
|
// wait a bit before saving hashtags
|
||||||
|
if(hashtags != null && !hashtags.isEmpty())
|
||||||
|
new Thread(()->{
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
CassandraConnection.getInstance().getDatabookStore().saveHashTags(toWrite.getKey(), scope, hashtags);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.error("Failed to save hashtags in Cassandra", e1);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
|
// build the notification manager
|
||||||
|
|
||||||
|
SocialNetworkingUser user = new SocialNetworkingUser(appId, "", applicationProfile.getName(), applicationProfile.getImageUrl());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
||||||
|
UserManagerWSBuilder.getInstance().getUserManager(),
|
||||||
|
site,
|
||||||
|
scope,
|
||||||
|
user,
|
||||||
|
NEWS_FEED_PORTLET_CLASSNAME);
|
||||||
|
|
||||||
|
if (!mentionedUsers.isEmpty())
|
||||||
|
new Thread(new MentionNotificationsThread(toWrite.getKey(), toWrite.getDescription(), nm, null, mentionedUsers)).start();
|
||||||
|
|
||||||
|
if(notifyGroup){
|
||||||
|
|
||||||
|
logger.debug("Sending notifications for " + appId + " " + scope);
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
String name = scope;//new ScopeBean(scope).name(); // scope such as devVRE // need to fix
|
||||||
|
|
||||||
|
// retrieve group information
|
||||||
|
GroupManager gManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
|
||||||
|
long groupId = gManager.getGroupId(name);
|
||||||
|
String groupName = gManager.getGroup(groupId).getGroupName();
|
||||||
|
|
||||||
|
logger.debug("Company id and name " + groupId + " " + groupName);
|
||||||
|
|
||||||
|
// start notification thread
|
||||||
|
new Thread(new PostNotificationsThread(
|
||||||
|
UserManagerWSBuilder.getInstance().getUserManager(),
|
||||||
|
toWrite.getKey(),
|
||||||
|
toWrite.getDescription(),
|
||||||
|
""+groupId,
|
||||||
|
nm,
|
||||||
|
new HashSet<String>(hashtags),
|
||||||
|
new HashSet<String>())
|
||||||
|
).start();
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.debug("Post succesfully created but unable to send notifications.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return toWrite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an ApplicationProfile Post.
|
||||||
|
*
|
||||||
|
* @param description add a description for the update you are sharing
|
||||||
|
* @param uriParams the additional parameters your applicationProfile needs to open the subject of this update e.g. id=12345&type=foo
|
||||||
|
* @param previewTitle the title to show in the preview
|
||||||
|
* @param previewDescription the description to show in the preview
|
||||||
|
* @param previewThumbnailUrl the image url to show in the preview
|
||||||
|
* @return a post instance ready to be written
|
||||||
|
*/
|
||||||
|
private static Post buildPost(
|
||||||
|
String description,
|
||||||
|
String uriParams,
|
||||||
|
String previewTitle,
|
||||||
|
String previewDescription,
|
||||||
|
String previewThumbnailUrl,
|
||||||
|
ApplicationProfile applicationProfile,
|
||||||
|
String scopeApp) {
|
||||||
|
|
||||||
|
String uri = applicationProfile.getUrl();
|
||||||
|
|
||||||
|
//add the GET params if necessary
|
||||||
|
if (uriParams != null && uriParams.compareTo("") != 0)
|
||||||
|
uri += "?"+uriParams;
|
||||||
|
|
||||||
|
Post toReturn = new Post(
|
||||||
|
UUID.randomUUID().toString(),
|
||||||
|
PostType.PUBLISH,
|
||||||
|
applicationProfile.getKey(),
|
||||||
|
new Date(),
|
||||||
|
scopeApp,
|
||||||
|
uri,
|
||||||
|
previewThumbnailUrl,
|
||||||
|
description,
|
||||||
|
PrivacyLevel.SINGLE_VRE,
|
||||||
|
applicationProfile.getName(),
|
||||||
|
"no-email",
|
||||||
|
applicationProfile.getImageUrl(),
|
||||||
|
previewTitle,
|
||||||
|
previewDescription,
|
||||||
|
"",
|
||||||
|
true);
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
//removed getprofilefrominfrastructure
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows user to post a post in a certain vre.
|
||||||
|
* @param userId
|
||||||
|
* @param postText
|
||||||
|
* @param vreId
|
||||||
|
* @param previewTitle
|
||||||
|
* @param previewDescription
|
||||||
|
* @param previewHost
|
||||||
|
* @param previewUrl
|
||||||
|
* @param urlThumbnail
|
||||||
|
* @param notifyGroup
|
||||||
|
* @return The written Post
|
||||||
|
*/
|
||||||
|
public static Post shareUserUpdate(
|
||||||
|
String userId,
|
||||||
|
String postText,
|
||||||
|
String vreId,
|
||||||
|
String previewTitle,
|
||||||
|
String previewDescription,
|
||||||
|
String previewHost,
|
||||||
|
String previewUrl,
|
||||||
|
String urlThumbnail,
|
||||||
|
boolean notifyGroup,
|
||||||
|
Secret secret) {
|
||||||
|
|
||||||
|
SocialMessageParser messageParser = new SocialMessageParser(postText);
|
||||||
|
String escapedPostText = messageParser.getParsedMessage();
|
||||||
|
List<String> hashtags = messageParser.getHashtags();
|
||||||
|
//check if any mention exists
|
||||||
|
ArrayList<GenericItemBean> mentionedUsers = getUsersFromUsernames(Utils.getMentionedUsernames(postText));
|
||||||
|
ArrayList<ItemBean> mentionedUsersToConvertInHTML = convertToItemBean(mentionedUsers);
|
||||||
|
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(secret.getContext());
|
||||||
|
|
||||||
|
escapedPostText = Utils.convertMentionUsernamesAnchorHTML(escapedPostText, mentionedUsersToConvertInHTML, site.getSiteURL(), site.getSiteLandingPagePath());
|
||||||
|
|
||||||
|
GCubeUser user;
|
||||||
|
|
||||||
|
// retrieve group information
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
try {
|
||||||
|
user = uManager.getUserByUsername(userId);
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations, post write fails.", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String email = user.getEmail();
|
||||||
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
||||||
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
String linkTitle = previewTitle == null ? "" : previewTitle;
|
||||||
|
String linkDesc = previewDescription == null ? "" : previewDescription;
|
||||||
|
String host = previewHost == null ? "" : previewHost;
|
||||||
|
String url = previewUrl == null ? "" : previewUrl;
|
||||||
|
if (urlThumbnail == null)
|
||||||
|
urlThumbnail = "null";
|
||||||
|
|
||||||
|
//this means the user has shared a file without text in it.
|
||||||
|
String textToPost = "";
|
||||||
|
if (escapedPostText.trim().compareTo(NO_TEXT_FILE_SHARE) == 0) {
|
||||||
|
textToPost = org.gcube.social_networking.socialutillibrary.Utils.convertFileNameAnchorHTML(url);
|
||||||
|
} else {
|
||||||
|
textToPost = escapedPostText;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
logger.debug("Attempting to save Post with text: " + textToPost + " Level = " + PrivacyLevel.SINGLE_VRE + " Timeline = " + vreId);
|
||||||
|
|
||||||
|
boolean result = CassandraConnection.getInstance().getDatabookStore().saveUserPost(toShare);
|
||||||
|
|
||||||
|
if(vreId != null && vreId.compareTo("") != 0 && result) {
|
||||||
|
|
||||||
|
logger.trace("Attempting to write onto " + vreId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.debug("Sleeping waiting for cassandra's update");
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
|
||||||
|
logger.error(e.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
CassandraConnection.getInstance().getDatabookStore().savePostToVRETimeline(toShare.getKey(), vreId);
|
||||||
|
|
||||||
|
if (hashtags != null && !hashtags.isEmpty())
|
||||||
|
CassandraConnection.getInstance().getDatabookStore().saveHashTags(toShare.getKey(), vreId, hashtags);
|
||||||
|
|
||||||
|
} catch (PostIDNotFoundException e) {
|
||||||
|
logger.error("Error writing onto VRES Time Line" + vreId);
|
||||||
|
}
|
||||||
|
logger.trace("Success writing onto " + vreId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
SocialNetworkingUser socialUser =
|
||||||
|
new SocialNetworkingUser(userId, email, fullName, thumbnailURL);
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, vreId, socialUser, NEWS_FEED_PORTLET_CLASSNAME);
|
||||||
|
if (!mentionedUsers.isEmpty())
|
||||||
|
new Thread(new MentionNotificationsThread(toShare.getKey(), toShare.getDescription(), nm, null, mentionedUsers)).start();
|
||||||
|
|
||||||
|
//send the notification about this posts to everyone in the group if notifyGroup is true
|
||||||
|
if (vreId != null && vreId.compareTo("") != 0 && notifyGroup) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
// retrieve group information
|
||||||
|
GroupManager gManager = GroupManagerWSBuilder.getInstance().getGroupManager();
|
||||||
|
// handle the scope
|
||||||
|
String name = vreId; //new ScopeBean(vreId).name(); // scope such as devVR // need to fix
|
||||||
|
long groupId = gManager.getGroupId(name);
|
||||||
|
String groupName = gManager.getGroup(groupId).getGroupName();
|
||||||
|
|
||||||
|
logger.debug("Company id and name " + groupId + " " + groupName);
|
||||||
|
new Thread(
|
||||||
|
new PostNotificationsThread(
|
||||||
|
UserManagerWSBuilder.getInstance().getUserManager(),
|
||||||
|
toShare.getKey(),
|
||||||
|
toShare.getDescription(),
|
||||||
|
""+groupId,
|
||||||
|
nm,
|
||||||
|
new HashSet<String>(),
|
||||||
|
new HashSet<String>(hashtags))
|
||||||
|
).start();
|
||||||
|
|
||||||
|
logger.debug("Start sending notifications for post written by " + userId);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to notify users", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toShare;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Allows to comment post in a certain vre.
|
||||||
|
|
||||||
|
* @param userid the username
|
||||||
|
* @param time the date and time of the comment
|
||||||
|
* @param postId the key of the post that was commented
|
||||||
|
* @param commentText the text as it is, it will be parsed
|
||||||
|
* @param postOwnerId the username of the user who created the post that was commented
|
||||||
|
* @param context the VRE context
|
||||||
|
*
|
||||||
|
* @return the Comment instance if ok, null if somwthign went KO
|
||||||
|
* @throws PostIDNotFoundException
|
||||||
|
*/
|
||||||
|
public static Comment commentPost(String userid, Date time, String postId, String commentText, String postOwnerId, String context, Secret secret) throws PostIDNotFoundException {
|
||||||
|
|
||||||
|
SocialMessageParser messageParser = new SocialMessageParser(commentText);
|
||||||
|
String escapedCommentText = messageParser.getParsedMessage();
|
||||||
|
//check if any mention exists
|
||||||
|
ArrayList<GenericItemBean> mentionedUsers = getUsersFromUsernames(Utils.getMentionedUsernames(commentText));
|
||||||
|
ArrayList<ItemBean> mentionedUsersToConvertInHTML = convertToItemBean(mentionedUsers);
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(secret.getContext());
|
||||||
|
|
||||||
|
escapedCommentText = Utils.convertMentionUsernamesAnchorHTML(escapedCommentText, mentionedUsersToConvertInHTML, site.getSiteURL(), site.getSiteLandingPagePath());
|
||||||
|
|
||||||
|
// retrieve user information
|
||||||
|
GCubeUser user;
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
try {
|
||||||
|
user = uManager.getUserByUsername(userid);
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations, comment write fails.", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String commentKey = UUID.randomUUID().toString(); // a unique id that goes in the DB
|
||||||
|
String email = user.getEmail();
|
||||||
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
||||||
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
|
||||||
|
Comment theComment = new Comment(commentKey, userid, time, postId, escapedCommentText, fullName, thumbnailURL);
|
||||||
|
logger.debug("Attempting to save Comment with text: " + commentText + " postid="+postId);
|
||||||
|
|
||||||
|
boolean result = CassandraConnection.getInstance().getDatabookStore().addComment(theComment);
|
||||||
|
logger.debug("Added comment? " + theComment.toString() + " Result is " +result);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//if the comment was correctly delivered notify users involved
|
||||||
|
SocialNetworkingUser socialUser = new SocialNetworkingUser(userid, email, fullName, thumbnailURL);
|
||||||
|
|
||||||
|
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)
|
||||||
|
logger.debug("The post creator is " + postOwnerId);
|
||||||
|
if (! user.getUsername().equals(postOwnerId)) {
|
||||||
|
boolean resultNotifyOwnComment = nm.notifyOwnCommentReply(postOwnerId, postId, escapedCommentText, theComment.getKey());
|
||||||
|
logger.debug("Comment Notification to post creator added? " + resultNotifyOwnComment);
|
||||||
|
}
|
||||||
|
//if there are users who liked this post they get notified, asynchronously with this thread
|
||||||
|
ArrayList<Like> likes = getAllLikesByPost(postId);
|
||||||
|
Thread likesThread = new Thread(new LikeNotificationsThread(escapedCommentText, nm, likes, postOwnerId, theComment.getKey()));
|
||||||
|
likesThread.start();
|
||||||
|
|
||||||
|
//notify the other users who commented this post (excluding the ones above)
|
||||||
|
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(
|
||||||
|
CassandraConnection.getInstance().getDatabookStore(),
|
||||||
|
uManager, user.getUsername(), theComment.getPostid(), escapedCommentText, nm, postOwnerId, theComment.getKey(), likes));
|
||||||
|
commentsNotificationthread.start();
|
||||||
|
|
||||||
|
//send the notification to the mentioned users, if any
|
||||||
|
if (mentionedUsers != null && mentionedUsers.size() > 0) {
|
||||||
|
ArrayList<GenericItemBean> toPass = new ArrayList<GenericItemBean>();
|
||||||
|
|
||||||
|
|
||||||
|
// among the mentionedUsers there could be groups of people
|
||||||
|
Map<String, ItemBean> uniqueUsersToNotify = new HashMap<>();
|
||||||
|
UserManager um = new LiferayUserManager();
|
||||||
|
|
||||||
|
for (ItemBean bean : mentionedUsersToConvertInHTML) {
|
||||||
|
|
||||||
|
if(bean.isItemGroup()){
|
||||||
|
|
||||||
|
// retrieve the users of this group
|
||||||
|
try {
|
||||||
|
List<GCubeUser> teamUsers = um.listUsersByTeam(Long.parseLong(bean.getId()));
|
||||||
|
|
||||||
|
for (GCubeUser userTeam : teamUsers) {
|
||||||
|
if(!uniqueUsersToNotify.containsKey(userTeam.getUsername()))
|
||||||
|
uniqueUsersToNotify.put(userTeam.getUsername(), new ItemBean(userTeam.getUserId()+"",
|
||||||
|
userTeam.getUsername(), userTeam.getFullname(), userTeam.getUserAvatarURL()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (NumberFormatException
|
||||||
|
| UserManagementSystemException
|
||||||
|
| TeamRetrievalFault | UserRetrievalFault e) {
|
||||||
|
logger.error("Unable to retrieve team information", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
// it is a user, just add to the hashmap
|
||||||
|
if(!uniqueUsersToNotify.containsKey(bean.getName()))
|
||||||
|
uniqueUsersToNotify.put(bean.getName(), bean);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// iterate over the hashmap
|
||||||
|
Iterator<Entry<String, ItemBean>> userMapIterator = uniqueUsersToNotify.entrySet().iterator();
|
||||||
|
while (userMapIterator.hasNext()) {
|
||||||
|
Map.Entry<String, ItemBean> userEntry = (Map.Entry<String, ItemBean>) userMapIterator
|
||||||
|
.next();
|
||||||
|
ItemBean userBean = userEntry.getValue();
|
||||||
|
toPass.add(new GenericItemBean(userBean.getId(), userBean.getName(), userBean.getAlternativeName(), userBean.getThumbnailURL()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread thread = new Thread(new MentionNotificationsThread(theComment.getPostid(), escapedCommentText, nm, null, toPass));
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
return theComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<Like> getAllLikesByPost(String postid) {
|
||||||
|
ArrayList<Like> toReturn = (ArrayList<Like>) CassandraConnection.getInstance().getDatabookStore().getAllLikesByPost(postid);
|
||||||
|
logger.debug("Asking likes for " + postid);
|
||||||
|
for (Like like : toReturn) {
|
||||||
|
// retrieve user information
|
||||||
|
GCubeUser user;
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
try {
|
||||||
|
user = uManager.getUserByUsername(like.getUserid());
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations, comment write fails.", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
|
||||||
|
like.setThumbnailURL(thumbnailURL == null ? "" : thumbnailURL);
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean like(String username, String postid, String context, Secret secret) {
|
||||||
|
boolean likeCommitResult = false;
|
||||||
|
// retrieve user information
|
||||||
|
GCubeUser user;
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
try {
|
||||||
|
user = uManager.getUserByUsername(username);
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations, like write fails.", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String email = user.getEmail();
|
||||||
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
||||||
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
SocialNetworkingUser socialUser = new SocialNetworkingUser(user.getUsername(), email, fullName, thumbnailURL);
|
||||||
|
|
||||||
|
Like toLike = new Like(UUID.randomUUID().toString(), user.getUsername(),
|
||||||
|
new Date(), postid, user.getFullname(), user.getUserAvatarURL());
|
||||||
|
Post thePost = null;
|
||||||
|
try {
|
||||||
|
logger.debug("Attempting to read post with id: " +postid);
|
||||||
|
thePost = CassandraConnection.getInstance().getDatabookStore().readPost(postid);
|
||||||
|
likeCommitResult = CassandraConnection.getInstance().getDatabookStore().like(toLike);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Post not found for this like ot could not like the post " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//if the like was correctly delivered notify the user who made the post
|
||||||
|
|
||||||
|
boolean resultNotifyLike =false;
|
||||||
|
if (likeCommitResult) {
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(secret.getContext());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, socialUser, NEWS_FEED_PORTLET_CLASSNAME);
|
||||||
|
|
||||||
|
String postText = thePost.getDescription();
|
||||||
|
String postOwnerId = thePost.getEntityId();
|
||||||
|
SocialMessageParser messageParser = new SocialMessageParser(postText);
|
||||||
|
String escapedPostText = messageParser.getParsedMessage();
|
||||||
|
|
||||||
|
//if the user who liked this post is not the user who posted it notify the poster user (Post owner)
|
||||||
|
logger.debug("The post creator is " + postOwnerId);
|
||||||
|
if (! user.getUsername().equals(postOwnerId)) {
|
||||||
|
resultNotifyLike = nm.notifyLikedPost(postOwnerId, postid, escapedPostText);
|
||||||
|
logger.debug("Like Notification to post creator added? " + resultNotifyLike);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return likeCommitResult && resultNotifyLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean unlike(String username, String likeid, String postid) {
|
||||||
|
boolean unlikeCommitResult = false;
|
||||||
|
// retrieve user information
|
||||||
|
GCubeUser user;
|
||||||
|
UserManager uManager = UserManagerWSBuilder.getInstance().getUserManager();
|
||||||
|
try {
|
||||||
|
user = uManager.getUserByUsername(username);
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to get user informations, unlike write fails.", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String fullName = user.getFirstName() + " " + user.getLastName();
|
||||||
|
String thumbnailURL = user.getUserAvatarURL();
|
||||||
|
try {
|
||||||
|
|
||||||
|
unlikeCommitResult = CassandraConnection.getInstance().getDatabookStore().unlike(username, likeid, postid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Post not Found for this like ot could not unlike the post " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return unlikeCommitResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,194 @@
|
||||||
|
package org.gcube.social_networking.ws.utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class UserProfileExtendedWithVerifiedEmail {
|
||||||
|
|
||||||
|
@JsonProperty("id")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@JsonProperty("roles")
|
||||||
|
private List<String> roles;
|
||||||
|
|
||||||
|
@JsonProperty("picture")
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
@JsonProperty("name")
|
||||||
|
private String fullname;
|
||||||
|
|
||||||
|
@JsonProperty("middle_name")
|
||||||
|
private String middleName;
|
||||||
|
|
||||||
|
@JsonProperty("male")
|
||||||
|
private boolean male;
|
||||||
|
|
||||||
|
@JsonProperty("location_industry")
|
||||||
|
private String locationIndustry;
|
||||||
|
|
||||||
|
@JsonProperty("given_name")
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@JsonProperty("email")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@JsonProperty("job_title")
|
||||||
|
private String jobTitle;
|
||||||
|
|
||||||
|
@JsonProperty("family_name")
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@JsonProperty("verified_email")
|
||||||
|
private boolean verifiedEmail = true;
|
||||||
|
|
||||||
|
public UserProfileExtendedWithVerifiedEmail() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param username
|
||||||
|
* @param roles
|
||||||
|
* @param avatar
|
||||||
|
* @param fullname
|
||||||
|
*/
|
||||||
|
public UserProfileExtendedWithVerifiedEmail(String username, List<String> roles, String avatar, String fullname) {
|
||||||
|
this.username = username;
|
||||||
|
this.roles = roles;
|
||||||
|
this.avatar = avatar;
|
||||||
|
this.fullname = fullname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<String> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvatar(String avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullname() {
|
||||||
|
return fullname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFullname(String fullname) {
|
||||||
|
this.fullname = fullname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMiddleName() {
|
||||||
|
return middleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMiddleName(String middleName) {
|
||||||
|
this.middleName = middleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMale() {
|
||||||
|
return male;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMale(boolean male) {
|
||||||
|
this.male = male;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocationIndustry() {
|
||||||
|
return locationIndustry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocationIndustry(String locationIndustry) {
|
||||||
|
this.locationIndustry = locationIndustry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJobTitle() {
|
||||||
|
return jobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJobTitle(String jobTitle) {
|
||||||
|
this.jobTitle = jobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVerifiedEmail() {
|
||||||
|
return verifiedEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerifiedEmail(boolean verifiedEmail) {
|
||||||
|
this.verifiedEmail = verifiedEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("UserProfileExtendedWithVerifiedEmail [username=");
|
||||||
|
builder.append(username);
|
||||||
|
builder.append(", roles=");
|
||||||
|
builder.append(roles);
|
||||||
|
builder.append(", avatar=");
|
||||||
|
builder.append(avatar);
|
||||||
|
builder.append(", fullname=");
|
||||||
|
builder.append(fullname);
|
||||||
|
builder.append(", middleName=");
|
||||||
|
builder.append(middleName);
|
||||||
|
builder.append(", male=");
|
||||||
|
builder.append(male);
|
||||||
|
builder.append(", locationIndustry=");
|
||||||
|
builder.append(locationIndustry);
|
||||||
|
builder.append(", firstName=");
|
||||||
|
builder.append(firstName);
|
||||||
|
builder.append(", email=");
|
||||||
|
builder.append(email);
|
||||||
|
builder.append(", jobTitle=");
|
||||||
|
builder.append(jobTitle);
|
||||||
|
builder.append(", lastName=");
|
||||||
|
builder.append(lastName);
|
||||||
|
builder.append(", verifiedEmail=");
|
||||||
|
builder.append(verifiedEmail);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,19 +1,19 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE xml>
|
<!DOCTYPE xml>
|
||||||
<web-app>
|
<web-app>
|
||||||
|
<context-param>
|
||||||
|
<param-name>admin-username</param-name>
|
||||||
|
<param-value>{{adminId}}</param-value>
|
||||||
|
</context-param>
|
||||||
|
<context-param>
|
||||||
|
<param-name>admin-pwd</param-name>
|
||||||
|
<param-value>{{adminPwd}}</param-value>
|
||||||
|
</context-param>
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>org.gcube.acme.ResourceInitializer</servlet-name>
|
<servlet-name>org.gcube.social_networking.SocialService</servlet-name>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>default</servlet-name>
|
<servlet-name>org.gcube.social_networking.SocialService</servlet-name>
|
||||||
<url-pattern>/docs/*</url-pattern>
|
<url-pattern>/social-service/*</url-pattern>
|
||||||
</servlet-mapping>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>default</servlet-name>
|
|
||||||
<url-pattern>/api-docs/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>org.gcube.acme.ResourceInitializer</servlet-name>
|
|
||||||
<url-pattern>/*</url-pattern>
|
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
</web-app>
|
</web-app>
|
|
@ -0,0 +1,139 @@
|
||||||
|
[INFO] Scanning for projects...
|
||||||
|
[INFO]
|
||||||
|
[INFO] -------------< org.gcube.social_networking:social-service >-------------
|
||||||
|
[INFO] Building Social Service 1.0.0-SNAPSHOT
|
||||||
|
[INFO] from pom.xml
|
||||||
|
[INFO] --------------------------------[ war ]---------------------------------
|
||||||
|
[INFO]
|
||||||
|
[INFO] --- dependency:3.6.1:tree (default-cli) @ social-service ---
|
||||||
|
[INFO] org.gcube.social_networking:social-service:war:1.0.0-SNAPSHOT
|
||||||
|
[INFO] +- org.slf4j:slf4j-api:jar:2.0.12:provided
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet:jar:3.1.5:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
|
||||||
|
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:3.1.5:compile
|
||||||
|
[INFO] | | \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
|
||||||
|
[INFO] | \- jakarta.ws.rs:jakarta.ws.rs-api:jar:3.1.0:compile
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:3.1.5:compile
|
||||||
|
[INFO] | \- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears-app:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | +- org.javassist:javassist:jar:3.20.0-GA:compile
|
||||||
|
[INFO] | \- com.google.guava:guava:jar:18.0:provided
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears:jar:4.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.reflections:reflections:jar:0.9.12:provided
|
||||||
|
[INFO] | +- org.yaml:snakeyaml:jar:2.2:provided
|
||||||
|
[INFO] | +- io.github.classgraph:classgraph:jar:4.8.28:provided
|
||||||
|
[INFO] | +- org.gcube.common:health-api:jar:1.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-databind:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-annotations:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-core:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:common-security:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.data.publishing:document-store-lib:jar:3.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.accounting:accounting-lib:jar:5.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.resources.discovery:ic-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.resources.discovery:discovery-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | \- org.gcube.core:common-gcore-stubs:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.core:common-encryption:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:common-utility-sg4:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:gxHTTP:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.ini4j:ini4j:jar:0.5.4:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-validator:jar:1.1.0:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-events:jar:1.0.2:provided
|
||||||
|
[INFO] | +- org.gcube.common.security:gcube-secrets:jar:1.0.1:provided
|
||||||
|
[INFO] | | +- org.gcube.common:keycloak-client:jar:2.1.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.common:gxJRS:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | | \- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:provided
|
||||||
|
[INFO] | | | +- io.jsonwebtoken:jjwt-api:jar:0.12.5:provided
|
||||||
|
[INFO] | | | \- io.jsonwebtoken:jjwt-impl:jar:0.12.5:provided
|
||||||
|
[INFO] | | \- com.auth0:java-jwt:jar:4.4.0:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-core:jar:1.9.0:provided
|
||||||
|
[INFO] | | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
|
||||||
|
[INFO] | | \- org.latencyutils:LatencyUtils:jar:2.0.3:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-registry-prometheus:jar:1.9.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient:jar:0.15.0:provided
|
||||||
|
[INFO] | | +- io.prometheus:simpleclient_tracer_otel:jar:0.15.0:provided
|
||||||
|
[INFO] | | | \- io.prometheus:simpleclient_tracer_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.15.0:provided
|
||||||
|
[INFO] | \- org.gcube.resources:common-gcore-resources:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.ws:jakarta.xml.ws-api:jar:4.0.1:provided
|
||||||
|
[INFO] | | \- jakarta.xml.soap:jakarta.xml.soap-api:jar:3.0.1:provided
|
||||||
|
[INFO] | \- com.sun.xml.ws:jaxws-rt:jar:4.0.2:provided
|
||||||
|
[INFO] | +- org.glassfish.ha:ha-api:jar:3.1.13:provided
|
||||||
|
[INFO] | +- org.glassfish.external:management-api:jar:3.2.3:provided
|
||||||
|
[INFO] | +- org.glassfish.gmbal:gmbal-api-only:jar:4.0.3:provided
|
||||||
|
[INFO] | +- org.jvnet.staxex:stax-ex:jar:2.1.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.stream.buffer:streambuffer:jar:2.1.0:provided
|
||||||
|
[INFO] | +- org.jvnet.mimepull:mimepull:jar:1.10.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.fastinfoset:FastInfoset:jar:2.1.0:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-activation:jar:2.0.1:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-mail:jar:2.0.2:provided
|
||||||
|
[INFO] | +- com.sun.xml.messaging.saaj:saaj-impl:jar:3.0.3:provided
|
||||||
|
[INFO] | +- com.fasterxml.woodstox:woodstox-core:jar:6.5.1:provided
|
||||||
|
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:4.2.2:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.1:compile
|
||||||
|
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:compile
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-impl:jar:4.0.4:provided
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-core:jar:4.0.4:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope-maps:jar:1.1.1:provided
|
||||||
|
[INFO] +- org.gcube.common:authorization-client:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | \- org.gcube.common:common-authorization:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] +- org.gcube.social-networking:social-service-model:jar:2.0.0-SNAPSHOT:compile
|
||||||
|
[INFO] | +- org.gcube.common:storagehub-model:jar:2.0.0-SNAPSHOT:compile
|
||||||
|
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.11:compile
|
||||||
|
[INFO] | +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
|
||||||
|
[INFO] | \- com.google:gwt-jsonmaker:jar:1.2.1:provided
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-query-builder:jar:4.13.0:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-core:jar:4.13.0:compile
|
||||||
|
[INFO] | | +- com.datastax.oss:native-protocol:jar:1.5.0:compile
|
||||||
|
[INFO] | | +- io.netty:netty-handler:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-common:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-transport:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | \- io.netty:netty-codec:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | +- com.typesafe:config:jar:1.4.1:compile
|
||||||
|
[INFO] | | +- com.github.jnr:jnr-posix:jar:3.1.5:compile
|
||||||
|
[INFO] | | | +- com.github.jnr:jnr-ffi:jar:2.2.2:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:1.3.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:native:1.3.1:runtime
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-commons:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-analysis:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-tree:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-util:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jnr-a64asm:jar:1.0.0:compile
|
||||||
|
[INFO] | | | | \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
|
||||||
|
[INFO] | | | \- com.github.jnr:jnr-constants:jar:0.10.1:compile
|
||||||
|
[INFO] | | +- io.dropwizard.metrics:metrics-core:jar:4.1.18:compile
|
||||||
|
[INFO] | | +- com.esri.geometry:esri-geometry-api:jar:1.2.1:compile
|
||||||
|
[INFO] | | | +- org.json:json:jar:20090211:compile
|
||||||
|
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:provided
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.12.2:compile
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.2:compile
|
||||||
|
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-shaded-guava:jar:25.1-jre-graal-sub-1:compile
|
||||||
|
[INFO] | +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
|
||||||
|
[INFO] | \- com.github.spotbugs:spotbugs-annotations:jar:3.1.12:compile
|
||||||
|
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:compile
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-mapper-runtime:jar:4.13.0:compile
|
||||||
|
[INFO] +- commons-lang:commons-lang:jar:2.6:provided
|
||||||
|
[INFO] +- org.gcube.common.portal:portal-manager:jar:2.4.2:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-core-annotations:jar:2.14.0:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-rt-util:jar:2.14.0:provided
|
||||||
|
[INFO] +- jakarta.servlet:jakarta.servlet-api:jar:4.0.4:provided
|
||||||
|
[INFO] +- junit:junit:jar:4.13.2:test
|
||||||
|
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
|
||||||
|
[INFO] +- ch.qos.logback:logback-classic:jar:1.5.0:test
|
||||||
|
[INFO] | \- ch.qos.logback:logback-core:jar:1.5.0:test
|
||||||
|
[INFO] +- jakarta.mail:jakarta.mail-api:jar:1.6.7:compile
|
||||||
|
[INFO] \- net.sf.ehcache:ehcache:jar:2.10.0:compile
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] BUILD SUCCESS
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] Total time: 0.875 s
|
||||||
|
[INFO] Finished at: 2024-05-16T15:44:20+02:00
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
|
@ -0,0 +1,138 @@
|
||||||
|
[INFO] Scanning for projects...
|
||||||
|
[INFO]
|
||||||
|
[INFO] -------------< org.gcube.social_networking:social-service >-------------
|
||||||
|
[INFO] Building Social Service 1.0.0-SNAPSHOT
|
||||||
|
[INFO] from pom.xml
|
||||||
|
[INFO] --------------------------------[ war ]---------------------------------
|
||||||
|
[INFO]
|
||||||
|
[INFO] --- dependency:3.6.1:tree (default-cli) @ social-service ---
|
||||||
|
[INFO] org.gcube.social_networking:social-service:war:1.0.0-SNAPSHOT
|
||||||
|
[INFO] +- org.slf4j:slf4j-api:jar:2.0.12:provided
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet:jar:3.1.5:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
|
||||||
|
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:3.1.5:compile
|
||||||
|
[INFO] | | \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
|
||||||
|
[INFO] | \- jakarta.ws.rs:jakarta.ws.rs-api:jar:3.1.0:compile
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:3.1.5:compile
|
||||||
|
[INFO] | \- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears-app:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | +- org.javassist:javassist:jar:3.20.0-GA:compile
|
||||||
|
[INFO] | \- com.google.guava:guava:jar:18.0:provided
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears:jar:4.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.reflections:reflections:jar:0.9.12:provided
|
||||||
|
[INFO] | +- org.yaml:snakeyaml:jar:2.2:provided
|
||||||
|
[INFO] | +- io.github.classgraph:classgraph:jar:4.8.28:provided
|
||||||
|
[INFO] | +- org.gcube.common:health-api:jar:1.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-databind:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-annotations:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-core:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:common-security:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.data.publishing:document-store-lib:jar:3.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.accounting:accounting-lib:jar:5.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.resources.discovery:ic-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.resources.discovery:discovery-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | \- org.gcube.core:common-gcore-stubs:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.core:common-encryption:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:common-utility-sg4:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:gxHTTP:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.ini4j:ini4j:jar:0.5.4:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-validator:jar:1.1.0:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-events:jar:1.0.2:provided
|
||||||
|
[INFO] | +- org.gcube.common.security:gcube-secrets:jar:1.0.1:provided
|
||||||
|
[INFO] | | +- org.gcube.common:keycloak-client:jar:2.1.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.common:gxJRS:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | | \- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:provided
|
||||||
|
[INFO] | | | +- io.jsonwebtoken:jjwt-api:jar:0.12.5:provided
|
||||||
|
[INFO] | | | \- io.jsonwebtoken:jjwt-impl:jar:0.12.5:provided
|
||||||
|
[INFO] | | \- com.auth0:java-jwt:jar:4.4.0:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-core:jar:1.9.0:provided
|
||||||
|
[INFO] | | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
|
||||||
|
[INFO] | | \- org.latencyutils:LatencyUtils:jar:2.0.3:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-registry-prometheus:jar:1.9.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient:jar:0.15.0:provided
|
||||||
|
[INFO] | | +- io.prometheus:simpleclient_tracer_otel:jar:0.15.0:provided
|
||||||
|
[INFO] | | | \- io.prometheus:simpleclient_tracer_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.15.0:provided
|
||||||
|
[INFO] | \- org.gcube.resources:common-gcore-resources:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.ws:jakarta.xml.ws-api:jar:4.0.1:provided
|
||||||
|
[INFO] | | \- jakarta.xml.soap:jakarta.xml.soap-api:jar:3.0.1:provided
|
||||||
|
[INFO] | \- com.sun.xml.ws:jaxws-rt:jar:4.0.2:provided
|
||||||
|
[INFO] | +- org.glassfish.ha:ha-api:jar:3.1.13:provided
|
||||||
|
[INFO] | +- org.glassfish.external:management-api:jar:3.2.3:provided
|
||||||
|
[INFO] | +- org.glassfish.gmbal:gmbal-api-only:jar:4.0.3:provided
|
||||||
|
[INFO] | +- org.jvnet.staxex:stax-ex:jar:2.1.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.stream.buffer:streambuffer:jar:2.1.0:provided
|
||||||
|
[INFO] | +- org.jvnet.mimepull:mimepull:jar:1.10.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.fastinfoset:FastInfoset:jar:2.1.0:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-activation:jar:2.0.1:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-mail:jar:2.0.2:provided
|
||||||
|
[INFO] | +- com.sun.xml.messaging.saaj:saaj-impl:jar:3.0.3:provided
|
||||||
|
[INFO] | +- com.fasterxml.woodstox:woodstox-core:jar:6.5.1:provided
|
||||||
|
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:4.2.2:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.1:compile
|
||||||
|
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:compile
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-impl:jar:4.0.4:provided
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-core:jar:4.0.4:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope-maps:jar:1.1.1:provided
|
||||||
|
[INFO] +- org.gcube.common:authorization-client:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | \- org.gcube.common:common-authorization:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] +- org.gcube.social-networking:social-service-model:jar:2.0.0-SNAPSHOT:compile
|
||||||
|
[INFO] | +- org.gcube.common:storagehub-model:jar:2.0.0-SNAPSHOT:compile
|
||||||
|
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.11:compile
|
||||||
|
[INFO] | +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
|
||||||
|
[INFO] | \- com.google:gwt-jsonmaker:jar:1.2.1:provided
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-query-builder:jar:4.13.0:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-core:jar:4.13.0:compile
|
||||||
|
[INFO] | | +- com.datastax.oss:native-protocol:jar:1.5.0:compile
|
||||||
|
[INFO] | | +- io.netty:netty-handler:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-common:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-transport:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | \- io.netty:netty-codec:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | +- com.typesafe:config:jar:1.4.1:compile
|
||||||
|
[INFO] | | +- com.github.jnr:jnr-posix:jar:3.1.5:compile
|
||||||
|
[INFO] | | | +- com.github.jnr:jnr-ffi:jar:2.2.2:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:1.3.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:native:1.3.1:runtime
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-commons:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-analysis:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-tree:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-util:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jnr-a64asm:jar:1.0.0:compile
|
||||||
|
[INFO] | | | | \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
|
||||||
|
[INFO] | | | \- com.github.jnr:jnr-constants:jar:0.10.1:compile
|
||||||
|
[INFO] | | +- io.dropwizard.metrics:metrics-core:jar:4.1.18:compile
|
||||||
|
[INFO] | | +- com.esri.geometry:esri-geometry-api:jar:1.2.1:compile
|
||||||
|
[INFO] | | | +- org.json:json:jar:20090211:compile
|
||||||
|
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:provided
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.12.2:compile
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.2:compile
|
||||||
|
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-shaded-guava:jar:25.1-jre-graal-sub-1:compile
|
||||||
|
[INFO] | +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
|
||||||
|
[INFO] | \- com.github.spotbugs:spotbugs-annotations:jar:3.1.12:compile
|
||||||
|
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:compile
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-mapper-runtime:jar:4.13.0:compile
|
||||||
|
[INFO] +- commons-lang:commons-lang:jar:2.6:provided
|
||||||
|
[INFO] +- org.gcube.common.portal:portal-manager:jar:2.4.2:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-core-annotations:jar:2.14.0:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-rt-util:jar:2.14.0:provided
|
||||||
|
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
|
||||||
|
[INFO] +- junit:junit:jar:4.13.2:test
|
||||||
|
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
|
||||||
|
[INFO] +- ch.qos.logback:logback-classic:jar:1.5.0:test
|
||||||
|
[INFO] | \- ch.qos.logback:logback-core:jar:1.5.0:test
|
||||||
|
[INFO] \- jakarta.mail:jakarta.mail-api:jar:1.6.7:compile
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] BUILD SUCCESS
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] Total time: 0.917 s
|
||||||
|
[INFO] Finished at: 2024-05-16T15:21:58+02:00
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
|
@ -0,0 +1,146 @@
|
||||||
|
[INFO] Scanning for projects...
|
||||||
|
[WARNING]
|
||||||
|
[WARNING] Some problems were encountered while building the effective model for org.gcube.social_networking:social-service:war:1.0.0-SNAPSHOT
|
||||||
|
[WARNING] 'parent.relativePath' of POM org.gcube.social_networking:social-service:1.0.0-SNAPSHOT (/Users/Alfredo/works/gCubeSystem/social-service/pom.xml) points at org.gcube.idm:idm-client-library instead of org.gcube.tools:maven-parent, please verify your project structure @ line 5, column 10
|
||||||
|
[WARNING]
|
||||||
|
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
|
||||||
|
[WARNING]
|
||||||
|
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
|
||||||
|
[WARNING]
|
||||||
|
[INFO]
|
||||||
|
[INFO] -------------< org.gcube.social_networking:social-service >-------------
|
||||||
|
[INFO] Building Social Service 1.0.0-SNAPSHOT
|
||||||
|
[INFO] from pom.xml
|
||||||
|
[INFO] --------------------------------[ war ]---------------------------------
|
||||||
|
[WARNING] The POM for org.gcube.social-networking:social-service-model:jar:2.0.0-SNAPSHOT is missing, no dependency information available
|
||||||
|
[INFO]
|
||||||
|
[INFO] --- dependency:3.6.1:tree (default-cli) @ social-service ---
|
||||||
|
[INFO] org.gcube.social_networking:social-service:war:1.0.0-SNAPSHOT
|
||||||
|
[INFO] +- org.slf4j:slf4j-api:jar:2.0.12:provided
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet:jar:3.1.5:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
|
||||||
|
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
|
||||||
|
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:3.1.5:compile
|
||||||
|
[INFO] | | +- org.glassfish.jersey.core:jersey-client:jar:3.1.5:compile
|
||||||
|
[INFO] | | \- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
|
||||||
|
[INFO] | \- jakarta.ws.rs:jakarta.ws.rs-api:jar:3.1.0:compile
|
||||||
|
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:3.1.5:compile
|
||||||
|
[INFO] | \- jakarta.inject:jakarta.inject-api:jar:2.0.1:compile
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears-app:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | +- org.javassist:javassist:jar:3.20.0-GA:compile
|
||||||
|
[INFO] | \- com.google.guava:guava:jar:18.0:provided
|
||||||
|
[INFO] +- org.gcube.core:common-smartgears:jar:4.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.reflections:reflections:jar:0.9.12:provided
|
||||||
|
[INFO] | +- org.yaml:snakeyaml:jar:2.2:provided
|
||||||
|
[INFO] | +- io.github.classgraph:classgraph:jar:4.8.28:provided
|
||||||
|
[INFO] | +- org.gcube.common:health-api:jar:1.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-databind:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-annotations:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:gcube-jackson-core:jar:2.8.11:provided
|
||||||
|
[INFO] | +- org.gcube.common:common-security:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.data.publishing:document-store-lib:jar:3.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.gcube.accounting:accounting-lib:jar:5.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.resources.discovery:ic-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.resources.discovery:discovery-client:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | \- org.gcube.core:common-gcore-stubs:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | +- org.gcube.core:common-encryption:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:common-utility-sg4:jar:1.0.1-SNAPSHOT:provided
|
||||||
|
[INFO] | | \- org.gcube.common:gxHTTP:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- org.ini4j:ini4j:jar:0.5.4:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-validator:jar:1.1.0:provided
|
||||||
|
[INFO] | +- org.gcube.core:common-events:jar:1.0.2:provided
|
||||||
|
[INFO] | +- org.gcube.common.security:gcube-secrets:jar:1.0.1:provided
|
||||||
|
[INFO] | | +- org.gcube.common:keycloak-client:jar:2.1.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | +- org.gcube.common:gxJRS:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | | | | \- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:provided
|
||||||
|
[INFO] | | | +- io.jsonwebtoken:jjwt-api:jar:0.12.5:provided
|
||||||
|
[INFO] | | | \- io.jsonwebtoken:jjwt-impl:jar:0.12.5:provided
|
||||||
|
[INFO] | | \- com.auth0:java-jwt:jar:4.4.0:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-core:jar:1.9.0:provided
|
||||||
|
[INFO] | | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
|
||||||
|
[INFO] | | \- org.latencyutils:LatencyUtils:jar:2.0.3:provided
|
||||||
|
[INFO] | +- io.micrometer:micrometer-registry-prometheus:jar:1.9.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient:jar:0.15.0:provided
|
||||||
|
[INFO] | | +- io.prometheus:simpleclient_tracer_otel:jar:0.15.0:provided
|
||||||
|
[INFO] | | | \- io.prometheus:simpleclient_tracer_common:jar:0.15.0:provided
|
||||||
|
[INFO] | | \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.15.0:provided
|
||||||
|
[INFO] | \- org.gcube.resources:common-gcore-resources:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.ws:jakarta.xml.ws-api:jar:4.0.1:provided
|
||||||
|
[INFO] | | \- jakarta.xml.soap:jakarta.xml.soap-api:jar:3.0.1:provided
|
||||||
|
[INFO] | \- com.sun.xml.ws:jaxws-rt:jar:4.0.2:provided
|
||||||
|
[INFO] | +- org.glassfish.ha:ha-api:jar:3.1.13:provided
|
||||||
|
[INFO] | +- org.glassfish.external:management-api:jar:3.2.3:provided
|
||||||
|
[INFO] | +- org.glassfish.gmbal:gmbal-api-only:jar:4.0.3:provided
|
||||||
|
[INFO] | +- org.jvnet.staxex:stax-ex:jar:2.1.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.stream.buffer:streambuffer:jar:2.1.0:provided
|
||||||
|
[INFO] | +- org.jvnet.mimepull:mimepull:jar:1.10.0:provided
|
||||||
|
[INFO] | +- com.sun.xml.fastinfoset:FastInfoset:jar:2.1.0:provided
|
||||||
|
[INFO] | +- jakarta.mail:jakarta.mail-api:jar:2.1.2:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-activation:jar:2.0.1:provided
|
||||||
|
[INFO] | +- org.eclipse.angus:angus-mail:jar:2.0.2:provided
|
||||||
|
[INFO] | +- com.sun.xml.messaging.saaj:saaj-impl:jar:3.0.3:provided
|
||||||
|
[INFO] | +- com.fasterxml.woodstox:woodstox-core:jar:6.5.1:provided
|
||||||
|
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:4.2.2:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope:jar:2.0.0-SNAPSHOT:provided
|
||||||
|
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.1:compile
|
||||||
|
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:compile
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-impl:jar:4.0.4:provided
|
||||||
|
[INFO] | \- com.sun.xml.bind:jaxb-core:jar:4.0.4:provided
|
||||||
|
[INFO] +- org.gcube.core:common-scope-maps:jar:1.1.1:provided
|
||||||
|
[INFO] +- org.gcube.common:authorization-client:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] | \- org.gcube.common:common-authorization:jar:3.0.1-SNAPSHOT:compile
|
||||||
|
[INFO] +- org.gcube.social-networking:social-service-model:jar:2.0.0-SNAPSHOT:compile
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-query-builder:jar:4.13.0:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-core:jar:4.13.0:compile
|
||||||
|
[INFO] | | +- com.datastax.oss:native-protocol:jar:1.5.0:compile
|
||||||
|
[INFO] | | +- io.netty:netty-handler:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-common:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | +- io.netty:netty-transport:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | | \- io.netty:netty-codec:jar:4.1.60.Final:compile
|
||||||
|
[INFO] | | +- com.typesafe:config:jar:1.4.1:compile
|
||||||
|
[INFO] | | +- com.github.jnr:jnr-posix:jar:3.1.5:compile
|
||||||
|
[INFO] | | | +- com.github.jnr:jnr-ffi:jar:2.2.2:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:1.3.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jffi:jar:native:1.3.1:runtime
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-commons:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-analysis:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-tree:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- org.ow2.asm:asm-util:jar:9.1:compile
|
||||||
|
[INFO] | | | | +- com.github.jnr:jnr-a64asm:jar:1.0.0:compile
|
||||||
|
[INFO] | | | | \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
|
||||||
|
[INFO] | | | \- com.github.jnr:jnr-constants:jar:0.10.1:compile
|
||||||
|
[INFO] | | +- io.dropwizard.metrics:metrics-core:jar:4.1.18:compile
|
||||||
|
[INFO] | | +- com.esri.geometry:esri-geometry-api:jar:1.2.1:compile
|
||||||
|
[INFO] | | | +- org.json:json:jar:20090211:compile
|
||||||
|
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:provided
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.12.2:compile
|
||||||
|
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.2:compile
|
||||||
|
[INFO] | | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.2:compile
|
||||||
|
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
|
||||||
|
[INFO] | +- com.datastax.oss:java-driver-shaded-guava:jar:25.1-jre-graal-sub-1:compile
|
||||||
|
[INFO] | +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
|
||||||
|
[INFO] | \- com.github.spotbugs:spotbugs-annotations:jar:3.1.12:compile
|
||||||
|
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:compile
|
||||||
|
[INFO] +- com.datastax.oss:java-driver-mapper-runtime:jar:4.13.0:compile
|
||||||
|
[INFO] +- commons-lang:commons-lang:jar:2.6:provided
|
||||||
|
[INFO] +- com.sun.mail:javax.mail:jar:1.5.2:compile
|
||||||
|
[INFO] | \- javax.activation:activation:jar:1.1:compile
|
||||||
|
[INFO] +- org.gcube.common.portal:portal-manager:jar:2.4.2:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-core-annotations:jar:2.14.0:provided
|
||||||
|
[INFO] +- com.webcohesion.enunciate:enunciate-rt-util:jar:2.14.0:provided
|
||||||
|
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
|
||||||
|
[INFO] +- junit:junit:jar:4.13.2:test
|
||||||
|
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
|
||||||
|
[INFO] \- ch.qos.logback:logback-classic:jar:1.5.0:test
|
||||||
|
[INFO] \- ch.qos.logback:logback-core:jar:1.5.0:test
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] BUILD SUCCESS
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
||||||
|
[INFO] Total time: 0.697 s
|
||||||
|
[INFO] Finished at: 2024-05-16T15:11:57+02:00
|
||||||
|
[INFO] ------------------------------------------------------------------------
|
Loading…
Reference in New Issue