From 036889d389c45676ca1f1d40415919f4bfa1aacd Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Tue, 9 Dec 2014 14:55:36 +0000
Subject: [PATCH] SSDM-1321 : PAPER - UI to create Users (Server Side)

SVN: 32997
---
 .../api/v1/GeneralInformationService.java     |  17 ++-
 .../v1/GeneralInformationServiceLogger.java   |   8 ++
 .../generic/shared/api/v1/Translator.java     |  15 +-
 .../openbis/public/resources/js/openbis.js    |  13 ++
 .../dto/search/DateFieldSearchCriterion.java  |  15 +-
 .../api/v1/IGeneralInformationService.java    |  10 ++
 .../generic/shared/api/v1/dto/Person.java     | 133 ++++++++++++++++++
 7 files changed, 204 insertions(+), 7 deletions(-)
 create mode 100644 openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Person.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
index 181e88c22d8..5477304dd46 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
@@ -116,6 +116,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListMaterialCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Metaproject;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SearchDomainSearchResultWithFullEntity;
 import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentHolderPE;
@@ -146,7 +147,7 @@ import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
 public class GeneralInformationService extends AbstractServer<IGeneralInformationService> implements
         IGeneralInformationService
 {
-    public static final int MINOR_VERSION = 30;
+    public static final int MINOR_VERSION = 31;
 
     @Resource(name = ch.systemsx.cisd.openbis.generic.shared.ResourceNames.COMMON_SERVER)
     private ICommonServer commonServer;
@@ -1351,4 +1352,18 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio
         }
     }
 
+    @Override
+    @Transactional(readOnly = true)
+    @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN)
+    public List<ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person> listPersons(String sessionToken)
+    {
+        List<ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person> persons = commonServer.listPersons(sessionToken);
+        List<ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person> personsResult = new ArrayList<ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person>();
+        
+        for(Person person:persons) {
+            personsResult.add(Translator.translate(person));
+        }
+        
+        return personsResult;
+    }
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java
index aab8f57d781..c24337e49b0 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java
@@ -41,6 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ExperimentType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MaterialIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MetaprojectAssignments;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Role;
@@ -506,4 +507,11 @@ class GeneralInformationServiceLogger extends AbstractServerLogger implements
         return null;
     }
 
+    @Override
+    public List<Person> listPersons(String sessionToken)
+    {
+        logAccess(sessionToken, "listPersons");
+        return null;
+    }
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
index a5fb9f81194..1d3416056b0 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/Translator.java
@@ -112,7 +112,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.LinkDataSet;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.LinkDataSetUrl;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Metaproject;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy.RoleCode;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy.RoleLevel;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Script;
@@ -625,7 +625,7 @@ public class Translator
     private static EntityRegistrationDetails.EntityRegistrationDetailsInitializer createInitializer(
             CodeWithRegistration<?> thingWithRegistrationDetails)
     {
-        Person registrator = thingWithRegistrationDetails.getRegistrator();
+        ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person registrator = thingWithRegistrationDetails.getRegistrator();
         EntityRegistrationDetails.EntityRegistrationDetailsInitializer initializer =
                 new EntityRegistrationDetails.EntityRegistrationDetailsInitializer();
         if (registrator != null)
@@ -1078,6 +1078,17 @@ public class Translator
         return result;
     }
 
+    public static Person translate(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person person)
+    {
+        Person result = new Person();
+        result.setUserId(person.getUserId());
+        result.setFirstName(person.getFirstName());
+        result.setLastName(person.getLastName());
+        result.setEmail(person.getEmail());
+        result.setActive(person.isActive());
+        return result;
+    }
+    
     public static Deletion translate(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion deletion)
     {
         Deletion result = new Deletion();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/js/openbis.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/js/openbis.js
index 0fd23a9d66d..0dd01b2e3b7 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/js/openbis.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/js/openbis.js
@@ -1113,6 +1113,19 @@ openbis.prototype.listDeletions = function(fetchOptions, action) {
 	});
 }
 
+/**
+ * @see GeneralInformationService.listPersons(String)
+ * @method
+ */
+openbis.prototype.listPersons = function(action) {
+	this._internal.ajaxRequest({
+		url: this._internal.generalInfoServiceUrl,
+		data: { "method" : "listPersons",
+				"params" : [ this.getSession() ] },
+		success: action
+	});
+}
+
 /**
  * ==========================================================================================
  * ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationChangingService methods
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/search/DateFieldSearchCriterion.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/search/DateFieldSearchCriterion.java
index 584bf5fdc62..4738a7dd30b 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/search/DateFieldSearchCriterion.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/search/DateFieldSearchCriterion.java
@@ -18,8 +18,9 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.search;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 import ch.systemsx.cisd.base.annotation.JsonObject;
 
@@ -29,8 +30,14 @@ public class DateFieldSearchCriterion extends AbstractFieldSearchCriterion<IDate
 
     private static final long serialVersionUID = 1L;
 
-    private static final IDateFormat[] DATE_FORMATS = new IDateFormat[] { new ShortDateFormat(), new NormalDateFormat(), new LongDateFormat() };
-
+    private static final List<IDateFormat> DATE_FORMATS = new ArrayList<IDateFormat>();
+    
+    static {
+        DATE_FORMATS.add(new ShortDateFormat());
+        DATE_FORMATS.add(new NormalDateFormat());
+        DATE_FORMATS.add(new LongDateFormat());
+    }
+    
     private ITimeZone timeZone = new ServerTimeZone();
 
     DateFieldSearchCriterion(String fieldName, SearchFieldType fieldType)
@@ -116,7 +123,7 @@ public class DateFieldSearchCriterion extends AbstractFieldSearchCriterion<IDate
             }
 
             throw new IllegalArgumentException("Date value: " + value + " does not match any of the supported formats: "
-                    + Arrays.toString(DATE_FORMATS));
+                    + DATE_FORMATS);
         }
     }
 
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java
index bde1a3c3f81..6ae9a82eabd 100644
--- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java
@@ -39,6 +39,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ExperimentType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MaterialIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MetaprojectAssignments;
+import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Person;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Role;
@@ -576,4 +577,13 @@ public interface IGeneralInformationService extends IRpcService
      */
     public List<Deletion> listDeletions(String sessionToken, EnumSet<DeletionFetchOption> fetchOptions);
 
+    /**
+     * Returns all persons.
+     * 
+     * @param fetchOptions Options that control which parts of the deletions are fetched.
+     * @return a list of maps with the user information.
+     * @since 1.31
+     */
+    List<Person> listPersons(String sessionToken);
+
 }
diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Person.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Person.java
new file mode 100644
index 00000000000..6ee8c514b12
--- /dev/null
+++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/Person.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2008 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.shared.api.v1.dto;
+
+import java.io.Serializable;
+
+import ch.systemsx.cisd.base.annotation.JsonObject;
+
+/**
+ * Immutable value object representing a person.
+ * 
+ * @author Juan Fuentes
+ */
+@JsonObject("Person")
+public class Person implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private String firstName;
+
+    private String lastName;
+
+    private String email;
+
+    private String userId;
+
+    private boolean active;
+
+    public final String getFirstName()
+    {
+        return firstName;
+    }
+
+    public final void setFirstName(final String firstName)
+    {
+        this.firstName = firstName;
+    }
+
+    public final String getLastName()
+    {
+        return lastName;
+    }
+
+    public final void setLastName(final String lastName)
+    {
+        this.lastName = lastName;
+    }
+
+    public final String getEmail()
+    {
+        return email;
+    }
+
+    public final void setEmail(final String mail)
+    {
+        email = mail;
+    }
+
+    public String getUserId()
+    {
+        return userId;
+    }
+
+    public void setUserId(final String code)
+    {
+        this.userId = code;
+    }
+
+    public boolean isActive()
+    {
+        return active;
+    }
+
+    public void setActive(boolean active)
+    {
+        this.active = active;
+    }
+
+    //
+    // Object
+    //
+    @Override
+    public boolean equals(Object obj)
+    {
+        assert getUserId() != null;
+        if (obj == this)
+        {
+            return true;
+        }
+        if (obj instanceof Person == false)
+        {
+            return false;
+        }
+        final Person that = (Person) obj;
+        return getUserId().equals(that.getUserId());
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return getUserId().hashCode();
+    }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder result = new StringBuilder();
+        if (firstName != null && lastName != null)
+        {
+            result.append(firstName);
+            result.append(" ");
+            result.append(lastName);
+        } else
+        {
+            result.append(userId);
+        }
+        return result.toString();
+    }
+}
-- 
GitLab