sort indexing for newly created test steps fixed
diff --git a/src/main/java/org/eclipse/mdm/api/base/model/BaseEntityFactory.java b/src/main/java/org/eclipse/mdm/api/base/model/BaseEntityFactory.java
index 78599c9..56025d1 100644
--- a/src/main/java/org/eclipse/mdm/api/base/model/BaseEntityFactory.java
+++ b/src/main/java/org/eclipse/mdm/api/base/model/BaseEntityFactory.java
@@ -123,6 +123,7 @@
return parameter;
}
+ @Override
public ParameterSet createParameterSet(String name, String version, Measurement measurement) {
ParameterSet parameterSet = new ParameterSet(createCore(ParameterSet.class));
@@ -137,6 +138,7 @@
return parameterSet;
}
+ @Override
public ParameterSet createParameterSet(String name, String version, Channel channel) {
ParameterSet parameterSet = new ParameterSet(createCore(ParameterSet.class));
@@ -229,6 +231,9 @@
* {@inheritDoc}
*/
@Override
+ // TODO if test already exists sortindex is set to -1
+ // as soon as test step is written with a negative sort index
+ // current max index is queried before test step fields are written
public TestStep createTestStep(String name, Test test) {
TestStep testStep = new TestStep(createCore(TestStep.class));
@@ -247,7 +252,12 @@
testStep.setName(name);
testStep.setDateCreated(LocalDateTime.now());
testStep.setOptional(Boolean.TRUE);
- testStep.setSortIndex(Integer.valueOf(0)); // TODO
+
+ if(test.getID() > 0) {
+ testStep.setSortIndex(Integer.valueOf(-1));
+ } else {
+ testStep.setSortIndex(nextIndex(getChildrenStore(test).get(TestStep.class)));
+ }
return testStep;
}
@@ -307,13 +317,12 @@
return getCore(entity).getPermanentStore();
}
- @Deprecated
- protected final Core getCore(BaseEntity entity) {
- return entity.getCore();
- }
-
protected abstract <T extends Entity> Core createCore(Class<T> entityClass);
protected abstract <T extends Entity> Core createCore(Class<T> entityClass, ContextType contextType);
+ private final Core getCore(BaseEntity entity) {
+ return entity.getCore();
+ }
+
}
diff --git a/src/main/java/org/eclipse/mdm/api/base/query/Filter.java b/src/main/java/org/eclipse/mdm/api/base/query/Filter.java
index 36a8862..5422073 100644
--- a/src/main/java/org/eclipse/mdm/api/base/query/Filter.java
+++ b/src/main/java/org/eclipse/mdm/api/base/query/Filter.java
@@ -14,7 +14,6 @@
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -58,8 +57,16 @@
return and().id(entityType, id);
}
+ public static Filter idOnly(Relation relation, Long id) {
+ return and().id(relation, id);
+ }
+
public static Filter idsOnly(EntityType entityType, Collection<Long> ids) {
- return Filter.and().ids(entityType, ids);
+ return and().ids(entityType, ids);
+ }
+
+ public static Filter idsOnly(Relation relation, Collection<Long> ids) {
+ return and().ids(relation, ids);
}
public static Filter nameOnly(EntityType entityType, String pattern) {
@@ -132,16 +139,22 @@
return this;
}
+ public Filter id(Relation relation, Long id) {
+ add(Operation.EQUAL.create(relation.getAttribute(), id));
+ return this;
+ }
+
// TODO
public Filter ids(EntityType entityType, Collection<Long> ids) {
- List<Long> distinctIDs = ids.stream().distinct().collect(Collectors.toList());
- long[] unboxedIDs = new long[distinctIDs.size()];
- int i = 0;
- for(Long id : distinctIDs) {
- unboxedIDs[i++] = id;
- }
+ return ids(entityType.getIDAttribute(), ids);
+ }
- add(Operation.IN_SET.create(entityType.getIDAttribute(), unboxedIDs));
+ public Filter ids(Relation relation, Collection<Long> ids) {
+ return ids(relation.getAttribute(), ids);
+ }
+
+ private Filter ids(Attribute attribute, Collection<Long> ids) {
+ add(Operation.IN_SET.create(attribute, ids.stream().distinct().mapToLong(Long::longValue).toArray()));
return this;
}