extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/CohortTypeDefFactory.java

Code
Comments
Other
Rev Date Author Line
4464 24 Apr 17 nicklas 1 package net.sf.basedb.reggie.plugins.release;
4464 24 Apr 17 nicklas 2
4468 26 Apr 17 nicklas 3 import java.util.ArrayList;
4468 26 Apr 17 nicklas 4 import java.util.List;
4468 26 Apr 17 nicklas 5
4468 26 Apr 17 nicklas 6 import net.sf.basedb.core.AnnotationType;
4468 26 Apr 17 nicklas 7 import net.sf.basedb.core.DbControl;
4464 24 Apr 17 nicklas 8 import net.sf.basedb.core.Item;
4464 24 Apr 17 nicklas 9 import net.sf.basedb.core.Type;
4464 24 Apr 17 nicklas 10 import net.sf.basedb.reggie.dao.Annotationtype;
4469 26 Apr 17 nicklas 11 import net.sf.basedb.reggie.dao.Datafiletype;
7014 26 Jan 23 nicklas 12 import net.sf.basedb.reggie.dao.Rawdatatype;
4464 24 Apr 17 nicklas 13
4464 24 Apr 17 nicklas 14 /**
4464 24 Apr 17 nicklas 15   Helper class for creating cohort annotation type definitions
4464 24 Apr 17 nicklas 16   that share some common properties.
4464 24 Apr 17 nicklas 17
4464 24 Apr 17 nicklas 18   @author nicklas
4464 24 Apr 17 nicklas 19   @since 4.10
4464 24 Apr 17 nicklas 20 */
4469 26 Apr 17 nicklas 21 public class CohortTypeDefFactory 
4464 24 Apr 17 nicklas 22 {
4464 24 Apr 17 nicklas 23   
4468 26 Apr 17 nicklas 24   private final DbControl dc;
4468 26 Apr 17 nicklas 25   private final List<CohortTypeDef> allCreated;
4468 26 Apr 17 nicklas 26   
4464 24 Apr 17 nicklas 27   private Item itemType;
4464 24 Apr 17 nicklas 28   private String subtype;
4464 24 Apr 17 nicklas 29   
4464 24 Apr 17 nicklas 30   private String namePrefix;
4468 26 Apr 17 nicklas 31   private boolean projectSpecificValues;
4464 24 Apr 17 nicklas 32   
4469 26 Apr 17 nicklas 33   public CohortTypeDefFactory(DbControl dc)
4468 26 Apr 17 nicklas 34   {
4468 26 Apr 17 nicklas 35     this.dc = dc;
4468 26 Apr 17 nicklas 36     this.allCreated = new ArrayList<>();
4468 26 Apr 17 nicklas 37   }
4464 24 Apr 17 nicklas 38
4469 26 Apr 17 nicklas 39   public CohortTypeDefFactory(DbControl dc, Item itemType, String subtype)
4464 24 Apr 17 nicklas 40   {
4468 26 Apr 17 nicklas 41     this(dc);
4464 24 Apr 17 nicklas 42     this.itemType = itemType;
4464 24 Apr 17 nicklas 43     this.subtype = subtype;
4464 24 Apr 17 nicklas 44   }
4464 24 Apr 17 nicklas 45   
4469 26 Apr 17 nicklas 46   public CohortTypeDefFactory setItemType(Item itemType)
4464 24 Apr 17 nicklas 47   {
4464 24 Apr 17 nicklas 48     this.itemType = itemType;
4464 24 Apr 17 nicklas 49     return this;
4464 24 Apr 17 nicklas 50   }
4464 24 Apr 17 nicklas 51
4469 26 Apr 17 nicklas 52   public CohortTypeDefFactory setSubtype(String subtype)
4464 24 Apr 17 nicklas 53   {
4464 24 Apr 17 nicklas 54     this.subtype = subtype;
4464 24 Apr 17 nicklas 55     return this;
4464 24 Apr 17 nicklas 56   }
4464 24 Apr 17 nicklas 57
4469 26 Apr 17 nicklas 58   public CohortTypeDefFactory setNamePrefix(String prefix)
4464 24 Apr 17 nicklas 59   {
4464 24 Apr 17 nicklas 60     this.namePrefix = prefix;
4464 24 Apr 17 nicklas 61     return this;
4464 24 Apr 17 nicklas 62   }
4464 24 Apr 17 nicklas 63   
4469 26 Apr 17 nicklas 64   public CohortTypeDefFactory setProjectSpecificValues(boolean projectSpecificValues)
4468 26 Apr 17 nicklas 65   {
4468 26 Apr 17 nicklas 66     this.projectSpecificValues = projectSpecificValues;
4468 26 Apr 17 nicklas 67     return this;
4468 26 Apr 17 nicklas 68   }
4468 26 Apr 17 nicklas 69   
4469 26 Apr 17 nicklas 70   public CohortAnnotationType createAnnotationType(String name, Type valueType)
4464 24 Apr 17 nicklas 71   {
4469 26 Apr 17 nicklas 72     CohortAnnotationType vcat = new CohortAnnotationType(join(namePrefix, name), valueType, itemType, subtype);
4468 26 Apr 17 nicklas 73     vcat.setProjectSpecificValues(projectSpecificValues);
4468 26 Apr 17 nicklas 74     allCreated.add(vcat);
4468 26 Apr 17 nicklas 75     return vcat;
4464 24 Apr 17 nicklas 76   }
4464 24 Apr 17 nicklas 77
4469 26 Apr 17 nicklas 78   public CohortAnnotationType createAnnotationType(Annotationtype at)
4464 24 Apr 17 nicklas 79   {
4469 26 Apr 17 nicklas 80     CohortAnnotationType cat = createAnnotationType(at.getName(), at.getValueType());
4468 26 Apr 17 nicklas 81     AnnotationType tmp = at.get(dc);
4469 26 Apr 17 nicklas 82     if (tmp.isEnumeration()) cat.setEnumeration(tmp.getValues());
4469 26 Apr 17 nicklas 83     return cat;
4464 24 Apr 17 nicklas 84   }
4464 24 Apr 17 nicklas 85   
4469 26 Apr 17 nicklas 86   public CohortDataFileType createFileType(Datafiletype filetype)
4468 26 Apr 17 nicklas 87   {
7016 26 Jan 23 nicklas 88     CohortDataFileType cdf = new CohortDataFileType(dc, itemType, filetype, subtype);
4469 26 Apr 17 nicklas 89     allCreated.add(cdf);
4469 26 Apr 17 nicklas 90     return cdf;
4468 26 Apr 17 nicklas 91   }
4469 26 Apr 17 nicklas 92   
7014 26 Jan 23 nicklas 93   public CohortDataFileType createFileType(Datafiletype filetype, Rawdatatype rawDataType)
4469 26 Apr 17 nicklas 94   {
7016 26 Jan 23 nicklas 95     CohortDataFileType cdf = new CohortDataFileType(dc, itemType, filetype, rawDataType.getPlatformId(), rawDataType.getVariantId());
4469 26 Apr 17 nicklas 96     allCreated.add(cdf);
4469 26 Apr 17 nicklas 97     return cdf;
4469 26 Apr 17 nicklas 98   }
4469 26 Apr 17 nicklas 99   
4469 26 Apr 17 nicklas 100   public List<CohortTypeDef> allCreated()
4469 26 Apr 17 nicklas 101   {
4469 26 Apr 17 nicklas 102     return allCreated;
4469 26 Apr 17 nicklas 103   }
4468 26 Apr 17 nicklas 104     
4464 24 Apr 17 nicklas 105   private String join(String... strings)
4464 24 Apr 17 nicklas 106   {
4464 24 Apr 17 nicklas 107     StringBuilder sb = new StringBuilder();
4464 24 Apr 17 nicklas 108     for (String s : strings)
4464 24 Apr 17 nicklas 109     {
4464 24 Apr 17 nicklas 110       if (s != null) sb.append(s);
4464 24 Apr 17 nicklas 111     }
4464 24 Apr 17 nicklas 112     return sb.toString();
4464 24 Apr 17 nicklas 113   }
4464 24 Apr 17 nicklas 114   
4464 24 Apr 17 nicklas 115 }