6775 |
17 Mar 15 |
nicklas |
1 |
/** |
6775 |
17 Mar 15 |
nicklas |
$Id$ |
6775 |
17 Mar 15 |
nicklas |
3 |
|
6775 |
17 Mar 15 |
nicklas |
Copyright (C) 2015 Nicklas Nordborg |
6775 |
17 Mar 15 |
nicklas |
5 |
|
6775 |
17 Mar 15 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6775 |
17 Mar 15 |
nicklas |
Available at http://base.thep.lu.se/ |
6775 |
17 Mar 15 |
nicklas |
8 |
|
6775 |
17 Mar 15 |
nicklas |
BASE is free software; you can redistribute it and/or |
6775 |
17 Mar 15 |
nicklas |
modify it under the terms of the GNU General Public License |
6775 |
17 Mar 15 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6775 |
17 Mar 15 |
nicklas |
of the License, or (at your option) any later version. |
6775 |
17 Mar 15 |
nicklas |
13 |
|
6775 |
17 Mar 15 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6775 |
17 Mar 15 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6775 |
17 Mar 15 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6775 |
17 Mar 15 |
nicklas |
GNU General Public License for more details. |
6775 |
17 Mar 15 |
nicklas |
18 |
|
6775 |
17 Mar 15 |
nicklas |
You should have received a copy of the GNU General Public License |
6775 |
17 Mar 15 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6775 |
17 Mar 15 |
nicklas |
21 |
*/ |
6775 |
17 Mar 15 |
nicklas |
22 |
package net.sf.basedb.util.listable; |
6775 |
17 Mar 15 |
nicklas |
23 |
|
6775 |
17 Mar 15 |
nicklas |
24 |
import java.util.Set; |
6775 |
17 Mar 15 |
nicklas |
25 |
|
6775 |
17 Mar 15 |
nicklas |
26 |
import net.sf.basedb.core.BioSource; |
6775 |
17 Mar 15 |
nicklas |
27 |
import net.sf.basedb.core.Item; |
6775 |
17 Mar 15 |
nicklas |
28 |
import net.sf.basedb.core.ItemQuery; |
6775 |
17 Mar 15 |
nicklas |
29 |
import net.sf.basedb.core.query.Expressions; |
6775 |
17 Mar 15 |
nicklas |
30 |
import net.sf.basedb.core.query.Hql; |
6775 |
17 Mar 15 |
nicklas |
31 |
import net.sf.basedb.core.query.Restrictions; |
6775 |
17 Mar 15 |
nicklas |
32 |
|
6775 |
17 Mar 15 |
nicklas |
33 |
/** |
6775 |
17 Mar 15 |
nicklas |
Source item transformer that transform sample items to their parent |
6775 |
17 Mar 15 |
nicklas |
biosources. This implementation will only transform to the sample:s |
6775 |
17 Mar 15 |
nicklas |
immediate parent biosources. Grandparents are not included. To do this, |
6775 |
17 Mar 15 |
nicklas |
combine this transformer with a {@link SampleToParentSampleTransformer}. |
6775 |
17 Mar 15 |
nicklas |
38 |
|
6775 |
17 Mar 15 |
nicklas |
@author Nicklas |
6775 |
17 Mar 15 |
nicklas |
@since 3.5 |
6775 |
17 Mar 15 |
nicklas |
41 |
*/ |
6775 |
17 Mar 15 |
nicklas |
42 |
public class SampleToBioSourceTransformer |
6775 |
17 Mar 15 |
nicklas |
43 |
extends AbstractSourceItemTransformer |
6775 |
17 Mar 15 |
nicklas |
44 |
{ |
6775 |
17 Mar 15 |
nicklas |
45 |
|
7772 |
17 Feb 20 |
nicklas |
46 |
private boolean pushOnly; |
7772 |
17 Feb 20 |
nicklas |
47 |
|
6775 |
17 Mar 15 |
nicklas |
48 |
public SampleToBioSourceTransformer() |
6775 |
17 Mar 15 |
nicklas |
49 |
{ |
6775 |
17 Mar 15 |
nicklas |
50 |
super(Item.SAMPLE, Item.BIOSOURCE); |
6775 |
17 Mar 15 |
nicklas |
51 |
} |
6775 |
17 Mar 15 |
nicklas |
52 |
|
6775 |
17 Mar 15 |
nicklas |
53 |
/** |
7772 |
17 Feb 20 |
nicklas |
Create a new sample to biosource transformer that only load parent biosources |
7772 |
17 Feb 20 |
nicklas |
to sample that has a subtype with "push annotations" set. This functionality |
7772 |
17 Feb 20 |
nicklas |
should only be used in the first transformation step. |
7772 |
17 Feb 20 |
nicklas |
@see PushToParentsTransformer |
7772 |
17 Feb 20 |
nicklas |
@since 3.16 |
7772 |
17 Feb 20 |
nicklas |
59 |
*/ |
7772 |
17 Feb 20 |
nicklas |
60 |
public SampleToBioSourceTransformer(boolean childrensThatPushOnly) |
7772 |
17 Feb 20 |
nicklas |
61 |
{ |
7772 |
17 Feb 20 |
nicklas |
62 |
this(); |
7772 |
17 Feb 20 |
nicklas |
63 |
this.pushOnly = childrensThatPushOnly; |
7772 |
17 Feb 20 |
nicklas |
64 |
} |
7772 |
17 Feb 20 |
nicklas |
65 |
|
7772 |
17 Feb 20 |
nicklas |
66 |
/** |
6775 |
17 Mar 15 |
nicklas |
Load the ID of all biosources that are immediate parents to the |
6775 |
17 Mar 15 |
nicklas |
given set of samples. |
6775 |
17 Mar 15 |
nicklas |
69 |
*/ |
6775 |
17 Mar 15 |
nicklas |
70 |
@Override |
6775 |
17 Mar 15 |
nicklas |
71 |
public Set<Integer> transform(TransformContext context, Set<Integer> source) |
6775 |
17 Mar 15 |
nicklas |
72 |
{ |
8094 |
04 Nov 22 |
nicklas |
73 |
context.collect(getSourceItemType(), source); |
6775 |
17 Mar 15 |
nicklas |
74 |
ItemQuery<BioSource> query = BioSource.getQuery(); |
6848 |
13 Apr 15 |
nicklas |
75 |
query.setIncludes(context.getInclude()); |
6775 |
17 Mar 15 |
nicklas |
76 |
query.join(Hql.innerJoin("children", "ch")); |
6775 |
17 Mar 15 |
nicklas |
77 |
query.restrict( |
6775 |
17 Mar 15 |
nicklas |
78 |
Restrictions.in( |
6775 |
17 Mar 15 |
nicklas |
79 |
Hql.alias("ch"), |
6775 |
17 Mar 15 |
nicklas |
80 |
Expressions.parameter("samples") |
6775 |
17 Mar 15 |
nicklas |
81 |
) |
6775 |
17 Mar 15 |
nicklas |
82 |
); |
7772 |
17 Feb 20 |
nicklas |
83 |
if (pushOnly) |
7772 |
17 Feb 20 |
nicklas |
84 |
{ |
7772 |
17 Feb 20 |
nicklas |
85 |
query.join(Hql.innerJoin("ch", "itemSubtype", "st")); |
7772 |
17 Feb 20 |
nicklas |
86 |
query.restrict(Restrictions.eq(Hql.property("st", "pushAnnotations"), Expressions.bool(true))); |
7772 |
17 Feb 20 |
nicklas |
87 |
} |
8094 |
04 Nov 22 |
nicklas |
88 |
return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "samples", source)); |
6775 |
17 Mar 15 |
nicklas |
89 |
} |
6775 |
17 Mar 15 |
nicklas |
90 |
|
6775 |
17 Mar 15 |
nicklas |
91 |
} |