Skip to content

Commit 91c4641

Browse files
committed
feat(model): add TestRunTemplate EIP-28
Ref etf-validator/governance#28 Signed-off-by: Jon Herrmann <herrmann@interactive-instruments.de>
1 parent 5c9f4bc commit 91c4641

23 files changed

+1505
-215
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ build
99
outputFileStates.bin
1010
*.licensed
1111
/build-dependencies.txt
12+
/out

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ configurations {
4646

4747
dependencies {
4848
compileOnly group: 'de.interactive_instruments', name: 'ii-commons-util', version:'3.0.0'+project.snapshotSuffix
49-
compileOnly group: 'de.interactive_instruments.etf', name: 'etf-core', version:'1.1.0'+project.snapshotSuffix
50-
compileOnly group: 'de.interactive_instruments.etf', name: 'etf-spi', version:'1.0.1'+project.snapshotSuffix
49+
compileOnly group: 'de.interactive_instruments.etf', name: 'etf-core', version:'1.1.1'+project.snapshotSuffix
50+
compileOnly group: 'de.interactive_instruments.etf', name: 'etf-spi', version:'1.0.2'+project.snapshotSuffix
5151

5252
compile group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.5.6'
5353

src/main/java/de/interactive_instruments/etf/dal/dao/basex/AbstractBsxDao.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.basex.core.cmd.XQuery;
3434

3535
import de.interactive_instruments.IFile;
36+
import de.interactive_instruments.SUtils;
3637
import de.interactive_instruments.etf.dal.dao.Dao;
3738
import de.interactive_instruments.etf.dal.dao.Filter;
3839
import de.interactive_instruments.etf.dal.dao.PreparedDto;
@@ -78,7 +79,7 @@ protected AbstractBsxDao(final String queryPath, final String typeName, final Bs
7879
try {
7980
xqueryStatement = IOUtils.toString(getClass().getClassLoader().getResourceAsStream(
8081
"xquery/" + typeName + "-xdb.xquery"), "UTF-8");
81-
} catch (IOException e) {
82+
} catch (NullPointerException | IOException e) {
8283
throw new StorageException("Could not load XQuery resource for " + typeName, e);
8384
}
8485
}
@@ -218,18 +219,41 @@ public PreparedDto<T> getById(final EID eid, final Filter filter) throws Storage
218219
}
219220

220221
@Override
221-
public PreparedDtoCollection<T> getByIds(final Set<EID> set, final Filter filter)
222-
throws StorageException, ObjectWithIdNotFoundException {
223-
throw new StorageException("Not implemented yet");
222+
public PreparedDtoCollection<T> getByIds(final Set<EID> ids, final Filter filter)
223+
throws StorageException {
224+
try {
225+
for (final EID id : ids) {
226+
// TODO(performance): provoke cache call. Could be optimized.
227+
getById(id).getDto();
228+
}
229+
final BsXQuery bsXQuery = createIdsQuery(ids, filter);
230+
return new BsxPreparedDtoCollection(ids, bsXQuery, getDtoResultCmd);
231+
} catch (ObjectWithIdNotFoundException | IOException e) {
232+
ctx.getLogger().error(e.getMessage());
233+
throw new StorageException(e);
234+
}
224235
}
225236

226237
private BsXQuery createPagedQuery(final Filter filter) throws BaseXException {
227-
return new BsXQuery(this.ctx, xqueryStatement).parameter(filter).parameter("function", "paged").parameter("selection",
228-
typeName);
238+
return new BsXQuery(this.ctx, xqueryStatement).parameter(filter)
239+
.parameter("function", "paged")
240+
.parameter("selection",
241+
typeName);
229242
}
230243

231244
private BsXQuery createIdQuery(final String id, final Filter filter) throws BaseXException {
232-
return new BsXQuery(this.ctx, xqueryStatement).parameter(filter).parameter("qids", id).parameter("function", "byId")
245+
return new BsXQuery(this.ctx, xqueryStatement).parameter(filter)
246+
.parameter("qids", id)
247+
.parameter("function", "byId")
248+
.parameter("selection", typeName);
249+
}
250+
251+
private BsXQuery createIdsQuery(final Set<EID> ids, final Filter filter) throws BaseXException {
252+
return new BsXQuery(this.ctx, xqueryStatement).parameter(filter)
253+
.parameter("qids", SUtils.concatStrWithPrefixAndSuffix(
254+
",", BsxDataStorage.ID_PREFIX, "", ids),
255+
"xs:string")
256+
.parameter("function", "byId")
233257
.parameter("selection", typeName);
234258
}
235259

src/main/java/de/interactive_instruments/etf/dal/dao/basex/AbstractBsxStreamWriteDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import de.interactive_instruments.IFile;
4747
import de.interactive_instruments.MdUtils;
4848
import de.interactive_instruments.SUtils;
49-
import de.interactive_instruments.etf.XmlUtils;
49+
import de.interactive_instruments.etf.EtfXpathEvaluator;
5050
import de.interactive_instruments.etf.dal.dao.StreamWriteDao;
5151
import de.interactive_instruments.etf.dal.dao.exceptions.StoreException;
5252
import de.interactive_instruments.etf.dal.dto.Dto;
@@ -119,7 +119,7 @@ private EID addAndValidate(final byte[] buffer) throws StorageException {
119119
IFile itemFile = null;
120120
try {
121121
// Parse ID
122-
final XPath xpath = XmlUtils.newXPath();
122+
final XPath xpath = EtfXpathEvaluator.newXPath();
123123
final String xpathExpression = this.queryPath + "[1]/@id";
124124
final Object oid = xpath.evaluate(xpathExpression, new InputSource(new ByteArrayInputStream(buffer)),
125125
XPathConstants.STRING);

src/main/java/de/interactive_instruments/etf/dal/dao/basex/BsxDataStorage.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@
6868
import de.interactive_instruments.etf.dal.dao.WriteDao;
6969
import de.interactive_instruments.etf.dal.dao.exceptions.StoreException;
7070
import de.interactive_instruments.etf.dal.dto.Dto;
71-
import de.interactive_instruments.etf.dal.dto.capabilities.ComponentDto;
72-
import de.interactive_instruments.etf.dal.dto.capabilities.TagDto;
73-
import de.interactive_instruments.etf.dal.dto.capabilities.TestObjectDto;
74-
import de.interactive_instruments.etf.dal.dto.capabilities.TestObjectTypeDto;
71+
import de.interactive_instruments.etf.dal.dto.capabilities.*;
7572
import de.interactive_instruments.etf.dal.dto.result.TestTaskResultDto;
7673
import de.interactive_instruments.etf.dal.dto.run.TestRunDto;
7774
import de.interactive_instruments.etf.dal.dto.run.TestTaskDto;
@@ -310,6 +307,7 @@ private void initDaosAndMoxyDtoMapping()
310307
tmpDaoMapping.put(TranslationTemplateBundleDto.class, new TranslationTemplateBundleDao(this));
311308
tmpDaoMapping.put(TagDto.class, new TagDao(this));
312309
tmpDaoMapping.put(ExecutableTestSuiteDto.class, new ExecutableTestSuiteDao(this));
310+
tmpDaoMapping.put(TestRunTemplateDto.class, new TestRunTemplateDao(this));
313311
tmpDaoMapping.put(ComponentDto.class, new ComponentDao(this));
314312
tmpDaoMapping.put(TestTaskResultDto.class, new TestTaskResultDao(this));
315313
tmpDaoMapping.put(TestItemTypeDto.class, new TestItemTypeDao(this));

src/main/java/de/interactive_instruments/etf/dal/dao/basex/BsxPreparedDtoCollection.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.xml.sax.InputSource;
3434

3535
import de.interactive_instruments.SUtils;
36-
import de.interactive_instruments.etf.XmlUtils;
36+
import de.interactive_instruments.etf.EtfXpathEvaluator;
3737
import de.interactive_instruments.etf.dal.dao.PreparedDtoCollection;
3838
import de.interactive_instruments.etf.dal.dto.Dto;
3939
import de.interactive_instruments.etf.model.DefaultEidMap;
@@ -53,13 +53,25 @@ final class BsxPreparedDtoCollection<T extends Dto> extends AbstractBsxPreparedD
5353
private final GetDtoResultCmd<T> getter;
5454
private List<T> cachedDtos;
5555
private HashMap<EID, T> mappedDtos;
56-
private HashSet<EID> ids;
56+
private Set<EID> ids;
5757

5858
BsxPreparedDtoCollection(final BsXQuery bsXQuery, final GetDtoResultCmd<T> getter) {
5959
super(bsXQuery);
6060
this.getter = getter;
6161
}
6262

63+
BsxPreparedDtoCollection(final Set<EID> ids, final BsXQuery bsXQuery, final GetDtoResultCmd<T> getter) {
64+
super(bsXQuery);
65+
this.getter = getter;
66+
this.ids = ids;
67+
mappedDtos = new HashMap<>();
68+
for (final EID id : ids) {
69+
final T dtoFromCache = (T) bsXQuery.getCtx().getFromCache(id);
70+
// TODO(performance): remove valid cached dtos from query
71+
mappedDtos.put(id, dtoFromCache);
72+
}
73+
}
74+
6375
private BsxPreparedDtoCollection(final BsxPreparedDtoCollection<T> preparedDtoCollection) {
6476
super(preparedDtoCollection.bsXquery.createCopy());
6577
this.getter = preparedDtoCollection.getter;
@@ -214,7 +226,7 @@ private Set<EID> ensureIdsQueried() {
214226
try {
215227
final ByteArrayOutputStream output = new ByteArrayOutputStream(32784);
216228
bsXquery.createCopy().parameter("fields", "@id").execute(output);
217-
final XPath xpath = XmlUtils.newXPath();
229+
final XPath xpath = EtfXpathEvaluator.newXPath();
218230
final String xpathExpression = "/etf:DsResultSet/etf:*[1]/etf:*/@id";
219231
final NodeList ns = ((NodeList) xpath.evaluate(xpathExpression, new InputSource(
220232
new ByteArrayInputStream(output.toByteArray())), XPathConstants.NODESET));
@@ -283,11 +295,7 @@ private void ensureMap() {
283295

284296
@Override
285297
public int compareTo(final PreparedDtoCollection o) {
286-
if (!(o instanceof PreparedDtoCollection)) {
287-
return -1;
288-
}
289-
final BsxPreparedDtoCollection bsxO = (BsxPreparedDtoCollection) o;
290-
return toString().compareTo(bsxO.toString());
298+
return toString().compareTo(o.toString());
291299
}
292300

293301
@Override

src/main/java/de/interactive_instruments/etf/dal/dao/basex/DsResultSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ final class DsResultSet {
5353
// private List<TestRunTemplateDto> testRunTemplates;
5454
private List<TestRunDto> testRuns;
5555
private List<TestTaskResultDto> testTaskResults;
56+
private List<TestRunTemplateDto> testRunTemplates;
5657

5758
public List<ComponentDto> getComponents() {
5859
return components;
@@ -93,4 +94,8 @@ public List<TestRunDto> getTestRuns() {
9394
public List<TestTaskResultDto> getTestTaskResults() {
9495
return testTaskResults;
9596
}
97+
98+
public List<TestRunTemplateDto> getTestRunTemplates() {
99+
return testRunTemplates;
100+
}
96101
}

src/main/java/de/interactive_instruments/etf/dal/dao/basex/DtoCache.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ Dto getFromCache(final EID eid) {
205205
final Dto dto = dtoCache.getIfPresent(eid.toString());
206206
if (logger.isDebugEnabled() && dto != null) {
207207
logger.debug("Returning {} from cache", dto.getDescriptiveLabel());
208-
return dto;
209208
}
210209
return dto;
211210
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2017-2019 European Union, interactive instruments GmbH
3+
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
4+
* the European Commission - subsequent versions of the EUPL (the "Licence");
5+
* You may not use this work except in compliance with the Licence.
6+
* You may obtain a copy of the Licence at:
7+
*
8+
* https://joinup.ec.europa.eu/software/page/eupl
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the Licence is distributed on an "AS IS" basis,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the Licence for the specific language governing permissions and
14+
* limitations under the Licence.
15+
*
16+
* This work was supported by the EU Interoperability Solutions for
17+
* European Public Administrations Programme (http://ec.europa.eu/isa)
18+
* through Action 1.17: A Reusable INSPIRE Reference Platform (ARE3NA).
19+
*/
20+
package de.interactive_instruments.etf.dal.dao.basex;
21+
22+
import java.util.Collection;
23+
24+
import de.interactive_instruments.etf.dal.dto.capabilities.TestRunTemplateDto;
25+
import de.interactive_instruments.etf.model.EID;
26+
import de.interactive_instruments.exceptions.ObjectWithIdNotFoundException;
27+
import de.interactive_instruments.exceptions.StorageException;
28+
29+
/**
30+
* @author Jon Herrmann ( herrmann aT interactive-instruments doT de )
31+
*/
32+
final class TestRunTemplateDao extends AbstractBsxStreamWriteDao<TestRunTemplateDto> {
33+
34+
protected TestRunTemplateDao(final BsxDsCtx ctx) throws StorageException {
35+
super("/etf:TestRunTemplate", "TestRunTemplate", ctx,
36+
(dsResultSet) -> dsResultSet.getTestRunTemplates());
37+
}
38+
39+
@Override
40+
protected void doCleanAfterDelete(final EID eid) {}
41+
42+
@Override
43+
protected void doDeleteOrDisable(final Collection<EID> eids, final boolean clean)
44+
throws StorageException, ObjectWithIdNotFoundException {
45+
for (final EID eid : eids) {
46+
// ID checks are done in doDelete()
47+
doDelete(eid, clean);
48+
}
49+
}
50+
51+
@Override
52+
public Class<TestRunTemplateDto> getDtoType() {
53+
return TestRunTemplateDto.class;
54+
}
55+
56+
}

src/main/resources/eclipselink/classes/de.interactive_instruments.etf.dal.dao.basex.DsResultSet.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<superclass-handle>
66
<type-name>java.lang.Object</type-name>
77
</superclass-handle>
8-
<last-refresh-timestamp>2017-12-01T18:11:53.612+01:00</last-refresh-timestamp>
8+
<last-refresh-timestamp>2019-01-15T13:51:18.761+01:00</last-refresh-timestamp>
99
<attributes>
1010
<class-attribute>
1111
<name>components</name>
@@ -79,6 +79,15 @@
7979
</type-handle>
8080
</type-declaration>
8181
</class-attribute>
82+
<class-attribute>
83+
<name>testRunTemplates</name>
84+
<modifier>2</modifier>
85+
<type-declaration>
86+
<type-handle>
87+
<type-name>java.util.List</type-name>
88+
</type-handle>
89+
</type-declaration>
90+
</class-attribute>
8291
<class-attribute>
8392
<name>testTaskResults</name>
8493
<modifier>2</modifier>
@@ -175,6 +184,15 @@
175184
</type-handle>
176185
</return-type-declaration>
177186
</method>
187+
<method>
188+
<name>getTestRunTemplates</name>
189+
<modifier>1</modifier>
190+
<return-type-declaration>
191+
<type-handle>
192+
<type-name>java.util.List</type-name>
193+
</type-handle>
194+
</return-type-declaration>
195+
</method>
178196
<method>
179197
<name>getTestTaskResults</name>
180198
<modifier>1</modifier>

0 commit comments

Comments
 (0)