Changeset 3972
- Timestamp:
- Nov 15, 2007, 12:49:51 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/BioAssaySet.java
r3956 r3972 347 347 @since 2.5 348 348 */ 349 public BioAssaySetInfo toInfo(BioAssaySetInfo info , DbControl dc)349 public BioAssaySetInfo toInfo(BioAssaySetInfo info) 350 350 { 351 351 super.toInfo(info); … … 354 354 info.setNumReporters(this.getNumReporters()); 355 355 info.setNumSpots(this.getNumSpots()); 356 357 ItemQuery<BioAssay> query = this.getBioAssays();358 List<BioAssay> bioas = null;359 int[] basIds;;360 try361 {362 bioas = query.list(dc);363 basIds = new int[bioas.size()];364 }365 catch (PermissionDeniedException pex)366 {367 basIds = new int[0];368 }369 for (int i=0; i<basIds.length; i++)370 {371 basIds[i] = bioas.get(i).getId();372 }373 info.setBioAssayIds(basIds);374 375 356 return info; 376 357 } -
trunk/src/info/net/sf/basedb/info/BioAssaySetInfo.java
r3959 r3972 37 37 public class BioAssaySetInfo 38 38 extends BasicItemInfo 39 39 implements NameableInfo, Serializable 40 40 { 41 41 private static final long serialVersionUID = -1192040975292178464L; … … 44 44 private int numReporters = 0; 45 45 private int numSpots = 0; 46 private int[] bioAssayIds;47 46 48 47 /** … … 86 85 } 87 86 88 /**89 @param bioAssayIds The bioAssayIds to set.90 */91 public void setBioAssayIds(int[] bioAssayIds)92 {93 this.bioAssayIds = bioAssayIds;94 }95 96 /**97 @return Returns the bioAssayIds.98 */99 public int[] getBioAssayIds()100 {101 return bioAssayIds;102 }103 104 87 public String getDescription() 105 88 { -
trunk/src/test/TestWebservices.java
r3964 r3972 292 292 if (hasDownloadableData && fileTypes.length > 0) 293 293 { 294 System.out.print("--Download of array design file....");294 System.out.print("--Download of " + fileTypes[0].getName() + " for array design...."); 295 295 File receivedFile = new File(fileTypes[0].getName()); 296 296 OutputStream out = new FileOutputStream(receivedFile); … … 373 373 if (hasDownloadableData && fileTypes.length > 0) 374 374 { 375 System.out.print("--Download of raw data filefor RawBioAssay....");375 System.out.print("--Download of " + fileTypes[0].getName() + " for RawBioAssay...."); 376 376 File receivedFile = new File(fileTypes[0].getName()); 377 377 OutputStream out = new FileOutputStream(receivedFile); -
trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java
r3964 r3972 34 34 import net.sf.basedb.info.DataFileTypeInfo; 35 35 import net.sf.basedb.info.QueryOptions; 36 37 import java.util.LinkedList;38 import java.util.List;39 36 40 37 import org.apache.axiom.om.OMElement; … … 74 71 { 75 72 ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId); 76 DataFileType type = DataFileType.getByExternalId(dc, dataFileType);77 73 if (design.hasFileSet()) 78 74 { 79 75 FileSet fileSet = design.getFileSet(); 76 DataFileType type = DataFileType.getByExternalId(dc, dataFileType); 80 77 if (fileSet.hasMember(type)) 81 78 { … … 128 125 SessionControl sc = getSessionControl(ID); 129 126 DbControl dc = sc.newDbControl(); 130 List<DataFileTypeInfo> types = new LinkedList<DataFileTypeInfo>();131 127 132 128 try … … 136 132 { 137 133 FileSet fileSet = design.getFileSet(); 138 ItemQuery<FileSetMember> query = fileSet.getMembers(); 139 if (qOpt != null) util.getConfiguredItemQuery(query, qOpt); 140 for (FileSetMember fsm : query.list(dc)) 141 { 142 DataFileTypeInfo dftInfo = new DataFileTypeInfo(); 143 dftInfo = fsm.getDataFileType().toInfo(dftInfo); 144 types.add(dftInfo); 145 } 134 ItemQuery<DataFileType> query = fileSet.getMemberTypes(); 135 query = util.getConfiguredItemQuery(query, qOpt); 136 return util.listToInfo(query.list(dc), DataFileTypeInfo.class); 146 137 } 147 138 } … … 150 141 if (dc != null) dc.close(); 151 142 } 152 DataFileTypeInfo[] dataFileTypeInfos = new DataFileTypeInfo[types.size()]; 153 return types.toArray(dataFileTypeInfos); 143 return new DataFileTypeInfo[0]; 154 144 } 155 145 } -
trunk/src/webservices/server/net/sf/basedb/ws/server/ExperimentService.java
r3956 r3972 69 69 ItemQuery<Experiment> query= Experiment.getQuery(); 70 70 query = util.getConfiguredItemQuery(query, qOpt); 71 72 for (Experiment experiment : query.list(dc)) 73 { 74 ExperimentInfo expInfo = new ExperimentInfo(); 75 experiment.toInfo(expInfo); 76 experiments.add(expInfo); 77 } 71 return util.listToInfo(query.list(dc), ExperimentInfo.class); 78 72 } 79 73 finally … … 81 75 if (dc != null) dc.close(); 82 76 } 83 ExperimentInfo[] ii = new ExperimentInfo[experiments.size()];84 return experiments.toArray(ii);85 77 } 86 78 … … 95 87 public BioAssaySetInfo[] getBioAssaySets(String ID, int experimentId, QueryOptions qOpt) 96 88 { 97 List<BioAssaySetInfo> bioAssaySetsInfo = new LinkedList<BioAssaySetInfo>();98 89 SessionControl sc = getSessionControl(ID); 99 90 DbControl dc = sc.newDbControl(); 100 101 91 try 102 92 { 103 93 Experiment experiment = Experiment.getById(dc, experimentId); 104 94 ItemQuery<BioAssaySet> query = experiment.getBioAssaySets(); 105 query = qOpt != null ? util.getConfiguredItemQuery(query, qOpt) : query; 106 107 for (BioAssaySet bas : query.list(dc)) 108 { 109 BioAssaySetInfo basInfo = new BioAssaySetInfo(); 110 bas.toInfo(basInfo, dc); 111 bioAssaySetsInfo.add(basInfo); 112 } 95 query = util.getConfiguredItemQuery(query, qOpt); 96 return util.listToInfo(query.list(dc), BioAssaySetInfo.class); 113 97 } 114 98 finally … … 116 100 if (dc != null) dc.close(); 117 101 } 118 119 BioAssaySetInfo[] ii = new BioAssaySetInfo[bioAssaySetsInfo.size()];120 return bioAssaySetsInfo.toArray(ii);121 102 } 122 103 … … 133 114 SessionControl sc = getSessionControl(ID); 134 115 DbControl dc = sc.newDbControl(); 135 List<RawBioAssayInfo> rawBioAssays = new LinkedList<RawBioAssayInfo>();136 116 try 137 117 { 138 118 Experiment experiment = Experiment.getById(dc, experimentId); 139 119 ItemQuery<RawBioAssay> query = experiment.getRawBioAssays(); 140 query = qOpt != null ? util.getConfiguredItemQuery(query, qOpt) : query; 141 142 for (RawBioAssay rba : query.list(dc)) 143 { 144 RawBioAssayInfo rbaInfo = new RawBioAssayInfo(); 145 rbaInfo = rba.toInfo(rbaInfo); 146 rawBioAssays.add(rbaInfo); 147 } 148 120 query = util.getConfiguredItemQuery(query, qOpt); 121 return util.listToInfo(query.list(dc), RawBioAssayInfo.class); 149 122 } 150 123 finally … … 152 125 if (dc != null) dc.close(); 153 126 } 154 RawBioAssayInfo[] ii = new RawBioAssayInfo[rawBioAssays.size()];155 return rawBioAssays.toArray(ii);156 127 } 157 128 } -
trunk/src/webservices/server/net/sf/basedb/ws/server/ProjectService.java
r3956 r3972 31 31 import net.sf.basedb.info.QueryOptions; 32 32 33 import java.util.LinkedList;34 import java.util.List;35 33 36 34 /** … … 83 81 { 84 82 SessionControl sc = getSessionControl(ID); 85 DbControl dc = sc.newDbControl(); 86 List<ProjectInfo> projects = new LinkedList<ProjectInfo>(); 83 DbControl dc = sc.newDbControl(); 87 84 try 88 85 { 89 86 ItemQuery<Project> query = Project.getQuery(); 90 query = qOpt != null ? util.getConfiguredItemQuery(query, qOpt) : query; 91 92 for (Project project : query.list(dc)) 93 { 94 ProjectInfo pInfo = new ProjectInfo(); 95 project.toInfo(pInfo); 96 projects.add(pInfo); 97 } 87 query = util.getConfiguredItemQuery(query, qOpt); 88 return util.listToInfo(query.list(dc), ProjectInfo.class); 98 89 } 99 90 finally … … 101 92 if (dc != null) dc.close(); 102 93 } 103 ProjectInfo[] ii = new ProjectInfo[projects.size()];104 return projects.toArray(ii);105 94 } 106 95 } -
trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java
r3964 r3972 37 37 import net.sf.basedb.info.QueryOptions; 38 38 39 import java.util.LinkedList;40 import java.util.List;41 39 42 40 import org.apache.axiom.om.OMElement; … … 67 65 SessionControl sc = getSessionControl(ID); 68 66 DbControl dc = sc.newDbControl(); 69 ArrayDesign arrayDesign= null;67 ArrayDesignInfo info = null; 70 68 try 71 69 { 72 70 RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId); 73 arrayDesign= rawBioAssay.getArrayDesign(); 71 ArrayDesign arrayDesign = rawBioAssay.getArrayDesign(); 72 if (arrayDesign != null) info = arrayDesign.toInfo(new ArrayDesignInfo()); 74 73 } 75 74 finally … … 77 76 if (dc != null) dc.close(); 78 77 } 79 80 ArrayDesignInfo adInfo = new ArrayDesignInfo(); 81 arrayDesign.toInfo(adInfo); 82 return adInfo; 78 return info; 83 79 } 84 80 … … 101 97 { 102 98 RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId); 103 DataFileType type = DataFileType.getByExternalId(dc, dataFileType);104 99 if (rawBioAssay.hasFileSet()) 105 100 { 106 101 FileSet fileSet = rawBioAssay.getFileSet(); 102 DataFileType type = DataFileType.getByExternalId(dc, dataFileType); 107 103 if (fileSet.hasMember(type)) 108 104 { … … 156 152 SessionControl sc = getSessionControl(ID); 157 153 DbControl dc = sc.newDbControl(); 158 List<DataFileTypeInfo> types = new LinkedList<DataFileTypeInfo>();159 154 try 160 155 { … … 162 157 if (rawBioAssay.hasFileSet()) 163 158 { 164 ItemQuery<FileSetMember> query = rawBioAssay.getFileSet().getMembers(); 165 if (qOpt != null) util.getConfiguredItemQuery(query, qOpt); 166 for (FileSetMember fsm : query.list(dc)) 167 { 168 DataFileTypeInfo dftInfo = new DataFileTypeInfo(); 169 fsm.getDataFileType().toInfo(dftInfo); 170 types.add(dftInfo); 171 } 159 ItemQuery<DataFileType> query = rawBioAssay.getFileSet().getMemberTypes(); 160 query = util.getConfiguredItemQuery(query, qOpt); 161 return util.listToInfo(query.list(dc), DataFileTypeInfo.class); 172 162 } 173 163 } … … 176 166 if (dc != null) dc.close(); 177 167 } 178 DataFileTypeInfo[] dataFileTypeInfo = new DataFileTypeInfo[types.size()]; 179 return types.toArray(dataFileTypeInfo); 168 return new DataFileTypeInfo[0]; 180 169 } 181 170 } -
trunk/src/webservices/server/net/sf/basedb/ws/server/ServicesUtil.java
r3952 r3972 28 28 import net.sf.basedb.core.ItemQuery; 29 29 import net.sf.basedb.core.query.Hql; 30 import net.sf.basedb.info.BasicItemInfo; 30 31 import net.sf.basedb.info.QueryOptions; 31 32 32 import java.util.ArrayList; 33 import java.lang.reflect.InvocationTargetException; 34 import java.lang.reflect.Method; 35 import java.util.EnumSet; 33 36 import java.util.List; 37 import java.util.Set; 34 38 35 39 /** 36 40 A utility class for common methods in the web services. 37 @author Martin 41 @author Martin, Nicklas 38 42 @version 2.5 39 43 */ … … 50 54 */ 51 55 @SuppressWarnings("unchecked") 52 p rotected<T extends BasicItem> ItemQuery<T> getConfiguredItemQuery(ItemQuery<T> query, QueryOptions qOpt)56 public <T extends BasicItem> ItemQuery<T> getConfiguredItemQuery(ItemQuery<T> query, QueryOptions qOpt) 53 57 { 54 List<Include> includes = new ArrayList<Include>();55 qOpt = qOpt == null ? new QueryOptions() : qOpt;58 Set<Include> includes = EnumSet.noneOf(Include.class); 59 if (qOpt == null) qOpt = new QueryOptions(); 56 60 if (qOpt.getIncludeMine()) includes.add(Include.MINE); 57 61 if (qOpt.getIncludeShared()) includes.add(Include.SHARED); … … 62 66 query.include(includes); 63 67 if (qOpt.getRestriction() != null) 64 { 65 query.restrict(Hql.restriction(qOpt.getRestriction(), qOpt.getRestrictionPrefix())); 66 } 68 { 69 query.restrict(Hql.restriction(qOpt.getRestriction(), qOpt.getRestrictionPrefix())); 70 } 67 71 return query; 68 72 } 73 74 /** 75 Convert a list of objects to an array of info objects 76 objects. This method uses reflection to find the correct method. For this 77 to work there are a few requirements: 78 79 <ul> 80 <li>The list must contain objects of the same class only. 81 <li>The class for the objects in the list must contain a method 82 with the name "toInfo". 83 <li>The "toInfo" method must take an object of the specified 84 info class as the single parameter. 85 <li>The "toInfo" method must return the same object that was 86 passed to it. 87 </ul> 88 89 See for example: {@link net.sf.basedb.core.Experiment#toInfo(net.sf.basedb.info.ExperimentInfo)} 90 91 <p> 92 Note that this method is not limited to BasicItem object. It will work with 93 any kind of object as long as the above requirements are fulfilled. 94 95 @param list A list of BasicItem objects or one of the subclasses 96 @param clazz The class of the BasicItemInfo that is matching the BasicItem:s 97 in the list 98 @return An array info objects of the specified class 99 */ 100 @SuppressWarnings("unchecked") 101 public <T> T[] listToInfo(List<?> list, Class<T> clazz) 102 { 103 T[] result = (T[])java.lang.reflect.Array.newInstance(clazz, list.size()); 104 int i = 0; 105 Method toInfo = null; 106 try 107 { 108 for (Object o : list) 109 { 110 if (toInfo == null) toInfo = o.getClass().getDeclaredMethod("toInfo", clazz); 111 result[i] = clazz.newInstance(); 112 toInfo.invoke(o, result[i]); 113 ++i; 114 } 115 } 116 catch (NoSuchMethodException ex) 117 { 118 throw new RuntimeException(ex); 119 } 120 catch (InstantiationException ex) 121 { 122 throw new RuntimeException(ex); 123 } 124 catch (IllegalAccessException ex) 125 { 126 throw new RuntimeException(ex); 127 } 128 catch (InvocationTargetException ex) 129 { 130 throw new RuntimeException(ex); 131 } 132 return result; 133 } 134 69 135 }
Note: See TracChangeset
for help on using the changeset viewer.