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.Item; |
6775 |
17 Mar 15 |
nicklas |
27 |
import net.sf.basedb.core.ItemQuery; |
6775 |
17 Mar 15 |
nicklas |
28 |
import net.sf.basedb.core.Sample; |
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 extract items to their parent |
6775 |
17 Mar 15 |
nicklas |
samples. This implementation will only transform to the extract:s immediate |
6775 |
17 Mar 15 |
nicklas |
parent samples. Grandparents are not included (neither on the extract or |
6775 |
17 Mar 15 |
nicklas |
sample side). |
6775 |
17 Mar 15 |
nicklas |
38 |
|
6775 |
17 Mar 15 |
nicklas |
To include all grandparents, combine this transformer with |
6775 |
17 Mar 15 |
nicklas |
{@link SampleToParentSampleTransformer} and {@link ExtractToParentExtractTransformer}. |
6775 |
17 Mar 15 |
nicklas |
41 |
|
6775 |
17 Mar 15 |
nicklas |
@author Nicklas |
6775 |
17 Mar 15 |
nicklas |
@since 3.5 |
6775 |
17 Mar 15 |
nicklas |
44 |
*/ |
6775 |
17 Mar 15 |
nicklas |
45 |
public class ExtractToSampleTransformer |
6775 |
17 Mar 15 |
nicklas |
46 |
extends AbstractSourceItemTransformer |
6775 |
17 Mar 15 |
nicklas |
47 |
{ |
6775 |
17 Mar 15 |
nicklas |
48 |
|
7772 |
17 Feb 20 |
nicklas |
49 |
private boolean pushOnly; |
7772 |
17 Feb 20 |
nicklas |
50 |
|
6775 |
17 Mar 15 |
nicklas |
51 |
public ExtractToSampleTransformer() |
6775 |
17 Mar 15 |
nicklas |
52 |
{ |
6775 |
17 Mar 15 |
nicklas |
53 |
super(Item.EXTRACT, Item.SAMPLE); |
6775 |
17 Mar 15 |
nicklas |
54 |
} |
6775 |
17 Mar 15 |
nicklas |
55 |
|
6775 |
17 Mar 15 |
nicklas |
56 |
/** |
7772 |
17 Feb 20 |
nicklas |
Create a new extract to sample transformer that only load parent samples |
7772 |
17 Feb 20 |
nicklas |
to extracts 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 |
62 |
*/ |
7772 |
17 Feb 20 |
nicklas |
63 |
public ExtractToSampleTransformer(boolean childrensThatPushOnly) |
7772 |
17 Feb 20 |
nicklas |
64 |
{ |
7772 |
17 Feb 20 |
nicklas |
65 |
this(); |
7772 |
17 Feb 20 |
nicklas |
66 |
this.pushOnly = childrensThatPushOnly; |
7772 |
17 Feb 20 |
nicklas |
67 |
} |
7772 |
17 Feb 20 |
nicklas |
68 |
|
7772 |
17 Feb 20 |
nicklas |
69 |
/** |
6775 |
17 Mar 15 |
nicklas |
Load the ID of all samples that are immediate parents to the |
6775 |
17 Mar 15 |
nicklas |
given set of extracts. |
6775 |
17 Mar 15 |
nicklas |
72 |
*/ |
6775 |
17 Mar 15 |
nicklas |
73 |
@Override |
6775 |
17 Mar 15 |
nicklas |
74 |
public Set<Integer> transform(TransformContext context, Set<Integer> source) |
6775 |
17 Mar 15 |
nicklas |
75 |
{ |
8094 |
04 Nov 22 |
nicklas |
76 |
context.collect(getSourceItemType(), source); |
6775 |
17 Mar 15 |
nicklas |
77 |
ItemQuery<Sample> query = Sample.getQuery(); |
6848 |
13 Apr 15 |
nicklas |
78 |
query.setIncludes(context.getInclude()); |
6775 |
17 Mar 15 |
nicklas |
79 |
query.join(Hql.innerJoin("children", "ch")); |
6775 |
17 Mar 15 |
nicklas |
80 |
query.restrict( |
6775 |
17 Mar 15 |
nicklas |
81 |
Restrictions.in( |
6775 |
17 Mar 15 |
nicklas |
82 |
Hql.alias("ch"), |
6775 |
17 Mar 15 |
nicklas |
83 |
Expressions.parameter("extracts") |
6775 |
17 Mar 15 |
nicklas |
84 |
) |
6775 |
17 Mar 15 |
nicklas |
85 |
); |
7772 |
17 Feb 20 |
nicklas |
86 |
if (pushOnly) |
7772 |
17 Feb 20 |
nicklas |
87 |
{ |
7772 |
17 Feb 20 |
nicklas |
88 |
query.join(Hql.innerJoin("ch", "itemSubtype", "st")); |
7772 |
17 Feb 20 |
nicklas |
89 |
query.restrict(Restrictions.eq(Hql.property("st", "pushAnnotations"), Expressions.bool(true))); |
7772 |
17 Feb 20 |
nicklas |
90 |
} |
8094 |
04 Nov 22 |
nicklas |
91 |
return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "extracts", source)); |
6775 |
17 Mar 15 |
nicklas |
92 |
} |
6775 |
17 Mar 15 |
nicklas |
93 |
|
6775 |
17 Mar 15 |
nicklas |
94 |
|
6775 |
17 Mar 15 |
nicklas |
95 |
} |