From 697b86d33bb7c1fef08c916484723672c85298fd Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <adellam@isti.cnr.it>
Date: Wed, 11 Oct 2017 18:40:14 +0200
Subject: [PATCH] grsf_publisher_ws: Convert to maven_artifact.

---
 .../grsf_publisher_ws/defaults/main.yml       | 11 +++-----
 smartgears/grsf_publisher_ws/tasks/main.yml   | 25 +++++++++++++++----
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/smartgears/grsf_publisher_ws/defaults/main.yml b/smartgears/grsf_publisher_ws/defaults/main.yml
index 6b7312f..0ba17b3 100644
--- a/smartgears/grsf_publisher_ws/defaults/main.yml
+++ b/smartgears/grsf_publisher_ws/defaults/main.yml
@@ -1,10 +1,7 @@
 ---
 grsf_publisher_ws_install: False
-grsf_publisher_ws_upgrade: False
-grsf_publisher_ws_gcube_repository: gcube-staging
-grsf_publisher_ws_ver: 1.3.0-4.6.1-152504
-
+grsf_publisher_ws_ver: latest
+grsf_publisher_ws_group_id: org.gcube.data-catalogue
 grsf_publisher_ws_name: grsf-publisher-ws
-grsf_publisher_ws_file: '{{ grsf_publisher_ws_name }}-{{ grsf_publisher_ws_ver }}.war'
-
-grsf_publisher_ws_url: 'http://maven.research-infrastructures.eu/nexus/content/repositories/{{ grsf_publisher_ws_gcube_repository }}/org/gcube/data-catalogue/{{grsf_publisher_ws_name}}/{{ grsf_publisher_ws_ver }}/{{ grsf_publisher_ws_file }}'
+grsf_publisher_ws_extension: war
+grsf_publisher_ws_file: '{{ grsf_publisher_ws_name }}-{{ grsf_publisher_ws_ver }}.{{ grsf_publisher_ws_extension }}'
diff --git a/smartgears/grsf_publisher_ws/tasks/main.yml b/smartgears/grsf_publisher_ws/tasks/main.yml
index 073a397..f85d8a1 100644
--- a/smartgears/grsf_publisher_ws/tasks/main.yml
+++ b/smartgears/grsf_publisher_ws/tasks/main.yml
@@ -1,14 +1,29 @@
 ---
 - block:
     - name: Remove the old grsf-publisher-ws files
-      file: path={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }} state=absent
-      when: grsf_publisher_ws_upgrade
+      file: path={{ item }} state=absent
+      with_items:
+        - '{{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }}'
+        - '{{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }}.{{ grsf_publisher_ws_extension }}'
+      notify: Restart smartgears
 
-    - name: Create the grsf-publisher-ws working directory
-      file: path={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }} state=directory owner={{ smartgears_user }} group={{ smartgears_user }}
+  become: True
+  become_user: '{{ d4science_user }}'
+  tags: [ 'smartgears', 'grsf_publisher_ws', 'tomcat' ]
+  when: not grsf_publisher_ws_install 
+
+- block:
+    - name: Get the grsf-publisher-ws war
+      maven_artifact: artifact_id={{ grsf_publisher_ws_name }} version={{ grsf_publisher_ws_version | default(omit) }} group_id={{ quota_group_id }} extension={{ quota_extension | default('war') }} repository_url={{ smartgears_global_base_url }} dest={{ smartgears_downloads_dir }}/{{ grsf_publisher_ws_file }}
+      register: grsf_publisher_download
+  
+    - name: Remove the old grsf-publisher-ws files
+      file: path={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }} state=absent
+      notify: Restart smartgears
+      when: ( grsf_publisher_download | changed )
   
     - name: Unarchive the grsf_publisher_ws war
-      unarchive: copy=no src={{ grsf_publisher_ws_url }} dest={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }} creates={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }}/WEB-INF/lib
+      copy: src={{ smartgears_downloads_dir }}/{{ grsf_publisher_ws_file }} dest={{ smartgears_instance_path }}/webapps/{{ grsf_publisher_ws_name }}. {{ grsf_publisher_ws_extension }} remote_src=yes force=yes
       notify: Restart smartgears
 
   become: True