From b1dfd9ce934914554e0fdb87c15391114096e497 Mon Sep 17 00:00:00 2001
From: jakubs <jakubs>
Date: Mon, 16 Mar 2015 15:06:24 +0000
Subject: [PATCH] SSDM-1626 add materials to v3

SVN: 33656
---
 .../shared/api/v3/IApplicationServerApi.java  |   5 +
 .../api/v3/dto/entity/material/Material.java  | 168 +++++++++++++++++-
 .../api/v3/dto/generators/Generator.java      |  29 +++
 .../v3/dto/id/material/MaterialPermId.java    |  82 ++++++++-
 4 files changed, 273 insertions(+), 11 deletions(-)

diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java
index 0b09eec3848..f52a293b895 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java
@@ -28,6 +28,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.dataset.DataSetUpdat
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleUpdate;
@@ -37,12 +38,14 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.space.SpaceUpdate;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.DataSetFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.experiment.ExperimentFetchOptions;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.material.MaterialFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.IMaterialId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.ISpaceId;
@@ -135,6 +138,8 @@ public interface IApplicationServerApi extends IRpcService
 
     public Map<IDataSetId, DataSet> mapDataSets(String sessionToken, List<? extends IDataSetId> dataSetIds, DataSetFetchOptions fetchOptions);
 
+    public Map<IMaterialId, Material> mapMaterials(String sessionToken, List<? extends IMaterialId> materialIds, MaterialFetchOptions fetchOptions);
+
     // REPLACES:
     // - ServiceForDataStoreServer.listExperimentsForProjects(List<ProjectIdentifier>, ExperimentFetchOptions)
     // - ServiceForDataStoreServer.listExperiments(ProjectIdentifier)
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/material/Material.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/material/Material.java
index c8b4098ee57..4ea7a30bca7 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/material/Material.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/material/Material.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 ETH Zuerich, CISD
+ * Copyright 2014 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.
@@ -13,20 +13,176 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material;
 
-import java.io.Serializable;
-
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.person.Person;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.tag.Tag;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.material.MaterialFetchOptions;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId;
+import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.NotFetchedException;
 import ch.systemsx.cisd.base.annotation.JsonObject;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
 
 /**
- * @author pkupczyk
+ * Class automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
  */
 @JsonObject("dto.entity.material.Material")
 public class Material implements Serializable
 {
-
     private static final long serialVersionUID = 1L;
 
+    @JsonProperty
+    private MaterialFetchOptions fetchOptions;
+
+    @JsonProperty
+    private MaterialPermId permId;
+
+    @JsonProperty
+    private String code;
+
+    @JsonProperty
+    private Date registrationDate;
+
+    @JsonProperty
+    private Person registrator;
+
+    @JsonProperty
+    private Date modificationDate;
+
+    @JsonProperty
+    private Map<String, String> properties;
+
+    @JsonProperty
+    private Set<Tag> tags;
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public MaterialFetchOptions getFetchOptions()
+    {
+        return fetchOptions;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setFetchOptions(MaterialFetchOptions fetchOptions)
+    {
+        this.fetchOptions = fetchOptions;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public MaterialPermId getPermId()
+    {
+        return permId;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setPermId(MaterialPermId permId)
+    {
+        this.permId = permId;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public String getCode()
+    {
+        return code;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setCode(String code)
+    {
+        this.code = code;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public Date getRegistrationDate()
+    {
+        return registrationDate;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setRegistrationDate(Date registrationDate)
+    {
+        this.registrationDate = registrationDate;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public Person getRegistrator()
+    {
+        if (getFetchOptions().hasRegistrator())
+        {
+            return registrator;
+        }
+        else
+        {
+            throw new NotFetchedException("Registrator has not been fetched.");
+        }
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setRegistrator(Person registrator)
+    {
+        this.registrator = registrator;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public Date getModificationDate()
+    {
+        return modificationDate;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setModificationDate(Date modificationDate)
+    {
+        this.modificationDate = modificationDate;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public Map<String, String> getProperties()
+    {
+        if (getFetchOptions().hasProperties())
+        {
+            return properties;
+        }
+        else
+        {
+            throw new NotFetchedException("Properties have not been fetched.");
+        }
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setProperties(Map<String, String> properties)
+    {
+        this.properties = properties;
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    @JsonIgnore
+    public Set<Tag> getTags()
+    {
+        if (getFetchOptions().hasTags())
+        {
+            return tags;
+        }
+        else
+        {
+            throw new NotFetchedException("Tags have not been fetched.");
+        }
+    }
+
+    // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator}
+    public void setTags(Set<Tag> tags)
+    {
+        this.tags = tags;
+    }
+
 }
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java
index a81792fc58e..88796160674 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java
@@ -30,6 +30,8 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.FileFo
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.LocatorTypeFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.experiment.ExperimentFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.experiment.ExperimentTypeFetchOptions;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.material.MaterialFetchOptions;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.material.MaterialTypeFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.person.PersonFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions;
@@ -42,6 +44,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.DataSetPermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.EntityTypePermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentIdentifier;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId;
+import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectIdentifier;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId;
 import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SampleIdentifier;
@@ -364,6 +367,30 @@ public class Generator extends AbstractGenerator
         return gen;
     }
 
+    private static DtoGenerator createMaterialGenerator()
+    {
+        DtoGenerator gen = new DtoGenerator("material", "Material", MaterialFetchOptions.class);
+        gen.addSimpleField(MaterialPermId.class, "permId");
+        addCode(gen);
+        addRegistrationDate(gen);
+        addRegistrator(gen);
+        addModificationDate(gen);
+        addProperties(gen);
+        addTags(gen);
+        return gen;
+    }
+
+    private static DtoGenerator createMaterialTypeGenerator()
+    {
+        DtoGenerator gen = new DtoGenerator("material", "MaterialType", MaterialTypeFetchOptions.class);
+
+        gen.addSimpleField(EntityTypePermId.class, "permId");
+        addCode(gen);
+        addDescription(gen);
+        addModificationDate(gen);
+        return gen;
+    }
+
     public static void main(String[] args) throws FileNotFoundException
     {
         List<DtoGenerator> list = new LinkedList<DtoGenerator>();
@@ -378,6 +405,8 @@ public class Generator extends AbstractGenerator
         list.add(createSampleTypeGenerator());
         list.add(createSpaceGenerator());
         list.add(createTagGenerator());
+        list.add(createMaterialGenerator());
+        list.add(createMaterialTypeGenerator());
 
         for (DtoGenerator gen : list)
         {
diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/id/material/MaterialPermId.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/id/material/MaterialPermId.java
index f5b00a452e6..ea5f1343ec8 100644
--- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/id/material/MaterialPermId.java
+++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/id/material/MaterialPermId.java
@@ -16,7 +16,6 @@
 
 package ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material;
 
-import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.ObjectPermId;
 import ch.systemsx.cisd.base.annotation.JsonObject;
 
 /**
@@ -25,17 +24,42 @@ import ch.systemsx.cisd.base.annotation.JsonObject;
  * @author pkupczyk
  */
 @JsonObject("dto.id.material.MaterialPermId")
-public class MaterialPermId extends ObjectPermId implements IMaterialId
+public class MaterialPermId implements IMaterialId
 {
 
     private static final long serialVersionUID = 1L;
 
+    private String code;
+
+    private String typeCode;
+
     /**
-     * @param permId Material perm id, e.g. "MY_MATERIAL (MY_MATERIAL_TYPE)".
+     * Material perm id, e.g. "MY_MATERIAL (MY_MATERIAL_TYPE)".
      */
-    public MaterialPermId(String permId)
+    public MaterialPermId(String materialCode, String materialTypeCode)
+    {
+        this.code = materialCode;
+        this.typeCode = materialTypeCode;
+    }
+
+    public String getCode()
     {
-        super(permId);
+        return code;
+    }
+
+    public void setCode(String code)
+    {
+        this.code = code;
+    }
+
+    public String getTypeCode()
+    {
+        return typeCode;
+    }
+
+    public void setTypeCode(String typeCode)
+    {
+        this.typeCode = typeCode;
     }
 
     //
@@ -48,4 +72,52 @@ public class MaterialPermId extends ObjectPermId implements IMaterialId
         super();
     }
 
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((code == null) ? 0 : code.hashCode());
+        result = prime * result + ((typeCode == null) ? 0 : typeCode.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        MaterialPermId other = (MaterialPermId) obj;
+        if (code == null)
+        {
+            if (other.code != null)
+            {
+                return false;
+            }
+        } else if (!code.equals(other.code))
+        {
+            return false;
+        }
+        if (typeCode == null)
+        {
+            if (other.typeCode != null)
+            {
+                return false;
+            }
+        } else if (!typeCode.equals(other.typeCode))
+        {
+            return false;
+        }
+        return true;
+    }
 }
-- 
GitLab