From 13d2a309b1cfd2207f0f5d6af17a7db5963f3ebc Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 16 Aug 2017 17:45:12 +0200
Subject: [PATCH] allow to change overlay owenr and public status

---
 .../projects/overlays/OverlayRestImpl.java    | 27 +++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
index d42c8d428c..ceaaaa346c 100644
--- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
+++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
@@ -17,6 +17,7 @@ import lcsb.mapviewer.api.BaseRestImpl;
 import lcsb.mapviewer.api.ObjectNotFoundException;
 import lcsb.mapviewer.api.QueryException;
 import lcsb.mapviewer.common.Configuration;
+import lcsb.mapviewer.common.exception.InvalidArgumentException;
 import lcsb.mapviewer.model.Project;
 import lcsb.mapviewer.model.cache.FileEntry;
 import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException;
@@ -158,11 +159,27 @@ public class OverlayRestImpl extends BaseRestImpl {
 			if (layout.isPublicLayout() && !isAdmin) {
 				throw new SecurityException("You cannot modify given overlay");
 			}
-			if (overlayData.containsKey("description")) {
-				layout.setDescription((String) overlayData.get("description"));
-			}
-			if (overlayData.containsKey("name")) {
-				layout.setTitle((String) overlayData.get("name"));
+			for (String key : overlayData.keySet()) {
+				Object value = overlayData.get(key);
+				if (key.equalsIgnoreCase("description")) {
+					layout.setDescription((String) value);
+				} else if (key.equalsIgnoreCase("name")) {
+					layout.setTitle((String) value);
+				} else if (key.equalsIgnoreCase("publicOverlay")) {
+					if (value instanceof Boolean) {
+						layout.setPublicLayout((Boolean) value);
+					} else {
+						layout.setPublicLayout("true".equalsIgnoreCase((String) value));
+					}
+				} else if (key.equalsIgnoreCase("creator")) {
+					if ("".equals(value)) {
+						layout.setCreator(null);
+					} else {
+						layout.setCreator(getUserService().getUserByLogin((String) value));
+					}
+				} else {
+					throw new QueryException("Unknown parameter: " + key);
+				}
 			}
 			layoutDao.update(layout);
 			return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken);
-- 
GitLab